gpiolib: add support to register sparse pin range

Add support to register for GPIO<->pin mapping using a list of non
consecutive pins. The core already supports sparse pin range (pins member
of struct pinctrl_gpio_range), but it was not possible to register one. If
pins is not NULL the core uses it, otherwise it assumes that a consecutive
pin range was registered and it uses pin_base.

The function gpiochip_add_pin_range() which allocates and fills the struct
pinctrl_gpio_range was renamed to gpiochip_add_pin_range_with_pins() and
the pins parameter was added.

Two new functions were added, gpiochip_add_pin_range() and
gpiochip_add_sparse_pin_range() to register a consecutive or sparse pins
range. Both use gpiochip_add_pin_range_with_pins().

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Thomas Richard <thomas.richard@bootlin.com>
Link: https://lore.kernel.org/r/20250811-aaeon-up-board-pinctrl-support-v9-1-29f0cbbdfb30@bootlin.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This commit is contained in:
Thomas Richard
2025-08-11 15:25:44 +02:00
committed by Bartosz Golaszewski
parent 8f5ae30d69
commit 181fe022ec
2 changed files with 68 additions and 12 deletions

View File

@@ -772,16 +772,50 @@ struct gpio_pin_range {
#ifdef CONFIG_PINCTRL
int gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name,
unsigned int gpio_offset, unsigned int pin_offset,
unsigned int npins);
int gpiochip_add_pin_range_with_pins(struct gpio_chip *gc,
const char *pinctl_name,
unsigned int gpio_offset,
unsigned int pin_offset,
unsigned int const *pins,
unsigned int npins);
int gpiochip_add_pingroup_range(struct gpio_chip *gc,
struct pinctrl_dev *pctldev,
unsigned int gpio_offset, const char *pin_group);
void gpiochip_remove_pin_ranges(struct gpio_chip *gc);
static inline int
gpiochip_add_pin_range(struct gpio_chip *gc,
const char *pinctl_name,
unsigned int gpio_offset,
unsigned int pin_offset,
unsigned int npins)
{
return gpiochip_add_pin_range_with_pins(gc, pinctl_name, gpio_offset,
pin_offset, NULL, npins);
}
static inline int
gpiochip_add_sparse_pin_range(struct gpio_chip *gc,
const char *pinctl_name,
unsigned int gpio_offset,
unsigned int const *pins,
unsigned int npins)
{
return gpiochip_add_pin_range_with_pins(gc, pinctl_name, gpio_offset, 0,
pins, npins);
}
#else /* ! CONFIG_PINCTRL */
static inline int
gpiochip_add_pin_range_with_pins(struct gpio_chip *gc,
const char *pinctl_name,
unsigned int gpio_offset,
unsigned int pin_offset,
unsigned int npins)
{
return 0;
}
static inline int
gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name,
unsigned int gpio_offset, unsigned int pin_offset,
@@ -789,6 +823,17 @@ gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name,
{
return 0;
}
static inline int
gpiochip_add_sparse_pin_range(struct gpio_chip *gc,
const char *pinctl_name,
unsigned int gpio_offset,
unsigned int const *pins,
unsigned int npins)
{
return 0;
}
static inline int
gpiochip_add_pingroup_range(struct gpio_chip *gc,
struct pinctrl_dev *pctldev,