blob: d754bc57d461df47619265c3586a07ca27c49734 [file] [log] [blame]
Meng Wang688a8672019-01-29 13:43:33 +08001// SPDX-License-Identifier: GPL-2.0-only
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07002/*
Xiaoyu Ye2228bf02018-12-12 15:47:20 -08003 * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07004 */
5
6#include <linux/clk.h>
7#include <linux/delay.h>
8#include <linux/gpio.h>
9#include <linux/of_gpio.h>
10#include <linux/platform_device.h>
11#include <linux/slab.h>
12#include <linux/io.h>
13#include <linux/module.h>
14#include <linux/input.h>
15#include <linux/of_device.h>
Karthikeyan Mani5eb13422018-11-05 13:49:17 -080016#include <linux/soc/qcom/fsa4480-i2c.h>
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -070017#include <sound/core.h>
18#include <sound/soc.h>
19#include <sound/soc-dapm.h>
20#include <sound/pcm.h>
21#include <sound/pcm_params.h>
22#include <sound/info.h>
Vignesh Kulothungan483a5592018-10-19 15:00:08 -070023#include <soc/snd_event.h>
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -070024#include <dsp/audio_notifier.h>
Karthikeyan Mani7eef68e2018-12-13 17:45:02 -080025#include <soc/swr-common.h>
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -070026#include <dsp/q6afe-v2.h>
27#include <dsp/q6core.h>
28#include "device_event.h"
29#include "msm-pcm-routing-v2.h"
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -070030#include "asoc/msm-cdc-pinctrl.h"
31#include "asoc/wcd-mbhc-v2.h"
Karthikeyan Mani5eb13422018-11-05 13:49:17 -080032#include "codecs/wcd938x/wcd938x-mbhc.h"
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -070033#include "codecs/wsa881x.h"
Karthikeyan Mani5eb13422018-11-05 13:49:17 -080034#include "codecs/wcd938x/wcd938x.h"
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -070035#include "codecs/bolero/bolero-cdc.h"
36#include <dt-bindings/sound/audio-codec-port-types.h>
37#include "codecs/bolero/wsa-macro.h"
Vatsal Bucha82b30ba2019-04-17 12:43:54 +053038#include "kona-port-config.h"
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -070039
40#define DRV_NAME "kona-asoc-snd"
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -070041#define __CHIPSET__ "KONA "
42#define MSM_DAILINK_NAME(name) (__CHIPSET__#name)
43
44#define SAMPLING_RATE_8KHZ 8000
Vignesh Kulothungan483a5592018-10-19 15:00:08 -070045#define SAMPLING_RATE_11P025KHZ 11025
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -070046#define SAMPLING_RATE_16KHZ 16000
Vignesh Kulothungan483a5592018-10-19 15:00:08 -070047#define SAMPLING_RATE_22P05KHZ 22050
48#define SAMPLING_RATE_32KHZ 32000
49#define SAMPLING_RATE_44P1KHZ 44100
50#define SAMPLING_RATE_48KHZ 48000
51#define SAMPLING_RATE_88P2KHZ 88200
52#define SAMPLING_RATE_96KHZ 96000
53#define SAMPLING_RATE_176P4KHZ 176400
54#define SAMPLING_RATE_192KHZ 192000
55#define SAMPLING_RATE_352P8KHZ 352800
56#define SAMPLING_RATE_384KHZ 384000
57
Karthikeyan Mani5eb13422018-11-05 13:49:17 -080058#define WCD9XXX_MBHC_DEF_RLOADS 5
59#define WCD9XXX_MBHC_DEF_BUTTONS 8
60#define CODEC_EXT_CLK_RATE 9600000
61#define ADSP_STATE_READY_TIMEOUT_MS 3000
62#define DEV_NAME_STR_LEN 32
63#define WCD_MBHC_HS_V_MAX 1600
64
Vignesh Kulothungan483a5592018-10-19 15:00:08 -070065#define TDM_CHANNEL_MAX 8
66#define DEV_NAME_STR_LEN 32
67
68#define MSM_LL_QOS_VALUE 300 /* time in us to ensure LPM doesn't go in C3/C4 */
69
70#define ADSP_STATE_READY_TIMEOUT_MS 3000
71
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -070072#define WSA8810_NAME_1 "wsa881x.20170211"
73#define WSA8810_NAME_2 "wsa881x.20170212"
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -080074#define WCN_CDC_SLIM_RX_CH_MAX 2
75#define WCN_CDC_SLIM_TX_CH_MAX 2
Vatsal Bucha82b30ba2019-04-17 12:43:54 +053076#define WCN_CDC_SLIM_TX_CH_MAX_LITO 3
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -070077
Vignesh Kulothungan483a5592018-10-19 15:00:08 -070078enum {
79 TDM_0 = 0,
80 TDM_1,
81 TDM_2,
82 TDM_3,
83 TDM_4,
84 TDM_5,
85 TDM_6,
86 TDM_7,
87 TDM_PORT_MAX,
88};
89
90enum {
91 TDM_PRI = 0,
92 TDM_SEC,
93 TDM_TERT,
94 TDM_INTERFACE_MAX,
95};
96
97enum {
98 PRIM_AUX_PCM = 0,
99 SEC_AUX_PCM,
100 TERT_AUX_PCM,
101 AUX_PCM_MAX,
102};
103
104enum {
105 PRIM_MI2S = 0,
106 SEC_MI2S,
107 TERT_MI2S,
108 MI2S_MAX,
109};
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700110
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -0700111enum {
112 WSA_CDC_DMA_RX_0 = 0,
113 WSA_CDC_DMA_RX_1,
114 RX_CDC_DMA_RX_0,
115 RX_CDC_DMA_RX_1,
116 RX_CDC_DMA_RX_2,
117 RX_CDC_DMA_RX_3,
118 RX_CDC_DMA_RX_5,
119 CDC_DMA_RX_MAX,
120};
121
122enum {
123 WSA_CDC_DMA_TX_0 = 0,
124 WSA_CDC_DMA_TX_1,
125 WSA_CDC_DMA_TX_2,
126 TX_CDC_DMA_TX_0,
127 TX_CDC_DMA_TX_3,
128 TX_CDC_DMA_TX_4,
Xiaoyu Ye2228bf02018-12-12 15:47:20 -0800129 VA_CDC_DMA_TX_0,
130 VA_CDC_DMA_TX_1,
131 VA_CDC_DMA_TX_2,
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -0700132 CDC_DMA_TX_MAX,
133};
134
Banajit Goswami83a370d2019-03-05 16:15:21 -0800135enum {
136 SLIM_RX_7 = 0,
137 SLIM_RX_MAX,
138};
139enum {
140 SLIM_TX_7 = 0,
Vatsal Bucha82b30ba2019-04-17 12:43:54 +0530141 SLIM_TX_8,
Banajit Goswami83a370d2019-03-05 16:15:21 -0800142 SLIM_TX_MAX,
143};
144
Meng Wange8e53822019-03-18 10:49:50 +0800145enum {
146 AFE_LOOPBACK_TX_IDX = 0,
147 AFE_LOOPBACK_TX_IDX_MAX,
148};
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700149struct msm_asoc_mach_data {
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700150 struct snd_info_entry *codec_root;
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700151 int usbc_en2_gpio; /* used by gpio driver API */
152 struct device_node *dmic01_gpio_p; /* used by pinctrl API */
153 struct device_node *dmic23_gpio_p; /* used by pinctrl API */
154 struct device_node *dmic45_gpio_p; /* used by pinctrl API */
155 struct device_node *us_euro_gpio_p; /* used by pinctrl API */
156 struct pinctrl *usbc_en2_gpio_p; /* used by pinctrl API */
157 struct device_node *hph_en1_gpio_p; /* used by pinctrl API */
158 struct device_node *hph_en0_gpio_p; /* used by pinctrl API */
159 bool is_afe_config_done;
Karthikeyan Mani5eb13422018-11-05 13:49:17 -0800160 struct device_node *fsa_handle;
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700161};
162
163struct tdm_port {
164 u32 mode;
165 u32 channel;
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700166};
167
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -0800168enum {
169 EXT_DISP_RX_IDX_DP = 0,
170 EXT_DISP_RX_IDX_MAX,
171};
172
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -0700173struct msm_wsa881x_dev_info {
174 struct device_node *of_node;
175 u32 index;
176};
177
178struct aux_codec_dev_info {
179 struct device_node *of_node;
180 u32 index;
181};
182
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700183struct dev_config {
184 u32 sample_rate;
185 u32 bit_format;
186 u32 channels;
187};
188
Banajit Goswami83a370d2019-03-05 16:15:21 -0800189/* Default configuration of slimbus channels */
190static struct dev_config slim_rx_cfg[] = {
191 [SLIM_RX_7] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
192};
193
194static struct dev_config slim_tx_cfg[] = {
195 [SLIM_TX_7] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
Vatsal Bucha82b30ba2019-04-17 12:43:54 +0530196 [SLIM_TX_8] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
Banajit Goswami83a370d2019-03-05 16:15:21 -0800197};
198
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -0800199/* Default configuration of external display BE */
200static struct dev_config ext_disp_rx_cfg[] = {
201 [EXT_DISP_RX_IDX_DP] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
202};
203
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700204static struct dev_config usb_rx_cfg = {
205 .sample_rate = SAMPLING_RATE_48KHZ,
206 .bit_format = SNDRV_PCM_FORMAT_S16_LE,
207 .channels = 2,
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700208};
209
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700210static struct dev_config usb_tx_cfg = {
211 .sample_rate = SAMPLING_RATE_48KHZ,
212 .bit_format = SNDRV_PCM_FORMAT_S16_LE,
213 .channels = 1,
214};
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700215
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700216static struct dev_config proxy_rx_cfg = {
217 .sample_rate = SAMPLING_RATE_48KHZ,
218 .bit_format = SNDRV_PCM_FORMAT_S16_LE,
219 .channels = 2,
220};
221
222static struct afe_clk_set mi2s_clk[MI2S_MAX] = {
223 {
224 AFE_API_VERSION_I2S_CONFIG,
225 Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT,
226 Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ,
227 Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO,
228 Q6AFE_LPASS_CLK_ROOT_DEFAULT,
229 0,
230 },
231 {
232 AFE_API_VERSION_I2S_CONFIG,
233 Q6AFE_LPASS_CLK_ID_SEC_MI2S_IBIT,
234 Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ,
235 Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO,
236 Q6AFE_LPASS_CLK_ROOT_DEFAULT,
237 0,
238 },
239 {
240 AFE_API_VERSION_I2S_CONFIG,
241 Q6AFE_LPASS_CLK_ID_TER_MI2S_IBIT,
242 Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ,
243 Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO,
244 Q6AFE_LPASS_CLK_ROOT_DEFAULT,
245 0,
246 },
247};
248
249struct mi2s_conf {
250 struct mutex lock;
251 u32 ref_cnt;
252 u32 msm_is_mi2s_master;
253};
254
255static u32 mi2s_ebit_clk[MI2S_MAX] = {
256 Q6AFE_LPASS_CLK_ID_PRI_MI2S_EBIT,
257 Q6AFE_LPASS_CLK_ID_SEC_MI2S_EBIT,
258 Q6AFE_LPASS_CLK_ID_TER_MI2S_EBIT,
259};
260
261static struct mi2s_conf mi2s_intf_conf[MI2S_MAX];
262
263/* Default configuration of TDM channels */
264static struct dev_config tdm_rx_cfg[TDM_INTERFACE_MAX][TDM_PORT_MAX] = {
265 { /* PRI TDM */
266 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_0 */
267 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_1 */
268 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_2 */
269 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_3 */
270 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_4 */
271 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_5 */
272 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_6 */
273 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_7 */
274 },
275 { /* SEC TDM */
276 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_0 */
277 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_1 */
278 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_2 */
279 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_3 */
280 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_4 */
281 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_5 */
282 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_6 */
283 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_7 */
284 },
285 { /* TERT TDM */
286 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_0 */
287 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_1 */
288 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_2 */
289 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_3 */
290 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_4 */
291 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_5 */
292 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_6 */
293 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_7 */
294 },
295};
296
297static struct dev_config tdm_tx_cfg[TDM_INTERFACE_MAX][TDM_PORT_MAX] = {
298 { /* PRI TDM */
299 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_0 */
300 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_1 */
301 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_2 */
302 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_3 */
303 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_4 */
304 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_5 */
305 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_6 */
306 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_7 */
307 },
308 { /* SEC TDM */
309 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_0 */
310 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_1 */
311 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_2 */
312 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_3 */
313 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_4 */
314 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_5 */
315 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_6 */
316 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_7 */
317 },
318 { /* TERT TDM */
319 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_0 */
320 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_1 */
321 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_2 */
322 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_3 */
323 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_4 */
324 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_5 */
325 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_6 */
326 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_7 */
327 },
328};
329
330/* Default configuration of AUX PCM channels */
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700331static struct dev_config aux_pcm_rx_cfg[] = {
332 [PRIM_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700333 [SEC_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
334 [TERT_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700335};
336
337static struct dev_config aux_pcm_tx_cfg[] = {
338 [PRIM_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700339 [SEC_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
340 [TERT_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700341};
342
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700343/* Default configuration of MI2S channels */
344static struct dev_config mi2s_rx_cfg[] = {
345 [PRIM_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
346 [SEC_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
347 [TERT_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
348};
349
350static struct dev_config mi2s_tx_cfg[] = {
351 [PRIM_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
352 [SEC_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
353 [TERT_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
354};
355
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -0700356/* Default configuration of Codec DMA Interface RX */
357static struct dev_config cdc_dma_rx_cfg[] = {
358 [WSA_CDC_DMA_RX_0] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
359 [WSA_CDC_DMA_RX_1] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
360 [RX_CDC_DMA_RX_0] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
361 [RX_CDC_DMA_RX_1] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
362 [RX_CDC_DMA_RX_2] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
363 [RX_CDC_DMA_RX_3] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
364 [RX_CDC_DMA_RX_5] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
365};
366
367/* Default configuration of Codec DMA Interface TX */
368static struct dev_config cdc_dma_tx_cfg[] = {
369 [WSA_CDC_DMA_TX_0] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
370 [WSA_CDC_DMA_TX_1] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
371 [WSA_CDC_DMA_TX_2] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
372 [TX_CDC_DMA_TX_0] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
373 [TX_CDC_DMA_TX_3] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
374 [TX_CDC_DMA_TX_4] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
Xiaoyu Ye2228bf02018-12-12 15:47:20 -0800375 [VA_CDC_DMA_TX_0] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 8},
376 [VA_CDC_DMA_TX_1] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 8},
377 [VA_CDC_DMA_TX_2] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 8},
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -0700378};
379
Meng Wange8e53822019-03-18 10:49:50 +0800380static struct dev_config afe_loopback_tx_cfg[] = {
381 [AFE_LOOPBACK_TX_IDX] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
382};
383
Meng Wangd1db67c2019-04-17 12:41:34 +0800384static int msm_vi_feed_tx_ch = 2;
385static const char *const vi_feed_ch_text[] = {"One", "Two"};
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700386static char const *bit_format_text[] = {"S16_LE", "S24_LE", "S24_3LE",
387 "S32_LE"};
388static char const *ch_text[] = {"Two", "Three", "Four", "Five",
389 "Six", "Seven", "Eight"};
390static char const *usb_sample_rate_text[] = {"KHZ_8", "KHZ_11P025",
391 "KHZ_16", "KHZ_22P05",
392 "KHZ_32", "KHZ_44P1", "KHZ_48",
393 "KHZ_88P2", "KHZ_96", "KHZ_176P4",
394 "KHZ_192", "KHZ_352P8", "KHZ_384"};
395static const char *const usb_ch_text[] = {"One", "Two", "Three", "Four",
396 "Five", "Six", "Seven",
397 "Eight"};
398static char const *tdm_sample_rate_text[] = {"KHZ_8", "KHZ_16", "KHZ_32",
399 "KHZ_48", "KHZ_176P4",
400 "KHZ_352P8"};
401static char const *tdm_bit_format_text[] = {"S16_LE", "S24_LE", "S32_LE"};
402static char const *tdm_ch_text[] = {"One", "Two", "Three", "Four",
403 "Five", "Six", "Seven", "Eight"};
404static const char *const auxpcm_rate_text[] = {"KHZ_8", "KHZ_16"};
405static char const *mi2s_rate_text[] = {"KHZ_8", "KHZ_11P025", "KHZ_16",
406 "KHZ_22P05", "KHZ_32", "KHZ_44P1",
407 "KHZ_48", "KHZ_96", "KHZ_192"};
408static const char *const mi2s_ch_text[] = {"One", "Two", "Three", "Four",
409 "Five", "Six", "Seven",
410 "Eight"};
411
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -0700412static const char *const cdc_dma_rx_ch_text[] = {"One", "Two"};
413static const char *const cdc_dma_tx_ch_text[] = {"One", "Two", "Three", "Four",
414 "Five", "Six", "Seven",
415 "Eight"};
416static char const *cdc_dma_sample_rate_text[] = {"KHZ_8", "KHZ_11P025",
417 "KHZ_16", "KHZ_22P05",
418 "KHZ_32", "KHZ_44P1", "KHZ_48",
419 "KHZ_88P2", "KHZ_96",
420 "KHZ_176P4", "KHZ_192",
421 "KHZ_352P8", "KHZ_384"};
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -0800422static char const *ext_disp_bit_format_text[] = {"S16_LE", "S24_LE",
423 "S24_3LE"};
424static char const *ext_disp_sample_rate_text[] = {"KHZ_48", "KHZ_96",
425 "KHZ_192", "KHZ_32", "KHZ_44P1",
426 "KHZ_88P2", "KHZ_176P4"};
Banajit Goswami83a370d2019-03-05 16:15:21 -0800427static char const *bt_sample_rate_text[] = {"KHZ_8", "KHZ_16",
428 "KHZ_44P1", "KHZ_48",
429 "KHZ_88P2", "KHZ_96"};
430static char const *bt_sample_rate_rx_text[] = {"KHZ_8", "KHZ_16",
431 "KHZ_44P1", "KHZ_48",
432 "KHZ_88P2", "KHZ_96"};
433static char const *bt_sample_rate_tx_text[] = {"KHZ_8", "KHZ_16",
434 "KHZ_44P1", "KHZ_48",
435 "KHZ_88P2", "KHZ_96"};
Meng Wange8e53822019-03-18 10:49:50 +0800436static const char *const afe_loopback_tx_ch_text[] = {"One", "Two"};
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -0700437
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700438static SOC_ENUM_SINGLE_EXT_DECL(usb_rx_sample_rate, usb_sample_rate_text);
439static SOC_ENUM_SINGLE_EXT_DECL(usb_tx_sample_rate, usb_sample_rate_text);
440static SOC_ENUM_SINGLE_EXT_DECL(usb_rx_format, bit_format_text);
441static SOC_ENUM_SINGLE_EXT_DECL(usb_tx_format, bit_format_text);
442static SOC_ENUM_SINGLE_EXT_DECL(usb_rx_chs, usb_ch_text);
443static SOC_ENUM_SINGLE_EXT_DECL(usb_tx_chs, usb_ch_text);
Meng Wangd1db67c2019-04-17 12:41:34 +0800444static SOC_ENUM_SINGLE_EXT_DECL(vi_feed_tx_chs, vi_feed_ch_text);
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700445static SOC_ENUM_SINGLE_EXT_DECL(proxy_rx_chs, ch_text);
446static SOC_ENUM_SINGLE_EXT_DECL(tdm_rx_sample_rate, tdm_sample_rate_text);
447static SOC_ENUM_SINGLE_EXT_DECL(tdm_tx_sample_rate, tdm_sample_rate_text);
448static SOC_ENUM_SINGLE_EXT_DECL(tdm_rx_format, tdm_bit_format_text);
449static SOC_ENUM_SINGLE_EXT_DECL(tdm_tx_format, tdm_bit_format_text);
450static SOC_ENUM_SINGLE_EXT_DECL(tdm_tx_chs, tdm_ch_text);
451static SOC_ENUM_SINGLE_EXT_DECL(tdm_rx_chs, tdm_ch_text);
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700452static SOC_ENUM_SINGLE_EXT_DECL(prim_aux_pcm_rx_sample_rate, auxpcm_rate_text);
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700453static SOC_ENUM_SINGLE_EXT_DECL(sec_aux_pcm_rx_sample_rate, auxpcm_rate_text);
454static SOC_ENUM_SINGLE_EXT_DECL(tert_aux_pcm_rx_sample_rate, auxpcm_rate_text);
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700455static SOC_ENUM_SINGLE_EXT_DECL(prim_aux_pcm_tx_sample_rate, auxpcm_rate_text);
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700456static SOC_ENUM_SINGLE_EXT_DECL(sec_aux_pcm_tx_sample_rate, auxpcm_rate_text);
457static SOC_ENUM_SINGLE_EXT_DECL(tert_aux_pcm_tx_sample_rate, auxpcm_rate_text);
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700458static SOC_ENUM_SINGLE_EXT_DECL(aux_pcm_rx_format, bit_format_text);
459static SOC_ENUM_SINGLE_EXT_DECL(aux_pcm_tx_format, bit_format_text);
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700460static SOC_ENUM_SINGLE_EXT_DECL(prim_mi2s_rx_sample_rate, mi2s_rate_text);
461static SOC_ENUM_SINGLE_EXT_DECL(sec_mi2s_rx_sample_rate, mi2s_rate_text);
462static SOC_ENUM_SINGLE_EXT_DECL(tert_mi2s_rx_sample_rate, mi2s_rate_text);
463static SOC_ENUM_SINGLE_EXT_DECL(prim_mi2s_tx_sample_rate, mi2s_rate_text);
464static SOC_ENUM_SINGLE_EXT_DECL(sec_mi2s_tx_sample_rate, mi2s_rate_text);
465static SOC_ENUM_SINGLE_EXT_DECL(tert_mi2s_tx_sample_rate, mi2s_rate_text);
466static SOC_ENUM_SINGLE_EXT_DECL(mi2s_rx_format, bit_format_text);
467static SOC_ENUM_SINGLE_EXT_DECL(mi2s_tx_format, bit_format_text);
468static SOC_ENUM_SINGLE_EXT_DECL(prim_mi2s_rx_chs, mi2s_ch_text);
469static SOC_ENUM_SINGLE_EXT_DECL(sec_mi2s_rx_chs, mi2s_ch_text);
470static SOC_ENUM_SINGLE_EXT_DECL(tert_mi2s_rx_chs, mi2s_ch_text);
471static SOC_ENUM_SINGLE_EXT_DECL(prim_mi2s_tx_chs, mi2s_ch_text);
472static SOC_ENUM_SINGLE_EXT_DECL(sec_mi2s_tx_chs, mi2s_ch_text);
473static SOC_ENUM_SINGLE_EXT_DECL(tert_mi2s_tx_chs, mi2s_ch_text);
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -0700474static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_rx_0_chs, cdc_dma_rx_ch_text);
475static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_rx_1_chs, cdc_dma_rx_ch_text);
476static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_0_chs, cdc_dma_rx_ch_text);
477static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_1_chs, cdc_dma_rx_ch_text);
478static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_2_chs, cdc_dma_rx_ch_text);
479static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_3_chs, cdc_dma_rx_ch_text);
480static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_5_chs, cdc_dma_rx_ch_text);
481static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_0_chs, cdc_dma_tx_ch_text);
482static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_1_chs, cdc_dma_tx_ch_text);
483static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_2_chs, cdc_dma_tx_ch_text);
484static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_0_chs, cdc_dma_tx_ch_text);
485static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_3_chs, cdc_dma_tx_ch_text);
486static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_4_chs, cdc_dma_tx_ch_text);
Xiaoyu Ye2228bf02018-12-12 15:47:20 -0800487static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_0_chs, cdc_dma_tx_ch_text);
488static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_1_chs, cdc_dma_tx_ch_text);
489static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_2_chs, cdc_dma_tx_ch_text);
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -0700490static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_rx_0_format, bit_format_text);
491static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_rx_1_format, bit_format_text);
492static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_0_format, bit_format_text);
493static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_1_format, bit_format_text);
494static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_2_format, bit_format_text);
495static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_3_format, bit_format_text);
496static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_5_format, bit_format_text);
497static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_1_format, bit_format_text);
498static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_2_format, bit_format_text);
499static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_0_format, bit_format_text);
500static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_3_format, bit_format_text);
501static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_4_format, bit_format_text);
Xiaoyu Ye2228bf02018-12-12 15:47:20 -0800502static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_0_format, bit_format_text);
503static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_1_format, bit_format_text);
504static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_2_format, bit_format_text);
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -0700505static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_rx_0_sample_rate,
506 cdc_dma_sample_rate_text);
507static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_rx_1_sample_rate,
508 cdc_dma_sample_rate_text);
509static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_0_sample_rate,
510 cdc_dma_sample_rate_text);
511static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_1_sample_rate,
512 cdc_dma_sample_rate_text);
513static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_2_sample_rate,
514 cdc_dma_sample_rate_text);
515static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_3_sample_rate,
516 cdc_dma_sample_rate_text);
517static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_5_sample_rate,
518 cdc_dma_sample_rate_text);
519static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_0_sample_rate,
520 cdc_dma_sample_rate_text);
521static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_1_sample_rate,
522 cdc_dma_sample_rate_text);
523static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_2_sample_rate,
524 cdc_dma_sample_rate_text);
525static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_0_sample_rate,
526 cdc_dma_sample_rate_text);
527static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_3_sample_rate,
528 cdc_dma_sample_rate_text);
529static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_4_sample_rate,
530 cdc_dma_sample_rate_text);
Xiaoyu Ye2228bf02018-12-12 15:47:20 -0800531static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_0_sample_rate,
532 cdc_dma_sample_rate_text);
533static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_1_sample_rate,
534 cdc_dma_sample_rate_text);
535static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_2_sample_rate,
536 cdc_dma_sample_rate_text);
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -0800537static SOC_ENUM_SINGLE_EXT_DECL(ext_disp_rx_chs, ch_text);
538static SOC_ENUM_SINGLE_EXT_DECL(ext_disp_rx_format, ext_disp_bit_format_text);
539static SOC_ENUM_SINGLE_EXT_DECL(ext_disp_rx_sample_rate,
540 ext_disp_sample_rate_text);
Banajit Goswami83a370d2019-03-05 16:15:21 -0800541static SOC_ENUM_SINGLE_EXT_DECL(bt_sample_rate, bt_sample_rate_text);
542static SOC_ENUM_SINGLE_EXT_DECL(bt_sample_rate_rx, bt_sample_rate_rx_text);
543static SOC_ENUM_SINGLE_EXT_DECL(bt_sample_rate_tx, bt_sample_rate_tx_text);
Meng Wange8e53822019-03-18 10:49:50 +0800544static SOC_ENUM_SINGLE_EXT_DECL(afe_loopback_tx_chs, afe_loopback_tx_ch_text);
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700545
546static bool is_initial_boot;
547static bool codec_reg_done;
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -0700548static struct snd_soc_aux_dev *msm_aux_dev;
549static struct snd_soc_codec_conf *msm_codec_conf;
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700550static struct snd_soc_card snd_soc_card_kona_msm;
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -0700551static int dmic_0_1_gpio_cnt;
552static int dmic_2_3_gpio_cnt;
553static int dmic_4_5_gpio_cnt;
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700554
Karthikeyan Mani5eb13422018-11-05 13:49:17 -0800555static void *def_wcd_mbhc_cal(void);
556
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700557/*
558 * Need to report LINEIN
559 * if R/L channel impedance is larger than 5K ohm
560 */
561static struct wcd_mbhc_config wcd_mbhc_cfg = {
562 .read_fw_bin = false,
563 .calibration = NULL,
564 .detect_extn_cable = true,
565 .mono_stero_detection = false,
566 .swap_gnd_mic = NULL,
567 .hs_ext_micbias = true,
568 .key_code[0] = KEY_MEDIA,
569 .key_code[1] = KEY_VOICECOMMAND,
570 .key_code[2] = KEY_VOLUMEUP,
571 .key_code[3] = KEY_VOLUMEDOWN,
572 .key_code[4] = 0,
573 .key_code[5] = 0,
574 .key_code[6] = 0,
575 .key_code[7] = 0,
576 .linein_th = 5000,
577 .moisture_en = true,
578 .mbhc_micbias = MIC_BIAS_2,
579 .anc_micbias = MIC_BIAS_2,
580 .enable_anc_mic_detect = false,
581};
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700582
583static inline int param_is_mask(int p)
584{
585 return (p >= SNDRV_PCM_HW_PARAM_FIRST_MASK) &&
586 (p <= SNDRV_PCM_HW_PARAM_LAST_MASK);
587}
588
589static inline struct snd_mask *param_to_mask(struct snd_pcm_hw_params *p,
590 int n)
591{
592 return &(p->masks[n - SNDRV_PCM_HW_PARAM_FIRST_MASK]);
593}
594
595static void param_set_mask(struct snd_pcm_hw_params *p, int n,
596 unsigned int bit)
597{
598 if (bit >= SNDRV_MASK_MAX)
599 return;
600 if (param_is_mask(n)) {
601 struct snd_mask *m = param_to_mask(p, n);
602
603 m->bits[0] = 0;
604 m->bits[1] = 0;
605 m->bits[bit >> 5] |= (1 << (bit & 31));
606 }
607}
608
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700609static int usb_audio_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
610 struct snd_ctl_elem_value *ucontrol)
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700611{
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700612 int sample_rate_val = 0;
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700613
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700614 switch (usb_rx_cfg.sample_rate) {
615 case SAMPLING_RATE_384KHZ:
616 sample_rate_val = 12;
617 break;
618 case SAMPLING_RATE_352P8KHZ:
619 sample_rate_val = 11;
620 break;
621 case SAMPLING_RATE_192KHZ:
622 sample_rate_val = 10;
623 break;
624 case SAMPLING_RATE_176P4KHZ:
625 sample_rate_val = 9;
626 break;
627 case SAMPLING_RATE_96KHZ:
628 sample_rate_val = 8;
629 break;
630 case SAMPLING_RATE_88P2KHZ:
631 sample_rate_val = 7;
632 break;
633 case SAMPLING_RATE_48KHZ:
634 sample_rate_val = 6;
635 break;
636 case SAMPLING_RATE_44P1KHZ:
637 sample_rate_val = 5;
638 break;
639 case SAMPLING_RATE_32KHZ:
640 sample_rate_val = 4;
641 break;
642 case SAMPLING_RATE_22P05KHZ:
643 sample_rate_val = 3;
644 break;
645 case SAMPLING_RATE_16KHZ:
646 sample_rate_val = 2;
647 break;
648 case SAMPLING_RATE_11P025KHZ:
649 sample_rate_val = 1;
650 break;
651 case SAMPLING_RATE_8KHZ:
652 default:
653 sample_rate_val = 0;
654 break;
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700655 }
656
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700657 ucontrol->value.integer.value[0] = sample_rate_val;
658 pr_debug("%s: usb_audio_rx_sample_rate = %d\n", __func__,
659 usb_rx_cfg.sample_rate);
660 return 0;
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -0700661}
662
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700663static int usb_audio_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
664 struct snd_ctl_elem_value *ucontrol)
665{
666 switch (ucontrol->value.integer.value[0]) {
667 case 12:
668 usb_rx_cfg.sample_rate = SAMPLING_RATE_384KHZ;
669 break;
670 case 11:
671 usb_rx_cfg.sample_rate = SAMPLING_RATE_352P8KHZ;
672 break;
673 case 10:
674 usb_rx_cfg.sample_rate = SAMPLING_RATE_192KHZ;
675 break;
676 case 9:
677 usb_rx_cfg.sample_rate = SAMPLING_RATE_176P4KHZ;
678 break;
679 case 8:
680 usb_rx_cfg.sample_rate = SAMPLING_RATE_96KHZ;
681 break;
682 case 7:
683 usb_rx_cfg.sample_rate = SAMPLING_RATE_88P2KHZ;
684 break;
685 case 6:
686 usb_rx_cfg.sample_rate = SAMPLING_RATE_48KHZ;
687 break;
688 case 5:
689 usb_rx_cfg.sample_rate = SAMPLING_RATE_44P1KHZ;
690 break;
691 case 4:
692 usb_rx_cfg.sample_rate = SAMPLING_RATE_32KHZ;
693 break;
694 case 3:
695 usb_rx_cfg.sample_rate = SAMPLING_RATE_22P05KHZ;
696 break;
697 case 2:
698 usb_rx_cfg.sample_rate = SAMPLING_RATE_16KHZ;
699 break;
700 case 1:
701 usb_rx_cfg.sample_rate = SAMPLING_RATE_11P025KHZ;
702 break;
703 case 0:
704 usb_rx_cfg.sample_rate = SAMPLING_RATE_8KHZ;
705 break;
706 default:
707 usb_rx_cfg.sample_rate = SAMPLING_RATE_48KHZ;
708 break;
709 }
710
711 pr_debug("%s: control value = %ld, usb_audio_rx_sample_rate = %d\n",
712 __func__, ucontrol->value.integer.value[0],
713 usb_rx_cfg.sample_rate);
714 return 0;
715}
716
717static int usb_audio_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
718 struct snd_ctl_elem_value *ucontrol)
719{
720 int sample_rate_val = 0;
721
722 switch (usb_tx_cfg.sample_rate) {
723 case SAMPLING_RATE_384KHZ:
724 sample_rate_val = 12;
725 break;
726 case SAMPLING_RATE_352P8KHZ:
727 sample_rate_val = 11;
728 break;
729 case SAMPLING_RATE_192KHZ:
730 sample_rate_val = 10;
731 break;
732 case SAMPLING_RATE_176P4KHZ:
733 sample_rate_val = 9;
734 break;
735 case SAMPLING_RATE_96KHZ:
736 sample_rate_val = 8;
737 break;
738 case SAMPLING_RATE_88P2KHZ:
739 sample_rate_val = 7;
740 break;
741 case SAMPLING_RATE_48KHZ:
742 sample_rate_val = 6;
743 break;
744 case SAMPLING_RATE_44P1KHZ:
745 sample_rate_val = 5;
746 break;
747 case SAMPLING_RATE_32KHZ:
748 sample_rate_val = 4;
749 break;
750 case SAMPLING_RATE_22P05KHZ:
751 sample_rate_val = 3;
752 break;
753 case SAMPLING_RATE_16KHZ:
754 sample_rate_val = 2;
755 break;
756 case SAMPLING_RATE_11P025KHZ:
757 sample_rate_val = 1;
758 break;
759 case SAMPLING_RATE_8KHZ:
760 sample_rate_val = 0;
761 break;
762 default:
763 sample_rate_val = 6;
764 break;
765 }
766
767 ucontrol->value.integer.value[0] = sample_rate_val;
768 pr_debug("%s: usb_audio_tx_sample_rate = %d\n", __func__,
769 usb_tx_cfg.sample_rate);
770 return 0;
771}
772
773static int usb_audio_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
774 struct snd_ctl_elem_value *ucontrol)
775{
776 switch (ucontrol->value.integer.value[0]) {
777 case 12:
778 usb_tx_cfg.sample_rate = SAMPLING_RATE_384KHZ;
779 break;
780 case 11:
781 usb_tx_cfg.sample_rate = SAMPLING_RATE_352P8KHZ;
782 break;
783 case 10:
784 usb_tx_cfg.sample_rate = SAMPLING_RATE_192KHZ;
785 break;
786 case 9:
787 usb_tx_cfg.sample_rate = SAMPLING_RATE_176P4KHZ;
788 break;
789 case 8:
790 usb_tx_cfg.sample_rate = SAMPLING_RATE_96KHZ;
791 break;
792 case 7:
793 usb_tx_cfg.sample_rate = SAMPLING_RATE_88P2KHZ;
794 break;
795 case 6:
796 usb_tx_cfg.sample_rate = SAMPLING_RATE_48KHZ;
797 break;
798 case 5:
799 usb_tx_cfg.sample_rate = SAMPLING_RATE_44P1KHZ;
800 break;
801 case 4:
802 usb_tx_cfg.sample_rate = SAMPLING_RATE_32KHZ;
803 break;
804 case 3:
805 usb_tx_cfg.sample_rate = SAMPLING_RATE_22P05KHZ;
806 break;
807 case 2:
808 usb_tx_cfg.sample_rate = SAMPLING_RATE_16KHZ;
809 break;
810 case 1:
811 usb_tx_cfg.sample_rate = SAMPLING_RATE_11P025KHZ;
812 break;
813 case 0:
814 usb_tx_cfg.sample_rate = SAMPLING_RATE_8KHZ;
815 break;
816 default:
817 usb_tx_cfg.sample_rate = SAMPLING_RATE_48KHZ;
818 break;
819 }
820
821 pr_debug("%s: control value = %ld, usb_audio_tx_sample_rate = %d\n",
822 __func__, ucontrol->value.integer.value[0],
823 usb_tx_cfg.sample_rate);
824 return 0;
825}
Meng Wange8e53822019-03-18 10:49:50 +0800826static int afe_loopback_tx_ch_get(struct snd_kcontrol *kcontrol,
827 struct snd_ctl_elem_value *ucontrol)
828{
829 pr_debug("%s: afe_loopback_tx_ch = %d\n", __func__,
830 afe_loopback_tx_cfg[0].channels);
831 ucontrol->value.enumerated.item[0] =
832 afe_loopback_tx_cfg[0].channels - 1;
833
834 return 0;
835}
836
837static int afe_loopback_tx_ch_put(struct snd_kcontrol *kcontrol,
838 struct snd_ctl_elem_value *ucontrol)
839{
840 afe_loopback_tx_cfg[0].channels =
841 ucontrol->value.enumerated.item[0] + 1;
842 pr_debug("%s: afe_loopback_tx_ch = %d\n", __func__,
843 afe_loopback_tx_cfg[0].channels);
844
845 return 1;
846}
Vignesh Kulothungan483a5592018-10-19 15:00:08 -0700847
848static int usb_audio_rx_format_get(struct snd_kcontrol *kcontrol,
849 struct snd_ctl_elem_value *ucontrol)
850{
851 switch (usb_rx_cfg.bit_format) {
852 case SNDRV_PCM_FORMAT_S32_LE:
853 ucontrol->value.integer.value[0] = 3;
854 break;
855 case SNDRV_PCM_FORMAT_S24_3LE:
856 ucontrol->value.integer.value[0] = 2;
857 break;
858 case SNDRV_PCM_FORMAT_S24_LE:
859 ucontrol->value.integer.value[0] = 1;
860 break;
861 case SNDRV_PCM_FORMAT_S16_LE:
862 default:
863 ucontrol->value.integer.value[0] = 0;
864 break;
865 }
866
867 pr_debug("%s: usb_audio_rx_format = %d, ucontrol value = %ld\n",
868 __func__, usb_rx_cfg.bit_format,
869 ucontrol->value.integer.value[0]);
870 return 0;
871}
872
873static int usb_audio_rx_format_put(struct snd_kcontrol *kcontrol,
874 struct snd_ctl_elem_value *ucontrol)
875{
876 int rc = 0;
877
878 switch (ucontrol->value.integer.value[0]) {
879 case 3:
880 usb_rx_cfg.bit_format = SNDRV_PCM_FORMAT_S32_LE;
881 break;
882 case 2:
883 usb_rx_cfg.bit_format = SNDRV_PCM_FORMAT_S24_3LE;
884 break;
885 case 1:
886 usb_rx_cfg.bit_format = SNDRV_PCM_FORMAT_S24_LE;
887 break;
888 case 0:
889 default:
890 usb_rx_cfg.bit_format = SNDRV_PCM_FORMAT_S16_LE;
891 break;
892 }
893 pr_debug("%s: usb_audio_rx_format = %d, ucontrol value = %ld\n",
894 __func__, usb_rx_cfg.bit_format,
895 ucontrol->value.integer.value[0]);
896
897 return rc;
898}
899
900static int usb_audio_tx_format_get(struct snd_kcontrol *kcontrol,
901 struct snd_ctl_elem_value *ucontrol)
902{
903 switch (usb_tx_cfg.bit_format) {
904 case SNDRV_PCM_FORMAT_S32_LE:
905 ucontrol->value.integer.value[0] = 3;
906 break;
907 case SNDRV_PCM_FORMAT_S24_3LE:
908 ucontrol->value.integer.value[0] = 2;
909 break;
910 case SNDRV_PCM_FORMAT_S24_LE:
911 ucontrol->value.integer.value[0] = 1;
912 break;
913 case SNDRV_PCM_FORMAT_S16_LE:
914 default:
915 ucontrol->value.integer.value[0] = 0;
916 break;
917 }
918
919 pr_debug("%s: usb_audio_tx_format = %d, ucontrol value = %ld\n",
920 __func__, usb_tx_cfg.bit_format,
921 ucontrol->value.integer.value[0]);
922 return 0;
923}
924
925static int usb_audio_tx_format_put(struct snd_kcontrol *kcontrol,
926 struct snd_ctl_elem_value *ucontrol)
927{
928 int rc = 0;
929
930 switch (ucontrol->value.integer.value[0]) {
931 case 3:
932 usb_tx_cfg.bit_format = SNDRV_PCM_FORMAT_S32_LE;
933 break;
934 case 2:
935 usb_tx_cfg.bit_format = SNDRV_PCM_FORMAT_S24_3LE;
936 break;
937 case 1:
938 usb_tx_cfg.bit_format = SNDRV_PCM_FORMAT_S24_LE;
939 break;
940 case 0:
941 default:
942 usb_tx_cfg.bit_format = SNDRV_PCM_FORMAT_S16_LE;
943 break;
944 }
945 pr_debug("%s: usb_audio_tx_format = %d, ucontrol value = %ld\n",
946 __func__, usb_tx_cfg.bit_format,
947 ucontrol->value.integer.value[0]);
948
949 return rc;
950}
951
952static int usb_audio_rx_ch_get(struct snd_kcontrol *kcontrol,
953 struct snd_ctl_elem_value *ucontrol)
954{
955 pr_debug("%s: usb_audio_rx_ch = %d\n", __func__,
956 usb_rx_cfg.channels);
957 ucontrol->value.integer.value[0] = usb_rx_cfg.channels - 1;
958 return 0;
959}
960
961static int usb_audio_rx_ch_put(struct snd_kcontrol *kcontrol,
962 struct snd_ctl_elem_value *ucontrol)
963{
964 usb_rx_cfg.channels = ucontrol->value.integer.value[0] + 1;
965
966 pr_debug("%s: usb_audio_rx_ch = %d\n", __func__, usb_rx_cfg.channels);
967 return 1;
968}
969
970static int usb_audio_tx_ch_get(struct snd_kcontrol *kcontrol,
971 struct snd_ctl_elem_value *ucontrol)
972{
973 pr_debug("%s: usb_audio_tx_ch = %d\n", __func__,
974 usb_tx_cfg.channels);
975 ucontrol->value.integer.value[0] = usb_tx_cfg.channels - 1;
976 return 0;
977}
978
979static int usb_audio_tx_ch_put(struct snd_kcontrol *kcontrol,
980 struct snd_ctl_elem_value *ucontrol)
981{
982 usb_tx_cfg.channels = ucontrol->value.integer.value[0] + 1;
983
984 pr_debug("%s: usb_audio_tx_ch = %d\n", __func__, usb_tx_cfg.channels);
985 return 1;
986}
987
Meng Wangd1db67c2019-04-17 12:41:34 +0800988static int msm_vi_feed_tx_ch_get(struct snd_kcontrol *kcontrol,
989 struct snd_ctl_elem_value *ucontrol)
990{
991 ucontrol->value.integer.value[0] = msm_vi_feed_tx_ch - 1;
992 pr_debug("%s: msm_vi_feed_tx_ch = %ld\n", __func__,
993 ucontrol->value.integer.value[0]);
994 return 0;
995}
996
997static int msm_vi_feed_tx_ch_put(struct snd_kcontrol *kcontrol,
998 struct snd_ctl_elem_value *ucontrol)
999{
1000 msm_vi_feed_tx_ch = ucontrol->value.integer.value[0] + 1;
1001 pr_debug("%s: msm_vi_feed_tx_ch = %d\n", __func__, msm_vi_feed_tx_ch);
1002 return 1;
1003}
1004
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -08001005static int ext_disp_get_port_idx(struct snd_kcontrol *kcontrol)
1006{
1007 int idx = 0;
1008
1009 if (strnstr(kcontrol->id.name, "Display Port RX",
1010 sizeof("Display Port RX"))) {
1011 idx = EXT_DISP_RX_IDX_DP;
1012 } else {
1013 pr_err("%s: unsupported BE: %s\n",
1014 __func__, kcontrol->id.name);
1015 idx = -EINVAL;
1016 }
1017
1018 return idx;
1019}
1020
1021static int ext_disp_rx_format_get(struct snd_kcontrol *kcontrol,
1022 struct snd_ctl_elem_value *ucontrol)
1023{
1024 int idx = ext_disp_get_port_idx(kcontrol);
1025
1026 if (idx < 0)
1027 return idx;
1028
1029 switch (ext_disp_rx_cfg[idx].bit_format) {
1030 case SNDRV_PCM_FORMAT_S24_3LE:
1031 ucontrol->value.integer.value[0] = 2;
1032 break;
1033 case SNDRV_PCM_FORMAT_S24_LE:
1034 ucontrol->value.integer.value[0] = 1;
1035 break;
1036 case SNDRV_PCM_FORMAT_S16_LE:
1037 default:
1038 ucontrol->value.integer.value[0] = 0;
1039 break;
1040 }
1041
1042 pr_debug("%s: ext_disp_rx[%d].format = %d, ucontrol value = %ld\n",
1043 __func__, idx, ext_disp_rx_cfg[idx].bit_format,
1044 ucontrol->value.integer.value[0]);
1045 return 0;
1046}
1047
1048static int ext_disp_rx_format_put(struct snd_kcontrol *kcontrol,
1049 struct snd_ctl_elem_value *ucontrol)
1050{
1051 int idx = ext_disp_get_port_idx(kcontrol);
1052
1053 if (idx < 0)
1054 return idx;
1055
1056 switch (ucontrol->value.integer.value[0]) {
1057 case 2:
1058 ext_disp_rx_cfg[idx].bit_format = SNDRV_PCM_FORMAT_S24_3LE;
1059 break;
1060 case 1:
1061 ext_disp_rx_cfg[idx].bit_format = SNDRV_PCM_FORMAT_S24_LE;
1062 break;
1063 case 0:
1064 default:
1065 ext_disp_rx_cfg[idx].bit_format = SNDRV_PCM_FORMAT_S16_LE;
1066 break;
1067 }
1068 pr_debug("%s: ext_disp_rx[%d].format = %d, ucontrol value = %ld\n",
1069 __func__, idx, ext_disp_rx_cfg[idx].bit_format,
1070 ucontrol->value.integer.value[0]);
1071
1072 return 0;
1073}
1074
1075static int ext_disp_rx_ch_get(struct snd_kcontrol *kcontrol,
1076 struct snd_ctl_elem_value *ucontrol)
1077{
1078 int idx = ext_disp_get_port_idx(kcontrol);
1079
1080 if (idx < 0)
1081 return idx;
1082
1083 ucontrol->value.integer.value[0] =
1084 ext_disp_rx_cfg[idx].channels - 2;
1085
1086 pr_debug("%s: ext_disp_rx[%d].ch = %d\n", __func__,
1087 idx, ext_disp_rx_cfg[idx].channels);
1088
1089 return 0;
1090}
1091
1092static int ext_disp_rx_ch_put(struct snd_kcontrol *kcontrol,
1093 struct snd_ctl_elem_value *ucontrol)
1094{
1095 int idx = ext_disp_get_port_idx(kcontrol);
1096
1097 if (idx < 0)
1098 return idx;
1099
1100 ext_disp_rx_cfg[idx].channels =
1101 ucontrol->value.integer.value[0] + 2;
1102
1103 pr_debug("%s: ext_disp_rx[%d].ch = %d\n", __func__,
1104 idx, ext_disp_rx_cfg[idx].channels);
1105 return 1;
1106}
1107
1108static int ext_disp_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
1109 struct snd_ctl_elem_value *ucontrol)
1110{
1111 int sample_rate_val;
1112 int idx = ext_disp_get_port_idx(kcontrol);
1113
1114 if (idx < 0)
1115 return idx;
1116
1117 switch (ext_disp_rx_cfg[idx].sample_rate) {
1118 case SAMPLING_RATE_176P4KHZ:
1119 sample_rate_val = 6;
1120 break;
1121
1122 case SAMPLING_RATE_88P2KHZ:
1123 sample_rate_val = 5;
1124 break;
1125
1126 case SAMPLING_RATE_44P1KHZ:
1127 sample_rate_val = 4;
1128 break;
1129
1130 case SAMPLING_RATE_32KHZ:
1131 sample_rate_val = 3;
1132 break;
1133
1134 case SAMPLING_RATE_192KHZ:
1135 sample_rate_val = 2;
1136 break;
1137
1138 case SAMPLING_RATE_96KHZ:
1139 sample_rate_val = 1;
1140 break;
1141
1142 case SAMPLING_RATE_48KHZ:
1143 default:
1144 sample_rate_val = 0;
1145 break;
1146 }
1147
1148 ucontrol->value.integer.value[0] = sample_rate_val;
1149 pr_debug("%s: ext_disp_rx[%d].sample_rate = %d\n", __func__,
1150 idx, ext_disp_rx_cfg[idx].sample_rate);
1151
1152 return 0;
1153}
1154
1155static int ext_disp_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
1156 struct snd_ctl_elem_value *ucontrol)
1157{
1158 int idx = ext_disp_get_port_idx(kcontrol);
1159
1160 if (idx < 0)
1161 return idx;
1162
1163 switch (ucontrol->value.integer.value[0]) {
1164 case 6:
1165 ext_disp_rx_cfg[idx].sample_rate = SAMPLING_RATE_176P4KHZ;
1166 break;
1167 case 5:
1168 ext_disp_rx_cfg[idx].sample_rate = SAMPLING_RATE_88P2KHZ;
1169 break;
1170 case 4:
1171 ext_disp_rx_cfg[idx].sample_rate = SAMPLING_RATE_44P1KHZ;
1172 break;
1173 case 3:
1174 ext_disp_rx_cfg[idx].sample_rate = SAMPLING_RATE_32KHZ;
1175 break;
1176 case 2:
1177 ext_disp_rx_cfg[idx].sample_rate = SAMPLING_RATE_192KHZ;
1178 break;
1179 case 1:
1180 ext_disp_rx_cfg[idx].sample_rate = SAMPLING_RATE_96KHZ;
1181 break;
1182 case 0:
1183 default:
1184 ext_disp_rx_cfg[idx].sample_rate = SAMPLING_RATE_48KHZ;
1185 break;
1186 }
1187
1188 pr_debug("%s: control value = %ld, ext_disp_rx[%d].sample_rate = %d\n",
1189 __func__, ucontrol->value.integer.value[0], idx,
1190 ext_disp_rx_cfg[idx].sample_rate);
1191 return 0;
1192}
1193
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001194static int proxy_rx_ch_get(struct snd_kcontrol *kcontrol,
1195 struct snd_ctl_elem_value *ucontrol)
1196{
1197 pr_debug("%s: proxy_rx channels = %d\n",
1198 __func__, proxy_rx_cfg.channels);
1199 ucontrol->value.integer.value[0] = proxy_rx_cfg.channels - 2;
1200
1201 return 0;
1202}
1203
1204static int proxy_rx_ch_put(struct snd_kcontrol *kcontrol,
1205 struct snd_ctl_elem_value *ucontrol)
1206{
1207 proxy_rx_cfg.channels = ucontrol->value.integer.value[0] + 2;
1208 pr_debug("%s: proxy_rx channels = %d\n",
1209 __func__, proxy_rx_cfg.channels);
1210
1211 return 1;
1212}
1213
1214static int tdm_get_port_idx(struct snd_kcontrol *kcontrol,
1215 struct tdm_port *port)
1216{
1217 if (port) {
1218 if (strnstr(kcontrol->id.name, "PRI",
1219 sizeof(kcontrol->id.name))) {
1220 port->mode = TDM_PRI;
1221 } else if (strnstr(kcontrol->id.name, "SEC",
1222 sizeof(kcontrol->id.name))) {
1223 port->mode = TDM_SEC;
1224 } else if (strnstr(kcontrol->id.name, "TERT",
1225 sizeof(kcontrol->id.name))) {
1226 port->mode = TDM_TERT;
1227 } else {
1228 pr_err("%s: unsupported mode in: %s\n",
1229 __func__, kcontrol->id.name);
1230 return -EINVAL;
1231 }
1232
1233 if (strnstr(kcontrol->id.name, "RX_0",
1234 sizeof(kcontrol->id.name)) ||
1235 strnstr(kcontrol->id.name, "TX_0",
1236 sizeof(kcontrol->id.name))) {
1237 port->channel = TDM_0;
1238 } else if (strnstr(kcontrol->id.name, "RX_1",
1239 sizeof(kcontrol->id.name)) ||
1240 strnstr(kcontrol->id.name, "TX_1",
1241 sizeof(kcontrol->id.name))) {
1242 port->channel = TDM_1;
1243 } else if (strnstr(kcontrol->id.name, "RX_2",
1244 sizeof(kcontrol->id.name)) ||
1245 strnstr(kcontrol->id.name, "TX_2",
1246 sizeof(kcontrol->id.name))) {
1247 port->channel = TDM_2;
1248 } else if (strnstr(kcontrol->id.name, "RX_3",
1249 sizeof(kcontrol->id.name)) ||
1250 strnstr(kcontrol->id.name, "TX_3",
1251 sizeof(kcontrol->id.name))) {
1252 port->channel = TDM_3;
1253 } else if (strnstr(kcontrol->id.name, "RX_4",
1254 sizeof(kcontrol->id.name)) ||
1255 strnstr(kcontrol->id.name, "TX_4",
1256 sizeof(kcontrol->id.name))) {
1257 port->channel = TDM_4;
1258 } else if (strnstr(kcontrol->id.name, "RX_5",
1259 sizeof(kcontrol->id.name)) ||
1260 strnstr(kcontrol->id.name, "TX_5",
1261 sizeof(kcontrol->id.name))) {
1262 port->channel = TDM_5;
1263 } else if (strnstr(kcontrol->id.name, "RX_6",
1264 sizeof(kcontrol->id.name)) ||
1265 strnstr(kcontrol->id.name, "TX_6",
1266 sizeof(kcontrol->id.name))) {
1267 port->channel = TDM_6;
1268 } else if (strnstr(kcontrol->id.name, "RX_7",
1269 sizeof(kcontrol->id.name)) ||
1270 strnstr(kcontrol->id.name, "TX_7",
1271 sizeof(kcontrol->id.name))) {
1272 port->channel = TDM_7;
1273 } else {
1274 pr_err("%s: unsupported channel in: %s\n",
1275 __func__, kcontrol->id.name);
1276 return -EINVAL;
1277 }
1278 } else {
1279 return -EINVAL;
1280 }
1281 return 0;
1282}
1283
1284static int tdm_get_sample_rate(int value)
1285{
1286 int sample_rate = 0;
1287
1288 switch (value) {
1289 case 0:
1290 sample_rate = SAMPLING_RATE_8KHZ;
1291 break;
1292 case 1:
1293 sample_rate = SAMPLING_RATE_16KHZ;
1294 break;
1295 case 2:
1296 sample_rate = SAMPLING_RATE_32KHZ;
1297 break;
1298 case 3:
1299 sample_rate = SAMPLING_RATE_48KHZ;
1300 break;
1301 case 4:
1302 sample_rate = SAMPLING_RATE_176P4KHZ;
1303 break;
1304 case 5:
1305 sample_rate = SAMPLING_RATE_352P8KHZ;
1306 break;
1307 default:
1308 sample_rate = SAMPLING_RATE_48KHZ;
1309 break;
1310 }
1311 return sample_rate;
1312}
1313
1314static int tdm_get_sample_rate_val(int sample_rate)
1315{
1316 int sample_rate_val = 0;
1317
1318 switch (sample_rate) {
1319 case SAMPLING_RATE_8KHZ:
1320 sample_rate_val = 0;
1321 break;
1322 case SAMPLING_RATE_16KHZ:
1323 sample_rate_val = 1;
1324 break;
1325 case SAMPLING_RATE_32KHZ:
1326 sample_rate_val = 2;
1327 break;
1328 case SAMPLING_RATE_48KHZ:
1329 sample_rate_val = 3;
1330 break;
1331 case SAMPLING_RATE_176P4KHZ:
1332 sample_rate_val = 4;
1333 break;
1334 case SAMPLING_RATE_352P8KHZ:
1335 sample_rate_val = 5;
1336 break;
1337 default:
1338 sample_rate_val = 3;
1339 break;
1340 }
1341 return sample_rate_val;
1342}
1343
1344static int tdm_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
1345 struct snd_ctl_elem_value *ucontrol)
1346{
1347 struct tdm_port port;
1348 int ret = tdm_get_port_idx(kcontrol, &port);
1349
1350 if (ret) {
1351 pr_err("%s: unsupported control: %s\n",
1352 __func__, kcontrol->id.name);
1353 } else {
1354 ucontrol->value.enumerated.item[0] = tdm_get_sample_rate_val(
1355 tdm_rx_cfg[port.mode][port.channel].sample_rate);
1356
1357 pr_debug("%s: tdm_rx_sample_rate = %d, item = %d\n", __func__,
1358 tdm_rx_cfg[port.mode][port.channel].sample_rate,
1359 ucontrol->value.enumerated.item[0]);
1360 }
1361 return ret;
1362}
1363
1364static int tdm_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
1365 struct snd_ctl_elem_value *ucontrol)
1366{
1367 struct tdm_port port;
1368 int ret = tdm_get_port_idx(kcontrol, &port);
1369
1370 if (ret) {
1371 pr_err("%s: unsupported control: %s\n",
1372 __func__, kcontrol->id.name);
1373 } else {
1374 tdm_rx_cfg[port.mode][port.channel].sample_rate =
1375 tdm_get_sample_rate(ucontrol->value.enumerated.item[0]);
1376
1377 pr_debug("%s: tdm_rx_sample_rate = %d, item = %d\n", __func__,
1378 tdm_rx_cfg[port.mode][port.channel].sample_rate,
1379 ucontrol->value.enumerated.item[0]);
1380 }
1381 return ret;
1382}
1383
1384static int tdm_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
1385 struct snd_ctl_elem_value *ucontrol)
1386{
1387 struct tdm_port port;
1388 int ret = tdm_get_port_idx(kcontrol, &port);
1389
1390 if (ret) {
1391 pr_err("%s: unsupported control: %s\n",
1392 __func__, kcontrol->id.name);
1393 } else {
1394 ucontrol->value.enumerated.item[0] = tdm_get_sample_rate_val(
1395 tdm_tx_cfg[port.mode][port.channel].sample_rate);
1396
1397 pr_debug("%s: tdm_tx_sample_rate = %d, item = %d\n", __func__,
1398 tdm_tx_cfg[port.mode][port.channel].sample_rate,
1399 ucontrol->value.enumerated.item[0]);
1400 }
1401 return ret;
1402}
1403
1404static int tdm_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
1405 struct snd_ctl_elem_value *ucontrol)
1406{
1407 struct tdm_port port;
1408 int ret = tdm_get_port_idx(kcontrol, &port);
1409
1410 if (ret) {
1411 pr_err("%s: unsupported control: %s\n",
1412 __func__, kcontrol->id.name);
1413 } else {
1414 tdm_tx_cfg[port.mode][port.channel].sample_rate =
1415 tdm_get_sample_rate(ucontrol->value.enumerated.item[0]);
1416
1417 pr_debug("%s: tdm_tx_sample_rate = %d, item = %d\n", __func__,
1418 tdm_tx_cfg[port.mode][port.channel].sample_rate,
1419 ucontrol->value.enumerated.item[0]);
1420 }
1421 return ret;
1422}
1423
1424static int tdm_get_format(int value)
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001425{
1426 int format = 0;
1427
1428 switch (value) {
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001429 case 0:
1430 format = SNDRV_PCM_FORMAT_S16_LE;
1431 break;
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001432 case 1:
1433 format = SNDRV_PCM_FORMAT_S24_LE;
1434 break;
1435 case 2:
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001436 format = SNDRV_PCM_FORMAT_S32_LE;
1437 break;
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001438 default:
1439 format = SNDRV_PCM_FORMAT_S16_LE;
1440 break;
1441 }
1442 return format;
1443}
1444
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001445static int tdm_get_format_val(int format)
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001446{
1447 int value = 0;
1448
1449 switch (format) {
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001450 case SNDRV_PCM_FORMAT_S16_LE:
1451 value = 0;
1452 break;
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001453 case SNDRV_PCM_FORMAT_S24_LE:
1454 value = 1;
1455 break;
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001456 case SNDRV_PCM_FORMAT_S32_LE:
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001457 value = 2;
1458 break;
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001459 default:
1460 value = 0;
1461 break;
1462 }
1463 return value;
1464}
1465
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001466static int tdm_rx_format_get(struct snd_kcontrol *kcontrol,
1467 struct snd_ctl_elem_value *ucontrol)
1468{
1469 struct tdm_port port;
1470 int ret = tdm_get_port_idx(kcontrol, &port);
1471
1472 if (ret) {
1473 pr_err("%s: unsupported control: %s\n",
1474 __func__, kcontrol->id.name);
1475 } else {
1476 ucontrol->value.enumerated.item[0] = tdm_get_format_val(
1477 tdm_rx_cfg[port.mode][port.channel].bit_format);
1478
1479 pr_debug("%s: tdm_rx_bit_format = %d, item = %d\n", __func__,
1480 tdm_rx_cfg[port.mode][port.channel].bit_format,
1481 ucontrol->value.enumerated.item[0]);
1482 }
1483 return ret;
1484}
1485
1486static int tdm_rx_format_put(struct snd_kcontrol *kcontrol,
1487 struct snd_ctl_elem_value *ucontrol)
1488{
1489 struct tdm_port port;
1490 int ret = tdm_get_port_idx(kcontrol, &port);
1491
1492 if (ret) {
1493 pr_err("%s: unsupported control: %s\n",
1494 __func__, kcontrol->id.name);
1495 } else {
1496 tdm_rx_cfg[port.mode][port.channel].bit_format =
1497 tdm_get_format(ucontrol->value.enumerated.item[0]);
1498
1499 pr_debug("%s: tdm_rx_bit_format = %d, item = %d\n", __func__,
1500 tdm_rx_cfg[port.mode][port.channel].bit_format,
1501 ucontrol->value.enumerated.item[0]);
1502 }
1503 return ret;
1504}
1505
1506static int tdm_tx_format_get(struct snd_kcontrol *kcontrol,
1507 struct snd_ctl_elem_value *ucontrol)
1508{
1509 struct tdm_port port;
1510 int ret = tdm_get_port_idx(kcontrol, &port);
1511
1512 if (ret) {
1513 pr_err("%s: unsupported control: %s\n",
1514 __func__, kcontrol->id.name);
1515 } else {
1516 ucontrol->value.enumerated.item[0] = tdm_get_format_val(
1517 tdm_tx_cfg[port.mode][port.channel].bit_format);
1518
1519 pr_debug("%s: tdm_tx_bit_format = %d, item = %d\n", __func__,
1520 tdm_tx_cfg[port.mode][port.channel].bit_format,
1521 ucontrol->value.enumerated.item[0]);
1522 }
1523 return ret;
1524}
1525
1526static int tdm_tx_format_put(struct snd_kcontrol *kcontrol,
1527 struct snd_ctl_elem_value *ucontrol)
1528{
1529 struct tdm_port port;
1530 int ret = tdm_get_port_idx(kcontrol, &port);
1531
1532 if (ret) {
1533 pr_err("%s: unsupported control: %s\n",
1534 __func__, kcontrol->id.name);
1535 } else {
1536 tdm_tx_cfg[port.mode][port.channel].bit_format =
1537 tdm_get_format(ucontrol->value.enumerated.item[0]);
1538
1539 pr_debug("%s: tdm_tx_bit_format = %d, item = %d\n", __func__,
1540 tdm_tx_cfg[port.mode][port.channel].bit_format,
1541 ucontrol->value.enumerated.item[0]);
1542 }
1543 return ret;
1544}
1545
1546static int tdm_rx_ch_get(struct snd_kcontrol *kcontrol,
1547 struct snd_ctl_elem_value *ucontrol)
1548{
1549 struct tdm_port port;
1550 int ret = tdm_get_port_idx(kcontrol, &port);
1551
1552 if (ret) {
1553 pr_err("%s: unsupported control: %s\n",
1554 __func__, kcontrol->id.name);
1555 } else {
1556
1557 ucontrol->value.enumerated.item[0] =
1558 tdm_rx_cfg[port.mode][port.channel].channels - 1;
1559
1560 pr_debug("%s: tdm_rx_ch = %d, item = %d\n", __func__,
1561 tdm_rx_cfg[port.mode][port.channel].channels - 1,
1562 ucontrol->value.enumerated.item[0]);
1563 }
1564 return ret;
1565}
1566
1567static int tdm_rx_ch_put(struct snd_kcontrol *kcontrol,
1568 struct snd_ctl_elem_value *ucontrol)
1569{
1570 struct tdm_port port;
1571 int ret = tdm_get_port_idx(kcontrol, &port);
1572
1573 if (ret) {
1574 pr_err("%s: unsupported control: %s\n",
1575 __func__, kcontrol->id.name);
1576 } else {
1577 tdm_rx_cfg[port.mode][port.channel].channels =
1578 ucontrol->value.enumerated.item[0] + 1;
1579
1580 pr_debug("%s: tdm_rx_ch = %d, item = %d\n", __func__,
1581 tdm_rx_cfg[port.mode][port.channel].channels,
1582 ucontrol->value.enumerated.item[0] + 1);
1583 }
1584 return ret;
1585}
1586
1587static int tdm_tx_ch_get(struct snd_kcontrol *kcontrol,
1588 struct snd_ctl_elem_value *ucontrol)
1589{
1590 struct tdm_port port;
1591 int ret = tdm_get_port_idx(kcontrol, &port);
1592
1593 if (ret) {
1594 pr_err("%s: unsupported control: %s\n",
1595 __func__, kcontrol->id.name);
1596 } else {
1597 ucontrol->value.enumerated.item[0] =
1598 tdm_tx_cfg[port.mode][port.channel].channels - 1;
1599
1600 pr_debug("%s: tdm_tx_ch = %d, item = %d\n", __func__,
1601 tdm_tx_cfg[port.mode][port.channel].channels - 1,
1602 ucontrol->value.enumerated.item[0]);
1603 }
1604 return ret;
1605}
1606
1607static int tdm_tx_ch_put(struct snd_kcontrol *kcontrol,
1608 struct snd_ctl_elem_value *ucontrol)
1609{
1610 struct tdm_port port;
1611 int ret = tdm_get_port_idx(kcontrol, &port);
1612
1613 if (ret) {
1614 pr_err("%s: unsupported control: %s\n",
1615 __func__, kcontrol->id.name);
1616 } else {
1617 tdm_tx_cfg[port.mode][port.channel].channels =
1618 ucontrol->value.enumerated.item[0] + 1;
1619
1620 pr_debug("%s: tdm_tx_ch = %d, item = %d\n", __func__,
1621 tdm_tx_cfg[port.mode][port.channel].channels,
1622 ucontrol->value.enumerated.item[0] + 1);
1623 }
1624 return ret;
1625}
1626
1627static int aux_pcm_get_port_idx(struct snd_kcontrol *kcontrol)
1628{
1629 int idx = 0;
1630
1631 if (strnstr(kcontrol->id.name, "PRIM_AUX_PCM",
1632 sizeof("PRIM_AUX_PCM"))) {
1633 idx = PRIM_AUX_PCM;
1634 } else if (strnstr(kcontrol->id.name, "SEC_AUX_PCM",
1635 sizeof("SEC_AUX_PCM"))) {
1636 idx = SEC_AUX_PCM;
1637 } else if (strnstr(kcontrol->id.name, "TERT_AUX_PCM",
1638 sizeof("TERT_AUX_PCM"))) {
1639 idx = TERT_AUX_PCM;
1640 } else {
1641 pr_err("%s: unsupported port: %s\n",
1642 __func__, kcontrol->id.name);
1643 idx = -EINVAL;
1644 }
1645
1646 return idx;
1647}
1648
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001649static int aux_pcm_get_sample_rate(int value)
1650{
1651 int sample_rate = 0;
1652
1653 switch (value) {
1654 case 1:
1655 sample_rate = SAMPLING_RATE_16KHZ;
1656 break;
1657 case 0:
1658 default:
1659 sample_rate = SAMPLING_RATE_8KHZ;
1660 break;
1661 }
1662 return sample_rate;
1663}
1664
1665static int aux_pcm_get_sample_rate_val(int sample_rate)
1666{
1667 int sample_rate_val = 0;
1668
1669 switch (sample_rate) {
1670 case SAMPLING_RATE_16KHZ:
1671 sample_rate_val = 1;
1672 break;
1673 case SAMPLING_RATE_8KHZ:
1674 default:
1675 sample_rate_val = 0;
1676 break;
1677 }
1678 return sample_rate_val;
1679}
1680
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001681static int mi2s_auxpcm_get_format(int value)
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001682{
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001683 int format = 0;
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001684
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001685 switch (value) {
1686 case 0:
1687 format = SNDRV_PCM_FORMAT_S16_LE;
1688 break;
1689 case 1:
1690 format = SNDRV_PCM_FORMAT_S24_LE;
1691 break;
1692 case 2:
1693 format = SNDRV_PCM_FORMAT_S24_3LE;
1694 break;
1695 case 3:
1696 format = SNDRV_PCM_FORMAT_S32_LE;
1697 break;
1698 default:
1699 format = SNDRV_PCM_FORMAT_S16_LE;
1700 break;
1701 }
1702 return format;
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001703}
1704
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001705static int mi2s_auxpcm_get_format_value(int format)
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001706{
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001707 int value = 0;
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001708
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001709 switch (format) {
1710 case SNDRV_PCM_FORMAT_S16_LE:
1711 value = 0;
1712 break;
1713 case SNDRV_PCM_FORMAT_S24_LE:
1714 value = 1;
1715 break;
1716 case SNDRV_PCM_FORMAT_S24_3LE:
1717 value = 2;
1718 break;
1719 case SNDRV_PCM_FORMAT_S32_LE:
1720 value = 3;
1721 break;
1722 default:
1723 value = 0;
1724 break;
1725 }
1726 return value;
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001727}
1728
1729static int aux_pcm_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
1730 struct snd_ctl_elem_value *ucontrol)
1731{
1732 int idx = aux_pcm_get_port_idx(kcontrol);
1733
1734 if (idx < 0)
1735 return idx;
1736
1737 ucontrol->value.enumerated.item[0] =
1738 aux_pcm_get_sample_rate_val(aux_pcm_rx_cfg[idx].sample_rate);
1739
1740 pr_debug("%s: idx[%d]_rx_sample_rate = %d, item = %d\n", __func__,
1741 idx, aux_pcm_rx_cfg[idx].sample_rate,
1742 ucontrol->value.enumerated.item[0]);
1743
1744 return 0;
1745}
1746
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001747static int aux_pcm_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001748 struct snd_ctl_elem_value *ucontrol)
1749{
1750 int idx = aux_pcm_get_port_idx(kcontrol);
1751
1752 if (idx < 0)
1753 return idx;
1754
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001755 aux_pcm_rx_cfg[idx].sample_rate =
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001756 aux_pcm_get_sample_rate(ucontrol->value.enumerated.item[0]);
1757
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001758 pr_debug("%s: idx[%d]_rx_sample_rate = %d, item = %d\n", __func__,
1759 idx, aux_pcm_rx_cfg[idx].sample_rate,
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07001760 ucontrol->value.enumerated.item[0]);
1761
1762 return 0;
1763}
1764
1765static int aux_pcm_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
1766 struct snd_ctl_elem_value *ucontrol)
1767{
1768 int idx = aux_pcm_get_port_idx(kcontrol);
1769
1770 if (idx < 0)
1771 return idx;
1772
1773 ucontrol->value.enumerated.item[0] =
1774 aux_pcm_get_sample_rate_val(aux_pcm_tx_cfg[idx].sample_rate);
1775
1776 pr_debug("%s: idx[%d]_tx_sample_rate = %d, item = %d\n", __func__,
1777 idx, aux_pcm_tx_cfg[idx].sample_rate,
1778 ucontrol->value.enumerated.item[0]);
1779
1780 return 0;
1781}
1782
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07001783static int aux_pcm_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
1784 struct snd_ctl_elem_value *ucontrol)
1785{
1786 int idx = aux_pcm_get_port_idx(kcontrol);
1787
1788 if (idx < 0)
1789 return idx;
1790
1791 aux_pcm_tx_cfg[idx].sample_rate =
1792 aux_pcm_get_sample_rate(ucontrol->value.enumerated.item[0]);
1793
1794 pr_debug("%s: idx[%d]_tx_sample_rate = %d, item = %d\n", __func__,
1795 idx, aux_pcm_tx_cfg[idx].sample_rate,
1796 ucontrol->value.enumerated.item[0]);
1797
1798 return 0;
1799}
1800
1801static int msm_aux_pcm_rx_format_get(struct snd_kcontrol *kcontrol,
1802 struct snd_ctl_elem_value *ucontrol)
1803{
1804 int idx = aux_pcm_get_port_idx(kcontrol);
1805
1806 if (idx < 0)
1807 return idx;
1808
1809 ucontrol->value.enumerated.item[0] =
1810 mi2s_auxpcm_get_format_value(aux_pcm_rx_cfg[idx].bit_format);
1811
1812 pr_debug("%s: idx[%d]_rx_format = %d, item = %d\n", __func__,
1813 idx, aux_pcm_rx_cfg[idx].bit_format,
1814 ucontrol->value.enumerated.item[0]);
1815
1816 return 0;
1817}
1818
1819static int msm_aux_pcm_rx_format_put(struct snd_kcontrol *kcontrol,
1820 struct snd_ctl_elem_value *ucontrol)
1821{
1822 int idx = aux_pcm_get_port_idx(kcontrol);
1823
1824 if (idx < 0)
1825 return idx;
1826
1827 aux_pcm_rx_cfg[idx].bit_format =
1828 mi2s_auxpcm_get_format(ucontrol->value.enumerated.item[0]);
1829
1830 pr_debug("%s: idx[%d]_rx_format = %d, item = %d\n", __func__,
1831 idx, aux_pcm_rx_cfg[idx].bit_format,
1832 ucontrol->value.enumerated.item[0]);
1833
1834 return 0;
1835}
1836
1837static int msm_aux_pcm_tx_format_get(struct snd_kcontrol *kcontrol,
1838 struct snd_ctl_elem_value *ucontrol)
1839{
1840 int idx = aux_pcm_get_port_idx(kcontrol);
1841
1842 if (idx < 0)
1843 return idx;
1844
1845 ucontrol->value.enumerated.item[0] =
1846 mi2s_auxpcm_get_format_value(aux_pcm_tx_cfg[idx].bit_format);
1847
1848 pr_debug("%s: idx[%d]_tx_format = %d, item = %d\n", __func__,
1849 idx, aux_pcm_tx_cfg[idx].bit_format,
1850 ucontrol->value.enumerated.item[0]);
1851
1852 return 0;
1853}
1854
1855static int msm_aux_pcm_tx_format_put(struct snd_kcontrol *kcontrol,
1856 struct snd_ctl_elem_value *ucontrol)
1857{
1858 int idx = aux_pcm_get_port_idx(kcontrol);
1859
1860 if (idx < 0)
1861 return idx;
1862
1863 aux_pcm_tx_cfg[idx].bit_format =
1864 mi2s_auxpcm_get_format(ucontrol->value.enumerated.item[0]);
1865
1866 pr_debug("%s: idx[%d]_tx_format = %d, item = %d\n", __func__,
1867 idx, aux_pcm_tx_cfg[idx].bit_format,
1868 ucontrol->value.enumerated.item[0]);
1869
1870 return 0;
1871}
1872
1873static int mi2s_get_port_idx(struct snd_kcontrol *kcontrol)
1874{
1875 int idx = 0;
1876
1877 if (strnstr(kcontrol->id.name, "PRIM_MI2S_RX",
1878 sizeof("PRIM_MI2S_RX"))) {
1879 idx = PRIM_MI2S;
1880 } else if (strnstr(kcontrol->id.name, "SEC_MI2S_RX",
1881 sizeof("SEC_MI2S_RX"))) {
1882 idx = SEC_MI2S;
1883 } else if (strnstr(kcontrol->id.name, "TERT_MI2S_RX",
1884 sizeof("TERT_MI2S_RX"))) {
1885 idx = TERT_MI2S;
1886 } else if (strnstr(kcontrol->id.name, "PRIM_MI2S_TX",
1887 sizeof("PRIM_MI2S_TX"))) {
1888 idx = PRIM_MI2S;
1889 } else if (strnstr(kcontrol->id.name, "SEC_MI2S_TX",
1890 sizeof("SEC_MI2S_TX"))) {
1891 idx = SEC_MI2S;
1892 } else if (strnstr(kcontrol->id.name, "TERT_MI2S_TX",
1893 sizeof("TERT_MI2S_TX"))) {
1894 idx = TERT_MI2S;
1895 } else {
1896 pr_err("%s: unsupported channel: %s\n",
1897 __func__, kcontrol->id.name);
1898 idx = -EINVAL;
1899 }
1900
1901 return idx;
1902}
1903
1904static int mi2s_get_sample_rate(int value)
1905{
1906 int sample_rate = 0;
1907
1908 switch (value) {
1909 case 0:
1910 sample_rate = SAMPLING_RATE_8KHZ;
1911 break;
1912 case 1:
1913 sample_rate = SAMPLING_RATE_11P025KHZ;
1914 break;
1915 case 2:
1916 sample_rate = SAMPLING_RATE_16KHZ;
1917 break;
1918 case 3:
1919 sample_rate = SAMPLING_RATE_22P05KHZ;
1920 break;
1921 case 4:
1922 sample_rate = SAMPLING_RATE_32KHZ;
1923 break;
1924 case 5:
1925 sample_rate = SAMPLING_RATE_44P1KHZ;
1926 break;
1927 case 6:
1928 sample_rate = SAMPLING_RATE_48KHZ;
1929 break;
1930 case 7:
1931 sample_rate = SAMPLING_RATE_96KHZ;
1932 break;
1933 case 8:
1934 sample_rate = SAMPLING_RATE_192KHZ;
1935 break;
1936 default:
1937 sample_rate = SAMPLING_RATE_48KHZ;
1938 break;
1939 }
1940 return sample_rate;
1941}
1942
1943static int mi2s_get_sample_rate_val(int sample_rate)
1944{
1945 int sample_rate_val = 0;
1946
1947 switch (sample_rate) {
1948 case SAMPLING_RATE_8KHZ:
1949 sample_rate_val = 0;
1950 break;
1951 case SAMPLING_RATE_11P025KHZ:
1952 sample_rate_val = 1;
1953 break;
1954 case SAMPLING_RATE_16KHZ:
1955 sample_rate_val = 2;
1956 break;
1957 case SAMPLING_RATE_22P05KHZ:
1958 sample_rate_val = 3;
1959 break;
1960 case SAMPLING_RATE_32KHZ:
1961 sample_rate_val = 4;
1962 break;
1963 case SAMPLING_RATE_44P1KHZ:
1964 sample_rate_val = 5;
1965 break;
1966 case SAMPLING_RATE_48KHZ:
1967 sample_rate_val = 6;
1968 break;
1969 case SAMPLING_RATE_96KHZ:
1970 sample_rate_val = 7;
1971 break;
1972 case SAMPLING_RATE_192KHZ:
1973 sample_rate_val = 8;
1974 break;
1975 default:
1976 sample_rate_val = 6;
1977 break;
1978 }
1979 return sample_rate_val;
1980}
1981
1982static int mi2s_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
1983 struct snd_ctl_elem_value *ucontrol)
1984{
1985 int idx = mi2s_get_port_idx(kcontrol);
1986
1987 if (idx < 0)
1988 return idx;
1989
1990 ucontrol->value.enumerated.item[0] =
1991 mi2s_get_sample_rate_val(mi2s_rx_cfg[idx].sample_rate);
1992
1993 pr_debug("%s: idx[%d]_rx_sample_rate = %d, item = %d\n", __func__,
1994 idx, mi2s_rx_cfg[idx].sample_rate,
1995 ucontrol->value.enumerated.item[0]);
1996
1997 return 0;
1998}
1999
2000static int mi2s_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
2001 struct snd_ctl_elem_value *ucontrol)
2002{
2003 int idx = mi2s_get_port_idx(kcontrol);
2004
2005 if (idx < 0)
2006 return idx;
2007
2008 mi2s_rx_cfg[idx].sample_rate =
2009 mi2s_get_sample_rate(ucontrol->value.enumerated.item[0]);
2010
2011 pr_debug("%s: idx[%d]_rx_sample_rate = %d, item = %d\n", __func__,
2012 idx, mi2s_rx_cfg[idx].sample_rate,
2013 ucontrol->value.enumerated.item[0]);
2014
2015 return 0;
2016}
2017
2018static int mi2s_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
2019 struct snd_ctl_elem_value *ucontrol)
2020{
2021 int idx = mi2s_get_port_idx(kcontrol);
2022
2023 if (idx < 0)
2024 return idx;
2025
2026 ucontrol->value.enumerated.item[0] =
2027 mi2s_get_sample_rate_val(mi2s_tx_cfg[idx].sample_rate);
2028
2029 pr_debug("%s: idx[%d]_tx_sample_rate = %d, item = %d\n", __func__,
2030 idx, mi2s_tx_cfg[idx].sample_rate,
2031 ucontrol->value.enumerated.item[0]);
2032
2033 return 0;
2034}
2035
2036static int mi2s_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
2037 struct snd_ctl_elem_value *ucontrol)
2038{
2039 int idx = mi2s_get_port_idx(kcontrol);
2040
2041 if (idx < 0)
2042 return idx;
2043
2044 mi2s_tx_cfg[idx].sample_rate =
2045 mi2s_get_sample_rate(ucontrol->value.enumerated.item[0]);
2046
2047 pr_debug("%s: idx[%d]_tx_sample_rate = %d, item = %d\n", __func__,
2048 idx, mi2s_tx_cfg[idx].sample_rate,
2049 ucontrol->value.enumerated.item[0]);
2050
2051 return 0;
2052}
2053
2054static int msm_mi2s_rx_format_get(struct snd_kcontrol *kcontrol,
2055 struct snd_ctl_elem_value *ucontrol)
2056{
2057 int idx = mi2s_get_port_idx(kcontrol);
2058
2059 if (idx < 0)
2060 return idx;
2061
2062 ucontrol->value.enumerated.item[0] =
2063 mi2s_auxpcm_get_format_value(mi2s_rx_cfg[idx].bit_format);
2064
2065 pr_debug("%s: idx[%d]_rx_format = %d, item = %d\n", __func__,
2066 idx, mi2s_rx_cfg[idx].bit_format,
2067 ucontrol->value.enumerated.item[0]);
2068
2069 return 0;
2070}
2071
2072static int msm_mi2s_rx_format_put(struct snd_kcontrol *kcontrol,
2073 struct snd_ctl_elem_value *ucontrol)
2074{
2075 int idx = mi2s_get_port_idx(kcontrol);
2076
2077 if (idx < 0)
2078 return idx;
2079
2080 mi2s_rx_cfg[idx].bit_format =
2081 mi2s_auxpcm_get_format(ucontrol->value.enumerated.item[0]);
2082
2083 pr_debug("%s: idx[%d]_rx_format = %d, item = %d\n", __func__,
2084 idx, mi2s_rx_cfg[idx].bit_format,
2085 ucontrol->value.enumerated.item[0]);
2086
2087 return 0;
2088}
2089
2090static int msm_mi2s_tx_format_get(struct snd_kcontrol *kcontrol,
2091 struct snd_ctl_elem_value *ucontrol)
2092{
2093 int idx = mi2s_get_port_idx(kcontrol);
2094
2095 if (idx < 0)
2096 return idx;
2097
2098 ucontrol->value.enumerated.item[0] =
2099 mi2s_auxpcm_get_format_value(mi2s_tx_cfg[idx].bit_format);
2100
2101 pr_debug("%s: idx[%d]_tx_format = %d, item = %d\n", __func__,
2102 idx, mi2s_tx_cfg[idx].bit_format,
2103 ucontrol->value.enumerated.item[0]);
2104
2105 return 0;
2106}
2107
2108static int msm_mi2s_tx_format_put(struct snd_kcontrol *kcontrol,
2109 struct snd_ctl_elem_value *ucontrol)
2110{
2111 int idx = mi2s_get_port_idx(kcontrol);
2112
2113 if (idx < 0)
2114 return idx;
2115
2116 mi2s_tx_cfg[idx].bit_format =
2117 mi2s_auxpcm_get_format(ucontrol->value.enumerated.item[0]);
2118
2119 pr_debug("%s: idx[%d]_tx_format = %d, item = %d\n", __func__,
2120 idx, mi2s_tx_cfg[idx].bit_format,
2121 ucontrol->value.enumerated.item[0]);
2122
2123 return 0;
2124}
2125static int msm_mi2s_rx_ch_get(struct snd_kcontrol *kcontrol,
2126 struct snd_ctl_elem_value *ucontrol)
2127{
2128 int idx = mi2s_get_port_idx(kcontrol);
2129
2130 if (idx < 0)
2131 return idx;
2132
2133 pr_debug("%s: msm_mi2s_[%d]_rx_ch = %d\n", __func__,
2134 idx, mi2s_rx_cfg[idx].channels);
2135 ucontrol->value.enumerated.item[0] = mi2s_rx_cfg[idx].channels - 1;
2136
2137 return 0;
2138}
2139
2140static int msm_mi2s_rx_ch_put(struct snd_kcontrol *kcontrol,
2141 struct snd_ctl_elem_value *ucontrol)
2142{
2143 int idx = mi2s_get_port_idx(kcontrol);
2144
2145 if (idx < 0)
2146 return idx;
2147
2148 mi2s_rx_cfg[idx].channels = ucontrol->value.enumerated.item[0] + 1;
2149 pr_debug("%s: msm_mi2s_[%d]_rx_ch = %d\n", __func__,
2150 idx, mi2s_rx_cfg[idx].channels);
2151
2152 return 1;
2153}
2154
2155static int msm_mi2s_tx_ch_get(struct snd_kcontrol *kcontrol,
2156 struct snd_ctl_elem_value *ucontrol)
2157{
2158 int idx = mi2s_get_port_idx(kcontrol);
2159
2160 if (idx < 0)
2161 return idx;
2162
2163 pr_debug("%s: msm_mi2s_[%d]_tx_ch = %d\n", __func__,
2164 idx, mi2s_tx_cfg[idx].channels);
2165 ucontrol->value.enumerated.item[0] = mi2s_tx_cfg[idx].channels - 1;
2166
2167 return 0;
2168}
2169
2170static int msm_mi2s_tx_ch_put(struct snd_kcontrol *kcontrol,
2171 struct snd_ctl_elem_value *ucontrol)
2172{
2173 int idx = mi2s_get_port_idx(kcontrol);
2174
2175 if (idx < 0)
2176 return idx;
2177
2178 mi2s_tx_cfg[idx].channels = ucontrol->value.enumerated.item[0] + 1;
2179 pr_debug("%s: msm_mi2s_[%d]_tx_ch = %d\n", __func__,
2180 idx, mi2s_tx_cfg[idx].channels);
2181
2182 return 1;
2183}
2184
2185static int msm_get_port_id(int be_id)
2186{
2187 int afe_port_id = 0;
2188
2189 switch (be_id) {
2190 case MSM_BACKEND_DAI_PRI_MI2S_RX:
2191 afe_port_id = AFE_PORT_ID_PRIMARY_MI2S_RX;
2192 break;
2193 case MSM_BACKEND_DAI_PRI_MI2S_TX:
2194 afe_port_id = AFE_PORT_ID_PRIMARY_MI2S_TX;
2195 break;
2196 case MSM_BACKEND_DAI_SECONDARY_MI2S_RX:
2197 afe_port_id = AFE_PORT_ID_SECONDARY_MI2S_RX;
2198 break;
2199 case MSM_BACKEND_DAI_SECONDARY_MI2S_TX:
2200 afe_port_id = AFE_PORT_ID_SECONDARY_MI2S_TX;
2201 break;
2202 case MSM_BACKEND_DAI_TERTIARY_MI2S_RX:
2203 afe_port_id = AFE_PORT_ID_TERTIARY_MI2S_RX;
2204 break;
2205 case MSM_BACKEND_DAI_TERTIARY_MI2S_TX:
2206 afe_port_id = AFE_PORT_ID_TERTIARY_MI2S_TX;
2207 break;
Xiaoyu Yeffbdc9f2019-05-17 15:02:39 -07002208 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_0:
2209 afe_port_id = AFE_PORT_ID_VA_CODEC_DMA_TX_0;
2210 break;
2211 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_1:
2212 afe_port_id = AFE_PORT_ID_VA_CODEC_DMA_TX_1;
2213 break;
2214 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_2:
2215 afe_port_id = AFE_PORT_ID_VA_CODEC_DMA_TX_2;
2216 break;
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07002217 default:
2218 pr_err("%s: Invalid BE id: %d\n", __func__, be_id);
2219 afe_port_id = -EINVAL;
2220 }
2221
2222 return afe_port_id;
2223}
2224
2225static u32 get_mi2s_bits_per_sample(u32 bit_format)
2226{
2227 u32 bit_per_sample = 0;
2228
2229 switch (bit_format) {
2230 case SNDRV_PCM_FORMAT_S32_LE:
2231 case SNDRV_PCM_FORMAT_S24_3LE:
2232 case SNDRV_PCM_FORMAT_S24_LE:
2233 bit_per_sample = 32;
2234 break;
2235 case SNDRV_PCM_FORMAT_S16_LE:
2236 default:
2237 bit_per_sample = 16;
2238 break;
2239 }
2240
2241 return bit_per_sample;
2242}
2243
2244static void update_mi2s_clk_val(int dai_id, int stream)
2245{
2246 u32 bit_per_sample = 0;
2247
2248 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
2249 bit_per_sample =
2250 get_mi2s_bits_per_sample(mi2s_rx_cfg[dai_id].bit_format);
2251 mi2s_clk[dai_id].clk_freq_in_hz =
2252 mi2s_rx_cfg[dai_id].sample_rate * 2 * bit_per_sample;
2253 } else {
2254 bit_per_sample =
2255 get_mi2s_bits_per_sample(mi2s_tx_cfg[dai_id].bit_format);
2256 mi2s_clk[dai_id].clk_freq_in_hz =
2257 mi2s_tx_cfg[dai_id].sample_rate * 2 * bit_per_sample;
2258 }
2259}
2260
2261static int msm_mi2s_set_sclk(struct snd_pcm_substream *substream, bool enable)
2262{
2263 int ret = 0;
2264 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2265 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2266 int port_id = 0;
2267 int index = cpu_dai->id;
2268
2269 port_id = msm_get_port_id(rtd->dai_link->id);
2270 if (port_id < 0) {
2271 dev_err(rtd->card->dev, "%s: Invalid port_id\n", __func__);
2272 ret = port_id;
2273 goto err;
2274 }
2275
2276 if (enable) {
2277 update_mi2s_clk_val(index, substream->stream);
2278 dev_dbg(rtd->card->dev, "%s: clock rate %ul\n", __func__,
2279 mi2s_clk[index].clk_freq_in_hz);
2280 }
2281
2282 mi2s_clk[index].enable = enable;
2283 ret = afe_set_lpass_clock_v2(port_id,
2284 &mi2s_clk[index]);
2285 if (ret < 0) {
2286 dev_err(rtd->card->dev,
2287 "%s: afe lpass clock failed for port 0x%x , err:%d\n",
2288 __func__, port_id, ret);
2289 goto err;
2290 }
2291
2292err:
2293 return ret;
2294}
2295
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07002296static int cdc_dma_get_port_idx(struct snd_kcontrol *kcontrol)
2297{
2298 int idx = 0;
2299
2300 if (strnstr(kcontrol->id.name, "WSA_CDC_DMA_RX_0",
2301 sizeof("WSA_CDC_DMA_RX_0")))
2302 idx = WSA_CDC_DMA_RX_0;
2303 else if (strnstr(kcontrol->id.name, "WSA_CDC_DMA_RX_1",
2304 sizeof("WSA_CDC_DMA_RX_0")))
2305 idx = WSA_CDC_DMA_RX_1;
2306 else if (strnstr(kcontrol->id.name, "RX_CDC_DMA_RX_0",
2307 sizeof("RX_CDC_DMA_RX_0")))
2308 idx = RX_CDC_DMA_RX_0;
2309 else if (strnstr(kcontrol->id.name, "RX_CDC_DMA_RX_1",
2310 sizeof("RX_CDC_DMA_RX_1")))
2311 idx = RX_CDC_DMA_RX_1;
2312 else if (strnstr(kcontrol->id.name, "RX_CDC_DMA_RX_2",
2313 sizeof("RX_CDC_DMA_RX_2")))
2314 idx = RX_CDC_DMA_RX_2;
2315 else if (strnstr(kcontrol->id.name, "RX_CDC_DMA_RX_3",
2316 sizeof("RX_CDC_DMA_RX_3")))
2317 idx = RX_CDC_DMA_RX_3;
2318 else if (strnstr(kcontrol->id.name, "RX_CDC_DMA_RX_5",
2319 sizeof("RX_CDC_DMA_RX_5")))
2320 idx = RX_CDC_DMA_RX_5;
2321 else if (strnstr(kcontrol->id.name, "WSA_CDC_DMA_TX_0",
2322 sizeof("WSA_CDC_DMA_TX_0")))
2323 idx = WSA_CDC_DMA_TX_0;
2324 else if (strnstr(kcontrol->id.name, "WSA_CDC_DMA_TX_1",
2325 sizeof("WSA_CDC_DMA_TX_1")))
2326 idx = WSA_CDC_DMA_TX_1;
2327 else if (strnstr(kcontrol->id.name, "WSA_CDC_DMA_TX_2",
2328 sizeof("WSA_CDC_DMA_TX_2")))
2329 idx = WSA_CDC_DMA_TX_2;
2330 else if (strnstr(kcontrol->id.name, "TX_CDC_DMA_TX_0",
2331 sizeof("TX_CDC_DMA_TX_0")))
2332 idx = TX_CDC_DMA_TX_0;
2333 else if (strnstr(kcontrol->id.name, "TX_CDC_DMA_TX_3",
2334 sizeof("TX_CDC_DMA_TX_3")))
2335 idx = TX_CDC_DMA_TX_3;
2336 else if (strnstr(kcontrol->id.name, "TX_CDC_DMA_TX_4",
2337 sizeof("TX_CDC_DMA_TX_4")))
2338 idx = TX_CDC_DMA_TX_4;
Xiaoyu Ye2228bf02018-12-12 15:47:20 -08002339 else if (strnstr(kcontrol->id.name, "VA_CDC_DMA_TX_0",
2340 sizeof("VA_CDC_DMA_TX_0")))
2341 idx = VA_CDC_DMA_TX_0;
2342 else if (strnstr(kcontrol->id.name, "VA_CDC_DMA_TX_1",
2343 sizeof("VA_CDC_DMA_TX_1")))
2344 idx = VA_CDC_DMA_TX_1;
2345 else if (strnstr(kcontrol->id.name, "VA_CDC_DMA_TX_2",
2346 sizeof("VA_CDC_DMA_TX_2")))
2347 idx = VA_CDC_DMA_TX_2;
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07002348 else {
2349 pr_err("%s: unsupported channel: %s\n",
2350 __func__, kcontrol->id.name);
2351 return -EINVAL;
2352 }
2353
2354 return idx;
2355}
2356
2357static int cdc_dma_rx_ch_get(struct snd_kcontrol *kcontrol,
2358 struct snd_ctl_elem_value *ucontrol)
2359{
2360 int ch_num = cdc_dma_get_port_idx(kcontrol);
2361
Vignesh Kulothungan9e17da02019-03-21 12:15:59 -07002362 if (ch_num < 0 || ch_num >= CDC_DMA_RX_MAX) {
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07002363 pr_err("%s: ch_num: %d is invalid\n", __func__, ch_num);
2364 return ch_num;
2365 }
2366
2367 pr_debug("%s: cdc_dma_rx_ch = %d\n", __func__,
2368 cdc_dma_rx_cfg[ch_num].channels - 1);
2369 ucontrol->value.integer.value[0] = cdc_dma_rx_cfg[ch_num].channels - 1;
2370 return 0;
2371}
2372
2373static int cdc_dma_rx_ch_put(struct snd_kcontrol *kcontrol,
2374 struct snd_ctl_elem_value *ucontrol)
2375{
2376 int ch_num = cdc_dma_get_port_idx(kcontrol);
2377
Vignesh Kulothungan9e17da02019-03-21 12:15:59 -07002378 if (ch_num < 0 || ch_num >= CDC_DMA_RX_MAX) {
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07002379 pr_err("%s: ch_num: %d is invalid\n", __func__, ch_num);
2380 return ch_num;
2381 }
2382
2383 cdc_dma_rx_cfg[ch_num].channels = ucontrol->value.integer.value[0] + 1;
2384
2385 pr_debug("%s: cdc_dma_rx_ch = %d\n", __func__,
2386 cdc_dma_rx_cfg[ch_num].channels);
2387 return 1;
2388}
2389
2390static int cdc_dma_rx_format_get(struct snd_kcontrol *kcontrol,
2391 struct snd_ctl_elem_value *ucontrol)
2392{
2393 int ch_num = cdc_dma_get_port_idx(kcontrol);
2394
Vignesh Kulothungan9e17da02019-03-21 12:15:59 -07002395 if (ch_num < 0 || ch_num >= CDC_DMA_RX_MAX) {
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07002396 pr_err("%s: ch_num: %d is invalid\n", __func__, ch_num);
2397 return ch_num;
2398 }
2399
2400 switch (cdc_dma_rx_cfg[ch_num].bit_format) {
2401 case SNDRV_PCM_FORMAT_S32_LE:
2402 ucontrol->value.integer.value[0] = 3;
2403 break;
2404 case SNDRV_PCM_FORMAT_S24_3LE:
2405 ucontrol->value.integer.value[0] = 2;
2406 break;
2407 case SNDRV_PCM_FORMAT_S24_LE:
2408 ucontrol->value.integer.value[0] = 1;
2409 break;
2410 case SNDRV_PCM_FORMAT_S16_LE:
2411 default:
2412 ucontrol->value.integer.value[0] = 0;
2413 break;
2414 }
2415
2416 pr_debug("%s: cdc_dma_rx_format = %d, ucontrol value = %ld\n",
2417 __func__, cdc_dma_rx_cfg[ch_num].bit_format,
2418 ucontrol->value.integer.value[0]);
2419 return 0;
2420}
2421
2422static int cdc_dma_rx_format_put(struct snd_kcontrol *kcontrol,
2423 struct snd_ctl_elem_value *ucontrol)
2424{
2425 int rc = 0;
2426 int ch_num = cdc_dma_get_port_idx(kcontrol);
2427
Vignesh Kulothungan9e17da02019-03-21 12:15:59 -07002428 if (ch_num < 0 || ch_num >= CDC_DMA_RX_MAX) {
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07002429 pr_err("%s: ch_num: %d is invalid\n", __func__, ch_num);
2430 return ch_num;
2431 }
2432
2433 switch (ucontrol->value.integer.value[0]) {
2434 case 3:
2435 cdc_dma_rx_cfg[ch_num].bit_format = SNDRV_PCM_FORMAT_S32_LE;
2436 break;
2437 case 2:
2438 cdc_dma_rx_cfg[ch_num].bit_format = SNDRV_PCM_FORMAT_S24_3LE;
2439 break;
2440 case 1:
2441 cdc_dma_rx_cfg[ch_num].bit_format = SNDRV_PCM_FORMAT_S24_LE;
2442 break;
2443 case 0:
2444 default:
2445 cdc_dma_rx_cfg[ch_num].bit_format = SNDRV_PCM_FORMAT_S16_LE;
2446 break;
2447 }
2448 pr_debug("%s: cdc_dma_rx_format = %d, ucontrol value = %ld\n",
2449 __func__, cdc_dma_rx_cfg[ch_num].bit_format,
2450 ucontrol->value.integer.value[0]);
2451
2452 return rc;
2453}
2454
2455
2456static int cdc_dma_get_sample_rate_val(int sample_rate)
2457{
2458 int sample_rate_val = 0;
2459
2460 switch (sample_rate) {
2461 case SAMPLING_RATE_8KHZ:
2462 sample_rate_val = 0;
2463 break;
2464 case SAMPLING_RATE_11P025KHZ:
2465 sample_rate_val = 1;
2466 break;
2467 case SAMPLING_RATE_16KHZ:
2468 sample_rate_val = 2;
2469 break;
2470 case SAMPLING_RATE_22P05KHZ:
2471 sample_rate_val = 3;
2472 break;
2473 case SAMPLING_RATE_32KHZ:
2474 sample_rate_val = 4;
2475 break;
2476 case SAMPLING_RATE_44P1KHZ:
2477 sample_rate_val = 5;
2478 break;
2479 case SAMPLING_RATE_48KHZ:
2480 sample_rate_val = 6;
2481 break;
2482 case SAMPLING_RATE_88P2KHZ:
2483 sample_rate_val = 7;
2484 break;
2485 case SAMPLING_RATE_96KHZ:
2486 sample_rate_val = 8;
2487 break;
2488 case SAMPLING_RATE_176P4KHZ:
2489 sample_rate_val = 9;
2490 break;
2491 case SAMPLING_RATE_192KHZ:
2492 sample_rate_val = 10;
2493 break;
2494 case SAMPLING_RATE_352P8KHZ:
2495 sample_rate_val = 11;
2496 break;
2497 case SAMPLING_RATE_384KHZ:
2498 sample_rate_val = 12;
2499 break;
2500 default:
2501 sample_rate_val = 6;
2502 break;
2503 }
2504 return sample_rate_val;
2505}
2506
2507static int cdc_dma_get_sample_rate(int value)
2508{
2509 int sample_rate = 0;
2510
2511 switch (value) {
2512 case 0:
2513 sample_rate = SAMPLING_RATE_8KHZ;
2514 break;
2515 case 1:
2516 sample_rate = SAMPLING_RATE_11P025KHZ;
2517 break;
2518 case 2:
2519 sample_rate = SAMPLING_RATE_16KHZ;
2520 break;
2521 case 3:
2522 sample_rate = SAMPLING_RATE_22P05KHZ;
2523 break;
2524 case 4:
2525 sample_rate = SAMPLING_RATE_32KHZ;
2526 break;
2527 case 5:
2528 sample_rate = SAMPLING_RATE_44P1KHZ;
2529 break;
2530 case 6:
2531 sample_rate = SAMPLING_RATE_48KHZ;
2532 break;
2533 case 7:
2534 sample_rate = SAMPLING_RATE_88P2KHZ;
2535 break;
2536 case 8:
2537 sample_rate = SAMPLING_RATE_96KHZ;
2538 break;
2539 case 9:
2540 sample_rate = SAMPLING_RATE_176P4KHZ;
2541 break;
2542 case 10:
2543 sample_rate = SAMPLING_RATE_192KHZ;
2544 break;
2545 case 11:
2546 sample_rate = SAMPLING_RATE_352P8KHZ;
2547 break;
2548 case 12:
2549 sample_rate = SAMPLING_RATE_384KHZ;
2550 break;
2551 default:
2552 sample_rate = SAMPLING_RATE_48KHZ;
2553 break;
2554 }
2555 return sample_rate;
2556}
2557
2558static int cdc_dma_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
2559 struct snd_ctl_elem_value *ucontrol)
2560{
2561 int ch_num = cdc_dma_get_port_idx(kcontrol);
2562
Vignesh Kulothungan9e17da02019-03-21 12:15:59 -07002563 if (ch_num < 0 || ch_num >= CDC_DMA_RX_MAX) {
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07002564 pr_err("%s: ch_num: %d is invalid\n", __func__, ch_num);
2565 return ch_num;
2566 }
2567
2568 ucontrol->value.enumerated.item[0] =
2569 cdc_dma_get_sample_rate_val(cdc_dma_rx_cfg[ch_num].sample_rate);
2570
2571 pr_debug("%s: cdc_dma_rx_sample_rate = %d\n", __func__,
2572 cdc_dma_rx_cfg[ch_num].sample_rate);
2573 return 0;
2574}
2575
2576static int cdc_dma_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
2577 struct snd_ctl_elem_value *ucontrol)
2578{
2579 int ch_num = cdc_dma_get_port_idx(kcontrol);
2580
Vignesh Kulothungan9e17da02019-03-21 12:15:59 -07002581 if (ch_num < 0 || ch_num >= CDC_DMA_RX_MAX) {
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07002582 pr_err("%s: ch_num: %d is invalid\n", __func__, ch_num);
2583 return ch_num;
2584 }
2585
2586 cdc_dma_rx_cfg[ch_num].sample_rate =
2587 cdc_dma_get_sample_rate(ucontrol->value.enumerated.item[0]);
2588
2589
2590 pr_debug("%s: control value = %d, cdc_dma_rx_sample_rate = %d\n",
2591 __func__, ucontrol->value.enumerated.item[0],
2592 cdc_dma_rx_cfg[ch_num].sample_rate);
2593 return 0;
2594}
2595
2596static int cdc_dma_tx_ch_get(struct snd_kcontrol *kcontrol,
2597 struct snd_ctl_elem_value *ucontrol)
2598{
2599 int ch_num = cdc_dma_get_port_idx(kcontrol);
2600
2601 if (ch_num < 0) {
2602 pr_err("%s: ch_num: %d is invalid\n", __func__, ch_num);
2603 return ch_num;
2604 }
2605
2606 pr_debug("%s: cdc_dma_tx_ch = %d\n", __func__,
2607 cdc_dma_tx_cfg[ch_num].channels);
2608 ucontrol->value.integer.value[0] = cdc_dma_tx_cfg[ch_num].channels - 1;
2609 return 0;
2610}
2611
2612static int cdc_dma_tx_ch_put(struct snd_kcontrol *kcontrol,
2613 struct snd_ctl_elem_value *ucontrol)
2614{
2615 int ch_num = cdc_dma_get_port_idx(kcontrol);
2616
2617 if (ch_num < 0) {
2618 pr_err("%s: ch_num: %d is invalid\n", __func__, ch_num);
2619 return ch_num;
2620 }
2621
2622 cdc_dma_tx_cfg[ch_num].channels = ucontrol->value.integer.value[0] + 1;
2623
2624 pr_debug("%s: cdc_dma_tx_ch = %d\n", __func__,
2625 cdc_dma_tx_cfg[ch_num].channels);
2626 return 1;
2627}
2628
2629static int cdc_dma_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
2630 struct snd_ctl_elem_value *ucontrol)
2631{
2632 int sample_rate_val;
2633 int ch_num = cdc_dma_get_port_idx(kcontrol);
2634
2635 if (ch_num < 0) {
2636 pr_err("%s: ch_num: %d is invalid\n", __func__, ch_num);
2637 return ch_num;
2638 }
2639
2640 switch (cdc_dma_tx_cfg[ch_num].sample_rate) {
2641 case SAMPLING_RATE_384KHZ:
2642 sample_rate_val = 12;
2643 break;
2644 case SAMPLING_RATE_352P8KHZ:
2645 sample_rate_val = 11;
2646 break;
2647 case SAMPLING_RATE_192KHZ:
2648 sample_rate_val = 10;
2649 break;
2650 case SAMPLING_RATE_176P4KHZ:
2651 sample_rate_val = 9;
2652 break;
2653 case SAMPLING_RATE_96KHZ:
2654 sample_rate_val = 8;
2655 break;
2656 case SAMPLING_RATE_88P2KHZ:
2657 sample_rate_val = 7;
2658 break;
2659 case SAMPLING_RATE_48KHZ:
2660 sample_rate_val = 6;
2661 break;
2662 case SAMPLING_RATE_44P1KHZ:
2663 sample_rate_val = 5;
2664 break;
2665 case SAMPLING_RATE_32KHZ:
2666 sample_rate_val = 4;
2667 break;
2668 case SAMPLING_RATE_22P05KHZ:
2669 sample_rate_val = 3;
2670 break;
2671 case SAMPLING_RATE_16KHZ:
2672 sample_rate_val = 2;
2673 break;
2674 case SAMPLING_RATE_11P025KHZ:
2675 sample_rate_val = 1;
2676 break;
2677 case SAMPLING_RATE_8KHZ:
2678 sample_rate_val = 0;
2679 break;
2680 default:
2681 sample_rate_val = 6;
2682 break;
2683 }
2684
2685 ucontrol->value.integer.value[0] = sample_rate_val;
2686 pr_debug("%s: cdc_dma_tx_sample_rate = %d\n", __func__,
2687 cdc_dma_tx_cfg[ch_num].sample_rate);
2688 return 0;
2689}
2690
2691static int cdc_dma_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
2692 struct snd_ctl_elem_value *ucontrol)
2693{
2694 int ch_num = cdc_dma_get_port_idx(kcontrol);
2695
2696 if (ch_num < 0) {
2697 pr_err("%s: ch_num: %d is invalid\n", __func__, ch_num);
2698 return ch_num;
2699 }
2700
2701 switch (ucontrol->value.integer.value[0]) {
2702 case 12:
2703 cdc_dma_tx_cfg[ch_num].sample_rate = SAMPLING_RATE_384KHZ;
2704 break;
2705 case 11:
2706 cdc_dma_tx_cfg[ch_num].sample_rate = SAMPLING_RATE_352P8KHZ;
2707 break;
2708 case 10:
2709 cdc_dma_tx_cfg[ch_num].sample_rate = SAMPLING_RATE_192KHZ;
2710 break;
2711 case 9:
2712 cdc_dma_tx_cfg[ch_num].sample_rate = SAMPLING_RATE_176P4KHZ;
2713 break;
2714 case 8:
2715 cdc_dma_tx_cfg[ch_num].sample_rate = SAMPLING_RATE_96KHZ;
2716 break;
2717 case 7:
2718 cdc_dma_tx_cfg[ch_num].sample_rate = SAMPLING_RATE_88P2KHZ;
2719 break;
2720 case 6:
2721 cdc_dma_tx_cfg[ch_num].sample_rate = SAMPLING_RATE_48KHZ;
2722 break;
2723 case 5:
2724 cdc_dma_tx_cfg[ch_num].sample_rate = SAMPLING_RATE_44P1KHZ;
2725 break;
2726 case 4:
2727 cdc_dma_tx_cfg[ch_num].sample_rate = SAMPLING_RATE_32KHZ;
2728 break;
2729 case 3:
2730 cdc_dma_tx_cfg[ch_num].sample_rate = SAMPLING_RATE_22P05KHZ;
2731 break;
2732 case 2:
2733 cdc_dma_tx_cfg[ch_num].sample_rate = SAMPLING_RATE_16KHZ;
2734 break;
2735 case 1:
2736 cdc_dma_tx_cfg[ch_num].sample_rate = SAMPLING_RATE_11P025KHZ;
2737 break;
2738 case 0:
2739 cdc_dma_tx_cfg[ch_num].sample_rate = SAMPLING_RATE_8KHZ;
2740 break;
2741 default:
2742 cdc_dma_tx_cfg[ch_num].sample_rate = SAMPLING_RATE_48KHZ;
2743 break;
2744 }
2745
2746 pr_debug("%s: control value = %ld, cdc_dma_tx_sample_rate = %d\n",
2747 __func__, ucontrol->value.integer.value[0],
2748 cdc_dma_tx_cfg[ch_num].sample_rate);
2749 return 0;
2750}
2751
2752static int cdc_dma_tx_format_get(struct snd_kcontrol *kcontrol,
2753 struct snd_ctl_elem_value *ucontrol)
2754{
2755 int ch_num = cdc_dma_get_port_idx(kcontrol);
2756
2757 if (ch_num < 0) {
2758 pr_err("%s: ch_num: %d is invalid\n", __func__, ch_num);
2759 return ch_num;
2760 }
2761
2762 switch (cdc_dma_tx_cfg[ch_num].bit_format) {
2763 case SNDRV_PCM_FORMAT_S32_LE:
2764 ucontrol->value.integer.value[0] = 3;
2765 break;
2766 case SNDRV_PCM_FORMAT_S24_3LE:
2767 ucontrol->value.integer.value[0] = 2;
2768 break;
2769 case SNDRV_PCM_FORMAT_S24_LE:
2770 ucontrol->value.integer.value[0] = 1;
2771 break;
2772 case SNDRV_PCM_FORMAT_S16_LE:
2773 default:
2774 ucontrol->value.integer.value[0] = 0;
2775 break;
2776 }
2777
2778 pr_debug("%s: cdc_dma_tx_format = %d, ucontrol value = %ld\n",
2779 __func__, cdc_dma_tx_cfg[ch_num].bit_format,
2780 ucontrol->value.integer.value[0]);
2781 return 0;
2782}
2783
2784static int cdc_dma_tx_format_put(struct snd_kcontrol *kcontrol,
2785 struct snd_ctl_elem_value *ucontrol)
2786{
2787 int rc = 0;
2788 int ch_num = cdc_dma_get_port_idx(kcontrol);
2789
2790 if (ch_num < 0) {
2791 pr_err("%s: ch_num: %d is invalid\n", __func__, ch_num);
2792 return ch_num;
2793 }
2794
2795 switch (ucontrol->value.integer.value[0]) {
2796 case 3:
2797 cdc_dma_tx_cfg[ch_num].bit_format = SNDRV_PCM_FORMAT_S32_LE;
2798 break;
2799 case 2:
2800 cdc_dma_tx_cfg[ch_num].bit_format = SNDRV_PCM_FORMAT_S24_3LE;
2801 break;
2802 case 1:
2803 cdc_dma_tx_cfg[ch_num].bit_format = SNDRV_PCM_FORMAT_S24_LE;
2804 break;
2805 case 0:
2806 default:
2807 cdc_dma_tx_cfg[ch_num].bit_format = SNDRV_PCM_FORMAT_S16_LE;
2808 break;
2809 }
2810 pr_debug("%s: cdc_dma_tx_format = %d, ucontrol value = %ld\n",
2811 __func__, cdc_dma_tx_cfg[ch_num].bit_format,
2812 ucontrol->value.integer.value[0]);
2813
2814 return rc;
2815}
2816
2817static int msm_cdc_dma_get_idx_from_beid(int32_t be_id)
2818{
2819 int idx = 0;
2820
2821 switch (be_id) {
2822 case MSM_BACKEND_DAI_WSA_CDC_DMA_RX_0:
2823 idx = WSA_CDC_DMA_RX_0;
2824 break;
2825 case MSM_BACKEND_DAI_WSA_CDC_DMA_TX_0:
2826 idx = WSA_CDC_DMA_TX_0;
2827 break;
2828 case MSM_BACKEND_DAI_WSA_CDC_DMA_RX_1:
2829 idx = WSA_CDC_DMA_RX_1;
2830 break;
2831 case MSM_BACKEND_DAI_WSA_CDC_DMA_TX_1:
2832 idx = WSA_CDC_DMA_TX_1;
2833 break;
2834 case MSM_BACKEND_DAI_WSA_CDC_DMA_TX_2:
2835 idx = WSA_CDC_DMA_TX_2;
2836 break;
2837 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_0:
2838 idx = RX_CDC_DMA_RX_0;
2839 break;
2840 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_1:
2841 idx = RX_CDC_DMA_RX_1;
2842 break;
2843 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_2:
2844 idx = RX_CDC_DMA_RX_2;
2845 break;
2846 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_3:
2847 idx = RX_CDC_DMA_RX_3;
2848 break;
2849 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_5:
2850 idx = RX_CDC_DMA_RX_5;
2851 break;
2852 case MSM_BACKEND_DAI_TX_CDC_DMA_TX_0:
2853 idx = TX_CDC_DMA_TX_0;
2854 break;
2855 case MSM_BACKEND_DAI_TX_CDC_DMA_TX_3:
2856 idx = TX_CDC_DMA_TX_3;
2857 break;
2858 case MSM_BACKEND_DAI_TX_CDC_DMA_TX_4:
2859 idx = TX_CDC_DMA_TX_4;
2860 break;
Xiaoyu Ye2228bf02018-12-12 15:47:20 -08002861 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_0:
2862 idx = VA_CDC_DMA_TX_0;
2863 break;
2864 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_1:
2865 idx = VA_CDC_DMA_TX_1;
2866 break;
2867 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_2:
2868 idx = VA_CDC_DMA_TX_2;
2869 break;
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07002870 default:
2871 idx = RX_CDC_DMA_RX_0;
2872 break;
2873 }
2874
2875 return idx;
2876}
2877
Banajit Goswami83a370d2019-03-05 16:15:21 -08002878static int msm_bt_sample_rate_get(struct snd_kcontrol *kcontrol,
2879 struct snd_ctl_elem_value *ucontrol)
2880{
2881 /*
2882 * Slimbus_7_Rx/Tx sample rate values should always be in sync (same)
2883 * when used for BT_SCO use case. Return either Rx or Tx sample rate
2884 * value.
2885 */
2886 switch (slim_rx_cfg[SLIM_RX_7].sample_rate) {
2887 case SAMPLING_RATE_96KHZ:
2888 ucontrol->value.integer.value[0] = 5;
2889 break;
2890 case SAMPLING_RATE_88P2KHZ:
2891 ucontrol->value.integer.value[0] = 4;
2892 break;
2893 case SAMPLING_RATE_48KHZ:
2894 ucontrol->value.integer.value[0] = 3;
2895 break;
2896 case SAMPLING_RATE_44P1KHZ:
2897 ucontrol->value.integer.value[0] = 2;
2898 break;
2899 case SAMPLING_RATE_16KHZ:
2900 ucontrol->value.integer.value[0] = 1;
2901 break;
2902 case SAMPLING_RATE_8KHZ:
2903 default:
2904 ucontrol->value.integer.value[0] = 0;
2905 break;
2906 }
2907 pr_debug("%s: sample rate = %d\n", __func__,
2908 slim_rx_cfg[SLIM_RX_7].sample_rate);
2909
2910 return 0;
2911}
2912
2913static int msm_bt_sample_rate_put(struct snd_kcontrol *kcontrol,
2914 struct snd_ctl_elem_value *ucontrol)
2915{
2916 switch (ucontrol->value.integer.value[0]) {
2917 case 1:
2918 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_16KHZ;
2919 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_16KHZ;
2920 break;
2921 case 2:
2922 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_44P1KHZ;
2923 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_44P1KHZ;
2924 break;
2925 case 3:
2926 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_48KHZ;
2927 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_48KHZ;
2928 break;
2929 case 4:
2930 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_88P2KHZ;
2931 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_88P2KHZ;
2932 break;
2933 case 5:
2934 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_96KHZ;
2935 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_96KHZ;
2936 break;
2937 case 0:
2938 default:
2939 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_8KHZ;
2940 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_8KHZ;
2941 break;
2942 }
2943 pr_debug("%s: sample rates: slim7_rx = %d, slim7_tx = %d, value = %d\n",
2944 __func__,
2945 slim_rx_cfg[SLIM_RX_7].sample_rate,
2946 slim_tx_cfg[SLIM_TX_7].sample_rate,
2947 ucontrol->value.enumerated.item[0]);
2948
2949 return 0;
2950}
2951
2952static int msm_bt_sample_rate_rx_get(struct snd_kcontrol *kcontrol,
2953 struct snd_ctl_elem_value *ucontrol)
2954{
2955 switch (slim_rx_cfg[SLIM_RX_7].sample_rate) {
2956 case SAMPLING_RATE_96KHZ:
2957 ucontrol->value.integer.value[0] = 5;
2958 break;
2959 case SAMPLING_RATE_88P2KHZ:
2960 ucontrol->value.integer.value[0] = 4;
2961 break;
2962 case SAMPLING_RATE_48KHZ:
2963 ucontrol->value.integer.value[0] = 3;
2964 break;
2965 case SAMPLING_RATE_44P1KHZ:
2966 ucontrol->value.integer.value[0] = 2;
2967 break;
2968 case SAMPLING_RATE_16KHZ:
2969 ucontrol->value.integer.value[0] = 1;
2970 break;
2971 case SAMPLING_RATE_8KHZ:
2972 default:
2973 ucontrol->value.integer.value[0] = 0;
2974 break;
2975 }
2976 pr_debug("%s: sample rate rx = %d\n", __func__,
2977 slim_rx_cfg[SLIM_RX_7].sample_rate);
2978
2979 return 0;
2980}
2981
2982static int msm_bt_sample_rate_rx_put(struct snd_kcontrol *kcontrol,
2983 struct snd_ctl_elem_value *ucontrol)
2984{
2985 switch (ucontrol->value.integer.value[0]) {
2986 case 1:
2987 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_16KHZ;
2988 break;
2989 case 2:
2990 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_44P1KHZ;
2991 break;
2992 case 3:
2993 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_48KHZ;
2994 break;
2995 case 4:
2996 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_88P2KHZ;
2997 break;
2998 case 5:
2999 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_96KHZ;
3000 break;
3001 case 0:
3002 default:
3003 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_8KHZ;
3004 break;
3005 }
3006 pr_debug("%s: sample rate: slim7_rx = %d, value = %d\n",
3007 __func__,
3008 slim_rx_cfg[SLIM_RX_7].sample_rate,
3009 ucontrol->value.enumerated.item[0]);
3010
3011 return 0;
3012}
3013
3014static int msm_bt_sample_rate_tx_get(struct snd_kcontrol *kcontrol,
3015 struct snd_ctl_elem_value *ucontrol)
3016{
3017 switch (slim_tx_cfg[SLIM_TX_7].sample_rate) {
3018 case SAMPLING_RATE_96KHZ:
3019 ucontrol->value.integer.value[0] = 5;
3020 break;
3021 case SAMPLING_RATE_88P2KHZ:
3022 ucontrol->value.integer.value[0] = 4;
3023 break;
3024 case SAMPLING_RATE_48KHZ:
3025 ucontrol->value.integer.value[0] = 3;
3026 break;
3027 case SAMPLING_RATE_44P1KHZ:
3028 ucontrol->value.integer.value[0] = 2;
3029 break;
3030 case SAMPLING_RATE_16KHZ:
3031 ucontrol->value.integer.value[0] = 1;
3032 break;
3033 case SAMPLING_RATE_8KHZ:
3034 default:
3035 ucontrol->value.integer.value[0] = 0;
3036 break;
3037 }
3038 pr_debug("%s: sample rate tx = %d\n", __func__,
3039 slim_tx_cfg[SLIM_TX_7].sample_rate);
3040
3041 return 0;
3042}
3043
3044static int msm_bt_sample_rate_tx_put(struct snd_kcontrol *kcontrol,
3045 struct snd_ctl_elem_value *ucontrol)
3046{
3047 switch (ucontrol->value.integer.value[0]) {
3048 case 1:
3049 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_16KHZ;
3050 break;
3051 case 2:
3052 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_44P1KHZ;
3053 break;
3054 case 3:
3055 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_48KHZ;
3056 break;
3057 case 4:
3058 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_88P2KHZ;
3059 break;
3060 case 5:
3061 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_96KHZ;
3062 break;
3063 case 0:
3064 default:
3065 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_8KHZ;
3066 break;
3067 }
3068 pr_debug("%s: sample rate: slim7_tx = %d, value = %d\n",
3069 __func__,
3070 slim_tx_cfg[SLIM_TX_7].sample_rate,
3071 ucontrol->value.enumerated.item[0]);
3072
3073 return 0;
3074}
3075
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07003076static const struct snd_kcontrol_new msm_int_snd_controls[] = {
3077 SOC_ENUM_EXT("WSA_CDC_DMA_RX_0 Channels", wsa_cdc_dma_rx_0_chs,
3078 cdc_dma_rx_ch_get, cdc_dma_rx_ch_put),
3079 SOC_ENUM_EXT("WSA_CDC_DMA_RX_1 Channels", wsa_cdc_dma_rx_1_chs,
3080 cdc_dma_rx_ch_get, cdc_dma_rx_ch_put),
3081 SOC_ENUM_EXT("RX_CDC_DMA_RX_0 Channels", rx_cdc_dma_rx_0_chs,
3082 cdc_dma_rx_ch_get, cdc_dma_rx_ch_put),
3083 SOC_ENUM_EXT("RX_CDC_DMA_RX_1 Channels", rx_cdc_dma_rx_1_chs,
3084 cdc_dma_rx_ch_get, cdc_dma_rx_ch_put),
3085 SOC_ENUM_EXT("RX_CDC_DMA_RX_2 Channels", rx_cdc_dma_rx_2_chs,
3086 cdc_dma_rx_ch_get, cdc_dma_rx_ch_put),
3087 SOC_ENUM_EXT("RX_CDC_DMA_RX_3 Channels", rx_cdc_dma_rx_3_chs,
3088 cdc_dma_rx_ch_get, cdc_dma_rx_ch_put),
3089 SOC_ENUM_EXT("RX_CDC_DMA_RX_5 Channels", rx_cdc_dma_rx_5_chs,
3090 cdc_dma_rx_ch_get, cdc_dma_rx_ch_put),
3091 SOC_ENUM_EXT("WSA_CDC_DMA_TX_0 Channels", wsa_cdc_dma_tx_0_chs,
3092 cdc_dma_tx_ch_get, cdc_dma_tx_ch_put),
3093 SOC_ENUM_EXT("WSA_CDC_DMA_TX_1 Channels", wsa_cdc_dma_tx_1_chs,
3094 cdc_dma_tx_ch_get, cdc_dma_tx_ch_put),
3095 SOC_ENUM_EXT("WSA_CDC_DMA_TX_2 Channels", wsa_cdc_dma_tx_2_chs,
3096 cdc_dma_tx_ch_get, cdc_dma_tx_ch_put),
3097 SOC_ENUM_EXT("TX_CDC_DMA_TX_0 Channels", tx_cdc_dma_tx_0_chs,
3098 cdc_dma_tx_ch_get, cdc_dma_tx_ch_put),
3099 SOC_ENUM_EXT("TX_CDC_DMA_TX_3 Channels", tx_cdc_dma_tx_3_chs,
3100 cdc_dma_tx_ch_get, cdc_dma_tx_ch_put),
3101 SOC_ENUM_EXT("TX_CDC_DMA_TX_4 Channels", tx_cdc_dma_tx_4_chs,
3102 cdc_dma_tx_ch_get, cdc_dma_tx_ch_put),
Xiaoyu Ye2228bf02018-12-12 15:47:20 -08003103 SOC_ENUM_EXT("VA_CDC_DMA_TX_0 Channels", va_cdc_dma_tx_0_chs,
3104 cdc_dma_tx_ch_get, cdc_dma_tx_ch_put),
3105 SOC_ENUM_EXT("VA_CDC_DMA_TX_1 Channels", va_cdc_dma_tx_1_chs,
3106 cdc_dma_tx_ch_get, cdc_dma_tx_ch_put),
3107 SOC_ENUM_EXT("VA_CDC_DMA_TX_2 Channels", va_cdc_dma_tx_2_chs,
3108 cdc_dma_tx_ch_get, cdc_dma_tx_ch_put),
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07003109 SOC_ENUM_EXT("WSA_CDC_DMA_RX_0 Format", wsa_cdc_dma_rx_0_format,
3110 cdc_dma_rx_format_get, cdc_dma_rx_format_put),
3111 SOC_ENUM_EXT("WSA_CDC_DMA_RX_1 Format", wsa_cdc_dma_rx_1_format,
3112 cdc_dma_rx_format_get, cdc_dma_rx_format_put),
3113 SOC_ENUM_EXT("RX_CDC_DMA_RX_0 Format", rx_cdc_dma_rx_0_format,
3114 cdc_dma_rx_format_get, cdc_dma_rx_format_put),
3115 SOC_ENUM_EXT("RX_CDC_DMA_RX_1 Format", rx_cdc_dma_rx_1_format,
3116 cdc_dma_rx_format_get, cdc_dma_rx_format_put),
3117 SOC_ENUM_EXT("RX_CDC_DMA_RX_2 Format", rx_cdc_dma_rx_2_format,
3118 cdc_dma_rx_format_get, cdc_dma_rx_format_put),
3119 SOC_ENUM_EXT("RX_CDC_DMA_RX_3 Format", rx_cdc_dma_rx_3_format,
3120 cdc_dma_rx_format_get, cdc_dma_rx_format_put),
3121 SOC_ENUM_EXT("RX_CDC_DMA_RX_5 Format", rx_cdc_dma_rx_5_format,
3122 cdc_dma_rx_format_get, cdc_dma_rx_format_put),
3123 SOC_ENUM_EXT("WSA_CDC_DMA_TX_1 Format", wsa_cdc_dma_tx_1_format,
3124 cdc_dma_tx_format_get, cdc_dma_tx_format_put),
3125 SOC_ENUM_EXT("WSA_CDC_DMA_TX_2 Format", wsa_cdc_dma_tx_2_format,
3126 cdc_dma_tx_format_get, cdc_dma_tx_format_put),
3127 SOC_ENUM_EXT("TX_CDC_DMA_TX_0 Format", tx_cdc_dma_tx_0_format,
3128 cdc_dma_tx_format_get, cdc_dma_tx_format_put),
3129 SOC_ENUM_EXT("TX_CDC_DMA_TX_3 Format", tx_cdc_dma_tx_3_format,
3130 cdc_dma_tx_format_get, cdc_dma_tx_format_put),
3131 SOC_ENUM_EXT("TX_CDC_DMA_TX_4 Format", tx_cdc_dma_tx_4_format,
3132 cdc_dma_tx_format_get, cdc_dma_tx_format_put),
Xiaoyu Ye2228bf02018-12-12 15:47:20 -08003133 SOC_ENUM_EXT("VA_CDC_DMA_TX_0 Format", va_cdc_dma_tx_0_format,
3134 cdc_dma_tx_format_get, cdc_dma_tx_format_put),
3135 SOC_ENUM_EXT("VA_CDC_DMA_TX_1 Format", va_cdc_dma_tx_1_format,
3136 cdc_dma_tx_format_get, cdc_dma_tx_format_put),
3137 SOC_ENUM_EXT("VA_CDC_DMA_TX_2 Format", va_cdc_dma_tx_2_format,
3138 cdc_dma_tx_format_get, cdc_dma_tx_format_put),
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07003139 SOC_ENUM_EXT("WSA_CDC_DMA_RX_0 SampleRate",
3140 wsa_cdc_dma_rx_0_sample_rate,
3141 cdc_dma_rx_sample_rate_get,
3142 cdc_dma_rx_sample_rate_put),
3143 SOC_ENUM_EXT("WSA_CDC_DMA_RX_1 SampleRate",
3144 wsa_cdc_dma_rx_1_sample_rate,
3145 cdc_dma_rx_sample_rate_get,
3146 cdc_dma_rx_sample_rate_put),
3147 SOC_ENUM_EXT("RX_CDC_DMA_RX_0 SampleRate",
3148 rx_cdc_dma_rx_0_sample_rate,
3149 cdc_dma_rx_sample_rate_get,
3150 cdc_dma_rx_sample_rate_put),
3151 SOC_ENUM_EXT("RX_CDC_DMA_RX_1 SampleRate",
3152 rx_cdc_dma_rx_1_sample_rate,
3153 cdc_dma_rx_sample_rate_get,
3154 cdc_dma_rx_sample_rate_put),
3155 SOC_ENUM_EXT("RX_CDC_DMA_RX_2 SampleRate",
3156 rx_cdc_dma_rx_2_sample_rate,
3157 cdc_dma_rx_sample_rate_get,
3158 cdc_dma_rx_sample_rate_put),
3159 SOC_ENUM_EXT("RX_CDC_DMA_RX_3 SampleRate",
3160 rx_cdc_dma_rx_3_sample_rate,
3161 cdc_dma_rx_sample_rate_get,
3162 cdc_dma_rx_sample_rate_put),
3163 SOC_ENUM_EXT("RX_CDC_DMA_RX_5 SampleRate",
3164 rx_cdc_dma_rx_5_sample_rate,
3165 cdc_dma_rx_sample_rate_get,
3166 cdc_dma_rx_sample_rate_put),
3167 SOC_ENUM_EXT("WSA_CDC_DMA_TX_0 SampleRate",
3168 wsa_cdc_dma_tx_0_sample_rate,
3169 cdc_dma_tx_sample_rate_get,
3170 cdc_dma_tx_sample_rate_put),
3171 SOC_ENUM_EXT("WSA_CDC_DMA_TX_1 SampleRate",
3172 wsa_cdc_dma_tx_1_sample_rate,
3173 cdc_dma_tx_sample_rate_get,
3174 cdc_dma_tx_sample_rate_put),
3175 SOC_ENUM_EXT("WSA_CDC_DMA_TX_2 SampleRate",
3176 wsa_cdc_dma_tx_2_sample_rate,
3177 cdc_dma_tx_sample_rate_get,
3178 cdc_dma_tx_sample_rate_put),
3179 SOC_ENUM_EXT("TX_CDC_DMA_TX_0 SampleRate",
3180 tx_cdc_dma_tx_0_sample_rate,
3181 cdc_dma_tx_sample_rate_get,
3182 cdc_dma_tx_sample_rate_put),
3183 SOC_ENUM_EXT("TX_CDC_DMA_TX_3 SampleRate",
3184 tx_cdc_dma_tx_3_sample_rate,
3185 cdc_dma_tx_sample_rate_get,
3186 cdc_dma_tx_sample_rate_put),
3187 SOC_ENUM_EXT("TX_CDC_DMA_TX_4 SampleRate",
3188 tx_cdc_dma_tx_4_sample_rate,
3189 cdc_dma_tx_sample_rate_get,
3190 cdc_dma_tx_sample_rate_put),
Xiaoyu Ye2228bf02018-12-12 15:47:20 -08003191 SOC_ENUM_EXT("VA_CDC_DMA_TX_0 SampleRate",
3192 va_cdc_dma_tx_0_sample_rate,
3193 cdc_dma_tx_sample_rate_get,
3194 cdc_dma_tx_sample_rate_put),
3195 SOC_ENUM_EXT("VA_CDC_DMA_TX_1 SampleRate",
3196 va_cdc_dma_tx_1_sample_rate,
3197 cdc_dma_tx_sample_rate_get,
3198 cdc_dma_tx_sample_rate_put),
3199 SOC_ENUM_EXT("VA_CDC_DMA_TX_2 SampleRate",
3200 va_cdc_dma_tx_2_sample_rate,
3201 cdc_dma_tx_sample_rate_get,
3202 cdc_dma_tx_sample_rate_put),
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07003203};
3204
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07003205static const struct snd_kcontrol_new msm_common_snd_controls[] = {
3206 SOC_ENUM_EXT("USB_AUDIO_RX SampleRate", usb_rx_sample_rate,
3207 usb_audio_rx_sample_rate_get,
3208 usb_audio_rx_sample_rate_put),
3209 SOC_ENUM_EXT("USB_AUDIO_TX SampleRate", usb_tx_sample_rate,
3210 usb_audio_tx_sample_rate_get,
3211 usb_audio_tx_sample_rate_put),
3212 SOC_ENUM_EXT("PRI_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
3213 tdm_rx_sample_rate_get,
3214 tdm_rx_sample_rate_put),
3215 SOC_ENUM_EXT("SEC_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
3216 tdm_rx_sample_rate_get,
3217 tdm_rx_sample_rate_put),
3218 SOC_ENUM_EXT("TERT_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
3219 tdm_rx_sample_rate_get,
3220 tdm_rx_sample_rate_put),
3221 SOC_ENUM_EXT("PRI_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
3222 tdm_tx_sample_rate_get,
3223 tdm_tx_sample_rate_put),
3224 SOC_ENUM_EXT("SEC_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
3225 tdm_tx_sample_rate_get,
3226 tdm_tx_sample_rate_put),
3227 SOC_ENUM_EXT("TERT_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
3228 tdm_tx_sample_rate_get,
3229 tdm_tx_sample_rate_put),
3230 SOC_ENUM_EXT("PRIM_AUX_PCM_RX SampleRate", prim_aux_pcm_rx_sample_rate,
3231 aux_pcm_rx_sample_rate_get,
3232 aux_pcm_rx_sample_rate_put),
3233 SOC_ENUM_EXT("SEC_AUX_PCM_RX SampleRate", sec_aux_pcm_rx_sample_rate,
3234 aux_pcm_rx_sample_rate_get,
3235 aux_pcm_rx_sample_rate_put),
3236 SOC_ENUM_EXT("TERT_AUX_PCM_RX SampleRate", tert_aux_pcm_rx_sample_rate,
3237 aux_pcm_rx_sample_rate_get,
3238 aux_pcm_rx_sample_rate_put),
3239 SOC_ENUM_EXT("PRIM_AUX_PCM_TX SampleRate", prim_aux_pcm_tx_sample_rate,
3240 aux_pcm_tx_sample_rate_get,
3241 aux_pcm_tx_sample_rate_put),
3242 SOC_ENUM_EXT("SEC_AUX_PCM_TX SampleRate", sec_aux_pcm_tx_sample_rate,
3243 aux_pcm_tx_sample_rate_get,
3244 aux_pcm_tx_sample_rate_put),
3245 SOC_ENUM_EXT("TERT_AUX_PCM_TX SampleRate", tert_aux_pcm_tx_sample_rate,
3246 aux_pcm_tx_sample_rate_get,
3247 aux_pcm_tx_sample_rate_put),
3248 SOC_ENUM_EXT("PRIM_MI2S_RX SampleRate", prim_mi2s_rx_sample_rate,
3249 mi2s_rx_sample_rate_get,
3250 mi2s_rx_sample_rate_put),
3251 SOC_ENUM_EXT("SEC_MI2S_RX SampleRate", sec_mi2s_rx_sample_rate,
3252 mi2s_rx_sample_rate_get,
3253 mi2s_rx_sample_rate_put),
3254 SOC_ENUM_EXT("TERT_MI2S_RX SampleRate", tert_mi2s_rx_sample_rate,
3255 mi2s_rx_sample_rate_get,
3256 mi2s_rx_sample_rate_put),
3257 SOC_ENUM_EXT("PRIM_MI2S_TX SampleRate", prim_mi2s_tx_sample_rate,
3258 mi2s_tx_sample_rate_get,
3259 mi2s_tx_sample_rate_put),
3260 SOC_ENUM_EXT("SEC_MI2S_TX SampleRate", sec_mi2s_tx_sample_rate,
3261 mi2s_tx_sample_rate_get,
3262 mi2s_tx_sample_rate_put),
3263 SOC_ENUM_EXT("TERT_MI2S_TX SampleRate", tert_mi2s_tx_sample_rate,
3264 mi2s_tx_sample_rate_get,
3265 mi2s_tx_sample_rate_put),
3266 SOC_ENUM_EXT("USB_AUDIO_RX Format", usb_rx_format,
3267 usb_audio_rx_format_get, usb_audio_rx_format_put),
3268 SOC_ENUM_EXT("USB_AUDIO_TX Format", usb_tx_format,
3269 usb_audio_tx_format_get, usb_audio_tx_format_put),
3270 SOC_ENUM_EXT("PRI_TDM_RX_0 Format", tdm_rx_format,
3271 tdm_rx_format_get,
3272 tdm_rx_format_put),
3273 SOC_ENUM_EXT("SEC_TDM_RX_0 Format", tdm_rx_format,
3274 tdm_rx_format_get,
3275 tdm_rx_format_put),
3276 SOC_ENUM_EXT("TERT_TDM_RX_0 Format", tdm_rx_format,
3277 tdm_rx_format_get,
3278 tdm_rx_format_put),
3279 SOC_ENUM_EXT("PRI_TDM_TX_0 Format", tdm_tx_format,
3280 tdm_tx_format_get,
3281 tdm_tx_format_put),
3282 SOC_ENUM_EXT("SEC_TDM_TX_0 Format", tdm_tx_format,
3283 tdm_tx_format_get,
3284 tdm_tx_format_put),
3285 SOC_ENUM_EXT("TERT_TDM_TX_0 Format", tdm_tx_format,
3286 tdm_tx_format_get,
3287 tdm_tx_format_put),
3288 SOC_ENUM_EXT("PRIM_AUX_PCM_RX Format", aux_pcm_rx_format,
3289 msm_aux_pcm_rx_format_get, msm_aux_pcm_rx_format_put),
3290 SOC_ENUM_EXT("SEC_AUX_PCM_RX Format", aux_pcm_rx_format,
3291 msm_aux_pcm_rx_format_get, msm_aux_pcm_rx_format_put),
3292 SOC_ENUM_EXT("TERT_AUX_PCM_RX Format", aux_pcm_rx_format,
3293 msm_aux_pcm_rx_format_get, msm_aux_pcm_rx_format_put),
3294 SOC_ENUM_EXT("PRIM_AUX_PCM_TX Format", aux_pcm_tx_format,
3295 msm_aux_pcm_tx_format_get, msm_aux_pcm_tx_format_put),
3296 SOC_ENUM_EXT("SEC_AUX_PCM_TX Format", aux_pcm_tx_format,
3297 msm_aux_pcm_tx_format_get, msm_aux_pcm_tx_format_put),
3298 SOC_ENUM_EXT("TERT_AUX_PCM_TX Format", aux_pcm_tx_format,
3299 msm_aux_pcm_tx_format_get, msm_aux_pcm_tx_format_put),
3300 SOC_ENUM_EXT("PRIM_MI2S_RX Format", mi2s_rx_format,
3301 msm_mi2s_rx_format_get, msm_mi2s_rx_format_put),
3302 SOC_ENUM_EXT("SEC_MI2S_RX Format", mi2s_rx_format,
3303 msm_mi2s_rx_format_get, msm_mi2s_rx_format_put),
3304 SOC_ENUM_EXT("TERT_MI2S_RX Format", mi2s_rx_format,
3305 msm_mi2s_rx_format_get, msm_mi2s_rx_format_put),
3306 SOC_ENUM_EXT("PRIM_MI2S_TX Format", mi2s_tx_format,
3307 msm_mi2s_tx_format_get, msm_mi2s_tx_format_put),
3308 SOC_ENUM_EXT("SEC_MI2S_TX Format", mi2s_tx_format,
3309 msm_mi2s_tx_format_get, msm_mi2s_tx_format_put),
3310 SOC_ENUM_EXT("TERT_MI2S_TX Format", mi2s_tx_format,
3311 msm_mi2s_tx_format_get, msm_mi2s_tx_format_put),
3312 SOC_ENUM_EXT("USB_AUDIO_RX Channels", usb_rx_chs,
3313 usb_audio_rx_ch_get, usb_audio_rx_ch_put),
3314 SOC_ENUM_EXT("USB_AUDIO_TX Channels", usb_tx_chs,
3315 usb_audio_tx_ch_get, usb_audio_tx_ch_put),
3316 SOC_ENUM_EXT("PROXY_RX Channels", proxy_rx_chs,
3317 proxy_rx_ch_get, proxy_rx_ch_put),
3318 SOC_ENUM_EXT("PRI_TDM_RX_0 Channels", tdm_rx_chs,
3319 tdm_rx_ch_get,
3320 tdm_rx_ch_put),
3321 SOC_ENUM_EXT("SEC_TDM_RX_0 Channels", tdm_rx_chs,
3322 tdm_rx_ch_get,
3323 tdm_rx_ch_put),
3324 SOC_ENUM_EXT("TERT_TDM_RX_0 Channels", tdm_rx_chs,
3325 tdm_rx_ch_get,
3326 tdm_rx_ch_put),
3327 SOC_ENUM_EXT("PRI_TDM_TX_0 Channels", tdm_tx_chs,
3328 tdm_tx_ch_get,
3329 tdm_tx_ch_put),
3330 SOC_ENUM_EXT("SEC_TDM_TX_0 Channels", tdm_tx_chs,
3331 tdm_tx_ch_get,
3332 tdm_tx_ch_put),
3333 SOC_ENUM_EXT("TERT_TDM_TX_0 Channels", tdm_tx_chs,
3334 tdm_tx_ch_get,
3335 tdm_tx_ch_put),
3336 SOC_ENUM_EXT("PRIM_MI2S_RX Channels", prim_mi2s_rx_chs,
3337 msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
3338 SOC_ENUM_EXT("SEC_MI2S_RX Channels", sec_mi2s_rx_chs,
3339 msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
3340 SOC_ENUM_EXT("TERT_MI2S_RX Channels", tert_mi2s_rx_chs,
3341 msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
3342 SOC_ENUM_EXT("PRIM_MI2S_TX Channels", prim_mi2s_tx_chs,
3343 msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
3344 SOC_ENUM_EXT("SEC_MI2S_TX Channels", sec_mi2s_tx_chs,
3345 msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
3346 SOC_ENUM_EXT("TERT_MI2S_TX Channels", tert_mi2s_tx_chs,
3347 msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
Banajit Goswamib4347d52019-02-28 20:11:49 -08003348 SOC_ENUM_EXT("Display Port RX Channels", ext_disp_rx_chs,
3349 ext_disp_rx_ch_get, ext_disp_rx_ch_put),
3350 SOC_ENUM_EXT("Display Port RX Bit Format", ext_disp_rx_format,
3351 ext_disp_rx_format_get, ext_disp_rx_format_put),
3352 SOC_ENUM_EXT("Display Port RX SampleRate", ext_disp_rx_sample_rate,
3353 ext_disp_rx_sample_rate_get,
3354 ext_disp_rx_sample_rate_put),
Banajit Goswami83a370d2019-03-05 16:15:21 -08003355 SOC_ENUM_EXT("BT SampleRate", bt_sample_rate,
3356 msm_bt_sample_rate_get,
3357 msm_bt_sample_rate_put),
3358 SOC_ENUM_EXT("BT SampleRate RX", bt_sample_rate_rx,
3359 msm_bt_sample_rate_rx_get,
3360 msm_bt_sample_rate_rx_put),
3361 SOC_ENUM_EXT("BT SampleRate TX", bt_sample_rate_tx,
3362 msm_bt_sample_rate_tx_get,
3363 msm_bt_sample_rate_tx_put),
Meng Wange8e53822019-03-18 10:49:50 +08003364 SOC_ENUM_EXT("AFE_LOOPBACK_TX Channels", afe_loopback_tx_chs,
3365 afe_loopback_tx_ch_get, afe_loopback_tx_ch_put),
Meng Wangd1db67c2019-04-17 12:41:34 +08003366 SOC_ENUM_EXT("VI_FEED_TX Channels", vi_feed_tx_chs,
3367 msm_vi_feed_tx_ch_get, msm_vi_feed_tx_ch_put),
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07003368};
3369
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07003370static const struct snd_kcontrol_new msm_snd_controls[] = {
3371 SOC_ENUM_EXT("PRIM_AUX_PCM_RX Format", aux_pcm_rx_format,
3372 msm_aux_pcm_rx_format_get, msm_aux_pcm_rx_format_put),
3373 SOC_ENUM_EXT("PRIM_AUX_PCM_TX Format", aux_pcm_tx_format,
3374 msm_aux_pcm_tx_format_get, msm_aux_pcm_tx_format_put),
3375 SOC_ENUM_EXT("PRIM_AUX_PCM_RX SampleRate", prim_aux_pcm_rx_sample_rate,
3376 aux_pcm_rx_sample_rate_get,
3377 aux_pcm_rx_sample_rate_put),
3378 SOC_ENUM_EXT("PRIM_AUX_PCM_TX SampleRate", prim_aux_pcm_tx_sample_rate,
3379 aux_pcm_tx_sample_rate_get,
3380 aux_pcm_tx_sample_rate_put),
3381};
3382
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -08003383static int msm_ext_disp_get_idx_from_beid(int32_t be_id)
3384{
3385 int idx;
3386
3387 switch (be_id) {
3388 case MSM_BACKEND_DAI_DISPLAY_PORT_RX:
3389 idx = EXT_DISP_RX_IDX_DP;
3390 break;
3391 default:
3392 pr_err("%s: Incorrect ext_disp BE id %d\n", __func__, be_id);
3393 idx = -EINVAL;
3394 break;
3395 }
3396
3397 return idx;
3398}
3399
Xiaoyu Yeffbdc9f2019-05-17 15:02:39 -07003400static int kona_send_island_va_config(int32_t be_id)
3401{
3402 int rc = 0;
3403 int port_id = 0xFFFF;
3404
3405 port_id = msm_get_port_id(be_id);
3406 if (port_id < 0) {
3407 pr_err("%s: Invalid island interface, be_id: %d\n",
3408 __func__, be_id);
3409 rc = -EINVAL;
3410 } else {
3411 /*
3412 * send island mode config
3413 * This should be the first configuration
3414 */
3415 rc = afe_send_port_island_mode(port_id);
3416 if (rc)
3417 pr_err("%s: afe send island mode failed %d\n",
3418 __func__, rc);
3419 }
3420
3421 return rc;
3422}
3423
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07003424static int msm_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
3425 struct snd_pcm_hw_params *params)
3426{
3427 struct snd_soc_dai_link *dai_link = rtd->dai_link;
3428 struct snd_interval *rate = hw_param_interval(params,
3429 SNDRV_PCM_HW_PARAM_RATE);
3430 struct snd_interval *channels = hw_param_interval(params,
3431 SNDRV_PCM_HW_PARAM_CHANNELS);
Meng Wange8e53822019-03-18 10:49:50 +08003432 int idx = 0, rc = 0;
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07003433
3434 pr_debug("%s: format = %d, rate = %d\n",
3435 __func__, params_format(params), params_rate(params));
3436
3437 switch (dai_link->id) {
3438 case MSM_BACKEND_DAI_USB_RX:
3439 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3440 usb_rx_cfg.bit_format);
3441 rate->min = rate->max = usb_rx_cfg.sample_rate;
3442 channels->min = channels->max = usb_rx_cfg.channels;
3443 break;
3444
3445 case MSM_BACKEND_DAI_USB_TX:
3446 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3447 usb_tx_cfg.bit_format);
3448 rate->min = rate->max = usb_tx_cfg.sample_rate;
3449 channels->min = channels->max = usb_tx_cfg.channels;
3450 break;
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -08003451
3452 case MSM_BACKEND_DAI_DISPLAY_PORT_RX:
3453 idx = msm_ext_disp_get_idx_from_beid(dai_link->id);
3454 if (idx < 0) {
3455 pr_err("%s: Incorrect ext disp idx %d\n",
3456 __func__, idx);
3457 rc = idx;
3458 goto done;
3459 }
3460
3461 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3462 ext_disp_rx_cfg[idx].bit_format);
3463 rate->min = rate->max = ext_disp_rx_cfg[idx].sample_rate;
3464 channels->min = channels->max = ext_disp_rx_cfg[idx].channels;
3465 break;
3466
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07003467 case MSM_BACKEND_DAI_AFE_PCM_RX:
3468 channels->min = channels->max = proxy_rx_cfg.channels;
3469 rate->min = rate->max = SAMPLING_RATE_48KHZ;
3470 break;
3471
3472 case MSM_BACKEND_DAI_PRI_TDM_RX_0:
3473 channels->min = channels->max =
3474 tdm_rx_cfg[TDM_PRI][TDM_0].channels;
3475 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3476 tdm_rx_cfg[TDM_PRI][TDM_0].bit_format);
3477 rate->min = rate->max = tdm_rx_cfg[TDM_PRI][TDM_0].sample_rate;
3478 break;
3479
3480 case MSM_BACKEND_DAI_PRI_TDM_TX_0:
3481 channels->min = channels->max =
3482 tdm_tx_cfg[TDM_PRI][TDM_0].channels;
3483 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3484 tdm_tx_cfg[TDM_PRI][TDM_0].bit_format);
3485 rate->min = rate->max = tdm_tx_cfg[TDM_PRI][TDM_0].sample_rate;
3486 break;
3487
3488 case MSM_BACKEND_DAI_SEC_TDM_RX_0:
3489 channels->min = channels->max =
3490 tdm_rx_cfg[TDM_SEC][TDM_0].channels;
3491 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3492 tdm_rx_cfg[TDM_SEC][TDM_0].bit_format);
3493 rate->min = rate->max = tdm_rx_cfg[TDM_SEC][TDM_0].sample_rate;
3494 break;
3495
3496 case MSM_BACKEND_DAI_SEC_TDM_TX_0:
3497 channels->min = channels->max =
3498 tdm_tx_cfg[TDM_SEC][TDM_0].channels;
3499 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3500 tdm_tx_cfg[TDM_SEC][TDM_0].bit_format);
3501 rate->min = rate->max = tdm_tx_cfg[TDM_SEC][TDM_0].sample_rate;
3502 break;
3503
3504 case MSM_BACKEND_DAI_TERT_TDM_RX_0:
3505 channels->min = channels->max =
3506 tdm_rx_cfg[TDM_TERT][TDM_0].channels;
3507 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3508 tdm_rx_cfg[TDM_TERT][TDM_0].bit_format);
3509 rate->min = rate->max = tdm_rx_cfg[TDM_TERT][TDM_0].sample_rate;
3510 break;
3511
3512 case MSM_BACKEND_DAI_TERT_TDM_TX_0:
3513 channels->min = channels->max =
3514 tdm_tx_cfg[TDM_TERT][TDM_0].channels;
3515 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3516 tdm_tx_cfg[TDM_TERT][TDM_0].bit_format);
3517 rate->min = rate->max = tdm_tx_cfg[TDM_TERT][TDM_0].sample_rate;
3518 break;
3519
3520 case MSM_BACKEND_DAI_AUXPCM_RX:
3521 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3522 aux_pcm_rx_cfg[PRIM_AUX_PCM].bit_format);
3523 rate->min = rate->max =
3524 aux_pcm_rx_cfg[PRIM_AUX_PCM].sample_rate;
3525 channels->min = channels->max =
3526 aux_pcm_rx_cfg[PRIM_AUX_PCM].channels;
3527 break;
3528
3529 case MSM_BACKEND_DAI_AUXPCM_TX:
3530 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3531 aux_pcm_tx_cfg[PRIM_AUX_PCM].bit_format);
3532 rate->min = rate->max =
3533 aux_pcm_tx_cfg[PRIM_AUX_PCM].sample_rate;
3534 channels->min = channels->max =
3535 aux_pcm_tx_cfg[PRIM_AUX_PCM].channels;
3536 break;
3537
3538 case MSM_BACKEND_DAI_SEC_AUXPCM_RX:
3539 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3540 aux_pcm_rx_cfg[SEC_AUX_PCM].bit_format);
3541 rate->min = rate->max =
3542 aux_pcm_rx_cfg[SEC_AUX_PCM].sample_rate;
3543 channels->min = channels->max =
3544 aux_pcm_rx_cfg[SEC_AUX_PCM].channels;
3545 break;
3546
3547 case MSM_BACKEND_DAI_SEC_AUXPCM_TX:
3548 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3549 aux_pcm_tx_cfg[SEC_AUX_PCM].bit_format);
3550 rate->min = rate->max =
3551 aux_pcm_tx_cfg[SEC_AUX_PCM].sample_rate;
3552 channels->min = channels->max =
3553 aux_pcm_tx_cfg[SEC_AUX_PCM].channels;
3554 break;
3555
3556 case MSM_BACKEND_DAI_TERT_AUXPCM_RX:
3557 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3558 aux_pcm_rx_cfg[TERT_AUX_PCM].bit_format);
3559 rate->min = rate->max =
3560 aux_pcm_rx_cfg[TERT_AUX_PCM].sample_rate;
3561 channels->min = channels->max =
3562 aux_pcm_rx_cfg[TERT_AUX_PCM].channels;
3563 break;
3564
3565 case MSM_BACKEND_DAI_TERT_AUXPCM_TX:
3566 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3567 aux_pcm_tx_cfg[TERT_AUX_PCM].bit_format);
3568 rate->min = rate->max =
3569 aux_pcm_tx_cfg[TERT_AUX_PCM].sample_rate;
3570 channels->min = channels->max =
3571 aux_pcm_tx_cfg[TERT_AUX_PCM].channels;
3572 break;
3573
3574 case MSM_BACKEND_DAI_PRI_MI2S_RX:
3575 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3576 mi2s_rx_cfg[PRIM_MI2S].bit_format);
3577 rate->min = rate->max = mi2s_rx_cfg[PRIM_MI2S].sample_rate;
3578 channels->min = channels->max =
3579 mi2s_rx_cfg[PRIM_MI2S].channels;
3580 break;
3581
3582 case MSM_BACKEND_DAI_PRI_MI2S_TX:
3583 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3584 mi2s_tx_cfg[PRIM_MI2S].bit_format);
3585 rate->min = rate->max = mi2s_tx_cfg[PRIM_MI2S].sample_rate;
3586 channels->min = channels->max =
3587 mi2s_tx_cfg[PRIM_MI2S].channels;
3588 break;
3589
3590 case MSM_BACKEND_DAI_SECONDARY_MI2S_RX:
3591 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3592 mi2s_rx_cfg[SEC_MI2S].bit_format);
3593 rate->min = rate->max = mi2s_rx_cfg[SEC_MI2S].sample_rate;
3594 channels->min = channels->max =
3595 mi2s_rx_cfg[SEC_MI2S].channels;
3596 break;
3597
3598 case MSM_BACKEND_DAI_SECONDARY_MI2S_TX:
3599 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3600 mi2s_tx_cfg[SEC_MI2S].bit_format);
3601 rate->min = rate->max = mi2s_tx_cfg[SEC_MI2S].sample_rate;
3602 channels->min = channels->max =
3603 mi2s_tx_cfg[SEC_MI2S].channels;
3604 break;
3605
3606 case MSM_BACKEND_DAI_TERTIARY_MI2S_RX:
3607 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3608 mi2s_rx_cfg[TERT_MI2S].bit_format);
3609 rate->min = rate->max = mi2s_rx_cfg[TERT_MI2S].sample_rate;
3610 channels->min = channels->max =
3611 mi2s_rx_cfg[TERT_MI2S].channels;
3612 break;
3613
3614 case MSM_BACKEND_DAI_TERTIARY_MI2S_TX:
3615 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3616 mi2s_tx_cfg[TERT_MI2S].bit_format);
3617 rate->min = rate->max = mi2s_tx_cfg[TERT_MI2S].sample_rate;
3618 channels->min = channels->max =
3619 mi2s_tx_cfg[TERT_MI2S].channels;
3620 break;
3621
Meng Wang574f4942019-02-18 12:59:41 +08003622 case MSM_BACKEND_DAI_WSA_CDC_DMA_RX_0:
3623 case MSM_BACKEND_DAI_WSA_CDC_DMA_RX_1:
3624 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_0:
3625 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_1:
3626 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_2:
3627 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_3:
3628 idx = msm_cdc_dma_get_idx_from_beid(dai_link->id);
3629 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3630 cdc_dma_rx_cfg[idx].bit_format);
3631 rate->min = rate->max = cdc_dma_rx_cfg[idx].sample_rate;
3632 channels->min = channels->max = cdc_dma_rx_cfg[idx].channels;
3633 break;
3634
3635 case MSM_BACKEND_DAI_WSA_CDC_DMA_TX_1:
3636 case MSM_BACKEND_DAI_WSA_CDC_DMA_TX_2:
3637 case MSM_BACKEND_DAI_TX_CDC_DMA_TX_0:
3638 case MSM_BACKEND_DAI_TX_CDC_DMA_TX_3:
3639 case MSM_BACKEND_DAI_TX_CDC_DMA_TX_4:
Xiaoyu Ye2228bf02018-12-12 15:47:20 -08003640 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_0:
3641 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_1:
3642 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_2:
3643 idx = msm_cdc_dma_get_idx_from_beid(dai_link->id);
3644 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
Meng Wang574f4942019-02-18 12:59:41 +08003645 cdc_dma_tx_cfg[idx].bit_format);
Xiaoyu Ye2228bf02018-12-12 15:47:20 -08003646 rate->min = rate->max = cdc_dma_tx_cfg[idx].sample_rate;
3647 channels->min = channels->max = cdc_dma_tx_cfg[idx].channels;
3648 break;
3649
Meng Wang574f4942019-02-18 12:59:41 +08003650 case MSM_BACKEND_DAI_WSA_CDC_DMA_TX_0:
3651 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3652 SNDRV_PCM_FORMAT_S32_LE);
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07003653 rate->min = rate->max = SAMPLING_RATE_8KHZ;
Meng Wang574f4942019-02-18 12:59:41 +08003654 channels->min = channels->max = msm_vi_feed_tx_ch;
3655 break;
3656
Banajit Goswami83a370d2019-03-05 16:15:21 -08003657 case MSM_BACKEND_DAI_SLIMBUS_7_RX:
3658 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3659 slim_rx_cfg[SLIM_RX_7].bit_format);
3660 rate->min = rate->max = slim_rx_cfg[SLIM_RX_7].sample_rate;
3661 channels->min = channels->max =
3662 slim_rx_cfg[SLIM_RX_7].channels;
3663 break;
3664
3665 case MSM_BACKEND_DAI_SLIMBUS_7_TX:
3666 rate->min = rate->max = slim_tx_cfg[SLIM_TX_7].sample_rate;
3667 channels->min = channels->max =
3668 slim_tx_cfg[SLIM_TX_7].channels;
3669 break;
3670
Vatsal Bucha82b30ba2019-04-17 12:43:54 +05303671 case MSM_BACKEND_DAI_SLIMBUS_8_TX:
3672 rate->min = rate->max = slim_tx_cfg[SLIM_TX_8].sample_rate;
3673 channels->min = channels->max =
3674 slim_tx_cfg[SLIM_TX_8].channels;
3675 break;
3676
Meng Wange8e53822019-03-18 10:49:50 +08003677 case MSM_BACKEND_DAI_AFE_LOOPBACK_TX:
3678 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
3679 afe_loopback_tx_cfg[idx].bit_format);
3680 rate->min = rate->max = afe_loopback_tx_cfg[idx].sample_rate;
3681 channels->min = channels->max =
3682 afe_loopback_tx_cfg[idx].channels;
3683 break;
3684
Meng Wang574f4942019-02-18 12:59:41 +08003685 default:
3686 rate->min = rate->max = SAMPLING_RATE_48KHZ;
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07003687 break;
3688 }
3689
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -08003690done:
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07003691 return rc;
3692}
3693
Karthikeyan Mani5eb13422018-11-05 13:49:17 -08003694static bool msm_usbc_swap_gnd_mic(struct snd_soc_component *component, bool active)
3695{
3696 struct snd_soc_card *card = component->card;
3697 struct msm_asoc_mach_data *pdata =
3698 snd_soc_card_get_drvdata(card);
3699
3700 if (!pdata->fsa_handle)
3701 return false;
3702
3703 return fsa4480_switch_event(pdata->fsa_handle, FSA_MIC_GND_SWAP);
3704}
3705
3706static bool msm_swap_gnd_mic(struct snd_soc_component *component, bool active)
3707{
3708 int value = 0;
3709 bool ret = false;
3710 struct snd_soc_card *card;
3711 struct msm_asoc_mach_data *pdata;
3712
3713 if (!component) {
3714 pr_err("%s component is NULL\n", __func__);
3715 return false;
3716 }
3717 card = component->card;
3718 pdata = snd_soc_card_get_drvdata(card);
3719
3720 if (!pdata)
3721 return false;
3722
3723 if (wcd_mbhc_cfg.enable_usbc_analog)
3724 return msm_usbc_swap_gnd_mic(component, active);
3725
3726 /* if usbc is not defined, swap using us_euro_gpio_p */
3727 if (pdata->us_euro_gpio_p) {
3728 value = msm_cdc_pinctrl_get_state(
3729 pdata->us_euro_gpio_p);
3730 if (value)
3731 msm_cdc_pinctrl_select_sleep_state(
3732 pdata->us_euro_gpio_p);
3733 else
3734 msm_cdc_pinctrl_select_active_state(
3735 pdata->us_euro_gpio_p);
3736 dev_dbg(component->dev, "%s: swap select switch %d to %d\n",
3737 __func__, value, !value);
3738 ret = true;
3739 }
3740
3741 return ret;
3742}
3743
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07003744static int kona_tdm_snd_hw_params(struct snd_pcm_substream *substream,
3745 struct snd_pcm_hw_params *params)
3746{
3747 struct snd_soc_pcm_runtime *rtd = substream->private_data;
3748 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
3749 int ret = 0;
3750 int slot_width = 32;
3751 int channels, slots;
3752 unsigned int slot_mask, rate, clk_freq;
3753 unsigned int slot_offset[8] = {0, 4, 8, 12, 16, 20, 24, 28};
3754
3755 pr_debug("%s: dai id = 0x%x\n", __func__, cpu_dai->id);
3756
3757 /* currently only supporting TDM_RX_0 and TDM_TX_0 */
3758 switch (cpu_dai->id) {
3759 case AFE_PORT_ID_PRIMARY_TDM_RX:
3760 slots = tdm_rx_cfg[TDM_PRI][TDM_0].channels;
3761 break;
3762 case AFE_PORT_ID_SECONDARY_TDM_RX:
3763 slots = tdm_rx_cfg[TDM_SEC][TDM_0].channels;
3764 break;
3765 case AFE_PORT_ID_TERTIARY_TDM_RX:
3766 slots = tdm_rx_cfg[TDM_TERT][TDM_0].channels;
3767 break;
3768 case AFE_PORT_ID_PRIMARY_TDM_TX:
3769 slots = tdm_tx_cfg[TDM_PRI][TDM_0].channels;
3770 break;
3771 case AFE_PORT_ID_SECONDARY_TDM_TX:
3772 slots = tdm_tx_cfg[TDM_SEC][TDM_0].channels;
3773 break;
3774 case AFE_PORT_ID_TERTIARY_TDM_TX:
3775 slots = tdm_tx_cfg[TDM_TERT][TDM_0].channels;
3776 break;
3777
3778 default:
3779 pr_err("%s: dai id 0x%x not supported\n",
3780 __func__, cpu_dai->id);
3781 return -EINVAL;
3782 }
3783
3784 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
3785 /*2 slot config - bits 0 and 1 set for the first two slots */
3786 slot_mask = 0x0000FFFF >> (16 - slots);
3787 channels = slots;
3788
3789 pr_debug("%s: tdm rx slot_width %d slots %d\n",
3790 __func__, slot_width, slots);
3791
3792 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0, slot_mask,
3793 slots, slot_width);
3794 if (ret < 0) {
3795 pr_err("%s: failed to set tdm rx slot, err:%d\n",
3796 __func__, ret);
3797 goto end;
3798 }
3799
3800 ret = snd_soc_dai_set_channel_map(cpu_dai,
3801 0, NULL, channels, slot_offset);
3802 if (ret < 0) {
3803 pr_err("%s: failed to set tdm rx channel map, err:%d\n",
3804 __func__, ret);
3805 goto end;
3806 }
3807 } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
3808 /*2 slot config - bits 0 and 1 set for the first two slots */
3809 slot_mask = 0x0000FFFF >> (16 - slots);
3810 channels = slots;
3811
3812 pr_debug("%s: tdm tx slot_width %d slots %d\n",
3813 __func__, slot_width, slots);
3814
3815 ret = snd_soc_dai_set_tdm_slot(cpu_dai, slot_mask, 0,
3816 slots, slot_width);
3817 if (ret < 0) {
3818 pr_err("%s: failed to set tdm tx slot, err:%d\n",
3819 __func__, ret);
3820 goto end;
3821 }
3822
3823 ret = snd_soc_dai_set_channel_map(cpu_dai,
3824 channels, slot_offset, 0, NULL);
3825 if (ret < 0) {
3826 pr_err("%s: failed to set tdm tx channel map, err:%d\n",
3827 __func__, ret);
3828 goto end;
3829 }
3830 } else {
3831 ret = -EINVAL;
3832 pr_err("%s: invalid use case, err:%d\n",
3833 __func__, ret);
3834 goto end;
3835 }
3836
3837 rate = params_rate(params);
3838 clk_freq = rate * slot_width * slots;
3839 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, clk_freq, SND_SOC_CLOCK_OUT);
3840 if (ret < 0)
3841 pr_err("%s: failed to set tdm clk, err:%d\n",
3842 __func__, ret);
3843
3844end:
3845 return ret;
3846}
3847
Xiaoyu Yeffbdc9f2019-05-17 15:02:39 -07003848static int msm_snd_cdc_dma_startup(struct snd_pcm_substream *substream)
3849{
3850 int ret = 0;
3851 struct snd_soc_pcm_runtime *rtd = substream->private_data;
3852 struct snd_soc_dai_link *dai_link = rtd->dai_link;
3853
3854 switch (dai_link->id) {
3855 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_0:
3856 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_1:
3857 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_2:
3858 ret = kona_send_island_va_config(dai_link->id);
3859 if (ret)
3860 pr_err("%s: send island va cfg failed, err: %d\n",
3861 __func__, ret);
3862 break;
3863 }
3864
3865 return ret;
3866}
3867
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07003868static int msm_snd_cdc_dma_hw_params(struct snd_pcm_substream *substream,
3869 struct snd_pcm_hw_params *params)
3870{
3871 struct snd_soc_pcm_runtime *rtd = substream->private_data;
3872 struct snd_soc_dai *codec_dai = rtd->codec_dai;
3873 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
3874 struct snd_soc_dai_link *dai_link = rtd->dai_link;
3875
3876 int ret = 0;
3877 u32 rx_ch_cdc_dma, tx_ch_cdc_dma;
3878 u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
3879 u32 user_set_tx_ch = 0;
3880 u32 user_set_rx_ch = 0;
3881 u32 ch_id;
3882
3883 ret = snd_soc_dai_get_channel_map(codec_dai,
3884 &tx_ch_cnt, &tx_ch_cdc_dma, &rx_ch_cnt,
3885 &rx_ch_cdc_dma);
3886 if (ret < 0) {
3887 pr_err("%s: failed to get codec chan map, err:%d\n",
3888 __func__, ret);
3889 goto err;
3890 }
3891
3892 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
3893 switch (dai_link->id) {
3894 case MSM_BACKEND_DAI_WSA_CDC_DMA_RX_0:
3895 case MSM_BACKEND_DAI_WSA_CDC_DMA_RX_1:
3896 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_0:
3897 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_1:
3898 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_2:
3899 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_3:
3900 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_4:
3901 case MSM_BACKEND_DAI_RX_CDC_DMA_RX_5:
3902 {
3903 ch_id = msm_cdc_dma_get_idx_from_beid(dai_link->id);
3904 pr_debug("%s: id %d rx_ch=%d\n", __func__,
3905 ch_id, cdc_dma_rx_cfg[ch_id].channels);
3906 user_set_rx_ch = cdc_dma_rx_cfg[ch_id].channels;
3907 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
3908 user_set_rx_ch, &rx_ch_cdc_dma);
3909 if (ret < 0) {
3910 pr_err("%s: failed to set cpu chan map, err:%d\n",
3911 __func__, ret);
3912 goto err;
3913 }
3914
3915 }
3916 break;
3917 }
3918 } else {
3919 switch (dai_link->id) {
3920 case MSM_BACKEND_DAI_WSA_CDC_DMA_TX_0:
3921 {
3922 user_set_tx_ch = msm_vi_feed_tx_ch;
3923 }
3924 break;
3925 case MSM_BACKEND_DAI_WSA_CDC_DMA_TX_1:
3926 case MSM_BACKEND_DAI_WSA_CDC_DMA_TX_2:
3927 case MSM_BACKEND_DAI_TX_CDC_DMA_TX_0:
3928 case MSM_BACKEND_DAI_TX_CDC_DMA_TX_3:
3929 case MSM_BACKEND_DAI_TX_CDC_DMA_TX_4:
Xiaoyu Ye2228bf02018-12-12 15:47:20 -08003930 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_0:
3931 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_1:
3932 case MSM_BACKEND_DAI_VA_CDC_DMA_TX_2:
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07003933 {
3934 ch_id = msm_cdc_dma_get_idx_from_beid(dai_link->id);
3935 pr_debug("%s: id %d tx_ch=%d\n", __func__,
3936 ch_id, cdc_dma_tx_cfg[ch_id].channels);
3937 user_set_tx_ch = cdc_dma_tx_cfg[ch_id].channels;
3938 }
3939 break;
3940 }
3941
3942 ret = snd_soc_dai_set_channel_map(cpu_dai, user_set_tx_ch,
3943 &tx_ch_cdc_dma, 0, 0);
3944 if (ret < 0) {
3945 pr_err("%s: failed to set cpu chan map, err:%d\n",
3946 __func__, ret);
3947 goto err;
3948 }
3949 }
3950
3951err:
3952 return ret;
3953}
3954
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07003955static int msm_fe_qos_prepare(struct snd_pcm_substream *substream)
3956{
3957 cpumask_t mask;
3958
3959 if (pm_qos_request_active(&substream->latency_pm_qos_req))
3960 pm_qos_remove_request(&substream->latency_pm_qos_req);
3961
3962 cpumask_clear(&mask);
3963 cpumask_set_cpu(1, &mask); /* affine to core 1 */
3964 cpumask_set_cpu(2, &mask); /* affine to core 2 */
3965 cpumask_copy(&substream->latency_pm_qos_req.cpus_affine, &mask);
3966
3967 substream->latency_pm_qos_req.type = PM_QOS_REQ_AFFINE_CORES;
3968
3969 pm_qos_add_request(&substream->latency_pm_qos_req,
3970 PM_QOS_CPU_DMA_LATENCY,
3971 MSM_LL_QOS_VALUE);
3972 return 0;
3973}
3974
3975static int msm_mi2s_snd_startup(struct snd_pcm_substream *substream)
3976{
3977 int ret = 0;
3978 struct snd_soc_pcm_runtime *rtd = substream->private_data;
3979 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
3980 int index = cpu_dai->id;
3981 unsigned int fmt = SND_SOC_DAIFMT_CBS_CFS;
3982
3983 dev_dbg(rtd->card->dev,
3984 "%s: substream = %s stream = %d, dai name %s, dai ID %d\n",
3985 __func__, substream->name, substream->stream,
3986 cpu_dai->name, cpu_dai->id);
3987
3988 if (index < PRIM_MI2S || index >= MI2S_MAX) {
3989 ret = -EINVAL;
3990 dev_err(rtd->card->dev,
3991 "%s: CPU DAI id (%d) out of range\n",
3992 __func__, cpu_dai->id);
3993 goto err;
3994 }
3995 /*
3996 * Mutex protection in case the same MI2S
3997 * interface using for both TX and RX so
3998 * that the same clock won't be enable twice.
3999 */
4000 mutex_lock(&mi2s_intf_conf[index].lock);
4001 if (++mi2s_intf_conf[index].ref_cnt == 1) {
4002 /* Check if msm needs to provide the clock to the interface */
4003 if (!mi2s_intf_conf[index].msm_is_mi2s_master) {
4004 mi2s_clk[index].clk_id = mi2s_ebit_clk[index];
4005 fmt = SND_SOC_DAIFMT_CBM_CFM;
4006 }
4007 ret = msm_mi2s_set_sclk(substream, true);
4008 if (ret < 0) {
4009 dev_err(rtd->card->dev,
4010 "%s: afe lpass clock failed to enable MI2S clock, err:%d\n",
4011 __func__, ret);
4012 goto clean_up;
4013 }
4014
4015 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
4016 if (ret < 0) {
4017 pr_err("%s: set fmt cpu dai failed for MI2S (%d), err:%d\n",
4018 __func__, index, ret);
4019 goto clk_off;
4020 }
4021 }
4022clk_off:
4023 if (ret < 0)
4024 msm_mi2s_set_sclk(substream, false);
4025clean_up:
4026 if (ret < 0)
4027 mi2s_intf_conf[index].ref_cnt--;
4028 mutex_unlock(&mi2s_intf_conf[index].lock);
4029err:
4030 return ret;
4031}
4032
4033static void msm_mi2s_snd_shutdown(struct snd_pcm_substream *substream)
4034{
4035 int ret = 0;
4036 struct snd_soc_pcm_runtime *rtd = substream->private_data;
4037 int index = rtd->cpu_dai->id;
4038
4039 pr_debug("%s(): substream = %s stream = %d\n", __func__,
4040 substream->name, substream->stream);
4041 if (index < PRIM_MI2S || index >= MI2S_MAX) {
4042 pr_err("%s:invalid MI2S DAI(%d)\n", __func__, index);
4043 return;
4044 }
4045
4046 mutex_lock(&mi2s_intf_conf[index].lock);
4047 if (--mi2s_intf_conf[index].ref_cnt == 0) {
4048 ret = msm_mi2s_set_sclk(substream, false);
4049 if (ret < 0)
4050 pr_err("%s:clock disable failed for MI2S (%d); ret=%d\n",
4051 __func__, index, ret);
4052 }
4053 mutex_unlock(&mi2s_intf_conf[index].lock);
4054}
4055
Vatsal Bucha82b30ba2019-04-17 12:43:54 +05304056static int msm_wcn_hw_params_lito(struct snd_pcm_substream *substream,
4057 struct snd_pcm_hw_params *params)
4058{
4059 struct snd_soc_pcm_runtime *rtd = substream->private_data;
4060 struct snd_soc_dai *codec_dai = rtd->codec_dai;
4061 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
4062 struct snd_soc_dai_link *dai_link = rtd->dai_link;
4063 u32 rx_ch[WCN_CDC_SLIM_RX_CH_MAX], tx_ch[WCN_CDC_SLIM_TX_CH_MAX_LITO];
4064 u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
4065 int ret = 0;
4066
4067 dev_dbg(rtd->dev, "%s: %s_tx_dai_id_%d\n", __func__,
4068 codec_dai->name, codec_dai->id);
4069 ret = snd_soc_dai_get_channel_map(codec_dai,
4070 &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
4071 if (ret) {
4072 dev_err(rtd->dev,
4073 "%s: failed to get BTFM codec chan map\n, err:%d\n",
4074 __func__, ret);
4075 goto err;
4076 }
4077
4078 dev_dbg(rtd->dev, "%s: tx_ch_cnt(%d) BE id %d\n",
4079 __func__, tx_ch_cnt, dai_link->id);
4080
4081 ret = snd_soc_dai_set_channel_map(cpu_dai,
4082 tx_ch_cnt, tx_ch, rx_ch_cnt, rx_ch);
4083 if (ret)
4084 dev_err(rtd->dev, "%s: failed to set cpu chan map, err:%d\n",
4085 __func__, ret);
4086
4087err:
4088 return ret;
4089}
4090
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -08004091static int msm_wcn_hw_params(struct snd_pcm_substream *substream,
4092 struct snd_pcm_hw_params *params)
4093{
4094 struct snd_soc_pcm_runtime *rtd = substream->private_data;
4095 struct snd_soc_dai *codec_dai = rtd->codec_dai;
4096 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
4097 struct snd_soc_dai_link *dai_link = rtd->dai_link;
4098 u32 rx_ch[WCN_CDC_SLIM_RX_CH_MAX], tx_ch[WCN_CDC_SLIM_TX_CH_MAX];
4099 u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
4100 int ret = 0;
4101
4102 dev_dbg(rtd->dev, "%s: %s_tx_dai_id_%d\n", __func__,
4103 codec_dai->name, codec_dai->id);
4104 ret = snd_soc_dai_get_channel_map(codec_dai,
4105 &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
4106 if (ret) {
4107 dev_err(rtd->dev,
4108 "%s: failed to get BTFM codec chan map\n, err:%d\n",
4109 __func__, ret);
4110 goto err;
4111 }
4112
4113 dev_dbg(rtd->dev, "%s: tx_ch_cnt(%d) BE id %d\n",
4114 __func__, tx_ch_cnt, dai_link->id);
4115
4116 ret = snd_soc_dai_set_channel_map(cpu_dai,
4117 tx_ch_cnt, tx_ch, rx_ch_cnt, rx_ch);
4118 if (ret)
4119 dev_err(rtd->dev, "%s: failed to set cpu chan map, err:%d\n",
4120 __func__, ret);
4121
4122err:
4123 return ret;
4124}
4125
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07004126static struct snd_soc_ops kona_tdm_be_ops = {
4127 .hw_params = kona_tdm_snd_hw_params,
4128};
4129
4130static struct snd_soc_ops msm_mi2s_be_ops = {
4131 .startup = msm_mi2s_snd_startup,
4132 .shutdown = msm_mi2s_snd_shutdown,
4133};
4134
4135static struct snd_soc_ops msm_fe_qos_ops = {
4136 .prepare = msm_fe_qos_prepare,
4137};
4138
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07004139static struct snd_soc_ops msm_cdc_dma_be_ops = {
Xiaoyu Yeffbdc9f2019-05-17 15:02:39 -07004140 .startup = msm_snd_cdc_dma_startup,
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07004141 .hw_params = msm_snd_cdc_dma_hw_params,
4142};
4143
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -08004144static struct snd_soc_ops msm_wcn_ops = {
4145 .hw_params = msm_wcn_hw_params,
4146};
4147
Vatsal Bucha82b30ba2019-04-17 12:43:54 +05304148static struct snd_soc_ops msm_wcn_ops_lito = {
4149 .hw_params = msm_wcn_hw_params_lito,
4150};
4151
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07004152static int msm_dmic_event(struct snd_soc_dapm_widget *w,
4153 struct snd_kcontrol *kcontrol, int event)
4154{
4155 struct msm_asoc_mach_data *pdata = NULL;
4156 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
4157 int ret = 0;
4158 u32 dmic_idx;
4159 int *dmic_gpio_cnt;
4160 struct device_node *dmic_gpio;
4161 char *wname;
4162
4163 wname = strpbrk(w->name, "012345");
4164 if (!wname) {
4165 dev_err(component->dev, "%s: widget not found\n", __func__);
4166 return -EINVAL;
4167 }
4168
4169 ret = kstrtouint(wname, 10, &dmic_idx);
4170 if (ret < 0) {
4171 dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
4172 __func__);
4173 return -EINVAL;
4174 }
4175
4176 pdata = snd_soc_card_get_drvdata(component->card);
4177
4178 switch (dmic_idx) {
4179 case 0:
4180 case 1:
4181 dmic_gpio_cnt = &dmic_0_1_gpio_cnt;
4182 dmic_gpio = pdata->dmic01_gpio_p;
4183 break;
4184 case 2:
4185 case 3:
4186 dmic_gpio_cnt = &dmic_2_3_gpio_cnt;
4187 dmic_gpio = pdata->dmic23_gpio_p;
4188 break;
4189 case 4:
4190 case 5:
4191 dmic_gpio_cnt = &dmic_4_5_gpio_cnt;
4192 dmic_gpio = pdata->dmic45_gpio_p;
4193 break;
4194 default:
4195 dev_err(component->dev, "%s: Invalid DMIC Selection\n",
4196 __func__);
4197 return -EINVAL;
4198 }
4199
4200 dev_dbg(component->dev, "%s: event %d DMIC%d dmic_gpio_cnt %d\n",
4201 __func__, event, dmic_idx, *dmic_gpio_cnt);
4202
4203 switch (event) {
4204 case SND_SOC_DAPM_PRE_PMU:
4205 (*dmic_gpio_cnt)++;
4206 if (*dmic_gpio_cnt == 1) {
4207 ret = msm_cdc_pinctrl_select_active_state(
4208 dmic_gpio);
4209 if (ret < 0) {
4210 pr_err("%s: gpio set cannot be activated %sd",
4211 __func__, "dmic_gpio");
4212 return ret;
4213 }
4214 }
4215
4216 break;
4217 case SND_SOC_DAPM_POST_PMD:
4218 (*dmic_gpio_cnt)--;
4219 if (*dmic_gpio_cnt == 0) {
4220 ret = msm_cdc_pinctrl_select_sleep_state(
4221 dmic_gpio);
4222 if (ret < 0) {
4223 pr_err("%s: gpio set cannot be de-activated %sd",
4224 __func__, "dmic_gpio");
4225 return ret;
4226 }
4227 }
4228 break;
4229 default:
4230 pr_err("%s: invalid DAPM event %d\n", __func__, event);
4231 return -EINVAL;
4232 }
4233 return 0;
4234}
4235
4236static const struct snd_soc_dapm_widget msm_int_dapm_widgets[] = {
4237 SND_SOC_DAPM_MIC("Analog Mic1", NULL),
4238 SND_SOC_DAPM_MIC("Analog Mic2", NULL),
4239 SND_SOC_DAPM_MIC("Analog Mic3", NULL),
4240 SND_SOC_DAPM_MIC("Analog Mic4", NULL),
Karthikeyan Mani1a111b92019-02-12 21:35:31 -08004241 SND_SOC_DAPM_MIC("Analog Mic5", NULL),
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07004242 SND_SOC_DAPM_MIC("Digital Mic0", msm_dmic_event),
4243 SND_SOC_DAPM_MIC("Digital Mic1", msm_dmic_event),
4244 SND_SOC_DAPM_MIC("Digital Mic2", msm_dmic_event),
4245 SND_SOC_DAPM_MIC("Digital Mic3", msm_dmic_event),
4246 SND_SOC_DAPM_MIC("Digital Mic4", msm_dmic_event),
4247 SND_SOC_DAPM_MIC("Digital Mic5", msm_dmic_event),
4248};
4249
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -08004250static int msm_wcn_init(struct snd_soc_pcm_runtime *rtd)
4251{
4252 unsigned int rx_ch[WCN_CDC_SLIM_RX_CH_MAX] = {157, 158};
4253 unsigned int tx_ch[WCN_CDC_SLIM_TX_CH_MAX] = {159, 160};
4254 struct snd_soc_dai *codec_dai = rtd->codec_dai;
4255
4256 return snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
4257 tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
4258}
4259
Vatsal Bucha82b30ba2019-04-17 12:43:54 +05304260static int msm_wcn_init_lito(struct snd_soc_pcm_runtime *rtd)
4261{
4262 unsigned int rx_ch[WCN_CDC_SLIM_RX_CH_MAX] = {157, 158};
4263 unsigned int tx_ch[WCN_CDC_SLIM_TX_CH_MAX_LITO] = {159, 160, 161};
4264 struct snd_soc_dai *codec_dai = rtd->codec_dai;
4265
4266 return snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
4267 tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
4268}
4269
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07004270static int msm_int_audrx_init(struct snd_soc_pcm_runtime *rtd)
4271{
4272 int ret = -EINVAL;
4273 struct snd_soc_component *component;
4274 struct snd_soc_dapm_context *dapm;
4275 struct snd_card *card;
4276 struct snd_info_entry *entry;
4277 struct snd_soc_component *aux_comp;
4278 struct msm_asoc_mach_data *pdata =
4279 snd_soc_card_get_drvdata(rtd->card);
4280
4281 component = snd_soc_rtdcom_lookup(rtd, "bolero_codec");
4282 if (!component) {
4283 pr_err("%s: could not find component for bolero_codec\n",
4284 __func__);
4285 return ret;
4286 }
4287
4288 dapm = snd_soc_component_get_dapm(component);
4289
4290 ret = snd_soc_add_component_controls(component, msm_int_snd_controls,
4291 ARRAY_SIZE(msm_int_snd_controls));
4292 if (ret < 0) {
4293 pr_err("%s: add_component_controls failed: %d\n",
4294 __func__, ret);
4295 return ret;
4296 }
4297 ret = snd_soc_add_component_controls(component, msm_common_snd_controls,
4298 ARRAY_SIZE(msm_common_snd_controls));
4299 if (ret < 0) {
4300 pr_err("%s: add common snd controls failed: %d\n",
4301 __func__, ret);
4302 return ret;
4303 }
4304
4305 snd_soc_dapm_new_controls(dapm, msm_int_dapm_widgets,
4306 ARRAY_SIZE(msm_int_dapm_widgets));
4307
4308 snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
4309 snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
4310 snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
4311 snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
Sudheer Papothi3fc2d772019-05-11 14:11:29 +05304312 snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
4313 snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07004314
4315 snd_soc_dapm_ignore_suspend(dapm, "Analog Mic1");
4316 snd_soc_dapm_ignore_suspend(dapm, "Analog Mic2");
4317 snd_soc_dapm_ignore_suspend(dapm, "Analog Mic3");
4318 snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
Karthikeyan Mani1a111b92019-02-12 21:35:31 -08004319 snd_soc_dapm_ignore_suspend(dapm, "Analog Mic5");
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07004320
4321 snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK1 OUT");
4322 snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK2 OUT");
4323 snd_soc_dapm_ignore_suspend(dapm, "WSA AIF VI");
4324 snd_soc_dapm_ignore_suspend(dapm, "VIINPUT_WSA");
4325
4326 snd_soc_dapm_sync(dapm);
4327
4328 /*
4329 * Send speaker configuration only for WSA8810.
4330 * Default configuration is for WSA8815.
4331 */
4332 dev_dbg(component->dev, "%s: Number of aux devices: %d\n",
4333 __func__, rtd->card->num_aux_devs);
4334 if (rtd->card->num_aux_devs &&
4335 !list_empty(&rtd->card->component_dev_list)) {
4336 aux_comp = list_first_entry(
4337 &rtd->card->component_dev_list,
4338 struct snd_soc_component,
4339 card_aux_list);
4340 if (!strcmp(aux_comp->name, WSA8810_NAME_1) ||
4341 !strcmp(aux_comp->name, WSA8810_NAME_2)) {
4342 wsa_macro_set_spkr_mode(component,
4343 WSA_MACRO_SPKR_MODE_1);
4344 wsa_macro_set_spkr_gain_offset(component,
4345 WSA_MACRO_GAIN_OFFSET_M1P5_DB);
4346 }
Karthikeyan Mani7eef68e2018-12-13 17:45:02 -08004347 bolero_set_port_map(component, ARRAY_SIZE(sm_port_map),
4348 sm_port_map);
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07004349 }
4350 card = rtd->card->snd_card;
4351 if (!pdata->codec_root) {
4352 entry = snd_info_create_subdir(card->module, "codecs",
4353 card->proc_root);
4354 if (!entry) {
4355 pr_debug("%s: Cannot create codecs module entry\n",
4356 __func__);
4357 ret = 0;
4358 goto err;
4359 }
4360 pdata->codec_root = entry;
4361 }
4362 bolero_info_create_codec_entry(pdata->codec_root, component);
Karthikeyan Mani664bd4a2019-02-21 13:30:34 -08004363 bolero_register_wake_irq(component, false);
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07004364 codec_reg_done = true;
4365 return 0;
4366err:
4367 return ret;
4368}
4369
Karthikeyan Mani5eb13422018-11-05 13:49:17 -08004370static void *def_wcd_mbhc_cal(void)
4371{
4372 void *wcd_mbhc_cal;
4373 struct wcd_mbhc_btn_detect_cfg *btn_cfg;
4374 u16 *btn_high;
4375
4376 wcd_mbhc_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS,
4377 WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL);
4378 if (!wcd_mbhc_cal)
4379 return NULL;
4380
4381 WCD_MBHC_CAL_PLUG_TYPE_PTR(wcd_mbhc_cal)->v_hs_max = WCD_MBHC_HS_V_MAX;
4382 WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal)->num_btn = WCD_MBHC_DEF_BUTTONS;
4383 btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal);
4384 btn_high = ((void *)&btn_cfg->_v_btn_low) +
4385 (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn);
4386
4387 btn_high[0] = 75;
4388 btn_high[1] = 150;
4389 btn_high[2] = 237;
4390 btn_high[3] = 500;
4391 btn_high[4] = 500;
4392 btn_high[5] = 500;
4393 btn_high[6] = 500;
4394 btn_high[7] = 500;
4395
4396 return wcd_mbhc_cal;
4397}
4398
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07004399/* Digital audio interface glue - connects codec <---> CPU */
4400static struct snd_soc_dai_link msm_common_dai_links[] = {
4401 /* FrontEnd DAI Links */
4402 {/* hw:x,0 */
4403 .name = MSM_DAILINK_NAME(Media1),
4404 .stream_name = "MultiMedia1",
4405 .cpu_dai_name = "MultiMedia1",
4406 .platform_name = "msm-pcm-dsp.0",
4407 .dynamic = 1,
4408 .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
4409 .dpcm_playback = 1,
4410 .dpcm_capture = 1,
4411 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4412 SND_SOC_DPCM_TRIGGER_POST},
4413 .codec_dai_name = "snd-soc-dummy-dai",
4414 .codec_name = "snd-soc-dummy",
4415 .ignore_suspend = 1,
4416 /* this dainlink has playback support */
4417 .ignore_pmdown_time = 1,
4418 .id = MSM_FRONTEND_DAI_MULTIMEDIA1
4419 },
4420 {/* hw:x,1 */
4421 .name = MSM_DAILINK_NAME(Media2),
4422 .stream_name = "MultiMedia2",
4423 .cpu_dai_name = "MultiMedia2",
4424 .platform_name = "msm-pcm-dsp.0",
4425 .dynamic = 1,
4426 .dpcm_playback = 1,
4427 .dpcm_capture = 1,
4428 .codec_dai_name = "snd-soc-dummy-dai",
4429 .codec_name = "snd-soc-dummy",
4430 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4431 SND_SOC_DPCM_TRIGGER_POST},
4432 .ignore_suspend = 1,
4433 /* this dainlink has playback support */
4434 .ignore_pmdown_time = 1,
4435 .id = MSM_FRONTEND_DAI_MULTIMEDIA2,
4436 },
4437 {/* hw:x,2 */
4438 .name = "VoiceMMode1",
4439 .stream_name = "VoiceMMode1",
4440 .cpu_dai_name = "VoiceMMode1",
4441 .platform_name = "msm-pcm-voice",
4442 .dynamic = 1,
4443 .dpcm_playback = 1,
4444 .dpcm_capture = 1,
4445 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4446 SND_SOC_DPCM_TRIGGER_POST},
4447 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4448 .ignore_suspend = 1,
4449 .ignore_pmdown_time = 1,
4450 .codec_dai_name = "snd-soc-dummy-dai",
4451 .codec_name = "snd-soc-dummy",
4452 .id = MSM_FRONTEND_DAI_VOICEMMODE1,
4453 },
4454 {/* hw:x,3 */
4455 .name = "MSM VoIP",
4456 .stream_name = "VoIP",
4457 .cpu_dai_name = "VoIP",
4458 .platform_name = "msm-voip-dsp",
4459 .dynamic = 1,
4460 .dpcm_playback = 1,
4461 .dpcm_capture = 1,
4462 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4463 SND_SOC_DPCM_TRIGGER_POST},
4464 .codec_dai_name = "snd-soc-dummy-dai",
4465 .codec_name = "snd-soc-dummy",
4466 .ignore_suspend = 1,
4467 /* this dainlink has playback support */
4468 .ignore_pmdown_time = 1,
4469 .id = MSM_FRONTEND_DAI_VOIP,
4470 },
4471 {/* hw:x,4 */
4472 .name = MSM_DAILINK_NAME(ULL),
4473 .stream_name = "MultiMedia3",
4474 .cpu_dai_name = "MultiMedia3",
4475 .platform_name = "msm-pcm-dsp.2",
4476 .dynamic = 1,
4477 .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
4478 .dpcm_playback = 1,
4479 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4480 SND_SOC_DPCM_TRIGGER_POST},
4481 .codec_dai_name = "snd-soc-dummy-dai",
4482 .codec_name = "snd-soc-dummy",
4483 .ignore_suspend = 1,
4484 /* this dainlink has playback support */
4485 .ignore_pmdown_time = 1,
4486 .id = MSM_FRONTEND_DAI_MULTIMEDIA3,
4487 },
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07004488 {/* hw:x,5 */
4489 .name = "MSM AFE-PCM RX",
4490 .stream_name = "AFE-PROXY RX",
4491 .cpu_dai_name = "msm-dai-q6-dev.241",
4492 .codec_name = "msm-stub-codec.1",
4493 .codec_dai_name = "msm-stub-rx",
4494 .platform_name = "msm-pcm-afe",
4495 .dpcm_playback = 1,
4496 .ignore_suspend = 1,
4497 /* this dainlink has playback support */
4498 .ignore_pmdown_time = 1,
4499 },
4500 {/* hw:x,6 */
4501 .name = "MSM AFE-PCM TX",
4502 .stream_name = "AFE-PROXY TX",
4503 .cpu_dai_name = "msm-dai-q6-dev.240",
4504 .codec_name = "msm-stub-codec.1",
4505 .codec_dai_name = "msm-stub-tx",
4506 .platform_name = "msm-pcm-afe",
4507 .dpcm_capture = 1,
4508 .ignore_suspend = 1,
4509 },
4510 {/* hw:x,7 */
4511 .name = MSM_DAILINK_NAME(Compress1),
4512 .stream_name = "Compress1",
4513 .cpu_dai_name = "MultiMedia4",
4514 .platform_name = "msm-compress-dsp",
4515 .dynamic = 1,
4516 .async_ops = ASYNC_DPCM_SND_SOC_HW_PARAMS,
4517 .dpcm_playback = 1,
4518 .dpcm_capture = 1,
4519 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4520 SND_SOC_DPCM_TRIGGER_POST},
4521 .codec_dai_name = "snd-soc-dummy-dai",
4522 .codec_name = "snd-soc-dummy",
4523 .ignore_suspend = 1,
4524 .ignore_pmdown_time = 1,
4525 /* this dainlink has playback support */
4526 .id = MSM_FRONTEND_DAI_MULTIMEDIA4,
4527 },
Meng Wang197cb302019-03-01 13:54:38 +08004528 /* Hostless PCM purpose */
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07004529 {/* hw:x,8 */
4530 .name = "AUXPCM Hostless",
4531 .stream_name = "AUXPCM Hostless",
4532 .cpu_dai_name = "AUXPCM_HOSTLESS",
4533 .platform_name = "msm-pcm-hostless",
4534 .dynamic = 1,
4535 .dpcm_playback = 1,
4536 .dpcm_capture = 1,
4537 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4538 SND_SOC_DPCM_TRIGGER_POST},
4539 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4540 .ignore_suspend = 1,
4541 /* this dainlink has playback support */
4542 .ignore_pmdown_time = 1,
4543 .codec_dai_name = "snd-soc-dummy-dai",
4544 .codec_name = "snd-soc-dummy",
4545 },
4546 {/* hw:x,9 */
4547 .name = MSM_DAILINK_NAME(LowLatency),
4548 .stream_name = "MultiMedia5",
4549 .cpu_dai_name = "MultiMedia5",
4550 .platform_name = "msm-pcm-dsp.1",
4551 .dynamic = 1,
4552 .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
4553 .dpcm_playback = 1,
4554 .dpcm_capture = 1,
4555 .codec_dai_name = "snd-soc-dummy-dai",
4556 .codec_name = "snd-soc-dummy",
4557 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4558 SND_SOC_DPCM_TRIGGER_POST},
4559 .ignore_suspend = 1,
4560 /* this dainlink has playback support */
4561 .ignore_pmdown_time = 1,
4562 .id = MSM_FRONTEND_DAI_MULTIMEDIA5,
4563 .ops = &msm_fe_qos_ops,
4564 },
4565 {/* hw:x,10 */
4566 .name = "Listen 1 Audio Service",
4567 .stream_name = "Listen 1 Audio Service",
4568 .cpu_dai_name = "LSM1",
4569 .platform_name = "msm-lsm-client",
4570 .dynamic = 1,
4571 .dpcm_capture = 1,
4572 .trigger = { SND_SOC_DPCM_TRIGGER_POST,
4573 SND_SOC_DPCM_TRIGGER_POST },
4574 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4575 .ignore_suspend = 1,
4576 .codec_dai_name = "snd-soc-dummy-dai",
4577 .codec_name = "snd-soc-dummy",
4578 .id = MSM_FRONTEND_DAI_LSM1,
4579 },
4580 /* Multiple Tunnel instances */
4581 {/* hw:x,11 */
4582 .name = MSM_DAILINK_NAME(Compress2),
4583 .stream_name = "Compress2",
4584 .cpu_dai_name = "MultiMedia7",
4585 .platform_name = "msm-compress-dsp",
4586 .dynamic = 1,
4587 .dpcm_playback = 1,
4588 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4589 SND_SOC_DPCM_TRIGGER_POST},
4590 .codec_dai_name = "snd-soc-dummy-dai",
4591 .codec_name = "snd-soc-dummy",
4592 .ignore_suspend = 1,
4593 .ignore_pmdown_time = 1,
4594 /* this dainlink has playback support */
4595 .id = MSM_FRONTEND_DAI_MULTIMEDIA7,
4596 },
4597 {/* hw:x,12 */
4598 .name = MSM_DAILINK_NAME(MultiMedia10),
4599 .stream_name = "MultiMedia10",
4600 .cpu_dai_name = "MultiMedia10",
4601 .platform_name = "msm-pcm-dsp.1",
4602 .dynamic = 1,
4603 .dpcm_playback = 1,
4604 .dpcm_capture = 1,
4605 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4606 SND_SOC_DPCM_TRIGGER_POST},
4607 .codec_dai_name = "snd-soc-dummy-dai",
4608 .codec_name = "snd-soc-dummy",
4609 .ignore_suspend = 1,
4610 .ignore_pmdown_time = 1,
4611 /* this dainlink has playback support */
4612 .id = MSM_FRONTEND_DAI_MULTIMEDIA10,
4613 },
4614 {/* hw:x,13 */
4615 .name = MSM_DAILINK_NAME(ULL_NOIRQ),
4616 .stream_name = "MM_NOIRQ",
4617 .cpu_dai_name = "MultiMedia8",
4618 .platform_name = "msm-pcm-dsp-noirq",
4619 .dynamic = 1,
4620 .dpcm_playback = 1,
4621 .dpcm_capture = 1,
4622 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4623 SND_SOC_DPCM_TRIGGER_POST},
4624 .codec_dai_name = "snd-soc-dummy-dai",
4625 .codec_name = "snd-soc-dummy",
4626 .ignore_suspend = 1,
4627 .ignore_pmdown_time = 1,
4628 /* this dainlink has playback support */
4629 .id = MSM_FRONTEND_DAI_MULTIMEDIA8,
4630 .ops = &msm_fe_qos_ops,
4631 },
4632 /* HDMI Hostless */
4633 {/* hw:x,14 */
4634 .name = "HDMI_RX_HOSTLESS",
4635 .stream_name = "HDMI_RX_HOSTLESS",
4636 .cpu_dai_name = "HDMI_HOSTLESS",
4637 .platform_name = "msm-pcm-hostless",
4638 .dynamic = 1,
4639 .dpcm_playback = 1,
4640 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4641 SND_SOC_DPCM_TRIGGER_POST},
4642 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4643 .ignore_suspend = 1,
4644 .ignore_pmdown_time = 1,
4645 .codec_dai_name = "snd-soc-dummy-dai",
4646 .codec_name = "snd-soc-dummy",
4647 },
4648 {/* hw:x,15 */
4649 .name = "VoiceMMode2",
4650 .stream_name = "VoiceMMode2",
4651 .cpu_dai_name = "VoiceMMode2",
4652 .platform_name = "msm-pcm-voice",
4653 .dynamic = 1,
4654 .dpcm_playback = 1,
4655 .dpcm_capture = 1,
4656 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4657 SND_SOC_DPCM_TRIGGER_POST},
4658 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4659 .ignore_suspend = 1,
4660 .ignore_pmdown_time = 1,
4661 .codec_dai_name = "snd-soc-dummy-dai",
4662 .codec_name = "snd-soc-dummy",
4663 .id = MSM_FRONTEND_DAI_VOICEMMODE2,
4664 },
4665 /* LSM FE */
4666 {/* hw:x,16 */
4667 .name = "Listen 2 Audio Service",
4668 .stream_name = "Listen 2 Audio Service",
4669 .cpu_dai_name = "LSM2",
4670 .platform_name = "msm-lsm-client",
4671 .dynamic = 1,
4672 .dpcm_capture = 1,
4673 .trigger = { SND_SOC_DPCM_TRIGGER_POST,
4674 SND_SOC_DPCM_TRIGGER_POST },
4675 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4676 .ignore_suspend = 1,
4677 .codec_dai_name = "snd-soc-dummy-dai",
4678 .codec_name = "snd-soc-dummy",
4679 .id = MSM_FRONTEND_DAI_LSM2,
4680 },
4681 {/* hw:x,17 */
4682 .name = "Listen 3 Audio Service",
4683 .stream_name = "Listen 3 Audio Service",
4684 .cpu_dai_name = "LSM3",
4685 .platform_name = "msm-lsm-client",
4686 .dynamic = 1,
4687 .dpcm_capture = 1,
4688 .trigger = { SND_SOC_DPCM_TRIGGER_POST,
4689 SND_SOC_DPCM_TRIGGER_POST },
4690 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4691 .ignore_suspend = 1,
4692 .codec_dai_name = "snd-soc-dummy-dai",
4693 .codec_name = "snd-soc-dummy",
4694 .id = MSM_FRONTEND_DAI_LSM3,
4695 },
4696 {/* hw:x,18 */
4697 .name = "Listen 4 Audio Service",
4698 .stream_name = "Listen 4 Audio Service",
4699 .cpu_dai_name = "LSM4",
4700 .platform_name = "msm-lsm-client",
4701 .dynamic = 1,
4702 .dpcm_capture = 1,
4703 .trigger = { SND_SOC_DPCM_TRIGGER_POST,
4704 SND_SOC_DPCM_TRIGGER_POST },
4705 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4706 .ignore_suspend = 1,
4707 .codec_dai_name = "snd-soc-dummy-dai",
4708 .codec_name = "snd-soc-dummy",
4709 .id = MSM_FRONTEND_DAI_LSM4,
4710 },
4711 {/* hw:x,19 */
4712 .name = "Listen 5 Audio Service",
4713 .stream_name = "Listen 5 Audio Service",
4714 .cpu_dai_name = "LSM5",
4715 .platform_name = "msm-lsm-client",
4716 .dynamic = 1,
4717 .dpcm_capture = 1,
4718 .trigger = { SND_SOC_DPCM_TRIGGER_POST,
4719 SND_SOC_DPCM_TRIGGER_POST },
4720 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4721 .ignore_suspend = 1,
4722 .codec_dai_name = "snd-soc-dummy-dai",
4723 .codec_name = "snd-soc-dummy",
4724 .id = MSM_FRONTEND_DAI_LSM5,
4725 },
4726 {/* hw:x,20 */
4727 .name = "Listen 6 Audio Service",
4728 .stream_name = "Listen 6 Audio Service",
4729 .cpu_dai_name = "LSM6",
4730 .platform_name = "msm-lsm-client",
4731 .dynamic = 1,
4732 .dpcm_capture = 1,
4733 .trigger = { SND_SOC_DPCM_TRIGGER_POST,
4734 SND_SOC_DPCM_TRIGGER_POST },
4735 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4736 .ignore_suspend = 1,
4737 .codec_dai_name = "snd-soc-dummy-dai",
4738 .codec_name = "snd-soc-dummy",
4739 .id = MSM_FRONTEND_DAI_LSM6,
4740 },
4741 {/* hw:x,21 */
4742 .name = "Listen 7 Audio Service",
4743 .stream_name = "Listen 7 Audio Service",
4744 .cpu_dai_name = "LSM7",
4745 .platform_name = "msm-lsm-client",
4746 .dynamic = 1,
4747 .dpcm_capture = 1,
4748 .trigger = { SND_SOC_DPCM_TRIGGER_POST,
4749 SND_SOC_DPCM_TRIGGER_POST },
4750 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4751 .ignore_suspend = 1,
4752 .codec_dai_name = "snd-soc-dummy-dai",
4753 .codec_name = "snd-soc-dummy",
4754 .id = MSM_FRONTEND_DAI_LSM7,
4755 },
4756 {/* hw:x,22 */
4757 .name = "Listen 8 Audio Service",
4758 .stream_name = "Listen 8 Audio Service",
4759 .cpu_dai_name = "LSM8",
4760 .platform_name = "msm-lsm-client",
4761 .dynamic = 1,
4762 .dpcm_capture = 1,
4763 .trigger = { SND_SOC_DPCM_TRIGGER_POST,
4764 SND_SOC_DPCM_TRIGGER_POST },
4765 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4766 .ignore_suspend = 1,
4767 .codec_dai_name = "snd-soc-dummy-dai",
4768 .codec_name = "snd-soc-dummy",
4769 .id = MSM_FRONTEND_DAI_LSM8,
4770 },
4771 {/* hw:x,23 */
4772 .name = MSM_DAILINK_NAME(Media9),
4773 .stream_name = "MultiMedia9",
4774 .cpu_dai_name = "MultiMedia9",
4775 .platform_name = "msm-pcm-dsp.0",
4776 .dynamic = 1,
4777 .dpcm_playback = 1,
4778 .dpcm_capture = 1,
4779 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4780 SND_SOC_DPCM_TRIGGER_POST},
4781 .codec_dai_name = "snd-soc-dummy-dai",
4782 .codec_name = "snd-soc-dummy",
4783 .ignore_suspend = 1,
4784 /* this dainlink has playback support */
4785 .ignore_pmdown_time = 1,
4786 .id = MSM_FRONTEND_DAI_MULTIMEDIA9,
4787 },
4788 {/* hw:x,24 */
4789 .name = MSM_DAILINK_NAME(Compress4),
4790 .stream_name = "Compress4",
4791 .cpu_dai_name = "MultiMedia11",
4792 .platform_name = "msm-compress-dsp",
4793 .dynamic = 1,
4794 .dpcm_playback = 1,
4795 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4796 SND_SOC_DPCM_TRIGGER_POST},
4797 .codec_dai_name = "snd-soc-dummy-dai",
4798 .codec_name = "snd-soc-dummy",
4799 .ignore_suspend = 1,
4800 .ignore_pmdown_time = 1,
4801 /* this dainlink has playback support */
4802 .id = MSM_FRONTEND_DAI_MULTIMEDIA11,
4803 },
4804 {/* hw:x,25 */
4805 .name = MSM_DAILINK_NAME(Compress5),
4806 .stream_name = "Compress5",
4807 .cpu_dai_name = "MultiMedia12",
4808 .platform_name = "msm-compress-dsp",
4809 .dynamic = 1,
4810 .dpcm_playback = 1,
4811 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4812 SND_SOC_DPCM_TRIGGER_POST},
4813 .codec_dai_name = "snd-soc-dummy-dai",
4814 .codec_name = "snd-soc-dummy",
4815 .ignore_suspend = 1,
4816 .ignore_pmdown_time = 1,
4817 /* this dainlink has playback support */
4818 .id = MSM_FRONTEND_DAI_MULTIMEDIA12,
4819 },
4820 {/* hw:x,26 */
4821 .name = MSM_DAILINK_NAME(Compress6),
4822 .stream_name = "Compress6",
4823 .cpu_dai_name = "MultiMedia13",
4824 .platform_name = "msm-compress-dsp",
4825 .dynamic = 1,
4826 .dpcm_playback = 1,
4827 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4828 SND_SOC_DPCM_TRIGGER_POST},
4829 .codec_dai_name = "snd-soc-dummy-dai",
4830 .codec_name = "snd-soc-dummy",
4831 .ignore_suspend = 1,
4832 .ignore_pmdown_time = 1,
4833 /* this dainlink has playback support */
4834 .id = MSM_FRONTEND_DAI_MULTIMEDIA13,
4835 },
4836 {/* hw:x,27 */
4837 .name = MSM_DAILINK_NAME(Compress7),
4838 .stream_name = "Compress7",
4839 .cpu_dai_name = "MultiMedia14",
4840 .platform_name = "msm-compress-dsp",
4841 .dynamic = 1,
4842 .dpcm_playback = 1,
4843 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4844 SND_SOC_DPCM_TRIGGER_POST},
4845 .codec_dai_name = "snd-soc-dummy-dai",
4846 .codec_name = "snd-soc-dummy",
4847 .ignore_suspend = 1,
4848 .ignore_pmdown_time = 1,
4849 /* this dainlink has playback support */
4850 .id = MSM_FRONTEND_DAI_MULTIMEDIA14,
4851 },
4852 {/* hw:x,28 */
4853 .name = MSM_DAILINK_NAME(Compress8),
4854 .stream_name = "Compress8",
4855 .cpu_dai_name = "MultiMedia15",
4856 .platform_name = "msm-compress-dsp",
4857 .dynamic = 1,
4858 .dpcm_playback = 1,
4859 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4860 SND_SOC_DPCM_TRIGGER_POST},
4861 .codec_dai_name = "snd-soc-dummy-dai",
4862 .codec_name = "snd-soc-dummy",
4863 .ignore_suspend = 1,
4864 .ignore_pmdown_time = 1,
4865 /* this dainlink has playback support */
4866 .id = MSM_FRONTEND_DAI_MULTIMEDIA15,
4867 },
4868 {/* hw:x,29 */
4869 .name = MSM_DAILINK_NAME(ULL_NOIRQ_2),
4870 .stream_name = "MM_NOIRQ_2",
4871 .cpu_dai_name = "MultiMedia16",
4872 .platform_name = "msm-pcm-dsp-noirq",
4873 .dynamic = 1,
4874 .dpcm_playback = 1,
4875 .dpcm_capture = 1,
4876 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4877 SND_SOC_DPCM_TRIGGER_POST},
4878 .codec_dai_name = "snd-soc-dummy-dai",
4879 .codec_name = "snd-soc-dummy",
4880 .ignore_suspend = 1,
4881 .ignore_pmdown_time = 1,
4882 /* this dainlink has playback support */
4883 .id = MSM_FRONTEND_DAI_MULTIMEDIA16,
4884 },
4885 {/* hw:x,30 */
4886 .name = "CDC_DMA Hostless",
4887 .stream_name = "CDC_DMA Hostless",
4888 .cpu_dai_name = "CDC_DMA_HOSTLESS",
4889 .platform_name = "msm-pcm-hostless",
4890 .dynamic = 1,
4891 .dpcm_playback = 1,
4892 .dpcm_capture = 1,
4893 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4894 SND_SOC_DPCM_TRIGGER_POST},
4895 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4896 .ignore_suspend = 1,
4897 /* this dailink has playback support */
4898 .ignore_pmdown_time = 1,
4899 .codec_dai_name = "snd-soc-dummy-dai",
4900 .codec_name = "snd-soc-dummy",
4901 },
4902 {/* hw:x,31 */
4903 .name = "TX3_CDC_DMA Hostless",
4904 .stream_name = "TX3_CDC_DMA Hostless",
4905 .cpu_dai_name = "TX3_CDC_DMA_HOSTLESS",
4906 .platform_name = "msm-pcm-hostless",
4907 .dynamic = 1,
4908 .dpcm_capture = 1,
4909 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4910 SND_SOC_DPCM_TRIGGER_POST},
4911 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4912 .ignore_suspend = 1,
4913 .codec_dai_name = "snd-soc-dummy-dai",
4914 .codec_name = "snd-soc-dummy",
4915 },
Karthikeyan Manif0de7562019-03-04 16:39:41 -08004916 {/* hw:x,32 */
4917 .name = "Tertiary MI2S TX_Hostless",
4918 .stream_name = "Tertiary MI2S_TX Hostless Capture",
4919 .cpu_dai_name = "TERT_MI2S_TX_HOSTLESS",
4920 .platform_name = "msm-pcm-hostless",
4921 .dynamic = 1,
4922 .dpcm_capture = 1,
4923 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4924 SND_SOC_DPCM_TRIGGER_POST},
4925 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4926 .ignore_suspend = 1,
4927 .ignore_pmdown_time = 1,
4928 .codec_dai_name = "snd-soc-dummy-dai",
4929 .codec_name = "snd-soc-dummy",
4930 },
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07004931};
4932
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07004933static struct snd_soc_dai_link msm_bolero_fe_dai_links[] = {
Karthikeyan Manif0de7562019-03-04 16:39:41 -08004934 {/* hw:x,33 */
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07004935 .name = LPASS_BE_WSA_CDC_DMA_TX_0,
4936 .stream_name = "WSA CDC DMA0 Capture",
4937 .cpu_dai_name = "msm-dai-cdc-dma-dev.45057",
4938 .platform_name = "msm-pcm-hostless",
4939 .codec_name = "bolero_codec",
4940 .codec_dai_name = "wsa_macro_vifeedback",
4941 .id = MSM_BACKEND_DAI_WSA_CDC_DMA_TX_0,
4942 .be_hw_params_fixup = msm_be_hw_params_fixup,
4943 .ignore_suspend = 1,
4944 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4945 .ops = &msm_cdc_dma_be_ops,
4946 },
4947};
4948
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07004949static struct snd_soc_dai_link msm_common_misc_fe_dai_links[] = {
Karthikeyan Manif0de7562019-03-04 16:39:41 -08004950 {/* hw:x,34 */
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07004951 .name = MSM_DAILINK_NAME(ASM Loopback),
4952 .stream_name = "MultiMedia6",
4953 .cpu_dai_name = "MultiMedia6",
4954 .platform_name = "msm-pcm-loopback",
4955 .dynamic = 1,
4956 .dpcm_playback = 1,
4957 .dpcm_capture = 1,
4958 .codec_dai_name = "snd-soc-dummy-dai",
4959 .codec_name = "snd-soc-dummy",
4960 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4961 SND_SOC_DPCM_TRIGGER_POST},
4962 .ignore_suspend = 1,
4963 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4964 .ignore_pmdown_time = 1,
4965 .id = MSM_FRONTEND_DAI_MULTIMEDIA6,
4966 },
Karthikeyan Manif0de7562019-03-04 16:39:41 -08004967 {/* hw:x,35 */
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07004968 .name = "USB Audio Hostless",
4969 .stream_name = "USB Audio Hostless",
4970 .cpu_dai_name = "USBAUDIO_HOSTLESS",
4971 .platform_name = "msm-pcm-hostless",
4972 .dynamic = 1,
4973 .dpcm_playback = 1,
4974 .dpcm_capture = 1,
4975 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4976 SND_SOC_DPCM_TRIGGER_POST},
4977 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4978 .ignore_suspend = 1,
4979 .ignore_pmdown_time = 1,
4980 .codec_dai_name = "snd-soc-dummy-dai",
4981 .codec_name = "snd-soc-dummy",
4982 },
Karthikeyan Manif0de7562019-03-04 16:39:41 -08004983 {/* hw:x,36 */
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07004984 .name = "SLIMBUS_7 Hostless",
4985 .stream_name = "SLIMBUS_7 Hostless",
4986 .cpu_dai_name = "SLIMBUS7_HOSTLESS",
4987 .platform_name = "msm-pcm-hostless",
4988 .dynamic = 1,
4989 .dpcm_capture = 1,
4990 .dpcm_playback = 1,
4991 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
4992 SND_SOC_DPCM_TRIGGER_POST},
4993 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
4994 .ignore_suspend = 1,
4995 .ignore_pmdown_time = 1,
4996 .codec_dai_name = "snd-soc-dummy-dai",
4997 .codec_name = "snd-soc-dummy",
4998 },
Karthikeyan Manif0de7562019-03-04 16:39:41 -08004999 {/* hw:x,37 */
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -08005000 .name = "Compress Capture",
5001 .stream_name = "Compress9",
5002 .cpu_dai_name = "MultiMedia17",
5003 .platform_name = "msm-compress-dsp",
5004 .dynamic = 1,
5005 .dpcm_capture = 1,
5006 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
5007 SND_SOC_DPCM_TRIGGER_POST},
5008 .codec_dai_name = "snd-soc-dummy-dai",
5009 .codec_name = "snd-soc-dummy",
5010 .ignore_suspend = 1,
5011 .ignore_pmdown_time = 1,
5012 .id = MSM_FRONTEND_DAI_MULTIMEDIA17,
5013 },
Vatsal Bucha82b30ba2019-04-17 12:43:54 +05305014 {/* hw:x,38 */
5015 .name = "SLIMBUS_8 Hostless",
5016 .stream_name = "SLIMBUS_8 Hostless",
5017 .cpu_dai_name = "SLIMBUS8_HOSTLESS",
5018 .platform_name = "msm-pcm-hostless",
5019 .dynamic = 1,
5020 .dpcm_capture = 1,
5021 .dpcm_playback = 1,
5022 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
5023 SND_SOC_DPCM_TRIGGER_POST},
5024 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
5025 .ignore_suspend = 1,
5026 .ignore_pmdown_time = 1,
5027 .codec_dai_name = "snd-soc-dummy-dai",
5028 .codec_name = "snd-soc-dummy",
5029 },
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07005030};
5031
5032static struct snd_soc_dai_link msm_common_be_dai_links[] = {
5033 /* Backend AFE DAI Links */
5034 {
5035 .name = LPASS_BE_AFE_PCM_RX,
5036 .stream_name = "AFE Playback",
5037 .cpu_dai_name = "msm-dai-q6-dev.224",
5038 .platform_name = "msm-pcm-routing",
5039 .codec_name = "msm-stub-codec.1",
5040 .codec_dai_name = "msm-stub-rx",
5041 .no_pcm = 1,
5042 .dpcm_playback = 1,
5043 .id = MSM_BACKEND_DAI_AFE_PCM_RX,
5044 .be_hw_params_fixup = msm_be_hw_params_fixup,
5045 /* this dainlink has playback support */
5046 .ignore_pmdown_time = 1,
5047 .ignore_suspend = 1,
5048 },
5049 {
5050 .name = LPASS_BE_AFE_PCM_TX,
5051 .stream_name = "AFE Capture",
5052 .cpu_dai_name = "msm-dai-q6-dev.225",
5053 .platform_name = "msm-pcm-routing",
5054 .codec_name = "msm-stub-codec.1",
5055 .codec_dai_name = "msm-stub-tx",
5056 .no_pcm = 1,
5057 .dpcm_capture = 1,
5058 .id = MSM_BACKEND_DAI_AFE_PCM_TX,
5059 .be_hw_params_fixup = msm_be_hw_params_fixup,
5060 .ignore_suspend = 1,
5061 },
5062 /* Incall Record Uplink BACK END DAI Link */
5063 {
5064 .name = LPASS_BE_INCALL_RECORD_TX,
5065 .stream_name = "Voice Uplink Capture",
5066 .cpu_dai_name = "msm-dai-q6-dev.32772",
5067 .platform_name = "msm-pcm-routing",
5068 .codec_name = "msm-stub-codec.1",
5069 .codec_dai_name = "msm-stub-tx",
5070 .no_pcm = 1,
5071 .dpcm_capture = 1,
5072 .id = MSM_BACKEND_DAI_INCALL_RECORD_TX,
5073 .be_hw_params_fixup = msm_be_hw_params_fixup,
5074 .ignore_suspend = 1,
5075 },
5076 /* Incall Record Downlink BACK END DAI Link */
5077 {
5078 .name = LPASS_BE_INCALL_RECORD_RX,
5079 .stream_name = "Voice Downlink Capture",
5080 .cpu_dai_name = "msm-dai-q6-dev.32771",
5081 .platform_name = "msm-pcm-routing",
5082 .codec_name = "msm-stub-codec.1",
5083 .codec_dai_name = "msm-stub-tx",
5084 .no_pcm = 1,
5085 .dpcm_capture = 1,
5086 .id = MSM_BACKEND_DAI_INCALL_RECORD_RX,
5087 .be_hw_params_fixup = msm_be_hw_params_fixup,
5088 .ignore_suspend = 1,
5089 },
5090 /* Incall Music BACK END DAI Link */
5091 {
5092 .name = LPASS_BE_VOICE_PLAYBACK_TX,
5093 .stream_name = "Voice Farend Playback",
5094 .cpu_dai_name = "msm-dai-q6-dev.32773",
5095 .platform_name = "msm-pcm-routing",
5096 .codec_name = "msm-stub-codec.1",
5097 .codec_dai_name = "msm-stub-rx",
5098 .no_pcm = 1,
5099 .dpcm_playback = 1,
5100 .id = MSM_BACKEND_DAI_VOICE_PLAYBACK_TX,
5101 .be_hw_params_fixup = msm_be_hw_params_fixup,
5102 .ignore_suspend = 1,
5103 .ignore_pmdown_time = 1,
5104 },
5105 /* Incall Music 2 BACK END DAI Link */
5106 {
5107 .name = LPASS_BE_VOICE2_PLAYBACK_TX,
5108 .stream_name = "Voice2 Farend Playback",
5109 .cpu_dai_name = "msm-dai-q6-dev.32770",
5110 .platform_name = "msm-pcm-routing",
5111 .codec_name = "msm-stub-codec.1",
5112 .codec_dai_name = "msm-stub-rx",
5113 .no_pcm = 1,
5114 .dpcm_playback = 1,
5115 .id = MSM_BACKEND_DAI_VOICE2_PLAYBACK_TX,
5116 .be_hw_params_fixup = msm_be_hw_params_fixup,
5117 .ignore_suspend = 1,
5118 .ignore_pmdown_time = 1,
5119 },
5120 {
5121 .name = LPASS_BE_USB_AUDIO_RX,
5122 .stream_name = "USB Audio Playback",
5123 .cpu_dai_name = "msm-dai-q6-dev.28672",
5124 .platform_name = "msm-pcm-routing",
5125 .codec_name = "msm-stub-codec.1",
5126 .codec_dai_name = "msm-stub-rx",
5127 .no_pcm = 1,
5128 .dpcm_playback = 1,
5129 .id = MSM_BACKEND_DAI_USB_RX,
5130 .be_hw_params_fixup = msm_be_hw_params_fixup,
5131 .ignore_pmdown_time = 1,
5132 .ignore_suspend = 1,
5133 },
5134 {
5135 .name = LPASS_BE_USB_AUDIO_TX,
5136 .stream_name = "USB Audio Capture",
5137 .cpu_dai_name = "msm-dai-q6-dev.28673",
5138 .platform_name = "msm-pcm-routing",
5139 .codec_name = "msm-stub-codec.1",
5140 .codec_dai_name = "msm-stub-tx",
5141 .no_pcm = 1,
5142 .dpcm_capture = 1,
5143 .id = MSM_BACKEND_DAI_USB_TX,
5144 .be_hw_params_fixup = msm_be_hw_params_fixup,
5145 .ignore_suspend = 1,
5146 },
5147 {
5148 .name = LPASS_BE_PRI_TDM_RX_0,
5149 .stream_name = "Primary TDM0 Playback",
5150 .cpu_dai_name = "msm-dai-q6-tdm.36864",
5151 .platform_name = "msm-pcm-routing",
5152 .codec_name = "msm-stub-codec.1",
5153 .codec_dai_name = "msm-stub-rx",
5154 .no_pcm = 1,
5155 .dpcm_playback = 1,
5156 .id = MSM_BACKEND_DAI_PRI_TDM_RX_0,
5157 .be_hw_params_fixup = msm_be_hw_params_fixup,
5158 .ops = &kona_tdm_be_ops,
5159 .ignore_suspend = 1,
5160 .ignore_pmdown_time = 1,
5161 },
5162 {
5163 .name = LPASS_BE_PRI_TDM_TX_0,
5164 .stream_name = "Primary TDM0 Capture",
5165 .cpu_dai_name = "msm-dai-q6-tdm.36865",
5166 .platform_name = "msm-pcm-routing",
5167 .codec_name = "msm-stub-codec.1",
5168 .codec_dai_name = "msm-stub-tx",
5169 .no_pcm = 1,
5170 .dpcm_capture = 1,
5171 .id = MSM_BACKEND_DAI_PRI_TDM_TX_0,
5172 .be_hw_params_fixup = msm_be_hw_params_fixup,
5173 .ops = &kona_tdm_be_ops,
5174 .ignore_suspend = 1,
5175 },
5176 {
5177 .name = LPASS_BE_SEC_TDM_RX_0,
5178 .stream_name = "Secondary TDM0 Playback",
5179 .cpu_dai_name = "msm-dai-q6-tdm.36880",
5180 .platform_name = "msm-pcm-routing",
5181 .codec_name = "msm-stub-codec.1",
5182 .codec_dai_name = "msm-stub-rx",
5183 .no_pcm = 1,
5184 .dpcm_playback = 1,
5185 .id = MSM_BACKEND_DAI_SEC_TDM_RX_0,
5186 .be_hw_params_fixup = msm_be_hw_params_fixup,
5187 .ops = &kona_tdm_be_ops,
5188 .ignore_suspend = 1,
5189 .ignore_pmdown_time = 1,
5190 },
5191 {
5192 .name = LPASS_BE_SEC_TDM_TX_0,
5193 .stream_name = "Secondary TDM0 Capture",
5194 .cpu_dai_name = "msm-dai-q6-tdm.36881",
5195 .platform_name = "msm-pcm-routing",
5196 .codec_name = "msm-stub-codec.1",
5197 .codec_dai_name = "msm-stub-tx",
5198 .no_pcm = 1,
5199 .dpcm_capture = 1,
5200 .id = MSM_BACKEND_DAI_SEC_TDM_TX_0,
5201 .be_hw_params_fixup = msm_be_hw_params_fixup,
5202 .ops = &kona_tdm_be_ops,
5203 .ignore_suspend = 1,
5204 },
5205 {
5206 .name = LPASS_BE_TERT_TDM_RX_0,
5207 .stream_name = "Tertiary TDM0 Playback",
5208 .cpu_dai_name = "msm-dai-q6-tdm.36896",
5209 .platform_name = "msm-pcm-routing",
5210 .codec_name = "msm-stub-codec.1",
5211 .codec_dai_name = "msm-stub-rx",
5212 .no_pcm = 1,
5213 .dpcm_playback = 1,
5214 .id = MSM_BACKEND_DAI_TERT_TDM_RX_0,
5215 .be_hw_params_fixup = msm_be_hw_params_fixup,
5216 .ops = &kona_tdm_be_ops,
5217 .ignore_suspend = 1,
5218 .ignore_pmdown_time = 1,
5219 },
5220 {
5221 .name = LPASS_BE_TERT_TDM_TX_0,
5222 .stream_name = "Tertiary TDM0 Capture",
5223 .cpu_dai_name = "msm-dai-q6-tdm.36897",
5224 .platform_name = "msm-pcm-routing",
5225 .codec_name = "msm-stub-codec.1",
5226 .codec_dai_name = "msm-stub-tx",
5227 .no_pcm = 1,
5228 .dpcm_capture = 1,
5229 .id = MSM_BACKEND_DAI_TERT_TDM_TX_0,
5230 .be_hw_params_fixup = msm_be_hw_params_fixup,
5231 .ops = &kona_tdm_be_ops,
5232 .ignore_suspend = 1,
5233 },
5234};
5235
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -08005236static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
5237 {
5238 .name = LPASS_BE_SLIMBUS_7_RX,
5239 .stream_name = "Slimbus7 Playback",
5240 .cpu_dai_name = "msm-dai-q6-dev.16398",
5241 .platform_name = "msm-pcm-routing",
5242 .codec_name = "btfmslim_slave",
5243 /* BT codec driver determines capabilities based on
5244 * dai name, bt codecdai name should always contains
5245 * supported usecase information
5246 */
5247 .codec_dai_name = "btfm_bt_sco_a2dp_slim_rx",
5248 .no_pcm = 1,
5249 .dpcm_playback = 1,
5250 .id = MSM_BACKEND_DAI_SLIMBUS_7_RX,
5251 .be_hw_params_fixup = msm_be_hw_params_fixup,
5252 .init = &msm_wcn_init,
5253 .ops = &msm_wcn_ops,
5254 /* dai link has playback support */
5255 .ignore_pmdown_time = 1,
5256 .ignore_suspend = 1,
5257 },
5258 {
5259 .name = LPASS_BE_SLIMBUS_7_TX,
5260 .stream_name = "Slimbus7 Capture",
5261 .cpu_dai_name = "msm-dai-q6-dev.16399",
5262 .platform_name = "msm-pcm-routing",
5263 .codec_name = "btfmslim_slave",
5264 .codec_dai_name = "btfm_bt_sco_slim_tx",
5265 .no_pcm = 1,
5266 .dpcm_capture = 1,
5267 .id = MSM_BACKEND_DAI_SLIMBUS_7_TX,
5268 .be_hw_params_fixup = msm_be_hw_params_fixup,
5269 .ops = &msm_wcn_ops,
5270 .ignore_suspend = 1,
5271 },
5272};
5273
Vatsal Bucha82b30ba2019-04-17 12:43:54 +05305274static struct snd_soc_dai_link msm_wcn_btfm_be_dai_links[] = {
5275 {
5276 .name = LPASS_BE_SLIMBUS_7_RX,
5277 .stream_name = "Slimbus7 Playback",
5278 .cpu_dai_name = "msm-dai-q6-dev.16398",
5279 .platform_name = "msm-pcm-routing",
5280 .codec_name = "btfmslim_slave",
5281 /* BT codec driver determines capabilities based on
5282 * dai name, bt codecdai name should always contains
5283 * supported usecase information
5284 */
5285 .codec_dai_name = "btfm_bt_sco_a2dp_slim_rx",
5286 .no_pcm = 1,
5287 .dpcm_playback = 1,
5288 .id = MSM_BACKEND_DAI_SLIMBUS_7_RX,
5289 .be_hw_params_fixup = msm_be_hw_params_fixup,
5290 .init = &msm_wcn_init_lito,
5291 .ops = &msm_wcn_ops_lito,
5292 /* dai link has playback support */
5293 .ignore_pmdown_time = 1,
5294 .ignore_suspend = 1,
5295 },
5296 {
5297 .name = LPASS_BE_SLIMBUS_7_TX,
5298 .stream_name = "Slimbus7 Capture",
5299 .cpu_dai_name = "msm-dai-q6-dev.16399",
5300 .platform_name = "msm-pcm-routing",
5301 .codec_name = "btfmslim_slave",
5302 .codec_dai_name = "btfm_bt_sco_slim_tx",
5303 .no_pcm = 1,
5304 .dpcm_capture = 1,
5305 .id = MSM_BACKEND_DAI_SLIMBUS_7_TX,
5306 .be_hw_params_fixup = msm_be_hw_params_fixup,
5307 .ops = &msm_wcn_ops_lito,
5308 .ignore_suspend = 1,
5309 },
5310 {
5311 .name = LPASS_BE_SLIMBUS_8_TX,
5312 .stream_name = "Slimbus8 Capture",
5313 .cpu_dai_name = "msm-dai-q6-dev.16401",
5314 .platform_name = "msm-pcm-routing",
5315 .codec_name = "btfmslim_slave",
5316 .codec_dai_name = "btfm_fm_slim_tx",
5317 .no_pcm = 1,
5318 .dpcm_capture = 1,
5319 .id = MSM_BACKEND_DAI_SLIMBUS_8_TX,
5320 .be_hw_params_fixup = msm_be_hw_params_fixup,
5321 .ops = &msm_wcn_ops_lito,
5322 .ignore_suspend = 1,
5323 },
5324};
5325
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -08005326static struct snd_soc_dai_link ext_disp_be_dai_link[] = {
5327 /* DISP PORT BACK END DAI Link */
5328 {
5329 .name = LPASS_BE_DISPLAY_PORT,
5330 .stream_name = "Display Port Playback",
5331 .cpu_dai_name = "msm-dai-q6-dp.24608",
5332 .platform_name = "msm-pcm-routing",
5333 .codec_name = "msm-ext-disp-audio-codec-rx",
5334 .codec_dai_name = "msm_dp_audio_codec_rx_dai",
5335 .no_pcm = 1,
5336 .dpcm_playback = 1,
5337 .id = MSM_BACKEND_DAI_DISPLAY_PORT_RX,
5338 .be_hw_params_fixup = msm_be_hw_params_fixup,
5339 .ignore_pmdown_time = 1,
5340 .ignore_suspend = 1,
5341 },
5342 /* DISP PORT 1 BACK END DAI Link */
5343 {
5344 .name = LPASS_BE_DISPLAY_PORT1,
5345 .stream_name = "Display Port1 Playback",
5346 .cpu_dai_name = "msm-dai-q6-dp.24608",
5347 .platform_name = "msm-pcm-routing",
5348 .codec_name = "msm-ext-disp-audio-codec-rx",
5349 .codec_dai_name = "msm_dp_audio_codec_rx1_dai",
5350 .no_pcm = 1,
5351 .dpcm_playback = 1,
5352 .id = MSM_BACKEND_DAI_DISPLAY_PORT_RX_1,
5353 .be_hw_params_fixup = msm_be_hw_params_fixup,
5354 .ignore_pmdown_time = 1,
5355 .ignore_suspend = 1,
5356 },
5357};
5358
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07005359static struct snd_soc_dai_link msm_mi2s_be_dai_links[] = {
5360 {
5361 .name = LPASS_BE_PRI_MI2S_RX,
5362 .stream_name = "Primary MI2S Playback",
5363 .cpu_dai_name = "msm-dai-q6-mi2s.0",
5364 .platform_name = "msm-pcm-routing",
5365 .codec_name = "msm-stub-codec.1",
5366 .codec_dai_name = "msm-stub-rx",
5367 .no_pcm = 1,
5368 .dpcm_playback = 1,
5369 .id = MSM_BACKEND_DAI_PRI_MI2S_RX,
5370 .be_hw_params_fixup = msm_be_hw_params_fixup,
5371 .ops = &msm_mi2s_be_ops,
5372 .ignore_suspend = 1,
5373 .ignore_pmdown_time = 1,
5374 },
5375 {
5376 .name = LPASS_BE_PRI_MI2S_TX,
5377 .stream_name = "Primary MI2S Capture",
5378 .cpu_dai_name = "msm-dai-q6-mi2s.0",
5379 .platform_name = "msm-pcm-routing",
5380 .codec_name = "msm-stub-codec.1",
5381 .codec_dai_name = "msm-stub-tx",
5382 .no_pcm = 1,
5383 .dpcm_capture = 1,
5384 .id = MSM_BACKEND_DAI_PRI_MI2S_TX,
5385 .be_hw_params_fixup = msm_be_hw_params_fixup,
5386 .ops = &msm_mi2s_be_ops,
5387 .ignore_suspend = 1,
5388 },
5389 {
5390 .name = LPASS_BE_SEC_MI2S_RX,
5391 .stream_name = "Secondary MI2S Playback",
5392 .cpu_dai_name = "msm-dai-q6-mi2s.1",
5393 .platform_name = "msm-pcm-routing",
5394 .codec_name = "msm-stub-codec.1",
5395 .codec_dai_name = "msm-stub-rx",
5396 .no_pcm = 1,
5397 .dpcm_playback = 1,
5398 .id = MSM_BACKEND_DAI_SECONDARY_MI2S_RX,
5399 .be_hw_params_fixup = msm_be_hw_params_fixup,
5400 .ops = &msm_mi2s_be_ops,
5401 .ignore_suspend = 1,
5402 .ignore_pmdown_time = 1,
5403 },
5404 {
5405 .name = LPASS_BE_SEC_MI2S_TX,
5406 .stream_name = "Secondary MI2S Capture",
5407 .cpu_dai_name = "msm-dai-q6-mi2s.1",
5408 .platform_name = "msm-pcm-routing",
5409 .codec_name = "msm-stub-codec.1",
5410 .codec_dai_name = "msm-stub-tx",
5411 .no_pcm = 1,
5412 .dpcm_capture = 1,
5413 .id = MSM_BACKEND_DAI_SECONDARY_MI2S_TX,
5414 .be_hw_params_fixup = msm_be_hw_params_fixup,
5415 .ops = &msm_mi2s_be_ops,
5416 .ignore_suspend = 1,
5417 },
5418 {
5419 .name = LPASS_BE_TERT_MI2S_RX,
5420 .stream_name = "Tertiary MI2S Playback",
5421 .cpu_dai_name = "msm-dai-q6-mi2s.2",
5422 .platform_name = "msm-pcm-routing",
5423 .codec_name = "msm-stub-codec.1",
5424 .codec_dai_name = "msm-stub-rx",
5425 .no_pcm = 1,
5426 .dpcm_playback = 1,
5427 .id = MSM_BACKEND_DAI_TERTIARY_MI2S_RX,
5428 .be_hw_params_fixup = msm_be_hw_params_fixup,
5429 .ops = &msm_mi2s_be_ops,
5430 .ignore_suspend = 1,
5431 .ignore_pmdown_time = 1,
5432 },
5433 {
5434 .name = LPASS_BE_TERT_MI2S_TX,
5435 .stream_name = "Tertiary MI2S Capture",
5436 .cpu_dai_name = "msm-dai-q6-mi2s.2",
5437 .platform_name = "msm-pcm-routing",
5438 .codec_name = "msm-stub-codec.1",
5439 .codec_dai_name = "msm-stub-tx",
5440 .no_pcm = 1,
5441 .dpcm_capture = 1,
5442 .id = MSM_BACKEND_DAI_TERTIARY_MI2S_TX,
5443 .be_hw_params_fixup = msm_be_hw_params_fixup,
5444 .ops = &msm_mi2s_be_ops,
5445 .ignore_suspend = 1,
5446 },
5447};
5448
5449static struct snd_soc_dai_link msm_auxpcm_be_dai_links[] = {
5450 /* Primary AUX PCM Backend DAI Links */
5451 {
5452 .name = LPASS_BE_AUXPCM_RX,
5453 .stream_name = "AUX PCM Playback",
5454 .cpu_dai_name = "msm-dai-q6-auxpcm.1",
5455 .platform_name = "msm-pcm-routing",
5456 .codec_name = "msm-stub-codec.1",
5457 .codec_dai_name = "msm-stub-rx",
5458 .no_pcm = 1,
5459 .dpcm_playback = 1,
5460 .id = MSM_BACKEND_DAI_AUXPCM_RX,
5461 .be_hw_params_fixup = msm_be_hw_params_fixup,
5462 .ignore_pmdown_time = 1,
5463 .ignore_suspend = 1,
5464 },
5465 {
5466 .name = LPASS_BE_AUXPCM_TX,
5467 .stream_name = "AUX PCM Capture",
5468 .cpu_dai_name = "msm-dai-q6-auxpcm.1",
5469 .platform_name = "msm-pcm-routing",
5470 .codec_name = "msm-stub-codec.1",
5471 .codec_dai_name = "msm-stub-tx",
5472 .no_pcm = 1,
5473 .dpcm_capture = 1,
5474 .id = MSM_BACKEND_DAI_AUXPCM_TX,
5475 .be_hw_params_fixup = msm_be_hw_params_fixup,
5476 .ignore_suspend = 1,
5477 },
5478 /* Secondary AUX PCM Backend DAI Links */
5479 {
5480 .name = LPASS_BE_SEC_AUXPCM_RX,
5481 .stream_name = "Sec AUX PCM Playback",
5482 .cpu_dai_name = "msm-dai-q6-auxpcm.2",
5483 .platform_name = "msm-pcm-routing",
5484 .codec_name = "msm-stub-codec.1",
5485 .codec_dai_name = "msm-stub-rx",
5486 .no_pcm = 1,
5487 .dpcm_playback = 1,
5488 .id = MSM_BACKEND_DAI_SEC_AUXPCM_RX,
5489 .be_hw_params_fixup = msm_be_hw_params_fixup,
5490 .ignore_pmdown_time = 1,
5491 .ignore_suspend = 1,
5492 },
5493 {
5494 .name = LPASS_BE_SEC_AUXPCM_TX,
5495 .stream_name = "Sec AUX PCM Capture",
5496 .cpu_dai_name = "msm-dai-q6-auxpcm.2",
5497 .platform_name = "msm-pcm-routing",
5498 .codec_name = "msm-stub-codec.1",
5499 .codec_dai_name = "msm-stub-tx",
5500 .no_pcm = 1,
5501 .dpcm_capture = 1,
5502 .id = MSM_BACKEND_DAI_SEC_AUXPCM_TX,
5503 .be_hw_params_fixup = msm_be_hw_params_fixup,
5504 .ignore_suspend = 1,
5505 },
5506 /* Tertiary AUX PCM Backend DAI Links */
5507 {
5508 .name = LPASS_BE_TERT_AUXPCM_RX,
5509 .stream_name = "Tert AUX PCM Playback",
5510 .cpu_dai_name = "msm-dai-q6-auxpcm.3",
5511 .platform_name = "msm-pcm-routing",
5512 .codec_name = "msm-stub-codec.1",
5513 .codec_dai_name = "msm-stub-rx",
5514 .no_pcm = 1,
5515 .dpcm_playback = 1,
5516 .id = MSM_BACKEND_DAI_TERT_AUXPCM_RX,
5517 .be_hw_params_fixup = msm_be_hw_params_fixup,
5518 .ignore_suspend = 1,
5519 },
5520 {
5521 .name = LPASS_BE_TERT_AUXPCM_TX,
5522 .stream_name = "Tert AUX PCM Capture",
5523 .cpu_dai_name = "msm-dai-q6-auxpcm.3",
5524 .platform_name = "msm-pcm-routing",
5525 .codec_name = "msm-stub-codec.1",
5526 .codec_dai_name = "msm-stub-tx",
5527 .no_pcm = 1,
5528 .dpcm_capture = 1,
5529 .id = MSM_BACKEND_DAI_TERT_AUXPCM_TX,
5530 .be_hw_params_fixup = msm_be_hw_params_fixup,
5531 .ignore_suspend = 1,
5532 },
5533};
5534
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07005535static struct snd_soc_dai_link msm_wsa_cdc_dma_be_dai_links[] = {
5536 /* WSA CDC DMA Backend DAI Links */
5537 {
5538 .name = LPASS_BE_WSA_CDC_DMA_RX_0,
5539 .stream_name = "WSA CDC DMA0 Playback",
5540 .cpu_dai_name = "msm-dai-cdc-dma-dev.45056",
5541 .platform_name = "msm-pcm-routing",
5542 .codec_name = "bolero_codec",
5543 .codec_dai_name = "wsa_macro_rx1",
5544 .no_pcm = 1,
5545 .dpcm_playback = 1,
5546 .init = &msm_int_audrx_init,
5547 .id = MSM_BACKEND_DAI_WSA_CDC_DMA_RX_0,
5548 .be_hw_params_fixup = msm_be_hw_params_fixup,
5549 .ignore_pmdown_time = 1,
5550 .ignore_suspend = 1,
5551 .ops = &msm_cdc_dma_be_ops,
5552 },
5553 {
5554 .name = LPASS_BE_WSA_CDC_DMA_RX_1,
5555 .stream_name = "WSA CDC DMA1 Playback",
5556 .cpu_dai_name = "msm-dai-cdc-dma-dev.45058",
5557 .platform_name = "msm-pcm-routing",
5558 .codec_name = "bolero_codec",
5559 .codec_dai_name = "wsa_macro_rx_mix",
5560 .no_pcm = 1,
5561 .dpcm_playback = 1,
5562 .id = MSM_BACKEND_DAI_WSA_CDC_DMA_RX_1,
5563 .be_hw_params_fixup = msm_be_hw_params_fixup,
5564 .ignore_pmdown_time = 1,
5565 .ignore_suspend = 1,
5566 .ops = &msm_cdc_dma_be_ops,
5567 },
5568 {
5569 .name = LPASS_BE_WSA_CDC_DMA_TX_1,
5570 .stream_name = "WSA CDC DMA1 Capture",
5571 .cpu_dai_name = "msm-dai-cdc-dma-dev.45059",
5572 .platform_name = "msm-pcm-routing",
5573 .codec_name = "bolero_codec",
5574 .codec_dai_name = "wsa_macro_echo",
5575 .no_pcm = 1,
5576 .dpcm_capture = 1,
5577 .id = MSM_BACKEND_DAI_WSA_CDC_DMA_TX_1,
5578 .be_hw_params_fixup = msm_be_hw_params_fixup,
5579 .ignore_suspend = 1,
5580 .ops = &msm_cdc_dma_be_ops,
5581 },
5582};
5583
5584static struct snd_soc_dai_link msm_rx_tx_cdc_dma_be_dai_links[] = {
5585 /* RX CDC DMA Backend DAI Links */
5586 {
5587 .name = LPASS_BE_RX_CDC_DMA_RX_0,
5588 .stream_name = "RX CDC DMA0 Playback",
5589 .cpu_dai_name = "msm-dai-cdc-dma-dev.45104",
5590 .platform_name = "msm-pcm-routing",
5591 .codec_name = "bolero_codec",
5592 .codec_dai_name = "rx_macro_rx1",
5593 .no_pcm = 1,
5594 .dpcm_playback = 1,
5595 .id = MSM_BACKEND_DAI_RX_CDC_DMA_RX_0,
5596 .be_hw_params_fixup = msm_be_hw_params_fixup,
5597 .ignore_pmdown_time = 1,
5598 .ignore_suspend = 1,
5599 .ops = &msm_cdc_dma_be_ops,
5600 },
5601 {
5602 .name = LPASS_BE_RX_CDC_DMA_RX_1,
5603 .stream_name = "RX CDC DMA1 Playback",
5604 .cpu_dai_name = "msm-dai-cdc-dma-dev.45106",
5605 .platform_name = "msm-pcm-routing",
5606 .codec_name = "bolero_codec",
5607 .codec_dai_name = "rx_macro_rx2",
5608 .no_pcm = 1,
5609 .dpcm_playback = 1,
5610 .id = MSM_BACKEND_DAI_RX_CDC_DMA_RX_1,
5611 .be_hw_params_fixup = msm_be_hw_params_fixup,
5612 .ignore_pmdown_time = 1,
5613 .ignore_suspend = 1,
5614 .ops = &msm_cdc_dma_be_ops,
5615 },
5616 {
5617 .name = LPASS_BE_RX_CDC_DMA_RX_2,
5618 .stream_name = "RX CDC DMA2 Playback",
5619 .cpu_dai_name = "msm-dai-cdc-dma-dev.45108",
5620 .platform_name = "msm-pcm-routing",
5621 .codec_name = "bolero_codec",
5622 .codec_dai_name = "rx_macro_rx3",
5623 .no_pcm = 1,
5624 .dpcm_playback = 1,
5625 .id = MSM_BACKEND_DAI_RX_CDC_DMA_RX_2,
5626 .be_hw_params_fixup = msm_be_hw_params_fixup,
5627 .ignore_pmdown_time = 1,
5628 .ignore_suspend = 1,
5629 .ops = &msm_cdc_dma_be_ops,
5630 },
5631 {
5632 .name = LPASS_BE_RX_CDC_DMA_RX_3,
5633 .stream_name = "RX CDC DMA3 Playback",
5634 .cpu_dai_name = "msm-dai-cdc-dma-dev.45110",
5635 .platform_name = "msm-pcm-routing",
5636 .codec_name = "bolero_codec",
5637 .codec_dai_name = "rx_macro_rx4",
5638 .no_pcm = 1,
5639 .dpcm_playback = 1,
5640 .id = MSM_BACKEND_DAI_RX_CDC_DMA_RX_3,
5641 .be_hw_params_fixup = msm_be_hw_params_fixup,
5642 .ignore_pmdown_time = 1,
5643 .ignore_suspend = 1,
5644 .ops = &msm_cdc_dma_be_ops,
5645 },
5646 /* TX CDC DMA Backend DAI Links */
5647 {
5648 .name = LPASS_BE_TX_CDC_DMA_TX_3,
5649 .stream_name = "TX CDC DMA3 Capture",
5650 .cpu_dai_name = "msm-dai-cdc-dma-dev.45111",
5651 .platform_name = "msm-pcm-routing",
5652 .codec_name = "bolero_codec",
5653 .codec_dai_name = "tx_macro_tx1",
5654 .no_pcm = 1,
5655 .dpcm_capture = 1,
5656 .id = MSM_BACKEND_DAI_TX_CDC_DMA_TX_3,
5657 .be_hw_params_fixup = msm_be_hw_params_fixup,
5658 .ignore_suspend = 1,
5659 .ops = &msm_cdc_dma_be_ops,
5660 },
5661 {
5662 .name = LPASS_BE_TX_CDC_DMA_TX_4,
5663 .stream_name = "TX CDC DMA4 Capture",
5664 .cpu_dai_name = "msm-dai-cdc-dma-dev.45113",
5665 .platform_name = "msm-pcm-routing",
5666 .codec_name = "bolero_codec",
5667 .codec_dai_name = "tx_macro_tx2",
5668 .no_pcm = 1,
5669 .dpcm_capture = 1,
5670 .id = MSM_BACKEND_DAI_TX_CDC_DMA_TX_4,
5671 .be_hw_params_fixup = msm_be_hw_params_fixup,
5672 .ignore_suspend = 1,
5673 .ops = &msm_cdc_dma_be_ops,
5674 },
5675};
5676
Xiaoyu Ye2228bf02018-12-12 15:47:20 -08005677static struct snd_soc_dai_link msm_va_cdc_dma_be_dai_links[] = {
5678 {
5679 .name = LPASS_BE_VA_CDC_DMA_TX_0,
5680 .stream_name = "VA CDC DMA0 Capture",
5681 .cpu_dai_name = "msm-dai-cdc-dma-dev.45089",
5682 .platform_name = "msm-pcm-routing",
5683 .codec_name = "bolero_codec",
5684 .codec_dai_name = "va_macro_tx1",
5685 .no_pcm = 1,
5686 .dpcm_capture = 1,
5687 .id = MSM_BACKEND_DAI_VA_CDC_DMA_TX_0,
5688 .be_hw_params_fixup = msm_be_hw_params_fixup,
5689 .ignore_suspend = 1,
5690 .ops = &msm_cdc_dma_be_ops,
5691 },
5692 {
5693 .name = LPASS_BE_VA_CDC_DMA_TX_1,
5694 .stream_name = "VA CDC DMA1 Capture",
5695 .cpu_dai_name = "msm-dai-cdc-dma-dev.45091",
5696 .platform_name = "msm-pcm-routing",
5697 .codec_name = "bolero_codec",
5698 .codec_dai_name = "va_macro_tx2",
5699 .no_pcm = 1,
5700 .dpcm_capture = 1,
5701 .id = MSM_BACKEND_DAI_VA_CDC_DMA_TX_1,
5702 .be_hw_params_fixup = msm_be_hw_params_fixup,
5703 .ignore_suspend = 1,
5704 .ops = &msm_cdc_dma_be_ops,
5705 },
5706 {
5707 .name = LPASS_BE_VA_CDC_DMA_TX_2,
5708 .stream_name = "VA CDC DMA2 Capture",
5709 .cpu_dai_name = "msm-dai-cdc-dma-dev.45093",
5710 .platform_name = "msm-pcm-routing",
5711 .codec_name = "bolero_codec",
5712 .codec_dai_name = "va_macro_tx3",
5713 .no_pcm = 1,
5714 .dpcm_capture = 1,
5715 .id = MSM_BACKEND_DAI_VA_CDC_DMA_TX_2,
5716 .be_hw_params_fixup = msm_be_hw_params_fixup,
5717 .ignore_suspend = 1,
5718 .ops = &msm_cdc_dma_be_ops,
5719 },
5720};
5721
Meng Wange8e53822019-03-18 10:49:50 +08005722static struct snd_soc_dai_link msm_afe_rxtx_lb_be_dai_link[] = {
5723 {
5724 .name = LPASS_BE_AFE_LOOPBACK_TX,
5725 .stream_name = "AFE Loopback Capture",
5726 .cpu_dai_name = "msm-dai-q6-dev.24577",
5727 .platform_name = "msm-pcm-routing",
5728 .codec_name = "msm-stub-codec.1",
5729 .codec_dai_name = "msm-stub-tx",
5730 .no_pcm = 1,
5731 .dpcm_capture = 1,
5732 .id = MSM_BACKEND_DAI_AFE_LOOPBACK_TX,
5733 .be_hw_params_fixup = msm_be_hw_params_fixup,
5734 .ignore_pmdown_time = 1,
5735 .ignore_suspend = 1,
5736 },
5737};
5738
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07005739static struct snd_soc_dai_link msm_kona_dai_links[
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07005740 ARRAY_SIZE(msm_common_dai_links) +
5741 ARRAY_SIZE(msm_bolero_fe_dai_links) +
5742 ARRAY_SIZE(msm_common_misc_fe_dai_links) +
5743 ARRAY_SIZE(msm_common_be_dai_links) +
5744 ARRAY_SIZE(msm_mi2s_be_dai_links) +
5745 ARRAY_SIZE(msm_auxpcm_be_dai_links) +
5746 ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links) +
Xiaoyu Ye2228bf02018-12-12 15:47:20 -08005747 ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links) +
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -08005748 ARRAY_SIZE(msm_va_cdc_dma_be_dai_links) +
5749 ARRAY_SIZE(ext_disp_be_dai_link) +
Meng Wange8e53822019-03-18 10:49:50 +08005750 ARRAY_SIZE(msm_wcn_be_dai_links) +
Vatsal Bucha82b30ba2019-04-17 12:43:54 +05305751 ARRAY_SIZE(msm_afe_rxtx_lb_be_dai_link) +
5752 ARRAY_SIZE(msm_wcn_btfm_be_dai_links)];
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07005753
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07005754static int msm_populate_dai_link_component_of_node(
5755 struct snd_soc_card *card)
5756{
5757 int i, index, ret = 0;
5758 struct device *cdev = card->dev;
5759 struct snd_soc_dai_link *dai_link = card->dai_link;
5760 struct device_node *np;
5761
5762 if (!cdev) {
5763 dev_err(cdev, "%s: Sound card device memory NULL\n", __func__);
5764 return -ENODEV;
5765 }
5766
5767 for (i = 0; i < card->num_links; i++) {
5768 if (dai_link[i].platform_of_node && dai_link[i].cpu_of_node)
5769 continue;
5770
5771 /* populate platform_of_node for snd card dai links */
5772 if (dai_link[i].platform_name &&
5773 !dai_link[i].platform_of_node) {
5774 index = of_property_match_string(cdev->of_node,
5775 "asoc-platform-names",
5776 dai_link[i].platform_name);
5777 if (index < 0) {
5778 dev_err(cdev, "%s: No match found for platform name: %s\n",
5779 __func__, dai_link[i].platform_name);
5780 ret = index;
5781 goto err;
5782 }
5783 np = of_parse_phandle(cdev->of_node, "asoc-platform",
5784 index);
5785 if (!np) {
5786 dev_err(cdev, "%s: retrieving phandle for platform %s, index %d failed\n",
5787 __func__, dai_link[i].platform_name,
5788 index);
5789 ret = -ENODEV;
5790 goto err;
5791 }
5792 dai_link[i].platform_of_node = np;
5793 dai_link[i].platform_name = NULL;
5794 }
5795
5796 /* populate cpu_of_node for snd card dai links */
5797 if (dai_link[i].cpu_dai_name && !dai_link[i].cpu_of_node) {
5798 index = of_property_match_string(cdev->of_node,
5799 "asoc-cpu-names",
5800 dai_link[i].cpu_dai_name);
5801 if (index >= 0) {
5802 np = of_parse_phandle(cdev->of_node, "asoc-cpu",
5803 index);
5804 if (!np) {
5805 dev_err(cdev, "%s: retrieving phandle for cpu dai %s failed\n",
5806 __func__,
5807 dai_link[i].cpu_dai_name);
5808 ret = -ENODEV;
5809 goto err;
5810 }
5811 dai_link[i].cpu_of_node = np;
5812 dai_link[i].cpu_dai_name = NULL;
5813 }
5814 }
5815
5816 /* populate codec_of_node for snd card dai links */
5817 if (dai_link[i].codec_name && !dai_link[i].codec_of_node) {
5818 index = of_property_match_string(cdev->of_node,
5819 "asoc-codec-names",
5820 dai_link[i].codec_name);
5821 if (index < 0)
5822 continue;
5823 np = of_parse_phandle(cdev->of_node, "asoc-codec",
5824 index);
5825 if (!np) {
5826 dev_err(cdev, "%s: retrieving phandle for codec %s failed\n",
5827 __func__, dai_link[i].codec_name);
5828 ret = -ENODEV;
5829 goto err;
5830 }
5831 dai_link[i].codec_of_node = np;
5832 dai_link[i].codec_name = NULL;
5833 }
5834 }
5835
5836err:
5837 return ret;
5838}
5839
5840static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
5841{
5842 int ret = -EINVAL;
5843 struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, "msm-stub-codec");
5844
5845 if (!component) {
5846 pr_err("* %s: No match for msm-stub-codec component\n", __func__);
5847 return ret;
5848 }
5849
5850 ret = snd_soc_add_component_controls(component, msm_snd_controls,
5851 ARRAY_SIZE(msm_snd_controls));
5852 if (ret < 0) {
5853 dev_err(component->dev,
5854 "%s: add_codec_controls failed, err = %d\n",
5855 __func__, ret);
5856 return ret;
5857 }
5858
5859 return ret;
5860}
5861
5862static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
5863 struct snd_pcm_hw_params *params)
5864{
5865 return 0;
5866}
5867
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07005868static struct snd_soc_ops msm_stub_be_ops = {
5869 .hw_params = msm_snd_stub_hw_params,
5870};
5871
5872struct snd_soc_card snd_soc_card_stub_msm = {
5873 .name = "kona-stub-snd-card",
5874};
5875
5876static struct snd_soc_dai_link msm_stub_fe_dai_links[] = {
5877 /* FrontEnd DAI Links */
5878 {
5879 .name = "MSMSTUB Media1",
5880 .stream_name = "MultiMedia1",
5881 .cpu_dai_name = "MultiMedia1",
5882 .platform_name = "msm-pcm-dsp.0",
5883 .dynamic = 1,
5884 .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
5885 .dpcm_playback = 1,
5886 .dpcm_capture = 1,
5887 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
5888 SND_SOC_DPCM_TRIGGER_POST},
5889 .codec_dai_name = "snd-soc-dummy-dai",
5890 .codec_name = "snd-soc-dummy",
5891 .ignore_suspend = 1,
5892 /* this dainlink has playback support */
5893 .ignore_pmdown_time = 1,
5894 .id = MSM_FRONTEND_DAI_MULTIMEDIA1
5895 },
5896};
5897
5898static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
5899 /* Backend DAI Links */
5900 {
5901 .name = LPASS_BE_AUXPCM_RX,
5902 .stream_name = "AUX PCM Playback",
5903 .cpu_dai_name = "msm-dai-q6-auxpcm.1",
5904 .platform_name = "msm-pcm-routing",
5905 .codec_name = "msm-stub-codec.1",
5906 .codec_dai_name = "msm-stub-rx",
5907 .no_pcm = 1,
5908 .dpcm_playback = 1,
5909 .id = MSM_BACKEND_DAI_AUXPCM_RX,
5910 .init = &msm_audrx_stub_init,
5911 .be_hw_params_fixup = msm_be_hw_params_fixup,
5912 .ignore_pmdown_time = 1,
5913 .ignore_suspend = 1,
5914 .ops = &msm_stub_be_ops,
5915 },
5916 {
5917 .name = LPASS_BE_AUXPCM_TX,
5918 .stream_name = "AUX PCM Capture",
5919 .cpu_dai_name = "msm-dai-q6-auxpcm.1",
5920 .platform_name = "msm-pcm-routing",
5921 .codec_name = "msm-stub-codec.1",
5922 .codec_dai_name = "msm-stub-tx",
5923 .no_pcm = 1,
5924 .dpcm_capture = 1,
5925 .id = MSM_BACKEND_DAI_AUXPCM_TX,
5926 .be_hw_params_fixup = msm_be_hw_params_fixup,
5927 .ignore_suspend = 1,
5928 .ops = &msm_stub_be_ops,
5929 },
5930};
5931
5932static struct snd_soc_dai_link msm_stub_dai_links[
5933 ARRAY_SIZE(msm_stub_fe_dai_links) +
5934 ARRAY_SIZE(msm_stub_be_dai_links)];
5935
5936static const struct of_device_id kona_asoc_machine_of_match[] = {
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07005937 { .compatible = "qcom,kona-asoc-snd",
5938 .data = "codec"},
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07005939 { .compatible = "qcom,kona-asoc-snd-stub",
5940 .data = "stub_codec"},
5941 {},
5942};
5943
5944static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev)
5945{
5946 struct snd_soc_card *card = NULL;
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07005947 struct snd_soc_dai_link *dailink = NULL;
5948 int len_1 = 0;
5949 int len_2 = 0;
5950 int total_links = 0;
5951 int rc = 0;
5952 u32 mi2s_audio_intf = 0;
5953 u32 auxpcm_audio_intf = 0;
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -08005954 u32 val = 0;
Vatsal Bucha82b30ba2019-04-17 12:43:54 +05305955 u32 wcn_btfm_intf = 0;
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07005956 const struct of_device_id *match;
5957
5958 match = of_match_node(kona_asoc_machine_of_match, dev->of_node);
5959 if (!match) {
5960 dev_err(dev, "%s: No DT match found for sound card\n",
5961 __func__);
5962 return NULL;
5963 }
5964
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07005965 if (!strcmp(match->data, "codec")) {
5966 card = &snd_soc_card_kona_msm;
5967
5968 memcpy(msm_kona_dai_links + total_links,
5969 msm_common_dai_links,
5970 sizeof(msm_common_dai_links));
5971 total_links += ARRAY_SIZE(msm_common_dai_links);
5972
5973 memcpy(msm_kona_dai_links + total_links,
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07005974 msm_bolero_fe_dai_links,
5975 sizeof(msm_bolero_fe_dai_links));
5976 total_links +=
5977 ARRAY_SIZE(msm_bolero_fe_dai_links);
5978
5979 memcpy(msm_kona_dai_links + total_links,
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07005980 msm_common_misc_fe_dai_links,
5981 sizeof(msm_common_misc_fe_dai_links));
5982 total_links += ARRAY_SIZE(msm_common_misc_fe_dai_links);
5983
5984 memcpy(msm_kona_dai_links + total_links,
5985 msm_common_be_dai_links,
5986 sizeof(msm_common_be_dai_links));
5987 total_links += ARRAY_SIZE(msm_common_be_dai_links);
5988
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07005989 memcpy(msm_kona_dai_links + total_links,
5990 msm_wsa_cdc_dma_be_dai_links,
5991 sizeof(msm_wsa_cdc_dma_be_dai_links));
5992 total_links +=
5993 ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links);
5994
5995 memcpy(msm_kona_dai_links + total_links,
5996 msm_rx_tx_cdc_dma_be_dai_links,
5997 sizeof(msm_rx_tx_cdc_dma_be_dai_links));
5998 total_links +=
5999 ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links);
6000
Xiaoyu Ye2228bf02018-12-12 15:47:20 -08006001 memcpy(msm_kona_dai_links + total_links,
6002 msm_va_cdc_dma_be_dai_links,
6003 sizeof(msm_va_cdc_dma_be_dai_links));
6004 total_links +=
6005 ARRAY_SIZE(msm_va_cdc_dma_be_dai_links);
6006
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07006007 rc = of_property_read_u32(dev->of_node, "qcom,mi2s-audio-intf",
6008 &mi2s_audio_intf);
6009 if (rc) {
6010 dev_dbg(dev, "%s: No DT match MI2S audio interface\n",
6011 __func__);
6012 } else {
6013 if (mi2s_audio_intf) {
6014 memcpy(msm_kona_dai_links + total_links,
6015 msm_mi2s_be_dai_links,
6016 sizeof(msm_mi2s_be_dai_links));
6017 total_links +=
6018 ARRAY_SIZE(msm_mi2s_be_dai_links);
6019 }
6020 }
6021
6022 rc = of_property_read_u32(dev->of_node,
6023 "qcom,auxpcm-audio-intf",
6024 &auxpcm_audio_intf);
6025 if (rc) {
6026 dev_dbg(dev, "%s: No DT match Aux PCM interface\n",
6027 __func__);
6028 } else {
6029 if (auxpcm_audio_intf) {
6030 memcpy(msm_kona_dai_links + total_links,
6031 msm_auxpcm_be_dai_links,
6032 sizeof(msm_auxpcm_be_dai_links));
6033 total_links +=
6034 ARRAY_SIZE(msm_auxpcm_be_dai_links);
6035 }
6036 }
6037
Karthikeyan Manieaad2ed2018-12-26 11:47:26 -08006038 rc = of_property_read_u32(dev->of_node,
6039 "qcom,ext-disp-audio-rx", &val);
6040 if (!rc && val) {
6041 dev_dbg(dev, "%s(): ext disp audio support present\n",
6042 __func__);
6043 memcpy(msm_kona_dai_links + total_links,
6044 ext_disp_be_dai_link,
6045 sizeof(ext_disp_be_dai_link));
6046 total_links += ARRAY_SIZE(ext_disp_be_dai_link);
6047 }
6048
6049 rc = of_property_read_u32(dev->of_node, "qcom,wcn-bt", &val);
6050 if (!rc && val) {
6051 dev_dbg(dev, "%s(): WCN BT support present\n",
6052 __func__);
6053 memcpy(msm_kona_dai_links + total_links,
6054 msm_wcn_be_dai_links,
6055 sizeof(msm_wcn_be_dai_links));
6056 total_links += ARRAY_SIZE(msm_wcn_be_dai_links);
6057 }
6058
Meng Wange8e53822019-03-18 10:49:50 +08006059 rc = of_property_read_u32(dev->of_node, "qcom,afe-rxtx-lb",
6060 &val);
6061 if (!rc && val) {
6062 memcpy(msm_kona_dai_links + total_links,
6063 msm_afe_rxtx_lb_be_dai_link,
6064 sizeof(msm_afe_rxtx_lb_be_dai_link));
6065 total_links +=
6066 ARRAY_SIZE(msm_afe_rxtx_lb_be_dai_link);
6067 }
Vatsal Bucha82b30ba2019-04-17 12:43:54 +05306068
6069 rc = of_property_read_u32(dev->of_node, "qcom,wcn-btfm",
6070 &wcn_btfm_intf);
6071 if (rc) {
6072 dev_dbg(dev, "%s: No DT match wcn btfm interface\n",
6073 __func__);
6074 } else {
6075 if (wcn_btfm_intf) {
6076 memcpy(msm_kona_dai_links + total_links,
6077 msm_wcn_btfm_be_dai_links,
6078 sizeof(msm_wcn_btfm_be_dai_links));
6079 total_links +=
6080 ARRAY_SIZE(msm_wcn_btfm_be_dai_links);
6081 }
6082 }
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07006083 dailink = msm_kona_dai_links;
6084 } else if(!strcmp(match->data, "stub_codec")) {
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07006085 card = &snd_soc_card_stub_msm;
6086 len_1 = ARRAY_SIZE(msm_stub_fe_dai_links);
6087 len_2 = len_1 + ARRAY_SIZE(msm_stub_be_dai_links);
6088
6089 memcpy(msm_stub_dai_links,
6090 msm_stub_fe_dai_links,
6091 sizeof(msm_stub_fe_dai_links));
6092 memcpy(msm_stub_dai_links + len_1,
6093 msm_stub_be_dai_links,
6094 sizeof(msm_stub_be_dai_links));
6095
6096 dailink = msm_stub_dai_links;
6097 total_links = len_2;
6098 }
6099
6100 if (card) {
6101 card->dai_link = dailink;
6102 card->num_links = total_links;
6103 }
6104
6105 return card;
6106}
6107
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07006108static int msm_wsa881x_init(struct snd_soc_component *component)
6109{
6110 u8 spkleft_ports[WSA881X_MAX_SWR_PORTS] = {0, 1, 2, 3};
6111 u8 spkright_ports[WSA881X_MAX_SWR_PORTS] = {0, 1, 2, 3};
6112 u8 spkleft_port_types[WSA881X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
6113 SPKR_L_BOOST, SPKR_L_VI};
6114 u8 spkright_port_types[WSA881X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
6115 SPKR_R_BOOST, SPKR_R_VI};
6116 unsigned int ch_rate[WSA881X_MAX_SWR_PORTS] = {2400, 600, 300, 1200};
6117 unsigned int ch_mask[WSA881X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
6118 struct msm_asoc_mach_data *pdata;
6119 struct snd_soc_dapm_context *dapm;
6120 struct snd_card *card;
6121 struct snd_info_entry *entry;
6122 int ret = 0;
6123
6124 if (!component) {
6125 pr_err("%s component is NULL\n", __func__);
6126 return -EINVAL;
6127 }
6128
6129 card = component->card->snd_card;
6130 dapm = snd_soc_component_get_dapm(component);
6131
6132 if (!strcmp(component->name_prefix, "SpkrLeft")) {
6133 dev_dbg(component->dev, "%s: setting left ch map to codec %s\n",
6134 __func__, component->name);
6135 wsa881x_set_channel_map(component, &spkleft_ports[0],
6136 WSA881X_MAX_SWR_PORTS, &ch_mask[0],
6137 &ch_rate[0], &spkleft_port_types[0]);
6138 if (dapm->component) {
6139 snd_soc_dapm_ignore_suspend(dapm, "SpkrLeft IN");
6140 snd_soc_dapm_ignore_suspend(dapm, "SpkrLeft SPKR");
6141 }
6142 } else if (!strcmp(component->name_prefix, "SpkrRight")) {
6143 dev_dbg(component->dev, "%s: setting right ch map to codec %s\n",
6144 __func__, component->name);
6145 wsa881x_set_channel_map(component, &spkright_ports[0],
6146 WSA881X_MAX_SWR_PORTS, &ch_mask[0],
6147 &ch_rate[0], &spkright_port_types[0]);
6148 if (dapm->component) {
6149 snd_soc_dapm_ignore_suspend(dapm, "SpkrRight IN");
6150 snd_soc_dapm_ignore_suspend(dapm, "SpkrRight SPKR");
6151 }
6152 } else {
6153 dev_err(component->dev, "%s: wrong codec name %s\n", __func__,
6154 component->name);
6155 ret = -EINVAL;
6156 goto err;
6157 }
6158 pdata = snd_soc_card_get_drvdata(component->card);
6159 if (!pdata->codec_root) {
6160 entry = snd_info_create_subdir(card->module, "codecs",
6161 card->proc_root);
6162 if (!entry) {
6163 pr_err("%s: Cannot create codecs module entry\n",
6164 __func__);
6165 ret = 0;
6166 goto err;
6167 }
6168 pdata->codec_root = entry;
6169 }
6170 wsa881x_codec_info_create_codec_entry(pdata->codec_root,
6171 component);
6172err:
6173 return ret;
6174}
6175
6176static int msm_aux_codec_init(struct snd_soc_component *component)
6177{
6178 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
6179 int ret = 0;
Karthikeyan Mani5eb13422018-11-05 13:49:17 -08006180 void *mbhc_calibration;
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07006181 struct snd_info_entry *entry;
6182 struct snd_card *card = component->card->snd_card;
6183 struct msm_asoc_mach_data *pdata;
6184
6185 snd_soc_dapm_ignore_suspend(dapm, "EAR");
6186 snd_soc_dapm_ignore_suspend(dapm, "AUX");
6187 snd_soc_dapm_ignore_suspend(dapm, "HPHL");
6188 snd_soc_dapm_ignore_suspend(dapm, "HPHR");
6189 snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
6190 snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
6191 snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
6192 snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
6193 snd_soc_dapm_sync(dapm);
6194
6195 pdata = snd_soc_card_get_drvdata(component->card);
6196 if (!pdata->codec_root) {
6197 entry = snd_info_create_subdir(card->module, "codecs",
6198 card->proc_root);
6199 if (!entry) {
Karthikeyan Mani5eb13422018-11-05 13:49:17 -08006200 dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07006201 __func__);
6202 ret = 0;
Karthikeyan Mani5eb13422018-11-05 13:49:17 -08006203 goto mbhc_cfg_cal;
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07006204 }
6205 pdata->codec_root = entry;
6206 }
Karthikeyan Mani5eb13422018-11-05 13:49:17 -08006207 wcd938x_info_create_codec_entry(pdata->codec_root, component);
6208
6209mbhc_cfg_cal:
6210 mbhc_calibration = def_wcd_mbhc_cal();
6211 if (!mbhc_calibration)
6212 return -ENOMEM;
6213 wcd_mbhc_cfg.calibration = mbhc_calibration;
6214 ret = wcd938x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
6215 if (ret) {
6216 dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
6217 __func__, ret);
6218 goto err_hs_detect;
6219 }
6220 return 0;
6221
6222err_hs_detect:
6223 kfree(mbhc_calibration);
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07006224 return ret;
6225}
6226
6227static int msm_init_aux_dev(struct platform_device *pdev,
6228 struct snd_soc_card *card)
6229{
6230 struct device_node *wsa_of_node;
6231 struct device_node *aux_codec_of_node;
6232 u32 wsa_max_devs;
6233 u32 wsa_dev_cnt;
6234 u32 codec_aux_dev_cnt = 0;
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07006235 int i;
6236 struct msm_wsa881x_dev_info *wsa881x_dev_info;
6237 struct aux_codec_dev_info *aux_cdc_dev_info;
6238 const char *auxdev_name_prefix[1];
6239 char *dev_name_str = NULL;
6240 int found = 0;
6241 int codecs_found = 0;
6242 int ret = 0;
6243
6244 /* Get maximum WSA device count for this platform */
6245 ret = of_property_read_u32(pdev->dev.of_node,
6246 "qcom,wsa-max-devs", &wsa_max_devs);
6247 if (ret) {
6248 dev_info(&pdev->dev,
6249 "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
6250 __func__, pdev->dev.of_node->full_name, ret);
6251 wsa_max_devs = 0;
6252 goto codec_aux_dev;
6253 }
6254 if (wsa_max_devs == 0) {
6255 dev_warn(&pdev->dev,
6256 "%s: Max WSA devices is 0 for this target?\n",
6257 __func__);
6258 goto codec_aux_dev;
6259 }
6260
6261 /* Get count of WSA device phandles for this platform */
6262 wsa_dev_cnt = of_count_phandle_with_args(pdev->dev.of_node,
6263 "qcom,wsa-devs", NULL);
6264 if (wsa_dev_cnt == -ENOENT) {
6265 dev_warn(&pdev->dev, "%s: No wsa device defined in DT.\n",
6266 __func__);
6267 goto err;
6268 } else if (wsa_dev_cnt <= 0) {
6269 dev_err(&pdev->dev,
6270 "%s: Error reading wsa device from DT. wsa_dev_cnt = %d\n",
6271 __func__, wsa_dev_cnt);
6272 ret = -EINVAL;
6273 goto err;
6274 }
6275
6276 /*
6277 * Expect total phandles count to be NOT less than maximum possible
6278 * WSA count. However, if it is less, then assign same value to
6279 * max count as well.
6280 */
6281 if (wsa_dev_cnt < wsa_max_devs) {
6282 dev_dbg(&pdev->dev,
6283 "%s: wsa_max_devs = %d cannot exceed wsa_dev_cnt = %d\n",
6284 __func__, wsa_max_devs, wsa_dev_cnt);
6285 wsa_max_devs = wsa_dev_cnt;
6286 }
6287
6288 /* Make sure prefix string passed for each WSA device */
6289 ret = of_property_count_strings(pdev->dev.of_node,
6290 "qcom,wsa-aux-dev-prefix");
6291 if (ret != wsa_dev_cnt) {
6292 dev_err(&pdev->dev,
6293 "%s: expecting %d wsa prefix. Defined only %d in DT\n",
6294 __func__, wsa_dev_cnt, ret);
6295 ret = -EINVAL;
6296 goto err;
6297 }
6298
6299 /*
6300 * Alloc mem to store phandle and index info of WSA device, if already
6301 * registered with ALSA core
6302 */
6303 wsa881x_dev_info = devm_kcalloc(&pdev->dev, wsa_max_devs,
6304 sizeof(struct msm_wsa881x_dev_info),
6305 GFP_KERNEL);
6306 if (!wsa881x_dev_info) {
6307 ret = -ENOMEM;
6308 goto err;
6309 }
6310
6311 /*
6312 * search and check whether all WSA devices are already
6313 * registered with ALSA core or not. If found a node, store
6314 * the node and the index in a local array of struct for later
6315 * use.
6316 */
6317 for (i = 0; i < wsa_dev_cnt; i++) {
6318 wsa_of_node = of_parse_phandle(pdev->dev.of_node,
6319 "qcom,wsa-devs", i);
6320 if (unlikely(!wsa_of_node)) {
6321 /* we should not be here */
6322 dev_err(&pdev->dev,
6323 "%s: wsa dev node is not present\n",
6324 __func__);
6325 ret = -EINVAL;
6326 goto err;
6327 }
6328 if (soc_find_component(wsa_of_node, NULL)) {
6329 /* WSA device registered with ALSA core */
6330 wsa881x_dev_info[found].of_node = wsa_of_node;
6331 wsa881x_dev_info[found].index = i;
6332 found++;
6333 if (found == wsa_max_devs)
6334 break;
6335 }
6336 }
6337
6338 if (found < wsa_max_devs) {
6339 dev_dbg(&pdev->dev,
6340 "%s: failed to find %d components. Found only %d\n",
6341 __func__, wsa_max_devs, found);
6342 return -EPROBE_DEFER;
6343 }
6344 dev_info(&pdev->dev,
6345 "%s: found %d wsa881x devices registered with ALSA core\n",
6346 __func__, found);
6347
6348codec_aux_dev:
Karthikeyan Mani1a111b92019-02-12 21:35:31 -08006349 /* Get count of aux codec device phandles for this platform */
6350 codec_aux_dev_cnt = of_count_phandle_with_args(
6351 pdev->dev.of_node,
6352 "qcom,codec-aux-devs", NULL);
6353 if (codec_aux_dev_cnt == -ENOENT) {
6354 dev_warn(&pdev->dev, "%s: No aux codec defined in DT.\n",
6355 __func__);
6356 goto err;
6357 } else if (codec_aux_dev_cnt <= 0) {
6358 dev_err(&pdev->dev,
6359 "%s: Error reading aux codec device from DT, dev_cnt=%d\n",
6360 __func__, codec_aux_dev_cnt);
6361 ret = -EINVAL;
6362 goto err;
6363 }
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07006364
Karthikeyan Mani1a111b92019-02-12 21:35:31 -08006365 /*
6366 * Alloc mem to store phandle and index info of aux codec
6367 * if already registered with ALSA core
6368 */
6369 aux_cdc_dev_info = devm_kcalloc(&pdev->dev, codec_aux_dev_cnt,
6370 sizeof(struct aux_codec_dev_info),
6371 GFP_KERNEL);
6372 if (!aux_cdc_dev_info) {
6373 ret = -ENOMEM;
6374 goto err;
6375 }
6376
6377 /*
6378 * search and check whether all aux codecs are already
6379 * registered with ALSA core or not. If found a node, store
6380 * the node and the index in a local array of struct for later
6381 * use.
6382 */
6383 for (i = 0; i < codec_aux_dev_cnt; i++) {
6384 aux_codec_of_node = of_parse_phandle(pdev->dev.of_node,
6385 "qcom,codec-aux-devs", i);
6386 if (unlikely(!aux_codec_of_node)) {
6387 /* we should not be here */
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07006388 dev_err(&pdev->dev,
Karthikeyan Mani1a111b92019-02-12 21:35:31 -08006389 "%s: aux codec dev node is not present\n",
6390 __func__);
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07006391 ret = -EINVAL;
6392 goto err;
6393 }
Karthikeyan Mani1a111b92019-02-12 21:35:31 -08006394 if (soc_find_component(aux_codec_of_node, NULL)) {
6395 /* AUX codec registered with ALSA core */
6396 aux_cdc_dev_info[codecs_found].of_node =
6397 aux_codec_of_node;
6398 aux_cdc_dev_info[codecs_found].index = i;
6399 codecs_found++;
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07006400 }
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07006401 }
6402
Karthikeyan Mani1a111b92019-02-12 21:35:31 -08006403 if (codecs_found < codec_aux_dev_cnt) {
6404 dev_dbg(&pdev->dev,
6405 "%s: failed to find %d components. Found only %d\n",
6406 __func__, codec_aux_dev_cnt, codecs_found);
6407 return -EPROBE_DEFER;
6408 }
6409 dev_info(&pdev->dev,
6410 "%s: found %d AUX codecs registered with ALSA core\n",
6411 __func__, codecs_found);
6412
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07006413 card->num_aux_devs = wsa_max_devs + codec_aux_dev_cnt;
6414 card->num_configs = wsa_max_devs + codec_aux_dev_cnt;
6415
6416 /* Alloc array of AUX devs struct */
6417 msm_aux_dev = devm_kcalloc(&pdev->dev, card->num_aux_devs,
6418 sizeof(struct snd_soc_aux_dev),
6419 GFP_KERNEL);
6420 if (!msm_aux_dev) {
6421 ret = -ENOMEM;
6422 goto err;
6423 }
6424
6425 /* Alloc array of codec conf struct */
6426 msm_codec_conf = devm_kcalloc(&pdev->dev, card->num_configs,
6427 sizeof(struct snd_soc_codec_conf),
6428 GFP_KERNEL);
6429 if (!msm_codec_conf) {
6430 ret = -ENOMEM;
6431 goto err;
6432 }
6433
6434 for (i = 0; i < wsa_max_devs; i++) {
6435 dev_name_str = devm_kzalloc(&pdev->dev, DEV_NAME_STR_LEN,
6436 GFP_KERNEL);
6437 if (!dev_name_str) {
6438 ret = -ENOMEM;
6439 goto err;
6440 }
6441
6442 ret = of_property_read_string_index(pdev->dev.of_node,
6443 "qcom,wsa-aux-dev-prefix",
6444 wsa881x_dev_info[i].index,
6445 auxdev_name_prefix);
6446 if (ret) {
6447 dev_err(&pdev->dev,
6448 "%s: failed to read wsa aux dev prefix, ret = %d\n",
6449 __func__, ret);
6450 ret = -EINVAL;
6451 goto err;
6452 }
6453
6454 snprintf(dev_name_str, strlen("wsa881x.%d"), "wsa881x.%d", i);
6455 msm_aux_dev[i].name = dev_name_str;
6456 msm_aux_dev[i].codec_name = NULL;
6457 msm_aux_dev[i].codec_of_node =
6458 wsa881x_dev_info[i].of_node;
6459 msm_aux_dev[i].init = msm_wsa881x_init;
6460 msm_codec_conf[i].dev_name = NULL;
6461 msm_codec_conf[i].name_prefix = auxdev_name_prefix[0];
6462 msm_codec_conf[i].of_node =
6463 wsa881x_dev_info[i].of_node;
6464 }
6465
6466 for (i = 0; i < codec_aux_dev_cnt; i++) {
6467 msm_aux_dev[wsa_max_devs + i].name = NULL;
6468 msm_aux_dev[wsa_max_devs + i].codec_name = NULL;
6469 msm_aux_dev[wsa_max_devs + i].codec_of_node =
6470 aux_cdc_dev_info[i].of_node;
6471 msm_aux_dev[wsa_max_devs + i].init = msm_aux_codec_init;
6472 msm_codec_conf[wsa_max_devs + i].dev_name = NULL;
6473 msm_codec_conf[wsa_max_devs + i].name_prefix =
6474 NULL;
6475 msm_codec_conf[wsa_max_devs + i].of_node =
6476 aux_cdc_dev_info[i].of_node;
6477 }
6478
6479 card->codec_conf = msm_codec_conf;
6480 card->aux_dev = msm_aux_dev;
6481err:
6482 return ret;
6483}
6484
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07006485static void msm_i2s_auxpcm_init(struct platform_device *pdev)
6486{
6487 int count = 0;
6488 u32 mi2s_master_slave[MI2S_MAX];
6489 int ret = 0;
6490
6491 for (count = 0; count < MI2S_MAX; count++) {
6492 mutex_init(&mi2s_intf_conf[count].lock);
6493 mi2s_intf_conf[count].ref_cnt = 0;
6494 }
6495
6496 ret = of_property_read_u32_array(pdev->dev.of_node,
6497 "qcom,msm-mi2s-master",
6498 mi2s_master_slave, MI2S_MAX);
6499 if (ret) {
6500 dev_dbg(&pdev->dev, "%s: no qcom,msm-mi2s-master in DT node\n",
6501 __func__);
6502 } else {
6503 for (count = 0; count < MI2S_MAX; count++) {
6504 mi2s_intf_conf[count].msm_is_mi2s_master =
6505 mi2s_master_slave[count];
6506 }
6507 }
6508}
6509
6510static void msm_i2s_auxpcm_deinit(void)
6511{
6512 int count = 0;
6513
6514 for (count = 0; count < MI2S_MAX; count++) {
6515 mutex_destroy(&mi2s_intf_conf[count].lock);
6516 mi2s_intf_conf[count].ref_cnt = 0;
6517 mi2s_intf_conf[count].msm_is_mi2s_master = 0;
6518 }
6519}
6520
6521static int kona_ssr_enable(struct device *dev, void *data)
6522{
6523 struct platform_device *pdev = to_platform_device(dev);
6524 struct snd_soc_card *card = platform_get_drvdata(pdev);
6525 int ret = 0;
6526
6527 if (!card) {
6528 dev_err(dev, "%s: card is NULL\n", __func__);
6529 ret = -EINVAL;
6530 goto err;
6531 }
6532
6533 if (!strcmp(card->name, "kona-stub-snd-card")) {
6534 /* TODO */
6535 dev_dbg(dev, "%s: TODO \n", __func__);
6536 }
6537
6538 snd_soc_card_change_online_state(card, 1);
6539 dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
6540
6541err:
6542 return ret;
6543}
6544
6545static void kona_ssr_disable(struct device *dev, void *data)
6546{
6547 struct platform_device *pdev = to_platform_device(dev);
6548 struct snd_soc_card *card = platform_get_drvdata(pdev);
6549
6550 if (!card) {
6551 dev_err(dev, "%s: card is NULL\n", __func__);
6552 return;
6553 }
6554
6555 dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
6556 snd_soc_card_change_online_state(card, 0);
6557
6558 if (!strcmp(card->name, "kona-stub-snd-card")) {
6559 /* TODO */
6560 dev_dbg(dev, "%s: TODO \n", __func__);
6561 }
6562}
6563
6564static const struct snd_event_ops kona_ssr_ops = {
6565 .enable = kona_ssr_enable,
6566 .disable = kona_ssr_disable,
6567};
6568
6569static int msm_audio_ssr_compare(struct device *dev, void *data)
6570{
6571 struct device_node *node = data;
6572
6573 dev_dbg(dev, "%s: dev->of_node = 0x%p, node = 0x%p\n",
6574 __func__, dev->of_node, node);
6575 return (dev->of_node && dev->of_node == node);
6576}
6577
6578static int msm_audio_ssr_register(struct device *dev)
6579{
6580 struct device_node *np = dev->of_node;
6581 struct snd_event_clients *ssr_clients = NULL;
6582 struct device_node *node = NULL;
6583 int ret = 0;
6584 int i = 0;
6585
6586 for (i = 0; ; i++) {
6587 node = of_parse_phandle(np, "qcom,msm_audio_ssr_devs", i);
6588 if (!node)
6589 break;
6590 snd_event_mstr_add_client(&ssr_clients,
6591 msm_audio_ssr_compare, node);
6592 }
6593
6594 ret = snd_event_master_register(dev, &kona_ssr_ops,
6595 ssr_clients, NULL);
6596 if (!ret)
6597 snd_event_notify(dev, SND_EVENT_UP);
6598
6599 return ret;
6600}
6601
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07006602static int msm_asoc_machine_probe(struct platform_device *pdev)
6603{
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07006604 struct snd_soc_card *card = NULL;
6605 struct msm_asoc_mach_data *pdata = NULL;
6606 const char *mbhc_audio_jack_type = NULL;
6607 int ret = 0;
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07006608
6609 if (!pdev->dev.of_node) {
6610 dev_err(&pdev->dev, "%s: No platform supplied from device tree\n", __func__);
6611 return -EINVAL;
6612 }
6613
6614 pdata = devm_kzalloc(&pdev->dev,
6615 sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
6616 if (!pdata)
6617 return -ENOMEM;
6618
6619 card = populate_snd_card_dailinks(&pdev->dev);
6620 if (!card) {
6621 dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
6622 ret = -EINVAL;
6623 goto err;
6624 }
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07006625
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07006626 card->dev = &pdev->dev;
6627 platform_set_drvdata(pdev, card);
6628 snd_soc_card_set_drvdata(card, pdata);
6629
6630 ret = snd_soc_of_parse_card_name(card, "qcom,model");
6631 if (ret) {
6632 dev_err(&pdev->dev, "%s: parse card name failed, err:%d\n",
6633 __func__, ret);
6634 goto err;
6635 }
6636
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07006637 ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
6638 if (ret) {
6639 dev_err(&pdev->dev, "%s: parse audio routing failed, err:%d\n",
6640 __func__, ret);
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07006641 goto err;
6642 }
6643
6644 ret = msm_populate_dai_link_component_of_node(card);
6645 if (ret) {
6646 ret = -EPROBE_DEFER;
6647 goto err;
6648 }
6649
Vignesh Kulothungan3e5ebbf2018-10-23 12:19:13 -07006650 ret = msm_init_aux_dev(pdev, card);
6651 if (ret)
6652 goto err;
6653
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07006654 ret = devm_snd_soc_register_card(&pdev->dev, card);
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07006655 if (ret == -EPROBE_DEFER) {
6656 if (codec_reg_done)
6657 ret = -EINVAL;
6658 goto err;
6659 } else if (ret) {
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07006660 dev_err(&pdev->dev, "%s: snd_soc_register_card failed (%d)\n",
6661 __func__, ret);
6662 goto err;
6663 }
6664 dev_info(&pdev->dev, "%s: Sound card %s registered\n",
6665 __func__, card->name);
6666
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07006667 pdata->hph_en1_gpio_p = of_parse_phandle(pdev->dev.of_node,
6668 "qcom,hph-en1-gpio", 0);
6669 if (!pdata->hph_en1_gpio_p) {
6670 dev_dbg(&pdev->dev, "%s: property %s not detected in node %s\n",
6671 __func__, "qcom,hph-en1-gpio",
6672 pdev->dev.of_node->full_name);
6673 }
6674
6675 pdata->hph_en0_gpio_p = of_parse_phandle(pdev->dev.of_node,
6676 "qcom,hph-en0-gpio", 0);
6677 if (!pdata->hph_en0_gpio_p) {
6678 dev_dbg(&pdev->dev, "%s: property %s not detected in node %s\n",
6679 __func__, "qcom,hph-en0-gpio",
6680 pdev->dev.of_node->full_name);
6681 }
6682
6683 ret = of_property_read_string(pdev->dev.of_node,
6684 "qcom,mbhc-audio-jack-type", &mbhc_audio_jack_type);
6685 if (ret) {
6686 dev_dbg(&pdev->dev, "%s: Looking up %s property in node %s failed\n",
6687 __func__, "qcom,mbhc-audio-jack-type",
6688 pdev->dev.of_node->full_name);
6689 dev_dbg(&pdev->dev, "Jack type properties set to default\n");
6690 } else {
6691 if (!strcmp(mbhc_audio_jack_type, "4-pole-jack")) {
6692 wcd_mbhc_cfg.enable_anc_mic_detect = false;
6693 dev_dbg(&pdev->dev, "This hardware has 4 pole jack");
6694 } else if (!strcmp(mbhc_audio_jack_type, "5-pole-jack")) {
6695 wcd_mbhc_cfg.enable_anc_mic_detect = true;
6696 dev_dbg(&pdev->dev, "This hardware has 5 pole jack");
6697 } else if (!strcmp(mbhc_audio_jack_type, "6-pole-jack")) {
6698 wcd_mbhc_cfg.enable_anc_mic_detect = true;
6699 dev_dbg(&pdev->dev, "This hardware has 6 pole jack");
6700 } else {
6701 wcd_mbhc_cfg.enable_anc_mic_detect = false;
6702 dev_dbg(&pdev->dev, "Unknown value, set to default\n");
6703 }
6704 }
Karthikeyan Mani5eb13422018-11-05 13:49:17 -08006705 /*
6706 * Parse US-Euro gpio info from DT. Report no error if us-euro
6707 * entry is not found in DT file as some targets do not support
6708 * US-Euro detection
6709 */
6710 pdata->us_euro_gpio_p = of_parse_phandle(pdev->dev.of_node,
6711 "qcom,us-euro-gpios", 0);
6712 if (!pdata->us_euro_gpio_p) {
6713 dev_dbg(&pdev->dev, "property %s not detected in node %s",
6714 "qcom,us-euro-gpios", pdev->dev.of_node->full_name);
6715 } else {
6716 dev_dbg(&pdev->dev, "%s detected\n",
6717 "qcom,us-euro-gpios");
6718 wcd_mbhc_cfg.swap_gnd_mic = msm_swap_gnd_mic;
6719 }
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07006720
Meng Wanga60b4082019-02-25 17:02:23 +08006721 if (wcd_mbhc_cfg.enable_usbc_analog)
6722 wcd_mbhc_cfg.swap_gnd_mic = msm_usbc_swap_gnd_mic;
6723
6724 pdata->fsa_handle = of_parse_phandle(pdev->dev.of_node,
6725 "fsa4480-i2c-handle", 0);
6726 if (!pdata->fsa_handle)
6727 dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
6728 "fsa4480-i2c-handle", pdev->dev.of_node->full_name);
6729
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07006730 msm_i2s_auxpcm_init(pdev);
Karthikeyan Mani1a111b92019-02-12 21:35:31 -08006731 pdata->dmic01_gpio_p = of_parse_phandle(pdev->dev.of_node,
6732 "qcom,cdc-dmic01-gpios",
6733 0);
6734 pdata->dmic23_gpio_p = of_parse_phandle(pdev->dev.of_node,
6735 "qcom,cdc-dmic23-gpios",
6736 0);
6737 pdata->dmic45_gpio_p = of_parse_phandle(pdev->dev.of_node,
6738 "qcom,cdc-dmic45-gpios",
6739 0);
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07006740
6741 ret = msm_audio_ssr_register(&pdev->dev);
6742 if (ret)
6743 pr_err("%s: Registration with SND event FWK failed ret = %d\n",
6744 __func__, ret);
6745
6746 is_initial_boot = true;
6747
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07006748 return 0;
6749err:
6750 devm_kfree(&pdev->dev, pdata);
6751 return ret;
6752}
6753
6754static int msm_asoc_machine_remove(struct platform_device *pdev)
6755{
6756 struct snd_soc_card *card = platform_get_drvdata(pdev);
6757
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07006758 snd_event_master_deregister(&pdev->dev);
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07006759 snd_soc_unregister_card(card);
Vignesh Kulothungan483a5592018-10-19 15:00:08 -07006760 msm_i2s_auxpcm_deinit();
6761
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07006762 return 0;
6763}
6764
6765static struct platform_driver kona_asoc_machine_driver = {
6766 .driver = {
6767 .name = DRV_NAME,
6768 .owner = THIS_MODULE,
6769 .pm = &snd_soc_pm_ops,
6770 .of_match_table = kona_asoc_machine_of_match,
Xiaojun Sang53cd13a2018-06-29 15:14:37 +08006771 .suppress_bind_attrs = true,
Vignesh Kulothungane9abcd02018-10-01 15:55:25 -07006772 },
6773 .probe = msm_asoc_machine_probe,
6774 .remove = msm_asoc_machine_remove,
6775};
6776module_platform_driver(kona_asoc_machine_driver);
6777
6778MODULE_DESCRIPTION("ALSA SoC msm");
6779MODULE_LICENSE("GPL v2");
6780MODULE_ALIAS("platform:" DRV_NAME);
6781MODULE_DEVICE_TABLE(of, kona_asoc_machine_of_match);