diff mbox series

[v2,2/3] i2c: sh_mobile: Use platform_get_irq_optional() to get the interrupt

Message ID 20211221175322.7096-3-prabhakar.mahadev-lad.rj@bp.renesas.com
State Accepted
Commit aab799e44ce3953ac56c42721742c9cd9208b2f4
Headers show
Series i2c/busses: Use platform_get_irq/_optional() variants to fetch IRQ's | expand

Commit Message

Prabhakar Mahadev Lad Dec. 21, 2021, 5:53 p.m. UTC
platform_get_resource(pdev, IORESOURCE_IRQ, ..) relies on static
allocation of IRQ resources in DT core code, this causes an issue
when using hierarchical interrupt domains using "interrupts" property
in the node as this bypasses the hierarchical setup and messes up the
irq chaining.

In preparation for removal of static setup of IRQ resource from DT core
code use platform_get_irq_optional() for DT users only.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
v1->v2
* Dropped IRQ0 check
* Simplified code
---
 drivers/i2c/busses/i2c-sh_mobile.c | 34 +++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 8 deletions(-)

Comments

Geert Uytterhoeven Dec. 22, 2021, 9:20 a.m. UTC | #1
On Tue, Dec 21, 2021 at 7:21 PM Lad Prabhakar
<prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> platform_get_resource(pdev, IORESOURCE_IRQ, ..) relies on static
> allocation of IRQ resources in DT core code, this causes an issue
> when using hierarchical interrupt domains using "interrupts" property
> in the node as this bypasses the hierarchical setup and messes up the
> irq chaining.
>
> In preparation for removal of static setup of IRQ resource from DT core
> code use platform_get_irq_optional() for DT users only.
>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Wolfram Sang Dec. 22, 2021, 9:49 a.m. UTC | #2
On Tue, Dec 21, 2021 at 05:53:21PM +0000, Lad Prabhakar wrote:
> platform_get_resource(pdev, IORESOURCE_IRQ, ..) relies on static
> allocation of IRQ resources in DT core code, this causes an issue
> when using hierarchical interrupt domains using "interrupts" property
> in the node as this bypasses the hierarchical setup and messes up the
> irq chaining.
> 
> In preparation for removal of static setup of IRQ resource from DT core
> code use platform_get_irq_optional() for DT users only.
> 
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Tested on a Renesas R-Car Gen3 SoC (M3-W) and IIC port still works and
no false positive printouts in the kernel log:

Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Andy Shevchenko Dec. 25, 2021, 5:48 p.m. UTC | #3
On Wed, Dec 22, 2021 at 2:41 PM Lad Prabhakar
<prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
>
> platform_get_resource(pdev, IORESOURCE_IRQ, ..) relies on static
> allocation of IRQ resources in DT core code, this causes an issue
> when using hierarchical interrupt domains using "interrupts" property
> in the node as this bypasses the hierarchical setup and messes up the
> irq chaining.
>
> In preparation for removal of static setup of IRQ resource from DT core
> code use platform_get_irq_optional() for DT users only.

...

> +       if (np) {

Same comments as per your other patches, i.e.
Why is this check here?

> +               int irq;
> +
> +               while ((irq = platform_get_irq_optional(dev, k)) != -ENXIO) {

Consider 0 as no IRQ.

> +                       if (irq < 0)
> +                               return irq;
> +                       ret = devm_request_irq(&dev->dev, irq, sh_mobile_i2c_isr,
> +                                              0, dev_name(&dev->dev), pd);
>                         if (ret) {
> -                               dev_err(&dev->dev, "cannot request IRQ %pa\n", &n);
> +                               dev_err(&dev->dev, "cannot request IRQ %d\n", irq);
>                                 return ret;
>                         }
> +                       k++;
> +               };
> +       } else {
> +               struct resource *res;
> +               resource_size_t n;
> +
> +               while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) {
> +                       for (n = res->start; n <= res->end; n++) {
> +                               ret = devm_request_irq(&dev->dev, n, sh_mobile_i2c_isr,
> +                                                      0, dev_name(&dev->dev), pd);
> +                               if (ret) {
> +                                       dev_err(&dev->dev, "cannot request IRQ %pa\n", &n);
> +                                       return ret;
> +                               }
> +                       }
> +                       k++;
>                 }
> -               k++;
>         }
Prabhakar Mahadev Lad Dec. 25, 2021, 11:45 p.m. UTC | #4
Hi Andy,

