Index | Thread | Search

From:
Mark Kettenis <mark.kettenis@xs4all.nl>
Subject:
Add RK3588 support to rkusbphy(4)
To:
dlg@openbsd.org, patrick@openbsd.org, brad@comstyle.com
Cc:
tech@openbsd.org
Date:
Fri, 14 Jun 2024 00:23:50 +0200

Download raw body.

Thread
While trying a more recent U-Boot version, I noticed a hang after
ohci(4) attached.  After bisecting U-Boot, the breakage started to
happen after some fixes to the U-Boot driver for the USB PHY.  Adding
support for the RK3588 SoC fixes the issue.

On the RK3588 there is no "rockchip,usbgrf" property.  Instead we need
to use the regmap provided by the parent.  Also since the PHYs are
dedicated to OTG or host ports, there is only one otg-port or
host-port subnode, but not both.  So don't warn if either of those is
missing.

ok?


Index: dev/fdt/rkusbphy.c
===================================================================
RCS file: /cvs/src/sys/dev/fdt/rkusbphy.c,v
retrieving revision 1.4
diff -u -p -r1.4 rkusbphy.c
--- dev/fdt/rkusbphy.c	29 Sep 2023 17:30:35 -0000	1.4
+++ dev/fdt/rkusbphy.c	13 Jun 2024 22:18:06 -0000
@@ -90,6 +90,38 @@ static const struct rkusbphy_chip rkusbp
 	},
 };
 
+static const struct rkusbphy_regs rkusbphy_rk3588_regs = {
+	/*				shift,	mask,	set */
+	.clk_enable =	{ 0x0000,	0,	0x1,	0x0 },
+
+	.otg = {
+		.phy_enable =	{ 0x000c,	11,	0x1,	0x0 },
+	},
+
+	.host = {
+		.phy_enable =	{ 0x0008,	2,	0x1,	0x0 },
+	},
+};
+
+static const struct rkusbphy_chip rkusbphy_rk3588[] = {
+	{
+		.c_base_addr = 0x0000,
+		.c_regs = &rkusbphy_rk3588_regs,
+	},
+	{
+		.c_base_addr = 0x4000,
+		.c_regs = &rkusbphy_rk3588_regs,
+	},
+	{
+		.c_base_addr = 0x8000,
+		.c_regs = &rkusbphy_rk3588_regs,
+	},
+	{
+		.c_base_addr = 0xc000,
+		.c_regs = &rkusbphy_rk3588_regs,
+	},
+};
+
 /*
  * driver stuff
  */
@@ -159,6 +191,7 @@ struct rkusbphy_id {
 
 static const struct rkusbphy_id rkusbphy_ids[] = {
 	RKUSBPHY_ID("rockchip,rk3568-usb2phy", rkusbphy_rk3568),
+	RKUSBPHY_ID("rockchip,rk3588-usb2phy", rkusbphy_rk3588),
 };
 
 static const struct rkusbphy_id *
@@ -213,7 +246,10 @@ rkusbphy_attach(struct device *parent, s
 	sc->sc_node = faa->fa_node;
 
 	grfph = OF_getpropint(sc->sc_node, "rockchip,usbgrf", 0);
-	sc->sc_grf = regmap_byphandle(grfph);
+	if (grfph)
+		sc->sc_grf = regmap_byphandle(grfph);
+	else
+		sc->sc_grf = regmap_bynode(OF_parent(faa->fa_node));
 	if (sc->sc_grf == NULL) {
 		printf("%s: rockchip,usbgrf 0x%x not found\n", DEVNAME(sc),
 		    grfph);
@@ -267,10 +303,8 @@ rkusbphy_register(struct rkusbphy_softc 
 	int node;
 
 	node = OF_getnodebyname(sc->sc_node, pc->pc_name);
-	if (node == 0) {
-		printf("%s: cannot find %s\n", DEVNAME(sc), pc->pc_name);
+	if (node == 0)
 		return;
-	}
 
 	if (OF_getprop(node, "status", status, sizeof(status)) > 0 &&
 	    strcmp(status, "disabled") == 0)