Skip to content

Commit 17a027a

Browse files
andy-shevgregkh
authored andcommitted
gpio: pca953x: Improve bias setting
commit 55a9968 upstream. The commit 15add06 ("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: 15add06 ("gpio: pca953x: add ->set_config implementation") Cc: Thomas Petazzoni <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d84a69a commit 17a027a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

drivers/gpio/gpio-pca953x.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -558,21 +558,21 @@ static int pca953x_gpio_set_pull_up_down(struct pca953x_chip *chip,
558558

559559
mutex_lock(&chip->i2c_lock);
560560

561-
/* Disable pull-up/pull-down */
562-
ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, 0);
563-
if (ret)
564-
goto exit;
565-
566561
/* Configure pull-up/pull-down */
567562
if (config == PIN_CONFIG_BIAS_PULL_UP)
568563
ret = regmap_write_bits(chip->regmap, pull_sel_reg, bit, bit);
569564
else if (config == PIN_CONFIG_BIAS_PULL_DOWN)
570565
ret = regmap_write_bits(chip->regmap, pull_sel_reg, bit, 0);
566+
else
567+
ret = 0;
571568
if (ret)
572569
goto exit;
573570

574-
/* Enable pull-up/pull-down */
575-
ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, bit);
571+
/* Disable/Enable pull-up/pull-down */
572+
if (config == PIN_CONFIG_BIAS_DISABLE)
573+
ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, 0);
574+
else
575+
ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, bit);
576576

577577
exit:
578578
mutex_unlock(&chip->i2c_lock);
@@ -586,7 +586,9 @@ static int pca953x_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
586586

587587
switch (pinconf_to_config_param(config)) {
588588
case PIN_CONFIG_BIAS_PULL_UP:
589+
case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
589590
case PIN_CONFIG_BIAS_PULL_DOWN:
591+
case PIN_CONFIG_BIAS_DISABLE:
590592
return pca953x_gpio_set_pull_up_down(chip, offset, config);
591593
default:
592594
return -ENOTSUPP;

0 commit comments

Comments
 (0)