Thank you for the review.

> -----Original Message-----
> From: Andy Shevchenko <andy.shevchenko@gmail.com>
> Sent: 25 December 2021 17:49
> To: Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>
> Cc: Florian Fainelli <f.fainelli@gmail.com>; Ray Jui <rjui@broadcom.com>; Scott Branden
> <sbranden@broadcom.com>; bcm-kernel-feedback-list <bcm-kernel-feedback-list@broadcom.com>; Nicolas
> Saenz Julienne <nsaenz@kernel.org>; Chris Brandt <Chris.Brandt@renesas.com>; Wolfram Sang
> <wsa+renesas@sang-engineering.com>; linux-i2c <linux-i2c@vger.kernel.org>; linux-rpi-kernel <linux-
> rpi-kernel@lists.infradead.org>; linux-arm Mailing List <linux-arm-kernel@lists.infradead.org>; Linux-
> Renesas <linux-renesas-soc@vger.kernel.org>; Linux Kernel Mailing List <linux-kernel@vger.kernel.org>;
> Prabhakarprabhakar.csengg@gmail.com
> Subject: Re: [PATCH v2 2/3] i2c: sh_mobile: Use platform_get_irq_optional() to get the interrupt
> 
> On Wed, Dec 22, 2021 at 2:41 PM Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> >
> > platform_get_resource(pdev, IORESOURCE_IRQ, ..) relies on static
> > allocation of IRQ resources in DT core code, this causes an issue when
> > using hierarchical interrupt domains using "interrupts" property in
> > the node as this bypasses the hierarchical setup and messes up the irq
> > chaining.
> >
> > In preparation for removal of static setup of IRQ resource from DT
> > core code use platform_get_irq_optional() for DT users only.
> 
> ...
> 
> > +       if (np) {
> 
> Same comments as per your other patches, i.e.
> Why is this check here?
> 
Because the interrupt resource has range of interrupts in one IRQ resource [0]. Let me know if there is any other alternative way to avoid such case.

> > +               int irq;
> > +
> > +               while ((irq = platform_get_irq_optional(dev, k)) !=
> > + -ENXIO) {
> 
> Consider 0 as no IRQ.
> 
OK.

[0] https://elixir.bootlin.com/linux/v5.16-rc6/source/arch/sh/kernel/cpu/sh4a/setup-sh7724.c#L454

Cheers,
Prabhakar

> > +                       if (irq < 0)
> > +                               return irq;
> > +                       ret = devm_request_irq(&dev->dev, irq, sh_mobile_i2c_isr,
> > +                                              0, dev_name(&dev->dev),
> > + pd);
> >                         if (ret) {
> > -                               dev_err(&dev->dev, "cannot request IRQ %pa\n", &n);
> > +                               dev_err(&dev->dev, "cannot request IRQ
> > + %d\n", irq);
> >                                 return ret;
> >                         }
> > +                       k++;
> > +               };
> > +       } else {
> > +               struct resource *res;
> > +               resource_size_t n;
> > +
> > +               while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) {
> > +                       for (n = res->start; n <= res->end; n++) {
> > +                               ret = devm_request_irq(&dev->dev, n, sh_mobile_i2c_isr,
> > +                                                      0, dev_name(&dev->dev), pd);
> > +                               if (ret) {
> > +                                       dev_err(&dev->dev, "cannot request IRQ %pa\n", &n);
> > +                                       return ret;
> > +                               }
> > +                       }
> > +                       k++;
> >                 }
> > -               k++;
> >         }
> 
> --
> With Best Regards,
> Andy Shevchenko
Andy Shevchenko Dec. 26, 2021, 8:40 a.m. UTC | #5
On Sun, Dec 26, 2021 at 1:45 AM Prabhakar Mahadev Lad
<prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> > On Wed, Dec 22, 2021 at 2:41 PM Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:

