diff mbox series

gpio: pci-idio-16: Use irqchip template

Message ID 20200722110649.202223-1-linus.walleij@linaro.org
State Accepted
Commit 4530a840e74eface949dc4255b66ad640c0521b9
Headers show
Series gpio: pci-idio-16: Use irqchip template | expand

Commit Message

Linus Walleij July 22, 2020, 11:06 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-pci-idio-16.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

-- 
2.26.2

Comments

William Breathitt Gray July 22, 2020, 5:34 p.m. UTC | #1
On Wed, Jul 22, 2020 at 01:06:49PM +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-pci-idio-16.c | 33 ++++++++++++++++++++++-----------

>  1 file changed, 22 insertions(+), 11 deletions(-)

> 

> diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c

> index 638d6656ce73..9acec76e0b51 100644

> --- a/drivers/gpio/gpio-pci-idio-16.c

> +++ b/drivers/gpio/gpio-pci-idio-16.c

> @@ -280,6 +280,17 @@ static const char *idio_16_names[IDIO_16_NGPIO] = {

>  	"IIN8", "IIN9", "IIN10", "IIN11", "IIN12", "IIN13", "IIN14", "IIN15"

>  };

>  

> +static int idio_16_irq_init_hw(struct gpio_chip *gc)

> +{

> +	struct idio_16_gpio *const idio16gpio = gpiochip_get_data(gc);

> +

> +	/* Disable IRQ by default and clear any pending interrupt */

> +	iowrite8(0, &idio16gpio->reg->irq_ctl);

> +	iowrite8(0, &idio16gpio->reg->in0_7);

> +

> +	return 0;

> +}

> +

>  static int idio_16_probe(struct pci_dev *pdev, const struct pci_device_id *id)

>  {

>  	struct device *const dev = &pdev->dev;

> @@ -287,6 +298,7 @@ static int idio_16_probe(struct pci_dev *pdev, const struct pci_device_id *id)

>  	int err;

>  	const size_t pci_bar_index = 2;

>  	const char *const name = pci_name(pdev);

> +	struct gpio_irq_chip *girq;

>  

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

>  	if (!idio16gpio)

> @@ -323,6 +335,16 @@ static int idio_16_probe(struct pci_dev *pdev, const struct pci_device_id *id)

>  	idio16gpio->chip.set = idio_16_gpio_set;

>  	idio16gpio->chip.set_multiple = idio_16_gpio_set_multiple;

>  

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

> +	girq->chip = &idio_16_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 = idio_16_irq_init_hw;

> +

>  	raw_spin_lock_init(&idio16gpio->lock);

>  

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

> @@ -331,17 +353,6 @@ static int idio_16_probe(struct pci_dev *pdev, const struct pci_device_id *id)

>  		return err;

>  	}

>  

> -	/* Disable IRQ by default and clear any pending interrupt */

> -	iowrite8(0, &idio16gpio->reg->irq_ctl);

> -	iowrite8(0, &idio16gpio->reg->in0_7);

> -

> -	err = gpiochip_irqchip_add(&idio16gpio->chip, &idio_16_irqchip, 0,

> -		handle_edge_irq, IRQ_TYPE_NONE);

> -	if (err) {

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

> -		return err;

> -	}

> -

>  	err = devm_request_irq(dev, pdev->irq, idio_16_irq_handler, IRQF_SHARED,

>  		name, idio16gpio);

>  	if (err) {

> -- 

> 2.26.2

>
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c
index 638d6656ce73..9acec76e0b51 100644
--- a/drivers/gpio/gpio-pci-idio-16.c
+++ b/drivers/gpio/gpio-pci-idio-16.c
@@ -280,6 +280,17 @@  static const char *idio_16_names[IDIO_16_NGPIO] = {
 	"IIN8", "IIN9", "IIN10", "IIN11", "IIN12", "IIN13", "IIN14", "IIN15"
 };
 
+static int idio_16_irq_init_hw(struct gpio_chip *gc)
+{
+	struct idio_16_gpio *const idio16gpio = gpiochip_get_data(gc);
+
+	/* Disable IRQ by default and clear any pending interrupt */
+	iowrite8(0, &idio16gpio->reg->irq_ctl);
+	iowrite8(0, &idio16gpio->reg->in0_7);
+
+	return 0;
+}
+
 static int idio_16_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	struct device *const dev = &pdev->dev;
@@ -287,6 +298,7 @@  static int idio_16_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	int err;
 	const size_t pci_bar_index = 2;
 	const char *const name = pci_name(pdev);
+	struct gpio_irq_chip *girq;
 
 	idio16gpio = devm_kzalloc(dev, sizeof(*idio16gpio), GFP_KERNEL);
 	if (!idio16gpio)
@@ -323,6 +335,16 @@  static int idio_16_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	idio16gpio->chip.set = idio_16_gpio_set;
 	idio16gpio->chip.set_multiple = idio_16_gpio_set_multiple;
 
+	girq = &idio16gpio->chip.irq;
+	girq->chip = &idio_16_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 = idio_16_irq_init_hw;
+
 	raw_spin_lock_init(&idio16gpio->lock);
 
 	err = devm_gpiochip_add_data(dev, &idio16gpio->chip, idio16gpio);
@@ -331,17 +353,6 @@  static int idio_16_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		return err;
 	}
 
-	/* Disable IRQ by default and clear any pending interrupt */
-	iowrite8(0, &idio16gpio->reg->irq_ctl);
-	iowrite8(0, &idio16gpio->reg->in0_7);
-
-	err = gpiochip_irqchip_add(&idio16gpio->chip, &idio_16_irqchip, 0,
-		handle_edge_irq, IRQ_TYPE_NONE);
-	if (err) {
-		dev_err(dev, "Could not add irqchip (%d)\n", err);
-		return err;
-	}
-
 	err = devm_request_irq(dev, pdev->irq, idio_16_irq_handler, IRQF_SHARED,
 		name, idio16gpio);
 	if (err) {