blob: 6e0bcae991282f683e740b45ac67bd1fea0e02d7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Gregory CLEMENTa2490a22017-05-09 13:36:21 +02002/*
3 * U-Boot Marvell 37xx SoC pinctrl driver
4 *
5 * Copyright (C) 2017 Stefan Roese <sr@denx.de>
6 *
7 * This driver is based on the Linux driver version, which is:
8 * Copyright (C) 2017 Marvell
9 * Gregory CLEMENT <gregory.clement@free-electrons.com>
10 *
11 * Additionally parts are derived from the Meson U-Boot pinctrl driver,
12 * which is:
13 * (C) Copyright 2016 - Beniamino Galvani <b.galvani@gmail.com>
14 * Based on code from Linux kernel:
15 * Copyright (C) 2016 Endless Mobile, Inc.
Gregory CLEMENTa2490a22017-05-09 13:36:21 +020016 * https://spdx.org/licenses
17 */
18
19#include <common.h>
20#include <config.h>
21#include <dm.h>
Simon Glass9bc15642020-02-03 07:36:16 -070022#include <malloc.h>
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +020023#include <dm/device-internal.h>
Simon Glass9bc15642020-02-03 07:36:16 -070024#include <dm/device_compat.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070025#include <dm/devres.h>
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +020026#include <dm/lists.h>
Gregory CLEMENTa2490a22017-05-09 13:36:21 +020027#include <dm/pinctrl.h>
28#include <dm/root.h>
29#include <errno.h>
30#include <fdtdec.h>
31#include <regmap.h>
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +020032#include <asm/gpio.h>
Gregory CLEMENTa2490a22017-05-09 13:36:21 +020033#include <asm/system.h>
34#include <asm/io.h>
35
36DECLARE_GLOBAL_DATA_PTR;
37
38#define OUTPUT_EN 0x0
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +020039#define INPUT_VAL 0x10
40#define OUTPUT_VAL 0x18
Gregory CLEMENTa2490a22017-05-09 13:36:21 +020041#define OUTPUT_CTL 0x20
42#define SELECTION 0x30
43
44#define IRQ_EN 0x0
45#define IRQ_POL 0x08
46#define IRQ_STATUS 0x10
47#define IRQ_WKUP 0x18
48
Ken Mab28aedb2018-03-26 15:56:01 +080049#define NB_FUNCS 3
Gregory CLEMENTa2490a22017-05-09 13:36:21 +020050#define GPIO_PER_REG 32
51
52/**
53 * struct armada_37xx_pin_group: represents group of pins of a pinmux function.
54 * The pins of a pinmux groups are composed of one or two groups of contiguous
55 * pins.
56 * @name: Name of the pin group, used to lookup the group.
57 * @start_pins: Index of the first pin of the main range of pins belonging to
58 * the group
59 * @npins: Number of pins included in the first range
60 * @reg_mask: Bit mask matching the group in the selection register
61 * @extra_pins: Index of the first pin of the optional second range of pins
62 * belonging to the group
63 * @npins: Number of pins included in the second optional range
64 * @funcs: A list of pinmux functions that can be selected for this group.
65 * @pins: List of the pins included in the group
66 */
67struct armada_37xx_pin_group {
68 const char *name;
69 unsigned int start_pin;
70 unsigned int npins;
71 u32 reg_mask;
72 u32 val[NB_FUNCS];
73 unsigned int extra_pin;
74 unsigned int extra_npins;
75 const char *funcs[NB_FUNCS];
76 unsigned int *pins;
77};
78
79struct armada_37xx_pin_data {
80 u8 nr_pins;
81 char *name;
82 struct armada_37xx_pin_group *groups;
83 int ngroups;
84};
85
86struct armada_37xx_pmx_func {
87 const char *name;
88 const char **groups;
89 unsigned int ngroups;
90};
91
92struct armada_37xx_pinctrl {
93 void __iomem *base;
94 const struct armada_37xx_pin_data *data;
95 struct udevice *dev;
96 struct pinctrl_dev *pctl_dev;
97 struct armada_37xx_pin_group *groups;
98 unsigned int ngroups;
99 struct armada_37xx_pmx_func *funcs;
100 unsigned int nfuncs;
101};
102
103#define PIN_GRP(_name, _start, _nr, _mask, _func1, _func2) \
104 { \
105 .name = _name, \
106 .start_pin = _start, \
107 .npins = _nr, \
108 .reg_mask = _mask, \
109 .val = {0, _mask}, \
110 .funcs = {_func1, _func2} \
111 }
112
113#define PIN_GRP_GPIO(_name, _start, _nr, _mask, _func1) \
114 { \
115 .name = _name, \
116 .start_pin = _start, \
117 .npins = _nr, \
118 .reg_mask = _mask, \
119 .val = {0, _mask}, \
120 .funcs = {_func1, "gpio"} \
121 }
122
123#define PIN_GRP_GPIO_2(_name, _start, _nr, _mask, _val1, _val2, _func1) \
124 { \
125 .name = _name, \
126 .start_pin = _start, \
127 .npins = _nr, \
128 .reg_mask = _mask, \
129 .val = {_val1, _val2}, \
130 .funcs = {_func1, "gpio"} \
131 }
132
Ken Mab28aedb2018-03-26 15:56:01 +0800133#define PIN_GRP_GPIO_3(_name, _start, _nr, _mask, _v1, _v2, _v3, _f1, _f2) \
134 { \
135 .name = _name, \
136 .start_pin = _start, \
137 .npins = _nr, \
138 .reg_mask = _mask, \
139 .val = {_v1, _v2, _v3}, \
140 .funcs = {_f1, _f2, "gpio"} \
141 }
142
Gregory CLEMENTa2490a22017-05-09 13:36:21 +0200143#define PIN_GRP_EXTRA(_name, _start, _nr, _mask, _v1, _v2, _start2, _nr2, \
144 _f1, _f2) \
145 { \
146 .name = _name, \
147 .start_pin = _start, \
148 .npins = _nr, \
149 .reg_mask = _mask, \
150 .val = {_v1, _v2}, \
151 .extra_pin = _start2, \
152 .extra_npins = _nr2, \
153 .funcs = {_f1, _f2} \
154 }
155
156static struct armada_37xx_pin_group armada_37xx_nb_groups[] = {
157 PIN_GRP_GPIO("jtag", 20, 5, BIT(0), "jtag"),
158 PIN_GRP_GPIO("sdio0", 8, 3, BIT(1), "sdio"),
159 PIN_GRP_GPIO("emmc_nb", 27, 9, BIT(2), "emmc"),
160 PIN_GRP_GPIO("pwm0", 11, 1, BIT(3), "pwm"),
161 PIN_GRP_GPIO("pwm1", 12, 1, BIT(4), "pwm"),
162 PIN_GRP_GPIO("pwm2", 13, 1, BIT(5), "pwm"),
163 PIN_GRP_GPIO("pwm3", 14, 1, BIT(6), "pwm"),
Ken Ma3cdd35b2018-03-26 15:56:03 +0800164 PIN_GRP_GPIO("pmic1", 7, 1, BIT(7), "pmic"),
165 PIN_GRP_GPIO("pmic0", 6, 1, BIT(8), "pmic"),
Gregory CLEMENTa2490a22017-05-09 13:36:21 +0200166 PIN_GRP_GPIO("i2c2", 2, 2, BIT(9), "i2c"),
167 PIN_GRP_GPIO("i2c1", 0, 2, BIT(10), "i2c"),
168 PIN_GRP_GPIO("spi_cs1", 17, 1, BIT(12), "spi"),
169 PIN_GRP_GPIO_2("spi_cs2", 18, 1, BIT(13) | BIT(19), 0, BIT(13), "spi"),
170 PIN_GRP_GPIO_2("spi_cs3", 19, 1, BIT(14) | BIT(19), 0, BIT(14), "spi"),
171 PIN_GRP_GPIO("onewire", 4, 1, BIT(16), "onewire"),
172 PIN_GRP_GPIO("uart1", 25, 2, BIT(17), "uart"),
173 PIN_GRP_GPIO("spi_quad", 15, 2, BIT(18), "spi"),
Ken Maa12d6372017-06-22 17:13:35 +0800174 PIN_GRP_EXTRA("uart2", 9, 2, BIT(1) | BIT(13) | BIT(14) | BIT(19),
175 BIT(1) | BIT(13) | BIT(14), BIT(1) | BIT(19),
176 18, 2, "gpio", "uart"),
Gregory CLEMENTa2490a22017-05-09 13:36:21 +0200177 PIN_GRP_GPIO("led0_od", 11, 1, BIT(20), "led"),
178 PIN_GRP_GPIO("led1_od", 12, 1, BIT(21), "led"),
179 PIN_GRP_GPIO("led2_od", 13, 1, BIT(22), "led"),
180 PIN_GRP_GPIO("led3_od", 14, 1, BIT(23), "led"),
181
182};
183
184static struct armada_37xx_pin_group armada_37xx_sb_groups[] = {
185 PIN_GRP_GPIO("usb32_drvvbus0", 0, 1, BIT(0), "drvbus"),
186 PIN_GRP_GPIO("usb2_drvvbus1", 1, 1, BIT(1), "drvbus"),
Ken Ma3cdd35b2018-03-26 15:56:03 +0800187 PIN_GRP_GPIO("sdio_sb", 24, 6, BIT(2), "sdio"),
188 PIN_GRP_GPIO("rgmii", 6, 12, BIT(3), "mii"),
189 PIN_GRP_GPIO("smi", 18, 2, BIT(4), "smi"),
190 PIN_GRP_GPIO("pcie1", 3, 3, BIT(5) | BIT(9) | BIT(10), "pcie"),
191 PIN_GRP_GPIO("ptp", 20, 3, BIT(11) | BIT(12) | BIT(13), "ptp"),
Gregory CLEMENTa2490a22017-05-09 13:36:21 +0200192 PIN_GRP("ptp_clk", 21, 1, BIT(6), "ptp", "mii"),
193 PIN_GRP("ptp_trig", 22, 1, BIT(7), "ptp", "mii"),
Ken Mab28aedb2018-03-26 15:56:01 +0800194 PIN_GRP_GPIO_3("mii_col", 23, 1, BIT(8) | BIT(14), 0, BIT(8), BIT(14),
195 "mii", "mii_err"),
Gregory CLEMENTa2490a22017-05-09 13:36:21 +0200196};
197
198const struct armada_37xx_pin_data armada_37xx_pin_nb = {
199 .nr_pins = 36,
200 .name = "GPIO1",
201 .groups = armada_37xx_nb_groups,
202 .ngroups = ARRAY_SIZE(armada_37xx_nb_groups),
203};
204
205const struct armada_37xx_pin_data armada_37xx_pin_sb = {
Ken Maa1d81602018-03-26 15:55:59 +0800206 .nr_pins = 30,
Gregory CLEMENTa2490a22017-05-09 13:36:21 +0200207 .name = "GPIO2",
208 .groups = armada_37xx_sb_groups,
209 .ngroups = ARRAY_SIZE(armada_37xx_sb_groups),
210};
211
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +0200212static inline void armada_37xx_update_reg(unsigned int *reg,
Ken Maf72c5292018-03-26 15:56:02 +0800213 unsigned int *offset)
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +0200214{
215 /* We never have more than 2 registers */
Ken Maf72c5292018-03-26 15:56:02 +0800216 if (*offset >= GPIO_PER_REG) {
217 *offset -= GPIO_PER_REG;
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +0200218 *reg += sizeof(u32);
219 }
220}
221
Gregory CLEMENTa2490a22017-05-09 13:36:21 +0200222static int armada_37xx_get_func_reg(struct armada_37xx_pin_group *grp,
223 const char *func)
224{
225 int f;
226
Ken Mab28aedb2018-03-26 15:56:01 +0800227 for (f = 0; (f < NB_FUNCS) && grp->funcs[f]; f++)
Gregory CLEMENTa2490a22017-05-09 13:36:21 +0200228 if (!strcmp(grp->funcs[f], func))
229 return f;
230
231 return -ENOTSUPP;
232}
233
234static int armada_37xx_pmx_get_groups_count(struct udevice *dev)
235{
236 struct armada_37xx_pinctrl *info = dev_get_priv(dev);
237
238 return info->ngroups;
239}
240
241static const char *armada_37xx_pmx_dummy_name = "_dummy";
242
243static const char *armada_37xx_pmx_get_group_name(struct udevice *dev,
244 unsigned selector)
245{
246 struct armada_37xx_pinctrl *info = dev_get_priv(dev);
247
248 if (!info->groups[selector].name)
249 return armada_37xx_pmx_dummy_name;
250
251 return info->groups[selector].name;
252}
253
254static int armada_37xx_pmx_get_funcs_count(struct udevice *dev)
255{
256 struct armada_37xx_pinctrl *info = dev_get_priv(dev);
257
258 return info->nfuncs;
259}
260
261static const char *armada_37xx_pmx_get_func_name(struct udevice *dev,
262 unsigned selector)
263{
264 struct armada_37xx_pinctrl *info = dev_get_priv(dev);
265
266 return info->funcs[selector].name;
267}
268
269static int armada_37xx_pmx_set_by_name(struct udevice *dev,
270 const char *name,
271 struct armada_37xx_pin_group *grp)
272{
273 struct armada_37xx_pinctrl *info = dev_get_priv(dev);
274 unsigned int reg = SELECTION;
275 unsigned int mask = grp->reg_mask;
276 int func, val;
277
278 dev_dbg(info->dev, "enable function %s group %s\n",
279 name, grp->name);
280
281 func = armada_37xx_get_func_reg(grp, name);
282
283 if (func < 0)
284 return func;
285
286 val = grp->val[func];
287
288 clrsetbits_le32(info->base + reg, mask, val);
289
290 return 0;
291}
292
293static int armada_37xx_pmx_group_set(struct udevice *dev,
294 unsigned group_selector,
295 unsigned func_selector)
296{
297 struct armada_37xx_pinctrl *info = dev_get_priv(dev);
298 struct armada_37xx_pin_group *grp = &info->groups[group_selector];
299 const char *name = info->funcs[func_selector].name;
300
301 return armada_37xx_pmx_set_by_name(dev, name, grp);
302}
303
304/**
305 * armada_37xx_add_function() - Add a new function to the list
306 * @funcs: array of function to add the new one
307 * @funcsize: size of the remaining space for the function
308 * @name: name of the function to add
309 *
310 * If it is a new function then create it by adding its name else
311 * increment the number of group associated to this function.
312 */
313static int armada_37xx_add_function(struct armada_37xx_pmx_func *funcs,
314 int *funcsize, const char *name)
315{
316 int i = 0;
317
318 if (*funcsize <= 0)
319 return -EOVERFLOW;
320
321 while (funcs->ngroups) {
322 /* function already there */
323 if (strcmp(funcs->name, name) == 0) {
324 funcs->ngroups++;
325
326 return -EEXIST;
327 }
328 funcs++;
329 i++;
330 }
331
332 /* append new unique function */
333 funcs->name = name;
334 funcs->ngroups = 1;
335 (*funcsize)--;
336
337 return 0;
338}
339
340/**
341 * armada_37xx_fill_group() - complete the group array
342 * @info: info driver instance
343 *
344 * Based on the data available from the armada_37xx_pin_group array
345 * completes the last member of the struct for each function: the list
346 * of the groups associated to this function.
347 *
348 */
349static int armada_37xx_fill_group(struct armada_37xx_pinctrl *info)
350{
351 int n, num = 0, funcsize = info->data->nr_pins;
352
353 for (n = 0; n < info->ngroups; n++) {
354 struct armada_37xx_pin_group *grp = &info->groups[n];
355 int i, j, f;
356
357 grp->pins = devm_kzalloc(info->dev,
358 (grp->npins + grp->extra_npins) *
359 sizeof(*grp->pins), GFP_KERNEL);
360 if (!grp->pins)
361 return -ENOMEM;
362
363 for (i = 0; i < grp->npins; i++)
364 grp->pins[i] = grp->start_pin + i;
365
366 for (j = 0; j < grp->extra_npins; j++)
367 grp->pins[i+j] = grp->extra_pin + j;
368
Ken Mab28aedb2018-03-26 15:56:01 +0800369 for (f = 0; (f < NB_FUNCS) && grp->funcs[f]; f++) {
Gregory CLEMENTa2490a22017-05-09 13:36:21 +0200370 int ret;
371 /* check for unique functions and count groups */
372 ret = armada_37xx_add_function(info->funcs, &funcsize,
373 grp->funcs[f]);
374 if (ret == -EOVERFLOW)
375 dev_err(info->dev,
376 "More functions than pins(%d)\n",
377 info->data->nr_pins);
378 if (ret < 0)
379 continue;
380 num++;
381 }
382 }
383
384 info->nfuncs = num;
385
386 return 0;
387}
388
389/**
390 * armada_37xx_fill_funcs() - complete the funcs array
391 * @info: info driver instance
392 *
393 * Based on the data available from the armada_37xx_pin_group array
394 * completes the last two member of the struct for each group:
395 * - the list of the pins included in the group
396 * - the list of pinmux functions that can be selected for this group
397 *
398 */
399static int armada_37xx_fill_func(struct armada_37xx_pinctrl *info)
400{
401 struct armada_37xx_pmx_func *funcs = info->funcs;
402 int n;
403
404 for (n = 0; n < info->nfuncs; n++) {
405 const char *name = funcs[n].name;
406 const char **groups;
407 int g;
408
409 funcs[n].groups = devm_kzalloc(info->dev, funcs[n].ngroups *
410 sizeof(*(funcs[n].groups)),
411 GFP_KERNEL);
412 if (!funcs[n].groups)
413 return -ENOMEM;
414
415 groups = funcs[n].groups;
416
417 for (g = 0; g < info->ngroups; g++) {
418 struct armada_37xx_pin_group *gp = &info->groups[g];
419 int f;
420
Ken Mab28aedb2018-03-26 15:56:01 +0800421 for (f = 0; (f < NB_FUNCS) && gp->funcs[f]; f++) {
Gregory CLEMENTa2490a22017-05-09 13:36:21 +0200422 if (strcmp(gp->funcs[f], name) == 0) {
423 *groups = gp->name;
424 groups++;
425 }
426 }
427 }
428 }
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +0200429 return 0;
430}
431
432static int armada_37xx_gpio_get(struct udevice *dev, unsigned int offset)
433{
434 struct armada_37xx_pinctrl *info = dev_get_priv(dev->parent);
435 unsigned int reg = INPUT_VAL;
436 unsigned int val, mask;
437
Ken Maf72c5292018-03-26 15:56:02 +0800438 armada_37xx_update_reg(&reg, &offset);
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +0200439 mask = BIT(offset);
440
441 val = readl(info->base + reg);
442
443 return (val & mask) != 0;
444}
445
446static int armada_37xx_gpio_set(struct udevice *dev, unsigned int offset,
447 int value)
448{
449 struct armada_37xx_pinctrl *info = dev_get_priv(dev->parent);
450 unsigned int reg = OUTPUT_VAL;
451 unsigned int mask, val;
452
Ken Maf72c5292018-03-26 15:56:02 +0800453 armada_37xx_update_reg(&reg, &offset);
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +0200454 mask = BIT(offset);
455 val = value ? mask : 0;
456
457 clrsetbits_le32(info->base + reg, mask, val);
458
459 return 0;
460}
461
462static int armada_37xx_gpio_get_direction(struct udevice *dev,
463 unsigned int offset)
464{
465 struct armada_37xx_pinctrl *info = dev_get_priv(dev->parent);
466 unsigned int reg = OUTPUT_EN;
467 unsigned int val, mask;
468
Ken Maf72c5292018-03-26 15:56:02 +0800469 armada_37xx_update_reg(&reg, &offset);
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +0200470 mask = BIT(offset);
471 val = readl(info->base + reg);
472
473 if (val & mask)
474 return GPIOF_OUTPUT;
475 else
476 return GPIOF_INPUT;
477}
478
479static int armada_37xx_gpio_direction_input(struct udevice *dev,
480 unsigned int offset)
481{
482 struct armada_37xx_pinctrl *info = dev_get_priv(dev->parent);
483 unsigned int reg = OUTPUT_EN;
484 unsigned int mask;
485
Ken Maf72c5292018-03-26 15:56:02 +0800486 armada_37xx_update_reg(&reg, &offset);
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +0200487 mask = BIT(offset);
488
489 clrbits_le32(info->base + reg, mask);
490
491 return 0;
492}
493
494static int armada_37xx_gpio_direction_output(struct udevice *dev,
495 unsigned int offset, int value)
496{
497 struct armada_37xx_pinctrl *info = dev_get_priv(dev->parent);
498 unsigned int reg = OUTPUT_EN;
499 unsigned int mask;
500
Ken Maf72c5292018-03-26 15:56:02 +0800501 armada_37xx_update_reg(&reg, &offset);
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +0200502 mask = BIT(offset);
503
504 setbits_le32(info->base + reg, mask);
505
506 /* And set the requested value */
507 return armada_37xx_gpio_set(dev, offset, value);
508}
509
510static int armada_37xx_gpio_probe(struct udevice *dev)
511{
512 struct armada_37xx_pinctrl *info = dev_get_priv(dev->parent);
513 struct gpio_dev_priv *uc_priv;
514
515 uc_priv = dev_get_uclass_priv(dev);
516 uc_priv->bank_name = info->data->name;
517 uc_priv->gpio_count = info->data->nr_pins;
518
519 return 0;
520}
521
522static const struct dm_gpio_ops armada_37xx_gpio_ops = {
523 .set_value = armada_37xx_gpio_set,
524 .get_value = armada_37xx_gpio_get,
525 .get_function = armada_37xx_gpio_get_direction,
526 .direction_input = armada_37xx_gpio_direction_input,
527 .direction_output = armada_37xx_gpio_direction_output,
528};
529
530static struct driver armada_37xx_gpio_driver = {
531 .name = "armada-37xx-gpio",
532 .id = UCLASS_GPIO,
533 .probe = armada_37xx_gpio_probe,
534 .ops = &armada_37xx_gpio_ops,
535};
536
537static int armada_37xx_gpiochip_register(struct udevice *parent,
538 struct armada_37xx_pinctrl *info)
539{
540 const void *blob = gd->fdt_blob;
541 int node = dev_of_offset(parent);
542 struct uclass_driver *drv;
543 struct udevice *dev;
544 int ret = -ENODEV;
545 int subnode;
546 char *name;
547
548 /* Lookup GPIO driver */
549 drv = lists_uclass_lookup(UCLASS_GPIO);
550 if (!drv) {
551 puts("Cannot find GPIO driver\n");
552 return -ENOENT;
553 }
554
555 fdt_for_each_subnode(subnode, blob, node) {
Ken Mafeb93c62017-06-22 17:13:36 +0800556 if (fdtdec_get_bool(blob, subnode, "gpio-controller")) {
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +0200557 ret = 0;
558 break;
559 }
560 };
561 if (ret)
562 return ret;
563
564 name = calloc(1, 32);
565 sprintf(name, "armada-37xx-gpio");
566
567 /* Create child device UCLASS_GPIO and bind it */
568 device_bind(parent, &armada_37xx_gpio_driver, name, NULL, subnode,
569 &dev);
570 dev_set_of_offset(dev, subnode);
571
Gregory CLEMENTa2490a22017-05-09 13:36:21 +0200572 return 0;
573}
574
575const struct pinctrl_ops armada_37xx_pinctrl_ops = {
576 .get_groups_count = armada_37xx_pmx_get_groups_count,
577 .get_group_name = armada_37xx_pmx_get_group_name,
578 .get_functions_count = armada_37xx_pmx_get_funcs_count,
579 .get_function_name = armada_37xx_pmx_get_func_name,
580 .pinmux_group_set = armada_37xx_pmx_group_set,
581 .set_state = pinctrl_generic_set_state,
582};
583
584int armada_37xx_pinctrl_probe(struct udevice *dev)
585{
586 struct armada_37xx_pinctrl *info = dev_get_priv(dev);
587 const struct armada_37xx_pin_data *pin_data;
588 int ret;
589
590 info->data = (struct armada_37xx_pin_data *)dev_get_driver_data(dev);
591 pin_data = info->data;
592
Simon Glassba1dea42017-05-17 17:18:05 -0600593 info->base = (void __iomem *)devfdt_get_addr(dev);
Gregory CLEMENTa2490a22017-05-09 13:36:21 +0200594 if (!info->base) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900595 pr_err("unable to find regmap\n");
Gregory CLEMENTa2490a22017-05-09 13:36:21 +0200596 return -ENODEV;
597 }
598
599 info->groups = pin_data->groups;
600 info->ngroups = pin_data->ngroups;
601
602 /*
603 * we allocate functions for number of pins and hope there are
604 * fewer unique functions than pins available
605 */
606 info->funcs = devm_kzalloc(info->dev, pin_data->nr_pins *
607 sizeof(struct armada_37xx_pmx_func), GFP_KERNEL);
608 if (!info->funcs)
609 return -ENOMEM;
610
611
612 ret = armada_37xx_fill_group(info);
613 if (ret)
614 return ret;
615
616 ret = armada_37xx_fill_func(info);
617 if (ret)
618 return ret;
619
Gregory CLEMENT7ca5e2b2017-05-17 17:05:25 +0200620 ret = armada_37xx_gpiochip_register(dev, info);
621 if (ret)
622 return ret;
623
Gregory CLEMENTa2490a22017-05-09 13:36:21 +0200624 return 0;
625}
626
627static const struct udevice_id armada_37xx_pinctrl_of_match[] = {
628 {
629 .compatible = "marvell,armada3710-sb-pinctrl",
630 .data = (ulong)&armada_37xx_pin_sb,
631 },
632 {
633 .compatible = "marvell,armada3710-nb-pinctrl",
634 .data = (ulong)&armada_37xx_pin_nb,
635 },
636 { /* sentinel */ }
637};
638
639U_BOOT_DRIVER(armada_37xx_pinctrl) = {
640 .name = "armada-37xx-pinctrl",
641 .id = UCLASS_PINCTRL,
642 .of_match = of_match_ptr(armada_37xx_pinctrl_of_match),
643 .probe = armada_37xx_pinctrl_probe,
644 .priv_auto_alloc_size = sizeof(struct armada_37xx_pinctrl),
645 .ops = &armada_37xx_pinctrl_ops,
646};