The bank_shift = 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: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
int (*read_regs)(struct pca953x_chip *, int, u8 *);
};
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;
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,
int offset = off / BANK_SZ;
ret = i2c_smbus_read_byte_data(chip->client,
- 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,
int offset = off / BANK_SZ;
ret = i2c_smbus_write_byte_data(chip->client,
static int pca953x_write_regs_24(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;
int addr = (reg & PCAL_GPIO_MASK) << bank_shift;
int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1;
static int pca953x_read_regs_24(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;
int addr = (reg & PCAL_GPIO_MASK) << bank_shift;
int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1;
unsigned long *mask, unsigned long *bits)
{
struct pca953x_chip *chip = gpiochip_get_data(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;
unsigned int bank_mask, bank_val;
u8 reg_val[MAX_BANK];
int ret;
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++) {
mutex_lock(&chip->i2c_lock);
memcpy(reg_val, chip->reg_output, NBANK(chip));
for (bank = 0; bank < NBANK(chip); bank++) {