Extcon: Fix mic high level of noise.
authorWen Xie <xiewen3@motorola.com>
Tue, 28 May 2019 03:14:34 +0000 (11:14 +0800)
committerlingsen1 <lingsen1@lenovo.com>
Sun, 7 Feb 2021 09:37:02 +0000 (17:37 +0800)
cirrus vendor patch:
Fix mic high level of noise Set MICD_RATE and
POLARITY_INV bit to 0 when a headset with mic is plugged in and set it in a
default state at removail.

Change-Id: I7ed17ef425cc3e9e0d03541996e9ea1427ee8013
Signed-off-by: Wen Xie <xiewen3@motorola.com>
Reviewed-on: https://gerrit.mot.com/1362099
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Zhengming Yao <yaozm1@mt.com>
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Submit-Approved: Jira Key

drivers/extcon/extcon-madera.c

index 32b27882773274cb95f785ce5b671d3b98f4de53..403bc9f685b7deff2b93bc3602ae635983700ece 100755 (executable)
@@ -1594,6 +1594,31 @@ static void madera_hpdet_start_micd(struct madera_extcon *info)
                           MADERA_MICD_ENA, MADERA_MICD_ENA);
 }
 
+void madera_set_magic_bit(struct madera_extcon *info, bool on)
+{
+       int rate = 1;
+       struct madera *madera = info->madera;
+       if (on) {
+               regmap_update_bits(madera->regmap,
+                                  MADERA_ACCESSORY_DETECT_MODE_1,
+                                  MADERA_ACCDET_POLARITY_INV_ENA_MASK,
+                                  0);
+               regmap_update_bits(madera->regmap, MADERA_MIC_DETECT_1_CONTROL_1,
+                          MADERA_MICD_RATE_MASK ,
+                          0);
+       } else {
+               if (info->pdata->micd_rate)
+                       rate = info->pdata->micd_rate;
+               regmap_update_bits(madera->regmap,
+                                  MADERA_ACCESSORY_DETECT_MODE_1,
+                                  MADERA_ACCDET_POLARITY_INV_ENA_MASK,
+                                  MADERA_ACCDET_POLARITY_INV_ENA);
+               regmap_update_bits(madera->regmap, MADERA_MIC_DETECT_1_CONTROL_1,
+                          MADERA_MICD_RATE_MASK ,
+                          rate << MADERA_MICD_RATE_SHIFT);
+       }
+}
+
 static void madera_hpdet_stop_micd(struct madera_extcon *info)
 {
        struct madera *madera = info->madera;
@@ -1795,6 +1820,8 @@ void madera_hpdet_stop(struct madera_extcon *info)
        /* Reset back to starting range */
        madera_hpdet_stop_micd(info);
 
+       madera_set_magic_bit(info, info->have_mic);
+
        regmap_update_bits(madera->regmap, MADERA_HEADPHONE_DETECT_1,
                           MADERA_HP_IMPEDANCE_RANGE_MASK | MADERA_HP_POLL,
                           info->hpdet_init_range <<
@@ -2434,6 +2461,8 @@ static irqreturn_t madera_jackdet(int irq, void *data)
                madera_set_headphone_imp(info, MADERA_HP_Z_OPEN);
 
                madera_extcon_notify_micd(info, false, 0);
+
+                madera_set_magic_bit(info, false);
        }
 
 out: