2021-12-24 14:57:59

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH 0/2] pinctrl: Use platform_get_irq*() variants to fetch IRQ's

Hi All,

This patch series aims to drop using platform_get_resource() for IRQ types
in preparation for removal of static setup of IRQ resource from DT core
code.

Dropping usage of platform_get_resource() was agreed based on
the discussion [0].

[0] https://patchwork.kernel.org/project/linux-renesas-soc/
patch/[email protected]/

Cheers,
Prabhakar

Lad Prabhakar (2):
pinctrl: samsung: Use platform_get_irq_optional() to get the interrupt
pinctrl: at91-pio4: Use platform_get_irq_optional() to get the
interrupt

drivers/pinctrl/pinctrl-at91-pio4.c | 14 ++++++--------
drivers/pinctrl/samsung/pinctrl-samsung.c | 9 +++++----
2 files changed, 11 insertions(+), 12 deletions(-)

--
2.17.1



2021-12-24 14:58:02

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH 1/2] pinctrl: samsung: Use platform_get_irq_optional() to get the interrupt

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().

Signed-off-by: Lad Prabhakar <[email protected]>
---
drivers/pinctrl/samsung/pinctrl-samsung.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
index 8941f658e7f1..0f6e9305fec5 100644
--- a/drivers/pinctrl/samsung/pinctrl-samsung.c
+++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
@@ -1095,7 +1095,6 @@ static int samsung_pinctrl_probe(struct platform_device *pdev)
struct samsung_pinctrl_drv_data *drvdata;
const struct samsung_pin_ctrl *ctrl;
struct device *dev = &pdev->dev;
- struct resource *res;
int ret;

drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
@@ -1109,9 +1108,11 @@ static int samsung_pinctrl_probe(struct platform_device *pdev)
}
drvdata->dev = dev;

- res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
- if (res)
- drvdata->irq = res->start;
+ ret = platform_get_irq_optional(pdev, 0);
+ if (ret < 0 && ret != -ENXIO)
+ return ret;
+ if (ret > 0)
+ drvdata->irq = ret;

