blob: b603b8a49613e94849a04fa014524ab97735372a [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/delay.h>
14#include <linux/of_gpio.h>
15#include <linux/platform_device.h>
16#include <linux/module.h>
17#include <sound/soc.h>
18#include <sound/pcm.h>
19#include <sound/pcm_params.h>
20#include <sound/q6core.h>
21#include <linux/qdsp6v2/audio_notifier.h>
22#include "qdsp6v2/msm-pcm-routing-v2.h"
23#include "msm-audio-pinctrl.h"
Neeraj Upadhyay49934422016-12-27 19:03:35 +053024#include "sdm660-common.h"
25#include "sdm660-external.h"
Banajit Goswami0530e2f2016-12-09 21:34:37 -080026#include "../codecs/wcd9335.h"
27#include "../codecs/wcd934x/wcd934x.h"
28#include "../codecs/wcd934x/wcd934x-mbhc.h"
29
Neeraj Upadhyay49934422016-12-27 19:03:35 +053030#define SDM660_SPK_ON 1
31#define SDM660_SPK_OFF 0
Banajit Goswami0530e2f2016-12-09 21:34:37 -080032
33#define WCD9XXX_MBHC_DEF_BUTTONS 8
34#define WCD9XXX_MBHC_DEF_RLOADS 5
35#define CODEC_EXT_CLK_RATE 9600000
36#define ADSP_STATE_READY_TIMEOUT_MS 3000
37
Laxminath Kasamfb36dc12016-11-28 23:04:47 +053038#define TLMM_CENTER_MPM_WAKEUP_INT_EN_0 0x03596000
39#define LPI_GPIO_22_WAKEUP_VAL 0x00000002
40
41#define TLMM_LPI_DIR_CONN_INTR1_CFG_APPS 0x0359D004
42#define LPI_GPIO_22_INTR1_CFG_VAL 0x01
43#define LPI_GPIO_22_INTR1_CFG_MASK 0x03
44
45#define TLMM_LPI_GPIO_INTR_CFG1 0x0359B004
46#define LPI_GPIO_INTR_CFG1_VAL 0x00000113
47
48#define TLMM_LPI_GPIO22_CFG 0x15078040
49#define LPI_GPIO22_CFG_VAL 0x0000009
50
Yeleswarapu Nagaradhesh8d42ce02017-01-25 20:33:29 +053051#define TLMM_LPI_GPIO22_INOUT 0x179D1318
52#define LPI_GPIO22_INOUT_VAL 0x0020000
Laxminath Kasamfb36dc12016-11-28 23:04:47 +053053
Banajit Goswami0530e2f2016-12-09 21:34:37 -080054#define WSA8810_NAME_1 "wsa881x.20170211"
55#define WSA8810_NAME_2 "wsa881x.20170212"
56
57static int msm_ext_spk_control = 1;
58static struct wcd_mbhc_config *wcd_mbhc_cfg_ptr;
Laxminath Kasam54dc88a2016-12-22 19:44:52 +053059bool codec_reg_done;
Banajit Goswami0530e2f2016-12-09 21:34:37 -080060
61struct msm_asoc_wcd93xx_codec {
62 void* (*get_afe_config_fn)(struct snd_soc_codec *codec,
63 enum afe_config_type config_type);
64 void (*mbhc_hs_detect_exit)(struct snd_soc_codec *codec);
65};
66
67static struct msm_asoc_wcd93xx_codec msm_codec_fn;
68static struct platform_device *spdev;
69
70static bool is_initial_boot;
71
72static void *def_ext_mbhc_cal(void);
73
74enum {
75 SLIM_RX_0 = 0,
76 SLIM_RX_1,
77 SLIM_RX_2,
78 SLIM_RX_3,
79 SLIM_RX_4,
80 SLIM_RX_5,
81 SLIM_RX_6,
82 SLIM_RX_7,
83 SLIM_RX_MAX,
84};
85
86enum {
87 SLIM_TX_0 = 0,
88 SLIM_TX_1,
89 SLIM_TX_2,
90 SLIM_TX_3,
91 SLIM_TX_4,
92 SLIM_TX_5,
93 SLIM_TX_6,
94 SLIM_TX_7,
95 SLIM_TX_8,
96 SLIM_TX_MAX,
97};
98
99struct dev_config {
100 u32 sample_rate;
101 u32 bit_format;
102 u32 channels;
103};
104
105/* Default configuration of slimbus channels */
106static struct dev_config slim_rx_cfg[] = {
107 [SLIM_RX_0] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
108 [SLIM_RX_1] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
109 [SLIM_RX_2] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
110 [SLIM_RX_3] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
111 [SLIM_RX_4] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
112 [SLIM_RX_5] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
113 [SLIM_RX_6] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
114 [SLIM_RX_7] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
115};
116
117static struct dev_config slim_tx_cfg[] = {
118 [SLIM_TX_0] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
119 [SLIM_TX_1] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
120 [SLIM_TX_2] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
121 [SLIM_TX_3] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
122 [SLIM_TX_4] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
123 [SLIM_TX_5] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
124 [SLIM_TX_6] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
125 [SLIM_TX_7] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
126 [SLIM_TX_8] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
127};
128
129static int msm_vi_feed_tx_ch = 2;
130static const char *const slim_rx_ch_text[] = {"One", "Two"};
131static const char *const slim_tx_ch_text[] = {"One", "Two", "Three", "Four",
132 "Five", "Six", "Seven",
133 "Eight"};
134static const char *const vi_feed_ch_text[] = {"One", "Two"};
135static char const *bit_format_text[] = {"S16_LE", "S24_LE", "S24_3LE",
136 "S32_LE"};
137static char const *slim_sample_rate_text[] = {"KHZ_8", "KHZ_16",
138 "KHZ_32", "KHZ_44P1", "KHZ_48",
139 "KHZ_88P2", "KHZ_96", "KHZ_176P4",
140 "KHZ_192", "KHZ_352P8", "KHZ_384"};
141static const char *const spk_function_text[] = {"Off", "On"};
142static char const *bt_sample_rate_text[] = {"KHZ_8", "KHZ_16", "KHZ_48"};
143
144static SOC_ENUM_SINGLE_EXT_DECL(spk_func_en, spk_function_text);
145static SOC_ENUM_SINGLE_EXT_DECL(slim_0_rx_chs, slim_rx_ch_text);
146static SOC_ENUM_SINGLE_EXT_DECL(slim_2_rx_chs, slim_rx_ch_text);
147static SOC_ENUM_SINGLE_EXT_DECL(slim_0_tx_chs, slim_tx_ch_text);
148static SOC_ENUM_SINGLE_EXT_DECL(slim_1_tx_chs, slim_tx_ch_text);
149static SOC_ENUM_SINGLE_EXT_DECL(slim_5_rx_chs, slim_rx_ch_text);
150static SOC_ENUM_SINGLE_EXT_DECL(slim_6_rx_chs, slim_rx_ch_text);
151static SOC_ENUM_SINGLE_EXT_DECL(vi_feed_tx_chs, vi_feed_ch_text);
152static SOC_ENUM_SINGLE_EXT_DECL(slim_0_rx_format, bit_format_text);
153static SOC_ENUM_SINGLE_EXT_DECL(slim_5_rx_format, bit_format_text);
154static SOC_ENUM_SINGLE_EXT_DECL(slim_6_rx_format, bit_format_text);
155static SOC_ENUM_SINGLE_EXT_DECL(slim_0_tx_format, bit_format_text);
156static SOC_ENUM_SINGLE_EXT_DECL(slim_0_rx_sample_rate, slim_sample_rate_text);
157static SOC_ENUM_SINGLE_EXT_DECL(slim_2_rx_sample_rate, slim_sample_rate_text);
158static SOC_ENUM_SINGLE_EXT_DECL(slim_0_tx_sample_rate, slim_sample_rate_text);
159static SOC_ENUM_SINGLE_EXT_DECL(slim_5_rx_sample_rate, slim_sample_rate_text);
160static SOC_ENUM_SINGLE_EXT_DECL(slim_6_rx_sample_rate, slim_sample_rate_text);
161static SOC_ENUM_SINGLE_EXT_DECL(bt_sample_rate, bt_sample_rate_text);
162
163static int slim_get_sample_rate_val(int sample_rate)
164{
165 int sample_rate_val = 0;
166
167 switch (sample_rate) {
168 case SAMPLING_RATE_8KHZ:
169 sample_rate_val = 0;
170 break;
171 case SAMPLING_RATE_16KHZ:
172 sample_rate_val = 1;
173 break;
174 case SAMPLING_RATE_32KHZ:
175 sample_rate_val = 2;
176 break;
177 case SAMPLING_RATE_44P1KHZ:
178 sample_rate_val = 3;
179 break;
180 case SAMPLING_RATE_48KHZ:
181 sample_rate_val = 4;
182 break;
183 case SAMPLING_RATE_88P2KHZ:
184 sample_rate_val = 5;
185 break;
186 case SAMPLING_RATE_96KHZ:
187 sample_rate_val = 6;
188 break;
189 case SAMPLING_RATE_176P4KHZ:
190 sample_rate_val = 7;
191 break;
192 case SAMPLING_RATE_192KHZ:
193 sample_rate_val = 8;
194 break;
195 case SAMPLING_RATE_352P8KHZ:
196 sample_rate_val = 9;
197 break;
198 case SAMPLING_RATE_384KHZ:
199 sample_rate_val = 10;
200 break;
201 default:
202 sample_rate_val = 4;
203 break;
204 }
205 return sample_rate_val;
206}
207
208static int slim_get_sample_rate(int value)
209{
210 int sample_rate = 0;
211
212 switch (value) {
213 case 0:
214 sample_rate = SAMPLING_RATE_8KHZ;
215 break;
216 case 1:
217 sample_rate = SAMPLING_RATE_16KHZ;
218 break;
219 case 2:
220 sample_rate = SAMPLING_RATE_32KHZ;
221 break;
222 case 3:
223 sample_rate = SAMPLING_RATE_44P1KHZ;
224 break;
225 case 4:
226 sample_rate = SAMPLING_RATE_48KHZ;
227 break;
228 case 5:
229 sample_rate = SAMPLING_RATE_88P2KHZ;
230 break;
231 case 6:
232 sample_rate = SAMPLING_RATE_96KHZ;
233 break;
234 case 7:
235 sample_rate = SAMPLING_RATE_176P4KHZ;
236 break;
237 case 8:
238 sample_rate = SAMPLING_RATE_192KHZ;
239 break;
240 case 9:
241 sample_rate = SAMPLING_RATE_352P8KHZ;
242 break;
243 case 10:
244 sample_rate = SAMPLING_RATE_384KHZ;
245 break;
246 default:
247 sample_rate = SAMPLING_RATE_48KHZ;
248 break;
249 }
250 return sample_rate;
251}
252
253static int slim_get_bit_format_val(int bit_format)
254{
255 int val = 0;
256
257 switch (bit_format) {
258 case SNDRV_PCM_FORMAT_S32_LE:
259 val = 3;
260 break;
261 case SNDRV_PCM_FORMAT_S24_3LE:
262 val = 2;
263 break;
264 case SNDRV_PCM_FORMAT_S24_LE:
265 val = 1;
266 break;
267 case SNDRV_PCM_FORMAT_S16_LE:
268 default:
269 val = 0;
270 break;
271 }
272 return val;
273}
274
275static int slim_get_bit_format(int val)
276{
277 int bit_fmt = SNDRV_PCM_FORMAT_S16_LE;
278
279 switch (val) {
280 case 0:
281 bit_fmt = SNDRV_PCM_FORMAT_S16_LE;
282 break;
283 case 1:
284 bit_fmt = SNDRV_PCM_FORMAT_S24_LE;
285 break;
286 case 2:
287 bit_fmt = SNDRV_PCM_FORMAT_S24_3LE;
288 break;
289 case 3:
290 bit_fmt = SNDRV_PCM_FORMAT_S32_LE;
291 break;
292 default:
293 bit_fmt = SNDRV_PCM_FORMAT_S16_LE;
294 break;
295 }
296 return bit_fmt;
297}
298
299static int slim_get_port_idx(struct snd_kcontrol *kcontrol)
300{
301 int port_id = 0;
302
303 if (strnstr(kcontrol->id.name, "SLIM_0_RX", sizeof("SLIM_0_RX")))
304 port_id = SLIM_RX_0;
305 else if (strnstr(kcontrol->id.name, "SLIM_2_RX", sizeof("SLIM_2_RX")))
306 port_id = SLIM_RX_2;
307 else if (strnstr(kcontrol->id.name, "SLIM_5_RX", sizeof("SLIM_5_RX")))
308 port_id = SLIM_RX_5;
309 else if (strnstr(kcontrol->id.name, "SLIM_6_RX", sizeof("SLIM_6_RX")))
310 port_id = SLIM_RX_6;
311 else if (strnstr(kcontrol->id.name, "SLIM_0_TX", sizeof("SLIM_0_TX")))
312 port_id = SLIM_TX_0;
313 else if (strnstr(kcontrol->id.name, "SLIM_1_TX", sizeof("SLIM_1_TX")))
314 port_id = SLIM_TX_1;
315 else {
316 pr_err("%s: unsupported channel: %s",
317 __func__, kcontrol->id.name);
318 return -EINVAL;
319 }
320
321 return port_id;
322}
323
324static int msm_bt_sample_rate_get(struct snd_kcontrol *kcontrol,
325 struct snd_ctl_elem_value *ucontrol)
326{
327 /*
328 * Slimbus_7_Rx/Tx sample rate values should always be in sync (same)
329 * when used for BT_SCO use case. Return either Rx or Tx sample rate
330 * value.
331 */
332 switch (slim_rx_cfg[SLIM_RX_7].sample_rate) {
333 case SAMPLING_RATE_48KHZ:
334 ucontrol->value.integer.value[0] = 2;
335 break;
336 case SAMPLING_RATE_16KHZ:
337 ucontrol->value.integer.value[0] = 1;
338 break;
339 case SAMPLING_RATE_8KHZ:
340 default:
341 ucontrol->value.integer.value[0] = 0;
342 break;
343 }
344 pr_debug("%s: sample rate = %d", __func__,
345 slim_rx_cfg[SLIM_RX_7].sample_rate);
346
347 return 0;
348}
349
350static int msm_bt_sample_rate_put(struct snd_kcontrol *kcontrol,
351 struct snd_ctl_elem_value *ucontrol)
352{
353 switch (ucontrol->value.integer.value[0]) {
354 case 1:
355 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_16KHZ;
356 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_16KHZ;
357 break;
358 case 2:
359 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_48KHZ;
360 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_48KHZ;
361 break;
362 case 0:
363 default:
364 slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_8KHZ;
365 slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_8KHZ;
366 break;
367 }
368 pr_debug("%s: sample rates: slim7_rx = %d, slim7_tx = %d, value = %d\n",
369 __func__,
370 slim_rx_cfg[SLIM_RX_7].sample_rate,
371 slim_tx_cfg[SLIM_TX_7].sample_rate,
372 ucontrol->value.enumerated.item[0]);
373
374 return 0;
375}
376
377static int slim_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
378 struct snd_ctl_elem_value *ucontrol)
379{
380 int ch_num = slim_get_port_idx(kcontrol);
381
382 if (ch_num < 0)
383 return ch_num;
384
385 ucontrol->value.enumerated.item[0] =
386 slim_get_sample_rate_val(slim_rx_cfg[ch_num].sample_rate);
387
388 pr_debug("%s: slim[%d]_rx_sample_rate = %d, item = %d\n", __func__,
389 ch_num, slim_rx_cfg[ch_num].sample_rate,
390 ucontrol->value.enumerated.item[0]);
391
392 return 0;
393}
394
395static int slim_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
396 struct snd_ctl_elem_value *ucontrol)
397{
398 int ch_num = slim_get_port_idx(kcontrol);
399
400 if (ch_num < 0)
401 return ch_num;
402
403 slim_rx_cfg[ch_num].sample_rate =
404 slim_get_sample_rate(ucontrol->value.enumerated.item[0]);
405
406 pr_debug("%s: slim[%d]_rx_sample_rate = %d, item = %d\n", __func__,
407 ch_num, slim_rx_cfg[ch_num].sample_rate,
408 ucontrol->value.enumerated.item[0]);
409
410 return 0;
411}
412
413static int slim_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
414 struct snd_ctl_elem_value *ucontrol)
415{
416 int ch_num = slim_get_port_idx(kcontrol);
417
418 if (ch_num < 0)
419 return ch_num;
420
421 ucontrol->value.enumerated.item[0] =
422 slim_get_sample_rate_val(slim_tx_cfg[ch_num].sample_rate);
423
424 pr_debug("%s: slim[%d]_tx_sample_rate = %d, item = %d\n", __func__,
425 ch_num, slim_tx_cfg[ch_num].sample_rate,
426 ucontrol->value.enumerated.item[0]);
427
428 return 0;
429}
430
431static int slim_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
432 struct snd_ctl_elem_value *ucontrol)
433{
434 int sample_rate = 0;
435 int ch_num = slim_get_port_idx(kcontrol);
436
437 if (ch_num < 0)
438 return ch_num;
439
440 sample_rate = slim_get_sample_rate(ucontrol->value.enumerated.item[0]);
441 if (sample_rate == SAMPLING_RATE_44P1KHZ) {
442 pr_err("%s: Unsupported sample rate %d: for Tx path\n",
443 __func__, sample_rate);
444 return -EINVAL;
445 }
446 slim_tx_cfg[ch_num].sample_rate = sample_rate;
447
448 pr_debug("%s: slim[%d]_tx_sample_rate = %d, value = %d\n", __func__,
449 ch_num, slim_tx_cfg[ch_num].sample_rate,
450 ucontrol->value.enumerated.item[0]);
451
452 return 0;
453}
454
455static int slim_rx_bit_format_get(struct snd_kcontrol *kcontrol,
456 struct snd_ctl_elem_value *ucontrol)
457{
458 int ch_num = slim_get_port_idx(kcontrol);
459
460 if (ch_num < 0)
461 return ch_num;
462
463 ucontrol->value.enumerated.item[0] =
464 slim_get_bit_format_val(slim_rx_cfg[ch_num].bit_format);
465
466 pr_debug("%s: slim[%d]_rx_bit_format = %d, ucontrol value = %d\n",
467 __func__, ch_num, slim_rx_cfg[ch_num].bit_format,
468 ucontrol->value.enumerated.item[0]);
469
470 return 0;
471}
472
473static int slim_rx_bit_format_put(struct snd_kcontrol *kcontrol,
474 struct snd_ctl_elem_value *ucontrol)
475{
476 int ch_num = slim_get_port_idx(kcontrol);
477
478 if (ch_num < 0)
479 return ch_num;
480
481 slim_rx_cfg[ch_num].bit_format =
482 slim_get_bit_format(ucontrol->value.enumerated.item[0]);
483
484 pr_debug("%s: slim[%d]_rx_bit_format = %d, ucontrol value = %d\n",
485 __func__, ch_num, slim_rx_cfg[ch_num].bit_format,
486 ucontrol->value.enumerated.item[0]);
487
488 return 0;
489}
490
491static int slim_tx_bit_format_get(struct snd_kcontrol *kcontrol,
492 struct snd_ctl_elem_value *ucontrol)
493{
494 int ch_num = slim_get_port_idx(kcontrol);
495
496 if (ch_num < 0)
497 return ch_num;
498
499 ucontrol->value.enumerated.item[0] =
500 slim_get_bit_format_val(slim_tx_cfg[ch_num].bit_format);
501
502 pr_debug("%s: slim[%d]_tx_bit_format = %d, ucontrol value = %d\n",
503 __func__, ch_num, slim_tx_cfg[ch_num].bit_format,
504 ucontrol->value.enumerated.item[0]);
505
506 return 0;
507}
508
509static int slim_tx_bit_format_put(struct snd_kcontrol *kcontrol,
510 struct snd_ctl_elem_value *ucontrol)
511{
512 int ch_num = slim_get_port_idx(kcontrol);
513
514 if (ch_num < 0)
515 return ch_num;
516
517 slim_tx_cfg[ch_num].bit_format =
518 slim_get_bit_format(ucontrol->value.enumerated.item[0]);
519
520 pr_debug("%s: slim[%d]_tx_bit_format = %d, ucontrol value = %d\n",
521 __func__, ch_num, slim_tx_cfg[ch_num].bit_format,
522 ucontrol->value.enumerated.item[0]);
523
524 return 0;
525}
526
527static int msm_slim_rx_ch_get(struct snd_kcontrol *kcontrol,
528 struct snd_ctl_elem_value *ucontrol)
529{
530 int ch_num = slim_get_port_idx(kcontrol);
531
532 if (ch_num < 0)
533 return ch_num;
534
535 pr_debug("%s: msm_slim_[%d]_rx_ch = %d\n", __func__,
536 ch_num, slim_rx_cfg[ch_num].channels);
537 ucontrol->value.enumerated.item[0] = slim_rx_cfg[ch_num].channels - 1;
538
539 return 0;
540}
541
542static int msm_slim_rx_ch_put(struct snd_kcontrol *kcontrol,
543 struct snd_ctl_elem_value *ucontrol)
544{
545 int ch_num = slim_get_port_idx(kcontrol);
546
547 if (ch_num < 0)
548 return ch_num;
549
550 slim_rx_cfg[ch_num].channels = ucontrol->value.enumerated.item[0] + 1;
551 pr_debug("%s: msm_slim_[%d]_rx_ch = %d\n", __func__,
552 ch_num, slim_rx_cfg[ch_num].channels);
553
554 return 1;
555}
556
557static int msm_slim_tx_ch_get(struct snd_kcontrol *kcontrol,
558 struct snd_ctl_elem_value *ucontrol)
559{
560 int ch_num = slim_get_port_idx(kcontrol);
561
562 if (ch_num < 0)
563 return ch_num;
564
565 pr_debug("%s: msm_slim_[%d]_tx_ch = %d\n", __func__,
566 ch_num, slim_tx_cfg[ch_num].channels);
567 ucontrol->value.enumerated.item[0] = slim_tx_cfg[ch_num].channels - 1;
568
569 return 0;
570}
571
572static int msm_slim_tx_ch_put(struct snd_kcontrol *kcontrol,
573 struct snd_ctl_elem_value *ucontrol)
574{
575 int ch_num = slim_get_port_idx(kcontrol);
576
577 if (ch_num < 0)
578 return ch_num;
579
580 slim_tx_cfg[ch_num].channels = ucontrol->value.enumerated.item[0] + 1;
581 pr_debug("%s: msm_slim_[%d]_tx_ch = %d\n", __func__,
582 ch_num, slim_tx_cfg[ch_num].channels);
583
584 return 1;
585}
586
587static int msm_vi_feed_tx_ch_get(struct snd_kcontrol *kcontrol,
588 struct snd_ctl_elem_value *ucontrol)
589{
590 ucontrol->value.integer.value[0] = msm_vi_feed_tx_ch - 1;
591 pr_debug("%s: msm_vi_feed_tx_ch = %ld\n", __func__,
592 ucontrol->value.integer.value[0]);
593 return 0;
594}
595
596static int msm_vi_feed_tx_ch_put(struct snd_kcontrol *kcontrol,
597 struct snd_ctl_elem_value *ucontrol)
598{
599 msm_vi_feed_tx_ch = ucontrol->value.integer.value[0] + 1;
600
601 pr_debug("%s: msm_vi_feed_tx_ch = %d\n", __func__, msm_vi_feed_tx_ch);
602 return 1;
603}
604
605static void *def_ext_mbhc_cal(void)
606{
607 void *tavil_wcd_cal;
608 struct wcd_mbhc_btn_detect_cfg *btn_cfg;
609 u16 *btn_high;
610
611 tavil_wcd_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS,
612 WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL);
613 if (!tavil_wcd_cal)
614 return NULL;
615
616#define S(X, Y) ((WCD_MBHC_CAL_PLUG_TYPE_PTR(tavil_wcd_cal)->X) = (Y))
617 S(v_hs_max, 1600);
618#undef S
619#define S(X, Y) ((WCD_MBHC_CAL_BTN_DET_PTR(tavil_wcd_cal)->X) = (Y))
620 S(num_btn, WCD_MBHC_DEF_BUTTONS);
621#undef S
622
623 btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(tavil_wcd_cal);
624 btn_high = ((void *)&btn_cfg->_v_btn_low) +
625 (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn);
626
627 btn_high[0] = 75;
628 btn_high[1] = 150;
629 btn_high[2] = 237;
630 btn_high[3] = 500;
631 btn_high[4] = 500;
632 btn_high[5] = 500;
633 btn_high[6] = 500;
634 btn_high[7] = 500;
635
636 return tavil_wcd_cal;
637}
638
639static inline int param_is_mask(int p)
640{
641 return (p >= SNDRV_PCM_HW_PARAM_FIRST_MASK) &&
642 (p <= SNDRV_PCM_HW_PARAM_LAST_MASK);
643}
644
645static inline struct snd_mask *param_to_mask(struct snd_pcm_hw_params *p, int n)
646{
647 return &(p->masks[n - SNDRV_PCM_HW_PARAM_FIRST_MASK]);
648}
649
650
651static void msm_ext_control(struct snd_soc_codec *codec)
652{
653 struct snd_soc_dapm_context *dapm =
654 snd_soc_codec_get_dapm(codec);
655
656 pr_debug("%s: msm_ext_spk_control = %d", __func__, msm_ext_spk_control);
Neeraj Upadhyay49934422016-12-27 19:03:35 +0530657 if (msm_ext_spk_control == SDM660_SPK_ON) {
Banajit Goswami0530e2f2016-12-09 21:34:37 -0800658 snd_soc_dapm_enable_pin(dapm, "Lineout_1 amp");
659 snd_soc_dapm_enable_pin(dapm, "Lineout_3 amp");
660 } else {
661 snd_soc_dapm_disable_pin(dapm, "Lineout_1 amp");
662 snd_soc_dapm_disable_pin(dapm, "Lineout_3 amp");
663 }
664 snd_soc_dapm_sync(dapm);
665}
666
667static int msm_ext_get_spk(struct snd_kcontrol *kcontrol,
668 struct snd_ctl_elem_value *ucontrol)
669{
670 pr_debug("%s: msm_ext_spk_control = %d\n",
671 __func__, msm_ext_spk_control);
672 ucontrol->value.integer.value[0] = msm_ext_spk_control;
673 return 0;
674}
675
676static int msm_ext_set_spk(struct snd_kcontrol *kcontrol,
677 struct snd_ctl_elem_value *ucontrol)
678{
Rohit Kumarcc4ae642017-02-09 17:52:56 +0530679 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
Banajit Goswami0530e2f2016-12-09 21:34:37 -0800680
681 pr_debug("%s()\n", __func__);
682 if (msm_ext_spk_control == ucontrol->value.integer.value[0])
683 return 0;
684
685 msm_ext_spk_control = ucontrol->value.integer.value[0];
686 msm_ext_control(codec);
687 return 1;
688}
689
690
691int msm_ext_enable_codec_mclk(struct snd_soc_codec *codec, int enable,
692 bool dapm)
693{
694 int ret;
695
696 pr_debug("%s: enable = %d\n", __func__, enable);
697
698 if (!strcmp(dev_name(codec->dev), "tasha_codec"))
699 ret = tasha_cdc_mclk_enable(codec, enable, dapm);
700 else if (!strcmp(dev_name(codec->dev), "tavil_codec"))
701 ret = tavil_cdc_mclk_enable(codec, enable);
702 else {
703 dev_err(codec->dev, "%s: unknown codec to enable ext clk\n",
704 __func__);
705 ret = -EINVAL;
706 }
707 return ret;
708}
709
710static const struct snd_kcontrol_new msm_snd_controls[] = {
711 SOC_ENUM_EXT("Speaker Function", spk_func_en, msm_ext_get_spk,
712 msm_ext_set_spk),
713 SOC_ENUM_EXT("SLIM_0_RX Channels", slim_0_rx_chs,
714 msm_slim_rx_ch_get, msm_slim_rx_ch_put),
715 SOC_ENUM_EXT("SLIM_2_RX Channels", slim_2_rx_chs,
716 msm_slim_rx_ch_get, msm_slim_rx_ch_put),
717 SOC_ENUM_EXT("SLIM_0_TX Channels", slim_0_tx_chs,
718 msm_slim_tx_ch_get, msm_slim_tx_ch_put),
719 SOC_ENUM_EXT("SLIM_1_TX Channels", slim_1_tx_chs,
720 msm_slim_tx_ch_get, msm_slim_tx_ch_put),
721 SOC_ENUM_EXT("SLIM_5_RX Channels", slim_5_rx_chs,
722 msm_slim_rx_ch_get, msm_slim_rx_ch_put),
723 SOC_ENUM_EXT("SLIM_6_RX Channels", slim_6_rx_chs,
724 msm_slim_rx_ch_get, msm_slim_rx_ch_put),
725 SOC_ENUM_EXT("VI_FEED_TX Channels", vi_feed_tx_chs,
726 msm_vi_feed_tx_ch_get, msm_vi_feed_tx_ch_put),
727 SOC_ENUM_EXT("SLIM_0_RX Format", slim_0_rx_format,
728 slim_rx_bit_format_get, slim_rx_bit_format_put),
729 SOC_ENUM_EXT("SLIM_5_RX Format", slim_5_rx_format,
730 slim_rx_bit_format_get, slim_rx_bit_format_put),
731 SOC_ENUM_EXT("SLIM_6_RX Format", slim_6_rx_format,
732 slim_rx_bit_format_get, slim_rx_bit_format_put),
733 SOC_ENUM_EXT("SLIM_0_TX Format", slim_0_tx_format,
734 slim_tx_bit_format_get, slim_tx_bit_format_put),
735 SOC_ENUM_EXT("SLIM_0_RX SampleRate", slim_0_rx_sample_rate,
736 slim_rx_sample_rate_get, slim_rx_sample_rate_put),
737 SOC_ENUM_EXT("SLIM_2_RX SampleRate", slim_2_rx_sample_rate,
738 slim_rx_sample_rate_get, slim_rx_sample_rate_put),
739 SOC_ENUM_EXT("SLIM_0_TX SampleRate", slim_0_tx_sample_rate,
740 slim_tx_sample_rate_get, slim_tx_sample_rate_put),
741 SOC_ENUM_EXT("SLIM_5_RX SampleRate", slim_5_rx_sample_rate,
742 slim_rx_sample_rate_get, slim_rx_sample_rate_put),
743 SOC_ENUM_EXT("SLIM_6_RX SampleRate", slim_6_rx_sample_rate,
744 slim_rx_sample_rate_get, slim_rx_sample_rate_put),
745 SOC_ENUM_EXT("BT SampleRate", bt_sample_rate,
746 msm_bt_sample_rate_get,
747 msm_bt_sample_rate_put),
748};
749
750static int msm_slim_get_ch_from_beid(int32_t be_id)
751{
752 int ch_id = 0;
753
754 switch (be_id) {
755 case MSM_BACKEND_DAI_SLIMBUS_0_RX:
756 ch_id = SLIM_RX_0;
757 break;
758 case MSM_BACKEND_DAI_SLIMBUS_1_RX:
759 ch_id = SLIM_RX_1;
760 break;
761 case MSM_BACKEND_DAI_SLIMBUS_2_RX:
762 ch_id = SLIM_RX_2;
763 break;
764 case MSM_BACKEND_DAI_SLIMBUS_3_RX:
765 ch_id = SLIM_RX_3;
766 break;
767 case MSM_BACKEND_DAI_SLIMBUS_4_RX:
768 ch_id = SLIM_RX_4;
769 break;
770 case MSM_BACKEND_DAI_SLIMBUS_6_RX:
771 ch_id = SLIM_RX_6;
772 break;
773 case MSM_BACKEND_DAI_SLIMBUS_0_TX:
774 ch_id = SLIM_TX_0;
775 break;
776 case MSM_BACKEND_DAI_SLIMBUS_3_TX:
777 ch_id = SLIM_TX_3;
778 break;
779 default:
780 ch_id = SLIM_RX_0;
781 break;
782 }
783
784 return ch_id;
785}
786
787static void param_set_mask(struct snd_pcm_hw_params *p, int n, unsigned int bit)
788{
789 if (bit >= SNDRV_MASK_MAX)
790 return;
791 if (param_is_mask(n)) {
792 struct snd_mask *m = param_to_mask(p, n);
793
794 m->bits[0] = 0;
795 m->bits[1] = 0;
796 m->bits[bit >> 5] |= (1 << (bit & 31));
797 }
798}
799
800/**
801 * msm_ext_be_hw_params_fixup - updates settings of ALSA BE hw params.
802 *
803 * @rtd: runtime dailink instance
804 * @params: HW params of associated backend dailink.
805 *
806 * Returns 0 on success or rc on failure.
807 */
808int msm_ext_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
809 struct snd_pcm_hw_params *params)
810{
811 struct snd_soc_dai_link *dai_link = rtd->dai_link;
812 struct snd_interval *rate = hw_param_interval(params,
813 SNDRV_PCM_HW_PARAM_RATE);
814 struct snd_interval *channels = hw_param_interval(params,
815 SNDRV_PCM_HW_PARAM_CHANNELS);
816 int rc = 0;
817 int idx;
818 void *config = NULL;
819 struct snd_soc_codec *codec = rtd->codec;
820
821 pr_debug("%s: format = %d, rate = %d\n",
822 __func__, params_format(params), params_rate(params));
823
824 switch (dai_link->be_id) {
825 case MSM_BACKEND_DAI_SLIMBUS_0_RX:
826 case MSM_BACKEND_DAI_SLIMBUS_1_RX:
827 case MSM_BACKEND_DAI_SLIMBUS_2_RX:
828 case MSM_BACKEND_DAI_SLIMBUS_3_RX:
829 case MSM_BACKEND_DAI_SLIMBUS_4_RX:
830 case MSM_BACKEND_DAI_SLIMBUS_6_RX:
831 idx = msm_slim_get_ch_from_beid(dai_link->be_id);
832 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
833 slim_rx_cfg[idx].bit_format);
834 rate->min = rate->max = slim_rx_cfg[idx].sample_rate;
835 channels->min = channels->max = slim_rx_cfg[idx].channels;
836 break;
837
838 case MSM_BACKEND_DAI_SLIMBUS_0_TX:
839 case MSM_BACKEND_DAI_SLIMBUS_3_TX:
840 idx = msm_slim_get_ch_from_beid(dai_link->be_id);
841 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
842 slim_tx_cfg[idx].bit_format);
843 rate->min = rate->max = slim_tx_cfg[idx].sample_rate;
844 channels->min = channels->max = slim_tx_cfg[idx].channels;
845 break;
846
847 case MSM_BACKEND_DAI_SLIMBUS_1_TX:
848 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
849 slim_tx_cfg[1].bit_format);
850 rate->min = rate->max = slim_tx_cfg[1].sample_rate;
851 channels->min = channels->max = slim_tx_cfg[1].channels;
852 break;
853
854 case MSM_BACKEND_DAI_SLIMBUS_4_TX:
855 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
856 SNDRV_PCM_FORMAT_S32_LE);
857 rate->min = rate->max = SAMPLING_RATE_8KHZ;
858 channels->min = channels->max = msm_vi_feed_tx_ch;
859 break;
860
861 case MSM_BACKEND_DAI_SLIMBUS_5_RX:
862 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
863 slim_rx_cfg[5].bit_format);
864 rate->min = rate->max = slim_rx_cfg[5].sample_rate;
865 channels->min = channels->max = slim_rx_cfg[5].channels;
866 break;
867
868 case MSM_BACKEND_DAI_SLIMBUS_5_TX:
869 rate->min = rate->max = SAMPLING_RATE_16KHZ;
870 channels->min = channels->max = 1;
871
872 config = msm_codec_fn.get_afe_config_fn(codec,
873 AFE_SLIMBUS_SLAVE_PORT_CONFIG);
874 if (config) {
875 rc = afe_set_config(AFE_SLIMBUS_SLAVE_PORT_CONFIG,
876 config, SLIMBUS_5_TX);
877 if (rc)
878 pr_err("%s: Failed to set slimbus slave port config %d\n",
879 __func__, rc);
880 }
881 break;
882
883 case MSM_BACKEND_DAI_SLIMBUS_7_RX:
884 param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
885 slim_rx_cfg[SLIM_RX_7].bit_format);
886 rate->min = rate->max = slim_rx_cfg[SLIM_RX_7].sample_rate;
887 channels->min = channels->max =
888 slim_rx_cfg[SLIM_RX_7].channels;
889 break;
890
891 case MSM_BACKEND_DAI_SLIMBUS_7_TX:
892 rate->min = rate->max = slim_tx_cfg[SLIM_TX_7].sample_rate;
893 channels->min = channels->max =
894 slim_tx_cfg[SLIM_TX_7].channels;
895 break;
896
897 case MSM_BACKEND_DAI_SLIMBUS_8_TX:
898 rate->min = rate->max = slim_tx_cfg[SLIM_TX_8].sample_rate;
899 channels->min = channels->max =
900 slim_tx_cfg[SLIM_TX_8].channels;
901 break;
902
903 default:
904 rate->min = rate->max = SAMPLING_RATE_48KHZ;
905 break;
906 }
907 return rc;
908}
909EXPORT_SYMBOL(msm_ext_be_hw_params_fixup);
910
911/**
912 * msm_snd_hw_params - hw params ops of backend dailink.
913 *
914 * @substream: PCM stream of associated backend dailink.
915 * @params: HW params of associated backend dailink.
916 *
917 * Returns 0 on success or ret on failure.
918 */
919int msm_snd_hw_params(struct snd_pcm_substream *substream,
920 struct snd_pcm_hw_params *params)
921{
922 struct snd_soc_pcm_runtime *rtd = substream->private_data;
923 struct snd_soc_dai *codec_dai = rtd->codec_dai;
924 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
925 struct snd_soc_dai_link *dai_link = rtd->dai_link;
926
927 int ret = 0;
928 u32 rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
929 u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
930 u32 user_set_tx_ch = 0;
931 u32 rx_ch_count;
932
933 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
934 ret = snd_soc_dai_get_channel_map(codec_dai,
935 &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
936 if (ret < 0) {
937 pr_err("%s: failed to get codec chan map, err:%d\n",
938 __func__, ret);
939 goto err_ch_map;
940 }
941 if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_5_RX) {
942 pr_debug("%s: rx_5_ch=%d\n", __func__,
943 slim_rx_cfg[5].channels);
944 rx_ch_count = slim_rx_cfg[5].channels;
945 } else if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_2_RX) {
946 pr_debug("%s: rx_2_ch=%d\n", __func__,
947 slim_rx_cfg[2].channels);
948 rx_ch_count = slim_rx_cfg[2].channels;
949 } else if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_6_RX) {
950 pr_debug("%s: rx_6_ch=%d\n", __func__,
951 slim_rx_cfg[6].channels);
952 rx_ch_count = slim_rx_cfg[6].channels;
953 } else {
954 pr_debug("%s: rx_0_ch=%d\n", __func__,
955 slim_rx_cfg[0].channels);
956 rx_ch_count = slim_rx_cfg[0].channels;
957 }
958 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
959 rx_ch_count, rx_ch);
960 if (ret < 0) {
961 pr_err("%s: failed to set cpu chan map, err:%d\n",
962 __func__, ret);
963 goto err_ch_map;
964 }
965 } else {
966 pr_debug("%s: %s_tx_dai_id_%d_ch=%d\n", __func__,
967 codec_dai->name, codec_dai->id, user_set_tx_ch);
968 ret = snd_soc_dai_get_channel_map(codec_dai,
969 &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
970 if (ret < 0) {
971 pr_err("%s: failed to get codec chan map\n, err:%d\n",
972 __func__, ret);
973 goto err_ch_map;
974 }
975 /* For <codec>_tx1 case */
976 if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_0_TX)
977 user_set_tx_ch = slim_tx_cfg[0].channels;
978 /* For <codec>_tx3 case */
979 else if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_1_TX)
980 user_set_tx_ch = slim_tx_cfg[1].channels;
981 else if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_4_TX)
982 user_set_tx_ch = msm_vi_feed_tx_ch;
983 else
984 user_set_tx_ch = tx_ch_cnt;
985
986 pr_debug("%s: msm_slim_0_tx_ch(%d) user_set_tx_ch(%d) tx_ch_cnt(%d), be_id (%d)\n",
987 __func__, slim_tx_cfg[0].channels, user_set_tx_ch,
988 tx_ch_cnt, dai_link->be_id);
989
990 ret = snd_soc_dai_set_channel_map(cpu_dai,
991 user_set_tx_ch, tx_ch, 0, 0);
992 if (ret < 0)
993 pr_err("%s: failed to set cpu chan map, err:%d\n",
994 __func__, ret);
995 }
996
997err_ch_map:
998 return ret;
999}
1000EXPORT_SYMBOL(msm_snd_hw_params);
1001
1002/**
1003 * msm_ext_slimbus_2_hw_params - hw params ops of slimbus_2 BE.
1004 *
1005 * @substream: PCM stream of associated backend dailink.
1006 * @params: HW params of associated backend dailink.
1007 *
1008 * Returns 0 on success or ret on failure.
1009 */
1010int msm_ext_slimbus_2_hw_params(struct snd_pcm_substream *substream,
1011 struct snd_pcm_hw_params *params)
1012{
1013 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1014 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1015 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1016 int ret = 0;
1017 unsigned int rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
1018 unsigned int rx_ch_cnt = 0, tx_ch_cnt = 0;
1019 unsigned int num_tx_ch = 0;
1020 unsigned int num_rx_ch = 0;
1021
1022 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1023 num_rx_ch = params_channels(params);
1024 pr_debug("%s: %s rx_dai_id = %d num_ch = %d\n", __func__,
1025 codec_dai->name, codec_dai->id, num_rx_ch);
1026 ret = snd_soc_dai_get_channel_map(codec_dai,
1027 &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
1028 if (ret < 0) {
1029 pr_err("%s: failed to get codec chan map, err:%d\n",
1030 __func__, ret);
1031 goto end;
1032 }
1033 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
1034 num_rx_ch, rx_ch);
1035 if (ret < 0) {
1036 pr_err("%s: failed to set cpu chan map, err:%d\n",
1037 __func__, ret);
1038 goto end;
1039 }
1040 } else {
1041 num_tx_ch = params_channels(params);
1042 pr_debug("%s: %s tx_dai_id = %d num_ch = %d\n", __func__,
1043 codec_dai->name, codec_dai->id, num_tx_ch);
1044 ret = snd_soc_dai_get_channel_map(codec_dai,
1045 &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
1046 if (ret < 0) {
1047 pr_err("%s: failed to get codec chan map, err:%d\n",
1048 __func__, ret);
1049 goto end;
1050 }
1051 ret = snd_soc_dai_set_channel_map(cpu_dai,
1052 num_tx_ch, tx_ch, 0, 0);
1053 if (ret < 0) {
1054 pr_err("%s: failed to set cpu chan map, err:%d\n",
1055 __func__, ret);
1056 goto end;
1057 }
1058 }
1059end:
1060 return ret;
1061}
1062EXPORT_SYMBOL(msm_ext_slimbus_2_hw_params);
1063
1064/**
1065 * msm_snd_cpe_hw_params - hw params ops of CPE backend.
1066 *
1067 * @substream: PCM stream of associated backend dailink.
1068 * @params: HW params of associated backend dailink.
1069 *
1070 * Returns 0 on success or ret on failure.
1071 */
1072int msm_snd_cpe_hw_params(struct snd_pcm_substream *substream,
1073 struct snd_pcm_hw_params *params)
1074{
1075 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1076 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1077 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1078 struct snd_soc_dai_link *dai_link = rtd->dai_link;
1079 int ret = 0;
1080 u32 tx_ch[SLIM_MAX_TX_PORTS];
1081 u32 tx_ch_cnt = 0;
1082
1083 if (substream->stream != SNDRV_PCM_STREAM_CAPTURE) {
1084 pr_err("%s: Invalid stream type %d\n",
1085 __func__, substream->stream);
1086 ret = -EINVAL;
1087 goto end;
1088 }
1089
1090 pr_debug("%s: %s_tx_dai_id_%d\n", __func__,
1091 codec_dai->name, codec_dai->id);
1092 ret = snd_soc_dai_get_channel_map(codec_dai,
1093 &tx_ch_cnt, tx_ch, NULL, NULL);
1094 if (ret < 0) {
1095 pr_err("%s: failed to get codec chan map\n, err:%d\n",
1096 __func__, ret);
1097 goto end;
1098 }
1099
1100 pr_debug("%s: tx_ch_cnt(%d) be_id %d\n",
1101 __func__, tx_ch_cnt, dai_link->be_id);
1102
1103 ret = snd_soc_dai_set_channel_map(cpu_dai,
1104 tx_ch_cnt, tx_ch, 0, 0);
1105 if (ret < 0) {
1106 pr_err("%s: failed to set cpu chan map, err:%d\n",
1107 __func__, ret);
1108 goto end;
1109 }
1110end:
1111 return ret;
1112}
1113EXPORT_SYMBOL(msm_snd_cpe_hw_params);
1114
1115static int msm_afe_set_config(struct snd_soc_codec *codec)
1116{
1117 int rc;
1118 void *config_data;
1119
1120 pr_debug("%s: enter\n", __func__);
1121
1122 if (!msm_codec_fn.get_afe_config_fn) {
1123 dev_err(codec->dev, "%s: codec get afe config not init'ed\n",
1124 __func__);
1125 return -EINVAL;
1126 }
1127 config_data = msm_codec_fn.get_afe_config_fn(codec,
1128 AFE_CDC_REGISTERS_CONFIG);
1129 if (config_data) {
1130 rc = afe_set_config(AFE_CDC_REGISTERS_CONFIG, config_data, 0);
1131 if (rc) {
1132 pr_err("%s: Failed to set codec registers config %d\n",
1133 __func__, rc);
1134 return rc;
1135 }
1136 }
1137
1138 config_data = msm_codec_fn.get_afe_config_fn(codec,
1139 AFE_CDC_REGISTER_PAGE_CONFIG);
1140 if (config_data) {
1141 rc = afe_set_config(AFE_CDC_REGISTER_PAGE_CONFIG, config_data,
1142 0);
1143 if (rc)
1144 pr_err("%s: Failed to set cdc register page config\n",
1145 __func__);
1146 }
1147
1148 config_data = msm_codec_fn.get_afe_config_fn(codec,
1149 AFE_SLIMBUS_SLAVE_CONFIG);
1150 if (config_data) {
1151 rc = afe_set_config(AFE_SLIMBUS_SLAVE_CONFIG, config_data, 0);
1152 if (rc) {
1153 pr_err("%s: Failed to set slimbus slave config %d\n",
1154 __func__, rc);
1155 return rc;
1156 }
1157 }
1158
1159 config_data = msm_codec_fn.get_afe_config_fn(codec,
1160 AFE_AANC_VERSION);
1161 if (config_data) {
1162 rc = afe_set_config(AFE_AANC_VERSION, config_data, 0);
1163 if (rc) {
1164 pr_err("%s: Failed to set AANC version %d\n",
1165 __func__, rc);
1166 return rc;
1167 }
1168 }
1169
1170 config_data = msm_codec_fn.get_afe_config_fn(codec,
1171 AFE_CDC_CLIP_REGISTERS_CONFIG);
1172 if (config_data) {
1173 rc = afe_set_config(AFE_CDC_CLIP_REGISTERS_CONFIG,
1174 config_data, 0);
1175 if (rc) {
1176 pr_err("%s: Failed to set clip registers %d\n",
1177 __func__, rc);
1178 return rc;
1179 }
1180 }
1181
1182 config_data = msm_codec_fn.get_afe_config_fn(codec,
1183 AFE_CLIP_BANK_SEL);
1184 if (config_data) {
1185 rc = afe_set_config(AFE_CLIP_BANK_SEL,
1186 config_data, 0);
1187 if (rc) {
1188 pr_err("%s: Failed to set AFE bank selection %d\n",
1189 __func__, rc);
1190 return rc;
1191 }
1192 }
1193
1194 config_data = msm_codec_fn.get_afe_config_fn(codec,
1195 AFE_CDC_REGISTER_PAGE_CONFIG);
1196 if (config_data) {
1197 rc = afe_set_config(AFE_CDC_REGISTER_PAGE_CONFIG, config_data,
1198 0);
1199 if (rc)
1200 pr_err("%s: Failed to set cdc register page config\n",
1201 __func__);
1202 }
1203
1204 return 0;
1205}
1206
1207static void msm_afe_clear_config(void)
1208{
1209 afe_clear_config(AFE_CDC_REGISTERS_CONFIG);
1210 afe_clear_config(AFE_SLIMBUS_SLAVE_CONFIG);
1211}
1212
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301213static void msm_snd_interrupt_config(struct msm_asoc_mach_data *pdata)
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301214{
1215 int val;
1216
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301217 val = ioread32(pdata->msm_snd_intr_lpi.mpm_wakeup);
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301218 val |= LPI_GPIO_22_WAKEUP_VAL;
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301219 iowrite32(val, pdata->msm_snd_intr_lpi.mpm_wakeup);
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301220
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301221 val = ioread32(pdata->msm_snd_intr_lpi.intr1_cfg_apps);
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301222 val &= ~(LPI_GPIO_22_INTR1_CFG_MASK);
1223 val |= LPI_GPIO_22_INTR1_CFG_VAL;
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301224 iowrite32(val, pdata->msm_snd_intr_lpi.intr1_cfg_apps);
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301225
1226 iowrite32(LPI_GPIO_INTR_CFG1_VAL,
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301227 pdata->msm_snd_intr_lpi.lpi_gpio_intr_cfg);
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301228 iowrite32(LPI_GPIO22_CFG_VAL,
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301229 pdata->msm_snd_intr_lpi.lpi_gpio_cfg);
Yeleswarapu Nagaradhesh8d42ce02017-01-25 20:33:29 +05301230 val = ioread32(pdata->msm_snd_intr_lpi.lpi_gpio_inout);
1231 val |= LPI_GPIO22_INOUT_VAL;
1232 iowrite32(val, pdata->msm_snd_intr_lpi.lpi_gpio_inout);
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301233}
1234
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001235static int msm_adsp_power_up_config(struct snd_soc_codec *codec)
1236{
1237 int ret = 0;
1238 unsigned long timeout;
1239 int adsp_ready = 0;
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301240 struct snd_soc_card *card = codec->component.card;
1241 struct msm_asoc_mach_data *pdata;
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001242
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301243 pdata = snd_soc_card_get_drvdata(card);
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001244 timeout = jiffies +
1245 msecs_to_jiffies(ADSP_STATE_READY_TIMEOUT_MS);
1246
1247 do {
1248 if (q6core_is_adsp_ready()) {
1249 pr_debug("%s: ADSP Audio is ready\n", __func__);
1250 adsp_ready = 1;
1251 break;
1252 }
1253 /*
1254 * ADSP will be coming up after subsystem restart and
1255 * it might not be fully up when the control reaches
1256 * here. So, wait for 50msec before checking ADSP state
1257 */
1258 msleep(50);
1259 } while (time_after(timeout, jiffies));
1260
1261 if (!adsp_ready) {
1262 pr_err("%s: timed out waiting for ADSP Audio\n", __func__);
1263 ret = -ETIMEDOUT;
1264 goto err_fail;
1265 }
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301266 msm_snd_interrupt_config(pdata);
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001267
1268 ret = msm_afe_set_config(codec);
1269 if (ret)
1270 pr_err("%s: Failed to set AFE config. err %d\n",
1271 __func__, ret);
1272
1273 return 0;
1274
1275err_fail:
1276 return ret;
1277}
1278
Neeraj Upadhyay49934422016-12-27 19:03:35 +05301279static int sdm660_notifier_service_cb(struct notifier_block *this,
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001280 unsigned long opcode, void *ptr)
1281{
1282 int ret;
1283 struct snd_soc_card *card = NULL;
1284 const char *be_dl_name = LPASS_BE_SLIMBUS_0_RX;
1285 struct snd_soc_pcm_runtime *rtd;
1286 struct snd_soc_codec *codec;
1287
1288 pr_debug("%s: Service opcode 0x%lx\n", __func__, opcode);
1289
1290 switch (opcode) {
1291 case AUDIO_NOTIFIER_SERVICE_DOWN:
1292 /*
1293 * Use flag to ignore initial boot notifications
1294 * On initial boot msm_adsp_power_up_config is
1295 * called on init. There is no need to clear
1296 * and set the config again on initial boot.
1297 */
1298 if (is_initial_boot)
1299 break;
1300 msm_afe_clear_config();
1301 break;
1302 case AUDIO_NOTIFIER_SERVICE_UP:
1303 if (is_initial_boot) {
1304 is_initial_boot = false;
1305 break;
1306 }
1307 if (!spdev)
1308 return -EINVAL;
1309
1310 card = platform_get_drvdata(spdev);
1311 rtd = snd_soc_get_pcm_runtime(card, be_dl_name);
1312 if (!rtd) {
1313 dev_err(card->dev,
1314 "%s: snd_soc_get_pcm_runtime for %s failed!\n",
1315 __func__, be_dl_name);
1316 ret = -EINVAL;
1317 goto done;
1318 }
1319 codec = rtd->codec;
1320
1321 ret = msm_adsp_power_up_config(codec);
1322 if (ret < 0) {
1323 dev_err(card->dev,
1324 "%s: msm_adsp_power_up_config failed ret = %d!\n",
1325 __func__, ret);
1326 goto done;
1327 }
1328 break;
1329 default:
1330 break;
1331 }
1332done:
1333 return NOTIFY_OK;
1334}
1335
1336static struct notifier_block service_nb = {
Neeraj Upadhyay49934422016-12-27 19:03:35 +05301337 .notifier_call = sdm660_notifier_service_cb,
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001338 .priority = -INT_MAX,
1339};
1340
1341static int msm_config_hph_en0_gpio(struct snd_soc_codec *codec, bool high)
1342{
1343 struct snd_soc_card *card = codec->component.card;
1344 struct msm_asoc_mach_data *pdata;
1345 int val;
1346
1347 if (!card)
1348 return 0;
1349
1350 pdata = snd_soc_card_get_drvdata(card);
1351 if (!pdata || !gpio_is_valid(pdata->hph_en0_gpio))
1352 return 0;
1353
1354 val = gpio_get_value_cansleep(pdata->hph_en0_gpio);
1355 if ((!!val) == high)
1356 return 0;
1357
1358 gpio_direction_output(pdata->hph_en0_gpio, (int)high);
1359
1360 return 1;
1361}
1362
1363static int msm_snd_enable_codec_ext_tx_clk(struct snd_soc_codec *codec,
1364 int enable, bool dapm)
1365{
1366 int ret = 0;
1367
1368 if (!strcmp(dev_name(codec->dev), "tasha_codec"))
1369 ret = tasha_cdc_mclk_tx_enable(codec, enable, dapm);
1370 else {
1371 dev_err(codec->dev, "%s: unknown codec to enable ext clk\n",
1372 __func__);
1373 ret = -EINVAL;
1374 }
1375 return ret;
1376}
1377
1378static int msm_ext_mclk_tx_event(struct snd_soc_dapm_widget *w,
1379 struct snd_kcontrol *kcontrol, int event)
1380{
1381 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1382
1383 pr_debug("%s: event = %d\n", __func__, event);
1384
1385 switch (event) {
1386 case SND_SOC_DAPM_PRE_PMU:
1387 return msm_snd_enable_codec_ext_tx_clk(codec, 1, true);
1388 case SND_SOC_DAPM_POST_PMD:
1389 return msm_snd_enable_codec_ext_tx_clk(codec, 0, true);
1390 }
1391 return 0;
1392}
1393
1394static int msm_ext_mclk_event(struct snd_soc_dapm_widget *w,
1395 struct snd_kcontrol *kcontrol, int event)
1396{
1397 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1398
1399 pr_debug("%s: event = %d\n", __func__, event);
1400
1401 switch (event) {
1402 case SND_SOC_DAPM_PRE_PMU:
1403 return msm_ext_enable_codec_mclk(codec, 1, true);
1404 case SND_SOC_DAPM_POST_PMD:
1405 return msm_ext_enable_codec_mclk(codec, 0, true);
1406 }
1407 return 0;
1408}
1409
1410static int msm_ext_prepare_hifi(struct msm_asoc_mach_data *pdata)
1411{
1412 int ret = 0;
1413
1414 if (gpio_is_valid(pdata->hph_en1_gpio)) {
1415 pr_debug("%s: hph_en1_gpio request %d\n", __func__,
1416 pdata->hph_en1_gpio);
1417 ret = gpio_request(pdata->hph_en1_gpio, "hph_en1_gpio");
1418 if (ret) {
1419 pr_err("%s: hph_en1_gpio request failed, ret:%d\n",
1420 __func__, ret);
1421 goto err;
1422 }
1423 }
1424 if (gpio_is_valid(pdata->hph_en0_gpio)) {
1425 pr_debug("%s: hph_en0_gpio request %d\n", __func__,
1426 pdata->hph_en0_gpio);
1427 ret = gpio_request(pdata->hph_en0_gpio, "hph_en0_gpio");
1428 if (ret)
1429 pr_err("%s: hph_en0_gpio request failed, ret:%d\n",
1430 __func__, ret);
1431 }
1432
1433err:
1434 return ret;
1435}
1436
1437static const struct snd_soc_dapm_widget msm_dapm_widgets[] = {
1438
1439 SND_SOC_DAPM_SUPPLY_S("MCLK", -1, SND_SOC_NOPM, 0, 0,
1440 msm_ext_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1441
1442 SND_SOC_DAPM_SUPPLY_S("MCLK TX", -1, SND_SOC_NOPM, 0, 0,
1443 msm_ext_mclk_tx_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1444
1445 SND_SOC_DAPM_SPK("Lineout_1 amp", NULL),
1446 SND_SOC_DAPM_SPK("Lineout_3 amp", NULL),
1447 SND_SOC_DAPM_SPK("Lineout_2 amp", NULL),
1448 SND_SOC_DAPM_SPK("Lineout_4 amp", NULL),
1449 SND_SOC_DAPM_MIC("Handset Mic", NULL),
1450 SND_SOC_DAPM_MIC("Headset Mic", NULL),
1451 SND_SOC_DAPM_MIC("Secondary Mic", NULL),
1452 SND_SOC_DAPM_MIC("ANCRight Headset Mic", NULL),
1453 SND_SOC_DAPM_MIC("ANCLeft Headset Mic", NULL),
1454 SND_SOC_DAPM_MIC("Analog Mic4", NULL),
1455 SND_SOC_DAPM_MIC("Analog Mic6", NULL),
1456 SND_SOC_DAPM_MIC("Analog Mic7", NULL),
1457 SND_SOC_DAPM_MIC("Analog Mic8", NULL),
1458
1459 SND_SOC_DAPM_MIC("Digital Mic0", NULL),
1460 SND_SOC_DAPM_MIC("Digital Mic1", NULL),
1461 SND_SOC_DAPM_MIC("Digital Mic2", NULL),
1462 SND_SOC_DAPM_MIC("Digital Mic3", NULL),
1463 SND_SOC_DAPM_MIC("Digital Mic4", NULL),
1464 SND_SOC_DAPM_MIC("Digital Mic5", NULL),
1465 SND_SOC_DAPM_MIC("Digital Mic6", NULL),
1466};
1467
1468static struct snd_soc_dapm_route wcd_audio_paths_tasha[] = {
1469 {"MIC BIAS1", NULL, "MCLK TX"},
1470 {"MIC BIAS2", NULL, "MCLK TX"},
1471 {"MIC BIAS3", NULL, "MCLK TX"},
1472 {"MIC BIAS4", NULL, "MCLK TX"},
1473};
1474
1475static struct snd_soc_dapm_route wcd_audio_paths[] = {
1476 {"MIC BIAS1", NULL, "MCLK"},
1477 {"MIC BIAS2", NULL, "MCLK"},
1478 {"MIC BIAS3", NULL, "MCLK"},
1479 {"MIC BIAS4", NULL, "MCLK"},
1480};
1481
1482/**
1483 * msm_audrx_init - Audio init function of sound card instantiate.
1484 *
1485 * @rtd: runtime dailink instance
1486 *
1487 * Returns 0 on success or ret on failure.
1488 */
1489int msm_audrx_init(struct snd_soc_pcm_runtime *rtd)
1490{
1491 int ret;
1492 void *config_data;
1493 struct snd_soc_codec *codec = rtd->codec;
1494 struct snd_soc_dapm_context *dapm =
1495 snd_soc_codec_get_dapm(codec);
1496 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1497 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1498 struct snd_soc_pcm_runtime *rtd_aux = rtd->card->rtd_aux;
1499 struct snd_card *card;
1500 struct snd_info_entry *entry;
1501 struct msm_asoc_mach_data *pdata =
1502 snd_soc_card_get_drvdata(rtd->card);
1503
1504 /* Codec SLIMBUS configuration
1505 * RX1, RX2, RX3, RX4, RX5, RX6, RX7, RX8, RX9, RX10, RX11, RX12, RX13
1506 * TX1, TX2, TX3, TX4, TX5, TX6, TX7, TX8, TX9, TX10, TX11, TX12, TX13
1507 * TX14, TX15, TX16
1508 */
1509 unsigned int rx_ch[TASHA_RX_MAX] = {144, 145, 146, 147, 148, 149, 150,
1510 151, 152, 153, 154, 155, 156};
1511 unsigned int tx_ch[TASHA_TX_MAX] = {128, 129, 130, 131, 132, 133,
1512 134, 135, 136, 137, 138, 139,
1513 140, 141, 142, 143};
1514
Laxminath Kasam9f2ba412017-01-26 18:50:33 +05301515 /* Tavil Codec SLIMBUS configuration
1516 * RX1, RX2, RX3, RX4, RX5, RX6, RX7, RX8
1517 * TX1, TX2, TX3, TX4, TX5, TX6, TX7, TX8, TX9, TX10, TX11, TX12, TX13
1518 * TX14, TX15, TX16
1519 */
1520 unsigned int rx_ch_tavil[WCD934X_RX_MAX] = {144, 145, 146, 147, 148,
1521 149, 150, 151};
1522 unsigned int tx_ch_tavil[WCD934X_TX_MAX] = {128, 129, 130, 131, 132,
1523 133, 134, 135, 136, 137, 138,
1524 139, 140, 141, 142, 143};
1525
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001526 pr_debug("%s: dev_name%s\n", __func__, dev_name(cpu_dai->dev));
1527
1528 rtd->pmdown_time = 0;
1529
1530 ret = snd_soc_add_codec_controls(codec, msm_snd_controls,
1531 ARRAY_SIZE(msm_snd_controls));
1532 if (ret < 0) {
1533 pr_err("%s: add_codec_controls failed: %d\n",
1534 __func__, ret);
1535 return ret;
1536 }
1537
Laxminath Kasam35a610e2016-12-30 15:02:33 +05301538 ret = snd_soc_add_codec_controls(codec, msm_common_snd_controls,
1539 msm_common_snd_controls_size());
1540 if (ret < 0) {
1541 pr_err("%s: add_common_snd_controls failed: %d\n",
1542 __func__, ret);
1543 return ret;
1544 }
1545
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001546 snd_soc_dapm_new_controls(dapm, msm_dapm_widgets,
1547 ARRAY_SIZE(msm_dapm_widgets));
1548
1549 if (!strcmp(dev_name(codec_dai->dev), "tasha_codec"))
1550 snd_soc_dapm_add_routes(dapm, wcd_audio_paths_tasha,
1551 ARRAY_SIZE(wcd_audio_paths_tasha));
1552 else
1553 snd_soc_dapm_add_routes(dapm, wcd_audio_paths,
1554 ARRAY_SIZE(wcd_audio_paths));
1555
1556 snd_soc_dapm_enable_pin(dapm, "Lineout_1 amp");
1557 snd_soc_dapm_enable_pin(dapm, "Lineout_3 amp");
1558 snd_soc_dapm_enable_pin(dapm, "Lineout_2 amp");
1559 snd_soc_dapm_enable_pin(dapm, "Lineout_4 amp");
1560
1561 snd_soc_dapm_ignore_suspend(dapm, "MADINPUT");
1562 snd_soc_dapm_ignore_suspend(dapm, "MAD_CPE_INPUT");
1563 snd_soc_dapm_ignore_suspend(dapm, "Handset Mic");
1564 snd_soc_dapm_ignore_suspend(dapm, "Headset Mic");
1565 snd_soc_dapm_ignore_suspend(dapm, "Secondary Mic");
1566 snd_soc_dapm_ignore_suspend(dapm, "Lineout_1 amp");
1567 snd_soc_dapm_ignore_suspend(dapm, "Lineout_3 amp");
1568 snd_soc_dapm_ignore_suspend(dapm, "Lineout_2 amp");
1569 snd_soc_dapm_ignore_suspend(dapm, "Lineout_4 amp");
1570 snd_soc_dapm_ignore_suspend(dapm, "ANCRight Headset Mic");
1571 snd_soc_dapm_ignore_suspend(dapm, "ANCLeft Headset Mic");
1572 snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
1573 snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
1574 snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
1575 snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
1576 snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
1577 snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
1578 snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
1579 snd_soc_dapm_ignore_suspend(dapm, "Analog Mic6");
1580 snd_soc_dapm_ignore_suspend(dapm, "Analog Mic7");
1581 snd_soc_dapm_ignore_suspend(dapm, "Analog Mic8");
1582
1583 snd_soc_dapm_ignore_suspend(dapm, "EAR");
1584 snd_soc_dapm_ignore_suspend(dapm, "LINEOUT1");
1585 snd_soc_dapm_ignore_suspend(dapm, "LINEOUT2");
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001586 snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
1587 snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
1588 snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
1589 snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
1590 snd_soc_dapm_ignore_suspend(dapm, "AMIC5");
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001591 snd_soc_dapm_ignore_suspend(dapm, "DMIC0");
1592 snd_soc_dapm_ignore_suspend(dapm, "DMIC1");
1593 snd_soc_dapm_ignore_suspend(dapm, "DMIC2");
1594 snd_soc_dapm_ignore_suspend(dapm, "DMIC3");
1595 snd_soc_dapm_ignore_suspend(dapm, "DMIC4");
1596 snd_soc_dapm_ignore_suspend(dapm, "DMIC5");
1597 snd_soc_dapm_ignore_suspend(dapm, "ANC EAR");
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001598 snd_soc_dapm_ignore_suspend(dapm, "SPK1 OUT");
1599 snd_soc_dapm_ignore_suspend(dapm, "SPK2 OUT");
1600 snd_soc_dapm_ignore_suspend(dapm, "HPHL");
1601 snd_soc_dapm_ignore_suspend(dapm, "HPHR");
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001602 snd_soc_dapm_ignore_suspend(dapm, "AIF4 VI");
1603 snd_soc_dapm_ignore_suspend(dapm, "VIINPUT");
1604
Laxminath Kasam9f2ba412017-01-26 18:50:33 +05301605 if (!strcmp(dev_name(codec_dai->dev), "tasha_codec")) {
1606 snd_soc_dapm_ignore_suspend(dapm, "LINEOUT3");
1607 snd_soc_dapm_ignore_suspend(dapm, "LINEOUT4");
1608 snd_soc_dapm_ignore_suspend(dapm, "ANC HPHL");
1609 snd_soc_dapm_ignore_suspend(dapm, "ANC HPHR");
1610 snd_soc_dapm_ignore_suspend(dapm, "ANC LINEOUT1");
1611 snd_soc_dapm_ignore_suspend(dapm, "ANC LINEOUT2");
1612 }
1613
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001614 snd_soc_dapm_sync(dapm);
Laxminath Kasam9f2ba412017-01-26 18:50:33 +05301615
1616 if (!strcmp(dev_name(codec_dai->dev), "tavil_codec")) {
1617 snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch_tavil),
1618 tx_ch_tavil, ARRAY_SIZE(rx_ch_tavil),
1619 rx_ch_tavil);
1620 } else {
1621 snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
1622 tx_ch, ARRAY_SIZE(rx_ch),
1623 rx_ch);
1624 }
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001625
1626 if (!strcmp(dev_name(codec_dai->dev), "tavil_codec")) {
1627 msm_codec_fn.get_afe_config_fn = tavil_get_afe_config;
1628 } else {
1629 msm_codec_fn.get_afe_config_fn = tasha_get_afe_config;
1630 msm_codec_fn.mbhc_hs_detect_exit = tasha_mbhc_hs_detect_exit;
1631 }
1632
1633 ret = msm_adsp_power_up_config(codec);
1634 if (ret) {
1635 pr_err("%s: Failed to set AFE config %d\n", __func__, ret);
1636 goto err_afe_cfg;
1637 }
1638
1639 config_data = msm_codec_fn.get_afe_config_fn(codec,
1640 AFE_AANC_VERSION);
1641 if (config_data) {
1642 ret = afe_set_config(AFE_AANC_VERSION, config_data, 0);
1643 if (ret) {
1644 pr_err("%s: Failed to set aanc version %d\n",
1645 __func__, ret);
1646 goto err_afe_cfg;
1647 }
1648 }
1649
1650 if (!strcmp(dev_name(codec_dai->dev), "tasha_codec")) {
1651 config_data = msm_codec_fn.get_afe_config_fn(codec,
1652 AFE_CDC_CLIP_REGISTERS_CONFIG);
1653 if (config_data) {
1654 ret = afe_set_config(AFE_CDC_CLIP_REGISTERS_CONFIG,
1655 config_data, 0);
1656 if (ret) {
1657 pr_err("%s: Failed to set clip registers %d\n",
1658 __func__, ret);
1659 goto err_afe_cfg;
1660 }
1661 }
1662 config_data = msm_codec_fn.get_afe_config_fn(codec,
1663 AFE_CLIP_BANK_SEL);
1664 if (config_data) {
1665 ret = afe_set_config(AFE_CLIP_BANK_SEL, config_data, 0);
1666 if (ret) {
1667 pr_err("%s: Failed to set AFE bank selection %d\n",
1668 __func__, ret);
1669 goto err_afe_cfg;
1670 }
1671 }
1672 }
1673
1674 /*
1675 * Send speaker configuration only for WSA8810.
1676 * Defalut configuration is for WSA8815.
1677 */
1678 if (!strcmp(dev_name(codec_dai->dev), "tavil_codec")) {
1679 if (rtd_aux && rtd_aux->component)
1680 if (!strcmp(rtd_aux->component->name, WSA8810_NAME_1) ||
1681 !strcmp(rtd_aux->component->name, WSA8810_NAME_2)) {
1682 tavil_set_spkr_mode(rtd->codec, SPKR_MODE_1);
1683 tavil_set_spkr_gain_offset(rtd->codec,
1684 RX_GAIN_OFFSET_M1P5_DB);
1685 }
1686 card = rtd->card->snd_card;
1687 entry = snd_info_create_subdir(card->module, "codecs",
1688 card->proc_root);
1689 if (!entry) {
1690 pr_debug("%s: Cannot create codecs module entry\n",
1691 __func__);
1692 pdata->codec_root = NULL;
1693 goto done;
1694 }
1695 pdata->codec_root = entry;
1696 tavil_codec_info_create_codec_entry(pdata->codec_root, codec);
1697 } else {
1698 if (rtd_aux && rtd_aux->component)
1699 if (!strcmp(rtd_aux->component->name, WSA8810_NAME_1) ||
1700 !strcmp(rtd_aux->component->name, WSA8810_NAME_2)) {
1701 tasha_set_spkr_mode(rtd->codec, SPKR_MODE_1);
1702 tasha_set_spkr_gain_offset(rtd->codec,
1703 RX_GAIN_OFFSET_M1P5_DB);
1704 }
1705 card = rtd->card->snd_card;
1706 entry = snd_info_create_subdir(card->module, "codecs",
1707 card->proc_root);
1708 if (!entry) {
1709 pr_debug("%s: Cannot create codecs module entry\n",
1710 __func__);
1711 ret = 0;
1712 goto err_snd_module;
1713 }
1714 pdata->codec_root = entry;
1715 tasha_codec_info_create_codec_entry(pdata->codec_root, codec);
1716 tasha_mbhc_zdet_gpio_ctrl(msm_config_hph_en0_gpio, rtd->codec);
1717 }
1718
1719 wcd_mbhc_cfg_ptr->calibration = def_ext_mbhc_cal();
1720 if (!strcmp(dev_name(codec_dai->dev), "tavil_codec")) {
1721 if (wcd_mbhc_cfg_ptr->calibration) {
1722 pdata->codec = codec;
1723 ret = tavil_mbhc_hs_detect(codec, wcd_mbhc_cfg_ptr);
1724 if (ret < 0)
1725 pr_err("%s: Failed to intialise mbhc %d\n",
1726 __func__, ret);
1727 } else {
1728 pr_err("%s: wcd_mbhc_cfg calibration is NULL\n",
1729 __func__);
1730 ret = -ENOMEM;
1731 goto err_mbhc_cal;
1732 }
1733 } else {
1734 if (wcd_mbhc_cfg_ptr->calibration) {
1735 pdata->codec = codec;
1736 ret = tasha_mbhc_hs_detect(codec, wcd_mbhc_cfg_ptr);
1737 if (ret < 0)
1738 pr_err("%s: Failed to intialise mbhc %d\n",
1739 __func__, ret);
1740 } else {
1741 pr_err("%s: wcd_mbhc_cfg calibration is NULL\n",
1742 __func__);
1743 ret = -ENOMEM;
1744 goto err_mbhc_cal;
1745 }
1746
1747 }
Laxminath Kasam54dc88a2016-12-22 19:44:52 +05301748 codec_reg_done = true;
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001749done:
1750 return 0;
1751
1752err_snd_module:
1753err_afe_cfg:
1754err_mbhc_cal:
1755 return ret;
1756}
1757EXPORT_SYMBOL(msm_audrx_init);
1758
1759/**
1760 * msm_ext_register_audio_notifier - register SSR notifier.
1761 */
Laxminath Kasam54dc88a2016-12-22 19:44:52 +05301762void msm_ext_register_audio_notifier(struct platform_device *pdev)
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001763{
1764 int ret;
1765
Laxminath Kasam54dc88a2016-12-22 19:44:52 +05301766 is_initial_boot = true;
1767 spdev = pdev;
Neeraj Upadhyay49934422016-12-27 19:03:35 +05301768 ret = audio_notifier_register("sdm660", AUDIO_NOTIFIER_ADSP_DOMAIN,
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001769 &service_nb);
1770 if (ret < 0)
1771 pr_err("%s: Audio notifier register failed ret = %d\n",
1772 __func__, ret);
1773}
1774EXPORT_SYMBOL(msm_ext_register_audio_notifier);
1775
1776/**
1777 * msm_ext_cdc_init - external codec machine specific init.
1778 *
1779 * @pdev: platform device handle
1780 * @pdata: private data of machine driver
1781 * @card: sound card pointer reference
1782 * @mbhc_cfg: MBHC config reference
1783 *
1784 * Returns 0 on success or ret on failure.
1785 */
1786int msm_ext_cdc_init(struct platform_device *pdev,
1787 struct msm_asoc_mach_data *pdata,
1788 struct snd_soc_card **card,
1789 struct wcd_mbhc_config *wcd_mbhc_cfg_ptr1)
1790{
1791 int ret = 0;
1792
1793 wcd_mbhc_cfg_ptr = wcd_mbhc_cfg_ptr1;
1794 pdev->id = 0;
1795 wcd_mbhc_cfg_ptr->moisture_en = true;
1796 wcd_mbhc_cfg_ptr->mbhc_micbias = MIC_BIAS_2;
1797 wcd_mbhc_cfg_ptr->anc_micbias = MIC_BIAS_2;
1798 wcd_mbhc_cfg_ptr->enable_anc_mic_detect = false;
1799
1800 *card = populate_snd_card_dailinks(&pdev->dev, pdata->snd_card_val);
1801 if (!(*card)) {
1802 dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
1803 ret = -EPROBE_DEFER;
1804 goto err;
1805 }
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001806 platform_set_drvdata(pdev, *card);
1807 snd_soc_card_set_drvdata(*card, pdata);
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001808 pdata->hph_en1_gpio = of_get_named_gpio(pdev->dev.of_node,
1809 "qcom,hph-en1-gpio", 0);
1810 if (!gpio_is_valid(pdata->hph_en1_gpio))
1811 pdata->hph_en1_gpio_p = of_parse_phandle(pdev->dev.of_node,
1812 "qcom,hph-en1-gpio", 0);
1813 if (!gpio_is_valid(pdata->hph_en1_gpio) && (!pdata->hph_en1_gpio_p)) {
1814 dev_dbg(&pdev->dev, "property %s not detected in node %s",
1815 "qcom,hph-en1-gpio", pdev->dev.of_node->full_name);
1816 }
1817
1818 pdata->hph_en0_gpio = of_get_named_gpio(pdev->dev.of_node,
1819 "qcom,hph-en0-gpio", 0);
1820 if (!gpio_is_valid(pdata->hph_en0_gpio))
1821 pdata->hph_en0_gpio_p = of_parse_phandle(pdev->dev.of_node,
1822 "qcom,hph-en0-gpio", 0);
1823 if (!gpio_is_valid(pdata->hph_en0_gpio) && (!pdata->hph_en0_gpio_p)) {
1824 dev_dbg(&pdev->dev, "property %s not detected in node %s",
1825 "qcom,hph-en0-gpio", pdev->dev.of_node->full_name);
1826 }
1827
1828 ret = msm_ext_prepare_hifi(pdata);
1829 if (ret) {
1830 dev_dbg(&pdev->dev, "msm_ext_prepare_hifi failed (%d)\n",
1831 ret);
1832 ret = 0;
1833 }
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301834 pdata->msm_snd_intr_lpi.mpm_wakeup =
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301835 ioremap(TLMM_CENTER_MPM_WAKEUP_INT_EN_0, 4);
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301836 pdata->msm_snd_intr_lpi.intr1_cfg_apps =
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301837 ioremap(TLMM_LPI_DIR_CONN_INTR1_CFG_APPS, 4);
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301838 pdata->msm_snd_intr_lpi.lpi_gpio_intr_cfg =
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301839 ioremap(TLMM_LPI_GPIO_INTR_CFG1, 4);
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301840 pdata->msm_snd_intr_lpi.lpi_gpio_cfg =
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301841 ioremap(TLMM_LPI_GPIO22_CFG, 4);
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301842 pdata->msm_snd_intr_lpi.lpi_gpio_inout =
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301843 ioremap(TLMM_LPI_GPIO22_INOUT, 4);
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001844err:
1845 return ret;
1846}
1847EXPORT_SYMBOL(msm_ext_cdc_init);
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301848
1849/**
1850 * msm_ext_cdc_deinit - external codec machine specific deinit.
1851 */
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301852void msm_ext_cdc_deinit(struct msm_asoc_mach_data *pdata)
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301853{
Laxminath Kasamc1a8f7c2017-01-23 13:33:31 +05301854 if (pdata->msm_snd_intr_lpi.mpm_wakeup)
1855 iounmap(pdata->msm_snd_intr_lpi.mpm_wakeup);
1856 if (pdata->msm_snd_intr_lpi.intr1_cfg_apps)
1857 iounmap(pdata->msm_snd_intr_lpi.intr1_cfg_apps);
1858 if (pdata->msm_snd_intr_lpi.lpi_gpio_intr_cfg)
1859 iounmap(pdata->msm_snd_intr_lpi.lpi_gpio_intr_cfg);
1860 if (pdata->msm_snd_intr_lpi.lpi_gpio_cfg)
1861 iounmap(pdata->msm_snd_intr_lpi.lpi_gpio_cfg);
1862 if (pdata->msm_snd_intr_lpi.lpi_gpio_inout)
1863 iounmap(pdata->msm_snd_intr_lpi.lpi_gpio_inout);
1864
Laxminath Kasamfb36dc12016-11-28 23:04:47 +05301865}
1866EXPORT_SYMBOL(msm_ext_cdc_deinit);