blob: 54a91872514f91f481e193d8e96abfc415ad2880 [file] [log] [blame]
Kiran Kandi5e809b02012-01-31 00:24:33 -08001/* Copyright (c) 2010-2012, Code Aurora Forum. 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
18#include <linux/ion.h>
19#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
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070051
52#define ENCDEC_SBCBITRATE 0x0001
53#define ENCDEC_IMMEDIATE_DECODE 0x0002
54#define ENCDEC_CFG_BLK 0x0003
55
56#define CMD_PAUSE 0x0001
57#define CMD_FLUSH 0x0002
58#define CMD_EOS 0x0003
59#define CMD_CLOSE 0x0004
60#define CMD_OUT_FLUSH 0x0005
61
62/* bit 0:1 represents priority of stream */
63#define STREAM_PRIORITY_NORMAL 0x0000
64#define STREAM_PRIORITY_LOW 0x0001
65#define STREAM_PRIORITY_HIGH 0x0002
66
67/* bit 4 represents META enable of encoded data buffer */
68#define BUFFER_META_ENABLE 0x0010
69
70/* Enable Sample_Rate/Channel_Mode notification event from Decoder */
71#define SR_CM_NOTIFY_ENABLE 0x0004
72
73#define ASYNC_IO_MODE 0x0002
74#define SYNC_IO_MODE 0x0001
75#define NO_TIMESTAMP 0xFF00
76#define SET_TIMESTAMP 0x0000
77
78#define SOFT_PAUSE_ENABLE 1
79#define SOFT_PAUSE_DISABLE 0
80
81#define SESSION_MAX 0x08
82
Sriranjan Srikantam5285a212011-09-06 19:09:19 -070083#define SOFT_PAUSE_PERIOD 30 /* ramp up/down for 30ms */
84#define SOFT_PAUSE_STEP 2000 /* Step value 2ms or 2000us */
85enum {
86 SOFT_PAUSE_CURVE_LINEAR = 0,
87 SOFT_PAUSE_CURVE_EXP,
88 SOFT_PAUSE_CURVE_LOG,
89};
90
91#define SOFT_VOLUME_PERIOD 30 /* ramp up/down for 30ms */
92#define SOFT_VOLUME_STEP 2000 /* Step value 2ms or 2000us */
93enum {
94 SOFT_VOLUME_CURVE_LINEAR = 0,
95 SOFT_VOLUME_CURVE_EXP,
96 SOFT_VOLUME_CURVE_LOG,
97};
98
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070099typedef void (*app_cb)(uint32_t opcode, uint32_t token,
100 uint32_t *payload, void *priv);
101
102struct audio_buffer {
103 dma_addr_t phys;
104 void *data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700105 uint32_t used;
106 uint32_t size;/* size of buffer */
107 uint32_t actual_size; /* actual number of bytes read by DSP */
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800108#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
109 struct ion_handle *handle;
110 struct ion_client *client;
111#else
Laura Abbottea3e7b62012-04-30 15:59:21 -0700112 void *mem_buffer;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800113#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700114};
115
116struct audio_aio_write_param {
117 unsigned long paddr;
118 uint32_t uid;
119 uint32_t len;
120 uint32_t msw_ts;
121 uint32_t lsw_ts;
122 uint32_t flags;
123};
124
125struct audio_aio_read_param {
126 unsigned long paddr;
127 uint32_t len;
128 uint32_t uid;
129};
130
131struct audio_port_data {
132 struct audio_buffer *buf;
133 uint32_t max_buf_cnt;
134 uint32_t dsp_buf;
135 uint32_t cpu_buf;
136 /* read or write locks */
137 struct mutex lock;
138 spinlock_t dsp_lock;
139};
140
141struct audio_client {
142 int session;
143 /* idx:1 out port, 0: in port*/
144 struct audio_port_data port[2];
145
146 struct apr_svc *apr;
147 struct mutex cmd_lock;
148
149 atomic_t cmd_state;
150 atomic_t time_flag;
151 wait_queue_head_t cmd_wait;
152 wait_queue_head_t time_wait;
153
154 app_cb cb;
155 void *priv;
156 uint32_t io_mode;
157 uint64_t time_stamp;
158};
159
160void q6asm_audio_client_free(struct audio_client *ac);
161
162struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv);
163
Ben Romberger61754dc2011-10-31 18:25:41 -0700164struct audio_client *q6asm_get_audio_client(int session_id);
165
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700166int q6asm_audio_client_buf_alloc(unsigned int dir/* 1:Out,0:In */,
167 struct audio_client *ac,
168 unsigned int bufsz,
169 unsigned int bufcnt);
170int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir
171 /* 1:Out,0:In */,
172 struct audio_client *ac,
173 unsigned int bufsz,
174 unsigned int bufcnt);
175
176int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
177 struct audio_client *ac);
178
179int q6asm_open_read(struct audio_client *ac, uint32_t format);
180
181int q6asm_open_write(struct audio_client *ac, uint32_t format);
182
Santosh Mardi23321202012-03-22 04:33:25 +0530183int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format);
184
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185int q6asm_open_read_write(struct audio_client *ac,
186 uint32_t rd_format,
187 uint32_t wr_format);
188
189int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
190 uint32_t lsw_ts, uint32_t flags);
191int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
192 uint32_t lsw_ts, uint32_t flags);
193
194int q6asm_async_write(struct audio_client *ac,
195 struct audio_aio_write_param *param);
196
197int q6asm_async_read(struct audio_client *ac,
198 struct audio_aio_read_param *param);
199
200int q6asm_read(struct audio_client *ac);
201int q6asm_read_nolock(struct audio_client *ac);
202
203int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add,
204 int dir, uint32_t bufsz, uint32_t bufcnt);
205
206int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add,
207 int dir);
208
209int q6asm_run(struct audio_client *ac, uint32_t flags,
210 uint32_t msw_ts, uint32_t lsw_ts);
211
212int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
213 uint32_t msw_ts, uint32_t lsw_ts);
214
215int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable);
216
217int q6asm_cmd(struct audio_client *ac, int cmd);
218
219int q6asm_cmd_nowait(struct audio_client *ac, int cmd);
220
221void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac,
222 uint32_t *size, uint32_t *idx);
223
Jay Wang9cf59a02011-08-10 16:58:40 -0700224void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
225 uint32_t *size, uint32_t *idx);
226
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700227int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac);
228
229/* File format specific configurations to be added below */
230
231int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
232 uint32_t frames_per_buf,
233 uint32_t sample_rate, uint32_t channels,
234 uint32_t bit_rate,
235 uint32_t mode, uint32_t format);
236
237int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
238 uint32_t rate, uint32_t channels);
239
Mingming Yin647e9ea2012-03-17 19:56:10 -0700240int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
241 uint32_t rate, uint32_t channels);
242
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700243int q6asm_enable_sbrps(struct audio_client *ac,
244 uint32_t sbr_ps);
245
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -0700246int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
247 uint16_t sce_left, uint16_t sce_right);
248
Swaminathan Sathappan6f530882012-05-01 16:42:22 -0700249int q6asm_set_encdec_chan_map(struct audio_client *ac,
250 uint32_t num_channels);
251
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700252int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
253 uint16_t min_rate, uint16_t max_rate,
254 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd);
255
256int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
257 uint16_t min_rate, uint16_t max_rate,
258 uint16_t rate_modulation_cmd);
259
260int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
261 uint16_t band_mode, uint16_t dtx_enable);
262
Alex Wong2caeecc2011-10-28 10:52:15 +0530263int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
264 uint16_t band_mode, uint16_t dtx_enable);
265
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700266int q6asm_media_format_block_pcm(struct audio_client *ac,
267 uint32_t rate, uint32_t channels);
268
Kiran Kandi5e809b02012-01-31 00:24:33 -0800269int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
270 uint32_t rate, uint32_t channels);
271
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700272int q6asm_media_format_block_aac(struct audio_client *ac,
273 struct asm_aac_cfg *cfg);
274
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -0700275int q6asm_media_format_block_multi_aac(struct audio_client *ac,
276 struct asm_aac_cfg *cfg);
277
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700278int q6asm_media_format_block_wma(struct audio_client *ac,
279 void *cfg);
280
281int q6asm_media_format_block_wmapro(struct audio_client *ac,
282 void *cfg);
283
284/* PP specific */
285int q6asm_equalizer(struct audio_client *ac, void *eq);
286
287/* Send Volume Command */
288int q6asm_set_volume(struct audio_client *ac, int volume);
289
290/* Set SoftPause Params */
291int q6asm_set_softpause(struct audio_client *ac,
292 struct asm_softpause_params *param);
293
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -0700294/* Set Softvolume Params */
295int q6asm_set_softvolume(struct audio_client *ac,
296 struct asm_softvolume_params *param);
297
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700298/* Send left-right channel gain */
299int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain);
300
301/* Enable Mute/unmute flag */
302int q6asm_set_mute(struct audio_client *ac, int muteflag);
303
304uint64_t q6asm_get_session_time(struct audio_client *ac);
305
306/* Client can set the IO mode to either AIO/SIO mode */
307int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode);
308
Ben Romberger45b351c2011-07-20 22:37:27 -0700309#ifdef CONFIG_RTAC
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700310/* Get Service ID for APR communication */
311int q6asm_get_apr_service_id(int session_id);
312#endif
313
Alex Wong2caeecc2011-10-28 10:52:15 +0530314/* Common format block without any payload
315*/
316int q6asm_media_format_block(struct audio_client *ac, uint32_t format);
317
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700318#endif /* __Q6_ASM_H__ */