Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame^] | 1 | /* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -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_H__ |
| 13 | #define __Q6_ASM_H__ |
| 14 | |
| 15 | #include <mach/qdsp6v2/apr.h> |
| 16 | #include <mach/msm_subsystem_map.h> |
| 17 | #include <sound/apr_audio.h> |
| 18 | |
| 19 | #define IN 0x000 |
| 20 | #define OUT 0x001 |
| 21 | #define CH_MODE_MONO 0x001 |
| 22 | #define CH_MODE_STEREO 0x002 |
| 23 | |
| 24 | #define FORMAT_LINEAR_PCM 0x0000 |
| 25 | #define FORMAT_DTMF 0x0001 |
| 26 | #define FORMAT_ADPCM 0x0002 |
| 27 | #define FORMAT_YADPCM 0x0003 |
| 28 | #define FORMAT_MP3 0x0004 |
| 29 | #define FORMAT_MPEG4_AAC 0x0005 |
| 30 | #define FORMAT_AMRNB 0x0006 |
| 31 | #define FORMAT_AMRWB 0x0007 |
| 32 | #define FORMAT_V13K 0x0008 |
| 33 | #define FORMAT_EVRC 0x0009 |
| 34 | #define FORMAT_EVRCB 0x000a |
| 35 | #define FORMAT_EVRCWB 0x000b |
| 36 | #define FORMAT_MIDI 0x000c |
| 37 | #define FORMAT_SBC 0x000d |
| 38 | #define FORMAT_WMA_V10PRO 0x000e |
| 39 | #define FORMAT_WMA_V9 0x000f |
| 40 | #define FORMAT_AMR_WB_PLUS 0x0010 |
Bharath Ramachandramurthy | 4f71d50 | 2011-10-23 19:45:22 -0700 | [diff] [blame] | 41 | #define FORMAT_MPEG4_MULTI_AAC 0x0011 |
Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame^] | 42 | #define FORMAT_MULTI_CHANNEL_LINEAR_PCM 0x0012 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 43 | |
| 44 | #define ENCDEC_SBCBITRATE 0x0001 |
| 45 | #define ENCDEC_IMMEDIATE_DECODE 0x0002 |
| 46 | #define ENCDEC_CFG_BLK 0x0003 |
| 47 | |
| 48 | #define CMD_PAUSE 0x0001 |
| 49 | #define CMD_FLUSH 0x0002 |
| 50 | #define CMD_EOS 0x0003 |
| 51 | #define CMD_CLOSE 0x0004 |
| 52 | #define CMD_OUT_FLUSH 0x0005 |
| 53 | |
| 54 | /* bit 0:1 represents priority of stream */ |
| 55 | #define STREAM_PRIORITY_NORMAL 0x0000 |
| 56 | #define STREAM_PRIORITY_LOW 0x0001 |
| 57 | #define STREAM_PRIORITY_HIGH 0x0002 |
| 58 | |
| 59 | /* bit 4 represents META enable of encoded data buffer */ |
| 60 | #define BUFFER_META_ENABLE 0x0010 |
| 61 | |
| 62 | /* Enable Sample_Rate/Channel_Mode notification event from Decoder */ |
| 63 | #define SR_CM_NOTIFY_ENABLE 0x0004 |
| 64 | |
| 65 | #define ASYNC_IO_MODE 0x0002 |
| 66 | #define SYNC_IO_MODE 0x0001 |
| 67 | #define NO_TIMESTAMP 0xFF00 |
| 68 | #define SET_TIMESTAMP 0x0000 |
| 69 | |
| 70 | #define SOFT_PAUSE_ENABLE 1 |
| 71 | #define SOFT_PAUSE_DISABLE 0 |
| 72 | |
| 73 | #define SESSION_MAX 0x08 |
| 74 | |
Sriranjan Srikantam | 5285a21 | 2011-09-06 19:09:19 -0700 | [diff] [blame] | 75 | #define SOFT_PAUSE_PERIOD 30 /* ramp up/down for 30ms */ |
| 76 | #define SOFT_PAUSE_STEP 2000 /* Step value 2ms or 2000us */ |
| 77 | enum { |
| 78 | SOFT_PAUSE_CURVE_LINEAR = 0, |
| 79 | SOFT_PAUSE_CURVE_EXP, |
| 80 | SOFT_PAUSE_CURVE_LOG, |
| 81 | }; |
| 82 | |
| 83 | #define SOFT_VOLUME_PERIOD 30 /* ramp up/down for 30ms */ |
| 84 | #define SOFT_VOLUME_STEP 2000 /* Step value 2ms or 2000us */ |
| 85 | enum { |
| 86 | SOFT_VOLUME_CURVE_LINEAR = 0, |
| 87 | SOFT_VOLUME_CURVE_EXP, |
| 88 | SOFT_VOLUME_CURVE_LOG, |
| 89 | }; |
| 90 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 91 | typedef void (*app_cb)(uint32_t opcode, uint32_t token, |
| 92 | uint32_t *payload, void *priv); |
| 93 | |
| 94 | struct audio_buffer { |
| 95 | dma_addr_t phys; |
| 96 | void *data; |
| 97 | struct msm_mapped_buffer *mem_buffer; |
| 98 | uint32_t used; |
| 99 | uint32_t size;/* size of buffer */ |
| 100 | uint32_t actual_size; /* actual number of bytes read by DSP */ |
| 101 | }; |
| 102 | |
| 103 | struct audio_aio_write_param { |
| 104 | unsigned long paddr; |
| 105 | uint32_t uid; |
| 106 | uint32_t len; |
| 107 | uint32_t msw_ts; |
| 108 | uint32_t lsw_ts; |
| 109 | uint32_t flags; |
| 110 | }; |
| 111 | |
| 112 | struct audio_aio_read_param { |
| 113 | unsigned long paddr; |
| 114 | uint32_t len; |
| 115 | uint32_t uid; |
| 116 | }; |
| 117 | |
| 118 | struct audio_port_data { |
| 119 | struct audio_buffer *buf; |
| 120 | uint32_t max_buf_cnt; |
| 121 | uint32_t dsp_buf; |
| 122 | uint32_t cpu_buf; |
| 123 | /* read or write locks */ |
| 124 | struct mutex lock; |
| 125 | spinlock_t dsp_lock; |
| 126 | }; |
| 127 | |
| 128 | struct audio_client { |
| 129 | int session; |
| 130 | /* idx:1 out port, 0: in port*/ |
| 131 | struct audio_port_data port[2]; |
| 132 | |
| 133 | struct apr_svc *apr; |
| 134 | struct mutex cmd_lock; |
| 135 | |
| 136 | atomic_t cmd_state; |
| 137 | atomic_t time_flag; |
| 138 | wait_queue_head_t cmd_wait; |
| 139 | wait_queue_head_t time_wait; |
| 140 | |
| 141 | app_cb cb; |
| 142 | void *priv; |
| 143 | uint32_t io_mode; |
| 144 | uint64_t time_stamp; |
| 145 | }; |
| 146 | |
| 147 | void q6asm_audio_client_free(struct audio_client *ac); |
| 148 | |
| 149 | struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv); |
| 150 | |
Ben Romberger | 61754dc | 2011-10-31 18:25:41 -0700 | [diff] [blame] | 151 | struct audio_client *q6asm_get_audio_client(int session_id); |
| 152 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 153 | int q6asm_audio_client_buf_alloc(unsigned int dir/* 1:Out,0:In */, |
| 154 | struct audio_client *ac, |
| 155 | unsigned int bufsz, |
| 156 | unsigned int bufcnt); |
| 157 | int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir |
| 158 | /* 1:Out,0:In */, |
| 159 | struct audio_client *ac, |
| 160 | unsigned int bufsz, |
| 161 | unsigned int bufcnt); |
| 162 | |
| 163 | int q6asm_audio_client_buf_free_contiguous(unsigned int dir, |
| 164 | struct audio_client *ac); |
| 165 | |
| 166 | int q6asm_open_read(struct audio_client *ac, uint32_t format); |
| 167 | |
| 168 | int q6asm_open_write(struct audio_client *ac, uint32_t format); |
| 169 | |
| 170 | int q6asm_open_read_write(struct audio_client *ac, |
| 171 | uint32_t rd_format, |
| 172 | uint32_t wr_format); |
| 173 | |
| 174 | int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts, |
| 175 | uint32_t lsw_ts, uint32_t flags); |
| 176 | int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts, |
| 177 | uint32_t lsw_ts, uint32_t flags); |
| 178 | |
| 179 | int q6asm_async_write(struct audio_client *ac, |
| 180 | struct audio_aio_write_param *param); |
| 181 | |
| 182 | int q6asm_async_read(struct audio_client *ac, |
| 183 | struct audio_aio_read_param *param); |
| 184 | |
| 185 | int q6asm_read(struct audio_client *ac); |
| 186 | int q6asm_read_nolock(struct audio_client *ac); |
| 187 | |
| 188 | int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, |
| 189 | int dir, uint32_t bufsz, uint32_t bufcnt); |
| 190 | |
| 191 | int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, |
| 192 | int dir); |
| 193 | |
| 194 | int q6asm_run(struct audio_client *ac, uint32_t flags, |
| 195 | uint32_t msw_ts, uint32_t lsw_ts); |
| 196 | |
| 197 | int q6asm_run_nowait(struct audio_client *ac, uint32_t flags, |
| 198 | uint32_t msw_ts, uint32_t lsw_ts); |
| 199 | |
| 200 | int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable); |
| 201 | |
| 202 | int q6asm_cmd(struct audio_client *ac, int cmd); |
| 203 | |
| 204 | int q6asm_cmd_nowait(struct audio_client *ac, int cmd); |
| 205 | |
| 206 | void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, |
| 207 | uint32_t *size, uint32_t *idx); |
| 208 | |
Jay Wang | 9cf59a0 | 2011-08-10 16:58:40 -0700 | [diff] [blame] | 209 | void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac, |
| 210 | uint32_t *size, uint32_t *idx); |
| 211 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 212 | int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac); |
| 213 | |
| 214 | /* File format specific configurations to be added below */ |
| 215 | |
| 216 | int q6asm_enc_cfg_blk_aac(struct audio_client *ac, |
| 217 | uint32_t frames_per_buf, |
| 218 | uint32_t sample_rate, uint32_t channels, |
| 219 | uint32_t bit_rate, |
| 220 | uint32_t mode, uint32_t format); |
| 221 | |
| 222 | int q6asm_enc_cfg_blk_pcm(struct audio_client *ac, |
| 223 | uint32_t rate, uint32_t channels); |
| 224 | |
| 225 | int q6asm_enable_sbrps(struct audio_client *ac, |
| 226 | uint32_t sbr_ps); |
| 227 | |
Swaminathan Sathappan | 70765cd | 2011-07-19 18:42:47 -0700 | [diff] [blame] | 228 | int q6asm_cfg_dual_mono_aac(struct audio_client *ac, |
| 229 | uint16_t sce_left, uint16_t sce_right); |
| 230 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 231 | int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf, |
| 232 | uint16_t min_rate, uint16_t max_rate, |
| 233 | uint16_t reduced_rate_level, uint16_t rate_modulation_cmd); |
| 234 | |
| 235 | int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf, |
| 236 | uint16_t min_rate, uint16_t max_rate, |
| 237 | uint16_t rate_modulation_cmd); |
| 238 | |
| 239 | int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf, |
| 240 | uint16_t band_mode, uint16_t dtx_enable); |
| 241 | |
Alex Wong | 2caeecc | 2011-10-28 10:52:15 +0530 | [diff] [blame] | 242 | int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf, |
| 243 | uint16_t band_mode, uint16_t dtx_enable); |
| 244 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 245 | int q6asm_media_format_block_pcm(struct audio_client *ac, |
| 246 | uint32_t rate, uint32_t channels); |
| 247 | |
Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame^] | 248 | int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac, |
| 249 | uint32_t rate, uint32_t channels); |
| 250 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 251 | int q6asm_media_format_block_aac(struct audio_client *ac, |
| 252 | struct asm_aac_cfg *cfg); |
| 253 | |
Bharath Ramachandramurthy | 4f71d50 | 2011-10-23 19:45:22 -0700 | [diff] [blame] | 254 | int q6asm_media_format_block_multi_aac(struct audio_client *ac, |
| 255 | struct asm_aac_cfg *cfg); |
| 256 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 257 | int q6asm_media_format_block_wma(struct audio_client *ac, |
| 258 | void *cfg); |
| 259 | |
| 260 | int q6asm_media_format_block_wmapro(struct audio_client *ac, |
| 261 | void *cfg); |
| 262 | |
| 263 | /* PP specific */ |
| 264 | int q6asm_equalizer(struct audio_client *ac, void *eq); |
| 265 | |
| 266 | /* Send Volume Command */ |
| 267 | int q6asm_set_volume(struct audio_client *ac, int volume); |
| 268 | |
| 269 | /* Set SoftPause Params */ |
| 270 | int q6asm_set_softpause(struct audio_client *ac, |
| 271 | struct asm_softpause_params *param); |
| 272 | |
Swaminathan Sathappan | b0021cd | 2011-08-31 15:20:12 -0700 | [diff] [blame] | 273 | /* Set Softvolume Params */ |
| 274 | int q6asm_set_softvolume(struct audio_client *ac, |
| 275 | struct asm_softvolume_params *param); |
| 276 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 277 | /* Send left-right channel gain */ |
| 278 | int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain); |
| 279 | |
| 280 | /* Enable Mute/unmute flag */ |
| 281 | int q6asm_set_mute(struct audio_client *ac, int muteflag); |
| 282 | |
| 283 | uint64_t q6asm_get_session_time(struct audio_client *ac); |
| 284 | |
| 285 | /* Client can set the IO mode to either AIO/SIO mode */ |
| 286 | int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode); |
| 287 | |
Ben Romberger | 45b351c | 2011-07-20 22:37:27 -0700 | [diff] [blame] | 288 | #ifdef CONFIG_RTAC |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 289 | /* Get Service ID for APR communication */ |
| 290 | int q6asm_get_apr_service_id(int session_id); |
| 291 | #endif |
| 292 | |
Alex Wong | 2caeecc | 2011-10-28 10:52:15 +0530 | [diff] [blame] | 293 | /* Common format block without any payload |
| 294 | */ |
| 295 | int q6asm_media_format_block(struct audio_client *ac, uint32_t format); |
| 296 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 297 | #endif /* __Q6_ASM_H__ */ |