msm-pcm.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* sound/soc/msm/msm-pcm.h
  2. *
  3. * Copyright (C) 2008 Google, Inc.
  4. * Copyright (C) 2008 HTC Corporation
  5. * Copyright (c) 2008-2009, 2012 The Linux Foundation. All rights reserved.
  6. *
  7. * This software is licensed under the terms of the GNU General Public
  8. * License version 2, as published by the Free Software Foundation, and
  9. * may be copied, distributed, and modified under those terms.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU General Public License for more details.
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you can find it at http://www.fsf.org.
  18. */
  19. #ifndef _MSM_PCM_H
  20. #define _MSM_PCM_H
  21. #include <mach/qdsp5/qdsp5audppcmdi.h>
  22. #include <mach/qdsp5/qdsp5audppmsg.h>
  23. #include <mach/qdsp5/qdsp5audreccmdi.h>
  24. #include <mach/qdsp5/qdsp5audrecmsg.h>
  25. #include <mach/qdsp5/qdsp5audpreproccmdi.h>
  26. #include <mach/qdsp5/qdsp5audpreprocmsg.h>
  27. #include <mach/qdsp5/qdsp5audpp.h>
  28. #include <../arch/arm/mach-msm/qdsp5/adsp.h>
  29. #include <../arch/arm/mach-msm/qdsp5/audmgr.h>
  30. #define FRAME_NUM (8)
  31. #define FRAME_SIZE (2052 * 2)
  32. #define MONO_DATA_SIZE (2048)
  33. #define STEREO_DATA_SIZE (MONO_DATA_SIZE * 2)
  34. #define CAPTURE_DMASZ (FRAME_SIZE * FRAME_NUM)
  35. #define BUFSZ (960 * 5)
  36. #define PLAYBACK_DMASZ (BUFSZ * 2)
  37. #define MSM_PLAYBACK_DEFAULT_VOLUME 0 /* 0dB */
  38. #define MSM_PLAYBACK_DEFAULT_PAN 0
  39. #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE
  40. #define USE_CHANNELS_MIN 1
  41. #define USE_CHANNELS_MAX 2
  42. /* Support unconventional sample rates 12000, 24000 as well */
  43. #define USE_RATE \
  44. (SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_KNOT)
  45. #define USE_RATE_MIN 8000
  46. #define USE_RATE_MAX 48000
  47. #define MAX_BUFFER_PLAYBACK_SIZE \
  48. (4800*4)
  49. /* 2048 frames (Mono), 1024 frames (Stereo) */
  50. #define CAPTURE_SIZE 4096
  51. #define MAX_BUFFER_CAPTURE_SIZE (4096*4)
  52. #define MAX_PERIOD_SIZE BUFSZ
  53. #define USE_PERIODS_MAX 1024
  54. #define USE_PERIODS_MIN 1
  55. #define MAX_DB (16)
  56. #define MIN_DB (-50)
  57. #define PCMPLAYBACK_DECODERID 5
  58. /* 0xFFFFFFFF Indicates not to be used for audio data copy */
  59. #define BUF_INVALID_LEN 0xFFFFFFFF
  60. extern int copy_count;
  61. extern int intcnt;
  62. struct msm_volume {
  63. bool update;
  64. int volume; /* Volume parameter, in dB Scale */
  65. int pan;
  66. };
  67. struct buffer {
  68. void *data;
  69. unsigned size;
  70. unsigned used;
  71. unsigned addr;
  72. };
  73. struct buffer_rec {
  74. void *data;
  75. unsigned int size;
  76. unsigned int read;
  77. unsigned int addr;
  78. };
  79. struct audio_locks {
  80. struct mutex lock;
  81. struct mutex write_lock;
  82. struct mutex read_lock;
  83. spinlock_t read_dsp_lock;
  84. spinlock_t write_dsp_lock;
  85. spinlock_t mixer_lock;
  86. wait_queue_head_t read_wait;
  87. wait_queue_head_t write_wait;
  88. wait_queue_head_t eos_wait;
  89. };
  90. extern struct audio_locks the_locks;
  91. struct msm_audio_event_callbacks {
  92. /* event is called from interrupt context when a message
  93. * arrives from the DSP.
  94. */
  95. void (*playback)(void *);
  96. void (*capture)(void *);
  97. };
  98. struct msm_audio {
  99. struct buffer out[2];
  100. struct buffer_rec in[8];
  101. uint8_t out_head;
  102. uint8_t out_tail;
  103. uint8_t out_needed; /* number of buffers the dsp is waiting for */
  104. atomic_t out_bytes;
  105. /* configuration to use on next enable */
  106. uint32_t out_sample_rate;
  107. uint32_t out_channel_mode;
  108. uint32_t out_weight;
  109. uint32_t out_buffer_size;
  110. struct audmgr audmgr;
  111. struct snd_pcm_substream *playback_substream;
  112. struct snd_pcm_substream *capture_substream;
  113. /* data allocated for various buffers */
  114. char *data;
  115. dma_addr_t phys;
  116. unsigned int pcm_size;
  117. unsigned int pcm_count;
  118. unsigned int pcm_irq_pos; /* IRQ position */
  119. unsigned int pcm_buf_pos; /* position in buffer */
  120. struct msm_adsp_module *audpre;
  121. struct msm_adsp_module *audrec;
  122. /* configuration to use on next enable */
  123. uint32_t samp_rate;
  124. uint32_t channel_mode;
  125. uint32_t buffer_size; /* 2048 for mono, 4096 for stereo */
  126. uint32_t type; /* 0 for PCM ,1 for AAC */
  127. uint32_t dsp_cnt;
  128. uint32_t in_head; /* next buffer dsp will write */
  129. uint32_t in_tail; /* next buffer read() will read */
  130. uint32_t in_count; /* number of buffers available to read() */
  131. unsigned short samp_rate_index;
  132. /* audpre settings */
  133. audpreproc_cmd_cfg_agc_params tx_agc_cfg;
  134. audpreproc_cmd_cfg_ns_params ns_cfg;
  135. /* For different sample rate, the coeff might be different. *
  136. * All the coeff should be passed from user space */
  137. audpreproc_cmd_cfg_iir_tuning_filter_params iir_cfg;
  138. struct msm_audio_event_callbacks *ops;
  139. int dir;
  140. int opened;
  141. int enabled;
  142. int running;
  143. int stopped; /* set when stopped, cleared on flush */
  144. int eos_ack;
  145. int mmap_flag;
  146. int period;
  147. };
  148. /* platform data */
  149. extern int alsa_dsp_send_buffer(struct msm_audio *prtd,
  150. unsigned idx, unsigned len);
  151. extern int audio_dsp_out_enable(struct msm_audio *prtd, int yes);
  152. extern struct snd_soc_platform_driver msm_soc_platform;
  153. int audrec_encoder_config(struct msm_audio *prtd);
  154. extern void alsa_get_dsp_frames(struct msm_audio *prtd);
  155. extern int alsa_rec_dsp_enable(struct msm_audio *prtd, int enable);
  156. extern int alsa_audrec_disable(struct msm_audio *prtd);
  157. extern int alsa_audio_configure(struct msm_audio *prtd);
  158. extern int alsa_audio_disable(struct msm_audio *prtd);
  159. extern int alsa_adsp_configure(struct msm_audio *prtd);
  160. extern int alsa_buffer_read(struct msm_audio *prtd, void __user *buf,
  161. size_t count, loff_t *pos);
  162. ssize_t alsa_send_buffer(struct msm_audio *prtd, const char __user *buf,
  163. size_t count, loff_t *pos);
  164. int msm_audio_volume_update(unsigned id,
  165. int volume, int pan);
  166. extern struct audio_locks the_locks;
  167. extern struct msm_volume msm_vol_ctl;
  168. #endif /*_MSM_PCM_H*/