blob: 4b49656c0f153f1196000705b4a72b5976ca7b53 [file] [log] [blame]
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/input.h>
14#include <linux/of_gpio.h>
15#include <linux/mfd/msm-cdc-pinctrl.h>
16#include <sound/pcm_params.h>
17#include <sound/q6afe-v2.h>
18#include "qdsp6v2/msm-pcm-routing-v2.h"
19#include "msm-audio-pinctrl.h"
20#include "msmfalcon-common.h"
21#include "msmfalcon-internal.h"
22#include "msmfalcon-external.h"
Laxminath Kasame68e94f2016-12-09 12:08:00 +053023#include "../codecs/msmfalcon_cdc/msm-analog-cdc.h"
Banajit Goswami0530e2f2016-12-09 21:34:37 -080024#include "../codecs/wsa881x.h"
25
26#define DRV_NAME "msmfalcon-asoc-snd"
27
Laxminath Kasame68e94f2016-12-09 12:08:00 +053028#define MSM_INT_DIGITAL_CODEC "msm-dig-codec"
29#define PMIC_INT_ANALOG_CODEC "analog-codec"
30
Banajit Goswami0530e2f2016-12-09 21:34:37 -080031#define DEV_NAME_STR_LEN 32
32#define DEFAULT_MCLK_RATE 9600000
33
34struct dev_config {
35 u32 sample_rate;
36 u32 bit_format;
37 u32 channels;
38};
39
40/* TDM default config */
41static struct dev_config tdm_rx_cfg[TDM_INTERFACE_MAX][TDM_PORT_MAX] = {
42 { /* PRI TDM */
43 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_0 */
44 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_1 */
45 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_2 */
46 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_3 */
47 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_4 */
48 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_5 */
49 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_6 */
50 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_7 */
51 },
52 { /* SEC TDM */
53 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_0 */
54 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_1 */
55 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_2 */
56 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_3 */
57 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_4 */
58 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_5 */
59 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_6 */
60 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_7 */
61 },
62 { /* TERT TDM */
63 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_0 */
64 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_1 */
65 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_2 */
66 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_3 */
67 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_4 */
68 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_5 */
69 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_6 */
70 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_7 */
71 },
72 { /* QUAT TDM */
73 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_0 */
74 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_1 */
75 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_2 */
76 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_3 */
77 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_4 */
78 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_5 */
79 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_6 */
80 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_7 */
81 }
82};
83
84/* TDM default config */
85static struct dev_config tdm_tx_cfg[TDM_INTERFACE_MAX][TDM_PORT_MAX] = {
86 { /* PRI TDM */
87 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_0 */
88 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_1 */
89 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_2 */
90 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_3 */
91 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_4 */
92 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_5 */
93 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_6 */
94 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_7 */
95 },
96 { /* SEC TDM */
97 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_0 */
98 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_1 */
99 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_2 */
100 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_3 */
101 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_4 */
102 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_5 */
103 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_6 */
104 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_7 */
105 },
106 { /* TERT TDM */
107 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_0 */
108 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_1 */
109 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_2 */
110 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_3 */
111 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_4 */
112 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_5 */
113 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_6 */
114 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_7 */
115 },
116 { /* QUAT TDM */
117 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_0 */
118 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_1 */
119 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_2 */
120 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_3 */
121 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_4 */
122 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_5 */
123 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_6 */
124 {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_7 */
125 }
126};
127
128static struct dev_config usb_rx_cfg = {
129 .sample_rate = SAMPLING_RATE_48KHZ,
130 .bit_format = SNDRV_PCM_FORMAT_S16_LE,
131 .channels = 2,
132};
133
134static struct dev_config usb_tx_cfg = {
135 .sample_rate = SAMPLING_RATE_48KHZ,
136 .bit_format = SNDRV_PCM_FORMAT_S16_LE,
137 .channels = 1,
138};
139
140enum {
141 PRIM_MI2S = 0,
142 SEC_MI2S,
143 TERT_MI2S,
144 QUAT_MI2S,
145 MI2S_MAX,
146};
147
148enum {
149 PRIM_AUX_PCM = 0,
150 SEC_AUX_PCM,
151 TERT_AUX_PCM,
152 QUAT_AUX_PCM,
153 AUX_PCM_MAX,
154};
155
156enum {
157 PCM_I2S_SEL_PRIM = 0,
158 PCM_I2S_SEL_SEC,
159 PCM_I2S_SEL_TERT,
160 PCM_I2S_SEL_QUAT,
161 PCM_I2S_SEL_MAX,
162};
163
164struct mi2s_aux_pcm_common_conf {
165 struct mutex lock;
166 void *pcm_i2s_sel_vt_addr;
167};
168
169struct mi2s_conf {
170 struct mutex lock;
171 u32 ref_cnt;
172 u32 msm_is_mi2s_master;
173};
174
175struct auxpcm_conf {
176 struct mutex lock;
177 u32 ref_cnt;
178};
179
180struct msm_wsa881x_dev_info {
181 struct device_node *of_node;
182 u32 index;
183};
184static struct snd_soc_aux_dev *msm_aux_dev;
185static struct snd_soc_codec_conf *msm_codec_conf;
186
187static bool msm_swap_gnd_mic(struct snd_soc_codec *codec);
188
189static struct wcd_mbhc_config mbhc_cfg = {
190 .read_fw_bin = false,
191 .calibration = NULL,
192 .detect_extn_cable = true,
193 .mono_stero_detection = false,
194 .swap_gnd_mic = NULL,
Laxminath Kasame68e94f2016-12-09 12:08:00 +0530195 .hs_ext_micbias = true,
Banajit Goswami0530e2f2016-12-09 21:34:37 -0800196 .key_code[0] = KEY_MEDIA,
197 .key_code[1] = KEY_VOICECOMMAND,
198 .key_code[2] = KEY_VOLUMEUP,
199 .key_code[3] = KEY_VOLUMEDOWN,
200 .key_code[4] = 0,
201 .key_code[5] = 0,
202 .key_code[6] = 0,
203 .key_code[7] = 0,
204 .linein_th = 5000,
205 .moisture_en = false,
206 .mbhc_micbias = 0,
207 .anc_micbias = 0,
208 .enable_anc_mic_detect = false,
209};
210
211static struct dev_config proxy_rx_cfg = {
212 .sample_rate = SAMPLING_RATE_48KHZ,
213 .bit_format = SNDRV_PCM_FORMAT_S16_LE,
214 .channels = 2,
215};
216
217/* Default configuration of MI2S channels */
218static struct dev_config mi2s_rx_cfg[] = {
219 [PRIM_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
220 [SEC_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
221 [TERT_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
222 [QUAT_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
223};
224
225static struct dev_config mi2s_tx_cfg[] = {
226 [PRIM_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
227 [SEC_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
228 [TERT_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
229 [QUAT_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
230};
231
232static struct dev_config aux_pcm_rx_cfg[] = {
233 [PRIM_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
234 [SEC_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
235 [TERT_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
236 [QUAT_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
237};
238
239static struct dev_config aux_pcm_tx_cfg[] = {
240 [PRIM_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
241 [SEC_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
242 [TERT_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
243 [QUAT_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
244};
245
246static char const *ch_text[] = {"Two", "Three", "Four", "Five",
247 "Six", "Seven", "Eight"};
248static const char *const auxpcm_rate_text[] = {"KHZ_8", "KHZ_16"};
249static char const *mi2s_rate_text[] = {"KHZ_8", "KHZ_16",
250 "KHZ_32", "KHZ_44P1", "KHZ_48",
251 "KHZ_96", "KHZ_192"};
252static const char *const mi2s_ch_text[] = {"One", "Two", "Three", "Four",
253 "Five", "Six", "Seven",
254 "Eight"};
255static char const *bit_format_text[] = {"S16_LE", "S24_LE", "S24_3LE",
256 "S32_LE"};
257static char const *tdm_ch_text[] = {"One", "Two", "Three", "Four",
258 "Five", "Six", "Seven", "Eight"};
259static char const *tdm_bit_format_text[] = {"S16_LE", "S24_LE", "S32_LE"};
260static char const *tdm_sample_rate_text[] = {"KHZ_8", "KHZ_16", "KHZ_32",
261 "KHZ_44P1", "KHZ_48", "KHZ_96",
262 "KHZ_192", "KHZ_352P8", "KHZ_384"};
263static const char *const usb_ch_text[] = {"One", "Two", "Three", "Four",
264 "Five", "Six", "Seven",
265 "Eight"};
266static char const *usb_sample_rate_text[] = {"KHZ_8", "KHZ_11P025",
267 "KHZ_16", "KHZ_22P05",
268 "KHZ_32", "KHZ_44P1", "KHZ_48",
269 "KHZ_96", "KHZ_192", "KHZ_384"};
270
271static SOC_ENUM_SINGLE_EXT_DECL(proxy_rx_chs, ch_text);
272static SOC_ENUM_SINGLE_EXT_DECL(prim_aux_pcm_rx_sample_rate, auxpcm_rate_text);
273static SOC_ENUM_SINGLE_EXT_DECL(sec_aux_pcm_rx_sample_rate, auxpcm_rate_text);
274static SOC_ENUM_SINGLE_EXT_DECL(tert_aux_pcm_rx_sample_rate, auxpcm_rate_text);
275static SOC_ENUM_SINGLE_EXT_DECL(quat_aux_pcm_rx_sample_rate, auxpcm_rate_text);
276static SOC_ENUM_SINGLE_EXT_DECL(prim_aux_pcm_tx_sample_rate, auxpcm_rate_text);
277static SOC_ENUM_SINGLE_EXT_DECL(sec_aux_pcm_tx_sample_rate, auxpcm_rate_text);
278static SOC_ENUM_SINGLE_EXT_DECL(tert_aux_pcm_tx_sample_rate, auxpcm_rate_text);
279static SOC_ENUM_SINGLE_EXT_DECL(quat_aux_pcm_tx_sample_rate, auxpcm_rate_text);
280static SOC_ENUM_SINGLE_EXT_DECL(prim_mi2s_rx_sample_rate, mi2s_rate_text);
281static SOC_ENUM_SINGLE_EXT_DECL(sec_mi2s_rx_sample_rate, mi2s_rate_text);
282static SOC_ENUM_SINGLE_EXT_DECL(tert_mi2s_rx_sample_rate, mi2s_rate_text);
283static SOC_ENUM_SINGLE_EXT_DECL(quat_mi2s_rx_sample_rate, mi2s_rate_text);
284static SOC_ENUM_SINGLE_EXT_DECL(prim_mi2s_tx_sample_rate, mi2s_rate_text);
285static SOC_ENUM_SINGLE_EXT_DECL(sec_mi2s_tx_sample_rate, mi2s_rate_text);
286static SOC_ENUM_SINGLE_EXT_DECL(tert_mi2s_tx_sample_rate, mi2s_rate_text);
287static SOC_ENUM_SINGLE_EXT_DECL(quat_mi2s_tx_sample_rate, mi2s_rate_text);
288static SOC_ENUM_SINGLE_EXT_DECL(prim_mi2s_rx_chs, mi2s_ch_text);
289static SOC_ENUM_SINGLE_EXT_DECL(prim_mi2s_tx_chs, mi2s_ch_text);
290static SOC_ENUM_SINGLE_EXT_DECL(sec_mi2s_rx_chs, mi2s_ch_text);
291static SOC_ENUM_SINGLE_EXT_DECL(sec_mi2s_tx_chs, mi2s_ch_text);
292static SOC_ENUM_SINGLE_EXT_DECL(tert_mi2s_rx_chs, mi2s_ch_text);
293static SOC_ENUM_SINGLE_EXT_DECL(tert_mi2s_tx_chs, mi2s_ch_text);
294static SOC_ENUM_SINGLE_EXT_DECL(quat_mi2s_rx_chs, mi2s_ch_text);
295static SOC_ENUM_SINGLE_EXT_DECL(quat_mi2s_tx_chs, mi2s_ch_text);
296static SOC_ENUM_SINGLE_EXT_DECL(usb_rx_chs, usb_ch_text);
297static SOC_ENUM_SINGLE_EXT_DECL(usb_tx_chs, usb_ch_text);
298static SOC_ENUM_SINGLE_EXT_DECL(usb_rx_format, bit_format_text);
299static SOC_ENUM_SINGLE_EXT_DECL(usb_tx_format, bit_format_text);
300static SOC_ENUM_SINGLE_EXT_DECL(usb_rx_sample_rate, usb_sample_rate_text);
301static SOC_ENUM_SINGLE_EXT_DECL(usb_tx_sample_rate, usb_sample_rate_text);
302static SOC_ENUM_SINGLE_EXT_DECL(tdm_tx_chs, tdm_ch_text);
303static SOC_ENUM_SINGLE_EXT_DECL(tdm_tx_format, tdm_bit_format_text);
304static SOC_ENUM_SINGLE_EXT_DECL(tdm_tx_sample_rate, tdm_sample_rate_text);
305static SOC_ENUM_SINGLE_EXT_DECL(tdm_rx_chs, tdm_ch_text);
306static SOC_ENUM_SINGLE_EXT_DECL(tdm_rx_format, tdm_bit_format_text);
307static SOC_ENUM_SINGLE_EXT_DECL(tdm_rx_sample_rate, tdm_sample_rate_text);
308
309static struct afe_clk_set mi2s_clk[MI2S_MAX] = {
310 {
311 AFE_API_VERSION_I2S_CONFIG,
312 Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT,
313 Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ,
314 Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO,
315 Q6AFE_LPASS_CLK_ROOT_DEFAULT,
316 0,
317 },
318 {
319 AFE_API_VERSION_I2S_CONFIG,
320 Q6AFE_LPASS_CLK_ID_SEC_MI2S_IBIT,
321 Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ,
322 Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO,
323 Q6AFE_LPASS_CLK_ROOT_DEFAULT,
324 0,
325 },
326 {
327 AFE_API_VERSION_I2S_CONFIG,
328 Q6AFE_LPASS_CLK_ID_TER_MI2S_IBIT,
329 Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ,
330 Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO,
331 Q6AFE_LPASS_CLK_ROOT_DEFAULT,
332 0,
333 },
334 {
335 AFE_API_VERSION_I2S_CONFIG,
336 Q6AFE_LPASS_CLK_ID_QUAD_MI2S_IBIT,
337 Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ,
338 Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO,
339 Q6AFE_LPASS_CLK_ROOT_DEFAULT,
340 0,
341 }
342};
343
344static struct mi2s_aux_pcm_common_conf mi2s_auxpcm_conf[PCM_I2S_SEL_MAX];
345static struct mi2s_conf mi2s_intf_conf[MI2S_MAX];
346static struct auxpcm_conf auxpcm_intf_conf[AUX_PCM_MAX];
347
348static int proxy_rx_ch_get(struct snd_kcontrol *kcontrol,
349 struct snd_ctl_elem_value *ucontrol)
350{
351 pr_debug("%s: proxy_rx channels = %d\n",
352 __func__, proxy_rx_cfg.channels);
353 ucontrol->value.integer.value[0] = proxy_rx_cfg.channels - 2;
354
355 return 0;
356}
357
358static int proxy_rx_ch_put(struct snd_kcontrol *kcontrol,
359 struct snd_ctl_elem_value *ucontrol)
360{
361 proxy_rx_cfg.channels = ucontrol->value.integer.value[0] + 2;
362 pr_debug("%s: proxy_rx channels = %d\n",
363 __func__, proxy_rx_cfg.channels);
364
365 return 1;
366}
367
368static int tdm_get_sample_rate(int value)
369{
370 int sample_rate = 0;
371
372 switch (value) {
373 case 0:
374 sample_rate = SAMPLING_RATE_8KHZ;
375 break;
376 case 1:
377 sample_rate = SAMPLING_RATE_16KHZ;
378 break;
379 case 2:
380 sample_rate = SAMPLING_RATE_32KHZ;
381 break;
382 case 3:
383 sample_rate = SAMPLING_RATE_44P1KHZ;
384 break;
385 case 4:
386 sample_rate = SAMPLING_RATE_48KHZ;
387 break;
388 case 5:
389 sample_rate = SAMPLING_RATE_96KHZ;
390 break;
391 case 6:
392 sample_rate = SAMPLING_RATE_192KHZ;
393 break;
394 case 7:
395 sample_rate = SAMPLING_RATE_352P8KHZ;
396 break;
397 case 8:
398 sample_rate = SAMPLING_RATE_384KHZ;
399 break;
400 default:
401 sample_rate = SAMPLING_RATE_48KHZ;
402 break;
403 }
404 return sample_rate;
405}
406
407static int tdm_get_sample_rate_val(int sample_rate)
408{
409 int sample_rate_val = 0;
410
411 switch (sample_rate) {
412 case SAMPLING_RATE_8KHZ:
413 sample_rate_val = 0;
414 break;
415 case SAMPLING_RATE_16KHZ:
416 sample_rate_val = 1;
417 break;
418 case SAMPLING_RATE_32KHZ:
419 sample_rate_val = 2;
420 break;
421 case SAMPLING_RATE_44P1KHZ:
422 sample_rate_val = 3;
423 break;
424 case SAMPLING_RATE_48KHZ:
425 sample_rate_val = 4;
426 break;
427 case SAMPLING_RATE_96KHZ:
428 sample_rate_val = 5;
429 break;
430 case SAMPLING_RATE_192KHZ:
431 sample_rate_val = 6;
432 break;
433 case SAMPLING_RATE_352P8KHZ:
434 sample_rate_val = 7;
435 break;
436 case SAMPLING_RATE_384KHZ:
437 sample_rate_val = 8;
438 break;
439 default:
440 sample_rate_val = 4;
441 break;
442 }
443 return sample_rate_val;
444}
445
446static int tdm_get_port_idx(struct snd_kcontrol *kcontrol,
447 struct tdm_port *port)
448{
449 if (port) {
450 if (strnstr(kcontrol->id.name, "PRI",
451 sizeof(kcontrol->id.name))) {
452 port->mode = TDM_PRI;
453 } else if (strnstr(kcontrol->id.name, "SEC",
454 sizeof(kcontrol->id.name))) {
455 port->mode = TDM_SEC;
456 } else if (strnstr(kcontrol->id.name, "TERT",
457 sizeof(kcontrol->id.name))) {
458 port->mode = TDM_TERT;
459 } else if (strnstr(kcontrol->id.name, "QUAT",
460 sizeof(kcontrol->id.name))) {
461 port->mode = TDM_QUAT;
462 } else {
463 pr_err("%s: unsupported mode in: %s",
464 __func__, kcontrol->id.name);
465 return -EINVAL;
466 }
467
468 if (strnstr(kcontrol->id.name, "RX_0",
469 sizeof(kcontrol->id.name)) ||
470 strnstr(kcontrol->id.name, "TX_0",
471 sizeof(kcontrol->id.name))) {
472 port->channel = TDM_0;
473 } else if (strnstr(kcontrol->id.name, "RX_1",
474 sizeof(kcontrol->id.name)) ||
475 strnstr(kcontrol->id.name, "TX_1",
476 sizeof(kcontrol->id.name))) {
477 port->channel = TDM_1;
478 } else if (strnstr(kcontrol->id.name, "RX_2",
479 sizeof(kcontrol->id.name)) ||
480 strnstr(kcontrol->id.name, "TX_2",
481 sizeof(kcontrol->id.name))) {
482 port->channel = TDM_2;
483 } else if (strnstr(kcontrol->id.name, "RX_3",
484 sizeof(kcontrol->id.name)) ||
485 strnstr(kcontrol->id.name, "TX_3",
486 sizeof(kcontrol->id.name))) {
487 port->channel = TDM_3;
488 } else if (strnstr(kcontrol->id.name, "RX_4",
489 sizeof(kcontrol->id.name)) ||
490 strnstr(kcontrol->id.name, "TX_4",
491 sizeof(kcontrol->id.name))) {
492 port->channel = TDM_4;
493 } else if (strnstr(kcontrol->id.name, "RX_5",
494 sizeof(kcontrol->id.name)) ||
495 strnstr(kcontrol->id.name, "TX_5",
496 sizeof(kcontrol->id.name))) {
497 port->channel = TDM_5;
498 } else if (strnstr(kcontrol->id.name, "RX_6",
499 sizeof(kcontrol->id.name)) ||
500 strnstr(kcontrol->id.name, "TX_6",
501 sizeof(kcontrol->id.name))) {
502 port->channel = TDM_6;
503 } else if (strnstr(kcontrol->id.name, "RX_7",
504 sizeof(kcontrol->id.name)) ||
505 strnstr(kcontrol->id.name, "TX_7",
506 sizeof(kcontrol->id.name))) {
507 port->channel = TDM_7;
508 } else {
509 pr_err("%s: unsupported channel in: %s",
510 __func__, kcontrol->id.name);
511 return -EINVAL;
512 }
513 } else
514 return -EINVAL;
515 return 0;
516}
517
518static int tdm_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
519 struct snd_ctl_elem_value *ucontrol)
520{
521 struct tdm_port port;
522 int ret = tdm_get_port_idx(kcontrol, &port);
523
524 if (ret) {
525 pr_err("%s: unsupported control: %s",
526 __func__, kcontrol->id.name);
527 } else {
528 ucontrol->value.enumerated.item[0] = tdm_get_sample_rate_val(
529 tdm_rx_cfg[port.mode][port.channel].sample_rate);
530
531 pr_debug("%s: tdm_rx_sample_rate = %d, item = %d\n", __func__,
532 tdm_rx_cfg[port.mode][port.channel].sample_rate,
533 ucontrol->value.enumerated.item[0]);
534 }
535 return ret;
536}
537
538static int tdm_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
539 struct snd_ctl_elem_value *ucontrol)
540{
541 struct tdm_port port;
542 int ret = tdm_get_port_idx(kcontrol, &port);
543
544 if (ret) {
545 pr_err("%s: unsupported control: %s",
546 __func__, kcontrol->id.name);
547 } else {
548 tdm_rx_cfg[port.mode][port.channel].sample_rate =
549 tdm_get_sample_rate(ucontrol->value.enumerated.item[0]);
550
551 pr_debug("%s: tdm_rx_sample_rate = %d, item = %d\n", __func__,
552 tdm_rx_cfg[port.mode][port.channel].sample_rate,
553 ucontrol->value.enumerated.item[0]);
554 }
555 return ret;
556}
557
558static int tdm_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
559 struct snd_ctl_elem_value *ucontrol)
560{
561 struct tdm_port port;
562 int ret = tdm_get_port_idx(kcontrol, &port);
563
564 if (ret) {
565 pr_err("%s: unsupported control: %s",
566 __func__, kcontrol->id.name);
567 } else {
568 ucontrol->value.enumerated.item[0] = tdm_get_sample_rate_val(
569 tdm_tx_cfg[port.mode][port.channel].sample_rate);
570
571 pr_debug("%s: tdm_tx_sample_rate = %d, item = %d\n", __func__,
572 tdm_tx_cfg[port.mode][port.channel].sample_rate,
573 ucontrol->value.enumerated.item[0]);
574 }
575 return ret;
576}
577
578static int tdm_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
579 struct snd_ctl_elem_value *ucontrol)
580{
581 struct tdm_port port;
582 int ret = tdm_get_port_idx(kcontrol, &port);
583
584 if (ret) {
585 pr_err("%s: unsupported control: %s",
586 __func__, kcontrol->id.name);
587 } else {
588 tdm_tx_cfg[port.mode][port.channel].sample_rate =
589 tdm_get_sample_rate(ucontrol->value.enumerated.item[0]);
590
591 pr_debug("%s: tdm_tx_sample_rate = %d, item = %d\n", __func__,
592 tdm_tx_cfg[port.mode][port.channel].sample_rate,
593 ucontrol->value.enumerated.item[0]);
594 }
595 return ret;
596}
597
598static int tdm_get_format(int value)
599{
600 int format = 0;
601
602 switch (value) {
603 case 0:
604 format = SNDRV_PCM_FORMAT_S16_LE;
605 break;
606 case 1:
607 format = SNDRV_PCM_FORMAT_S24_LE;
608 break;
609 case 2:
610 format = SNDRV_PCM_FORMAT_S32_LE;
611 break;
612 default:
613 format = SNDRV_PCM_FORMAT_S16_LE;
614 break;
615 }
616 return format;
617}
618
619static int tdm_get_format_val(int format)
620{
621 int value = 0;
622
623 switch (format) {
624 case SNDRV_PCM_FORMAT_S16_LE:
625 value = 0;
626 break;
627 case SNDRV_PCM_FORMAT_S24_LE:
628 value = 1;
629 break;
630 case SNDRV_PCM_FORMAT_S32_LE:
631 value = 2;
632 break;
633 default:
634 value = 0;
635 break;
636 }
637 return value;
638}
639
640static int tdm_rx_format_get(struct snd_kcontrol *kcontrol,
641 struct snd_ctl_elem_value *ucontrol)
642{
643 struct tdm_port port;
644 int ret = tdm_get_port_idx(kcontrol, &port);
645
646 if (ret) {
647 pr_err("%s: unsupported control: %s",
648 __func__, kcontrol->id.name);
649 } else {
650 ucontrol->value.enumerated.item[0] = tdm_get_format_val(
651 tdm_rx_cfg[port.mode][port.channel].bit_format);
652
653 pr_debug("%s: tdm_rx_bit_format = %d, item = %d\n", __func__,
654 tdm_rx_cfg[port.mode][port.channel].bit_format,
655 ucontrol->value.enumerated.item[0]);
656 }
657 return ret;
658}
659
660static int tdm_rx_format_put(struct snd_kcontrol *kcontrol,
661 struct snd_ctl_elem_value *ucontrol)
662{
663 struct tdm_port port;
664 int ret = tdm_get_port_idx(kcontrol, &port);
665
666 if (ret) {
667 pr_err("%s: unsupported control: %s",
668 __func__, kcontrol->id.name);
669 } else {
670 tdm_rx_cfg[port.mode][port.channel].bit_format =
671 tdm_get_format(ucontrol->value.enumerated.item[0]);
672
673 pr_debug("%s: tdm_rx_bit_format = %d, item = %d\n", __func__,
674 tdm_rx_cfg[port.mode][port.channel].bit_format,
675 ucontrol->value.enumerated.item[0]);
676 }
677 return ret;
678}
679
680static int tdm_tx_format_get(struct snd_kcontrol *kcontrol,
681 struct snd_ctl_elem_value *ucontrol)
682{
683 struct tdm_port port;
684 int ret = tdm_get_port_idx(kcontrol, &port);
685
686 if (ret) {
687 pr_err("%s: unsupported control: %s",
688 __func__, kcontrol->id.name);
689 } else {
690 ucontrol->value.enumerated.item[0] = tdm_get_format_val(
691 tdm_tx_cfg[port.mode][port.channel].bit_format);
692
693 pr_debug("%s: tdm_tx_bit_format = %d, item = %d\n", __func__,
694 tdm_tx_cfg[port.mode][port.channel].bit_format,
695 ucontrol->value.enumerated.item[0]);
696 }
697 return ret;
698}
699
700static int tdm_tx_format_put(struct snd_kcontrol *kcontrol,
701 struct snd_ctl_elem_value *ucontrol)
702{
703 struct tdm_port port;
704 int ret = tdm_get_port_idx(kcontrol, &port);
705
706 if (ret) {
707 pr_err("%s: unsupported control: %s",
708 __func__, kcontrol->id.name);
709 } else {
710 tdm_tx_cfg[port.mode][port.channel].bit_format =
711 tdm_get_format(ucontrol->value.enumerated.item[0]);
712
713 pr_debug("%s: tdm_tx_bit_format = %d, item = %d\n", __func__,
714 tdm_tx_cfg[port.mode][port.channel].bit_format,
715 ucontrol->value.enumerated.item[0]);
716 }
717 return ret;
718}
719
720static int tdm_rx_ch_get(struct snd_kcontrol *kcontrol,
721 struct snd_ctl_elem_value *ucontrol)
722{
723 struct tdm_port port;
724 int ret = tdm_get_port_idx(kcontrol, &port);
725
726 if (ret) {
727 pr_err("%s: unsupported control: %s",
728 __func__, kcontrol->id.name);
729 } else {
730
731 ucontrol->value.enumerated.item[0] =
732 tdm_rx_cfg[port.mode][port.channel].channels - 1;
733
734 pr_debug("%s: tdm_rx_ch = %d, item = %d\n", __func__,
735 tdm_rx_cfg[port.mode][port.channel].channels - 1,
736 ucontrol->value.enumerated.item[0]);
737 }
738 return ret;
739}
740
741static int tdm_rx_ch_put(struct snd_kcontrol *kcontrol,
742 struct snd_ctl_elem_value *ucontrol)
743{
744 struct tdm_port port;
745 int ret = tdm_get_port_idx(kcontrol, &port);
746
747 if (ret) {
748 pr_err("%s: unsupported control: %s",
749 __func__, kcontrol->id.name);
750 } else {
751 tdm_rx_cfg[port.mode][port.channel].channels =
752 ucontrol->value.enumerated.item[0] + 1;
753
754 pr_debug("%s: tdm_rx_ch = %d, item = %d\n", __func__,
755 tdm_rx_cfg[port.mode][port.channel].channels,
756 ucontrol->value.enumerated.item[0] + 1);
757 }
758 return ret;
759}
760
761static int tdm_tx_ch_get(struct snd_kcontrol *kcontrol,
762 struct snd_ctl_elem_value *ucontrol)
763{
764 struct tdm_port port;
765 int ret = tdm_get_port_idx(kcontrol, &port);
766
767 if (ret) {
768 pr_err("%s: unsupported control: %s",
769 __func__, kcontrol->id.name);
770 } else {
771 ucontrol->value.enumerated.item[0] =
772 tdm_tx_cfg[port.mode][port.channel].channels - 1;
773
774 pr_debug("%s: tdm_tx_ch = %d, item = %d\n", __func__,
775 tdm_tx_cfg[port.mode][port.channel].channels - 1,
776 ucontrol->value.enumerated.item[0]);
777 }
778 return ret;
779}
780
781static int tdm_tx_ch_put(struct snd_kcontrol *kcontrol,
782 struct snd_ctl_elem_value *ucontrol)
783{
784 struct tdm_port port;
785 int ret = tdm_get_port_idx(kcontrol, &port);
786
787 if (ret) {
788 pr_err("%s: unsupported control: %s",
789 __func__, kcontrol->id.name);
790 } else {
791 tdm_tx_cfg[port.mode][port.channel].channels =
792 ucontrol->value.enumerated.item[0] + 1;
793
794 pr_debug("%s: tdm_tx_ch = %d, item = %d\n", __func__,
795 tdm_tx_cfg[port.mode][port.channel].channels,
796 ucontrol->value.enumerated.item[0] + 1);
797 }
798 return ret;
799}
800
801static int aux_pcm_get_sample_rate(int value)
802{
803 int sample_rate;
804
805 switch (value) {
806 case 1:
807 sample_rate = SAMPLING_RATE_16KHZ;
808 break;
809 case 0:
810 default:
811 sample_rate = SAMPLING_RATE_8KHZ;
812 break;
813 }
814 return sample_rate;
815}
816
817static int aux_pcm_get_sample_rate_val(int sample_rate)
818{
819 int sample_rate_val;
820
821 switch (sample_rate) {
822 case SAMPLING_RATE_16KHZ:
823 sample_rate_val = 1;
824 break;
825 case SAMPLING_RATE_8KHZ:
826 default:
827 sample_rate_val = 0;
828 break;
829 }
830 return sample_rate_val;
831}
832
833static int aux_pcm_get_port_idx(struct snd_kcontrol *kcontrol)
834{
835 int idx;
836
837 if (strnstr(kcontrol->id.name, "PRIM_AUX_PCM",
838 sizeof("PRIM_AUX_PCM")))
839 idx = PRIM_AUX_PCM;
840 else if (strnstr(kcontrol->id.name, "SEC_AUX_PCM",
841 sizeof("SEC_AUX_PCM")))
842 idx = SEC_AUX_PCM;
843 else if (strnstr(kcontrol->id.name, "TERT_AUX_PCM",
844 sizeof("TERT_AUX_PCM")))
845 idx = TERT_AUX_PCM;
846 else if (strnstr(kcontrol->id.name, "QUAT_AUX_PCM",
847 sizeof("QUAT_AUX_PCM")))
848 idx = QUAT_AUX_PCM;
849 else {
850 pr_err("%s: unsupported port: %s",
851 __func__, kcontrol->id.name);
852 idx = -EINVAL;
853 }
854
855 return idx;
856}
857
858static int aux_pcm_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
859 struct snd_ctl_elem_value *ucontrol)
860{
861 int idx = aux_pcm_get_port_idx(kcontrol);
862
863 if (idx < 0)
864 return idx;
865
866 aux_pcm_rx_cfg[idx].sample_rate =
867 aux_pcm_get_sample_rate(ucontrol->value.enumerated.item[0]);
868
869 pr_debug("%s: idx[%d]_rx_sample_rate = %d, item = %d\n", __func__,
870 idx, aux_pcm_rx_cfg[idx].sample_rate,
871 ucontrol->value.enumerated.item[0]);
872
873 return 0;
874}
875
876static int aux_pcm_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
877 struct snd_ctl_elem_value *ucontrol)
878{
879 int idx = aux_pcm_get_port_idx(kcontrol);
880
881 if (idx < 0)
882 return idx;
883
884 ucontrol->value.enumerated.item[0] =
885 aux_pcm_get_sample_rate_val(aux_pcm_rx_cfg[idx].sample_rate);
886
887 pr_debug("%s: idx[%d]_rx_sample_rate = %d, item = %d\n", __func__,
888 idx, aux_pcm_rx_cfg[idx].sample_rate,
889 ucontrol->value.enumerated.item[0]);
890
891 return 0;
892}
893
894static int aux_pcm_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
895 struct snd_ctl_elem_value *ucontrol)
896{
897 int idx = aux_pcm_get_port_idx(kcontrol);
898
899 if (idx < 0)
900 return idx;
901
902 aux_pcm_tx_cfg[idx].sample_rate =
903 aux_pcm_get_sample_rate(ucontrol->value.enumerated.item[0]);
904
905 pr_debug("%s: idx[%d]_tx_sample_rate = %d, item = %d\n", __func__,
906 idx, aux_pcm_tx_cfg[idx].sample_rate,
907 ucontrol->value.enumerated.item[0]);
908
909 return 0;
910}
911
912static int aux_pcm_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
913 struct snd_ctl_elem_value *ucontrol)
914{
915 int idx = aux_pcm_get_port_idx(kcontrol);
916
917 if (idx < 0)
918 return idx;
919
920 ucontrol->value.enumerated.item[0] =
921 aux_pcm_get_sample_rate_val(aux_pcm_tx_cfg[idx].sample_rate);
922
923 pr_debug("%s: idx[%d]_tx_sample_rate = %d, item = %d\n", __func__,
924 idx, aux_pcm_tx_cfg[idx].sample_rate,
925 ucontrol->value.enumerated.item[0]);
926
927 return 0;
928}
929
930static int mi2s_get_port_idx(struct snd_kcontrol *kcontrol)
931{
932 int idx;
933
934 if (strnstr(kcontrol->id.name, "PRIM_MI2S_RX",
935 sizeof("PRIM_MI2S_RX")))
936 idx = PRIM_MI2S;
937 else if (strnstr(kcontrol->id.name, "SEC_MI2S_RX",
938 sizeof("SEC_MI2S_RX")))
939 idx = SEC_MI2S;
940 else if (strnstr(kcontrol->id.name, "TERT_MI2S_RX",
941 sizeof("TERT_MI2S_RX")))
942 idx = TERT_MI2S;
943 else if (strnstr(kcontrol->id.name, "QUAT_MI2S_RX",
944 sizeof("QUAT_MI2S_RX")))
945 idx = QUAT_MI2S;
946 else if (strnstr(kcontrol->id.name, "PRIM_MI2S_TX",
947 sizeof("PRIM_MI2S_TX")))
948 idx = PRIM_MI2S;
949 else if (strnstr(kcontrol->id.name, "SEC_MI2S_TX",
950 sizeof("SEC_MI2S_TX")))
951 idx = SEC_MI2S;
952 else if (strnstr(kcontrol->id.name, "TERT_MI2S_TX",
953 sizeof("TERT_MI2S_TX")))
954 idx = TERT_MI2S;
955 else if (strnstr(kcontrol->id.name, "QUAT_MI2S_TX",
956 sizeof("QUAT_MI2S_TX")))
957 idx = QUAT_MI2S;
958 else {
959 pr_err("%s: unsupported channel: %s",
960 __func__, kcontrol->id.name);
961 idx = -EINVAL;
962 }
963
964 return idx;
965}
966
967static int mi2s_get_sample_rate_val(int sample_rate)
968{
969 int sample_rate_val;
970
971 switch (sample_rate) {
972 case SAMPLING_RATE_8KHZ:
973 sample_rate_val = 0;
974 break;
975 case SAMPLING_RATE_16KHZ:
976 sample_rate_val = 1;
977 break;
978 case SAMPLING_RATE_32KHZ:
979 sample_rate_val = 2;
980 break;
981 case SAMPLING_RATE_44P1KHZ:
982 sample_rate_val = 3;
983 break;
984 case SAMPLING_RATE_48KHZ:
985 sample_rate_val = 4;
986 break;
987 case SAMPLING_RATE_96KHZ:
988 sample_rate_val = 5;
989 break;
990 case SAMPLING_RATE_192KHZ:
991 sample_rate_val = 6;
992 break;
993 default:
994 sample_rate_val = 4;
995 break;
996 }
997 return sample_rate_val;
998}
999
1000static int mi2s_get_sample_rate(int value)
1001{
1002 int sample_rate;
1003
1004 switch (value) {
1005 case 0:
1006 sample_rate = SAMPLING_RATE_8KHZ;
1007 break;
1008 case 1:
1009 sample_rate = SAMPLING_RATE_16KHZ;
1010 break;
1011 case 2:
1012 sample_rate = SAMPLING_RATE_32KHZ;
1013 break;
1014 case 3:
1015 sample_rate = SAMPLING_RATE_44P1KHZ;
1016 break;
1017 case 4:
1018 sample_rate = SAMPLING_RATE_48KHZ;
1019 break;
1020 case 5:
1021 sample_rate = SAMPLING_RATE_96KHZ;
1022 break;
1023 case 6:
1024 sample_rate = SAMPLING_RATE_192KHZ;
1025 break;
1026 default:
1027 sample_rate = SAMPLING_RATE_48KHZ;
1028 break;
1029 }
1030 return sample_rate;
1031}
1032
1033static int mi2s_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
1034 struct snd_ctl_elem_value *ucontrol)
1035{
1036 int idx = mi2s_get_port_idx(kcontrol);
1037
1038 if (idx < 0)
1039 return idx;
1040
1041 mi2s_rx_cfg[idx].sample_rate =
1042 mi2s_get_sample_rate(ucontrol->value.enumerated.item[0]);
1043
1044 pr_debug("%s: idx[%d]_rx_sample_rate = %d, item = %d\n", __func__,
1045 idx, mi2s_rx_cfg[idx].sample_rate,
1046 ucontrol->value.enumerated.item[0]);
1047
1048 return 0;
1049}
1050
1051static int mi2s_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
1052 struct snd_ctl_elem_value *ucontrol)
1053{
1054 int idx = mi2s_get_port_idx(kcontrol);
1055
1056 if (idx < 0)
1057 return idx;
1058
1059 ucontrol->value.enumerated.item[0] =
1060 mi2s_get_sample_rate_val(mi2s_rx_cfg[idx].sample_rate);
1061
1062 pr_debug("%s: idx[%d]_rx_sample_rate = %d, item = %d\n", __func__,
1063 idx, mi2s_rx_cfg[idx].sample_rate,
1064 ucontrol->value.enumerated.item[0]);
1065
1066 return 0;
1067}
1068
1069static int mi2s_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
1070 struct snd_ctl_elem_value *ucontrol)
1071{
1072 int idx = mi2s_get_port_idx(kcontrol);
1073
1074 if (idx < 0)
1075 return idx;
1076
1077 mi2s_tx_cfg[idx].sample_rate =
1078 mi2s_get_sample_rate(ucontrol->value.enumerated.item[0]);
1079
1080 pr_debug("%s: idx[%d]_tx_sample_rate = %d, item = %d\n", __func__,
1081 idx, mi2s_tx_cfg[idx].sample_rate,
1082 ucontrol->value.enumerated.item[0]);
1083
1084 return 0;
1085}
1086
1087static int mi2s_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
1088 struct snd_ctl_elem_value *ucontrol)
1089{
1090 int idx = mi2s_get_port_idx(kcontrol);
1091
1092 if (idx < 0)
1093 return idx;
1094
1095 ucontrol->value.enumerated.item[0] =
1096 mi2s_get_sample_rate_val(mi2s_tx_cfg[idx].sample_rate);
1097
1098 pr_debug("%s: idx[%d]_tx_sample_rate = %d, item = %d\n", __func__,
1099 idx, mi2s_tx_cfg[idx].sample_rate,
1100 ucontrol->value.enumerated.item[0]);
1101
1102 return 0;
1103}
1104
1105static int msm_mi2s_rx_ch_get(struct snd_kcontrol *kcontrol,
1106 struct snd_ctl_elem_value *ucontrol)
1107{
1108 int idx = mi2s_get_port_idx(kcontrol);
1109
1110 if (idx < 0)
1111 return idx;
1112
1113 pr_debug("%s: msm_mi2s_[%d]_rx_ch = %d\n", __func__,
1114 idx, mi2s_rx_cfg[idx].channels);
1115 ucontrol->value.enumerated.item[0] = mi2s_rx_cfg[idx].channels - 1;
1116
1117 return 0;
1118}
1119
1120static int msm_mi2s_rx_ch_put(struct snd_kcontrol *kcontrol,
1121 struct snd_ctl_elem_value *ucontrol)
1122{
1123 int idx = mi2s_get_port_idx(kcontrol);
1124
1125 if (idx < 0)
1126 return idx;
1127
1128 mi2s_rx_cfg[idx].channels = ucontrol->value.enumerated.item[0] + 1;
1129 pr_debug("%s: msm_mi2s_[%d]_rx_ch = %d\n", __func__,
1130 idx, mi2s_rx_cfg[idx].channels);
1131
1132 return 1;
1133}
1134
1135static int msm_mi2s_tx_ch_get(struct snd_kcontrol *kcontrol,
1136 struct snd_ctl_elem_value *ucontrol)
1137{
1138 int idx = mi2s_get_port_idx(kcontrol);
1139
1140 if (idx < 0)
1141 return idx;
1142
1143 pr_debug("%s: msm_mi2s_[%d]_tx_ch = %d\n", __func__,
1144 idx, mi2s_tx_cfg[idx].channels);
1145 ucontrol->value.enumerated.item[0] = mi2s_tx_cfg[idx].channels - 1;
1146
1147 return 0;
1148}
1149
1150static int msm_mi2s_tx_ch_put(struct snd_kcontrol *kcontrol,
1151 struct snd_ctl_elem_value *ucontrol)
1152{
1153 int idx = mi2s_get_port_idx(kcontrol);
1154
1155 if (idx < 0)
1156 return idx;
1157
1158 mi2s_tx_cfg[idx].channels = ucontrol->value.enumerated.item[0] + 1;
1159 pr_debug("%s: msm_mi2s_[%d]_tx_ch = %d\n", __func__,
1160 idx, mi2s_tx_cfg[idx].channels);
1161
1162 return 1;
1163}
1164
1165static int usb_audio_rx_ch_get(struct snd_kcontrol *kcontrol,
1166 struct snd_ctl_elem_value *ucontrol)
1167{
1168 pr_debug("%s: usb_audio_rx_ch = %d\n", __func__,
1169 usb_rx_cfg.channels);
1170 ucontrol->value.integer.value[0] = usb_rx_cfg.channels - 1;
1171 return 0;
1172}
1173
1174static int usb_audio_rx_ch_put(struct snd_kcontrol *kcontrol,
1175 struct snd_ctl_elem_value *ucontrol)
1176{
1177 usb_rx_cfg.channels = ucontrol->value.integer.value[0] + 1;
1178
1179 pr_debug("%s: usb_audio_rx_ch = %d\n", __func__, usb_rx_cfg.channels);
1180 return 1;
1181}
1182
1183static int usb_audio_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
1184 struct snd_ctl_elem_value *ucontrol)
1185{
1186 int sample_rate_val;
1187
1188 switch (usb_rx_cfg.sample_rate) {
1189 case SAMPLING_RATE_384KHZ:
1190 sample_rate_val = 9;
1191 break;
1192 case SAMPLING_RATE_192KHZ:
1193 sample_rate_val = 8;
1194 break;
1195 case SAMPLING_RATE_96KHZ:
1196 sample_rate_val = 7;
1197 break;
1198 case SAMPLING_RATE_48KHZ:
1199 sample_rate_val = 6;
1200 break;
1201 case SAMPLING_RATE_44P1KHZ:
1202 sample_rate_val = 5;
1203 break;
1204 case SAMPLING_RATE_32KHZ:
1205 sample_rate_val = 4;
1206 break;
1207 case SAMPLING_RATE_22P05KHZ:
1208 sample_rate_val = 3;
1209 break;
1210 case SAMPLING_RATE_16KHZ:
1211 sample_rate_val = 2;
1212 break;
1213 case SAMPLING_RATE_11P025KHZ:
1214 sample_rate_val = 1;
1215 break;
1216 case SAMPLING_RATE_8KHZ:
1217 default:
1218 sample_rate_val = 0;
1219 break;
1220 }
1221
1222 ucontrol->value.integer.value[0] = sample_rate_val;
1223 pr_debug("%s: usb_audio_rx_sample_rate = %d\n", __func__,
1224 usb_rx_cfg.sample_rate);
1225 return 0;
1226}
1227
1228static int usb_audio_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
1229 struct snd_ctl_elem_value *ucontrol)
1230{
1231 switch (ucontrol->value.integer.value[0]) {
1232 case 9:
1233 usb_rx_cfg.sample_rate = SAMPLING_RATE_384KHZ;
1234 break;
1235 case 8:
1236 usb_rx_cfg.sample_rate = SAMPLING_RATE_192KHZ;
1237 break;
1238 case 7:
1239 usb_rx_cfg.sample_rate = SAMPLING_RATE_96KHZ;
1240 break;
1241 case 6:
1242 usb_rx_cfg.sample_rate = SAMPLING_RATE_48KHZ;
1243 break;
1244 case 5:
1245 usb_rx_cfg.sample_rate = SAMPLING_RATE_44P1KHZ;
1246 break;
1247 case 4:
1248 usb_rx_cfg.sample_rate = SAMPLING_RATE_32KHZ;
1249 break;
1250 case 3:
1251 usb_rx_cfg.sample_rate = SAMPLING_RATE_22P05KHZ;
1252 break;
1253 case 2:
1254 usb_rx_cfg.sample_rate = SAMPLING_RATE_16KHZ;
1255 break;
1256 case 1:
1257 usb_rx_cfg.sample_rate = SAMPLING_RATE_11P025KHZ;
1258 break;
1259 case 0:
1260 usb_rx_cfg.sample_rate = SAMPLING_RATE_8KHZ;
1261 break;
1262 default:
1263 usb_rx_cfg.sample_rate = SAMPLING_RATE_48KHZ;
1264 break;
1265 }
1266
1267 pr_debug("%s: control value = %ld, usb_audio_rx_sample_rate = %d\n",
1268 __func__, ucontrol->value.integer.value[0],
1269 usb_rx_cfg.sample_rate);
1270 return 0;
1271}
1272
1273static int usb_audio_rx_format_get(struct snd_kcontrol *kcontrol,
1274 struct snd_ctl_elem_value *ucontrol)
1275{
1276 switch (usb_rx_cfg.bit_format) {
1277 case SNDRV_PCM_FORMAT_S32_LE:
1278 ucontrol->value.integer.value[0] = 3;
1279 break;
1280 case SNDRV_PCM_FORMAT_S24_3LE:
1281 ucontrol->value.integer.value[0] = 2;
1282 break;
1283 case SNDRV_PCM_FORMAT_S24_LE:
1284 ucontrol->value.integer.value[0] = 1;
1285 break;
1286 case SNDRV_PCM_FORMAT_S16_LE:
1287 default:
1288 ucontrol->value.integer.value[0] = 0;
1289 break;
1290 }
1291
1292 pr_debug("%s: usb_audio_rx_format = %d, ucontrol value = %ld\n",
1293 __func__, usb_rx_cfg.bit_format,
1294 ucontrol->value.integer.value[0]);
1295 return 0;
1296}
1297
1298static int usb_audio_rx_format_put(struct snd_kcontrol *kcontrol,
1299 struct snd_ctl_elem_value *ucontrol)
1300{
1301 int rc = 0;
1302
1303 switch (ucontrol->value.integer.value[0]) {
1304 case 3:
1305 usb_rx_cfg.bit_format = SNDRV_PCM_FORMAT_S32_LE;
1306 break;
1307 case 2:
1308 usb_rx_cfg.bit_format = SNDRV_PCM_FORMAT_S24_3LE;
1309 break;
1310 case 1:
1311 usb_rx_cfg.bit_format = SNDRV_PCM_FORMAT_S24_LE;
1312 break;
1313 case 0:
1314 default:
1315 usb_rx_cfg.bit_format = SNDRV_PCM_FORMAT_S16_LE;
1316 break;
1317 }
1318 pr_debug("%s: usb_audio_rx_format = %d, ucontrol value = %ld\n",
1319 __func__, usb_rx_cfg.bit_format,
1320 ucontrol->value.integer.value[0]);
1321
1322 return rc;
1323}
1324
1325static int usb_audio_tx_ch_get(struct snd_kcontrol *kcontrol,
1326 struct snd_ctl_elem_value *ucontrol)
1327{
1328 pr_debug("%s: usb_audio_tx_ch = %d\n", __func__,
1329 usb_tx_cfg.channels);
1330 ucontrol->value.integer.value[0] = usb_tx_cfg.channels - 1;
1331 return 0;
1332}
1333
1334static int usb_audio_tx_ch_put(struct snd_kcontrol *kcontrol,
1335 struct snd_ctl_elem_value *ucontrol)
1336{
1337 usb_tx_cfg.channels = ucontrol->value.integer.value[0] + 1;
1338
1339 pr_debug("%s: usb_audio_tx_ch = %d\n", __func__, usb_tx_cfg.channels);
1340 return 1;
1341}
1342
1343static int usb_audio_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
1344 struct snd_ctl_elem_value *ucontrol)
1345{
1346 int sample_rate_val;
1347
1348 switch (usb_tx_cfg.sample_rate) {
1349 case SAMPLING_RATE_384KHZ:
1350 sample_rate_val = 9;
1351 break;
1352 case SAMPLING_RATE_192KHZ:
1353 sample_rate_val = 8;
1354 break;
1355 case SAMPLING_RATE_96KHZ:
1356 sample_rate_val = 7;
1357 break;
1358 case SAMPLING_RATE_48KHZ:
1359 sample_rate_val = 6;
1360 break;
1361 case SAMPLING_RATE_44P1KHZ:
1362 sample_rate_val = 5;
1363 break;
1364 case SAMPLING_RATE_32KHZ:
1365 sample_rate_val = 4;
1366 break;
1367 case SAMPLING_RATE_22P05KHZ:
1368 sample_rate_val = 3;
1369 break;
1370 case SAMPLING_RATE_16KHZ:
1371 sample_rate_val = 2;
1372 break;
1373 case SAMPLING_RATE_11P025KHZ:
1374 sample_rate_val = 1;
1375 break;
1376 case SAMPLING_RATE_8KHZ:
1377 sample_rate_val = 0;
1378 break;
1379 default:
1380 sample_rate_val = 6;
1381 break;
1382 }
1383
1384 ucontrol->value.integer.value[0] = sample_rate_val;
1385 pr_debug("%s: usb_audio_tx_sample_rate = %d\n", __func__,
1386 usb_tx_cfg.sample_rate);
1387 return 0;
1388}
1389
1390static int usb_audio_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
1391 struct snd_ctl_elem_value *ucontrol)
1392{
1393 switch (ucontrol->value.integer.value[0]) {
1394 case 9:
1395 usb_tx_cfg.sample_rate = SAMPLING_RATE_384KHZ;
1396 break;
1397 case 8:
1398 usb_tx_cfg.sample_rate = SAMPLING_RATE_192KHZ;
1399 break;
1400 case 7:
1401 usb_tx_cfg.sample_rate = SAMPLING_RATE_96KHZ;
1402 break;
1403 case 6:
1404 usb_tx_cfg.sample_rate = SAMPLING_RATE_48KHZ;
1405 break;
1406 case 5:
1407 usb_tx_cfg.sample_rate = SAMPLING_RATE_44P1KHZ;
1408 break;
1409 case 4:
1410 usb_tx_cfg.sample_rate = SAMPLING_RATE_32KHZ;
1411 break;
1412 case 3:
1413 usb_tx_cfg.sample_rate = SAMPLING_RATE_22P05KHZ;
1414 break;
1415 case 2:
1416 usb_tx_cfg.sample_rate = SAMPLING_RATE_16KHZ;
1417 break;
1418 case 1:
1419 usb_tx_cfg.sample_rate = SAMPLING_RATE_11P025KHZ;
1420 break;
1421 case 0:
1422 usb_tx_cfg.sample_rate = SAMPLING_RATE_8KHZ;
1423 break;
1424 default:
1425 usb_tx_cfg.sample_rate = SAMPLING_RATE_48KHZ;
1426 break;
1427 }
1428
1429 pr_debug("%s: control value = %ld, usb_audio_tx_sample_rate = %d\n",
1430 __func__, ucontrol->value.integer.value[0],
1431 usb_tx_cfg.sample_rate);
1432 return 0;
1433}
1434
1435static int usb_audio_tx_format_get(struct snd_kcontrol *kcontrol,
1436 struct snd_ctl_elem_value *ucontrol)
1437{
1438 switch (usb_tx_cfg.bit_format) {
1439 case SNDRV_PCM_FORMAT_S32_LE:
1440 ucontrol->value.integer.value[0] = 3;
1441 break;
1442 case SNDRV_PCM_FORMAT_S24_3LE:
1443 ucontrol->value.integer.value[0] = 2;
1444 break;
1445 case SNDRV_PCM_FORMAT_S24_LE:
1446 ucontrol->value.integer.value[0] = 1;
1447 break;
1448 case SNDRV_PCM_FORMAT_S16_LE:
1449 default:
1450 ucontrol->value.integer.value[0] = 0;
1451 break;
1452 }
1453
1454 pr_debug("%s: usb_audio_tx_format = %d, ucontrol value = %ld\n",
1455 __func__, usb_tx_cfg.bit_format,
1456 ucontrol->value.integer.value[0]);
1457 return 0;
1458}
1459
1460static int usb_audio_tx_format_put(struct snd_kcontrol *kcontrol,
1461 struct snd_ctl_elem_value *ucontrol)
1462{
1463 int rc = 0;
1464
1465 switch (ucontrol->value.integer.value[0]) {
1466 case 3:
1467 usb_tx_cfg.bit_format = SNDRV_PCM_FORMAT_S32_LE;
1468 break;
1469 case 2:
1470 usb_tx_cfg.bit_format = SNDRV_PCM_FORMAT_S24_3LE;
1471 break;
1472 case 1:
1473 usb_tx_cfg.bit_format = SNDRV_PCM_FORMAT_S24_LE;
1474 break;
1475 case 0:
1476 default:
1477 usb_tx_cfg.bit_format = SNDRV_PCM_FORMAT_S16_LE;
1478 break;
1479 }
1480 pr_debug("%s: usb_audio_tx_format = %d, ucontrol value = %ld\n",
1481 __func__, usb_tx_cfg.bit_format,
1482 ucontrol->value.integer.value[0]);
1483
1484 return rc;
1485}
1486
1487const struct snd_kcontrol_new msm_common_snd_controls[] = {
1488 SOC_ENUM_EXT("PROXY_RX Channels", proxy_rx_chs,
1489 proxy_rx_ch_get, proxy_rx_ch_put),
1490 SOC_ENUM_EXT("PRIM_AUX_PCM_RX SampleRate", prim_aux_pcm_rx_sample_rate,
1491 aux_pcm_rx_sample_rate_get,
1492 aux_pcm_rx_sample_rate_put),
1493 SOC_ENUM_EXT("SEC_AUX_PCM_RX SampleRate", sec_aux_pcm_rx_sample_rate,
1494 aux_pcm_rx_sample_rate_get,
1495 aux_pcm_rx_sample_rate_put),
1496 SOC_ENUM_EXT("TERT_AUX_PCM_RX SampleRate", tert_aux_pcm_rx_sample_rate,
1497 aux_pcm_rx_sample_rate_get,
1498 aux_pcm_rx_sample_rate_put),
1499 SOC_ENUM_EXT("QUAT_AUX_PCM_RX SampleRate", quat_aux_pcm_rx_sample_rate,
1500 aux_pcm_rx_sample_rate_get,
1501 aux_pcm_rx_sample_rate_put),
1502 SOC_ENUM_EXT("PRIM_AUX_PCM_TX SampleRate", prim_aux_pcm_tx_sample_rate,
1503 aux_pcm_tx_sample_rate_get,
1504 aux_pcm_tx_sample_rate_put),
1505 SOC_ENUM_EXT("SEC_AUX_PCM_TX SampleRate", sec_aux_pcm_tx_sample_rate,
1506 aux_pcm_tx_sample_rate_get,
1507 aux_pcm_tx_sample_rate_put),
1508 SOC_ENUM_EXT("TERT_AUX_PCM_TX SampleRate", tert_aux_pcm_tx_sample_rate,
1509 aux_pcm_tx_sample_rate_get,
1510 aux_pcm_tx_sample_rate_put),
1511 SOC_ENUM_EXT("QUAT_AUX_PCM_TX SampleRate", quat_aux_pcm_tx_sample_rate,
1512 aux_pcm_tx_sample_rate_get,
1513 aux_pcm_tx_sample_rate_put),
1514 SOC_ENUM_EXT("PRIM_MI2S_RX SampleRate", prim_mi2s_rx_sample_rate,
1515 mi2s_rx_sample_rate_get,
1516 mi2s_rx_sample_rate_put),
1517 SOC_ENUM_EXT("SEC_MI2S_RX SampleRate", sec_mi2s_rx_sample_rate,
1518 mi2s_rx_sample_rate_get,
1519 mi2s_rx_sample_rate_put),
1520 SOC_ENUM_EXT("TERT_MI2S_RX SampleRate", tert_mi2s_rx_sample_rate,
1521 mi2s_rx_sample_rate_get,
1522 mi2s_rx_sample_rate_put),
1523 SOC_ENUM_EXT("QUAT_MI2S_RX SampleRate", quat_mi2s_rx_sample_rate,
1524 mi2s_rx_sample_rate_get,
1525 mi2s_rx_sample_rate_put),
1526 SOC_ENUM_EXT("PRIM_MI2S_TX SampleRate", prim_mi2s_tx_sample_rate,
1527 mi2s_tx_sample_rate_get,
1528 mi2s_tx_sample_rate_put),
1529 SOC_ENUM_EXT("SEC_MI2S_TX SampleRate", sec_mi2s_tx_sample_rate,
1530 mi2s_tx_sample_rate_get,
1531 mi2s_tx_sample_rate_put),
1532 SOC_ENUM_EXT("TERT_MI2S_TX SampleRate", tert_mi2s_tx_sample_rate,
1533 mi2s_tx_sample_rate_get,
1534 mi2s_tx_sample_rate_put),
1535 SOC_ENUM_EXT("QUAT_MI2S_TX SampleRate", quat_mi2s_tx_sample_rate,
1536 mi2s_tx_sample_rate_get,
1537 mi2s_tx_sample_rate_put),
1538 SOC_ENUM_EXT("PRIM_MI2S_RX Channels", prim_mi2s_rx_chs,
1539 msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
1540 SOC_ENUM_EXT("PRIM_MI2S_TX Channels", prim_mi2s_tx_chs,
1541 msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
1542 SOC_ENUM_EXT("SEC_MI2S_RX Channels", sec_mi2s_rx_chs,
1543 msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
1544 SOC_ENUM_EXT("SEC_MI2S_TX Channels", sec_mi2s_tx_chs,
1545 msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
1546 SOC_ENUM_EXT("TERT_MI2S_RX Channels", tert_mi2s_rx_chs,
1547 msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
1548 SOC_ENUM_EXT("TERT_MI2S_TX Channels", tert_mi2s_tx_chs,
1549 msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
1550 SOC_ENUM_EXT("QUAT_MI2S_RX Channels", quat_mi2s_rx_chs,
1551 msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
1552 SOC_ENUM_EXT("QUAT_MI2S_TX Channels", quat_mi2s_tx_chs,
1553 msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
1554 SOC_ENUM_EXT("USB_AUDIO_RX Channels", usb_rx_chs,
1555 usb_audio_rx_ch_get, usb_audio_rx_ch_put),
1556 SOC_ENUM_EXT("USB_AUDIO_TX Channels", usb_tx_chs,
1557 usb_audio_tx_ch_get, usb_audio_tx_ch_put),
1558 SOC_ENUM_EXT("USB_AUDIO_RX Format", usb_rx_format,
1559 usb_audio_rx_format_get, usb_audio_rx_format_put),
1560 SOC_ENUM_EXT("USB_AUDIO_TX Format", usb_tx_format,
1561 usb_audio_tx_format_get, usb_audio_tx_format_put),
1562 SOC_ENUM_EXT("USB_AUDIO_RX SampleRate", usb_rx_sample_rate,
1563 usb_audio_rx_sample_rate_get,
1564 usb_audio_rx_sample_rate_put),
1565 SOC_ENUM_EXT("USB_AUDIO_TX SampleRate", usb_tx_sample_rate,
1566 usb_audio_tx_sample_rate_get,
1567 usb_audio_tx_sample_rate_put),
1568 SOC_ENUM_EXT("PRI_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
1569 tdm_rx_sample_rate_get,
1570 tdm_rx_sample_rate_put),
1571 SOC_ENUM_EXT("PRI_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
1572 tdm_tx_sample_rate_get,
1573 tdm_tx_sample_rate_put),
1574 SOC_ENUM_EXT("PRI_TDM_RX_0 Format", tdm_rx_format,
1575 tdm_rx_format_get,
1576 tdm_rx_format_put),
1577 SOC_ENUM_EXT("PRI_TDM_TX_0 Format", tdm_tx_format,
1578 tdm_tx_format_get,
1579 tdm_tx_format_put),
1580 SOC_ENUM_EXT("PRI_TDM_RX_0 Channels", tdm_rx_chs,
1581 tdm_rx_ch_get,
1582 tdm_rx_ch_put),
1583 SOC_ENUM_EXT("PRI_TDM_TX_0 Channels", tdm_tx_chs,
1584 tdm_tx_ch_get,
1585 tdm_tx_ch_put),
1586 SOC_ENUM_EXT("SEC_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
1587 tdm_rx_sample_rate_get,
1588 tdm_rx_sample_rate_put),
1589 SOC_ENUM_EXT("SEC_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
1590 tdm_tx_sample_rate_get,
1591 tdm_tx_sample_rate_put),
1592 SOC_ENUM_EXT("SEC_TDM_RX_0 Format", tdm_rx_format,
1593 tdm_rx_format_get,
1594 tdm_rx_format_put),
1595 SOC_ENUM_EXT("SEC_TDM_TX_0 Format", tdm_tx_format,
1596 tdm_tx_format_get,
1597 tdm_tx_format_put),
1598 SOC_ENUM_EXT("SEC_TDM_RX_0 Channels", tdm_rx_chs,
1599 tdm_rx_ch_get,
1600 tdm_rx_ch_put),
1601 SOC_ENUM_EXT("SEC_TDM_TX_0 Channels", tdm_tx_chs,
1602 tdm_tx_ch_get,
1603 tdm_tx_ch_put),
1604 SOC_ENUM_EXT("TERT_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
1605 tdm_rx_sample_rate_get,
1606 tdm_rx_sample_rate_put),
1607 SOC_ENUM_EXT("TERT_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
1608 tdm_tx_sample_rate_get,
1609 tdm_tx_sample_rate_put),
1610 SOC_ENUM_EXT("TERT_TDM_RX_0 Format", tdm_rx_format,
1611 tdm_rx_format_get,
1612 tdm_rx_format_put),
1613 SOC_ENUM_EXT("TERT_TDM_TX_0 Format", tdm_tx_format,
1614 tdm_tx_format_get,
1615 tdm_tx_format_put),
1616 SOC_ENUM_EXT("TERT_TDM_RX_0 Channels", tdm_rx_chs,
1617 tdm_rx_ch_get,
1618 tdm_rx_ch_put),
1619 SOC_ENUM_EXT("TERT_TDM_TX_0 Channels", tdm_tx_chs,
1620 tdm_tx_ch_get,
1621 tdm_tx_ch_put),
1622 SOC_ENUM_EXT("QUAT_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
1623 tdm_rx_sample_rate_get,
1624 tdm_rx_sample_rate_put),
1625 SOC_ENUM_EXT("QUAT_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
1626 tdm_tx_sample_rate_get,
1627 tdm_tx_sample_rate_put),
1628 SOC_ENUM_EXT("QUAT_TDM_RX_0 Format", tdm_rx_format,
1629 tdm_rx_format_get,
1630 tdm_rx_format_put),
1631 SOC_ENUM_EXT("QUAT_TDM_TX_0 Format", tdm_tx_format,
1632 tdm_tx_format_get,
1633 tdm_tx_format_put),
1634 SOC_ENUM_EXT("QUAT_TDM_RX_0 Channels", tdm_rx_chs,
1635 tdm_rx_ch_get,
1636 tdm_rx_ch_put),
1637 SOC_ENUM_EXT("QUAT_TDM_TX_0 Channels", tdm_tx_chs,
1638 tdm_tx_ch_get,
1639 tdm_tx_ch_put),
1640};
1641
1642static inline int param_is_mask(int p)
1643{
1644 return (p >= SNDRV_PCM_HW_PARAM_FIRST_MASK) &&
1645 (p <= SNDRV_PCM_HW_PARAM_LAST_MASK);
1646}
1647
1648static inline struct snd_mask *param_to_mask(struct snd_pcm_hw_params *p,
1649 int n)
1650{
1651 return &(p->masks[n - SNDRV_PCM_HW_PARAM_FIRST_MASK]);
1652}
1653
1654static void param_set_mask(struct snd_pcm_hw_params *p, int n, unsigned int bit)
1655{
1656 if (bit >= SNDRV_MASK_MAX)
1657 return;
1658 if (param_is_mask(n)) {
1659 struct snd_mask *m = param_to_mask(p, n);
1660
1661 m->bits[0] = 0;
1662 m->bits[1] = 0;
1663 m->bits[bit >> 5] |= (1 << (bit & 31));
1664 }
1665}
1666
1667/**
1668 * msm_common_be_hw_params_fixup - updates settings of ALSA BE hw params.
1669 *
1670 * @rtd: runtime dailink instance
1671 * @params: HW params of associated backend dailink.
1672 *
1673 * Returns 0.
1674 */
1675int msm_common_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
1676 struct snd_pcm_hw_params *params)
1677{
1678 struct snd_soc_dai_link *dai_link = rtd->dai_link;
1679 struct snd_interval *rate = hw_param_interval(params,
1680 SNDRV_PCM_HW_PARAM_RATE);
1681 struct snd_interval *channels = hw_param_interval(params,
1682 SNDRV_PCM_HW_PARAM_CHANNELS);
1683 int rc = 0;
1684
1685 pr_debug("%s: format = %d, rate = %d\n",
1686 __func__, params_format(params), params_rate(params));
1687
1688 switch (dai_link->be_id) {
1689 case MSM_BACKEND_DAI_USB_RX:
1690 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
1691 usb_rx_cfg.bit_format);
1692 rate->min = rate->max = usb_rx_cfg.sample_rate;
1693 channels->min = channels->max = usb_rx_cfg.channels;
1694 break;
1695
1696 case MSM_BACKEND_DAI_USB_TX:
1697 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
1698 usb_tx_cfg.bit_format);
1699 rate->min = rate->max = usb_tx_cfg.sample_rate;
1700 channels->min = channels->max = usb_tx_cfg.channels;
1701 break;
1702
1703 case MSM_BACKEND_DAI_AFE_PCM_RX:
1704 channels->min = channels->max = proxy_rx_cfg.channels;
1705 rate->min = rate->max = SAMPLING_RATE_48KHZ;
1706 break;
1707
1708 case MSM_BACKEND_DAI_PRI_TDM_RX_0:
1709 channels->min = channels->max =
1710 tdm_rx_cfg[TDM_PRI][TDM_0].channels;
1711 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
1712 tdm_rx_cfg[TDM_PRI][TDM_0].bit_format);
1713 rate->min = rate->max = tdm_rx_cfg[TDM_PRI][TDM_0].sample_rate;
1714 break;
1715
1716 case MSM_BACKEND_DAI_PRI_TDM_TX_0:
1717 channels->min = channels->max =
1718 tdm_tx_cfg[TDM_PRI][TDM_0].channels;
1719 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
1720 tdm_tx_cfg[TDM_PRI][TDM_0].bit_format);
1721 rate->min = rate->max = tdm_tx_cfg[TDM_PRI][TDM_0].sample_rate;
1722 break;
1723
1724 case MSM_BACKEND_DAI_SEC_TDM_RX_0:
1725 channels->min = channels->max =
1726 tdm_rx_cfg[TDM_SEC][TDM_0].channels;
1727 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
1728 tdm_rx_cfg[TDM_SEC][TDM_0].bit_format);
1729 rate->min = rate->max = tdm_rx_cfg[TDM_SEC][TDM_0].sample_rate;
1730 break;
1731
1732 case MSM_BACKEND_DAI_SEC_TDM_TX_0:
1733 channels->min = channels->max =
1734 tdm_tx_cfg[TDM_SEC][TDM_0].channels;
1735 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
1736 tdm_tx_cfg[TDM_SEC][TDM_0].bit_format);
1737 rate->min = rate->max = tdm_tx_cfg[TDM_SEC][TDM_0].sample_rate;
1738 break;
1739
1740 case MSM_BACKEND_DAI_TERT_TDM_RX_0:
1741 channels->min = channels->max =
1742 tdm_rx_cfg[TDM_TERT][TDM_0].channels;
1743 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
1744 tdm_rx_cfg[TDM_TERT][TDM_0].bit_format);
1745 rate->min = rate->max = tdm_rx_cfg[TDM_TERT][TDM_0].sample_rate;
1746 break;
1747
1748 case MSM_BACKEND_DAI_TERT_TDM_TX_0:
1749 channels->min = channels->max =
1750 tdm_tx_cfg[TDM_TERT][TDM_0].channels;
1751 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
1752 tdm_tx_cfg[TDM_TERT][TDM_0].bit_format);
1753 rate->min = rate->max = tdm_tx_cfg[TDM_TERT][TDM_0].sample_rate;
1754 break;
1755
1756 case MSM_BACKEND_DAI_QUAT_TDM_RX_0:
1757 channels->min = channels->max =
1758 tdm_rx_cfg[TDM_QUAT][TDM_0].channels;
1759 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
1760 tdm_rx_cfg[TDM_QUAT][TDM_0].bit_format);
1761 rate->min = rate->max = tdm_rx_cfg[TDM_QUAT][TDM_0].sample_rate;
1762 break;
1763
1764 case MSM_BACKEND_DAI_QUAT_TDM_TX_0:
1765 channels->min = channels->max =
1766 tdm_tx_cfg[TDM_QUAT][TDM_0].channels;
1767 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
1768 tdm_tx_cfg[TDM_QUAT][TDM_0].bit_format);
1769 rate->min = rate->max = tdm_tx_cfg[TDM_QUAT][TDM_0].sample_rate;
1770 break;
1771
1772 case MSM_BACKEND_DAI_AUXPCM_RX:
1773 rate->min = rate->max =
1774 aux_pcm_rx_cfg[PRIM_AUX_PCM].sample_rate;
1775 channels->min = channels->max =
1776 aux_pcm_rx_cfg[PRIM_AUX_PCM].channels;
1777 break;
1778
1779 case MSM_BACKEND_DAI_AUXPCM_TX:
1780 rate->min = rate->max =
1781 aux_pcm_tx_cfg[PRIM_AUX_PCM].sample_rate;
1782 channels->min = channels->max =
1783 aux_pcm_tx_cfg[PRIM_AUX_PCM].channels;
1784 break;
1785
1786 case MSM_BACKEND_DAI_SEC_AUXPCM_RX:
1787 rate->min = rate->max =
1788 aux_pcm_rx_cfg[SEC_AUX_PCM].sample_rate;
1789 channels->min = channels->max =
1790 aux_pcm_rx_cfg[SEC_AUX_PCM].channels;
1791 break;
1792
1793 case MSM_BACKEND_DAI_SEC_AUXPCM_TX:
1794 rate->min = rate->max =
1795 aux_pcm_tx_cfg[SEC_AUX_PCM].sample_rate;
1796 channels->min = channels->max =
1797 aux_pcm_tx_cfg[SEC_AUX_PCM].channels;
1798 break;
1799
1800 case MSM_BACKEND_DAI_TERT_AUXPCM_RX:
1801 rate->min = rate->max =
1802 aux_pcm_rx_cfg[TERT_AUX_PCM].sample_rate;
1803 channels->min = channels->max =
1804 aux_pcm_rx_cfg[TERT_AUX_PCM].channels;
1805 break;
1806
1807 case MSM_BACKEND_DAI_TERT_AUXPCM_TX:
1808 rate->min = rate->max =
1809 aux_pcm_tx_cfg[TERT_AUX_PCM].sample_rate;
1810 channels->min = channels->max =
1811 aux_pcm_tx_cfg[TERT_AUX_PCM].channels;
1812 break;
1813
1814 case MSM_BACKEND_DAI_QUAT_AUXPCM_RX:
1815 rate->min = rate->max =
1816 aux_pcm_rx_cfg[QUAT_AUX_PCM].sample_rate;
1817 channels->min = channels->max =
1818 aux_pcm_rx_cfg[QUAT_AUX_PCM].channels;
1819 break;
1820
1821 case MSM_BACKEND_DAI_QUAT_AUXPCM_TX:
1822 rate->min = rate->max =
1823 aux_pcm_tx_cfg[QUAT_AUX_PCM].sample_rate;
1824 channels->min = channels->max =
1825 aux_pcm_tx_cfg[QUAT_AUX_PCM].channels;
1826 break;
1827
1828 case MSM_BACKEND_DAI_PRI_MI2S_RX:
1829 rate->min = rate->max = mi2s_rx_cfg[PRIM_MI2S].sample_rate;
1830 channels->min = channels->max =
1831 mi2s_rx_cfg[PRIM_MI2S].channels;
1832 break;
1833
1834 case MSM_BACKEND_DAI_PRI_MI2S_TX:
1835 rate->min = rate->max = mi2s_tx_cfg[PRIM_MI2S].sample_rate;
1836 channels->min = channels->max =
1837 mi2s_tx_cfg[PRIM_MI2S].channels;
1838 break;
1839
1840 case MSM_BACKEND_DAI_SECONDARY_MI2S_RX:
1841 rate->min = rate->max = mi2s_rx_cfg[SEC_MI2S].sample_rate;
1842 channels->min = channels->max =
1843 mi2s_rx_cfg[SEC_MI2S].channels;
1844 break;
1845
1846 case MSM_BACKEND_DAI_SECONDARY_MI2S_TX:
1847 rate->min = rate->max = mi2s_tx_cfg[SEC_MI2S].sample_rate;
1848 channels->min = channels->max =
1849 mi2s_tx_cfg[SEC_MI2S].channels;
1850 break;
1851
1852 case MSM_BACKEND_DAI_TERTIARY_MI2S_RX:
1853 rate->min = rate->max = mi2s_rx_cfg[TERT_MI2S].sample_rate;
1854 channels->min = channels->max =
1855 mi2s_rx_cfg[TERT_MI2S].channels;
1856 break;
1857
1858 case MSM_BACKEND_DAI_TERTIARY_MI2S_TX:
1859 rate->min = rate->max = mi2s_tx_cfg[TERT_MI2S].sample_rate;
1860 channels->min = channels->max =
1861 mi2s_tx_cfg[TERT_MI2S].channels;
1862 break;
1863
1864 case MSM_BACKEND_DAI_QUATERNARY_MI2S_RX:
1865 rate->min = rate->max = mi2s_rx_cfg[QUAT_MI2S].sample_rate;
1866 channels->min = channels->max =
1867 mi2s_rx_cfg[QUAT_MI2S].channels;
1868 break;
1869
1870 case MSM_BACKEND_DAI_QUATERNARY_MI2S_TX:
1871 rate->min = rate->max = mi2s_tx_cfg[QUAT_MI2S].sample_rate;
1872 channels->min = channels->max =
1873 mi2s_tx_cfg[QUAT_MI2S].channels;
1874 break;
1875
1876 default:
1877 rate->min = rate->max = SAMPLING_RATE_48KHZ;
1878 break;
1879 }
1880 return rc;
1881}
1882EXPORT_SYMBOL(msm_common_be_hw_params_fixup);
1883
1884/**
1885 * msm_aux_pcm_snd_startup - startup ops of auxpcm.
1886 *
1887 * @substream: PCM stream pointer of associated backend dailink
1888 *
1889 * Returns 0 on success or -EINVAL on error.
1890 */
1891int msm_aux_pcm_snd_startup(struct snd_pcm_substream *substream)
1892{
1893 int ret = 0;
1894 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1895 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1896 int index = cpu_dai->id - 1;
1897 return ret = 0;
1898
1899 dev_dbg(rtd->card->dev,
1900 "%s: substream = %s stream = %d, dai name %s, dai ID %d\n",
1901 __func__, substream->name, substream->stream,
1902 cpu_dai->name, cpu_dai->id);
1903
1904 if (index < PRIM_AUX_PCM || index > QUAT_AUX_PCM) {
1905 ret = -EINVAL;
1906 dev_err(rtd->card->dev,
1907 "%s: CPU DAI id (%d) out of range\n",
1908 __func__, cpu_dai->id);
1909 goto done;
1910 }
1911
1912 mutex_lock(&auxpcm_intf_conf[index].lock);
1913 if (++auxpcm_intf_conf[index].ref_cnt == 1) {
1914 if (mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr != NULL) {
1915 mutex_lock(&mi2s_auxpcm_conf[index].lock);
1916 iowrite32(1,
1917 mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr);
1918 mutex_unlock(&mi2s_auxpcm_conf[index].lock);
1919 } else {
1920 dev_err(rtd->card->dev,
1921 "%s lpaif_tert_muxsel_virt_addr is NULL\n",
1922 __func__);
1923 ret = -EINVAL;
1924 }
1925 }
Xiaoyu Ye1a2d8bd92017-01-31 18:54:15 -08001926 if (ret < 0)
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001927 auxpcm_intf_conf[index].ref_cnt--;
1928
1929 mutex_unlock(&auxpcm_intf_conf[index].lock);
1930
1931done:
1932 return ret;
1933}
1934EXPORT_SYMBOL(msm_aux_pcm_snd_startup);
1935
1936/**
1937 * msm_aux_pcm_snd_shutdown - shutdown ops of auxpcm.
1938 *
1939 * @substream: PCM stream pointer of associated backend dailink
1940 */
1941void msm_aux_pcm_snd_shutdown(struct snd_pcm_substream *substream)
1942{
1943 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1944 int index = rtd->cpu_dai->id - 1;
1945
1946 dev_dbg(rtd->card->dev,
1947 "%s: substream = %s stream = %d, dai name %s, dai ID %d\n",
1948 __func__,
1949 substream->name, substream->stream,
1950 rtd->cpu_dai->name, rtd->cpu_dai->id);
1951
1952 if (index < PRIM_AUX_PCM || index > QUAT_AUX_PCM) {
1953 dev_err(rtd->card->dev,
1954 "%s: CPU DAI id (%d) out of range\n",
1955 __func__, rtd->cpu_dai->id);
1956 return;
1957 }
1958
1959 mutex_lock(&auxpcm_intf_conf[index].lock);
1960 if (--auxpcm_intf_conf[index].ref_cnt == 0) {
1961 if (mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr != NULL) {
1962 mutex_lock(&mi2s_auxpcm_conf[index].lock);
1963 iowrite32(0,
1964 mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr);
1965 mutex_unlock(&mi2s_auxpcm_conf[index].lock);
1966 } else {
1967 dev_err(rtd->card->dev,
1968 "%s lpaif_tert_muxsel_virt_addr is NULL\n",
1969 __func__);
1970 auxpcm_intf_conf[index].ref_cnt++;
1971 }
1972 }
1973 mutex_unlock(&auxpcm_intf_conf[index].lock);
1974}
1975EXPORT_SYMBOL(msm_aux_pcm_snd_shutdown);
1976
1977static int msm_get_port_id(int be_id)
1978{
1979 int afe_port_id;
1980
1981 switch (be_id) {
1982 case MSM_BACKEND_DAI_PRI_MI2S_RX:
1983 afe_port_id = AFE_PORT_ID_PRIMARY_MI2S_RX;
1984 break;
1985 case MSM_BACKEND_DAI_PRI_MI2S_TX:
1986 afe_port_id = AFE_PORT_ID_PRIMARY_MI2S_TX;
1987 break;
1988 case MSM_BACKEND_DAI_SECONDARY_MI2S_RX:
1989 afe_port_id = AFE_PORT_ID_SECONDARY_MI2S_RX;
1990 break;
1991 case MSM_BACKEND_DAI_SECONDARY_MI2S_TX:
1992 afe_port_id = AFE_PORT_ID_SECONDARY_MI2S_TX;
1993 break;
1994 case MSM_BACKEND_DAI_TERTIARY_MI2S_RX:
1995 afe_port_id = AFE_PORT_ID_TERTIARY_MI2S_RX;
1996 break;
1997 case MSM_BACKEND_DAI_TERTIARY_MI2S_TX:
1998 afe_port_id = AFE_PORT_ID_TERTIARY_MI2S_TX;
1999 break;
2000 case MSM_BACKEND_DAI_QUATERNARY_MI2S_RX:
2001 afe_port_id = AFE_PORT_ID_QUATERNARY_MI2S_RX;
2002 break;
2003 case MSM_BACKEND_DAI_QUATERNARY_MI2S_TX:
2004 afe_port_id = AFE_PORT_ID_QUATERNARY_MI2S_TX;
2005 break;
2006 default:
2007 pr_err("%s: Invalid be_id: %d\n", __func__, be_id);
2008 afe_port_id = -EINVAL;
2009 }
2010
2011 return afe_port_id;
2012}
2013
2014static u32 get_mi2s_bits_per_sample(u32 bit_format)
2015{
2016 u32 bit_per_sample;
2017
2018 switch (bit_format) {
2019 case SNDRV_PCM_FORMAT_S24_3LE:
2020 case SNDRV_PCM_FORMAT_S24_LE:
2021 bit_per_sample = 32;
2022 break;
2023 case SNDRV_PCM_FORMAT_S16_LE:
2024 default:
2025 bit_per_sample = 16;
2026 break;
2027 }
2028
2029 return bit_per_sample;
2030}
2031
2032static void update_mi2s_clk_val(int dai_id, int stream)
2033{
2034 u32 bit_per_sample;
2035
2036 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
2037 bit_per_sample =
2038 get_mi2s_bits_per_sample(mi2s_rx_cfg[dai_id].bit_format);
2039 mi2s_clk[dai_id].clk_freq_in_hz =
2040 mi2s_rx_cfg[dai_id].sample_rate * 2 * bit_per_sample;
2041 } else {
2042 bit_per_sample =
2043 get_mi2s_bits_per_sample(mi2s_tx_cfg[dai_id].bit_format);
2044 mi2s_clk[dai_id].clk_freq_in_hz =
2045 mi2s_tx_cfg[dai_id].sample_rate * 2 * bit_per_sample;
2046 }
2047
2048 if (!mi2s_intf_conf[dai_id].msm_is_mi2s_master)
2049 mi2s_clk[dai_id].clk_freq_in_hz = 0;
2050}
2051
2052static int msm_mi2s_set_sclk(struct snd_pcm_substream *substream, bool enable)
2053{
2054 int ret = 0;
2055 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2056 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2057 int port_id = 0;
2058 int index = cpu_dai->id;
2059
2060 port_id = msm_get_port_id(rtd->dai_link->be_id);
Xiaoyu Ye1a2d8bd92017-01-31 18:54:15 -08002061 if (port_id < 0) {
Banajit Goswami0530e2f2016-12-09 21:34:37 -08002062 dev_err(rtd->card->dev, "%s: Invalid port_id\n", __func__);
2063 ret = port_id;
2064 goto done;
2065 }
2066
2067 if (enable) {
2068 update_mi2s_clk_val(index, substream->stream);
2069 dev_dbg(rtd->card->dev, "%s: clock rate %ul\n", __func__,
2070 mi2s_clk[index].clk_freq_in_hz);
2071 }
2072
2073 mi2s_clk[index].enable = enable;
2074 ret = afe_set_lpass_clock_v2(port_id,
2075 &mi2s_clk[index]);
2076 if (ret < 0) {
2077 dev_err(rtd->card->dev,
2078 "%s: afe lpass clock failed for port 0x%x , err:%d\n",
2079 __func__, port_id, ret);
2080 goto done;
2081 }
2082
2083done:
2084 return ret;
2085}
2086
2087/**
2088 * msm_mi2s_snd_startup - startup ops of mi2s.
2089 *
2090 * @substream: PCM stream pointer of associated backend dailink
2091 *
2092 * Returns 0 on success or -EINVAL on error.
2093 */
2094int msm_mi2s_snd_startup(struct snd_pcm_substream *substream)
2095{
2096 int ret = 0;
2097 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2098 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2099 int index = cpu_dai->id;
2100 unsigned int fmt = SND_SOC_DAIFMT_CBS_CFS;
2101
2102 dev_dbg(rtd->card->dev,
2103 "%s: substream = %s stream = %d, dai name %s, dai ID %d\n",
2104 __func__, substream->name, substream->stream,
2105 cpu_dai->name, cpu_dai->id);
2106
2107 if (index < PRIM_MI2S || index > QUAT_MI2S) {
2108 ret = -EINVAL;
2109 dev_err(rtd->card->dev,
2110 "%s: CPU DAI id (%d) out of range\n",
2111 __func__, cpu_dai->id);
2112 goto done;
2113 }
2114 /*
2115 * Muxtex protection in case the same MI2S
2116 * interface using for both TX and RX so
2117 * that the same clock won't be enable twice.
2118 */
2119 mutex_lock(&mi2s_intf_conf[index].lock);
2120 if (++mi2s_intf_conf[index].ref_cnt == 1) {
2121 ret = msm_mi2s_set_sclk(substream, true);
Xiaoyu Ye1a2d8bd92017-01-31 18:54:15 -08002122 if (ret < 0) {
Banajit Goswami0530e2f2016-12-09 21:34:37 -08002123 dev_err(rtd->card->dev,
2124 "%s: afe lpass clock failed to enable MI2S clock, err:%d\n",
2125 __func__, ret);
2126 goto clean_up;
2127 }
2128 if (mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr != NULL) {
2129 mutex_lock(&mi2s_auxpcm_conf[index].lock);
2130 iowrite32(0,
2131 mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr);
2132 mutex_unlock(&mi2s_auxpcm_conf[index].lock);
2133 } else {
2134 dev_err(rtd->card->dev,
2135 "%s lpaif_muxsel_virt_addr is NULL for dai %d\n",
2136 __func__, index);
2137 ret = -EINVAL;
2138 goto clk_off;
2139 }
2140 /* Check if msm needs to provide the clock to the interface */
2141 if (!mi2s_intf_conf[index].msm_is_mi2s_master)
2142 fmt = SND_SOC_DAIFMT_CBM_CFM;
2143 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
Xiaoyu Ye1a2d8bd92017-01-31 18:54:15 -08002144 if (ret < 0) {
Banajit Goswami0530e2f2016-12-09 21:34:37 -08002145 dev_err(rtd->card->dev,
2146 "%s: set fmt cpu dai failed for MI2S (%d), err:%d\n",
2147 __func__, index, ret);
2148 goto clk_off;
2149 }
2150 }
2151clk_off:
Xiaoyu Ye1a2d8bd92017-01-31 18:54:15 -08002152 if (ret < 0)
Banajit Goswami0530e2f2016-12-09 21:34:37 -08002153 msm_mi2s_set_sclk(substream, false);
2154clean_up:
Xiaoyu Ye1a2d8bd92017-01-31 18:54:15 -08002155 if (ret < 0)
Banajit Goswami0530e2f2016-12-09 21:34:37 -08002156 mi2s_intf_conf[index].ref_cnt--;
2157 mutex_unlock(&mi2s_intf_conf[index].lock);
2158done:
2159 return ret;
2160}
2161EXPORT_SYMBOL(msm_mi2s_snd_startup);
2162
2163/**
2164 * msm_mi2s_snd_shutdown - shutdown ops of mi2s.
2165 *
2166 * @substream: PCM stream pointer of associated backend dailink
2167 */
2168void msm_mi2s_snd_shutdown(struct snd_pcm_substream *substream)
2169{
2170 int ret;
2171 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2172 int index = rtd->cpu_dai->id;
2173
2174 pr_debug("%s(): substream = %s stream = %d\n", __func__,
2175 substream->name, substream->stream);
2176 if (index < PRIM_MI2S || index > QUAT_MI2S) {
2177 pr_err("%s:invalid MI2S DAI(%d)\n", __func__, index);
2178 return;
2179 }
2180
2181 mutex_lock(&mi2s_intf_conf[index].lock);
2182 if (--mi2s_intf_conf[index].ref_cnt == 0) {
2183 ret = msm_mi2s_set_sclk(substream, false);
2184 if (ret < 0) {
2185 pr_err("%s:clock disable failed for MI2S (%d); ret=%d\n",
2186 __func__, index, ret);
2187 mi2s_intf_conf[index].ref_cnt++;
2188 }
2189 }
2190 mutex_unlock(&mi2s_intf_conf[index].lock);
2191}
2192EXPORT_SYMBOL(msm_mi2s_snd_shutdown);
2193
2194/* Validate whether US EU switch is present or not */
2195static int msm_prepare_us_euro(struct snd_soc_card *card)
2196{
2197 struct msm_asoc_mach_data *pdata =
2198 snd_soc_card_get_drvdata(card);
2199 int ret = 0;
2200
2201 if (pdata->us_euro_gpio >= 0) {
2202 dev_dbg(card->dev, "%s: us_euro gpio request %d", __func__,
2203 pdata->us_euro_gpio);
2204 ret = gpio_request(pdata->us_euro_gpio, "TASHA_CODEC_US_EURO");
2205 if (ret) {
2206 dev_err(card->dev,
2207 "%s: Failed to request codec US/EURO gpio %d error %d\n",
2208 __func__, pdata->us_euro_gpio, ret);
2209 }
2210 }
2211
2212 return ret;
2213}
2214
2215static bool msm_swap_gnd_mic(struct snd_soc_codec *codec)
2216{
2217 struct snd_soc_card *card = codec->component.card;
2218 struct msm_asoc_mach_data *pdata =
2219 snd_soc_card_get_drvdata(card);
2220 int value = 0;
2221
2222 if (pdata->us_euro_gpio_p) {
2223 value = msm_cdc_pinctrl_get_state(pdata->us_euro_gpio_p);
2224 if (value)
2225 msm_cdc_pinctrl_select_sleep_state(
2226 pdata->us_euro_gpio_p);
2227 else
2228 msm_cdc_pinctrl_select_active_state(
2229 pdata->us_euro_gpio_p);
2230 } else if (pdata->us_euro_gpio >= 0) {
2231 value = gpio_get_value_cansleep(pdata->us_euro_gpio);
2232 gpio_set_value_cansleep(pdata->us_euro_gpio, !value);
2233 }
2234 pr_debug("%s: swap select switch %d to %d\n", __func__, value, !value);
2235 return true;
2236}
2237
2238static int msm_populate_dai_link_component_of_node(
Laxminath Kasame68e94f2016-12-09 12:08:00 +05302239 struct msm_asoc_mach_data *pdata,
Banajit Goswami0530e2f2016-12-09 21:34:37 -08002240 struct snd_soc_card *card)
2241{
2242 int i, index, ret = 0;
2243 struct device *cdev = card->dev;
2244 struct snd_soc_dai_link *dai_link = card->dai_link;
2245 struct device_node *phandle;
2246
2247 if (!cdev) {
2248 pr_err("%s: Sound card device memory NULL\n", __func__);
2249 return -ENODEV;
2250 }
2251
2252 for (i = 0; i < card->num_links; i++) {
2253 if (dai_link[i].platform_of_node && dai_link[i].cpu_of_node)
2254 continue;
2255
2256 /* populate platform_of_node for snd card dai links */
2257 if (dai_link[i].platform_name &&
2258 !dai_link[i].platform_of_node) {
2259 index = of_property_match_string(cdev->of_node,
2260 "asoc-platform-names",
2261 dai_link[i].platform_name);
2262 if (index < 0) {
2263 pr_err("%s: No match found for platform name: %s\n",
2264 __func__, dai_link[i].platform_name);
2265 ret = index;
2266 goto cpu_dai;
2267 }
2268 phandle = of_parse_phandle(cdev->of_node,
2269 "asoc-platform",
2270 index);
2271 if (!phandle) {
2272 pr_err("%s: retrieving phandle for platform %s, index %d failed\n",
2273 __func__, dai_link[i].platform_name,
2274 index);
2275 ret = -ENODEV;
2276 goto err;
2277 }
2278 dai_link[i].platform_of_node = phandle;
2279 dai_link[i].platform_name = NULL;
2280 }
2281cpu_dai:
2282 /* populate cpu_of_node for snd card dai links */
2283 if (dai_link[i].cpu_dai_name && !dai_link[i].cpu_of_node) {
2284 index = of_property_match_string(cdev->of_node,
2285 "asoc-cpu-names",
2286 dai_link[i].cpu_dai_name);
2287 if (index < 0)
2288 goto codec_dai;
2289 phandle = of_parse_phandle(cdev->of_node, "asoc-cpu",
2290 index);
2291 if (!phandle) {
2292 pr_err("%s: retrieving phandle for cpu dai %s failed\n",
2293 __func__, dai_link[i].cpu_dai_name);
2294 ret = -ENODEV;
2295 goto err;
2296 }
2297 dai_link[i].cpu_of_node = phandle;
2298 dai_link[i].cpu_dai_name = NULL;
2299 }
2300codec_dai:
2301 /* populate codec_of_node for snd card dai links */
2302 if (dai_link[i].codec_name && !dai_link[i].codec_of_node) {
2303 index = of_property_match_string(cdev->of_node,
2304 "asoc-codec-names",
2305 dai_link[i].codec_name);
2306 if (index < 0)
2307 continue;
2308 phandle = of_parse_phandle(cdev->of_node, "asoc-codec",
2309 index);
2310 if (!phandle) {
2311 pr_err("%s: retrieving phandle for codec dai %s failed\n",
2312 __func__, dai_link[i].codec_name);
2313 ret = -ENODEV;
2314 goto err;
2315 }
2316 dai_link[i].codec_of_node = phandle;
2317 dai_link[i].codec_name = NULL;
2318 }
Laxminath Kasame68e94f2016-12-09 12:08:00 +05302319 if (pdata->int_codec) {
2320 if ((dai_link[i].be_id ==
2321 MSM_BACKEND_DAI_INT0_MI2S_RX) ||
2322 (dai_link[i].be_id ==
2323 MSM_BACKEND_DAI_INT1_MI2S_RX) ||
2324 (dai_link[i].be_id ==
2325 MSM_BACKEND_DAI_INT2_MI2S_TX) ||
2326 (dai_link[i].be_id ==
2327 MSM_BACKEND_DAI_INT3_MI2S_TX)) {
2328 index = of_property_match_string(cdev->of_node,
2329 "asoc-codec-names",
2330 MSM_INT_DIGITAL_CODEC);
2331 phandle = of_parse_phandle(cdev->of_node,
2332 "asoc-codec",
2333 index);
2334 dai_link[i].codecs[DIG_CDC].of_node = phandle;
2335 index = of_property_match_string(cdev->of_node,
2336 "asoc-codec-names",
2337 PMIC_INT_ANALOG_CODEC);
2338 phandle = of_parse_phandle(cdev->of_node,
2339 "asoc-codec",
2340 index);
2341 dai_link[i].codecs[ANA_CDC].of_node = phandle;
2342 }
2343 }
Banajit Goswami0530e2f2016-12-09 21:34:37 -08002344 }
2345err:
2346 return ret;
2347}
2348
2349static int msm_wsa881x_init(struct snd_soc_component *component)
2350{
2351 u8 spkleft_ports[WSA881X_MAX_SWR_PORTS] = {100, 101, 102, 106};
2352 u8 spkright_ports[WSA881X_MAX_SWR_PORTS] = {103, 104, 105, 107};
2353 unsigned int ch_rate[WSA881X_MAX_SWR_PORTS] = {2400, 600, 300, 1200};
2354 unsigned int ch_mask[WSA881X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
2355 struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
2356 struct msm_asoc_mach_data *pdata;
2357 struct snd_soc_dapm_context *dapm =
2358 snd_soc_codec_get_dapm(codec);
2359
2360 if (!codec) {
2361 pr_err("%s codec is NULL\n", __func__);
2362 return -EINVAL;
2363 }
2364
2365 if (!strcmp(component->name_prefix, "SpkrLeft")) {
2366 dev_dbg(codec->dev, "%s: setting left ch map to codec %s\n",
2367 __func__, codec->component.name);
2368 wsa881x_set_channel_map(codec, &spkleft_ports[0],
2369 WSA881X_MAX_SWR_PORTS, &ch_mask[0],
2370 &ch_rate[0]);
2371 if (dapm->component) {
2372 snd_soc_dapm_ignore_suspend(dapm, "SpkrLeft IN");
2373 snd_soc_dapm_ignore_suspend(dapm, "SpkrLeft SPKR");
2374 }
2375 } else if (!strcmp(component->name_prefix, "SpkrRight")) {
2376 dev_dbg(codec->dev, "%s: setting right ch map to codec %s\n",
2377 __func__, codec->component.name);
2378 wsa881x_set_channel_map(codec, &spkright_ports[0],
2379 WSA881X_MAX_SWR_PORTS, &ch_mask[0],
2380 &ch_rate[0]);
2381 if (dapm->component) {
2382 snd_soc_dapm_ignore_suspend(dapm, "SpkrRight IN");
2383 snd_soc_dapm_ignore_suspend(dapm, "SpkrRight SPKR");
2384 }
2385 } else {
2386 dev_err(codec->dev, "%s: wrong codec name %s\n", __func__,
2387 codec->component.name);
2388 return -EINVAL;
2389 }
2390
2391
2392 pdata = snd_soc_card_get_drvdata(component->card);
2393 if (pdata && pdata->codec_root)
2394 wsa881x_codec_info_create_codec_entry(pdata->codec_root,
2395 codec);
2396 return 0;
2397}
2398
2399
2400static int msm_init_wsa_dev(struct platform_device *pdev,
2401 struct snd_soc_card *card)
2402{
2403 struct device_node *wsa_of_node;
2404 u32 wsa_max_devs;
2405 u32 wsa_dev_cnt;
2406 char *dev_name_str = NULL;
2407 struct msm_wsa881x_dev_info *wsa881x_dev_info;
2408 const char *wsa_auxdev_name_prefix[1];
2409 int found = 0;
2410 int i;
2411 int ret;
2412
2413 /* Get maximum WSA device count for this platform */
2414 ret = of_property_read_u32(pdev->dev.of_node,
2415 "qcom,wsa-max-devs", &wsa_max_devs);
2416 if (ret) {
2417 dev_dbg(&pdev->dev,
2418 "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
2419 __func__, pdev->dev.of_node->full_name, ret);
2420 goto err_dt;
2421 }
2422 if (wsa_max_devs == 0) {
2423 dev_warn(&pdev->dev,
2424 "%s: Max WSA devices is 0 for this target?\n",
2425 __func__);
2426 goto err_dt;
2427 }
2428
2429 /* Get count of WSA device phandles for this platform */
2430 wsa_dev_cnt = of_count_phandle_with_args(pdev->dev.of_node,
2431 "qcom,wsa-devs", NULL);
2432 if (wsa_dev_cnt == -ENOENT) {
2433 dev_warn(&pdev->dev, "%s: No wsa device defined in DT.\n",
2434 __func__);
2435 goto err_dt;
2436 } else if (wsa_dev_cnt <= 0) {
2437 dev_err(&pdev->dev,
2438 "%s: Error reading wsa device from DT. wsa_dev_cnt = %d\n",
2439 __func__, wsa_dev_cnt);
2440 ret = -EINVAL;
2441 goto err_dt;
2442 }
2443
2444 /*
2445 * Expect total phandles count to be NOT less than maximum possible
2446 * WSA count. However, if it is less, then assign same value to
2447 * max count as well.
2448 */
2449 if (wsa_dev_cnt < wsa_max_devs) {
2450 dev_dbg(&pdev->dev,
2451 "%s: wsa_max_devs = %d cannot exceed wsa_dev_cnt = %d\n",
2452 __func__, wsa_max_devs, wsa_dev_cnt);
2453 wsa_max_devs = wsa_dev_cnt;
2454 }
2455
2456 /* Make sure prefix string passed for each WSA device */
2457 ret = of_property_count_strings(pdev->dev.of_node,
2458 "qcom,wsa-aux-dev-prefix");
2459 if (ret != wsa_dev_cnt) {
2460 dev_err(&pdev->dev,
2461 "%s: expecting %d wsa prefix. Defined only %d in DT\n",
2462 __func__, wsa_dev_cnt, ret);
2463 ret = -EINVAL;
2464 goto err_dt;
2465 }
2466
2467 /*
2468 * Alloc mem to store phandle and index info of WSA device, if already
2469 * registered with ALSA core
2470 */
2471 wsa881x_dev_info = devm_kcalloc(&pdev->dev, wsa_max_devs,
2472 sizeof(struct msm_wsa881x_dev_info),
2473 GFP_KERNEL);
2474 if (!wsa881x_dev_info) {
2475 ret = -ENOMEM;
2476 goto err_mem;
2477 }
2478
2479 /*
2480 * search and check whether all WSA devices are already
2481 * registered with ALSA core or not. If found a node, store
2482 * the node and the index in a local array of struct for later
2483 * use.
2484 */
2485 for (i = 0; i < wsa_dev_cnt; i++) {
2486 wsa_of_node = of_parse_phandle(pdev->dev.of_node,
2487 "qcom,wsa-devs", i);
2488 if (unlikely(!wsa_of_node)) {
2489 /* we should not be here */
2490 dev_err(&pdev->dev,
2491 "%s: wsa dev node is not present\n",
2492 __func__);
2493 ret = -EINVAL;
2494 goto err_dev_node;
2495 }
2496 if (soc_find_component(wsa_of_node, NULL)) {
2497 /* WSA device registered with ALSA core */
2498 wsa881x_dev_info[found].of_node = wsa_of_node;
2499 wsa881x_dev_info[found].index = i;
2500 found++;
2501 if (found == wsa_max_devs)
2502 break;
2503 }
2504 }
2505
2506 if (found < wsa_max_devs) {
2507 dev_dbg(&pdev->dev,
2508 "%s: failed to find %d components. Found only %d\n",
2509 __func__, wsa_max_devs, found);
2510 return -EPROBE_DEFER;
2511 }
2512 dev_info(&pdev->dev,
2513 "%s: found %d wsa881x devices registered with ALSA core\n",
2514 __func__, found);
2515
2516 card->num_aux_devs = wsa_max_devs;
2517 card->num_configs = wsa_max_devs;
2518
2519 /* Alloc array of AUX devs struct */
2520 msm_aux_dev = devm_kcalloc(&pdev->dev, card->num_aux_devs,
2521 sizeof(struct snd_soc_aux_dev),
2522 GFP_KERNEL);
2523 if (!msm_aux_dev) {
2524 ret = -ENOMEM;
2525 goto err_auxdev_mem;
2526 }
2527
2528 /* Alloc array of codec conf struct */
2529 msm_codec_conf = devm_kcalloc(&pdev->dev, card->num_aux_devs,
2530 sizeof(struct snd_soc_codec_conf),
2531 GFP_KERNEL);
2532 if (!msm_codec_conf) {
2533 ret = -ENOMEM;
2534 goto err_codec_conf;
2535 }
2536
2537 for (i = 0; i < card->num_aux_devs; i++) {
2538 dev_name_str = devm_kzalloc(&pdev->dev, DEV_NAME_STR_LEN,
2539 GFP_KERNEL);
2540 if (!dev_name_str) {
2541 ret = -ENOMEM;
2542 goto err_dev_str;
2543 }
2544
2545 ret = of_property_read_string_index(pdev->dev.of_node,
2546 "qcom,wsa-aux-dev-prefix",
2547 wsa881x_dev_info[i].index,
2548 wsa_auxdev_name_prefix);
2549 if (ret) {
2550 dev_err(&pdev->dev,
2551 "%s: failed to read wsa aux dev prefix, ret = %d\n",
2552 __func__, ret);
2553 ret = -EINVAL;
2554 goto err_dt_prop;
2555 }
2556
2557 snprintf(dev_name_str, strlen("wsa881x.%d"), "wsa881x.%d", i);
2558 msm_aux_dev[i].name = dev_name_str;
2559 msm_aux_dev[i].codec_name = NULL;
2560 msm_aux_dev[i].codec_of_node =
2561 wsa881x_dev_info[i].of_node;
2562 msm_aux_dev[i].init = msm_wsa881x_init;
2563 msm_codec_conf[i].dev_name = NULL;
2564 msm_codec_conf[i].name_prefix = wsa_auxdev_name_prefix[0];
2565 msm_codec_conf[i].of_node = wsa881x_dev_info[i].of_node;
2566 }
2567 card->codec_conf = msm_codec_conf;
2568 card->aux_dev = msm_aux_dev;
2569
2570 return 0;
2571
2572err_dt_prop:
2573 devm_kfree(&pdev->dev, dev_name_str);
2574err_dev_str:
2575 devm_kfree(&pdev->dev, msm_codec_conf);
2576err_codec_conf:
2577 devm_kfree(&pdev->dev, msm_aux_dev);
2578err_auxdev_mem:
2579err_dev_node:
2580 devm_kfree(&pdev->dev, wsa881x_dev_info);
2581err_mem:
2582err_dt:
2583 return ret;
2584}
2585
2586static void msm_free_auxdev_mem(struct platform_device *pdev)
2587{
2588 struct snd_soc_card *card = platform_get_drvdata(pdev);
2589 int i;
2590
2591 if (card->num_aux_devs > 0) {
2592 for (i = 0; i < card->num_aux_devs; i++) {
2593 kfree(msm_aux_dev[i].codec_name);
2594 kfree(msm_codec_conf[i].dev_name);
2595 kfree(msm_codec_conf[i].name_prefix);
2596 }
2597 }
2598}
2599
2600static void i2s_auxpcm_init(struct platform_device *pdev)
2601{
2602 struct resource *muxsel;
2603 int count;
2604 u32 mi2s_master_slave[MI2S_MAX];
2605 int ret;
2606 char *str[PCM_I2S_SEL_MAX] = {
2607 "lpaif_pri_mode_muxsel",
2608 "lpaif_sec_mode_muxsel",
2609 "lpaif_tert_mode_muxsel",
2610 "lpaif_quat_mode_muxsel"
2611 };
2612
2613 for (count = 0; count < MI2S_MAX; count++) {
2614 mutex_init(&mi2s_intf_conf[count].lock);
2615 mi2s_intf_conf[count].ref_cnt = 0;
2616 }
2617
2618 for (count = 0; count < AUX_PCM_MAX; count++) {
2619 mutex_init(&auxpcm_intf_conf[count].lock);
2620 auxpcm_intf_conf[count].ref_cnt = 0;
2621 }
2622
2623 for (count = 0; count < PCM_I2S_SEL_MAX; count++) {
2624 mutex_init(&mi2s_auxpcm_conf[count].lock);
2625 mi2s_auxpcm_conf[count].pcm_i2s_sel_vt_addr = NULL;
2626 }
2627
2628 for (count = 0; count < PCM_I2S_SEL_MAX; count++) {
2629 muxsel = platform_get_resource_byname(pdev, IORESOURCE_MEM,
2630 str[count]);
2631 if (muxsel) {
2632 mi2s_auxpcm_conf[count].pcm_i2s_sel_vt_addr
2633 = ioremap(muxsel->start, resource_size(muxsel));
2634 }
2635 }
2636
2637 ret = of_property_read_u32_array(pdev->dev.of_node,
2638 "qcom,msm-mi2s-master",
2639 mi2s_master_slave, MI2S_MAX);
2640 if (ret) {
2641 dev_dbg(&pdev->dev, "%s: no qcom,msm-mi2s-master in DT node\n",
2642 __func__);
2643 } else {
2644 for (count = 0; count < MI2S_MAX; count++) {
2645 mi2s_intf_conf[count].msm_is_mi2s_master =
2646 mi2s_master_slave[count];
2647 }
2648 }
2649}
2650
2651static void i2s_auxpcm_deinit(void)
2652{
2653 int count;
2654
2655 for (count = 0; count < PCM_I2S_SEL_MAX; count++)
2656 if (mi2s_auxpcm_conf[count].pcm_i2s_sel_vt_addr !=
2657 NULL)
2658 iounmap(
2659 mi2s_auxpcm_conf[count].pcm_i2s_sel_vt_addr);
2660}
2661
2662static const struct of_device_id msmfalcon_asoc_machine_of_match[] = {
2663 { .compatible = "qcom,msmfalcon-asoc-snd",
2664 .data = "internal_codec"},
2665 { .compatible = "qcom,msmfalcon-asoc-snd-tasha",
2666 .data = "tasha_codec"},
2667 { .compatible = "qcom,msmfalcon-asoc-snd-tavil",
2668 .data = "tavil_codec"},
2669 {},
2670};
2671
2672static int msm_asoc_machine_probe(struct platform_device *pdev)
2673{
2674 struct snd_soc_card *card = NULL;
2675 struct msm_asoc_mach_data *pdata = NULL;
2676 const char *mclk = "qcom,msm-mclk-freq";
2677 int ret = -EINVAL, id;
2678 const struct of_device_id *match;
2679
2680 pdata = devm_kzalloc(&pdev->dev,
2681 sizeof(struct msm_asoc_mach_data),
2682 GFP_KERNEL);
2683 if (!pdata)
2684 return -ENOMEM;
2685
2686 match = of_match_node(msmfalcon_asoc_machine_of_match,
2687 pdev->dev.of_node);
2688 if (!match)
2689 goto err;
2690
2691 ret = of_property_read_u32(pdev->dev.of_node, mclk, &id);
2692 if (ret) {
2693 dev_err(&pdev->dev,
2694 "%s: missing %s in dt node\n", __func__, mclk);
2695 id = DEFAULT_MCLK_RATE;
2696 }
2697 pdata->mclk_freq = id;
2698
2699 if (!strcmp(match->data, "tasha_codec") ||
2700 !strcmp(match->data, "tavil_codec")) {
2701 if (!strcmp(match->data, "tasha_codec"))
2702 pdata->snd_card_val = EXT_SND_CARD_TASHA;
2703 else
2704 pdata->snd_card_val = EXT_SND_CARD_TAVIL;
2705 ret = msm_ext_cdc_init(pdev, pdata, &card, &mbhc_cfg);
2706 if (ret)
2707 goto err;
2708 } else if (!strcmp(match->data, "internal_codec")) {
2709 pdata->snd_card_val = INT_SND_CARD;
2710 ret = msm_int_cdc_init(pdev, pdata, &card, &mbhc_cfg);
2711 if (ret)
2712 goto err;
2713 } else {
2714 dev_err(&pdev->dev,
2715 "%s: Not a matching DT sound node\n", __func__);
2716 goto err;
2717 }
2718 if (!card)
2719 goto err;
2720
2721 if (pdata->snd_card_val == INT_SND_CARD) {
2722 /*reading the gpio configurations from dtsi file*/
2723 ret = msm_gpioset_initialize(CLIENT_WCD, &pdev->dev);
2724 if (ret < 0) {
2725 dev_err(&pdev->dev,
2726 "%s: error reading dtsi files%d\n",
2727 __func__, ret);
2728 goto err;
2729 }
2730 }
2731
2732 /*
2733 * Parse US-Euro gpio info from DT. Report no error if us-euro
2734 * entry is not found in DT file as some targets do not support
2735 * US-Euro detection
2736 */
2737 pdata->us_euro_gpio = of_get_named_gpio(pdev->dev.of_node,
2738 "qcom,us-euro-gpios", 0);
2739 if (!gpio_is_valid(pdata->us_euro_gpio))
2740 pdata->us_euro_gpio_p = of_parse_phandle(pdev->dev.of_node,
2741 "qcom,us-euro-gpios", 0);
2742 if (!gpio_is_valid(pdata->us_euro_gpio) && (!pdata->us_euro_gpio_p)) {
2743 dev_dbg(&pdev->dev, "property %s not detected in node %s",
2744 "qcom,us-euro-gpios", pdev->dev.of_node->full_name);
2745 } else {
2746 dev_dbg(&pdev->dev, "%s detected",
2747 "qcom,us-euro-gpios");
2748 mbhc_cfg.swap_gnd_mic = msm_swap_gnd_mic;
2749 }
2750
2751 ret = msm_prepare_us_euro(card);
2752 if (ret)
2753 dev_dbg(&pdev->dev, "msm_prepare_us_euro failed (%d)\n",
2754 ret);
2755
2756 i2s_auxpcm_init(pdev);
2757
2758 ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
2759 if (ret)
2760 goto err;
2761
Laxminath Kasame68e94f2016-12-09 12:08:00 +05302762 ret = msm_populate_dai_link_component_of_node(pdata, card);
Banajit Goswami0530e2f2016-12-09 21:34:37 -08002763 if (ret) {
2764 ret = -EPROBE_DEFER;
2765 goto err;
2766 }
2767 ret = msm_init_wsa_dev(pdev, card);
2768 if (ret)
2769 goto err;
2770
2771
2772 ret = devm_snd_soc_register_card(&pdev->dev, card);
2773 if (ret) {
2774 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
2775 ret);
2776 goto err;
2777 }
Banajit Goswami0530e2f2016-12-09 21:34:37 -08002778 return 0;
2779err:
2780 if (pdata->us_euro_gpio > 0) {
2781 dev_dbg(&pdev->dev, "%s free us_euro gpio %d\n",
2782 __func__, pdata->us_euro_gpio);
2783 pdata->us_euro_gpio = 0;
2784 }
2785 if (pdata->hph_en1_gpio > 0) {
2786 dev_dbg(&pdev->dev, "%s free hph_en1_gpio %d\n",
2787 __func__, pdata->hph_en1_gpio);
2788 gpio_free(pdata->hph_en1_gpio);
2789 pdata->hph_en1_gpio = 0;
2790 }
2791 if (pdata->hph_en0_gpio > 0) {
2792 dev_dbg(&pdev->dev, "%s free hph_en0_gpio %d\n",
2793 __func__, pdata->hph_en0_gpio);
2794 gpio_free(pdata->hph_en0_gpio);
2795 pdata->hph_en0_gpio = 0;
2796 }
2797 devm_kfree(&pdev->dev, pdata);
2798 return ret;
2799}
2800
2801static int msm_asoc_machine_remove(struct platform_device *pdev)
2802{
2803 struct snd_soc_card *card = platform_get_drvdata(pdev);
2804 struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
2805
2806 if (pdata->snd_card_val == INT_SND_CARD)
2807 mutex_destroy(&pdata->cdc_int_mclk0_mutex);
2808 msm_free_auxdev_mem(pdev);
2809
2810 gpio_free(pdata->us_euro_gpio);
2811 gpio_free(pdata->hph_en1_gpio);
2812 gpio_free(pdata->hph_en0_gpio);
2813 i2s_auxpcm_deinit();
2814 snd_soc_unregister_card(card);
2815 return 0;
2816}
2817
2818static struct platform_driver msmfalcon_asoc_machine_driver = {
2819 .driver = {
2820 .name = DRV_NAME,
2821 .owner = THIS_MODULE,
2822 .pm = &snd_soc_pm_ops,
2823 .of_match_table = msmfalcon_asoc_machine_of_match,
2824 },
2825 .probe = msm_asoc_machine_probe,
2826 .remove = msm_asoc_machine_remove,
2827};
2828module_platform_driver(msmfalcon_asoc_machine_driver);
2829
2830MODULE_DESCRIPTION("ALSA SoC msm");
2831MODULE_LICENSE("GPL v2");
2832MODULE_ALIAS("platform:" DRV_NAME);
2833MODULE_DEVICE_TABLE(of, msmfalcon_asoc_machine_of_match);