Commit df9091e9 authored by Ben Zhang's avatar Ben Zhang Committed by Mark Brown

ASoC: rt5677: handle concurrent interrupts

The rt5677 driver writes to the IRQ control register within the IRQ
handler in order to flip the polarity of the interrupts that have been
signalled.  If an interrupt fires in the interval between the
regmap_read and the regmap_write, it will not trigger a new call to
rt5677_irq.

Add a bounded loop to rt5677_irq that keeps checking interrupts until
none are seen, so that any interrupts that are signalled in that
interval are correctly handled.
Signed-off-by: default avatarBen Zhang <benzh@chromium.org>
Signed-off-by: default avatarFletcher Woodruff <fletcherw@chromium.org>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 4f7b018b
...@@ -5072,17 +5072,35 @@ static const struct rt5677_irq_desc rt5677_irq_descs[] = { ...@@ -5072,17 +5072,35 @@ static const struct rt5677_irq_desc rt5677_irq_descs[] = {
static irqreturn_t rt5677_irq(int unused, void *data) static irqreturn_t rt5677_irq(int unused, void *data)
{ {
struct rt5677_priv *rt5677 = data; struct rt5677_priv *rt5677 = data;
int ret = 0, i, reg_irq, virq; int ret = 0, loop, i, reg_irq, virq;
bool irq_fired = false; bool irq_fired = false;
mutex_lock(&rt5677->irq_lock); mutex_lock(&rt5677->irq_lock);
/*
* Loop to handle interrupts until the last i2c read shows no pending
* irqs. The interrupt line is shared by multiple interrupt sources.
* After the regmap_read() below, a new interrupt source line may
* become high before the regmap_write() finishes, so there isn't a
* rising edge on the shared interrupt line for the new interrupt. Thus,
* the loop is needed to avoid missing irqs.
*
* A safeguard of 20 loops is used to avoid hanging in the irq handler
* if there is something wrong with the interrupt status update. The
* interrupt sources here are audio jack plug/unplug events which
* shouldn't happen at a high frequency for a long period of time.
* Empirically, more than 3 loops have never been seen.
*/
for (loop = 0; loop < 20; loop++) {
/* Read interrupt status */ /* Read interrupt status */
ret = regmap_read(rt5677->regmap, RT5677_IRQ_CTRL1, &reg_irq); ret = regmap_read(rt5677->regmap, RT5677_IRQ_CTRL1, &reg_irq);
if (ret) { if (ret) {
dev_err(rt5677->dev, "failed reading IRQ status: %d\n", ret); dev_err(rt5677->dev, "failed reading IRQ status: %d\n",
ret);
goto exit; goto exit;
} }
irq_fired = false;
for (i = 0; i < RT5677_IRQ_NUM; i++) { for (i = 0; i < RT5677_IRQ_NUM; i++) {
if (reg_irq & rt5677_irq_descs[i].status_mask) { if (reg_irq & rt5677_irq_descs[i].status_mask) {
irq_fired = true; irq_fired = true;
...@@ -5090,21 +5108,22 @@ static irqreturn_t rt5677_irq(int unused, void *data) ...@@ -5090,21 +5108,22 @@ static irqreturn_t rt5677_irq(int unused, void *data)
if (virq) if (virq)
handle_nested_irq(virq); handle_nested_irq(virq);
/* Clear the interrupt by flipping the polarity of the /* Clear the interrupt by flipping the polarity
* interrupt source line that fired * of the interrupt source line that fired
*/ */
reg_irq ^= rt5677_irq_descs[i].polarity_mask; reg_irq ^= rt5677_irq_descs[i].polarity_mask;
} }
} }
if (!irq_fired) if (!irq_fired)
goto exit; goto exit;
ret = regmap_write(rt5677->regmap, RT5677_IRQ_CTRL1, reg_irq); ret = regmap_write(rt5677->regmap, RT5677_IRQ_CTRL1, reg_irq);
if (ret) { if (ret) {
dev_err(rt5677->dev, "failed updating IRQ status: %d\n", ret); dev_err(rt5677->dev, "failed updating IRQ status: %d\n",
ret);
goto exit; goto exit;
} }
}
exit: exit:
mutex_unlock(&rt5677->irq_lock); mutex_unlock(&rt5677->irq_lock);
if (irq_fired) if (irq_fired)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment