aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib.c
diff options
context:
space:
mode:
authorJani Nikula <ext-jani.1.nikula@nokia.com>2009-09-22 19:46:33 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-09-23 10:39:46 -0400
commita4177ee7f1a83eecb1d75e85d32664b023ef65e9 (patch)
tree614b12b1f28a1a9090d96bea33639265e3e79839 /drivers/gpio/gpiolib.c
parentd8c1acb1664d17dd995e34507533321e986d9215 (diff)
gpiolib: allow exported GPIO nodes to be named using sysfs links
Commit 926b663ce8215ba448960e1ff6e58b67a2c3b99b (gpiolib: allow GPIOs to be named) already provides naming on the chip level. This patch provides more flexibility by allowing multiple names where ever in sysfs on a per GPIO basis. Adapted from David Brownell's comments on a similar concept: http://lkml.org/lkml/2009/4/20/203. [randy.dunlap@oracle.com: fix build for CONFIG_GENERIC_GPIO=n] Signed-off-by: Jani Nikula <ext-jani.1.nikula@nokia.com> Acked-by: David Brownell <david-b@pacbell.net> Cc: Daniel Silverstone <dsilvers@simtec.co.uk> Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r--drivers/gpio/gpiolib.c45
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 */
518int 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
544done:
545 if (status)
546 pr_debug("%s: gpio%d status %d\n", __func__, gpio, status);
547
548 return status;
549}
550EXPORT_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 *