blob: 01d658ea6e98b03d3697ae5af5038d0d8b0a1c17 [file] [log] [blame]
Samuel Hollandb799eab2021-08-12 20:09:43 -05001// SPDX-License-Identifier: GPL-2.0
2
3#include <clk.h>
4#include <dm.h>
5#include <dm/device-internal.h>
6#include <dm/lists.h>
7#include <dm/pinctrl.h>
8#include <errno.h>
9#include <malloc.h>
10
11#include <asm/gpio.h>
12
13extern U_BOOT_DRIVER(gpio_sunxi);
14
Samuel Holland29babfd2021-08-16 23:56:47 -050015/*
16 * This structure implements a simplified view of the possible pinmux settings:
17 * Each mux value is assumed to be the same for a given function, across the
18 * pins in each group (almost universally true, with same rare exceptions not
19 * relevant to U-Boot), but also across different ports (not true in many
20 * cases). We ignore the first problem, and work around the latter by just
21 * supporting one particular port for a each function. This works fine for all
22 * board configurations so far. If this would need to be revisited, we could
23 * add a "u8 port;" below and match that, with 0 encoding the "don't care" case.
24 */
25struct sunxi_pinctrl_function {
26 const char name[sizeof("gpio_out")];
27 u8 mux;
28};
29
Samuel Hollandb799eab2021-08-12 20:09:43 -050030struct sunxi_pinctrl_desc {
Samuel Holland29babfd2021-08-16 23:56:47 -050031 const struct sunxi_pinctrl_function *functions;
32 u8 num_functions;
Samuel Hollandb799eab2021-08-12 20:09:43 -050033 u8 first_bank;
34 u8 num_banks;
35};
36
37struct sunxi_pinctrl_plat {
38 struct sunxi_gpio __iomem *base;
39};
40
Samuel Holland29babfd2021-08-16 23:56:47 -050041static int sunxi_pinctrl_get_pins_count(struct udevice *dev)
42{
43 const struct sunxi_pinctrl_desc *desc = dev_get_priv(dev);
44
45 return desc->num_banks * SUNXI_GPIOS_PER_BANK;
46}
47
48static const char *sunxi_pinctrl_get_pin_name(struct udevice *dev,
49 uint pin_selector)
50{
51 const struct sunxi_pinctrl_desc *desc = dev_get_priv(dev);
52 static char pin_name[sizeof("PN31")];
53
54 snprintf(pin_name, sizeof(pin_name), "P%c%d",
55 pin_selector / SUNXI_GPIOS_PER_BANK + desc->first_bank + 'A',
56 pin_selector % SUNXI_GPIOS_PER_BANK);
57
58 return pin_name;
59}
60
61static int sunxi_pinctrl_get_functions_count(struct udevice *dev)
62{
63 const struct sunxi_pinctrl_desc *desc = dev_get_priv(dev);
64
65 return desc->num_functions;
66}
67
68static const char *sunxi_pinctrl_get_function_name(struct udevice *dev,
69 uint func_selector)
70{
71 const struct sunxi_pinctrl_desc *desc = dev_get_priv(dev);
72
73 return desc->functions[func_selector].name;
74}
75
76static int sunxi_pinctrl_pinmux_set(struct udevice *dev, uint pin_selector,
77 uint func_selector)
78{
79 const struct sunxi_pinctrl_desc *desc = dev_get_priv(dev);
80 struct sunxi_pinctrl_plat *plat = dev_get_plat(dev);
81 int bank = pin_selector / SUNXI_GPIOS_PER_BANK;
82 int pin = pin_selector % SUNXI_GPIOS_PER_BANK;
83
84 debug("set mux: %-4s => %s (%d)\n",
85 sunxi_pinctrl_get_pin_name(dev, pin_selector),
86 sunxi_pinctrl_get_function_name(dev, func_selector),
87 desc->functions[func_selector].mux);
88
89 sunxi_gpio_set_cfgbank(plat->base + bank, pin,
90 desc->functions[func_selector].mux);
91
92 return 0;
93}
94
Samuel Holland50c195e2021-08-28 21:10:47 -050095static const struct pinconf_param sunxi_pinctrl_pinconf_params[] = {
96 { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
97 { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 2 },
98 { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
99 { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 10 },
100};
101
102static int sunxi_pinctrl_pinconf_set_pull(struct sunxi_pinctrl_plat *plat,
103 uint bank, uint pin, uint bias)
104{
105 struct sunxi_gpio *regs = &plat->base[bank];
106
107 sunxi_gpio_set_pull_bank(regs, pin, bias);
108
109 return 0;
110}
111
112static int sunxi_pinctrl_pinconf_set_drive(struct sunxi_pinctrl_plat *plat,
113 uint bank, uint pin, uint drive)
114{
115 struct sunxi_gpio *regs = &plat->base[bank];
116
117 if (drive < 10 || drive > 40)
118 return -EINVAL;
119
120 /* Convert mA to the register value, rounding down. */
121 sunxi_gpio_set_drv_bank(regs, pin, drive / 10 - 1);
122
123 return 0;
124}
125
126static int sunxi_pinctrl_pinconf_set(struct udevice *dev, uint pin_selector,
127 uint param, uint val)
128{
129 struct sunxi_pinctrl_plat *plat = dev_get_plat(dev);
130 int bank = pin_selector / SUNXI_GPIOS_PER_BANK;
131 int pin = pin_selector % SUNXI_GPIOS_PER_BANK;
132
133 switch (param) {
134 case PIN_CONFIG_BIAS_DISABLE:
135 case PIN_CONFIG_BIAS_PULL_DOWN:
136 case PIN_CONFIG_BIAS_PULL_UP:
137 return sunxi_pinctrl_pinconf_set_pull(plat, bank, pin, val);
138 case PIN_CONFIG_DRIVE_STRENGTH:
139 return sunxi_pinctrl_pinconf_set_drive(plat, bank, pin, val);
140 }
141
142 return -EINVAL;
143}
144
Samuel Hollandd4b38822021-08-17 00:52:00 -0500145static int sunxi_pinctrl_get_pin_muxing(struct udevice *dev, uint pin_selector,
146 char *buf, int size)
147{
148 struct sunxi_pinctrl_plat *plat = dev_get_plat(dev);
149 int bank = pin_selector / SUNXI_GPIOS_PER_BANK;
150 int pin = pin_selector % SUNXI_GPIOS_PER_BANK;
151 int mux = sunxi_gpio_get_cfgbank(plat->base + bank, pin);
152
153 switch (mux) {
154 case SUNXI_GPIO_INPUT:
155 strlcpy(buf, "gpio input", size);
156 break;
157 case SUNXI_GPIO_OUTPUT:
158 strlcpy(buf, "gpio output", size);
159 break;
160 case SUNXI_GPIO_DISABLE:
161 strlcpy(buf, "disabled", size);
162 break;
163 default:
164 snprintf(buf, size, "function %d", mux);
165 break;
166 }
167
168 return 0;
169}
170
Samuel Hollandb799eab2021-08-12 20:09:43 -0500171static const struct pinctrl_ops sunxi_pinctrl_ops = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500172 .get_pins_count = sunxi_pinctrl_get_pins_count,
173 .get_pin_name = sunxi_pinctrl_get_pin_name,
174 .get_functions_count = sunxi_pinctrl_get_functions_count,
175 .get_function_name = sunxi_pinctrl_get_function_name,
176 .pinmux_set = sunxi_pinctrl_pinmux_set,
Samuel Holland50c195e2021-08-28 21:10:47 -0500177 .pinconf_num_params = ARRAY_SIZE(sunxi_pinctrl_pinconf_params),
178 .pinconf_params = sunxi_pinctrl_pinconf_params,
179 .pinconf_set = sunxi_pinctrl_pinconf_set,
Samuel Hollandb799eab2021-08-12 20:09:43 -0500180 .set_state = pinctrl_generic_set_state,
Samuel Hollandd4b38822021-08-17 00:52:00 -0500181 .get_pin_muxing = sunxi_pinctrl_get_pin_muxing,
Samuel Hollandb799eab2021-08-12 20:09:43 -0500182};
183
184static int sunxi_pinctrl_bind(struct udevice *dev)
185{
186 struct sunxi_pinctrl_plat *plat = dev_get_plat(dev);
187 struct sunxi_pinctrl_desc *desc;
188 struct sunxi_gpio_plat *gpio_plat;
189 struct udevice *gpio_dev;
190 int i, ret;
191
192 desc = (void *)dev_get_driver_data(dev);
193 if (!desc)
194 return -EINVAL;
195 dev_set_priv(dev, desc);
196
197 plat->base = dev_read_addr_ptr(dev);
198
199 ret = device_bind_driver_to_node(dev, "gpio_sunxi", dev->name,
200 dev_ofnode(dev), &gpio_dev);
201 if (ret)
202 return ret;
203
204 for (i = 0; i < desc->num_banks; ++i) {
205 gpio_plat = malloc(sizeof(*gpio_plat));
206 if (!gpio_plat)
207 return -ENOMEM;
208
209 gpio_plat->regs = plat->base + i;
210 gpio_plat->bank_name[0] = 'P';
211 gpio_plat->bank_name[1] = 'A' + desc->first_bank + i;
212 gpio_plat->bank_name[2] = '\0';
213
214 ret = device_bind(gpio_dev, DM_DRIVER_REF(gpio_sunxi),
215 gpio_plat->bank_name, gpio_plat,
216 ofnode_null(), NULL);
217 if (ret)
218 return ret;
219 }
220
221 return 0;
222}
223
224static int sunxi_pinctrl_probe(struct udevice *dev)
225{
226 struct clk *apb_clk;
227
228 apb_clk = devm_clk_get(dev, "apb");
229 if (!IS_ERR(apb_clk))
230 clk_enable(apb_clk);
231
232 return 0;
233}
234
Samuel Holland29babfd2021-08-16 23:56:47 -0500235static const struct sunxi_pinctrl_function suniv_f1c100s_pinctrl_functions[] = {
236 { "gpio_in", 0 },
237 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500238#if IS_ENABLED(CONFIG_UART0_PORT_F)
239 { "uart0", 3 }, /* PF2-PF4 */
240#else
241 { "uart0", 5 }, /* PE0-PE1 */
242#endif
Samuel Holland29babfd2021-08-16 23:56:47 -0500243};
244
Samuel Hollandb799eab2021-08-12 20:09:43 -0500245static const struct sunxi_pinctrl_desc __maybe_unused suniv_f1c100s_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500246 .functions = suniv_f1c100s_pinctrl_functions,
247 .num_functions = ARRAY_SIZE(suniv_f1c100s_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500248 .first_bank = SUNXI_GPIO_A,
249 .num_banks = 6,
250};
251
Samuel Holland29babfd2021-08-16 23:56:47 -0500252static const struct sunxi_pinctrl_function sun4i_a10_pinctrl_functions[] = {
Samuel Hollandfcdbbd62021-08-28 13:21:36 -0500253 { "emac", 2 }, /* PA0-PA17 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500254 { "gpio_in", 0 },
255 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500256#if IS_ENABLED(CONFIG_UART0_PORT_F)
257 { "uart0", 4 }, /* PF2-PF4 */
258#else
259 { "uart0", 2 }, /* PB22-PB23 */
260#endif
Samuel Holland29babfd2021-08-16 23:56:47 -0500261};
262
Samuel Hollandb799eab2021-08-12 20:09:43 -0500263static const struct sunxi_pinctrl_desc __maybe_unused sun4i_a10_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500264 .functions = sun4i_a10_pinctrl_functions,
265 .num_functions = ARRAY_SIZE(sun4i_a10_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500266 .first_bank = SUNXI_GPIO_A,
267 .num_banks = 9,
268};
269
Samuel Holland29babfd2021-08-16 23:56:47 -0500270static const struct sunxi_pinctrl_function sun5i_a13_pinctrl_functions[] = {
Samuel Hollandfcdbbd62021-08-28 13:21:36 -0500271 { "emac", 2 }, /* PA0-PA17 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500272 { "gpio_in", 0 },
273 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500274#if IS_ENABLED(CONFIG_UART0_PORT_F)
275 { "uart0", 4 }, /* PF2-PF4 */
276#else
277 { "uart0", 2 }, /* PB19-PB20 */
278#endif
279 { "uart1", 4 }, /* PG3-PG4 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500280};
281
Samuel Hollandb799eab2021-08-12 20:09:43 -0500282static const struct sunxi_pinctrl_desc __maybe_unused sun5i_a13_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500283 .functions = sun5i_a13_pinctrl_functions,
284 .num_functions = ARRAY_SIZE(sun5i_a13_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500285 .first_bank = SUNXI_GPIO_A,
286 .num_banks = 7,
287};
288
Samuel Holland29babfd2021-08-16 23:56:47 -0500289static const struct sunxi_pinctrl_function sun6i_a31_pinctrl_functions[] = {
Samuel Holland7a936442021-08-28 13:13:52 -0500290 { "gmac", 2 }, /* PA0-PA27 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500291 { "gpio_in", 0 },
292 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500293#if IS_ENABLED(CONFIG_UART0_PORT_F)
294 { "uart0", 3 }, /* PF2-PF4 */
295#else
296 { "uart0", 2 }, /* PH20-PH21 */
297#endif
Samuel Holland29babfd2021-08-16 23:56:47 -0500298};
299
Samuel Hollandb799eab2021-08-12 20:09:43 -0500300static const struct sunxi_pinctrl_desc __maybe_unused sun6i_a31_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500301 .functions = sun6i_a31_pinctrl_functions,
302 .num_functions = ARRAY_SIZE(sun6i_a31_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500303 .first_bank = SUNXI_GPIO_A,
304 .num_banks = 8,
305};
306
Samuel Holland29babfd2021-08-16 23:56:47 -0500307static const struct sunxi_pinctrl_function sun6i_a31_r_pinctrl_functions[] = {
308 { "gpio_in", 0 },
309 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500310 { "s_uart", 2 }, /* PL2-PL3 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500311};
312
Samuel Hollandb799eab2021-08-12 20:09:43 -0500313static const struct sunxi_pinctrl_desc __maybe_unused sun6i_a31_r_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500314 .functions = sun6i_a31_r_pinctrl_functions,
315 .num_functions = ARRAY_SIZE(sun6i_a31_r_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500316 .first_bank = SUNXI_GPIO_L,
317 .num_banks = 2,
318};
319
Samuel Holland29babfd2021-08-16 23:56:47 -0500320static const struct sunxi_pinctrl_function sun7i_a20_pinctrl_functions[] = {
Samuel Hollandfcdbbd62021-08-28 13:21:36 -0500321 { "emac", 2 }, /* PA0-PA17 */
Samuel Holland7a936442021-08-28 13:13:52 -0500322 { "gmac", 5 }, /* PA0-PA17 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500323 { "gpio_in", 0 },
324 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500325#if IS_ENABLED(CONFIG_UART0_PORT_F)
326 { "uart0", 4 }, /* PF2-PF4 */
327#else
328 { "uart0", 2 }, /* PB22-PB23 */
329#endif
Samuel Holland29babfd2021-08-16 23:56:47 -0500330};
331
Samuel Hollandb799eab2021-08-12 20:09:43 -0500332static const struct sunxi_pinctrl_desc __maybe_unused sun7i_a20_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500333 .functions = sun7i_a20_pinctrl_functions,
334 .num_functions = ARRAY_SIZE(sun7i_a20_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500335 .first_bank = SUNXI_GPIO_A,
336 .num_banks = 9,
337};
338
Samuel Holland29babfd2021-08-16 23:56:47 -0500339static const struct sunxi_pinctrl_function sun8i_a23_pinctrl_functions[] = {
340 { "gpio_in", 0 },
341 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500342#if IS_ENABLED(CONFIG_UART0_PORT_F)
343 { "uart0", 3 }, /* PF2-PF4 */
344#endif
345 { "uart1", 2 }, /* PG6-PG7 */
346 { "uart2", 2 }, /* PB0-PB1 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500347};
348
Samuel Hollandb799eab2021-08-12 20:09:43 -0500349static const struct sunxi_pinctrl_desc __maybe_unused sun8i_a23_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500350 .functions = sun8i_a23_pinctrl_functions,
351 .num_functions = ARRAY_SIZE(sun8i_a23_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500352 .first_bank = SUNXI_GPIO_A,
353 .num_banks = 8,
354};
355
Samuel Holland29babfd2021-08-16 23:56:47 -0500356static const struct sunxi_pinctrl_function sun8i_a23_r_pinctrl_functions[] = {
357 { "gpio_in", 0 },
358 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500359 { "s_uart", 2 }, /* PL2-PL3 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500360};
361
Samuel Hollandb799eab2021-08-12 20:09:43 -0500362static const struct sunxi_pinctrl_desc __maybe_unused sun8i_a23_r_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500363 .functions = sun8i_a23_r_pinctrl_functions,
364 .num_functions = ARRAY_SIZE(sun8i_a23_r_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500365 .first_bank = SUNXI_GPIO_L,
366 .num_banks = 1,
367};
368
Samuel Holland29babfd2021-08-16 23:56:47 -0500369static const struct sunxi_pinctrl_function sun8i_a33_pinctrl_functions[] = {
370 { "gpio_in", 0 },
371 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500372#if IS_ENABLED(CONFIG_UART0_PORT_F)
373 { "uart0", 3 }, /* PF2-PF4 */
374#else
375 { "uart0", 3 }, /* PB0-PB1 */
376#endif
377 { "uart1", 2 }, /* PG6-PG7 */
378 { "uart2", 2 }, /* PB0-PB1 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500379};
380
Samuel Hollandb799eab2021-08-12 20:09:43 -0500381static const struct sunxi_pinctrl_desc __maybe_unused sun8i_a33_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500382 .functions = sun8i_a33_pinctrl_functions,
383 .num_functions = ARRAY_SIZE(sun8i_a33_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500384 .first_bank = SUNXI_GPIO_A,
385 .num_banks = 8,
386};
387
Samuel Holland29babfd2021-08-16 23:56:47 -0500388static const struct sunxi_pinctrl_function sun8i_a83t_pinctrl_functions[] = {
Samuel Holland37b3de42021-08-28 13:34:29 -0500389 { "gmac", 4 }, /* PD2-PD23 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500390 { "gpio_in", 0 },
391 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500392#if IS_ENABLED(CONFIG_UART0_PORT_F)
393 { "uart0", 3 }, /* PF2-PF4 */
394#else
395 { "uart0", 2 }, /* PB9-PB10 */
396#endif
397 { "uart1", 2 }, /* PG6-PG7 */
398 { "uart2", 2 }, /* PB0-PB1 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500399};
400
Samuel Hollandb799eab2021-08-12 20:09:43 -0500401static const struct sunxi_pinctrl_desc __maybe_unused sun8i_a83t_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500402 .functions = sun8i_a83t_pinctrl_functions,
403 .num_functions = ARRAY_SIZE(sun8i_a83t_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500404 .first_bank = SUNXI_GPIO_A,
405 .num_banks = 8,
406};
407
Samuel Holland29babfd2021-08-16 23:56:47 -0500408static const struct sunxi_pinctrl_function sun8i_a83t_r_pinctrl_functions[] = {
409 { "gpio_in", 0 },
410 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500411 { "s_uart", 2 }, /* PL2-PL3 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500412};
413
Samuel Hollandb799eab2021-08-12 20:09:43 -0500414static const struct sunxi_pinctrl_desc __maybe_unused sun8i_a83t_r_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500415 .functions = sun8i_a83t_r_pinctrl_functions,
416 .num_functions = ARRAY_SIZE(sun8i_a83t_r_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500417 .first_bank = SUNXI_GPIO_L,
418 .num_banks = 1,
419};
420
Samuel Holland29babfd2021-08-16 23:56:47 -0500421static const struct sunxi_pinctrl_function sun8i_h3_pinctrl_functions[] = {
Samuel Holland37b3de42021-08-28 13:34:29 -0500422 { "emac", 2 }, /* PD0-PD17 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500423 { "gpio_in", 0 },
424 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500425#if IS_ENABLED(CONFIG_UART0_PORT_F)
426 { "uart0", 3 }, /* PF2-PF4 */
427#else
428 { "uart0", 2 }, /* PA4-PA5 */
429#endif
430 { "uart1", 2 }, /* PG6-PG7 */
431 { "uart2", 2 }, /* PA0-PA1 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500432};
433
Samuel Hollandb799eab2021-08-12 20:09:43 -0500434static const struct sunxi_pinctrl_desc __maybe_unused sun8i_h3_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500435 .functions = sun8i_h3_pinctrl_functions,
436 .num_functions = ARRAY_SIZE(sun8i_h3_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500437 .first_bank = SUNXI_GPIO_A,
438 .num_banks = 7,
439};
440
Samuel Holland29babfd2021-08-16 23:56:47 -0500441static const struct sunxi_pinctrl_function sun8i_h3_r_pinctrl_functions[] = {
442 { "gpio_in", 0 },
443 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500444 { "s_uart", 2 }, /* PL2-PL3 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500445};
446
Samuel Hollandb799eab2021-08-12 20:09:43 -0500447static const struct sunxi_pinctrl_desc __maybe_unused sun8i_h3_r_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500448 .functions = sun8i_h3_r_pinctrl_functions,
449 .num_functions = ARRAY_SIZE(sun8i_h3_r_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500450 .first_bank = SUNXI_GPIO_L,
451 .num_banks = 1,
452};
453
Samuel Holland29babfd2021-08-16 23:56:47 -0500454static const struct sunxi_pinctrl_function sun8i_v3s_pinctrl_functions[] = {
Samuel Holland37b3de42021-08-28 13:34:29 -0500455 { "emac", 4 }, /* PD0-PD17 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500456 { "gpio_in", 0 },
457 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500458#if IS_ENABLED(CONFIG_UART0_PORT_F)
459 { "uart0", 3 }, /* PF2-PF4 */
460#else
461 { "uart0", 3 }, /* PB8-PB9 */
462#endif
463 { "uart1", 2 }, /* PG6-PG7 */
464 { "uart2", 2 }, /* PB0-PB1 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500465};
466
Samuel Hollandb799eab2021-08-12 20:09:43 -0500467static const struct sunxi_pinctrl_desc __maybe_unused sun8i_v3s_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500468 .functions = sun8i_v3s_pinctrl_functions,
469 .num_functions = ARRAY_SIZE(sun8i_v3s_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500470 .first_bank = SUNXI_GPIO_A,
471 .num_banks = 7,
472};
473
Samuel Holland29babfd2021-08-16 23:56:47 -0500474static const struct sunxi_pinctrl_function sun9i_a80_pinctrl_functions[] = {
Samuel Holland7a936442021-08-28 13:13:52 -0500475 { "gmac", 2 }, /* PA0-PA17 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500476 { "gpio_in", 0 },
477 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500478#if IS_ENABLED(CONFIG_UART0_PORT_F)
479 { "uart0", 4 }, /* PF2-PF4 */
480#else
481 { "uart0", 2 }, /* PH12-PH13 */
482#endif
Samuel Holland29babfd2021-08-16 23:56:47 -0500483};
484
Samuel Hollandb799eab2021-08-12 20:09:43 -0500485static const struct sunxi_pinctrl_desc __maybe_unused sun9i_a80_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500486 .functions = sun9i_a80_pinctrl_functions,
487 .num_functions = ARRAY_SIZE(sun9i_a80_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500488 .first_bank = SUNXI_GPIO_A,
489 .num_banks = 8,
490};
491
Samuel Holland29babfd2021-08-16 23:56:47 -0500492static const struct sunxi_pinctrl_function sun9i_a80_r_pinctrl_functions[] = {
493 { "gpio_in", 0 },
494 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500495 { "s_uart", 3 }, /* PL0-PL1 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500496};
497
Samuel Hollandb799eab2021-08-12 20:09:43 -0500498static const struct sunxi_pinctrl_desc __maybe_unused sun9i_a80_r_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500499 .functions = sun9i_a80_r_pinctrl_functions,
500 .num_functions = ARRAY_SIZE(sun9i_a80_r_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500501 .first_bank = SUNXI_GPIO_L,
502 .num_banks = 3,
503};
504
Samuel Holland29babfd2021-08-16 23:56:47 -0500505static const struct sunxi_pinctrl_function sun50i_a64_pinctrl_functions[] = {
Samuel Holland37b3de42021-08-28 13:34:29 -0500506 { "emac", 4 }, /* PD8-PD23 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500507 { "gpio_in", 0 },
508 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500509#if IS_ENABLED(CONFIG_UART0_PORT_F)
510 { "uart0", 3 }, /* PF2-PF4 */
511#else
512 { "uart0", 4 }, /* PB8-PB9 */
513#endif
514 { "uart1", 2 }, /* PG6-PG7 */
515 { "uart2", 2 }, /* PB0-PB1 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500516};
517
Samuel Hollandb799eab2021-08-12 20:09:43 -0500518static const struct sunxi_pinctrl_desc __maybe_unused sun50i_a64_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500519 .functions = sun50i_a64_pinctrl_functions,
520 .num_functions = ARRAY_SIZE(sun50i_a64_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500521 .first_bank = SUNXI_GPIO_A,
522 .num_banks = 8,
523};
524
Samuel Holland29babfd2021-08-16 23:56:47 -0500525static const struct sunxi_pinctrl_function sun50i_a64_r_pinctrl_functions[] = {
526 { "gpio_in", 0 },
527 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500528 { "s_uart", 2 }, /* PL2-PL3 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500529};
530
Samuel Hollandb799eab2021-08-12 20:09:43 -0500531static const struct sunxi_pinctrl_desc __maybe_unused sun50i_a64_r_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500532 .functions = sun50i_a64_r_pinctrl_functions,
533 .num_functions = ARRAY_SIZE(sun50i_a64_r_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500534 .first_bank = SUNXI_GPIO_L,
535 .num_banks = 1,
536};
537
Samuel Holland29babfd2021-08-16 23:56:47 -0500538static const struct sunxi_pinctrl_function sun50i_h5_pinctrl_functions[] = {
Samuel Holland37b3de42021-08-28 13:34:29 -0500539 { "emac", 2 }, /* PD0-PD17 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500540 { "gpio_in", 0 },
541 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500542#if IS_ENABLED(CONFIG_UART0_PORT_F)
543 { "uart0", 3 }, /* PF2-PF4 */
544#else
545 { "uart0", 2 }, /* PA4-PA5 */
546#endif
547 { "uart1", 2 }, /* PG6-PG7 */
548 { "uart2", 2 }, /* PA0-PA1 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500549};
550
Samuel Hollandb799eab2021-08-12 20:09:43 -0500551static const struct sunxi_pinctrl_desc __maybe_unused sun50i_h5_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500552 .functions = sun50i_h5_pinctrl_functions,
553 .num_functions = ARRAY_SIZE(sun50i_h5_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500554 .first_bank = SUNXI_GPIO_A,
555 .num_banks = 7,
556};
557
Samuel Holland29babfd2021-08-16 23:56:47 -0500558static const struct sunxi_pinctrl_function sun50i_h6_pinctrl_functions[] = {
Samuel Holland37b3de42021-08-28 13:34:29 -0500559 { "emac", 5 }, /* PD0-PD20 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500560 { "gpio_in", 0 },
561 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500562#if IS_ENABLED(CONFIG_UART0_PORT_F)
563 { "uart0", 3 }, /* PF2-PF4 */
564#else
565 { "uart0", 2 }, /* PH0-PH1 */
566#endif
567 { "uart1", 2 }, /* PG6-PG7 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500568};
569
Samuel Hollandb799eab2021-08-12 20:09:43 -0500570static const struct sunxi_pinctrl_desc __maybe_unused sun50i_h6_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500571 .functions = sun50i_h6_pinctrl_functions,
572 .num_functions = ARRAY_SIZE(sun50i_h6_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500573 .first_bank = SUNXI_GPIO_A,
574 .num_banks = 8,
575};
576
Samuel Holland29babfd2021-08-16 23:56:47 -0500577static const struct sunxi_pinctrl_function sun50i_h6_r_pinctrl_functions[] = {
578 { "gpio_in", 0 },
579 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500580 { "s_uart", 2 }, /* PL2-PL3 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500581};
582
Samuel Hollandb799eab2021-08-12 20:09:43 -0500583static const struct sunxi_pinctrl_desc __maybe_unused sun50i_h6_r_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500584 .functions = sun50i_h6_r_pinctrl_functions,
585 .num_functions = ARRAY_SIZE(sun50i_h6_r_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500586 .first_bank = SUNXI_GPIO_L,
587 .num_banks = 2,
588};
589
Samuel Holland29babfd2021-08-16 23:56:47 -0500590static const struct sunxi_pinctrl_function sun50i_h616_pinctrl_functions[] = {
Samuel Holland37b3de42021-08-28 13:34:29 -0500591 { "emac0", 2 }, /* PI0-PI16 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500592 { "gpio_in", 0 },
593 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500594#if IS_ENABLED(CONFIG_UART0_PORT_F)
595 { "uart0", 3 }, /* PF2-PF4 */
596#else
597 { "uart0", 2 }, /* PH0-PH1 */
598#endif
599 { "uart1", 2 }, /* PG6-PG7 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500600};
601
Samuel Hollandb799eab2021-08-12 20:09:43 -0500602static const struct sunxi_pinctrl_desc __maybe_unused sun50i_h616_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500603 .functions = sun50i_h616_pinctrl_functions,
604 .num_functions = ARRAY_SIZE(sun50i_h616_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500605 .first_bank = SUNXI_GPIO_A,
606 .num_banks = 9,
607};
608
Samuel Holland29babfd2021-08-16 23:56:47 -0500609static const struct sunxi_pinctrl_function sun50i_h616_r_pinctrl_functions[] = {
610 { "gpio_in", 0 },
611 { "gpio_out", 1 },
Samuel Holland470a7bd2021-08-28 13:00:45 -0500612 { "s_uart", 2 }, /* PL2-PL3 */
Samuel Holland29babfd2021-08-16 23:56:47 -0500613};
614
Samuel Hollandb799eab2021-08-12 20:09:43 -0500615static const struct sunxi_pinctrl_desc __maybe_unused sun50i_h616_r_pinctrl_desc = {
Samuel Holland29babfd2021-08-16 23:56:47 -0500616 .functions = sun50i_h616_r_pinctrl_functions,
617 .num_functions = ARRAY_SIZE(sun50i_h616_r_pinctrl_functions),
Samuel Hollandb799eab2021-08-12 20:09:43 -0500618 .first_bank = SUNXI_GPIO_L,
619 .num_banks = 1,
620};
621
622static const struct udevice_id sunxi_pinctrl_ids[] = {
623#ifdef CONFIG_PINCTRL_SUNIV_F1C100S
624 {
625 .compatible = "allwinner,suniv-f1c100s-pinctrl",
626 .data = (ulong)&suniv_f1c100s_pinctrl_desc,
627 },
628#endif
629#ifdef CONFIG_PINCTRL_SUN4I_A10
630 {
631 .compatible = "allwinner,sun4i-a10-pinctrl",
632 .data = (ulong)&sun4i_a10_pinctrl_desc,
633 },
634#endif
635#ifdef CONFIG_PINCTRL_SUN5I_A13
636 {
637 .compatible = "allwinner,sun5i-a10s-pinctrl",
638 .data = (ulong)&sun5i_a13_pinctrl_desc,
639 },
640 {
641 .compatible = "allwinner,sun5i-a13-pinctrl",
642 .data = (ulong)&sun5i_a13_pinctrl_desc,
643 },
644#endif
645#ifdef CONFIG_PINCTRL_SUN6I_A31
646 {
647 .compatible = "allwinner,sun6i-a31-pinctrl",
648 .data = (ulong)&sun6i_a31_pinctrl_desc,
649 },
650 {
651 .compatible = "allwinner,sun6i-a31s-pinctrl",
652 .data = (ulong)&sun6i_a31_pinctrl_desc,
653 },
654#endif
655#ifdef CONFIG_PINCTRL_SUN6I_A31_R
656 {
657 .compatible = "allwinner,sun6i-a31-r-pinctrl",
658 .data = (ulong)&sun6i_a31_r_pinctrl_desc,
659 },
660#endif
661#ifdef CONFIG_PINCTRL_SUN7I_A20
662 {
663 .compatible = "allwinner,sun7i-a20-pinctrl",
664 .data = (ulong)&sun7i_a20_pinctrl_desc,
665 },
666#endif
667#ifdef CONFIG_PINCTRL_SUN8I_A23
668 {
669 .compatible = "allwinner,sun8i-a23-pinctrl",
670 .data = (ulong)&sun8i_a23_pinctrl_desc,
671 },
672#endif
673#ifdef CONFIG_PINCTRL_SUN8I_A23_R
674 {
675 .compatible = "allwinner,sun8i-a23-r-pinctrl",
676 .data = (ulong)&sun8i_a23_r_pinctrl_desc,
677 },
678#endif
679#ifdef CONFIG_PINCTRL_SUN8I_A33
680 {
681 .compatible = "allwinner,sun8i-a33-pinctrl",
682 .data = (ulong)&sun8i_a33_pinctrl_desc,
683 },
684#endif
685#ifdef CONFIG_PINCTRL_SUN8I_A83T
686 {
687 .compatible = "allwinner,sun8i-a83t-pinctrl",
688 .data = (ulong)&sun8i_a83t_pinctrl_desc,
689 },
690#endif
691#ifdef CONFIG_PINCTRL_SUN8I_A83T_R
692 {
693 .compatible = "allwinner,sun8i-a83t-r-pinctrl",
694 .data = (ulong)&sun8i_a83t_r_pinctrl_desc,
695 },
696#endif
697#ifdef CONFIG_PINCTRL_SUN8I_H3
698 {
699 .compatible = "allwinner,sun8i-h3-pinctrl",
700 .data = (ulong)&sun8i_h3_pinctrl_desc,
701 },
702#endif
703#ifdef CONFIG_PINCTRL_SUN8I_H3_R
704 {
705 .compatible = "allwinner,sun8i-h3-r-pinctrl",
706 .data = (ulong)&sun8i_h3_r_pinctrl_desc,
707 },
708#endif
709#ifdef CONFIG_PINCTRL_SUN7I_A20
710 {
711 .compatible = "allwinner,sun8i-r40-pinctrl",
712 .data = (ulong)&sun7i_a20_pinctrl_desc,
713 },
714#endif
715#ifdef CONFIG_PINCTRL_SUN8I_V3S
716 {
717 .compatible = "allwinner,sun8i-v3-pinctrl",
718 .data = (ulong)&sun8i_v3s_pinctrl_desc,
719 },
720 {
721 .compatible = "allwinner,sun8i-v3s-pinctrl",
722 .data = (ulong)&sun8i_v3s_pinctrl_desc,
723 },
724#endif
725#ifdef CONFIG_PINCTRL_SUN9I_A80
726 {
727 .compatible = "allwinner,sun9i-a80-pinctrl",
728 .data = (ulong)&sun9i_a80_pinctrl_desc,
729 },
730#endif
731#ifdef CONFIG_PINCTRL_SUN9I_A80_R
732 {
733 .compatible = "allwinner,sun9i-a80-r-pinctrl",
734 .data = (ulong)&sun9i_a80_r_pinctrl_desc,
735 },
736#endif
737#ifdef CONFIG_PINCTRL_SUN50I_A64
738 {
739 .compatible = "allwinner,sun50i-a64-pinctrl",
740 .data = (ulong)&sun50i_a64_pinctrl_desc,
741 },
742#endif
743#ifdef CONFIG_PINCTRL_SUN50I_A64_R
744 {
745 .compatible = "allwinner,sun50i-a64-r-pinctrl",
746 .data = (ulong)&sun50i_a64_r_pinctrl_desc,
747 },
748#endif
749#ifdef CONFIG_PINCTRL_SUN50I_H5
750 {
751 .compatible = "allwinner,sun50i-h5-pinctrl",
752 .data = (ulong)&sun50i_h5_pinctrl_desc,
753 },
754#endif
755#ifdef CONFIG_PINCTRL_SUN50I_H6
756 {
757 .compatible = "allwinner,sun50i-h6-pinctrl",
758 .data = (ulong)&sun50i_h6_pinctrl_desc,
759 },
760#endif
761#ifdef CONFIG_PINCTRL_SUN50I_H6_R
762 {
763 .compatible = "allwinner,sun50i-h6-r-pinctrl",
764 .data = (ulong)&sun50i_h6_r_pinctrl_desc,
765 },
766#endif
767#ifdef CONFIG_PINCTRL_SUN50I_H616
768 {
769 .compatible = "allwinner,sun50i-h616-pinctrl",
770 .data = (ulong)&sun50i_h616_pinctrl_desc,
771 },
772#endif
773#ifdef CONFIG_PINCTRL_SUN50I_H616_R
774 {
775 .compatible = "allwinner,sun50i-h616-r-pinctrl",
776 .data = (ulong)&sun50i_h616_r_pinctrl_desc,
777 },
778#endif
779 {}
780};
781
782U_BOOT_DRIVER(sunxi_pinctrl) = {
783 .name = "sunxi-pinctrl",
784 .id = UCLASS_PINCTRL,
785 .of_match = sunxi_pinctrl_ids,
786 .bind = sunxi_pinctrl_bind,
787 .probe = sunxi_pinctrl_probe,
788 .plat_auto = sizeof(struct sunxi_pinctrl_plat),
789 .ops = &sunxi_pinctrl_ops,
790};