[v2,1/1] gpio: vf610: make irq_chip immutable

Message ID 20230214125949.3462396-1-alexander.stein@ew.tq-group.com
State New
Headers
Series [v2,1/1] gpio: vf610: make irq_chip immutable |

Commit Message

Alexander Stein Feb. 14, 2023, 12:59 p.m. UTC
  Since recently, the kernel is nagging about mutable irq_chips:

    "not an immutable chip, please consider fixing it!"

Drop the unneeded copy, flag it as IRQCHIP_IMMUTABLE, add the new
helper functions and call the appropriate gpiolib functions.

Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
---
Thanks Andy for the feedback!

Changes in v2:
* Add missing calls to gpiochip_disable_irq() and gpiochip_enable_irq()

 drivers/gpio/gpio-vf610.c | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)
  

Comments

Andy Shevchenko Feb. 14, 2023, 4:45 p.m. UTC | #1
On Tue, Feb 14, 2023 at 2:59 PM Alexander Stein
<alexander.stein@ew.tq-group.com> wrote:
>
> Since recently, the kernel is nagging about mutable irq_chips:
>
>     "not an immutable chip, please consider fixing it!"
>
> Drop the unneeded copy, flag it as IRQCHIP_IMMUTABLE, add the new
> helper functions and call the appropriate gpiolib functions.

Thanks for an update, something to amend below, otherwise
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
> ---
> Thanks Andy for the feedback!
>
> Changes in v2:
> * Add missing calls to gpiochip_disable_irq() and gpiochip_enable_irq()
>
>  drivers/gpio/gpio-vf610.c | 35 ++++++++++++++++++++---------------
>  1 file changed, 20 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
> index a429176673e7..b657a07a9b56 100644
> --- a/drivers/gpio/gpio-vf610.c
> +++ b/drivers/gpio/gpio-vf610.c
> @@ -30,7 +30,6 @@ struct fsl_gpio_soc_data {
>
>  struct vf610_gpio_port {
>         struct gpio_chip gc;
> -       struct irq_chip ic;
>         void __iomem *base;
>         void __iomem *gpio_base;
>         const struct fsl_gpio_soc_data *sdata;
> @@ -207,19 +206,23 @@ static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type)
>
>  static void vf610_gpio_irq_mask(struct irq_data *d)
>  {
> -       struct vf610_gpio_port *port =
> -               gpiochip_get_data(irq_data_get_irq_chip_data(d));
> +       struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
> +       struct vf610_gpio_port *port = gpiochip_get_data(gc);
>         void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq);

Now you can use gpio_num here...

> +       irq_hw_number_t gpio_num = irqd_to_hwirq(d);
>
>         vf610_gpio_writel(0, pcr_base);
> +       gpiochip_disable_irq(gc, gpio_num);
>  }
>
>  static void vf610_gpio_irq_unmask(struct irq_data *d)
>  {
> -       struct vf610_gpio_port *port =
> -               gpiochip_get_data(irq_data_get_irq_chip_data(d));
> +       struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
> +       struct vf610_gpio_port *port = gpiochip_get_data(gc);
>         void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq);
> +       irq_hw_number_t gpio_num = irqd_to_hwirq(d);
>
> +       gpiochip_enable_irq(gc, gpio_num);
>         vf610_gpio_writel(port->irqc[d->hwirq] << PORT_PCR_IRQC_OFFSET,

...and here.


>                           pcr_base);
>  }
> @@ -237,6 +240,17 @@ static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable)
>         return 0;
>  }
>
> +static const struct irq_chip vf610_irqchip = {
> +       .name = "gpio-vf610",
> +       .irq_ack = vf610_gpio_irq_ack,
> +       .irq_mask = vf610_gpio_irq_mask,
> +       .irq_unmask = vf610_gpio_irq_unmask,
> +       .irq_set_type = vf610_gpio_irq_set_type,
> +       .irq_set_wake = vf610_gpio_irq_set_wake,
> +       .flags = IRQCHIP_IMMUTABLE,
> +       GPIOCHIP_IRQ_RESOURCE_HELPERS,
> +};
> +
>  static void vf610_gpio_disable_clk(void *data)
>  {
>         clk_disable_unprepare(data);
> @@ -249,7 +263,6 @@ static int vf610_gpio_probe(struct platform_device *pdev)
>         struct vf610_gpio_port *port;
>         struct gpio_chip *gc;
>         struct gpio_irq_chip *girq;
> -       struct irq_chip *ic;
>         int i;
>         int ret;
>
> @@ -315,14 +328,6 @@ static int vf610_gpio_probe(struct platform_device *pdev)
>         gc->direction_output = vf610_gpio_direction_output;
>         gc->set = vf610_gpio_set;
>
> -       ic = &port->ic;
> -       ic->name = "gpio-vf610";
> -       ic->irq_ack = vf610_gpio_irq_ack;
> -       ic->irq_mask = vf610_gpio_irq_mask;
> -       ic->irq_unmask = vf610_gpio_irq_unmask;
> -       ic->irq_set_type = vf610_gpio_irq_set_type;
> -       ic->irq_set_wake = vf610_gpio_irq_set_wake;
> -
>         /* Mask all GPIO interrupts */
>         for (i = 0; i < gc->ngpio; i++)
>                 vf610_gpio_writel(0, port->base + PORT_PCR(i));
> @@ -331,7 +336,7 @@ static int vf610_gpio_probe(struct platform_device *pdev)
>         vf610_gpio_writel(~0, port->base + PORT_ISFR);
>
>         girq = &gc->irq;
> -       girq->chip = ic;
> +       gpio_irq_chip_set_chip(girq, &vf610_irqchip);
>         girq->parent_handler = vf610_gpio_irq_handler;
>         girq->num_parents = 1;
>         girq->parents = devm_kcalloc(&pdev->dev, 1,
> --
> 2.34.1
>
  
Andy Shevchenko Feb. 14, 2023, 4:48 p.m. UTC | #2
On Tue, Feb 14, 2023 at 6:45 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Tue, Feb 14, 2023 at 2:59 PM Alexander Stein
> <alexander.stein@ew.tq-group.com> wrote:

...

> >         void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq);
>
> Now you can use gpio_num here...
>
> > +       irq_hw_number_t gpio_num = irqd_to_hwirq(d);

...

> >  static void vf610_gpio_irq_unmask(struct irq_data *d)
> >  {
> > -       struct vf610_gpio_port *port =
> > -               gpiochip_get_data(irq_data_get_irq_chip_data(d));
> > +       struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
> > +       struct vf610_gpio_port *port = gpiochip_get_data(gc);
> >         void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq);

And here.

> > +       irq_hw_number_t gpio_num = irqd_to_hwirq(d);
> >
> > +       gpiochip_enable_irq(gc, gpio_num);
> >         vf610_gpio_writel(port->irqc[d->hwirq] << PORT_PCR_IRQC_OFFSET,
>
> ...and here.
>
> >                           pcr_base);
> >  }
  

