1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Pinctrl driver for Rockchip SoCs 4 * 5 * Copyright (c) 2013 MundoReader S.L. 6 * Author: Heiko Stuebner <heiko@sntech.de> 7 * 8 * With some ideas taken from pinctrl-samsung: 9 * Copyright (c) 2012 Samsung Electronics Co., Ltd. 10 * http://www.samsung.com 11 * Copyright (c) 2012 Linaro Ltd 12 * https://www.linaro.org 13 * 14 * and pinctrl-at91: 15 * Copyright (C) 2011-2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> 16 */ 17 18 #include <linux/init.h> 19 #include <linux/module.h> 20 #include <linux/platform_device.h> 21 #include <linux/io.h> 22 #include <linux/bitops.h> 23 #include <linux/gpio/driver.h> 24 #include <linux/of.h> 25 #include <linux/of_platform.h> 26 #include <linux/pinctrl/machine.h> 27 #include <linux/pinctrl/pinconf.h> 28 #include <linux/pinctrl/pinctrl.h> 29 #include <linux/pinctrl/pinmux.h> 30 #include <linux/pinctrl/pinconf-generic.h> 31 #include <linux/irqchip/chained_irq.h> 32 #include <linux/clk.h> 33 #include <linux/regmap.h> 34 #include <linux/mfd/syscon.h> 35 #include <linux/string_helpers.h> 36 37 #include <dt-bindings/pinctrl/rockchip.h> 38 39 #include "core.h" 40 #include "pinconf.h" 41 #include "pinctrl-rockchip.h" 42 43 /* 44 * Generate a bitmask for setting a value (v) with a write mask bit in hiword 45 * register 31:16 area. 46 */ 47 #define WRITE_MASK_VAL(h, l, v) \ 48 (GENMASK(((h) + 16), ((l) + 16)) | (((v) << (l)) & GENMASK((h), (l)))) 49 50 /* 51 * Encode variants of iomux registers into a type variable 52 */ 53 #define IOMUX_GPIO_ONLY BIT(0) 54 #define IOMUX_WIDTH_4BIT BIT(1) 55 #define IOMUX_SOURCE_PMU BIT(2) 56 #define IOMUX_UNROUTED BIT(3) 57 #define IOMUX_WIDTH_3BIT BIT(4) 58 #define IOMUX_WIDTH_2BIT BIT(5) 59 #define IOMUX_L_SOURCE_PMU BIT(6) 60 61 #define PIN_BANK(id, pins, label) \ 62 { \ 63 .bank_num = id, \ 64 .nr_pins = pins, \ 65 .name = label, \ 66 .iomux = { \ 67 { .offset = -1 }, \ 68 { .offset = -1 }, \ 69 { .offset = -1 }, \ 70 { .offset = -1 }, \ 71 }, \ 72 } 73 74 #define PIN_BANK_IOMUX_FLAGS(id, pins, label, iom0, iom1, iom2, iom3) \ 75 { \ 76 .bank_num = id, \ 77 .nr_pins = pins, \ 78 .name = label, \ 79 .iomux = { \ 80 { .type = iom0, .offset = -1 }, \ 81 { .type = iom1, .offset = -1 }, \ 82 { .type = iom2, .offset = -1 }, \ 83 { .type = iom3, .offset = -1 }, \ 84 }, \ 85 } 86 87 #define PIN_BANK_DRV_FLAGS(id, pins, label, type0, type1, type2, type3) \ 88 { \ 89 .bank_num = id, \ 90 .nr_pins = pins, \ 91 .name = label, \ 92 .iomux = { \ 93 { .offset = -1 }, \ 94 { .offset = -1 }, \ 95 { .offset = -1 }, \ 96 { .offset = -1 }, \ 97 }, \ 98 .drv = { \ 99 { .drv_type = type0, .offset = -1 }, \ 100 { .drv_type = type1, .offset = -1 }, \ 101 { .drv_type = type2, .offset = -1 }, \ 102 { .drv_type = type3, .offset = -1 }, \ 103 }, \ 104 } 105 106 #define PIN_BANK_IOMUX_FLAGS_PULL_FLAGS(id, pins, label, iom0, iom1, \ 107 iom2, iom3, pull0, pull1, \ 108 pull2, pull3) \ 109 { \ 110 .bank_num = id, \ 111 .nr_pins = pins, \ 112 .name = label, \ 113 .iomux = { \ 114 { .type = iom0, .offset = -1 }, \ 115 { .type = iom1, .offset = -1 }, \ 116 { .type = iom2, .offset = -1 }, \ 117 { .type = iom3, .offset = -1 }, \ 118 }, \ 119 .pull_type[0] = pull0, \ 120 .pull_type[1] = pull1, \ 121 .pull_type[2] = pull2, \ 122 .pull_type[3] = pull3, \ 123 } 124 125 #define PIN_BANK_DRV_FLAGS_PULL_FLAGS(id, pins, label, drv0, drv1, \ 126 drv2, drv3, pull0, pull1, \ 127 pull2, pull3) \ 128 { \ 129 .bank_num = id, \ 130 .nr_pins = pins, \ 131 .name = label, \ 132 .iomux = { \ 133 { .offset = -1 }, \ 134 { .offset = -1 }, \ 135 { .offset = -1 }, \ 136 { .offset = -1 }, \ 137 }, \ 138 .drv = { \ 139 { .drv_type = drv0, .offset = -1 }, \ 140 { .drv_type = drv1, .offset = -1 }, \ 141 { .drv_type = drv2, .offset = -1 }, \ 142 { .drv_type = drv3, .offset = -1 }, \ 143 }, \ 144 .pull_type[0] = pull0, \ 145 .pull_type[1] = pull1, \ 146 .pull_type[2] = pull2, \ 147 .pull_type[3] = pull3, \ 148 } 149 150 #define PIN_BANK_IOMUX_FLAGS_OFFSET(id, pins, label, iom0, iom1, iom2, \ 151 iom3, offset0, offset1, offset2, \ 152 offset3) \ 153 { \ 154 .bank_num = id, \ 155 .nr_pins = pins, \ 156 .name = label, \ 157 .iomux = { \ 158 { .type = iom0, .offset = offset0 }, \ 159 { .type = iom1, .offset = offset1 }, \ 160 { .type = iom2, .offset = offset2 }, \ 161 { .type = iom3, .offset = offset3 }, \ 162 }, \ 163 } 164 165 #define PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(id, pins, label, iom0, iom1, \ 166 iom2, iom3, drv0, drv1, drv2, \ 167 drv3, offset0, offset1, \ 168 offset2, offset3) \ 169 { \ 170 .bank_num = id, \ 171 .nr_pins = pins, \ 172 .name = label, \ 173 .iomux = { \ 174 { .type = iom0, .offset = -1 }, \ 175 { .type = iom1, .offset = -1 }, \ 176 { .type = iom2, .offset = -1 }, \ 177 { .type = iom3, .offset = -1 }, \ 178 }, \ 179 .drv = { \ 180 { .drv_type = drv0, .offset = offset0 }, \ 181 { .drv_type = drv1, .offset = offset1 }, \ 182 { .drv_type = drv2, .offset = offset2 }, \ 183 { .drv_type = drv3, .offset = offset3 }, \ 184 }, \ 185 } 186 187 #define PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(id, pins, \ 188 label, iom0, iom1, iom2, \ 189 iom3, drv0, drv1, drv2, \ 190 drv3, offset0, offset1, \ 191 offset2, offset3, pull0, \ 192 pull1, pull2, pull3) \ 193 { \ 194 .bank_num = id, \ 195 .nr_pins = pins, \ 196 .name = label, \ 197 .iomux = { \ 198 { .type = iom0, .offset = -1 }, \ 199 { .type = iom1, .offset = -1 }, \ 200 { .type = iom2, .offset = -1 }, \ 201 { .type = iom3, .offset = -1 }, \ 202 }, \ 203 .drv = { \ 204 { .drv_type = drv0, .offset = offset0 }, \ 205 { .drv_type = drv1, .offset = offset1 }, \ 206 { .drv_type = drv2, .offset = offset2 }, \ 207 { .drv_type = drv3, .offset = offset3 }, \ 208 }, \ 209 .pull_type[0] = pull0, \ 210 .pull_type[1] = pull1, \ 211 .pull_type[2] = pull2, \ 212 .pull_type[3] = pull3, \ 213 } 214 215 #define PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, FLAG) \ 216 { \ 217 .bank_num = ID, \ 218 .pin = PIN, \ 219 .func = FUNC, \ 220 .route_offset = REG, \ 221 .route_val = VAL, \ 222 .route_location = FLAG, \ 223 } 224 225 #define RK_MUXROUTE_SAME(ID, PIN, FUNC, REG, VAL) \ 226 PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, ROCKCHIP_ROUTE_SAME) 227 228 #define RK_MUXROUTE_GRF(ID, PIN, FUNC, REG, VAL) \ 229 PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, ROCKCHIP_ROUTE_GRF) 230 231 #define RK_MUXROUTE_PMU(ID, PIN, FUNC, REG, VAL) \ 232 PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, ROCKCHIP_ROUTE_PMU) 233 234 #define RK3588_PIN_BANK_FLAGS(ID, PIN, LABEL, M, P) \ 235 PIN_BANK_IOMUX_FLAGS_PULL_FLAGS(ID, PIN, LABEL, M, M, M, M, P, P, P, P) 236 237 static struct regmap_config rockchip_regmap_config = { 238 .reg_bits = 32, 239 .val_bits = 32, 240 .reg_stride = 4, 241 }; 242 243 static inline const struct rockchip_pin_group *pinctrl_name_to_group( 244 const struct rockchip_pinctrl *info, 245 const char *name) 246 { 247 int i; 248 249 for (i = 0; i < info->ngroups; i++) { 250 if (!strcmp(info->groups[i].name, name)) 251 return &info->groups[i]; 252 } 253 254 return NULL; 255 } 256 257 /* 258 * given a pin number that is local to a pin controller, find out the pin bank 259 * and the register base of the pin bank. 260 */ 261 static struct rockchip_pin_bank *pin_to_bank(struct rockchip_pinctrl *info, 262 unsigned pin) 263 { 264 struct rockchip_pin_bank *b = info->ctrl->pin_banks; 265 266 while (pin >= (b->pin_base + b->nr_pins)) 267 b++; 268 269 return b; 270 } 271 272 static struct rockchip_pin_bank *bank_num_to_bank( 273 struct rockchip_pinctrl *info, 274 unsigned num) 275 { 276 struct rockchip_pin_bank *b = info->ctrl->pin_banks; 277 int i; 278 279 for (i = 0; i < info->ctrl->nr_banks; i++, b++) { 280 if (b->bank_num == num) 281 return b; 282 } 283 284 return ERR_PTR(-EINVAL); 285 } 286 287 /* 288 * Pinctrl_ops handling 289 */ 290 291 static int rockchip_get_groups_count(struct pinctrl_dev *pctldev) 292 { 293 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); 294 295 return info->ngroups; 296 } 297 298 static const char *rockchip_get_group_name(struct pinctrl_dev *pctldev, 299 unsigned selector) 300 { 301 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); 302 303 return info->groups[selector].name; 304 } 305 306 static int rockchip_get_group_pins(struct pinctrl_dev *pctldev, 307 unsigned selector, const unsigned **pins, 308 unsigned *npins) 309 { 310 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); 311 312 if (selector >= info->ngroups) 313 return -EINVAL; 314 315 *pins = info->groups[selector].pins; 316 *npins = info->groups[selector].npins; 317 318 return 0; 319 } 320 321 static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev, 322 struct device_node *np, 323 struct pinctrl_map **map, unsigned *num_maps) 324 { 325 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); 326 const struct rockchip_pin_group *grp; 327 struct device *dev = info->dev; 328 struct pinctrl_map *new_map; 329 struct device_node *parent; 330 int map_num = 1; 331 int i; 332 333 /* 334 * first find the group of this node and check if we need to create 335 * config maps for pins 336 */ 337 grp = pinctrl_name_to_group(info, np->name); 338 if (!grp) { 339 dev_err(dev, "unable to find group for node %pOFn\n", np); 340 return -EINVAL; 341 } 342 343 map_num += grp->npins; 344 345 new_map = kcalloc(map_num, sizeof(*new_map), GFP_KERNEL); 346 if (!new_map) 347 return -ENOMEM; 348 349 *map = new_map; 350 *num_maps = map_num; 351 352 /* create mux map */ 353 parent = of_get_parent(np); 354 if (!parent) { 355 kfree(new_map); 356 return -EINVAL; 357 } 358 new_map[0].type = PIN_MAP_TYPE_MUX_GROUP; 359 new_map[0].data.mux.function = parent->name; 360 new_map[0].data.mux.group = np->name; 361 of_node_put(parent); 362 363 /* create config map */ 364 new_map++; 365 for (i = 0; i < grp->npins; i++) { 366 new_map[i].type = PIN_MAP_TYPE_CONFIGS_PIN; 367 new_map[i].data.configs.group_or_pin = 368 pin_get_name(pctldev, grp->pins[i]); 369 new_map[i].data.configs.configs = grp->data[i].configs; 370 new_map[i].data.configs.num_configs = grp->data[i].nconfigs; 371 } 372 373 dev_dbg(dev, "maps: function %s group %s num %d\n", 374 (*map)->data.mux.function, (*map)->data.mux.group, map_num); 375 376 return 0; 377 } 378 379 static void rockchip_dt_free_map(struct pinctrl_dev *pctldev, 380 struct pinctrl_map *map, unsigned num_maps) 381 { 382 kfree(map); 383 } 384 385 static const struct pinctrl_ops rockchip_pctrl_ops = { 386 .get_groups_count = rockchip_get_groups_count, 387 .get_group_name = rockchip_get_group_name, 388 .get_group_pins = rockchip_get_group_pins, 389 .dt_node_to_map = rockchip_dt_node_to_map, 390 .dt_free_map = rockchip_dt_free_map, 391 }; 392 393 /* 394 * Hardware access 395 */ 396 397 static struct rockchip_mux_recalced_data rv1108_mux_recalced_data[] = { 398 { 399 .num = 1, 400 .pin = 0, 401 .reg = 0x418, 402 .bit = 0, 403 .mask = 0x3 404 }, { 405 .num = 1, 406 .pin = 1, 407 .reg = 0x418, 408 .bit = 2, 409 .mask = 0x3 410 }, { 411 .num = 1, 412 .pin = 2, 413 .reg = 0x418, 414 .bit = 4, 415 .mask = 0x3 416 }, { 417 .num = 1, 418 .pin = 3, 419 .reg = 0x418, 420 .bit = 6, 421 .mask = 0x3 422 }, { 423 .num = 1, 424 .pin = 4, 425 .reg = 0x418, 426 .bit = 8, 427 .mask = 0x3 428 }, { 429 .num = 1, 430 .pin = 5, 431 .reg = 0x418, 432 .bit = 10, 433 .mask = 0x3 434 }, { 435 .num = 1, 436 .pin = 6, 437 .reg = 0x418, 438 .bit = 12, 439 .mask = 0x3 440 }, { 441 .num = 1, 442 .pin = 7, 443 .reg = 0x418, 444 .bit = 14, 445 .mask = 0x3 446 }, { 447 .num = 1, 448 .pin = 8, 449 .reg = 0x41c, 450 .bit = 0, 451 .mask = 0x3 452 }, { 453 .num = 1, 454 .pin = 9, 455 .reg = 0x41c, 456 .bit = 2, 457 .mask = 0x3 458 }, 459 }; 460 461 static struct rockchip_mux_recalced_data rv1126_mux_recalced_data[] = { 462 { 463 .num = 0, 464 .pin = 20, 465 .reg = 0x10000, 466 .bit = 0, 467 .mask = 0xf 468 }, 469 { 470 .num = 0, 471 .pin = 21, 472 .reg = 0x10000, 473 .bit = 4, 474 .mask = 0xf 475 }, 476 { 477 .num = 0, 478 .pin = 22, 479 .reg = 0x10000, 480 .bit = 8, 481 .mask = 0xf 482 }, 483 { 484 .num = 0, 485 .pin = 23, 486 .reg = 0x10000, 487 .bit = 12, 488 .mask = 0xf 489 }, 490 }; 491 492 static struct rockchip_mux_recalced_data rk3128_mux_recalced_data[] = { 493 { 494 .num = 2, 495 .pin = 20, 496 .reg = 0xe8, 497 .bit = 0, 498 .mask = 0x7 499 }, { 500 .num = 2, 501 .pin = 21, 502 .reg = 0xe8, 503 .bit = 4, 504 .mask = 0x7 505 }, { 506 .num = 2, 507 .pin = 22, 508 .reg = 0xe8, 509 .bit = 8, 510 .mask = 0x7 511 }, { 512 .num = 2, 513 .pin = 23, 514 .reg = 0xe8, 515 .bit = 12, 516 .mask = 0x7 517 }, { 518 .num = 2, 519 .pin = 24, 520 .reg = 0xd4, 521 .bit = 12, 522 .mask = 0x7 523 }, 524 }; 525 526 static struct rockchip_mux_recalced_data rk3308_mux_recalced_data[] = { 527 { 528 /* gpio1b6_sel */ 529 .num = 1, 530 .pin = 14, 531 .reg = 0x28, 532 .bit = 12, 533 .mask = 0xf 534 }, { 535 /* gpio1b7_sel */ 536 .num = 1, 537 .pin = 15, 538 .reg = 0x2c, 539 .bit = 0, 540 .mask = 0x3 541 }, { 542 /* gpio1c2_sel */ 543 .num = 1, 544 .pin = 18, 545 .reg = 0x30, 546 .bit = 4, 547 .mask = 0xf 548 }, { 549 /* gpio1c3_sel */ 550 .num = 1, 551 .pin = 19, 552 .reg = 0x30, 553 .bit = 8, 554 .mask = 0xf 555 }, { 556 /* gpio1c4_sel */ 557 .num = 1, 558 .pin = 20, 559 .reg = 0x30, 560 .bit = 12, 561 .mask = 0xf 562 }, { 563 /* gpio1c5_sel */ 564 .num = 1, 565 .pin = 21, 566 .reg = 0x34, 567 .bit = 0, 568 .mask = 0xf 569 }, { 570 /* gpio1c6_sel */ 571 .num = 1, 572 .pin = 22, 573 .reg = 0x34, 574 .bit = 4, 575 .mask = 0xf 576 }, { 577 /* gpio1c7_sel */ 578 .num = 1, 579 .pin = 23, 580 .reg = 0x34, 581 .bit = 8, 582 .mask = 0xf 583 }, { 584 /* gpio2a2_sel */ 585 .num = 2, 586 .pin = 2, 587 .reg = 0x40, 588 .bit = 4, 589 .mask = 0x3 590 }, { 591 /* gpio2a3_sel */ 592 .num = 2, 593 .pin = 3, 594 .reg = 0x40, 595 .bit = 6, 596 .mask = 0x3 597 }, { 598 /* gpio2c0_sel */ 599 .num = 2, 600 .pin = 16, 601 .reg = 0x50, 602 .bit = 0, 603 .mask = 0x3 604 }, { 605 /* gpio3b2_sel */ 606 .num = 3, 607 .pin = 10, 608 .reg = 0x68, 609 .bit = 4, 610 .mask = 0x3 611 }, { 612 /* gpio3b3_sel */ 613 .num = 3, 614 .pin = 11, 615 .reg = 0x68, 616 .bit = 6, 617 .mask = 0x3 618 }, { 619 /* gpio3b4_sel */ 620 .num = 3, 621 .pin = 12, 622 .reg = 0x68, 623 .bit = 8, 624 .mask = 0xf 625 }, { 626 /* gpio3b5_sel */ 627 .num = 3, 628 .pin = 13, 629 .reg = 0x68, 630 .bit = 12, 631 .mask = 0xf 632 }, 633 }; 634 635 static struct rockchip_mux_recalced_data rk3328_mux_recalced_data[] = { 636 { 637 /* gpio2_b7_sel */ 638 .num = 2, 639 .pin = 15, 640 .reg = 0x28, 641 .bit = 0, 642 .mask = 0x7 643 }, { 644 /* gpio2_c7_sel */ 645 .num = 2, 646 .pin = 23, 647 .reg = 0x30, 648 .bit = 14, 649 .mask = 0x3 650 }, { 651 /* gpio3_b1_sel */ 652 .num = 3, 653 .pin = 9, 654 .reg = 0x44, 655 .bit = 2, 656 .mask = 0x3 657 }, { 658 /* gpio3_b2_sel */ 659 .num = 3, 660 .pin = 10, 661 .reg = 0x44, 662 .bit = 4, 663 .mask = 0x3 664 }, { 665 /* gpio3_b3_sel */ 666 .num = 3, 667 .pin = 11, 668 .reg = 0x44, 669 .bit = 6, 670 .mask = 0x3 671 }, { 672 /* gpio3_b4_sel */ 673 .num = 3, 674 .pin = 12, 675 .reg = 0x44, 676 .bit = 8, 677 .mask = 0x3 678 }, { 679 /* gpio3_b5_sel */ 680 .num = 3, 681 .pin = 13, 682 .reg = 0x44, 683 .bit = 10, 684 .mask = 0x3 685 }, { 686 /* gpio3_b6_sel */ 687 .num = 3, 688 .pin = 14, 689 .reg = 0x44, 690 .bit = 12, 691 .mask = 0x3 692 }, { 693 /* gpio3_b7_sel */ 694 .num = 3, 695 .pin = 15, 696 .reg = 0x44, 697 .bit = 14, 698 .mask = 0x3 699 }, 700 }; 701 702 static void rockchip_get_recalced_mux(struct rockchip_pin_bank *bank, int pin, 703 int *reg, u8 *bit, int *mask) 704 { 705 struct rockchip_pinctrl *info = bank->drvdata; 706 struct rockchip_pin_ctrl *ctrl = info->ctrl; 707 struct rockchip_mux_recalced_data *data; 708 int i; 709 710 for (i = 0; i < ctrl->niomux_recalced; i++) { 711 data = &ctrl->iomux_recalced[i]; 712 if (data->num == bank->bank_num && 713 data->pin == pin) 714 break; 715 } 716 717 if (i >= ctrl->niomux_recalced) 718 return; 719 720 *reg = data->reg; 721 *mask = data->mask; 722 *bit = data->bit; 723 } 724 725 static struct rockchip_mux_route_data px30_mux_route_data[] = { 726 RK_MUXROUTE_SAME(2, RK_PB4, 1, 0x184, BIT(16 + 7)), /* cif-d0m0 */ 727 RK_MUXROUTE_SAME(3, RK_PA1, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d0m1 */ 728 RK_MUXROUTE_SAME(2, RK_PB6, 1, 0x184, BIT(16 + 7)), /* cif-d1m0 */ 729 RK_MUXROUTE_SAME(3, RK_PA2, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d1m1 */ 730 RK_MUXROUTE_SAME(2, RK_PA0, 1, 0x184, BIT(16 + 7)), /* cif-d2m0 */ 731 RK_MUXROUTE_SAME(3, RK_PA3, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d2m1 */ 732 RK_MUXROUTE_SAME(2, RK_PA1, 1, 0x184, BIT(16 + 7)), /* cif-d3m0 */ 733 RK_MUXROUTE_SAME(3, RK_PA5, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d3m1 */ 734 RK_MUXROUTE_SAME(2, RK_PA2, 1, 0x184, BIT(16 + 7)), /* cif-d4m0 */ 735 RK_MUXROUTE_SAME(3, RK_PA7, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d4m1 */ 736 RK_MUXROUTE_SAME(2, RK_PA3, 1, 0x184, BIT(16 + 7)), /* cif-d5m0 */ 737 RK_MUXROUTE_SAME(3, RK_PB0, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d5m1 */ 738 RK_MUXROUTE_SAME(2, RK_PA4, 1, 0x184, BIT(16 + 7)), /* cif-d6m0 */ 739 RK_MUXROUTE_SAME(3, RK_PB1, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d6m1 */ 740 RK_MUXROUTE_SAME(2, RK_PA5, 1, 0x184, BIT(16 + 7)), /* cif-d7m0 */ 741 RK_MUXROUTE_SAME(3, RK_PB4, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d7m1 */ 742 RK_MUXROUTE_SAME(2, RK_PA6, 1, 0x184, BIT(16 + 7)), /* cif-d8m0 */ 743 RK_MUXROUTE_SAME(3, RK_PB6, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d8m1 */ 744 RK_MUXROUTE_SAME(2, RK_PA7, 1, 0x184, BIT(16 + 7)), /* cif-d9m0 */ 745 RK_MUXROUTE_SAME(3, RK_PB7, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d9m1 */ 746 RK_MUXROUTE_SAME(2, RK_PB7, 1, 0x184, BIT(16 + 7)), /* cif-d10m0 */ 747 RK_MUXROUTE_SAME(3, RK_PC6, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d10m1 */ 748 RK_MUXROUTE_SAME(2, RK_PC0, 1, 0x184, BIT(16 + 7)), /* cif-d11m0 */ 749 RK_MUXROUTE_SAME(3, RK_PC7, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d11m1 */ 750 RK_MUXROUTE_SAME(2, RK_PB0, 1, 0x184, BIT(16 + 7)), /* cif-vsyncm0 */ 751 RK_MUXROUTE_SAME(3, RK_PD1, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-vsyncm1 */ 752 RK_MUXROUTE_SAME(2, RK_PB1, 1, 0x184, BIT(16 + 7)), /* cif-hrefm0 */ 753 RK_MUXROUTE_SAME(3, RK_PD2, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-hrefm1 */ 754 RK_MUXROUTE_SAME(2, RK_PB2, 1, 0x184, BIT(16 + 7)), /* cif-clkinm0 */ 755 RK_MUXROUTE_SAME(3, RK_PD3, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-clkinm1 */ 756 RK_MUXROUTE_SAME(2, RK_PB3, 1, 0x184, BIT(16 + 7)), /* cif-clkoutm0 */ 757 RK_MUXROUTE_SAME(3, RK_PD0, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-clkoutm1 */ 758 RK_MUXROUTE_SAME(3, RK_PC6, 2, 0x184, BIT(16 + 8)), /* pdm-m0 */ 759 RK_MUXROUTE_SAME(2, RK_PC6, 1, 0x184, BIT(16 + 8) | BIT(8)), /* pdm-m1 */ 760 RK_MUXROUTE_SAME(3, RK_PD3, 2, 0x184, BIT(16 + 8)), /* pdm-sdi0m0 */ 761 RK_MUXROUTE_SAME(2, RK_PC5, 2, 0x184, BIT(16 + 8) | BIT(8)), /* pdm-sdi0m1 */ 762 RK_MUXROUTE_SAME(1, RK_PD3, 2, 0x184, BIT(16 + 10)), /* uart2-rxm0 */ 763 RK_MUXROUTE_SAME(2, RK_PB6, 2, 0x184, BIT(16 + 10) | BIT(10)), /* uart2-rxm1 */ 764 RK_MUXROUTE_SAME(1, RK_PD2, 2, 0x184, BIT(16 + 10)), /* uart2-txm0 */ 765 RK_MUXROUTE_SAME(2, RK_PB4, 2, 0x184, BIT(16 + 10) | BIT(10)), /* uart2-txm1 */ 766 RK_MUXROUTE_SAME(0, RK_PC1, 2, 0x184, BIT(16 + 9)), /* uart3-rxm0 */ 767 RK_MUXROUTE_SAME(1, RK_PB7, 2, 0x184, BIT(16 + 9) | BIT(9)), /* uart3-rxm1 */ 768 RK_MUXROUTE_SAME(0, RK_PC0, 2, 0x184, BIT(16 + 9)), /* uart3-txm0 */ 769 RK_MUXROUTE_SAME(1, RK_PB6, 2, 0x184, BIT(16 + 9) | BIT(9)), /* uart3-txm1 */ 770 RK_MUXROUTE_SAME(0, RK_PC2, 2, 0x184, BIT(16 + 9)), /* uart3-ctsm0 */ 771 RK_MUXROUTE_SAME(1, RK_PB4, 2, 0x184, BIT(16 + 9) | BIT(9)), /* uart3-ctsm1 */ 772 RK_MUXROUTE_SAME(0, RK_PC3, 2, 0x184, BIT(16 + 9)), /* uart3-rtsm0 */ 773 RK_MUXROUTE_SAME(1, RK_PB5, 2, 0x184, BIT(16 + 9) | BIT(9)), /* uart3-rtsm1 */ 774 }; 775 776 static struct rockchip_mux_route_data rv1126_mux_route_data[] = { 777 RK_MUXROUTE_GRF(3, RK_PD2, 1, 0x10260, WRITE_MASK_VAL(0, 0, 0)), /* I2S0_MCLK_M0 */ 778 RK_MUXROUTE_GRF(3, RK_PB0, 3, 0x10260, WRITE_MASK_VAL(0, 0, 1)), /* I2S0_MCLK_M1 */ 779 780 RK_MUXROUTE_GRF(0, RK_PD4, 4, 0x10260, WRITE_MASK_VAL(3, 2, 0)), /* I2S1_MCLK_M0 */ 781 RK_MUXROUTE_GRF(1, RK_PD5, 2, 0x10260, WRITE_MASK_VAL(3, 2, 1)), /* I2S1_MCLK_M1 */ 782 RK_MUXROUTE_GRF(2, RK_PC7, 6, 0x10260, WRITE_MASK_VAL(3, 2, 2)), /* I2S1_MCLK_M2 */ 783 784 RK_MUXROUTE_GRF(1, RK_PD0, 1, 0x10260, WRITE_MASK_VAL(4, 4, 0)), /* I2S2_MCLK_M0 */ 785 RK_MUXROUTE_GRF(2, RK_PB3, 2, 0x10260, WRITE_MASK_VAL(4, 4, 1)), /* I2S2_MCLK_M1 */ 786 787 RK_MUXROUTE_GRF(3, RK_PD4, 2, 0x10260, WRITE_MASK_VAL(12, 12, 0)), /* PDM_CLK0_M0 */ 788 RK_MUXROUTE_GRF(3, RK_PC0, 3, 0x10260, WRITE_MASK_VAL(12, 12, 1)), /* PDM_CLK0_M1 */ 789 790 RK_MUXROUTE_GRF(3, RK_PC6, 1, 0x10264, WRITE_MASK_VAL(0, 0, 0)), /* CIF_CLKOUT_M0 */ 791 RK_MUXROUTE_GRF(2, RK_PD1, 3, 0x10264, WRITE_MASK_VAL(0, 0, 1)), /* CIF_CLKOUT_M1 */ 792 793 RK_MUXROUTE_GRF(3, RK_PA4, 5, 0x10264, WRITE_MASK_VAL(5, 4, 0)), /* I2C3_SCL_M0 */ 794 RK_MUXROUTE_GRF(2, RK_PD4, 7, 0x10264, WRITE_MASK_VAL(5, 4, 1)), /* I2C3_SCL_M1 */ 795 RK_MUXROUTE_GRF(1, RK_PD6, 3, 0x10264, WRITE_MASK_VAL(5, 4, 2)), /* I2C3_SCL_M2 */ 796 797 RK_MUXROUTE_GRF(3, RK_PA0, 7, 0x10264, WRITE_MASK_VAL(6, 6, 0)), /* I2C4_SCL_M0 */ 798 RK_MUXROUTE_GRF(4, RK_PA0, 4, 0x10264, WRITE_MASK_VAL(6, 6, 1)), /* I2C4_SCL_M1 */ 799 800 RK_MUXROUTE_GRF(2, RK_PA5, 7, 0x10264, WRITE_MASK_VAL(9, 8, 0)), /* I2C5_SCL_M0 */ 801 RK_MUXROUTE_GRF(3, RK_PB0, 5, 0x10264, WRITE_MASK_VAL(9, 8, 1)), /* I2C5_SCL_M1 */ 802 RK_MUXROUTE_GRF(1, RK_PD0, 4, 0x10264, WRITE_MASK_VAL(9, 8, 2)), /* I2C5_SCL_M2 */ 803 804 RK_MUXROUTE_GRF(3, RK_PC0, 5, 0x10264, WRITE_MASK_VAL(11, 10, 0)), /* SPI1_CLK_M0 */ 805 RK_MUXROUTE_GRF(1, RK_PC6, 3, 0x10264, WRITE_MASK_VAL(11, 10, 1)), /* SPI1_CLK_M1 */ 806 RK_MUXROUTE_GRF(2, RK_PD5, 6, 0x10264, WRITE_MASK_VAL(11, 10, 2)), /* SPI1_CLK_M2 */ 807 808 RK_MUXROUTE_GRF(3, RK_PC0, 2, 0x10264, WRITE_MASK_VAL(12, 12, 0)), /* RGMII_CLK_M0 */ 809 RK_MUXROUTE_GRF(2, RK_PB7, 2, 0x10264, WRITE_MASK_VAL(12, 12, 1)), /* RGMII_CLK_M1 */ 810 811 RK_MUXROUTE_GRF(3, RK_PA1, 3, 0x10264, WRITE_MASK_VAL(13, 13, 0)), /* CAN_TXD_M0 */ 812 RK_MUXROUTE_GRF(3, RK_PA7, 5, 0x10264, WRITE_MASK_VAL(13, 13, 1)), /* CAN_TXD_M1 */ 813 814 RK_MUXROUTE_GRF(3, RK_PA4, 6, 0x10268, WRITE_MASK_VAL(0, 0, 0)), /* PWM8_M0 */ 815 RK_MUXROUTE_GRF(2, RK_PD7, 5, 0x10268, WRITE_MASK_VAL(0, 0, 1)), /* PWM8_M1 */ 816 817 RK_MUXROUTE_GRF(3, RK_PA5, 6, 0x10268, WRITE_MASK_VAL(2, 2, 0)), /* PWM9_M0 */ 818 RK_MUXROUTE_GRF(2, RK_PD6, 5, 0x10268, WRITE_MASK_VAL(2, 2, 1)), /* PWM9_M1 */ 819 820 RK_MUXROUTE_GRF(3, RK_PA6, 6, 0x10268, WRITE_MASK_VAL(4, 4, 0)), /* PWM10_M0 */ 821 RK_MUXROUTE_GRF(2, RK_PD5, 5, 0x10268, WRITE_MASK_VAL(4, 4, 1)), /* PWM10_M1 */ 822 823 RK_MUXROUTE_GRF(3, RK_PA7, 6, 0x10268, WRITE_MASK_VAL(6, 6, 0)), /* PWM11_IR_M0 */ 824 RK_MUXROUTE_GRF(3, RK_PA1, 5, 0x10268, WRITE_MASK_VAL(6, 6, 1)), /* PWM11_IR_M1 */ 825 826 RK_MUXROUTE_GRF(1, RK_PA5, 3, 0x10268, WRITE_MASK_VAL(8, 8, 0)), /* UART2_TX_M0 */ 827 RK_MUXROUTE_GRF(3, RK_PA2, 1, 0x10268, WRITE_MASK_VAL(8, 8, 1)), /* UART2_TX_M1 */ 828 829 RK_MUXROUTE_GRF(3, RK_PC6, 3, 0x10268, WRITE_MASK_VAL(11, 10, 0)), /* UART3_TX_M0 */ 830 RK_MUXROUTE_GRF(1, RK_PA7, 2, 0x10268, WRITE_MASK_VAL(11, 10, 1)), /* UART3_TX_M1 */ 831 RK_MUXROUTE_GRF(3, RK_PA0, 4, 0x10268, WRITE_MASK_VAL(11, 10, 2)), /* UART3_TX_M2 */ 832 833 RK_MUXROUTE_GRF(3, RK_PA4, 4, 0x10268, WRITE_MASK_VAL(13, 12, 0)), /* UART4_TX_M0 */ 834 RK_MUXROUTE_GRF(2, RK_PA6, 4, 0x10268, WRITE_MASK_VAL(13, 12, 1)), /* UART4_TX_M1 */ 835 RK_MUXROUTE_GRF(1, RK_PD5, 3, 0x10268, WRITE_MASK_VAL(13, 12, 2)), /* UART4_TX_M2 */ 836 837 RK_MUXROUTE_GRF(3, RK_PA6, 4, 0x10268, WRITE_MASK_VAL(15, 14, 0)), /* UART5_TX_M0 */ 838 RK_MUXROUTE_GRF(2, RK_PB0, 4, 0x10268, WRITE_MASK_VAL(15, 14, 1)), /* UART5_TX_M1 */ 839 RK_MUXROUTE_GRF(2, RK_PA0, 3, 0x10268, WRITE_MASK_VAL(15, 14, 2)), /* UART5_TX_M2 */ 840 841 RK_MUXROUTE_PMU(0, RK_PB6, 3, 0x0114, WRITE_MASK_VAL(0, 0, 0)), /* PWM0_M0 */ 842 RK_MUXROUTE_PMU(2, RK_PB3, 5, 0x0114, WRITE_MASK_VAL(0, 0, 1)), /* PWM0_M1 */ 843 844 RK_MUXROUTE_PMU(0, RK_PB7, 3, 0x0114, WRITE_MASK_VAL(2, 2, 0)), /* PWM1_M0 */ 845 RK_MUXROUTE_PMU(2, RK_PB2, 5, 0x0114, WRITE_MASK_VAL(2, 2, 1)), /* PWM1_M1 */ 846 847 RK_MUXROUTE_PMU(0, RK_PC0, 3, 0x0114, WRITE_MASK_VAL(4, 4, 0)), /* PWM2_M0 */ 848 RK_MUXROUTE_PMU(2, RK_PB1, 5, 0x0114, WRITE_MASK_VAL(4, 4, 1)), /* PWM2_M1 */ 849 850 RK_MUXROUTE_PMU(0, RK_PC1, 3, 0x0114, WRITE_MASK_VAL(6, 6, 0)), /* PWM3_IR_M0 */ 851 RK_MUXROUTE_PMU(2, RK_PB0, 5, 0x0114, WRITE_MASK_VAL(6, 6, 1)), /* PWM3_IR_M1 */ 852 853 RK_MUXROUTE_PMU(0, RK_PC2, 3, 0x0114, WRITE_MASK_VAL(8, 8, 0)), /* PWM4_M0 */ 854 RK_MUXROUTE_PMU(2, RK_PA7, 5, 0x0114, WRITE_MASK_VAL(8, 8, 1)), /* PWM4_M1 */ 855 856 RK_MUXROUTE_PMU(0, RK_PC3, 3, 0x0114, WRITE_MASK_VAL(10, 10, 0)), /* PWM5_M0 */ 857 RK_MUXROUTE_PMU(2, RK_PA6, 5, 0x0114, WRITE_MASK_VAL(10, 10, 1)), /* PWM5_M1 */ 858 859 RK_MUXROUTE_PMU(0, RK_PB2, 3, 0x0114, WRITE_MASK_VAL(12, 12, 0)), /* PWM6_M0 */ 860 RK_MUXROUTE_PMU(2, RK_PD4, 5, 0x0114, WRITE_MASK_VAL(12, 12, 1)), /* PWM6_M1 */ 861 862 RK_MUXROUTE_PMU(0, RK_PB1, 3, 0x0114, WRITE_MASK_VAL(14, 14, 0)), /* PWM7_IR_M0 */ 863 RK_MUXROUTE_PMU(3, RK_PA0, 5, 0x0114, WRITE_MASK_VAL(14, 14, 1)), /* PWM7_IR_M1 */ 864 865 RK_MUXROUTE_PMU(0, RK_PB0, 1, 0x0118, WRITE_MASK_VAL(1, 0, 0)), /* SPI0_CLK_M0 */ 866 RK_MUXROUTE_PMU(2, RK_PA1, 1, 0x0118, WRITE_MASK_VAL(1, 0, 1)), /* SPI0_CLK_M1 */ 867 RK_MUXROUTE_PMU(2, RK_PB2, 6, 0x0118, WRITE_MASK_VAL(1, 0, 2)), /* SPI0_CLK_M2 */ 868 869 RK_MUXROUTE_PMU(0, RK_PB6, 2, 0x0118, WRITE_MASK_VAL(2, 2, 0)), /* UART1_TX_M0 */ 870 RK_MUXROUTE_PMU(1, RK_PD0, 5, 0x0118, WRITE_MASK_VAL(2, 2, 1)), /* UART1_TX_M1 */ 871 }; 872 873 static struct rockchip_mux_route_data rk3128_mux_route_data[] = { 874 RK_MUXROUTE_SAME(1, RK_PB2, 1, 0x144, BIT(16 + 3) | BIT(16 + 4)), /* spi-0 */ 875 RK_MUXROUTE_SAME(1, RK_PD3, 3, 0x144, BIT(16 + 3) | BIT(16 + 4) | BIT(3)), /* spi-1 */ 876 RK_MUXROUTE_SAME(0, RK_PB5, 2, 0x144, BIT(16 + 3) | BIT(16 + 4) | BIT(4)), /* spi-2 */ 877 RK_MUXROUTE_SAME(1, RK_PA5, 1, 0x144, BIT(16 + 5)), /* i2s-0 */ 878 RK_MUXROUTE_SAME(0, RK_PB6, 1, 0x144, BIT(16 + 5) | BIT(5)), /* i2s-1 */ 879 RK_MUXROUTE_SAME(1, RK_PC6, 2, 0x144, BIT(16 + 6)), /* emmc-0 */ 880 RK_MUXROUTE_SAME(2, RK_PA4, 2, 0x144, BIT(16 + 6) | BIT(6)), /* emmc-1 */ 881 }; 882 883 static struct rockchip_mux_route_data rk3188_mux_route_data[] = { 884 RK_MUXROUTE_SAME(0, RK_PD0, 1, 0xa0, BIT(16 + 11)), /* non-iomuxed emmc/flash pins on flash-dqs */ 885 RK_MUXROUTE_SAME(0, RK_PD0, 2, 0xa0, BIT(16 + 11) | BIT(11)), /* non-iomuxed emmc/flash pins on emmc-clk */ 886 }; 887 888 static struct rockchip_mux_route_data rk3228_mux_route_data[] = { 889 RK_MUXROUTE_SAME(0, RK_PD2, 1, 0x50, BIT(16)), /* pwm0-0 */ 890 RK_MUXROUTE_SAME(3, RK_PC5, 1, 0x50, BIT(16) | BIT(0)), /* pwm0-1 */ 891 RK_MUXROUTE_SAME(0, RK_PD3, 1, 0x50, BIT(16 + 1)), /* pwm1-0 */ 892 RK_MUXROUTE_SAME(0, RK_PD6, 2, 0x50, BIT(16 + 1) | BIT(1)), /* pwm1-1 */ 893 RK_MUXROUTE_SAME(0, RK_PD4, 1, 0x50, BIT(16 + 2)), /* pwm2-0 */ 894 RK_MUXROUTE_SAME(1, RK_PB4, 2, 0x50, BIT(16 + 2) | BIT(2)), /* pwm2-1 */ 895 RK_MUXROUTE_SAME(3, RK_PD2, 1, 0x50, BIT(16 + 3)), /* pwm3-0 */ 896 RK_MUXROUTE_SAME(1, RK_PB3, 2, 0x50, BIT(16 + 3) | BIT(3)), /* pwm3-1 */ 897 RK_MUXROUTE_SAME(1, RK_PA1, 1, 0x50, BIT(16 + 4)), /* sdio-0_d0 */ 898 RK_MUXROUTE_SAME(3, RK_PA2, 1, 0x50, BIT(16 + 4) | BIT(4)), /* sdio-1_d0 */ 899 RK_MUXROUTE_SAME(0, RK_PB5, 2, 0x50, BIT(16 + 5)), /* spi-0_rx */ 900 RK_MUXROUTE_SAME(2, RK_PA0, 2, 0x50, BIT(16 + 5) | BIT(5)), /* spi-1_rx */ 901 RK_MUXROUTE_SAME(1, RK_PC6, 2, 0x50, BIT(16 + 7)), /* emmc-0_cmd */ 902 RK_MUXROUTE_SAME(2, RK_PA4, 2, 0x50, BIT(16 + 7) | BIT(7)), /* emmc-1_cmd */ 903 RK_MUXROUTE_SAME(1, RK_PC3, 2, 0x50, BIT(16 + 8)), /* uart2-0_rx */ 904 RK_MUXROUTE_SAME(1, RK_PB2, 2, 0x50, BIT(16 + 8) | BIT(8)), /* uart2-1_rx */ 905 RK_MUXROUTE_SAME(1, RK_PB2, 1, 0x50, BIT(16 + 11)), /* uart1-0_rx */ 906 RK_MUXROUTE_SAME(3, RK_PB5, 1, 0x50, BIT(16 + 11) | BIT(11)), /* uart1-1_rx */ 907 }; 908 909 static struct rockchip_mux_route_data rk3288_mux_route_data[] = { 910 RK_MUXROUTE_SAME(7, RK_PC0, 2, 0x264, BIT(16 + 12) | BIT(12)), /* edphdmi_cecinoutt1 */ 911 RK_MUXROUTE_SAME(7, RK_PC7, 4, 0x264, BIT(16 + 12)), /* edphdmi_cecinout */ 912 }; 913 914 static struct rockchip_mux_route_data rk3308_mux_route_data[] = { 915 RK_MUXROUTE_SAME(0, RK_PC3, 1, 0x314, BIT(16 + 0) | BIT(0)), /* rtc_clk */ 916 RK_MUXROUTE_SAME(1, RK_PC6, 2, 0x314, BIT(16 + 2) | BIT(16 + 3)), /* uart2_rxm0 */ 917 RK_MUXROUTE_SAME(4, RK_PD2, 2, 0x314, BIT(16 + 2) | BIT(16 + 3) | BIT(2)), /* uart2_rxm1 */ 918 RK_MUXROUTE_SAME(0, RK_PB7, 2, 0x608, BIT(16 + 8) | BIT(16 + 9)), /* i2c3_sdam0 */ 919 RK_MUXROUTE_SAME(3, RK_PB4, 2, 0x608, BIT(16 + 8) | BIT(16 + 9) | BIT(8)), /* i2c3_sdam1 */ 920 RK_MUXROUTE_SAME(2, RK_PA0, 3, 0x608, BIT(16 + 8) | BIT(16 + 9) | BIT(9)), /* i2c3_sdam2 */ 921 RK_MUXROUTE_SAME(1, RK_PA3, 2, 0x308, BIT(16 + 3)), /* i2s-8ch-1-sclktxm0 */ 922 RK_MUXROUTE_SAME(1, RK_PA4, 2, 0x308, BIT(16 + 3)), /* i2s-8ch-1-sclkrxm0 */ 923 RK_MUXROUTE_SAME(1, RK_PB5, 2, 0x308, BIT(16 + 3) | BIT(3)), /* i2s-8ch-1-sclktxm1 */ 924 RK_MUXROUTE_SAME(1, RK_PB6, 2, 0x308, BIT(16 + 3) | BIT(3)), /* i2s-8ch-1-sclkrxm1 */ 925 RK_MUXROUTE_SAME(1, RK_PA4, 3, 0x308, BIT(16 + 12) | BIT(16 + 13)), /* pdm-clkm0 */ 926 RK_MUXROUTE_SAME(1, RK_PB6, 4, 0x308, BIT(16 + 12) | BIT(16 + 13) | BIT(12)), /* pdm-clkm1 */ 927 RK_MUXROUTE_SAME(2, RK_PA6, 2, 0x308, BIT(16 + 12) | BIT(16 + 13) | BIT(13)), /* pdm-clkm2 */ 928 RK_MUXROUTE_SAME(2, RK_PA4, 3, 0x600, BIT(16 + 2) | BIT(2)), /* pdm-clkm-m2 */ 929 RK_MUXROUTE_SAME(3, RK_PB2, 3, 0x314, BIT(16 + 9)), /* spi1_miso */ 930 RK_MUXROUTE_SAME(2, RK_PA4, 2, 0x314, BIT(16 + 9) | BIT(9)), /* spi1_miso_m1 */ 931 RK_MUXROUTE_SAME(0, RK_PB3, 3, 0x314, BIT(16 + 10) | BIT(16 + 11)), /* owire_m0 */ 932 RK_MUXROUTE_SAME(1, RK_PC6, 7, 0x314, BIT(16 + 10) | BIT(16 + 11) | BIT(10)), /* owire_m1 */ 933 RK_MUXROUTE_SAME(2, RK_PA2, 5, 0x314, BIT(16 + 10) | BIT(16 + 11) | BIT(11)), /* owire_m2 */ 934 RK_MUXROUTE_SAME(0, RK_PB3, 2, 0x314, BIT(16 + 12) | BIT(16 + 13)), /* can_rxd_m0 */ 935 RK_MUXROUTE_SAME(1, RK_PC6, 5, 0x314, BIT(16 + 12) | BIT(16 + 13) | BIT(12)), /* can_rxd_m1 */ 936 RK_MUXROUTE_SAME(2, RK_PA2, 4, 0x314, BIT(16 + 12) | BIT(16 + 13) | BIT(13)), /* can_rxd_m2 */ 937 RK_MUXROUTE_SAME(1, RK_PC4, 3, 0x314, BIT(16 + 14)), /* mac_rxd0_m0 */ 938 RK_MUXROUTE_SAME(4, RK_PA2, 2, 0x314, BIT(16 + 14) | BIT(14)), /* mac_rxd0_m1 */ 939 RK_MUXROUTE_SAME(3, RK_PB4, 4, 0x314, BIT(16 + 15)), /* uart3_rx */ 940 RK_MUXROUTE_SAME(0, RK_PC1, 3, 0x314, BIT(16 + 15) | BIT(15)), /* uart3_rx_m1 */ 941 }; 942 943 static struct rockchip_mux_route_data rk3328_mux_route_data[] = { 944 RK_MUXROUTE_SAME(1, RK_PA1, 2, 0x50, BIT(16) | BIT(16 + 1)), /* uart2dbg_rxm0 */ 945 RK_MUXROUTE_SAME(2, RK_PA1, 1, 0x50, BIT(16) | BIT(16 + 1) | BIT(0)), /* uart2dbg_rxm1 */ 946 RK_MUXROUTE_SAME(1, RK_PB3, 2, 0x50, BIT(16 + 2) | BIT(2)), /* gmac-m1_rxd0 */ 947 RK_MUXROUTE_SAME(1, RK_PB6, 2, 0x50, BIT(16 + 10) | BIT(10)), /* gmac-m1-optimized_rxd3 */ 948 RK_MUXROUTE_SAME(2, RK_PC3, 2, 0x50, BIT(16 + 3)), /* pdm_sdi0m0 */ 949 RK_MUXROUTE_SAME(1, RK_PC7, 3, 0x50, BIT(16 + 3) | BIT(3)), /* pdm_sdi0m1 */ 950 RK_MUXROUTE_SAME(3, RK_PA2, 4, 0x50, BIT(16 + 4) | BIT(16 + 5) | BIT(5)), /* spi_rxdm2 */ 951 RK_MUXROUTE_SAME(1, RK_PD0, 1, 0x50, BIT(16 + 6)), /* i2s2_sdim0 */ 952 RK_MUXROUTE_SAME(3, RK_PA2, 6, 0x50, BIT(16 + 6) | BIT(6)), /* i2s2_sdim1 */ 953 RK_MUXROUTE_SAME(2, RK_PC6, 3, 0x50, BIT(16 + 7) | BIT(7)), /* card_iom1 */ 954 RK_MUXROUTE_SAME(2, RK_PC0, 3, 0x50, BIT(16 + 8) | BIT(8)), /* tsp_d5m1 */ 955 RK_MUXROUTE_SAME(2, RK_PC0, 4, 0x50, BIT(16 + 9) | BIT(9)), /* cif_data5m1 */ 956 }; 957 958 static struct rockchip_mux_route_data rk3399_mux_route_data[] = { 959 RK_MUXROUTE_SAME(4, RK_PB0, 2, 0xe21c, BIT(16 + 10) | BIT(16 + 11)), /* uart2dbga_rx */ 960 RK_MUXROUTE_SAME(4, RK_PC0, 2, 0xe21c, BIT(16 + 10) | BIT(16 + 11) | BIT(10)), /* uart2dbgb_rx */ 961 RK_MUXROUTE_SAME(4, RK_PC3, 1, 0xe21c, BIT(16 + 10) | BIT(16 + 11) | BIT(11)), /* uart2dbgc_rx */ 962 RK_MUXROUTE_SAME(2, RK_PD2, 2, 0xe21c, BIT(16 + 14)), /* pcie_clkreqn */ 963 RK_MUXROUTE_SAME(4, RK_PD0, 1, 0xe21c, BIT(16 + 14) | BIT(14)), /* pcie_clkreqnb */ 964 }; 965 966 static struct rockchip_mux_route_data rk3568_mux_route_data[] = { 967 RK_MUXROUTE_PMU(0, RK_PB7, 1, 0x0110, WRITE_MASK_VAL(1, 0, 0)), /* PWM0 IO mux M0 */ 968 RK_MUXROUTE_PMU(0, RK_PC7, 2, 0x0110, WRITE_MASK_VAL(1, 0, 1)), /* PWM0 IO mux M1 */ 969 RK_MUXROUTE_PMU(0, RK_PC0, 1, 0x0110, WRITE_MASK_VAL(3, 2, 0)), /* PWM1 IO mux M0 */ 970 RK_MUXROUTE_PMU(0, RK_PB5, 4, 0x0110, WRITE_MASK_VAL(3, 2, 1)), /* PWM1 IO mux M1 */ 971 RK_MUXROUTE_PMU(0, RK_PC1, 1, 0x0110, WRITE_MASK_VAL(5, 4, 0)), /* PWM2 IO mux M0 */ 972 RK_MUXROUTE_PMU(0, RK_PB6, 4, 0x0110, WRITE_MASK_VAL(5, 4, 1)), /* PWM2 IO mux M1 */ 973 RK_MUXROUTE_GRF(0, RK_PB3, 2, 0x0300, WRITE_MASK_VAL(0, 0, 0)), /* CAN0 IO mux M0 */ 974 RK_MUXROUTE_GRF(2, RK_PA1, 4, 0x0300, WRITE_MASK_VAL(0, 0, 1)), /* CAN0 IO mux M1 */ 975 RK_MUXROUTE_GRF(1, RK_PA1, 3, 0x0300, WRITE_MASK_VAL(2, 2, 0)), /* CAN1 IO mux M0 */ 976 RK_MUXROUTE_GRF(4, RK_PC3, 3, 0x0300, WRITE_MASK_VAL(2, 2, 1)), /* CAN1 IO mux M1 */ 977 RK_MUXROUTE_GRF(4, RK_PB5, 3, 0x0300, WRITE_MASK_VAL(4, 4, 0)), /* CAN2 IO mux M0 */ 978 RK_MUXROUTE_GRF(2, RK_PB2, 4, 0x0300, WRITE_MASK_VAL(4, 4, 1)), /* CAN2 IO mux M1 */ 979 RK_MUXROUTE_GRF(4, RK_PC4, 1, 0x0300, WRITE_MASK_VAL(6, 6, 0)), /* HPDIN IO mux M0 */ 980 RK_MUXROUTE_GRF(0, RK_PC2, 2, 0x0300, WRITE_MASK_VAL(6, 6, 1)), /* HPDIN IO mux M1 */ 981 RK_MUXROUTE_GRF(3, RK_PB1, 3, 0x0300, WRITE_MASK_VAL(8, 8, 0)), /* GMAC1 IO mux M0 */ 982 RK_MUXROUTE_GRF(4, RK_PA7, 3, 0x0300, WRITE_MASK_VAL(8, 8, 1)), /* GMAC1 IO mux M1 */ 983 RK_MUXROUTE_GRF(4, RK_PD1, 1, 0x0300, WRITE_MASK_VAL(10, 10, 0)), /* HDMITX IO mux M0 */ 984 RK_MUXROUTE_GRF(0, RK_PC7, 1, 0x0300, WRITE_MASK_VAL(10, 10, 1)), /* HDMITX IO mux M1 */ 985 RK_MUXROUTE_GRF(0, RK_PB6, 1, 0x0300, WRITE_MASK_VAL(14, 14, 0)), /* I2C2 IO mux M0 */ 986 RK_MUXROUTE_GRF(4, RK_PB4, 1, 0x0300, WRITE_MASK_VAL(14, 14, 1)), /* I2C2 IO mux M1 */ 987 RK_MUXROUTE_GRF(1, RK_PA0, 1, 0x0304, WRITE_MASK_VAL(0, 0, 0)), /* I2C3 IO mux M0 */ 988 RK_MUXROUTE_GRF(3, RK_PB6, 4, 0x0304, WRITE_MASK_VAL(0, 0, 1)), /* I2C3 IO mux M1 */ 989 RK_MUXROUTE_GRF(4, RK_PB2, 1, 0x0304, WRITE_MASK_VAL(2, 2, 0)), /* I2C4 IO mux M0 */ 990 RK_MUXROUTE_GRF(2, RK_PB1, 2, 0x0304, WRITE_MASK_VAL(2, 2, 1)), /* I2C4 IO mux M1 */ 991 RK_MUXROUTE_GRF(3, RK_PB4, 4, 0x0304, WRITE_MASK_VAL(4, 4, 0)), /* I2C5 IO mux M0 */ 992 RK_MUXROUTE_GRF(4, RK_PD0, 2, 0x0304, WRITE_MASK_VAL(4, 4, 1)), /* I2C5 IO mux M1 */ 993 RK_MUXROUTE_GRF(3, RK_PB1, 5, 0x0304, WRITE_MASK_VAL(14, 14, 0)), /* PWM8 IO mux M0 */ 994 RK_MUXROUTE_GRF(1, RK_PD5, 4, 0x0304, WRITE_MASK_VAL(14, 14, 1)), /* PWM8 IO mux M1 */ 995 RK_MUXROUTE_GRF(3, RK_PB2, 5, 0x0308, WRITE_MASK_VAL(0, 0, 0)), /* PWM9 IO mux M0 */ 996 RK_MUXROUTE_GRF(1, RK_PD6, 4, 0x0308, WRITE_MASK_VAL(0, 0, 1)), /* PWM9 IO mux M1 */ 997 RK_MUXROUTE_GRF(3, RK_PB5, 5, 0x0308, WRITE_MASK_VAL(2, 2, 0)), /* PWM10 IO mux M0 */ 998 RK_MUXROUTE_GRF(2, RK_PA1, 2, 0x0308, WRITE_MASK_VAL(2, 2, 1)), /* PWM10 IO mux M1 */ 999 RK_MUXROUTE_GRF(3, RK_PB6, 5, 0x0308, WRITE_MASK_VAL(4, 4, 0)), /* PWM11 IO mux M0 */ 1000 RK_MUXROUTE_GRF(4, RK_PC0, 3, 0x0308, WRITE_MASK_VAL(4, 4, 1)), /* PWM11 IO mux M1 */ 1001 RK_MUXROUTE_GRF(3, RK_PB7, 2, 0x0308, WRITE_MASK_VAL(6, 6, 0)), /* PWM12 IO mux M0 */ 1002 RK_MUXROUTE_GRF(4, RK_PC5, 1, 0x0308, WRITE_MASK_VAL(6, 6, 1)), /* PWM12 IO mux M1 */ 1003 RK_MUXROUTE_GRF(3, RK_PC0, 2, 0x0308, WRITE_MASK_VAL(8, 8, 0)), /* PWM13 IO mux M0 */ 1004 RK_MUXROUTE_GRF(4, RK_PC6, 1, 0x0308, WRITE_MASK_VAL(8, 8, 1)), /* PWM13 IO mux M1 */ 1005 RK_MUXROUTE_GRF(3, RK_PC4, 1, 0x0308, WRITE_MASK_VAL(10, 10, 0)), /* PWM14 IO mux M0 */ 1006 RK_MUXROUTE_GRF(4, RK_PC2, 1, 0x0308, WRITE_MASK_VAL(10, 10, 1)), /* PWM14 IO mux M1 */ 1007 RK_MUXROUTE_GRF(3, RK_PC5, 1, 0x0308, WRITE_MASK_VAL(12, 12, 0)), /* PWM15 IO mux M0 */ 1008 RK_MUXROUTE_GRF(4, RK_PC3, 1, 0x0308, WRITE_MASK_VAL(12, 12, 1)), /* PWM15 IO mux M1 */ 1009 RK_MUXROUTE_GRF(3, RK_PD2, 3, 0x0308, WRITE_MASK_VAL(14, 14, 0)), /* SDMMC2 IO mux M0 */ 1010 RK_MUXROUTE_GRF(3, RK_PA5, 5, 0x0308, WRITE_MASK_VAL(14, 14, 1)), /* SDMMC2 IO mux M1 */ 1011 RK_MUXROUTE_GRF(0, RK_PB5, 2, 0x030c, WRITE_MASK_VAL(0, 0, 0)), /* SPI0 IO mux M0 */ 1012 RK_MUXROUTE_GRF(2, RK_PD3, 3, 0x030c, WRITE_MASK_VAL(0, 0, 1)), /* SPI0 IO mux M1 */ 1013 RK_MUXROUTE_GRF(2, RK_PB5, 3, 0x030c, WRITE_MASK_VAL(2, 2, 0)), /* SPI1 IO mux M0 */ 1014 RK_MUXROUTE_GRF(3, RK_PC3, 3, 0x030c, WRITE_MASK_VAL(2, 2, 1)), /* SPI1 IO mux M1 */ 1015 RK_MUXROUTE_GRF(2, RK_PC1, 4, 0x030c, WRITE_MASK_VAL(4, 4, 0)), /* SPI2 IO mux M0 */ 1016 RK_MUXROUTE_GRF(3, RK_PA0, 3, 0x030c, WRITE_MASK_VAL(4, 4, 1)), /* SPI2 IO mux M1 */ 1017 RK_MUXROUTE_GRF(4, RK_PB3, 4, 0x030c, WRITE_MASK_VAL(6, 6, 0)), /* SPI3 IO mux M0 */ 1018 RK_MUXROUTE_GRF(4, RK_PC2, 2, 0x030c, WRITE_MASK_VAL(6, 6, 1)), /* SPI3 IO mux M1 */ 1019 RK_MUXROUTE_GRF(2, RK_PB4, 2, 0x030c, WRITE_MASK_VAL(8, 8, 0)), /* UART1 IO mux M0 */ 1020 RK_MUXROUTE_GRF(3, RK_PD6, 4, 0x030c, WRITE_MASK_VAL(8, 8, 1)), /* UART1 IO mux M1 */ 1021 RK_MUXROUTE_GRF(0, RK_PD1, 1, 0x030c, WRITE_MASK_VAL(10, 10, 0)), /* UART2 IO mux M0 */ 1022 RK_MUXROUTE_GRF(1, RK_PD5, 2, 0x030c, WRITE_MASK_VAL(10, 10, 1)), /* UART2 IO mux M1 */ 1023 RK_MUXROUTE_GRF(1, RK_PA1, 2, 0x030c, WRITE_MASK_VAL(12, 12, 0)), /* UART3 IO mux M0 */ 1024 RK_MUXROUTE_GRF(3, RK_PB7, 4, 0x030c, WRITE_MASK_VAL(12, 12, 1)), /* UART3 IO mux M1 */ 1025 RK_MUXROUTE_GRF(1, RK_PA6, 2, 0x030c, WRITE_MASK_VAL(14, 14, 0)), /* UART4 IO mux M0 */ 1026 RK_MUXROUTE_GRF(3, RK_PB2, 4, 0x030c, WRITE_MASK_VAL(14, 14, 1)), /* UART4 IO mux M1 */ 1027 RK_MUXROUTE_GRF(2, RK_PA2, 3, 0x0310, WRITE_MASK_VAL(0, 0, 0)), /* UART5 IO mux M0 */ 1028 RK_MUXROUTE_GRF(3, RK_PC2, 4, 0x0310, WRITE_MASK_VAL(0, 0, 1)), /* UART5 IO mux M1 */ 1029 RK_MUXROUTE_GRF(2, RK_PA4, 3, 0x0310, WRITE_MASK_VAL(2, 2, 0)), /* UART6 IO mux M0 */ 1030 RK_MUXROUTE_GRF(1, RK_PD5, 3, 0x0310, WRITE_MASK_VAL(2, 2, 1)), /* UART6 IO mux M1 */ 1031 RK_MUXROUTE_GRF(2, RK_PA6, 3, 0x0310, WRITE_MASK_VAL(5, 4, 0)), /* UART7 IO mux M0 */ 1032 RK_MUXROUTE_GRF(3, RK_PC4, 4, 0x0310, WRITE_MASK_VAL(5, 4, 1)), /* UART7 IO mux M1 */ 1033 RK_MUXROUTE_GRF(4, RK_PA2, 4, 0x0310, WRITE_MASK_VAL(5, 4, 2)), /* UART7 IO mux M2 */ 1034 RK_MUXROUTE_GRF(2, RK_PC5, 3, 0x0310, WRITE_MASK_VAL(6, 6, 0)), /* UART8 IO mux M0 */ 1035 RK_MUXROUTE_GRF(2, RK_PD7, 4, 0x0310, WRITE_MASK_VAL(6, 6, 1)), /* UART8 IO mux M1 */ 1036 RK_MUXROUTE_GRF(2, RK_PB0, 3, 0x0310, WRITE_MASK_VAL(9, 8, 0)), /* UART9 IO mux M0 */ 1037 RK_MUXROUTE_GRF(4, RK_PC5, 4, 0x0310, WRITE_MASK_VAL(9, 8, 1)), /* UART9 IO mux M1 */ 1038 RK_MUXROUTE_GRF(4, RK_PA4, 4, 0x0310, WRITE_MASK_VAL(9, 8, 2)), /* UART9 IO mux M2 */ 1039 RK_MUXROUTE_GRF(1, RK_PA2, 1, 0x0310, WRITE_MASK_VAL(11, 10, 0)), /* I2S1 IO mux M0 */ 1040 RK_MUXROUTE_GRF(3, RK_PC6, 4, 0x0310, WRITE_MASK_VAL(11, 10, 1)), /* I2S1 IO mux M1 */ 1041 RK_MUXROUTE_GRF(2, RK_PD0, 5, 0x0310, WRITE_MASK_VAL(11, 10, 2)), /* I2S1 IO mux M2 */ 1042 RK_MUXROUTE_GRF(2, RK_PC1, 1, 0x0310, WRITE_MASK_VAL(12, 12, 0)), /* I2S2 IO mux M0 */ 1043 RK_MUXROUTE_GRF(4, RK_PB6, 5, 0x0310, WRITE_MASK_VAL(12, 12, 1)), /* I2S2 IO mux M1 */ 1044 RK_MUXROUTE_GRF(3, RK_PA2, 4, 0x0310, WRITE_MASK_VAL(14, 14, 0)), /* I2S3 IO mux M0 */ 1045 RK_MUXROUTE_GRF(4, RK_PC2, 5, 0x0310, WRITE_MASK_VAL(14, 14, 1)), /* I2S3 IO mux M1 */ 1046 RK_MUXROUTE_GRF(1, RK_PA4, 3, 0x0314, WRITE_MASK_VAL(1, 0, 0)), /* PDM IO mux M0 */ 1047 RK_MUXROUTE_GRF(1, RK_PA6, 3, 0x0314, WRITE_MASK_VAL(1, 0, 0)), /* PDM IO mux M0 */ 1048 RK_MUXROUTE_GRF(3, RK_PD6, 5, 0x0314, WRITE_MASK_VAL(1, 0, 1)), /* PDM IO mux M1 */ 1049 RK_MUXROUTE_GRF(4, RK_PA0, 4, 0x0314, WRITE_MASK_VAL(1, 0, 1)), /* PDM IO mux M1 */ 1050 RK_MUXROUTE_GRF(3, RK_PC4, 5, 0x0314, WRITE_MASK_VAL(1, 0, 2)), /* PDM IO mux M2 */ 1051 RK_MUXROUTE_GRF(0, RK_PA5, 3, 0x0314, WRITE_MASK_VAL(3, 2, 0)), /* PCIE20 IO mux M0 */ 1052 RK_MUXROUTE_GRF(2, RK_PD0, 4, 0x0314, WRITE_MASK_VAL(3, 2, 1)), /* PCIE20 IO mux M1 */ 1053 RK_MUXROUTE_GRF(1, RK_PB0, 4, 0x0314, WRITE_MASK_VAL(3, 2, 2)), /* PCIE20 IO mux M2 */ 1054 RK_MUXROUTE_GRF(0, RK_PA4, 3, 0x0314, WRITE_MASK_VAL(5, 4, 0)), /* PCIE30X1 IO mux M0 */ 1055 RK_MUXROUTE_GRF(2, RK_PD2, 4, 0x0314, WRITE_MASK_VAL(5, 4, 1)), /* PCIE30X1 IO mux M1 */ 1056 RK_MUXROUTE_GRF(1, RK_PA5, 4, 0x0314, WRITE_MASK_VAL(5, 4, 2)), /* PCIE30X1 IO mux M2 */ 1057 RK_MUXROUTE_GRF(0, RK_PA6, 2, 0x0314, WRITE_MASK_VAL(7, 6, 0)), /* PCIE30X2 IO mux M0 */ 1058 RK_MUXROUTE_GRF(2, RK_PD4, 4, 0x0314, WRITE_MASK_VAL(7, 6, 1)), /* PCIE30X2 IO mux M1 */ 1059 RK_MUXROUTE_GRF(4, RK_PC2, 4, 0x0314, WRITE_MASK_VAL(7, 6, 2)), /* PCIE30X2 IO mux M2 */ 1060 }; 1061 1062 static bool rockchip_get_mux_route(struct rockchip_pin_bank *bank, int pin, 1063 int mux, u32 *loc, u32 *reg, u32 *value) 1064 { 1065 struct rockchip_pinctrl *info = bank->drvdata; 1066 struct rockchip_pin_ctrl *ctrl = info->ctrl; 1067 struct rockchip_mux_route_data *data; 1068 int i; 1069 1070 for (i = 0; i < ctrl->niomux_routes; i++) { 1071 data = &ctrl->iomux_routes[i]; 1072 if ((data->bank_num == bank->bank_num) && 1073 (data->pin == pin) && (data->func == mux)) 1074 break; 1075 } 1076 1077 if (i >= ctrl->niomux_routes) 1078 return false; 1079 1080 *loc = data->route_location; 1081 *reg = data->route_offset; 1082 *value = data->route_val; 1083 1084 return true; 1085 } 1086 1087 static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin) 1088 { 1089 struct rockchip_pinctrl *info = bank->drvdata; 1090 struct rockchip_pin_ctrl *ctrl = info->ctrl; 1091 int iomux_num = (pin / 8); 1092 struct regmap *regmap; 1093 unsigned int val; 1094 int reg, ret, mask, mux_type; 1095 u8 bit; 1096 1097 if (iomux_num > 3) 1098 return -EINVAL; 1099 1100 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) { 1101 dev_err(info->dev, "pin %d is unrouted\n", pin); 1102 return -EINVAL; 1103 } 1104 1105 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) 1106 return RK_FUNC_GPIO; 1107 1108 if (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU) 1109 regmap = info->regmap_pmu; 1110 else if (bank->iomux[iomux_num].type & IOMUX_L_SOURCE_PMU) 1111 regmap = (pin % 8 < 4) ? info->regmap_pmu : info->regmap_base; 1112 else 1113 regmap = info->regmap_base; 1114 1115 /* get basic quadrupel of mux registers and the correct reg inside */ 1116 mux_type = bank->iomux[iomux_num].type; 1117 reg = bank->iomux[iomux_num].offset; 1118 if (mux_type & IOMUX_WIDTH_4BIT) { 1119 if ((pin % 8) >= 4) 1120 reg += 0x4; 1121 bit = (pin % 4) * 4; 1122 mask = 0xf; 1123 } else if (mux_type & IOMUX_WIDTH_3BIT) { 1124 if ((pin % 8) >= 5) 1125 reg += 0x4; 1126 bit = (pin % 8 % 5) * 3; 1127 mask = 0x7; 1128 } else { 1129 bit = (pin % 8) * 2; 1130 mask = 0x3; 1131 } 1132 1133 if (bank->recalced_mask & BIT(pin)) 1134 rockchip_get_recalced_mux(bank, pin, ®, &bit, &mask); 1135 1136 if (ctrl->type == RK3588) { 1137 if (bank->bank_num == 0) { 1138 if ((pin >= RK_PB4) && (pin <= RK_PD7)) { 1139 u32 reg0 = 0; 1140 1141 reg0 = reg + 0x4000 - 0xC; /* PMU2_IOC_BASE */ 1142 ret = regmap_read(regmap, reg0, &val); 1143 if (ret) 1144 return ret; 1145 1146 if (!(val & BIT(8))) 1147 return ((val >> bit) & mask); 1148 1149 reg = reg + 0x8000; /* BUS_IOC_BASE */ 1150 regmap = info->regmap_base; 1151 } 1152 } else if (bank->bank_num > 0) { 1153 reg += 0x8000; /* BUS_IOC_BASE */ 1154 } 1155 } 1156 1157 ret = regmap_read(regmap, reg, &val); 1158 if (ret) 1159 return ret; 1160 1161 return ((val >> bit) & mask); 1162 } 1163 1164 static int rockchip_verify_mux(struct rockchip_pin_bank *bank, 1165 int pin, int mux) 1166 { 1167 struct rockchip_pinctrl *info = bank->drvdata; 1168 struct device *dev = info->dev; 1169 int iomux_num = (pin / 8); 1170 1171 if (iomux_num > 3) 1172 return -EINVAL; 1173 1174 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) { 1175 dev_err(dev, "pin %d is unrouted\n", pin); 1176 return -EINVAL; 1177 } 1178 1179 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) { 1180 if (mux != RK_FUNC_GPIO) { 1181 dev_err(dev, "pin %d only supports a gpio mux\n", pin); 1182 return -ENOTSUPP; 1183 } 1184 } 1185 1186 return 0; 1187 } 1188 1189 /* 1190 * Set a new mux function for a pin. 1191 * 1192 * The register is divided into the upper and lower 16 bit. When changing 1193 * a value, the previous register value is not read and changed. Instead 1194 * it seems the changed bits are marked in the upper 16 bit, while the 1195 * changed value gets set in the same offset in the lower 16 bit. 1196 * All pin settings seem to be 2 bit wide in both the upper and lower 1197 * parts. 1198 * @bank: pin bank to change 1199 * @pin: pin to change 1200 * @mux: new mux function to set 1201 */ 1202 static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux) 1203 { 1204 struct rockchip_pinctrl *info = bank->drvdata; 1205 struct rockchip_pin_ctrl *ctrl = info->ctrl; 1206 struct device *dev = info->dev; 1207 int iomux_num = (pin / 8); 1208 struct regmap *regmap; 1209 int reg, ret, mask, mux_type; 1210 u8 bit; 1211 u32 data, rmask, route_location, route_reg, route_val; 1212 1213 ret = rockchip_verify_mux(bank, pin, mux); 1214 if (ret < 0) 1215 return ret; 1216 1217 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) 1218 return 0; 1219 1220 dev_dbg(dev, "setting mux of GPIO%d-%d to %d\n", bank->bank_num, pin, mux); 1221 1222 if (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU) 1223 regmap = info->regmap_pmu; 1224 else if (bank->iomux[iomux_num].type & IOMUX_L_SOURCE_PMU) 1225 regmap = (pin % 8 < 4) ? info->regmap_pmu : info->regmap_base; 1226 else 1227 regmap = info->regmap_base; 1228 1229 /* get basic quadrupel of mux registers and the correct reg inside */ 1230 mux_type = bank->iomux[iomux_num].type; 1231 reg = bank->iomux[iomux_num].offset; 1232 if (mux_type & IOMUX_WIDTH_4BIT) { 1233 if ((pin % 8) >= 4) 1234 reg += 0x4; 1235 bit = (pin % 4) * 4; 1236 mask = 0xf; 1237 } else if (mux_type & IOMUX_WIDTH_3BIT) { 1238 if ((pin % 8) >= 5) 1239 reg += 0x4; 1240 bit = (pin % 8 % 5) * 3; 1241 mask = 0x7; 1242 } else { 1243 bit = (pin % 8) * 2; 1244 mask = 0x3; 1245 } 1246 1247 if (bank->recalced_mask & BIT(pin)) 1248 rockchip_get_recalced_mux(bank, pin, ®, &bit, &mask); 1249 1250 if (ctrl->type == RK3588) { 1251 if (bank->bank_num == 0) { 1252 if ((pin >= RK_PB4) && (pin <= RK_PD7)) { 1253 if (mux < 8) { 1254 reg += 0x4000 - 0xC; /* PMU2_IOC_BASE */ 1255 data = (mask << (bit + 16)); 1256 rmask = data | (data >> 16); 1257 data |= (mux & mask) << bit; 1258 ret = regmap_update_bits(regmap, reg, rmask, data); 1259 } else { 1260 u32 reg0 = 0; 1261 1262 reg0 = reg + 0x4000 - 0xC; /* PMU2_IOC_BASE */ 1263 data = (mask << (bit + 16)); 1264 rmask = data | (data >> 16); 1265 data |= 8 << bit; 1266 ret = regmap_update_bits(regmap, reg0, rmask, data); 1267 1268 reg0 = reg + 0x8000; /* BUS_IOC_BASE */ 1269 data = (mask << (bit + 16)); 1270 rmask = data | (data >> 16); 1271 data |= mux << bit; 1272 regmap = info->regmap_base; 1273 ret |= regmap_update_bits(regmap, reg0, rmask, data); 1274 } 1275 } else { 1276 data = (mask << (bit + 16)); 1277 rmask = data | (data >> 16); 1278 data |= (mux & mask) << bit; 1279 ret = regmap_update_bits(regmap, reg, rmask, data); 1280 } 1281 return ret; 1282 } else if (bank->bank_num > 0) { 1283 reg += 0x8000; /* BUS_IOC_BASE */ 1284 } 1285 } 1286 1287 if (mux > mask) 1288 return -EINVAL; 1289 1290 if (bank->route_mask & BIT(pin)) { 1291 if (rockchip_get_mux_route(bank, pin, mux, &route_location, 1292 &route_reg, &route_val)) { 1293 struct regmap *route_regmap = regmap; 1294 1295 /* handle special locations */ 1296 switch (route_location) { 1297 case ROCKCHIP_ROUTE_PMU: 1298 route_regmap = info->regmap_pmu; 1299 break; 1300 case ROCKCHIP_ROUTE_GRF: 1301 route_regmap = info->regmap_base; 1302 break; 1303 } 1304 1305 ret = regmap_write(route_regmap, route_reg, route_val); 1306 if (ret) 1307 return ret; 1308 } 1309 } 1310 1311 data = (mask << (bit + 16)); 1312 rmask = data | (data >> 16); 1313 data |= (mux & mask) << bit; 1314 ret = regmap_update_bits(regmap, reg, rmask, data); 1315 1316 return ret; 1317 } 1318 1319 #define PX30_PULL_PMU_OFFSET 0x10 1320 #define PX30_PULL_GRF_OFFSET 0x60 1321 #define PX30_PULL_BITS_PER_PIN 2 1322 #define PX30_PULL_PINS_PER_REG 8 1323 #define PX30_PULL_BANK_STRIDE 16 1324 1325 static int px30_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, 1326 int pin_num, struct regmap **regmap, 1327 int *reg, u8 *bit) 1328 { 1329 struct rockchip_pinctrl *info = bank->drvdata; 1330 1331 /* The first 32 pins of the first bank are located in PMU */ 1332 if (bank->bank_num == 0) { 1333 *regmap = info->regmap_pmu; 1334 *reg = PX30_PULL_PMU_OFFSET; 1335 } else { 1336 *regmap = info->regmap_base; 1337 *reg = PX30_PULL_GRF_OFFSET; 1338 1339 /* correct the offset, as we're starting with the 2nd bank */ 1340 *reg -= 0x10; 1341 *reg += bank->bank_num * PX30_PULL_BANK_STRIDE; 1342 } 1343 1344 *reg += ((pin_num / PX30_PULL_PINS_PER_REG) * 4); 1345 *bit = (pin_num % PX30_PULL_PINS_PER_REG); 1346 *bit *= PX30_PULL_BITS_PER_PIN; 1347 1348 return 0; 1349 } 1350 1351 #define PX30_DRV_PMU_OFFSET 0x20 1352 #define PX30_DRV_GRF_OFFSET 0xf0 1353 #define PX30_DRV_BITS_PER_PIN 2 1354 #define PX30_DRV_PINS_PER_REG 8 1355 #define PX30_DRV_BANK_STRIDE 16 1356 1357 static int px30_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank, 1358 int pin_num, struct regmap **regmap, 1359 int *reg, u8 *bit) 1360 { 1361 struct rockchip_pinctrl *info = bank->drvdata; 1362 1363 /* The first 32 pins of the first bank are located in PMU */ 1364 if (bank->bank_num == 0) { 1365 *regmap = info->regmap_pmu; 1366 *reg = PX30_DRV_PMU_OFFSET; 1367 } else { 1368 *regmap = info->regmap_base; 1369 *reg = PX30_DRV_GRF_OFFSET; 1370 1371 /* correct the offset, as we're starting with the 2nd bank */ 1372 *reg -= 0x10; 1373 *reg += bank->bank_num * PX30_DRV_BANK_STRIDE; 1374 } 1375 1376 *reg += ((pin_num / PX30_DRV_PINS_PER_REG) * 4); 1377 *bit = (pin_num % PX30_DRV_PINS_PER_REG); 1378 *bit *= PX30_DRV_BITS_PER_PIN; 1379 1380 return 0; 1381 } 1382 1383 #define PX30_SCHMITT_PMU_OFFSET 0x38 1384 #define PX30_SCHMITT_GRF_OFFSET 0xc0 1385 #define PX30_SCHMITT_PINS_PER_PMU_REG 16 1386 #define PX30_SCHMITT_BANK_STRIDE 16 1387 #define PX30_SCHMITT_PINS_PER_GRF_REG 8 1388 1389 static int px30_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank, 1390 int pin_num, 1391 struct regmap **regmap, 1392 int *reg, u8 *bit) 1393 { 1394 struct rockchip_pinctrl *info = bank->drvdata; 1395 int pins_per_reg; 1396 1397 if (bank->bank_num == 0) { 1398 *regmap = info->regmap_pmu; 1399 *reg = PX30_SCHMITT_PMU_OFFSET; 1400 pins_per_reg = PX30_SCHMITT_PINS_PER_PMU_REG; 1401 } else { 1402 *regmap = info->regmap_base; 1403 *reg = PX30_SCHMITT_GRF_OFFSET; 1404 pins_per_reg = PX30_SCHMITT_PINS_PER_GRF_REG; 1405 *reg += (bank->bank_num - 1) * PX30_SCHMITT_BANK_STRIDE; 1406 } 1407 1408 *reg += ((pin_num / pins_per_reg) * 4); 1409 *bit = pin_num % pins_per_reg; 1410 1411 return 0; 1412 } 1413 1414 #define RV1108_PULL_PMU_OFFSET 0x10 1415 #define RV1108_PULL_OFFSET 0x110 1416 #define RV1108_PULL_PINS_PER_REG 8 1417 #define RV1108_PULL_BITS_PER_PIN 2 1418 #define RV1108_PULL_BANK_STRIDE 16 1419 1420 static int rv1108_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, 1421 int pin_num, struct regmap **regmap, 1422 int *reg, u8 *bit) 1423 { 1424 struct rockchip_pinctrl *info = bank->drvdata; 1425 1426 /* The first 24 pins of the first bank are located in PMU */ 1427 if (bank->bank_num == 0) { 1428 *regmap = info->regmap_pmu; 1429 *reg = RV1108_PULL_PMU_OFFSET; 1430 } else { 1431 *reg = RV1108_PULL_OFFSET; 1432 *regmap = info->regmap_base; 1433 /* correct the offset, as we're starting with the 2nd bank */ 1434 *reg -= 0x10; 1435 *reg += bank->bank_num * RV1108_PULL_BANK_STRIDE; 1436 } 1437 1438 *reg += ((pin_num / RV1108_PULL_PINS_PER_REG) * 4); 1439 *bit = (pin_num % RV1108_PULL_PINS_PER_REG); 1440 *bit *= RV1108_PULL_BITS_PER_PIN; 1441 1442 return 0; 1443 } 1444 1445 #define RV1108_DRV_PMU_OFFSET 0x20 1446 #define RV1108_DRV_GRF_OFFSET 0x210 1447 #define RV1108_DRV_BITS_PER_PIN 2 1448 #define RV1108_DRV_PINS_PER_REG 8 1449 #define RV1108_DRV_BANK_STRIDE 16 1450 1451 static int rv1108_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank, 1452 int pin_num, struct regmap **regmap, 1453 int *reg, u8 *bit) 1454 { 1455 struct rockchip_pinctrl *info = bank->drvdata; 1456 1457 /* The first 24 pins of the first bank are located in PMU */ 1458 if (bank->bank_num == 0) { 1459 *regmap = info->regmap_pmu; 1460 *reg = RV1108_DRV_PMU_OFFSET; 1461 } else { 1462 *regmap = info->regmap_base; 1463 *reg = RV1108_DRV_GRF_OFFSET; 1464 1465 /* correct the offset, as we're starting with the 2nd bank */ 1466 *reg -= 0x10; 1467 *reg += bank->bank_num * RV1108_DRV_BANK_STRIDE; 1468 } 1469 1470 *reg += ((pin_num / RV1108_DRV_PINS_PER_REG) * 4); 1471 *bit = pin_num % RV1108_DRV_PINS_PER_REG; 1472 *bit *= RV1108_DRV_BITS_PER_PIN; 1473 1474 return 0; 1475 } 1476 1477 #define RV1108_SCHMITT_PMU_OFFSET 0x30 1478 #define RV1108_SCHMITT_GRF_OFFSET 0x388 1479 #define RV1108_SCHMITT_BANK_STRIDE 8 1480 #define RV1108_SCHMITT_PINS_PER_GRF_REG 16 1481 #define RV1108_SCHMITT_PINS_PER_PMU_REG 8 1482 1483 static int rv1108_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank, 1484 int pin_num, 1485 struct regmap **regmap, 1486 int *reg, u8 *bit) 1487 { 1488 struct rockchip_pinctrl *info = bank->drvdata; 1489 int pins_per_reg; 1490 1491 if (bank->bank_num == 0) { 1492 *regmap = info->regmap_pmu; 1493 *reg = RV1108_SCHMITT_PMU_OFFSET; 1494 pins_per_reg = RV1108_SCHMITT_PINS_PER_PMU_REG; 1495 } else { 1496 *regmap = info->regmap_base; 1497 *reg = RV1108_SCHMITT_GRF_OFFSET; 1498 pins_per_reg = RV1108_SCHMITT_PINS_PER_GRF_REG; 1499 *reg += (bank->bank_num - 1) * RV1108_SCHMITT_BANK_STRIDE; 1500 } 1501 *reg += ((pin_num / pins_per_reg) * 4); 1502 *bit = pin_num % pins_per_reg; 1503 1504 return 0; 1505 } 1506 1507 #define RV1126_PULL_PMU_OFFSET 0x40 1508 #define RV1126_PULL_GRF_GPIO1A0_OFFSET 0x10108 1509 #define RV1126_PULL_PINS_PER_REG 8 1510 #define RV1126_PULL_BITS_PER_PIN 2 1511 #define RV1126_PULL_BANK_STRIDE 16 1512 #define RV1126_GPIO_C4_D7(p) (p >= 20 && p <= 31) /* GPIO0_C4 ~ GPIO0_D7 */ 1513 1514 static int rv1126_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, 1515 int pin_num, struct regmap **regmap, 1516 int *reg, u8 *bit) 1517 { 1518 struct rockchip_pinctrl *info = bank->drvdata; 1519 1520 /* The first 24 pins of the first bank are located in PMU */ 1521 if (bank->bank_num == 0) { 1522 if (RV1126_GPIO_C4_D7(pin_num)) { 1523 *regmap = info->regmap_base; 1524 *reg = RV1126_PULL_GRF_GPIO1A0_OFFSET; 1525 *reg -= (((31 - pin_num) / RV1126_PULL_PINS_PER_REG + 1) * 4); 1526 *bit = pin_num % RV1126_PULL_PINS_PER_REG; 1527 *bit *= RV1126_PULL_BITS_PER_PIN; 1528 return 0; 1529 } 1530 *regmap = info->regmap_pmu; 1531 *reg = RV1126_PULL_PMU_OFFSET; 1532 } else { 1533 *reg = RV1126_PULL_GRF_GPIO1A0_OFFSET; 1534 *regmap = info->regmap_base; 1535 *reg += (bank->bank_num - 1) * RV1126_PULL_BANK_STRIDE; 1536 } 1537 1538 *reg += ((pin_num / RV1126_PULL_PINS_PER_REG) * 4); 1539 *bit = (pin_num % RV1126_PULL_PINS_PER_REG); 1540 *bit *= RV1126_PULL_BITS_PER_PIN; 1541 1542 return 0; 1543 } 1544 1545 #define RV1126_DRV_PMU_OFFSET 0x20 1546 #define RV1126_DRV_GRF_GPIO1A0_OFFSET 0x10090 1547 #define RV1126_DRV_BITS_PER_PIN 4 1548 #define RV1126_DRV_PINS_PER_REG 4 1549 #define RV1126_DRV_BANK_STRIDE 32 1550 1551 static int rv1126_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank, 1552 int pin_num, struct regmap **regmap, 1553 int *reg, u8 *bit) 1554 { 1555 struct rockchip_pinctrl *info = bank->drvdata; 1556 1557 /* The first 24 pins of the first bank are located in PMU */ 1558 if (bank->bank_num == 0) { 1559 if (RV1126_GPIO_C4_D7(pin_num)) { 1560 *regmap = info->regmap_base; 1561 *reg = RV1126_DRV_GRF_GPIO1A0_OFFSET; 1562 *reg -= (((31 - pin_num) / RV1126_DRV_PINS_PER_REG + 1) * 4); 1563 *reg -= 0x4; 1564 *bit = pin_num % RV1126_DRV_PINS_PER_REG; 1565 *bit *= RV1126_DRV_BITS_PER_PIN; 1566 return 0; 1567 } 1568 *regmap = info->regmap_pmu; 1569 *reg = RV1126_DRV_PMU_OFFSET; 1570 } else { 1571 *regmap = info->regmap_base; 1572 *reg = RV1126_DRV_GRF_GPIO1A0_OFFSET; 1573 *reg += (bank->bank_num - 1) * RV1126_DRV_BANK_STRIDE; 1574 } 1575 1576 *reg += ((pin_num / RV1126_DRV_PINS_PER_REG) * 4); 1577 *bit = pin_num % RV1126_DRV_PINS_PER_REG; 1578 *bit *= RV1126_DRV_BITS_PER_PIN; 1579 1580 return 0; 1581 } 1582 1583 #define RV1126_SCHMITT_PMU_OFFSET 0x60 1584 #define RV1126_SCHMITT_GRF_GPIO1A0_OFFSET 0x10188 1585 #define RV1126_SCHMITT_BANK_STRIDE 16 1586 #define RV1126_SCHMITT_PINS_PER_GRF_REG 8 1587 #define RV1126_SCHMITT_PINS_PER_PMU_REG 8 1588 1589 static int rv1126_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank, 1590 int pin_num, 1591 struct regmap **regmap, 1592 int *reg, u8 *bit) 1593 { 1594 struct rockchip_pinctrl *info = bank->drvdata; 1595 int pins_per_reg; 1596 1597 if (bank->bank_num == 0) { 1598 if (RV1126_GPIO_C4_D7(pin_num)) { 1599 *regmap = info->regmap_base; 1600 *reg = RV1126_SCHMITT_GRF_GPIO1A0_OFFSET; 1601 *reg -= (((31 - pin_num) / RV1126_SCHMITT_PINS_PER_GRF_REG + 1) * 4); 1602 *bit = pin_num % RV1126_SCHMITT_PINS_PER_GRF_REG; 1603 return 0; 1604 } 1605 *regmap = info->regmap_pmu; 1606 *reg = RV1126_SCHMITT_PMU_OFFSET; 1607 pins_per_reg = RV1126_SCHMITT_PINS_PER_PMU_REG; 1608 } else { 1609 *regmap = info->regmap_base; 1610 *reg = RV1126_SCHMITT_GRF_GPIO1A0_OFFSET; 1611 pins_per_reg = RV1126_SCHMITT_PINS_PER_GRF_REG; 1612 *reg += (bank->bank_num - 1) * RV1126_SCHMITT_BANK_STRIDE; 1613 } 1614 *reg += ((pin_num / pins_per_reg) * 4); 1615 *bit = pin_num % pins_per_reg; 1616 1617 return 0; 1618 } 1619 1620 #define RK3308_SCHMITT_PINS_PER_REG 8 1621 #define RK3308_SCHMITT_BANK_STRIDE 16 1622 #define RK3308_SCHMITT_GRF_OFFSET 0x1a0 1623 1624 static int rk3308_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank, 1625 int pin_num, struct regmap **regmap, 1626 int *reg, u8 *bit) 1627 { 1628 struct rockchip_pinctrl *info = bank->drvdata; 1629 1630 *regmap = info->regmap_base; 1631 *reg = RK3308_SCHMITT_GRF_OFFSET; 1632 1633 *reg += bank->bank_num * RK3308_SCHMITT_BANK_STRIDE; 1634 *reg += ((pin_num / RK3308_SCHMITT_PINS_PER_REG) * 4); 1635 *bit = pin_num % RK3308_SCHMITT_PINS_PER_REG; 1636 1637 return 0; 1638 } 1639 1640 #define RK2928_PULL_OFFSET 0x118 1641 #define RK2928_PULL_PINS_PER_REG 16 1642 #define RK2928_PULL_BANK_STRIDE 8 1643 1644 static int rk2928_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, 1645 int pin_num, struct regmap **regmap, 1646 int *reg, u8 *bit) 1647 { 1648 struct rockchip_pinctrl *info = bank->drvdata; 1649 1650 *regmap = info->regmap_base; 1651 *reg = RK2928_PULL_OFFSET; 1652 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE; 1653 *reg += (pin_num / RK2928_PULL_PINS_PER_REG) * 4; 1654 1655 *bit = pin_num % RK2928_PULL_PINS_PER_REG; 1656 1657 return 0; 1658 }; 1659 1660 #define RK3128_PULL_OFFSET 0x118 1661 1662 static int rk3128_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, 1663 int pin_num, struct regmap **regmap, 1664 int *reg, u8 *bit) 1665 { 1666 struct rockchip_pinctrl *info = bank->drvdata; 1667 1668 *regmap = info->regmap_base; 1669 *reg = RK3128_PULL_OFFSET; 1670 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE; 1671 *reg += ((pin_num / RK2928_PULL_PINS_PER_REG) * 4); 1672 1673 *bit = pin_num % RK2928_PULL_PINS_PER_REG; 1674 1675 return 0; 1676 } 1677 1678 #define RK3188_PULL_OFFSET 0x164 1679 #define RK3188_PULL_BITS_PER_PIN 2 1680 #define RK3188_PULL_PINS_PER_REG 8 1681 #define RK3188_PULL_BANK_STRIDE 16 1682 #define RK3188_PULL_PMU_OFFSET 0x64 1683 1684 static int rk3188_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, 1685 int pin_num, struct regmap **regmap, 1686 int *reg, u8 *bit) 1687 { 1688 struct rockchip_pinctrl *info = bank->drvdata; 1689 1690 /* The first 12 pins of the first bank are located elsewhere */ 1691 if (bank->bank_num == 0 && pin_num < 12) { 1692 *regmap = info->regmap_pmu ? info->regmap_pmu 1693 : bank->regmap_pull; 1694 *reg = info->regmap_pmu ? RK3188_PULL_PMU_OFFSET : 0; 1695 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4); 1696 *bit = pin_num % RK3188_PULL_PINS_PER_REG; 1697 *bit *= RK3188_PULL_BITS_PER_PIN; 1698 } else { 1699 *regmap = info->regmap_pull ? info->regmap_pull 1700 : info->regmap_base; 1701 *reg = info->regmap_pull ? 0 : RK3188_PULL_OFFSET; 1702 1703 /* correct the offset, as it is the 2nd pull register */ 1704 *reg -= 4; 1705 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE; 1706 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4); 1707 1708 /* 1709 * The bits in these registers have an inverse ordering 1710 * with the lowest pin being in bits 15:14 and the highest 1711 * pin in bits 1:0 1712 */ 1713 *bit = 7 - (pin_num % RK3188_PULL_PINS_PER_REG); 1714 *bit *= RK3188_PULL_BITS_PER_PIN; 1715 } 1716 1717 return 0; 1718 } 1719 1720 #define RK3288_PULL_OFFSET 0x140 1721 static int rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, 1722 int pin_num, struct regmap **regmap, 1723 int *reg, u8 *bit) 1724 { 1725 struct rockchip_pinctrl *info = bank->drvdata; 1726 1727 /* The first 24 pins of the first bank are located in PMU */ 1728 if (bank->bank_num == 0) { 1729 *regmap = info->regmap_pmu; 1730 *reg = RK3188_PULL_PMU_OFFSET; 1731 1732 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4); 1733 *bit = pin_num % RK3188_PULL_PINS_PER_REG; 1734 *bit *= RK3188_PULL_BITS_PER_PIN; 1735 } else { 1736 *regmap = info->regmap_base; 1737 *reg = RK3288_PULL_OFFSET; 1738 1739 /* correct the offset, as we're starting with the 2nd bank */ 1740 *reg -= 0x10; 1741 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE; 1742 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4); 1743 1744 *bit = (pin_num % RK3188_PULL_PINS_PER_REG); 1745 *bit *= RK3188_PULL_BITS_PER_PIN; 1746 } 1747 1748 return 0; 1749 } 1750 1751 #define RK3288_DRV_PMU_OFFSET 0x70 1752 #define RK3288_DRV_GRF_OFFSET 0x1c0 1753 #define RK3288_DRV_BITS_PER_PIN 2 1754 #define RK3288_DRV_PINS_PER_REG 8 1755 #define RK3288_DRV_BANK_STRIDE 16 1756 1757 static int rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank, 1758 int pin_num, struct regmap **regmap, 1759 int *reg, u8 *bit) 1760 { 1761 struct rockchip_pinctrl *info = bank->drvdata; 1762 1763 /* The first 24 pins of the first bank are located in PMU */ 1764 if (bank->bank_num == 0) { 1765 *regmap = info->regmap_pmu; 1766 *reg = RK3288_DRV_PMU_OFFSET; 1767 1768 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4); 1769 *bit = pin_num % RK3288_DRV_PINS_PER_REG; 1770 *bit *= RK3288_DRV_BITS_PER_PIN; 1771 } else { 1772 *regmap = info->regmap_base; 1773 *reg = RK3288_DRV_GRF_OFFSET; 1774 1775 /* correct the offset, as we're starting with the 2nd bank */ 1776 *reg -= 0x10; 1777 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE; 1778 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4); 1779 1780 *bit = (pin_num % RK3288_DRV_PINS_PER_REG); 1781 *bit *= RK3288_DRV_BITS_PER_PIN; 1782 } 1783 1784 return 0; 1785 } 1786 1787 #define RK3228_PULL_OFFSET 0x100 1788 1789 static int rk3228_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, 1790 int pin_num, struct regmap **regmap, 1791 int *reg, u8 *bit) 1792 { 1793 struct rockchip_pinctrl *info = bank->drvdata; 1794 1795 *regmap = info->regmap_base; 1796 *reg = RK3228_PULL_OFFSET; 1797 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE; 1798 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4); 1799 1800 *bit = (pin_num % RK3188_PULL_PINS_PER_REG); 1801 *bit *= RK3188_PULL_BITS_PER_PIN; 1802 1803 return 0; 1804 } 1805 1806 #define RK3228_DRV_GRF_OFFSET 0x200 1807 1808 static int rk3228_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank, 1809 int pin_num, struct regmap **regmap, 1810 int *reg, u8 *bit) 1811 { 1812 struct rockchip_pinctrl *info = bank->drvdata; 1813 1814 *regmap = info->regmap_base; 1815 *reg = RK3228_DRV_GRF_OFFSET; 1816 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE; 1817 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4); 1818 1819 *bit = (pin_num % RK3288_DRV_PINS_PER_REG); 1820 *bit *= RK3288_DRV_BITS_PER_PIN; 1821 1822 return 0; 1823 } 1824 1825 #define RK3308_PULL_OFFSET 0xa0 1826 1827 static int rk3308_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, 1828 int pin_num, struct regmap **regmap, 1829 int *reg, u8 *bit) 1830 { 1831 struct rockchip_pinctrl *info = bank->drvdata; 1832 1833 *regmap = info->regmap_base; 1834 *reg = RK3308_PULL_OFFSET; 1835 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE; 1836 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4); 1837 1838 *bit = (pin_num % RK3188_PULL_PINS_PER_REG); 1839 *bit *= RK3188_PULL_BITS_PER_PIN; 1840 1841 return 0; 1842 } 1843 1844 #define RK3308_DRV_GRF_OFFSET 0x100 1845 1846 static int rk3308_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank, 1847 int pin_num, struct regmap **regmap, 1848 int *reg, u8 *bit) 1849 { 1850 struct rockchip_pinctrl *info = bank->drvdata; 1851 1852 *regmap = info->regmap_base; 1853 *reg = RK3308_DRV_GRF_OFFSET; 1854 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE; 1855 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4); 1856 1857 *bit = (pin_num % RK3288_DRV_PINS_PER_REG); 1858 *bit *= RK3288_DRV_BITS_PER_PIN; 1859 1860 return 0; 1861 } 1862 1863 #define RK3368_PULL_GRF_OFFSET 0x100 1864 #define RK3368_PULL_PMU_OFFSET 0x10 1865 1866 static int rk3368_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, 1867 int pin_num, struct regmap **regmap, 1868 int *reg, u8 *bit) 1869 { 1870 struct rockchip_pinctrl *info = bank->drvdata; 1871 1872 /* The first 32 pins of the first bank are located in PMU */ 1873 if (bank->bank_num == 0) { 1874 *regmap = info->regmap_pmu; 1875 *reg = RK3368_PULL_PMU_OFFSET; 1876 1877 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4); 1878 *bit = pin_num % RK3188_PULL_PINS_PER_REG; 1879 *bit *= RK3188_PULL_BITS_PER_PIN; 1880 } else { 1881 *regmap = info->regmap_base; 1882 *reg = RK3368_PULL_GRF_OFFSET; 1883 1884 /* correct the offset, as we're starting with the 2nd bank */ 1885 *reg -= 0x10; 1886 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE; 1887 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4); 1888 1889 *bit = (pin_num % RK3188_PULL_PINS_PER_REG); 1890 *bit *= RK3188_PULL_BITS_PER_PIN; 1891 } 1892 1893 return 0; 1894 } 1895 1896 #define RK3368_DRV_PMU_OFFSET 0x20 1897 #define RK3368_DRV_GRF_OFFSET 0x200 1898 1899 static int rk3368_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank, 1900 int pin_num, struct regmap **regmap, 1901 int *reg, u8 *bit) 1902 { 1903 struct rockchip_pinctrl *info = bank->drvdata; 1904 1905 /* The first 32 pins of the first bank are located in PMU */ 1906 if (bank->bank_num == 0) { 1907 *regmap = info->regmap_pmu; 1908 *reg = RK3368_DRV_PMU_OFFSET; 1909 1910 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4); 1911 *bit = pin_num % RK3288_DRV_PINS_PER_REG; 1912 *bit *= RK3288_DRV_BITS_PER_PIN; 1913 } else { 1914 *regmap = info->regmap_base; 1915 *reg = RK3368_DRV_GRF_OFFSET; 1916 1917 /* correct the offset, as we're starting with the 2nd bank */ 1918 *reg -= 0x10; 1919 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE; 1920 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4); 1921 1922 *bit = (pin_num % RK3288_DRV_PINS_PER_REG); 1923 *bit *= RK3288_DRV_BITS_PER_PIN; 1924 } 1925 1926 return 0; 1927 } 1928 1929 #define RK3399_PULL_GRF_OFFSET 0xe040 1930 #define RK3399_PULL_PMU_OFFSET 0x40 1931 #define RK3399_DRV_3BITS_PER_PIN 3 1932 1933 static int rk3399_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, 1934 int pin_num, struct regmap **regmap, 1935 int *reg, u8 *bit) 1936 { 1937 struct rockchip_pinctrl *info = bank->drvdata; 1938 1939 /* The bank0:16 and bank1:32 pins are located in PMU */ 1940 if ((bank->bank_num == 0) || (bank->bank_num == 1)) { 1941 *regmap = info->regmap_pmu; 1942 *reg = RK3399_PULL_PMU_OFFSET; 1943 1944 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE; 1945 1946 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4); 1947 *bit = pin_num % RK3188_PULL_PINS_PER_REG; 1948 *bit *= RK3188_PULL_BITS_PER_PIN; 1949 } else { 1950 *regmap = info->regmap_base; 1951 *reg = RK3399_PULL_GRF_OFFSET; 1952 1953 /* correct the offset, as we're starting with the 3rd bank */ 1954 *reg -= 0x20; 1955 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE; 1956 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4); 1957 1958 *bit = (pin_num % RK3188_PULL_PINS_PER_REG); 1959 *bit *= RK3188_PULL_BITS_PER_PIN; 1960 } 1961 1962 return 0; 1963 } 1964 1965 static int rk3399_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank, 1966 int pin_num, struct regmap **regmap, 1967 int *reg, u8 *bit) 1968 { 1969 struct rockchip_pinctrl *info = bank->drvdata; 1970 int drv_num = (pin_num / 8); 1971 1972 /* The bank0:16 and bank1:32 pins are located in PMU */ 1973 if ((bank->bank_num == 0) || (bank->bank_num == 1)) 1974 *regmap = info->regmap_pmu; 1975 else 1976 *regmap = info->regmap_base; 1977 1978 *reg = bank->drv[drv_num].offset; 1979 if ((bank->drv[drv_num].drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) || 1980 (bank->drv[drv_num].drv_type == DRV_TYPE_IO_3V3_ONLY)) 1981 *bit = (pin_num % 8) * 3; 1982 else 1983 *bit = (pin_num % 8) * 2; 1984 1985 return 0; 1986 } 1987 1988 #define RK3568_PULL_PMU_OFFSET 0x20 1989 #define RK3568_PULL_GRF_OFFSET 0x80 1990 #define RK3568_PULL_BITS_PER_PIN 2 1991 #define RK3568_PULL_PINS_PER_REG 8 1992 #define RK3568_PULL_BANK_STRIDE 0x10 1993 1994 static int rk3568_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, 1995 int pin_num, struct regmap **regmap, 1996 int *reg, u8 *bit) 1997 { 1998 struct rockchip_pinctrl *info = bank->drvdata; 1999 2000 if (bank->bank_num == 0) { 2001 *regmap = info->regmap_pmu; 2002 *reg = RK3568_PULL_PMU_OFFSET; 2003 *reg += bank->bank_num * RK3568_PULL_BANK_STRIDE; 2004 *reg += ((pin_num / RK3568_PULL_PINS_PER_REG) * 4); 2005 2006 *bit = pin_num % RK3568_PULL_PINS_PER_REG; 2007 *bit *= RK3568_PULL_BITS_PER_PIN; 2008 } else { 2009 *regmap = info->regmap_base; 2010 *reg = RK3568_PULL_GRF_OFFSET; 2011 *reg += (bank->bank_num - 1) * RK3568_PULL_BANK_STRIDE; 2012 *reg += ((pin_num / RK3568_PULL_PINS_PER_REG) * 4); 2013 2014 *bit = (pin_num % RK3568_PULL_PINS_PER_REG); 2015 *bit *= RK3568_PULL_BITS_PER_PIN; 2016 } 2017 2018 return 0; 2019 } 2020 2021 #define RK3568_DRV_PMU_OFFSET 0x70 2022 #define RK3568_DRV_GRF_OFFSET 0x200 2023 #define RK3568_DRV_BITS_PER_PIN 8 2024 #define RK3568_DRV_PINS_PER_REG 2 2025 #define RK3568_DRV_BANK_STRIDE 0x40 2026 2027 static int rk3568_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank, 2028 int pin_num, struct regmap **regmap, 2029 int *reg, u8 *bit) 2030 { 2031 struct rockchip_pinctrl *info = bank->drvdata; 2032 2033 /* The first 32 pins of the first bank are located in PMU */ 2034 if (bank->bank_num == 0) { 2035 *regmap = info->regmap_pmu; 2036 *reg = RK3568_DRV_PMU_OFFSET; 2037 *reg += ((pin_num / RK3568_DRV_PINS_PER_REG) * 4); 2038 2039 *bit = pin_num % RK3568_DRV_PINS_PER_REG; 2040 *bit *= RK3568_DRV_BITS_PER_PIN; 2041 } else { 2042 *regmap = info->regmap_base; 2043 *reg = RK3568_DRV_GRF_OFFSET; 2044 *reg += (bank->bank_num - 1) * RK3568_DRV_BANK_STRIDE; 2045 *reg += ((pin_num / RK3568_DRV_PINS_PER_REG) * 4); 2046 2047 *bit = (pin_num % RK3568_DRV_PINS_PER_REG); 2048 *bit *= RK3568_DRV_BITS_PER_PIN; 2049 } 2050 2051 return 0; 2052 } 2053 2054 #define RK3588_PMU1_IOC_REG (0x0000) 2055 #define RK3588_PMU2_IOC_REG (0x4000) 2056 #define RK3588_BUS_IOC_REG (0x8000) 2057 #define RK3588_VCCIO1_4_IOC_REG (0x9000) 2058 #define RK3588_VCCIO3_5_IOC_REG (0xA000) 2059 #define RK3588_VCCIO2_IOC_REG (0xB000) 2060 #define RK3588_VCCIO6_IOC_REG (0xC000) 2061 #define RK3588_EMMC_IOC_REG (0xD000) 2062 2063 static const u32 rk3588_ds_regs[][2] = { 2064 {RK_GPIO0_A0, RK3588_PMU1_IOC_REG + 0x0010}, 2065 {RK_GPIO0_A4, RK3588_PMU1_IOC_REG + 0x0014}, 2066 {RK_GPIO0_B0, RK3588_PMU1_IOC_REG + 0x0018}, 2067 {RK_GPIO0_B4, RK3588_PMU2_IOC_REG + 0x0014}, 2068 {RK_GPIO0_C0, RK3588_PMU2_IOC_REG + 0x0018}, 2069 {RK_GPIO0_C4, RK3588_PMU2_IOC_REG + 0x001C}, 2070 {RK_GPIO0_D0, RK3588_PMU2_IOC_REG + 0x0020}, 2071 {RK_GPIO0_D4, RK3588_PMU2_IOC_REG + 0x0024}, 2072 {RK_GPIO1_A0, RK3588_VCCIO1_4_IOC_REG + 0x0020}, 2073 {RK_GPIO1_A4, RK3588_VCCIO1_4_IOC_REG + 0x0024}, 2074 {RK_GPIO1_B0, RK3588_VCCIO1_4_IOC_REG + 0x0028}, 2075 {RK_GPIO1_B4, RK3588_VCCIO1_4_IOC_REG + 0x002C}, 2076 {RK_GPIO1_C0, RK3588_VCCIO1_4_IOC_REG + 0x0030}, 2077 {RK_GPIO1_C4, RK3588_VCCIO1_4_IOC_REG + 0x0034}, 2078 {RK_GPIO1_D0, RK3588_VCCIO1_4_IOC_REG + 0x0038}, 2079 {RK_GPIO1_D4, RK3588_VCCIO1_4_IOC_REG + 0x003C}, 2080 {RK_GPIO2_A0, RK3588_EMMC_IOC_REG + 0x0040}, 2081 {RK_GPIO2_A4, RK3588_VCCIO3_5_IOC_REG + 0x0044}, 2082 {RK_GPIO2_B0, RK3588_VCCIO3_5_IOC_REG + 0x0048}, 2083 {RK_GPIO2_B4, RK3588_VCCIO3_5_IOC_REG + 0x004C}, 2084 {RK_GPIO2_C0, RK3588_VCCIO3_5_IOC_REG + 0x0050}, 2085 {RK_GPIO2_C4, RK3588_VCCIO3_5_IOC_REG + 0x0054}, 2086 {RK_GPIO2_D0, RK3588_EMMC_IOC_REG + 0x0058}, 2087 {RK_GPIO2_D4, RK3588_EMMC_IOC_REG + 0x005C}, 2088 {RK_GPIO3_A0, RK3588_VCCIO3_5_IOC_REG + 0x0060}, 2089 {RK_GPIO3_A4, RK3588_VCCIO3_5_IOC_REG + 0x0064}, 2090 {RK_GPIO3_B0, RK3588_VCCIO3_5_IOC_REG + 0x0068}, 2091 {RK_GPIO3_B4, RK3588_VCCIO3_5_IOC_REG + 0x006C}, 2092 {RK_GPIO3_C0, RK3588_VCCIO3_5_IOC_REG + 0x0070}, 2093 {RK_GPIO3_C4, RK3588_VCCIO3_5_IOC_REG + 0x0074}, 2094 {RK_GPIO3_D0, RK3588_VCCIO3_5_IOC_REG + 0x0078}, 2095 {RK_GPIO3_D4, RK3588_VCCIO3_5_IOC_REG + 0x007C}, 2096 {RK_GPIO4_A0, RK3588_VCCIO6_IOC_REG + 0x0080}, 2097 {RK_GPIO4_A4, RK3588_VCCIO6_IOC_REG + 0x0084}, 2098 {RK_GPIO4_B0, RK3588_VCCIO6_IOC_REG + 0x0088}, 2099 {RK_GPIO4_B4, RK3588_VCCIO6_IOC_REG + 0x008C}, 2100 {RK_GPIO4_C0, RK3588_VCCIO6_IOC_REG + 0x0090}, 2101 {RK_GPIO4_C2, RK3588_VCCIO3_5_IOC_REG + 0x0090}, 2102 {RK_GPIO4_C4, RK3588_VCCIO3_5_IOC_REG + 0x0094}, 2103 {RK_GPIO4_D0, RK3588_VCCIO2_IOC_REG + 0x0098}, 2104 {RK_GPIO4_D4, RK3588_VCCIO2_IOC_REG + 0x009C}, 2105 }; 2106 2107 static const u32 rk3588_p_regs[][2] = { 2108 {RK_GPIO0_A0, RK3588_PMU1_IOC_REG + 0x0020}, 2109 {RK_GPIO0_B0, RK3588_PMU1_IOC_REG + 0x0024}, 2110 {RK_GPIO0_B5, RK3588_PMU2_IOC_REG + 0x0028}, 2111 {RK_GPIO0_C0, RK3588_PMU2_IOC_REG + 0x002C}, 2112 {RK_GPIO0_D0, RK3588_PMU2_IOC_REG + 0x0030}, 2113 {RK_GPIO1_A0, RK3588_VCCIO1_4_IOC_REG + 0x0110}, 2114 {RK_GPIO1_B0, RK3588_VCCIO1_4_IOC_REG + 0x0114}, 2115 {RK_GPIO1_C0, RK3588_VCCIO1_4_IOC_REG + 0x0118}, 2116 {RK_GPIO1_D0, RK3588_VCCIO1_4_IOC_REG + 0x011C}, 2117 {RK_GPIO2_A0, RK3588_EMMC_IOC_REG + 0x0120}, 2118 {RK_GPIO2_A6, RK3588_VCCIO3_5_IOC_REG + 0x0120}, 2119 {RK_GPIO2_B0, RK3588_VCCIO3_5_IOC_REG + 0x0124}, 2120 {RK_GPIO2_C0, RK3588_VCCIO3_5_IOC_REG + 0x0128}, 2121 {RK_GPIO2_D0, RK3588_EMMC_IOC_REG + 0x012C}, 2122 {RK_GPIO3_A0, RK3588_VCCIO3_5_IOC_REG + 0x0130}, 2123 {RK_GPIO3_B0, RK3588_VCCIO3_5_IOC_REG + 0x0134}, 2124 {RK_GPIO3_C0, RK3588_VCCIO3_5_IOC_REG + 0x0138}, 2125 {RK_GPIO3_D0, RK3588_VCCIO3_5_IOC_REG + 0x013C}, 2126 {RK_GPIO4_A0, RK3588_VCCIO6_IOC_REG + 0x0140}, 2127 {RK_GPIO4_B0, RK3588_VCCIO6_IOC_REG + 0x0144}, 2128 {RK_GPIO4_C0, RK3588_VCCIO6_IOC_REG + 0x0148}, 2129 {RK_GPIO4_C2, RK3588_VCCIO3_5_IOC_REG + 0x0148}, 2130 {RK_GPIO4_D0, RK3588_VCCIO2_IOC_REG + 0x014C}, 2131 }; 2132 2133 static const u32 rk3588_smt_regs[][2] = { 2134 {RK_GPIO0_A0, RK3588_PMU1_IOC_REG + 0x0030}, 2135 {RK_GPIO0_B0, RK3588_PMU1_IOC_REG + 0x0034}, 2136 {RK_GPIO0_B5, RK3588_PMU2_IOC_REG + 0x0040}, 2137 {RK_GPIO0_C0, RK3588_PMU2_IOC_REG + 0x0044}, 2138 {RK_GPIO0_D0, RK3588_PMU2_IOC_REG + 0x0048}, 2139 {RK_GPIO1_A0, RK3588_VCCIO1_4_IOC_REG + 0x0210}, 2140 {RK_GPIO1_B0, RK3588_VCCIO1_4_IOC_REG + 0x0214}, 2141 {RK_GPIO1_C0, RK3588_VCCIO1_4_IOC_REG + 0x0218}, 2142 {RK_GPIO1_D0, RK3588_VCCIO1_4_IOC_REG + 0x021C}, 2143 {RK_GPIO2_A0, RK3588_EMMC_IOC_REG + 0x0220}, 2144 {RK_GPIO2_A6, RK3588_VCCIO3_5_IOC_REG + 0x0220}, 2145 {RK_GPIO2_B0, RK3588_VCCIO3_5_IOC_REG + 0x0224}, 2146 {RK_GPIO2_C0, RK3588_VCCIO3_5_IOC_REG + 0x0228}, 2147 {RK_GPIO2_D0, RK3588_EMMC_IOC_REG + 0x022C}, 2148 {RK_GPIO3_A0, RK3588_VCCIO3_5_IOC_REG + 0x0230}, 2149 {RK_GPIO3_B0, RK3588_VCCIO3_5_IOC_REG + 0x0234}, 2150 {RK_GPIO3_C0, RK3588_VCCIO3_5_IOC_REG + 0x0238}, 2151 {RK_GPIO3_D0, RK3588_VCCIO3_5_IOC_REG + 0x023C}, 2152 {RK_GPIO4_A0, RK3588_VCCIO6_IOC_REG + 0x0240}, 2153 {RK_GPIO4_B0, RK3588_VCCIO6_IOC_REG + 0x0244}, 2154 {RK_GPIO4_C0, RK3588_VCCIO6_IOC_REG + 0x0248}, 2155 {RK_GPIO4_C2, RK3588_VCCIO3_5_IOC_REG + 0x0248}, 2156 {RK_GPIO4_D0, RK3588_VCCIO2_IOC_REG + 0x024C}, 2157 }; 2158 2159 #define RK3588_PULL_BITS_PER_PIN 2 2160 #define RK3588_PULL_PINS_PER_REG 8 2161 2162 static int rk3588_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, 2163 int pin_num, struct regmap **regmap, 2164 int *reg, u8 *bit) 2165 { 2166 struct rockchip_pinctrl *info = bank->drvdata; 2167 u8 bank_num = bank->bank_num; 2168 u32 pin = bank_num * 32 + pin_num; 2169 int i; 2170 2171 for (i = ARRAY_SIZE(rk3588_p_regs) - 1; i >= 0; i--) { 2172 if (pin >= rk3588_p_regs[i][0]) { 2173 *reg = rk3588_p_regs[i][1]; 2174 *regmap = info->regmap_base; 2175 *bit = pin_num % RK3588_PULL_PINS_PER_REG; 2176 *bit *= RK3588_PULL_BITS_PER_PIN; 2177 return 0; 2178 } 2179 } 2180 2181 return -EINVAL; 2182 } 2183 2184 #define RK3588_DRV_BITS_PER_PIN 4 2185 #define RK3588_DRV_PINS_PER_REG 4 2186 2187 static int rk3588_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank, 2188 int pin_num, struct regmap **regmap, 2189 int *reg, u8 *bit) 2190 { 2191 struct rockchip_pinctrl *info = bank->drvdata; 2192 u8 bank_num = bank->bank_num; 2193 u32 pin = bank_num * 32 + pin_num; 2194 int i; 2195 2196 for (i = ARRAY_SIZE(rk3588_ds_regs) - 1; i >= 0; i--) { 2197 if (pin >= rk3588_ds_regs[i][0]) { 2198 *reg = rk3588_ds_regs[i][1]; 2199 *regmap = info->regmap_base; 2200 *bit = pin_num % RK3588_DRV_PINS_PER_REG; 2201 *bit *= RK3588_DRV_BITS_PER_PIN; 2202 return 0; 2203 } 2204 } 2205 2206 return -EINVAL; 2207 } 2208 2209 #define RK3588_SMT_BITS_PER_PIN 1 2210 #define RK3588_SMT_PINS_PER_REG 8 2211 2212 static int rk3588_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank, 2213 int pin_num, 2214 struct regmap **regmap, 2215 int *reg, u8 *bit) 2216 { 2217 struct rockchip_pinctrl *info = bank->drvdata; 2218 u8 bank_num = bank->bank_num; 2219 u32 pin = bank_num * 32 + pin_num; 2220 int i; 2221 2222 for (i = ARRAY_SIZE(rk3588_smt_regs) - 1; i >= 0; i--) { 2223 if (pin >= rk3588_smt_regs[i][0]) { 2224 *reg = rk3588_smt_regs[i][1]; 2225 *regmap = info->regmap_base; 2226 *bit = pin_num % RK3588_SMT_PINS_PER_REG; 2227 *bit *= RK3588_SMT_BITS_PER_PIN; 2228 return 0; 2229 } 2230 } 2231 2232 return -EINVAL; 2233 } 2234 2235 static int rockchip_perpin_drv_list[DRV_TYPE_MAX][8] = { 2236 { 2, 4, 8, 12, -1, -1, -1, -1 }, 2237 { 3, 6, 9, 12, -1, -1, -1, -1 }, 2238 { 5, 10, 15, 20, -1, -1, -1, -1 }, 2239 { 4, 6, 8, 10, 12, 14, 16, 18 }, 2240 { 4, 7, 10, 13, 16, 19, 22, 26 } 2241 }; 2242 2243 static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank, 2244 int pin_num) 2245 { 2246 struct rockchip_pinctrl *info = bank->drvdata; 2247 struct rockchip_pin_ctrl *ctrl = info->ctrl; 2248 struct device *dev = info->dev; 2249 struct regmap *regmap; 2250 int reg, ret; 2251 u32 data, temp, rmask_bits; 2252 u8 bit; 2253 int drv_type = bank->drv[pin_num / 8].drv_type; 2254 2255 ret = ctrl->drv_calc_reg(bank, pin_num, ®map, ®, &bit); 2256 if (ret) 2257 return ret; 2258 2259 switch (drv_type) { 2260 case DRV_TYPE_IO_1V8_3V0_AUTO: 2261 case DRV_TYPE_IO_3V3_ONLY: 2262 rmask_bits = RK3399_DRV_3BITS_PER_PIN; 2263 switch (bit) { 2264 case 0 ... 12: 2265 /* regular case, nothing to do */ 2266 break; 2267 case 15: 2268 /* 2269 * drive-strength offset is special, as it is 2270 * spread over 2 registers 2271 */ 2272 ret = regmap_read(regmap, reg, &data); 2273 if (ret) 2274 return ret; 2275 2276 ret = regmap_read(regmap, reg + 0x4, &temp); 2277 if (ret) 2278 return ret; 2279 2280 /* 2281 * the bit data[15] contains bit 0 of the value 2282 * while temp[1:0] contains bits 2 and 1 2283 */ 2284 data >>= 15; 2285 temp &= 0x3; 2286 temp <<= 1; 2287 data |= temp; 2288 2289 return rockchip_perpin_drv_list[drv_type][data]; 2290 case 18 ... 21: 2291 /* setting fully enclosed in the second register */ 2292 reg += 4; 2293 bit -= 16; 2294 break; 2295 default: 2296 dev_err(dev, "unsupported bit: %d for pinctrl drive type: %d\n", 2297 bit, drv_type); 2298 return -EINVAL; 2299 } 2300 2301 break; 2302 case DRV_TYPE_IO_DEFAULT: 2303 case DRV_TYPE_IO_1V8_OR_3V0: 2304 case DRV_TYPE_IO_1V8_ONLY: 2305 rmask_bits = RK3288_DRV_BITS_PER_PIN; 2306 break; 2307 default: 2308 dev_err(dev, "unsupported pinctrl drive type: %d\n", drv_type); 2309 return -EINVAL; 2310 } 2311 2312 ret = regmap_read(regmap, reg, &data); 2313 if (ret) 2314 return ret; 2315 2316 data >>= bit; 2317 data &= (1 << rmask_bits) - 1; 2318 2319 return rockchip_perpin_drv_list[drv_type][data]; 2320 } 2321 2322 static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank, 2323 int pin_num, int strength) 2324 { 2325 struct rockchip_pinctrl *info = bank->drvdata; 2326 struct rockchip_pin_ctrl *ctrl = info->ctrl; 2327 struct device *dev = info->dev; 2328 struct regmap *regmap; 2329 int reg, ret, i; 2330 u32 data, rmask, rmask_bits, temp; 2331 u8 bit; 2332 int drv_type = bank->drv[pin_num / 8].drv_type; 2333 2334 dev_dbg(dev, "setting drive of GPIO%d-%d to %d\n", 2335 bank->bank_num, pin_num, strength); 2336 2337 ret = ctrl->drv_calc_reg(bank, pin_num, ®map, ®, &bit); 2338 if (ret) 2339 return ret; 2340 if (ctrl->type == RK3588) { 2341 rmask_bits = RK3588_DRV_BITS_PER_PIN; 2342 ret = strength; 2343 goto config; 2344 } else if (ctrl->type == RK3568) { 2345 rmask_bits = RK3568_DRV_BITS_PER_PIN; 2346 ret = (1 << (strength + 1)) - 1; 2347 goto config; 2348 } 2349 2350 if (ctrl->type == RV1126) { 2351 rmask_bits = RV1126_DRV_BITS_PER_PIN; 2352 ret = strength; 2353 goto config; 2354 } 2355 2356 ret = -EINVAL; 2357 for (i = 0; i < ARRAY_SIZE(rockchip_perpin_drv_list[drv_type]); i++) { 2358 if (rockchip_perpin_drv_list[drv_type][i] == strength) { 2359 ret = i; 2360 break; 2361 } else if (rockchip_perpin_drv_list[drv_type][i] < 0) { 2362 ret = rockchip_perpin_drv_list[drv_type][i]; 2363 break; 2364 } 2365 } 2366 2367 if (ret < 0) { 2368 dev_err(dev, "unsupported driver strength %d\n", strength); 2369 return ret; 2370 } 2371 2372 switch (drv_type) { 2373 case DRV_TYPE_IO_1V8_3V0_AUTO: 2374 case DRV_TYPE_IO_3V3_ONLY: 2375 rmask_bits = RK3399_DRV_3BITS_PER_PIN; 2376 switch (bit) { 2377 case 0 ... 12: 2378 /* regular case, nothing to do */ 2379 break; 2380 case 15: 2381 /* 2382 * drive-strength offset is special, as it is spread 2383 * over 2 registers, the bit data[15] contains bit 0 2384 * of the value while temp[1:0] contains bits 2 and 1 2385 */ 2386 data = (ret & 0x1) << 15; 2387 temp = (ret >> 0x1) & 0x3; 2388 2389 rmask = BIT(15) | BIT(31); 2390 data |= BIT(31); 2391 ret = regmap_update_bits(regmap, reg, rmask, data); 2392 if (ret) 2393 return ret; 2394 2395 rmask = 0x3 | (0x3 << 16); 2396 temp |= (0x3 << 16); 2397 reg += 0x4; 2398 ret = regmap_update_bits(regmap, reg, rmask, temp); 2399 2400 return ret; 2401 case 18 ... 21: 2402 /* setting fully enclosed in the second register */ 2403 reg += 4; 2404 bit -= 16; 2405 break; 2406 default: 2407 dev_err(dev, "unsupported bit: %d for pinctrl drive type: %d\n", 2408 bit, drv_type); 2409 return -EINVAL; 2410 } 2411 break; 2412 case DRV_TYPE_IO_DEFAULT: 2413 case DRV_TYPE_IO_1V8_OR_3V0: 2414 case DRV_TYPE_IO_1V8_ONLY: 2415 rmask_bits = RK3288_DRV_BITS_PER_PIN; 2416 break; 2417 default: 2418 dev_err(dev, "unsupported pinctrl drive type: %d\n", drv_type); 2419 return -EINVAL; 2420 } 2421 2422 config: 2423 /* enable the write to the equivalent lower bits */ 2424 data = ((1 << rmask_bits) - 1) << (bit + 16); 2425 rmask = data | (data >> 16); 2426 data |= (ret << bit); 2427 2428 ret = regmap_update_bits(regmap, reg, rmask, data); 2429 2430 return ret; 2431 } 2432 2433 static int rockchip_pull_list[PULL_TYPE_MAX][4] = { 2434 { 2435 PIN_CONFIG_BIAS_DISABLE, 2436 PIN_CONFIG_BIAS_PULL_UP, 2437 PIN_CONFIG_BIAS_PULL_DOWN, 2438 PIN_CONFIG_BIAS_BUS_HOLD 2439 }, 2440 { 2441 PIN_CONFIG_BIAS_DISABLE, 2442 PIN_CONFIG_BIAS_PULL_DOWN, 2443 PIN_CONFIG_BIAS_DISABLE, 2444 PIN_CONFIG_BIAS_PULL_UP 2445 }, 2446 }; 2447 2448 static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num) 2449 { 2450 struct rockchip_pinctrl *info = bank->drvdata; 2451 struct rockchip_pin_ctrl *ctrl = info->ctrl; 2452 struct device *dev = info->dev; 2453 struct regmap *regmap; 2454 int reg, ret, pull_type; 2455 u8 bit; 2456 u32 data; 2457 2458 /* rk3066b does support any pulls */ 2459 if (ctrl->type == RK3066B) 2460 return PIN_CONFIG_BIAS_DISABLE; 2461 2462 ret = ctrl->pull_calc_reg(bank, pin_num, ®map, ®, &bit); 2463 if (ret) 2464 return ret; 2465 2466 ret = regmap_read(regmap, reg, &data); 2467 if (ret) 2468 return ret; 2469 2470 switch (ctrl->type) { 2471 case RK2928: 2472 case RK3128: 2473 return !(data & BIT(bit)) 2474 ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT 2475 : PIN_CONFIG_BIAS_DISABLE; 2476 case PX30: 2477 case RV1108: 2478 case RK3188: 2479 case RK3288: 2480 case RK3308: 2481 case RK3328: 2482 case RK3368: 2483 case RK3399: 2484 case RK3568: 2485 case RK3588: 2486 pull_type = bank->pull_type[pin_num / 8]; 2487 data >>= bit; 2488 data &= (1 << RK3188_PULL_BITS_PER_PIN) - 1; 2489 /* 2490 * In the TRM, pull-up being 1 for everything except the GPIO0_D3-D6, 2491 * where that pull up value becomes 3. 2492 */ 2493 if (ctrl->type == RK3568 && bank->bank_num == 0 && pin_num >= 27 && pin_num <= 30) { 2494 if (data == 3) 2495 data = 1; 2496 } 2497 2498 return rockchip_pull_list[pull_type][data]; 2499 default: 2500 dev_err(dev, "unsupported pinctrl type\n"); 2501 return -EINVAL; 2502 }; 2503 } 2504 2505 static int rockchip_set_pull(struct rockchip_pin_bank *bank, 2506 int pin_num, int pull) 2507 { 2508 struct rockchip_pinctrl *info = bank->drvdata; 2509 struct rockchip_pin_ctrl *ctrl = info->ctrl; 2510 struct device *dev = info->dev; 2511 struct regmap *regmap; 2512 int reg, ret, i, pull_type; 2513 u8 bit; 2514 u32 data, rmask; 2515 2516 dev_dbg(dev, "setting pull of GPIO%d-%d to %d\n", bank->bank_num, pin_num, pull); 2517 2518 /* rk3066b does support any pulls */ 2519 if (ctrl->type == RK3066B) 2520 return pull ? -EINVAL : 0; 2521 2522 ret = ctrl->pull_calc_reg(bank, pin_num, ®map, ®, &bit); 2523 if (ret) 2524 return ret; 2525 2526 switch (ctrl->type) { 2527 case RK2928: 2528 case RK3128: 2529 data = BIT(bit + 16); 2530 if (pull == PIN_CONFIG_BIAS_DISABLE) 2531 data |= BIT(bit); 2532 ret = regmap_write(regmap, reg, data); 2533 break; 2534 case PX30: 2535 case RV1108: 2536 case RV1126: 2537 case RK3188: 2538 case RK3288: 2539 case RK3308: 2540 case RK3328: 2541 case RK3368: 2542 case RK3399: 2543 case RK3568: 2544 case RK3588: 2545 pull_type = bank->pull_type[pin_num / 8]; 2546 ret = -EINVAL; 2547 for (i = 0; i < ARRAY_SIZE(rockchip_pull_list[pull_type]); 2548 i++) { 2549 if (rockchip_pull_list[pull_type][i] == pull) { 2550 ret = i; 2551 break; 2552 } 2553 } 2554 /* 2555 * In the TRM, pull-up being 1 for everything except the GPIO0_D3-D6, 2556 * where that pull up value becomes 3. 2557 */ 2558 if (ctrl->type == RK3568 && bank->bank_num == 0 && pin_num >= 27 && pin_num <= 30) { 2559 if (ret == 1) 2560 ret = 3; 2561 } 2562 2563 if (ret < 0) { 2564 dev_err(dev, "unsupported pull setting %d\n", pull); 2565 return ret; 2566 } 2567 2568 /* enable the write to the equivalent lower bits */ 2569 data = ((1 << RK3188_PULL_BITS_PER_PIN) - 1) << (bit + 16); 2570 rmask = data | (data >> 16); 2571 data |= (ret << bit); 2572 2573 ret = regmap_update_bits(regmap, reg, rmask, data); 2574 break; 2575 default: 2576 dev_err(dev, "unsupported pinctrl type\n"); 2577 return -EINVAL; 2578 } 2579 2580 return ret; 2581 } 2582 2583 #define RK3328_SCHMITT_BITS_PER_PIN 1 2584 #define RK3328_SCHMITT_PINS_PER_REG 16 2585 #define RK3328_SCHMITT_BANK_STRIDE 8 2586 #define RK3328_SCHMITT_GRF_OFFSET 0x380 2587 2588 static int rk3328_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank, 2589 int pin_num, 2590 struct regmap **regmap, 2591 int *reg, u8 *bit) 2592 { 2593 struct rockchip_pinctrl *info = bank->drvdata; 2594 2595 *regmap = info->regmap_base; 2596 *reg = RK3328_SCHMITT_GRF_OFFSET; 2597 2598 *reg += bank->bank_num * RK3328_SCHMITT_BANK_STRIDE; 2599 *reg += ((pin_num / RK3328_SCHMITT_PINS_PER_REG) * 4); 2600 *bit = pin_num % RK3328_SCHMITT_PINS_PER_REG; 2601 2602 return 0; 2603 } 2604 2605 #define RK3568_SCHMITT_BITS_PER_PIN 2 2606 #define RK3568_SCHMITT_PINS_PER_REG 8 2607 #define RK3568_SCHMITT_BANK_STRIDE 0x10 2608 #define RK3568_SCHMITT_GRF_OFFSET 0xc0 2609 #define RK3568_SCHMITT_PMUGRF_OFFSET 0x30 2610 2611 static int rk3568_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank, 2612 int pin_num, 2613 struct regmap **regmap, 2614 int *reg, u8 *bit) 2615 { 2616 struct rockchip_pinctrl *info = bank->drvdata; 2617 2618 if (bank->bank_num == 0) { 2619 *regmap = info->regmap_pmu; 2620 *reg = RK3568_SCHMITT_PMUGRF_OFFSET; 2621 } else { 2622 *regmap = info->regmap_base; 2623 *reg = RK3568_SCHMITT_GRF_OFFSET; 2624 *reg += (bank->bank_num - 1) * RK3568_SCHMITT_BANK_STRIDE; 2625 } 2626 2627 *reg += ((pin_num / RK3568_SCHMITT_PINS_PER_REG) * 4); 2628 *bit = pin_num % RK3568_SCHMITT_PINS_PER_REG; 2629 *bit *= RK3568_SCHMITT_BITS_PER_PIN; 2630 2631 return 0; 2632 } 2633 2634 static int rockchip_get_schmitt(struct rockchip_pin_bank *bank, int pin_num) 2635 { 2636 struct rockchip_pinctrl *info = bank->drvdata; 2637 struct rockchip_pin_ctrl *ctrl = info->ctrl; 2638 struct regmap *regmap; 2639 int reg, ret; 2640 u8 bit; 2641 u32 data; 2642 2643 ret = ctrl->schmitt_calc_reg(bank, pin_num, ®map, ®, &bit); 2644 if (ret) 2645 return ret; 2646 2647 ret = regmap_read(regmap, reg, &data); 2648 if (ret) 2649 return ret; 2650 2651 data >>= bit; 2652 switch (ctrl->type) { 2653 case RK3568: 2654 return data & ((1 << RK3568_SCHMITT_BITS_PER_PIN) - 1); 2655 default: 2656 break; 2657 } 2658 2659 return data & 0x1; 2660 } 2661 2662 static int rockchip_set_schmitt(struct rockchip_pin_bank *bank, 2663 int pin_num, int enable) 2664 { 2665 struct rockchip_pinctrl *info = bank->drvdata; 2666 struct rockchip_pin_ctrl *ctrl = info->ctrl; 2667 struct device *dev = info->dev; 2668 struct regmap *regmap; 2669 int reg, ret; 2670 u8 bit; 2671 u32 data, rmask; 2672 2673 dev_dbg(dev, "setting input schmitt of GPIO%d-%d to %d\n", 2674 bank->bank_num, pin_num, enable); 2675 2676 ret = ctrl->schmitt_calc_reg(bank, pin_num, ®map, ®, &bit); 2677 if (ret) 2678 return ret; 2679 2680 /* enable the write to the equivalent lower bits */ 2681 switch (ctrl->type) { 2682 case RK3568: 2683 data = ((1 << RK3568_SCHMITT_BITS_PER_PIN) - 1) << (bit + 16); 2684 rmask = data | (data >> 16); 2685 data |= ((enable ? 0x2 : 0x1) << bit); 2686 break; 2687 default: 2688 data = BIT(bit + 16) | (enable << bit); 2689 rmask = BIT(bit + 16) | BIT(bit); 2690 break; 2691 } 2692 2693 return regmap_update_bits(regmap, reg, rmask, data); 2694 } 2695 2696 /* 2697 * Pinmux_ops handling 2698 */ 2699 2700 static int rockchip_pmx_get_funcs_count(struct pinctrl_dev *pctldev) 2701 { 2702 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); 2703 2704 return info->nfunctions; 2705 } 2706 2707 static const char *rockchip_pmx_get_func_name(struct pinctrl_dev *pctldev, 2708 unsigned selector) 2709 { 2710 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); 2711 2712 return info->functions[selector].name; 2713 } 2714 2715 static int rockchip_pmx_get_groups(struct pinctrl_dev *pctldev, 2716 unsigned selector, const char * const **groups, 2717 unsigned * const num_groups) 2718 { 2719 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); 2720 2721 *groups = info->functions[selector].groups; 2722 *num_groups = info->functions[selector].ngroups; 2723 2724 return 0; 2725 } 2726 2727 static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector, 2728 unsigned group) 2729 { 2730 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); 2731 const unsigned int *pins = info->groups[group].pins; 2732 const struct rockchip_pin_config *data = info->groups[group].data; 2733 struct device *dev = info->dev; 2734 struct rockchip_pin_bank *bank; 2735 int cnt, ret = 0; 2736 2737 dev_dbg(dev, "enable function %s group %s\n", 2738 info->functions[selector].name, info->groups[group].name); 2739 2740 /* 2741 * for each pin in the pin group selected, program the corresponding 2742 * pin function number in the config register. 2743 */ 2744 for (cnt = 0; cnt < info->groups[group].npins; cnt++) { 2745 bank = pin_to_bank(info, pins[cnt]); 2746 ret = rockchip_set_mux(bank, pins[cnt] - bank->pin_base, 2747 data[cnt].func); 2748 if (ret) 2749 break; 2750 } 2751 2752 if (ret) { 2753 /* revert the already done pin settings */ 2754 for (cnt--; cnt >= 0; cnt--) { 2755 bank = pin_to_bank(info, pins[cnt]); 2756 rockchip_set_mux(bank, pins[cnt] - bank->pin_base, 0); 2757 } 2758 2759 return ret; 2760 } 2761 2762 return 0; 2763 } 2764 2765 static int rockchip_pmx_gpio_set_direction(struct pinctrl_dev *pctldev, 2766 struct pinctrl_gpio_range *range, 2767 unsigned offset, 2768 bool input) 2769 { 2770 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); 2771 struct rockchip_pin_bank *bank; 2772 2773 bank = pin_to_bank(info, offset); 2774 return rockchip_set_mux(bank, offset - bank->pin_base, RK_FUNC_GPIO); 2775 } 2776 2777 static const struct pinmux_ops rockchip_pmx_ops = { 2778 .get_functions_count = rockchip_pmx_get_funcs_count, 2779 .get_function_name = rockchip_pmx_get_func_name, 2780 .get_function_groups = rockchip_pmx_get_groups, 2781 .set_mux = rockchip_pmx_set, 2782 .gpio_set_direction = rockchip_pmx_gpio_set_direction, 2783 }; 2784 2785 /* 2786 * Pinconf_ops handling 2787 */ 2788 2789 static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl *ctrl, 2790 enum pin_config_param pull) 2791 { 2792 switch (ctrl->type) { 2793 case RK2928: 2794 case RK3128: 2795 return (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT || 2796 pull == PIN_CONFIG_BIAS_DISABLE); 2797 case RK3066B: 2798 return pull ? false : true; 2799 case PX30: 2800 case RV1108: 2801 case RV1126: 2802 case RK3188: 2803 case RK3288: 2804 case RK3308: 2805 case RK3328: 2806 case RK3368: 2807 case RK3399: 2808 case RK3568: 2809 case RK3588: 2810 return (pull != PIN_CONFIG_BIAS_PULL_PIN_DEFAULT); 2811 } 2812 2813 return false; 2814 } 2815 2816 static int rockchip_pinconf_defer_pin(struct rockchip_pin_bank *bank, 2817 unsigned int pin, u32 param, u32 arg) 2818 { 2819 struct rockchip_pin_deferred *cfg; 2820 2821 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL); 2822 if (!cfg) 2823 return -ENOMEM; 2824 2825 cfg->pin = pin; 2826 cfg->param = param; 2827 cfg->arg = arg; 2828 2829 list_add_tail(&cfg->head, &bank->deferred_pins); 2830 2831 return 0; 2832 } 2833 2834 /* set the pin config settings for a specified pin */ 2835 static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin, 2836 unsigned long *configs, unsigned num_configs) 2837 { 2838 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); 2839 struct rockchip_pin_bank *bank = pin_to_bank(info, pin); 2840 struct gpio_chip *gpio = &bank->gpio_chip; 2841 enum pin_config_param param; 2842 u32 arg; 2843 int i; 2844 int rc; 2845 2846 for (i = 0; i < num_configs; i++) { 2847 param = pinconf_to_config_param(configs[i]); 2848 arg = pinconf_to_config_argument(configs[i]); 2849 2850 if (param == PIN_CONFIG_OUTPUT || param == PIN_CONFIG_INPUT_ENABLE) { 2851 /* 2852 * Check for gpio driver not being probed yet. 2853 * The lock makes sure that either gpio-probe has completed 2854 * or the gpio driver hasn't probed yet. 2855 */ 2856 mutex_lock(&bank->deferred_lock); 2857 if (!gpio || !gpio->direction_output) { 2858 rc = rockchip_pinconf_defer_pin(bank, pin - bank->pin_base, param, 2859 arg); 2860 mutex_unlock(&bank->deferred_lock); 2861 if (rc) 2862 return rc; 2863 2864 break; 2865 } 2866 mutex_unlock(&bank->deferred_lock); 2867 } 2868 2869 switch (param) { 2870 case PIN_CONFIG_BIAS_DISABLE: 2871 rc = rockchip_set_pull(bank, pin - bank->pin_base, 2872 param); 2873 if (rc) 2874 return rc; 2875 break; 2876 case PIN_CONFIG_BIAS_PULL_UP: 2877 case PIN_CONFIG_BIAS_PULL_DOWN: 2878 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: 2879 case PIN_CONFIG_BIAS_BUS_HOLD: 2880 if (!rockchip_pinconf_pull_valid(info->ctrl, param)) 2881 return -ENOTSUPP; 2882 2883 if (!arg) 2884 return -EINVAL; 2885 2886 rc = rockchip_set_pull(bank, pin - bank->pin_base, 2887 param); 2888 if (rc) 2889 return rc; 2890 break; 2891 case PIN_CONFIG_OUTPUT: 2892 rc = rockchip_set_mux(bank, pin - bank->pin_base, 2893 RK_FUNC_GPIO); 2894 if (rc != RK_FUNC_GPIO) 2895 return -EINVAL; 2896 2897 rc = gpio->direction_output(gpio, pin - bank->pin_base, 2898 arg); 2899 if (rc) 2900 return rc; 2901 break; 2902 case PIN_CONFIG_INPUT_ENABLE: 2903 rc = rockchip_set_mux(bank, pin - bank->pin_base, 2904 RK_FUNC_GPIO); 2905 if (rc != RK_FUNC_GPIO) 2906 return -EINVAL; 2907 2908 rc = gpio->direction_input(gpio, pin - bank->pin_base); 2909 if (rc) 2910 return rc; 2911 break; 2912 case PIN_CONFIG_DRIVE_STRENGTH: 2913 /* rk3288 is the first with per-pin drive-strength */ 2914 if (!info->ctrl->drv_calc_reg) 2915 return -ENOTSUPP; 2916 2917 rc = rockchip_set_drive_perpin(bank, 2918 pin - bank->pin_base, arg); 2919 if (rc < 0) 2920 return rc; 2921 break; 2922 case PIN_CONFIG_INPUT_SCHMITT_ENABLE: 2923 if (!info->ctrl->schmitt_calc_reg) 2924 return -ENOTSUPP; 2925 2926 rc = rockchip_set_schmitt(bank, 2927 pin - bank->pin_base, arg); 2928 if (rc < 0) 2929 return rc; 2930 break; 2931 default: 2932 return -ENOTSUPP; 2933 break; 2934 } 2935 } /* for each config */ 2936 2937 return 0; 2938 } 2939 2940 /* get the pin config settings for a specified pin */ 2941 static int rockchip_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin, 2942 unsigned long *config) 2943 { 2944 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); 2945 struct rockchip_pin_bank *bank = pin_to_bank(info, pin); 2946 struct gpio_chip *gpio = &bank->gpio_chip; 2947 enum pin_config_param param = pinconf_to_config_param(*config); 2948 u16 arg; 2949 int rc; 2950 2951 switch (param) { 2952 case PIN_CONFIG_BIAS_DISABLE: 2953 if (rockchip_get_pull(bank, pin - bank->pin_base) != param) 2954 return -EINVAL; 2955 2956 arg = 0; 2957 break; 2958 case PIN_CONFIG_BIAS_PULL_UP: 2959 case PIN_CONFIG_BIAS_PULL_DOWN: 2960 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: 2961 case PIN_CONFIG_BIAS_BUS_HOLD: 2962 if (!rockchip_pinconf_pull_valid(info->ctrl, param)) 2963 return -ENOTSUPP; 2964 2965 if (rockchip_get_pull(bank, pin - bank->pin_base) != param) 2966 return -EINVAL; 2967 2968 arg = 1; 2969 break; 2970 case PIN_CONFIG_OUTPUT: 2971 rc = rockchip_get_mux(bank, pin - bank->pin_base); 2972 if (rc != RK_FUNC_GPIO) 2973 return -EINVAL; 2974 2975 if (!gpio || !gpio->get) { 2976 arg = 0; 2977 break; 2978 } 2979 2980 rc = gpio->get(gpio, pin - bank->pin_base); 2981 if (rc < 0) 2982 return rc; 2983 2984 arg = rc ? 1 : 0; 2985 break; 2986 case PIN_CONFIG_DRIVE_STRENGTH: 2987 /* rk3288 is the first with per-pin drive-strength */ 2988 if (!info->ctrl->drv_calc_reg) 2989 return -ENOTSUPP; 2990 2991 rc = rockchip_get_drive_perpin(bank, pin - bank->pin_base); 2992 if (rc < 0) 2993 return rc; 2994 2995 arg = rc; 2996 break; 2997 case PIN_CONFIG_INPUT_SCHMITT_ENABLE: 2998 if (!info->ctrl->schmitt_calc_reg) 2999 return -ENOTSUPP; 3000 3001 rc = rockchip_get_schmitt(bank, pin - bank->pin_base); 3002 if (rc < 0) 3003 return rc; 3004 3005 arg = rc; 3006 break; 3007 default: 3008 return -ENOTSUPP; 3009 break; 3010 } 3011 3012 *config = pinconf_to_config_packed(param, arg); 3013 3014 return 0; 3015 } 3016 3017 static const struct pinconf_ops rockchip_pinconf_ops = { 3018 .pin_config_get = rockchip_pinconf_get, 3019 .pin_config_set = rockchip_pinconf_set, 3020 .is_generic = true, 3021 }; 3022 3023 static const struct of_device_id rockchip_bank_match[] = { 3024 { .compatible = "rockchip,gpio-bank" }, 3025 { .compatible = "rockchip,rk3188-gpio-bank0" }, 3026 {}, 3027 }; 3028 3029 static void rockchip_pinctrl_child_count(struct rockchip_pinctrl *info, 3030 struct device_node *np) 3031 { 3032 struct device_node *child; 3033 3034 for_each_child_of_node(np, child) { 3035 if (of_match_node(rockchip_bank_match, child)) 3036 continue; 3037 3038 info->nfunctions++; 3039 info->ngroups += of_get_child_count(child); 3040 } 3041 } 3042 3043 static int rockchip_pinctrl_parse_groups(struct device_node *np, 3044 struct rockchip_pin_group *grp, 3045 struct rockchip_pinctrl *info, 3046 u32 index) 3047 { 3048 struct device *dev = info->dev; 3049 struct rockchip_pin_bank *bank; 3050 int size; 3051 const __be32 *list; 3052 int num; 3053 int i, j; 3054 int ret; 3055 3056 dev_dbg(dev, "group(%d): %pOFn\n", index, np); 3057 3058 /* Initialise group */ 3059 grp->name = np->name; 3060 3061 /* 3062 * the binding format is rockchip,pins = <bank pin mux CONFIG>, 3063 * do sanity check and calculate pins number 3064 */ 3065 list = of_get_property(np, "rockchip,pins", &size); 3066 /* we do not check return since it's safe node passed down */ 3067 size /= sizeof(*list); 3068 if (!size || size % 4) 3069 return dev_err_probe(dev, -EINVAL, "wrong pins number or pins and configs should be by 4\n"); 3070 3071 grp->npins = size / 4; 3072 3073 grp->pins = devm_kcalloc(dev, grp->npins, sizeof(*grp->pins), GFP_KERNEL); 3074 grp->data = devm_kcalloc(dev, grp->npins, sizeof(*grp->data), GFP_KERNEL); 3075 if (!grp->pins || !grp->data) 3076 return -ENOMEM; 3077 3078 for (i = 0, j = 0; i < size; i += 4, j++) { 3079 const __be32 *phandle; 3080 struct device_node *np_config; 3081 3082 num = be32_to_cpu(*list++); 3083 bank = bank_num_to_bank(info, num); 3084 if (IS_ERR(bank)) 3085 return PTR_ERR(bank); 3086 3087 grp->pins[j] = bank->pin_base + be32_to_cpu(*list++); 3088 grp->data[j].func = be32_to_cpu(*list++); 3089 3090 phandle = list++; 3091 if (!phandle) 3092 return -EINVAL; 3093 3094 np_config = of_find_node_by_phandle(be32_to_cpup(phandle)); 3095 ret = pinconf_generic_parse_dt_config(np_config, NULL, 3096 &grp->data[j].configs, &grp->data[j].nconfigs); 3097 of_node_put(np_config); 3098 if (ret) 3099 return ret; 3100 } 3101 3102 return 0; 3103 } 3104 3105 static int rockchip_pinctrl_parse_functions(struct device_node *np, 3106 struct rockchip_pinctrl *info, 3107 u32 index) 3108 { 3109 struct device *dev = info->dev; 3110 struct device_node *child; 3111 struct rockchip_pmx_func *func; 3112 struct rockchip_pin_group *grp; 3113 int ret; 3114 static u32 grp_index; 3115 u32 i = 0; 3116 3117 dev_dbg(dev, "parse function(%d): %pOFn\n", index, np); 3118 3119 func = &info->functions[index]; 3120 3121 /* Initialise function */ 3122 func->name = np->name; 3123 func->ngroups = of_get_child_count(np); 3124 if (func->ngroups <= 0) 3125 return 0; 3126 3127 func->groups = devm_kcalloc(dev, func->ngroups, sizeof(*func->groups), GFP_KERNEL); 3128 if (!func->groups) 3129 return -ENOMEM; 3130 3131 for_each_child_of_node(np, child) { 3132 func->groups[i] = child->name; 3133 grp = &info->groups[grp_index++]; 3134 ret = rockchip_pinctrl_parse_groups(child, grp, info, i++); 3135 if (ret) { 3136 of_node_put(child); 3137 return ret; 3138 } 3139 } 3140 3141 return 0; 3142 } 3143 3144 static int rockchip_pinctrl_parse_dt(struct platform_device *pdev, 3145 struct rockchip_pinctrl *info) 3146 { 3147 struct device *dev = &pdev->dev; 3148 struct device_node *np = dev->of_node; 3149 struct device_node *child; 3150 int ret; 3151 int i; 3152 3153 rockchip_pinctrl_child_count(info, np); 3154 3155 dev_dbg(dev, "nfunctions = %d\n", info->nfunctions); 3156 dev_dbg(dev, "ngroups = %d\n", info->ngroups); 3157 3158 info->functions = devm_kcalloc(dev, info->nfunctions, sizeof(*info->functions), GFP_KERNEL); 3159 if (!info->functions) 3160 return -ENOMEM; 3161 3162 info->groups = devm_kcalloc(dev, info->ngroups, sizeof(*info->groups), GFP_KERNEL); 3163 if (!info->groups) 3164 return -ENOMEM; 3165 3166 i = 0; 3167 3168 for_each_child_of_node(np, child) { 3169 if (of_match_node(rockchip_bank_match, child)) 3170 continue; 3171 3172 ret = rockchip_pinctrl_parse_functions(child, info, i++); 3173 if (ret) { 3174 dev_err(dev, "failed to parse function\n"); 3175 of_node_put(child); 3176 return ret; 3177 } 3178 } 3179 3180 return 0; 3181 } 3182 3183 static int rockchip_pinctrl_register(struct platform_device *pdev, 3184 struct rockchip_pinctrl *info) 3185 { 3186 struct pinctrl_desc *ctrldesc = &info->pctl; 3187 struct pinctrl_pin_desc *pindesc, *pdesc; 3188 struct rockchip_pin_bank *pin_bank; 3189 struct device *dev = &pdev->dev; 3190 char **pin_names; 3191 int pin, bank, ret; 3192 int k; 3193 3194 ctrldesc->name = "rockchip-pinctrl"; 3195 ctrldesc->owner = THIS_MODULE; 3196 ctrldesc->pctlops = &rockchip_pctrl_ops; 3197 ctrldesc->pmxops = &rockchip_pmx_ops; 3198 ctrldesc->confops = &rockchip_pinconf_ops; 3199 3200 pindesc = devm_kcalloc(dev, info->ctrl->nr_pins, sizeof(*pindesc), GFP_KERNEL); 3201 if (!pindesc) 3202 return -ENOMEM; 3203 3204 ctrldesc->pins = pindesc; 3205 ctrldesc->npins = info->ctrl->nr_pins; 3206 3207 pdesc = pindesc; 3208 for (bank = 0, k = 0; bank < info->ctrl->nr_banks; bank++) { 3209 pin_bank = &info->ctrl->pin_banks[bank]; 3210 3211 pin_names = devm_kasprintf_strarray(dev, pin_bank->name, pin_bank->nr_pins); 3212 if (IS_ERR(pin_names)) 3213 return PTR_ERR(pin_names); 3214 3215 for (pin = 0; pin < pin_bank->nr_pins; pin++, k++) { 3216 pdesc->number = k; 3217 pdesc->name = pin_names[pin]; 3218 pdesc++; 3219 } 3220 3221 INIT_LIST_HEAD(&pin_bank->deferred_pins); 3222 mutex_init(&pin_bank->deferred_lock); 3223 } 3224 3225 ret = rockchip_pinctrl_parse_dt(pdev, info); 3226 if (ret) 3227 return ret; 3228 3229 info->pctl_dev = devm_pinctrl_register(dev, ctrldesc, info); 3230 if (IS_ERR(info->pctl_dev)) 3231 return dev_err_probe(dev, PTR_ERR(info->pctl_dev), "could not register pinctrl driver\n"); 3232 3233 return 0; 3234 } 3235 3236 static const struct of_device_id rockchip_pinctrl_dt_match[]; 3237 3238 /* retrieve the soc specific data */ 3239 static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data( 3240 struct rockchip_pinctrl *d, 3241 struct platform_device *pdev) 3242 { 3243 struct device *dev = &pdev->dev; 3244 struct device_node *node = dev->of_node; 3245 const struct of_device_id *match; 3246 struct rockchip_pin_ctrl *ctrl; 3247 struct rockchip_pin_bank *bank; 3248 int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j; 3249 3250 match = of_match_node(rockchip_pinctrl_dt_match, node); 3251 ctrl = (struct rockchip_pin_ctrl *)match->data; 3252 3253 grf_offs = ctrl->grf_mux_offset; 3254 pmu_offs = ctrl->pmu_mux_offset; 3255 drv_pmu_offs = ctrl->pmu_drv_offset; 3256 drv_grf_offs = ctrl->grf_drv_offset; 3257 bank = ctrl->pin_banks; 3258 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) { 3259 int bank_pins = 0; 3260 3261 raw_spin_lock_init(&bank->slock); 3262 bank->drvdata = d; 3263 bank->pin_base = ctrl->nr_pins; 3264 ctrl->nr_pins += bank->nr_pins; 3265 3266 /* calculate iomux and drv offsets */ 3267 for (j = 0; j < 4; j++) { 3268 struct rockchip_iomux *iom = &bank->iomux[j]; 3269 struct rockchip_drv *drv = &bank->drv[j]; 3270 int inc; 3271 3272 if (bank_pins >= bank->nr_pins) 3273 break; 3274 3275 /* preset iomux offset value, set new start value */ 3276 if (iom->offset >= 0) { 3277 if ((iom->type & IOMUX_SOURCE_PMU) || 3278 (iom->type & IOMUX_L_SOURCE_PMU)) 3279 pmu_offs = iom->offset; 3280 else 3281 grf_offs = iom->offset; 3282 } else { /* set current iomux offset */ 3283 iom->offset = ((iom->type & IOMUX_SOURCE_PMU) || 3284 (iom->type & IOMUX_L_SOURCE_PMU)) ? 3285 pmu_offs : grf_offs; 3286 } 3287 3288 /* preset drv offset value, set new start value */ 3289 if (drv->offset >= 0) { 3290 if (iom->type & IOMUX_SOURCE_PMU) 3291 drv_pmu_offs = drv->offset; 3292 else 3293 drv_grf_offs = drv->offset; 3294 } else { /* set current drv offset */ 3295 drv->offset = (iom->type & IOMUX_SOURCE_PMU) ? 3296 drv_pmu_offs : drv_grf_offs; 3297 } 3298 3299 dev_dbg(dev, "bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n", 3300 i, j, iom->offset, drv->offset); 3301 3302 /* 3303 * Increase offset according to iomux width. 3304 * 4bit iomux'es are spread over two registers. 3305 */ 3306 inc = (iom->type & (IOMUX_WIDTH_4BIT | 3307 IOMUX_WIDTH_3BIT | 3308 IOMUX_WIDTH_2BIT)) ? 8 : 4; 3309 if ((iom->type & IOMUX_SOURCE_PMU) || (iom->type & IOMUX_L_SOURCE_PMU)) 3310 pmu_offs += inc; 3311 else 3312 grf_offs += inc; 3313 3314 /* 3315 * Increase offset according to drv width. 3316 * 3bit drive-strenth'es are spread over two registers. 3317 */ 3318 if ((drv->drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) || 3319 (drv->drv_type == DRV_TYPE_IO_3V3_ONLY)) 3320 inc = 8; 3321 else 3322 inc = 4; 3323 3324 if (iom->type & IOMUX_SOURCE_PMU) 3325 drv_pmu_offs += inc; 3326 else 3327 drv_grf_offs += inc; 3328 3329 bank_pins += 8; 3330 } 3331 3332 /* calculate the per-bank recalced_mask */ 3333 for (j = 0; j < ctrl->niomux_recalced; j++) { 3334 int pin = 0; 3335 3336 if (ctrl->iomux_recalced[j].num == bank->bank_num) { 3337 pin = ctrl->iomux_recalced[j].pin; 3338 bank->recalced_mask |= BIT(pin); 3339 } 3340 } 3341 3342 /* calculate the per-bank route_mask */ 3343 for (j = 0; j < ctrl->niomux_routes; j++) { 3344 int pin = 0; 3345 3346 if (ctrl->iomux_routes[j].bank_num == bank->bank_num) { 3347 pin = ctrl->iomux_routes[j].pin; 3348 bank->route_mask |= BIT(pin); 3349 } 3350 } 3351 } 3352 3353 return ctrl; 3354 } 3355 3356 #define RK3288_GRF_GPIO6C_IOMUX 0x64 3357 #define GPIO6C6_SEL_WRITE_ENABLE BIT(28) 3358 3359 static u32 rk3288_grf_gpio6c_iomux; 3360 3361 static int __maybe_unused rockchip_pinctrl_suspend(struct device *dev) 3362 { 3363 struct rockchip_pinctrl *info = dev_get_drvdata(dev); 3364 int ret = pinctrl_force_sleep(info->pctl_dev); 3365 3366 if (ret) 3367 return ret; 3368 3369 /* 3370 * RK3288 GPIO6_C6 mux would be modified by Maskrom when resume, so save 3371 * the setting here, and restore it at resume. 3372 */ 3373 if (info->ctrl->type == RK3288) { 3374 ret = regmap_read(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX, 3375 &rk3288_grf_gpio6c_iomux); 3376 if (ret) { 3377 pinctrl_force_default(info->pctl_dev); 3378 return ret; 3379 } 3380 } 3381 3382 return 0; 3383 } 3384 3385 static int __maybe_unused rockchip_pinctrl_resume(struct device *dev) 3386 { 3387 struct rockchip_pinctrl *info = dev_get_drvdata(dev); 3388 int ret; 3389 3390 if (info->ctrl->type == RK3288) { 3391 ret = regmap_write(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX, 3392 rk3288_grf_gpio6c_iomux | 3393 GPIO6C6_SEL_WRITE_ENABLE); 3394 if (ret) 3395 return ret; 3396 } 3397 3398 return pinctrl_force_default(info->pctl_dev); 3399 } 3400 3401 static SIMPLE_DEV_PM_OPS(rockchip_pinctrl_dev_pm_ops, rockchip_pinctrl_suspend, 3402 rockchip_pinctrl_resume); 3403 3404 static int rockchip_pinctrl_probe(struct platform_device *pdev) 3405 { 3406 struct rockchip_pinctrl *info; 3407 struct device *dev = &pdev->dev; 3408 struct device_node *np = dev->of_node, *node; 3409 struct rockchip_pin_ctrl *ctrl; 3410 struct resource *res; 3411 void __iomem *base; 3412 int ret; 3413 3414 if (!dev->of_node) 3415 return dev_err_probe(dev, -ENODEV, "device tree node not found\n"); 3416 3417 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); 3418 if (!info) 3419 return -ENOMEM; 3420 3421 info->dev = dev; 3422 3423 ctrl = rockchip_pinctrl_get_soc_data(info, pdev); 3424 if (!ctrl) 3425 return dev_err_probe(dev, -EINVAL, "driver data not available\n"); 3426 info->ctrl = ctrl; 3427 3428 node = of_parse_phandle(np, "rockchip,grf", 0); 3429 if (node) { 3430 info->regmap_base = syscon_node_to_regmap(node); 3431 of_node_put(node); 3432 if (IS_ERR(info->regmap_base)) 3433 return PTR_ERR(info->regmap_base); 3434 } else { 3435 base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 3436 if (IS_ERR(base)) 3437 return PTR_ERR(base); 3438 3439 rockchip_regmap_config.max_register = resource_size(res) - 4; 3440 rockchip_regmap_config.name = "rockchip,pinctrl"; 3441 info->regmap_base = 3442 devm_regmap_init_mmio(dev, base, &rockchip_regmap_config); 3443 3444 /* to check for the old dt-bindings */ 3445 info->reg_size = resource_size(res); 3446 3447 /* Honor the old binding, with pull registers as 2nd resource */ 3448 if (ctrl->type == RK3188 && info->reg_size < 0x200) { 3449 base = devm_platform_get_and_ioremap_resource(pdev, 1, &res); 3450 if (IS_ERR(base)) 3451 return PTR_ERR(base); 3452 3453 rockchip_regmap_config.max_register = resource_size(res) - 4; 3454 rockchip_regmap_config.name = "rockchip,pinctrl-pull"; 3455 info->regmap_pull = 3456 devm_regmap_init_mmio(dev, base, &rockchip_regmap_config); 3457 } 3458 } 3459 3460 /* try to find the optional reference to the pmu syscon */ 3461 node = of_parse_phandle(np, "rockchip,pmu", 0); 3462 if (node) { 3463 info->regmap_pmu = syscon_node_to_regmap(node); 3464 of_node_put(node); 3465 if (IS_ERR(info->regmap_pmu)) 3466 return PTR_ERR(info->regmap_pmu); 3467 } 3468 3469 ret = rockchip_pinctrl_register(pdev, info); 3470 if (ret) 3471 return ret; 3472 3473 platform_set_drvdata(pdev, info); 3474 3475 ret = of_platform_populate(np, NULL, NULL, &pdev->dev); 3476 if (ret) 3477 return dev_err_probe(dev, ret, "failed to register gpio device\n"); 3478 3479 return 0; 3480 } 3481 3482 static int rockchip_pinctrl_remove(struct platform_device *pdev) 3483 { 3484 struct rockchip_pinctrl *info = platform_get_drvdata(pdev); 3485 struct rockchip_pin_bank *bank; 3486 struct rockchip_pin_deferred *cfg; 3487 int i; 3488 3489 of_platform_depopulate(&pdev->dev); 3490 3491 for (i = 0; i < info->ctrl->nr_banks; i++) { 3492 bank = &info->ctrl->pin_banks[i]; 3493 3494 mutex_lock(&bank->deferred_lock); 3495 while (!list_empty(&bank->deferred_pins)) { 3496 cfg = list_first_entry(&bank->deferred_pins, 3497 struct rockchip_pin_deferred, head); 3498 list_del(&cfg->head); 3499 kfree(cfg); 3500 } 3501 mutex_unlock(&bank->deferred_lock); 3502 } 3503 3504 return 0; 3505 } 3506 3507 static struct rockchip_pin_bank px30_pin_banks[] = { 3508 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU, 3509 IOMUX_SOURCE_PMU, 3510 IOMUX_SOURCE_PMU, 3511 IOMUX_SOURCE_PMU 3512 ), 3513 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT, 3514 IOMUX_WIDTH_4BIT, 3515 IOMUX_WIDTH_4BIT, 3516 IOMUX_WIDTH_4BIT 3517 ), 3518 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT, 3519 IOMUX_WIDTH_4BIT, 3520 IOMUX_WIDTH_4BIT, 3521 IOMUX_WIDTH_4BIT 3522 ), 3523 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT, 3524 IOMUX_WIDTH_4BIT, 3525 IOMUX_WIDTH_4BIT, 3526 IOMUX_WIDTH_4BIT 3527 ), 3528 }; 3529 3530 static struct rockchip_pin_ctrl px30_pin_ctrl = { 3531 .pin_banks = px30_pin_banks, 3532 .nr_banks = ARRAY_SIZE(px30_pin_banks), 3533 .label = "PX30-GPIO", 3534 .type = PX30, 3535 .grf_mux_offset = 0x0, 3536 .pmu_mux_offset = 0x0, 3537 .iomux_routes = px30_mux_route_data, 3538 .niomux_routes = ARRAY_SIZE(px30_mux_route_data), 3539 .pull_calc_reg = px30_calc_pull_reg_and_bit, 3540 .drv_calc_reg = px30_calc_drv_reg_and_bit, 3541 .schmitt_calc_reg = px30_calc_schmitt_reg_and_bit, 3542 }; 3543 3544 static struct rockchip_pin_bank rv1108_pin_banks[] = { 3545 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU, 3546 IOMUX_SOURCE_PMU, 3547 IOMUX_SOURCE_PMU, 3548 IOMUX_SOURCE_PMU), 3549 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0), 3550 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, 0), 3551 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, 0), 3552 }; 3553 3554 static struct rockchip_pin_ctrl rv1108_pin_ctrl = { 3555 .pin_banks = rv1108_pin_banks, 3556 .nr_banks = ARRAY_SIZE(rv1108_pin_banks), 3557 .label = "RV1108-GPIO", 3558 .type = RV1108, 3559 .grf_mux_offset = 0x10, 3560 .pmu_mux_offset = 0x0, 3561 .iomux_recalced = rv1108_mux_recalced_data, 3562 .niomux_recalced = ARRAY_SIZE(rv1108_mux_recalced_data), 3563 .pull_calc_reg = rv1108_calc_pull_reg_and_bit, 3564 .drv_calc_reg = rv1108_calc_drv_reg_and_bit, 3565 .schmitt_calc_reg = rv1108_calc_schmitt_reg_and_bit, 3566 }; 3567 3568 static struct rockchip_pin_bank rv1126_pin_banks[] = { 3569 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", 3570 IOMUX_WIDTH_4BIT | IOMUX_SOURCE_PMU, 3571 IOMUX_WIDTH_4BIT | IOMUX_SOURCE_PMU, 3572 IOMUX_WIDTH_4BIT | IOMUX_L_SOURCE_PMU, 3573 IOMUX_WIDTH_4BIT), 3574 PIN_BANK_IOMUX_FLAGS_OFFSET(1, 32, "gpio1", 3575 IOMUX_WIDTH_4BIT, 3576 IOMUX_WIDTH_4BIT, 3577 IOMUX_WIDTH_4BIT, 3578 IOMUX_WIDTH_4BIT, 3579 0x10010, 0x10018, 0x10020, 0x10028), 3580 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 3581 IOMUX_WIDTH_4BIT, 3582 IOMUX_WIDTH_4BIT, 3583 IOMUX_WIDTH_4BIT, 3584 IOMUX_WIDTH_4BIT), 3585 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 3586 IOMUX_WIDTH_4BIT, 3587 IOMUX_WIDTH_4BIT, 3588 IOMUX_WIDTH_4BIT, 3589 IOMUX_WIDTH_4BIT), 3590 PIN_BANK_IOMUX_FLAGS(4, 2, "gpio4", 3591 IOMUX_WIDTH_4BIT, 0, 0, 0), 3592 }; 3593 3594 static struct rockchip_pin_ctrl rv1126_pin_ctrl = { 3595 .pin_banks = rv1126_pin_banks, 3596 .nr_banks = ARRAY_SIZE(rv1126_pin_banks), 3597 .label = "RV1126-GPIO", 3598 .type = RV1126, 3599 .grf_mux_offset = 0x10004, /* mux offset from GPIO0_D0 */ 3600 .pmu_mux_offset = 0x0, 3601 .iomux_routes = rv1126_mux_route_data, 3602 .niomux_routes = ARRAY_SIZE(rv1126_mux_route_data), 3603 .iomux_recalced = rv1126_mux_recalced_data, 3604 .niomux_recalced = ARRAY_SIZE(rv1126_mux_recalced_data), 3605 .pull_calc_reg = rv1126_calc_pull_reg_and_bit, 3606 .drv_calc_reg = rv1126_calc_drv_reg_and_bit, 3607 .schmitt_calc_reg = rv1126_calc_schmitt_reg_and_bit, 3608 }; 3609 3610 static struct rockchip_pin_bank rk2928_pin_banks[] = { 3611 PIN_BANK(0, 32, "gpio0"), 3612 PIN_BANK(1, 32, "gpio1"), 3613 PIN_BANK(2, 32, "gpio2"), 3614 PIN_BANK(3, 32, "gpio3"), 3615 }; 3616 3617 static struct rockchip_pin_ctrl rk2928_pin_ctrl = { 3618 .pin_banks = rk2928_pin_banks, 3619 .nr_banks = ARRAY_SIZE(rk2928_pin_banks), 3620 .label = "RK2928-GPIO", 3621 .type = RK2928, 3622 .grf_mux_offset = 0xa8, 3623 .pull_calc_reg = rk2928_calc_pull_reg_and_bit, 3624 }; 3625 3626 static struct rockchip_pin_bank rk3036_pin_banks[] = { 3627 PIN_BANK(0, 32, "gpio0"), 3628 PIN_BANK(1, 32, "gpio1"), 3629 PIN_BANK(2, 32, "gpio2"), 3630 }; 3631 3632 static struct rockchip_pin_ctrl rk3036_pin_ctrl = { 3633 .pin_banks = rk3036_pin_banks, 3634 .nr_banks = ARRAY_SIZE(rk3036_pin_banks), 3635 .label = "RK3036-GPIO", 3636 .type = RK2928, 3637 .grf_mux_offset = 0xa8, 3638 .pull_calc_reg = rk2928_calc_pull_reg_and_bit, 3639 }; 3640 3641 static struct rockchip_pin_bank rk3066a_pin_banks[] = { 3642 PIN_BANK(0, 32, "gpio0"), 3643 PIN_BANK(1, 32, "gpio1"), 3644 PIN_BANK(2, 32, "gpio2"), 3645 PIN_BANK(3, 32, "gpio3"), 3646 PIN_BANK(4, 32, "gpio4"), 3647 PIN_BANK(6, 16, "gpio6"), 3648 }; 3649 3650 static struct rockchip_pin_ctrl rk3066a_pin_ctrl = { 3651 .pin_banks = rk3066a_pin_banks, 3652 .nr_banks = ARRAY_SIZE(rk3066a_pin_banks), 3653 .label = "RK3066a-GPIO", 3654 .type = RK2928, 3655 .grf_mux_offset = 0xa8, 3656 .pull_calc_reg = rk2928_calc_pull_reg_and_bit, 3657 }; 3658 3659 static struct rockchip_pin_bank rk3066b_pin_banks[] = { 3660 PIN_BANK(0, 32, "gpio0"), 3661 PIN_BANK(1, 32, "gpio1"), 3662 PIN_BANK(2, 32, "gpio2"), 3663 PIN_BANK(3, 32, "gpio3"), 3664 }; 3665 3666 static struct rockchip_pin_ctrl rk3066b_pin_ctrl = { 3667 .pin_banks = rk3066b_pin_banks, 3668 .nr_banks = ARRAY_SIZE(rk3066b_pin_banks), 3669 .label = "RK3066b-GPIO", 3670 .type = RK3066B, 3671 .grf_mux_offset = 0x60, 3672 }; 3673 3674 static struct rockchip_pin_bank rk3128_pin_banks[] = { 3675 PIN_BANK(0, 32, "gpio0"), 3676 PIN_BANK(1, 32, "gpio1"), 3677 PIN_BANK(2, 32, "gpio2"), 3678 PIN_BANK(3, 32, "gpio3"), 3679 }; 3680 3681 static struct rockchip_pin_ctrl rk3128_pin_ctrl = { 3682 .pin_banks = rk3128_pin_banks, 3683 .nr_banks = ARRAY_SIZE(rk3128_pin_banks), 3684 .label = "RK3128-GPIO", 3685 .type = RK3128, 3686 .grf_mux_offset = 0xa8, 3687 .iomux_recalced = rk3128_mux_recalced_data, 3688 .niomux_recalced = ARRAY_SIZE(rk3128_mux_recalced_data), 3689 .iomux_routes = rk3128_mux_route_data, 3690 .niomux_routes = ARRAY_SIZE(rk3128_mux_route_data), 3691 .pull_calc_reg = rk3128_calc_pull_reg_and_bit, 3692 }; 3693 3694 static struct rockchip_pin_bank rk3188_pin_banks[] = { 3695 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_GPIO_ONLY, 0, 0, 0), 3696 PIN_BANK(1, 32, "gpio1"), 3697 PIN_BANK(2, 32, "gpio2"), 3698 PIN_BANK(3, 32, "gpio3"), 3699 }; 3700 3701 static struct rockchip_pin_ctrl rk3188_pin_ctrl = { 3702 .pin_banks = rk3188_pin_banks, 3703 .nr_banks = ARRAY_SIZE(rk3188_pin_banks), 3704 .label = "RK3188-GPIO", 3705 .type = RK3188, 3706 .grf_mux_offset = 0x60, 3707 .iomux_routes = rk3188_mux_route_data, 3708 .niomux_routes = ARRAY_SIZE(rk3188_mux_route_data), 3709 .pull_calc_reg = rk3188_calc_pull_reg_and_bit, 3710 }; 3711 3712 static struct rockchip_pin_bank rk3228_pin_banks[] = { 3713 PIN_BANK(0, 32, "gpio0"), 3714 PIN_BANK(1, 32, "gpio1"), 3715 PIN_BANK(2, 32, "gpio2"), 3716 PIN_BANK(3, 32, "gpio3"), 3717 }; 3718 3719 static struct rockchip_pin_ctrl rk3228_pin_ctrl = { 3720 .pin_banks = rk3228_pin_banks, 3721 .nr_banks = ARRAY_SIZE(rk3228_pin_banks), 3722 .label = "RK3228-GPIO", 3723 .type = RK3288, 3724 .grf_mux_offset = 0x0, 3725 .iomux_routes = rk3228_mux_route_data, 3726 .niomux_routes = ARRAY_SIZE(rk3228_mux_route_data), 3727 .pull_calc_reg = rk3228_calc_pull_reg_and_bit, 3728 .drv_calc_reg = rk3228_calc_drv_reg_and_bit, 3729 }; 3730 3731 static struct rockchip_pin_bank rk3288_pin_banks[] = { 3732 PIN_BANK_IOMUX_FLAGS(0, 24, "gpio0", IOMUX_SOURCE_PMU, 3733 IOMUX_SOURCE_PMU, 3734 IOMUX_SOURCE_PMU, 3735 IOMUX_UNROUTED 3736 ), 3737 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_UNROUTED, 3738 IOMUX_UNROUTED, 3739 IOMUX_UNROUTED, 3740 0 3741 ), 3742 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, IOMUX_UNROUTED), 3743 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, IOMUX_WIDTH_4BIT), 3744 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT, 3745 IOMUX_WIDTH_4BIT, 3746 0, 3747 0 3748 ), 3749 PIN_BANK_IOMUX_FLAGS(5, 32, "gpio5", IOMUX_UNROUTED, 3750 0, 3751 0, 3752 IOMUX_UNROUTED 3753 ), 3754 PIN_BANK_IOMUX_FLAGS(6, 32, "gpio6", 0, 0, 0, IOMUX_UNROUTED), 3755 PIN_BANK_IOMUX_FLAGS(7, 32, "gpio7", 0, 3756 0, 3757 IOMUX_WIDTH_4BIT, 3758 IOMUX_UNROUTED 3759 ), 3760 PIN_BANK(8, 16, "gpio8"), 3761 }; 3762 3763 static struct rockchip_pin_ctrl rk3288_pin_ctrl = { 3764 .pin_banks = rk3288_pin_banks, 3765 .nr_banks = ARRAY_SIZE(rk3288_pin_banks), 3766 .label = "RK3288-GPIO", 3767 .type = RK3288, 3768 .grf_mux_offset = 0x0, 3769 .pmu_mux_offset = 0x84, 3770 .iomux_routes = rk3288_mux_route_data, 3771 .niomux_routes = ARRAY_SIZE(rk3288_mux_route_data), 3772 .pull_calc_reg = rk3288_calc_pull_reg_and_bit, 3773 .drv_calc_reg = rk3288_calc_drv_reg_and_bit, 3774 }; 3775 3776 static struct rockchip_pin_bank rk3308_pin_banks[] = { 3777 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_WIDTH_2BIT, 3778 IOMUX_WIDTH_2BIT, 3779 IOMUX_WIDTH_2BIT, 3780 IOMUX_WIDTH_2BIT), 3781 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_2BIT, 3782 IOMUX_WIDTH_2BIT, 3783 IOMUX_WIDTH_2BIT, 3784 IOMUX_WIDTH_2BIT), 3785 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_2BIT, 3786 IOMUX_WIDTH_2BIT, 3787 IOMUX_WIDTH_2BIT, 3788 IOMUX_WIDTH_2BIT), 3789 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_2BIT, 3790 IOMUX_WIDTH_2BIT, 3791 IOMUX_WIDTH_2BIT, 3792 IOMUX_WIDTH_2BIT), 3793 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_2BIT, 3794 IOMUX_WIDTH_2BIT, 3795 IOMUX_WIDTH_2BIT, 3796 IOMUX_WIDTH_2BIT), 3797 }; 3798 3799 static struct rockchip_pin_ctrl rk3308_pin_ctrl = { 3800 .pin_banks = rk3308_pin_banks, 3801 .nr_banks = ARRAY_SIZE(rk3308_pin_banks), 3802 .label = "RK3308-GPIO", 3803 .type = RK3308, 3804 .grf_mux_offset = 0x0, 3805 .iomux_recalced = rk3308_mux_recalced_data, 3806 .niomux_recalced = ARRAY_SIZE(rk3308_mux_recalced_data), 3807 .iomux_routes = rk3308_mux_route_data, 3808 .niomux_routes = ARRAY_SIZE(rk3308_mux_route_data), 3809 .pull_calc_reg = rk3308_calc_pull_reg_and_bit, 3810 .drv_calc_reg = rk3308_calc_drv_reg_and_bit, 3811 .schmitt_calc_reg = rk3308_calc_schmitt_reg_and_bit, 3812 }; 3813 3814 static struct rockchip_pin_bank rk3328_pin_banks[] = { 3815 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", 0, 0, 0, 0), 3816 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0), 3817 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 3818 0, 3819 IOMUX_WIDTH_3BIT, 3820 0), 3821 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 3822 IOMUX_WIDTH_3BIT, 3823 IOMUX_WIDTH_3BIT, 3824 0, 3825 0), 3826 }; 3827 3828 static struct rockchip_pin_ctrl rk3328_pin_ctrl = { 3829 .pin_banks = rk3328_pin_banks, 3830 .nr_banks = ARRAY_SIZE(rk3328_pin_banks), 3831 .label = "RK3328-GPIO", 3832 .type = RK3328, 3833 .grf_mux_offset = 0x0, 3834 .iomux_recalced = rk3328_mux_recalced_data, 3835 .niomux_recalced = ARRAY_SIZE(rk3328_mux_recalced_data), 3836 .iomux_routes = rk3328_mux_route_data, 3837 .niomux_routes = ARRAY_SIZE(rk3328_mux_route_data), 3838 .pull_calc_reg = rk3228_calc_pull_reg_and_bit, 3839 .drv_calc_reg = rk3228_calc_drv_reg_and_bit, 3840 .schmitt_calc_reg = rk3328_calc_schmitt_reg_and_bit, 3841 }; 3842 3843 static struct rockchip_pin_bank rk3368_pin_banks[] = { 3844 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU, 3845 IOMUX_SOURCE_PMU, 3846 IOMUX_SOURCE_PMU, 3847 IOMUX_SOURCE_PMU 3848 ), 3849 PIN_BANK(1, 32, "gpio1"), 3850 PIN_BANK(2, 32, "gpio2"), 3851 PIN_BANK(3, 32, "gpio3"), 3852 }; 3853 3854 static struct rockchip_pin_ctrl rk3368_pin_ctrl = { 3855 .pin_banks = rk3368_pin_banks, 3856 .nr_banks = ARRAY_SIZE(rk3368_pin_banks), 3857 .label = "RK3368-GPIO", 3858 .type = RK3368, 3859 .grf_mux_offset = 0x0, 3860 .pmu_mux_offset = 0x0, 3861 .pull_calc_reg = rk3368_calc_pull_reg_and_bit, 3862 .drv_calc_reg = rk3368_calc_drv_reg_and_bit, 3863 }; 3864 3865 static struct rockchip_pin_bank rk3399_pin_banks[] = { 3866 PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(0, 32, "gpio0", 3867 IOMUX_SOURCE_PMU, 3868 IOMUX_SOURCE_PMU, 3869 IOMUX_SOURCE_PMU, 3870 IOMUX_SOURCE_PMU, 3871 DRV_TYPE_IO_1V8_ONLY, 3872 DRV_TYPE_IO_1V8_ONLY, 3873 DRV_TYPE_IO_DEFAULT, 3874 DRV_TYPE_IO_DEFAULT, 3875 0x80, 3876 0x88, 3877 -1, 3878 -1, 3879 PULL_TYPE_IO_1V8_ONLY, 3880 PULL_TYPE_IO_1V8_ONLY, 3881 PULL_TYPE_IO_DEFAULT, 3882 PULL_TYPE_IO_DEFAULT 3883 ), 3884 PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(1, 32, "gpio1", IOMUX_SOURCE_PMU, 3885 IOMUX_SOURCE_PMU, 3886 IOMUX_SOURCE_PMU, 3887 IOMUX_SOURCE_PMU, 3888 DRV_TYPE_IO_1V8_OR_3V0, 3889 DRV_TYPE_IO_1V8_OR_3V0, 3890 DRV_TYPE_IO_1V8_OR_3V0, 3891 DRV_TYPE_IO_1V8_OR_3V0, 3892 0xa0, 3893 0xa8, 3894 0xb0, 3895 0xb8 3896 ), 3897 PIN_BANK_DRV_FLAGS_PULL_FLAGS(2, 32, "gpio2", DRV_TYPE_IO_1V8_OR_3V0, 3898 DRV_TYPE_IO_1V8_OR_3V0, 3899 DRV_TYPE_IO_1V8_ONLY, 3900 DRV_TYPE_IO_1V8_ONLY, 3901 PULL_TYPE_IO_DEFAULT, 3902 PULL_TYPE_IO_DEFAULT, 3903 PULL_TYPE_IO_1V8_ONLY, 3904 PULL_TYPE_IO_1V8_ONLY 3905 ), 3906 PIN_BANK_DRV_FLAGS(3, 32, "gpio3", DRV_TYPE_IO_3V3_ONLY, 3907 DRV_TYPE_IO_3V3_ONLY, 3908 DRV_TYPE_IO_3V3_ONLY, 3909 DRV_TYPE_IO_1V8_OR_3V0 3910 ), 3911 PIN_BANK_DRV_FLAGS(4, 32, "gpio4", DRV_TYPE_IO_1V8_OR_3V0, 3912 DRV_TYPE_IO_1V8_3V0_AUTO, 3913 DRV_TYPE_IO_1V8_OR_3V0, 3914 DRV_TYPE_IO_1V8_OR_3V0 3915 ), 3916 }; 3917 3918 static struct rockchip_pin_ctrl rk3399_pin_ctrl = { 3919 .pin_banks = rk3399_pin_banks, 3920 .nr_banks = ARRAY_SIZE(rk3399_pin_banks), 3921 .label = "RK3399-GPIO", 3922 .type = RK3399, 3923 .grf_mux_offset = 0xe000, 3924 .pmu_mux_offset = 0x0, 3925 .grf_drv_offset = 0xe100, 3926 .pmu_drv_offset = 0x80, 3927 .iomux_routes = rk3399_mux_route_data, 3928 .niomux_routes = ARRAY_SIZE(rk3399_mux_route_data), 3929 .pull_calc_reg = rk3399_calc_pull_reg_and_bit, 3930 .drv_calc_reg = rk3399_calc_drv_reg_and_bit, 3931 }; 3932 3933 static struct rockchip_pin_bank rk3568_pin_banks[] = { 3934 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT, 3935 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT, 3936 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT, 3937 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT), 3938 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT, 3939 IOMUX_WIDTH_4BIT, 3940 IOMUX_WIDTH_4BIT, 3941 IOMUX_WIDTH_4BIT), 3942 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT, 3943 IOMUX_WIDTH_4BIT, 3944 IOMUX_WIDTH_4BIT, 3945 IOMUX_WIDTH_4BIT), 3946 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT, 3947 IOMUX_WIDTH_4BIT, 3948 IOMUX_WIDTH_4BIT, 3949 IOMUX_WIDTH_4BIT), 3950 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT, 3951 IOMUX_WIDTH_4BIT, 3952 IOMUX_WIDTH_4BIT, 3953 IOMUX_WIDTH_4BIT), 3954 }; 3955 3956 static struct rockchip_pin_ctrl rk3568_pin_ctrl = { 3957 .pin_banks = rk3568_pin_banks, 3958 .nr_banks = ARRAY_SIZE(rk3568_pin_banks), 3959 .label = "RK3568-GPIO", 3960 .type = RK3568, 3961 .grf_mux_offset = 0x0, 3962 .pmu_mux_offset = 0x0, 3963 .grf_drv_offset = 0x0200, 3964 .pmu_drv_offset = 0x0070, 3965 .iomux_routes = rk3568_mux_route_data, 3966 .niomux_routes = ARRAY_SIZE(rk3568_mux_route_data), 3967 .pull_calc_reg = rk3568_calc_pull_reg_and_bit, 3968 .drv_calc_reg = rk3568_calc_drv_reg_and_bit, 3969 .schmitt_calc_reg = rk3568_calc_schmitt_reg_and_bit, 3970 }; 3971 3972 static struct rockchip_pin_bank rk3588_pin_banks[] = { 3973 RK3588_PIN_BANK_FLAGS(0, 32, "gpio0", 3974 IOMUX_WIDTH_4BIT, PULL_TYPE_IO_1V8_ONLY), 3975 RK3588_PIN_BANK_FLAGS(1, 32, "gpio1", 3976 IOMUX_WIDTH_4BIT, PULL_TYPE_IO_1V8_ONLY), 3977 RK3588_PIN_BANK_FLAGS(2, 32, "gpio2", 3978 IOMUX_WIDTH_4BIT, PULL_TYPE_IO_1V8_ONLY), 3979 RK3588_PIN_BANK_FLAGS(3, 32, "gpio3", 3980 IOMUX_WIDTH_4BIT, PULL_TYPE_IO_1V8_ONLY), 3981 RK3588_PIN_BANK_FLAGS(4, 32, "gpio4", 3982 IOMUX_WIDTH_4BIT, PULL_TYPE_IO_1V8_ONLY), 3983 }; 3984 3985 static struct rockchip_pin_ctrl rk3588_pin_ctrl = { 3986 .pin_banks = rk3588_pin_banks, 3987 .nr_banks = ARRAY_SIZE(rk3588_pin_banks), 3988 .label = "RK3588-GPIO", 3989 .type = RK3588, 3990 .pull_calc_reg = rk3588_calc_pull_reg_and_bit, 3991 .drv_calc_reg = rk3588_calc_drv_reg_and_bit, 3992 .schmitt_calc_reg = rk3588_calc_schmitt_reg_and_bit, 3993 }; 3994 3995 static const struct of_device_id rockchip_pinctrl_dt_match[] = { 3996 { .compatible = "rockchip,px30-pinctrl", 3997 .data = &px30_pin_ctrl }, 3998 { .compatible = "rockchip,rv1108-pinctrl", 3999 .data = &rv1108_pin_ctrl }, 4000 { .compatible = "rockchip,rv1126-pinctrl", 4001 .data = &rv1126_pin_ctrl }, 4002 { .compatible = "rockchip,rk2928-pinctrl", 4003 .data = &rk2928_pin_ctrl }, 4004 { .compatible = "rockchip,rk3036-pinctrl", 4005 .data = &rk3036_pin_ctrl }, 4006 { .compatible = "rockchip,rk3066a-pinctrl", 4007 .data = &rk3066a_pin_ctrl }, 4008 { .compatible = "rockchip,rk3066b-pinctrl", 4009 .data = &rk3066b_pin_ctrl }, 4010 { .compatible = "rockchip,rk3128-pinctrl", 4011 .data = (void *)&rk3128_pin_ctrl }, 4012 { .compatible = "rockchip,rk3188-pinctrl", 4013 .data = &rk3188_pin_ctrl }, 4014 { .compatible = "rockchip,rk3228-pinctrl", 4015 .data = &rk3228_pin_ctrl }, 4016 { .compatible = "rockchip,rk3288-pinctrl", 4017 .data = &rk3288_pin_ctrl }, 4018 { .compatible = "rockchip,rk3308-pinctrl", 4019 .data = &rk3308_pin_ctrl }, 4020 { .compatible = "rockchip,rk3328-pinctrl", 4021 .data = &rk3328_pin_ctrl }, 4022 { .compatible = "rockchip,rk3368-pinctrl", 4023 .data = &rk3368_pin_ctrl }, 4024 { .compatible = "rockchip,rk3399-pinctrl", 4025 .data = &rk3399_pin_ctrl }, 4026 { .compatible = "rockchip,rk3568-pinctrl", 4027 .data = &rk3568_pin_ctrl }, 4028 { .compatible = "rockchip,rk3588-pinctrl", 4029 .data = &rk3588_pin_ctrl }, 4030 {}, 4031 }; 4032 4033 static struct platform_driver rockchip_pinctrl_driver = { 4034 .probe = rockchip_pinctrl_probe, 4035 .remove = rockchip_pinctrl_remove, 4036 .driver = { 4037 .name = "rockchip-pinctrl", 4038 .pm = &rockchip_pinctrl_dev_pm_ops, 4039 .of_match_table = rockchip_pinctrl_dt_match, 4040 }, 4041 }; 4042 4043 static int __init rockchip_pinctrl_drv_register(void) 4044 { 4045 return platform_driver_register(&rockchip_pinctrl_driver); 4046 } 4047 postcore_initcall(rockchip_pinctrl_drv_register); 4048 4049 static void __exit rockchip_pinctrl_drv_unregister(void) 4050 { 4051 platform_driver_unregister(&rockchip_pinctrl_driver); 4052 } 4053 module_exit(rockchip_pinctrl_drv_unregister); 4054 4055 MODULE_DESCRIPTION("ROCKCHIP Pin Controller Driver"); 4056 MODULE_LICENSE("GPL"); 4057 MODULE_ALIAS("platform:pinctrl-rockchip"); 4058 MODULE_DEVICE_TABLE(of, rockchip_pinctrl_dt_match); 4059