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