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