Commit b1cc5409 authored by Shreyas Joshi's avatar Shreyas Joshi Committed by Lee Jones

mfd: da9062: Add support for interrupt polarity defined in device tree

The da9062 interrupt handler cannot necessarily be low active.
Add a function to configure the interrupt type based on what is defined in the device tree.
The allowable interrupt type is either low or high level trigger.
Signed-off-by: default avatarShreyas Joshi <shreyas.joshi@biamp.com>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Reviewed-by: default avatarAdam Thomson <Adam.Thomson.Opensource@diasemi.com>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
parent a045f357
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
#define DA9062_REG_EVENT_B_OFFSET 1 #define DA9062_REG_EVENT_B_OFFSET 1
#define DA9062_REG_EVENT_C_OFFSET 2 #define DA9062_REG_EVENT_C_OFFSET 2
#define DA9062_IRQ_LOW 0
#define DA9062_IRQ_HIGH 1
static struct regmap_irq da9061_irqs[] = { static struct regmap_irq da9061_irqs[] = {
/* EVENT A */ /* EVENT A */
[DA9061_IRQ_ONKEY] = { [DA9061_IRQ_ONKEY] = {
...@@ -369,6 +372,33 @@ static int da9062_get_device_type(struct da9062 *chip) ...@@ -369,6 +372,33 @@ static int da9062_get_device_type(struct da9062 *chip)
return ret; return ret;
} }
static u32 da9062_configure_irq_type(struct da9062 *chip, int irq, u32 *trigger)
{
u32 irq_type = 0;
struct irq_data *irq_data = irq_get_irq_data(irq);
if (!irq_data) {
dev_err(chip->dev, "Invalid IRQ: %d\n", irq);
return -EINVAL;
}
*trigger = irqd_get_trigger_type(irq_data);
switch (*trigger) {
case IRQ_TYPE_LEVEL_HIGH:
irq_type = DA9062_IRQ_HIGH;
break;
case IRQ_TYPE_LEVEL_LOW:
irq_type = DA9062_IRQ_LOW;
break;
default:
dev_warn(chip->dev, "Unsupported IRQ type: %d\n", *trigger);
return -EINVAL;
}
return regmap_update_bits(chip->regmap, DA9062AA_CONFIG_A,
DA9062AA_IRQ_TYPE_MASK,
irq_type << DA9062AA_IRQ_TYPE_SHIFT);
}
static const struct regmap_range da9061_aa_readable_ranges[] = { static const struct regmap_range da9061_aa_readable_ranges[] = {
regmap_reg_range(DA9062AA_PAGE_CON, DA9062AA_STATUS_B), regmap_reg_range(DA9062AA_PAGE_CON, DA9062AA_STATUS_B),
regmap_reg_range(DA9062AA_STATUS_D, DA9062AA_EVENT_C), regmap_reg_range(DA9062AA_STATUS_D, DA9062AA_EVENT_C),
...@@ -388,6 +418,7 @@ static const struct regmap_range da9061_aa_readable_ranges[] = { ...@@ -388,6 +418,7 @@ static const struct regmap_range da9061_aa_readable_ranges[] = {
regmap_reg_range(DA9062AA_VBUCK1_A, DA9062AA_VBUCK4_A), regmap_reg_range(DA9062AA_VBUCK1_A, DA9062AA_VBUCK4_A),
regmap_reg_range(DA9062AA_VBUCK3_A, DA9062AA_VBUCK3_A), regmap_reg_range(DA9062AA_VBUCK3_A, DA9062AA_VBUCK3_A),
regmap_reg_range(DA9062AA_VLDO1_A, DA9062AA_VLDO4_A), regmap_reg_range(DA9062AA_VLDO1_A, DA9062AA_VLDO4_A),
regmap_reg_range(DA9062AA_CONFIG_A, DA9062AA_CONFIG_A),
regmap_reg_range(DA9062AA_VBUCK1_B, DA9062AA_VBUCK4_B), regmap_reg_range(DA9062AA_VBUCK1_B, DA9062AA_VBUCK4_B),
regmap_reg_range(DA9062AA_VBUCK3_B, DA9062AA_VBUCK3_B), regmap_reg_range(DA9062AA_VBUCK3_B, DA9062AA_VBUCK3_B),
regmap_reg_range(DA9062AA_VLDO1_B, DA9062AA_VLDO4_B), regmap_reg_range(DA9062AA_VLDO1_B, DA9062AA_VLDO4_B),
...@@ -417,6 +448,7 @@ static const struct regmap_range da9061_aa_writeable_ranges[] = { ...@@ -417,6 +448,7 @@ static const struct regmap_range da9061_aa_writeable_ranges[] = {
regmap_reg_range(DA9062AA_VBUCK1_A, DA9062AA_VBUCK4_A), regmap_reg_range(DA9062AA_VBUCK1_A, DA9062AA_VBUCK4_A),
regmap_reg_range(DA9062AA_VBUCK3_A, DA9062AA_VBUCK3_A), regmap_reg_range(DA9062AA_VBUCK3_A, DA9062AA_VBUCK3_A),
regmap_reg_range(DA9062AA_VLDO1_A, DA9062AA_VLDO4_A), regmap_reg_range(DA9062AA_VLDO1_A, DA9062AA_VLDO4_A),
regmap_reg_range(DA9062AA_CONFIG_A, DA9062AA_CONFIG_A),
regmap_reg_range(DA9062AA_VBUCK1_B, DA9062AA_VBUCK4_B), regmap_reg_range(DA9062AA_VBUCK1_B, DA9062AA_VBUCK4_B),
regmap_reg_range(DA9062AA_VBUCK3_B, DA9062AA_VBUCK3_B), regmap_reg_range(DA9062AA_VBUCK3_B, DA9062AA_VBUCK3_B),
regmap_reg_range(DA9062AA_VLDO1_B, DA9062AA_VLDO4_B), regmap_reg_range(DA9062AA_VLDO1_B, DA9062AA_VLDO4_B),
...@@ -596,6 +628,7 @@ static int da9062_i2c_probe(struct i2c_client *i2c, ...@@ -596,6 +628,7 @@ static int da9062_i2c_probe(struct i2c_client *i2c,
const struct regmap_irq_chip *irq_chip; const struct regmap_irq_chip *irq_chip;
const struct regmap_config *config; const struct regmap_config *config;
int cell_num; int cell_num;
u32 trigger_type = 0;
int ret; int ret;
chip = devm_kzalloc(&i2c->dev, sizeof(*chip), GFP_KERNEL); chip = devm_kzalloc(&i2c->dev, sizeof(*chip), GFP_KERNEL);
...@@ -654,10 +687,15 @@ static int da9062_i2c_probe(struct i2c_client *i2c, ...@@ -654,10 +687,15 @@ static int da9062_i2c_probe(struct i2c_client *i2c,
if (ret) if (ret)
return ret; return ret;
ret = da9062_configure_irq_type(chip, i2c->irq, &trigger_type);
if (ret < 0) {
dev_err(chip->dev, "Failed to configure IRQ type\n");
return ret;
}
ret = regmap_add_irq_chip(chip->regmap, i2c->irq, ret = regmap_add_irq_chip(chip->regmap, i2c->irq,
IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED, trigger_type | IRQF_SHARED | IRQF_ONESHOT,
-1, irq_chip, -1, irq_chip, &chip->regmap_irq);
&chip->regmap_irq);
if (ret) { if (ret) {
dev_err(chip->dev, "Failed to request IRQ %d: %d\n", dev_err(chip->dev, "Failed to request IRQ %d: %d\n",
i2c->irq, ret); i2c->irq, ret);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment