diff options
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r-- | drivers/gpio/gpiolib.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 51a8d4103be5..aef6b3d8e2cf 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -505,6 +505,51 @@ static int match_export(struct device *dev, void *data) | |||
505 | } | 505 | } |
506 | 506 | ||
507 | /** | 507 | /** |
508 | * gpio_export_link - create a sysfs link to an exported GPIO node | ||
509 | * @dev: device under which to create symlink | ||
510 | * @name: name of the symlink | ||
511 | * @gpio: gpio to create symlink to, already exported | ||
512 | * | ||
513 | * Set up a symlink from /sys/.../dev/name to /sys/class/gpio/gpioN | ||
514 | * node. Caller is responsible for unlinking. | ||
515 | * | ||
516 | * Returns zero on success, else an error. | ||
517 | */ | ||
518 | int gpio_export_link(struct device *dev, const char *name, unsigned gpio) | ||
519 | { | ||
520 | struct gpio_desc *desc; | ||
521 | int status = -EINVAL; | ||
522 | |||
523 | if (!gpio_is_valid(gpio)) | ||
524 | goto done; | ||
525 | |||
526 | mutex_lock(&sysfs_lock); | ||
527 | |||
528 | desc = &gpio_desc[gpio]; | ||
529 | |||
530 | if (test_bit(FLAG_EXPORT, &desc->flags)) { | ||
531 | struct device *tdev; | ||
532 | |||
533 | tdev = class_find_device(&gpio_class, NULL, desc, match_export); | ||
534 | if (tdev != NULL) { | ||
535 | status = sysfs_create_link(&dev->kobj, &tdev->kobj, | ||
536 | name); | ||
537 | } else { | ||
538 | status = -ENODEV; | ||
539 | } | ||
540 | } | ||
541 | |||
542 | mutex_unlock(&sysfs_lock); | ||
543 | |||
544 | done: | ||
545 | if (status) | ||
546 | pr_debug("%s: gpio%d status %d\n", __func__, gpio, status); | ||
547 | |||
548 | return status; | ||
549 | } | ||
550 | EXPORT_SYMBOL_GPL(gpio_export_link); | ||
551 | |||
552 | /** | ||
508 | * gpio_unexport - reverse effect of gpio_export() | 553 | * gpio_unexport - reverse effect of gpio_export() |
509 | * @gpio: gpio to make unavailable | 554 | * @gpio: gpio to make unavailable |
510 | * | 555 | * |