blob: ce7119931daac874ee25d5163be0e04fcf3930af [file] [log] [blame]
Samuel Hollande3095022021-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 Hollandecbbedb2021-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 Hollande3095022021-08-12 20:09:43 -050030struct sunxi_pinctrl_desc {
Samuel Hollandecbbedb2021-08-16 23:56:47 -050031 const struct sunxi_pinctrl_function *functions;
32 u8 num_functions;
Samuel Hollande3095022021-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 Hollandecbbedb2021-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 Hollandde828b42021-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 Holland116d5232021-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 Hollande3095022021-08-12 20:09:43 -0500171static const struct pinctrl_ops sunxi_pinctrl_ops = {
Samuel Hollandecbbedb2021-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 Hollandde828b42021-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 Hollande3095022021-08-12 20:09:43 -0500180 .set_state = pinctrl_generic_set_state,
Samuel Holland116d5232021-08-17 00:52:00 -0500181 .get_pin_muxing = sunxi_pinctrl_get_pin_muxing,
Samuel Hollande3095022021-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 Hollandecbbedb2021-08-16 23:56:47 -0500235static const struct sunxi_pinctrl_function suniv_f1c100s_pinctrl_functions[] = {
236 { "gpio_in", 0 },
237 { "gpio_out", 1 },
Samuel Holland5a08d412021-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 Hollandecbbedb2021-08-16 23:56:47 -0500243};
244
Samuel Hollande3095022021-08-12 20:09:43 -0500245static const struct sunxi_pinctrl_desc __maybe_unused suniv_f1c100s_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500246 .functions = suniv_f1c100s_pinctrl_functions,
247 .num_functions = ARRAY_SIZE(suniv_f1c100s_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500248 .first_bank = SUNXI_GPIO_A,
249 .num_banks = 6,
250};
251
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500252static const struct sunxi_pinctrl_function sun4i_a10_pinctrl_functions[] = {
Samuel Holland5d57e052021-08-28 13:21:36 -0500253 { "emac", 2 }, /* PA0-PA17 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500254 { "gpio_in", 0 },
255 { "gpio_out", 1 },
Samuel Holland5a08d412021-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 Hollandecbbedb2021-08-16 23:56:47 -0500261};
262
Samuel Hollande3095022021-08-12 20:09:43 -0500263static const struct sunxi_pinctrl_desc __maybe_unused sun4i_a10_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500264 .functions = sun4i_a10_pinctrl_functions,
265 .num_functions = ARRAY_SIZE(sun4i_a10_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500266 .first_bank = SUNXI_GPIO_A,
267 .num_banks = 9,
268};
269
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500270static const struct sunxi_pinctrl_function sun5i_a13_pinctrl_functions[] = {
Samuel Holland5d57e052021-08-28 13:21:36 -0500271 { "emac", 2 }, /* PA0-PA17 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500272 { "gpio_in", 0 },
273 { "gpio_out", 1 },
Samuel Holland5a08d412021-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 Hollandecbbedb2021-08-16 23:56:47 -0500280};
281
Samuel Hollande3095022021-08-12 20:09:43 -0500282static const struct sunxi_pinctrl_desc __maybe_unused sun5i_a13_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500283 .functions = sun5i_a13_pinctrl_functions,
284 .num_functions = ARRAY_SIZE(sun5i_a13_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500285 .first_bank = SUNXI_GPIO_A,
286 .num_banks = 7,
287};
288
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500289static const struct sunxi_pinctrl_function sun6i_a31_pinctrl_functions[] = {
290 { "gpio_in", 0 },
291 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500292#if IS_ENABLED(CONFIG_UART0_PORT_F)
293 { "uart0", 3 }, /* PF2-PF4 */
294#else
295 { "uart0", 2 }, /* PH20-PH21 */
296#endif
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500297};
298
Samuel Hollande3095022021-08-12 20:09:43 -0500299static const struct sunxi_pinctrl_desc __maybe_unused sun6i_a31_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500300 .functions = sun6i_a31_pinctrl_functions,
301 .num_functions = ARRAY_SIZE(sun6i_a31_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500302 .first_bank = SUNXI_GPIO_A,
303 .num_banks = 8,
304};
305
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500306static const struct sunxi_pinctrl_function sun6i_a31_r_pinctrl_functions[] = {
307 { "gpio_in", 0 },
308 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500309 { "s_uart", 2 }, /* PL2-PL3 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500310};
311
Samuel Hollande3095022021-08-12 20:09:43 -0500312static const struct sunxi_pinctrl_desc __maybe_unused sun6i_a31_r_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500313 .functions = sun6i_a31_r_pinctrl_functions,
314 .num_functions = ARRAY_SIZE(sun6i_a31_r_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500315 .first_bank = SUNXI_GPIO_L,
316 .num_banks = 2,
317};
318
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500319static const struct sunxi_pinctrl_function sun7i_a20_pinctrl_functions[] = {
Samuel Holland5d57e052021-08-28 13:21:36 -0500320 { "emac", 2 }, /* PA0-PA17 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500321 { "gpio_in", 0 },
322 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500323#if IS_ENABLED(CONFIG_UART0_PORT_F)
324 { "uart0", 4 }, /* PF2-PF4 */
325#else
326 { "uart0", 2 }, /* PB22-PB23 */
327#endif
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500328};
329
Samuel Hollande3095022021-08-12 20:09:43 -0500330static const struct sunxi_pinctrl_desc __maybe_unused sun7i_a20_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500331 .functions = sun7i_a20_pinctrl_functions,
332 .num_functions = ARRAY_SIZE(sun7i_a20_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500333 .first_bank = SUNXI_GPIO_A,
334 .num_banks = 9,
335};
336
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500337static const struct sunxi_pinctrl_function sun8i_a23_pinctrl_functions[] = {
338 { "gpio_in", 0 },
339 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500340#if IS_ENABLED(CONFIG_UART0_PORT_F)
341 { "uart0", 3 }, /* PF2-PF4 */
342#endif
343 { "uart1", 2 }, /* PG6-PG7 */
344 { "uart2", 2 }, /* PB0-PB1 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500345};
346
Samuel Hollande3095022021-08-12 20:09:43 -0500347static const struct sunxi_pinctrl_desc __maybe_unused sun8i_a23_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500348 .functions = sun8i_a23_pinctrl_functions,
349 .num_functions = ARRAY_SIZE(sun8i_a23_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500350 .first_bank = SUNXI_GPIO_A,
351 .num_banks = 8,
352};
353
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500354static const struct sunxi_pinctrl_function sun8i_a23_r_pinctrl_functions[] = {
355 { "gpio_in", 0 },
356 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500357 { "s_uart", 2 }, /* PL2-PL3 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500358};
359
Samuel Hollande3095022021-08-12 20:09:43 -0500360static const struct sunxi_pinctrl_desc __maybe_unused sun8i_a23_r_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500361 .functions = sun8i_a23_r_pinctrl_functions,
362 .num_functions = ARRAY_SIZE(sun8i_a23_r_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500363 .first_bank = SUNXI_GPIO_L,
364 .num_banks = 1,
365};
366
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500367static const struct sunxi_pinctrl_function sun8i_a33_pinctrl_functions[] = {
368 { "gpio_in", 0 },
369 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500370#if IS_ENABLED(CONFIG_UART0_PORT_F)
371 { "uart0", 3 }, /* PF2-PF4 */
372#else
373 { "uart0", 3 }, /* PB0-PB1 */
374#endif
375 { "uart1", 2 }, /* PG6-PG7 */
376 { "uart2", 2 }, /* PB0-PB1 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500377};
378
Samuel Hollande3095022021-08-12 20:09:43 -0500379static const struct sunxi_pinctrl_desc __maybe_unused sun8i_a33_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500380 .functions = sun8i_a33_pinctrl_functions,
381 .num_functions = ARRAY_SIZE(sun8i_a33_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500382 .first_bank = SUNXI_GPIO_A,
383 .num_banks = 8,
384};
385
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500386static const struct sunxi_pinctrl_function sun8i_a83t_pinctrl_functions[] = {
387 { "gpio_in", 0 },
388 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500389#if IS_ENABLED(CONFIG_UART0_PORT_F)
390 { "uart0", 3 }, /* PF2-PF4 */
391#else
392 { "uart0", 2 }, /* PB9-PB10 */
393#endif
394 { "uart1", 2 }, /* PG6-PG7 */
395 { "uart2", 2 }, /* PB0-PB1 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500396};
397
Samuel Hollande3095022021-08-12 20:09:43 -0500398static const struct sunxi_pinctrl_desc __maybe_unused sun8i_a83t_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500399 .functions = sun8i_a83t_pinctrl_functions,
400 .num_functions = ARRAY_SIZE(sun8i_a83t_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500401 .first_bank = SUNXI_GPIO_A,
402 .num_banks = 8,
403};
404
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500405static const struct sunxi_pinctrl_function sun8i_a83t_r_pinctrl_functions[] = {
406 { "gpio_in", 0 },
407 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500408 { "s_uart", 2 }, /* PL2-PL3 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500409};
410
Samuel Hollande3095022021-08-12 20:09:43 -0500411static const struct sunxi_pinctrl_desc __maybe_unused sun8i_a83t_r_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500412 .functions = sun8i_a83t_r_pinctrl_functions,
413 .num_functions = ARRAY_SIZE(sun8i_a83t_r_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500414 .first_bank = SUNXI_GPIO_L,
415 .num_banks = 1,
416};
417
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500418static const struct sunxi_pinctrl_function sun8i_h3_pinctrl_functions[] = {
419 { "gpio_in", 0 },
420 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500421#if IS_ENABLED(CONFIG_UART0_PORT_F)
422 { "uart0", 3 }, /* PF2-PF4 */
423#else
424 { "uart0", 2 }, /* PA4-PA5 */
425#endif
426 { "uart1", 2 }, /* PG6-PG7 */
427 { "uart2", 2 }, /* PA0-PA1 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500428};
429
Samuel Hollande3095022021-08-12 20:09:43 -0500430static const struct sunxi_pinctrl_desc __maybe_unused sun8i_h3_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500431 .functions = sun8i_h3_pinctrl_functions,
432 .num_functions = ARRAY_SIZE(sun8i_h3_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500433 .first_bank = SUNXI_GPIO_A,
434 .num_banks = 7,
435};
436
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500437static const struct sunxi_pinctrl_function sun8i_h3_r_pinctrl_functions[] = {
438 { "gpio_in", 0 },
439 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500440 { "s_uart", 2 }, /* PL2-PL3 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500441};
442
Samuel Hollande3095022021-08-12 20:09:43 -0500443static const struct sunxi_pinctrl_desc __maybe_unused sun8i_h3_r_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500444 .functions = sun8i_h3_r_pinctrl_functions,
445 .num_functions = ARRAY_SIZE(sun8i_h3_r_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500446 .first_bank = SUNXI_GPIO_L,
447 .num_banks = 1,
448};
449
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500450static const struct sunxi_pinctrl_function sun8i_v3s_pinctrl_functions[] = {
451 { "gpio_in", 0 },
452 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500453#if IS_ENABLED(CONFIG_UART0_PORT_F)
454 { "uart0", 3 }, /* PF2-PF4 */
455#else
456 { "uart0", 3 }, /* PB8-PB9 */
457#endif
458 { "uart1", 2 }, /* PG6-PG7 */
459 { "uart2", 2 }, /* PB0-PB1 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500460};
461
Samuel Hollande3095022021-08-12 20:09:43 -0500462static const struct sunxi_pinctrl_desc __maybe_unused sun8i_v3s_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500463 .functions = sun8i_v3s_pinctrl_functions,
464 .num_functions = ARRAY_SIZE(sun8i_v3s_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500465 .first_bank = SUNXI_GPIO_A,
466 .num_banks = 7,
467};
468
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500469static const struct sunxi_pinctrl_function sun9i_a80_pinctrl_functions[] = {
470 { "gpio_in", 0 },
471 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500472#if IS_ENABLED(CONFIG_UART0_PORT_F)
473 { "uart0", 4 }, /* PF2-PF4 */
474#else
475 { "uart0", 2 }, /* PH12-PH13 */
476#endif
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500477};
478
Samuel Hollande3095022021-08-12 20:09:43 -0500479static const struct sunxi_pinctrl_desc __maybe_unused sun9i_a80_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500480 .functions = sun9i_a80_pinctrl_functions,
481 .num_functions = ARRAY_SIZE(sun9i_a80_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500482 .first_bank = SUNXI_GPIO_A,
483 .num_banks = 8,
484};
485
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500486static const struct sunxi_pinctrl_function sun9i_a80_r_pinctrl_functions[] = {
487 { "gpio_in", 0 },
488 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500489 { "s_uart", 3 }, /* PL0-PL1 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500490};
491
Samuel Hollande3095022021-08-12 20:09:43 -0500492static const struct sunxi_pinctrl_desc __maybe_unused sun9i_a80_r_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500493 .functions = sun9i_a80_r_pinctrl_functions,
494 .num_functions = ARRAY_SIZE(sun9i_a80_r_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500495 .first_bank = SUNXI_GPIO_L,
496 .num_banks = 3,
497};
498
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500499static const struct sunxi_pinctrl_function sun50i_a64_pinctrl_functions[] = {
500 { "gpio_in", 0 },
501 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500502#if IS_ENABLED(CONFIG_UART0_PORT_F)
503 { "uart0", 3 }, /* PF2-PF4 */
504#else
505 { "uart0", 4 }, /* PB8-PB9 */
506#endif
507 { "uart1", 2 }, /* PG6-PG7 */
508 { "uart2", 2 }, /* PB0-PB1 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500509};
510
Samuel Hollande3095022021-08-12 20:09:43 -0500511static const struct sunxi_pinctrl_desc __maybe_unused sun50i_a64_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500512 .functions = sun50i_a64_pinctrl_functions,
513 .num_functions = ARRAY_SIZE(sun50i_a64_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500514 .first_bank = SUNXI_GPIO_A,
515 .num_banks = 8,
516};
517
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500518static const struct sunxi_pinctrl_function sun50i_a64_r_pinctrl_functions[] = {
519 { "gpio_in", 0 },
520 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500521 { "s_uart", 2 }, /* PL2-PL3 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500522};
523
Samuel Hollande3095022021-08-12 20:09:43 -0500524static const struct sunxi_pinctrl_desc __maybe_unused sun50i_a64_r_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500525 .functions = sun50i_a64_r_pinctrl_functions,
526 .num_functions = ARRAY_SIZE(sun50i_a64_r_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500527 .first_bank = SUNXI_GPIO_L,
528 .num_banks = 1,
529};
530
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500531static const struct sunxi_pinctrl_function sun50i_h5_pinctrl_functions[] = {
532 { "gpio_in", 0 },
533 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500534#if IS_ENABLED(CONFIG_UART0_PORT_F)
535 { "uart0", 3 }, /* PF2-PF4 */
536#else
537 { "uart0", 2 }, /* PA4-PA5 */
538#endif
539 { "uart1", 2 }, /* PG6-PG7 */
540 { "uart2", 2 }, /* PA0-PA1 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500541};
542
Samuel Hollande3095022021-08-12 20:09:43 -0500543static const struct sunxi_pinctrl_desc __maybe_unused sun50i_h5_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500544 .functions = sun50i_h5_pinctrl_functions,
545 .num_functions = ARRAY_SIZE(sun50i_h5_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500546 .first_bank = SUNXI_GPIO_A,
547 .num_banks = 7,
548};
549
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500550static const struct sunxi_pinctrl_function sun50i_h6_pinctrl_functions[] = {
551 { "gpio_in", 0 },
552 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500553#if IS_ENABLED(CONFIG_UART0_PORT_F)
554 { "uart0", 3 }, /* PF2-PF4 */
555#else
556 { "uart0", 2 }, /* PH0-PH1 */
557#endif
558 { "uart1", 2 }, /* PG6-PG7 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500559};
560
Samuel Hollande3095022021-08-12 20:09:43 -0500561static const struct sunxi_pinctrl_desc __maybe_unused sun50i_h6_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500562 .functions = sun50i_h6_pinctrl_functions,
563 .num_functions = ARRAY_SIZE(sun50i_h6_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500564 .first_bank = SUNXI_GPIO_A,
565 .num_banks = 8,
566};
567
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500568static const struct sunxi_pinctrl_function sun50i_h6_r_pinctrl_functions[] = {
569 { "gpio_in", 0 },
570 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500571 { "s_uart", 2 }, /* PL2-PL3 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500572};
573
Samuel Hollande3095022021-08-12 20:09:43 -0500574static const struct sunxi_pinctrl_desc __maybe_unused sun50i_h6_r_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500575 .functions = sun50i_h6_r_pinctrl_functions,
576 .num_functions = ARRAY_SIZE(sun50i_h6_r_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500577 .first_bank = SUNXI_GPIO_L,
578 .num_banks = 2,
579};
580
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500581static const struct sunxi_pinctrl_function sun50i_h616_pinctrl_functions[] = {
582 { "gpio_in", 0 },
583 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500584#if IS_ENABLED(CONFIG_UART0_PORT_F)
585 { "uart0", 3 }, /* PF2-PF4 */
586#else
587 { "uart0", 2 }, /* PH0-PH1 */
588#endif
589 { "uart1", 2 }, /* PG6-PG7 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500590};
591
Samuel Hollande3095022021-08-12 20:09:43 -0500592static const struct sunxi_pinctrl_desc __maybe_unused sun50i_h616_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500593 .functions = sun50i_h616_pinctrl_functions,
594 .num_functions = ARRAY_SIZE(sun50i_h616_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500595 .first_bank = SUNXI_GPIO_A,
596 .num_banks = 9,
597};
598
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500599static const struct sunxi_pinctrl_function sun50i_h616_r_pinctrl_functions[] = {
600 { "gpio_in", 0 },
601 { "gpio_out", 1 },
Samuel Holland5a08d412021-08-28 13:00:45 -0500602 { "s_uart", 2 }, /* PL2-PL3 */
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500603};
604
Samuel Hollande3095022021-08-12 20:09:43 -0500605static const struct sunxi_pinctrl_desc __maybe_unused sun50i_h616_r_pinctrl_desc = {
Samuel Hollandecbbedb2021-08-16 23:56:47 -0500606 .functions = sun50i_h616_r_pinctrl_functions,
607 .num_functions = ARRAY_SIZE(sun50i_h616_r_pinctrl_functions),
Samuel Hollande3095022021-08-12 20:09:43 -0500608 .first_bank = SUNXI_GPIO_L,
609 .num_banks = 1,
610};
611
612static const struct udevice_id sunxi_pinctrl_ids[] = {
613#ifdef CONFIG_PINCTRL_SUNIV_F1C100S
614 {
615 .compatible = "allwinner,suniv-f1c100s-pinctrl",
616 .data = (ulong)&suniv_f1c100s_pinctrl_desc,
617 },
618#endif
619#ifdef CONFIG_PINCTRL_SUN4I_A10
620 {
621 .compatible = "allwinner,sun4i-a10-pinctrl",
622 .data = (ulong)&sun4i_a10_pinctrl_desc,
623 },
624#endif
625#ifdef CONFIG_PINCTRL_SUN5I_A13
626 {
627 .compatible = "allwinner,sun5i-a10s-pinctrl",
628 .data = (ulong)&sun5i_a13_pinctrl_desc,
629 },
630 {
631 .compatible = "allwinner,sun5i-a13-pinctrl",
632 .data = (ulong)&sun5i_a13_pinctrl_desc,
633 },
634#endif
635#ifdef CONFIG_PINCTRL_SUN6I_A31
636 {
637 .compatible = "allwinner,sun6i-a31-pinctrl",
638 .data = (ulong)&sun6i_a31_pinctrl_desc,
639 },
640 {
641 .compatible = "allwinner,sun6i-a31s-pinctrl",
642 .data = (ulong)&sun6i_a31_pinctrl_desc,
643 },
644#endif
645#ifdef CONFIG_PINCTRL_SUN6I_A31_R
646 {
647 .compatible = "allwinner,sun6i-a31-r-pinctrl",
648 .data = (ulong)&sun6i_a31_r_pinctrl_desc,
649 },
650#endif
651#ifdef CONFIG_PINCTRL_SUN7I_A20
652 {
653 .compatible = "allwinner,sun7i-a20-pinctrl",
654 .data = (ulong)&sun7i_a20_pinctrl_desc,
655 },
656#endif
657#ifdef CONFIG_PINCTRL_SUN8I_A23
658 {
659 .compatible = "allwinner,sun8i-a23-pinctrl",
660 .data = (ulong)&sun8i_a23_pinctrl_desc,
661 },
662#endif
663#ifdef CONFIG_PINCTRL_SUN8I_A23_R
664 {
665 .compatible = "allwinner,sun8i-a23-r-pinctrl",
666 .data = (ulong)&sun8i_a23_r_pinctrl_desc,
667 },
668#endif
669#ifdef CONFIG_PINCTRL_SUN8I_A33
670 {
671 .compatible = "allwinner,sun8i-a33-pinctrl",
672 .data = (ulong)&sun8i_a33_pinctrl_desc,
673 },
674#endif
675#ifdef CONFIG_PINCTRL_SUN8I_A83T
676 {
677 .compatible = "allwinner,sun8i-a83t-pinctrl",
678 .data = (ulong)&sun8i_a83t_pinctrl_desc,
679 },
680#endif
681#ifdef CONFIG_PINCTRL_SUN8I_A83T_R
682 {
683 .compatible = "allwinner,sun8i-a83t-r-pinctrl",
684 .data = (ulong)&sun8i_a83t_r_pinctrl_desc,
685 },
686#endif
687#ifdef CONFIG_PINCTRL_SUN8I_H3
688 {
689 .compatible = "allwinner,sun8i-h3-pinctrl",
690 .data = (ulong)&sun8i_h3_pinctrl_desc,
691 },
692#endif
693#ifdef CONFIG_PINCTRL_SUN8I_H3_R
694 {
695 .compatible = "allwinner,sun8i-h3-r-pinctrl",
696 .data = (ulong)&sun8i_h3_r_pinctrl_desc,
697 },
698#endif
699#ifdef CONFIG_PINCTRL_SUN7I_A20
700 {
701 .compatible = "allwinner,sun8i-r40-pinctrl",
702 .data = (ulong)&sun7i_a20_pinctrl_desc,
703 },
704#endif
705#ifdef CONFIG_PINCTRL_SUN8I_V3S
706 {
707 .compatible = "allwinner,sun8i-v3-pinctrl",
708 .data = (ulong)&sun8i_v3s_pinctrl_desc,
709 },
710 {
711 .compatible = "allwinner,sun8i-v3s-pinctrl",
712 .data = (ulong)&sun8i_v3s_pinctrl_desc,
713 },
714#endif
715#ifdef CONFIG_PINCTRL_SUN9I_A80
716 {
717 .compatible = "allwinner,sun9i-a80-pinctrl",
718 .data = (ulong)&sun9i_a80_pinctrl_desc,
719 },
720#endif
721#ifdef CONFIG_PINCTRL_SUN9I_A80_R
722 {
723 .compatible = "allwinner,sun9i-a80-r-pinctrl",
724 .data = (ulong)&sun9i_a80_r_pinctrl_desc,
725 },
726#endif
727#ifdef CONFIG_PINCTRL_SUN50I_A64
728 {
729 .compatible = "allwinner,sun50i-a64-pinctrl",
730 .data = (ulong)&sun50i_a64_pinctrl_desc,
731 },
732#endif
733#ifdef CONFIG_PINCTRL_SUN50I_A64_R
734 {
735 .compatible = "allwinner,sun50i-a64-r-pinctrl",
736 .data = (ulong)&sun50i_a64_r_pinctrl_desc,
737 },
738#endif
739#ifdef CONFIG_PINCTRL_SUN50I_H5
740 {
741 .compatible = "allwinner,sun50i-h5-pinctrl",
742 .data = (ulong)&sun50i_h5_pinctrl_desc,
743 },
744#endif
745#ifdef CONFIG_PINCTRL_SUN50I_H6
746 {
747 .compatible = "allwinner,sun50i-h6-pinctrl",
748 .data = (ulong)&sun50i_h6_pinctrl_desc,
749 },
750#endif
751#ifdef CONFIG_PINCTRL_SUN50I_H6_R
752 {
753 .compatible = "allwinner,sun50i-h6-r-pinctrl",
754 .data = (ulong)&sun50i_h6_r_pinctrl_desc,
755 },
756#endif
757#ifdef CONFIG_PINCTRL_SUN50I_H616
758 {
759 .compatible = "allwinner,sun50i-h616-pinctrl",
760 .data = (ulong)&sun50i_h616_pinctrl_desc,
761 },
762#endif
763#ifdef CONFIG_PINCTRL_SUN50I_H616_R
764 {
765 .compatible = "allwinner,sun50i-h616-r-pinctrl",
766 .data = (ulong)&sun50i_h616_r_pinctrl_desc,
767 },
768#endif
769 {}
770};
771
772U_BOOT_DRIVER(sunxi_pinctrl) = {
773 .name = "sunxi-pinctrl",
774 .id = UCLASS_PINCTRL,
775 .of_match = sunxi_pinctrl_ids,
776 .bind = sunxi_pinctrl_bind,
777 .probe = sunxi_pinctrl_probe,
778 .plat_auto = sizeof(struct sunxi_pinctrl_plat),
779 .ops = &sunxi_pinctrl_ops,
780};