Skip to content

Commit 8ced32f

Browse files
geertuLinus Walleij
authored andcommitted
gpiolib: Introduce gpiod_set_config()
The GPIO Aggregator will need a method to forward a .set_config() call to its parent gpiochip. This requires obtaining the gpio_chip and offset for a given gpio_desc. While gpiod_to_chip() is public, gpio_chip_hwgpio() is not, so there is currently no method to obtain the needed GPIO offset parameter. Hence introduce a public gpiod_set_config() helper, which invokes the .set_config() callback through a gpio_desc pointer, like is done for most other gpio_chip callbacks. Rewrite the existing gpiod_set_debounce() helper as a wrapper around gpiod_set_config(), to avoid duplication. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Link: https://lore.kernel.org/r/20200324135653.6676-5-geert+renesas@glider.be Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 06dd3f3 commit 8ced32f

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

‎drivers/gpio/gpiolib.c‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,6 +3431,26 @@ int gpiod_direction_output(struct gpio_desc *desc, int value)
34313431
}
34323432
EXPORT_SYMBOL_GPL(gpiod_direction_output);
34333433

3434+
/**
3435+
* gpiod_set_config - sets @config for a GPIO
3436+
* @desc: descriptor of the GPIO for which to set the configuration
3437+
* @config: Same packed config format as generic pinconf
3438+
*
3439+
* Returns:
3440+
* 0 on success, %-ENOTSUPP if the controller doesn't support setting the
3441+
* configuration.
3442+
*/
3443+
int gpiod_set_config(struct gpio_desc *desc, unsigned long config)
3444+
{
3445+
struct gpio_chip *chip;
3446+
3447+
VALIDATE_DESC(desc);
3448+
chip = desc->gdev->chip;
3449+
3450+
return gpio_do_set_config(chip, gpio_chip_hwgpio(desc), config);
3451+
}
3452+
EXPORT_SYMBOL_GPL(gpiod_set_config);
3453+
34343454
/**
34353455
* gpiod_set_debounce - sets @debounce time for a GPIO
34363456
* @desc: descriptor of the GPIO for which to set debounce time
@@ -3442,14 +3462,10 @@ EXPORT_SYMBOL_GPL(gpiod_direction_output);
34423462
*/
34433463
int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
34443464
{
3445-
struct gpio_chip *chip;
3446-
unsigned long config;
3447-
3448-
VALIDATE_DESC(desc);
3449-
chip = desc->gdev->chip;
3465+
unsigned long config;
34503466

34513467
config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
3452-
return gpio_do_set_config(chip, gpio_chip_hwgpio(desc), config);
3468+
return gpiod_set_config(desc, config);
34533469
}
34543470
EXPORT_SYMBOL_GPL(gpiod_set_debounce);
34553471

‎include/linux/gpio/consumer.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
157157
struct gpio_array *array_info,
158158
unsigned long *value_bitmap);
159159

160+
int gpiod_set_config(struct gpio_desc *desc, unsigned long config);
160161
int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
161162
int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
162163
void gpiod_toggle_active_low(struct gpio_desc *desc);
@@ -473,6 +474,13 @@ static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
473474
return 0;
474475
}
475476

477+
static inline int gpiod_set_config(struct gpio_desc *desc, unsigned long config)
478+
{
479+
/* GPIO can never have been requested */
480+
WARN_ON(desc);
481+
return -ENOSYS;
482+
}
483+
476484
static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
477485
{
478486
/* GPIO can never have been requested */

0 commit comments

Comments
 (0)