diff mbox series

[RFC,1/1] gpio: sifive: To get gpio irq offset from device tree data

Message ID 802c8865b70c3bdf70e44d37f14e7767b6495e88.1604631371.git.greentime.hu@sifive.com
State New
Headers show
Series [RFC,1/1] gpio: sifive: To get gpio irq offset from device tree data | expand

Commit Message

Greentime Hu Nov. 6, 2020, 2:58 a.m. UTC
We can get hwirq number of the gpio by its irq_data->hwirq so that we don't
need to add more macros for different platforms. This patch is tested in
SiFive Unleashed board and SiFive Unmatched board.

Signed-off-by: Greentime Hu <greentime.hu@sifive.com>
Reviewed-by: Yash Shah <yash.shah@sifive.com>
---
 drivers/gpio/gpio-sifive.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Andy Shevchenko Nov. 6, 2020, 9:24 a.m. UTC | #1
On Fri, Nov 6, 2020 at 4:59 AM Greentime Hu <greentime.hu@sifive.com> wrote:
>
> We can get hwirq number of the gpio by its irq_data->hwirq so that we don't
> need to add more macros for different platforms. This patch is tested in
> SiFive Unleashed board and SiFive Unmatched board.

...

> +       struct sifive_gpio *chip = gpiochip_get_data(gc);
> +       struct irq_data *d = irq_get_irq_data(chip->irq_number[child]);

> +       *parent = d->hwirq;

There is an API to get hwirq.

...

> +       for (i = 0; i < ngpio; i++)
> +               chip->irq_number[i] = irq_of_parse_and_map(node, i);

Can't you use platform_get_irq_optional()?
Greentime Hu Nov. 6, 2020, 11 a.m. UTC | #2
Andy Shevchenko <andy.shevchenko@gmail.com> 於 2020年11月6日 週五 下午5:25寫道:
>
> On Fri, Nov 6, 2020 at 4:59 AM Greentime Hu <greentime.hu@sifive.com> wrote:
> >
> > We can get hwirq number of the gpio by its irq_data->hwirq so that we don't
> > need to add more macros for different platforms. This patch is tested in
> > SiFive Unleashed board and SiFive Unmatched board.
>
> ...
>
> > +       struct sifive_gpio *chip = gpiochip_get_data(gc);
> > +       struct irq_data *d = irq_get_irq_data(chip->irq_number[child]);
>
> > +       *parent = d->hwirq;
>
> There is an API to get hwirq.
>
> ...
>
> > +       for (i = 0; i < ngpio; i++)
> > +               chip->irq_number[i] = irq_of_parse_and_map(node, i);
>
> Can't you use platform_get_irq_optional()?
>

Thank you for reviewing.
I would change it like this.

diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c
index e8cd8741dbae..bfb915bf5d78 100644
--- a/drivers/gpio/gpio-sifive.c
+++ b/drivers/gpio/gpio-sifive.c
@@ -145,7 +145,7 @@ static int
sifive_gpio_child_to_parent_hwirq(struct gpio_chip *gc,
 {
        struct sifive_gpio *chip = gpiochip_get_data(gc);
        struct irq_data *d = irq_get_irq_data(chip->irq_number[child]);
-       *parent = d->hwirq;
+       *parent = irqd_to_hwirq(d);
        *parent_type = IRQ_TYPE_NONE;
        return 0;
 }
@@ -202,7 +202,7 @@ static int sifive_gpio_probe(struct platform_device *pdev)
        }

        for (i = 0; i < ngpio; i++)
-               chip->irq_number[i] = irq_of_parse_and_map(node, i);
+               chip->irq_number[i] = platform_get_irq(pdev, i);

        ret = bgpio_init(&chip->gc, dev, 4,
                         chip->base + SIFIVE_GPIO_INPUT_VAL,
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c
index c54dd08f2cbf..e8cd8741dbae 100644
--- a/drivers/gpio/gpio-sifive.c
+++ b/drivers/gpio/gpio-sifive.c
@@ -29,7 +29,6 @@ 
 #define SIFIVE_GPIO_OUTPUT_XOR	0x40
 
 #define SIFIVE_GPIO_MAX		32
-#define SIFIVE_GPIO_IRQ_OFFSET	7
 
 struct sifive_gpio {
 	void __iomem		*base;
@@ -37,7 +36,7 @@  struct sifive_gpio {
 	struct regmap		*regs;
 	unsigned long		irq_state;
 	unsigned int		trigger[SIFIVE_GPIO_MAX];
-	unsigned int		irq_parent[SIFIVE_GPIO_MAX];
+	unsigned int		irq_number[SIFIVE_GPIO_MAX];
 };
 
 static void sifive_gpio_set_ie(struct sifive_gpio *chip, unsigned int offset)
@@ -144,8 +143,10 @@  static int sifive_gpio_child_to_parent_hwirq(struct gpio_chip *gc,
 					     unsigned int *parent,
 					     unsigned int *parent_type)
 {
+	struct sifive_gpio *chip = gpiochip_get_data(gc);
+	struct irq_data *d = irq_get_irq_data(chip->irq_number[child]);
+	*parent = d->hwirq;
 	*parent_type = IRQ_TYPE_NONE;
-	*parent = child + SIFIVE_GPIO_IRQ_OFFSET;
 	return 0;
 }
 
@@ -165,7 +166,7 @@  static int sifive_gpio_probe(struct platform_device *pdev)
 	struct irq_domain *parent;
 	struct gpio_irq_chip *girq;
 	struct sifive_gpio *chip;
-	int ret, ngpio;
+	int ret, ngpio, i;
 
 	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
 	if (!chip)
@@ -200,6 +201,9 @@  static int sifive_gpio_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
+	for (i = 0; i < ngpio; i++)
+		chip->irq_number[i] = irq_of_parse_and_map(node, i);
+
 	ret = bgpio_init(&chip->gc, dev, 4,
 			 chip->base + SIFIVE_GPIO_INPUT_VAL,
 			 chip->base + SIFIVE_GPIO_OUTPUT_VAL,