diff options
Diffstat (limited to 'Documentation/pinctrl.txt')
-rw-r--r-- | Documentation/pinctrl.txt | 311 |
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 | |||
206 | stable value when nothing is driving the rail it is connected to, or when it's | 206 | stable value when nothing is driving the rail it is connected to, or when it's |
207 | unconnected. | 207 | unconnected. |
208 | 208 | ||
209 | For example, a platform may do this: | 209 | Pin configuration can be programmed either using the explicit APIs described |
210 | immediately below, or by adding configuration entries into the mapping table; | ||
211 | see section "Board/machine configuration" below. | ||
212 | |||
213 | For example, a platform may do the following to pull up a pin to VDD: | ||
214 | |||
215 | #include <linux/pinctrl/consumer.h> | ||
210 | 216 | ||
211 | ret = pin_config_set("foo-dev", "FOO_GPIO_PIN", PLATFORM_X_PULL_UP); | 217 | ret = pin_config_set("foo-dev", "FOO_GPIO_PIN", PLATFORM_X_PULL_UP); |
212 | 218 | ||
213 | To pull up a pin to VDD. The pin configuration driver implements callbacks for | 219 | The format and meaning of the configuration parameter, PLATFORM_X_PULL_UP |
214 | changing pin configuration in the pin controller ops like this: | 220 | above, is entirely defined by the pin controller driver. |
221 | |||
222 | The pin configuration driver implements callbacks for changing pin | ||
223 | configuration 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. | |||
726 | All the above functions are mandatory to implement for a pinmux driver. | 731 | All the above functions are mandatory to implement for a pinmux driver. |
727 | 732 | ||
728 | 733 | ||
729 | Pinmux interaction with the GPIO subsystem | 734 | Pin control interaction with the GPIO subsystem |
730 | ========================================== | 735 | =============================================== |
731 | 736 | ||
732 | The public pinmux API contains two functions named pinmux_request_gpio() | 737 | The public pinmux API contains two functions named pinctrl_request_gpio() |
733 | and pinmux_free_gpio(). These two functions shall *ONLY* be called from | 738 | and pinctrl_free_gpio(). These two functions shall *ONLY* be called from |
734 | gpiolib-based drivers as part of their gpio_request() and | 739 | gpiolib-based drivers as part of their gpio_request() and |
735 | gpio_free() semantics. Likewise the pinmux_gpio_direction_[input|output] | 740 | gpio_free() semantics. Likewise the pinctrl_gpio_direction_[input|output] |
736 | shall only be called from within respective gpio_direction_[input|output] | 741 | shall only be called from within respective gpio_direction_[input|output] |
737 | gpiolib implementation. | 742 | gpiolib implementation. |
738 | 743 | ||
739 | NOTE that platforms and individual drivers shall *NOT* request GPIO pins to be | 744 | NOTE that platforms and individual drivers shall *NOT* request GPIO pins to be |
740 | muxed in. Instead, implement a proper gpiolib driver and have that driver | 745 | controlled e.g. muxed in. Instead, implement a proper gpiolib driver and have |
741 | request proper muxing for its pins. | 746 | that driver request proper muxing and other control for its pins. |
742 | 747 | ||
743 | The function list could become long, especially if you can convert every | 748 | The function list could become long, especially if you can convert every |
744 | individual pin into a GPIO pin independent of any other pins, and then try | 749 | individual 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. | |||
747 | In this case, the function array would become 64 entries for each GPIO | 752 | In this case, the function array would become 64 entries for each GPIO |
748 | setting and then the device functions. | 753 | setting and then the device functions. |
749 | 754 | ||
750 | For this reason there are two functions a pinmux driver can implement | 755 | For this reason there are two functions a pin control driver can implement |
751 | to enable only GPIO on an individual pin: .gpio_request_enable() and | 756 | to 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 | |||
762 | will be passed along to this function. | 767 | will be passed along to this function. |
763 | 768 | ||
764 | Alternatively to using these special functions, it is fully allowed to use | 769 | Alternatively to using these special functions, it is fully allowed to use |
765 | named functions for each GPIO pin, the pinmux_request_gpio() will attempt to | 770 | named functions for each GPIO pin, the pinctrl_request_gpio() will attempt to |
766 | obtain the function "gpioN" where "N" is the global GPIO pin number if no | 771 | obtain the function "gpioN" where "N" is the global GPIO pin number if no |
767 | special GPIO-handler is registered. | 772 | special GPIO-handler is registered. |
768 | 773 | ||
769 | 774 | ||
770 | Pinmux board/machine configuration | 775 | Board/machine configuration |
771 | ================================== | 776 | ================================== |
772 | 777 | ||
773 | Boards and machines define how a certain complete running system is put | 778 | Boards 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 | |||
775 | constrained and how the clock tree looks. Of course pinmux settings are also | 780 | constrained and how the clock tree looks. Of course pinmux settings are also |
776 | part of this. | 781 | part of this. |
777 | 782 | ||
778 | A pinmux config for a machine looks pretty much like a simple regulator | 783 | A pin controller configuration for a machine looks pretty much like a simple |
779 | configuration, so for the example array above we want to enable i2c and | 784 | regulator configuration, so for the example array above we want to enable i2c |
780 | spi on the second function mapping: | 785 | and spi on the second function mapping: |
781 | 786 | ||
782 | #include <linux/pinctrl/machine.h> | 787 | #include <linux/pinctrl/machine.h> |
783 | 788 | ||
784 | static const struct pinmux_map __initdata pmx_mapping[] = { | 789 | static 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 | ||
806 | As you can see we may have several pin controllers on the system and thus | 817 | As you can see we may have several pin controllers on the system and thus |
807 | we need to specify which one of them that contain the functions we wish | 818 | we need to specify which one of them that contain the functions we wish |
808 | to map. The map can also use struct device * directly, so there is no | 819 | to map. |
809 | inherent need to use strings to specify .dev_name or .ctrl_dev_name, these | ||
810 | are for the situation where you do not have a handle to the struct device *, | ||
811 | for example if they are not yet instantiated or cumbersome to obtain. | ||
812 | 820 | ||
813 | You register this pinmux mapping to the pinmux subsystem by simply: | 821 | You 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 | ||
817 | Since the above construct is pretty common there is a helper macro to make | 825 | Since the above construct is pretty common there is a helper macro to make |
818 | it even more compact which assumes you want to use pinctrl-foo and position | 826 | it even more compact which assumes you want to use pinctrl-foo and position |
819 | 0 for mapping, for example: | 827 | 0 for mapping, for example: |
820 | 828 | ||
821 | static struct pinmux_map __initdata pmx_mapping[] = { | 829 | static 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 | |||
833 | The mapping table may also contain pin configuration entries. It's common for | ||
834 | each pin/group to have a number of configuration entries that affect it, so | ||
835 | the table entries for configuration reference an array of config parameters | ||
836 | and values. An example using the convenience macros is shown below: | ||
837 | |||
838 | static unsigned long i2c_grp_configs[] = { | ||
839 | FOO_PIN_DRIVEN, | ||
840 | FOO_PIN_PULLUP, | ||
841 | }; | ||
842 | |||
843 | static unsigned long i2c_pin_configs[] = { | ||
844 | FOO_OPEN_COLLECTOR, | ||
845 | FOO_SLEW_RATE_SLOW, | ||
846 | }; | ||
847 | |||
848 | static 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 | |||
855 | Finally, some devices expect the mapping table to contain certain specific | ||
856 | named states. When running on hardware that doesn't need any pin controller | ||
857 | configuration, the mapping table must still contain those named states, in | ||
858 | order to explicitly indicate that the states were provided and intended to | ||
859 | be empty. Table entry macro PIN_MAP_DUMMY_STATE serves the purpose of defining | ||
860 | a named state without causing any pin controller to be programmed: | ||
861 | |||
862 | static 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 | ||
849 | This example mapping is used to switch between two positions for spi0 at | 892 | This example mapping is used to switch between two positions for spi0 at |
850 | runtime, as described further below under the heading "Runtime pinmuxing". | 893 | runtime, as described further below under the heading "Runtime pinmuxing". |
851 | 894 | ||
852 | Further it is possible to match several groups of pins to the same function | 895 | Further it is possible for one named state to affect the muxing of several |
853 | for a single device, say for example in the mmc0 example above, where you can | 896 | groups of pins, say for example in the mmc0 example above, where you can |
854 | additively expand the mmc0 bus from 2 to 4 to 8 pins. If we want to use all | 897 | additively expand the mmc0 bus from 2 to 4 to 8 pins. If we want to use all |
855 | three groups for a total of 2+2+4 = 8 pins (for an 8-bit MMC bus as is the | 898 | three groups for a total of 2+2+4 = 8 pins (for an 8-bit MMC bus as is the |
856 | case), we define a mapping like this: | 899 | case), 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 | ||
902 | The result of grabbing this mapping from the device with something like | 952 | The result of grabbing this mapping from the device with something like |
903 | this (see next paragraph): | 953 | this (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 | |||
959 | or more simply: | ||
960 | |||
961 | p = pinctrl_get_select(dev, "8bit"); | ||
906 | 962 | ||
907 | Will be that you activate all the three bottom records in the mapping at | 963 | Will be that you activate all the three bottom records in the mapping at |
908 | once. Since they share the same name, pin controller device, funcion and | 964 | once. Since they share the same name, pin controller device, function and |
909 | device, and since we allow multiple groups to match to a single device, they | 965 | device, and since we allow multiple groups to match to a single device, they |
910 | all get selected, and they all get enabled and disable simultaneously by the | 966 | all get selected, and they all get enabled and disable simultaneously by the |
911 | pinmux core. | 967 | pinmux core. |
@@ -914,97 +970,111 @@ pinmux core. | |||
914 | Pinmux requests from drivers | 970 | Pinmux requests from drivers |
915 | ============================ | 971 | ============================ |
916 | 972 | ||
917 | Generally it is discouraged to let individual drivers get and enable pinmuxes. | 973 | Generally it is discouraged to let individual drivers get and enable pin |
918 | So if possible, handle the pinmuxes in platform code or some other place where | 974 | control. So if possible, handle the pin control in platform code or some other |
919 | you have access to all the affected struct device * pointers. In some cases | 975 | place where you have access to all the affected struct device * pointers. In |
920 | where a driver needs to switch between different mux mappings at runtime | 976 | some cases where a driver needs to e.g. switch between different mux mappings |
921 | this is not possible. | 977 | at runtime this is not possible. |
922 | 978 | ||
923 | A driver may request a certain mux to be activated, usually just the default | 979 | A driver may request a certain control state to be activated, usually just the |
924 | mux like this: | 980 | default state like this: |
925 | 981 | ||
926 | #include <linux/pinctrl/pinmux.h> | 982 | #include <linux/pinctrl/consumer.h> |
927 | 983 | ||
928 | struct foo_state { | 984 | struct foo_state { |
929 | struct pinmux *pmx; | 985 | struct pinctrl *p; |
986 | struct pinctrl_state *s; | ||
930 | ... | 987 | ... |
931 | }; | 988 | }; |
932 | 989 | ||
933 | foo_probe() | 990 | foo_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 | ||
946 | foo_remove() | 1016 | foo_remove() |
947 | { | 1017 | { |
948 | pinmux_disable(state->pmx); | 1018 | pinctrl_put(state->p); |
949 | pinmux_put(state->pmx); | ||
950 | } | 1019 | } |
951 | 1020 | ||
952 | If you want to grab a specific mux mapping and not just the first one found for | 1021 | This get/lookup/select/put sequence can just as well be handled by bus drivers |
953 | this device you can specify a specific mapping name, for example in the above | ||
954 | example the second i2c0 setting: pinmux_get(&device, "spi0-pos-B"); | ||
955 | |||
956 | This get/enable/disable/put sequence can just as well be handled by bus drivers | ||
957 | if you don't want each and every driver to handle it and you know the | 1022 | if you don't want each and every driver to handle it and you know the |
958 | arrangement on your bus. | 1023 | arrangement on your bus. |
959 | 1024 | ||
960 | The semantics of the get/enable respective disable/put is as follows: | 1025 | The 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 | ||
974 | Usually the pinmux core handled the get/put pair and call out to the device | 1044 | Usually the pin control core handled the get/put pair and call out to the |
975 | drivers bookkeeping operations, like checking available functions and the | 1045 | device drivers bookkeeping operations, like checking available functions and |
976 | associated pins, whereas the enable/disable pass on to the pin controller | 1046 | the associated pins, whereas the enable/disable pass on to the pin controller |
977 | driver which takes care of activating and/or deactivating the mux setting by | 1047 | driver which takes care of activating and/or deactivating the mux setting by |
978 | quickly poking some registers. | 1048 | quickly poking some registers. |
979 | 1049 | ||
980 | The pins are allocated for your device when you issue the pinmux_get() call, | 1050 | The pins are allocated for your device when you issue the pinctrl_get() call, |
981 | after this you should be able to see this in the debugfs listing of all pins. | 1051 | after this you should be able to see this in the debugfs listing of all pins. |
982 | 1052 | ||
983 | 1053 | ||
984 | System pinmux hogging | 1054 | System pin control hogging |
985 | ===================== | 1055 | ========================== |
986 | 1056 | ||
987 | A system pinmux map entry, i.e. a pinmux setting that does not have a device | 1057 | Pin control map entries can be hogged by the core when the pin controller |
988 | associated with it, can be hogged by the core when the pin controller is | 1058 | is registered. This means that the core will attempt to call pinctrl_get(), |
989 | registered. This means that the core will attempt to call pinmux_get() and | 1059 | lookup_state() and select_state() on it immediately after the pin control |
990 | pinmux_enable() on it immediately after the pin control device has been | 1060 | device has been registered. |
991 | registered. | ||
992 | 1061 | ||
993 | This is enabled by simply setting the .hog_on_boot field in the map to true, | 1062 | This occurs for mapping table entries where the client device name is equal |
994 | like this: | 1063 | to 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 | ||
1003 | Since it may be common to request the core to hog a few always-applicable | 1073 | Since it may be common to request the core to hog a few always-applicable |
1004 | mux settings on the primary pin controller, there is a convenience macro for | 1074 | mux settings on the primary pin controller, there is a convenience macro for |
1005 | this: | 1075 | this: |
1006 | 1076 | ||
1007 | PINMUX_MAP_PRIMARY_SYS_HOG("POWERMAP", "power_func") | 1077 | PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-foo", NULL /* group */, "power_func") |
1008 | 1078 | ||
1009 | This gives the exact same result as the above construction. | 1079 | This 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 | |||
1016 | an SPI port from one set of pins to another set of pins. Say for example for | 1086 | an SPI port from one set of pins to another set of pins. Say for example for |
1017 | spi0 in the example above, we expose two different groups of pins for the same | 1087 | spi0 in the example above, we expose two different groups of pins for the same |
1018 | function, but with different named in the mapping as described under | 1088 | function, 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 | ||
1022 | This snippet first muxes the function in the pins defined by group A, enables | 1092 | This snippet first muxes the function in the pins defined by group A, enables |
1023 | it, disables and releases it, and muxes it in on the pins defined by group B: | 1093 | it, disables and releases it, and muxes it in on the pins defined by group B: |
1024 | 1094 | ||
1095 | #include <linux/pinctrl/consumer.h> | ||
1096 | |||
1025 | foo_switch() | 1097 | foo_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 | ||
1047 | The above has to be done from process context. | 1132 | The above has to be done from process context. |