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.
Unified · Split
| @@ -3431,6 +3431,26 @@ set_output_flag: · 3430 unmodified lines | ||
| 3431 | 3431 | } |
| 3432 | 3432 | EXPORT_SYMBOL_GPL(gpiod_direction_output); |
| 3433 | 3433 | |
| 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 | + | |
| 3434 | 3454 | /** |
| 3435 | 3455 | * gpiod_set_debounce - sets @debounce time for a GPIO |
| 3436 | 3456 | * @desc: descriptor of the GPIO for which to set debounce time |
| @@ -3442,14 +3462,10 @@ EXPORT_SYMBOL_GPL(gpiod_direction_output); · 5 unmodified lines | ||
| 3442 | 3462 | */ |
| 3443 | 3463 | int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) |
| 3444 | 3464 | { |
| 3445 | − struct gpio_chip *chip; | |
| 3446 | − unsigned long config; | |
| 3447 | − | |
| 3448 | − VALIDATE_DESC(desc); | |
| 3449 | − chip = desc->gdev->chip; | |
| 3465 | + unsigned long config; | |
| 3450 | 3466 | |
| 3451 | 3467 | 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); | |
| 3453 | 3469 | } |
| 3454 | 3470 | EXPORT_SYMBOL_GPL(gpiod_set_debounce); |
| 3455 | 3471 | |
| @@ -157,6 +157,7 @@ int gpiod_set_raw_array_value_cansleep(unsigned int array_size, · 156 unmodified lines | ||
| 157 | 157 | struct gpio_array *array_info, |
| 158 | 158 | unsigned long *value_bitmap); |
| 159 | 159 | |
| 160 | +int gpiod_set_config(struct gpio_desc *desc, unsigned long config); | |
| 160 | 161 | int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); |
| 161 | 162 | int gpiod_set_transitory(struct gpio_desc *desc, bool transitory); |
| 162 | 163 | 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, · 310 unmodified lines | ||
| 473 | 474 | return 0; |
| 474 | 475 | } |
| 475 | 476 | |
| 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 | + | |
| 476 | 484 | static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) |
| 477 | 485 | { |
| 478 | 486 | /* GPIO can never have been requested */ |