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

mfd: Fix bus lock interaction for WM831x IRQ set_type() operation

The WM831x IRQ set_type() operation is doing a direct register write when
called but since set_type() is called with the bus lock held this isn't
legal and could cause deadlocks in the IRQ core.

Fix this by posting the updates into an array and syncing in the
bus_sync_unlock() callback.
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent 24c30470
...@@ -348,6 +348,15 @@ static void wm831x_irq_sync_unlock(struct irq_data *data) ...@@ -348,6 +348,15 @@ static void wm831x_irq_sync_unlock(struct irq_data *data)
struct wm831x *wm831x = irq_data_get_irq_chip_data(data); struct wm831x *wm831x = irq_data_get_irq_chip_data(data);
int i; int i;
for (i = 0; i < ARRAY_SIZE(wm831x->gpio_update); i++) {
if (wm831x->gpio_update[i]) {
wm831x_set_bits(wm831x, WM831X_GPIO1_CONTROL + i,
WM831X_GPN_INT_MODE | WM831X_GPN_POL,
wm831x->gpio_update[i]);
wm831x->gpio_update[i] = 0;
}
}
for (i = 0; i < ARRAY_SIZE(wm831x->irq_masks_cur); i++) { for (i = 0; i < ARRAY_SIZE(wm831x->irq_masks_cur); i++) {
/* If there's been a change in the mask write it back /* If there's been a change in the mask write it back
* to the hardware. */ * to the hardware. */
...@@ -387,7 +396,7 @@ static void wm831x_irq_disable(struct irq_data *data) ...@@ -387,7 +396,7 @@ static void wm831x_irq_disable(struct irq_data *data)
static int wm831x_irq_set_type(struct irq_data *data, unsigned int type) static int wm831x_irq_set_type(struct irq_data *data, unsigned int type)
{ {
struct wm831x *wm831x = irq_data_get_irq_chip_data(data); struct wm831x *wm831x = irq_data_get_irq_chip_data(data);
int val, irq; int irq;
irq = data->irq - wm831x->irq_base; irq = data->irq - wm831x->irq_base;
...@@ -399,22 +408,25 @@ static int wm831x_irq_set_type(struct irq_data *data, unsigned int type) ...@@ -399,22 +408,25 @@ static int wm831x_irq_set_type(struct irq_data *data, unsigned int type)
return -EINVAL; return -EINVAL;
} }
/* We set the high bit to flag that we need an update; don't
* do the update here as we can be called with the bus lock
* held.
*/
switch (type) { switch (type) {
case IRQ_TYPE_EDGE_BOTH: case IRQ_TYPE_EDGE_BOTH:
val = WM831X_GPN_INT_MODE; wm831x->gpio_update[irq] = 0x10000 | WM831X_GPN_INT_MODE;
break; break;
case IRQ_TYPE_EDGE_RISING: case IRQ_TYPE_EDGE_RISING:
val = WM831X_GPN_POL; wm831x->gpio_update[irq] = 0x10000 | WM831X_GPN_POL;
break; break;
case IRQ_TYPE_EDGE_FALLING: case IRQ_TYPE_EDGE_FALLING:
val = 0; wm831x->gpio_update[irq] = 0x10000;
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
return wm831x_set_bits(wm831x, WM831X_GPIO1_CONTROL + irq, return 0;
WM831X_GPN_INT_MODE | WM831X_GPN_POL, val);
} }
static struct irq_chip wm831x_irq_chip = { static struct irq_chip wm831x_irq_chip = {
......
...@@ -237,6 +237,7 @@ ...@@ -237,6 +237,7 @@
struct regulator_dev; struct regulator_dev;
#define WM831X_NUM_IRQ_REGS 5 #define WM831X_NUM_IRQ_REGS 5
#define WM831X_NUM_GPIO_REGS 16
enum wm831x_parent { enum wm831x_parent {
WM8310 = 0x8310, WM8310 = 0x8310,
...@@ -272,6 +273,9 @@ struct wm831x { ...@@ -272,6 +273,9 @@ struct wm831x {
int num_gpio; int num_gpio;
/* Used by the interrupt controller code to post writes */
int gpio_update[WM831X_NUM_GPIO_REGS];
struct mutex auxadc_lock; struct mutex auxadc_lock;
struct completion auxadc_done; struct completion auxadc_done;
......
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