aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/pinctrl.txt
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2013-03-15 07:01:20 -0400
committerLinus Walleij <linus.walleij@linaro.org>2013-03-18 06:03:29 -0400
commitfdba2d065cb2891b3006424b50fbc6406ce66672 (patch)
treec39f081800ad2d650deada201a6e89d1f1b419a4 /Documentation/pinctrl.txt
parent9cca1173594dccc67c50f0530dc5743fa395da67 (diff)
pinctrl: document the "GPIO mode" pitfall
Recently as adoption of the pinctrl framework is reaching niches where the pins are reconfigured during system sleep and datasheets often talk about something called "GPIO mode", some engineers become confused by this, thinking that since it is named "GPIO (something something)" it must be modeled in the kernel using <linux/gpio.h>. To clarify things, let's put in this piece of documentation, or just start off the discussion here. Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Cc: Pankaj Dev <pankaj.dev@st.com> Reviewed-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'Documentation/pinctrl.txt')
-rw-r--r--Documentation/pinctrl.txt112
1 files changed, 112 insertions, 0 deletions
diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt
index a2b57e0a1db0..447fd4cd54ec 100644
--- a/Documentation/pinctrl.txt
+++ b/Documentation/pinctrl.txt
@@ -736,6 +736,13 @@ All the above functions are mandatory to implement for a pinmux driver.
736Pin control interaction with the GPIO subsystem 736Pin control interaction with the GPIO subsystem
737=============================================== 737===============================================
738 738
739Note that the following implies that the use case is to use a certain pin
740from the Linux kernel using the API in <linux/gpio.h> with gpio_request()
741and similar functions. There are cases where you may be using something
742that your datasheet calls "GPIO mode" but actually is just an electrical
743configuration for a certain device. See the section below named
744"GPIO mode pitfalls" for more details on this scenario.
745
739The public pinmux API contains two functions named pinctrl_request_gpio() 746The public pinmux API contains two functions named pinctrl_request_gpio()
740and pinctrl_free_gpio(). These two functions shall *ONLY* be called from 747and pinctrl_free_gpio(). These two functions shall *ONLY* be called from
741gpiolib-based drivers as part of their gpio_request() and 748gpiolib-based drivers as part of their gpio_request() and
@@ -774,6 +781,111 @@ obtain the function "gpioN" where "N" is the global GPIO pin number if no
774special GPIO-handler is registered. 781special GPIO-handler is registered.
775 782
776 783
784GPIO mode pitfalls
785==================
786
787Sometime the developer may be confused by a datasheet talking about a pin
788being possible to set into "GPIO mode". It appears that what hardware
789engineers mean with "GPIO mode" is not necessarily the use case that is
790implied in the kernel interface <linux/gpio.h>: a pin that you grab from
791kernel code and then either listen for input or drive high/low to
792assert/deassert some external line.
793
794Rather hardware engineers think that "GPIO mode" means that you can
795software-control a few electrical properties of the pin that you would
796not be able to control if the pin was in some other mode, such as muxed in
797for a device.
798
799Example: a pin is usually muxed in to be used as a UART TX line. But during
800system sleep, we need to put this pin into "GPIO mode" and ground it.
801
802If you make a 1-to-1 map to the GPIO subsystem for this pin, you may start
803to think that you need to come up with something real complex, that the
804pin shall be used for UART TX and GPIO at the same time, that you will grab
805a pin control handle and set it to a certain state to enable UART TX to be
806muxed in, then twist it over to GPIO mode and use gpio_direction_output()
807to drive it low during sleep, then mux it over to UART TX again when you
808wake up and maybe even gpio_request/gpio_free as part of this cycle. This
809all gets very complicated.
810
811The solution is to not think that what the datasheet calls "GPIO mode"
812has to be handled by the <linux/gpio.h> interface. Instead view this as
813a certain pin config setting. Look in e.g. <linux/pinctrl/pinconf-generic.h>
814and you find this in the documentation:
815
816 PIN_CONFIG_OUTPUT: this will configure the pin in output, use argument
817 1 to indicate high level, argument 0 to indicate low level.
818
819So it is perfectly possible to push a pin into "GPIO mode" and drive the
820line low as part of the usual pin control map. So for example your UART
821driver may look like this:
822
823#include <linux/pinctrl/consumer.h>
824
825struct pinctrl *pinctrl;
826struct pinctrl_state *pins_default;
827struct pinctrl_state *pins_sleep;
828
829pins_default = pinctrl_lookup_state(uap->pinctrl, PINCTRL_STATE_DEFAULT);
830pins_sleep = pinctrl_lookup_state(uap->pinctrl, PINCTRL_STATE_SLEEP);
831
832/* Normal mode */
833retval = pinctrl_select_state(pinctrl, pins_default);
834/* Sleep mode */
835retval = pinctrl_select_state(pinctrl, pins_sleep);
836
837And your machine configuration may look like this:
838--------------------------------------------------
839
840static unsigned long uart_default_mode[] = {
841 PIN_CONF_PACKED(PIN_CONFIG_DRIVE_PUSH_PULL, 0),
842};
843
844static unsigned long uart_sleep_mode[] = {
845 PIN_CONF_PACKED(PIN_CONFIG_OUTPUT, 0),
846};
847
848static struct pinctrl_map __initdata pinmap[] = {
849 PIN_MAP_MUX_GROUP("uart", PINCTRL_STATE_DEFAULT, "pinctrl-foo",
850 "u0_group", "u0"),
851 PIN_MAP_CONFIGS_PIN("uart", PINCTRL_STATE_DEFAULT, "pinctrl-foo",
852 "UART_TX_PIN", uart_default_mode),
853 PIN_MAP_MUX_GROUP("uart", PINCTRL_STATE_SLEEP, "pinctrl-foo",
854 "u0_group", "gpio-mode"),
855 PIN_MAP_CONFIGS_PIN("uart", PINCTRL_STATE_SLEEP, "pinctrl-foo",
856 "UART_TX_PIN", uart_sleep_mode),
857};
858
859foo_init(void) {
860 pinctrl_register_mappings(pinmap, ARRAY_SIZE(pinmap));
861}
862
863Here the pins we want to control are in the "u0_group" and there is some
864function called "u0" that can be enabled on this group of pins, and then
865everything is UART business as usual. But there is also some function
866named "gpio-mode" that can be mapped onto the same pins to move them into
867GPIO mode.
868
869This will give the desired effect without any bogus interaction with the
870GPIO subsystem. It is just an electrical configuration used by that device
871when going to sleep, it might imply that the pin is set into something the
872datasheet calls "GPIO mode" but that is not the point: it is still used
873by that UART device to control the pins that pertain to that very UART
874driver, putting them into modes needed by the UART. GPIO in the Linux
875kernel sense are just some 1-bit line, and is a different use case.
876
877How the registers are poked to attain the push/pull and output low
878configuration and the muxing of the "u0" or "gpio-mode" group onto these
879pins is a question for the driver.
880
881Some datasheets will be more helpful and refer to the "GPIO mode" as
882"low power mode" rather than anything to do with GPIO. This often means
883the same thing electrically speaking, but in this latter case the
884software engineers will usually quickly identify that this is some
885specific muxing/configuration rather than anything related to the GPIO
886API.
887
888
777Board/machine configuration 889Board/machine configuration
778================================== 890==================================
779 891