diff mbox series

gpio: 104-dio-48e: Use irqchip template

Message ID 20200722103915.162156-1-linus.walleij@linaro.org
State Accepted
Commit 2fa1d392cdf49d9785f2fc67acca3c8db9a99036
Headers show
Series gpio: 104-dio-48e: Use irqchip template | expand

Commit Message

Linus Walleij July 22, 2020, 10:39 a.m. UTC
This makes the driver use the irqchip template to assign
properties to the gpio_irq_chip instead of using the
explicit call to gpiochip_irqchip_add().

The irqchip is instead added while adding the gpiochip.
Also move the IRQ initialization to the special .init_hw()
callback.

Cc: William Breathitt Gray <vilhelm.gray@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

---
 drivers/gpio/gpio-104-dio-48e.c | 35 ++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 12 deletions(-)

-- 
2.26.2

Comments

William Breathitt Gray July 22, 2020, 5:22 p.m. UTC | #1
On Wed, Jul 22, 2020 at 12:39:15PM +0200, Linus Walleij wrote:
> This makes the driver use the irqchip template to assign

> properties to the gpio_irq_chip instead of using the

> explicit call to gpiochip_irqchip_add().

> 

> The irqchip is instead added while adding the gpiochip.

> Also move the IRQ initialization to the special .init_hw()

> callback.

> 

> Cc: William Breathitt Gray <vilhelm.gray@gmail.com>

> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>


> ---

>  drivers/gpio/gpio-104-dio-48e.c | 35 ++++++++++++++++++++++-----------

>  1 file changed, 23 insertions(+), 12 deletions(-)

> 

> diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c

> index 1f7d9bbec0fc..7a9021c4fa48 100644

> --- a/drivers/gpio/gpio-104-dio-48e.c

> +++ b/drivers/gpio/gpio-104-dio-48e.c

> @@ -368,10 +368,21 @@ static const char *dio48e_names[DIO48E_NGPIO] = {

>  	"PPI Group 1 Port C 5", "PPI Group 1 Port C 6", "PPI Group 1 Port C 7"

>  };

>  

> +static int dio48e_irq_init_hw(struct gpio_chip *gc)

> +{

> +	struct dio48e_gpio *const dio48egpio = gpiochip_get_data(gc);

> +

> +	/* Disable IRQ by default */

> +	inb(dio48egpio->base + 0xB);

> +

> +	return 0;

> +}

> +

>  static int dio48e_probe(struct device *dev, unsigned int id)

>  {

>  	struct dio48e_gpio *dio48egpio;

>  	const char *const name = dev_name(dev);

> +	struct gpio_irq_chip *girq;

>  	int err;

>  

>  	dio48egpio = devm_kzalloc(dev, sizeof(*dio48egpio), GFP_KERNEL);

> @@ -399,13 +410,17 @@ static int dio48e_probe(struct device *dev, unsigned int id)

>  	dio48egpio->chip.set_multiple = dio48e_gpio_set_multiple;

>  	dio48egpio->base = base[id];

>  

> -	raw_spin_lock_init(&dio48egpio->lock);

> +	girq = &dio48egpio->chip.irq;

> +	girq->chip = &dio48e_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 = dio48e_irq_init_hw;

>  

> -	err = devm_gpiochip_add_data(dev, &dio48egpio->chip, dio48egpio);

> -	if (err) {

> -		dev_err(dev, "GPIO registering failed (%d)\n", err);

> -		return err;

> -	}

> +	raw_spin_lock_init(&dio48egpio->lock);

>  

>  	/* initialize all GPIO as output */

>  	outb(0x80, base[id] + 3);

> @@ -419,13 +434,9 @@ static int dio48e_probe(struct device *dev, unsigned int id)

>  	outb(0x00, base[id] + 6);

>  	outb(0x00, base[id] + 7);

>  

> -	/* disable IRQ by default */

> -	inb(base[id] + 0xB);

> -

> -	err = gpiochip_irqchip_add(&dio48egpio->chip, &dio48e_irqchip, 0,

> -		handle_edge_irq, IRQ_TYPE_NONE);

> +	err = devm_gpiochip_add_data(dev, &dio48egpio->chip, dio48egpio);

>  	if (err) {

> -		dev_err(dev, "Could not add irqchip (%d)\n", err);

> +		dev_err(dev, "GPIO registering failed (%d)\n", err);

>  		return err;

>  	}

>  

> -- 

> 2.26.2

>
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c
index 1f7d9bbec0fc..7a9021c4fa48 100644
--- a/drivers/gpio/gpio-104-dio-48e.c
+++ b/drivers/gpio/gpio-104-dio-48e.c
@@ -368,10 +368,21 @@  static const char *dio48e_names[DIO48E_NGPIO] = {
 	"PPI Group 1 Port C 5", "PPI Group 1 Port C 6", "PPI Group 1 Port C 7"
 };
 
+static int dio48e_irq_init_hw(struct gpio_chip *gc)
+{
+	struct dio48e_gpio *const dio48egpio = gpiochip_get_data(gc);
+
+	/* Disable IRQ by default */
+	inb(dio48egpio->base + 0xB);
+
+	return 0;
+}
+
 static int dio48e_probe(struct device *dev, unsigned int id)
 {
 	struct dio48e_gpio *dio48egpio;
 	const char *const name = dev_name(dev);
+	struct gpio_irq_chip *girq;
 	int err;
 
 	dio48egpio = devm_kzalloc(dev, sizeof(*dio48egpio), GFP_KERNEL);
@@ -399,13 +410,17 @@  static int dio48e_probe(struct device *dev, unsigned int id)
 	dio48egpio->chip.set_multiple = dio48e_gpio_set_multiple;
 	dio48egpio->base = base[id];
 
-	raw_spin_lock_init(&dio48egpio->lock);
+	girq = &dio48egpio->chip.irq;
+	girq->chip = &dio48e_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 = dio48e_irq_init_hw;
 
-	err = devm_gpiochip_add_data(dev, &dio48egpio->chip, dio48egpio);
-	if (err) {
-		dev_err(dev, "GPIO registering failed (%d)\n", err);
-		return err;
-	}
+	raw_spin_lock_init(&dio48egpio->lock);
 
 	/* initialize all GPIO as output */
 	outb(0x80, base[id] + 3);
@@ -419,13 +434,9 @@  static int dio48e_probe(struct device *dev, unsigned int id)
 	outb(0x00, base[id] + 6);
 	outb(0x00, base[id] + 7);
 
-	/* disable IRQ by default */
-	inb(base[id] + 0xB);
-
-	err = gpiochip_irqchip_add(&dio48egpio->chip, &dio48e_irqchip, 0,
-		handle_edge_irq, IRQ_TYPE_NONE);
+	err = devm_gpiochip_add_data(dev, &dio48egpio->chip, dio48egpio);
 	if (err) {
-		dev_err(dev, "Could not add irqchip (%d)\n", err);
+		dev_err(dev, "GPIO registering failed (%d)\n", err);
 		return err;
 	}