diff options
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r-- | drivers/gpio/gpiolib.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 86ef3461ec06..b83b7e491f76 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -1320,6 +1320,53 @@ EXPORT_SYMBOL_GPL(gpiochip_find); | |||
1320 | #ifdef CONFIG_PINCTRL | 1320 | #ifdef CONFIG_PINCTRL |
1321 | 1321 | ||
1322 | /** | 1322 | /** |
1323 | * gpiochip_add_pingroup_range() - add a range for GPIO <-> pin mapping | ||
1324 | * @chip: the gpiochip to add the range for | ||
1325 | * @pinctrl: the dev_name() of the pin controller to map to | ||
1326 | * @gpio_offset: the start offset in the current gpio_chip number space | ||
1327 | * @pin_group: name of the pin group inside the pin controller | ||
1328 | */ | ||
1329 | int gpiochip_add_pingroup_range(struct gpio_chip *chip, | ||
1330 | struct pinctrl_dev *pctldev, | ||
1331 | unsigned int gpio_offset, const char *pin_group) | ||
1332 | { | ||
1333 | struct gpio_pin_range *pin_range; | ||
1334 | int ret; | ||
1335 | |||
1336 | pin_range = kzalloc(sizeof(*pin_range), GFP_KERNEL); | ||
1337 | if (!pin_range) { | ||
1338 | pr_err("%s: GPIO chip: failed to allocate pin ranges\n", | ||
1339 | chip->label); | ||
1340 | return -ENOMEM; | ||
1341 | } | ||
1342 | |||
1343 | /* Use local offset as range ID */ | ||
1344 | pin_range->range.id = gpio_offset; | ||
1345 | pin_range->range.gc = chip; | ||
1346 | pin_range->range.name = chip->label; | ||
1347 | pin_range->range.base = chip->base + gpio_offset; | ||
1348 | pin_range->pctldev = pctldev; | ||
1349 | |||
1350 | ret = pinctrl_get_group_pins(pctldev, pin_group, | ||
1351 | &pin_range->range.pins, | ||
1352 | &pin_range->range.npins); | ||
1353 | if (ret < 0) | ||
1354 | return ret; | ||
1355 | |||
1356 | pinctrl_add_gpio_range(pctldev, &pin_range->range); | ||
1357 | |||
1358 | pr_debug("GPIO chip %s: created GPIO range %d->%d ==> %s PINGRP %s\n", | ||
1359 | chip->label, gpio_offset, | ||
1360 | gpio_offset + pin_range->range.npins - 1, | ||
1361 | pinctrl_dev_get_devname(pctldev), pin_group); | ||
1362 | |||
1363 | list_add_tail(&pin_range->node, &chip->pin_ranges); | ||
1364 | |||
1365 | return 0; | ||
1366 | } | ||
1367 | EXPORT_SYMBOL_GPL(gpiochip_add_pingroup_range); | ||
1368 | |||
1369 | /** | ||
1323 | * gpiochip_add_pin_range() - add a range for GPIO <-> pin mapping | 1370 | * gpiochip_add_pin_range() - add a range for GPIO <-> pin mapping |
1324 | * @chip: the gpiochip to add the range for | 1371 | * @chip: the gpiochip to add the range for |
1325 | * @pinctrl_name: the dev_name() of the pin controller to map to | 1372 | * @pinctrl_name: the dev_name() of the pin controller to map to |