Skip to content

Commit b7d2e50

Browse files
jwrdegoedegregkh
authored andcommitted
extcon: arizona: Fix some issues when HPDET IRQ fires after the jack has been unplugged
[ Upstream commit c309a3e ] When the jack is partially inserted and then removed again it may be removed while the hpdet code is running. In this case the following may happen: 1. The "JACKDET rise" or ""JACKDET fall" IRQ triggers 2. arizona_jackdet runs and takes info->lock 3. The "HPDET" IRQ triggers 4. arizona_hpdet_irq runs, blocks on info->lock 5. arizona_jackdet calls arizona_stop_mic() and clears info->hpdet_done 6. arizona_jackdet releases info->lock 7. arizona_hpdet_irq now can continue running and: 7.1 Calls arizona_start_mic() (if a mic was detected) 7.2 sets info->hpdet_done Step 7 is undesirable / a bug: 7.1 causes the device to stay in a high power-state (with MICVDD enabled) 7.2 causes hpdet to not run on the next jack insertion, which in turn causes the EXTCON_JACK_HEADPHONE state to never get set This fixes both issues by skipping these 2 steps when arizona_hpdet_irq runs after the jack has been unplugged. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com> Tested-by: Charles Keepax <ckeepax@opensource.cirrus.com> Acked-by: Chanwoo Choi <cw00.choi@samsung.com> Signed-off-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8ff0d8a commit b7d2e50

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎drivers/extcon/extcon-arizona.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
601601
struct arizona *arizona = info->arizona;
602602
int id_gpio = arizona->pdata.hpdet_id_gpio;
603603
unsigned int report = EXTCON_JACK_HEADPHONE;
604-
int ret, reading;
604+
int ret, reading, state;
605605
bool mic = false;
606606

607607
mutex_lock(&info->lock);
@@ -614,12 +614,11 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
614614
}
615615

616616
/* If the cable was removed while measuring ignore the result */
617-
ret = extcon_get_state(info->edev, EXTCON_MECHANICAL);
618-
if (ret < 0) {
619-
dev_err(arizona->dev, "Failed to check cable state: %d\n",
620-
ret);
617+
state = extcon_get_state(info->edev, EXTCON_MECHANICAL);
618+
if (state < 0) {
619+
dev_err(arizona->dev, "Failed to check cable state: %d\n", state);
621620
goto out;
622-
} else if (!ret) {
621+
} else if (!state) {
623622
dev_dbg(arizona->dev, "Ignoring HPDET for removed cable\n");
624623
goto done;
625624
}
@@ -667,15 +666,17 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
667666
gpio_set_value_cansleep(id_gpio, 0);
668667

669668
/* If we have a mic then reenable MICDET */
670-
if (mic || info->mic)
669+
if (state && (mic || info->mic))
671670
arizona_start_mic(info);
672671

673672
if (info->hpdet_active) {
674673
pm_runtime_put_autosuspend(info->dev);
675674
info->hpdet_active = false;
676675
}
677676

678-
info->hpdet_done = true;
677+
/* Do not set hp_det done when the cable has been unplugged */
678+
if (state)
679+
info->hpdet_done = true;
679680

680681
out:
681682
mutex_unlock(&info->lock);

0 commit comments

Comments
 (0)