Skip to content

Commit d90f368

Browse files
committed
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: Bartosz Golaszewski <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Linus Walleij <[email protected]>
1 parent a900176 commit d90f368

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

drivers/gpio/gpiolib.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,6 +3042,15 @@ EXPORT_SYMBOL_GPL(gpiochip_free_own_desc);
30423042
* rely on gpio_request() having been called beforehand.
30433043
*/
30443044

3045+
static int gpio_do_set_config(struct gpio_chip *gc, unsigned int offset,
3046+
enum pin_config_param mode)
3047+
{
3048+
if (!gc->set_config)
3049+
return -ENOTSUPP;
3050+
3051+
return gc->set_config(gc, offset, mode);
3052+
}
3053+
30453054
static int gpio_set_config(struct gpio_chip *gc, unsigned int offset,
30463055
enum pin_config_param mode)
30473056
{
@@ -3060,7 +3069,7 @@ static int gpio_set_config(struct gpio_chip *gc, unsigned int offset,
30603069
}
30613070

30623071
config = PIN_CONF_PACKED(mode, arg);
3063-
return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP;
3072+
return gpio_do_set_config(gc, offset, mode);
30643073
}
30653074

30663075
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)
32943303

32953304
VALIDATE_DESC(desc);
32963305
chip = desc->gdev->chip;
3297-
if (!chip->set || !chip->set_config) {
3298-
gpiod_dbg(desc,
3299-
"%s: missing set() or set_config() operations\n",
3300-
__func__);
3301-
return -ENOTSUPP;
3302-
}
33033306

33043307
config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
3305-
return chip->set_config(chip, gpio_chip_hwgpio(desc), config);
3308+
return gpio_do_set_config(chip, gpio_chip_hwgpio(desc), config);
33063309
}
33073310
EXPORT_SYMBOL_GPL(gpiod_set_debounce);
33083311

@@ -3339,7 +3342,7 @@ int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
33393342
packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE,
33403343
!transitory);
33413344
gpio = gpio_chip_hwgpio(desc);
3342-
rc = chip->set_config(chip, gpio, packed);
3345+
rc = gpio_do_set_config(chip, gpio, packed);
33433346
if (rc == -ENOTSUPP) {
33443347
dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n",
33453348
gpio);

0 commit comments

Comments
 (0)