aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation
diff options
context:
space:
mode:
authorJonathan Neuschäfer <j.neuschaefer@gmx.net>2018-03-08 18:40:22 -0500
committerLinus Walleij <linus.walleij@linaro.org>2018-03-22 23:21:40 -0400
commit4e0edc4b3fe7ee2ecb07360146479dbbeb63cd5a (patch)
tree533aa51ffc883c0fe8c203308592c2615ad7be5c /Documentation
parent7ee2c13080c99e7ba01c45841e7fd61cdd37fc65 (diff)
Documentation: gpio: Move gpiod_* consumer documentation to driver-api
Move gpio/consumer.txt to driver-api/gpio/consumer.rst and make sure it builds cleanly as ReST. Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/driver-api/gpio/consumer.rst (renamed from Documentation/gpio/consumer.txt)85
-rw-r--r--Documentation/driver-api/gpio/index.rst1
-rw-r--r--Documentation/gpio/00-INDEX2
3 files changed, 44 insertions, 44 deletions
diff --git a/Documentation/gpio/consumer.txt b/Documentation/driver-api/gpio/consumer.rst
index d53e5b5cfc9c..c71a50d85b50 100644
--- a/Documentation/gpio/consumer.txt
+++ b/Documentation/driver-api/gpio/consumer.rst
@@ -1,3 +1,4 @@
1==================================
1GPIO Descriptor Consumer Interface 2GPIO Descriptor Consumer Interface
2================================== 3==================================
3 4
@@ -30,10 +31,10 @@ warnings. These stubs are used for two use cases:
30 be met with console warnings that may be perceived as intimidating. 31 be met with console warnings that may be perceived as intimidating.
31 32
32All the functions that work with the descriptor-based GPIO interface are 33All the functions that work with the descriptor-based GPIO interface are
33prefixed with gpiod_. The gpio_ prefix is used for the legacy interface. No 34prefixed with ``gpiod_``. The ``gpio_`` prefix is used for the legacy
34other function in the kernel should use these prefixes. The use of the legacy 35interface. No other function in the kernel should use these prefixes. The use
35functions is strongly discouraged, new code should use <linux/gpio/consumer.h> 36of the legacy functions is strongly discouraged, new code should use
36and descriptors exclusively. 37<linux/gpio/consumer.h> and descriptors exclusively.
37 38
38 39
39Obtaining and Disposing GPIOs 40Obtaining and Disposing GPIOs
@@ -43,13 +44,13 @@ With the descriptor-based interface, GPIOs are identified with an opaque,
43non-forgeable handler that must be obtained through a call to one of the 44non-forgeable handler that must be obtained through a call to one of the
44gpiod_get() functions. Like many other kernel subsystems, gpiod_get() takes the 45gpiod_get() functions. Like many other kernel subsystems, gpiod_get() takes the
45device that will use the GPIO and the function the requested GPIO is supposed to 46device that will use the GPIO and the function the requested GPIO is supposed to
46fulfill: 47fulfill::
47 48
48 struct gpio_desc *gpiod_get(struct device *dev, const char *con_id, 49 struct gpio_desc *gpiod_get(struct device *dev, const char *con_id,
49 enum gpiod_flags flags) 50 enum gpiod_flags flags)
50 51
51If a function is implemented by using several GPIOs together (e.g. a simple LED 52If a function is implemented by using several GPIOs together (e.g. a simple LED
52device that displays digits), an additional index argument can be specified: 53device that displays digits), an additional index argument can be specified::
53 54
54 struct gpio_desc *gpiod_get_index(struct device *dev, 55 struct gpio_desc *gpiod_get_index(struct device *dev,
55 const char *con_id, unsigned int idx, 56 const char *con_id, unsigned int idx,
@@ -84,7 +85,7 @@ occurred while trying to acquire it. This is useful to discriminate between mere
84errors and an absence of GPIO for optional GPIO parameters. For the common 85errors and an absence of GPIO for optional GPIO parameters. For the common
85pattern where a GPIO is optional, the gpiod_get_optional() and 86pattern where a GPIO is optional, the gpiod_get_optional() and
86gpiod_get_index_optional() functions can be used. These functions return NULL 87gpiod_get_index_optional() functions can be used. These functions return NULL
87instead of -ENOENT if no GPIO has been assigned to the requested function: 88instead of -ENOENT if no GPIO has been assigned to the requested function::
88 89
89 struct gpio_desc *gpiod_get_optional(struct device *dev, 90 struct gpio_desc *gpiod_get_optional(struct device *dev,
90 const char *con_id, 91 const char *con_id,
@@ -101,14 +102,14 @@ This is helpful to driver authors, since they do not need to special case
101-ENOSYS return codes. System integrators should however be careful to enable 102-ENOSYS return codes. System integrators should however be careful to enable
102gpiolib on systems that need it. 103gpiolib on systems that need it.
103 104
104For a function using multiple GPIOs all of those can be obtained with one call: 105For a function using multiple GPIOs all of those can be obtained with one call::
105 106
106 struct gpio_descs *gpiod_get_array(struct device *dev, 107 struct gpio_descs *gpiod_get_array(struct device *dev,
107 const char *con_id, 108 const char *con_id,
108 enum gpiod_flags flags) 109 enum gpiod_flags flags)
109 110
110This function returns a struct gpio_descs which contains an array of 111This function returns a struct gpio_descs which contains an array of
111descriptors: 112descriptors::
112 113
113 struct gpio_descs { 114 struct gpio_descs {
114 unsigned int ndescs; 115 unsigned int ndescs;
@@ -116,13 +117,13 @@ descriptors:
116 } 117 }
117 118
118The following function returns NULL instead of -ENOENT if no GPIOs have been 119The following function returns NULL instead of -ENOENT if no GPIOs have been
119assigned to the requested function: 120assigned to the requested function::
120 121
121 struct gpio_descs *gpiod_get_array_optional(struct device *dev, 122 struct gpio_descs *gpiod_get_array_optional(struct device *dev,
122 const char *con_id, 123 const char *con_id,
123 enum gpiod_flags flags) 124 enum gpiod_flags flags)
124 125
125Device-managed variants of these functions are also defined: 126Device-managed variants of these functions are also defined::
126 127
127 struct gpio_desc *devm_gpiod_get(struct device *dev, const char *con_id, 128 struct gpio_desc *devm_gpiod_get(struct device *dev, const char *con_id,
128 enum gpiod_flags flags) 129 enum gpiod_flags flags)
@@ -149,11 +150,11 @@ Device-managed variants of these functions are also defined:
149 const char *con_id, 150 const char *con_id,
150 enum gpiod_flags flags) 151 enum gpiod_flags flags)
151 152
152A GPIO descriptor can be disposed of using the gpiod_put() function: 153A GPIO descriptor can be disposed of using the gpiod_put() function::
153 154
154 void gpiod_put(struct gpio_desc *desc) 155 void gpiod_put(struct gpio_desc *desc)
155 156
156For an array of GPIOs this function can be used: 157For an array of GPIOs this function can be used::
157 158
158 void gpiod_put_array(struct gpio_descs *descs) 159 void gpiod_put_array(struct gpio_descs *descs)
159 160
@@ -161,7 +162,7 @@ It is strictly forbidden to use a descriptor after calling these functions.
161It is also not allowed to individually release descriptors (using gpiod_put()) 162It is also not allowed to individually release descriptors (using gpiod_put())
162from an array acquired with gpiod_get_array(). 163from an array acquired with gpiod_get_array().
163 164
164The device-managed variants are, unsurprisingly: 165The device-managed variants are, unsurprisingly::
165 166
166 void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) 167 void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
167 168
@@ -175,7 +176,7 @@ Setting Direction
175----------------- 176-----------------
176The first thing a driver must do with a GPIO is setting its direction. If no 177The first thing a driver must do with a GPIO is setting its direction. If no
177direction-setting flags have been given to gpiod_get*(), this is done by 178direction-setting flags have been given to gpiod_get*(), this is done by
178invoking one of the gpiod_direction_*() functions: 179invoking one of the gpiod_direction_*() functions::
179 180
180 int gpiod_direction_input(struct gpio_desc *desc) 181 int gpiod_direction_input(struct gpio_desc *desc)
181 int gpiod_direction_output(struct gpio_desc *desc, int value) 182 int gpiod_direction_output(struct gpio_desc *desc, int value)
@@ -189,7 +190,7 @@ of early board setup.
189For output GPIOs, the value provided becomes the initial output value. This 190For output GPIOs, the value provided becomes the initial output value. This
190helps avoid signal glitching during system startup. 191helps avoid signal glitching during system startup.
191 192
192A driver can also query the current direction of a GPIO: 193A driver can also query the current direction of a GPIO::
193 194
194 int gpiod_get_direction(const struct gpio_desc *desc) 195 int gpiod_get_direction(const struct gpio_desc *desc)
195 196
@@ -206,7 +207,7 @@ Most GPIO controllers can be accessed with memory read/write instructions. Those
206don't need to sleep, and can safely be done from inside hard (non-threaded) IRQ 207don't need to sleep, and can safely be done from inside hard (non-threaded) IRQ
207handlers and similar contexts. 208handlers and similar contexts.
208 209
209Use the following calls to access GPIOs from an atomic context: 210Use the following calls to access GPIOs from an atomic context::
210 211
211 int gpiod_get_value(const struct gpio_desc *desc); 212 int gpiod_get_value(const struct gpio_desc *desc);
212 void gpiod_set_value(struct gpio_desc *desc, int value); 213 void gpiod_set_value(struct gpio_desc *desc, int value);
@@ -231,11 +232,11 @@ head of a queue to transmit a command and get its response. This requires
231sleeping, which can't be done from inside IRQ handlers. 232sleeping, which can't be done from inside IRQ handlers.
232 233
233Platforms that support this type of GPIO distinguish them from other GPIOs by 234Platforms that support this type of GPIO distinguish them from other GPIOs by
234returning nonzero from this call: 235returning nonzero from this call::
235 236
236 int gpiod_cansleep(const struct gpio_desc *desc) 237 int gpiod_cansleep(const struct gpio_desc *desc)
237 238
238To access such GPIOs, a different set of accessors is defined: 239To access such GPIOs, a different set of accessors is defined::
239 240
240 int gpiod_get_value_cansleep(const struct gpio_desc *desc) 241 int gpiod_get_value_cansleep(const struct gpio_desc *desc)
241 void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) 242 void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
@@ -271,23 +272,23 @@ As an example, if the active low property for a dedicated GPIO is set, and the
271gpiod_set_(array)_value_xxx() passes "asserted" ("1"), the physical line level 272gpiod_set_(array)_value_xxx() passes "asserted" ("1"), the physical line level
272will be driven low. 273will be driven low.
273 274
274To summarize: 275To summarize::
275 276
276Function (example) line property physical line 277 Function (example) line property physical line
277gpiod_set_raw_value(desc, 0); don't care low 278 gpiod_set_raw_value(desc, 0); don't care low
278gpiod_set_raw_value(desc, 1); don't care high 279 gpiod_set_raw_value(desc, 1); don't care high
279gpiod_set_value(desc, 0); default (active high) low 280 gpiod_set_value(desc, 0); default (active high) low
280gpiod_set_value(desc, 1); default (active high) high 281 gpiod_set_value(desc, 1); default (active high) high
281gpiod_set_value(desc, 0); active low high 282 gpiod_set_value(desc, 0); active low high
282gpiod_set_value(desc, 1); active low low 283 gpiod_set_value(desc, 1); active low low
283gpiod_set_value(desc, 0); default (active high) low 284 gpiod_set_value(desc, 0); default (active high) low
284gpiod_set_value(desc, 1); default (active high) high 285 gpiod_set_value(desc, 1); default (active high) high
285gpiod_set_value(desc, 0); open drain low 286 gpiod_set_value(desc, 0); open drain low
286gpiod_set_value(desc, 1); open drain high impedance 287 gpiod_set_value(desc, 1); open drain high impedance
287gpiod_set_value(desc, 0); open source high impedance 288 gpiod_set_value(desc, 0); open source high impedance
288gpiod_set_value(desc, 1); open source high 289 gpiod_set_value(desc, 1); open source high
289 290
290It is possible to override these semantics using the *set_raw/'get_raw functions 291It is possible to override these semantics using the set_raw/get_raw functions
291but it should be avoided as much as possible, especially by system-agnostic drivers 292but it should be avoided as much as possible, especially by system-agnostic drivers
292which should not need to care about the actual physical line level and worry about 293which should not need to care about the actual physical line level and worry about
293the logical value instead. 294the logical value instead.
@@ -300,7 +301,7 @@ their device will actually receive, no matter what lies between it and the GPIO
300line. 301line.
301 302
302The following set of calls ignore the active-low or open drain property of a GPIO and 303The following set of calls ignore the active-low or open drain property of a GPIO and
303work on the raw line value: 304work on the raw line value::
304 305
305 int gpiod_get_raw_value(const struct gpio_desc *desc) 306 int gpiod_get_raw_value(const struct gpio_desc *desc)
306 void gpiod_set_raw_value(struct gpio_desc *desc, int value) 307 void gpiod_set_raw_value(struct gpio_desc *desc, int value)
@@ -308,7 +309,7 @@ work on the raw line value:
308 void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value) 309 void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value)
309 int gpiod_direction_output_raw(struct gpio_desc *desc, int value) 310 int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
310 311
311The active low state of a GPIO can also be queried using the following call: 312The active low state of a GPIO can also be queried using the following call::
312 313
313 int gpiod_is_active_low(const struct gpio_desc *desc) 314 int gpiod_is_active_low(const struct gpio_desc *desc)
314 315
@@ -318,7 +319,7 @@ should not have to care about the physical line level or open drain semantics.
318 319
319Access multiple GPIOs with a single function call 320Access multiple GPIOs with a single function call
320------------------------------------------------- 321-------------------------------------------------
321The following functions get or set the values of an array of GPIOs: 322The following functions get or set the values of an array of GPIOs::
322 323
323 int gpiod_get_array_value(unsigned int array_size, 324 int gpiod_get_array_value(unsigned int array_size,
324 struct gpio_desc **desc_array, 325 struct gpio_desc **desc_array,
@@ -361,7 +362,7 @@ The functions take three arguments:
361The descriptor array can be obtained using the gpiod_get_array() function 362The descriptor array can be obtained using the gpiod_get_array() function
362or one of its variants. If the group of descriptors returned by that function 363or one of its variants. If the group of descriptors returned by that function
363matches the desired group of GPIOs, those GPIOs can be accessed by simply using 364matches the desired group of GPIOs, those GPIOs can be accessed by simply using
364the struct gpio_descs returned by gpiod_get_array(): 365the struct gpio_descs returned by gpiod_get_array()::
365 366
366 struct gpio_descs *my_gpio_descs = gpiod_get_array(...); 367 struct gpio_descs *my_gpio_descs = gpiod_get_array(...);
367 gpiod_set_array_value(my_gpio_descs->ndescs, my_gpio_descs->desc, 368 gpiod_set_array_value(my_gpio_descs->ndescs, my_gpio_descs->desc,
@@ -384,7 +385,7 @@ values are stored in value_array rather than passed back as return value.
384GPIOs mapped to IRQs 385GPIOs mapped to IRQs
385-------------------- 386--------------------
386GPIO lines can quite often be used as IRQs. You can get the IRQ number 387GPIO lines can quite often be used as IRQs. You can get the IRQ number
387corresponding to a given GPIO using the following call: 388corresponding to a given GPIO using the following call::
388 389
389 int gpiod_to_irq(const struct gpio_desc *desc) 390 int gpiod_to_irq(const struct gpio_desc *desc)
390 391
@@ -424,7 +425,7 @@ Interacting With the Legacy GPIO Subsystem
424Many kernel subsystems still handle GPIOs using the legacy integer-based 425Many kernel subsystems still handle GPIOs using the legacy integer-based
425interface. Although it is strongly encouraged to upgrade them to the safer 426interface. Although it is strongly encouraged to upgrade them to the safer
426descriptor-based API, the following two functions allow you to convert a GPIO 427descriptor-based API, the following two functions allow you to convert a GPIO
427descriptor into the GPIO integer namespace and vice-versa: 428descriptor into the GPIO integer namespace and vice-versa::
428 429
429 int desc_to_gpio(const struct gpio_desc *desc) 430 int desc_to_gpio(const struct gpio_desc *desc)
430 struct gpio_desc *gpio_to_desc(unsigned gpio) 431 struct gpio_desc *gpio_to_desc(unsigned gpio)
diff --git a/Documentation/driver-api/gpio/index.rst b/Documentation/driver-api/gpio/index.rst
index fd22c0d1419e..6ba9e0043310 100644
--- a/Documentation/driver-api/gpio/index.rst
+++ b/Documentation/driver-api/gpio/index.rst
@@ -9,6 +9,7 @@ Contents:
9 9
10 intro 10 intro
11 driver 11 driver
12 consumer
12 legacy 13 legacy
13 14
14Core 15Core
diff --git a/Documentation/gpio/00-INDEX b/Documentation/gpio/00-INDEX
index 64cf61245861..f960fc00a3ef 100644
--- a/Documentation/gpio/00-INDEX
+++ b/Documentation/gpio/00-INDEX
@@ -1,7 +1,5 @@
100-INDEX 100-INDEX
2 - This file 2 - This file
3consumer.txt
4 - How to obtain and use GPIOs in a driver
5drivers-on-gpio.txt: 3drivers-on-gpio.txt:
6 - Drivers in other subsystems that can use GPIO to provide more 4 - Drivers in other subsystems that can use GPIO to provide more
7 complex functionality. 5 complex functionality.