Skip to contentSkip to conversation

Add Starfive JH7110 Cadence USB driver

PATCH Superseded Minda Chen 4 participants 21 messages Aug 29, 2024 – Oct 26, 2024

Subsystems (7)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Minda Chen

author maintainer
#0 lore raw

v4 cover Add Starfive JH7110 Cadence USB driver

Add Starfive JH7110 Cadence USB driver and related PHY driver. So the codes can be used in visionfive2 and star64 7110 board.

The driver is almost the same with kernel driver.

Test with Star64 JH7110 board USB 3.0 + USB 2.0 host. The code can work.

- previous version
v1: https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/
v2: https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/
v3: https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/

- patch description.

patch1: Add set phy mode function in cdns3 core driver
which is used by Starfive JH7110.
patch2-3: USB and PCIe 2.0 (usb 3.0) PHY drivier
patch4: Cadence USB wrapper driver.
patch5: Add JH7110 USB default overcurrent pin. patch6-7 dts, config update.
patch8: Add star64 spl dts fixup patch
patch9: MAINTAINERS update

- change:
v4:
- patch 2 Add usb split setting, default set USB 2.0 only.
- patch 5 move to spl stage.
- Add a new patch 8 for star64 board usb host, vbus pin setting and usb 3.0
v3:
- patch 1 Move the added code to cdns3_drd_update_mode().
- patch 1-4 correct the code format.(follow Rogers's comments.)
- patch 3 using regmap_field.

v2:
- patch 1 Move the added code to cdns3_core_init_role(). Must set PHY mode before calling cdns3 role start function.
- patch 1-4 correct the code format.(follow Marek's comments.)
- patch 2 Add set 125M clock in PHY init function.
- Add new patch5.

Minda Chen (9):
usb: cdns3: Set USB PHY mode in cdns3_drd_update_mode()
phy: starfive: Add Starfive JH7110 USB 2.0 PHY driver
phy: starfive: Add Starfive JH7110 PCIe 2.0 PHY driver
usb: cdns: starfive: Add cdns USB driver
spl: starfive: visionfive2: Disable USB overcurrent pin by default.
configs: starfive: Add visionfive2 cadence USB configuration
dts: starfive: Add JH7110 Cadence USB dts node
spl: starfive: star64: Setup USB fdt fixup function
MAINTAINERS: Update Starfive visionfive2 maintain files.

 .../dts/jh7110-starfive-visionfive-2.dtsi     |   5 +
 arch/riscv/dts/jh7110.dtsi                    |  53 ++++
 arch/riscv/include/asm/arch-jh7110/gpio.h     |   5 +
 board/starfive/visionfive2/MAINTAINERS        |   2 +
 board/starfive/visionfive2/spl.c              |  69 +++++
 configs/starfive_visionfive2_defconfig        |   9 +
 drivers/phy/Kconfig                           |   1 +
 drivers/phy/Makefile                          |   1 +
 drivers/phy/starfive/Kconfig                  |  21 ++
 drivers/phy/starfive/Makefile                 |   7 +
 drivers/phy/starfive/phy-jh7110-pcie.c        | 237 ++++++++++++++++++
 drivers/phy/starfive/phy-jh7110-usb2.c        | 166 ++++++++++++
 drivers/usb/cdns3/Kconfig                     |   7 +
 drivers/usb/cdns3/Makefile                    |   2 +
 drivers/usb/cdns3/cdns3-starfive.c            | 191 ++++++++++++++
 drivers/usb/cdns3/drd.c                       |  14 ++
 16 files changed, 790 insertions(+)
 create mode 100644 drivers/phy/starfive/Kconfig
 create mode 100644 drivers/phy/starfive/Makefile
 create mode 100644 drivers/phy/starfive/phy-jh7110-pcie.c
 create mode 100644 drivers/phy/starfive/phy-jh7110-usb2.c
 create mode 100644 drivers/usb/cdns3/cdns3-starfive.c

base-commit: ee2af844ba1b27b2e959c4e649e4b769fbeb4074

Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH v4 1/9 usb: cdns3: Set USB PHY mode in cdns3_drd_update_mode()

USB PHY maybe need to set PHY mode in different USB dr mode. So translate USB PHY mode to generic PHY mode and call generic_phy_set_mode().

---
 drivers/usb/cdns3/drd.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/usb/cdns3/drd.c +14 -0
index 47874fec29..cbb1334234 100644
@@ -217,15 +217,19 @@ static int cdns3_init_otg_mode(struct cdns3 *cdns)
 int cdns3_drd_update_mode(struct cdns3 *cdns)
 {
 	int ret = 0;
+	int mode;
 
 	switch (cdns->dr_mode) {
 	case USB_DR_MODE_PERIPHERAL:
+		mode = PHY_MODE_USB_DEVICE;
 		ret = cdns3_set_mode(cdns, USB_DR_MODE_PERIPHERAL);
 		break;
 	case USB_DR_MODE_HOST:
+		mode = PHY_MODE_USB_HOST;
 		ret = cdns3_set_mode(cdns, USB_DR_MODE_HOST);
 		break;
 	case USB_DR_MODE_OTG:
+		mode = PHY_MODE_USB_OTG;
 		ret = cdns3_init_otg_mode(cdns);
 		break;
 	default:
@@ -234,6 +238,16 @@ int cdns3_drd_update_mode(struct cdns3 *cdns)
 		return -EINVAL;
 	}
 
+	ret = generic_phy_set_mode(&cdns->usb2_phy, mode, 0);
+	if (ret) {
+		dev_err(cdns->dev, "Set usb 2.0 PHY mode failed %d\n", ret);
+		return ret;
+	}
+
+	ret = generic_phy_set_mode(&cdns->usb3_phy, mode, 0);
+	if (ret)
+		dev_err(cdns->dev, "Set usb 3.0 PHY mode failed %d\n", ret);
+
 	return ret;
 }
 
Signature · 1 line
2.17.1
author maintainer
#3 lore raw

PATCH v4 2/9 phy: starfive: Add Starfive JH7110 USB 2.0 PHY driver

In reply to Minda Chen

Add Starfive JH7110 USB 2.0 PHY driver, which is generic PHY driver.

---
 drivers/phy/Kconfig                    |   1 +
 drivers/phy/Makefile                   |   1 +
 drivers/phy/starfive/Kconfig           |  14 +++
 drivers/phy/starfive/Makefile          |   6 +
 drivers/phy/starfive/phy-jh7110-usb2.c | 166 +++++++++++++++++++++++++
 5 files changed, 188 insertions(+)
 create mode 100644 drivers/phy/starfive/Kconfig
 create mode 100644 drivers/phy/starfive/Makefile
 create mode 100644 drivers/phy/starfive/phy-jh7110-usb2.c
drivers/phy/Kconfig +1 -0
index e12347e8a0..f940648fe5 100644
@@ -309,5 +309,6 @@ source "drivers/phy/cadence/Kconfig"
 source "drivers/phy/ti/Kconfig"
 source "drivers/phy/qcom/Kconfig"
 source "drivers/phy/renesas/Kconfig"
+source "drivers/phy/starfive/Kconfig"
 
 endmenu
drivers/phy/Makefile +1 -0
index 7a2b764492..6ac867350c 100644
@@ -44,3 +44,4 @@ obj-y += cadence/
 obj-y += ti/
 obj-y += qcom/
 obj-y += renesas/
+obj-y += starfive/
drivers/phy/starfive/Kconfig new file +14 -0
new file mode 100644
index 0000000000..f28529d1f9
@@ -0,0 +1,14 @@
+#
+# PHY drivers for Starfive platforms
+#
+
+menu "Starfive PHY driver"
+
+config PHY_STARFIVE_JH7110_USB2
+	bool "Starfive JH7110 USB 2.0 PHY driver"
+	select PHY
+	help
+	  Enable this to support the Starfive JH7110 USB 2.0 PHY.
+	  Generic PHY driver JH7110 USB 2.0.
+
+endmenu
drivers/phy/starfive/Makefile new file +6 -0
new file mode 100644
index 0000000000..a405a75e34
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2023 Starfive
+#
+
+obj-$(CONFIG_PHY_STARFIVE_JH7110_USB2)	+= phy-jh7110-usb2.o
drivers/phy/starfive/phy-jh7110-usb2.c new file +166 -0

166 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#9 lore raw

PATCH v4 4/9 usb: cdns: starfive: Add cdns USB driver

In reply to Minda Chen

Add cdns USB3 wrapper driver.

---
 drivers/usb/cdns3/Kconfig          |   7 ++
 drivers/usb/cdns3/Makefile         |   2 +
 drivers/usb/cdns3/cdns3-starfive.c | 191 +++++++++++++++++++++++++++++
 3 files changed, 200 insertions(+)
 create mode 100644 drivers/usb/cdns3/cdns3-starfive.c
drivers/usb/cdns3/Kconfig +7 -0
index 35b61497d9..f8f363982b 100644
@@ -55,4 +55,11 @@ config USB_CDNS3_TI
 	help
 	  Say 'Y' here if you are building for Texas Instruments
 	  platforms that contain Cadence USB3 controller core. E.g.: J721e.
+
+config USB_CDNS3_STARFIVE
+	tristate "Cadence USB3 support on Starfive platforms"
+	default USB_CDNS3
+	help
+	  Say 'Y' here if you are building for Starfive platforms
+	  that contain Cadence USB3 controller core. E.g.: JH7110.
 endif
drivers/usb/cdns3/Makefile +2 -0
index 18d7190755..03d1eadb2f 100644
@@ -9,3 +9,5 @@ cdns3-$(CONFIG_$(SPL_)USB_CDNS3_GADGET)	+= gadget.o ep0.o
 cdns3-$(CONFIG_$(SPL_)USB_CDNS3_HOST)	+= host.o
 
 obj-$(CONFIG_USB_CDNS3_TI)		+= cdns3-ti.o
+
+obj-$(CONFIG_USB_CDNS3_STARFIVE)	+= cdns3-starfive.o
drivers/usb/cdns3/cdns3-starfive.c new file +191 -0

191 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#7 lore raw

PATCH v4 3/9 phy: starfive: Add Starfive JH7110 PCIe 2.0 PHY driver

In reply to Minda Chen

Add Starfive JH7110 PCIe 2.0 PHY driver, which is generic PHY driver and can be used as USB 3.0 driver.

---
 drivers/phy/starfive/Kconfig           |   7 +
 drivers/phy/starfive/Makefile          |   1 +
 drivers/phy/starfive/phy-jh7110-pcie.c | 237 +++++++++++++++++++++++++
 3 files changed, 245 insertions(+)
 create mode 100644 drivers/phy/starfive/phy-jh7110-pcie.c
drivers/phy/starfive/Kconfig +7 -0
index f28529d1f9..0843070b74 100644
@@ -4,6 +4,13 @@
 
 menu "Starfive PHY driver"
 
+config PHY_STARFIVE_JH7110_PCIE
+	bool "Starfive JH7110 PCIe 2.0 PHY driver"
+	select PHY
+	help
+	  Enable this to support the Starfive JH7110 PCIE 2.0/USB 3.0 PHY.
+	  Generic PHY driver JH7110 USB 3.0/ PCIe 2.0.
+
 config PHY_STARFIVE_JH7110_USB2
 	bool "Starfive JH7110 USB 2.0 PHY driver"
 	select PHY
drivers/phy/starfive/Makefile +1 -0
index a405a75e34..82f25aa21b 100644
@@ -3,4 +3,5 @@
 # Copyright (C) 2023 Starfive
 #
 
+obj-$(CONFIG_PHY_STARFIVE_JH7110_PCIE)	+= phy-jh7110-pcie.o
 obj-$(CONFIG_PHY_STARFIVE_JH7110_USB2)	+= phy-jh7110-usb2.o
drivers/phy/starfive/phy-jh7110-pcie.c new file +237 -0

237 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#11 lore raw

PATCH v4 5/9 spl: starfive: visionfive2: Disable USB overcurrent pin by default.

In reply to Minda Chen

For some JH7110 boards, USB host overcurent pin is not reserved, To make USB host work, overcurrent pin must be disabled. So set the pin default disabled in spl stage.

---
 arch/riscv/include/asm/arch-jh7110/gpio.h | 5 +++++
 board/starfive/visionfive2/spl.c          | 3 +++
 2 files changed, 8 insertions(+)
arch/riscv/include/asm/arch-jh7110/gpio.h +5 -0
index 90aa2f8a9e..be2a1e0d1c 100644
@@ -63,6 +63,11 @@ enum gpio_state {
 			GPIO_DIN_MASK << GPIO_SHIFT(gpi), \
 			((gpio + 2) & GPIO_DIN_MASK) << GPIO_SHIFT(gpi))
 
+#define SYS_IOMUX_DIN_DISABLED(gpi)\
+	clrsetbits_le32(JH7110_SYS_IOMUX + GPIO_DIN + GPIO_OFFSET(gpi), \
+			GPIO_DIN_MASK << GPIO_SHIFT(gpi), \
+			((0x1) & GPIO_DIN_MASK) << GPIO_SHIFT(gpi))
+
 #define SYS_IOMUX_SET_DS(gpio, ds) \
 	clrsetbits_le32(JH7110_SYS_IOMUX + GPIO_CONFIG + gpio * 4, \
 			GPIO_DS_MASK, (ds) << GPIO_DS_SHIFT)
board/starfive/visionfive2/spl.c +3 -0
index b794b73b6b..388a06e4d9 100644
@@ -452,6 +452,9 @@ void board_init_f(ulong dummy)
 			JH7110_CLK_CPU_ROOT_MASK,
 			BIT(JH7110_CLK_CPU_ROOT_SHIFT));
 
+	/* Set USB overcurrent overflow pin disable */
+	SYS_IOMUX_DIN_DISABLED(2);
+
 	ret = spl_board_init_f();
 	if (ret) {
 		debug("spl_board_init_f init failed: %d\n", ret);
Signature · 1 line
2.17.1
author maintainer
#13 lore raw

PATCH v4 6/9 configs: starfive: Add visionfive2 cadence USB configuration

In reply to Minda Chen

Add cadence USB confiuration.

---
 configs/starfive_visionfive2_defconfig | 9 +++++++++
 1 file changed, 9 insertions(+)
configs/starfive_visionfive2_defconfig +9 -0
index 174ac24dc7..35137eec59 100644
@@ -69,6 +69,7 @@ CONFIG_SYS_EEPROM_SIZE=512
 CONFIG_SYS_EEPROM_PAGE_WRITE_BITS=4
 CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS=5
 CONFIG_CMD_MEMINFO=y
+# CONFIG_CMD_BIND is not set
 CONFIG_CMD_I2C=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_USB=y
@@ -112,6 +113,8 @@ CONFIG_NVME_PCI=y
 CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCI_REGION_MULTI_ENTRY=y
 CONFIG_PCIE_STARFIVE_JH7110=y
+CONFIG_PHY_STARFIVE_JH7110_PCIE=y
+CONFIG_PHY_STARFIVE_JH7110_USB2=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
@@ -127,13 +130,19 @@ CONFIG_CADENCE_QSPI=y
 CONFIG_SYSRESET=y
 CONFIG_TIMER_EARLY=y
 CONFIG_USB=y
+CONFIG_DM_USB_GADGET=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_PCI=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_EHCI_PCI=y
 CONFIG_USB_OHCI_HCD=y
 CONFIG_USB_OHCI_PCI=y
+CONFIG_USB_CDNS3=y
+CONFIG_USB_CDNS3_GADGET=y
+CONFIG_USB_CDNS3_HOST=y
+# CONFIG_USB_CDNS3_TI is not set
 CONFIG_USB_KEYBOARD=y
+CONFIG_USB_GADGET=y
 # CONFIG_WATCHDOG is not set
 # CONFIG_WATCHDOG_AUTOSTART is not set
 CONFIG_WDT=y
Signature · 1 line
2.17.1
author maintainer
#14 lore raw

PATCH v4 7/9 dts: starfive: Add JH7110 Cadence USB dts node

In reply to Minda Chen

Add Jh7110 Cadence USB dts node, Visionfive2 default setting is USB 2.0 device.

---
 .../dts/jh7110-starfive-visionfive-2.dtsi     |  5 ++
 arch/riscv/dts/jh7110.dtsi                    | 53 +++++++++++++++++++
 2 files changed, 58 insertions(+)
arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi +5 -0
index e11babc1cd..44785bbee3 100644
@@ -378,3 +378,8 @@
 		};
 	};
 };
