gpio: pca953x: Fix NBANK calculation for PCA9536
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
@@ -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
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 uninitializedPCA953X_INVERTregister. Fix this by usingDIV_ROUND_UPmacro inNBANK().Signed-off-by Vignesh R <[email protected]>
Patch applied.
Is this really a regression or affecting systems in development?
Which machine/device tree makes this problematic?
Yours,
Linus Walleij
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 uninitializedPCA953X_INVERTregister. Fix this by usingDIV_ROUND_UPmacro inNBANK().
Quoted 9 lines
Quoted 2 lines
Signed-off-by Vignesh R <[email protected]>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