Skip to content

Commit 19d4bce

Browse files
prabhakarladgeertu
authored andcommitted
pinctrl: renesas: rzg2l: Add support for pull-up/down
Add support to configure bias-disable, bias-pull-up, and bias-pull-down properties of the pin. Two new function pointers, hw_to_bias_param() and bias_param_to_hw(), are introduced in the struct rzg2l_pinctrl_data to configure bias settings, as the values in the PUPD register differ when compared to the RZ/G2L family and the RZ/V2H(P) SoC. Value | RZ/G2L | RZ/V2H --------------------------------- 00b: | Bias Disabled | Pull up/down disabled 01b: | Pull-up | Pull up/down disabled 10b: | Pull-down | Pull-down 11b: | Prohibited | Pull-up Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Link: https://lore.kernel.org/r/20240530173857.164073-12-prabhakar.mahadev-lad.rj@bp.renesas.com Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
1 parent b588b53 commit 19d4bce

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

drivers/pinctrl/renesas/pinctrl-rzg2l.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
#define IOLH(off) (0x1000 + (off) * 8)
130130
#define SR(off) (0x1400 + (off) * 8)
131131
#define IEN(off) (0x1800 + (off) * 8)
132+
#define PUPD(off) (0x1C00 + (off) * 8)
132133
#define ISEL(off) (0x2C00 + (off) * 8)
133134
#define SD_CH(off, ch) ((off) + (ch) * 4)
134135
#define ETH_POC(off, ch) ((off) + (ch) * 4)
@@ -147,6 +148,7 @@
147148
#define IEN_MASK 0x01
148149
#define IOLH_MASK 0x03
149150
#define SR_MASK 0x01
151+
#define PUPD_MASK 0x03
150152

151153
#define PM_INPUT 0x1
152154
#define PM_OUTPUT 0x2
@@ -259,6 +261,8 @@ struct rzg2l_pinctrl_data {
259261
void (*pmc_writeb)(struct rzg2l_pinctrl *pctrl, u8 val, u16 offset);
260262
u32 (*oen_read)(struct rzg2l_pinctrl *pctrl, u32 caps, u32 offset, u8 pin);
261263
int (*oen_write)(struct rzg2l_pinctrl *pctrl, u32 caps, u32 offset, u8 pin, u8 oen);
264+
int (*hw_to_bias_param)(unsigned int val);
265+
int (*bias_param_to_hw)(enum pin_config_param param);
262266
};
263267

264268
/**
@@ -1000,6 +1004,38 @@ static int rzg2l_write_oen(struct rzg2l_pinctrl *pctrl, u32 caps, u32 offset, u8
10001004
return 0;
10011005
}
10021006

1007+
static int rzg2l_hw_to_bias_param(unsigned int bias)
1008+
{
1009+
switch (bias) {
1010+
case 0:
1011+
return PIN_CONFIG_BIAS_DISABLE;
1012+
case 1:
1013+
return PIN_CONFIG_BIAS_PULL_UP;
1014+
case 2:
1015+
return PIN_CONFIG_BIAS_PULL_DOWN;
1016+
default:
1017+
break;
1018+
}
1019+
1020+
return -EINVAL;
1021+
}
1022+
1023+
static int rzg2l_bias_param_to_hw(enum pin_config_param param)
1024+
{
1025+
switch (param) {
1026+
case PIN_CONFIG_BIAS_DISABLE:
1027+
return 0;
1028+
case PIN_CONFIG_BIAS_PULL_UP:
1029+
return 1;
1030+
case PIN_CONFIG_BIAS_PULL_DOWN:
1031+
return 2;
1032+
default:
1033+
break;
1034+
}
1035+
1036+
return -EINVAL;
1037+
}
1038+
10031039
static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev,
10041040
unsigned int _pin,
10051041
unsigned long *config)
@@ -1058,6 +1094,23 @@ static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev,
10581094
arg = rzg2l_read_pin_config(pctrl, SR(off), bit, SR_MASK);
10591095
break;
10601096

1097+
case PIN_CONFIG_BIAS_DISABLE:
1098+
case PIN_CONFIG_BIAS_PULL_UP:
1099+
case PIN_CONFIG_BIAS_PULL_DOWN:
1100+
if (!(cfg & PIN_CFG_PUPD))
1101+
return -EINVAL;
1102+
1103+
arg = rzg2l_read_pin_config(pctrl, PUPD(off), bit, PUPD_MASK);
1104+
ret = pctrl->data->hw_to_bias_param(arg);
1105+
if (ret < 0)
1106+
return ret;
1107+
1108+
if (ret != param)
1109+
return -EINVAL;
1110+
/* for PIN_CONFIG_BIAS_PULL_UP/DOWN when enabled we just return 1 */
1111+
arg = 1;
1112+
break;
1113+
10611114
case PIN_CONFIG_DRIVE_STRENGTH: {
10621115
unsigned int index;
10631116

@@ -1173,6 +1226,19 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
11731226
rzg2l_rmw_pin_config(pctrl, SR(off), bit, SR_MASK, arg);
11741227
break;
11751228

1229+
case PIN_CONFIG_BIAS_DISABLE:
1230+
case PIN_CONFIG_BIAS_PULL_UP:
1231+
case PIN_CONFIG_BIAS_PULL_DOWN:
1232+
if (!(cfg & PIN_CFG_PUPD))
1233+
return -EINVAL;
1234+
1235+
ret = pctrl->data->bias_param_to_hw(param);
1236+
if (ret < 0)
1237+
return ret;
1238+
1239+
rzg2l_rmw_pin_config(pctrl, PUPD(off), bit, PUPD_MASK, ret);
1240+
break;
1241+
11761242
case PIN_CONFIG_DRIVE_STRENGTH:
11771243
arg = pinconf_to_config_argument(_configs[i]);
11781244

@@ -2645,6 +2711,8 @@ static struct rzg2l_pinctrl_data r9a07g043_data = {
26452711
.pmc_writeb = &rzg2l_pmc_writeb,
26462712
.oen_read = &rzg2l_read_oen,
26472713
.oen_write = &rzg2l_write_oen,
2714+
.hw_to_bias_param = &rzg2l_hw_to_bias_param,
2715+
.bias_param_to_hw = &rzg2l_bias_param_to_hw,
26482716
};
26492717

26502718
static struct rzg2l_pinctrl_data r9a07g044_data = {
@@ -2660,6 +2728,8 @@ static struct rzg2l_pinctrl_data r9a07g044_data = {
26602728
.pmc_writeb = &rzg2l_pmc_writeb,
26612729
.oen_read = &rzg2l_read_oen,
26622730
.oen_write = &rzg2l_write_oen,
2731+
.hw_to_bias_param = &rzg2l_hw_to_bias_param,
2732+
.bias_param_to_hw = &rzg2l_bias_param_to_hw,
26632733
};
26642734

26652735
static struct rzg2l_pinctrl_data r9a08g045_data = {
@@ -2674,6 +2744,8 @@ static struct rzg2l_pinctrl_data r9a08g045_data = {
26742744
.pmc_writeb = &rzg2l_pmc_writeb,
26752745
.oen_read = &rzg2l_read_oen,
26762746
.oen_write = &rzg2l_write_oen,
2747+
.hw_to_bias_param = &rzg2l_hw_to_bias_param,
2748+
.bias_param_to_hw = &rzg2l_bias_param_to_hw,
26772749
};
26782750

26792751
static const struct of_device_id rzg2l_pinctrl_of_table[] = {

0 commit comments

Comments
 (0)