aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2014-07-25 10:38:36 -0400
committerLinus Walleij <linus.walleij@linaro.org>2014-07-28 06:28:05 -0400
commit39b2bbe3d715cf5013b5c48695ccdd25bd3bf120 (patch)
tree019129dbc7b1cc10200342602fe7eac47230219e /Documentation
parent9b5b33f6256a941d9d34f219b508ba7140a39dba (diff)
gpio: add flags argument to gpiod_get*() functions
The huge majority of GPIOs have their direction and initial value set right after being obtained by one of the gpiod_get() functions. The integer GPIO API had gpio_request_one() that took a convenience flags parameter allowing to specify an direction and value applied to the returned GPIO. This feature greatly simplifies client code and ensures errors are always handled properly. A similar feature has been requested for the gpiod API. Since setting the direction of a GPIO is so often the very next action done after obtaining its descriptor, we prefer to extend the existing functions instead of introducing new functions that would raise the number of gpiod getters to 16 (!). The drawback of this approach is that all gpiod clients need to be updated. To limit the pain, temporary macros are introduced that allow gpiod_get*() to be called with or without the extra flags argument. They will be removed once all consumer code has been updated. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Mark Brown <broonie@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/gpio/consumer.txt26
1 files changed, 20 insertions, 6 deletions
diff --git a/Documentation/gpio/consumer.txt b/Documentation/gpio/consumer.txt
index d8abfc31abbe..76546324e968 100644
--- a/Documentation/gpio/consumer.txt
+++ b/Documentation/gpio/consumer.txt
@@ -29,13 +29,24 @@ gpiod_get() functions. Like many other kernel subsystems, gpiod_get() takes the
29device that will use the GPIO and the function the requested GPIO is supposed to 29device that will use the GPIO and the function the requested GPIO is supposed to
30fulfill: 30fulfill:
31 31
32 struct gpio_desc *gpiod_get(struct device *dev, const char *con_id) 32 struct gpio_desc *gpiod_get(struct device *dev, const char *con_id,
33 enum gpiod_flags flags)
33 34
34If a function is implemented by using several GPIOs together (e.g. a simple LED 35If a function is implemented by using several GPIOs together (e.g. a simple LED
35device that displays digits), an additional index argument can be specified: 36device that displays digits), an additional index argument can be specified:
36 37
37 struct gpio_desc *gpiod_get_index(struct device *dev, 38 struct gpio_desc *gpiod_get_index(struct device *dev,
38 const char *con_id, unsigned int idx) 39 const char *con_id, unsigned int idx,
40 enum gpiod_flags flags)
41
42The flags parameter is used to optionally specify a direction and initial value
43for the GPIO. Values can be:
44
45* GPIOD_ASIS or 0 to not initialize the GPIO at all. The direction must be set
46 later with one of the dedicated functions.
47* GPIOD_IN to initialize the GPIO as input.
48* GPIOD_OUT_LOW to initialize the GPIO as output with a value of 0.
49* GPIOD_OUT_HIGH to initialize the GPIO as output with a value of 1.
39 50
40Both functions return either a valid GPIO descriptor, or an error code checkable 51Both functions return either a valid GPIO descriptor, or an error code checkable
41with IS_ERR() (they will never return a NULL pointer). -ENOENT will be returned 52with IS_ERR() (they will never return a NULL pointer). -ENOENT will be returned
@@ -46,11 +57,13 @@ errors and an absence of GPIO for optional GPIO parameters.
46 57
47Device-managed variants of these functions are also defined: 58Device-managed variants of these functions are also defined:
48 59
49 struct gpio_desc *devm_gpiod_get(struct device *dev, const char *con_id) 60 struct gpio_desc *devm_gpiod_get(struct device *dev, const char *con_id,
61 enum gpiod_flags flags)
50 62
51 struct gpio_desc *devm_gpiod_get_index(struct device *dev, 63 struct gpio_desc *devm_gpiod_get_index(struct device *dev,
52 const char *con_id, 64 const char *con_id,
53 unsigned int idx) 65 unsigned int idx,
66 enum gpiod_flags flags)
54 67
55A GPIO descriptor can be disposed of using the gpiod_put() function: 68A GPIO descriptor can be disposed of using the gpiod_put() function:
56 69
@@ -67,8 +80,9 @@ Using GPIOs
67 80
68Setting Direction 81Setting Direction
69----------------- 82-----------------
70The first thing a driver must do with a GPIO is setting its direction. This is 83The first thing a driver must do with a GPIO is setting its direction. If no
71done by invoking one of the gpiod_direction_*() functions: 84direction-setting flags have been given to gpiod_get*(), this is done by
85invoking one of the gpiod_direction_*() functions:
72 86
73 int gpiod_direction_input(struct gpio_desc *desc) 87 int gpiod_direction_input(struct gpio_desc *desc)
74 int gpiod_direction_output(struct gpio_desc *desc, int value) 88 int gpiod_direction_output(struct gpio_desc *desc, int value)