1 // SPDX-License-Identifier: GPL-2.0
3 * Driver core interface to the pinctrl subsystem.
5 * Copyright (C) 2012 ST-Ericsson SA
6 * Written on behalf of Linaro for ST-Ericsson
7 * Based on bits of regulator core, gpio core and clk core
9 * Author: Linus Walleij <linus.walleij@linaro.org>
12 #include <linux/device.h>
13 #include <linux/pinctrl/devinfo.h>
14 #include <linux/pinctrl/consumer.h>
15 #include <linux/slab.h>
18 * pinctrl_bind_pins() - called by the device core before probe
19 * @dev: the device that is just about to probe
21 int pinctrl_bind_pins(struct device
*dev
)
25 if (dev
->of_node_reused
)
28 dev
->pins
= devm_kzalloc(dev
, sizeof(*(dev
->pins
)), GFP_KERNEL
);
32 dev
->pins
->p
= devm_pinctrl_get(dev
);
33 if (IS_ERR(dev
->pins
->p
)) {
34 dev_dbg(dev
, "no pinctrl handle\n");
35 ret
= PTR_ERR(dev
->pins
->p
);
39 dev
->pins
->default_state
= pinctrl_lookup_state(dev
->pins
->p
,
40 PINCTRL_STATE_DEFAULT
);
41 if (IS_ERR(dev
->pins
->default_state
)) {
42 dev_dbg(dev
, "no default pinctrl state\n");
47 dev
->pins
->init_state
= pinctrl_lookup_state(dev
->pins
->p
,
49 if (IS_ERR(dev
->pins
->init_state
)) {
50 /* Not supplying this state is perfectly legal */
51 dev_dbg(dev
, "no init pinctrl state\n");
53 ret
= pinctrl_select_state(dev
->pins
->p
,
54 dev
->pins
->default_state
);
56 ret
= pinctrl_select_state(dev
->pins
->p
, dev
->pins
->init_state
);
60 dev_dbg(dev
, "failed to activate initial pinctrl state\n");
66 * If power management is enabled, we also look for the optional
67 * sleep and idle pin states, with semantics as defined in
68 * <linux/pinctrl/pinctrl-state.h>
70 dev
->pins
->sleep_state
= pinctrl_lookup_state(dev
->pins
->p
,
72 if (IS_ERR(dev
->pins
->sleep_state
))
73 /* Not supplying this state is perfectly legal */
74 dev_dbg(dev
, "no sleep pinctrl state\n");
76 dev
->pins
->idle_state
= pinctrl_lookup_state(dev
->pins
->p
,
78 if (IS_ERR(dev
->pins
->idle_state
))
79 /* Not supplying this state is perfectly legal */
80 dev_dbg(dev
, "no idle pinctrl state\n");
86 * If no pinctrl handle or default state was found for this device,
87 * let's explicitly free the pin container in the device, there is
88 * no point in keeping it around.
91 devm_pinctrl_put(dev
->pins
->p
);
93 devm_kfree(dev
, dev
->pins
);
96 /* Return deferrals */
97 if (ret
== -EPROBE_DEFER
)
99 /* Return serious errors */
102 /* We ignore errors like -ENOENT meaning no pinctrl state */