Commit c956126c137d97acb6f4d56fa9572d0bcc84e4ed
Committed by
Linus Torvalds
1 parent
5affb60772
Exists in
master
and in
4 other branches
gpio: doc updates
There's been some recent confusion about error checking GPIO numbers. briefly, it should be handled mostly during setup, when gpio_request() is called, and NEVER by expectig gpio_is_valid to report more than never-usable GPIO numbers. [akpm@linux-foundation.org: terminate unterminated comment] Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Cc: Eric Miao" <eric.y.miao@gmail.com> Cc: "Ryan Mallon" <ryan@bluewatersys.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 2 changed files with 27 additions and 9 deletions Side-by-side Diff
Documentation/gpio.txt
... | ... | @@ -109,18 +109,20 @@ |
109 | 109 | |
110 | 110 | If you want to initialize a structure with an invalid GPIO number, use |
111 | 111 | some negative number (perhaps "-EINVAL"); that will never be valid. To |
112 | -test if a number could reference a GPIO, you may use this predicate: | |
112 | +test if such number from such a structure could reference a GPIO, you | |
113 | +may use this predicate: | |
113 | 114 | |
114 | 115 | int gpio_is_valid(int number); |
115 | 116 | |
116 | 117 | A number that's not valid will be rejected by calls which may request |
117 | 118 | or free GPIOs (see below). Other numbers may also be rejected; for |
118 | -example, a number might be valid but unused on a given board. | |
119 | +example, a number might be valid but temporarily unused on a given board. | |
119 | 120 | |
120 | -Whether a platform supports multiple GPIO controllers is currently a | |
121 | -platform-specific implementation issue. | |
121 | +Whether a platform supports multiple GPIO controllers is a platform-specific | |
122 | +implementation issue, as are whether that support can leave "holes" in the space | |
123 | +of GPIO numbers, and whether new controllers can be added at runtime. Such issues | |
124 | +can affect things including whether adjacent GPIO numbers are both valid. | |
122 | 125 | |
123 | - | |
124 | 126 | Using GPIOs |
125 | 127 | ----------- |
126 | 128 | The first thing a system should do with a GPIO is allocate it, using |
127 | 129 | |
128 | 130 | |
... | ... | @@ -480,12 +482,16 @@ |
480 | 482 | ARCH_REQUIRE_GPIOLIB or ARCH_WANT_OPTIONAL_GPIOLIB |
481 | 483 | and arrange that its <asm/gpio.h> includes <asm-generic/gpio.h> and defines |
482 | 484 | three functions: gpio_get_value(), gpio_set_value(), and gpio_cansleep(). |
483 | -They may also want to provide a custom value for ARCH_NR_GPIOS. | |
484 | 485 | |
485 | -ARCH_REQUIRE_GPIOLIB means that the gpio-lib code will always get compiled | |
486 | +It may also provide a custom value for ARCH_NR_GPIOS, so that it better | |
487 | +reflects the number of GPIOs in actual use on that platform, without | |
488 | +wasting static table space. (It should count both built-in/SoC GPIOs and | |
489 | +also ones on GPIO expanders. | |
490 | + | |
491 | +ARCH_REQUIRE_GPIOLIB means that the gpiolib code will always get compiled | |
486 | 492 | into the kernel on that architecture. |
487 | 493 | |
488 | -ARCH_WANT_OPTIONAL_GPIOLIB means the gpio-lib code defaults to off and the user | |
494 | +ARCH_WANT_OPTIONAL_GPIOLIB means the gpiolib code defaults to off and the user | |
489 | 495 | can enable it and build it into the kernel optionally. |
490 | 496 | |
491 | 497 | If neither of these options are selected, the platform does not support |
include/asm-generic/gpio.h
... | ... | @@ -16,15 +16,27 @@ |
16 | 16 | * While the GPIO programming interface defines valid GPIO numbers |
17 | 17 | * to be in the range 0..MAX_INT, this library restricts them to the |
18 | 18 | * smaller range 0..ARCH_NR_GPIOS-1. |
19 | + * | |
20 | + * ARCH_NR_GPIOS is somewhat arbitrary; it usually reflects the sum of | |
21 | + * builtin/SoC GPIOs plus a number of GPIOs on expanders; the latter is | |
22 | + * actually an estimate of a board-specific value. | |
19 | 23 | */ |
20 | 24 | |
21 | 25 | #ifndef ARCH_NR_GPIOS |
22 | 26 | #define ARCH_NR_GPIOS 256 |
23 | 27 | #endif |
24 | 28 | |
29 | +/* | |
30 | + * "valid" GPIO numbers are nonnegative and may be passed to | |
31 | + * setup routines like gpio_request(). only some valid numbers | |
32 | + * can successfully be requested and used. | |
33 | + * | |
34 | + * Invalid GPIO numbers are useful for indicating no-such-GPIO in | |
35 | + * platform data and other tables. | |
36 | + */ | |
37 | + | |
25 | 38 | static inline int gpio_is_valid(int number) |
26 | 39 | { |
27 | - /* only some non-negative numbers are valid */ | |
28 | 40 | return ((unsigned)number) < ARCH_NR_GPIOS; |
29 | 41 | } |
30 | 42 |