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
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
10 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
11 Fixes: 3b0213d56eb7 ("gpio: Add GPIO support for Broadcom STB SoCs")
13 drivers/gpio/gpio-brcmstb.c | 21 ++++++++++-----------
14 1 file changed, 10 insertions(+), 11 deletions(-)
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;
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)
30 - return hwirq - (bank->gc.base - bank->parent_priv->gpio_base);
31 + return hwirq - bank->id * 32;
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)
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;
44 if (hwirq >= priv->num_gpios)
46 @@ -263,7 +263,7 @@ static void brcmstb_gpio_irq_bank_handle
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;
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))
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)
64 @@ -598,8 +598,8 @@ static int brcmstb_gpio_probe(struct pla
70 - static int gpio_base;
71 unsigned long flags = 0;
72 bool need_wakeup_event = false;
74 @@ -614,7 +614,6 @@ static int brcmstb_gpio_probe(struct pla
76 return PTR_ERR(reg_base);
78 - priv->gpio_base = gpio_base;
79 priv->reg_base = reg_base;
82 @@ -656,7 +655,7 @@ static int brcmstb_gpio_probe(struct pla
83 dev_dbg(dev, "Width 0 found: Empty bank @ %d\n",
86 - gpio_base += MAX_GPIO_PER_BANK;
87 + num_gpios += MAX_GPIO_PER_BANK;
91 @@ -698,7 +697,7 @@ static int brcmstb_gpio_probe(struct pla
95 - gc->base = gpio_base;
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
104 - gpio_base += gc->ngpio;
105 + num_gpios += gc->ngpio;
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
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);