Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 164814
b: refs/heads/master
c: a4177ee
h: refs/heads/master
v: v3
  • Loading branch information
Jani Nikula authored and Linus Torvalds committed Sep 23, 2009
1 parent 0a72e00 commit fec8ab1
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d8c1acb1664d17dd995e34507533321e986d9215
refs/heads/master: a4177ee7f1a83eecb1d75e85d32664b023ef65e9
10 changes: 10 additions & 0 deletions trunk/Documentation/gpio.txt
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,11 @@ requested using gpio_request():
/* reverse gpio_export() */
void gpio_unexport();

/* create a sysfs link to an exported GPIO node */
int gpio_export_link(struct device *dev, const char *name,
unsigned gpio)


After a kernel driver requests a GPIO, it may only be made available in
the sysfs interface by gpio_export(). The driver can control whether the
signal direction may change. This helps drivers prevent userspace code
Expand All @@ -563,3 +568,8 @@ from accidentally clobbering important system state.
This explicit exporting can help with debugging (by making some kinds
of experiments easier), or can provide an always-there interface that's
suitable for documenting as part of a board support package.

After the GPIO has been exported, gpio_export_link() allows creating
symlinks from elsewhere in sysfs to the GPIO sysfs node. Drivers can
use this to provide the interface under their own device in sysfs with
a descriptive name.
45 changes: 45 additions & 0 deletions trunk/drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,51 @@ static int match_export(struct device *dev, void *data)
return dev_get_drvdata(dev) == data;
}

/**
* gpio_export_link - create a sysfs link to an exported GPIO node
* @dev: device under which to create symlink
* @name: name of the symlink
* @gpio: gpio to create symlink to, already exported
*
* Set up a symlink from /sys/.../dev/name to /sys/class/gpio/gpioN
* node. Caller is responsible for unlinking.
*
* Returns zero on success, else an error.
*/
int gpio_export_link(struct device *dev, const char *name, unsigned gpio)
{
struct gpio_desc *desc;
int status = -EINVAL;

if (!gpio_is_valid(gpio))
goto done;

mutex_lock(&sysfs_lock);

desc = &gpio_desc[gpio];

if (test_bit(FLAG_EXPORT, &desc->flags)) {
struct device *tdev;

tdev = class_find_device(&gpio_class, NULL, desc, match_export);
if (tdev != NULL) {
status = sysfs_create_link(&dev->kobj, &tdev->kobj,
name);
} else {
status = -ENODEV;
}
}

mutex_unlock(&sysfs_lock);

done:
if (status)
pr_debug("%s: gpio%d status %d\n", __func__, gpio, status);

return status;
}
EXPORT_SYMBOL_GPL(gpio_export_link);

/**
* gpio_unexport - reverse effect of gpio_export()
* @gpio: gpio to make unavailable
Expand Down
8 changes: 8 additions & 0 deletions trunk/include/asm-generic/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ extern int __gpio_to_irq(unsigned gpio);
* but more typically is configured entirely from userspace.
*/
extern int gpio_export(unsigned gpio, bool direction_may_change);
extern int gpio_export_link(struct device *dev, const char *name,
unsigned gpio);
extern void gpio_unexport(unsigned gpio);

#endif /* CONFIG_GPIO_SYSFS */
Expand Down Expand Up @@ -185,6 +187,12 @@ static inline int gpio_export(unsigned gpio, bool direction_may_change)
return -ENOSYS;
}

static inline int gpio_export_link(struct device *dev, const char *name,
unsigned gpio)
{
return -ENOSYS;
}

static inline void gpio_unexport(unsigned gpio)
{
}
Expand Down
11 changes: 11 additions & 0 deletions trunk/include/linux/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <linux/types.h>
#include <linux/errno.h>

struct device;

/*
* Some platforms don't support the GPIO programming interface.
*
Expand Down Expand Up @@ -89,6 +91,15 @@ static inline int gpio_export(unsigned gpio, bool direction_may_change)
return -EINVAL;
}

static inline int gpio_export_link(struct device *dev, const char *name,
unsigned gpio)
{
/* GPIO can never have been exported */
WARN_ON(1);
return -EINVAL;
}


static inline void gpio_unexport(unsigned gpio)
{
/* GPIO can never have been exported */
Expand Down

0 comments on commit fec8ab1

Please sign in to comment.