* [PATCH] gpio: pca953x: use regmap_update_bits() to improve efficiency
@ 2025-07-09 20:10 Hugo Villeneuve
2025-07-11 10:22 ` Bartosz Golaszewski
0 siblings, 1 reply; 3+ messages in thread
From: Hugo Villeneuve @ 2025-07-09 20:10 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski
Cc: hugo, Hugo Villeneuve, linux-gpio, linux-kernel
From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Using regmap_update_bits() allows to reduce the number of I2C transfers
when updating bits that haven't changed on non-volatile registers.
For example on a PCAL6416, when changing a GPIO direction from input to
output, the number of I2C transfers can be reduced from 4 to just 1 if
the pull resistors configuration hasn't changed and the output value
is the same as before.
Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
drivers/gpio/gpio-pca953x.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index e80a96f397885..34dd5b4a6b299 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -533,7 +533,7 @@ static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off)
guard(mutex)(&chip->i2c_lock);
- return regmap_write_bits(chip->regmap, dirreg, bit, bit);
+ return regmap_update_bits(chip->regmap, dirreg, bit, bit);
}
static int pca953x_gpio_direction_output(struct gpio_chip *gc,
@@ -548,12 +548,12 @@ static int pca953x_gpio_direction_output(struct gpio_chip *gc,
guard(mutex)(&chip->i2c_lock);
/* set output level */
- ret = regmap_write_bits(chip->regmap, outreg, bit, val ? bit : 0);
+ ret = regmap_update_bits(chip->regmap, outreg, bit, val ? bit : 0);
if (ret)
return ret;
/* then direction */
- return regmap_write_bits(chip->regmap, dirreg, bit, 0);
+ return regmap_update_bits(chip->regmap, dirreg, bit, 0);
}
static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off)
@@ -581,7 +581,7 @@ static int pca953x_gpio_set_value(struct gpio_chip *gc, unsigned int off,
guard(mutex)(&chip->i2c_lock);
- return regmap_write_bits(chip->regmap, outreg, bit, val ? bit : 0);
+ return regmap_update_bits(chip->regmap, outreg, bit, val ? bit : 0);
}
static int pca953x_gpio_get_direction(struct gpio_chip *gc, unsigned off)
@@ -658,9 +658,9 @@ static int pca953x_gpio_set_pull_up_down(struct pca953x_chip *chip,
/* Configure pull-up/pull-down */
if (param == PIN_CONFIG_BIAS_PULL_UP)
- ret = regmap_write_bits(chip->regmap, pull_sel_reg, bit, bit);
+ ret = regmap_update_bits(chip->regmap, pull_sel_reg, bit, bit);
else if (param == PIN_CONFIG_BIAS_PULL_DOWN)
- ret = regmap_write_bits(chip->regmap, pull_sel_reg, bit, 0);
+ ret = regmap_update_bits(chip->regmap, pull_sel_reg, bit, 0);
else
ret = 0;
if (ret)
@@ -668,9 +668,9 @@ static int pca953x_gpio_set_pull_up_down(struct pca953x_chip *chip,
/* Disable/Enable pull-up/pull-down */
if (param == PIN_CONFIG_BIAS_DISABLE)
- return regmap_write_bits(chip->regmap, pull_en_reg, bit, 0);
+ return regmap_update_bits(chip->regmap, pull_en_reg, bit, 0);
else
- return regmap_write_bits(chip->regmap, pull_en_reg, bit, bit);
+ return regmap_update_bits(chip->regmap, pull_en_reg, bit, bit);
}
static int pca953x_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
base-commit: 733923397fd95405a48f165c9b1fbc8c4b0a4681
--
2.39.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] gpio: pca953x: use regmap_update_bits() to improve efficiency
2025-07-09 20:10 [PATCH] gpio: pca953x: use regmap_update_bits() to improve efficiency Hugo Villeneuve
@ 2025-07-11 10:22 ` Bartosz Golaszewski
2025-07-14 13:33 ` Hugo Villeneuve
0 siblings, 1 reply; 3+ messages in thread
From: Bartosz Golaszewski @ 2025-07-11 10:22 UTC (permalink / raw)
To: Hugo Villeneuve; +Cc: Linus Walleij, Hugo Villeneuve, linux-gpio, linux-kernel
On Wed, Jul 9, 2025 at 10:10 PM Hugo Villeneuve <hugo@hugovil.com> wrote:
>
> From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
>
> Using regmap_update_bits() allows to reduce the number of I2C transfers
> when updating bits that haven't changed on non-volatile registers.
>
> For example on a PCAL6416, when changing a GPIO direction from input to
> output, the number of I2C transfers can be reduced from 4 to just 1 if
> the pull resistors configuration hasn't changed and the output value
> is the same as before.
>
> Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> ---
Nice! Can you rebase it on top of gpio/for-next, it doesn't apply
after recent changes to the driver.
Thanks!
Bart
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gpio: pca953x: use regmap_update_bits() to improve efficiency
2025-07-11 10:22 ` Bartosz Golaszewski
@ 2025-07-14 13:33 ` Hugo Villeneuve
0 siblings, 0 replies; 3+ messages in thread
From: Hugo Villeneuve @ 2025-07-14 13:33 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Hugo Villeneuve, linux-gpio, linux-kernel
On Fri, 11 Jul 2025 12:22:40 +0200
Bartosz Golaszewski <brgl@bgdev.pl> wrote:
Hi Bart,
> On Wed, Jul 9, 2025 at 10:10 PM Hugo Villeneuve <hugo@hugovil.com> wrote:
> >
> > From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> >
> > Using regmap_update_bits() allows to reduce the number of I2C transfers
> > when updating bits that haven't changed on non-volatile registers.
> >
> > For example on a PCAL6416, when changing a GPIO direction from input to
> > output, the number of I2C transfers can be reduced from 4 to just 1 if
> > the pull resistors configuration hasn't changed and the output value
> > is the same as before.
> >
> > Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> > ---
>
> Nice! Can you rebase it on top of gpio/for-next, it doesn't apply
> after recent changes to the driver.
Sure, I will send a V2 shortly.
Hugo.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-14 13:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-09 20:10 [PATCH] gpio: pca953x: use regmap_update_bits() to improve efficiency Hugo Villeneuve
2025-07-11 10:22 ` Bartosz Golaszewski
2025-07-14 13:33 ` Hugo Villeneuve
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).