diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2012-09-10 11:22:00 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2012-09-17 04:53:57 -0400 |
commit | c31a00cd30b176e40e0378664bace6fd5e0417c8 (patch) | |
tree | 24aaa631eb8b7f33ef476eb08e3c9c01ce2f1718 /Documentation/pinctrl.txt | |
parent | 6fc84b841114da84da39594a3abbb2adf3db06d2 (diff) |
pinctrl: document semantics vs GPIO
The semantics of the interactions between GPIO and pinctrl may be
unclear, e.g. which one do you request first? This amends the
documentation to make this clear.
Reported-by: Domenico Andreoli <cavokz@gmail.com>
Acked-by: Domenico Andreoli <domenico.andreoli@linux.com>
Acked-by: Stephen Warren <swarren@wwwdotorg.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'Documentation/pinctrl.txt')
-rw-r--r-- | Documentation/pinctrl.txt | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt index 1479aca23744..3b4ee5328868 100644 --- a/Documentation/pinctrl.txt +++ b/Documentation/pinctrl.txt | |||
@@ -289,6 +289,11 @@ Interaction with the GPIO subsystem | |||
289 | The GPIO drivers may want to perform operations of various types on the same | 289 | The GPIO drivers may want to perform operations of various types on the same |
290 | physical pins that are also registered as pin controller pins. | 290 | physical pins that are also registered as pin controller pins. |
291 | 291 | ||
292 | First and foremost, the two subsystems can be used as completely orthogonal, | ||
293 | see the section named "pin control requests from drivers" and | ||
294 | "drivers needing both pin control and GPIOs" below for details. But in some | ||
295 | situations a cross-subsystem mapping between pins and GPIOs is needed. | ||
296 | |||
292 | Since the pin controller subsystem have its pinspace local to the pin | 297 | Since the pin controller subsystem have its pinspace local to the pin |
293 | controller we need a mapping so that the pin control subsystem can figure out | 298 | controller we need a mapping so that the pin control subsystem can figure out |
294 | which pin controller handles control of a certain GPIO pin. Since a single | 299 | which pin controller handles control of a certain GPIO pin. Since a single |
@@ -359,6 +364,7 @@ will get an pin number into its handled number range. Further it is also passed | |||
359 | the range ID value, so that the pin controller knows which range it should | 364 | the range ID value, so that the pin controller knows which range it should |
360 | deal with. | 365 | deal with. |
361 | 366 | ||
367 | |||
362 | PINMUX interfaces | 368 | PINMUX interfaces |
363 | ================= | 369 | ================= |
364 | 370 | ||
@@ -960,8 +966,8 @@ all get selected, and they all get enabled and disable simultaneously by the | |||
960 | pinmux core. | 966 | pinmux core. |
961 | 967 | ||
962 | 968 | ||
963 | Pinmux requests from drivers | 969 | Pin control requests from drivers |
964 | ============================ | 970 | ================================= |
965 | 971 | ||
966 | Generally it is discouraged to let individual drivers get and enable pin | 972 | Generally it is discouraged to let individual drivers get and enable pin |
967 | control. So if possible, handle the pin control in platform code or some other | 973 | control. So if possible, handle the pin control in platform code or some other |
@@ -969,6 +975,11 @@ place where you have access to all the affected struct device * pointers. In | |||
969 | some cases where a driver needs to e.g. switch between different mux mappings | 975 | some cases where a driver needs to e.g. switch between different mux mappings |
970 | at runtime this is not possible. | 976 | at runtime this is not possible. |
971 | 977 | ||
978 | A typical case is if a driver needs to switch bias of pins from normal | ||
979 | operation and going to sleep, moving from the PINCTRL_STATE_DEFAULT to | ||
980 | PINCTRL_STATE_SLEEP at runtime, re-biasing or even re-muxing pins to save | ||
981 | current in sleep mode. | ||
982 | |||
972 | A driver may request a certain control state to be activated, usually just the | 983 | A driver may request a certain control state to be activated, usually just the |
973 | default state like this: | 984 | default state like this: |
974 | 985 | ||
@@ -1058,6 +1069,51 @@ registered. Thus make sure that the error path in your driver gracefully | |||
1058 | cleans up and is ready to retry the probing later in the startup process. | 1069 | cleans up and is ready to retry the probing later in the startup process. |
1059 | 1070 | ||
1060 | 1071 | ||
1072 | Drivers needing both pin control and GPIOs | ||
1073 | ========================================== | ||
1074 | |||
1075 | Again, it is discouraged to let drivers lookup and select pin control states | ||
1076 | themselves, but again sometimes this is unavoidable. | ||
1077 | |||
1078 | So say that your driver is fetching its resources like this: | ||
1079 | |||
1080 | #include <linux/pinctrl/consumer.h> | ||
1081 | #include <linux/gpio.h> | ||
1082 | |||
1083 | struct pinctrl *pinctrl; | ||
1084 | int gpio; | ||
1085 | |||
1086 | pinctrl = devm_pinctrl_get_select_default(&dev); | ||
1087 | gpio = devm_gpio_request(&dev, 14, "foo"); | ||
1088 | |||
1089 | Here we first request a certain pin state and then request GPIO 14 to be | ||
1090 | used. If you're using the subsystems orthogonally like this, you should | ||
1091 | nominally always get your pinctrl handle and select the desired pinctrl | ||
1092 | state BEFORE requesting the GPIO. This is a semantic convention to avoid | ||
1093 | situations that can be electrically unpleasant, you will certainly want to | ||
1094 | mux in and bias pins in a certain way before the GPIO subsystems starts to | ||
1095 | deal with them. | ||
1096 | |||
1097 | The above can be hidden: using pinctrl hogs, the pin control driver may be | ||
1098 | setting up the config and muxing for the pins when it is probing, | ||
1099 | nevertheless orthogonal to the GPIO subsystem. | ||
1100 | |||
1101 | But there are also situations where it makes sense for the GPIO subsystem | ||
1102 | to communicate directly with with the pinctrl subsystem, using the latter | ||
1103 | as a back-end. This is when the GPIO driver may call out to the functions | ||
1104 | described in the section "Pin control interaction with the GPIO subsystem" | ||
1105 | above. This only involves per-pin multiplexing, and will be completely | ||
1106 | hidden behind the gpio_*() function namespace. In this case, the driver | ||
1107 | need not interact with the pin control subsystem at all. | ||
1108 | |||
1109 | If a pin control driver and a GPIO driver is dealing with the same pins | ||
1110 | and the use cases involve multiplexing, you MUST implement the pin controller | ||
1111 | as a back-end for the GPIO driver like this, unless your hardware design | ||
1112 | is such that the GPIO controller can override the pin controller's | ||
1113 | multiplexing state through hardware without the need to interact with the | ||
1114 | pin control system. | ||
1115 | |||
1116 | |||
1061 | System pin control hogging | 1117 | System pin control hogging |
1062 | ========================== | 1118 | ========================== |
1063 | 1119 | ||