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