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