diff options
| author | Jonathan Neuschäfer <j.neuschaefer@gmx.net> | 2018-03-08 18:40:22 -0500 |
|---|---|---|
| committer | Linus Walleij <linus.walleij@linaro.org> | 2018-03-22 23:21:40 -0400 |
| commit | 4e0edc4b3fe7ee2ecb07360146479dbbeb63cd5a (patch) | |
| tree | 533aa51ffc883c0fe8c203308592c2615ad7be5c /Documentation | |
| parent | 7ee2c13080c99e7ba01c45841e7fd61cdd37fc65 (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.rst | 1 | ||||
| -rw-r--r-- | Documentation/gpio/00-INDEX | 2 |
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 | ================================== | ||
| 1 | GPIO Descriptor Consumer Interface | 2 | GPIO 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 | ||
| 32 | All the functions that work with the descriptor-based GPIO interface are | 33 | All the functions that work with the descriptor-based GPIO interface are |
| 33 | prefixed with gpiod_. The gpio_ prefix is used for the legacy interface. No | 34 | prefixed with ``gpiod_``. The ``gpio_`` prefix is used for the legacy |
| 34 | other function in the kernel should use these prefixes. The use of the legacy | 35 | interface. No other function in the kernel should use these prefixes. The use |
| 35 | functions is strongly discouraged, new code should use <linux/gpio/consumer.h> | 36 | of the legacy functions is strongly discouraged, new code should use |
| 36 | and descriptors exclusively. | 37 | <linux/gpio/consumer.h> and descriptors exclusively. |
| 37 | 38 | ||
| 38 | 39 | ||
| 39 | Obtaining and Disposing GPIOs | 40 | Obtaining and Disposing GPIOs |
| @@ -43,13 +44,13 @@ With the descriptor-based interface, GPIOs are identified with an opaque, | |||
| 43 | non-forgeable handler that must be obtained through a call to one of the | 44 | non-forgeable handler that must be obtained through a call to one of the |
| 44 | gpiod_get() functions. Like many other kernel subsystems, gpiod_get() takes the | 45 | gpiod_get() functions. Like many other kernel subsystems, gpiod_get() takes the |
| 45 | device that will use the GPIO and the function the requested GPIO is supposed to | 46 | device that will use the GPIO and the function the requested GPIO is supposed to |
| 46 | fulfill: | 47 | fulfill:: |
| 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 | ||
| 51 | If a function is implemented by using several GPIOs together (e.g. a simple LED | 52 | If a function is implemented by using several GPIOs together (e.g. a simple LED |
| 52 | device that displays digits), an additional index argument can be specified: | 53 | device 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 | |||
| 84 | errors and an absence of GPIO for optional GPIO parameters. For the common | 85 | errors and an absence of GPIO for optional GPIO parameters. For the common |
| 85 | pattern where a GPIO is optional, the gpiod_get_optional() and | 86 | pattern where a GPIO is optional, the gpiod_get_optional() and |
| 86 | gpiod_get_index_optional() functions can be used. These functions return NULL | 87 | gpiod_get_index_optional() functions can be used. These functions return NULL |
| 87 | instead of -ENOENT if no GPIO has been assigned to the requested function: | 88 | instead 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 |
| 102 | gpiolib on systems that need it. | 103 | gpiolib on systems that need it. |
| 103 | 104 | ||
| 104 | For a function using multiple GPIOs all of those can be obtained with one call: | 105 | For 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 | ||
| 110 | This function returns a struct gpio_descs which contains an array of | 111 | This function returns a struct gpio_descs which contains an array of |
| 111 | descriptors: | 112 | descriptors:: |
| 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 | ||
| 118 | The following function returns NULL instead of -ENOENT if no GPIOs have been | 119 | The following function returns NULL instead of -ENOENT if no GPIOs have been |
| 119 | assigned to the requested function: | 120 | assigned 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 | ||
| 125 | Device-managed variants of these functions are also defined: | 126 | Device-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 | ||
| 152 | A GPIO descriptor can be disposed of using the gpiod_put() function: | 153 | A 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 | ||
| 156 | For an array of GPIOs this function can be used: | 157 | For 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. | |||
| 161 | It is also not allowed to individually release descriptors (using gpiod_put()) | 162 | It is also not allowed to individually release descriptors (using gpiod_put()) |
| 162 | from an array acquired with gpiod_get_array(). | 163 | from an array acquired with gpiod_get_array(). |
| 163 | 164 | ||
| 164 | The device-managed variants are, unsurprisingly: | 165 | The 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 | ----------------- |
| 176 | The first thing a driver must do with a GPIO is setting its direction. If no | 177 | The first thing a driver must do with a GPIO is setting its direction. If no |
| 177 | direction-setting flags have been given to gpiod_get*(), this is done by | 178 | direction-setting flags have been given to gpiod_get*(), this is done by |
| 178 | invoking one of the gpiod_direction_*() functions: | 179 | invoking 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. | |||
| 189 | For output GPIOs, the value provided becomes the initial output value. This | 190 | For output GPIOs, the value provided becomes the initial output value. This |
| 190 | helps avoid signal glitching during system startup. | 191 | helps avoid signal glitching during system startup. |
| 191 | 192 | ||
| 192 | A driver can also query the current direction of a GPIO: | 193 | A 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 | |||
| 206 | don't need to sleep, and can safely be done from inside hard (non-threaded) IRQ | 207 | don't need to sleep, and can safely be done from inside hard (non-threaded) IRQ |
| 207 | handlers and similar contexts. | 208 | handlers and similar contexts. |
| 208 | 209 | ||
| 209 | Use the following calls to access GPIOs from an atomic context: | 210 | Use 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 | |||
| 231 | sleeping, which can't be done from inside IRQ handlers. | 232 | sleeping, which can't be done from inside IRQ handlers. |
| 232 | 233 | ||
| 233 | Platforms that support this type of GPIO distinguish them from other GPIOs by | 234 | Platforms that support this type of GPIO distinguish them from other GPIOs by |
| 234 | returning nonzero from this call: | 235 | returning 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 | ||
| 238 | To access such GPIOs, a different set of accessors is defined: | 239 | To 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 | |||
| 271 | gpiod_set_(array)_value_xxx() passes "asserted" ("1"), the physical line level | 272 | gpiod_set_(array)_value_xxx() passes "asserted" ("1"), the physical line level |
| 272 | will be driven low. | 273 | will be driven low. |
| 273 | 274 | ||
| 274 | To summarize: | 275 | To summarize:: |
| 275 | 276 | ||
| 276 | Function (example) line property physical line | 277 | Function (example) line property physical line |
| 277 | gpiod_set_raw_value(desc, 0); don't care low | 278 | gpiod_set_raw_value(desc, 0); don't care low |
| 278 | gpiod_set_raw_value(desc, 1); don't care high | 279 | gpiod_set_raw_value(desc, 1); don't care high |
| 279 | gpiod_set_value(desc, 0); default (active high) low | 280 | gpiod_set_value(desc, 0); default (active high) low |
| 280 | gpiod_set_value(desc, 1); default (active high) high | 281 | gpiod_set_value(desc, 1); default (active high) high |
| 281 | gpiod_set_value(desc, 0); active low high | 282 | gpiod_set_value(desc, 0); active low high |
| 282 | gpiod_set_value(desc, 1); active low low | 283 | gpiod_set_value(desc, 1); active low low |
| 283 | gpiod_set_value(desc, 0); default (active high) low | 284 | gpiod_set_value(desc, 0); default (active high) low |
| 284 | gpiod_set_value(desc, 1); default (active high) high | 285 | gpiod_set_value(desc, 1); default (active high) high |
| 285 | gpiod_set_value(desc, 0); open drain low | 286 | gpiod_set_value(desc, 0); open drain low |
| 286 | gpiod_set_value(desc, 1); open drain high impedance | 287 | gpiod_set_value(desc, 1); open drain high impedance |
| 287 | gpiod_set_value(desc, 0); open source high impedance | 288 | gpiod_set_value(desc, 0); open source high impedance |
| 288 | gpiod_set_value(desc, 1); open source high | 289 | gpiod_set_value(desc, 1); open source high |
| 289 | 290 | ||
| 290 | It is possible to override these semantics using the *set_raw/'get_raw functions | 291 | It is possible to override these semantics using the set_raw/get_raw functions |
| 291 | but it should be avoided as much as possible, especially by system-agnostic drivers | 292 | but it should be avoided as much as possible, especially by system-agnostic drivers |
| 292 | which should not need to care about the actual physical line level and worry about | 293 | which should not need to care about the actual physical line level and worry about |
| 293 | the logical value instead. | 294 | the logical value instead. |
| @@ -300,7 +301,7 @@ their device will actually receive, no matter what lies between it and the GPIO | |||
| 300 | line. | 301 | line. |
| 301 | 302 | ||
| 302 | The following set of calls ignore the active-low or open drain property of a GPIO and | 303 | The following set of calls ignore the active-low or open drain property of a GPIO and |
| 303 | work on the raw line value: | 304 | work 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 | ||
| 311 | The active low state of a GPIO can also be queried using the following call: | 312 | The 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 | ||
| 319 | Access multiple GPIOs with a single function call | 320 | Access multiple GPIOs with a single function call |
| 320 | ------------------------------------------------- | 321 | ------------------------------------------------- |
| 321 | The following functions get or set the values of an array of GPIOs: | 322 | The 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: | |||
| 361 | The descriptor array can be obtained using the gpiod_get_array() function | 362 | The descriptor array can be obtained using the gpiod_get_array() function |
| 362 | or one of its variants. If the group of descriptors returned by that function | 363 | or one of its variants. If the group of descriptors returned by that function |
| 363 | matches the desired group of GPIOs, those GPIOs can be accessed by simply using | 364 | matches the desired group of GPIOs, those GPIOs can be accessed by simply using |
| 364 | the struct gpio_descs returned by gpiod_get_array(): | 365 | the 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. | |||
| 384 | GPIOs mapped to IRQs | 385 | GPIOs mapped to IRQs |
| 385 | -------------------- | 386 | -------------------- |
| 386 | GPIO lines can quite often be used as IRQs. You can get the IRQ number | 387 | GPIO lines can quite often be used as IRQs. You can get the IRQ number |
| 387 | corresponding to a given GPIO using the following call: | 388 | corresponding 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 | |||
| 424 | Many kernel subsystems still handle GPIOs using the legacy integer-based | 425 | Many kernel subsystems still handle GPIOs using the legacy integer-based |
| 425 | interface. Although it is strongly encouraged to upgrade them to the safer | 426 | interface. Although it is strongly encouraged to upgrade them to the safer |
| 426 | descriptor-based API, the following two functions allow you to convert a GPIO | 427 | descriptor-based API, the following two functions allow you to convert a GPIO |
| 427 | descriptor into the GPIO integer namespace and vice-versa: | 428 | descriptor 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 | ||
| 14 | Core | 15 | Core |
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 @@ | |||
| 1 | 00-INDEX | 1 | 00-INDEX |
| 2 | - This file | 2 | - This file |
| 3 | consumer.txt | ||
| 4 | - How to obtain and use GPIOs in a driver | ||
| 5 | drivers-on-gpio.txt: | 3 | drivers-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. |
