Skip to content

Commit 28b05a6

Browse files
jayxurockchipmmind
authored andcommitted
soc: rockchip: io-domain: add rk3568 support
The io-domain registers on RK3568 SoCs have three separated bits to enable/disable the 1.8v/2.5v/3.3v power. This patch make the write to be a operation, allow rk3568 uses a private register set function. Since the 2.5v mode hasn't been fully validated yet, the driver only sets 1.8v [enable] + 3.3v [disable] for 1.8v mode 1.8v [disable] + 3.3v [enable] for 3.3v mode There is not register order requirement which has been cleared by our IC team. For future reference the full usage matrix including the 2.5V setting is: case V33 V25 V18 result 0 0 0 0 IO safe, but cannot work 1 0 0 1 IO require 1.8V, should < 1.98V, otherwise IO may damage 2 0 1 0 IO require 2.5V, should < 2.75V, otherwise IO may damage 3 0 1 1 Invalid state, should avoid 4 1 0 0 IO require 3.3V, should < 3.63V, otherwise IO may damage 5 1 0 1 IO require 1.8V, should < 1.98V, otherwise IO may damage 6 1 1 0 IO require 2.5V, should < 2.75V, otherwise IO may damage 7 1 1 1 Invalid state, should avoid Signed-off-by: Jianqun Xu <[email protected]> Tested-by: Peter Geis <[email protected]> [added mode clarification from Jay] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Heiko Stuebner <[email protected]>
1 parent fadbd4e commit 28b05a6

File tree

1 file changed

+80
-8
lines changed

1 file changed

+80
-8
lines changed

drivers/soc/rockchip/io-domain.c

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@
5151
#define RK3399_PMUGRF_CON0_VSEL BIT(8)
5252
#define RK3399_PMUGRF_VSEL_SUPPLY_NUM 9
5353

54-
struct rockchip_iodomain;
54+
#define RK3568_PMU_GRF_IO_VSEL0 (0x0140)
55+
#define RK3568_PMU_GRF_IO_VSEL1 (0x0144)
56+
#define RK3568_PMU_GRF_IO_VSEL2 (0x0148)
5557

56-
struct rockchip_iodomain_soc_data {
57-
int grf_offset;
58-
const char *supply_names[MAX_SUPPLIES];
59-
void (*init)(struct rockchip_iodomain *iod);
60-
};
58+
struct rockchip_iodomain;
6159

