blob: ec1cb9b652f3d2b7edb83cdad0c9f0daaf34a744 [file] [log] [blame]
David Wu5f596ae2019-01-02 21:00:55 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2019 Rockchip Electronics Co., Ltd
4 */
5
6#include <common.h>
7#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
David Wu5f596ae2019-01-02 21:00:55 +08009#include <dm/pinctrl.h>
10#include <regmap.h>
11#include <syscon.h>
12#include <fdtdec.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060013#include <linux/bitops.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060014#include <linux/libfdt.h>
David Wu5f596ae2019-01-02 21:00:55 +080015
16#include "pinctrl-rockchip.h"
17
18#define MAX_ROCKCHIP_PINS_ENTRIES 30
19#define MAX_ROCKCHIP_GPIO_PER_BANK 32
20#define RK_FUNC_GPIO 0
21
22static int rockchip_verify_config(struct udevice *dev, u32 bank, u32 pin)
23{
24 struct rockchip_pinctrl_priv *priv = dev_get_priv(dev);
25 struct rockchip_pin_ctrl *ctrl = priv->ctrl;
26
27 if (bank >= ctrl->nr_banks) {
28 debug("pin conf bank %d >= nbanks %d\n", bank, ctrl->nr_banks);
29 return -EINVAL;
30 }
31
32 if (pin >= MAX_ROCKCHIP_GPIO_PER_BANK) {
33 debug("pin conf pin %d >= %d\n", pin,
34 MAX_ROCKCHIP_GPIO_PER_BANK);
35 return -EINVAL;
36 }
37
38 return 0;
39}
40
David Wu3dd7d6c2019-04-16 21:50:55 +080041void rockchip_get_recalced_mux(struct rockchip_pin_bank *bank, int pin,
42 int *reg, u8 *bit, int *mask)
David Wu5f596ae2019-01-02 21:00:55 +080043{
44 struct rockchip_pinctrl_priv *priv = bank->priv;
45 struct rockchip_pin_ctrl *ctrl = priv->ctrl;
46 struct rockchip_mux_recalced_data *data;
47 int i;
48
49 for (i = 0; i < ctrl->niomux_recalced; i++) {
50 data = &ctrl->iomux_recalced[i];
51 if (data->num == bank->bank_num &&
52 data->pin == pin)
53 break;
54 }
55
56 if (i >= ctrl->niomux_recalced)
57 return;
58
59 *reg = data->reg;
60 *mask = data->mask;
61 *bit = data->bit;
62}
63
David Wu3dd7d6c2019-04-16 21:50:55 +080064bool rockchip_get_mux_route(struct rockchip_pin_bank *bank, int pin,
65 int mux, u32 *reg, u32 *value)
David Wu5f596ae2019-01-02 21:00:55 +080066{
67 struct rockchip_pinctrl_priv *priv = bank->priv;
68 struct rockchip_pin_ctrl *ctrl = priv->ctrl;
69 struct rockchip_mux_route_data *data;
70 int i;
71
72 for (i = 0; i < ctrl->niomux_routes; i++) {
73 data = &ctrl->iomux_routes[i];
74 if (data->bank_num == bank->bank_num &&
75 data->pin == pin && data->func == mux)
76 break;
77 }
78
79 if (i >= ctrl->niomux_routes)
80 return false;
81
82 *reg = data->route_offset;
83 *value = data->route_val;
84
85 return true;
86}
87
David Wu3dd7d6c2019-04-16 21:50:55 +080088int rockchip_get_mux_data(int mux_type, int pin, u8 *bit, int *mask)
David Wu5f596ae2019-01-02 21:00:55 +080089{
90 int offset = 0;
91
92 if (mux_type & IOMUX_WIDTH_4BIT) {
93 if ((pin % 8) >= 4)
94 offset = 0x4;
95 *bit = (pin % 4) * 4;
96 *mask = 0xf;
97 } else if (mux_type & IOMUX_WIDTH_3BIT) {
98 /*
99 * pin0 ~ pin4 are at first register, and
100 * pin5 ~ pin7 are at second register.
101 */
102 if ((pin % 8) >= 5)
103 offset = 0x4;
104 *bit = (pin % 8 % 5) * 3;
105 *mask = 0x7;
106 } else {
107 *bit = (pin % 8) * 2;
108 *mask = 0x3;
109 }
110
111 return offset;
112}
113
114static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin)
115{
116 struct rockchip_pinctrl_priv *priv = bank->priv;
117 int iomux_num = (pin / 8);
118 struct regmap *regmap;
119 unsigned int val;
120 int reg, ret, mask, mux_type;
121 u8 bit;
122
123 if (iomux_num > 3)
124 return -EINVAL;
125
126 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
127 debug("pin %d is unrouted\n", pin);
128 return -EINVAL;
129 }
130
131 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
132 return RK_FUNC_GPIO;
133
134 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
135 ? priv->regmap_pmu : priv->regmap_base;
136
137 /* get basic quadrupel of mux registers and the correct reg inside */
138 mux_type = bank->iomux[iomux_num].type;
139 reg = bank->iomux[iomux_num].offset;
140 reg += rockchip_get_mux_data(mux_type, pin, &bit, &mask);
141
142 if (bank->recalced_mask & BIT(pin))
143 rockchip_get_recalced_mux(bank, pin, &reg, &bit, &mask);
144
145 ret = regmap_read(regmap, reg, &val);
146 if (ret)
147 return ret;
148
149 return ((val >> bit) & mask);
150}
151
152static int rockchip_pinctrl_get_gpio_mux(struct udevice *dev, int banknum,
153 int index)
154{ struct rockchip_pinctrl_priv *priv = dev_get_priv(dev);
155 struct rockchip_pin_ctrl *ctrl = priv->ctrl;
156
157 return rockchip_get_mux(&ctrl->pin_banks[banknum], index);
158}
159
160static int rockchip_verify_mux(struct rockchip_pin_bank *bank,
161 int pin, int mux)
162{
163 int iomux_num = (pin / 8);
164
165 if (iomux_num > 3)
166 return -EINVAL;
167
168 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
169 debug("pin %d is unrouted\n", pin);
170 return -EINVAL;
171 }
172
173 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) {
174 if (mux != IOMUX_GPIO_ONLY) {
175 debug("pin %d only supports a gpio mux\n", pin);
176 return -ENOTSUPP;
177 }
178 }
179
180 return 0;
181}
182
183/*
184 * Set a new mux function for a pin.
185 *
186 * The register is divided into the upper and lower 16 bit. When changing
187 * a value, the previous register value is not read and changed. Instead
188 * it seems the changed bits are marked in the upper 16 bit, while the
189 * changed value gets set in the same offset in the lower 16 bit.
190 * All pin settings seem to be 2 bit wide in both the upper and lower
191 * parts.
192 * @bank: pin bank to change
193 * @pin: pin to change
194 * @mux: new mux function to set
195 */
196static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
197{
198 struct rockchip_pinctrl_priv *priv = bank->priv;
David Wu3dd7d6c2019-04-16 21:50:55 +0800199 struct rockchip_pin_ctrl *ctrl = priv->ctrl;
David Wu5f596ae2019-01-02 21:00:55 +0800200 int iomux_num = (pin / 8);
David Wu3dd7d6c2019-04-16 21:50:55 +0800201 int ret;
David Wu5f596ae2019-01-02 21:00:55 +0800202
203 ret = rockchip_verify_mux(bank, pin, mux);
204 if (ret < 0)
205 return ret;
206
207 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
208 return 0;
209
210 debug("setting mux of GPIO%d-%d to %d\n", bank->bank_num, pin, mux);
211
David Wu3dd7d6c2019-04-16 21:50:55 +0800212 if (!ctrl->set_mux)
213 return -ENOTSUPP;
David Wu5f596ae2019-01-02 21:00:55 +0800214
David Wu3dd7d6c2019-04-16 21:50:55 +0800215 ret = ctrl->set_mux(bank, pin, mux);
David Wu5f596ae2019-01-02 21:00:55 +0800216
217 return ret;
218}
219
220static int rockchip_perpin_drv_list[DRV_TYPE_MAX][8] = {
221 { 2, 4, 8, 12, -1, -1, -1, -1 },
222 { 3, 6, 9, 12, -1, -1, -1, -1 },
223 { 5, 10, 15, 20, -1, -1, -1, -1 },
224 { 4, 6, 8, 10, 12, 14, 16, 18 },
225 { 4, 7, 10, 13, 16, 19, 22, 26 }
226};
227
David Wu40a55482019-04-16 21:55:26 +0800228int rockchip_translate_drive_value(int type, int strength)
David Wu5f596ae2019-01-02 21:00:55 +0800229{
David Wu40a55482019-04-16 21:55:26 +0800230 int i, ret;
David Wu5f596ae2019-01-02 21:00:55 +0800231
232 ret = -EINVAL;
David Wu40a55482019-04-16 21:55:26 +0800233 for (i = 0; i < ARRAY_SIZE(rockchip_perpin_drv_list[type]); i++) {
234 if (rockchip_perpin_drv_list[type][i] == strength) {
David Wu5f596ae2019-01-02 21:00:55 +0800235 ret = i;
236 break;
David Wu40a55482019-04-16 21:55:26 +0800237 } else if (rockchip_perpin_drv_list[type][i] < 0) {
238 ret = rockchip_perpin_drv_list[type][i];
David Wu5f596ae2019-01-02 21:00:55 +0800239 break;
240 }
241 }
242
David Wu40a55482019-04-16 21:55:26 +0800243 return ret;
244}
David Wu5f596ae2019-01-02 21:00:55 +0800245
David Wu40a55482019-04-16 21:55:26 +0800246static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank,
247 int pin_num, int strength)
248{
249 struct rockchip_pinctrl_priv *priv = bank->priv;
250 struct rockchip_pin_ctrl *ctrl = priv->ctrl;
David Wu5f596ae2019-01-02 21:00:55 +0800251
David Wu40a55482019-04-16 21:55:26 +0800252 debug("setting drive of GPIO%d-%d to %d\n", bank->bank_num,
253 pin_num, strength);
David Wu5f596ae2019-01-02 21:00:55 +0800254
David Wu40a55482019-04-16 21:55:26 +0800255 if (!ctrl->set_drive)
256 return -ENOTSUPP;
Kever Yang56573c42019-05-07 09:36:32 +0800257
David Wu40a55482019-04-16 21:55:26 +0800258 return ctrl->set_drive(bank, pin_num, strength);
David Wu5f596ae2019-01-02 21:00:55 +0800259}
260
261static int rockchip_pull_list[PULL_TYPE_MAX][4] = {
262 {
263 PIN_CONFIG_BIAS_DISABLE,
264 PIN_CONFIG_BIAS_PULL_UP,
265 PIN_CONFIG_BIAS_PULL_DOWN,
266 PIN_CONFIG_BIAS_BUS_HOLD
267 },
268 {
269 PIN_CONFIG_BIAS_DISABLE,
270 PIN_CONFIG_BIAS_PULL_DOWN,
271 PIN_CONFIG_BIAS_DISABLE,
272 PIN_CONFIG_BIAS_PULL_UP
273 },
274};
275
David Wu2972c452019-04-16 21:57:05 +0800276int rockchip_translate_pull_value(int type, int pull)
277{
278 int i, ret;
279
280 ret = -EINVAL;
281 for (i = 0; i < ARRAY_SIZE(rockchip_pull_list[type]);
282 i++) {
283 if (rockchip_pull_list[type][i] == pull) {
284 ret = i;
285 break;
286 }
287 }
288
289 return ret;
290}
291
David Wu5f596ae2019-01-02 21:00:55 +0800292static int rockchip_set_pull(struct rockchip_pin_bank *bank,
293 int pin_num, int pull)
294{
295 struct rockchip_pinctrl_priv *priv = bank->priv;
296 struct rockchip_pin_ctrl *ctrl = priv->ctrl;
David Wu5f596ae2019-01-02 21:00:55 +0800297
298 debug("setting pull of GPIO%d-%d to %d\n", bank->bank_num,
299 pin_num, pull);
300
David Wu2972c452019-04-16 21:57:05 +0800301 if (!ctrl->set_pull)
302 return -ENOTSUPP;
David Wu5f596ae2019-01-02 21:00:55 +0800303
David Wu2972c452019-04-16 21:57:05 +0800304 return ctrl->set_pull(bank, pin_num, pull);
David Wu5f596ae2019-01-02 21:00:55 +0800305}
306
307static int rockchip_set_schmitt(struct rockchip_pin_bank *bank,
308 int pin_num, int enable)
309{
310 struct rockchip_pinctrl_priv *priv = bank->priv;
311 struct rockchip_pin_ctrl *ctrl = priv->ctrl;
David Wu5f596ae2019-01-02 21:00:55 +0800312
313 debug("setting input schmitt of GPIO%d-%d to %d\n", bank->bank_num,
314 pin_num, enable);
315
David Wu7ae4ec92019-04-16 21:58:13 +0800316 if (!ctrl->set_schmitt)
317 return -ENOTSUPP;
David Wu5f596ae2019-01-02 21:00:55 +0800318
David Wu7ae4ec92019-04-16 21:58:13 +0800319 return ctrl->set_schmitt(bank, pin_num, enable);
David Wu5f596ae2019-01-02 21:00:55 +0800320}
321
David Wu5f596ae2019-01-02 21:00:55 +0800322/* set the pin config settings for a specified pin */
323static int rockchip_pinconf_set(struct rockchip_pin_bank *bank,
324 u32 pin, u32 param, u32 arg)
325{
David Wu5f596ae2019-01-02 21:00:55 +0800326 int rc;
327
328 switch (param) {
329 case PIN_CONFIG_BIAS_DISABLE:
David Wu5f596ae2019-01-02 21:00:55 +0800330 case PIN_CONFIG_BIAS_PULL_UP:
331 case PIN_CONFIG_BIAS_PULL_DOWN:
332 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
333 case PIN_CONFIG_BIAS_BUS_HOLD:
David Wu5f596ae2019-01-02 21:00:55 +0800334 rc = rockchip_set_pull(bank, pin, param);
335 if (rc)
336 return rc;
337 break;
338
339 case PIN_CONFIG_DRIVE_STRENGTH:
David Wu5f596ae2019-01-02 21:00:55 +0800340 rc = rockchip_set_drive_perpin(bank, pin, arg);
341 if (rc < 0)
342 return rc;
343 break;
344
345 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
David Wu5f596ae2019-01-02 21:00:55 +0800346 rc = rockchip_set_schmitt(bank, pin, arg);
347 if (rc < 0)
348 return rc;
349 break;
350
351 default:
352 break;
353 }
354
355 return 0;
356}
357
358static const struct pinconf_param rockchip_conf_params[] = {
359 { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
360 { "bias-bus-hold", PIN_CONFIG_BIAS_BUS_HOLD, 0 },
361 { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
362 { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
David Wu18564512019-04-16 21:50:53 +0800363 { "bias-pull-pin-default", PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 1 },
David Wu5f596ae2019-01-02 21:00:55 +0800364 { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },
David Wu5f596ae2019-01-02 21:00:55 +0800365 { "input-schmitt-disable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 0 },
366 { "input-schmitt-enable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 1 },
367};
368
369static int rockchip_pinconf_prop_name_to_param(const char *property,
370 u32 *default_value)
371{
372 const struct pinconf_param *p, *end;
373
374 p = rockchip_conf_params;
375 end = p + sizeof(rockchip_conf_params) / sizeof(struct pinconf_param);
376
377 /* See if this pctldev supports this parameter */
378 for (; p < end; p++) {
379 if (!strcmp(property, p->property)) {
380 *default_value = p->default_value;
381 return p->param;
382 }
383 }
384
385 *default_value = 0;
386 return -EPERM;
387}
388
389static int rockchip_pinctrl_set_state(struct udevice *dev,
390 struct udevice *config)
391{
392 struct rockchip_pinctrl_priv *priv = dev_get_priv(dev);
393 struct rockchip_pin_ctrl *ctrl = priv->ctrl;
394 u32 cells[MAX_ROCKCHIP_PINS_ENTRIES * 4];
395 u32 bank, pin, mux, conf, arg, default_val;
396 int ret, count, i;
397 const char *prop_name;
398 const void *value;
399 int prop_len, param;
400 const u32 *data;
401 ofnode node;
402#ifdef CONFIG_OF_LIVE
403 const struct device_node *np;
404 struct property *pp;
405#else
406 int property_offset, pcfg_node;
407 const void *blob = gd->fdt_blob;
408#endif
409 data = dev_read_prop(config, "rockchip,pins", &count);
410 if (count < 0) {
411 debug("%s: bad array size %d\n", __func__, count);
412 return -EINVAL;
413 }
414
415 count /= sizeof(u32);
416 if (count > MAX_ROCKCHIP_PINS_ENTRIES * 4) {
417 debug("%s: unsupported pins array count %d\n",
418 __func__, count);
419 return -EINVAL;
420 }
421
422 for (i = 0; i < count; i++)
423 cells[i] = fdt32_to_cpu(data[i]);
424
425 for (i = 0; i < (count >> 2); i++) {
426 bank = cells[4 * i + 0];
427 pin = cells[4 * i + 1];
428 mux = cells[4 * i + 2];
429 conf = cells[4 * i + 3];
430
431 ret = rockchip_verify_config(dev, bank, pin);
432 if (ret)
433 return ret;
434
435 ret = rockchip_set_mux(&ctrl->pin_banks[bank], pin, mux);
436 if (ret)
437 return ret;
438
439 node = ofnode_get_by_phandle(conf);
440 if (!ofnode_valid(node))
441 return -ENODEV;
442#ifdef CONFIG_OF_LIVE
443 np = ofnode_to_np(node);
444 for (pp = np->properties; pp; pp = pp->next) {
445 prop_name = pp->name;
446 prop_len = pp->length;
447 value = pp->value;
448#else
449 pcfg_node = ofnode_to_offset(node);
450 fdt_for_each_property_offset(property_offset, blob, pcfg_node) {
451 value = fdt_getprop_by_offset(blob, property_offset,
452 &prop_name, &prop_len);
453 if (!value)
454 return -ENOENT;
455#endif
456 param = rockchip_pinconf_prop_name_to_param(prop_name,
457 &default_val);
458 if (param < 0)
459 break;
460
461 if (prop_len >= sizeof(fdt32_t))
462 arg = fdt32_to_cpu(*(fdt32_t *)value);
463 else
464 arg = default_val;
465
466 ret = rockchip_pinconf_set(&ctrl->pin_banks[bank], pin,
467 param, arg);
468 if (ret) {
469 debug("%s: rockchip_pinconf_set fail: %d\n",
470 __func__, ret);
471 return ret;
472 }
473 }
474 }
475
476 return 0;
477}
478
479const struct pinctrl_ops rockchip_pinctrl_ops = {
480 .set_state = rockchip_pinctrl_set_state,
481 .get_gpio_mux = rockchip_pinctrl_get_gpio_mux,
482};
483
484/* retrieve the soc specific data */
485static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(struct udevice *dev)
486{
487 struct rockchip_pinctrl_priv *priv = dev_get_priv(dev);
488 struct rockchip_pin_ctrl *ctrl =
489 (struct rockchip_pin_ctrl *)dev_get_driver_data(dev);
490 struct rockchip_pin_bank *bank;
491 int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
492
493 grf_offs = ctrl->grf_mux_offset;
494 pmu_offs = ctrl->pmu_mux_offset;
495 drv_pmu_offs = ctrl->pmu_drv_offset;
496 drv_grf_offs = ctrl->grf_drv_offset;
497 bank = ctrl->pin_banks;
498
499 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
500 int bank_pins = 0;
501
502 bank->priv = priv;
503 bank->pin_base = ctrl->nr_pins;
504 ctrl->nr_pins += bank->nr_pins;
505
506 /* calculate iomux and drv offsets */
507 for (j = 0; j < 4; j++) {
508 struct rockchip_iomux *iom = &bank->iomux[j];
509 struct rockchip_drv *drv = &bank->drv[j];
510 int inc;
511
512 if (bank_pins >= bank->nr_pins)
513 break;
514
515 /* preset iomux offset value, set new start value */
516 if (iom->offset >= 0) {
517 if (iom->type & IOMUX_SOURCE_PMU)
518 pmu_offs = iom->offset;
519 else
520 grf_offs = iom->offset;
521 } else { /* set current iomux offset */
522 iom->offset = (iom->type & IOMUX_SOURCE_PMU) ?
523 pmu_offs : grf_offs;
524 }
525
526 /* preset drv offset value, set new start value */
527 if (drv->offset >= 0) {
528 if (iom->type & IOMUX_SOURCE_PMU)
529 drv_pmu_offs = drv->offset;
530 else
531 drv_grf_offs = drv->offset;
532 } else { /* set current drv offset */
533 drv->offset = (iom->type & IOMUX_SOURCE_PMU) ?
534 drv_pmu_offs : drv_grf_offs;
535 }
536
537 debug("bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n",
538 i, j, iom->offset, drv->offset);
539
540 /*
541 * Increase offset according to iomux width.
542 * 4bit iomux'es are spread over two registers.
543 */
544 inc = (iom->type & (IOMUX_WIDTH_4BIT |
David Wufd2fdf72019-12-03 19:26:50 +0800545 IOMUX_WIDTH_3BIT |
546 IOMUX_8WIDTH_2BIT)) ? 8 : 4;
David Wu5f596ae2019-01-02 21:00:55 +0800547 if (iom->type & IOMUX_SOURCE_PMU)
548 pmu_offs += inc;
549 else
550 grf_offs += inc;
551
552 /*
553 * Increase offset according to drv width.
554 * 3bit drive-strenth'es are spread over two registers.
555 */
556 if ((drv->drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
557 (drv->drv_type == DRV_TYPE_IO_3V3_ONLY))
558 inc = 8;
559 else
560 inc = 4;
561
562 if (iom->type & IOMUX_SOURCE_PMU)
563 drv_pmu_offs += inc;
564 else
565 drv_grf_offs += inc;
566
567 bank_pins += 8;
568 }
569
570 /* calculate the per-bank recalced_mask */
571 for (j = 0; j < ctrl->niomux_recalced; j++) {
572 int pin = 0;
573
574 if (ctrl->iomux_recalced[j].num == bank->bank_num) {
575 pin = ctrl->iomux_recalced[j].pin;
576 bank->recalced_mask |= BIT(pin);
577 }
578 }
579
580 /* calculate the per-bank route_mask */
581 for (j = 0; j < ctrl->niomux_routes; j++) {
582 int pin = 0;
583
584 if (ctrl->iomux_routes[j].bank_num == bank->bank_num) {
585 pin = ctrl->iomux_routes[j].pin;
586 bank->route_mask |= BIT(pin);
587 }
588 }
589 }
590
591 return ctrl;
592}
593
594int rockchip_pinctrl_probe(struct udevice *dev)
595{
596 struct rockchip_pinctrl_priv *priv = dev_get_priv(dev);
597 struct rockchip_pin_ctrl *ctrl;
598 struct udevice *syscon;
599 struct regmap *regmap;
600 int ret = 0;
601
602 /* get rockchip grf syscon phandle */
603 ret = uclass_get_device_by_phandle(UCLASS_SYSCON, dev, "rockchip,grf",
604 &syscon);
605 if (ret) {
606 debug("unable to find rockchip,grf syscon device (%d)\n", ret);
607 return ret;
608 }
609
610 /* get grf-reg base address */
611 regmap = syscon_get_regmap(syscon);
612 if (!regmap) {
613 debug("unable to find rockchip grf regmap\n");
614 return -ENODEV;
615 }
616 priv->regmap_base = regmap;
617
618 /* option: get pmu-reg base address */
619 ret = uclass_get_device_by_phandle(UCLASS_SYSCON, dev, "rockchip,pmu",
620 &syscon);
621 if (!ret) {
622 /* get pmugrf-reg base address */
623 regmap = syscon_get_regmap(syscon);
624 if (!regmap) {
625 debug("unable to find rockchip pmu regmap\n");
626 return -ENODEV;
627 }
628 priv->regmap_pmu = regmap;
629 }
630
631 ctrl = rockchip_pinctrl_get_soc_data(dev);
632 if (!ctrl) {
633 debug("driver data not available\n");
634 return -EINVAL;
635 }
636
637 priv->ctrl = ctrl;
638 return 0;
639}