blob: 0786afe747fc6668cb24044f8ced3ffbff931e8e [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",
Eugen Hristev0523a6c2018-09-18 10:35:34 +030017 "W1"
Masahiro Yamada9c6a3c62015-08-27 12:44:30 +090018};
19
Patrice Chotard21e23aa2018-10-24 14:10:22 +020020static const char * const sandbox_pins_muxing[] = {
21 "I2C SCL",
22 "I2C SDA",
23 "Uart TX",
24 "Uart RX",
25 "1-wire gpio",
26};
27
Masahiro Yamada9c6a3c62015-08-27 12:44:30 +090028static const char * const sandbox_groups[] = {
29 "i2c",
30 "serial_a",
31 "serial_b",
32 "spi",
Eugen Hristev0523a6c2018-09-18 10:35:34 +030033 "w1",
Masahiro Yamada9c6a3c62015-08-27 12:44:30 +090034};
35
36static const char * const sandbox_functions[] = {
37 "i2c",
38 "serial",
39 "spi",
Eugen Hristev0523a6c2018-09-18 10:35:34 +030040 "w1",
Masahiro Yamada9c6a3c62015-08-27 12:44:30 +090041};
42
43static const struct pinconf_param sandbox_conf_params[] = {
44 { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
45 { "bias-high-impedance", PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0 },
46 { "bias-bus-hold", PIN_CONFIG_BIAS_BUS_HOLD, 0 },
47 { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
48 { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
49 { "bias-pull-pin-default", PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 1 },
50 { "drive-open-drain", PIN_CONFIG_DRIVE_OPEN_DRAIN, 0 },
51 { "drive-open-source", PIN_CONFIG_DRIVE_OPEN_SOURCE, 0 },
52 { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },
53 { "input-enable", PIN_CONFIG_INPUT_ENABLE, 1 },
54 { "input-disable", PIN_CONFIG_INPUT_ENABLE, 0 },
55};
56
57static int sandbox_get_pins_count(struct udevice *dev)
58{
59 return ARRAY_SIZE(sandbox_pins);
60}
61
62static const char *sandbox_get_pin_name(struct udevice *dev, unsigned selector)
63{
64 return sandbox_pins[selector];
65}
66
Patrice Chotard21e23aa2018-10-24 14:10:22 +020067static int sandbox_get_pin_muxing(struct udevice *dev,
68 unsigned int selector,
69 char *buf, int size)
70{
71 snprintf(buf, size, "%s", sandbox_pins_muxing[selector]);
72
73 return 0;
74}
75
Masahiro Yamada9c6a3c62015-08-27 12:44:30 +090076static int sandbox_get_groups_count(struct udevice *dev)
77{
78 return ARRAY_SIZE(sandbox_groups);
79}
80
81static const char *sandbox_get_group_name(struct udevice *dev,
82 unsigned selector)
83{
84 return sandbox_groups[selector];
85}
86
87static int sandbox_get_functions_count(struct udevice *dev)
88{
89 return ARRAY_SIZE(sandbox_functions);
90}
91
92static const char *sandbox_get_function_name(struct udevice *dev,
93 unsigned selector)
94{
95 return sandbox_functions[selector];
96}
97
98static int sandbox_pinmux_set(struct udevice *dev, unsigned pin_selector,
99 unsigned func_selector)
100{
101 debug("sandbox pinmux: pin = %d (%s), function = %d (%s)\n",
102 pin_selector, sandbox_get_pin_name(dev, pin_selector),
103 func_selector, sandbox_get_function_name(dev, func_selector));
104
105 return 0;
106}
107
108static int sandbox_pinmux_group_set(struct udevice *dev,
109 unsigned group_selector,
110 unsigned func_selector)
111{
112 debug("sandbox pinmux: group = %d (%s), function = %d (%s)\n",
113 group_selector, sandbox_get_group_name(dev, group_selector),
114 func_selector, sandbox_get_function_name(dev, func_selector));
115
116 return 0;
117}
118
119static int sandbox_pinconf_set(struct udevice *dev, unsigned pin_selector,
120 unsigned param, unsigned argument)
121{
122 debug("sandbox pinconf: pin = %d (%s), param = %d, arg = %d\n",
123 pin_selector, sandbox_get_pin_name(dev, pin_selector),
124 param, argument);
125
126 return 0;
127}
128
129static int sandbox_pinconf_group_set(struct udevice *dev,
130 unsigned group_selector,
131 unsigned param, unsigned argument)
132{
133 debug("sandbox pinconf: group = %d (%s), param = %d, arg = %d\n",
134 group_selector, sandbox_get_group_name(dev, group_selector),
135 param, argument);
136
137 return 0;
138}
139
140const struct pinctrl_ops sandbox_pinctrl_ops = {
141 .get_pins_count = sandbox_get_pins_count,
142 .get_pin_name = sandbox_get_pin_name,
Patrice Chotard21e23aa2018-10-24 14:10:22 +0200143 .get_pin_muxing = sandbox_get_pin_muxing,
Masahiro Yamada9c6a3c62015-08-27 12:44:30 +0900144 .get_groups_count = sandbox_get_groups_count,
145 .get_group_name = sandbox_get_group_name,
146 .get_functions_count = sandbox_get_functions_count,
147 .get_function_name = sandbox_get_function_name,
148 .pinmux_set = sandbox_pinmux_set,
149 .pinmux_group_set = sandbox_pinmux_group_set,
150 .pinconf_num_params = ARRAY_SIZE(sandbox_conf_params),
151 .pinconf_params = sandbox_conf_params,
152 .pinconf_set = sandbox_pinconf_set,
153 .pinconf_group_set = sandbox_pinconf_group_set,
154 .set_state = pinctrl_generic_set_state,
155};
156
157static const struct udevice_id sandbox_pinctrl_match[] = {
158 { .compatible = "sandbox,pinctrl" },
159 { /* sentinel */ }
160};
161
162U_BOOT_DRIVER(sandbox_pinctrl) = {
163 .name = "sandbox_pinctrl",
164 .id = UCLASS_PINCTRL,
165 .of_match = sandbox_pinctrl_match,
166 .ops = &sandbox_pinctrl_ops,
167};