[PATCH] mfd: da9062: add support for interrupt polarity defined in device tree
From: Shreyas Joshi
Date: Wed Jan 29 2020 - 18:35:55 EST
The da9062 interrupt handler cannot necessarily be low active.
Add a helper function to read the polarity defined in the device tree.
Based on the user defined polarity in device tree, the interrupt is
set active.
Signed-off-by: shreyas <shreyas.joshi@xxxxxxxxx>
---
drivers/mfd/da9062-core.c | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/drivers/mfd/da9062-core.c b/drivers/mfd/da9062-core.c
index 419c73533401..62ba10aeb440 100644
--- a/drivers/mfd/da9062-core.c
+++ b/drivers/mfd/da9062-core.c
@@ -369,6 +369,22 @@ static int da9062_get_device_type(struct da9062 *chip)
return ret;
}
+static inline u32 irqd_get_polarity(struct irq_data *d, struct device *dev)
+{
+ u32 trigger_type = irqd_get_trigger_type(d);
+
+ switch (trigger_type) {
+ case IRQ_TYPE_LEVEL_HIGH:
+ case IRQ_TYPE_LEVEL_LOW:
+ case IRQ_TYPE_NONE:
+ return trigger_type;
+ default:
+ dev_warn(dev, "Invalid IRQ type: %d defaulting to IRQ_TYPE_NONE\n",
+ trigger_type);
+ return IRQ_TYPE_NONE;
+ }
+}
+
static const struct regmap_range da9061_aa_readable_ranges[] = {
regmap_reg_range(DA9062AA_PAGE_CON, DA9062AA_STATUS_B),
regmap_reg_range(DA9062AA_STATUS_D, DA9062AA_EVENT_C),
@@ -592,6 +608,7 @@ static int da9062_i2c_probe(struct i2c_client *i2c,
struct da9062 *chip;
const struct of_device_id *match;
unsigned int irq_base;
+ struct irq_data *irq_data;
const struct mfd_cell *cell;
const struct regmap_irq_chip *irq_chip;
const struct regmap_config *config;
@@ -654,9 +671,16 @@ static int da9062_i2c_probe(struct i2c_client *i2c,
if (ret)
return ret;
+ irq_data = irq_get_irq_data(i2c->irq);
+ if (!irq_data) {
+ dev_err(chip->dev, "Invalid IRQ: %d\n", i2c->irq);
+ return -EINVAL;
+ }
+
ret = regmap_add_irq_chip(chip->regmap, i2c->irq,
- IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED,
- -1, irq_chip,
+ irqd_get_polarity(irq_data, chip->dev)
+ | IRQF_ONESHOT | IRQF_SHARED | IRQF_ONESHOT
+ | IRQF_SHARED, -1, irq_chip,
&chip->regmap_irq);
if (ret) {
dev_err(chip->dev, "Failed to request IRQ %d: %d\n",
--
2.20.1