q6asm.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef __Q6_ASM_H__
  13. #define __Q6_ASM_H__
  14. #include <mach/qdsp6v2/apr.h>
  15. #include <sound/apr_audio.h>
  16. #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
  17. #include <linux/msm_ion.h>
  18. #endif
  19. #define IN 0x000
  20. #define OUT 0x001
  21. #define CH_MODE_MONO 0x001
  22. #define CH_MODE_STEREO 0x002
  23. #define FORMAT_LINEAR_PCM 0x0000
  24. #define FORMAT_DTMF 0x0001
  25. #define FORMAT_ADPCM 0x0002
  26. #define FORMAT_YADPCM 0x0003
  27. #define FORMAT_MP3 0x0004
  28. #define FORMAT_MPEG4_AAC 0x0005
  29. #define FORMAT_AMRNB 0x0006
  30. #define FORMAT_AMRWB 0x0007
  31. #define FORMAT_V13K 0x0008
  32. #define FORMAT_EVRC 0x0009
  33. #define FORMAT_EVRCB 0x000a
  34. #define FORMAT_EVRCWB 0x000b
  35. #define FORMAT_MIDI 0x000c
  36. #define FORMAT_SBC 0x000d
  37. #define FORMAT_WMA_V10PRO 0x000e
  38. #define FORMAT_WMA_V9 0x000f
  39. #define FORMAT_AMR_WB_PLUS 0x0010
  40. #define FORMAT_MPEG4_MULTI_AAC 0x0011
  41. #define FORMAT_MULTI_CHANNEL_LINEAR_PCM 0x0012
  42. #define FORMAT_AC3 0x0013
  43. #define FORMAT_DTS 0x0014
  44. #define FORMAT_EAC3 0x0015
  45. #define FORMAT_ATRAC 0x0016
  46. #define FORMAT_MAT 0x0017
  47. #define FORMAT_AAC 0x0018
  48. #define FORMAT_DTS_LBR 0x0019
  49. #define FORMAT_PASS_THROUGH 0x0020
  50. #define FORMAT_MP2 0x0021
  51. #define ENCDEC_SBCBITRATE 0x0001
  52. #define ENCDEC_IMMEDIATE_DECODE 0x0002
  53. #define ENCDEC_CFG_BLK 0x0003
  54. #define DTS_ENC_SAMPLE_RATE48k 48000
  55. #define CMD_PAUSE 0x0001
  56. #define CMD_FLUSH 0x0002
  57. #define CMD_EOS 0x0003
  58. #define CMD_CLOSE 0x0004
  59. #define CMD_OUT_FLUSH 0x0005
  60. /* bit 0:1 represents priority of stream */
  61. #define STREAM_PRIORITY_NORMAL 0x0000
  62. #define STREAM_PRIORITY_LOW 0x0001
  63. #define STREAM_PRIORITY_HIGH 0x0002
  64. /* bit 4 represents META enable of encoded data buffer */
  65. #define BUFFER_META_ENABLE 0x0010
  66. /* Enable Sample_Rate/Channel_Mode notification event from Decoder */
  67. #define SR_CM_NOTIFY_ENABLE 0x0004
  68. #define TUN_WRITE_IO_MODE 0x0008 /* tunnel read write mode */
  69. #define TUN_READ_IO_MODE 0x0004 /* tunnel read write mode */
  70. #define ASYNC_IO_MODE 0x0002
  71. #define SYNC_IO_MODE 0x0001
  72. #define NO_TIMESTAMP 0xFF00
  73. #define SET_TIMESTAMP 0x0000
  74. #define SOFT_PAUSE_ENABLE 1
  75. #define SOFT_PAUSE_DISABLE 0
  76. #define SESSION_MAX 0x08
  77. #define SOFT_PAUSE_PERIOD 30 /* ramp up/down for 30ms */
  78. #define SOFT_PAUSE_STEP_LINEAR 0 /* Step value 0ms or 0us */
  79. #define SOFT_PAUSE_STEP 0 /* Step value 0ms or 0us */
  80. enum {
  81. SOFT_PAUSE_CURVE_LINEAR = 0,
  82. SOFT_PAUSE_CURVE_EXP,
  83. SOFT_PAUSE_CURVE_LOG,
  84. };
  85. #define SOFT_VOLUME_PERIOD 30 /* ramp up/down for 30ms */
  86. #define SOFT_VOLUME_STEP_LINEAR 0 /* Step value 0ms or 0us */
  87. #define SOFT_VOLUME_STEP 0 /* Step value 0ms or 0us */
  88. enum {
  89. SOFT_VOLUME_CURVE_LINEAR = 0,
  90. SOFT_VOLUME_CURVE_EXP,
  91. SOFT_VOLUME_CURVE_LOG,
  92. };
  93. typedef void (*app_cb)(uint32_t opcode, uint32_t token,
  94. uint32_t *payload, void *priv);
  95. struct audio_buffer {
  96. dma_addr_t phys;
  97. void *data;
  98. uint32_t used;
  99. uint32_t size;/* size of buffer */
  100. uint32_t actual_size; /* actual number of bytes read by DSP */
  101. #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
  102. struct ion_handle *handle;
  103. struct ion_client *client;
  104. #else
  105. void *mem_buffer;
  106. #endif
  107. };
  108. struct audio_aio_write_param {
  109. unsigned long paddr;
  110. uint32_t uid;
  111. uint32_t len;
  112. uint32_t msw_ts;
  113. uint32_t lsw_ts;
  114. uint32_t flags;
  115. };
  116. struct audio_aio_read_param {
  117. unsigned long paddr;
  118. uint32_t len;
  119. uint32_t uid;
  120. };
  121. struct audio_port_data {
  122. struct audio_buffer *buf;
  123. uint32_t max_buf_cnt;
  124. uint32_t dsp_buf;
  125. uint32_t cpu_buf;
  126. /* read or write locks */
  127. struct mutex lock;
  128. spinlock_t dsp_lock;
  129. };
  130. struct audio_client {
  131. int session;
  132. /* idx:1 out port, 0: in port*/
  133. struct audio_port_data port[2];
  134. struct apr_svc *apr;
  135. struct mutex cmd_lock;
  136. atomic_t cmd_state;
  137. atomic_t cmd_close_state;
  138. atomic_t time_flag;
  139. atomic_t nowait_cmd_cnt;
  140. wait_queue_head_t cmd_wait;
  141. wait_queue_head_t time_wait;
  142. app_cb cb;
  143. void *priv;
  144. uint32_t io_mode;
  145. uint64_t time_stamp;
  146. atomic_t cmd_response;
  147. bool perf_mode;
  148. };
  149. void q6asm_audio_client_free(struct audio_client *ac);
  150. struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv);
  151. struct audio_client *q6asm_get_audio_client(int session_id);
  152. int q6asm_audio_client_buf_alloc(unsigned int dir/* 1:Out,0:In */,
  153. struct audio_client *ac,
  154. unsigned int bufsz,
  155. unsigned int bufcnt);
  156. int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir
  157. /* 1:Out,0:In */,
  158. struct audio_client *ac,
  159. unsigned int bufsz,
  160. unsigned int bufcnt);
  161. int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
  162. struct audio_client *ac);
  163. int q6asm_open_read(struct audio_client *ac, uint32_t format);
  164. int q6asm_open_read_v2_1(struct audio_client *ac, uint32_t format);
  165. int q6asm_open_read_compressed(struct audio_client *ac,
  166. uint32_t frames_per_buffer, uint32_t meta_data_mode);
  167. int q6asm_open_write(struct audio_client *ac, uint32_t format);
  168. int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format);
  169. int q6asm_open_transcode_loopback(struct audio_client *ac, uint32_t channels);
  170. int q6asm_enc_cfg_blk_dts(struct audio_client *ac,
  171. uint32_t sample_rate, uint32_t channels);
  172. int q6asm_open_read_write(struct audio_client *ac,
  173. uint32_t rd_format,
  174. uint32_t wr_format);
  175. int q6asm_open_loopack(struct audio_client *ac);
  176. int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
  177. uint32_t lsw_ts, uint32_t flags);
  178. int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
  179. uint32_t lsw_ts, uint32_t flags);
  180. int q6asm_async_write(struct audio_client *ac,
  181. struct audio_aio_write_param *param);
  182. int q6asm_async_read(struct audio_client *ac,
  183. struct audio_aio_read_param *param);
  184. int q6asm_async_read_compressed(struct audio_client *ac,
  185. struct audio_aio_read_param *param);
  186. int q6asm_read(struct audio_client *ac);
  187. int q6asm_read_nolock(struct audio_client *ac);
  188. int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add,
  189. int dir, uint32_t bufsz, uint32_t bufcnt);
  190. int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add,
  191. int dir);
  192. int q6asm_run(struct audio_client *ac, uint32_t flags,
  193. uint32_t msw_ts, uint32_t lsw_ts);
  194. int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
  195. uint32_t msw_ts, uint32_t lsw_ts);
  196. int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable);
  197. int q6asm_cmd(struct audio_client *ac, int cmd);
  198. int q6asm_cmd_nowait(struct audio_client *ac, int cmd);
  199. void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac,
  200. uint32_t *size, uint32_t *idx);
  201. void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
  202. uint32_t *size, uint32_t *idx);
  203. int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac);
  204. /* File format specific configurations to be added below */
  205. int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
  206. uint32_t frames_per_buf,
  207. uint32_t sample_rate, uint32_t channels,
  208. uint32_t bit_rate,
  209. uint32_t mode, uint32_t format);
  210. int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
  211. uint32_t rate, uint32_t channels);
  212. int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
  213. uint32_t rate, uint32_t channels);
  214. int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
  215. uint32_t rate, uint32_t channels);
  216. int q6asm_enable_sbrps(struct audio_client *ac,
  217. uint32_t sbr_ps);
  218. int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
  219. uint16_t sce_left, uint16_t sce_right);
  220. int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff);
  221. int q6asm_set_encdec_chan_map(struct audio_client *ac,
  222. uint32_t num_channels);
  223. int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
  224. uint16_t min_rate, uint16_t max_rate,
  225. uint16_t reduced_rate_level, uint16_t rate_modulation_cmd);
  226. int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
  227. uint16_t min_rate, uint16_t max_rate,
  228. uint16_t rate_modulation_cmd);
  229. int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
  230. uint16_t band_mode, uint16_t dtx_enable);
  231. int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
  232. uint16_t band_mode, uint16_t dtx_enable);
  233. int q6asm_media_format_block_pcm(struct audio_client *ac,
  234. uint32_t rate, uint32_t channels);
  235. int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
  236. uint32_t rate, uint32_t channels,
  237. char *channel_map);
  238. int q6asm_media_format_block_aac(struct audio_client *ac,
  239. struct asm_aac_cfg *cfg);
  240. int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
  241. struct asm_amrwbplus_cfg *cfg);
  242. int q6asm_media_format_block_multi_aac(struct audio_client *ac,
  243. struct asm_aac_cfg *cfg);
  244. int q6asm_media_format_block_wma(struct audio_client *ac,
  245. void *cfg);
  246. int q6asm_media_format_block_wmapro(struct audio_client *ac,
  247. void *cfg);
  248. /* PP specific */
  249. int q6asm_equalizer(struct audio_client *ac, void *eq);
  250. /* Send Volume Command */
  251. int q6asm_set_volume(struct audio_client *ac, int volume);
  252. /* Set SoftPause Params */
  253. int q6asm_set_softpause(struct audio_client *ac,
  254. struct asm_softpause_params *param);
  255. /* Set Softvolume Params */
  256. int q6asm_set_softvolume(struct audio_client *ac,
  257. struct asm_softvolume_params *param);
  258. /* Send left-right channel gain */
  259. int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain);
  260. /* Enable Mute/unmute flag */
  261. int q6asm_set_mute(struct audio_client *ac, int muteflag);
  262. int q6asm_get_session_time(struct audio_client *ac, uint64_t *tstamp);
  263. /* Client can set the IO mode to either AIO/SIO mode */
  264. int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode);
  265. #ifdef CONFIG_RTAC
  266. /* Get Service ID for APR communication */
  267. int q6asm_get_apr_service_id(int session_id);
  268. #endif
  269. /* Common format block without any payload
  270. */
  271. int q6asm_media_format_block(struct audio_client *ac, uint32_t format);
  272. #endif /* __Q6_ASM_H__ */