2 * Driver core interface to the pinctrl subsystem.
4 * Copyright (C) 2012 ST-Ericsson SA
5 * Written on behalf of Linaro for ST-Ericsson
6 * Based on bits of regulator core, gpio core and clk core
8 * Author: Linus Walleij <linus.walleij@linaro.org>
10 * License terms: GNU General Public License (GPL) version 2
13 #include <linux/device.h>
14 #include <linux/pinctrl/devinfo.h>
15 #include <linux/pinctrl/consumer.h>
16 #include <linux/slab.h>
19 * pinctrl_bind_pins() - called by the device core before probe
20 * @dev: the device that is just about to probe
22 int pinctrl_bind_pins(struct device
*dev
)
26 if (dev
->of_node_reused
)
29 dev
->pins
= devm_kzalloc(dev
, sizeof(*(dev
->pins
)), GFP_KERNEL
);
33 dev
->pins
->p
= devm_pinctrl_get(dev
);
34 if (IS_ERR(dev
->pins
->p
)) {
35 dev_dbg(dev
, "no pinctrl handle\n");
36 ret
= PTR_ERR(dev
->pins
->p
);
40 dev
->pins
->default_state
= pinctrl_lookup_state(dev
->pins
->p
,
41 PINCTRL_STATE_DEFAULT
);
42 if (IS_ERR(dev
->pins
->default_state
)) {
43 dev_dbg(dev
, "no default pinctrl state\n");
48 dev
->pins
->init_state
= pinctrl_lookup_state(dev
->pins
->p
,
50 if (IS_ERR(dev
->pins
->init_state
)) {
51 /* Not supplying this state is perfectly legal */
52 dev_dbg(dev
, "no init pinctrl state\n");
54 ret
= pinctrl_select_state(dev
->pins
->p
,
55 dev
->pins
->default_state
);
57 ret
= pinctrl_select_state(dev
->pins
->p
, dev
->pins
->init_state
);
61 dev_dbg(dev
, "failed to activate initial pinctrl state\n");
67 * If power management is enabled, we also look for the optional
68 * sleep and idle pin states, with semantics as defined in
69 * <linux/pinctrl/pinctrl-state.h>
71 dev
->pins
->sleep_state
= pinctrl_lookup_state(dev
->pins
->p
,
73 if (IS_ERR(dev
->pins
->sleep_state
))
74 /* Not supplying this state is perfectly legal */
75 dev_dbg(dev
, "no sleep pinctrl state\n");
77 dev
->pins
->idle_state
= pinctrl_lookup_state(dev
->pins
->p
,
79 if (IS_ERR(dev
->pins
->idle_state
))
80 /* Not supplying this state is perfectly legal */
81 dev_dbg(dev
, "no idle pinctrl state\n");
87 * If no pinctrl handle or default state was found for this device,
88 * let's explicitly free the pin container in the device, there is
89 * no point in keeping it around.
92 devm_pinctrl_put(dev
->pins
->p
);
94 devm_kfree(dev
, dev
->pins
);
97 /* Return deferrals */
98 if (ret
== -EPROBE_DEFER
)
100 /* Return serious errors */
103 /* We ignore errors like -ENOENT meaning no pinctrl state */