Skip to content

Commit 84e769e

Browse files
committed
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 <[email protected]>
2 parents 2ddb7c4 + 9e5889c commit 84e769e

File tree

1 file changed

+145
-19
lines changed

1 file changed

+145
-19
lines changed

drivers/pinctrl/renesas/pinctrl-rzg2l.c

Lines changed: 145 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#define PIN_CFG_FILCLKSEL BIT(12)
5858
#define PIN_CFG_IOLH_C BIT(13)
5959
#define PIN_CFG_SOFT_PS BIT(14)
60+
#define PIN_CFG_OEN BIT(15)
6061

6162
#define RZG2L_MPXED_COMMON_PIN_FUNCS(group) \
6263
(PIN_CFG_IOLH_##group | \
@@ -107,16 +108,18 @@
107108
#define IEN(off) (0x1800 + (off) * 8)
108109
#define ISEL(off) (0x2C00 + (off) * 8)
109110
#define SD_CH(off, ch) ((off) + (ch) * 4)
111+
#define ETH_POC(off, ch) ((off) + (ch) * 4)
110112
#define QSPI (0x3008)
113+
#define ETH_MODE (0x3018)
111114

115+
#define PVDD_2500 2 /* I/O domain voltage 2.5V */
112116
#define PVDD_1800 1 /* I/O domain voltage <= 1.8V */
113117
#define PVDD_3300 0 /* I/O domain voltage >= 3.3V */
114118

115119
#define PWPR_B0WI BIT(7) /* Bit Write Disable */
116120
#define PWPR_PFCWE BIT(6) /* PFC Register Write Enable */
117121

118122
#define PM_MASK 0x03
119-
#define PVDD_MASK 0x01
120123
#define PFC_MASK 0x07
121124
#define IEN_MASK 0x01
122125
#define IOLH_MASK 0x03
@@ -135,10 +138,12 @@
135138
* struct rzg2l_register_offsets - specific register offsets
136139
* @pwpr: PWPR register offset
137140
* @sd_ch: SD_CH register offset
141+
* @eth_poc: ETH_POC register offset
138142
*/
139143
struct rzg2l_register_offsets {
140144
u16 pwpr;
141145
u16 sd_ch;
146+
u16 eth_poc;
142147
};
143148

144149
/**
@@ -167,6 +172,8 @@ enum rzg2l_iolh_index {
167172
* @iolh_groupb_oi: IOLH group B output impedance specific values
168173
* @drive_strength_ua: drive strength in uA is supported (otherwise mA is supported)
169174
* @func_base: base number for port function (see register PFC)
175+
* @oen_max_pin: the maximum pin number supporting output enable
176+
* @oen_max_port: the maximum port number supporting output enable
170177
*/
171178
struct rzg2l_hwcfg {
172179
const struct rzg2l_register_offsets regs;
@@ -176,6 +183,8 @@ struct rzg2l_hwcfg {
176183
u16 iolh_groupb_oi[4];
177184
bool drive_strength_ua;
178185
u8 func_base;
186+
u8 oen_max_pin;
187+
u8 oen_max_port;
179188
};
180189

181190
struct rzg2l_dedicated_configs {
@@ -376,8 +385,11 @@ static int rzg2l_dt_subnode_to_map(struct pinctrl_dev *pctldev,
376385
goto done;
377386
}
378387

379-
if (num_pinmux)
388+
if (num_pinmux) {
380389
nmaps += 1;
390+
if (num_configs)
391+
nmaps += 1;
392+
}
381393

382394
if (num_pins)
383395
nmaps += num_pins;
@@ -462,6 +474,16 @@ static int rzg2l_dt_subnode_to_map(struct pinctrl_dev *pctldev,
462474
maps[idx].data.mux.function = name;
463475
idx++;
464476

477+
if (num_configs) {
478+
ret = rzg2l_map_add_config(&maps[idx], name,
479+
PIN_MAP_TYPE_CONFIGS_GROUP,
480+
configs, num_configs);
481+
if (ret < 0)
482+
goto remove_group;
483+
484+
idx++;
485+
}
486+
465487
dev_dbg(pctrl->dev, "Parsed %pOF with %d pins\n", np, num_pinmux);
466488
ret = 0;
467489
goto done;
@@ -591,6 +613,10 @@ static int rzg2l_caps_to_pwr_reg(const struct rzg2l_register_offsets *regs, u32
591613
return SD_CH(regs->sd_ch, 0);
592614
if (caps & PIN_CFG_IO_VMC_SD1)
593615
return SD_CH(regs->sd_ch, 1);
616+
if (caps & PIN_CFG_IO_VMC_ETH0)
617+
return ETH_POC(regs->eth_poc, 0);
618+
if (caps & PIN_CFG_IO_VMC_ETH1)
619+
return ETH_POC(regs->eth_poc, 1);
594620
if (caps & PIN_CFG_IO_VMC_QSPI)
595621
return QSPI;
596622

@@ -602,6 +628,7 @@ static int rzg2l_get_power_source(struct rzg2l_pinctrl *pctrl, u32 pin, u32 caps
602628
const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg;
603629
const struct rzg2l_register_offsets *regs = &hwcfg->regs;
604630
int pwr_reg;
631+
u8 val;
605632

606633
if (caps & PIN_CFG_SOFT_PS)
607634
return pctrl->settings[pin].power_source;
@@ -610,25 +637,51 @@ static int rzg2l_get_power_source(struct rzg2l_pinctrl *pctrl, u32 pin, u32 caps
610637
if (pwr_reg < 0)
611638
return pwr_reg;
612639

613-
return (readl(pctrl->base + pwr_reg) & PVDD_MASK) ? 1800 : 3300;
640+
val = readb(pctrl->base + pwr_reg);
641+
switch (val) {
642+
case PVDD_1800:
643+
return 1800;
644+
case PVDD_2500:
645+
return 2500;
646+
case PVDD_3300:
647+
return 3300;
648+
default:
649+
/* Should not happen. */
650+
return -EINVAL;
651+
}
614652
}
615653

616654
static int rzg2l_set_power_source(struct rzg2l_pinctrl *pctrl, u32 pin, u32 caps, u32 ps)
617655
{
618656
const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg;
619657
const struct rzg2l_register_offsets *regs = &hwcfg->regs;
620658
int pwr_reg;
659+
u8 val;
621660

622661
if (caps & PIN_CFG_SOFT_PS) {
623662
pctrl->settings[pin].power_source = ps;
624663
return 0;
625664
}
626665

666+
switch (ps) {
667+
case 1800:
668+
val = PVDD_1800;
669+
break;
670+
case 2500:
671+
val = PVDD_2500;
672+
break;
673+
case 3300:
674+
val = PVDD_3300;
675+
break;
676+
default:
677+
return -EINVAL;
678+
}
679+
627680
pwr_reg = rzg2l_caps_to_pwr_reg(regs, caps);
628681
if (pwr_reg < 0)
629682
return pwr_reg;
630683

631-
writel((ps == 1800) ? PVDD_1800 : PVDD_3300, pctrl->base + pwr_reg);
684+
writeb(val, pctrl->base + pwr_reg);
632685
pctrl->settings[pin].power_source = ps;
633686

634687
return 0;
@@ -735,6 +788,66 @@ static bool rzg2l_ds_is_supported(struct rzg2l_pinctrl *pctrl, u32 caps,
735788
return false;
736789
}
737790

791+
static bool rzg2l_oen_is_supported(u32 caps, u8 pin, u8 max_pin)
792+
{
793+
if (!(caps & PIN_CFG_OEN))
794+
return false;
795+
796+
if (pin > max_pin)
797+
return false;
798+
799+
return true;
800+
}
801+
802+
static u8 rzg2l_pin_to_oen_bit(u32 offset, u8 pin, u8 max_port)
803+
{
804+
if (pin)
805+
pin *= 2;
806+
807+
if (offset / RZG2L_PINS_PER_PORT == max_port)
808+
pin += 1;
809+
810+
return pin;
811+
}
812+
813+
static u32 rzg2l_read_oen(struct rzg2l_pinctrl *pctrl, u32 caps, u32 offset, u8 pin)
814+
{
815+
u8 max_port = pctrl->data->hwcfg->oen_max_port;
816+
u8 max_pin = pctrl->data->hwcfg->oen_max_pin;
817+
u8 bit;
818+
819+
if (!rzg2l_oen_is_supported(caps, pin, max_pin))
820+
return 0;
821+
822+
bit = rzg2l_pin_to_oen_bit(offset, pin, max_port);
823+
824+
return !(readb(pctrl->base + ETH_MODE) & BIT(bit));
825+
}
826+
827+
static int rzg2l_write_oen(struct rzg2l_pinctrl *pctrl, u32 caps, u32 offset, u8 pin, u8 oen)
828+
{
829+
u8 max_port = pctrl->data->hwcfg->oen_max_port;
830+
u8 max_pin = pctrl->data->hwcfg->oen_max_pin;
831+
unsigned long flags;
832+
u8 val, bit;
833+
834+
if (!rzg2l_oen_is_supported(caps, pin, max_pin))
835+
return -EINVAL;
836+
837+
bit = rzg2l_pin_to_oen_bit(offset, pin, max_port);
838+
839+
spin_lock_irqsave(&pctrl->lock, flags);
840+
val = readb(pctrl->base + ETH_MODE);
841+
if (oen)
842+
val &= ~BIT(bit);
843+
else
844+
val |= BIT(bit);
845+
writeb(val, pctrl->base + ETH_MODE);
846+
spin_unlock_irqrestore(&pctrl->lock, flags);
847+
848+
return 0;
849+
}
850+
738851
static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev,
739852
unsigned int _pin,
740853
unsigned long *config)
@@ -772,6 +885,12 @@ static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev,
772885
return -EINVAL;
773886
break;
774887

888+
case PIN_CONFIG_OUTPUT_ENABLE:
889+
arg = rzg2l_read_oen(pctrl, cfg, _pin, bit);
890+
if (!arg)
891+
return -EINVAL;
892+
break;
893+
775894
case PIN_CONFIG_POWER_SOURCE:
776895
ret = rzg2l_get_power_source(pctrl, _pin, cfg);
777896
if (ret < 0)
@@ -842,7 +961,7 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
842961
struct rzg2l_pinctrl_pin_settings settings = pctrl->settings[_pin];
843962
unsigned int *pin_data = pin->drv_data;
844963
enum pin_config_param param;
845-
unsigned int i;
964+
unsigned int i, arg, index;
846965
u32 cfg, off;
847966
int ret;
848967
u8 bit;
@@ -864,24 +983,28 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
864983
for (i = 0; i < num_configs; i++) {
865984
param = pinconf_to_config_param(_configs[i]);
866985
switch (param) {
867-
case PIN_CONFIG_INPUT_ENABLE: {
868-
unsigned int arg =
869-
pinconf_to_config_argument(_configs[i]);
986+
case PIN_CONFIG_INPUT_ENABLE:
987+
arg = pinconf_to_config_argument(_configs[i]);
870988

871989
if (!(cfg & PIN_CFG_IEN))
872990
return -EINVAL;
873991

874992
rzg2l_rmw_pin_config(pctrl, IEN(off), bit, IEN_MASK, !!arg);
875993
break;
876-
}
994+
995+
case PIN_CONFIG_OUTPUT_ENABLE:
996+
arg = pinconf_to_config_argument(_configs[i]);
997+
ret = rzg2l_write_oen(pctrl, cfg, _pin, bit, !!arg);
998+
if (ret)
999+
return ret;
1000+
break;
8771001

8781002
case PIN_CONFIG_POWER_SOURCE:
8791003
settings.power_source = pinconf_to_config_argument(_configs[i]);
8801004
break;
8811005

882-
case PIN_CONFIG_DRIVE_STRENGTH: {
883-
unsigned int arg = pinconf_to_config_argument(_configs[i]);
884-
unsigned int index;
1006+
case PIN_CONFIG_DRIVE_STRENGTH:
1007+
arg = pinconf_to_config_argument(_configs[i]);
8851008

8861009
if (!(cfg & PIN_CFG_IOLH_A) || hwcfg->drive_strength_ua)
8871010
return -EINVAL;
@@ -896,7 +1019,6 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
8961019

8971020
rzg2l_rmw_pin_config(pctrl, IOLH(off), bit, IOLH_MASK, index);
8981021
break;
899-
}
9001022

9011023
case PIN_CONFIG_DRIVE_STRENGTH_UA:
9021024
if (!(cfg & (PIN_CFG_IOLH_A | PIN_CFG_IOLH_B | PIN_CFG_IOLH_C)) ||
@@ -906,9 +1028,8 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
9061028
settings.drive_strength_ua = pinconf_to_config_argument(_configs[i]);
9071029
break;
9081030

909-
case PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS: {
910-
unsigned int arg = pinconf_to_config_argument(_configs[i]);
911-
unsigned int index;
1031+
case PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS:
1032+
arg = pinconf_to_config_argument(_configs[i]);
9121033

9131034
if (!(cfg & PIN_CFG_IOLH_B) || !hwcfg->iolh_groupb_oi[0])
9141035
return -EINVAL;
@@ -922,7 +1043,6 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
9221043

9231044
rzg2l_rmw_pin_config(pctrl, IOLH(off), bit, IOLH_MASK, index);
9241045
break;
925-
}
9261046

9271047
default:
9281048
return -EOPNOTSUPP;
@@ -1323,7 +1443,8 @@ static const u32 r9a07g043_gpio_configs[] = {
13231443
static const u32 r9a08g045_gpio_configs[] = {
13241444
RZG2L_GPIO_PORT_PACK(4, 0x20, RZG3S_MPXED_PIN_FUNCS(A)), /* P0 */
13251445
RZG2L_GPIO_PORT_PACK(5, 0x30, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C |
1326-
PIN_CFG_IO_VMC_ETH0)), /* P1 */
1446+
PIN_CFG_IO_VMC_ETH0)) |
1447+
PIN_CFG_OEN | PIN_CFG_IEN, /* P1 */
13271448
RZG2L_GPIO_PORT_PACK(4, 0x31, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C |
13281449
PIN_CFG_IO_VMC_ETH0)), /* P2 */
13291450
RZG2L_GPIO_PORT_PACK(4, 0x32, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C |
@@ -1333,7 +1454,8 @@ static const u32 r9a08g045_gpio_configs[] = {
13331454
RZG2L_GPIO_PORT_PACK(5, 0x21, RZG3S_MPXED_PIN_FUNCS(A)), /* P5 */
13341455
RZG2L_GPIO_PORT_PACK(5, 0x22, RZG3S_MPXED_PIN_FUNCS(A)), /* P6 */
13351456
RZG2L_GPIO_PORT_PACK(5, 0x34, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C |
1336-
PIN_CFG_IO_VMC_ETH1)), /* P7 */
1457+
PIN_CFG_IO_VMC_ETH1)) |
1458+
PIN_CFG_OEN | PIN_CFG_IEN, /* P7 */
13371459
RZG2L_GPIO_PORT_PACK(5, 0x35, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C |
13381460
PIN_CFG_IO_VMC_ETH1)), /* P8 */
13391461
RZG2L_GPIO_PORT_PACK(4, 0x36, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C |
@@ -1878,6 +2000,7 @@ static const struct rzg2l_hwcfg rzg2l_hwcfg = {
18782000
.regs = {
18792001
.pwpr = 0x3014,
18802002
.sd_ch = 0x3000,
2003+
.eth_poc = 0x300c,
18812004
},
18822005
.iolh_groupa_ua = {
18832006
/* 3v3 power source */
@@ -1890,6 +2013,7 @@ static const struct rzg2l_hwcfg rzg3s_hwcfg = {
18902013
.regs = {
18912014
.pwpr = 0x3000,
18922015
.sd_ch = 0x3004,
2016+
.eth_poc = 0x3010,
18932017
},
18942018
.iolh_groupa_ua = {
18952019
/* 1v8 power source */
@@ -1913,6 +2037,8 @@ static const struct rzg2l_hwcfg rzg3s_hwcfg = {
19132037
},
19142038
.drive_strength_ua = true,
19152039
.func_base = 1,
2040+
.oen_max_pin = 1, /* Pin 1 of P0 and P7 is the maximum OEN pin. */
2041+
.oen_max_port = 7, /* P7_1 is the maximum OEN port. */
19162042
};
19172043

19182044
static struct rzg2l_pinctrl_data r9a07g043_data = {

0 commit comments

Comments
 (0)