blob: 6420e96ed7bed632a4c2d89d812d822f98c9b88e [file] [log] [blame]
Patrick Lai3aabeae2013-01-06 00:52:34 -08001/* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070016#include <sound/apr_audio.h>
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -080017#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
Mitchel Humpherys76a84982012-09-06 10:22:31 -070018#include <linux/msm_ion.h>
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -080019#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070020
21#define IN 0x000
22#define OUT 0x001
23#define CH_MODE_MONO 0x001
24#define CH_MODE_STEREO 0x002
25
26#define FORMAT_LINEAR_PCM 0x0000
27#define FORMAT_DTMF 0x0001
28#define FORMAT_ADPCM 0x0002
29#define FORMAT_YADPCM 0x0003
30#define FORMAT_MP3 0x0004
31#define FORMAT_MPEG4_AAC 0x0005
32#define FORMAT_AMRNB 0x0006
33#define FORMAT_AMRWB 0x0007
34#define FORMAT_V13K 0x0008
35#define FORMAT_EVRC 0x0009
36#define FORMAT_EVRCB 0x000a
37#define FORMAT_EVRCWB 0x000b
38#define FORMAT_MIDI 0x000c
39#define FORMAT_SBC 0x000d
40#define FORMAT_WMA_V10PRO 0x000e
41#define FORMAT_WMA_V9 0x000f
42#define FORMAT_AMR_WB_PLUS 0x0010
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -070043#define FORMAT_MPEG4_MULTI_AAC 0x0011
Kiran Kandi5e809b02012-01-31 00:24:33 -080044#define FORMAT_MULTI_CHANNEL_LINEAR_PCM 0x0012
Santosh Mardi23321202012-03-22 04:33:25 +053045#define FORMAT_AC3 0x0013
46#define FORMAT_DTS 0x0014
47#define FORMAT_EAC3 0x0015
48#define FORMAT_ATRAC 0x0016
49#define FORMAT_MAT 0x0017
50#define FORMAT_AAC 0x0018
Srikanth Uyyala66f781a2012-06-13 23:23:25 +053051#define FORMAT_DTS_LBR 0x0019
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070052
53#define ENCDEC_SBCBITRATE 0x0001
54#define ENCDEC_IMMEDIATE_DECODE 0x0002
55#define ENCDEC_CFG_BLK 0x0003
56
57#define CMD_PAUSE 0x0001
58#define CMD_FLUSH 0x0002
59#define CMD_EOS 0x0003
60#define CMD_CLOSE 0x0004
61#define CMD_OUT_FLUSH 0x0005
62
63/* bit 0:1 represents priority of stream */
64#define STREAM_PRIORITY_NORMAL 0x0000
65#define STREAM_PRIORITY_LOW 0x0001
66#define STREAM_PRIORITY_HIGH 0x0002
67
68/* bit 4 represents META enable of encoded data buffer */
69#define BUFFER_META_ENABLE 0x0010
70
71/* Enable Sample_Rate/Channel_Mode notification event from Decoder */
72#define SR_CM_NOTIFY_ENABLE 0x0004
73
Patrick Lai55f54c52012-11-17 00:29:07 -080074#define TUN_WRITE_IO_MODE 0x0008 /* tunnel read write mode */
75#define TUN_READ_IO_MODE 0x0004 /* tunnel read write mode */
76#define ASYNC_IO_MODE 0x0002
77#define SYNC_IO_MODE 0x0001
78#define NO_TIMESTAMP 0xFF00
79#define SET_TIMESTAMP 0x0000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070080
81#define SOFT_PAUSE_ENABLE 1
82#define SOFT_PAUSE_DISABLE 0
83
84#define SESSION_MAX 0x08
85
Fred Oha3720ae2013-01-18 15:58:29 -080086#define SOFT_PAUSE_PERIOD 30 /* ramp up/down for 30ms */
Deepa Madiregama623b5932012-05-22 14:44:33 +053087#define SOFT_PAUSE_STEP_LINEAR 0 /* Step value 0ms or 0us */
Fred Oha3720ae2013-01-18 15:58:29 -080088#define SOFT_PAUSE_STEP 0 /* Step value 0ms or 0us */
Sriranjan Srikantam5285a212011-09-06 19:09:19 -070089enum {
90 SOFT_PAUSE_CURVE_LINEAR = 0,
91 SOFT_PAUSE_CURVE_EXP,
92 SOFT_PAUSE_CURVE_LOG,
93};
94
Fred Oha3720ae2013-01-18 15:58:29 -080095#define SOFT_VOLUME_PERIOD 30 /* ramp up/down for 30ms */
Deepa Madiregama623b5932012-05-22 14:44:33 +053096#define SOFT_VOLUME_STEP_LINEAR 0 /* Step value 0ms or 0us */
Fred Oha3720ae2013-01-18 15:58:29 -080097#define SOFT_VOLUME_STEP 0 /* Step value 0ms or 0us */
Sriranjan Srikantam5285a212011-09-06 19:09:19 -070098enum {
99 SOFT_VOLUME_CURVE_LINEAR = 0,
100 SOFT_VOLUME_CURVE_EXP,
101 SOFT_VOLUME_CURVE_LOG,
102};
103
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700104typedef void (*app_cb)(uint32_t opcode, uint32_t token,
105 uint32_t *payload, void *priv);
106
107struct audio_buffer {
108 dma_addr_t phys;
109 void *data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700110 uint32_t used;
111 uint32_t size;/* size of buffer */
112 uint32_t actual_size; /* actual number of bytes read by DSP */
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800113#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
114 struct ion_handle *handle;
115 struct ion_client *client;
116#else
Laura Abbottea3e7b62012-04-30 15:59:21 -0700117 void *mem_buffer;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800118#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700119};
120
121struct audio_aio_write_param {
122 unsigned long paddr;
123 uint32_t uid;
124 uint32_t len;
125 uint32_t msw_ts;
126 uint32_t lsw_ts;
127 uint32_t flags;
128};
129
130struct audio_aio_read_param {
131 unsigned long paddr;
132 uint32_t len;
133 uint32_t uid;
134};
135
136struct audio_port_data {
137 struct audio_buffer *buf;
138 uint32_t max_buf_cnt;
139 uint32_t dsp_buf;
140 uint32_t cpu_buf;
141 /* read or write locks */
142 struct mutex lock;
143 spinlock_t dsp_lock;
144};
145
146struct audio_client {
147 int session;
148 /* idx:1 out port, 0: in port*/
149 struct audio_port_data port[2];
150
151 struct apr_svc *apr;
152 struct mutex cmd_lock;
153
154 atomic_t cmd_state;
Laxminath Kasamf16d3fd2012-12-19 14:54:14 +0530155 atomic_t cmd_close_state;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700156 atomic_t time_flag;
Jay Wang0668d1062012-07-11 18:53:21 -0700157 atomic_t nowait_cmd_cnt;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700158 wait_queue_head_t cmd_wait;
159 wait_queue_head_t time_wait;
160
161 app_cb cb;
162 void *priv;
163 uint32_t io_mode;
164 uint64_t time_stamp;
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530165 atomic_t cmd_response;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700166 bool perf_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700167};
168
169void q6asm_audio_client_free(struct audio_client *ac);
170
171struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv);
172
Ben Romberger61754dc2011-10-31 18:25:41 -0700173struct audio_client *q6asm_get_audio_client(int session_id);
174
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700175int q6asm_audio_client_buf_alloc(unsigned int dir/* 1:Out,0:In */,
176 struct audio_client *ac,
177 unsigned int bufsz,
178 unsigned int bufcnt);
179int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir
180 /* 1:Out,0:In */,
181 struct audio_client *ac,
182 unsigned int bufsz,
183 unsigned int bufcnt);
184
185int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
186 struct audio_client *ac);
187
188int q6asm_open_read(struct audio_client *ac, uint32_t format);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700189int q6asm_open_read_v2_1(struct audio_client *ac, uint32_t format);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700190
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -0700191int q6asm_open_read_compressed(struct audio_client *ac,
192 uint32_t frames_per_buffer, uint32_t meta_data_mode);
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700193
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700194int q6asm_open_write(struct audio_client *ac, uint32_t format);
195
Santosh Mardi23321202012-03-22 04:33:25 +0530196int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format);
197
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700198int q6asm_open_read_write(struct audio_client *ac,
199 uint32_t rd_format,
200 uint32_t wr_format);
201
Laxminath Kasam20824502013-01-07 14:33:56 +0530202int q6asm_open_loopack(struct audio_client *ac);
203
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700204int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
205 uint32_t lsw_ts, uint32_t flags);
206int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
207 uint32_t lsw_ts, uint32_t flags);
208
209int q6asm_async_write(struct audio_client *ac,
210 struct audio_aio_write_param *param);
211
212int q6asm_async_read(struct audio_client *ac,
213 struct audio_aio_read_param *param);
214
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -0700215int q6asm_async_read_compressed(struct audio_client *ac,
216 struct audio_aio_read_param *param);
217
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700218int q6asm_read(struct audio_client *ac);
219int q6asm_read_nolock(struct audio_client *ac);
220
221int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add,
222 int dir, uint32_t bufsz, uint32_t bufcnt);
223
224int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add,
225 int dir);
226
227int q6asm_run(struct audio_client *ac, uint32_t flags,
228 uint32_t msw_ts, uint32_t lsw_ts);
229
230int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
231 uint32_t msw_ts, uint32_t lsw_ts);
232
233int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable);
234
235int q6asm_cmd(struct audio_client *ac, int cmd);
236
237int q6asm_cmd_nowait(struct audio_client *ac, int cmd);
238
239void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac,
240 uint32_t *size, uint32_t *idx);
241
Jay Wang9cf59a02011-08-10 16:58:40 -0700242void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
243 uint32_t *size, uint32_t *idx);
244
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700245int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac);
246
247/* File format specific configurations to be added below */
248
249int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
250 uint32_t frames_per_buf,
251 uint32_t sample_rate, uint32_t channels,
252 uint32_t bit_rate,
253 uint32_t mode, uint32_t format);
254
255int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
256 uint32_t rate, uint32_t channels);
257
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700258int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
259 uint32_t rate, uint32_t channels);
260
Mingming Yin647e9ea2012-03-17 19:56:10 -0700261int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
262 uint32_t rate, uint32_t channels);
263
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700264int q6asm_enable_sbrps(struct audio_client *ac,
265 uint32_t sbr_ps);
266
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -0700267int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
268 uint16_t sce_left, uint16_t sce_right);
269
Amal Paul6e0f7982013-02-21 19:36:35 -0800270int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff);
271
Swaminathan Sathappan6f530882012-05-01 16:42:22 -0700272int q6asm_set_encdec_chan_map(struct audio_client *ac,
273 uint32_t num_channels);
274
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700275int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
276 uint16_t min_rate, uint16_t max_rate,
277 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd);
278
279int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
280 uint16_t min_rate, uint16_t max_rate,
281 uint16_t rate_modulation_cmd);
282
283int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
284 uint16_t band_mode, uint16_t dtx_enable);
285
Alex Wong2caeecc2011-10-28 10:52:15 +0530286int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
287 uint16_t band_mode, uint16_t dtx_enable);
288
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700289int q6asm_media_format_block_pcm(struct audio_client *ac,
290 uint32_t rate, uint32_t channels);
291
Kiran Kandi5e809b02012-01-31 00:24:33 -0800292int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
293 uint32_t rate, uint32_t channels);
294
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700295int q6asm_media_format_block_aac(struct audio_client *ac,
296 struct asm_aac_cfg *cfg);
297
Ajit Khare43fd8832012-08-07 13:19:44 -0700298int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
299 struct asm_amrwbplus_cfg *cfg);
300
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -0700301int q6asm_media_format_block_multi_aac(struct audio_client *ac,
302 struct asm_aac_cfg *cfg);
303
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700304int q6asm_media_format_block_wma(struct audio_client *ac,
305 void *cfg);
306
307int q6asm_media_format_block_wmapro(struct audio_client *ac,
308 void *cfg);
309
310/* PP specific */
311int q6asm_equalizer(struct audio_client *ac, void *eq);
312
313/* Send Volume Command */
314int q6asm_set_volume(struct audio_client *ac, int volume);
315
316/* Set SoftPause Params */
317int q6asm_set_softpause(struct audio_client *ac,
318 struct asm_softpause_params *param);
319
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -0700320/* Set Softvolume Params */
321int q6asm_set_softvolume(struct audio_client *ac,
322 struct asm_softvolume_params *param);
323
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700324/* Send left-right channel gain */
325int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain);
326
327/* Enable Mute/unmute flag */
328int q6asm_set_mute(struct audio_client *ac, int muteflag);
329
Patrick Lai3aabeae2013-01-06 00:52:34 -0800330int q6asm_get_session_time(struct audio_client *ac, uint64_t *tstamp);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700331
332/* Client can set the IO mode to either AIO/SIO mode */
333int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode);
334
Ben Romberger45b351c2011-07-20 22:37:27 -0700335#ifdef CONFIG_RTAC
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700336/* Get Service ID for APR communication */
337int q6asm_get_apr_service_id(int session_id);
338#endif
339
Alex Wong2caeecc2011-10-28 10:52:15 +0530340/* Common format block without any payload
341*/
342int q6asm_media_format_block(struct audio_client *ac, uint32_t format);
343
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700344#endif /* __Q6_ASM_H__ */