Commit c1a82780 authored by Mark Brown's avatar Mark Brown Committed by Samuel Ortiz

mfd: Read wm831x AUXADC conversion results before acknowledging interrupt

Ensure that there's no possibility of loosing an AUXADC interrupt by reading
the conversion result in the IRQ handler when using interrupts. Otherwise
it's possible that under very heavy load a new conversion could be initiated
before the acknowledgement for a previous interrupt has happened.
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent 5c05a8d1
...@@ -376,6 +376,16 @@ int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input) ...@@ -376,6 +376,16 @@ int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input)
goto disable; goto disable;
} }
} }
ret = wm831x_reg_read(wm831x, WM831X_AUXADC_DATA);
if (ret < 0) {
dev_err(wm831x->dev,
"Failed to read AUXADC data: %d\n", ret);
goto disable;
}
wm831x->auxadc_data = ret;
} else { } else {
/* If we are using interrupts then wait for the /* If we are using interrupts then wait for the
* interrupt to complete. Use an extremely long * interrupt to complete. Use an extremely long
...@@ -390,11 +400,7 @@ int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input) ...@@ -390,11 +400,7 @@ int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input)
} }
} }
ret = wm831x_reg_read(wm831x, WM831X_AUXADC_DATA); src = ((wm831x->auxadc_data & WM831X_AUX_DATA_SRC_MASK)
if (ret < 0) {
dev_err(wm831x->dev, "Failed to read AUXADC data: %d\n", ret);
} else {
src = ((ret & WM831X_AUX_DATA_SRC_MASK)
>> WM831X_AUX_DATA_SRC_SHIFT) - 1; >> WM831X_AUX_DATA_SRC_SHIFT) - 1;
if (src == 14) if (src == 14)
...@@ -405,8 +411,7 @@ int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input) ...@@ -405,8 +411,7 @@ int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input)
src, input); src, input);
ret = -EINVAL; ret = -EINVAL;
} else { } else {
ret &= WM831X_AUX_DATA_MASK; ret = wm831x->auxadc_data & WM831X_AUX_DATA_MASK;
}
} }
disable: disable:
...@@ -420,6 +425,16 @@ EXPORT_SYMBOL_GPL(wm831x_auxadc_read); ...@@ -420,6 +425,16 @@ EXPORT_SYMBOL_GPL(wm831x_auxadc_read);
static irqreturn_t wm831x_auxadc_irq(int irq, void *irq_data) static irqreturn_t wm831x_auxadc_irq(int irq, void *irq_data)
{ {
struct wm831x *wm831x = irq_data; struct wm831x *wm831x = irq_data;
int ret;
ret = wm831x_reg_read(wm831x, WM831X_AUXADC_DATA);
if (ret < 0) {
dev_err(wm831x->dev,
"Failed to read AUXADC data: %d\n", ret);
wm831x->auxadc_data = 0xffff;
} else {
wm831x->auxadc_data = ret;
}
complete(&wm831x->auxadc_done); complete(&wm831x->auxadc_done);
......
...@@ -278,6 +278,7 @@ struct wm831x { ...@@ -278,6 +278,7 @@ struct wm831x {
struct mutex auxadc_lock; struct mutex auxadc_lock;
struct completion auxadc_done; struct completion auxadc_done;
u16 auxadc_data;
/* The WM831x has a security key blocking access to certain /* The WM831x has a security key blocking access to certain
* registers. The mutex is taken by the accessors for locking * registers. The mutex is taken by the accessors for locking
......
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