]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
mfd: Add AUXADC support for WM8350
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Sat, 8 Nov 2008 00:10:21 +0000 (01:10 +0100)
committerSamuel Ortiz <samuel@sortiz.org>
Sun, 4 Jan 2009 11:17:38 +0000 (12:17 +0100)
The auxiliary ADC in the WM8350 is shared between several subdevices
so access to it needs to be arbitrated by the core driver.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Samuel Ortiz <sameo@openedhand.com>
drivers/mfd/wm8350-core.c
include/linux/mfd/wm8350/comparator.h
include/linux/mfd/wm8350/core.h

index c013afde260d4bcea817e3afb457ab28f8d24328..60439bd3984dc74e77ff2b9f8b94be47067f9b1a 100644 (file)
@@ -63,7 +63,6 @@
  */
 static DEFINE_MUTEX(io_mutex);
 static DEFINE_MUTEX(reg_lock_mutex);
-static DEFINE_MUTEX(auxadc_mutex);
 
 /* Perform a physical read from the device.
  */
@@ -1082,6 +1081,55 @@ int wm8350_unmask_irq(struct wm8350 *wm8350, int irq)
 }
 EXPORT_SYMBOL_GPL(wm8350_unmask_irq);
 
+int wm8350_read_auxadc(struct wm8350 *wm8350, int channel, int scale, int vref)
+{
+       u16 reg, result = 0;
+       int tries = 5;
+
+       if (channel < WM8350_AUXADC_AUX1 || channel > WM8350_AUXADC_TEMP)
+               return -EINVAL;
+       if (channel >= WM8350_AUXADC_USB && channel <= WM8350_AUXADC_TEMP
+           && (scale != 0 || vref != 0))
+               return -EINVAL;
+
+       mutex_lock(&wm8350->auxadc_mutex);
+
+       /* Turn on the ADC */
+       reg = wm8350_reg_read(wm8350, WM8350_POWER_MGMT_5);
+       wm8350_reg_write(wm8350, WM8350_POWER_MGMT_5, reg | WM8350_AUXADC_ENA);
+
+       if (scale || vref) {
+               reg = scale << 13;
+               reg |= vref << 12;
+               wm8350_reg_write(wm8350, WM8350_AUX1_READBACK + channel, reg);
+       }
+
+       reg = wm8350_reg_read(wm8350, WM8350_DIGITISER_CONTROL_1);
+       reg |= 1 << channel | WM8350_AUXADC_POLL;
+       wm8350_reg_write(wm8350, WM8350_DIGITISER_CONTROL_1, reg);
+
+       do {
+               schedule_timeout_interruptible(1);
+               reg = wm8350_reg_read(wm8350, WM8350_DIGITISER_CONTROL_1);
+       } while (tries-- && (reg & WM8350_AUXADC_POLL));
+
+       if (!tries)
+               dev_err(wm8350->dev, "adc chn %d read timeout\n", channel);
+       else
+               result = wm8350_reg_read(wm8350,
+                                        WM8350_AUX1_READBACK + channel);
+
+       /* Turn off the ADC */
+       reg = wm8350_reg_read(wm8350, WM8350_POWER_MGMT_5);
+       wm8350_reg_write(wm8350, WM8350_POWER_MGMT_5,
+                        reg & ~WM8350_AUXADC_ENA);
+
+       mutex_unlock(&wm8350->auxadc_mutex);
+
+       return result & WM8350_AUXADC_DATA1_MASK;
+}
+EXPORT_SYMBOL_GPL(wm8350_read_auxadc);
+
 /*
  * Cache is always host endian.
  */
@@ -1239,6 +1287,7 @@ int wm8350_device_init(struct wm8350 *wm8350, int irq,
                }
        }
 
+       mutex_init(&wm8350->auxadc_mutex);
        mutex_init(&wm8350->irq_mutex);
        INIT_WORK(&wm8350->irq_work, wm8350_irq_worker);
        if (irq) {
index 053788649452a595dad95de896f548e6f4006c5a..54bc5d0fd5025011ba52f0a3156875157181ef13 100644 (file)
 #define WM8350_AUXADC_BATT                     6
 #define WM8350_AUXADC_TEMP                     7
 
+struct wm8350;
+
+/*
+ * AUX ADC Readback
+ */
+int wm8350_read_auxadc(struct wm8350 *wm8350, int channel, int scale,
+                      int vref);
+
 #endif
index 9490ec175d5a38e0df3e8f61e264cfb229bace61..cc190055b9c450df97f42ea39a308a88fb6f2373 100644 (file)
@@ -573,6 +573,8 @@ struct wm8350 {
                         void *src);
        u16 *reg_cache;
 
+       struct mutex auxadc_mutex;
+
        /* Interrupt handling */
        struct work_struct irq_work;
        struct mutex irq_mutex; /* IRQ table mutex */