1 // 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> 8 #include <dm/pinctrl.h> 9 #include <regmap.h> 10 #include <syscon.h> 11 #include <fdtdec.h> 12 #include <dm/uclass-internal.h> 13 #include <asm/gpio.h> 14 15 #include "pinctrl-rockchip.h" 16 17 #define MAX_ROCKCHIP_PINS_ENTRIES 30 18 #define MAX_ROCKCHIP_GPIO_PER_BANK 32 19 #define RK_FUNC_GPIO 0 20 21 static int rockchip_verify_config(struct udevice *dev, u32 bank, u32 pin) 22 { 23 struct rockchip_pinctrl_priv *priv = dev_get_priv(dev); 24 struct rockchip_pin_ctrl *ctrl = priv->ctrl; 25 26 if (bank >= ctrl->nr_banks) { 27 debug("pin conf bank %d >= nbanks %d\n", bank, ctrl->nr_banks); 28 return -EINVAL; 29 } 30 31 if (pin >= MAX_ROCKCHIP_GPIO_PER_BANK) { 32 debug("pin conf pin %d >= %d\n", pin, 33 MAX_ROCKCHIP_GPIO_PER_BANK); 34 return -EINVAL; 35 } 36 37 return 0; 38 } 39 40 void rockchip_get_recalced_mux(struct rockchip_pin_bank *bank, int pin, 41 int *reg, u8 *bit, int *mask) 42 { 43 struct rockchip_pinctrl_priv *priv = bank->priv; 44 struct rockchip_pin_ctrl *ctrl = priv->ctrl; 45 struct rockchip_mux_recalced_data *data; 46 int i; 47 48 for (i = 0; i < ctrl->niomux_recalced; i++) { 49 data = &ctrl->iomux_recalced[i]; 50 if (data->num == bank->bank_num && 51 data->pin == pin) 52 break; 53 } 54 55 if (i >= ctrl->niomux_recalced) 56 return; 57 58 *reg = data->reg; 59 *mask = data->mask; 60 *bit = data->bit; 61 } 62 63 static enum rockchip_pin_route_type 64 rockchip_get_mux_route(struct rockchip_pin_bank *bank, int pin, 65 int mux, u32 *reg, u32 *value) 66 { 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 ROUTE_TYPE_INVALID; 81 82 *reg = data->route_offset; 83 *value = data->route_val; 84 85 return data->route_type; 86 } 87 88 int rockchip_get_mux_data(int mux_type, int pin, u8 *bit, int *mask) 89 { 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 114 static 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 -ENOTSUPP; 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, ®, &bit, &mask); 144 145 ret = regmap_read(regmap, reg, &val); 146 if (ret) 147 return ret; 148 149 return ((val >> bit) & mask); 150 } 151 152 static 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 160 static 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 -ENOTSUPP; 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 */ 196 static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux) 197 { 198 struct rockchip_pinctrl_priv *priv = bank->priv; 199 struct rockchip_pin_ctrl *ctrl = priv->ctrl; 200 int iomux_num = (pin / 8); 201 int ret; 202 203 ret = rockchip_verify_mux(bank, pin, mux); 204 if (ret < 0) 205 return ret == -ENOTSUPP ? 0 : 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 212 if (!ctrl->set_mux) 213 return -ENOTSUPP; 214 215 ret = ctrl->set_mux(bank, pin, mux); 216 if (ret) 217 return ret; 218 219 if (bank->route_mask & BIT(pin)) { 220 struct regmap *regmap; 221 u32 route_reg = 0, route_val = 0; 222 223 ret = rockchip_get_mux_route(bank, pin, mux, 224 &route_reg, &route_val); 225 switch (ret) { 226 case ROUTE_TYPE_DEFAULT: 227 if (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU) 228 regmap = priv->regmap_pmu; 229 else if (bank->iomux[iomux_num].type & IOMUX_L_SOURCE_PMU) 230 regmap = (pin % 8 < 4) ? priv->regmap_pmu : priv->regmap_base; 231 else 232 regmap = priv->regmap_base; 233 234 regmap_write(regmap, route_reg, route_val); 235 break; 236 case ROUTE_TYPE_TOPGRF: 237 regmap_write(priv->regmap_base, route_reg, route_val); 238 break; 239 case ROUTE_TYPE_PMUGRF: 240 regmap_write(priv->regmap_pmu, route_reg, route_val); 241 break; 242 case ROUTE_TYPE_INVALID: /* Fall through */ 243 default: 244 break; 245 } 246 } 247 248 return 0; 249 } 250 251 static int rockchip_perpin_drv_list[DRV_TYPE_MAX][8] = { 252 { 2, 4, 8, 12, -1, -1, -1, -1 }, 253 { 3, 6, 9, 12, -1, -1, -1, -1 }, 254 { 5, 10, 15, 20, -1, -1, -1, -1 }, 255 { 4, 6, 8, 10, 12, 14, 16, 18 }, 256 { 4, 7, 10, 13, 16, 19, 22, 26 } 257 }; 258 259 int rockchip_translate_drive_value(int type, int strength) 260 { 261 int i, ret; 262 263 ret = -EINVAL; 264 for (i = 0; i < ARRAY_SIZE(rockchip_perpin_drv_list[type]); i++) { 265 if (rockchip_perpin_drv_list[type][i] == strength) { 266 ret = i; 267 break; 268 } else if (rockchip_perpin_drv_list[type][i] < 0) { 269 ret = rockchip_perpin_drv_list[type][i]; 270 break; 271 } 272 } 273 274 return ret; 275 } 276 277 static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank, 278 int pin_num, int strength) 279 { 280 struct rockchip_pinctrl_priv *priv = bank->priv; 281 struct rockchip_pin_ctrl *ctrl = priv->ctrl; 282 283 debug("setting drive of GPIO%d-%d to %d\n", bank->bank_num, 284 pin_num, strength); 285 286 if (!ctrl->set_drive) 287 return -ENOTSUPP; 288 289 return ctrl->set_drive(bank, pin_num, strength); 290 } 291 292 static int rockchip_pull_list[PULL_TYPE_MAX][4] = { 293 { 294 PIN_CONFIG_BIAS_DISABLE, 295 PIN_CONFIG_BIAS_PULL_UP, 296 PIN_CONFIG_BIAS_PULL_DOWN, 297 PIN_CONFIG_BIAS_BUS_HOLD 298 }, 299 { 300 PIN_CONFIG_BIAS_DISABLE, 301 PIN_CONFIG_BIAS_PULL_DOWN, 302 PIN_CONFIG_BIAS_DISABLE, 303 PIN_CONFIG_BIAS_PULL_UP 304 }, 305 }; 306 307 int rockchip_translate_pull_value(int type, int pull) 308 { 309 int i, ret; 310 311 ret = -EINVAL; 312 for (i = 0; i < ARRAY_SIZE(rockchip_pull_list[type]); 313 i++) { 314 if (rockchip_pull_list[type][i] == pull) { 315 ret = i; 316 break; 317 } 318 } 319 320 return ret; 321 } 322 323 static int rockchip_set_pull(struct rockchip_pin_bank *bank, 324 int pin_num, int pull) 325 { 326 struct rockchip_pinctrl_priv *priv = bank->priv; 327 struct rockchip_pin_ctrl *ctrl = priv->ctrl; 328 329 debug("setting pull of GPIO%d-%d to %d\n", bank->bank_num, 330 pin_num, pull); 331 332 if (!ctrl->set_pull) 333 return -ENOTSUPP; 334 335 return ctrl->set_pull(bank, pin_num, pull); 336 } 337 338 static int rockchip_set_schmitt(struct rockchip_pin_bank *bank, 339 int pin_num, int enable) 340 { 341 struct rockchip_pinctrl_priv *priv = bank->priv; 342 struct rockchip_pin_ctrl *ctrl = priv->ctrl; 343 344 debug("setting input schmitt of GPIO%d-%d to %d\n", bank->bank_num, 345 pin_num, enable); 346 347 if (!ctrl->set_schmitt) 348 return -ENOTSUPP; 349 350 return ctrl->set_schmitt(bank, pin_num, enable); 351 } 352 353 /* set the pin config settings for a specified pin */ 354 static int rockchip_pinconf_set(struct rockchip_pin_bank *bank, 355 u32 pin, u32 param, u32 arg) 356 { 357 int rc; 358 struct gpio_desc desc; 359 char gpio_name[16]; 360 361 switch (param) { 362 case PIN_CONFIG_BIAS_DISABLE: 363 case PIN_CONFIG_BIAS_PULL_UP: 364 case PIN_CONFIG_BIAS_PULL_DOWN: 365 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: 366 case PIN_CONFIG_BIAS_BUS_HOLD: 367 rc = rockchip_set_pull(bank, pin, param); 368 if (rc) 369 return rc; 370 break; 371 372 case PIN_CONFIG_DRIVE_STRENGTH: 373 rc = rockchip_set_drive_perpin(bank, pin, arg); 374 if (rc < 0) 375 return rc; 376 break; 377 378 case PIN_CONFIG_INPUT_SCHMITT_ENABLE: 379 rc = rockchip_set_schmitt(bank, pin, arg); 380 if (rc < 0) 381 return rc; 382 break; 383 384 case PIN_CONFIG_OUTPUT: 385 desc.flags = GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE; 386 if (!arg) desc.flags |= GPIOD_ACTIVE_LOW; 387 snprintf(gpio_name, 16, "%s%d", bank->name, pin); 388 rc = dm_gpio_lookup_name(gpio_name, &desc); 389 if (rc < 0) { 390 debug("%s: GPIO %s-%d lookup failed (ret=%d)\n", __func__, 391 bank->name, pin, rc); 392 } 393 394 rc = dm_gpio_request(&desc, gpio_name); 395 if (rc < 0) { 396 debug("%s: GPIO %s-%d request failed (ret=%d)\n", __func__, 397 bank->name, pin, rc); 398 return rc; 399 } 400 dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT); 401 dm_gpio_set_value(&desc, arg ? 1 : 0); 402 debug("%s: GPIO %s-%d set to %d\n", __func__, bank->name, pin, arg); 403 break; 404 default: 405 break; 406 } 407 408 return 0; 409 } 410 411 static const struct pinconf_param rockchip_conf_params[] = { 412 { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 }, 413 { "bias-bus-hold", PIN_CONFIG_BIAS_BUS_HOLD, 0 }, 414 { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 }, 415 { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 }, 416 { "bias-pull-pin-default", PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 1 }, 417 { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 }, 418 { "input-schmitt-disable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 0 }, 419 { "input-schmitt-enable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 1 }, 420 { "output-high", PIN_CONFIG_OUTPUT, 1, }, 421 { "output-low", PIN_CONFIG_OUTPUT, 0, }, 422 }; 423 424 static int rockchip_pinconf_prop_name_to_param(const char *property, 425 u32 *default_value) 426 { 427 const struct pinconf_param *p, *end; 428 429 p = rockchip_conf_params; 430 end = p + sizeof(rockchip_conf_params) / sizeof(struct pinconf_param); 431 432 /* See if this pctldev supports this parameter */ 433 for (; p < end; p++) { 434 if (!strcmp(property, p->property)) { 435 *default_value = p->default_value; 436 return p->param; 437 } 438 } 439 440 *default_value = 0; 441 return -EPERM; 442 } 443 444 static int rockchip_pinctrl_set_state(struct udevice *dev, 445 struct udevice *config) 446 { 447 struct rockchip_pinctrl_priv *priv = dev_get_priv(dev); 448 struct rockchip_pin_ctrl *ctrl = priv->ctrl; 449 u32 cells[MAX_ROCKCHIP_PINS_ENTRIES * 4]; 450 u32 bank, pin, mux, conf, arg, default_val; 451 int ret, count, i; 452 const char *prop_name; 453 const void *value; 454 int prop_len, param; 455 const u32 *data; 456 ofnode node; 457 #if CONFIG_IS_ENABLED(OF_LIVE) 458 const struct device_node *np; 459 struct property *pp; 460 #else 461 int property_offset, pcfg_node; 462 const void *blob = gd->fdt_blob; 463 #endif 464 data = dev_read_prop(config, "rockchip,pins", &count); 465 if (count < 0) { 466 debug("%s: bad array size %d\n", __func__, count); 467 return -EINVAL; 468 } 469 470 count /= sizeof(u32); 471 if (count > MAX_ROCKCHIP_PINS_ENTRIES * 4) { 472 debug("%s: unsupported pins array count %d\n", 473 __func__, count); 474 return -EINVAL; 475 } 476 477 for (i = 0; i < count; i++) 478 cells[i] = fdt32_to_cpu(data[i]); 479 480 for (i = 0; i < (count >> 2); i++) { 481 bank = cells[4 * i + 0]; 482 pin = cells[4 * i + 1]; 483 mux = cells[4 * i + 2]; 484 conf = cells[4 * i + 3]; 485 486 ret = rockchip_verify_config(dev, bank, pin); 487 if (ret) 488 return ret; 489 490 ret = rockchip_set_mux(&ctrl->pin_banks[bank], pin, mux); 491 if (ret) 492 return ret; 493 494 node = ofnode_get_by_phandle(conf); 495 if (!ofnode_valid(node)) 496 return -ENODEV; 497 #if CONFIG_IS_ENABLED(OF_LIVE) 498 np = ofnode_to_np(node); 499 for (pp = np->properties; pp; pp = pp->next) { 500 prop_name = pp->name; 501 prop_len = pp->length; 502 value = pp->value; 503 #else 504 pcfg_node = ofnode_to_offset(node); 505 fdt_for_each_property_offset(property_offset, blob, pcfg_node) { 506 value = fdt_getprop_by_offset(blob, property_offset, 507 &prop_name, &prop_len); 508 if (!value) 509 return -ENOENT; 510 #endif 511 param = rockchip_pinconf_prop_name_to_param(prop_name, 512 &default_val); 513 if (param < 0) 514 break; 515 516 if (prop_len >= sizeof(fdt32_t)) 517 arg = fdt32_to_cpu(*(fdt32_t *)value); 518 else 519 arg = default_val; 520 521 ret = rockchip_pinconf_set(&ctrl->pin_banks[bank], pin, 522 param, arg); 523 if (ret) { 524 debug("%s: rockchip_pinconf_set fail: %d\n", 525 __func__, ret); 526 return ret; 527 } 528 } 529 } 530 531 return 0; 532 } 533 534 static int rockchip_pinctrl_get_pins_count(struct udevice *dev) 535 { 536 struct rockchip_pinctrl_priv *priv = dev_get_priv(dev); 537 struct rockchip_pin_ctrl *ctrl = priv->ctrl; 538 539 return ctrl->nr_pins; 540 } 541 542 const struct pinctrl_ops rockchip_pinctrl_ops = { 543 .get_pins_count = rockchip_pinctrl_get_pins_count, 544 .set_state = rockchip_pinctrl_set_state, 545 .get_gpio_mux = rockchip_pinctrl_get_gpio_mux, 546 }; 547 548 /* retrieve the soc specific data */ 549 static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(struct udevice *dev) 550 { 551 struct rockchip_pinctrl_priv *priv = dev_get_priv(dev); 552 struct rockchip_pin_ctrl *ctrl = 553 (struct rockchip_pin_ctrl *)dev_get_driver_data(dev); 554 struct rockchip_pin_bank *bank; 555 int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j; 556 u32 nr_pins; 557 558 grf_offs = ctrl->grf_mux_offset; 559 pmu_offs = ctrl->pmu_mux_offset; 560 drv_pmu_offs = ctrl->pmu_drv_offset; 561 drv_grf_offs = ctrl->grf_drv_offset; 562 bank = ctrl->pin_banks; 563 564 nr_pins = 0; 565 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) { 566 int bank_pins = 0; 567 568 bank->priv = priv; 569 bank->pin_base = nr_pins; 570 nr_pins += bank->nr_pins; 571 572 /* calculate iomux and drv offsets */ 573 for (j = 0; j < 4; j++) { 574 struct rockchip_iomux *iom = &bank->iomux[j]; 575 struct rockchip_drv *drv = &bank->drv[j]; 576 int inc; 577 578 if (bank_pins >= nr_pins) 579 break; 580 581 /* preset iomux offset value, set new start value */ 582 if (iom->offset >= 0) { 583 if ((iom->type & IOMUX_SOURCE_PMU) || (iom->type & IOMUX_L_SOURCE_PMU)) 584 pmu_offs = iom->offset; 585 else 586 grf_offs = iom->offset; 587 } else { /* set current iomux offset */ 588 iom->offset = ((iom->type & IOMUX_SOURCE_PMU) || 589 (iom->type & IOMUX_L_SOURCE_PMU)) ? 590 pmu_offs : grf_offs; 591 } 592 593 /* preset drv offset value, set new start value */ 594 if (drv->offset >= 0) { 595 if (iom->type & IOMUX_SOURCE_PMU) 596 drv_pmu_offs = drv->offset; 597 else 598 drv_grf_offs = drv->offset; 599 } else { /* set current drv offset */ 600 drv->offset = (iom->type & IOMUX_SOURCE_PMU) ? 601 drv_pmu_offs : drv_grf_offs; 602 } 603 604 debug("bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n", 605 i, j, iom->offset, drv->offset); 606 607 /* 608 * Increase offset according to iomux width. 609 * 4bit iomux'es are spread over two registers. 610 */ 611 inc = (iom->type & (IOMUX_WIDTH_4BIT | 612 IOMUX_WIDTH_3BIT | 613 IOMUX_8WIDTH_2BIT)) ? 8 : 4; 614 if ((iom->type & IOMUX_SOURCE_PMU) || (iom->type & IOMUX_L_SOURCE_PMU)) 615 pmu_offs += inc; 616 else 617 grf_offs += inc; 618 619 /* 620 * Increase offset according to drv width. 621 * 3bit drive-strenth'es are spread over two registers. 622 */ 623 if ((drv->drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) || 624 (drv->drv_type == DRV_TYPE_IO_3V3_ONLY)) 625 inc = 8; 626 else 627 inc = 4; 628 629 if (iom->type & IOMUX_SOURCE_PMU) 630 drv_pmu_offs += inc; 631 else 632 drv_grf_offs += inc; 633 634 bank_pins += 8; 635 } 636 637 /* calculate the per-bank recalced_mask */ 638 for (j = 0; j < ctrl->niomux_recalced; j++) { 639 int pin = 0; 640 641 if (ctrl->iomux_recalced[j].num == bank->bank_num) { 642 pin = ctrl->iomux_recalced[j].pin; 643 bank->recalced_mask |= BIT(pin); 644 } 645 } 646 647 /* calculate the per-bank route_mask */ 648 for (j = 0; j < ctrl->niomux_routes; j++) { 649 int pin = 0; 650 651 if (ctrl->iomux_routes[j].bank_num == bank->bank_num) { 652 pin = ctrl->iomux_routes[j].pin; 653 bank->route_mask |= BIT(pin); 654 } 655 } 656 } 657 658 WARN_ON(nr_pins != ctrl->nr_pins); 659 660 return ctrl; 661 } 662 663 int rockchip_pinctrl_probe(struct udevice *dev) 664 { 665 struct rockchip_pinctrl_priv *priv = dev_get_priv(dev); 666 struct rockchip_pin_ctrl *ctrl; 667 struct udevice *syscon; 668 struct regmap *regmap; 669 int ret = 0; 670 671 /* get rockchip grf syscon phandle */ 672 ret = uclass_get_device_by_phandle(UCLASS_SYSCON, dev, "rockchip,grf", 673 &syscon); 674 if (ret) { 675 debug("unable to find rockchip,grf syscon device (%d)\n", ret); 676 return ret; 677 } 678 679 /* get grf-reg base address */ 680 regmap = syscon_get_regmap(syscon); 681 if (!regmap) { 682 debug("unable to find rockchip grf regmap\n"); 683 return -ENODEV; 684 } 685 priv->regmap_base = regmap; 686 687 /* option: get pmu-reg base address */ 688 ret = uclass_get_device_by_phandle(UCLASS_SYSCON, dev, "rockchip,pmu", 689 &syscon); 690 if (!ret) { 691 /* get pmugrf-reg base address */ 692 regmap = syscon_get_regmap(syscon); 693 if (!regmap) { 694 debug("unable to find rockchip pmu regmap\n"); 695 return -ENODEV; 696 } 697 priv->regmap_pmu = regmap; 698 } 699 700 ctrl = rockchip_pinctrl_get_soc_data(dev); 701 if (!ctrl) { 702 debug("driver data not available\n"); 703 return -EINVAL; 704 } 705 706 priv->ctrl = ctrl; 707 return 0; 708 } 709