aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/pinctrl.txt
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/pinctrl.txt')
-rw-r--r--Documentation/pinctrl.txt94
1 files changed, 51 insertions, 43 deletions
diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt
index d97bccf46147..e40f4b4e1977 100644
--- a/Documentation/pinctrl.txt
+++ b/Documentation/pinctrl.txt
@@ -152,11 +152,9 @@ static const struct foo_group foo_groups[] = {
152}; 152};
153 153
154 154
155static int foo_list_groups(struct pinctrl_dev *pctldev, unsigned selector) 155static int foo_get_groups_count(struct pinctrl_dev *pctldev)
156{ 156{
157 if (selector >= ARRAY_SIZE(foo_groups)) 157 return ARRAY_SIZE(foo_groups);
158 return -EINVAL;
159 return 0;
160} 158}
161 159
162static const char *foo_get_group_name(struct pinctrl_dev *pctldev, 160static const char *foo_get_group_name(struct pinctrl_dev *pctldev,
@@ -175,7 +173,7 @@ static int foo_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
175} 173}
176 174
177static struct pinctrl_ops foo_pctrl_ops = { 175static struct pinctrl_ops foo_pctrl_ops = {
178 .list_groups = foo_list_groups, 176 .get_groups_count = foo_get_groups_count,
179 .get_group_name = foo_get_group_name, 177 .get_group_name = foo_get_group_name,
180 .get_group_pins = foo_get_group_pins, 178 .get_group_pins = foo_get_group_pins,
181}; 179};
@@ -186,13 +184,12 @@ static struct pinctrl_desc foo_desc = {
186 .pctlops = &foo_pctrl_ops, 184 .pctlops = &foo_pctrl_ops,
187}; 185};
188 186
189The pin control subsystem will call the .list_groups() function repeatedly 187The pin control subsystem will call the .get_groups_count() function to
190beginning on 0 until it returns non-zero to determine legal selectors, then 188determine total number of legal selectors, then it will call the other functions
191it will call the other functions to retrieve the name and pins of the group. 189to retrieve the name and pins of the group. Maintaining the data structure of
192Maintaining the data structure of the groups is up to the driver, this is 190the groups is up to the driver, this is just a simple example - in practice you
193just a simple example - in practice you may need more entries in your group 191may need more entries in your group structure, for example specific register
194structure, for example specific register ranges associated with each group 192ranges associated with each group and so on.
195and so on.
196 193
197 194
198Pin configuration 195Pin configuration
@@ -606,11 +603,9 @@ static const struct foo_group foo_groups[] = {
606}; 603};
607 604
608 605
609static int foo_list_groups(struct pinctrl_dev *pctldev, unsigned selector) 606static int foo_get_groups_count(struct pinctrl_dev *pctldev)
610{ 607{
611 if (selector >= ARRAY_SIZE(foo_groups)) 608 return ARRAY_SIZE(foo_groups);
612 return -EINVAL;
613 return 0;
614} 609}
615 610
616static const char *foo_get_group_name(struct pinctrl_dev *pctldev, 611static const char *foo_get_group_name(struct pinctrl_dev *pctldev,
@@ -629,7 +624,7 @@ static int foo_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
629} 624}
630 625
631static struct pinctrl_ops foo_pctrl_ops = { 626static struct pinctrl_ops foo_pctrl_ops = {
632 .list_groups = foo_list_groups, 627 .get_groups_count = foo_get_groups_count,
633 .get_group_name = foo_get_group_name, 628 .get_group_name = foo_get_group_name,
634 .get_group_pins = foo_get_group_pins, 629 .get_group_pins = foo_get_group_pins,
635}; 630};
@@ -640,7 +635,7 @@ struct foo_pmx_func {
640 const unsigned num_groups; 635 const unsigned num_groups;
641}; 636};
642 637
643static const char * const spi0_groups[] = { "spi0_1_grp" }; 638static const char * const spi0_groups[] = { "spi0_0_grp", "spi0_1_grp" };
644static const char * const i2c0_groups[] = { "i2c0_grp" }; 639static const char * const i2c0_groups[] = { "i2c0_grp" };
645static const char * const mmc0_groups[] = { "mmc0_1_grp", "mmc0_2_grp", 640static const char * const mmc0_groups[] = { "mmc0_1_grp", "mmc0_2_grp",
646 "mmc0_3_grp" }; 641 "mmc0_3_grp" };
@@ -663,11 +658,9 @@ static const struct foo_pmx_func foo_functions[] = {
663 }, 658 },
664}; 659};
665 660
666int foo_list_funcs(struct pinctrl_dev *pctldev, unsigned selector) 661int foo_get_functions_count(struct pinctrl_dev *pctldev)
667{ 662{
668 if (selector >= ARRAY_SIZE(foo_functions)) 663 return ARRAY_SIZE(foo_functions);
669 return -EINVAL;
670 return 0;
671} 664}
672 665
673const char *foo_get_fname(struct pinctrl_dev *pctldev, unsigned selector) 666const char *foo_get_fname(struct pinctrl_dev *pctldev, unsigned selector)
@@ -703,7 +696,7 @@ void foo_disable(struct pinctrl_dev *pctldev, unsigned selector,
703} 696}
704 697
705struct pinmux_ops foo_pmxops = { 698struct pinmux_ops foo_pmxops = {
706 .list_functions = foo_list_funcs, 699 .get_functions_count = foo_get_functions_count,
707 .get_function_name = foo_get_fname, 700 .get_function_name = foo_get_fname,
708 .get_function_groups = foo_get_groups, 701 .get_function_groups = foo_get_groups,
709 .enable = foo_enable, 702 .enable = foo_enable,
@@ -786,7 +779,7 @@ and spi on the second function mapping:
786 779
787#include <linux/pinctrl/machine.h> 780#include <linux/pinctrl/machine.h>
788 781
789static const struct pinctrl_map __initdata mapping[] = { 782static const struct pinctrl_map mapping[] __initconst = {
790 { 783 {
791 .dev_name = "foo-spi.0", 784 .dev_name = "foo-spi.0",
792 .name = PINCTRL_STATE_DEFAULT, 785 .name = PINCTRL_STATE_DEFAULT,
@@ -952,13 +945,13 @@ case), we define a mapping like this:
952The result of grabbing this mapping from the device with something like 945The result of grabbing this mapping from the device with something like
953this (see next paragraph): 946this (see next paragraph):
954 947
955 p = pinctrl_get(dev); 948 p = devm_pinctrl_get(dev);
956 s = pinctrl_lookup_state(p, "8bit"); 949 s = pinctrl_lookup_state(p, "8bit");
957 ret = pinctrl_select_state(p, s); 950 ret = pinctrl_select_state(p, s);
958 951
959or more simply: 952or more simply:
960 953
961 p = pinctrl_get_select(dev, "8bit"); 954 p = devm_pinctrl_get_select(dev, "8bit");
962 955
963Will be that you activate all the three bottom records in the mapping at 956Will be that you activate all the three bottom records in the mapping at
964once. Since they share the same name, pin controller device, function and 957once. Since they share the same name, pin controller device, function and
@@ -992,7 +985,7 @@ foo_probe()
992 /* Allocate a state holder named "foo" etc */ 985 /* Allocate a state holder named "foo" etc */
993 struct foo_state *foo = ...; 986 struct foo_state *foo = ...;
994 987
995 foo->p = pinctrl_get(&device); 988 foo->p = devm_pinctrl_get(&device);
996 if (IS_ERR(foo->p)) { 989 if (IS_ERR(foo->p)) {
997 /* FIXME: clean up "foo" here */ 990 /* FIXME: clean up "foo" here */
998 return PTR_ERR(foo->p); 991 return PTR_ERR(foo->p);
@@ -1000,24 +993,17 @@ foo_probe()
1000 993
1001 foo->s = pinctrl_lookup_state(foo->p, PINCTRL_STATE_DEFAULT); 994 foo->s = pinctrl_lookup_state(foo->p, PINCTRL_STATE_DEFAULT);
1002 if (IS_ERR(foo->s)) { 995 if (IS_ERR(foo->s)) {
1003 pinctrl_put(foo->p);
1004 /* FIXME: clean up "foo" here */ 996 /* FIXME: clean up "foo" here */
1005 return PTR_ERR(s); 997 return PTR_ERR(s);
1006 } 998 }
1007 999
1008 ret = pinctrl_select_state(foo->s); 1000 ret = pinctrl_select_state(foo->s);
1009 if (ret < 0) { 1001 if (ret < 0) {
1010 pinctrl_put(foo->p);
1011 /* FIXME: clean up "foo" here */ 1002 /* FIXME: clean up "foo" here */
1012 return ret; 1003 return ret;
1013 } 1004 }
1014} 1005}
1015 1006
1016foo_remove()
1017{
1018 pinctrl_put(state->p);
1019}
1020
1021This get/lookup/select/put sequence can just as well be handled by bus drivers 1007This get/lookup/select/put sequence can just as well be handled by bus drivers
1022if you don't want each and every driver to handle it and you know the 1008if you don't want each and every driver to handle it and you know the
1023arrangement on your bus. 1009arrangement on your bus.
@@ -1029,6 +1015,11 @@ The semantics of the pinctrl APIs are:
1029 kernel memory to hold the pinmux state. All mapping table parsing or similar 1015 kernel memory to hold the pinmux state. All mapping table parsing or similar
1030 slow operations take place within this API. 1016 slow operations take place within this API.
1031 1017
1018- devm_pinctrl_get() is a variant of pinctrl_get() that causes pinctrl_put()
1019 to be called automatically on the retrieved pointer when the associated
1020 device is removed. It is recommended to use this function over plain
1021 pinctrl_get().
1022
1032- pinctrl_lookup_state() is called in process context to obtain a handle to a 1023- pinctrl_lookup_state() is called in process context to obtain a handle to a
1033 specific state for a the client device. This operation may be slow too. 1024 specific state for a the client device. This operation may be slow too.
1034 1025
@@ -1041,14 +1032,30 @@ The semantics of the pinctrl APIs are:
1041 1032
1042- pinctrl_put() frees all information associated with a pinctrl handle. 1033- pinctrl_put() frees all information associated with a pinctrl handle.
1043 1034
1035- devm_pinctrl_put() is a variant of pinctrl_put() that may be used to
1036 explicitly destroy a pinctrl object returned by devm_pinctrl_get().
1037 However, use of this function will be rare, due to the automatic cleanup
1038 that will occur even without calling it.
1039
1040 pinctrl_get() must be paired with a plain pinctrl_put().
1041 pinctrl_get() may not be paired with devm_pinctrl_put().
1042 devm_pinctrl_get() can optionally be paired with devm_pinctrl_put().
1043 devm_pinctrl_get() may not be paired with plain pinctrl_put().
1044
1044Usually the pin control core handled the get/put pair and call out to the 1045Usually the pin control core handled the get/put pair and call out to the
1045device drivers bookkeeping operations, like checking available functions and 1046device drivers bookkeeping operations, like checking available functions and
1046the associated pins, whereas the enable/disable pass on to the pin controller 1047the associated pins, whereas the enable/disable pass on to the pin controller
1047driver which takes care of activating and/or deactivating the mux setting by 1048driver which takes care of activating and/or deactivating the mux setting by
1048quickly poking some registers. 1049quickly poking some registers.
1049 1050
1050The pins are allocated for your device when you issue the pinctrl_get() call, 1051The pins are allocated for your device when you issue the devm_pinctrl_get()
1051after this you should be able to see this in the debugfs listing of all pins. 1052call, after this you should be able to see this in the debugfs listing of all
1053pins.
1054
1055NOTE: the pinctrl system will return -EPROBE_DEFER if it cannot find the
1056requested pinctrl handles, for example if the pinctrl driver has not yet
1057registered. Thus make sure that the error path in your driver gracefully
1058cleans up and is ready to retry the probing later in the startup process.
1052 1059
1053 1060
1054System pin control hogging 1061System pin control hogging
@@ -1094,13 +1101,13 @@ it, disables and releases it, and muxes it in on the pins defined by group B:
1094 1101
1095#include <linux/pinctrl/consumer.h> 1102#include <linux/pinctrl/consumer.h>
1096 1103
1097foo_switch() 1104struct pinctrl *p;
1098{ 1105struct pinctrl_state *s1, *s2;
1099 struct pinctrl *p;
1100 struct pinctrl_state *s1, *s2;
1101 1106
1107foo_probe()
1108{
1102 /* Setup */ 1109 /* Setup */
1103 p = pinctrl_get(&device); 1110 p = devm_pinctrl_get(&device);
1104 if (IS_ERR(p)) 1111 if (IS_ERR(p))
1105 ... 1112 ...
1106 1113
@@ -1111,7 +1118,10 @@ foo_switch()
1111 s2 = pinctrl_lookup_state(foo->p, "pos-B"); 1118 s2 = pinctrl_lookup_state(foo->p, "pos-B");
1112 if (IS_ERR(s2)) 1119 if (IS_ERR(s2))
1113 ... 1120 ...
1121}
1114 1122
1123foo_switch()
1124{
1115 /* Enable on position A */ 1125 /* Enable on position A */
1116 ret = pinctrl_select_state(s1); 1126 ret = pinctrl_select_state(s1);
1117 if (ret < 0) 1127 if (ret < 0)
@@ -1125,8 +1135,6 @@ foo_switch()
1125 ... 1135 ...
1126 1136
1127 ... 1137 ...
1128
1129 pinctrl_put(p);
1130} 1138}
1131 1139
1132The above has to be done from process context. 1140The above has to be done from process context.