1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com>
10 #include <dm/pinctrl.h>
12 static const char * const sandbox_pins[] = {
24 static const char * const sandbox_pins_muxing[] = {
36 static const char * const sandbox_groups[] = {
44 static const char * const sandbox_functions[] = {
55 static const struct pinconf_param sandbox_conf_params[] = {
56 { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
57 { "bias-high-impedance", PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0 },
58 { "bias-bus-hold", PIN_CONFIG_BIAS_BUS_HOLD, 0 },
59 { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
60 { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
61 { "bias-pull-pin-default", PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 1 },
62 { "drive-open-drain", PIN_CONFIG_DRIVE_OPEN_DRAIN, 0 },
63 { "drive-open-source", PIN_CONFIG_DRIVE_OPEN_SOURCE, 0 },
64 { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },
65 { "input-enable", PIN_CONFIG_INPUT_ENABLE, 1 },
66 { "input-disable", PIN_CONFIG_INPUT_ENABLE, 0 },
69 /* bitfield used to save param and value of each pin/selector */
70 static unsigned int sandbox_pins_param[ARRAY_SIZE(sandbox_pins)];
71 static unsigned int sandbox_pins_value[ARRAY_SIZE(sandbox_pins)];
73 static int sandbox_get_pins_count(struct udevice *dev)
75 return ARRAY_SIZE(sandbox_pins);
78 static const char *sandbox_get_pin_name(struct udevice *dev, unsigned selector)
80 return sandbox_pins[selector];
83 static int sandbox_get_pin_muxing(struct udevice *dev,
84 unsigned int selector,
87 const struct pinconf_param *p;
90 snprintf(buf, size, "%s", sandbox_pins_muxing[selector]);
92 if (sandbox_pins_param[selector]) {
93 for (i = 0, p = sandbox_conf_params;
94 i < ARRAY_SIZE(sandbox_conf_params);
96 if ((sandbox_pins_param[selector] & BIT(p->param)) &&
97 (!!(sandbox_pins_value[selector] & BIT(p->param)) ==
99 strncat(buf, " ", size);
100 strncat(buf, p->property, size);
104 strncat(buf, ".", size);
109 static int sandbox_get_groups_count(struct udevice *dev)
111 return ARRAY_SIZE(sandbox_groups);
114 static const char *sandbox_get_group_name(struct udevice *dev,
117 return sandbox_groups[selector];
120 static int sandbox_get_functions_count(struct udevice *dev)
122 return ARRAY_SIZE(sandbox_functions);
125 static const char *sandbox_get_function_name(struct udevice *dev,
128 return sandbox_functions[selector];
131 static int sandbox_pinmux_set(struct udevice *dev, unsigned pin_selector,
132 unsigned func_selector)
134 debug("sandbox pinmux: pin = %d (%s), function = %d (%s)\n",
135 pin_selector, sandbox_get_pin_name(dev, pin_selector),
136 func_selector, sandbox_get_function_name(dev, func_selector));
138 sandbox_pins_param[pin_selector] = 0;
139 sandbox_pins_value[pin_selector] = 0;
144 static int sandbox_pinmux_group_set(struct udevice *dev,
145 unsigned group_selector,
146 unsigned func_selector)
148 debug("sandbox pinmux: group = %d (%s), function = %d (%s)\n",
149 group_selector, sandbox_get_group_name(dev, group_selector),
150 func_selector, sandbox_get_function_name(dev, func_selector));
155 static int sandbox_pinconf_set(struct udevice *dev, unsigned pin_selector,
156 unsigned param, unsigned argument)
158 debug("sandbox pinconf: pin = %d (%s), param = %d, arg = %d\n",
159 pin_selector, sandbox_get_pin_name(dev, pin_selector),
162 sandbox_pins_param[pin_selector] |= BIT(param);
164 sandbox_pins_value[pin_selector] |= BIT(param);
166 sandbox_pins_value[pin_selector] &= ~BIT(param);
171 static int sandbox_pinconf_group_set(struct udevice *dev,
172 unsigned group_selector,
173 unsigned param, unsigned argument)
175 debug("sandbox pinconf: group = %d (%s), param = %d, arg = %d\n",
176 group_selector, sandbox_get_group_name(dev, group_selector),
182 const struct pinctrl_ops sandbox_pinctrl_ops = {
183 .get_pins_count = sandbox_get_pins_count,
184 .get_pin_name = sandbox_get_pin_name,
185 .get_pin_muxing = sandbox_get_pin_muxing,
186 .get_groups_count = sandbox_get_groups_count,
187 .get_group_name = sandbox_get_group_name,
188 .get_functions_count = sandbox_get_functions_count,
189 .get_function_name = sandbox_get_function_name,
190 .pinmux_set = sandbox_pinmux_set,
191 .pinmux_group_set = sandbox_pinmux_group_set,
192 .pinconf_num_params = ARRAY_SIZE(sandbox_conf_params),
193 .pinconf_params = sandbox_conf_params,
194 .pinconf_set = sandbox_pinconf_set,
195 .pinconf_group_set = sandbox_pinconf_group_set,
196 .set_state = pinctrl_generic_set_state,
199 static const struct udevice_id sandbox_pinctrl_match[] = {
200 { .compatible = "sandbox,pinctrl" },
204 U_BOOT_DRIVER(sandbox_pinctrl) = {
205 .name = "sandbox_pinctrl",
206 .id = UCLASS_PINCTRL,
207 .of_match = sandbox_pinctrl_match,
208 .ops = &sandbox_pinctrl_ops,