Patch

diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index a429176673e7..b657a07a9b56 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -30,7 +30,6 @@  struct fsl_gpio_soc_data {
 
 struct vf610_gpio_port {
 	struct gpio_chip gc;
-	struct irq_chip ic;
 	void __iomem *base;
 	void __iomem *gpio_base;
 	const struct fsl_gpio_soc_data *sdata;
@@ -207,19 +206,23 @@  static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type)
 
 static void vf610_gpio_irq_mask(struct irq_data *d)
 {
-	struct vf610_gpio_port *port =
-		gpiochip_get_data(irq_data_get_irq_chip_data(d));
+	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+	struct vf610_gpio_port *port = gpiochip_get_data(gc);
 	void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq);
+	irq_hw_number_t gpio_num = irqd_to_hwirq(d);
 
 	vf610_gpio_writel(0, pcr_base);
+	gpiochip_disable_irq(gc, gpio_num);
 }
 
 static void vf610_gpio_irq_unmask(struct irq_data *d)
 {
-	struct vf610_gpio_port *port =
-		gpiochip_get_data(irq_data_get_irq_chip_data(d));
+	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+	struct vf610_gpio_port *port = gpiochip_get_data(gc);
 	void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq);
+	irq_hw_number_t gpio_num = irqd_to_hwirq(d);
 
+	gpiochip_enable_irq(gc, gpio_num);
 	vf610_gpio_writel(port->irqc[d->hwirq] << PORT_PCR_IRQC_OFFSET,
 			  pcr_base);
 }
@@ -237,6 +240,17 @@  static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable)
 	return 0;
 }
 
+static const struct irq_chip vf610_irqchip = {
+	.name = "gpio-vf610",
+	.irq_ack = vf610_gpio_irq_ack,
+	.irq_mask = vf610_gpio_irq_mask,
+	.irq_unmask = vf610_gpio_irq_unmask,
+	.irq_set_type = vf610_gpio_irq_set_type,
+	.irq_set_wake = vf610_gpio_irq_set_wake,
+	.flags = IRQCHIP_IMMUTABLE,
+	GPIOCHIP_IRQ_RESOURCE_HELPERS,
+};
+
 static void vf610_gpio_disable_clk(void *data)
 {
 	clk_disable_unprepare(data);
@@ -249,7 +263,6 @@  static int vf610_gpio_probe(struct platform_device *pdev)
 	struct vf610_gpio_port *port;
 	struct gpio_chip *gc;
 	struct gpio_irq_chip *girq;
-	struct irq_chip *ic;
 	int i;
 	int ret;
 
@@ -315,14 +328,6 @@  static int vf610_gpio_probe(struct platform_device *pdev)
 	gc->direction_output = vf610_gpio_direction_output;
 	gc->set = vf610_gpio_set;
 
-	ic = &port->ic;
-	ic->name = "gpio-vf610";
-	ic->irq_ack = vf610_gpio_irq_ack;
-	ic->irq_mask = vf610_gpio_irq_mask;
-	ic->irq_unmask = vf610_gpio_irq_unmask;
-	ic->irq_set_type = vf610_gpio_irq_set_type;
-	ic->irq_set_wake = vf610_gpio_irq_set_wake;
-
 	/* Mask all GPIO interrupts */
 	for (i = 0; i < gc->ngpio; i++)
 		vf610_gpio_writel(0, port->base + PORT_PCR(i));
@@ -331,7 +336,7 @@  static int vf610_gpio_probe(struct platform_device *pdev)
 	vf610_gpio_writel(~0, port->base + PORT_ISFR);
 
 	girq = &gc->irq;
-	girq->chip = ic;
+	gpio_irq_chip_set_chip(girq, &vf610_irqchip);
 	girq->parent_handler = vf610_gpio_irq_handler;
 	girq->num_parents = 1;
 	girq->parents = devm_kcalloc(&pdev->dev, 1,