Commit d90f3685 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski

gpiolib: have a single place of calling set_config()

Instead of calling the gpiochip's set_config() callback directly and
checking its existence every time - just add a new routine that performs
this check internally. Call it in gpio_set_config() and
gpiod_set_transitory(). Also call it in gpiod_set_debounce() and drop
the check for chip->set() as it's irrelevant to this config option.
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent a9001764
...@@ -3042,6 +3042,15 @@ EXPORT_SYMBOL_GPL(gpiochip_free_own_desc); ...@@ -3042,6 +3042,15 @@ EXPORT_SYMBOL_GPL(gpiochip_free_own_desc);
* rely on gpio_request() having been called beforehand. * rely on gpio_request() having been called beforehand.
*/ */
static int gpio_do_set_config(struct gpio_chip *gc, unsigned int offset,
enum pin_config_param mode)
{
if (!gc->set_config)
return -ENOTSUPP;
return gc->set_config(gc, offset, mode);
}
static int gpio_set_config(struct gpio_chip *gc, unsigned int offset, static int gpio_set_config(struct gpio_chip *gc, unsigned int offset,
enum pin_config_param mode) enum pin_config_param mode)
{ {
...@@ -3060,7 +3069,7 @@ static int gpio_set_config(struct gpio_chip *gc, unsigned int offset, ...@@ -3060,7 +3069,7 @@ static int gpio_set_config(struct gpio_chip *gc, unsigned int offset,
} }
config = PIN_CONF_PACKED(mode, arg); config = PIN_CONF_PACKED(mode, arg);
return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP; return gpio_do_set_config(gc, offset, mode);
} }
static int gpio_set_bias(struct gpio_chip *chip, struct gpio_desc *desc) static int gpio_set_bias(struct gpio_chip *chip, struct gpio_desc *desc)
...@@ -3294,15 +3303,9 @@ int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) ...@@ -3294,15 +3303,9 @@ int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
VALIDATE_DESC(desc); VALIDATE_DESC(desc);
chip = desc->gdev->chip; chip = desc->gdev->chip;
if (!chip->set || !chip->set_config) {
gpiod_dbg(desc,
"%s: missing set() or set_config() operations\n",
__func__);
return -ENOTSUPP;
}
config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce); config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
return chip->set_config(chip, gpio_chip_hwgpio(desc), config); return gpio_do_set_config(chip, gpio_chip_hwgpio(desc), config);
} }
EXPORT_SYMBOL_GPL(gpiod_set_debounce); EXPORT_SYMBOL_GPL(gpiod_set_debounce);
...@@ -3339,7 +3342,7 @@ int gpiod_set_transitory(struct gpio_desc *desc, bool transitory) ...@@ -3339,7 +3342,7 @@ int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE, packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE,
!transitory); !transitory);
gpio = gpio_chip_hwgpio(desc); gpio = gpio_chip_hwgpio(desc);
rc = chip->set_config(chip, gpio, packed); rc = gpio_do_set_config(chip, gpio, packed);
if (rc == -ENOTSUPP) { if (rc == -ENOTSUPP) {
dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n", dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n",
gpio); gpio);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment