mfd: Read wm831x AUXADC conversion results before acknowledging interrupt
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Thu, 2 Jun 2011 18:18:52 +0000 (19:18 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Sun, 31 Jul 2011 21:28:20 +0000 (23:28 +0200)
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: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/mfd/wm831x-core.c
include/linux/mfd/wm831x/core.h

index 58f033b57efee1b9db12cdfc908b2e0d863eeb1b..480abc18f9f3444e3a0d1bb8d4334111e5224dad 100644 (file)
@@ -376,6 +376,16 @@ int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input)
                                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 {
                /* If we are using interrupts then wait for the
                 * interrupt to complete.  Use an extremely long
@@ -390,23 +400,18 @@ int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input)
                }
        }
 
-       ret = wm831x_reg_read(wm831x, WM831X_AUXADC_DATA);
-       if (ret < 0) {
-               dev_err(wm831x->dev, "Failed to read AUXADC data: %d\n", ret);
+       src = ((wm831x->auxadc_data & WM831X_AUX_DATA_SRC_MASK)
+              >> WM831X_AUX_DATA_SRC_SHIFT) - 1;
+
+       if (src == 14)
+               src = WM831X_AUX_CAL;
+
+       if (src != input) {
+               dev_err(wm831x->dev, "Data from source %d not %d\n",
+                       src, input);
+               ret = -EINVAL;
        } else {
-               src = ((ret & WM831X_AUX_DATA_SRC_MASK)
-                      >> WM831X_AUX_DATA_SRC_SHIFT) - 1;
-
-               if (src == 14)
-                       src = WM831X_AUX_CAL;
-
-               if (src != input) {
-                       dev_err(wm831x->dev, "Data from source %d not %d\n",
-                               src, input);
-                       ret = -EINVAL;
-               } else {
-                       ret &= WM831X_AUX_DATA_MASK;
-               }
+               ret = wm831x->auxadc_data & WM831X_AUX_DATA_MASK;
        }
 
 disable:
@@ -420,6 +425,16 @@ EXPORT_SYMBOL_GPL(wm831x_auxadc_read);
 static irqreturn_t wm831x_auxadc_irq(int irq, void *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);
 
index 9564cf315276f462e6c88a1c343823945e401106..592e4fd6ab3fbee5e75b54e8a3ac52f5486f62eb 100644 (file)
@@ -278,6 +278,7 @@ struct wm831x {
 
        struct mutex auxadc_lock;
        struct completion auxadc_done;
+       u16 auxadc_data;
 
        /* The WM831x has a security key blocking access to certain
         * registers.  The mutex is taken by the accessors for locking