+
+&usb_cdns3 {
+	dr_mode = "peripheral";
+	status = "okay";
+};
arch/riscv/dts/jh7110.dtsi +53 -0

59 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#18 lore raw

PATCH v4 8/9 spl: starfive: star64: Setup USB fdt fixup function

In reply to Minda Chen

Setup star64 USB fdt fixup function. Set dr_mode to host, and add vbus pin (GPIO25), and set USB 3.0 mode. the functions can be used by other 7110 board like Milk-V board.

---
 board/starfive/visionfive2/spl.c | 66 ++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
board/starfive/visionfive2/spl.c +66 -0
index 388a06e4d9..b3034b19a3 100644
@@ -123,6 +123,69 @@ static const struct starfive_vf2_pro star64_pine64[] = {
 		"tx-internal-delay-ps", "300"},
 };
 
+static void spl_fdt_fixup_usb_vbus_pin(void *fdt, int pin)
+{
+	int offset, pin_offset;
+
+	offset = fdt_path_offset(fdt, "/soc/pinctrl@13040000"); /* &sysgpio */
+	fdt_add_subnode(fdt, offset, "usb0-0");
+	fdt_setprop_string(fdt, fdt_path_offset(fdt, "/__symbols__"),
+			   "usb_pins", "/soc/pinctrl@13040000/usb0-0");
+	offset = fdt_path_offset(fdt, "/soc/pinctrl@13040000/usb0-0");
+
+	/* usb_pins */
+	fdt_create_phandle(fdt, offset);
+	fdt_add_subnode(fdt, offset, "driver-vbus-pin");
+	offset = fdt_path_offset(fdt, "/soc/pinctrl@13040000/usb0-0/driver-vbus-pin");
+	/* GPIOMUX(25, GPOUT_SYS_USB_DRIVE_VBUS, GPOEN_ENABLE, GPI_NONE) */
+	fdt_setprop_u32(fdt, offset, "pinmux", (0xff07 << 16) | pin);
+	fdt_setprop_empty(fdt, offset, "bias-disable");
+	fdt_setprop_empty(fdt, offset, "input-disable");
+	fdt_setprop_empty(fdt, offset, "input-schmitt-disable");
+	fdt_setprop_u32(fdt, offset, "slew-rate", 0);
+
+	offset = fdt_path_offset(fdt, "/soc/usb@10100000"); /* &usb0 */
+	fdt_setprop_string(fdt, offset, "pinctrl-names", "default");
+	pin_offset = fdt_path_offset(fdt, "/soc/pinctrl@13040000/usb0-0");
+	fdt_setprop_u32(fdt, offset, "pinctrl-0",
+			fdt_get_phandle(fdt, pin_offset));
+}
+
+static void spl_fdt_fixup_usb_host(void *fdt)
+{
+	int offset;
+
+	offset = fdt_path_offset(fdt, "/soc/usb@10100000/usb@0"); /*&usb_cdns3 */
+	fdt_setprop_string(fdt, offset, "dr_mode", "host");
+}
+
+static void spl_fdt_fixup_set_usb3(void *fdt)
+{
+	int offset, phy_offset;
+
+	/* disable pcie0 */
+	offset = fdt_path_offset(fdt, "/soc/pcie@2b000000"); /* &pcie0 */
+	fdt_setprop_string(fdt, offset, "status", "disabled");
+
+	offset = fdt_path_offset(fdt, "/soc/phy@10210000"); /* &pciephy0 */
+	fdt_setprop_u32(fdt, offset, "starfive,sys-syscon", /* syscon */
+			fdt_get_phandle(fdt,
+					fdt_path_offset(fdt, "/soc/sys_syscon@13030000")));
+	fdt_appendprop_u32(fdt, offset, "starfive,sys-syscon", 0x18); /* append reg offset */
+	fdt_setprop_u32(fdt, offset, "starfive,stg-syscon",
+			fdt_get_phandle(fdt, fdt_path_offset(fdt, "/soc/stg_syscon@10240000")));
+	/* append reg offset */
+	fdt_appendprop_u32(fdt, offset, "starfive,stg-syscon", 0x148);
+	fdt_appendprop_u32(fdt, offset, "starfive,stg-syscon", 0x1f4);
+
+	offset = fdt_path_offset(fdt, "/soc/usb@10100000/usb@0"); /* usb_cdns3 */
+	phy_offset = fdt_path_offset(fdt, "/soc/phy@10210000"); /* <&pciephy0> */
+	/* append <&pciephy0> */
+	fdt_appendprop_u32(fdt, offset, "phys", fdt_get_phandle(fdt, phy_offset));
+	fdt_setprop(fdt, offset, "phy-names", "cdns3,usb2-phy\0cdns3,usb3-phy",
+		    sizeof("cdns3,usb2-phy\0cdns3,usb3-phy"));
+}
+
 void spl_fdt_fixup_mars(void *fdt)
 {
 	static const char compat[] = "milkv,mars\0starfive,jh7110";
@@ -335,6 +398,9 @@ void spl_fdt_fixup_star64(void *fdt)
 				break;
 		}
 	}