...

> > > +       if (np) {
> >
> > Same comments as per your other patches, i.e.
> > Why is this check here?
> >
> Because the interrupt resource has range of interrupts in one IRQ resource [0]. Let me know if there is any other alternative way to avoid such case.

Shouldn't be fixed in platform_get_irq_optional() to return IRQ by
index for all cases?

> [0] https://elixir.bootlin.com/linux/v5.16-rc6/source/arch/sh/kernel/cpu/sh4a/setup-sh7724.c#L454
Lad, Prabhakar Dec. 26, 2021, 10:03 a.m. UTC | #6
On Sun, Dec 26, 2021 at 8:41 AM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Sun, Dec 26, 2021 at 1:45 AM Prabhakar Mahadev Lad
> <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> > > On Wed, Dec 22, 2021 at 2:41 PM Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
>
> ...
>
> > > > +       if (np) {
> > >
> > > Same comments as per your other patches, i.e.
> > > Why is this check here?
> > >
> > Because the interrupt resource has range of interrupts in one IRQ resource [0]. Let me know if there is any other alternative way to avoid such case.
>
> Shouldn't be fixed in platform_get_irq_optional() to return IRQ by
> index for all cases?
>
Sorry, I don't get you here. Wasn't your earlier comment for np check?

Cheers,
Prabhakar
Wolfram Sang Jan. 3, 2022, 9:19 a.m. UTC | #7
On Tue, Dec 21, 2021 at 05:53:21PM +0000, Lad Prabhakar wrote:
> platform_get_resource(pdev, IORESOURCE_IRQ, ..) relies on static
> allocation of IRQ resources in DT core code, this causes an issue
> when using hierarchical interrupt domains using "interrupts" property
> in the node as this bypasses the hierarchical setup and messes up the
> irq chaining.
> 
> In preparation for removal of static setup of IRQ resource from DT core
> code use platform_get_irq_optional() for DT users only.
> 
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Applied to for-next, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index 7b8caf172851..9754849dbb23 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -830,20 +830,38 @@  static void sh_mobile_i2c_release_dma(struct sh_mobile_i2c_data *pd)
 
 static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, struct sh_mobile_i2c_data *pd)
 {
-	struct resource *res;
-	resource_size_t n;
+	struct device_node *np = dev_of_node(&dev->dev);
 	int k = 0, ret;
 
-	while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) {
-		for (n = res->start; n <= res->end; n++) {
-			ret = devm_request_irq(&dev->dev, n, sh_mobile_i2c_isr,
-					  0, dev_name(&dev->dev), pd);
+	if (np) {
+		int irq;
+
+		while ((irq = platform_get_irq_optional(dev, k)) != -ENXIO) {
+			if (irq < 0)
+				return irq;
+			ret = devm_request_irq(&dev->dev, irq, sh_mobile_i2c_isr,
+					       0, dev_name(&dev->dev), pd);
 			if (ret) {
-				dev_err(&dev->dev, "cannot request IRQ %pa\n", &n);
+				dev_err(&dev->dev, "cannot request IRQ %d\n", irq);
 				return ret;
 			}
+			k++;
+		};
+	} else {
+		struct resource *res;
+		resource_size_t n;
+
+		while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) {
+			for (n = res->start; n <= res->end; n++) {
+				ret = devm_request_irq(&dev->dev, n, sh_mobile_i2c_isr,
+						       0, dev_name(&dev->dev), pd);
+				if (ret) {
+					dev_err(&dev->dev, "cannot request IRQ %pa\n", &n);
+					return ret;
+				}
+			}
+			k++;
 		}
-		k++;
 	}
 
 	return k > 0 ? 0 : -ENOENT;