1 From e00f15b712b61f35fec747912dd5d3e9553d89a1 Mon Sep 17 00:00:00 2001
2 From: Greentime Hu <greentime.hu@sifive.com>
3 Date: Fri, 13 Nov 2020 10:33:55 +0800
4 Subject: [PATCH 17/29] gpio: sifive: To get gpio irq offset from device tree
7 We can get hwirq number of the gpio by its irq_data->hwirq so that we don't
8 need to add more macros for different platforms. This patch is tested in
9 SiFive Unleashed board and SiFive Unmatched board.
11 Signed-off-by: Greentime Hu <greentime.hu@sifive.com>
13 drivers/gpio/gpio-sifive.c | 14 ++++++++++----
14 1 file changed, 10 insertions(+), 4 deletions(-)
16 diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c
17 index d5eb9ca..63593c2 100644
18 --- a/drivers/gpio/gpio-sifive.c
19 +++ b/drivers/gpio/gpio-sifive.c
21 #define SIFIVE_GPIO_OUTPUT_XOR 0x40
23 #define SIFIVE_GPIO_MAX 32
24 -#define SIFIVE_GPIO_IRQ_OFFSET 7
28 @@ -37,7 +36,7 @@ struct sifive_gpio {
30 unsigned long irq_state;
31 unsigned int trigger[SIFIVE_GPIO_MAX];
32 - unsigned int irq_parent[SIFIVE_GPIO_MAX];
33 + unsigned int irq_number[SIFIVE_GPIO_MAX];
36 static void sifive_gpio_set_ie(struct sifive_gpio *chip, unsigned int offset)
37 @@ -144,8 +143,12 @@ static int sifive_gpio_child_to_parent_hwirq(struct gpio_chip *gc,
39 unsigned int *parent_type)
41 + struct sifive_gpio *chip = gpiochip_get_data(gc);
42 + struct irq_data *d = irq_get_irq_data(chip->irq_number[child]);
44 *parent_type = IRQ_TYPE_NONE;
45 - *parent = child + SIFIVE_GPIO_IRQ_OFFSET;
46 + *parent = irqd_to_hwirq(d);
51 @@ -165,7 +168,7 @@ static int sifive_gpio_probe(struct platform_device *pdev)
52 struct irq_domain *parent;
53 struct gpio_irq_chip *girq;
54 struct sifive_gpio *chip;
58 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
60 @@ -200,6 +203,9 @@ static int sifive_gpio_probe(struct platform_device *pdev)
64 + for (i = 0; i < ngpio; i++)
65 + chip->irq_number[i] = platform_get_irq(pdev, i);
67 ret = bgpio_init(&chip->gc, dev, 4,
68 chip->base + SIFIVE_GPIO_INPUT_VAL,
69 chip->base + SIFIVE_GPIO_OUTPUT_VAL,