]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
mfd: wm8994: Emulate level triggered interrupts if required
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Mon, 6 May 2013 15:12:56 +0000 (16:12 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 16 May 2013 16:59:48 +0000 (18:59 +0200)
The interrupt controller on the wm8994 series of devices requires a level
triggered parent. If one is not available but a GPIO is available for the
interrupt then emulate.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/mfd/wm8994-irq.c
include/linux/mfd/wm8994/core.h
include/linux/mfd/wm8994/pdata.h

index a050e56a9bbdcf16f200dbe363391393ce4f6756..d3a184a240f5e0a7cb683bb330b82d01c15eaeaf 100644 (file)
 
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/gpio.h>
 #include <linux/i2c.h>
 #include <linux/irq.h>
 #include <linux/mfd/core.h>
 #include <linux/interrupt.h>
+#include <linux/irqdomain.h>
 #include <linux/regmap.h>
 
 #include <linux/mfd/wm8994/core.h>
@@ -138,6 +140,55 @@ static struct regmap_irq_chip wm8994_irq_chip = {
        .runtime_pm = true,
 };
 
+static void wm8994_edge_irq_enable(struct irq_data *data)
+{
+}
+
+static void wm8994_edge_irq_disable(struct irq_data *data)
+{
+}
+
+static struct irq_chip wm8994_edge_irq_chip = {
+       .name                   = "wm8994_edge",
+       .irq_disable            = wm8994_edge_irq_disable,
+       .irq_enable             = wm8994_edge_irq_enable,
+};
+
+static irqreturn_t wm8994_edge_irq(int irq, void *data)
+{
+       struct wm8994 *wm8994 = data;
+
+       while (gpio_get_value_cansleep(wm8994->pdata.irq_gpio))
+               handle_nested_irq(irq_create_mapping(wm8994->edge_irq, 0));
+
+       return IRQ_HANDLED;
+}
+
+static int wm8994_edge_irq_map(struct irq_domain *h, unsigned int virq,
+                              irq_hw_number_t hw)
+{
+       struct wm8994 *wm8994 = h->host_data;
+
+       irq_set_chip_data(virq, wm8994);
+       irq_set_chip_and_handler(virq, &wm8994_edge_irq_chip, handle_edge_irq);
+       irq_set_nested_thread(virq, 1);
+
+       /* ARM needs us to explicitly flag the IRQ as valid
+        * and will set them noprobe when we do so. */
+#ifdef CONFIG_ARM
+       set_irq_flags(virq, IRQF_VALID);
+#else
+       irq_set_noprobe(virq);
+#endif
+
+       return 0;
+}
+
+static struct irq_domain_ops wm8994_edge_irq_ops = {
+       .map    = wm8994_edge_irq_map,
+       .xlate  = irq_domain_xlate_twocell,
+};
+
 int wm8994_irq_init(struct wm8994 *wm8994)
 {
        int ret;
@@ -156,10 +207,51 @@ int wm8994_irq_init(struct wm8994 *wm8994)
        if (pdata->irq_flags)
                irqflags = pdata->irq_flags;
 
-       ret = regmap_add_irq_chip(wm8994->regmap, wm8994->irq,
-                                 irqflags,
-                                 wm8994->irq_base, &wm8994_irq_chip,
-                                 &wm8994->irq_data);
+       /* use a GPIO for edge triggered controllers */
+       if (irqflags & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
+               if (gpio_to_irq(pdata->irq_gpio) != wm8994->irq) {
+                       dev_warn(wm8994->dev, "IRQ %d is not GPIO %d (%d)\n",
+                                wm8994->irq, pdata->irq_gpio,
+                                gpio_to_irq(pdata->irq_gpio));
+                       wm8994->irq = gpio_to_irq(pdata->irq_gpio);
+               }
+
+               ret = devm_gpio_request_one(wm8994->dev, pdata->irq_gpio,
+                                           GPIOF_IN, "WM8994 IRQ");
+
+               if (ret != 0) {
+                       dev_err(wm8994->dev, "Failed to get IRQ GPIO: %d\n",
+                               ret);
+                       return ret;
+               }
+
+               wm8994->edge_irq = irq_domain_add_linear(NULL, 1,
+                                                        &wm8994_edge_irq_ops,
+                                                        wm8994);
+
+               ret = regmap_add_irq_chip(wm8994->regmap,
+                                         irq_create_mapping(wm8994->edge_irq,
+                                                            0),
+                                         IRQF_ONESHOT,
+                                         wm8994->irq_base, &wm8994_irq_chip,
+                                         &wm8994->irq_data);
+               if (ret != 0) {
+                       dev_err(wm8994->dev, "Failed to get IRQ: %d\n",
+                               ret);
+                       return ret;
+               }
+
+               ret = request_threaded_irq(wm8994->irq,
+                                          NULL, wm8994_edge_irq,
+                                          irqflags,
+                                          "WM8994 edge", wm8994);
+       } else {
+               ret = regmap_add_irq_chip(wm8994->regmap, wm8994->irq,
+                                         irqflags,
+                                         wm8994->irq_base, &wm8994_irq_chip,
+                                         &wm8994->irq_data);
+       }
+
        if (ret != 0) {
                dev_err(wm8994->dev, "Failed to register IRQ chip: %d\n", ret);
                return ret;
index ae5c249530b4e7f527a22f44e242d4d4bce66419..40854ac0ba3d0cc6fdfd3116275db97d15ec3811 100644 (file)
@@ -29,6 +29,7 @@ enum wm8994_type {
 
 struct regulator_dev;
 struct regulator_bulk_data;
+struct irq_domain;
 
 #define WM8994_NUM_GPIO_REGS 11
 #define WM8994_NUM_LDO_REGS   2
@@ -73,6 +74,7 @@ struct wm8994 {
 
        int irq;
        struct regmap_irq_chip_data *irq_data;
+       struct irq_domain *edge_irq;
 
        /* Used over suspend/resume */
        bool suspended;
index 68e77659488950f69df451b04b065eee72c9d144..90e9bf86e643ce79cf2db4fd1be615d69dbb7052 100644 (file)
@@ -223,6 +223,11 @@ struct wm8994_pdata {
         * lines is mastered.
         */
        int max_channels_clocked[WM8994_NUM_AIF];
+
+       /**
+        * GPIO for the IRQ pin if host only supports edge triggering
+        */
+       int irq_gpio;
 };
 
 #endif