q6asm-v2.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /* Copyright (c) 2012-2014, 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_V2_H__
  13. #define __Q6_ASM_V2_H__
  14. #include <mach/qdsp6v2/apr.h>
  15. #include <mach/qdsp6v2/rtac.h>
  16. #include <sound/apr_audio-v2.h>
  17. #include <linux/list.h>
  18. #include <linux/msm_ion.h>
  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_EAC3 0x0014
  44. #define ENCDEC_SBCBITRATE 0x0001
  45. #define ENCDEC_IMMEDIATE_DECODE 0x0002
  46. #define ENCDEC_CFG_BLK 0x0003
  47. #define CMD_PAUSE 0x0001
  48. #define CMD_FLUSH 0x0002
  49. #define CMD_EOS 0x0003
  50. #define CMD_CLOSE 0x0004
  51. #define CMD_OUT_FLUSH 0x0005
  52. #define CMD_SUSPEND 0x0006
  53. /* bit 0:1 represents priority of stream */
  54. #define STREAM_PRIORITY_NORMAL 0x0000
  55. #define STREAM_PRIORITY_LOW 0x0001
  56. #define STREAM_PRIORITY_HIGH 0x0002
  57. /* bit 4 represents META enable of encoded data buffer */
  58. #define BUFFER_META_ENABLE 0x0010
  59. /* Enable Sample_Rate/Channel_Mode notification event from Decoder */
  60. #define SR_CM_NOTIFY_ENABLE 0x0004
  61. #define TUN_WRITE_IO_MODE 0x0008 /* tunnel read write mode */
  62. #define TUN_READ_IO_MODE 0x0004 /* tunnel read write mode */
  63. #define SYNC_IO_MODE 0x0001
  64. #define ASYNC_IO_MODE 0x0002
  65. #define COMPRESSED_IO 0x0040
  66. #define COMPRESSED_STREAM_IO 0x0080
  67. #define NT_MODE 0x0400
  68. #define NO_TIMESTAMP 0xFF00
  69. #define SET_TIMESTAMP 0x0000
  70. #define SOFT_PAUSE_ENABLE 1
  71. #define SOFT_PAUSE_DISABLE 0
  72. #define SESSION_MAX 0x08
  73. #define ASM_CONTROL_SESSION 0x0F
  74. #define ASM_SHIFT_GAPLESS_MODE_FLAG 31
  75. #define ASM_SHIFT_LAST_BUFFER_FLAG 30
  76. /* payload structure bytes */
  77. #define READDONE_IDX_STATUS 0
  78. #define READDONE_IDX_BUFADD_LSW 1
  79. #define READDONE_IDX_BUFADD_MSW 2
  80. #define READDONE_IDX_MEMMAP_HDL 3
  81. #define READDONE_IDX_SIZE 4
  82. #define READDONE_IDX_OFFSET 5
  83. #define READDONE_IDX_LSW_TS 6
  84. #define READDONE_IDX_MSW_TS 7
  85. #define READDONE_IDX_FLAGS 8
  86. #define READDONE_IDX_NUMFRAMES 9
  87. #define READDONE_IDX_SEQ_ID 10
  88. #define SOFT_PAUSE_PERIOD 30 /* ramp up/down for 30ms */
  89. #define SOFT_PAUSE_STEP 0 /* Step value 0ms or 0us */
  90. enum {
  91. SOFT_PAUSE_CURVE_LINEAR = 0,
  92. SOFT_PAUSE_CURVE_EXP,
  93. SOFT_PAUSE_CURVE_LOG,
  94. };
  95. #define SOFT_VOLUME_PERIOD 30 /* ramp up/down for 30ms */
  96. #define SOFT_VOLUME_STEP 0 /* Step value 0ms or 0us */
  97. enum {
  98. SOFT_VOLUME_CURVE_LINEAR = 0,
  99. SOFT_VOLUME_CURVE_EXP,
  100. SOFT_VOLUME_CURVE_LOG,
  101. };
  102. typedef void (*app_cb)(uint32_t opcode, uint32_t token,
  103. uint32_t *payload, void *priv);
  104. struct audio_buffer {
  105. dma_addr_t phys;
  106. void *data;
  107. uint32_t used;
  108. uint32_t size;/* size of buffer */
  109. uint32_t actual_size; /* actual number of bytes read by DSP */
  110. struct ion_handle *handle;
  111. struct ion_client *client;
  112. };
  113. struct audio_aio_write_param {
  114. unsigned long paddr;
  115. uint32_t len;
  116. uint32_t uid;
  117. uint32_t lsw_ts;
  118. uint32_t msw_ts;
  119. uint32_t flags;
  120. uint32_t metadata_len;
  121. uint32_t last_buffer;
  122. };
  123. struct audio_aio_read_param {
  124. unsigned long paddr;
  125. uint32_t len;
  126. uint32_t uid;
  127. };
  128. struct audio_port_data {
  129. struct audio_buffer *buf;
  130. uint32_t max_buf_cnt;
  131. uint32_t dsp_buf;
  132. uint32_t cpu_buf;
  133. struct list_head mem_map_handle;
  134. uint32_t tmp_hdl;
  135. /* read or write locks */
  136. struct mutex lock;
  137. spinlock_t dsp_lock;
  138. };
  139. struct audio_client {
  140. int session;
  141. app_cb cb;
  142. atomic_t cmd_state;
  143. /* Relative or absolute TS */
  144. atomic_t time_flag;
  145. atomic_t nowait_cmd_cnt;
  146. atomic_t mem_state;
  147. void *priv;
  148. uint32_t io_mode;
  149. uint64_t time_stamp;
  150. struct apr_svc *apr;
  151. struct apr_svc *mmap_apr;
  152. struct apr_svc *apr2;
  153. struct mutex cmd_lock;
  154. /* idx:1 out port, 0: in port*/
  155. struct audio_port_data port[2];
  156. wait_queue_head_t cmd_wait;
  157. wait_queue_head_t time_wait;
  158. wait_queue_head_t mem_wait;
  159. int perf_mode;
  160. int stream_id;
  161. /* audio cache operations fptr*/
  162. int (*fptr_cache_ops)(struct audio_buffer *abuff, int cache_op);
  163. atomic_t unmap_cb_success;
  164. atomic_t reset;
  165. };
  166. void q6asm_audio_client_free(struct audio_client *ac);
  167. struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv);
  168. struct audio_client *q6asm_get_audio_client(int session_id);
  169. int q6asm_audio_client_buf_alloc(unsigned int dir/* 1:Out,0:In */,
  170. struct audio_client *ac,
  171. unsigned int bufsz,
  172. unsigned int bufcnt);
  173. int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir
  174. /* 1:Out,0:In */,
  175. struct audio_client *ac,
  176. unsigned int bufsz,
  177. unsigned int bufcnt);
  178. int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
  179. struct audio_client *ac);
  180. int q6asm_open_read(struct audio_client *ac, uint32_t format
  181. /*, uint16_t bits_per_sample*/);
  182. int q6asm_open_read_v2(struct audio_client *ac, uint32_t format,
  183. uint16_t bits_per_sample);
  184. int q6asm_open_write(struct audio_client *ac, uint32_t format
  185. /*, uint16_t bits_per_sample*/);
  186. int q6asm_open_write_v2(struct audio_client *ac, uint32_t format,
  187. uint16_t bits_per_sample);
  188. int q6asm_stream_open_write_v2(struct audio_client *ac, uint32_t format,
  189. uint16_t bits_per_sample, int32_t stream_id,
  190. bool is_gapless_mode);
  191. int q6asm_open_read_write(struct audio_client *ac,
  192. uint32_t rd_format,
  193. uint32_t wr_format);
  194. int q6asm_open_loopback_v2(struct audio_client *ac,
  195. uint16_t bits_per_sample);
  196. int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
  197. uint32_t lsw_ts, uint32_t flags);
  198. int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
  199. uint32_t lsw_ts, uint32_t flags);
  200. int q6asm_async_write(struct audio_client *ac,
  201. struct audio_aio_write_param *param);
  202. int q6asm_async_read(struct audio_client *ac,
  203. struct audio_aio_read_param *param);
  204. int q6asm_read(struct audio_client *ac);
  205. int q6asm_read_nolock(struct audio_client *ac);
  206. int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add,
  207. int dir, uint32_t bufsz, uint32_t bufcnt);
  208. int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add,
  209. int dir);
  210. int q6asm_unmap_cal_blocks(void);
  211. int q6asm_map_rtac_block(struct rtac_cal_block_data *cal_block);
  212. int q6asm_unmap_rtac_block(uint32_t *mem_map_handle);
  213. int q6asm_run(struct audio_client *ac, uint32_t flags,
  214. uint32_t msw_ts, uint32_t lsw_ts);
  215. int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
  216. uint32_t msw_ts, uint32_t lsw_ts);
  217. int q6asm_stream_run_nowait(struct audio_client *ac, uint32_t flags,
  218. uint32_t msw_ts, uint32_t lsw_ts, uint32_t stream_id);
  219. int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable);
  220. int q6asm_reg_rx_underflow(struct audio_client *ac, uint16_t enable);
  221. int q6asm_cmd(struct audio_client *ac, int cmd);
  222. int q6asm_stream_cmd(struct audio_client *ac, int cmd, uint32_t stream_id);
  223. int q6asm_cmd_nowait(struct audio_client *ac, int cmd);
  224. int q6asm_stream_cmd_nowait(struct audio_client *ac, int cmd,
  225. uint32_t stream_id);
  226. void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac,
  227. uint32_t *size, uint32_t *idx);
  228. void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
  229. uint32_t *size, uint32_t *idx);
  230. int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac);
  231. /* File format specific configurations to be added below */
  232. int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
  233. uint32_t frames_per_buf,
  234. uint32_t sample_rate, uint32_t channels,
  235. uint32_t bit_rate,
  236. uint32_t mode, uint32_t format);
  237. int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
  238. uint32_t rate, uint32_t channels);
  239. int q6asm_enc_cfg_blk_pcm_format_support(struct audio_client *ac,
  240. uint32_t rate, uint32_t channels,
  241. uint16_t bits_per_sample);
  242. int q6asm_set_encdec_chan_map(struct audio_client *ac,
  243. uint32_t num_channels);
  244. int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
  245. uint32_t rate, uint32_t channels);
  246. int q6asm_enable_sbrps(struct audio_client *ac,
  247. uint32_t sbr_ps);
  248. int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
  249. uint16_t sce_left, uint16_t sce_right);
  250. int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff);
  251. int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
  252. uint16_t min_rate, uint16_t max_rate,
  253. uint16_t reduced_rate_level, uint16_t rate_modulation_cmd);
  254. int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
  255. uint16_t min_rate, uint16_t max_rate,
  256. uint16_t rate_modulation_cmd);
  257. int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
  258. uint16_t band_mode, uint16_t dtx_enable);
  259. int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
  260. uint16_t band_mode, uint16_t dtx_enable);
  261. int q6asm_media_format_block_pcm(struct audio_client *ac,
  262. uint32_t rate, uint32_t channels);
  263. int q6asm_media_format_block_pcm_format_support(struct audio_client *ac,
  264. uint32_t rate, uint32_t channels,
  265. uint16_t bits_per_sample);
  266. int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
  267. uint32_t rate, uint32_t channels,
  268. bool use_default_chmap, char *channel_map);
  269. int q6asm_media_format_block_multi_ch_pcm_v2(
  270. struct audio_client *ac,
  271. uint32_t rate, uint32_t channels,
  272. bool use_default_chmap, char *channel_map,
  273. uint16_t bits_per_sample);
  274. int q6asm_media_format_block_aac(struct audio_client *ac,
  275. struct asm_aac_cfg *cfg);
  276. int q6asm_stream_media_format_block_aac(struct audio_client *ac,
  277. struct asm_aac_cfg *cfg, int stream_id);
  278. int q6asm_media_format_block_multi_aac(struct audio_client *ac,
  279. struct asm_aac_cfg *cfg);
  280. int q6asm_media_format_block_wma(struct audio_client *ac,
  281. void *cfg);
  282. int q6asm_media_format_block_wmapro(struct audio_client *ac,
  283. void *cfg);
  284. int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
  285. struct asm_amrwbplus_cfg *cfg);
  286. int q6asm_ds1_set_endp_params(struct audio_client *ac,
  287. int param_id, int param_value);
  288. /* PP specific */
  289. int q6asm_equalizer(struct audio_client *ac, void *eq);
  290. /* Send Volume Command */
  291. int q6asm_set_volume(struct audio_client *ac, int volume);
  292. /* Set SoftPause Params */
  293. int q6asm_set_softpause(struct audio_client *ac,
  294. struct asm_softpause_params *param);
  295. /* Set Softvolume Params */
  296. int q6asm_set_softvolume(struct audio_client *ac,
  297. struct asm_softvolume_params *param);
  298. /* Send left-right channel gain */
  299. int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain);
  300. /* Enable Mute/unmute flag */
  301. int q6asm_set_mute(struct audio_client *ac, int muteflag);
  302. int q6asm_get_session_time(struct audio_client *ac, uint64_t *tstamp);
  303. int q6asm_send_audio_effects_params(struct audio_client *ac, char *params,
  304. uint32_t params_length);
  305. /* Client can set the IO mode to either AIO/SIO mode */
  306. int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode);
  307. /* Get Service ID for APR communication */
  308. int q6asm_get_apr_service_id(int session_id);
  309. /* Common format block without any payload
  310. */
  311. int q6asm_media_format_block(struct audio_client *ac, uint32_t format);
  312. /* Send the meta data to remove initial and trailing silence */
  313. int q6asm_send_meta_data(struct audio_client *ac, uint32_t initial_samples,
  314. uint32_t trailing_samples);
  315. int q6asm_set_sa(struct audio_client *ac,int *param);
  316. int q6asm_set_vsp(struct audio_client *ac,int *param);
  317. int q6asm_set_dha(struct audio_client *ac,int *param);
  318. int q6asm_set_lrsm(struct audio_client *ac,int *param);
  319. int q6asm_set_sa_ep(struct audio_client *ac,int *param);
  320. int q6asm_get_sa_ep(struct audio_client *ac);
  321. int q6asm_set_msp(struct audio_client *ac, long *param);
  322. /* Send the stream meta data to remove initial and trailing silence */
  323. int q6asm_stream_send_meta_data(struct audio_client *ac, uint32_t stream_id,
  324. uint32_t initial_samples, uint32_t trailing_samples);
  325. #endif /* __Q6_ASM_H__ */