Skip to content

Commit 8c1f1c3

Browse files
andy-shevLinus Walleij
authored andcommitted
gpio: pca953x: Correctly initialize registers 6 and 7 for PCA957x
When driver has been converted to the bitmap API the non-bitmap functions started behaving differently on 32-bit BE architectures since the bytes in two consequent unsigned longs are in different order in comparison to byte array. Hence if the chip had had more than 32 lines the memset() call over it would have not set up upper lines correctly. Although it's currently a theoretical case (no supported chips of this type has 32+ lines), it's better to provide a clean code to avoid people thinking this is okay and potentially producing not fully working things. Fixes: 35d13d9 ("gpio: pca953x: convert to use bitmap API") Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Link: https://lore.kernel.org/r/20200930142013.59247-2-andriy.shevchenko@linux.intel.com Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent e09e200 commit 8c1f1c3

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

drivers/gpio/gpio-pca953x.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,14 +942,17 @@ static int device_pca95xx_init(struct pca953x_chip *chip, u32 invert)
942942
static int device_pca957x_init(struct pca953x_chip *chip, u32 invert)
943943
{
944944
DECLARE_BITMAP(val, MAX_LINE);
945+
unsigned int i;
945946
int ret;
946947

947948
ret = device_pca95xx_init(chip, invert);
948949
if (ret)
949950
goto out;
950951

951952
/* To enable register 6, 7 to control pull up and pull down */
952-
memset(val, 0x02, NBANK(chip));
953+
for (i = 0; i < NBANK(chip); i++)
954+
bitmap_set_value8(val, 0x02, i * BANK_SZ);
955+
953956
ret = pca953x_write_regs(chip, PCA957X_BKEN, val);
954957
if (ret)
955958
goto out;

0 commit comments

Comments
 (0)