Skip to content

Commit

Permalink
gpio: add flags to export GPIOs when requesting
Browse files Browse the repository at this point in the history
Introduce new flags to automatically export GPIOs when using the convenience
functions gpio_request_one() or gpio_request_array(). This eases support for
custom boards where lots of GPIOs need to be exported for customer
applications.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
  • Loading branch information
Wolfram Sang authored and Grant Likely committed Apr 6, 2012
1 parent dd775ae commit fc3a1f0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Documentation/gpio.txt
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ where 'flags' is currently defined to specify the following properties:
* GPIOF_OPEN_DRAIN - gpio pin is open drain type.
* GPIOF_OPEN_SOURCE - gpio pin is open source type.

* GPIOF_EXPORT_DIR_FIXED - export gpio to sysfs, keep direction
* GPIOF_EXPORT_DIR_CHANGEABLE - also export, allow changing direction

since GPIOF_INIT_* are only valid when configured as output, so group valid
combinations as:

Expand Down
12 changes: 11 additions & 1 deletion drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1302,8 +1302,18 @@ int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
(flags & GPIOF_INIT_HIGH) ? 1 : 0);

if (err)
gpio_free(gpio);
goto free_gpio;

if (flags & GPIOF_EXPORT) {
err = gpio_export(gpio, flags & GPIOF_EXPORT_CHANGEABLE);
if (err)
goto free_gpio;
}

return 0;

free_gpio:
gpio_free(gpio);
return err;
}
EXPORT_SYMBOL_GPL(gpio_request_one);
Expand Down
5 changes: 5 additions & 0 deletions include/linux/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
/* Gpio pin is open source */
#define GPIOF_OPEN_SOURCE (1 << 3)

#define GPIOF_EXPORT (1 << 2)
#define GPIOF_EXPORT_CHANGEABLE (1 << 3)
#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)

/**
* struct gpio - a structure describing a GPIO with configuration
* @gpio: the GPIO number
Expand Down

0 comments on commit fc3a1f0

Please sign in to comment.