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