+	spl_fdt_fixup_usb_host(fdt);
+	spl_fdt_fixup_usb_vbus_pin(fdt, 25);
+	spl_fdt_fixup_set_usb3(fdt);
 }
 
 void spl_perform_fixups(struct spl_image_info *spl_image)
Signature · 1 line
2.17.1
author maintainer
#20 lore raw

PATCH v4 9/9 MAINTAINERS: Update Starfive visionfive2 maintain files.

In reply to Minda Chen

Add USB related files to Starfive visionfive2 MAINTAINERS.

---
 board/starfive/visionfive2/MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
board/starfive/visionfive2/MAINTAINERS +2 -0
index d7f638f9b4..1faf83f581 100644
@@ -6,3 +6,5 @@ F:	board/starfive/visionfive2/
 F:	include/configs/starfive-visionfive2.h
 F:	configs/starfive_visionfive2_defconfig
 F:	drivers/pci/pcie_starfive_jh7110.c
+F:	drivers/phy/starfive/
+F:	drivers/usb/cdns3/cdns3-starfive.c
Signature · 1 line
2.17.1
#15 lore raw

Re: [PATCH v4 7/9] dts: starfive: Add JH7110 Cadence USB dts node

In reply to Minda Chen

Hi,

Quoted 9 lines · Minda Chen

