blob: 468fa2a7d0b772f732bc5af82ba8a5e17d000314 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamada9c6a3c62015-08-27 12:44:30 +09002/*
3 * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada9c6a3c62015-08-27 12:44:30 +09004 */
5
6/* #define DEBUG */
7
8#include <common.h>
Simon Glass9d922452017-05-17 17:18:03 -06009#include <dm.h>
Masahiro Yamada9c6a3c62015-08-27 12:44:30 +090010#include <dm/pinctrl.h>
11
12static const char * const sandbox_pins[] = {
13 "SCL",
14 "SDA",
15 "TX",
16 "RX",
17};
18
19static const char * const sandbox_groups[] = {
20 "i2c",
21 "serial_a",
22 "serial_b",
23 "spi",
24};
25
26static const char * const sandbox_functions[] = {
27 "i2c",
28 "serial",
29 "spi",
30};
31
32static const struct pinconf_param sandbox_conf_params[] = {
33 { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
34 { "bias-high-impedance", PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0 },
35 { "bias-bus-hold", PIN_CONFIG_BIAS_BUS_HOLD, 0 },
36 { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
37 { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
38 { "bias-pull-pin-default", PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 1 },
39 { "drive-open-drain", PIN_CONFIG_DRIVE_OPEN_DRAIN, 0 },
40 { "drive-open-source", PIN_CONFIG_DRIVE_OPEN_SOURCE, 0 },
41 { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },
42 { "input-enable", PIN_CONFIG_INPUT_ENABLE, 1 },
43 { "input-disable", PIN_CONFIG_INPUT_ENABLE, 0 },
44};
45
46static int sandbox_get_pins_count(struct udevice *dev)
47{
48 return ARRAY_SIZE(sandbox_pins);
49}
50
51static const char *sandbox_get_pin_name(struct udevice *dev, unsigned selector)
52{
53 return sandbox_pins[selector];
54}
55
56static int sandbox_get_groups_count(struct udevice *dev)
57{
58 return ARRAY_SIZE(sandbox_groups);
59}
60
61static const char *sandbox_get_group_name(struct udevice *dev,
62 unsigned selector)
63{
64 return sandbox_groups[selector];
65}
66
67static int sandbox_get_functions_count(struct udevice *dev)
68{
69 return ARRAY_SIZE(sandbox_functions);
70}
71
72static const char *sandbox_get_function_name(struct udevice *dev,
73 unsigned selector)
74{
75 return sandbox_functions[selector];
76}
77
78static int sandbox_pinmux_set(struct udevice *dev, unsigned pin_selector,
79 unsigned func_selector)
80{
81 debug("sandbox pinmux: pin = %d (%s), function = %d (%s)\n",
82 pin_selector, sandbox_get_pin_name(dev, pin_selector),
83 func_selector, sandbox_get_function_name(dev, func_selector));
84
85 return 0;
86}
87
88static int sandbox_pinmux_group_set(struct udevice *dev,
89 unsigned group_selector,
90 unsigned func_selector)
91{
92 debug("sandbox pinmux: group = %d (%s), function = %d (%s)\n",
93 group_selector, sandbox_get_group_name(dev, group_selector),
94 func_selector, sandbox_get_function_name(dev, func_selector));
95
96 return 0;
97}
98
99static int sandbox_pinconf_set(struct udevice *dev, unsigned pin_selector,
100 unsigned param, unsigned argument)
101{
102 debug("sandbox pinconf: pin = %d (%s), param = %d, arg = %d\n",
103 pin_selector, sandbox_get_pin_name(dev, pin_selector),
104 param, argument);
105
106 return 0;
107}
108
109static int sandbox_pinconf_group_set(struct udevice *dev,
110 unsigned group_selector,
111 unsigned param, unsigned argument)
112{
113 debug("sandbox pinconf: group = %d (%s), param = %d, arg = %d\n",
114 group_selector, sandbox_get_group_name(dev, group_selector),
115 param, argument);
116
117 return 0;
118}
119
120const struct pinctrl_ops sandbox_pinctrl_ops = {
121 .get_pins_count = sandbox_get_pins_count,
122 .get_pin_name = sandbox_get_pin_name,
123 .get_groups_count = sandbox_get_groups_count,
124 .get_group_name = sandbox_get_group_name,
125 .get_functions_count = sandbox_get_functions_count,
126 .get_function_name = sandbox_get_function_name,
127 .pinmux_set = sandbox_pinmux_set,
128 .pinmux_group_set = sandbox_pinmux_group_set,
129 .pinconf_num_params = ARRAY_SIZE(sandbox_conf_params),
130 .pinconf_params = sandbox_conf_params,
131 .pinconf_set = sandbox_pinconf_set,
132 .pinconf_group_set = sandbox_pinconf_group_set,
133 .set_state = pinctrl_generic_set_state,
134};
135
136static const struct udevice_id sandbox_pinctrl_match[] = {
137 { .compatible = "sandbox,pinctrl" },
138 { /* sentinel */ }
139};
140
141U_BOOT_DRIVER(sandbox_pinctrl) = {
142 .name = "sandbox_pinctrl",
143 .id = UCLASS_PINCTRL,
144 .of_match = sandbox_pinctrl_match,
145 .ops = &sandbox_pinctrl_ops,
146};