All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/14] gpio: pca953x: Deduplicate the bank_size
@ 2018-12-02 19:35 Marek Vasut
  2018-12-02 19:35 ` [PATCH 02/14] gpio: pca953x: Fix AI overflow on PCAL6524 Marek Vasut
                   ` (13 more replies)
  0 siblings, 14 replies; 24+ messages in thread
From: Marek Vasut @ 2018-12-02 19:35 UTC (permalink / raw)
  To: linux-gpio
  Cc: linux-renesas-soc, Marek Vasut, Linus Walleij, Bartosz Golaszewski

The bank_size = fls(...) code was duplicated in the driver 5 times,
pull it into separate function.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/gpio/gpio-pca953x.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 023a32cfac42..31e3b1b52330 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -159,11 +159,16 @@ struct pca953x_chip {
 	int (*read_regs)(struct pca953x_chip *, int, u8 *);
 };
 
+static int pca953x_bank_shift(struct pca953x_chip *chip)
+{
+	return fls((chip->gpio_chip.ngpio - 1) / BANK_SZ);
+}
+
 static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val,
 				int off)
 {
 	int ret;
-	int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ);
+	int bank_shift = pca953x_bank_shift(chip);
 	int offset = off / BANK_SZ;
 
 	ret = i2c_smbus_read_byte_data(chip->client,
@@ -182,7 +187,7 @@ static int pca953x_write_single(struct pca953x_chip *chip, int reg, u32 val,
 				int off)
 {
 	int ret;
-	int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ);
+	int bank_shift = pca953x_bank_shift(chip);
 	int offset = off / BANK_SZ;
 
 	ret = i2c_smbus_write_byte_data(chip->client,
@@ -221,7 +226,7 @@ static int pca957x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val)
 
 static int pca953x_write_regs_24(struct pca953x_chip *chip, int reg, u8 *val)
 {
-	int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ);
+	int bank_shift = pca953x_bank_shift(chip);
 	int addr = (reg & PCAL_GPIO_MASK) << bank_shift;
 	int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1;
 
@@ -265,7 +270,7 @@ static int pca953x_read_regs_16(struct pca953x_chip *chip, int reg, u8 *val)
 
 static int pca953x_read_regs_24(struct pca953x_chip *chip, int reg, u8 *val)
 {
-	int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ);
+	int bank_shift = pca953x_bank_shift(chip);
 	int addr = (reg & PCAL_GPIO_MASK) << bank_shift;
 	int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1;
 
@@ -402,13 +407,12 @@ static void pca953x_gpio_set_multiple(struct gpio_chip *gc,
 				      unsigned long *mask, unsigned long *bits)
 {
 	struct pca953x_chip *chip = gpiochip_get_data(gc);
+	int bank_shift = pca953x_bank_shift(chip);
 	unsigned int bank_mask, bank_val;
-	int bank_shift, bank;
+	int bank;
 	u8 reg_val[MAX_BANK];
 	int ret;
 
-	bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ);
-
 	mutex_lock(&chip->i2c_lock);
 	memcpy(reg_val, chip->reg_output, NBANK(chip));
 	for (bank = 0; bank < NBANK(chip); bank++) {
-- 
2.18.0

^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2018-12-18 13:44 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-02 19:35 [PATCH 01/14] gpio: pca953x: Deduplicate the bank_size Marek Vasut
2018-12-02 19:35 ` [PATCH 02/14] gpio: pca953x: Fix AI overflow on PCAL6524 Marek Vasut
2018-12-03  9:37   ` Bartosz Golaszewski
2018-12-02 19:35 ` [PATCH 03/14] gpio: pca953x: Repair multi-byte IO address increment on PCA9575 Marek Vasut
2018-12-03 10:09   ` Geert Uytterhoeven
2018-12-02 19:35 ` [PATCH 04/14] gpio: pca953x: Unify pca95{3,7}x_write_regs_16() Marek Vasut
2018-12-02 19:35 ` [PATCH 05/14] gpio: pca953x: Unify pca953x_{read,write}_regs_{16,24}() Marek Vasut
2018-12-02 19:35 ` [PATCH 06/14] gpio: pca953x: Unify pca953x_{read,write}_regs_{8,mul}() Marek Vasut
2018-12-02 19:35 ` [PATCH 07/14] gpio: pca953x: Factor out common code from device_pca95xx_init() Marek Vasut
2018-12-02 19:35 ` [PATCH 08/14] gpio: pca953x: Zap ad-hoc I2C block write in multi GPIO set Marek Vasut
2018-12-02 19:35 ` [PATCH 09/14] gpio: pca953x: Extract the register address mangling to single function Marek Vasut
2018-12-02 19:35 ` [PATCH 10/14] gpio: pca953x: Perform basic regmap conversion Marek Vasut
2018-12-02 19:35 ` [PATCH 11/14] gpio: pca953x: Zap ad-hoc reg_direction cache Marek Vasut
2018-12-02 19:35 ` [PATCH 12/14] gpio: pca953x: Zap ad-hoc reg_output cache Marek Vasut
2018-12-02 19:35 ` [PATCH 13/14] gpio: pca953x: Zap single use of pca953x_read_single() Marek Vasut
2018-12-02 19:35 ` [PATCH 14/14] gpio: pca953x: Restore registers after suspend/resume cycle Marek Vasut
2018-12-03 17:55   ` Geert Uytterhoeven
2018-12-03 21:42     ` Marek Vasut
2018-12-18 12:57     ` Geert Uytterhoeven
2018-12-18 13:43       ` Geert Uytterhoeven
2018-12-05 14:39   ` Geert Uytterhoeven
2018-12-05 14:45     ` Marek Vasut
2018-12-03  9:36 ` [PATCH 01/14] gpio: pca953x: Deduplicate the bank_size Bartosz Golaszewski
2018-12-03 11:00   ` Marek Vasut

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.