blob: 7ef15ac029cc3c23714748cd9342f67aac3fc2f6 [file] [log] [blame]
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001/* Copyright (c) 2012, Code Aurora Forum. 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
15#include <mach/qdsp6v2/apr.h>
16#include <mach/msm_subsystem_map.h>
17#include <sound/apr_audio-v2.h>
18#include <linux/list.h>
19#include <linux/ion.h>
20
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
43#define FORMAT_MPEG4_MULTI_AAC 0x0011
44#define FORMAT_MULTI_CHANNEL_LINEAR_PCM 0x0012
45
46#define ENCDEC_SBCBITRATE 0x0001
47#define ENCDEC_IMMEDIATE_DECODE 0x0002
48#define ENCDEC_CFG_BLK 0x0003
49
50#define CMD_PAUSE 0x0001
51#define CMD_FLUSH 0x0002
52#define CMD_EOS 0x0003
53#define CMD_CLOSE 0x0004
54#define CMD_OUT_FLUSH 0x0005
55
56/* bit 0:1 represents priority of stream */
57#define STREAM_PRIORITY_NORMAL 0x0000
58#define STREAM_PRIORITY_LOW 0x0001
59#define STREAM_PRIORITY_HIGH 0x0002
60
61/* bit 4 represents META enable of encoded data buffer */
62#define BUFFER_META_ENABLE 0x0010
63
64/* Enable Sample_Rate/Channel_Mode notification event from Decoder */
65#define SR_CM_NOTIFY_ENABLE 0x0004
66
67#define ASYNC_IO_MODE 0x0002
68#define SYNC_IO_MODE 0x0001
69#define NO_TIMESTAMP 0xFF00
70#define SET_TIMESTAMP 0x0000
71
72#define SOFT_PAUSE_ENABLE 1
73#define SOFT_PAUSE_DISABLE 0
74
75#define SESSION_MAX 0x08
76
77#define SOFT_PAUSE_PERIOD 30 /* ramp up/down for 30ms */
78#define SOFT_PAUSE_STEP 2000 /* Step value 2ms or 2000us */
79enum {
80 SOFT_PAUSE_CURVE_LINEAR = 0,
81 SOFT_PAUSE_CURVE_EXP,
82 SOFT_PAUSE_CURVE_LOG,
83};
84
85#define SOFT_VOLUME_PERIOD 30 /* ramp up/down for 30ms */
86#define SOFT_VOLUME_STEP 2000 /* Step value 2ms or 2000us */
87enum {
88 SOFT_VOLUME_CURVE_LINEAR = 0,
89 SOFT_VOLUME_CURVE_EXP,
90 SOFT_VOLUME_CURVE_LOG,
91};
92
93typedef void (*app_cb)(uint32_t opcode, uint32_t token,
94 uint32_t *payload, void *priv);
95
96struct audio_buffer {
97 dma_addr_t phys;
98 void *data;
99 uint32_t used;
100 uint32_t size;/* size of buffer */
101 uint32_t actual_size; /* actual number of bytes read by DSP */
102 struct ion_handle *handle;
103 struct ion_client *client;
104};
105
106struct audio_aio_write_param {
107 unsigned long paddr;
108 uint32_t len;
109 uint32_t uid;
110 uint32_t lsw_ts;
111 uint32_t msw_ts;
112 uint32_t flags;
113};
114
115struct audio_aio_read_param {
116 unsigned long paddr;
117 uint32_t len;
118 uint32_t uid;
119};
120
121struct 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 struct list_head mem_map_handle;
127 uint32_t tmp_hdl;
128 /* read or write locks */
129 struct mutex lock;
130 spinlock_t dsp_lock;
131};
132
133struct audio_client {
134 int session;
135 app_cb cb;
136 atomic_t cmd_state;
137 /* Relative or absolute TS */
138 uint32_t time_flag;
139 void *priv;
140 uint32_t io_mode;
141 uint64_t time_stamp;
142 struct apr_svc *apr;
143 struct apr_svc *mmap_apr;
144 struct mutex cmd_lock;
145 /* idx:1 out port, 0: in port*/
146 struct audio_port_data port[2];
147 wait_queue_head_t cmd_wait;
148};
149
150void q6asm_audio_client_free(struct audio_client *ac);
151
152struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv);
153
154struct audio_client *q6asm_get_audio_client(int session_id);
155
156int q6asm_audio_client_buf_alloc(unsigned int dir/* 1:Out,0:In */,
157 struct audio_client *ac,
158 unsigned int bufsz,
159 unsigned int bufcnt);
160int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir
161 /* 1:Out,0:In */,
162 struct audio_client *ac,
163 unsigned int bufsz,
164 unsigned int bufcnt);
165
166int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
167 struct audio_client *ac);
168
169int q6asm_open_read(struct audio_client *ac, uint32_t format
170 /*, uint16_t bits_per_sample*/);
171
172int q6asm_open_write(struct audio_client *ac, uint32_t format
173 /*, uint16_t bits_per_sample*/);
174
175int q6asm_open_read_write(struct audio_client *ac,
176 uint32_t rd_format,
177 uint32_t wr_format);
178
179int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
180 uint32_t lsw_ts, uint32_t flags);
181int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
182 uint32_t lsw_ts, uint32_t flags);
183
184int q6asm_async_write(struct audio_client *ac,
185 struct audio_aio_write_param *param);
186
187int q6asm_async_read(struct audio_client *ac,
188 struct audio_aio_read_param *param);
189
190int q6asm_read(struct audio_client *ac);
191int q6asm_read_nolock(struct audio_client *ac);
192
193int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add,
194 int dir, uint32_t bufsz, uint32_t bufcnt);
195
196int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add,
197 int dir);
198
199int q6asm_run(struct audio_client *ac, uint32_t flags,
200 uint32_t msw_ts, uint32_t lsw_ts);
201
202int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
203 uint32_t msw_ts, uint32_t lsw_ts);
204
205int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable);
206
207int q6asm_cmd(struct audio_client *ac, int cmd);
208
209int q6asm_cmd_nowait(struct audio_client *ac, int cmd);
210
211void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac,
212 uint32_t *size, uint32_t *idx);
213
214void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
215 uint32_t *size, uint32_t *idx);
216
217int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac);
218
219/* File format specific configurations to be added below */
220
221int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
222 uint32_t frames_per_buf,
223 uint32_t sample_rate, uint32_t channels,
224 uint32_t bit_rate,
225 uint32_t mode, uint32_t format);
226
227int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
228 uint32_t rate, uint32_t channels);
229
230int q6asm_set_encdec_chan_map(struct audio_client *ac,
231 uint32_t num_channels);
232
233int q6asm_enable_sbrps(struct audio_client *ac,
234 uint32_t sbr_ps);
235
236int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
237 uint16_t sce_left, uint16_t sce_right);
238
239int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
240 uint16_t min_rate, uint16_t max_rate,
241 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd);
242
243int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
244 uint16_t min_rate, uint16_t max_rate,
245 uint16_t rate_modulation_cmd);
246
247int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
248 uint16_t band_mode, uint16_t dtx_enable);
249
250int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
251 uint16_t band_mode, uint16_t dtx_enable);
252
253int q6asm_media_format_block_pcm(struct audio_client *ac,
254 uint32_t rate, uint32_t channels);
255
256int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
257 uint32_t rate, uint32_t channels);
258
259int q6asm_media_format_block_aac(struct audio_client *ac,
260 struct asm_aac_cfg *cfg);
261
262int q6asm_media_format_block_multi_aac(struct audio_client *ac,
263 struct asm_aac_cfg *cfg);
264
265int q6asm_media_format_block_wma(struct audio_client *ac,
266 void *cfg);
267
268int q6asm_media_format_block_wmapro(struct audio_client *ac,
269 void *cfg);
270
271/* PP specific */
272int q6asm_equalizer(struct audio_client *ac, void *eq);
273
274/* Send Volume Command */
275int q6asm_set_volume(struct audio_client *ac, int volume);
276
277/* Set SoftPause Params */
278int q6asm_set_softpause(struct audio_client *ac,
279 struct asm_softpause_params *param);
280
281/* Set Softvolume Params */
282int q6asm_set_softvolume(struct audio_client *ac,
283 struct asm_softvolume_params *param);
284
285/* Send left-right channel gain */
286int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain);
287
288/* Enable Mute/unmute flag */
289int q6asm_set_mute(struct audio_client *ac, int muteflag);
290
291uint64_t q6asm_get_session_time(struct audio_client *ac);
292
293/* Client can set the IO mode to either AIO/SIO mode */
294int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode);
295
296/* Get Service ID for APR communication */
297int q6asm_get_apr_service_id(int session_id);
298
299/* Common format block without any payload
300*/
301int q6asm_media_format_block(struct audio_client *ac, uint32_t format);
302
303#endif /* __Q6_ASM_H__ */