msm7kv2-pcm.h 5.9 KB

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