Subhash Chandra Bose Naripeddy | e656216 | 2012-12-12 15:11:38 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 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 | |
| 15 | #include <mach/qdsp6v2/apr.h> |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 16 | #include <sound/apr_audio-v2.h> |
| 17 | #include <linux/list.h> |
Mitchel Humpherys | 71a6ac9 | 2012-09-06 10:22:31 -0700 | [diff] [blame] | 18 | #include <linux/msm_ion.h> |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 19 | |
| 20 | #define IN 0x000 |
| 21 | #define OUT 0x001 |
| 22 | #define CH_MODE_MONO 0x001 |
| 23 | #define CH_MODE_STEREO 0x002 |
| 24 | |
| 25 | #define FORMAT_LINEAR_PCM 0x0000 |
| 26 | #define FORMAT_DTMF 0x0001 |
| 27 | #define FORMAT_ADPCM 0x0002 |
| 28 | #define FORMAT_YADPCM 0x0003 |
| 29 | #define FORMAT_MP3 0x0004 |
| 30 | #define FORMAT_MPEG4_AAC 0x0005 |
| 31 | #define FORMAT_AMRNB 0x0006 |
| 32 | #define FORMAT_AMRWB 0x0007 |
| 33 | #define FORMAT_V13K 0x0008 |
| 34 | #define FORMAT_EVRC 0x0009 |
| 35 | #define FORMAT_EVRCB 0x000a |
| 36 | #define FORMAT_EVRCWB 0x000b |
| 37 | #define FORMAT_MIDI 0x000c |
| 38 | #define FORMAT_SBC 0x000d |
| 39 | #define FORMAT_WMA_V10PRO 0x000e |
| 40 | #define FORMAT_WMA_V9 0x000f |
| 41 | #define FORMAT_AMR_WB_PLUS 0x0010 |
| 42 | #define FORMAT_MPEG4_MULTI_AAC 0x0011 |
| 43 | #define FORMAT_MULTI_CHANNEL_LINEAR_PCM 0x0012 |
Subhash Chandra Bose Naripeddy | af3e03d | 2013-02-08 11:35:55 -0800 | [diff] [blame] | 44 | #define FORMAT_AC3 0x0013 |
| 45 | #define FORMAT_EAC3 0x0014 |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 46 | |
| 47 | #define ENCDEC_SBCBITRATE 0x0001 |
| 48 | #define ENCDEC_IMMEDIATE_DECODE 0x0002 |
| 49 | #define ENCDEC_CFG_BLK 0x0003 |
| 50 | |
| 51 | #define CMD_PAUSE 0x0001 |
| 52 | #define CMD_FLUSH 0x0002 |
| 53 | #define CMD_EOS 0x0003 |
| 54 | #define CMD_CLOSE 0x0004 |
| 55 | #define CMD_OUT_FLUSH 0x0005 |
| 56 | |
| 57 | /* bit 0:1 represents priority of stream */ |
| 58 | #define STREAM_PRIORITY_NORMAL 0x0000 |
| 59 | #define STREAM_PRIORITY_LOW 0x0001 |
| 60 | #define STREAM_PRIORITY_HIGH 0x0002 |
| 61 | |
| 62 | /* bit 4 represents META enable of encoded data buffer */ |
| 63 | #define BUFFER_META_ENABLE 0x0010 |
| 64 | |
| 65 | /* Enable Sample_Rate/Channel_Mode notification event from Decoder */ |
| 66 | #define SR_CM_NOTIFY_ENABLE 0x0004 |
| 67 | |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 68 | #define SYNC_IO_MODE 0x0001 |
Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 69 | #define ASYNC_IO_MODE 0x0002 |
Phani Kumar Uppalapati | f3c5fac | 2012-10-13 15:27:23 -0700 | [diff] [blame] | 70 | #define COMPRESSED_IO 0x0040 |
Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 71 | #define NT_MODE 0x0400 |
| 72 | |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 73 | #define NO_TIMESTAMP 0xFF00 |
| 74 | #define SET_TIMESTAMP 0x0000 |
| 75 | |
| 76 | #define SOFT_PAUSE_ENABLE 1 |
| 77 | #define SOFT_PAUSE_DISABLE 0 |
| 78 | |
| 79 | #define SESSION_MAX 0x08 |
| 80 | |
Krishnankutty Kolathappilly | 05c7bd9 | 2013-04-27 23:34:53 -0700 | [diff] [blame] | 81 | /* payload structure bytes */ |
| 82 | #define READDONE_IDX_STATUS 0 |
| 83 | #define READDONE_IDX_BUFADD_LSW 1 |
| 84 | #define READDONE_IDX_BUFADD_MSW 2 |
| 85 | #define READDONE_IDX_MEMMAP_HDL 3 |
| 86 | #define READDONE_IDX_SIZE 4 |
| 87 | #define READDONE_IDX_OFFSET 5 |
| 88 | #define READDONE_IDX_LSW_TS 6 |
| 89 | #define READDONE_IDX_MSW_TS 7 |
| 90 | #define READDONE_IDX_FLAGS 8 |
| 91 | #define READDONE_IDX_NUMFRAMES 9 |
| 92 | #define READDONE_IDX_SEQ_ID 10 |
| 93 | |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 94 | #define SOFT_PAUSE_PERIOD 30 /* ramp up/down for 30ms */ |
| 95 | #define SOFT_PAUSE_STEP 2000 /* Step value 2ms or 2000us */ |
| 96 | enum { |
| 97 | SOFT_PAUSE_CURVE_LINEAR = 0, |
| 98 | SOFT_PAUSE_CURVE_EXP, |
| 99 | SOFT_PAUSE_CURVE_LOG, |
| 100 | }; |
| 101 | |
| 102 | #define SOFT_VOLUME_PERIOD 30 /* ramp up/down for 30ms */ |
| 103 | #define SOFT_VOLUME_STEP 2000 /* Step value 2ms or 2000us */ |
| 104 | enum { |
| 105 | SOFT_VOLUME_CURVE_LINEAR = 0, |
| 106 | SOFT_VOLUME_CURVE_EXP, |
| 107 | SOFT_VOLUME_CURVE_LOG, |
| 108 | }; |
| 109 | |
| 110 | typedef void (*app_cb)(uint32_t opcode, uint32_t token, |
| 111 | uint32_t *payload, void *priv); |
| 112 | |
| 113 | struct audio_buffer { |
| 114 | dma_addr_t phys; |
| 115 | void *data; |
| 116 | uint32_t used; |
| 117 | uint32_t size;/* size of buffer */ |
| 118 | uint32_t actual_size; /* actual number of bytes read by DSP */ |
| 119 | struct ion_handle *handle; |
| 120 | struct ion_client *client; |
| 121 | }; |
| 122 | |
| 123 | struct audio_aio_write_param { |
| 124 | unsigned long paddr; |
| 125 | uint32_t len; |
| 126 | uint32_t uid; |
| 127 | uint32_t lsw_ts; |
| 128 | uint32_t msw_ts; |
| 129 | uint32_t flags; |
| 130 | }; |
| 131 | |
| 132 | struct audio_aio_read_param { |
| 133 | unsigned long paddr; |
| 134 | uint32_t len; |
| 135 | uint32_t uid; |
| 136 | }; |
| 137 | |
| 138 | struct audio_port_data { |
| 139 | struct audio_buffer *buf; |
| 140 | uint32_t max_buf_cnt; |
| 141 | uint32_t dsp_buf; |
| 142 | uint32_t cpu_buf; |
| 143 | struct list_head mem_map_handle; |
| 144 | uint32_t tmp_hdl; |
| 145 | /* read or write locks */ |
| 146 | struct mutex lock; |
| 147 | spinlock_t dsp_lock; |
| 148 | }; |
| 149 | |
| 150 | struct audio_client { |
| 151 | int session; |
| 152 | app_cb cb; |
| 153 | atomic_t cmd_state; |
| 154 | /* Relative or absolute TS */ |
Phani Kumar Uppalapati | c268df7 | 2013-02-19 19:06:41 -0800 | [diff] [blame] | 155 | atomic_t time_flag; |
Phani Kumar Uppalapati | 70a5d13 | 2012-12-05 11:35:13 -0800 | [diff] [blame] | 156 | atomic_t nowait_cmd_cnt; |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 157 | void *priv; |
| 158 | uint32_t io_mode; |
| 159 | uint64_t time_stamp; |
| 160 | struct apr_svc *apr; |
| 161 | struct apr_svc *mmap_apr; |
| 162 | struct mutex cmd_lock; |
| 163 | /* idx:1 out port, 0: in port*/ |
| 164 | struct audio_port_data port[2]; |
| 165 | wait_queue_head_t cmd_wait; |
Phani Kumar Uppalapati | c268df7 | 2013-02-19 19:06:41 -0800 | [diff] [blame] | 166 | wait_queue_head_t time_wait; |
Phani Kumar Uppalapati | 85b7c9b | 2013-02-19 09:59:47 -0800 | [diff] [blame] | 167 | bool perf_mode; |
Fred Oh | c274a7a | 2013-03-25 13:59:17 -0700 | [diff] [blame] | 168 | /* audio cache operations fptr*/ |
| 169 | int (*fptr_cache_ops)(struct audio_buffer *abuff, int cache_op); |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | void q6asm_audio_client_free(struct audio_client *ac); |
| 173 | |
| 174 | struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv); |
| 175 | |
| 176 | struct audio_client *q6asm_get_audio_client(int session_id); |
| 177 | |
| 178 | int q6asm_audio_client_buf_alloc(unsigned int dir/* 1:Out,0:In */, |
| 179 | struct audio_client *ac, |
| 180 | unsigned int bufsz, |
| 181 | unsigned int bufcnt); |
| 182 | int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir |
| 183 | /* 1:Out,0:In */, |
| 184 | struct audio_client *ac, |
| 185 | unsigned int bufsz, |
| 186 | unsigned int bufcnt); |
| 187 | |
| 188 | int q6asm_audio_client_buf_free_contiguous(unsigned int dir, |
| 189 | struct audio_client *ac); |
| 190 | |
| 191 | int q6asm_open_read(struct audio_client *ac, uint32_t format |
| 192 | /*, uint16_t bits_per_sample*/); |
| 193 | |
| 194 | int q6asm_open_write(struct audio_client *ac, uint32_t format |
| 195 | /*, uint16_t bits_per_sample*/); |
| 196 | |
Bhalchandra Gajare | 5b40c53 | 2013-02-19 13:36:47 -0800 | [diff] [blame] | 197 | int q6asm_open_write_v2(struct audio_client *ac, uint32_t format, |
| 198 | uint16_t bits_per_sample); |
| 199 | |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 200 | int q6asm_open_read_write(struct audio_client *ac, |
| 201 | uint32_t rd_format, |
| 202 | uint32_t wr_format); |
| 203 | |
| 204 | int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts, |
| 205 | uint32_t lsw_ts, uint32_t flags); |
| 206 | int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts, |
| 207 | uint32_t lsw_ts, uint32_t flags); |
| 208 | |
| 209 | int q6asm_async_write(struct audio_client *ac, |
| 210 | struct audio_aio_write_param *param); |
| 211 | |
| 212 | int q6asm_async_read(struct audio_client *ac, |
| 213 | struct audio_aio_read_param *param); |
| 214 | |
| 215 | int q6asm_read(struct audio_client *ac); |
| 216 | int q6asm_read_nolock(struct audio_client *ac); |
| 217 | |
| 218 | int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, |
| 219 | int dir, uint32_t bufsz, uint32_t bufcnt); |
| 220 | |
| 221 | int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, |
| 222 | int dir); |
| 223 | |
| 224 | int q6asm_run(struct audio_client *ac, uint32_t flags, |
| 225 | uint32_t msw_ts, uint32_t lsw_ts); |
| 226 | |
| 227 | int q6asm_run_nowait(struct audio_client *ac, uint32_t flags, |
| 228 | uint32_t msw_ts, uint32_t lsw_ts); |
| 229 | |
| 230 | int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable); |
| 231 | |
| 232 | int q6asm_cmd(struct audio_client *ac, int cmd); |
| 233 | |
| 234 | int q6asm_cmd_nowait(struct audio_client *ac, int cmd); |
| 235 | |
| 236 | void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, |
| 237 | uint32_t *size, uint32_t *idx); |
| 238 | |
| 239 | void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac, |
| 240 | uint32_t *size, uint32_t *idx); |
| 241 | |
| 242 | int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac); |
| 243 | |
| 244 | /* File format specific configurations to be added below */ |
| 245 | |
| 246 | int q6asm_enc_cfg_blk_aac(struct audio_client *ac, |
| 247 | uint32_t frames_per_buf, |
| 248 | uint32_t sample_rate, uint32_t channels, |
| 249 | uint32_t bit_rate, |
| 250 | uint32_t mode, uint32_t format); |
| 251 | |
| 252 | int q6asm_enc_cfg_blk_pcm(struct audio_client *ac, |
| 253 | uint32_t rate, uint32_t channels); |
| 254 | |
| 255 | int q6asm_set_encdec_chan_map(struct audio_client *ac, |
| 256 | uint32_t num_channels); |
| 257 | |
Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 258 | int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac, |
| 259 | uint32_t rate, uint32_t channels); |
| 260 | |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 261 | int q6asm_enable_sbrps(struct audio_client *ac, |
| 262 | uint32_t sbr_ps); |
| 263 | |
| 264 | int q6asm_cfg_dual_mono_aac(struct audio_client *ac, |
| 265 | uint16_t sce_left, uint16_t sce_right); |
| 266 | |
Amal Paul | 2ca061b | 2013-02-25 14:57:33 -0800 | [diff] [blame] | 267 | int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff); |
| 268 | |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 269 | int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf, |
| 270 | uint16_t min_rate, uint16_t max_rate, |
| 271 | uint16_t reduced_rate_level, uint16_t rate_modulation_cmd); |
| 272 | |
| 273 | int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf, |
| 274 | uint16_t min_rate, uint16_t max_rate, |
| 275 | uint16_t rate_modulation_cmd); |
| 276 | |
| 277 | int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf, |
| 278 | uint16_t band_mode, uint16_t dtx_enable); |
| 279 | |
| 280 | int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf, |
| 281 | uint16_t band_mode, uint16_t dtx_enable); |
| 282 | |
| 283 | int q6asm_media_format_block_pcm(struct audio_client *ac, |
| 284 | uint32_t rate, uint32_t channels); |
| 285 | |
Bhalchandra Gajare | 5b40c53 | 2013-02-19 13:36:47 -0800 | [diff] [blame] | 286 | int q6asm_media_format_block_pcm_format_support(struct audio_client *ac, |
| 287 | uint32_t rate, uint32_t channels, |
| 288 | uint16_t bits_per_sample); |
| 289 | |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 290 | int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac, |
Subhash Chandra Bose Naripeddy | e656216 | 2012-12-12 15:11:38 -0800 | [diff] [blame] | 291 | uint32_t rate, uint32_t channels, |
| 292 | bool use_default_chmap, char *channel_map); |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 293 | |
Bhalchandra Gajare | 5b40c53 | 2013-02-19 13:36:47 -0800 | [diff] [blame] | 294 | int q6asm_media_format_block_multi_ch_pcm_v2( |
| 295 | struct audio_client *ac, |
| 296 | uint32_t rate, uint32_t channels, |
| 297 | bool use_default_chmap, char *channel_map, |
| 298 | uint16_t bits_per_sample); |
| 299 | |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 300 | int q6asm_media_format_block_aac(struct audio_client *ac, |
| 301 | struct asm_aac_cfg *cfg); |
| 302 | |
| 303 | int q6asm_media_format_block_multi_aac(struct audio_client *ac, |
| 304 | struct asm_aac_cfg *cfg); |
| 305 | |
| 306 | int q6asm_media_format_block_wma(struct audio_client *ac, |
| 307 | void *cfg); |
| 308 | |
| 309 | int q6asm_media_format_block_wmapro(struct audio_client *ac, |
| 310 | void *cfg); |
| 311 | |
Phani Kumar Uppalapati | 1e0324c | 2013-03-21 14:13:23 -0700 | [diff] [blame] | 312 | int q6asm_media_format_block_amrwbplus(struct audio_client *ac, |
| 313 | struct asm_amrwbplus_cfg *cfg); |
Subhash Chandra Bose Naripeddy | af3e03d | 2013-02-08 11:35:55 -0800 | [diff] [blame] | 314 | |
| 315 | int q6asm_ds1_set_endp_params(struct audio_client *ac, |
| 316 | int param_id, int param_value); |
| 317 | |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 318 | /* PP specific */ |
| 319 | int q6asm_equalizer(struct audio_client *ac, void *eq); |
| 320 | |
| 321 | /* Send Volume Command */ |
| 322 | int q6asm_set_volume(struct audio_client *ac, int volume); |
| 323 | |
| 324 | /* Set SoftPause Params */ |
| 325 | int q6asm_set_softpause(struct audio_client *ac, |
| 326 | struct asm_softpause_params *param); |
| 327 | |
| 328 | /* Set Softvolume Params */ |
| 329 | int q6asm_set_softvolume(struct audio_client *ac, |
| 330 | struct asm_softvolume_params *param); |
| 331 | |
| 332 | /* Send left-right channel gain */ |
| 333 | int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain); |
| 334 | |
| 335 | /* Enable Mute/unmute flag */ |
| 336 | int q6asm_set_mute(struct audio_client *ac, int muteflag); |
| 337 | |
Patrick Lai | fc8f224 | 2013-01-06 00:52:34 -0800 | [diff] [blame] | 338 | int q6asm_get_session_time(struct audio_client *ac, uint64_t *tstamp); |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 339 | |
| 340 | /* Client can set the IO mode to either AIO/SIO mode */ |
| 341 | int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode); |
| 342 | |
| 343 | /* Get Service ID for APR communication */ |
| 344 | int q6asm_get_apr_service_id(int session_id); |
| 345 | |
| 346 | /* Common format block without any payload |
| 347 | */ |
| 348 | int q6asm_media_format_block(struct audio_client *ac, uint32_t format); |
| 349 | |
| 350 | #endif /* __Q6_ASM_H__ */ |