Add Jh7110 Cadence USB dts node, Visionfive2 default setting is USB 2.0 device.

---
 .../dts/jh7110-starfive-visionfive-2.dtsi     |  5 ++
 arch/riscv/dts/jh7110.dtsi                    | 53 +++++++++++++++++++
 2 files changed, 58 insertions(+)

Can you try to evaluate if this SoC can support OF_UPSTREAM? I can see corresponding DT sources well supported by dts/upstream. AFAICS, you at least need to add a Makefile for RISC-V here:
dts/upstream/src/riscv/ for which you can reference dts/upstream/src/arm64/Makefile.

This is not something to be considered as a blocker for this series but kind of follow-up work.

-Sumit

Quoted 81 lines
arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi +5 -0
index e11babc1cd..44785bbee3 100644
@@ -378,3 +378,8 @@
                };
        };
 };
+
+&usb_cdns3 {
+       dr_mode = "peripheral";
+       status = "okay";
+};
arch/riscv/dts/jh7110.dtsi +53 -1
index 2cdc683d49..7bf9b2a03a 100644
@@ -371,6 +371,59 @@
                        status = "disabled";
                };
 
+               usb0: usb@10100000 {
+                       compatible = "starfive,jh7110-usb";
+                       ranges = <0x0 0x0 0x10100000 0x100000>;
+                       #address-cells = <1>;
+                       #size-cells = <1>;
+                       starfive,stg-syscon = <&stg_syscon 0x4>;
+                       clocks = <&stgcrg JH7110_STGCLK_USB_LPM>,
+                                <&stgcrg JH7110_STGCLK_USB_STB>,
+                                <&stgcrg JH7110_STGCLK_USB_APB>,
+                                <&stgcrg JH7110_STGCLK_USB_AXI>,
+                                <&stgcrg JH7110_STGCLK_USB_UTMI_APB>;
+                       clock-names = "lpm", "stb", "apb", "axi", "utmi_apb";
+                       resets = <&stgcrg JH7110_STGRST_USB_PWRUP>,
+                                <&stgcrg JH7110_STGRST_USB_APB>,
+                                <&stgcrg JH7110_STGRST_USB_AXI>,
+                                <&stgcrg JH7110_STGRST_USB_UTMI_APB>;
+                       reset-names = "pwrup", "apb", "axi", "utmi_apb";
+
+                       usb_cdns3: usb@0 {
+                               compatible = "cdns,usb3";
+                               reg = <0x0 0x10000>,
+                                     <0x10000 0x10000>,
+                                     <0x20000 0x10000>;
+                               reg-names = "otg", "xhci", "dev";
+                               interrupts = <100>, <108>, <110>;
+                               interrupt-names = "host", "peripheral", "otg";
+                               phys = <&usbphy0>;
+                               phy-names = "cdns3,usb2-phy";
+                       };
+               };
+
+               usbphy0: phy@10200000 {
+                       compatible = "starfive,jh7110-usb-phy";
+                       reg = <0x0 0x10200000 0x0 0x10000>;
+                       clocks = <&syscrg JH7110_SYSCLK_USB_125M>,
+                                <&stgcrg JH7110_STGCLK_USB_APP_125>;
+                       clock-names = "125m", "app_125m";
+                       starfive,sys-syscon = <&sys_syscon 0x18>;
+                       #phy-cells = <0>;
+               };
+
+               pciephy0: phy@10210000 {
+                       compatible = "starfive,jh7110-pcie-phy";
+                       reg = <0x0 0x10210000 0x0 0x10000>;
+                       #phy-cells = <0>;
+               };
+
+               pciephy1: phy@10220000 {
+                       compatible = "starfive,jh7110-pcie-phy";
+                       reg = <0x0 0x10220000 0x0 0x10000>;
+                       #phy-cells = <0>;
+               };
+
                stgcrg: clock-controller@10230000 {
                        compatible = "starfive,jh7110-stgcrg";
                        reg = <0x0 0x10230000 0x0 0x10000>;
--

2.17.1

#16 lore raw

Re: [PATCH v4 7/9] dts: starfive: Add JH7110 Cadence USB dts node

Quoted 98 lines · Sumit Garg

Hi,

Quoted 9 lines · Minda Chen

Add Jh7110 Cadence USB dts node, Visionfive2 default setting is USB 2.0 device.

---
 .../dts/jh7110-starfive-visionfive-2.dtsi     |  5 ++
 arch/riscv/dts/jh7110.dtsi                    | 53 +++++++++++++++++++
 2 files changed, 58 insertions(+)

Can you try to evaluate if this SoC can support OF_UPSTREAM? I can see corresponding DT sources well supported by dts/upstream. AFAICS, you at least need to add a Makefile for RISC-V here:
dts/upstream/src/riscv/ for which you can reference dts/upstream/src/arm64/Makefile.

This is not something to be considered as a blocker for this series but kind of follow-up work.

-Sumit

Quoted 73 lines
arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi +5 -0
index e11babc1cd..44785bbee3 100644
@@ -378,3 +378,8 @@
                };
        };
 };
+
+&usb_cdns3 {
+       dr_mode = "peripheral";
+       status = "okay";
+};
arch/riscv/dts/jh7110.dtsi +51 -0
index 2cdc683d49..7bf9b2a03a 100644
@@ -371,6 +371,59 @@
                        status = "disabled";
                };
 
