diff mbox series

[RFC] gpio: brcmstb: account for empty banks

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

Commit Message

Justin Chen July 18, 2018, 9:46 p.m. UTC
From: Justin Chen <justinpopo6@gmail.com>

Currently the driver assumes all banks are consecutive. On some chips
we may have a hole in the register space between banks. To work around
this, when their is a hole we specify a bank width of 0. Then in the
driver we create a bank, but keep it out of the linked list so it never
gets used 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;