hifiveu: add new target for HiFive Unleashed/Unmatched RISC-V boards
[openwrt/staging/wigyori.git] / target / linux / hifiveu / patches-5.10 / 0017-gpio-sifive-To-get-gpio-irq-offset-from-device-tree-.patch
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
5 data
6
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.
10
11 Signed-off-by: Greentime Hu <greentime.hu@sifive.com>
12 ---
13 drivers/gpio/gpio-sifive.c | 14 ++++++++++----
14 1 file changed, 10 insertions(+), 4 deletions(-)
15
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
20 @@ -29,7 +29,6 @@
21 #define SIFIVE_GPIO_OUTPUT_XOR 0x40
22
23 #define SIFIVE_GPIO_MAX 32
24 -#define SIFIVE_GPIO_IRQ_OFFSET 7
25
26 struct sifive_gpio {
27 void __iomem *base;
28 @@ -37,7 +36,7 @@ struct sifive_gpio {
29 struct regmap *regs;
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];
34 };
35
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,
38 unsigned int *parent,
39 unsigned int *parent_type)
40 {
41 + struct sifive_gpio *chip = gpiochip_get_data(gc);
42 + struct irq_data *d = irq_get_irq_data(chip->irq_number[child]);
43 +
44 *parent_type = IRQ_TYPE_NONE;
45 - *parent = child + SIFIVE_GPIO_IRQ_OFFSET;
46 + *parent = irqd_to_hwirq(d);
47 +
48 return 0;
49 }
50
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;
55 - int ret, ngpio;
56 + int ret, ngpio, i;
57
58 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
59 if (!chip)
60 @@ -200,6 +203,9 @@ static int sifive_gpio_probe(struct platform_device *pdev)
61 return -ENODEV;
62 }
63
64 + for (i = 0; i < ngpio; i++)
65 + chip->irq_number[i] = platform_get_irq(pdev, i);
66 +
67 ret = bgpio_init(&chip->gc, dev, 4,
68 chip->base + SIFIVE_GPIO_INPUT_VAL,
69 chip->base + SIFIVE_GPIO_OUTPUT_VAL,
70 --
71 2.7.4
72