extcon: madera: Take external resistance into account for short circuit
authorRichard Fitzgerald <rf@opensource.wolfsonmicro.com>
Mon, 31 Jul 2017 10:42:13 +0000 (11:42 +0100)
committerCosmin Tanislav <demonsingur@gmail.com>
Mon, 22 Apr 2024 17:22:27 +0000 (20:22 +0300)
When checking the minimum value of impedance we can detect we should
take any external resistance into account, as we can detect lower
impedances if there is some external resistance pushing the detected
impedance up.

Change-Id: Ic784807c811ab453a7ca8ef2fb115d1bcd884e87
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
drivers/extcon/extcon-madera.c

index fae98b205788f48b12b7a985eefdfb4531aeb817..e96dc35a1b431edb2c51383f3bf902963bbfb4d8 100644 (file)
@@ -2859,7 +2859,7 @@ static int madera_extcon_probe(struct platform_device *pdev)
        struct madera_extcon *info;
        unsigned int debounce_val, analog_val;
        int jack_irq_fall, jack_irq_rise;
-       int ret, mode, i;
+       int ret, mode, i, hpdet_short;
 
        /* quick exit if Madera irqchip driver hasn't completed probe */
        if (!madera->irq_dev) {
@@ -2946,8 +2946,16 @@ static int madera_extcon_probe(struct platform_device *pdev)
        if (!pdata->enabled || pdata->output == 0)
                return -ENODEV; /* no accdet output configured */
 
-       if (pdata->hpdet_short_circuit_imp < MADERA_HP_SHORT_IMPEDANCE_MIN)
+       hpdet_short = pdata->hpdet_short_circuit_imp +
+                     madera_hohm_to_ohm(pdata->hpdet_ext_res_x100);
+
+       if (hpdet_short < MADERA_HP_SHORT_IMPEDANCE_MIN) {
+               dev_warn(info->dev,
+                        "Increasing HP short circuit impedance from %d to %d\n",
+                        pdata->hpdet_short_circuit_imp,
+                        MADERA_HP_SHORT_IMPEDANCE_MIN);
                pdata->hpdet_short_circuit_imp = MADERA_HP_SHORT_IMPEDANCE_MIN;
+       }
 
        info->micvdd = devm_regulator_get(&pdev->dev, "MICVDD");
        if (IS_ERR(info->micvdd)) {