Skip to contentSkip to conversation

gpio: pca953x: Fix NBANK calculation for PCA9536

PATCH In review Vignesh R 2 participants 3 messages Jun 9, 2016 – Jun 13, 2016 GPIO

lore
Share & tools
lore

Vignesh R

author
#0 lore raw

PATCH 1/1 gpio: pca953x: Fix NBANK calculation for PCA9536

NBANK() macro assumes that ngpios is a multiple of 8(BANK_SZ) and hence results in 0 banks for PCA9536 which has just 4 gpios. This is wrong as PCA9356 has 1 bank with 4 gpios. This results in uninitialized PCA953X_INVERT register. Fix this by using DIV_ROUND_UP macro in NBANK().

---
 drivers/gpio/gpio-pca953x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-pca953x.c +1 -1
index 763028562d22..f31b141c05de 100644
@@ -90,7 +90,7 @@ MODULE_DEVICE_TABLE(acpi, pca953x_acpi_ids);
 #define MAX_BANK 5
 #define BANK_SZ 8
 
-#define NBANK(chip) (chip->gpio_chip.ngpio / BANK_SZ)
+#define NBANK(chip) DIV_ROUND_UP(chip->gpio_chip.ngpio, BANK_SZ)
 
 struct pca953x_chip {
 	unsigned gpio_start;
Signature · 1 line
2.8.3
#1 lore raw
Quoted 8 lines · Vignesh R

NBANK() macro assumes that ngpios is a multiple of 8(BANK_SZ) and hence results in 0 banks for PCA9536 which has just 4 gpios. This is wrong as PCA9356 has 1 bank with 4 gpios. This results in uninitialized PCA953X_INVERT register. Fix this by using DIV_ROUND_UP macro in NBANK().

Patch applied.

Is this really a regression or affecting systems in development?

Which machine/device tree makes this problematic?

Yours,
Linus Walleij

author
#2 lore raw
Quoted 8 lines · Linus Walleij
Quoted 6 lines · Vignesh R

NBANK() macro assumes that ngpios is a multiple of 8(BANK_SZ) and hence results in 0 banks for PCA9536 which has just 4 gpios. This is wrong as PCA9356 has 1 bank with 4 gpios. This results in uninitialized PCA953X_INVERT register. Fix this by using DIV_ROUND_UP macro in NBANK().

Quoted 9 lines
Quoted 2 lines

Patch applied.

Is this really a regression or affecting systems in development?

Which machine/device tree makes this problematic?

I observed this on am335x-icev2 evm which is system in development. Basically, variable with uninitialized value (junk) gets written to PCA953X_INVERT register(in device_pca953x_init()) causing driver to report wrong gpio pin status. So, this bug will affect any platform with PCA9536 chip. Quick grep on arch/*/boot/dts/ folder shows one platform already using pca9536 chip. Hence, I added Cc to stable kernel.

Signature · 2 lines
Regards
Vignesh