blob: 1635fc3638786b07ef06b04e625ab0862cc87404 [file] [log] [blame]
Subhash Chandra Bose Naripeddye6562162012-12-12 15:11:38 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -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_V2_H__
13#define __Q6_ASM_V2_H__
14
15#include <mach/qdsp6v2/apr.h>
Ben Romberger092d70c2013-08-07 15:33:47 -070016#include <mach/qdsp6v2/rtac.h>
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -070017#include <sound/apr_audio-v2.h>
18#include <linux/list.h>
Mitchel Humpherys71a6ac92012-09-06 10:22:31 -070019#include <linux/msm_ion.h>
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -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
43#define FORMAT_MPEG4_MULTI_AAC 0x0011
44#define FORMAT_MULTI_CHANNEL_LINEAR_PCM 0x0012
Subhash Chandra Bose Naripeddyaf3e03d2013-02-08 11:35:55 -080045#define FORMAT_AC3 0x0013
46#define FORMAT_EAC3 0x0014
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -070047
48#define ENCDEC_SBCBITRATE 0x0001
49#define ENCDEC_IMMEDIATE_DECODE 0x0002
50#define ENCDEC_CFG_BLK 0x0003
51
52#define CMD_PAUSE 0x0001
53#define CMD_FLUSH 0x0002
54#define CMD_EOS 0x0003
55#define CMD_CLOSE 0x0004
56#define CMD_OUT_FLUSH 0x0005
Alexy Josepha02bd1c2013-10-31 17:11:31 -070057#define CMD_SUSPEND 0x0006
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -070058
59/* bit 0:1 represents priority of stream */
60#define STREAM_PRIORITY_NORMAL 0x0000
61#define STREAM_PRIORITY_LOW 0x0001
62#define STREAM_PRIORITY_HIGH 0x0002
63
64/* bit 4 represents META enable of encoded data buffer */
65#define BUFFER_META_ENABLE 0x0010
66
67/* Enable Sample_Rate/Channel_Mode notification event from Decoder */
68#define SR_CM_NOTIFY_ENABLE 0x0004
69
Damir Didjustof0c7c822013-11-13 15:26:14 -080070#define TUN_WRITE_IO_MODE 0x0008 /* tunnel read write mode */
71#define TUN_READ_IO_MODE 0x0004 /* tunnel read write mode */
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -070072#define SYNC_IO_MODE 0x0001
Harmandeep Singheaf59b42012-06-05 21:46:02 -070073#define ASYNC_IO_MODE 0x0002
Phani Kumar Uppalapatif3c5fac2012-10-13 15:27:23 -070074#define COMPRESSED_IO 0x0040
Krishnankutty Kolathappillyc88de732014-01-15 11:36:39 -080075#define COMPRESSED_STREAM_IO 0x0080
Harmandeep Singheaf59b42012-06-05 21:46:02 -070076#define NT_MODE 0x0400
77
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -070078#define NO_TIMESTAMP 0xFF00
79#define SET_TIMESTAMP 0x0000
80
81#define SOFT_PAUSE_ENABLE 1
82#define SOFT_PAUSE_DISABLE 0
83
Ben Romberger971765c2013-07-23 17:27:18 -070084#define SESSION_MAX 0x08
85#define ASM_CONTROL_SESSION 0x0F
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -070086
Ravi Kumar Alamandab58b13f2013-10-23 14:33:12 -070087#define ASM_SHIFT_GAPLESS_MODE_FLAG 31
88#define ASM_SHIFT_LAST_BUFFER_FLAG 30
89
Krishnankutty Kolathappilly05c7bd92013-04-27 23:34:53 -070090/* payload structure bytes */
91#define READDONE_IDX_STATUS 0
92#define READDONE_IDX_BUFADD_LSW 1
93#define READDONE_IDX_BUFADD_MSW 2
94#define READDONE_IDX_MEMMAP_HDL 3
95#define READDONE_IDX_SIZE 4
96#define READDONE_IDX_OFFSET 5
97#define READDONE_IDX_LSW_TS 6
98#define READDONE_IDX_MSW_TS 7
99#define READDONE_IDX_FLAGS 8
100#define READDONE_IDX_NUMFRAMES 9
101#define READDONE_IDX_SEQ_ID 10
102
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700103#define SOFT_PAUSE_PERIOD 30 /* ramp up/down for 30ms */
Santosh Mardib8d48f52013-07-19 05:33:28 +0530104#define SOFT_PAUSE_STEP 0 /* Step value 0ms or 0us */
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700105enum {
106 SOFT_PAUSE_CURVE_LINEAR = 0,
107 SOFT_PAUSE_CURVE_EXP,
108 SOFT_PAUSE_CURVE_LOG,
109};
110
111#define SOFT_VOLUME_PERIOD 30 /* ramp up/down for 30ms */
Santosh Mardib8d48f52013-07-19 05:33:28 +0530112#define SOFT_VOLUME_STEP 0 /* Step value 0ms or 0us */
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700113enum {
114 SOFT_VOLUME_CURVE_LINEAR = 0,
115 SOFT_VOLUME_CURVE_EXP,
116 SOFT_VOLUME_CURVE_LOG,
117};
118
119typedef void (*app_cb)(uint32_t opcode, uint32_t token,
120 uint32_t *payload, void *priv);
121
122struct audio_buffer {
123 dma_addr_t phys;
124 void *data;
125 uint32_t used;
126 uint32_t size;/* size of buffer */
127 uint32_t actual_size; /* actual number of bytes read by DSP */
128 struct ion_handle *handle;
129 struct ion_client *client;
130};
131
132struct audio_aio_write_param {
133 unsigned long paddr;
134 uint32_t len;
135 uint32_t uid;
136 uint32_t lsw_ts;
137 uint32_t msw_ts;
138 uint32_t flags;
Eric Laurent36e56242013-07-15 10:01:42 -0700139 uint32_t metadata_len;
Ravi Kumar Alamandab58b13f2013-10-23 14:33:12 -0700140 uint32_t last_buffer;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700141};
142
143struct audio_aio_read_param {
144 unsigned long paddr;
145 uint32_t len;
146 uint32_t uid;
147};
148
149struct audio_port_data {
150 struct audio_buffer *buf;
151 uint32_t max_buf_cnt;
152 uint32_t dsp_buf;
153 uint32_t cpu_buf;
154 struct list_head mem_map_handle;
155 uint32_t tmp_hdl;
156 /* read or write locks */
157 struct mutex lock;
158 spinlock_t dsp_lock;
159};
160
161struct audio_client {
162 int session;
163 app_cb cb;
164 atomic_t cmd_state;
165 /* Relative or absolute TS */
Phani Kumar Uppalapatic268df72013-02-19 19:06:41 -0800166 atomic_t time_flag;
Phani Kumar Uppalapati70a5d132012-12-05 11:35:13 -0800167 atomic_t nowait_cmd_cnt;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700168 void *priv;
169 uint32_t io_mode;
170 uint64_t time_stamp;
171 struct apr_svc *apr;
172 struct apr_svc *mmap_apr;
Ravi Kumar Alamandab58b13f2013-10-23 14:33:12 -0700173 struct apr_svc *apr2;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700174 struct mutex cmd_lock;
175 /* idx:1 out port, 0: in port*/
176 struct audio_port_data port[2];
177 wait_queue_head_t cmd_wait;
Phani Kumar Uppalapatic268df72013-02-19 19:06:41 -0800178 wait_queue_head_t time_wait;
Krishnankutty Kolathappilly3613a162013-11-25 12:13:10 -0800179 int perf_mode;
Ravi Kumar Alamandab58b13f2013-10-23 14:33:12 -0700180 int stream_id;
Fred Ohc274a7a2013-03-25 13:59:17 -0700181 /* audio cache operations fptr*/
182 int (*fptr_cache_ops)(struct audio_buffer *abuff, int cache_op);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700183};
184
185void q6asm_audio_client_free(struct audio_client *ac);
186
187struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv);
188
189struct audio_client *q6asm_get_audio_client(int session_id);
190
191int q6asm_audio_client_buf_alloc(unsigned int dir/* 1:Out,0:In */,
192 struct audio_client *ac,
193 unsigned int bufsz,
194 unsigned int bufcnt);
195int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir
196 /* 1:Out,0:In */,
197 struct audio_client *ac,
198 unsigned int bufsz,
199 unsigned int bufcnt);
200
201int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
202 struct audio_client *ac);
203
204int q6asm_open_read(struct audio_client *ac, uint32_t format
205 /*, uint16_t bits_per_sample*/);
206
Damir Didjusto1c69f1b2013-06-17 20:55:53 -0700207int q6asm_open_read_v2(struct audio_client *ac, uint32_t format,
208 uint16_t bits_per_sample);
209
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700210int q6asm_open_write(struct audio_client *ac, uint32_t format
211 /*, uint16_t bits_per_sample*/);
212
Bhalchandra Gajare5b40c532013-02-19 13:36:47 -0800213int q6asm_open_write_v2(struct audio_client *ac, uint32_t format,
214 uint16_t bits_per_sample);
215
Ravi Kumar Alamandab58b13f2013-10-23 14:33:12 -0700216int q6asm_stream_open_write_v2(struct audio_client *ac, uint32_t format,
217 uint16_t bits_per_sample, int32_t stream_id,
218 bool is_gapless_mode);
219
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700220int q6asm_open_read_write(struct audio_client *ac,
221 uint32_t rd_format,
222 uint32_t wr_format);
223
Damir Didjustobe4b22c2013-11-13 14:28:12 -0800224int q6asm_open_loopback_v2(struct audio_client *ac,
225 uint16_t bits_per_sample);
226
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700227int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
228 uint32_t lsw_ts, uint32_t flags);
229int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
230 uint32_t lsw_ts, uint32_t flags);
231
232int q6asm_async_write(struct audio_client *ac,
233 struct audio_aio_write_param *param);
234
235int q6asm_async_read(struct audio_client *ac,
236 struct audio_aio_read_param *param);
237
238int q6asm_read(struct audio_client *ac);
239int q6asm_read_nolock(struct audio_client *ac);
240
241int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add,
242 int dir, uint32_t bufsz, uint32_t bufcnt);
243
244int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add,
245 int dir);
246
Ben Romberger971765c2013-07-23 17:27:18 -0700247int q6asm_unmap_cal_blocks(void);
248
Ben Romberger092d70c2013-08-07 15:33:47 -0700249int q6asm_map_rtac_block(struct rtac_cal_block_data *cal_block);
250
251int q6asm_unmap_rtac_block(uint32_t *mem_map_handle);
252
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700253int q6asm_run(struct audio_client *ac, uint32_t flags,
254 uint32_t msw_ts, uint32_t lsw_ts);
255
256int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
257 uint32_t msw_ts, uint32_t lsw_ts);
258
Ravi Kumar Alamandab58b13f2013-10-23 14:33:12 -0700259int q6asm_stream_run_nowait(struct audio_client *ac, uint32_t flags,
260 uint32_t msw_ts, uint32_t lsw_ts, uint32_t stream_id);
261
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700262int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable);
263
Ravi Kumar Alamandab58b13f2013-10-23 14:33:12 -0700264int q6asm_reg_rx_underflow(struct audio_client *ac, uint16_t enable);
265
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700266int q6asm_cmd(struct audio_client *ac, int cmd);
267
Ravi Kumar Alamandab58b13f2013-10-23 14:33:12 -0700268int q6asm_stream_cmd(struct audio_client *ac, int cmd, uint32_t stream_id);
269
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700270int q6asm_cmd_nowait(struct audio_client *ac, int cmd);
271
Ravi Kumar Alamandab58b13f2013-10-23 14:33:12 -0700272int q6asm_stream_cmd_nowait(struct audio_client *ac, int cmd,
273 uint32_t stream_id);
274
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700275void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac,
276 uint32_t *size, uint32_t *idx);
277
278void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
279 uint32_t *size, uint32_t *idx);
280
281int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac);
282
283/* File format specific configurations to be added below */
284
285int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
286 uint32_t frames_per_buf,
287 uint32_t sample_rate, uint32_t channels,
288 uint32_t bit_rate,
289 uint32_t mode, uint32_t format);
290
291int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
292 uint32_t rate, uint32_t channels);
293
Damir Didjusto1c69f1b2013-06-17 20:55:53 -0700294int q6asm_enc_cfg_blk_pcm_format_support(struct audio_client *ac,
295 uint32_t rate, uint32_t channels,
296 uint16_t bits_per_sample);
297
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700298int q6asm_set_encdec_chan_map(struct audio_client *ac,
299 uint32_t num_channels);
300
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700301int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
302 uint32_t rate, uint32_t channels);
303
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700304int q6asm_enable_sbrps(struct audio_client *ac,
305 uint32_t sbr_ps);
306
307int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
308 uint16_t sce_left, uint16_t sce_right);
309
Amal Paul2ca061b2013-02-25 14:57:33 -0800310int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff);
311
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700312int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
313 uint16_t min_rate, uint16_t max_rate,
314 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd);
315
316int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
317 uint16_t min_rate, uint16_t max_rate,
318 uint16_t rate_modulation_cmd);
319
320int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
321 uint16_t band_mode, uint16_t dtx_enable);
322
323int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
324 uint16_t band_mode, uint16_t dtx_enable);
325
326int q6asm_media_format_block_pcm(struct audio_client *ac,
327 uint32_t rate, uint32_t channels);
328
Bhalchandra Gajare5b40c532013-02-19 13:36:47 -0800329int q6asm_media_format_block_pcm_format_support(struct audio_client *ac,
330 uint32_t rate, uint32_t channels,
331 uint16_t bits_per_sample);
332
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700333int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
Subhash Chandra Bose Naripeddye6562162012-12-12 15:11:38 -0800334 uint32_t rate, uint32_t channels,
335 bool use_default_chmap, char *channel_map);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700336
Bhalchandra Gajare5b40c532013-02-19 13:36:47 -0800337int q6asm_media_format_block_multi_ch_pcm_v2(
338 struct audio_client *ac,
339 uint32_t rate, uint32_t channels,
340 bool use_default_chmap, char *channel_map,
341 uint16_t bits_per_sample);
342
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700343int q6asm_media_format_block_aac(struct audio_client *ac,
344 struct asm_aac_cfg *cfg);
345
Ravi Kumar Alamandab58b13f2013-10-23 14:33:12 -0700346int q6asm_stream_media_format_block_aac(struct audio_client *ac,
347 struct asm_aac_cfg *cfg, int stream_id);
348
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700349int q6asm_media_format_block_multi_aac(struct audio_client *ac,
350 struct asm_aac_cfg *cfg);
351
352int q6asm_media_format_block_wma(struct audio_client *ac,
353 void *cfg);
354
355int q6asm_media_format_block_wmapro(struct audio_client *ac,
356 void *cfg);
357
Phani Kumar Uppalapati1e0324c2013-03-21 14:13:23 -0700358int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
359 struct asm_amrwbplus_cfg *cfg);
Subhash Chandra Bose Naripeddyaf3e03d2013-02-08 11:35:55 -0800360
361int q6asm_ds1_set_endp_params(struct audio_client *ac,
362 int param_id, int param_value);
363
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700364/* PP specific */
365int q6asm_equalizer(struct audio_client *ac, void *eq);
366
367/* Send Volume Command */
368int q6asm_set_volume(struct audio_client *ac, int volume);
369
370/* Set SoftPause Params */
371int q6asm_set_softpause(struct audio_client *ac,
372 struct asm_softpause_params *param);
373
374/* Set Softvolume Params */
375int q6asm_set_softvolume(struct audio_client *ac,
376 struct asm_softvolume_params *param);
377
378/* Send left-right channel gain */
379int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain);
380
381/* Enable Mute/unmute flag */
382int q6asm_set_mute(struct audio_client *ac, int muteflag);
383
Patrick Laifc8f2242013-01-06 00:52:34 -0800384int q6asm_get_session_time(struct audio_client *ac, uint64_t *tstamp);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700385
Ravi Kumar Alamanda3f6f0b12013-11-22 00:20:43 -0800386int q6asm_send_audio_effects_params(struct audio_client *ac, char *params,
387 uint32_t params_length);
388
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700389/* Client can set the IO mode to either AIO/SIO mode */
390int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode);
391
392/* Get Service ID for APR communication */
393int q6asm_get_apr_service_id(int session_id);
394
395/* Common format block without any payload
396*/
397int q6asm_media_format_block(struct audio_client *ac, uint32_t format);
398
Ravi Kumar Alamandab58b13f2013-10-23 14:33:12 -0700399/* Send the meta data to remove initial and trailing silence */
400int q6asm_send_meta_data(struct audio_client *ac, uint32_t initial_samples,
401 uint32_t trailing_samples);
402
Krishnankutty Kolathappillyc88de732014-01-15 11:36:39 -0800403/* Send the stream meta data to remove initial and trailing silence */
404int q6asm_stream_send_meta_data(struct audio_client *ac, uint32_t stream_id,
405 uint32_t initial_samples, uint32_t trailing_samples);
406
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700407#endif /* __Q6_ASM_H__ */