if (ctrl->retention_data) {
drvdata->retention_ctrl = ctrl->retention_data->init(drvdata,
--
2.17.1


2021-12-24 14:58:05

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH 2/2] pinctrl: at91-pio4: Use platform_get_irq_optional() to get the interrupt

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().

Signed-off-by: Lad Prabhakar <[email protected]>
---
drivers/pinctrl/pinctrl-at91-pio4.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-at91-pio4.c b/drivers/pinctrl/pinctrl-at91-pio4.c
index fafd1f55cba7..ebfb106be97d 100644
--- a/drivers/pinctrl/pinctrl-at91-pio4.c
+++ b/drivers/pinctrl/pinctrl-at91-pio4.c
@@ -1045,7 +1045,6 @@ static int atmel_pinctrl_probe(struct platform_device *pdev)
const char **group_names;
const struct of_device_id *match;
int i, ret;
- struct resource *res;
struct atmel_pioctrl *atmel_pioctrl;
const struct atmel_pioctrl_data *atmel_pioctrl_data;

@@ -1164,16 +1163,15 @@ static int atmel_pinctrl_probe(struct platform_device *pdev)

/* There is one controller but each bank has its own irq line. */
for (i = 0; i < atmel_pioctrl->nbanks; i++) {
- res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
- if (!res) {
+ ret = platform_get_irq_optional(pdev, i);
+ if (ret < 0) {
dev_err(dev, "missing irq resource for group %c\n",
'A' + i);
- return -EINVAL;
+ return ret;
}
- atmel_pioctrl->irqs[i] = res->start;
- irq_set_chained_handler_and_data(res->start,
- atmel_gpio_irq_handler, atmel_pioctrl);
- dev_dbg(dev, "bank %i: irq=%pr\n", i, res);
+ atmel_pioctrl->irqs[i] = ret;
+ irq_set_chained_handler_and_data(ret, atmel_gpio_irq_handler, atmel_pioctrl);
+ dev_dbg(dev, "bank %i: irq=%d\n", i, ret);
}

atmel_pioctrl->irq_domain = irq_domain_add_linear(dev->of_node,
--
2.17.1


2021-12-24 15:03:32

by Alexandre Belloni

[permalink] [raw]
Subject: Re: [PATCH 2/2] pinctrl: at91-pio4: Use platform_get_irq_optional() to get the interrupt

On 24/12/2021 14:57:48+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().
>
> Signed-off-by: Lad Prabhakar <[email protected]>
> ---
> drivers/pinctrl/pinctrl-at91-pio4.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/pinctrl/pinctrl-at91-pio4.c b/drivers/pinctrl/pinctrl-at91-pio4.c
> index fafd1f55cba7..ebfb106be97d 100644
> --- a/drivers/pinctrl/pinctrl-at91-pio4.c
> +++ b/drivers/pinctrl/pinctrl-at91-pio4.c
> @@ -1045,7 +1045,6 @@ static int atmel_pinctrl_probe(struct platform_device *pdev)
> const char **group_names;
> const struct of_device_id *match;
> int i, ret;
> - struct resource *res;
> struct atmel_pioctrl *atmel_pioctrl;
> const struct atmel_pioctrl_data *atmel_pioctrl_data;
>
> @@ -1164,16 +1163,15 @@ static int atmel_pinctrl_probe(struct platform_device *pdev)
>
> /* There is one controller but each bank has its own irq line. */
> for (i = 0; i < atmel_pioctrl->nbanks; i++) {
> - res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
> - if (!res) {
> + ret = platform_get_irq_optional(pdev, i);

I don't think the irq should be optional here.

> + if (ret < 0) {
> dev_err(dev, "missing irq resource for group %c\n",
> 'A' + i);
> - return -EINVAL;
> + return ret;
> }
> - atmel_pioctrl->irqs[i] = res->start;
> - irq_set_chained_handler_and_data(res->start,
> - atmel_gpio_irq_handler, atmel_pioctrl);
> - dev_dbg(dev, "bank %i: irq=%pr\n", i, res);
> + atmel_pioctrl->irqs[i] = ret;
> + irq_set_chained_handler_and_data(ret, atmel_gpio_irq_handler, atmel_pioctrl);
> + dev_dbg(dev, "bank %i: irq=%d\n", i, ret);
> }
>
> atmel_pioctrl->irq_domain = irq_domain_add_linear(dev->of_node,
> --
> 2.17.1
>

--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

2021-12-24 15:10:12

by Lad, Prabhakar

[permalink] [raw]
Subject: Re: [PATCH 2/2] pinctrl: at91-pio4: Use platform_get_irq_optional() to get the interrupt

Hi Alexandre,

Thank you for the review.

On Fri, Dec 24, 2021 at 3:03 PM Alexandre Belloni
<[email protected]> wrote:
>
> On 24/12/2021 14:57:48+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().
> >
> > Signed-off-by: Lad Prabhakar <[email protected]>
> > ---
> > drivers/pinctrl/pinctrl-at91-pio4.c | 14 ++++++--------
> > 1 file changed, 6 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/pinctrl/pinctrl-at91-pio4.c b/drivers/pinctrl/pinctrl-at91-pio4.c
> > index fafd1f55cba7..ebfb106be97d 100644
> > --- a/drivers/pinctrl/pinctrl-at91-pio4.c
> > +++ b/drivers/pinctrl/pinctrl-at91-pio4.c
> > @@ -1045,7 +1045,6 @@ static int atmel_pinctrl_probe(struct platform_device *pdev)
> > const char **group_names;
> > const struct of_device_id *match;
> > int i, ret;
> > - struct resource *res;
> > struct atmel_pioctrl *atmel_pioctrl;
> > const struct atmel_pioctrl_data *atmel_pioctrl_data;
> >
> > @@ -1164,16 +1163,15 @@ static int atmel_pinctrl_probe(struct platform_device *pdev)
> >
> > /* There is one controller but each bank has its own irq line. */
> > for (i = 0; i < atmel_pioctrl->nbanks; i++) {
> > - res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
> > - if (!res) {
> > + ret = platform_get_irq_optional(pdev, i);
>
> I don't think the irq should be optional here.
>
The only difference between platform_get_irq() and
platform_get_irq_optional() is that platform_get_irq() prints an error
message in case of error. Since we are already printing an sane error
message "missing irq resource for group %c\n" in the driver I've
chosen platform_get_irq_optional() instead platform_get_irq().

Let me know if you want me to drop platform_get_irq_optional() and use
platform_get_irq() instead, in that case I'll also drop the error
message "missing irq resource for group %c\n" from the driver.

Cheers,
Prabhakar

> > + if (ret < 0) {
> > dev_err(dev, "missing irq resource for group %c\n",
> > 'A' + i);
> > - return -EINVAL;
> > + return ret;
> > }
> > - atmel_pioctrl->irqs[i] = res->start;
> > - irq_set_chained_handler_and_data(res->start,
> > - atmel_gpio_irq_handler, atmel_pioctrl);
> > - dev_dbg(dev, "bank %i: irq=%pr\n", i, res);
> > + atmel_pioctrl->irqs[i] = ret;
> > + irq_set_chained_handler_and_data(ret, atmel_gpio_irq_handler, atmel_pioctrl);
> > + dev_dbg(dev, "bank %i: irq=%d\n", i, ret);
> > }
> >
> > atmel_pioctrl->irq_domain = irq_domain_add_linear(dev->of_node,
> > --
> > 2.17.1
> >
>
> --
> Alexandre Belloni, co-owner and COO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com

2021-12-25 10:18:24

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: (subset) [PATCH 1/2] pinctrl: samsung: Use platform_get_irq_optional() to get the interrupt

On Fri, 24 Dec 2021 14:57:47 +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().
>
> [...]

Applied, thanks!

[1/2] pinctrl: samsung: Use platform_get_irq_optional() to get the interrupt
commit: a382d568f144b9e533ad210117c6c50d8dbdcaf1

Best regards,
--
Krzysztof Kozlowski <[email protected]>

2021-12-25 15:35:11

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 1/2] pinctrl: samsung: Use platform_get_irq_optional() to get the interrupt

On Sat, Dec 25, 2021 at 3:59 AM Lad Prabhakar
<[email protected]> 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().

> + ret = platform_get_irq_optional(pdev, 0);
> + if (ret < 0 && ret != -ENXIO)
> + return ret;
> + if (ret > 0)
> + drvdata->irq = ret;

Yes, this is how platform_get_irq_optional() is expected to be used
right now. We are going to fix it a bit, so this code won't be
affected.

--
With Best Regards,
Andy Shevchenko

2021-12-25 15:37:04

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 2/2] pinctrl: at91-pio4: Use platform_get_irq_optional() to get the interrupt

On Sat, Dec 25, 2021 at 3:59 AM Lad Prabhakar
<[email protected]> 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().


> + ret = platform_get_irq_optional(pdev, i);
> + if (ret < 0) {
> dev_err(dev, "missing irq resource for group %c\n",
> 'A' + i);
> - return -EINVAL;
> + return ret;
> }

This is an incorrect use of platform_get_irq_optional() (It's not
related to what Alexandre said, it's an additional comment).
NAK.

--
With Best Regards,
Andy Shevchenko