Skip to content

Commit

Permalink
gpio: pca953x: Correctly initialize registers 6 and 7 for PCA957x
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Andy Shevchenko authored and Linus Walleij committed Oct 1, 2020
1 parent e09e200 commit 8c1f1c3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/gpio/gpio-pca953x.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,14 +942,17 @@ static int device_pca95xx_init(struct pca953x_chip *chip, u32 invert)
static int device_pca957x_init(struct pca953x_chip *chip, u32 invert)
{
DECLARE_BITMAP(val, MAX_LINE);
unsigned int i;
int ret;

ret = device_pca95xx_init(chip, invert);
if (ret)
goto out;

/* To enable register 6, 7 to control pull up and pull down */
memset(val, 0x02, NBANK(chip));
for (i = 0; i < NBANK(chip); i++)
bitmap_set_value8(val, 0x02, i * BANK_SZ);

ret = pca953x_write_regs(chip, PCA957X_BKEN, val);
if (ret)
goto out;
Expand Down

0 comments on commit 8c1f1c3

Please sign in to comment.