hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/sound/soc/codecs/msm8916-wcd-analog.c
....@@ -1,3 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0
2
+// Copyright (c) 2016, The Linux Foundation. All rights reserved.
3
+
14 #include <linux/module.h>
25 #include <linux/err.h>
36 #include <linux/kernel.h>
....@@ -225,6 +228,10 @@
225228 #define CDC_A_RX_EAR_CTL (0xf19E)
226229 #define RX_EAR_CTL_SPK_VBAT_LDO_EN_MASK BIT(0)
227230 #define RX_EAR_CTL_SPK_VBAT_LDO_EN_ENABLE BIT(0)
231
+#define RX_EAR_CTL_PA_EAR_PA_EN_MASK BIT(6)
232
+#define RX_EAR_CTL_PA_EAR_PA_EN_ENABLE BIT(6)
233
+#define RX_EAR_CTL_PA_SEL_MASK BIT(7)
234
+#define RX_EAR_CTL_PA_SEL BIT(7)
228235
229236 #define CDC_A_SPKR_DAC_CTL (0xf1B0)
230237 #define SPKR_DAC_CTL_DAC_RESET_MASK BIT(4)
....@@ -309,6 +316,7 @@
309316 static const struct soc_enum hph_enum = SOC_ENUM_SINGLE_VIRT(
310317 ARRAY_SIZE(hph_text), hph_text);
311318
319
+static const struct snd_kcontrol_new ear_mux = SOC_DAPM_ENUM("EAR_S", hph_enum);
312320 static const struct snd_kcontrol_new hphl_mux = SOC_DAPM_ENUM("HPHL", hph_enum);
313321 static const struct snd_kcontrol_new hphr_mux = SOC_DAPM_ENUM("HPHR", hph_enum);
314322
....@@ -366,9 +374,8 @@
366374
367375 }
368376
369
-static int pm8916_wcd_analog_enable_micbias_ext(struct snd_soc_component
370
- *component, int event,
371
- int reg, unsigned int cap_mode)
377
+static int pm8916_wcd_analog_enable_micbias(struct snd_soc_component *component,
378
+ int event, unsigned int cap_mode)
372379 {
373380 switch (event) {
374381 case SND_SOC_DAPM_POST_PMU:
....@@ -381,72 +388,44 @@
381388 return 0;
382389 }
383390
384
-static int pm8916_wcd_analog_enable_micbias_int(struct snd_soc_component
385
- *component, int event,
386
- int reg, u32 cap_mode)
391
+static int pm8916_wcd_analog_enable_micbias_int(struct snd_soc_dapm_widget *w,
392
+ struct snd_kcontrol *kcontrol,
393
+ int event)
387394 {
395
+ struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
388396
389397 switch (event) {
390398 case SND_SOC_DAPM_PRE_PMU:
391
- snd_soc_component_update_bits(component, reg, MICB_1_EN_PULL_DOWN_EN_MASK, 0);
392399 snd_soc_component_update_bits(component, CDC_A_MICB_1_EN,
393400 MICB_1_EN_OPA_STG2_TAIL_CURR_MASK,
394401 MICB_1_EN_OPA_STG2_TAIL_CURR_1_60UA);
395
-
396
- break;
397
- case SND_SOC_DAPM_POST_PMU:
398
- pm8916_wcd_analog_micbias_enable(component);
399
- snd_soc_component_update_bits(component, CDC_A_MICB_1_EN,
400
- MICB_1_EN_BYP_CAP_MASK, cap_mode);
401402 break;
402403 }
403404
404405 return 0;
405406 }
406407
407
-static int pm8916_wcd_analog_enable_micbias_ext1(struct
408
- snd_soc_dapm_widget
409
- *w, struct snd_kcontrol
410
- *kcontrol, int event)
408
+static int pm8916_wcd_analog_enable_micbias1(struct snd_soc_dapm_widget *w,
409
+ struct snd_kcontrol *kcontrol,
410
+ int event)
411411 {
412412 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
413413 struct pm8916_wcd_analog_priv *wcd = snd_soc_component_get_drvdata(component);
414414
415
- return pm8916_wcd_analog_enable_micbias_ext(component, event, w->reg,
416
- wcd->micbias1_cap_mode);
415
+ return pm8916_wcd_analog_enable_micbias(component, event,
416
+ wcd->micbias1_cap_mode);
417417 }
418418
419
-static int pm8916_wcd_analog_enable_micbias_ext2(struct
420
- snd_soc_dapm_widget
421
- *w, struct snd_kcontrol
422
- *kcontrol, int event)
419
+static int pm8916_wcd_analog_enable_micbias2(struct snd_soc_dapm_widget *w,
420
+ struct snd_kcontrol *kcontrol,
421
+ int event)
423422 {
424423 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
425424 struct pm8916_wcd_analog_priv *wcd = snd_soc_component_get_drvdata(component);
426425
427
- return pm8916_wcd_analog_enable_micbias_ext(component, event, w->reg,
428
- wcd->micbias2_cap_mode);
426
+ return pm8916_wcd_analog_enable_micbias(component, event,
427
+ wcd->micbias2_cap_mode);
429428
430
-}
431
-
432
-static int pm8916_wcd_analog_enable_micbias_int1(struct
433
- snd_soc_dapm_widget
434
- *w, struct snd_kcontrol
435
- *kcontrol, int event)
436
-{
437
- struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
438
- struct pm8916_wcd_analog_priv *wcd = snd_soc_component_get_drvdata(component);
439
-
440
- switch (event) {
441
- case SND_SOC_DAPM_PRE_PMU:
442
- snd_soc_component_update_bits(component, CDC_A_MICB_1_INT_RBIAS,
443
- MICB_1_INT_TX1_INT_RBIAS_EN_MASK,
444
- MICB_1_INT_TX1_INT_RBIAS_EN_ENABLE);
445
- break;
446
- }
447
-
448
- return pm8916_wcd_analog_enable_micbias_int(component, event, w->reg,
449
- wcd->micbias1_cap_mode);
450429 }
451430
452431 static int pm8916_mbhc_configure_bias(struct pm8916_wcd_analog_priv *priv,
....@@ -531,7 +510,7 @@
531510 DIG_CLK_CTL_D_MBHC_CLK_EN_MASK,
532511 DIG_CLK_CTL_D_MBHC_CLK_EN);
533512
534
- if (snd_soc_component_read32(component, CDC_A_MICB_2_EN) & CDC_A_MICB_2_EN_ENABLE)
513
+ if (snd_soc_component_read(component, CDC_A_MICB_2_EN) & CDC_A_MICB_2_EN_ENABLE)
535514 micbias_enabled = true;
536515
537516 pm8916_mbhc_configure_bias(wcd, micbias_enabled);
....@@ -556,9 +535,8 @@
556535
557536 switch (event) {
558537 case SND_SOC_DAPM_PRE_PMU:
559
- snd_soc_component_update_bits(component, CDC_A_MICB_1_INT_RBIAS,
560
- MICB_1_INT_TX2_INT_RBIAS_EN_MASK,
561
- MICB_1_INT_TX2_INT_RBIAS_EN_ENABLE);
538
+ snd_soc_component_update_bits(component, CDC_A_MICB_2_EN,
539
+ CDC_A_MICB_2_PULL_DOWN_EN_MASK, 0);
562540 break;
563541 case SND_SOC_DAPM_POST_PMU:
564542 pm8916_mbhc_configure_bias(wcd, true);
....@@ -568,8 +546,7 @@
568546 break;
569547 }
570548
571
- return pm8916_wcd_analog_enable_micbias_int(component, event, w->reg,
572
- wcd->micbias2_cap_mode);
549
+ return pm8916_wcd_analog_enable_micbias_int(w, kcontrol, event);
573550 }
574551
575552 static int pm8916_wcd_analog_enable_adc(struct snd_soc_dapm_widget *w,
....@@ -631,7 +608,7 @@
631608 case CDC_A_TX_2_EN:
632609 snd_soc_component_update_bits(component, CDC_A_MICB_1_CTL,
633610 MICB_1_CTL_CFILT_REF_SEL_MASK, 0);
634
- /* fall through */
611
+ fallthrough;
635612 case CDC_A_TX_3_EN:
636613 snd_soc_component_update_bits(component, CDC_D_CDC_CONN_TX2_CTL,
637614 CONN_TX2_SERIAL_TX2_MUX,
....@@ -692,6 +669,34 @@
692669 return 0;
693670 }
694671
672
+static int pm8916_wcd_analog_enable_ear_pa(struct snd_soc_dapm_widget *w,
673
+ struct snd_kcontrol *kcontrol,
674
+ int event)
675
+{
676
+ struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
677
+
678
+ switch (event) {
679
+ case SND_SOC_DAPM_PRE_PMU:
680
+ snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
681
+ RX_EAR_CTL_PA_SEL_MASK, RX_EAR_CTL_PA_SEL);
682
+ break;
683
+ case SND_SOC_DAPM_POST_PMU:
684
+ snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
685
+ RX_EAR_CTL_PA_EAR_PA_EN_MASK,
686
+ RX_EAR_CTL_PA_EAR_PA_EN_ENABLE);
687
+ break;
688
+ case SND_SOC_DAPM_POST_PMD:
689
+ snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
690
+ RX_EAR_CTL_PA_EAR_PA_EN_MASK, 0);
691
+ /* Delay to reduce ear turn off pop */
692
+ usleep_range(7000, 7100);
693
+ snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
694
+ RX_EAR_CTL_PA_SEL_MASK, 0);
695
+ break;
696
+ }
697
+ return 0;
698
+}
699
+
695700 static const struct reg_default wcd_reg_defaults_2_0[] = {
696701 {CDC_A_RX_COM_OCP_CTL, 0xD1},
697702 {CDC_A_RX_COM_OCP_COUNT, 0xFF},
....@@ -725,8 +730,8 @@
725730 snd_soc_component_init_regmap(component,
726731 dev_get_regmap(component->dev->parent, NULL));
727732 snd_soc_component_set_drvdata(component, priv);
728
- priv->pmic_rev = snd_soc_component_read32(component, CDC_D_REVISION1);
729
- priv->codec_version = snd_soc_component_read32(component, CDC_D_PERPH_SUBTYPE);
733
+ priv->pmic_rev = snd_soc_component_read(component, CDC_D_REVISION1);
734
+ priv->codec_version = snd_soc_component_read(component, CDC_D_PERPH_SUBTYPE);
730735
731736 dev_info(component->dev, "PMIC REV: %d\t CODEC Version: %d\n",
732737 priv->pmic_rev, priv->codec_version);
....@@ -808,12 +813,20 @@
808813 {"PDM_TX", NULL, "A_MCLK2"},
809814 {"A_MCLK2", NULL, "A_MCLK"},
810815
816
+ /* Earpiece (RX MIX1) */
817
+ {"EAR", NULL, "EAR_S"},
818
+ {"EAR_S", "Switch", "EAR PA"},
819
+ {"EAR PA", NULL, "RX_BIAS"},
820
+ {"EAR PA", NULL, "HPHL DAC"},
821
+ {"EAR PA", NULL, "HPHR DAC"},
822
+ {"EAR PA", NULL, "EAR CP"},
823
+
811824 /* Headset (RX MIX1 and RX MIX2) */
812825 {"HEADPHONE", NULL, "HPHL PA"},
813826 {"HEADPHONE", NULL, "HPHR PA"},
814827
815
- {"HPHL PA", NULL, "EAR_HPHL_CLK"},
816
- {"HPHR PA", NULL, "EAR_HPHR_CLK"},
828
+ {"HPHL DAC", NULL, "EAR_HPHL_CLK"},
829
+ {"HPHR DAC", NULL, "EAR_HPHR_CLK"},
817830
818831 {"CP", NULL, "NCP_CLK"},
819832
....@@ -834,14 +847,16 @@
834847 {"SPK PA", NULL, "SPK DAC"},
835848 {"SPK DAC", "Switch", "PDM_RX3"},
836849
837
- {"MIC BIAS Internal1", NULL, "INT_LDO_H"},
838
- {"MIC BIAS Internal2", NULL, "INT_LDO_H"},
839
- {"MIC BIAS External1", NULL, "INT_LDO_H"},
840
- {"MIC BIAS External2", NULL, "INT_LDO_H"},
841
- {"MIC BIAS Internal1", NULL, "vdd-micbias"},
842
- {"MIC BIAS Internal2", NULL, "vdd-micbias"},
843
- {"MIC BIAS External1", NULL, "vdd-micbias"},
844
- {"MIC BIAS External2", NULL, "vdd-micbias"},
850
+ {"MIC_BIAS1", NULL, "INT_LDO_H"},
851
+ {"MIC_BIAS2", NULL, "INT_LDO_H"},
852
+ {"MIC_BIAS1", NULL, "vdd-micbias"},
853
+ {"MIC_BIAS2", NULL, "vdd-micbias"},
854
+
855
+ {"MIC BIAS External1", NULL, "MIC_BIAS1"},
856
+ {"MIC BIAS Internal1", NULL, "MIC_BIAS1"},
857
+ {"MIC BIAS External2", NULL, "MIC_BIAS2"},
858
+ {"MIC BIAS Internal2", NULL, "MIC_BIAS2"},
859
+ {"MIC BIAS Internal3", NULL, "MIC_BIAS1"},
845860 };
846861
847862 static const struct snd_soc_dapm_widget pm8916_wcd_analog_dapm_widgets[] = {
....@@ -854,10 +869,19 @@
854869 SND_SOC_DAPM_INPUT("AMIC1"),
855870 SND_SOC_DAPM_INPUT("AMIC3"),
856871 SND_SOC_DAPM_INPUT("AMIC2"),
872
+ SND_SOC_DAPM_OUTPUT("EAR"),
857873 SND_SOC_DAPM_OUTPUT("HEADPHONE"),
858874
859875 /* RX stuff */
860876 SND_SOC_DAPM_SUPPLY("INT_LDO_H", SND_SOC_NOPM, 1, 0, NULL, 0),
877
+
878
+ SND_SOC_DAPM_PGA_E("EAR PA", SND_SOC_NOPM,
879
+ 0, 0, NULL, 0,
880
+ pm8916_wcd_analog_enable_ear_pa,
881
+ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
882
+ SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
883
+ SND_SOC_DAPM_MUX("EAR_S", SND_SOC_NOPM, 0, 0, &ear_mux),
884
+ SND_SOC_DAPM_SUPPLY("EAR CP", CDC_A_NCP_EN, 4, 0, NULL, 0),
861885
862886 SND_SOC_DAPM_PGA("HPHL PA", CDC_A_RX_HPH_CNP_EN, 5, 0, NULL, 0),
863887 SND_SOC_DAPM_MUX("HPHL", SND_SOC_NOPM, 0, 0, &hphl_mux),
....@@ -884,21 +908,26 @@
884908 SND_SOC_DAPM_SUPPLY("RX_BIAS", CDC_A_RX_COM_BIAS_DAC, 7, 0, NULL, 0),
885909
886910 /* TX */
887
- SND_SOC_DAPM_SUPPLY("MIC BIAS Internal1", CDC_A_MICB_1_EN, 7, 0,
888
- pm8916_wcd_analog_enable_micbias_int1,
889
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
890
- SND_SOC_DAPM_POST_PMD),
891
- SND_SOC_DAPM_SUPPLY("MIC BIAS Internal2", CDC_A_MICB_2_EN, 7, 0,
911
+ SND_SOC_DAPM_SUPPLY("MIC_BIAS1", CDC_A_MICB_1_EN, 7, 0,
912
+ pm8916_wcd_analog_enable_micbias1,
913
+ SND_SOC_DAPM_POST_PMU),
914
+ SND_SOC_DAPM_SUPPLY("MIC_BIAS2", CDC_A_MICB_2_EN, 7, 0,
915
+ pm8916_wcd_analog_enable_micbias2,
916
+ SND_SOC_DAPM_POST_PMU),
917
+
918
+ SND_SOC_DAPM_SUPPLY("MIC BIAS External1", SND_SOC_NOPM, 0, 0, NULL, 0),
919
+ SND_SOC_DAPM_SUPPLY("MIC BIAS External2", SND_SOC_NOPM, 0, 0, NULL, 0),
920
+
921
+ SND_SOC_DAPM_SUPPLY("MIC BIAS Internal1", CDC_A_MICB_1_INT_RBIAS, 7, 0,
922
+ pm8916_wcd_analog_enable_micbias_int,
923
+ SND_SOC_DAPM_PRE_PMU),
924
+ SND_SOC_DAPM_SUPPLY("MIC BIAS Internal2", CDC_A_MICB_1_INT_RBIAS, 4, 0,
892925 pm8916_wcd_analog_enable_micbias_int2,
893926 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
894927 SND_SOC_DAPM_POST_PMD),
895
-
896
- SND_SOC_DAPM_SUPPLY("MIC BIAS External1", CDC_A_MICB_1_EN, 7, 0,
897
- pm8916_wcd_analog_enable_micbias_ext1,
898
- SND_SOC_DAPM_POST_PMU),
899
- SND_SOC_DAPM_SUPPLY("MIC BIAS External2", CDC_A_MICB_2_EN, 7, 0,
900
- pm8916_wcd_analog_enable_micbias_ext2,
901
- SND_SOC_DAPM_POST_PMU),
928
+ SND_SOC_DAPM_SUPPLY("MIC BIAS Internal3", CDC_A_MICB_1_INT_RBIAS, 1, 0,
929
+ pm8916_wcd_analog_enable_micbias_int,
930
+ SND_SOC_DAPM_PRE_PMU),
902931
903932 SND_SOC_DAPM_ADC_E("ADC1", NULL, CDC_A_TX_1_EN, 7, 0,
904933 pm8916_wcd_analog_enable_adc,
....@@ -961,7 +990,7 @@
961990
962991 if (priv->detect_accessory_type) {
963992 struct snd_soc_component *component = priv->component;
964
- u32 val = snd_soc_component_read32(component, CDC_A_MBHC_RESULT_1);
993
+ u32 val = snd_soc_component_read(component, CDC_A_MBHC_RESULT_1);
965994
966995 /* check if its BTN0 thats released */
967996 if ((val != -1) && !(val & CDC_A_MBHC_RESULT_1_BTN_RESULT_MASK))
....@@ -980,7 +1009,7 @@
9801009 struct snd_soc_component *component = priv->component;
9811010 u32 btn_result;
9821011
983
- btn_result = snd_soc_component_read32(component, CDC_A_MBHC_RESULT_1) &
1012
+ btn_result = snd_soc_component_read(component, CDC_A_MBHC_RESULT_1) &
9841013 CDC_A_MBHC_RESULT_1_BTN_RESULT_MASK;
9851014
9861015 switch (btn_result) {
....@@ -1017,7 +1046,7 @@
10171046 struct snd_soc_component *component = priv->component;
10181047 bool ins = false;
10191048
1020
- if (snd_soc_component_read32(component, CDC_A_MBHC_DET_CTL_1) &
1049
+ if (snd_soc_component_read(component, CDC_A_MBHC_DET_CTL_1) &
10211050 CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_MASK)
10221051 ins = true;
10231052
....@@ -1030,7 +1059,7 @@
10301059 if (ins) { /* hs insertion */
10311060 bool micbias_enabled = false;
10321061
1033
- if (snd_soc_component_read32(component, CDC_A_MICB_2_EN) &
1062
+ if (snd_soc_component_read(component, CDC_A_MICB_2_EN) &
10341063 CDC_A_MICB_2_EN_ENABLE)
10351064 micbias_enabled = true;
10361065
....@@ -1193,8 +1222,8 @@
11931222
11941223 irq = platform_get_irq_byname(pdev, "mbhc_switch_int");
11951224 if (irq < 0) {
1196
- dev_err(dev, "failed to get mbhc switch irq\n");
1197
- return irq;
1225
+ ret = irq;
1226
+ goto err_disable_clk;
11981227 }
11991228
12001229 ret = devm_request_threaded_irq(dev, irq, NULL,
....@@ -1208,8 +1237,8 @@
12081237 if (priv->mbhc_btn_enabled) {
12091238 irq = platform_get_irq_byname(pdev, "mbhc_but_press_det");
12101239 if (irq < 0) {
1211
- dev_err(dev, "failed to get button press irq\n");
1212
- return irq;
1240
+ ret = irq;
1241
+ goto err_disable_clk;
12131242 }
12141243
12151244 ret = devm_request_threaded_irq(dev, irq, NULL,
....@@ -1222,8 +1251,8 @@
12221251
12231252 irq = platform_get_irq_byname(pdev, "mbhc_but_rel_det");
12241253 if (irq < 0) {
1225
- dev_err(dev, "failed to get button release irq\n");
1226
- return irq;
1254
+ ret = irq;
1255
+ goto err_disable_clk;
12271256 }
12281257
12291258 ret = devm_request_threaded_irq(dev, irq, NULL,
....@@ -1241,6 +1270,10 @@
12411270 return devm_snd_soc_register_component(dev, &pm8916_wcd_analog,
12421271 pm8916_wcd_analog_dai,
12431272 ARRAY_SIZE(pm8916_wcd_analog_dai));
1273
+
1274
+err_disable_clk:
1275
+ clk_disable_unprepare(priv->mclk);
1276
+ return ret;
12441277 }
12451278
12461279 static int pm8916_wcd_analog_spmi_remove(struct platform_device *pdev)