All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: pca953x: use the correct register address to do regcache sync
@ 2022-05-30 10:48 haibo.chen
  2022-06-01 17:20 ` Bartosz Golaszewski
  0 siblings, 1 reply; 2+ messages in thread
From: haibo.chen @ 2022-05-30 10:48 UTC (permalink / raw)
  To: linus.walleij, brgl, marek.vasut; +Cc: linux-gpio, linux-imx, haibo.chen

From: Haibo Chen <haibo.chen@nxp.com>

For regcache_sync_region, need to use pca953x_recalc_addr() to get
the real register address.

Fixes: b76574300504 ("gpio: pca953x: Restore registers after suspend/resume cycle")
Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
---
 drivers/gpio/gpio-pca953x.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index b444c6ab958b..08bc52c3cdcb 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -1120,20 +1120,21 @@ static int pca953x_regcache_sync(struct device *dev)
 {
 	struct pca953x_chip *chip = dev_get_drvdata(dev);
 	int ret;
+	u8 regaddr;
 
 	/*
 	 * The ordering between direction and output is important,
 	 * sync these registers first and only then sync the rest.
 	 */
-	ret = regcache_sync_region(chip->regmap, chip->regs->direction,
-				   chip->regs->direction + NBANK(chip));
+	regaddr = pca953x_recalc_addr(chip, chip->regs->direction, 0);
+	ret = regcache_sync_region(chip->regmap, regaddr, regaddr + NBANK(chip));
 	if (ret) {
 		dev_err(dev, "Failed to sync GPIO dir registers: %d\n", ret);
 		return ret;
 	}
 
-	ret = regcache_sync_region(chip->regmap, chip->regs->output,
-				   chip->regs->output + NBANK(chip));
+	regaddr = pca953x_recalc_addr(chip, chip->regs->output, 0);
+	ret = regcache_sync_region(chip->regmap, regaddr, regaddr + NBANK(chip));
 	if (ret) {
 		dev_err(dev, "Failed to sync GPIO out registers: %d\n", ret);
 		return ret;
@@ -1141,16 +1142,18 @@ static int pca953x_regcache_sync(struct device *dev)
 
 #ifdef CONFIG_GPIO_PCA953X_IRQ
 	if (chip->driver_data & PCA_PCAL) {
-		ret = regcache_sync_region(chip->regmap, PCAL953X_IN_LATCH,
-					   PCAL953X_IN_LATCH + NBANK(chip));
+		regaddr = pca953x_recalc_addr(chip, PCAL953X_IN_LATCH, 0);
+		ret = regcache_sync_region(chip->regmap, regaddr,
+					   regaddr + NBANK(chip));
 		if (ret) {
 			dev_err(dev, "Failed to sync INT latch registers: %d\n",
 				ret);
 			return ret;
 		}
 
-		ret = regcache_sync_region(chip->regmap, PCAL953X_INT_MASK,
-					   PCAL953X_INT_MASK + NBANK(chip));
+		regaddr = pca953x_recalc_addr(chip, PCAL953X_INT_MASK, 0);
+		ret = regcache_sync_region(chip->regmap, regaddr,
+					   regaddr + NBANK(chip));
 		if (ret) {
 			dev_err(dev, "Failed to sync INT mask registers: %d\n",
 				ret);
-- 
2.25.1


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

* Re: [PATCH] gpio: pca953x: use the correct register address to do regcache sync
  2022-05-30 10:48 [PATCH] gpio: pca953x: use the correct register address to do regcache sync haibo.chen
@ 2022-06-01 17:20 ` Bartosz Golaszewski
  0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2022-06-01 17:20 UTC (permalink / raw)
  To: haibo.chen
  Cc: Linus Walleij, Marek Vasut, open list:GPIO SUBSYSTEM, NXP Linux Team

On Mon, May 30, 2022 at 1:02 PM <haibo.chen@nxp.com> wrote:
>
> From: Haibo Chen <haibo.chen@nxp.com>
>
> For regcache_sync_region, need to use pca953x_recalc_addr() to get
> the real register address.
>
> Fixes: b76574300504 ("gpio: pca953x: Restore registers after suspend/resume cycle")
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
> ---
>  drivers/gpio/gpio-pca953x.c | 19 +++++++++++--------
>  1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
> index b444c6ab958b..08bc52c3cdcb 100644
> --- a/drivers/gpio/gpio-pca953x.c
> +++ b/drivers/gpio/gpio-pca953x.c
> @@ -1120,20 +1120,21 @@ static int pca953x_regcache_sync(struct device *dev)
>  {
>         struct pca953x_chip *chip = dev_get_drvdata(dev);
>         int ret;
> +       u8 regaddr;
>
>         /*
>          * The ordering between direction and output is important,
>          * sync these registers first and only then sync the rest.
>          */
> -       ret = regcache_sync_region(chip->regmap, chip->regs->direction,
> -                                  chip->regs->direction + NBANK(chip));
> +       regaddr = pca953x_recalc_addr(chip, chip->regs->direction, 0);
> +       ret = regcache_sync_region(chip->regmap, regaddr, regaddr + NBANK(chip));
>         if (ret) {
>                 dev_err(dev, "Failed to sync GPIO dir registers: %d\n", ret);
>                 return ret;
>         }
>
> -       ret = regcache_sync_region(chip->regmap, chip->regs->output,
> -                                  chip->regs->output + NBANK(chip));
> +       regaddr = pca953x_recalc_addr(chip, chip->regs->output, 0);
> +       ret = regcache_sync_region(chip->regmap, regaddr, regaddr + NBANK(chip));
>         if (ret) {
>                 dev_err(dev, "Failed to sync GPIO out registers: %d\n", ret);
>                 return ret;
> @@ -1141,16 +1142,18 @@ static int pca953x_regcache_sync(struct device *dev)
>
>  #ifdef CONFIG_GPIO_PCA953X_IRQ
>         if (chip->driver_data & PCA_PCAL) {
> -               ret = regcache_sync_region(chip->regmap, PCAL953X_IN_LATCH,
> -                                          PCAL953X_IN_LATCH + NBANK(chip));
> +               regaddr = pca953x_recalc_addr(chip, PCAL953X_IN_LATCH, 0);
> +               ret = regcache_sync_region(chip->regmap, regaddr,
> +                                          regaddr + NBANK(chip));
>                 if (ret) {
>                         dev_err(dev, "Failed to sync INT latch registers: %d\n",
>                                 ret);
>                         return ret;
>                 }
>
> -               ret = regcache_sync_region(chip->regmap, PCAL953X_INT_MASK,
> -                                          PCAL953X_INT_MASK + NBANK(chip));
> +               regaddr = pca953x_recalc_addr(chip, PCAL953X_INT_MASK, 0);
> +               ret = regcache_sync_region(chip->regmap, regaddr,
> +                                          regaddr + NBANK(chip));
>                 if (ret) {
>                         dev_err(dev, "Failed to sync INT mask registers: %d\n",
>                                 ret);
> --
> 2.25.1
>

Queued for fixes, thanks!

Bart

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

end of thread, other threads:[~2022-06-01 17:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-30 10:48 [PATCH] gpio: pca953x: use the correct register address to do regcache sync haibo.chen
2022-06-01 17:20 ` Bartosz Golaszewski

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.