blob: 4360a614683e4866256fae8eddbb791bf9a57909 [file] [log] [blame]
Cong Tang76c7e642019-02-26 15:08:55 +08001/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302 *
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 __Q6AFE_V2_H__
13#define __Q6AFE_V2_H__
Laxminath Kasam605b42f2017-08-01 22:02:15 +053014#include <dsp/apr_audio-v2.h>
15#include <dsp/rtac.h>
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053016
17#define IN 0x000
18#define OUT 0x001
19#define MSM_AFE_MONO 0
20#define MSM_AFE_CH_STEREO 1
21#define MSM_AFE_MONO_RIGHT 1
22#define MSM_AFE_MONO_LEFT 2
23#define MSM_AFE_STEREO 3
24#define MSM_AFE_4CHANNELS 4
25#define MSM_AFE_6CHANNELS 6
26#define MSM_AFE_8CHANNELS 8
27
28#define MSM_AFE_I2S_FORMAT_LPCM 0
29#define MSM_AFE_I2S_FORMAT_COMPR 1
30#define MSM_AFE_I2S_FORMAT_IEC60958_LPCM 2
31#define MSM_AFE_I2S_FORMAT_IEC60958_COMPR 3
32
33#define MSM_AFE_PORT_TYPE_RX 0
34#define MSM_AFE_PORT_TYPE_TX 1
35
36#define RT_PROXY_DAI_001_RX 0xE0
37#define RT_PROXY_DAI_001_TX 0xF0
38#define RT_PROXY_DAI_002_RX 0xF1
39#define RT_PROXY_DAI_002_TX 0xE1
40#define VIRTUAL_ID_TO_PORTID(val) ((val & 0xF) | 0x2000)
41
42#define AFE_CLK_VERSION_V1 1
43#define AFE_CLK_VERSION_V2 2
Xiaojun Sang12120ab2017-09-28 18:21:21 +080044#define AFE_API_VERSION_SUPPORT_SPV3 2
Cong Tang76c7e642019-02-26 15:08:55 +080045#define AFE_API_VERSION_V3 3
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053046typedef int (*routing_cb)(int port);
47
48enum {
49 /* IDX 0->4 */
50 IDX_PRIMARY_I2S_RX,
51 IDX_PRIMARY_I2S_TX,
52 IDX_AFE_PORT_ID_PRIMARY_PCM_RX,
53 IDX_AFE_PORT_ID_PRIMARY_PCM_TX,
54 IDX_SECONDARY_I2S_RX,
55 /* IDX 5->9 */
56 IDX_SECONDARY_I2S_TX,
57 IDX_MI2S_RX,
58 IDX_MI2S_TX,
59 IDX_HDMI_RX,
60 IDX_RSVD_2,
61 /* IDX 10->14 */
62 IDX_RSVD_3,
63 IDX_DIGI_MIC_TX,
64 IDX_VOICE_RECORD_RX,
65 IDX_VOICE_RECORD_TX,
66 IDX_VOICE_PLAYBACK_TX,
67 /* IDX 15->19 */
68 IDX_SLIMBUS_0_RX,
69 IDX_SLIMBUS_0_TX,
70 IDX_SLIMBUS_1_RX,
71 IDX_SLIMBUS_1_TX,
72 IDX_SLIMBUS_2_RX,
73 /* IDX 20->24 */
74 IDX_SLIMBUS_2_TX,
75 IDX_SLIMBUS_3_RX,
76 IDX_SLIMBUS_3_TX,
77 IDX_SLIMBUS_4_RX,
78 IDX_SLIMBUS_4_TX,
79 /* IDX 25->29 */
80 IDX_SLIMBUS_5_RX,
81 IDX_SLIMBUS_5_TX,
82 IDX_INT_BT_SCO_RX,
83 IDX_INT_BT_SCO_TX,
84 IDX_INT_BT_A2DP_RX,
85 /* IDX 30->34 */
86 IDX_INT_FM_RX,
87 IDX_INT_FM_TX,
88 IDX_RT_PROXY_PORT_001_RX,
89 IDX_RT_PROXY_PORT_001_TX,
90 IDX_AFE_PORT_ID_QUATERNARY_MI2S_RX,
91 /* IDX 35->39 */
92 IDX_AFE_PORT_ID_QUATERNARY_MI2S_TX,
93 IDX_AFE_PORT_ID_SECONDARY_MI2S_RX,
94 IDX_AFE_PORT_ID_SECONDARY_MI2S_TX,
95 IDX_AFE_PORT_ID_TERTIARY_MI2S_RX,
96 IDX_AFE_PORT_ID_TERTIARY_MI2S_TX,
97 /* IDX 40->44 */
98 IDX_AFE_PORT_ID_PRIMARY_MI2S_RX,
99 IDX_AFE_PORT_ID_PRIMARY_MI2S_TX,
100 IDX_AFE_PORT_ID_SECONDARY_PCM_RX,
101 IDX_AFE_PORT_ID_SECONDARY_PCM_TX,
102 IDX_VOICE2_PLAYBACK_TX,
103 /* IDX 45->49 */
104 IDX_SLIMBUS_6_RX,
105 IDX_SLIMBUS_6_TX,
106 IDX_SPDIF_RX,
107 IDX_GLOBAL_CFG,
108 IDX_AUDIO_PORT_ID_I2S_RX,
109 /* IDX 50->53 */
110 IDX_AFE_PORT_ID_SECONDARY_MI2S_RX_SD1,
111 IDX_AFE_PORT_ID_QUINARY_MI2S_RX,
112 IDX_AFE_PORT_ID_QUINARY_MI2S_TX,
113 IDX_AFE_PORT_ID_SENARY_MI2S_TX,
114 /* IDX 54->117 */
115 IDX_AFE_PORT_ID_PRIMARY_TDM_RX_0,
116 IDX_AFE_PORT_ID_PRIMARY_TDM_TX_0,
117 IDX_AFE_PORT_ID_PRIMARY_TDM_RX_1,
118 IDX_AFE_PORT_ID_PRIMARY_TDM_TX_1,
119 IDX_AFE_PORT_ID_PRIMARY_TDM_RX_2,
120 IDX_AFE_PORT_ID_PRIMARY_TDM_TX_2,
121 IDX_AFE_PORT_ID_PRIMARY_TDM_RX_3,
122 IDX_AFE_PORT_ID_PRIMARY_TDM_TX_3,
123 IDX_AFE_PORT_ID_PRIMARY_TDM_RX_4,
124 IDX_AFE_PORT_ID_PRIMARY_TDM_TX_4,
125 IDX_AFE_PORT_ID_PRIMARY_TDM_RX_5,
126 IDX_AFE_PORT_ID_PRIMARY_TDM_TX_5,
127 IDX_AFE_PORT_ID_PRIMARY_TDM_RX_6,
128 IDX_AFE_PORT_ID_PRIMARY_TDM_TX_6,
129 IDX_AFE_PORT_ID_PRIMARY_TDM_RX_7,
130 IDX_AFE_PORT_ID_PRIMARY_TDM_TX_7,
131 IDX_AFE_PORT_ID_SECONDARY_TDM_RX_0,
132 IDX_AFE_PORT_ID_SECONDARY_TDM_TX_0,
133 IDX_AFE_PORT_ID_SECONDARY_TDM_RX_1,
134 IDX_AFE_PORT_ID_SECONDARY_TDM_TX_1,
135 IDX_AFE_PORT_ID_SECONDARY_TDM_RX_2,
136 IDX_AFE_PORT_ID_SECONDARY_TDM_TX_2,
137 IDX_AFE_PORT_ID_SECONDARY_TDM_RX_3,
138 IDX_AFE_PORT_ID_SECONDARY_TDM_TX_3,
139 IDX_AFE_PORT_ID_SECONDARY_TDM_RX_4,
140 IDX_AFE_PORT_ID_SECONDARY_TDM_TX_4,
141 IDX_AFE_PORT_ID_SECONDARY_TDM_RX_5,
142 IDX_AFE_PORT_ID_SECONDARY_TDM_TX_5,
143 IDX_AFE_PORT_ID_SECONDARY_TDM_RX_6,
144 IDX_AFE_PORT_ID_SECONDARY_TDM_TX_6,
145 IDX_AFE_PORT_ID_SECONDARY_TDM_RX_7,
146 IDX_AFE_PORT_ID_SECONDARY_TDM_TX_7,
147 IDX_AFE_PORT_ID_TERTIARY_TDM_RX_0,
148 IDX_AFE_PORT_ID_TERTIARY_TDM_TX_0,
149 IDX_AFE_PORT_ID_TERTIARY_TDM_RX_1,
150 IDX_AFE_PORT_ID_TERTIARY_TDM_TX_1,
151 IDX_AFE_PORT_ID_TERTIARY_TDM_RX_2,
152 IDX_AFE_PORT_ID_TERTIARY_TDM_TX_2,
153 IDX_AFE_PORT_ID_TERTIARY_TDM_RX_3,
154 IDX_AFE_PORT_ID_TERTIARY_TDM_TX_3,
155 IDX_AFE_PORT_ID_TERTIARY_TDM_RX_4,
156 IDX_AFE_PORT_ID_TERTIARY_TDM_TX_4,
157 IDX_AFE_PORT_ID_TERTIARY_TDM_RX_5,
158 IDX_AFE_PORT_ID_TERTIARY_TDM_TX_5,
159 IDX_AFE_PORT_ID_TERTIARY_TDM_RX_6,
160 IDX_AFE_PORT_ID_TERTIARY_TDM_TX_6,
161 IDX_AFE_PORT_ID_TERTIARY_TDM_RX_7,
162 IDX_AFE_PORT_ID_TERTIARY_TDM_TX_7,
163 IDX_AFE_PORT_ID_QUATERNARY_TDM_RX_0,
164 IDX_AFE_PORT_ID_QUATERNARY_TDM_TX_0,
165 IDX_AFE_PORT_ID_QUATERNARY_TDM_RX_1,
166 IDX_AFE_PORT_ID_QUATERNARY_TDM_TX_1,
167 IDX_AFE_PORT_ID_QUATERNARY_TDM_RX_2,
168 IDX_AFE_PORT_ID_QUATERNARY_TDM_TX_2,
169 IDX_AFE_PORT_ID_QUATERNARY_TDM_RX_3,
170 IDX_AFE_PORT_ID_QUATERNARY_TDM_TX_3,
171 IDX_AFE_PORT_ID_QUATERNARY_TDM_RX_4,
172 IDX_AFE_PORT_ID_QUATERNARY_TDM_TX_4,
173 IDX_AFE_PORT_ID_QUATERNARY_TDM_RX_5,
174 IDX_AFE_PORT_ID_QUATERNARY_TDM_TX_5,
175 IDX_AFE_PORT_ID_QUATERNARY_TDM_RX_6,
176 IDX_AFE_PORT_ID_QUATERNARY_TDM_TX_6,
177 IDX_AFE_PORT_ID_QUATERNARY_TDM_RX_7,
178 IDX_AFE_PORT_ID_QUATERNARY_TDM_TX_7,
179 /* IDX 118->121 */
180 IDX_SLIMBUS_7_RX,
181 IDX_SLIMBUS_7_TX,
182 IDX_SLIMBUS_8_RX,
183 IDX_SLIMBUS_8_TX,
184 /* IDX 122-> 123 */
185 IDX_AFE_PORT_ID_USB_RX,
186 IDX_AFE_PORT_ID_USB_TX,
187 /* IDX 124 */
188 IDX_DISPLAY_PORT_RX,
189 /* IDX 125-> 128 */
190 IDX_AFE_PORT_ID_TERTIARY_PCM_RX,
191 IDX_AFE_PORT_ID_TERTIARY_PCM_TX,
192 IDX_AFE_PORT_ID_QUATERNARY_PCM_RX,
193 IDX_AFE_PORT_ID_QUATERNARY_PCM_TX,
194 /* IDX 129-> 142 */
195 IDX_AFE_PORT_ID_INT0_MI2S_RX,
196 IDX_AFE_PORT_ID_INT0_MI2S_TX,
197 IDX_AFE_PORT_ID_INT1_MI2S_RX,
198 IDX_AFE_PORT_ID_INT1_MI2S_TX,
199 IDX_AFE_PORT_ID_INT2_MI2S_RX,
200 IDX_AFE_PORT_ID_INT2_MI2S_TX,
201 IDX_AFE_PORT_ID_INT3_MI2S_RX,
202 IDX_AFE_PORT_ID_INT3_MI2S_TX,
203 IDX_AFE_PORT_ID_INT4_MI2S_RX,
204 IDX_AFE_PORT_ID_INT4_MI2S_TX,
205 IDX_AFE_PORT_ID_INT5_MI2S_RX,
206 IDX_AFE_PORT_ID_INT5_MI2S_TX,
207 IDX_AFE_PORT_ID_INT6_MI2S_RX,
208 IDX_AFE_PORT_ID_INT6_MI2S_TX,
Rohit Kumarc08b14f2017-10-06 10:52:17 +0530209 /* IDX 143-> 160 */
210 IDX_AFE_PORT_ID_QUINARY_PCM_RX,
211 IDX_AFE_PORT_ID_QUINARY_PCM_TX,
212 IDX_AFE_PORT_ID_QUINARY_TDM_RX_0,
213 IDX_AFE_PORT_ID_QUINARY_TDM_TX_0,
214 IDX_AFE_PORT_ID_QUINARY_TDM_RX_1,
215 IDX_AFE_PORT_ID_QUINARY_TDM_TX_1,
216 IDX_AFE_PORT_ID_QUINARY_TDM_RX_2,
217 IDX_AFE_PORT_ID_QUINARY_TDM_TX_2,
218 IDX_AFE_PORT_ID_QUINARY_TDM_RX_3,
219 IDX_AFE_PORT_ID_QUINARY_TDM_TX_3,
220 IDX_AFE_PORT_ID_QUINARY_TDM_RX_4,
221 IDX_AFE_PORT_ID_QUINARY_TDM_TX_4,
222 IDX_AFE_PORT_ID_QUINARY_TDM_RX_5,
223 IDX_AFE_PORT_ID_QUINARY_TDM_TX_5,
224 IDX_AFE_PORT_ID_QUINARY_TDM_RX_6,
225 IDX_AFE_PORT_ID_QUINARY_TDM_TX_6,
226 IDX_AFE_PORT_ID_QUINARY_TDM_RX_7,
227 IDX_AFE_PORT_ID_QUINARY_TDM_TX_7,
Raja Mallik425e1d32018-05-20 19:21:10 +0530228 IDX_AFE_LOOPBACK_TX,
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530229 AFE_MAX_PORTS
230};
231
232enum afe_mad_type {
233 MAD_HW_NONE = 0x00,
234 MAD_HW_AUDIO = 0x01,
235 MAD_HW_BEACON = 0x02,
236 MAD_HW_ULTRASOUND = 0x04,
237 MAD_SW_AUDIO = 0x05,
238};
239
240enum afe_cal_mode {
241 AFE_CAL_MODE_DEFAULT = 0x00,
242 AFE_CAL_MODE_NONE,
243};
244
Raja Mallike1b2f792018-06-01 13:17:36 +0530245enum lpass_clk_ver {
246 LPASS_CLK_VER_1,
247 LPASS_CLK_VER_2,
248};
249
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530250struct afe_audio_buffer {
251 dma_addr_t phys;
252 void *data;
253 uint32_t used;
254 uint32_t size;/* size of buffer */
255 uint32_t actual_size; /* actual number of bytes read by DSP */
256 struct ion_handle *handle;
257 struct ion_client *client;
258};
259
260struct afe_audio_port_data {
261 struct afe_audio_buffer *buf;
262 uint32_t max_buf_cnt;
263 uint32_t dsp_buf;
264 uint32_t cpu_buf;
265 struct list_head mem_map_handle;
266 uint32_t tmp_hdl;
267 /* read or write locks */
268 struct mutex lock;
269 spinlock_t dsp_lock;
270};
271
272struct afe_audio_client {
273 atomic_t cmd_state;
274 /* Relative or absolute TS */
275 uint32_t time_flag;
276 void *priv;
277 uint64_t time_stamp;
278 struct mutex cmd_lock;
279 /* idx:1 out port, 0: in port*/
280 struct afe_audio_port_data port[2];
281 wait_queue_head_t cmd_wait;
282 uint32_t mem_map_handle;
283};
284
285struct aanc_data {
286 bool aanc_active;
287 uint16_t aanc_rx_port;
288 uint16_t aanc_tx_port;
289 uint32_t aanc_rx_port_sample_rate;
290 uint32_t aanc_tx_port_sample_rate;
291};
292
293int afe_open(u16 port_id, union afe_port_config *afe_config, int rate);
294int afe_close(int port_id);
Raja Mallike1b2f792018-06-01 13:17:36 +0530295enum lpass_clk_ver afe_get_lpass_clk_ver(void);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530296int afe_loopback(u16 enable, u16 rx_port, u16 tx_port);
297int afe_sidetone_enable(u16 tx_port_id, u16 rx_port_id, bool enable);
298int afe_loopback_gain(u16 port_id, u16 volume);
299int afe_validate_port(u16 port_id);
300int afe_get_port_index(u16 port_id);
301int afe_get_topology(int port_id);
302int afe_start_pseudo_port(u16 port_id);
303int afe_stop_pseudo_port(u16 port_id);
304uint32_t afe_req_mmap_handle(struct afe_audio_client *ac);
305int afe_memory_map(phys_addr_t dma_addr_p, u32 dma_buf_sz,
306 struct afe_audio_client *ac);
307int afe_cmd_memory_map(phys_addr_t dma_addr_p, u32 dma_buf_sz);
308int afe_cmd_memory_map_nowait(int port_id, phys_addr_t dma_addr_p,
309 u32 dma_buf_sz);
310int afe_cmd_memory_unmap(u32 dma_addr_p);
311int afe_cmd_memory_unmap_nowait(u32 dma_addr_p);
312void afe_set_dtmf_gen_rx_portid(u16 rx_port_id, int set);
313int afe_dtmf_generate_rx(int64_t duration_in_ms,
314 uint16_t high_freq,
315 uint16_t low_freq, uint16_t gain);
316int afe_register_get_events(u16 port_id,
317 void (*cb)(uint32_t opcode,
318 uint32_t token, uint32_t *payload, void *priv),
319 void *private_data);
320int afe_unregister_get_events(u16 port_id);
321int afe_rt_proxy_port_write(phys_addr_t buf_addr_p,
322 u32 mem_map_handle, int bytes);
323int afe_rt_proxy_port_read(phys_addr_t buf_addr_p,
324 u32 mem_map_handle, int bytes);
325void afe_set_cal_mode(u16 port_id, enum afe_cal_mode afe_cal_mode);
326int afe_port_start(u16 port_id, union afe_port_config *afe_config,
327 u32 rate);
Manisha Agarwal472fc1e2018-11-04 15:46:02 +0530328int afe_set_tws_channel_mode(u16 port_id, u32 channel_mode);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530329int afe_port_start_v2(u16 port_id, union afe_port_config *afe_config,
330 u32 rate, u16 afe_in_channels, u16 afe_in_bit_width,
Aniket Kumar Lataf8664712018-02-22 14:46:09 -0800331 struct afe_enc_config *enc_config,
332 struct afe_dec_config *dec_config);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530333int afe_spk_prot_feed_back_cfg(int src_port, int dst_port,
334 int l_ch, int r_ch, u32 enable);
335int afe_spk_prot_get_calib_data(struct afe_spkr_prot_get_vi_calib *calib);
336int afe_port_stop_nowait(int port_id);
337int afe_apply_gain(u16 port_id, u16 gain);
338int afe_q6_interface_prepare(void);
339int afe_get_port_type(u16 port_id);
340int q6afe_audio_client_buf_alloc_contiguous(unsigned int dir,
341 struct afe_audio_client *ac,
342 unsigned int bufsz,
343 unsigned int bufcnt);
344struct afe_audio_client *q6afe_audio_client_alloc(void *priv);
345int q6afe_audio_client_buf_free_contiguous(unsigned int dir,
346 struct afe_audio_client *ac);
347void q6afe_audio_client_free(struct afe_audio_client *ac);
348/* if port_id is virtual, convert to physical..
349 * if port_id is already physical, return physical
350 */
351int afe_convert_virtual_to_portid(u16 port_id);
352
353int afe_pseudo_port_start_nowait(u16 port_id);
354int afe_pseudo_port_stop_nowait(u16 port_id);
355int afe_set_lpass_clock(u16 port_id, struct afe_clk_cfg *cfg);
356int afe_set_lpass_clock_v2(u16 port_id, struct afe_clk_set *cfg);
357int afe_set_lpass_clk_cfg(int index, struct afe_clk_set *cfg);
358int afe_set_digital_codec_core_clock(u16 port_id,
359 struct afe_digital_clk_cfg *cfg);
360int afe_set_lpass_internal_digital_codec_clock(u16 port_id,
361 struct afe_digital_clk_cfg *cfg);
362int afe_enable_lpass_core_shared_clock(u16 port_id, u32 enable);
363
364int q6afe_check_osr_clk_freq(u32 freq);
365
366int afe_send_spdif_clk_cfg(struct afe_param_id_spdif_clk_cfg *cfg,
367 u16 port_id);
368int afe_send_spdif_ch_status_cfg(struct afe_param_id_spdif_ch_status_cfg
369 *ch_status_cfg, u16 port_id);
370
371int afe_spdif_port_start(u16 port_id, struct afe_spdif_port_config *spdif_port,
372 u32 rate);
373
374int afe_turn_onoff_hw_mad(u16 mad_type, u16 mad_enable);
375int afe_port_set_mad_type(u16 port_id, enum afe_mad_type mad_type);
376enum afe_mad_type afe_port_get_mad_type(u16 port_id);
377int afe_set_config(enum afe_config_type config_type, void *config_data,
378 int arg);
379void afe_clear_config(enum afe_config_type config);
380bool afe_has_config(enum afe_config_type config);
381
382void afe_set_aanc_info(struct aanc_data *aanc_info);
383int afe_port_group_set_param(u16 group_id,
384 union afe_port_group_config *afe_group_config);
385int afe_port_group_enable(u16 group_id,
386 union afe_port_group_config *afe_group_config, u16 enable);
387int afe_unmap_rtac_block(uint32_t *mem_map_handle);
388int afe_map_rtac_block(struct rtac_cal_block_data *cal_block);
389int afe_send_slot_mapping_cfg(
390 struct afe_param_id_slot_mapping_cfg *slot_mapping_cfg,
391 u16 port_id);
392int afe_send_custom_tdm_header_cfg(
393 struct afe_param_id_custom_tdm_header_cfg *custom_tdm_header_cfg,
394 u16 port_id);
395int afe_tdm_port_start(u16 port_id, struct afe_tdm_port_config *tdm_port,
396 u32 rate, u16 num_groups);
397void afe_set_routing_callback(routing_cb cb);
398int afe_get_av_dev_drift(struct afe_param_id_dev_timing_stats *timing_stats,
399 u16 port);
400#endif /* __Q6AFE_V2_H__ */