Linux-GPIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] gpio: ws16c48: Use irqchip template
@ 2020-07-22 10:19 Linus Walleij
  2020-07-22 17:18 ` William Breathitt Gray
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Walleij @ 2020-07-22 10:19 UTC (permalink / raw)
  To: linux-gpio; +Cc: Bartosz Golaszewski, Linus Walleij, William Breathitt Gray

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-ws16c48.c | 39 ++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c
index cb510df2b014..2d89d0529135 100644
--- a/drivers/gpio/gpio-ws16c48.c
+++ b/drivers/gpio/gpio-ws16c48.c
@@ -365,10 +365,25 @@ static const char *ws16c48_names[WS16C48_NGPIO] = {
 	"Port 5 Bit 4", "Port 5 Bit 5", "Port 5 Bit 6", "Port 5 Bit 7"
 };
 
+static int ws16c48_irq_init_hw(struct gpio_chip *gc)
+{
+	struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(gc);
+
+	/* Disable IRQ by default */
+	outb(0x80, ws16c48gpio->base + 7);
+	outb(0, ws16c48gpio->base + 8);
+	outb(0, ws16c48gpio->base + 9);
+	outb(0, ws16c48gpio->base + 10);
+	outb(0xC0, ws16c48gpio->base + 7);
+
+	return 0;
+}
+
 static int ws16c48_probe(struct device *dev, unsigned int id)
 {
 	struct ws16c48_gpio *ws16c48gpio;
 	const char *const name = dev_name(dev);
+	struct gpio_irq_chip *girq;
 	int err;
 
 	ws16c48gpio = devm_kzalloc(dev, sizeof(*ws16c48gpio), GFP_KERNEL);
@@ -396,6 +411,16 @@ static int ws16c48_probe(struct device *dev, unsigned int id)
 	ws16c48gpio->chip.set_multiple = ws16c48_gpio_set_multiple;
 	ws16c48gpio->base = base[id];
 
+	girq = &ws16c48gpio->chip.irq;
+	girq->chip = &ws16c48_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 = ws16c48_irq_init_hw;
+
 	raw_spin_lock_init(&ws16c48gpio->lock);
 
 	err = devm_gpiochip_add_data(dev, &ws16c48gpio->chip, ws16c48gpio);
@@ -404,20 +429,6 @@ static int ws16c48_probe(struct device *dev, unsigned int id)
 		return err;
 	}
 
-	/* Disable IRQ by default */
-	outb(0x80, base[id] + 7);
-	outb(0, base[id] + 8);
-	outb(0, base[id] + 9);
-	outb(0, base[id] + 10);
-	outb(0xC0, base[id] + 7);
-
-	err = gpiochip_irqchip_add(&ws16c48gpio->chip, &ws16c48_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, irq[id], ws16c48_irq_handler, IRQF_SHARED,
 		name, ws16c48gpio);
 	if (err) {
-- 
2.26.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] gpio: ws16c48: Use irqchip template
  2020-07-22 10:19 [PATCH] gpio: ws16c48: Use irqchip template Linus Walleij
@ 2020-07-22 17:18 ` William Breathitt Gray
  0 siblings, 0 replies; 2+ messages in thread
From: William Breathitt Gray @ 2020-07-22 17:18 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, Bartosz Golaszewski


[-- Attachment #1: Type: text/plain, Size: 3026 bytes --]

On Wed, Jul 22, 2020 at 12:19:38PM +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-ws16c48.c | 39 ++++++++++++++++++++++++-------------
>  1 file changed, 25 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c
> index cb510df2b014..2d89d0529135 100644
> --- a/drivers/gpio/gpio-ws16c48.c
> +++ b/drivers/gpio/gpio-ws16c48.c
> @@ -365,10 +365,25 @@ static const char *ws16c48_names[WS16C48_NGPIO] = {
>  	"Port 5 Bit 4", "Port 5 Bit 5", "Port 5 Bit 6", "Port 5 Bit 7"
>  };
>  
> +static int ws16c48_irq_init_hw(struct gpio_chip *gc)
> +{
> +	struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(gc);
> +
> +	/* Disable IRQ by default */
> +	outb(0x80, ws16c48gpio->base + 7);
> +	outb(0, ws16c48gpio->base + 8);
> +	outb(0, ws16c48gpio->base + 9);
> +	outb(0, ws16c48gpio->base + 10);
> +	outb(0xC0, ws16c48gpio->base + 7);
> +
> +	return 0;
> +}
> +
>  static int ws16c48_probe(struct device *dev, unsigned int id)
>  {
>  	struct ws16c48_gpio *ws16c48gpio;
>  	const char *const name = dev_name(dev);
> +	struct gpio_irq_chip *girq;
>  	int err;
>  
>  	ws16c48gpio = devm_kzalloc(dev, sizeof(*ws16c48gpio), GFP_KERNEL);
> @@ -396,6 +411,16 @@ static int ws16c48_probe(struct device *dev, unsigned int id)
>  	ws16c48gpio->chip.set_multiple = ws16c48_gpio_set_multiple;
>  	ws16c48gpio->base = base[id];
>  
> +	girq = &ws16c48gpio->chip.irq;
> +	girq->chip = &ws16c48_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 = ws16c48_irq_init_hw;
> +
>  	raw_spin_lock_init(&ws16c48gpio->lock);
>  
>  	err = devm_gpiochip_add_data(dev, &ws16c48gpio->chip, ws16c48gpio);
> @@ -404,20 +429,6 @@ static int ws16c48_probe(struct device *dev, unsigned int id)
>  		return err;
>  	}
>  
> -	/* Disable IRQ by default */
> -	outb(0x80, base[id] + 7);
> -	outb(0, base[id] + 8);
> -	outb(0, base[id] + 9);
> -	outb(0, base[id] + 10);
> -	outb(0xC0, base[id] + 7);
> -
> -	err = gpiochip_irqchip_add(&ws16c48gpio->chip, &ws16c48_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, irq[id], ws16c48_irq_handler, IRQF_SHARED,
>  		name, ws16c48gpio);
>  	if (err) {
> -- 
> 2.26.2
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-22 10:19 [PATCH] gpio: ws16c48: Use irqchip template Linus Walleij
2020-07-22 17:18 ` William Breathitt Gray

Linux-GPIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-gpio/0 linux-gpio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-gpio linux-gpio/ https://lore.kernel.org/linux-gpio \
		linux-gpio@vger.kernel.org
	public-inbox-index linux-gpio

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-gpio


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git