diff mbox series

[RFC] gpio: brcmstb: Properly account for empty banks

Message ID 1531875521-29888-1-git-send-email-justinpopo6@gmail.com
State New
Headers show
Series [RFC] gpio: brcmstb: Properly account for empty banks | expand

Commit Message

Justin Chen July 18, 2018, 12:58 a.m. UTC
From: Justin Chen <justinpopo6@gmail.com>

On some chips we have empty banks or a hole in the register space.
The driver assumes all banks are consecutive and the same size.
To work around this, we create a fake bank where there is a hole
and keep it out of the linked list so it won't be called or initialized

Signed-off-by: Justin Chen <justinpopo6@gmail.com>
---
 drivers/gpio/gpio-brcmstb.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-brcmstb.c b/drivers/gpio/gpio-brcmstb.c
index 99247f6..9daeda7 100644
--- a/drivers/gpio/gpio-brcmstb.c
+++ b/drivers/gpio/gpio-brcmstb.c
@@ -603,6 +603,18 @@  static int brcmstb_gpio_probe(struct platform_device *pdev)
 		struct brcmstb_gpio_bank *bank;
 		struct gpio_chip *gc;
 
+		/*
+		 * If bank_width is 0, then there is an empty bank in the
+		 * register block. Special handling for this case.
+		 */
+		if (bank_width == 0) {
+			dev_dbg(dev, "Fake bank %d (GPIO(s): %d-%d)\n",
+			  num_banks, gpio_base, gpio_base + MAX_GPIO_PER_BANK);
+			num_banks++;
+			gpio_base += MAX_GPIO_PER_BANK;
+			continue;
+		}
+
 		bank = devm_kzalloc(dev, sizeof(*bank), GFP_KERNEL);
 		if (!bank) {
 			err = -ENOMEM;
@@ -611,7 +623,7 @@  static int brcmstb_gpio_probe(struct platform_device *pdev)
 
 		bank->parent_priv = priv;
 		bank->id = num_banks;
-		if (bank_width <= 0 || bank_width > MAX_GPIO_PER_BANK) {
+		if (bank_width < 0 || bank_width > MAX_GPIO_PER_BANK) {
 			dev_err(dev, "Invalid bank width %d\n", bank_width);
 			err = -EINVAL;
 			goto fail;