diff options
author | Stephen Warren <swarren@nvidia.com> | 2012-03-02 15:05:47 -0500 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2012-03-05 05:22:59 -0500 |
commit | 6e5e959dde0d92d177f035652aeaa77f9330c9c6 (patch) | |
tree | c2d874df6a1c591b558a17591a1c8fbc2ba7a1e1 /Documentation/pinctrl.txt | |
parent | 0e3db173e2b9fd3b82246516e72c17763eb5f98d (diff) |
pinctrl: API changes to support multiple states per device
The API model is changed from:
p = pinctrl_get(dev, "state1");
pinctrl_enable(p);
...
pinctrl_disable(p);
pinctrl_put(p);
p = pinctrl_get(dev, "state2");
pinctrl_enable(p);
...
pinctrl_disable(p);
pinctrl_put(p);
to this:
p = pinctrl_get(dev);
s1 = pinctrl_lookup_state(p, "state1");
s2 = pinctrl_lookup_state(p, "state2");
pinctrl_select_state(p, s1);
...
pinctrl_select_state(p, s2);
...
pinctrl_put(p);
This allows devices to directly transition between states without
disabling the pin controller programming and put()/get()ing the
configuration data each time. This model will also better suit pinconf
programming, which doesn't have a concept of "disable".
The special-case hogging feature of pin controllers is re-written to use
the regular APIs instead of special-case code. Hence, the pinmux-hogs
debugfs file is removed; see the top-level pinctrl-handles files for
equivalent data.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Dong Aisheng <dong.aisheng@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'Documentation/pinctrl.txt')
-rw-r--r-- | Documentation/pinctrl.txt | 120 |
1 files changed, 79 insertions, 41 deletions
diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt index 558aac554d09..23426c7bc8dc 100644 --- a/Documentation/pinctrl.txt +++ b/Documentation/pinctrl.txt | |||
@@ -847,8 +847,8 @@ As it is possible to map a function to different groups of pins an optional | |||
847 | This example mapping is used to switch between two positions for spi0 at | 847 | This example mapping is used to switch between two positions for spi0 at |
848 | runtime, as described further below under the heading "Runtime pinmuxing". | 848 | runtime, as described further below under the heading "Runtime pinmuxing". |
849 | 849 | ||
850 | Further it is possible to match several groups of pins to the same function | 850 | Further it is possible for one named state to affect the muxing of several |
851 | for a single device, say for example in the mmc0 example above, where you can | 851 | groups of pins, say for example in the mmc0 example above, where you can |
852 | additively expand the mmc0 bus from 2 to 4 to 8 pins. If we want to use all | 852 | additively expand the mmc0 bus from 2 to 4 to 8 pins. If we want to use all |
853 | three groups for a total of 2+2+4 = 8 pins (for an 8-bit MMC bus as is the | 853 | three groups for a total of 2+2+4 = 8 pins (for an 8-bit MMC bus as is the |
854 | case), we define a mapping like this: | 854 | case), we define a mapping like this: |
@@ -879,6 +879,7 @@ case), we define a mapping like this: | |||
879 | .dev_name = "foo-mmc.0", | 879 | .dev_name = "foo-mmc.0", |
880 | .name = "8bit" | 880 | .name = "8bit" |
881 | .ctrl_dev_name = "pinctrl-foo", | 881 | .ctrl_dev_name = "pinctrl-foo", |
882 | .function = "mmc0", | ||
882 | .group = "mmc0_1_grp", | 883 | .group = "mmc0_1_grp", |
883 | }, | 884 | }, |
884 | { | 885 | { |
@@ -900,10 +901,16 @@ case), we define a mapping like this: | |||
900 | The result of grabbing this mapping from the device with something like | 901 | The result of grabbing this mapping from the device with something like |
901 | this (see next paragraph): | 902 | this (see next paragraph): |
902 | 903 | ||
903 | p = pinctrl_get(&device, "8bit"); | 904 | p = pinctrl_get(dev); |
905 | s = pinctrl_lookup_state(p, "8bit"); | ||
906 | ret = pinctrl_select_state(p, s); | ||
907 | |||
908 | or more simply: | ||
909 | |||
910 | p = pinctrl_get_select(dev, "8bit"); | ||
904 | 911 | ||
905 | Will be that you activate all the three bottom records in the mapping at | 912 | Will be that you activate all the three bottom records in the mapping at |
906 | once. Since they share the same name, pin controller device, funcion and | 913 | once. Since they share the same name, pin controller device, function and |
907 | device, and since we allow multiple groups to match to a single device, they | 914 | device, and since we allow multiple groups to match to a single device, they |
908 | all get selected, and they all get enabled and disable simultaneously by the | 915 | all get selected, and they all get enabled and disable simultaneously by the |
909 | pinmux core. | 916 | pinmux core. |
@@ -925,45 +932,63 @@ default state like this: | |||
925 | 932 | ||
926 | struct foo_state { | 933 | struct foo_state { |
927 | struct pinctrl *p; | 934 | struct pinctrl *p; |
935 | struct pinctrl_state *s; | ||
928 | ... | 936 | ... |
929 | }; | 937 | }; |
930 | 938 | ||
931 | foo_probe() | 939 | foo_probe() |
932 | { | 940 | { |
933 | /* Allocate a state holder named "state" etc */ | 941 | /* Allocate a state holder named "foo" etc */ |
934 | struct pinctrl p; | 942 | struct foo_state *foo = ...; |
943 | |||
944 | foo->p = pinctrl_get(&device); | ||
945 | if (IS_ERR(foo->p)) { | ||
946 | /* FIXME: clean up "foo" here */ | ||
947 | return PTR_ERR(foo->p); | ||
948 | } | ||
935 | 949 | ||
936 | p = pinctrl_get(&device, PINCTRL_STATE_DEFAULT); | 950 | foo->s = pinctrl_lookup_state(foo->p, PINCTRL_STATE_DEFAULT); |
937 | if IS_ERR(p) | 951 | if (IS_ERR(foo->s)) { |
938 | return PTR_ERR(p); | 952 | pinctrl_put(foo->p); |
939 | pinctrl_enable(p); | 953 | /* FIXME: clean up "foo" here */ |
954 | return PTR_ERR(s); | ||
955 | } | ||
940 | 956 | ||
941 | state->p = p; | 957 | ret = pinctrl_select_state(foo->s); |
958 | if (ret < 0) { | ||
959 | pinctrl_put(foo->p); | ||
960 | /* FIXME: clean up "foo" here */ | ||
961 | return ret; | ||
962 | } | ||
942 | } | 963 | } |
943 | 964 | ||
944 | foo_remove() | 965 | foo_remove() |
945 | { | 966 | { |
946 | pinctrl_disable(state->p); | ||
947 | pinctrl_put(state->p); | 967 | pinctrl_put(state->p); |
948 | } | 968 | } |
949 | 969 | ||
950 | This get/enable/disable/put sequence can just as well be handled by bus drivers | 970 | This get/lookup/select/put sequence can just as well be handled by bus drivers |
951 | if you don't want each and every driver to handle it and you know the | 971 | if you don't want each and every driver to handle it and you know the |
952 | arrangement on your bus. | 972 | arrangement on your bus. |
953 | 973 | ||
954 | The semantics of the get/enable respective disable/put is as follows: | 974 | The semantics of the pinctrl APIs are: |
975 | |||
976 | - pinctrl_get() is called in process context to obtain a handle to all pinctrl | ||
977 | information for a given client device. It will allocate a struct from the | ||
978 | kernel memory to hold the pinmux state. All mapping table parsing or similar | ||
979 | slow operations take place within this API. | ||
955 | 980 | ||
956 | - pinctrl_get() is called in process context to reserve the pins affected with | 981 | - pinctrl_lookup_state() is called in process context to obtain a handle to a |
957 | a certain mapping and set up the pinmux core and the driver. It will allocate | 982 | specific state for a the client device. This operation may be slow too. |
958 | a struct from the kernel memory to hold the pinmux state. | ||
959 | 983 | ||
960 | - pinctrl_enable()/pinctrl_disable() is quick and can be called from fastpath | 984 | - pinctrl_select_state() programs pin controller hardware according to the |
961 | (irq context) when you quickly want to set up/tear down the hardware muxing | 985 | definition of the state as given by the mapping table. In theory this is a |
962 | when running a device driver. Usually it will just poke some values into a | 986 | fast-path operation, since it only involved blasting some register settings |
963 | register. | 987 | into hardware. However, note that some pin controllers may have their |
988 | registers on a slow/IRQ-based bus, so client devices should not assume they | ||
989 | can call pinctrl_select_state() from non-blocking contexts. | ||
964 | 990 | ||
965 | - pinctrl_disable() is called in process context to tear down the pin requests | 991 | - pinctrl_put() frees all information associated with a pinctrl handle. |
966 | and release the state holder struct for the mux setting etc. | ||
967 | 992 | ||
968 | Usually the pin control core handled the get/put pair and call out to the | 993 | Usually the pin control core handled the get/put pair and call out to the |
969 | device drivers bookkeeping operations, like checking available functions and | 994 | device drivers bookkeeping operations, like checking available functions and |
@@ -979,12 +1004,12 @@ System pin control hogging | |||
979 | ========================== | 1004 | ========================== |
980 | 1005 | ||
981 | Pin control map entries can be hogged by the core when the pin controller | 1006 | Pin control map entries can be hogged by the core when the pin controller |
982 | is registered. This means that the core will attempt to call pinctrl_get() and | 1007 | is registered. This means that the core will attempt to call pinctrl_get(), |
983 | pinctrl_enable() on it immediately after the pin control device has been | 1008 | lookup_state() and select_state() on it immediately after the pin control |
984 | registered. | 1009 | device has been registered. |
985 | 1010 | ||
986 | This is enabled by simply setting the .dev_name field in the map to the name | 1011 | This occurs for mapping table entries where the client device name is equal |
987 | of the pin controller itself, like this: | 1012 | to the pin controller device name, and the state name is PINCTRL_STATE_DEFAULT. |
988 | 1013 | ||
989 | { | 1014 | { |
990 | .dev_name = "pinctrl-foo", | 1015 | .dev_name = "pinctrl-foo", |
@@ -1009,8 +1034,8 @@ It is possible to mux a certain function in and out at runtime, say to move | |||
1009 | an SPI port from one set of pins to another set of pins. Say for example for | 1034 | an SPI port from one set of pins to another set of pins. Say for example for |
1010 | spi0 in the example above, we expose two different groups of pins for the same | 1035 | spi0 in the example above, we expose two different groups of pins for the same |
1011 | function, but with different named in the mapping as described under | 1036 | function, but with different named in the mapping as described under |
1012 | "Advanced mapping" above. So we have two mappings named "spi0-pos-A" and | 1037 | "Advanced mapping" above. So that for an SPI device, we have two states named |
1013 | "spi0-pos-B". | 1038 | "pos-A" and "pos-B". |
1014 | 1039 | ||
1015 | This snippet first muxes the function in the pins defined by group A, enables | 1040 | This snippet first muxes the function in the pins defined by group A, enables |
1016 | it, disables and releases it, and muxes it in on the pins defined by group B: | 1041 | it, disables and releases it, and muxes it in on the pins defined by group B: |
@@ -1020,23 +1045,36 @@ it, disables and releases it, and muxes it in on the pins defined by group B: | |||
1020 | foo_switch() | 1045 | foo_switch() |
1021 | { | 1046 | { |
1022 | struct pinctrl *p; | 1047 | struct pinctrl *p; |
1048 | struct pinctrl_state *s1, *s2; | ||
1049 | |||
1050 | /* Setup */ | ||
1051 | p = pinctrl_get(&device); | ||
1052 | if (IS_ERR(p)) | ||
1053 | ... | ||
1054 | |||
1055 | s1 = pinctrl_lookup_state(foo->p, "pos-A"); | ||
1056 | if (IS_ERR(s1)) | ||
1057 | ... | ||
1058 | |||
1059 | s2 = pinctrl_lookup_state(foo->p, "pos-B"); | ||
1060 | if (IS_ERR(s2)) | ||
1061 | ... | ||
1023 | 1062 | ||
1024 | /* Enable on position A */ | 1063 | /* Enable on position A */ |
1025 | p = pinctrl_get(&device, "spi0-pos-A"); | 1064 | ret = pinctrl_select_state(s1); |
1026 | if IS_ERR(p) | 1065 | if (ret < 0) |
1027 | return PTR_ERR(p); | 1066 | ... |
1028 | pinctrl_enable(p); | ||
1029 | 1067 | ||
1030 | /* This releases the pins again */ | 1068 | ... |
1031 | pinctrl_disable(p); | ||
1032 | pinctrl_put(p); | ||
1033 | 1069 | ||
1034 | /* Enable on position B */ | 1070 | /* Enable on position B */ |
1035 | p = pinctrl_get(&device, "spi0-pos-B"); | 1071 | ret = pinctrl_select_state(s2); |
1036 | if IS_ERR(p) | 1072 | if (ret < 0) |
1037 | return PTR_ERR(p); | 1073 | ... |
1038 | pinctrl_enable(p); | 1074 | |
1039 | ... | 1075 | ... |
1076 | |||
1077 | pinctrl_put(p); | ||
1040 | } | 1078 | } |
1041 | 1079 | ||
1042 | The above has to be done from process context. | 1080 | The above has to be done from process context. |