All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] gpio: pca953x: Improve bias setting
@ 2021-09-23 22:46 Andy Shevchenko
  2021-10-01  9:58 ` Bartosz Golaszewski
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2021-09-23 22:46 UTC (permalink / raw)
  To: Andy Shevchenko, linux-gpio, linux-kernel
  Cc: Linus Walleij, Bartosz Golaszewski, Thomas Petazzoni

The commit 15add06841a3 ("gpio: pca953x: add ->set_config implementation")
introduced support for bias setting. However this, due to being half-baked,
brought potential issues:
 - the turning bias via disabling makes the pin floating for a while;
 - once enabled, bias can't be disabled.

Fix all these by adding support for bias disabling and move the disabling
part under the corresponding conditional.

While at it, add support for default setting, since it's cheap to add.

Fixes: 15add06841a3 ("gpio: pca953x: add ->set_config implementation")
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpio-pca953x.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index f5cfc0698799..dac4d772a4d1 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -566,21 +566,21 @@ static int pca953x_gpio_set_pull_up_down(struct pca953x_chip *chip,
 
 	mutex_lock(&chip->i2c_lock);
 
-	/* Disable pull-up/pull-down */
-	ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, 0);
-	if (ret)
-		goto exit;
-
 	/* Configure pull-up/pull-down */
 	if (config == PIN_CONFIG_BIAS_PULL_UP)
 		ret = regmap_write_bits(chip->regmap, pull_sel_reg, bit, bit);
 	else if (config == PIN_CONFIG_BIAS_PULL_DOWN)
 		ret = regmap_write_bits(chip->regmap, pull_sel_reg, bit, 0);
+	else
+		ret = 0;
 	if (ret)
 		goto exit;
 
-	/* Enable pull-up/pull-down */
-	ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, bit);
+	/* Disable/Enable pull-up/pull-down */
+	if (config == PIN_CONFIG_BIAS_DISABLE)
+		ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, 0);
+	else
+		ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, bit);
 
 exit:
 	mutex_unlock(&chip->i2c_lock);
@@ -594,7 +594,9 @@ static int pca953x_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
 
 	switch (pinconf_to_config_param(config)) {
 	case PIN_CONFIG_BIAS_PULL_UP:
+	case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
 	case PIN_CONFIG_BIAS_PULL_DOWN:
+	case PIN_CONFIG_BIAS_DISABLE:
 		return pca953x_gpio_set_pull_up_down(chip, offset, config);
 	default:
 		return -ENOTSUPP;
-- 
2.33.0


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

* Re: [PATCH v1 1/1] gpio: pca953x: Improve bias setting
  2021-09-23 22:46 [PATCH v1 1/1] gpio: pca953x: Improve bias setting Andy Shevchenko
@ 2021-10-01  9:58 ` Bartosz Golaszewski
  0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2021-10-01  9:58 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-gpio, LKML, Linus Walleij, Thomas Petazzoni

On Fri, Sep 24, 2021 at 12:46 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> The commit 15add06841a3 ("gpio: pca953x: add ->set_config implementation")
> introduced support for bias setting. However this, due to being half-baked,
> brought potential issues:
>  - the turning bias via disabling makes the pin floating for a while;
>  - once enabled, bias can't be disabled.
>
> Fix all these by adding support for bias disabling and move the disabling
> part under the corresponding conditional.
>
> While at it, add support for default setting, since it's cheap to add.
>
> Fixes: 15add06841a3 ("gpio: pca953x: add ->set_config implementation")
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/gpio/gpio-pca953x.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
> index f5cfc0698799..dac4d772a4d1 100644
> --- a/drivers/gpio/gpio-pca953x.c
> +++ b/drivers/gpio/gpio-pca953x.c
> @@ -566,21 +566,21 @@ static int pca953x_gpio_set_pull_up_down(struct pca953x_chip *chip,
>
>         mutex_lock(&chip->i2c_lock);
>
> -       /* Disable pull-up/pull-down */
> -       ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, 0);
> -       if (ret)
> -               goto exit;
> -
>         /* Configure pull-up/pull-down */
>         if (config == PIN_CONFIG_BIAS_PULL_UP)
>                 ret = regmap_write_bits(chip->regmap, pull_sel_reg, bit, bit);
>         else if (config == PIN_CONFIG_BIAS_PULL_DOWN)
>                 ret = regmap_write_bits(chip->regmap, pull_sel_reg, bit, 0);
> +       else
> +               ret = 0;
>         if (ret)
>                 goto exit;
>
> -       /* Enable pull-up/pull-down */
> -       ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, bit);
> +       /* Disable/Enable pull-up/pull-down */
> +       if (config == PIN_CONFIG_BIAS_DISABLE)
> +               ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, 0);
> +       else
> +               ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, bit);
>
>  exit:
>         mutex_unlock(&chip->i2c_lock);
> @@ -594,7 +594,9 @@ static int pca953x_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
>
>         switch (pinconf_to_config_param(config)) {
>         case PIN_CONFIG_BIAS_PULL_UP:
> +       case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
>         case PIN_CONFIG_BIAS_PULL_DOWN:
> +       case PIN_CONFIG_BIAS_DISABLE:
>                 return pca953x_gpio_set_pull_up_down(chip, offset, config);
>         default:
>                 return -ENOTSUPP;
> --
> 2.33.0
>

Applied, thanks!

Bart

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

end of thread, other threads:[~2021-10-01  9:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-23 22:46 [PATCH v1 1/1] gpio: pca953x: Improve bias setting Andy Shevchenko
2021-10-01  9:58 ` 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.