aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/pinctrl.txt
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/pinctrl.txt')
-rw-r--r--Documentation/pinctrl.txt311
1 files changed, 198 insertions, 113 deletions
diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt
index 150fd3833d0b..d97bccf46147 100644
--- a/Documentation/pinctrl.txt
+++ b/Documentation/pinctrl.txt
@@ -206,12 +206,21 @@ using a certain resistor value - pull up and pull down - so that the pin has a
206stable value when nothing is driving the rail it is connected to, or when it's 206stable value when nothing is driving the rail it is connected to, or when it's
207unconnected. 207unconnected.
208 208
209For example, a platform may do this: 209Pin configuration can be programmed either using the explicit APIs described
210immediately below, or by adding configuration entries into the mapping table;
211see section "Board/machine configuration" below.
212
213For example, a platform may do the following to pull up a pin to VDD:
214
215#include <linux/pinctrl/consumer.h>
210 216
211ret = pin_config_set("foo-dev", "FOO_GPIO_PIN", PLATFORM_X_PULL_UP); 217ret = pin_config_set("foo-dev", "FOO_GPIO_PIN", PLATFORM_X_PULL_UP);
212 218
213To pull up a pin to VDD. The pin configuration driver implements callbacks for 219The format and meaning of the configuration parameter, PLATFORM_X_PULL_UP
214changing pin configuration in the pin controller ops like this: 220above, is entirely defined by the pin controller driver.
221
222The pin configuration driver implements callbacks for changing pin
223configuration in the pin controller ops like this:
215 224
216#include <linux/pinctrl/pinctrl.h> 225#include <linux/pinctrl/pinctrl.h>
217#include <linux/pinctrl/pinconf.h> 226#include <linux/pinctrl/pinconf.h>
@@ -492,14 +501,10 @@ Definitions:
492 {"map-i2c0", i2c0, pinctrl0, fi2c0, gi2c0} 501 {"map-i2c0", i2c0, pinctrl0, fi2c0, gi2c0}
493 } 502 }
494 503
495 Every map must be assigned a symbolic name, pin controller and function. 504 Every map must be assigned a state name, pin controller, device and
496 The group is not compulsory - if it is omitted the first group presented by 505 function. The group is not compulsory - if it is omitted the first group
497 the driver as applicable for the function will be selected, which is 506 presented by the driver as applicable for the function will be selected,
498 useful for simple cases. 507 which is useful for simple cases.
499
500 The device name is present in map entries tied to specific devices. Maps
501 without device names are referred to as SYSTEM pinmuxes, such as can be taken
502 by the machine implementation on boot and not tied to any specific device.
503 508
504 It is possible to map several groups to the same combination of device, 509 It is possible to map several groups to the same combination of device,
505 pin controller and function. This is for cases where a certain function on 510 pin controller and function. This is for cases where a certain function on
@@ -726,19 +731,19 @@ same time.
726All the above functions are mandatory to implement for a pinmux driver. 731All the above functions are mandatory to implement for a pinmux driver.
727 732
728 733
729Pinmux interaction with the GPIO subsystem 734Pin control interaction with the GPIO subsystem
730========================================== 735===============================================
731 736
732The public pinmux API contains two functions named pinmux_request_gpio() 737The public pinmux API contains two functions named pinctrl_request_gpio()
733and pinmux_free_gpio(). These two functions shall *ONLY* be called from 738and pinctrl_free_gpio(). These two functions shall *ONLY* be called from
734gpiolib-based drivers as part of their gpio_request() and 739gpiolib-based drivers as part of their gpio_request() and
735gpio_free() semantics. Likewise the pinmux_gpio_direction_[input|output] 740gpio_free() semantics. Likewise the pinctrl_gpio_direction_[input|output]
736shall only be called from within respective gpio_direction_[input|output] 741shall only be called from within respective gpio_direction_[input|output]
737gpiolib implementation. 742gpiolib implementation.
738 743
739NOTE that platforms and individual drivers shall *NOT* request GPIO pins to be 744NOTE that platforms and individual drivers shall *NOT* request GPIO pins to be
740muxed in. Instead, implement a proper gpiolib driver and have that driver 745controlled e.g. muxed in. Instead, implement a proper gpiolib driver and have
741request proper muxing for its pins. 746that driver request proper muxing and other control for its pins.
742 747
743The function list could become long, especially if you can convert every 748The function list could become long, especially if you can convert every
744individual pin into a GPIO pin independent of any other pins, and then try 749individual pin into a GPIO pin independent of any other pins, and then try
@@ -747,7 +752,7 @@ the approach to define every pin as a function.
747In this case, the function array would become 64 entries for each GPIO 752In this case, the function array would become 64 entries for each GPIO
748setting and then the device functions. 753setting and then the device functions.
749 754
750For this reason there are two functions a pinmux driver can implement 755For this reason there are two functions a pin control driver can implement
751to enable only GPIO on an individual pin: .gpio_request_enable() and 756to enable only GPIO on an individual pin: .gpio_request_enable() and
752.gpio_disable_free(). 757.gpio_disable_free().
753 758
@@ -762,12 +767,12 @@ gpiolib driver and the affected GPIO range, pin offset and desired direction
762will be passed along to this function. 767will be passed along to this function.
763 768
764Alternatively to using these special functions, it is fully allowed to use 769Alternatively to using these special functions, it is fully allowed to use
765named functions for each GPIO pin, the pinmux_request_gpio() will attempt to 770named functions for each GPIO pin, the pinctrl_request_gpio() will attempt to
766obtain the function "gpioN" where "N" is the global GPIO pin number if no 771obtain the function "gpioN" where "N" is the global GPIO pin number if no
767special GPIO-handler is registered. 772special GPIO-handler is registered.
768 773
769 774
770Pinmux board/machine configuration 775Board/machine configuration
771================================== 776==================================
772 777
773Boards and machines define how a certain complete running system is put 778Boards and machines define how a certain complete running system is put
@@ -775,27 +780,33 @@ together, including how GPIOs and devices are muxed, how regulators are
775constrained and how the clock tree looks. Of course pinmux settings are also 780constrained and how the clock tree looks. Of course pinmux settings are also
776part of this. 781part of this.
777 782
778A pinmux config for a machine looks pretty much like a simple regulator 783A pin controller configuration for a machine looks pretty much like a simple
779configuration, so for the example array above we want to enable i2c and 784regulator configuration, so for the example array above we want to enable i2c
780spi on the second function mapping: 785and spi on the second function mapping:
781 786
782#include <linux/pinctrl/machine.h> 787#include <linux/pinctrl/machine.h>
783 788
784static const struct pinmux_map __initdata pmx_mapping[] = { 789static const struct pinctrl_map __initdata mapping[] = {
785 { 790 {
786 .ctrl_dev_name = "pinctrl-foo",
787 .function = "spi0",
788 .dev_name = "foo-spi.0", 791 .dev_name = "foo-spi.0",
792 .name = PINCTRL_STATE_DEFAULT,
793 .type = PIN_MAP_TYPE_MUX_GROUP,
794 .ctrl_dev_name = "pinctrl-foo",
795 .data.mux.function = "spi0",
789 }, 796 },
790 { 797 {
791 .ctrl_dev_name = "pinctrl-foo",
792 .function = "i2c0",
793 .dev_name = "foo-i2c.0", 798 .dev_name = "foo-i2c.0",
799 .name = PINCTRL_STATE_DEFAULT,
800 .type = PIN_MAP_TYPE_MUX_GROUP,
801 .ctrl_dev_name = "pinctrl-foo",
802 .data.mux.function = "i2c0",
794 }, 803 },
795 { 804 {
796 .ctrl_dev_name = "pinctrl-foo",
797 .function = "mmc0",
798 .dev_name = "foo-mmc.0", 805 .dev_name = "foo-mmc.0",
806 .name = PINCTRL_STATE_DEFAULT,
807 .type = PIN_MAP_TYPE_MUX_GROUP,
808 .ctrl_dev_name = "pinctrl-foo",
809 .data.mux.function = "mmc0",
799 }, 810 },
800}; 811};
801 812
@@ -805,21 +816,51 @@ must match a function provided by the pinmux driver handling this pin range.
805 816
806As you can see we may have several pin controllers on the system and thus 817As you can see we may have several pin controllers on the system and thus
807we need to specify which one of them that contain the functions we wish 818we need to specify which one of them that contain the functions we wish
808to map. The map can also use struct device * directly, so there is no 819to map.
809inherent need to use strings to specify .dev_name or .ctrl_dev_name, these
810are for the situation where you do not have a handle to the struct device *,
811for example if they are not yet instantiated or cumbersome to obtain.
812 820
813You register this pinmux mapping to the pinmux subsystem by simply: 821You register this pinmux mapping to the pinmux subsystem by simply:
814 822
815 ret = pinmux_register_mappings(pmx_mapping, ARRAY_SIZE(pmx_mapping)); 823 ret = pinctrl_register_mappings(mapping, ARRAY_SIZE(mapping));
816 824
817Since the above construct is pretty common there is a helper macro to make 825Since the above construct is pretty common there is a helper macro to make
818it even more compact which assumes you want to use pinctrl-foo and position 826it even more compact which assumes you want to use pinctrl-foo and position
8190 for mapping, for example: 8270 for mapping, for example:
820 828
821static struct pinmux_map __initdata pmx_mapping[] = { 829static struct pinctrl_map __initdata mapping[] = {
822 PINMUX_MAP("I2CMAP", "pinctrl-foo", "i2c0", "foo-i2c.0"), 830 PIN_MAP_MUX_GROUP("foo-i2c.o", PINCTRL_STATE_DEFAULT, "pinctrl-foo", NULL, "i2c0"),
831};
832
833The mapping table may also contain pin configuration entries. It's common for
834each pin/group to have a number of configuration entries that affect it, so
835the table entries for configuration reference an array of config parameters
836and values. An example using the convenience macros is shown below:
837
838static unsigned long i2c_grp_configs[] = {
839 FOO_PIN_DRIVEN,
840 FOO_PIN_PULLUP,
841};
842
843static unsigned long i2c_pin_configs[] = {
844 FOO_OPEN_COLLECTOR,
845 FOO_SLEW_RATE_SLOW,
846};
847
848static struct pinctrl_map __initdata mapping[] = {
849 PIN_MAP_MUX_GROUP("foo-i2c.0", PINCTRL_STATE_DEFAULT, "pinctrl-foo", "i2c0", "i2c0"),
850 PIN_MAP_MUX_CONFIGS_GROUP("foo-i2c.0", PINCTRL_STATE_DEFAULT, "pinctrl-foo", "i2c0", i2c_grp_configs),
851 PIN_MAP_MUX_CONFIGS_PIN("foo-i2c.0", PINCTRL_STATE_DEFAULT, "pinctrl-foo", "i2c0scl", i2c_pin_configs),
852 PIN_MAP_MUX_CONFIGS_PIN("foo-i2c.0", PINCTRL_STATE_DEFAULT, "pinctrl-foo", "i2c0sda", i2c_pin_configs),
853};
854
855Finally, some devices expect the mapping table to contain certain specific
856named states. When running on hardware that doesn't need any pin controller
857configuration, the mapping table must still contain those named states, in
858order to explicitly indicate that the states were provided and intended to
859be empty. Table entry macro PIN_MAP_DUMMY_STATE serves the purpose of defining
860a named state without causing any pin controller to be programmed:
861
862static struct pinctrl_map __initdata mapping[] = {
863 PIN_MAP_DUMMY_STATE("foo-i2c.0", PINCTRL_STATE_DEFAULT),
823}; 864};
824 865
825 866
@@ -831,81 +872,96 @@ As it is possible to map a function to different groups of pins an optional
831 872
832... 873...
833{ 874{
875 .dev_name = "foo-spi.0",
834 .name = "spi0-pos-A", 876 .name = "spi0-pos-A",
877 .type = PIN_MAP_TYPE_MUX_GROUP,
835 .ctrl_dev_name = "pinctrl-foo", 878 .ctrl_dev_name = "pinctrl-foo",
836 .function = "spi0", 879 .function = "spi0",
837 .group = "spi0_0_grp", 880 .group = "spi0_0_grp",
838 .dev_name = "foo-spi.0",
839}, 881},
840{ 882{
883 .dev_name = "foo-spi.0",
841 .name = "spi0-pos-B", 884 .name = "spi0-pos-B",
885 .type = PIN_MAP_TYPE_MUX_GROUP,
842 .ctrl_dev_name = "pinctrl-foo", 886 .ctrl_dev_name = "pinctrl-foo",
843 .function = "spi0", 887 .function = "spi0",
844 .group = "spi0_1_grp", 888 .group = "spi0_1_grp",
845 .dev_name = "foo-spi.0",
846}, 889},
847... 890...
848 891
849This example mapping is used to switch between two positions for spi0 at 892This example mapping is used to switch between two positions for spi0 at
850runtime, as described further below under the heading "Runtime pinmuxing". 893runtime, as described further below under the heading "Runtime pinmuxing".
851 894
852Further it is possible to match several groups of pins to the same function 895Further it is possible for one named state to affect the muxing of several
853for a single device, say for example in the mmc0 example above, where you can 896groups of pins, say for example in the mmc0 example above, where you can
854additively expand the mmc0 bus from 2 to 4 to 8 pins. If we want to use all 897additively expand the mmc0 bus from 2 to 4 to 8 pins. If we want to use all
855three groups for a total of 2+2+4 = 8 pins (for an 8-bit MMC bus as is the 898three groups for a total of 2+2+4 = 8 pins (for an 8-bit MMC bus as is the
856case), we define a mapping like this: 899case), we define a mapping like this:
857 900
858... 901...
859{ 902{
903 .dev_name = "foo-mmc.0",
860 .name = "2bit" 904 .name = "2bit"
905 .type = PIN_MAP_TYPE_MUX_GROUP,
861 .ctrl_dev_name = "pinctrl-foo", 906 .ctrl_dev_name = "pinctrl-foo",
862 .function = "mmc0", 907 .function = "mmc0",
863 .group = "mmc0_1_grp", 908 .group = "mmc0_1_grp",
864 .dev_name = "foo-mmc.0",
865}, 909},
866{ 910{
911 .dev_name = "foo-mmc.0",
867 .name = "4bit" 912 .name = "4bit"
913 .type = PIN_MAP_TYPE_MUX_GROUP,
868 .ctrl_dev_name = "pinctrl-foo", 914 .ctrl_dev_name = "pinctrl-foo",
869 .function = "mmc0", 915 .function = "mmc0",
870 .group = "mmc0_1_grp", 916 .group = "mmc0_1_grp",
871 .dev_name = "foo-mmc.0",
872}, 917},
873{ 918{
919 .dev_name = "foo-mmc.0",
874 .name = "4bit" 920 .name = "4bit"
921 .type = PIN_MAP_TYPE_MUX_GROUP,
875 .ctrl_dev_name = "pinctrl-foo", 922 .ctrl_dev_name = "pinctrl-foo",
876 .function = "mmc0", 923 .function = "mmc0",
877 .group = "mmc0_2_grp", 924 .group = "mmc0_2_grp",
878 .dev_name = "foo-mmc.0",
879}, 925},
880{ 926{
927 .dev_name = "foo-mmc.0",
881 .name = "8bit" 928 .name = "8bit"
929 .type = PIN_MAP_TYPE_MUX_GROUP,
882 .ctrl_dev_name = "pinctrl-foo", 930 .ctrl_dev_name = "pinctrl-foo",
931 .function = "mmc0",
883 .group = "mmc0_1_grp", 932 .group = "mmc0_1_grp",
884 .dev_name = "foo-mmc.0",
885}, 933},
886{ 934{
935 .dev_name = "foo-mmc.0",
887 .name = "8bit" 936 .name = "8bit"
937 .type = PIN_MAP_TYPE_MUX_GROUP,
888 .ctrl_dev_name = "pinctrl-foo", 938 .ctrl_dev_name = "pinctrl-foo",
889 .function = "mmc0", 939 .function = "mmc0",
890 .group = "mmc0_2_grp", 940 .group = "mmc0_2_grp",
891 .dev_name = "foo-mmc.0",
892}, 941},
893{ 942{
943 .dev_name = "foo-mmc.0",
894 .name = "8bit" 944 .name = "8bit"
945 .type = PIN_MAP_TYPE_MUX_GROUP,
895 .ctrl_dev_name = "pinctrl-foo", 946 .ctrl_dev_name = "pinctrl-foo",
896 .function = "mmc0", 947 .function = "mmc0",
897 .group = "mmc0_3_grp", 948 .group = "mmc0_3_grp",
898 .dev_name = "foo-mmc.0",
899}, 949},
900... 950...
901 951
902The result of grabbing this mapping from the device with something like 952The result of grabbing this mapping from the device with something like
903this (see next paragraph): 953this (see next paragraph):
904 954
905 pmx = pinmux_get(&device, "8bit"); 955 p = pinctrl_get(dev);
956 s = pinctrl_lookup_state(p, "8bit");
957 ret = pinctrl_select_state(p, s);
958
959or more simply:
960
961 p = pinctrl_get_select(dev, "8bit");
906 962
907Will be that you activate all the three bottom records in the mapping at 963Will be that you activate all the three bottom records in the mapping at
908once. Since they share the same name, pin controller device, funcion and 964once. Since they share the same name, pin controller device, function and
909device, and since we allow multiple groups to match to a single device, they 965device, and since we allow multiple groups to match to a single device, they
910all get selected, and they all get enabled and disable simultaneously by the 966all get selected, and they all get enabled and disable simultaneously by the
911pinmux core. 967pinmux core.
@@ -914,97 +970,111 @@ pinmux core.
914Pinmux requests from drivers 970Pinmux requests from drivers
915============================ 971============================
916 972
917Generally it is discouraged to let individual drivers get and enable pinmuxes. 973Generally it is discouraged to let individual drivers get and enable pin
918So if possible, handle the pinmuxes in platform code or some other place where 974control. So if possible, handle the pin control in platform code or some other
919you have access to all the affected struct device * pointers. In some cases 975place where you have access to all the affected struct device * pointers. In
920where a driver needs to switch between different mux mappings at runtime 976some cases where a driver needs to e.g. switch between different mux mappings
921this is not possible. 977at runtime this is not possible.
922 978
923A driver may request a certain mux to be activated, usually just the default 979A driver may request a certain control state to be activated, usually just the
924mux like this: 980default state like this:
925 981
926#include <linux/pinctrl/pinmux.h> 982#include <linux/pinctrl/consumer.h>
927 983
928struct foo_state { 984struct foo_state {
929 struct pinmux *pmx; 985 struct pinctrl *p;
986 struct pinctrl_state *s;
930 ... 987 ...
931}; 988};
932 989
933foo_probe() 990foo_probe()
934{ 991{
935 /* Allocate a state holder named "state" etc */ 992 /* Allocate a state holder named "foo" etc */
936 struct pinmux pmx; 993 struct foo_state *foo = ...;
994
995 foo->p = pinctrl_get(&device);
996 if (IS_ERR(foo->p)) {
997 /* FIXME: clean up "foo" here */
998 return PTR_ERR(foo->p);
999 }
937 1000
938 pmx = pinmux_get(&device, NULL); 1001 foo->s = pinctrl_lookup_state(foo->p, PINCTRL_STATE_DEFAULT);
939 if IS_ERR(pmx) 1002 if (IS_ERR(foo->s)) {
940 return PTR_ERR(pmx); 1003 pinctrl_put(foo->p);
941 pinmux_enable(pmx); 1004 /* FIXME: clean up "foo" here */
1005 return PTR_ERR(s);
1006 }
942 1007
943 state->pmx = pmx; 1008 ret = pinctrl_select_state(foo->s);
1009 if (ret < 0) {
1010 pinctrl_put(foo->p);
1011 /* FIXME: clean up "foo" here */
1012 return ret;
1013 }
944} 1014}
945 1015
946foo_remove() 1016foo_remove()
947{ 1017{
948 pinmux_disable(state->pmx); 1018 pinctrl_put(state->p);
949 pinmux_put(state->pmx);
950} 1019}
951 1020
952If you want to grab a specific mux mapping and not just the first one found for 1021This get/lookup/select/put sequence can just as well be handled by bus drivers
953this device you can specify a specific mapping name, for example in the above
954example the second i2c0 setting: pinmux_get(&device, "spi0-pos-B");
955
956This get/enable/disable/put sequence can just as well be handled by bus drivers
957if you don't want each and every driver to handle it and you know the 1022if you don't want each and every driver to handle it and you know the
958arrangement on your bus. 1023arrangement on your bus.
959 1024
960The semantics of the get/enable respective disable/put is as follows: 1025The semantics of the pinctrl APIs are:
1026
1027- pinctrl_get() is called in process context to obtain a handle to all pinctrl
1028 information for a given client device. It will allocate a struct from the
1029 kernel memory to hold the pinmux state. All mapping table parsing or similar
1030 slow operations take place within this API.
961 1031
962- pinmux_get() is called in process context to reserve the pins affected with 1032- pinctrl_lookup_state() is called in process context to obtain a handle to a
963 a certain mapping and set up the pinmux core and the driver. It will allocate 1033 specific state for a the client device. This operation may be slow too.
964 a struct from the kernel memory to hold the pinmux state.
965 1034
966- pinmux_enable()/pinmux_disable() is quick and can be called from fastpath 1035- pinctrl_select_state() programs pin controller hardware according to the
967 (irq context) when you quickly want to set up/tear down the hardware muxing 1036 definition of the state as given by the mapping table. In theory this is a
968 when running a device driver. Usually it will just poke some values into a 1037 fast-path operation, since it only involved blasting some register settings
969 register. 1038 into hardware. However, note that some pin controllers may have their
1039 registers on a slow/IRQ-based bus, so client devices should not assume they
1040 can call pinctrl_select_state() from non-blocking contexts.
970 1041
971- pinmux_disable() is called in process context to tear down the pin requests 1042- pinctrl_put() frees all information associated with a pinctrl handle.
972 and release the state holder struct for the mux setting.
973 1043
974Usually the pinmux core handled the get/put pair and call out to the device 1044Usually the pin control core handled the get/put pair and call out to the
975drivers bookkeeping operations, like checking available functions and the 1045device drivers bookkeeping operations, like checking available functions and
976associated pins, whereas the enable/disable pass on to the pin controller 1046the associated pins, whereas the enable/disable pass on to the pin controller
977driver which takes care of activating and/or deactivating the mux setting by 1047driver which takes care of activating and/or deactivating the mux setting by
978quickly poking some registers. 1048quickly poking some registers.
979 1049
980The pins are allocated for your device when you issue the pinmux_get() call, 1050The pins are allocated for your device when you issue the pinctrl_get() call,
981after this you should be able to see this in the debugfs listing of all pins. 1051after this you should be able to see this in the debugfs listing of all pins.
982 1052
983 1053
984System pinmux hogging 1054System pin control hogging
985===================== 1055==========================
986 1056
987A system pinmux map entry, i.e. a pinmux setting that does not have a device 1057Pin control map entries can be hogged by the core when the pin controller
988associated with it, can be hogged by the core when the pin controller is 1058is registered. This means that the core will attempt to call pinctrl_get(),
989registered. This means that the core will attempt to call pinmux_get() and 1059lookup_state() and select_state() on it immediately after the pin control
990pinmux_enable() on it immediately after the pin control device has been 1060device has been registered.
991registered.
992 1061
993This is enabled by simply setting the .hog_on_boot field in the map to true, 1062This occurs for mapping table entries where the client device name is equal
994like this: 1063to the pin controller device name, and the state name is PINCTRL_STATE_DEFAULT.
995 1064
996{ 1065{
997 .name = "POWERMAP" 1066 .dev_name = "pinctrl-foo",
1067 .name = PINCTRL_STATE_DEFAULT,
1068 .type = PIN_MAP_TYPE_MUX_GROUP,
998 .ctrl_dev_name = "pinctrl-foo", 1069 .ctrl_dev_name = "pinctrl-foo",
999 .function = "power_func", 1070 .function = "power_func",
1000 .hog_on_boot = true,
1001}, 1071},
1002 1072
1003Since it may be common to request the core to hog a few always-applicable 1073Since it may be common to request the core to hog a few always-applicable
1004mux settings on the primary pin controller, there is a convenience macro for 1074mux settings on the primary pin controller, there is a convenience macro for
1005this: 1075this:
1006 1076
1007PINMUX_MAP_PRIMARY_SYS_HOG("POWERMAP", "power_func") 1077PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-foo", NULL /* group */, "power_func")
1008 1078
1009This gives the exact same result as the above construction. 1079This gives the exact same result as the above construction.
1010 1080
@@ -1016,32 +1086,47 @@ It is possible to mux a certain function in and out at runtime, say to move
1016an SPI port from one set of pins to another set of pins. Say for example for 1086an SPI port from one set of pins to another set of pins. Say for example for
1017spi0 in the example above, we expose two different groups of pins for the same 1087spi0 in the example above, we expose two different groups of pins for the same
1018function, but with different named in the mapping as described under 1088function, but with different named in the mapping as described under
1019"Advanced mapping" above. So we have two mappings named "spi0-pos-A" and 1089"Advanced mapping" above. So that for an SPI device, we have two states named
1020"spi0-pos-B". 1090"pos-A" and "pos-B".
1021 1091
1022This snippet first muxes the function in the pins defined by group A, enables 1092This snippet first muxes the function in the pins defined by group A, enables
1023it, disables and releases it, and muxes it in on the pins defined by group B: 1093it, disables and releases it, and muxes it in on the pins defined by group B:
1024 1094
1095#include <linux/pinctrl/consumer.h>
1096
1025foo_switch() 1097foo_switch()
1026{ 1098{
1027 struct pinmux *pmx; 1099 struct pinctrl *p;
1100 struct pinctrl_state *s1, *s2;
1101
1102 /* Setup */
1103 p = pinctrl_get(&device);
1104 if (IS_ERR(p))
1105 ...
1106
1107 s1 = pinctrl_lookup_state(foo->p, "pos-A");
1108 if (IS_ERR(s1))
1109 ...
1110
1111 s2 = pinctrl_lookup_state(foo->p, "pos-B");
1112 if (IS_ERR(s2))
1113 ...
1028 1114
1029 /* Enable on position A */ 1115 /* Enable on position A */
1030 pmx = pinmux_get(&device, "spi0-pos-A"); 1116 ret = pinctrl_select_state(s1);
1031 if IS_ERR(pmx) 1117 if (ret < 0)
1032 return PTR_ERR(pmx); 1118 ...
1033 pinmux_enable(pmx);
1034 1119
1035 /* This releases the pins again */ 1120 ...
1036 pinmux_disable(pmx);
1037 pinmux_put(pmx);
1038 1121
1039 /* Enable on position B */ 1122 /* Enable on position B */
1040 pmx = pinmux_get(&device, "spi0-pos-B"); 1123 ret = pinctrl_select_state(s2);
1041 if IS_ERR(pmx) 1124 if (ret < 0)
1042 return PTR_ERR(pmx); 1125 ...
1043 pinmux_enable(pmx); 1126
1044 ... 1127 ...
1128
1129 pinctrl_put(p);
1045} 1130}
1046 1131
1047The above has to be done from process context. 1132The above has to be done from process context.