1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com>
11 #include <dm/pinctrl.h>
13 static const char * const sandbox_pins[] = {
25 static const char * const sandbox_pins_muxing[] = {
37 static const char * const sandbox_groups[] = {
45 static const char * const sandbox_functions[] = {
56 static const struct pinconf_param sandbox_conf_params[] = {
57 { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
58 { "bias-high-impedance", PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0 },
59 { "bias-bus-hold", PIN_CONFIG_BIAS_BUS_HOLD, 0 },
60 { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
61 { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
62 { "bias-pull-pin-default", PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 1 },
63 { "drive-open-drain", PIN_CONFIG_DRIVE_OPEN_DRAIN, 0 },
64 { "drive-open-source", PIN_CONFIG_DRIVE_OPEN_SOURCE, 0 },
65 { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },
66 { "input-enable", PIN_CONFIG_INPUT_ENABLE, 1 },
67 { "input-disable", PIN_CONFIG_INPUT_ENABLE, 0 },
70 /* bitfield used to save param and value of each pin/selector */
71 static unsigned int sandbox_pins_param[ARRAY_SIZE(sandbox_pins)];
72 static unsigned int sandbox_pins_value[ARRAY_SIZE(sandbox_pins)];
74 static int sandbox_get_pins_count(struct udevice *dev)
76 return ARRAY_SIZE(sandbox_pins);
79 static const char *sandbox_get_pin_name(struct udevice *dev, unsigned selector)
81 return sandbox_pins[selector];
84 static int sandbox_get_pin_muxing(struct udevice *dev,
85 unsigned int selector,
88 const struct pinconf_param *p;
91 snprintf(buf, size, "%s", sandbox_pins_muxing[selector]);
93 if (sandbox_pins_param[selector]) {
94 for (i = 0, p = sandbox_conf_params;
95 i < ARRAY_SIZE(sandbox_conf_params);
97 if ((sandbox_pins_param[selector] & BIT(p->param)) &&
98 (!!(sandbox_pins_value[selector] & BIT(p->param)) ==
100 strncat(buf, " ", size);
101 strncat(buf, p->property, size);
105 strncat(buf, ".", size);
110 static int sandbox_get_groups_count(struct udevice *dev)
112 return ARRAY_SIZE(sandbox_groups);
115 static const char *sandbox_get_group_name(struct udevice *dev,
118 return sandbox_groups[selector];
121 static int sandbox_get_functions_count(struct udevice *dev)
123 return ARRAY_SIZE(sandbox_functions);
126 static const char *sandbox_get_function_name(struct udevice *dev,
129 return sandbox_functions[selector];
132 static int sandbox_pinmux_set(struct udevice *dev, unsigned pin_selector,
133 unsigned func_selector)
135 debug("sandbox pinmux: pin = %d (%s), function = %d (%s)\n",
136 pin_selector, sandbox_get_pin_name(dev, pin_selector),
137 func_selector, sandbox_get_function_name(dev, func_selector));
139 sandbox_pins_param[pin_selector] = 0;
140 sandbox_pins_value[pin_selector] = 0;
145 static int sandbox_pinmux_group_set(struct udevice *dev,
146 unsigned group_selector,
147 unsigned func_selector)
149 debug("sandbox pinmux: group = %d (%s), function = %d (%s)\n",
150 group_selector, sandbox_get_group_name(dev, group_selector),
151 func_selector, sandbox_get_function_name(dev, func_selector));
156 static int sandbox_pinconf_set(struct udevice *dev, unsigned pin_selector,
157 unsigned param, unsigned argument)
159 debug("sandbox pinconf: pin = %d (%s), param = %d, arg = %d\n",
160 pin_selector, sandbox_get_pin_name(dev, pin_selector),
163 sandbox_pins_param[pin_selector] |= BIT(param);
165 sandbox_pins_value[pin_selector] |= BIT(param);
167 sandbox_pins_value[pin_selector] &= ~BIT(param);
172 static int sandbox_pinconf_group_set(struct udevice *dev,
173 unsigned group_selector,
174 unsigned param, unsigned argument)
176 debug("sandbox pinconf: group = %d (%s), param = %d, arg = %d\n",
177 group_selector, sandbox_get_group_name(dev, group_selector),
183 const struct pinctrl_ops sandbox_pinctrl_ops = {
184 .get_pins_count = sandbox_get_pins_count,
185 .get_pin_name = sandbox_get_pin_name,
186 .get_pin_muxing = sandbox_get_pin_muxing,
187 .get_groups_count = sandbox_get_groups_count,
188 .get_group_name = sandbox_get_group_name,
189 .get_functions_count = sandbox_get_functions_count,
190 .get_function_name = sandbox_get_function_name,
191 .pinmux_set = sandbox_pinmux_set,
192 .pinmux_group_set = sandbox_pinmux_group_set,
193 .pinconf_num_params = ARRAY_SIZE(sandbox_conf_params),
194 .pinconf_params = sandbox_conf_params,
195 .pinconf_set = sandbox_pinconf_set,
196 .pinconf_group_set = sandbox_pinconf_group_set,
197 .set_state = pinctrl_generic_set_state,
200 static const struct udevice_id sandbox_pinctrl_match[] = {
201 { .compatible = "sandbox,pinctrl" },
205 U_BOOT_DRIVER(sandbox_pinctrl) = {
206 .name = "sandbox_pinctrl",
207 .id = UCLASS_PINCTRL,
208 .of_match = sandbox_pinctrl_match,
209 .ops = &sandbox_pinctrl_ops,