@@ -945,13 +945,13 @@ case), we define a mapping like this:
945945The result of grabbing this mapping from the device with something like
946946this (see next paragraph):
947947
948- p = pinctrl_get (dev);
948+ p = devm_pinctrl_get (dev);
949949 s = pinctrl_lookup_state(p, "8bit");
950950 ret = pinctrl_select_state(p, s);
951951
952952or more simply:
953953
954- p = pinctrl_get_select (dev, "8bit");
954+ p = devm_pinctrl_get_select (dev, "8bit");
955955
956956Will be that you activate all the three bottom records in the mapping at
957957once. Since they share the same name, pin controller device, function and
@@ -985,32 +985,25 @@ foo_probe()
985985 /* Allocate a state holder named "foo" etc */
986986 struct foo_state *foo = ...;
987987
988- foo->p = pinctrl_get (&device);
988+ foo->p = devm_pinctrl_get (&device);
989989 if (IS_ERR(foo->p)) {
990990 /* FIXME: clean up "foo" here */
991991 return PTR_ERR(foo->p);
992992 }
993993
994994 foo->s = pinctrl_lookup_state(foo->p, PINCTRL_STATE_DEFAULT);
995995 if (IS_ERR(foo->s)) {
996- pinctrl_put(foo->p);
997996 /* FIXME: clean up "foo" here */
998997 return PTR_ERR(s);
999998 }
1000999
10011000 ret = pinctrl_select_state(foo->s);
10021001 if (ret < 0) {
1003- pinctrl_put(foo->p);
10041002 /* FIXME: clean up "foo" here */
10051003 return ret;
10061004 }
10071005}
10081006
1009- foo_remove()
1010- {
1011- pinctrl_put(state->p);
1012- }
1013-
10141007This get/lookup/select/put sequence can just as well be handled by bus drivers
10151008if you don't want each and every driver to handle it and you know the
10161009arrangement on your bus.
@@ -1022,6 +1015,11 @@ The semantics of the pinctrl APIs are:
10221015 kernel memory to hold the pinmux state. All mapping table parsing or similar
10231016 slow operations take place within this API.
10241017
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+
10251023- pinctrl_lookup_state() is called in process context to obtain a handle to a
10261024 specific state for a the client device. This operation may be slow too.
10271025
@@ -1034,14 +1032,25 @@ The semantics of the pinctrl APIs are:
10341032
10351033- pinctrl_put() frees all information associated with a pinctrl handle.
10361034
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+
10371045Usually the pin control core handled the get/put pair and call out to the
10381046device drivers bookkeeping operations, like checking available functions and
10391047the associated pins, whereas the enable/disable pass on to the pin controller
10401048driver which takes care of activating and/or deactivating the mux setting by
10411049quickly poking some registers.
10421050
1043- The pins are allocated for your device when you issue the pinctrl_get() call,
1044- after this you should be able to see this in the debugfs listing of all pins.
1051+ The pins are allocated for your device when you issue the devm_pinctrl_get()
1052+ call, after this you should be able to see this in the debugfs listing of all
1053+ pins.
10451054
10461055NOTE: the pinctrl system will return -EPROBE_DEFER if it cannot find the
10471056requested pinctrl handles, for example if the pinctrl driver has not yet
@@ -1092,13 +1101,13 @@ it, disables and releases it, and muxes it in on the pins defined by group B:
10921101
10931102#include <linux/pinctrl/consumer.h>
10941103
1095- foo_switch()
1096- {
1097- struct pinctrl *p;
1098- struct pinctrl_state *s1, *s2;
1104+ struct pinctrl *p;
1105+ struct pinctrl_state *s1, *s2;
10991106
1107+ foo_probe()
1108+ {
11001109 /* Setup */
1101- p = pinctrl_get (&device);
1110+ p = devm_pinctrl_get (&device);
11021111 if (IS_ERR(p))
11031112 ...
11041113
@@ -1109,7 +1118,10 @@ foo_switch()
11091118 s2 = pinctrl_lookup_state(foo->p, "pos-B");
11101119 if (IS_ERR(s2))
11111120 ...
1121+ }
11121122
1123+ foo_switch()
1124+ {
11131125 /* Enable on position A */
11141126 ret = pinctrl_select_state(s1);
11151127 if (ret < 0)
@@ -1123,8 +1135,6 @@ foo_switch()
11231135 ...
11241136
11251137 ...
1126-
1127- pinctrl_put(p);
11281138}
11291139
11301140The above has to be done from process context.
0 commit comments