Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'renesas-pinctrl-for-v6.8-tag2' of git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers into devel

pinctrl: renesas: Updates for v6.8 (take two)

- Add pinmux groups, power source, and input/output enable support for
Ethernet pins on RZ/G2L SoCs,
- Miscellaneous fixes and improvements.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

+145 -19
+145 -19
drivers/pinctrl/renesas/pinctrl-rzg2l.c
··· 57 57 #define PIN_CFG_FILCLKSEL BIT(12) 58 58 #define PIN_CFG_IOLH_C BIT(13) 59 59 #define PIN_CFG_SOFT_PS BIT(14) 60 + #define PIN_CFG_OEN BIT(15) 60 61 61 62 #define RZG2L_MPXED_COMMON_PIN_FUNCS(group) \ 62 63 (PIN_CFG_IOLH_##group | \ ··· 108 107 #define IEN(off) (0x1800 + (off) * 8) 109 108 #define ISEL(off) (0x2C00 + (off) * 8) 110 109 #define SD_CH(off, ch) ((off) + (ch) * 4) 110 + #define ETH_POC(off, ch) ((off) + (ch) * 4) 111 111 #define QSPI (0x3008) 112 + #define ETH_MODE (0x3018) 112 113 114 + #define PVDD_2500 2 /* I/O domain voltage 2.5V */ 113 115 #define PVDD_1800 1 /* I/O domain voltage <= 1.8V */ 114 116 #define PVDD_3300 0 /* I/O domain voltage >= 3.3V */ 115 117 ··· 120 116 #define PWPR_PFCWE BIT(6) /* PFC Register Write Enable */ 121 117 122 118 #define PM_MASK 0x03 123 - #define PVDD_MASK 0x01 124 119 #define PFC_MASK 0x07 125 120 #define IEN_MASK 0x01 126 121 #define IOLH_MASK 0x03 ··· 138 135 * struct rzg2l_register_offsets - specific register offsets 139 136 * @pwpr: PWPR register offset 140 137 * @sd_ch: SD_CH register offset 138 + * @eth_poc: ETH_POC register offset 141 139 */ 142 140 struct rzg2l_register_offsets { 143 141 u16 pwpr; 144 142 u16 sd_ch; 143 + u16 eth_poc; 145 144 }; 146 145 147 146 /** ··· 172 167 * @iolh_groupb_oi: IOLH group B output impedance specific values 173 168 * @drive_strength_ua: drive strength in uA is supported (otherwise mA is supported) 174 169 * @func_base: base number for port function (see register PFC) 170 + * @oen_max_pin: the maximum pin number supporting output enable 171 + * @oen_max_port: the maximum port number supporting output enable 175 172 */ 176 173 struct rzg2l_hwcfg { 177 174 const struct rzg2l_register_offsets regs; ··· 183 176 u16 iolh_groupb_oi[4]; 184 177 bool drive_strength_ua; 185 178 u8 func_base; 179 + u8 oen_max_pin; 180 + u8 oen_max_port; 186 181 }; 187 182 188 183 struct rzg2l_dedicated_configs { ··· 385 376 goto done; 386 377 } 387 378 388 - if (num_pinmux) 379 + if (num_pinmux) { 389 380 nmaps += 1; 381 + if (num_configs) 382 + nmaps += 1; 383 + } 390 384 391 385 if (num_pins) 392 386 nmaps += num_pins; ··· 473 461 maps[idx].data.mux.group = name; 474 462 maps[idx].data.mux.function = name; 475 463 idx++; 464 + 465 + if (num_configs) { 466 + ret = rzg2l_map_add_config(&maps[idx], name, 467 + PIN_MAP_TYPE_CONFIGS_GROUP, 468 + configs, num_configs); 469 + if (ret < 0) 470 + goto remove_group; 471 + 472 + idx++; 473 + } 476 474 477 475 dev_dbg(pctrl->dev, "Parsed %pOF with %d pins\n", np, num_pinmux); 478 476 ret = 0; ··· 613 591 return SD_CH(regs->sd_ch, 0); 614 592 if (caps & PIN_CFG_IO_VMC_SD1) 615 593 return SD_CH(regs->sd_ch, 1); 594 + if (caps & PIN_CFG_IO_VMC_ETH0) 595 + return ETH_POC(regs->eth_poc, 0); 596 + if (caps & PIN_CFG_IO_VMC_ETH1) 597 + return ETH_POC(regs->eth_poc, 1); 616 598 if (caps & PIN_CFG_IO_VMC_QSPI) 617 599 return QSPI; 618 600 ··· 628 602 const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg; 629 603 const struct rzg2l_register_offsets *regs = &hwcfg->regs; 630 604 int pwr_reg; 605 + u8 val; 631 606 632 607 if (caps & PIN_CFG_SOFT_PS) 633 608 return pctrl->settings[pin].power_source; ··· 637 610 if (pwr_reg < 0) 638 611 return pwr_reg; 639 612 640 - return (readl(pctrl->base + pwr_reg) & PVDD_MASK) ? 1800 : 3300; 613 + val = readb(pctrl->base + pwr_reg); 614 + switch (val) { 615 + case PVDD_1800: 616 + return 1800; 617 + case PVDD_2500: 618 + return 2500; 619 + case PVDD_3300: 620 + return 3300; 621 + default: 622 + /* Should not happen. */ 623 + return -EINVAL; 624 + } 641 625 } 642 626 643 627 static int rzg2l_set_power_source(struct rzg2l_pinctrl *pctrl, u32 pin, u32 caps, u32 ps) ··· 656 618 const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg; 657 619 const struct rzg2l_register_offsets *regs = &hwcfg->regs; 658 620 int pwr_reg; 621 + u8 val; 659 622 660 623 if (caps & PIN_CFG_SOFT_PS) { 661 624 pctrl->settings[pin].power_source = ps; 662 625 return 0; 663 626 } 664 627 628 + switch (ps) { 629 + case 1800: 630 + val = PVDD_1800; 631 + break; 632 + case 2500: 633 + val = PVDD_2500; 634 + break; 635 + case 3300: 636 + val = PVDD_3300; 637 + break; 638 + default: 639 + return -EINVAL; 640 + } 641 + 665 642 pwr_reg = rzg2l_caps_to_pwr_reg(regs, caps); 666 643 if (pwr_reg < 0) 667 644 return pwr_reg; 668 645 669 - writel((ps == 1800) ? PVDD_1800 : PVDD_3300, pctrl->base + pwr_reg); 646 + writeb(val, pctrl->base + pwr_reg); 670 647 pctrl->settings[pin].power_source = ps; 671 648 672 649 return 0; ··· 788 735 return false; 789 736 } 790 737 738 + static bool rzg2l_oen_is_supported(u32 caps, u8 pin, u8 max_pin) 739 + { 740 + if (!(caps & PIN_CFG_OEN)) 741 + return false; 742 + 743 + if (pin > max_pin) 744 + return false; 745 + 746 + return true; 747 + } 748 + 749 + static u8 rzg2l_pin_to_oen_bit(u32 offset, u8 pin, u8 max_port) 750 + { 751 + if (pin) 752 + pin *= 2; 753 + 754 + if (offset / RZG2L_PINS_PER_PORT == max_port) 755 + pin += 1; 756 + 757 + return pin; 758 + } 759 + 760 + static u32 rzg2l_read_oen(struct rzg2l_pinctrl *pctrl, u32 caps, u32 offset, u8 pin) 761 + { 762 + u8 max_port = pctrl->data->hwcfg->oen_max_port; 763 + u8 max_pin = pctrl->data->hwcfg->oen_max_pin; 764 + u8 bit; 765 + 766 + if (!rzg2l_oen_is_supported(caps, pin, max_pin)) 767 + return 0; 768 + 769 + bit = rzg2l_pin_to_oen_bit(offset, pin, max_port); 770 + 771 + return !(readb(pctrl->base + ETH_MODE) & BIT(bit)); 772 + } 773 + 774 + static int rzg2l_write_oen(struct rzg2l_pinctrl *pctrl, u32 caps, u32 offset, u8 pin, u8 oen) 775 + { 776 + u8 max_port = pctrl->data->hwcfg->oen_max_port; 777 + u8 max_pin = pctrl->data->hwcfg->oen_max_pin; 778 + unsigned long flags; 779 + u8 val, bit; 780 + 781 + if (!rzg2l_oen_is_supported(caps, pin, max_pin)) 782 + return -EINVAL; 783 + 784 + bit = rzg2l_pin_to_oen_bit(offset, pin, max_port); 785 + 786 + spin_lock_irqsave(&pctrl->lock, flags); 787 + val = readb(pctrl->base + ETH_MODE); 788 + if (oen) 789 + val &= ~BIT(bit); 790 + else 791 + val |= BIT(bit); 792 + writeb(val, pctrl->base + ETH_MODE); 793 + spin_unlock_irqrestore(&pctrl->lock, flags); 794 + 795 + return 0; 796 + } 797 + 791 798 static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev, 792 799 unsigned int _pin, 793 800 unsigned long *config) ··· 881 768 if (!(cfg & PIN_CFG_IEN)) 882 769 return -EINVAL; 883 770 arg = rzg2l_read_pin_config(pctrl, IEN(off), bit, IEN_MASK); 771 + if (!arg) 772 + return -EINVAL; 773 + break; 774 + 775 + case PIN_CONFIG_OUTPUT_ENABLE: 776 + arg = rzg2l_read_oen(pctrl, cfg, _pin, bit); 884 777 if (!arg) 885 778 return -EINVAL; 886 779 break; ··· 961 842 struct rzg2l_pinctrl_pin_settings settings = pctrl->settings[_pin]; 962 843 unsigned int *pin_data = pin->drv_data; 963 844 enum pin_config_param param; 964 - unsigned int i; 845 + unsigned int i, arg, index; 965 846 u32 cfg, off; 966 847 int ret; 967 848 u8 bit; ··· 983 864 for (i = 0; i < num_configs; i++) { 984 865 param = pinconf_to_config_param(_configs[i]); 985 866 switch (param) { 986 - case PIN_CONFIG_INPUT_ENABLE: { 987 - unsigned int arg = 988 - pinconf_to_config_argument(_configs[i]); 867 + case PIN_CONFIG_INPUT_ENABLE: 868 + arg = pinconf_to_config_argument(_configs[i]); 989 869 990 870 if (!(cfg & PIN_CFG_IEN)) 991 871 return -EINVAL; 992 872 993 873 rzg2l_rmw_pin_config(pctrl, IEN(off), bit, IEN_MASK, !!arg); 994 874 break; 995 - } 875 + 876 + case PIN_CONFIG_OUTPUT_ENABLE: 877 + arg = pinconf_to_config_argument(_configs[i]); 878 + ret = rzg2l_write_oen(pctrl, cfg, _pin, bit, !!arg); 879 + if (ret) 880 + return ret; 881 + break; 996 882 997 883 case PIN_CONFIG_POWER_SOURCE: 998 884 settings.power_source = pinconf_to_config_argument(_configs[i]); 999 885 break; 1000 886 1001 - case PIN_CONFIG_DRIVE_STRENGTH: { 1002 - unsigned int arg = pinconf_to_config_argument(_configs[i]); 1003 - unsigned int index; 887 + case PIN_CONFIG_DRIVE_STRENGTH: 888 + arg = pinconf_to_config_argument(_configs[i]); 1004 889 1005 890 if (!(cfg & PIN_CFG_IOLH_A) || hwcfg->drive_strength_ua) 1006 891 return -EINVAL; ··· 1019 896 1020 897 rzg2l_rmw_pin_config(pctrl, IOLH(off), bit, IOLH_MASK, index); 1021 898 break; 1022 - } 1023 899 1024 900 case PIN_CONFIG_DRIVE_STRENGTH_UA: 1025 901 if (!(cfg & (PIN_CFG_IOLH_A | PIN_CFG_IOLH_B | PIN_CFG_IOLH_C)) || ··· 1028 906 settings.drive_strength_ua = pinconf_to_config_argument(_configs[i]); 1029 907 break; 1030 908 1031 - case PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS: { 1032 - unsigned int arg = pinconf_to_config_argument(_configs[i]); 1033 - unsigned int index; 909 + case PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS: 910 + arg = pinconf_to_config_argument(_configs[i]); 1034 911 1035 912 if (!(cfg & PIN_CFG_IOLH_B) || !hwcfg->iolh_groupb_oi[0]) 1036 913 return -EINVAL; ··· 1043 922 1044 923 rzg2l_rmw_pin_config(pctrl, IOLH(off), bit, IOLH_MASK, index); 1045 924 break; 1046 - } 1047 925 1048 926 default: 1049 927 return -EOPNOTSUPP; ··· 1443 1323 static const u32 r9a08g045_gpio_configs[] = { 1444 1324 RZG2L_GPIO_PORT_PACK(4, 0x20, RZG3S_MPXED_PIN_FUNCS(A)), /* P0 */ 1445 1325 RZG2L_GPIO_PORT_PACK(5, 0x30, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C | 1446 - PIN_CFG_IO_VMC_ETH0)), /* P1 */ 1326 + PIN_CFG_IO_VMC_ETH0)) | 1327 + PIN_CFG_OEN | PIN_CFG_IEN, /* P1 */ 1447 1328 RZG2L_GPIO_PORT_PACK(4, 0x31, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C | 1448 1329 PIN_CFG_IO_VMC_ETH0)), /* P2 */ 1449 1330 RZG2L_GPIO_PORT_PACK(4, 0x32, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C | ··· 1454 1333 RZG2L_GPIO_PORT_PACK(5, 0x21, RZG3S_MPXED_PIN_FUNCS(A)), /* P5 */ 1455 1334 RZG2L_GPIO_PORT_PACK(5, 0x22, RZG3S_MPXED_PIN_FUNCS(A)), /* P6 */ 1456 1335 RZG2L_GPIO_PORT_PACK(5, 0x34, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C | 1457 - PIN_CFG_IO_VMC_ETH1)), /* P7 */ 1336 + PIN_CFG_IO_VMC_ETH1)) | 1337 + PIN_CFG_OEN | PIN_CFG_IEN, /* P7 */ 1458 1338 RZG2L_GPIO_PORT_PACK(5, 0x35, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C | 1459 1339 PIN_CFG_IO_VMC_ETH1)), /* P8 */ 1460 1340 RZG2L_GPIO_PORT_PACK(4, 0x36, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C | ··· 2000 1878 .regs = { 2001 1879 .pwpr = 0x3014, 2002 1880 .sd_ch = 0x3000, 1881 + .eth_poc = 0x300c, 2003 1882 }, 2004 1883 .iolh_groupa_ua = { 2005 1884 /* 3v3 power source */ ··· 2013 1890 .regs = { 2014 1891 .pwpr = 0x3000, 2015 1892 .sd_ch = 0x3004, 1893 + .eth_poc = 0x3010, 2016 1894 }, 2017 1895 .iolh_groupa_ua = { 2018 1896 /* 1v8 power source */ ··· 2037 1913 }, 2038 1914 .drive_strength_ua = true, 2039 1915 .func_base = 1, 1916 + .oen_max_pin = 1, /* Pin 1 of P0 and P7 is the maximum OEN pin. */ 1917 + .oen_max_port = 7, /* P7_1 is the maximum OEN port. */ 2040 1918 }; 2041 1919 2042 1920 static struct rzg2l_pinctrl_data r9a07g043_data = {