summaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2022-12-11 00:06:00 +0200
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-01-30 15:55:27 +0100
commita87f901b59326c12313dbf224cc4591ae2c63785 (patch)
tree46629b3e1f7f1c13f80e1a4a5c2bc406f02eb295 /drivers/gpio
parentb1453d1eb93fd34848082fd181ff247f19c0ee86 (diff)
downloadlinux-stable-a87f901b59326c12313dbf224cc4591ae2c63785.tar.gz
linux-stable-a87f901b59326c12313dbf224cc4591ae2c63785.tar.bz2
linux-stable-a87f901b59326c12313dbf224cc4591ae2c63785.zip
gpio: pca953x: Clean up pcal6534_check_register()
The pcal6534_check_register() is a bit too verbose. Clean up it, by deduplicating some operations and switching to the modulo operation as on some architectures / and % can become a single assembly instruction. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpio-pca953x.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 2c8586b3191f..8aba8df393bd 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -306,6 +306,7 @@ static bool pca953x_check_register(struct pca953x_chip *chip, unsigned int reg,
static bool pcal6534_check_register(struct pca953x_chip *chip, unsigned int reg,
u32 checkbank)
{
+ int bank_shift;
int bank;
int offset;
@@ -314,26 +315,22 @@ static bool pcal6534_check_register(struct pca953x_chip *chip, unsigned int reg,
* Handle lack of reserved registers after output port
* configuration register to form a bank.
*/
- int temp = reg - 0x54;
-
- bank = temp / NBANK(chip);
- offset = temp - (bank * NBANK(chip));
- bank += 16;
+ reg -= 0x54;
+ bank_shift = 16;
} else if (reg >= 0x30) {
/*
* Reserved block between 14h and 2Fh does not align on
* expected bank boundaries like other devices.
*/
- int temp = reg - 0x30;
-
- bank = temp / NBANK(chip);
- offset = temp - (bank * NBANK(chip));
- bank += 8;
+ reg -= 0x30;
+ bank_shift = 8;
} else {
- bank = reg / NBANK(chip);
- offset = reg - (bank * NBANK(chip));
+ bank_shift = 0;
}
+ bank = bank_shift + reg / NBANK(chip);
+ offset = reg % NBANK(chip);
+
/* Register is not in the matching bank. */
if (!(BIT(bank) & checkbank))
return false;