summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/mfd/wm8994-irq.c100
-rw-r--r--include/linux/mfd/wm8994/core.h2
-rw-r--r--include/linux/mfd/wm8994/pdata.h5
3 files changed, 103 insertions, 4 deletions
diff --git a/drivers/mfd/wm8994-irq.c b/drivers/mfd/wm8994-irq.c
index a050e56a9bbd..d3a184a240f5 100644
--- a/drivers/mfd/wm8994-irq.c
+++ b/drivers/mfd/wm8994-irq.c
@@ -14,10 +14,12 @@
#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;
diff --git a/include/linux/mfd/wm8994/core.h b/include/linux/mfd/wm8994/core.h
index ae5c249530b4..40854ac0ba3d 100644
--- a/include/linux/mfd/wm8994/core.h
+++ b/include/linux/mfd/wm8994/core.h
@@ -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;
diff --git a/include/linux/mfd/wm8994/pdata.h b/include/linux/mfd/wm8994/pdata.h
index 68e776594889..90e9bf86e643 100644
--- a/include/linux/mfd/wm8994/pdata.h
+++ b/include/linux/mfd/wm8994/pdata.h
@@ -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