6260
struct rockchip_iodomain_supply {
6361
struct rockchip_iodomain *iod;
@@ -66,13 +64,62 @@ struct rockchip_iodomain_supply {
6664
int idx;
6765
};
6866

67+
struct rockchip_iodomain_soc_data {
68+
int grf_offset;
69+
const char *supply_names[MAX_SUPPLIES];
70+
void (*init)(struct rockchip_iodomain *iod);
71+
int (*write)(struct rockchip_iodomain_supply *supply, int uV);
72+
};
73+
6974
struct rockchip_iodomain {
7075
struct device *dev;
7176
struct regmap *grf;
7277
const struct rockchip_iodomain_soc_data *soc_data;
7378
struct rockchip_iodomain_supply supplies[MAX_SUPPLIES];
79+
int (*write)(struct rockchip_iodomain_supply *supply, int uV);
7480
};
7581

82+
static int rk3568_iodomain_write(struct rockchip_iodomain_supply *supply, int uV)
83+
{
84+
struct rockchip_iodomain *iod = supply->iod;
85+
u32 is_3v3 = uV > MAX_VOLTAGE_1_8;
86+
u32 val0, val1;
87+
int b;
88+
89+
switch (supply->idx) {
90+
case 0: /* pmuio1 */
91+
break;
92+
case 1: /* pmuio2 */
93+
b = supply->idx;
94+
val0 = BIT(16 + b) | (is_3v3 ? 0 : BIT(b));
95+
b = supply->idx + 4;
96+
val1 = BIT(16 + b) | (is_3v3 ? BIT(b) : 0);
97+
98+
regmap_write(iod->grf, RK3568_PMU_GRF_IO_VSEL2, val0);
99+
regmap_write(iod->grf, RK3568_PMU_GRF_IO_VSEL2, val1);
100+
break;
101+
case 3: /* vccio2 */
102+
break;
103+
case 2: /* vccio1 */
104+
case 4: /* vccio3 */
105+
case 5: /* vccio4 */
106+
case 6: /* vccio5 */
107+
case 7: /* vccio6 */
108+
case 8: /* vccio7 */
109+
b = supply->idx - 1;
110+
val0 = BIT(16 + b) | (is_3v3 ? 0 : BIT(b));
111+
val1 = BIT(16 + b) | (is_3v3 ? BIT(b) : 0);
112+
113+
regmap_write(iod->grf, RK3568_PMU_GRF_IO_VSEL0, val0);
114+
regmap_write(iod->grf, RK3568_PMU_GRF_IO_VSEL1, val1);
115+
break;
116+
default:
117+
return -EINVAL;
118+
};
119+
120+
return 0;
121+
}
122+
76123
static int rockchip_iodomain_write(struct rockchip_iodomain_supply *supply,
77124
int uV)
78125
{
@@ -136,7 +183,7 @@ static int rockchip_iodomain_notify(struct notifier_block *nb,
136183
return NOTIFY_BAD;
137184
}
138185

139-
ret = rockchip_iodomain_write(supply, uV);
186+
ret = supply->iod->write(supply, uV);
140187
if (ret && event == REGULATOR_EVENT_PRE_VOLTAGE_CHANGE)
141188
return NOTIFY_BAD;
142189

@@ -398,6 +445,22 @@ static const struct rockchip_iodomain_soc_data soc_data_rk3399_pmu = {
398445
.init = rk3399_pmu_iodomain_init,
399446
};
400447

448+
static const struct rockchip_iodomain_soc_data soc_data_rk3568_pmu = {
449+
.grf_offset = 0x140,
450+
.supply_names = {
451+
"pmuio1",
452+
"pmuio2",
453+
"vccio1",
454+
"vccio2",
455+
"vccio3",
456+
"vccio4",
457+
"vccio5",
458+
"vccio6",
459+
"vccio7",
460+
},
461+
.write = rk3568_iodomain_write,
462+
};
463+
401464
static const struct rockchip_iodomain_soc_data soc_data_rv1108 = {
402465
.grf_offset = 0x404,
403466
.supply_names = {
@@ -469,6 +532,10 @@ static const struct of_device_id rockchip_iodomain_match[] = {
469532
.compatible = "rockchip,rk3399-pmu-io-voltage-domain",
470533
.data = &soc_data_rk3399_pmu
471534
},
535+
{
536+
.compatible = "rockchip,rk3568-pmu-io-voltage-domain",
537+
.data = &soc_data_rk3568_pmu
538+
},
472539
{
473540
.compatible = "rockchip,rv1108-io-voltage-domain",
474541
.data = &soc_data_rv1108
@@ -502,6 +569,11 @@ static int rockchip_iodomain_probe(struct platform_device *pdev)
502569
match = of_match_node(rockchip_iodomain_match, np);
503570
iod->soc_data = match->data;
504571

572+
if (iod->soc_data->write)
573+
iod->write = iod->soc_data->write;
574+
else
575+
iod->write = rockchip_iodomain_write;
576+
505577
parent = pdev->dev.parent;
506578
if (parent && parent->of_node) {
507579
iod->grf = syscon_node_to_regmap(parent->of_node);
@@ -562,7 +634,7 @@ static int rockchip_iodomain_probe(struct platform_device *pdev)
562634
supply->reg = reg;
563635
supply->nb.notifier_call = rockchip_iodomain_notify;
564636

565-
ret = rockchip_iodomain_write(supply, uV);
637+
ret = iod->write(supply, uV);
566638
if (ret) {
567639
supply->reg = NULL;
568640
goto unreg_notify;

0 commit comments

Comments
 (0)