Skip to content

Commit 55a9968

Browse files
andy-shevbrgl
authored andcommitted
gpio: pca953x: Improve bias setting
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]>
1 parent be44918 commit 55a9968

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
@@ -559,21 +559,21 @@ static int pca953x_gpio_set_pull_up_down(struct pca953x_chip *chip,
559559

560560
mutex_lock(&chip->i2c_lock);
561561

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

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

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

588588
switch (pinconf_to_config_param(config)) {
589589
case PIN_CONFIG_BIAS_PULL_UP:
590+
case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
590591
case PIN_CONFIG_BIAS_PULL_DOWN:
592+
case PIN_CONFIG_BIAS_DISABLE:
591593
return pca953x_gpio_set_pull_up_down(chip, offset, config);
592594
default:
593595
return -ENOTSUPP;

0 commit comments

Comments
 (0)