+               usb0: usb@10100000 {
+                       compatible = "starfive,jh7110-usb";
+                       ranges = <0x0 0x0 0x10100000 0x100000>;
+                       #address-cells = <1>;
+                       #size-cells = <1>;
+                       starfive,stg-syscon = <&stg_syscon 0x4>;
+                       clocks = <&stgcrg JH7110_STGCLK_USB_LPM>,
+                                <&stgcrg JH7110_STGCLK_USB_STB>,
+                                <&stgcrg JH7110_STGCLK_USB_APB>,
+                                <&stgcrg JH7110_STGCLK_USB_AXI>,
+                                <&stgcrg JH7110_STGCLK_USB_UTMI_APB>;
+                       clock-names = "lpm", "stb", "apb", "axi", "utmi_apb";
+                       resets = <&stgcrg JH7110_STGRST_USB_PWRUP>,
+                                <&stgcrg JH7110_STGRST_USB_APB>,
+                                <&stgcrg JH7110_STGRST_USB_AXI>,
+                                <&stgcrg JH7110_STGRST_USB_UTMI_APB>;
+                       reset-names = "pwrup", "apb", "axi", "utmi_apb";
+
+                       usb_cdns3: usb@0 {
+                               compatible = "cdns,usb3";
+                               reg = <0x0 0x10000>,
+                                     <0x10000 0x10000>,
+                                     <0x20000 0x10000>;
+                               reg-names = "otg", "xhci", "dev";
+                               interrupts = <100>, <108>, <110>;
+                               interrupt-names = "host", "peripheral", "otg";
+                               phys = <&usbphy0>;
+                               phy-names = "cdns3,usb2-phy";
+                       };
+               };
+
+               usbphy0: phy@10200000 {
+                       compatible = "starfive,jh7110-usb-phy";
+                       reg = <0x0 0x10200000 0x0 0x10000>;
+                       clocks = <&syscrg JH7110_SYSCLK_USB_125M>,
+                                <&stgcrg JH7110_STGCLK_USB_APP_125>;
+                       clock-names = "125m", "app_125m";
+                       starfive,sys-syscon = <&sys_syscon 0x18>;
+                       #phy-cells = <0>;
+               };
+
+               pciephy0: phy@10210000 {
+                       compatible = "starfive,jh7110-pcie-phy";
+                       reg = <0x0 0x10210000 0x0 0x10000>;
+                       #phy-cells = <0>;
+               };
+
+               pciephy1: phy@10220000 {
+                       compatible = "starfive,jh7110-pcie-phy";
+                       reg = <0x0 0x10220000 0x0 0x10000>;
+                       #phy-cells = <0>;
Quoted 8 lines
Quoted 8 lines
arch/riscv/dts/jh7110.dtsi +2 -1
+               };
+
                stgcrg: clock-controller@10230000 {
                        compatible = "starfive,jh7110-stgcrg";
                        reg = <0x0 0x10230000 0x0 0x10000>;
--

2.17.1

I note that Hal Feng saying earlier this week they would take on OF_UPSTREAM of JH7110 boards:
https://lore.kernel.org/lkml/ZQ2PR01MB13073EF3BD7A64F2C098AA8FE6882@ZQ2PR01MB1307.CHNPR01.prod.partner.outlook.cn/

It is a good time for this work to begin.

-E

#4 lore raw

Re: [PATCH v4 2/9] phy: starfive: Add Starfive JH7110 USB 2.0 PHY driver

In reply to Minda Chen

On 8/29/24 3:30 AM, Minda Chen wrote:

[...]

drivers/phy/starfive/Kconfig line 9

Quoted 5 lines
drivers/phy/starfive/Kconfig new file +5 -0
+menu "Starfive PHY driver"
+
+config PHY_STARFIVE_JH7110_USB2
+	bool "Starfive JH7110 USB 2.0 PHY driver"
+	select PHY

Can this PHY_STARFIVE_JH7110_USB2 symbol be selected if CONFIG_PHY is not set ? I think it cannot, so this 'select PHY' is unnecessary and should be removed.

[...]

drivers/phy/starfive/phy-jh7110-usb2.c line 44

Quoted 10 lines
drivers/phy/starfive/phy-jh7110-usb2.c new file +10 -0
+static void usb2_set_ls_keepalive(struct jh7110_usb2_phy *phy, bool set)
+{
+	/* Host mode enable the LS speed keep-alive signal */
+	if (set)
+		clrsetbits_le32(phy->regs + USB_LS_KEEPALIVE_OFF,
+				USB_LS_KEEPALIVE_ENABLE,
+				USB_LS_KEEPALIVE_ENABLE);
+	else
+		clrsetbits_le32(phy->regs + USB_LS_KEEPALIVE_OFF,
+				USB_LS_KEEPALIVE_ENABLE, 0);

Either use clrbits_le32() or use rework the function this way:

		clrsetbits_le32(phy->regs + USB_LS_KEEPALIVE_OFF,
				USB_LS_KEEPALIVE_ENABLE,
				set ? USB_LS_KEEPALIVE_ENABLE : 0);

[...]

#8 lore raw

Re: [PATCH v4 3/9] phy: starfive: Add Starfive JH7110 PCIe 2.0 PHY driver

In reply to Minda Chen

On 8/29/24 3:30 AM, Minda Chen wrote:

[...]

drivers/phy/starfive/phy-jh7110-pcie.c line 50

Quoted 8 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +8 -0
+static int phy_pcie_mode_set(struct jh7110_pcie_phy *data, bool usb_mode)
+{
+	unsigned int phy_mode, width, usb3_phy, ss_mode, split;
+
+	/* default is PCIe mode */
+	if (!data->stg_syscon || !data->sys_syscon) {
+		if (usb_mode) {
+			dev_err(data->phy->dev, "doesn't support usb3 mode\n");

USB3 in capitals , USB is an abbreviation.

[...]

Quoted 1 line

+static int jh7110_pcie_phy_set_mode(struct phy *_phy,

Use plain 'phy' variable name, drop the leading underscore .

Quoted 15 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +15 -0
+				    enum phy_mode mode, int submode)
+{
+	struct udevice *dev = _phy->dev;
+	struct jh7110_pcie_phy *phy = dev_get_priv(dev);
+	int ret;
+
+	if (mode == phy->mode)
+		return 0;
+
+	switch (mode) {
+	case PHY_MODE_USB_HOST:
+	case PHY_MODE_USB_DEVICE:
+	case PHY_MODE_USB_OTG:
+		ret = phy_pcie_mode_set(phy, 1);
+		if (ret)

drivers/phy/starfive/phy-jh7110-pcie.c line 112

Quoted 10 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +10 -0
+			return ret;
+		break;
+	case PHY_MODE_PCIE:
+		phy_pcie_mode_set(phy, 0);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	dev_dbg(_phy->dev, "Changing phy mode to %d\n", mode);

PHY in capitals.

drivers/phy/starfive/phy-jh7110-pcie.c line 116

Quoted 4 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +4 -0
+	phy->mode = mode;
+
+	return 0;
+}

Looks pretty good, thanks !

#10 lore raw

Re: [PATCH v4 4/9] usb: cdns: starfive: Add cdns USB driver

In reply to Minda Chen
Quoted 15 lines · Minda Chen

Add cdns USB3 wrapper driver.

---
  drivers/usb/cdns3/Kconfig          |   7 ++
  drivers/usb/cdns3/Makefile         |   2 +
  drivers/usb/cdns3/cdns3-starfive.c | 191 +++++++++++++++++++++++++++++
  3 files changed, 200 insertions(+)

create mode 100644 drivers/usb/cdns3/cdns3-starfive.c

drivers/usb/cdns3/Kconfig +0 -0
index 35b61497d9..f8f363982b 100644

drivers/usb/cdns3/Kconfig config USB_CDNS3_TI · line 61

Quoted 7 lines
drivers/usb/cdns3/Kconfig +4 -0
@@ -55,4 +55,11 @@ config USB_CDNS3_TI
  	help
  	  Say 'Y' here if you are building for Texas Instruments
  	  platforms that contain Cadence USB3 controller core. E.g.: J721e.
+
+config USB_CDNS3_STARFIVE
+	tristate "Cadence USB3 support on Starfive platforms"
+	default USB_CDNS3

Should this be 'default y if SOMEPLATFORM' ?

[...]

Quoted 16 lines
drivers/usb/cdns3/Kconfig +16 -0
+static void cdns_mode_init(struct cdns_starfive *data, enum usb_dr_mode mode)
+{
+	unsigned int strap, suspendm;
+
+	regmap_update_bits(data->stg_syscon, data->stg_usb_mode,
+			   USB_MISC_CFG_MASK,
+			   USB_SUSPENDM_BYPS | USB_PLL_EN | USB_REFCLK_MODE);
+
+	switch (mode) {
+	case USB_DR_MODE_HOST:
+		strap = USB_STRAP_HOST;
+		suspendm = USB_SUSPENDM_HOST;
+		break;
+
+	case USB_DR_MODE_PERIPHERAL:
+		strap = USB_STRAP_DEVICE;

drivers/usb/cdns3/Kconfig config USB_CDNS3_TI

Quoted 10 lines
drivers/usb/cdns3/Kconfig +10 -0
+		suspendm = 0;
+		break;
+	default:
+		return;
+	}
+
+	regmap_update_bits(data->stg_syscon, data->stg_usb_mode,
+			   USB_STRAP_MASK, strap);
+	regmap_update_bits(data->stg_syscon, data->stg_usb_mode,
+			   USB_SUSPENDM_MASK, suspendm);

Are two consecutive writes to the same register mandatory here ?

Quoted 1 line

+}

[...]

Quoted 6 lines
drivers/usb/cdns3/Kconfig +6 -0
+static int cdns_starfive_probe(struct udevice *dev)
+{
+	struct cdns_starfive *data = dev_get_plat(dev);
+	enum usb_dr_mode dr_mode;
+	ofnode node;
+	int ret;

drivers/usb/cdns3/Kconfig

Quoted 10 lines
drivers/usb/cdns3/Kconfig +10 -0
+
+	data->dev = dev;
+
+	ret = cdns_starfive_get_syscon(data);
+	if (ret)
+		return ret;
+
+	node = ofnode_by_compatible(dev_ofnode(dev), "cdns,usb3");
+	if (!ofnode_valid(node)) {
+		dev_err(dev, "failed to get usb node\n");

USB in capitals.

Quoted 5 lines
drivers/usb/cdns3/Kconfig +5 -0
+		return -ENODEV;
+	}
+
+	dr_mode = usb_get_dr_mode(node);
+

drivers/usb/cdns3/Kconfig

Quoted 10 lines
drivers/usb/cdns3/Kconfig +10 -0
+	data->mode = dr_mode;
+	ret = cdns_clk_rst_init(data);
+	if (ret) {
+		dev_err(data->dev, "clk reset failed: %d\n", ret);
+		return ret;
+	}
+	cdns_mode_init(data, dr_mode);
+
+	return 0;
+}

Looks pretty good, thanks .

Reviewed-by Tested-by on v4 8/9
#19 lore raw

Re: [PATCH v4 8/9] spl: starfive: star64: Setup USB fdt fixup function

In reply to Minda Chen

Hi Minda,

Quoted 24 lines · Minda Chen

Setup star64 USB fdt fixup function. Set dr_mode to host, and add vbus pin (GPIO25), and set USB 3.0 mode. the functions can be used by other 7110 board like Milk-V board.

---
 board/starfive/visionfive2/spl.c | 66 ++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
board/starfive/visionfive2/spl.c +5 -0
index 388a06e4d9..b3034b19a3 100644
@@ -123,6 +123,69 @@ static const struct starfive_vf2_pro star64_pine64[] = {
                "tx-internal-delay-ps", "300"},
 };
 
+static void spl_fdt_fixup_usb_vbus_pin(void *fdt, int pin)
+{
+       int offset, pin_offset;
+
+       offset = fdt_path_offset(fdt, "/soc/pinctrl@13040000"); /* &sysgpio */

board/starfive/visionfive2/spl.c static const struct starfive_vf2_pro star64_pine64[] = { · line 140

Quoted 10 lines
board/starfive/visionfive2/spl.c +10 -0
+       fdt_add_subnode(fdt, offset, "usb0-0");
+       fdt_setprop_string(fdt, fdt_path_offset(fdt, "/__symbols__"),
+                          "usb_pins", "/soc/pinctrl@13040000/usb0-0");
+       offset = fdt_path_offset(fdt, "/soc/pinctrl@13040000/usb0-0");
+
+       /* usb_pins */
+       fdt_create_phandle(fdt, offset);
+       fdt_add_subnode(fdt, offset, "driver-vbus-pin");
+       offset = fdt_path_offset(fdt, "/soc/pinctrl@13040000/usb0-0/driver-vbus-pin");
+       /* GPIOMUX(25, GPOUT_SYS_USB_DRIVE_VBUS, GPOEN_ENABLE, GPI_NONE) */

This comment may now be updated:

/* GPIOMUX(pin, GPOUT_SYS_USB_DRIVE_VBUS, GPOEN_ENABLE, GPI_NONE) */

Aside I am confused why we do not use the GPIOMUX macro directly here. Can anyone say if that would be a problem to just use the macro GPIOMUX what we are pretending to be here?

I think it will not be a problem here anymore when OF_UPSTREAM is implemented to jh7110 boards in U-Boot so it is enough now to update the comment about GPIOMUX.

Quoted 38 lines
board/starfive/visionfive2/spl.c +38 -0
+       fdt_setprop_u32(fdt, offset, "pinmux", (0xff07 << 16) | pin);
+       fdt_setprop_empty(fdt, offset, "bias-disable");
+       fdt_setprop_empty(fdt, offset, "input-disable");
+       fdt_setprop_empty(fdt, offset, "input-schmitt-disable");
+       fdt_setprop_u32(fdt, offset, "slew-rate", 0);
+
+       offset = fdt_path_offset(fdt, "/soc/usb@10100000"); /* &usb0 */
+       fdt_setprop_string(fdt, offset, "pinctrl-names", "default");
+       pin_offset = fdt_path_offset(fdt, "/soc/pinctrl@13040000/usb0-0");
+       fdt_setprop_u32(fdt, offset, "pinctrl-0",
+                       fdt_get_phandle(fdt, pin_offset));
+}
+
+static void spl_fdt_fixup_usb_host(void *fdt)
+{
+       int offset;
+
+       offset = fdt_path_offset(fdt, "/soc/usb@10100000/usb@0"); /*&usb_cdns3 */
+       fdt_setprop_string(fdt, offset, "dr_mode", "host");
+}
+
+static void spl_fdt_fixup_set_usb3(void *fdt)
+{
+       int offset, phy_offset;
+
+       /* disable pcie0 */
+       offset = fdt_path_offset(fdt, "/soc/pcie@2b000000"); /* &pcie0 */
+       fdt_setprop_string(fdt, offset, "status", "disabled");
+
+       offset = fdt_path_offset(fdt, "/soc/phy@10210000"); /* &pciephy0 */
+       fdt_setprop_u32(fdt, offset, "starfive,sys-syscon", /* syscon */
+                       fdt_get_phandle(fdt,
+                                       fdt_path_offset(fdt, "/soc/sys_syscon@13030000")));
+       fdt_appendprop_u32(fdt, offset, "starfive,sys-syscon", 0x18); /* append reg offset */
+       fdt_setprop_u32(fdt, offset, "starfive,stg-syscon",
+                       fdt_get_phandle(fdt, fdt_path_offset(fdt, "/soc/stg_syscon@10240000")));
+       /* append reg offset */
+       fdt_appendprop_u32(fdt, offset, "starfive,stg-syscon", 0x148);

board/starfive/visionfive2/spl.c static const struct starfive_vf2_pro star64_pine64[] = { · line 188

Quoted 10 lines
board/starfive/visionfive2/spl.c +10 -0
+       fdt_appendprop_u32(fdt, offset, "starfive,stg-syscon", 0x1f4);
+
+       offset = fdt_path_offset(fdt, "/soc/usb@10100000/usb@0"); /* usb_cdns3 */
+       phy_offset = fdt_path_offset(fdt, "/soc/phy@10210000"); /* <&pciephy0> */
+       /* append <&pciephy0> */
+       fdt_appendprop_u32(fdt, offset, "phys", fdt_get_phandle(fdt, phy_offset));
+       fdt_setprop(fdt, offset, "phy-names", "cdns3,usb2-phy\0cdns3,usb3-phy",
+                   sizeof("cdns3,usb2-phy\0cdns3,usb3-phy"));
+}
+

Code readability can be better with fdt_appendprop_string helper. As:

fdt_setprop_string(fdt, offset, "phy-names", "cdns3,usb2-phy"); fdt_appendprop_string(fdt, offset, "phy-names", "cdns3,usb3-phy");

Some people prefer it to have "\0" and avoid the fdt_appendprop_string helper. What you should do is not my choice here to make.

Anyway, and again, I think this will not be our problem after OF_UPSTREAM is realized for JH7110 boards in U-Boot.

Quoted 14 lines
board/starfive/visionfive2/spl.c +3 -1
 void spl_fdt_fixup_mars(void *fdt)
 {
        static const char compat[] = "milkv,mars\0starfive,jh7110";
@@ -335,6 +398,9 @@ void spl_fdt_fixup_star64(void *fdt)
                                break;
                }
        }
+       spl_fdt_fixup_usb_host(fdt);
+       spl_fdt_fixup_usb_vbus_pin(fdt, 25);
+       spl_fdt_fixup_set_usb3(fdt);
 }
 
 void spl_perform_fixups(struct spl_image_info *spl_image)
--
Quoted 2 lines

2.17.1

I have now tested Mars CM Lite:

+ spl_fdt_fixup_usb_host(fdt);
+ spl_fdt_fixup_usb_vbus_pin(fdt, 25);

added to the Milk-V Mars CM fix-up routine: in U-Boot there is both working USB and PCIe. I would note also an error for PCIe in Linux if continuing from U-Boot with the fdt of U-Boot into Grub2, then Linux:

Loading Linux 6.11-rc4-riscv64 ...
Loading initial ramdisk ...

[   11.718961] pcie-starfive 2b000000.pcie: error -ENODEV: failed to
get valid pcie domain
[   11.727238] cadence-qspi 13010000.spi: couldn't determine
trigger-address
[   11.730479] pcie-starfive 2c000000.pcie: error -ENODEV: failed to
get valid pcie domain
[   11.734112] cadence-qspi 13010000.spi: Cannot get mandatory OF

data.
Gave up waiting for suspend/resume device

This is only a problem when I force fdtfile path to be not found, and U-Boot gives the internal fdt to the next boot software in sequence (here this is Grub2, and then Debian Linux).

For now, Minda, the error with Mars CM Lite and U-Boot internal fdt into 6.11-rc4 Linux causing PCIe to fail is something I consider a regression if we do enable for Mars CM and Mars CM Lite. It is good enough in this series with only the JH7110 boards that you have available for testing.

author maintainer
#17 lore raw

Re: [PATCH v4 7/9] dts: starfive: Add JH7110 Cadence USB dts node

In reply to E Shattow
Quoted 9 lines · Sumit Garg
Quoted 4 lines

Hi,

On Thu, 29 Aug 2024 at 07:01, Minda Chen <[email protected]>

Quoted 1 line · wrote:
Quoted 1 line
Quoted 21 lines
Quoted 7 lines
Quoted 7 lines

Add Jh7110 Cadence USB dts node, Visionfive2 default setting is USB 2.0 device.

---
 .../dts/jh7110-starfive-visionfive-2.dtsi     |  5 ++
 arch/riscv/dts/jh7110.dtsi                    | 53

+++++++++++++++++++

Quoted 13 lines
Quoted 1 line
 2 files changed, 58 insertions(+)

Can you try to evaluate if this SoC can support OF_UPSTREAM? I can see corresponding DT sources well supported by dts/upstream. AFAICS, you at least need to add a Makefile for RISC-V here:
dts/upstream/src/riscv/ for which you can reference dts/upstream/src/arm64/Makefile.

This is not something to be considered as a blocker for this series but kind of follow-up work.

-Sumit

Yes. We will support OF_UPSTREAM .
Hal will do this job.

Quoted 102 lines
Quoted 23 lines
Quoted 23 lines
arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi +5 -0
index e11babc1cd..44785bbee3 100644
@@ -378,3 +378,8 @@
                };
        };
 };
+
+&usb_cdns3 {
+       dr_mode = "peripheral";
+       status = "okay";
+};
arch/riscv/dts/jh7110.dtsi +0 -0
index 2cdc683d49..7bf9b2a03a 100644
@@ -371,6 +371,59 @@
                        status = "disabled";
                };
 
Quoted 7 lines

arch/riscv/dts/jh7110.dtsi

Quoted 7 lines
arch/riscv/dts/jh7110.dtsi +7 -0
+               usb0: usb@10100000 {
+                       compatible = "starfive,jh7110-usb";
+                       ranges = <0x0 0x0 0x10100000 0x100000>;
+                       #address-cells = <1>;
+                       #size-cells = <1>;
+                       starfive,stg-syscon = <&stg_syscon 0x4>;
+                       clocks = <&stgcrg

JH7110_STGCLK_USB_LPM>,

Quoted 1 line

arch/riscv/dts/jh7110.dtsi line 381

Quoted 1 line
arch/riscv/dts/jh7110.dtsi +1 -0
+                                <&stgcrg

JH7110_STGCLK_USB_STB>,

Quoted 1 line

arch/riscv/dts/jh7110.dtsi line 382

Quoted 1 line
arch/riscv/dts/jh7110.dtsi +1 -0
+                                <&stgcrg

JH7110_STGCLK_USB_APB>,

Quoted 1 line

arch/riscv/dts/jh7110.dtsi line 383

Quoted 1 line
arch/riscv/dts/jh7110.dtsi +1 -0
+                                <&stgcrg

JH7110_STGCLK_USB_AXI>,

Quoted 1 line

arch/riscv/dts/jh7110.dtsi line 384

Quoted 1 line
arch/riscv/dts/jh7110.dtsi +1 -0
+                                <&stgcrg

JH7110_STGCLK_USB_UTMI_APB>;

Quoted 1 line

arch/riscv/dts/jh7110.dtsi line 385

Quoted 1 line
arch/riscv/dts/jh7110.dtsi +1 -0
+                       clock-names = "lpm", "stb", "apb", "axi",

"utmi_apb";

Quoted 1 line

arch/riscv/dts/jh7110.dtsi line 386

Quoted 1 line
arch/riscv/dts/jh7110.dtsi +1 -0
+                       resets = <&stgcrg

JH7110_STGRST_USB_PWRUP>,

Quoted 1 line

arch/riscv/dts/jh7110.dtsi line 387

Quoted 1 line
arch/riscv/dts/jh7110.dtsi +1 -0
+                                <&stgcrg

JH7110_STGRST_USB_APB>,

Quoted 1 line

arch/riscv/dts/jh7110.dtsi line 388

Quoted 1 line
arch/riscv/dts/jh7110.dtsi +1 -0
+                                <&stgcrg

JH7110_STGRST_USB_AXI>,

Quoted 1 line

arch/riscv/dts/jh7110.dtsi line 389

Quoted 1 line
arch/riscv/dts/jh7110.dtsi +1 -0
+                                <&stgcrg

JH7110_STGRST_USB_UTMI_APB>;

Quoted 11 lines

arch/riscv/dts/jh7110.dtsi

Quoted 11 lines
arch/riscv/dts/jh7110.dtsi +11 -0
+                       reset-names = "pwrup", "apb", "axi",
+ "utmi_apb";
+
+                       usb_cdns3: usb@0 {
+                               compatible = "cdns,usb3";
+                               reg = <0x0 0x10000>,
+                                     <0x10000 0x10000>,
+                                     <0x20000 0x10000>;
+                               reg-names = "otg", "xhci", "dev";
+                               interrupts = <100>, <108>, <110>;
+                               interrupt-names = "host",

"peripheral", "otg";

Quoted 9 lines

arch/riscv/dts/jh7110.dtsi

Quoted 9 lines
arch/riscv/dts/jh7110.dtsi +9 -0
+                               phys = <&usbphy0>;
+                               phy-names = "cdns3,usb2-phy";
+                       };
+               };
+
+               usbphy0: phy@10200000 {
+                       compatible = "starfive,jh7110-usb-phy";
+                       reg = <0x0 0x10200000 0x0 0x10000>;
+                       clocks = <&syscrg

JH7110_SYSCLK_USB_125M>,

Quoted 1 line

arch/riscv/dts/jh7110.dtsi line 410

Quoted 1 line
arch/riscv/dts/jh7110.dtsi +1 -0
+                                <&stgcrg

JH7110_STGCLK_USB_APP_125>;

Quoted 15 lines
Quoted 15 lines
arch/riscv/dts/jh7110.dtsi +15 -0
+                       clock-names = "125m", "app_125m";
+                       starfive,sys-syscon = <&sys_syscon 0x18>;
+                       #phy-cells = <0>;
+               };
+
+               pciephy0: phy@10210000 {
+                       compatible = "starfive,jh7110-pcie-phy";
+                       reg = <0x0 0x10210000 0x0 0x10000>;
+                       #phy-cells = <0>;
+               };
+
+               pciephy1: phy@10220000 {
+                       compatible = "starfive,jh7110-pcie-phy";
+                       reg = <0x0 0x10220000 0x0 0x10000>;
+                       #phy-cells = <0>;
Quoted 8 lines
Quoted 8 lines
arch/riscv/dts/jh7110.dtsi +2 -1
+               };
+
                stgcrg: clock-controller@10230000 {
                        compatible = "starfive,jh7110-stgcrg";
                        reg = <0x0 0x10230000 0x0 0x10000>;
--

2.17.1

I note that Hal Feng saying earlier this week they would take on OF_UPSTREAM of JH7110 boards:
https://lore.kernel.org/lkml/ZQ2PR01MB13073EF3BD7A64F2C098AA8FE6882@
ZQ2PR01MB1307.CHNPR01.prod.partner.outlook.cn/

Quoted 3 lines

It is a good time for this work to begin.

-E

Yes, Hal Feng will do this job.

author maintainer
#5 lore raw

Re: [PATCH v4 2/9] phy: starfive: Add Starfive JH7110 USB 2.0 PHY driver

In reply to Marek Vasut
Quoted 16 lines · Minda Chen

[...]

drivers/phy/starfive/Kconfig line 9

Quoted 5 lines
drivers/phy/starfive/Kconfig new file +5 -0
+menu "Starfive PHY driver"
+
+config PHY_STARFIVE_JH7110_USB2
+	bool "Starfive JH7110 USB 2.0 PHY driver"
+	select PHY

Can this PHY_STARFIVE_JH7110_USB2 symbol be selected if CONFIG_PHY is not set ? I think it cannot, so this 'select PHY' is unnecessary and should be removed.

Quoted 2 lines

[...]

Thanks. I will check it.
Other are format issues. I will modify them.

Quoted 18 lines

drivers/phy/starfive/phy-jh7110-usb2.c line 44

Quoted 10 lines
drivers/phy/starfive/phy-jh7110-usb2.c new file +10 -0
+static void usb2_set_ls_keepalive(struct jh7110_usb2_phy *phy, bool
+set) {
+	/* Host mode enable the LS speed keep-alive signal */
+	if (set)
+		clrsetbits_le32(phy->regs + USB_LS_KEEPALIVE_OFF,
+				USB_LS_KEEPALIVE_ENABLE,
+				USB_LS_KEEPALIVE_ENABLE);
+	else
+		clrsetbits_le32(phy->regs + USB_LS_KEEPALIVE_OFF,
+				USB_LS_KEEPALIVE_ENABLE, 0);

Either use clrbits_le32() or use rework the function this way:

		clrsetbits_le32(phy->regs + USB_LS_KEEPALIVE_OFF,
				USB_LS_KEEPALIVE_ENABLE,
				set ? USB_LS_KEEPALIVE_ENABLE : 0);

[...]

#6 lore raw

Re: [PATCH v4 2/9] phy: starfive: Add Starfive JH7110 USB 2.0 PHY driver

Quoted 16 lines · Minda Chen
Quoted 16 lines · Minda Chen

[...]

drivers/phy/starfive/Kconfig line 9

Quoted 5 lines
drivers/phy/starfive/Kconfig new file +5 -0
+menu "Starfive PHY driver"
+
+config PHY_STARFIVE_JH7110_USB2
+	bool "Starfive JH7110 USB 2.0 PHY driver"
+	select PHY

Can this PHY_STARFIVE_JH7110_USB2 symbol be selected if CONFIG_PHY is not set ? I think it cannot, so this 'select PHY' is unnecessary and should be removed.

Quoted 4 lines
Quoted 2 lines

[...]

Thanks. I will check it.
Other are format issues. I will modify them.

Thank you

Tested-by on v4 5/9
#12 lore raw

Re: [PATCH v4 5/9] spl: starfive: visionfive2: Disable USB overcurrent pin by default.

In reply to Minda Chen
Quoted 42 lines · Minda Chen

For some JH7110 boards, USB host overcurent pin is not reserved, To make USB host work, overcurrent pin must be disabled. So set the pin default disabled in spl stage.

---
 arch/riscv/include/asm/arch-jh7110/gpio.h | 5 +++++
 board/starfive/visionfive2/spl.c          | 3 +++
 2 files changed, 8 insertions(+)
arch/riscv/include/asm/arch-jh7110/gpio.h +5 -0
index 90aa2f8a9e..be2a1e0d1c 100644
@@ -63,6 +63,11 @@ enum gpio_state {
                        GPIO_DIN_MASK << GPIO_SHIFT(gpi), \
                        ((gpio + 2) & GPIO_DIN_MASK) << GPIO_SHIFT(gpi))
 
+#define SYS_IOMUX_DIN_DISABLED(gpi)\
+       clrsetbits_le32(JH7110_SYS_IOMUX + GPIO_DIN + GPIO_OFFSET(gpi), \
+                       GPIO_DIN_MASK << GPIO_SHIFT(gpi), \
+                       ((0x1) & GPIO_DIN_MASK) << GPIO_SHIFT(gpi))
+
 #define SYS_IOMUX_SET_DS(gpio, ds) \
        clrsetbits_le32(JH7110_SYS_IOMUX + GPIO_CONFIG + gpio * 4, \
                        GPIO_DS_MASK, (ds) << GPIO_DS_SHIFT)
board/starfive/visionfive2/spl.c +3 -1
index b794b73b6b..388a06e4d9 100644
@@ -452,6 +452,9 @@ void board_init_f(ulong dummy)
                        JH7110_CLK_CPU_ROOT_MASK,
                        BIT(JH7110_CLK_CPU_ROOT_SHIFT));
 
+       /* Set USB overcurrent overflow pin disable */
+       SYS_IOMUX_DIN_DISABLED(2);
+
        ret = spl_board_init_f();
        if (ret) {
                debug("spl_board_init_f init failed: %d\n", ret);
--
Quoted 2 lines

2.17.1

As tested, this patch is required for the operating system after U-Boot to enable USB on at least Pine64 Star64 and Milk-V Mars CM Lite even if U-Boot does not adopt the other patches in this series.

Can this be cherry-picked separate from the series?