summaryrefslogtreecommitdiff
path: root/drivers/gpio/gpio-max77620.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpio/gpio-max77620.c')
-rw-r--r--drivers/gpio/gpio-max77620.c71
1 files changed, 50 insertions, 21 deletions
diff --git a/drivers/gpio/gpio-max77620.c b/drivers/gpio/gpio-max77620.c
index 313bd02dd893..7c0a9ef0b500 100644
--- a/drivers/gpio/gpio-max77620.c
+++ b/drivers/gpio/gpio-max77620.c
@@ -19,8 +19,8 @@ struct max77620_gpio {
struct regmap *rmap;
struct device *dev;
struct mutex buslock; /* irq_bus_lock */
- unsigned int irq_type[8];
- bool irq_enabled[8];
+ unsigned int irq_type[MAX77620_GPIO_NR];
+ bool irq_enabled[MAX77620_GPIO_NR];
};
static irqreturn_t max77620_gpio_irqhandler(int irq, void *data)
@@ -38,7 +38,7 @@ static irqreturn_t max77620_gpio_irqhandler(int irq, void *data)
pending = value;
- for_each_set_bit(offset, &pending, 8) {
+ for_each_set_bit(offset, &pending, MAX77620_GPIO_NR) {
unsigned int virq;
virq = irq_find_mapping(gpio->gpio_chip.irq.domain, offset);
@@ -260,26 +260,54 @@ static int max77620_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
return -ENOTSUPP;
}
+static int max77620_gpio_irq_init_hw(struct gpio_chip *gc)
+{
+ struct max77620_gpio *gpio = gpiochip_get_data(gc);
+ unsigned int i;
+ int err;
+
+ /*
+ * GPIO interrupts may be left ON after bootloader, hence let's
+ * pre-initialize hardware to the expected state by disabling all
+ * the interrupts.
+ */
+ for (i = 0; i < MAX77620_GPIO_NR; i++) {
+ err = regmap_update_bits(gpio->rmap, GPIO_REG_ADDR(i),
+ MAX77620_CNFG_GPIO_INT_MASK, 0);
+ if (err < 0) {
+ dev_err(gpio->dev,
+ "failed to disable interrupt: %d\n", err);
+ return err;
+ }
+ }
+
+ return 0;
+}
+
static int max77620_gpio_probe(struct platform_device *pdev)
{
struct max77620_chip *chip = dev_get_drvdata(pdev->dev.parent);
struct max77620_gpio *mgpio;
- int gpio_irq;
+ struct gpio_irq_chip *girq;
+ unsigned int gpio_irq;
int ret;
- gpio_irq = platform_get_irq(pdev, 0);
- if (gpio_irq <= 0)
- return -ENODEV;
+ ret = platform_get_irq(pdev, 0);
+ if (ret < 0)
+ return ret;
+
+ gpio_irq = ret;
mgpio = devm_kzalloc(&pdev->dev, sizeof(*mgpio), GFP_KERNEL);
if (!mgpio)
return -ENOMEM;
+ mutex_init(&mgpio->buslock);
mgpio->rmap = chip->rmap;
mgpio->dev = &pdev->dev;
mgpio->gpio_chip.label = pdev->name;
- mgpio->gpio_chip.parent = &pdev->dev;
+ mgpio->gpio_chip.parent = pdev->dev.parent;
mgpio->gpio_chip.direction_input = max77620_gpio_dir_input;
mgpio->gpio_chip.get = max77620_gpio_get;
mgpio->gpio_chip.direction_output = max77620_gpio_dir_output;
@@ -288,9 +316,17 @@ static int max77620_gpio_probe(struct platform_device *pdev)
mgpio->gpio_chip.ngpio = MAX77620_GPIO_NR;
mgpio->gpio_chip.can_sleep = 1;
mgpio->gpio_chip.base = -1;
-#ifdef CONFIG_OF_GPIO
- mgpio->gpio_chip.of_node = pdev->dev.parent->of_node;
-#endif
+
+ girq = &mgpio->gpio_chip.irq;
+ girq->chip = &max77620_gpio_irqchip;
+ /* This will let us handle the parent IRQ in the driver */
+ girq->parent_handler = NULL;
+ girq->num_parents = 0;
+ girq->parents = NULL;
+ girq->default_type = IRQ_TYPE_NONE;
+ girq->handler = handle_edge_irq;
+ girq->init_hw = max77620_gpio_irq_init_hw,
+ girq->threaded = true;
platform_set_drvdata(pdev, mgpio);
@@ -300,21 +336,14 @@ static int max77620_gpio_probe(struct platform_device *pdev)
return ret;
}
- mutex_init(&mgpio->buslock);
-
- gpiochip_irqchip_add_nested(&mgpio->gpio_chip, &max77620_gpio_irqchip,
- 0, handle_edge_irq, IRQ_TYPE_NONE);
-
- ret = request_threaded_irq(gpio_irq, NULL, max77620_gpio_irqhandler,
- IRQF_ONESHOT, "max77620-gpio", mgpio);
+ ret = devm_request_threaded_irq(&pdev->dev, gpio_irq, NULL,
+ max77620_gpio_irqhandler, IRQF_ONESHOT,
+ "max77620-gpio", mgpio);
if (ret < 0) {
dev_err(&pdev->dev, "failed to request IRQ: %d\n", ret);
return ret;
}
- gpiochip_set_nested_irqchip(&mgpio->gpio_chip, &max77620_gpio_irqchip,
- gpio_irq);
-
return 0;
}