bcm27xx: update 6.1 patches to latest version
[openwrt/staging/svanheule.git] / target / linux / bcm27xx / patches-6.1 / 950-1017-gpio-brcmstb-Use-dynamic-GPIO-base-numbers.patch
1 From 450d617786926b27c25e930241efbd2e37d66bb8 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Fri, 6 Oct 2023 16:30:35 +0100
4 Subject: [PATCH] gpio: brcmstb: Use dynamic GPIO base numbers
5
6 Forcing a gpiochip to have a fixed base number now leads to a warning
7 message. Remove the need to do so by calculating hwirq numbers based
8 on bank numbers.
9
10 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
11 Fixes: 3b0213d56eb7 ("gpio: Add GPIO support for Broadcom STB SoCs")
12 ---
13 drivers/gpio/gpio-brcmstb.c | 21 ++++++++++-----------
14 1 file changed, 10 insertions(+), 11 deletions(-)
15
16 --- a/drivers/gpio/gpio-brcmstb.c
17 +++ b/drivers/gpio/gpio-brcmstb.c
18 @@ -50,7 +50,6 @@ struct brcmstb_gpio_priv {
19 struct irq_domain *irq_domain;
20 struct irq_chip irq_chip;
21 int parent_irq;
22 - int gpio_base;
23 int num_gpios;
24 int parent_wake_irq;
25 };
26 @@ -92,7 +91,7 @@ brcmstb_gpio_get_active_irqs(struct brcm
27 static int brcmstb_gpio_hwirq_to_offset(irq_hw_number_t hwirq,
28 struct brcmstb_gpio_bank *bank)
29 {
30 - return hwirq - (bank->gc.base - bank->parent_priv->gpio_base);
31 + return hwirq - bank->id * 32;
32 }
33
34 static void brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank,
35 @@ -117,8 +116,9 @@ static void brcmstb_gpio_set_imask(struc
36 static int brcmstb_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
37 {
38 struct brcmstb_gpio_priv *priv = brcmstb_gpio_gc_to_priv(gc);
39 + struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc);
40 /* gc_offset is relative to this gpio_chip; want real offset */
41 - int hwirq = offset + (gc->base - priv->gpio_base);
42 + int hwirq = offset + bank->id * 32;
43
44 if (hwirq >= priv->num_gpios)
45 return -ENXIO;
46 @@ -263,7 +263,7 @@ static void brcmstb_gpio_irq_bank_handle
47 {
48 struct brcmstb_gpio_priv *priv = bank->parent_priv;
49 struct irq_domain *domain = priv->irq_domain;
50 - int hwbase = bank->gc.base - priv->gpio_base;
51 + int hwbase = bank->id * 32;
52 unsigned long status;
53
54 while ((status = brcmstb_gpio_get_active_irqs(bank))) {
55 @@ -414,7 +414,7 @@ static int brcmstb_gpio_of_xlate(struct
56 if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells))
57 return -EINVAL;
58
59 - offset = gpiospec->args[0] - (gc->base - priv->gpio_base);
60 + offset = gpiospec->args[0] - bank->id * 32;
61 if (offset >= gc->ngpio || offset < 0)
62 return -EINVAL;
63
64 @@ -598,8 +598,8 @@ static int brcmstb_gpio_probe(struct pla
65 const __be32 *p;
66 u32 bank_width;
67 int num_banks = 0;
68 + int num_gpios = 0;
69 int err;
70 - static int gpio_base;
71 unsigned long flags = 0;
72 bool need_wakeup_event = false;
73
74 @@ -614,7 +614,6 @@ static int brcmstb_gpio_probe(struct pla
75 if (IS_ERR(reg_base))
76 return PTR_ERR(reg_base);
77
78 - priv->gpio_base = gpio_base;
79 priv->reg_base = reg_base;
80 priv->pdev = pdev;
81
82 @@ -656,7 +655,7 @@ static int brcmstb_gpio_probe(struct pla
83 dev_dbg(dev, "Width 0 found: Empty bank @ %d\n",
84 num_banks);
85 num_banks++;
86 - gpio_base += MAX_GPIO_PER_BANK;
87 + num_gpios += MAX_GPIO_PER_BANK;
88 continue;
89 }
90
91 @@ -698,7 +697,7 @@ static int brcmstb_gpio_probe(struct pla
92 err = -ENOMEM;
93 goto fail;
94 }
95 - gc->base = gpio_base;
96 + gc->base = -1;
97 gc->of_gpio_n_cells = 2;
98 gc->of_xlate = brcmstb_gpio_of_xlate;
99 /* not all ngpio lines are valid, will use bank width later */
100 @@ -722,7 +721,7 @@ static int brcmstb_gpio_probe(struct pla
101 bank->id);
102 goto fail;
103 }
104 - gpio_base += gc->ngpio;
105 + num_gpios += gc->ngpio;
106
107 dev_dbg(dev, "bank=%d, base=%d, ngpio=%d, width=%d\n", bank->id,
108 gc->base, gc->ngpio, bank->width);
109 @@ -733,7 +732,7 @@ static int brcmstb_gpio_probe(struct pla
110 num_banks++;
111 }
112
113 - priv->num_gpios = gpio_base - priv->gpio_base;
114 + priv->num_gpios = num_gpios;
115 if (priv->parent_irq > 0) {
116 err = brcmstb_gpio_irq_setup(pdev, priv);
117 if (err)