Add Starfive JH7110 Cadence USB driver
Subsystems (8)
Minda Chen
maintainerv2 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.
- Star64 using USB 3.0 and USB 2.0 host must add below board dts setting.
1. usb pin setting
usb_pins: usb0-0 {
driver-vbus-pin {
pinmux = <GPIOMUX(25, GPOUT_SYS_USB_DRIVE_VBUS,
GPOEN_ENABLE,
GPI_NONE)>;
bias-disable;
input-disable;
input-schmitt-disable;
slew-rate = <0>;
};
};2. related dts node setting.
&pcie0 {
status = "disabled";
};&pciephy0 {
starfive,sys-syscon = <&sys_syscon 0x18>;
starfive,stg-syscon = <&stg_syscon 0x148 0x1f4>;
status = "okay";
};&usb0 {
pinctrl-names = "default";
pinctrl-0 = <&usb_pins>;
status = "okay";
};&usb_cdns3 {
phys = <&usbphy0>, <&pciephy0>;
phy-names = "cdns3,usb2-phy", "cdns3,usb3-phy";
dr_mode = "host";
status = "okay";
};- previous version
v1: 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-8 dts, config and maintainers update.
- change:
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 (8):
usb: cdns3: Set USB PHY mode in cdns3_core_init_role()
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
pinctrl: starfive: Setup USB default disable overcurrent pin
configs: starfive: Add visionfive2 cadence USB configuration
dts: starfive: Add JH7110 Cadence USB dts node
MAINTAINERS: Update Starfive visionfive2 maintain files.
.../dts/jh7110-starfive-visionfive-2.dtsi | 5 + arch/riscv/dts/jh7110.dtsi | 52 +++++ board/starfive/visionfive2/MAINTAINERS | 2 + 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 | 202 ++++++++++++++++++ drivers/phy/starfive/phy-jh7110-usb2.c | 135 ++++++++++++ drivers/pinctrl/starfive/pinctrl-jh7110-sys.c | 11 +- drivers/usb/cdns3/Kconfig | 7 + drivers/usb/cdns3/Makefile | 2 + drivers/usb/cdns3/cdns3-starfive.c | 183 ++++++++++++++++ drivers/usb/cdns3/core.c | 25 +++ 15 files changed, 661 insertions(+), 2 deletions(-) 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: 8937bb265a7f2251c1bd999784a4ef10e9c6080d
Signature · 1 line
2.17.1
Minda Chen
maintainerPATCH v2 1/8 usb: cdns3: Set USB PHY mode in cdns3_core_init_role()
USB PHY maybe need to set PHY mode in different USB dr mode. So translate to generic PHY mode and call generic_phy_set_mode().
--- drivers/usb/cdns3/core.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/usb/cdns3/core.c +25 -0
@@ -107,6 +107,7 @@ static int cdns3_core_init_role(struct cdns3 *cdns) {struct udevice *dev = cdns->dev;enum usb_dr_mode best_dr_mode; +int mode =PHY_MODE_INVALID ;enum usb_dr_mode dr_mode;int ret =0 ;
@@ -173,6 +174,30 @@ static int cdns3_core_init_role(struct cdns3 *cdns) cdns->dr_mode = dr_mode; +if (cdns->dr_mode ==USB_DR_MODE_HOST ) { + mode =PHY_MODE_USB_HOST ; + }else if (cdns->dr_mode ==USB_DR_MODE_PERIPHERAL ) { + mode =PHY_MODE_USB_DEVICE ; + }else if (cdns->dr_mode ==USB_DR_MODE_OTG ) { + mode =PHY_MODE_USB_OTG ; + }else { +dev_err (dev,"Unknown dr mode %d\n" , cdns->dr_mode); + ret = -EINVAL ; + goto err; + } + + ret =generic_phy_set_mode (&cdns->usb2_phy, mode,0 ); +if (ret) { +dev_err (dev,"Set usb 2.0 PHY mode failed %d\n" , ret); + goto err; + } + + ret =generic_phy_set_mode (&cdns->usb3_phy, mode,0 ); +if (ret) { +dev_err (dev,"Set usb 3.0 PHY mode failed %d\n" , ret); + goto err; + } + ret =cdns3_drd_update_mode (cdns);if (ret) goto err;
Signature · 1 line
2.17.1
Minda Chen
maintainerPATCH v2 3/8 phy: starfive: Add Starfive JH7110 PCIe 2.0 PHY driver
In reply to Minda ChenAdd 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 | 202 +++++++++++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 drivers/phy/starfive/phy-jh7110-pcie.c
drivers/phy/starfive/Kconfig +7 -0
@@ -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
@@ -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 +202 -0
202 lines not on this page · raw message
Signature · 1 line
2.17.1
Minda Chen
maintainerPATCH v2 5/8 pinctrl: starfive: Setup USB default disable overcurrent pin
In reply to Minda ChenFor 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.
--- drivers/pinctrl/starfive/pinctrl-jh7110-sys.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/pinctrl/starfive/pinctrl-jh7110-sys.c +9 -2
@@ -378,8 +378,15 @@ static int jh7110_sys_pinctrl_probe(struct udevice *dev) {struct starfive_pinctrl_soc_info *info = (struct starfive_pinctrl_soc_info *)dev_get_driver_data (dev); - -return starfive_pinctrl_probe (dev, info); +struct starfive_pinctrl_priv *priv =dev_get_priv (dev); +int ret; + + ret =starfive_pinctrl_probe (dev, info); +/* Set default the usb controller overcurrent signal. */ +if (!ret) +clrsetbits_le32 (priv->base +JH7110_SYS_GPI , +GENMASK (22 ,16 ),BIT (16 )); +return ret; }static const struct udevice_id jh7110_sys_pinctrl_ids[] = {
Signature · 1 line
2.17.1
Minda Chen
maintainerPATCH v2 4/8 usb: cdns: starfive: Add cdns USB driver
In reply to Minda ChenAdd cdns USB3 wrapper driver.
--- drivers/usb/cdns3/Kconfig | 7 ++ drivers/usb/cdns3/Makefile | 2 + drivers/usb/cdns3/cdns3-starfive.c | 183 +++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 drivers/usb/cdns3/cdns3-starfive.c
drivers/usb/cdns3/Kconfig +7 -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 + 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
@@ -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 +183 -0
183 lines not on this page · raw message
Signature · 1 line
2.17.1
Minda Chen
maintainerPATCH v2 6/8 configs: starfive: Add visionfive2 cadence USB configuration
In reply to Minda ChenAdd cadence USB confiuration.
--- configs/starfive_visionfive2_defconfig | 9 +++++++++ 1 file changed, 9 insertions(+)
configs/starfive_visionfive2_defconfig +9 -0
@@ -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
Minda Chen
maintainerPATCH v2 8/8 MAINTAINERS: Update Starfive visionfive2 maintain files.
In reply to Minda ChenAdd USB related files to Starfive visionfive2 MAINTAINERS.
--- board/starfive/visionfive2/MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+)
board/starfive/visionfive2/MAINTAINERS +2 -0
@@ -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
Minda Chen
maintainerPATCH v2 2/8 phy: starfive: Add Starfive JH7110 USB 2.0 PHY driver
In reply to Minda ChenAdd 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 | 135 +++++++++++++++++++++++++ 5 files changed, 157 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
@@ -307,5 +307,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
@@ -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
@@ -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
@@ -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 +135 -0
135 lines not on this page · raw message
Signature · 1 line
2.17.1
Minda Chen
maintainerPATCH v2 7/8 dts: starfive: Add JH7110 Cadence USB dts node
In reply to Minda ChenAdd 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 | 52 +++++++++++++++++++ 2 files changed, 57 insertions(+)
arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi +5 -0
@@ -378,3 +378,8 @@ }; }; }; + +&usb_cdns3 { + dr_mode = "peripheral"; + status = "okay"; +};
arch/riscv/dts/jh7110.dtsi +52 -0
58 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 9 lines · Minda Chen
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.
- Star64 using USB 3.0 and USB 2.0 host must add below board dts setting.
Does this mean a future patch for spl_fdt_fixup_star64() is needed?
Did you also have a look at the USB on the Milk V Mars CM?
Best regards
Heinrich
Quoted 92 lines
1. usb pin setting
usb_pins: usb0-0 { driver-vbus-pin { pinmux = <GPIOMUX(25, GPOUT_SYS_USB_DRIVE_VBUS, GPOEN_ENABLE, GPI_NONE)>; bias-disable; input-disable; input-schmitt-disable; slew-rate = <0>; }; };2. related dts node setting.
&pcie0 { status = "disabled"; };&pciephy0 { starfive,sys-syscon = <&sys_syscon 0x18>; starfive,stg-syscon = <&stg_syscon 0x148 0x1f4>; status = "okay"; };&usb0 { pinctrl-names = "default"; pinctrl-0 = <&usb_pins>; status = "okay"; };&usb_cdns3 { phys = <&usbphy0>, <&pciephy0>; phy-names = "cdns3,usb2-phy", "cdns3,usb3-phy"; dr_mode = "host"; status = "okay"; };- previous version
v1: 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-8 dts, config and maintainers update.- change:
v2:
- patch 1 Move the added code tocdns3_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 (8):
usb: cdns3: Set USB PHY mode incdns3_core_init_role()
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
pinctrl: starfive: Setup USB default disable overcurrent pin
configs: starfive: Add visionfive2 cadence USB configuration
dts: starfive: Add JH7110 Cadence USB dts node
MAINTAINERS: Update Starfive visionfive2 maintain files..../dts/jh7110-starfive-visionfive-2.dtsi | 5 + arch/riscv/dts/jh7110.dtsi | 52 +++++ board/starfive/visionfive2/MAINTAINERS | 2 + 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 | 202 ++++++++++++++++++ drivers/phy/starfive/phy-jh7110-usb2.c | 135 ++++++++++++ drivers/pinctrl/starfive/pinctrl-jh7110-sys.c | 11 +- drivers/usb/cdns3/Kconfig | 7 + drivers/usb/cdns3/Makefile | 2 + drivers/usb/cdns3/cdns3-starfive.c | 183 ++++++++++++++++ drivers/usb/cdns3/core.c | 25 +++ 15 files changed, 661 insertions(+), 2 deletions(-)create mode 100644
drivers/phy/starfive/Kconfigcreate mode 100644drivers/phy/starfive/Makefilecreate mode 100644drivers/phy/starfive/phy-jh7110-pcie.ccreate mode 100644drivers/phy/starfive/phy-jh7110-usb2.ccreate mode 100644drivers/usb/cdns3/cdns3-starfive.cbase-commit:
8937bb265a7f2251c1bd999784a4ef10e9c6080d
Roger Quadros
reviewerRe: [PATCH v2 1/8] usb: cdns3: Set USB PHY mode in cdns3_core_init_role()
In reply to Minda ChenHi,
Quoted 39 lines · Minda Chen
USB PHY maybe need to set PHY mode in different USB dr mode. So translate to generic PHY mode and call
generic_phy_set_mode().Signed-off-by Minda Chen <[email protected]>--- drivers/usb/cdns3/core.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)drivers/usb/cdns3/core.c +15
-0@@ -107,6 +107,7 @@ static int cdns3_core_init_role(struct cdns3 *cdns) {struct udevice *dev = cdns->dev;enum usb_dr_mode best_dr_mode; +int mode =PHY_MODE_INVALID ;enum usb_dr_mode dr_mode;int ret =0 ;@@ -173,6 +174,30 @@ static int cdns3_core_init_role(struct cdns3 *cdns) cdns->dr_mode = dr_mode; +if (cdns->dr_mode ==USB_DR_MODE_HOST ) { + mode =PHY_MODE_USB_HOST ; + }else if (cdns->dr_mode ==USB_DR_MODE_PERIPHERAL ) { + mode =PHY_MODE_USB_DEVICE ; + }else if (cdns->dr_mode ==USB_DR_MODE_OTG ) { + mode =PHY_MODE_USB_OTG ; + }else { +dev_err (dev,"Unknown dr mode %d\n" , cdns->dr_mode); + ret = -EINVAL ; + goto err; + } + + ret =generic_phy_set_mode (&cdns->usb2_phy, mode,0 ); +if (ret) {
drivers/usb/cdns3/core.c static int cdns3_core_init_role(struct cdns3 *cdns) · line 200
Quoted 10 lines
drivers/usb/cdns3/core.c +10
-0+dev_err (dev,"Set usb 2.0 PHY mode failed %d\n" , ret); + goto err; + } + + ret =generic_phy_set_mode (&cdns->usb3_phy, mode,0 ); +if (ret) { +dev_err (dev,"Set usb 3.0 PHY mode failed %d\n" , ret); + goto err; + } +
Should we be doing the above inside cdns3_drd_update_mode() so that the PHY can be put in the correct state even during role switches?
Quoted 3 lines
drivers/usb/cdns3/core.c +0
-0ret =cdns3_drd_update_mode (cdns);if (ret) goto err;
Signature · 2 lines
cheers, -roger
Re: [PATCH v2 2/8] phy: starfive: Add Starfive JH7110 USB 2.0 PHY driver
In reply to Minda ChenQuoted 41 lines · Minda Chen
Add Starfive JH7110 USB 2.0 PHY driver, which is generic PHY driver.
Signed-off-by Minda Chen <[email protected]>--- 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 | 135 +++++++++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 drivers/phy/starfive/Kconfig create mode 100644 drivers/phy/starfive/Makefile create mode 100644 drivers/phy/starfive/phy-jh7110-usb2.cdrivers/phy/Kconfig +1
-0@@ -307,5 +307,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" endmenudrivers/phy/Makefile +1
-0@@ -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 +0
-0
drivers/phy/starfive/Kconfig line 2
Quoted 2 lines
drivers/phy/starfive/Kconfig new file +2
-0@@ -0,0 +1,14 @@ +# +# Phy drivers for Starfive platforms
PHY?
Quoted 154 lines
drivers/phy/starfive/Kconfig new file +12
-0+# + +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. + +endmenudrivers/phy/starfive/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2023 Starfive +# + +obj-$(CONFIG_PHY_STARFIVE_JH7110_USB2) += phy-jh7110-usb2.odrivers/phy/starfive/phy-jh7110-usb2.c new file +124
-0@@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* StarFive JH7110 USB 2.0 PHY driver +* +* Copyright (C) 2024 StarFive Technology Co., Ltd. +* Author: Minda Chen <[email protected]> +*/ + +#include <asm/io.h> +#include <clk.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <errno.h> +#include <generic-phy.h> +#include <regmap.h> +#include <soc.h> +#include <syscon.h> +#include <linux/bitops.h> +#include <linux/err.h> + +#define USB_LS_KEEPALIVE_OFF 0x4 +#define USB_LS_KEEPALIVE_ENABLE BIT(4) +#define USB_PHY_CLK_RATE 125000000 + +struct jh7110_usb2_phy { +struct phy *phy; +void __iomem *regs; +struct clk *usb_125m_clk; +struct clk *app_125m; +enum phy_mode mode; +}; + +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 ); +} + +static int usb2_phy_set_mode (struct phy *_phy, +enum phy_mode mode,int submode) +{ +struct udevice *dev = _phy->dev; +struct jh7110_usb2_phy *phy =dev_get_priv (dev); + +if (mode == phy->mode) +return 0 ; + +switch (mode) { +case PHY_MODE_USB_HOST : +case PHY_MODE_USB_DEVICE : +case PHY_MODE_USB_OTG : +dev_dbg (dev,"Changing phy to %d\n" , mode); + phy->mode = mode; +usb2_set_ls_keepalive (phy, (mode !=PHY_MODE_USB_DEVICE )); +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int jh7110_usb2_phy_init (struct phy *_phy) +{ +struct udevice *dev = _phy->dev; +struct jh7110_usb2_phy *phy =dev_get_priv (dev); +int ret; + + ret =clk_set_rate (phy->usb_125m_clk,USB_PHY_CLK_RATE ); +if (ret <0 ) { +dev_err (dev,"Failed to set 125m clock\n" ); +return ret; + } + +return clk_prepare_enable (phy->app_125m); +} + +static int jh7110_usb2_phy_exit (struct phy *_phy) +{ +struct udevice *dev = _phy->dev; +struct jh7110_usb2_phy *phy =dev_get_priv (dev); + +clk_disable_unprepare (phy->app_125m); + +return 0 ; +} + +struct phy_ops jh7110_usb2_phy_ops = { + .init = jh7110_usb2_phy_init, + .exit = jh7110_usb2_phy_exit, + .set_mode = usb2_phy_set_mode, +}; + +int jh7110_usb2_phy_probe (struct udevice *dev) +{ +struct jh7110_usb2_phy *phy =dev_get_priv (dev); + + phy->regs =dev_read_addr_ptr (dev); +if (!phy->regs) +return -EINVAL ; + + phy->usb_125m_clk =devm_clk_get (dev,"125m" ); +if (IS_ERR (phy->usb_125m_clk)) { +dev_err (dev,"Failed to get 125m clock\n" ); +return PTR_ERR (phy->usb_125m_clk); + } + + phy->app_125m =devm_clk_get (dev,"app_125m" ); +if (IS_ERR (phy->app_125m)) { +dev_err (dev,"Failed to get app 125m clock\n" ); +return PTR_ERR (phy->app_125m); + } + +return 0 ; +} + +static const struct udevice_id jh7110_usb2_phy[] = { + { .compatible ="starfive,jh7110-usb-phy" },
drivers/phy/starfive/phy-jh7110-usb2.c line 134
Quoted 10 lines
drivers/phy/starfive/phy-jh7110-usb2.c new file +10
-0+ {}, +}; + +U_BOOT_DRIVER (jh7110_usb2_phy) = { + .name ="jh7110_usb2_phy" , + .id =UCLASS_PHY , + .of_match = jh7110_usb2_phy, + .probe = jh7110_usb2_phy_probe, + .ops = &jh7110_usb2_phy_ops, + .priv_auto =sizeof (struct jh7110_usb2_phy ),
how about space instead of tab?
drivers/phy/starfive/phy-jh7110-usb2.c line 135
Quoted 1 line
drivers/phy/starfive/phy-jh7110-usb2.c new file +1
-0+};
Signature · 2 lines
cheers, -roger
Roger Quadros
reviewerRe: [PATCH v2 3/8] phy: starfive: Add Starfive JH7110 PCIe 2.0 PHY driver
In reply to Minda ChenQuoted 16 lines · Minda Chen
Add Starfive JH7110 PCIe 2.0 PHY driver, which is generic PHY driver and can be used as USB 3.0 driver.
Signed-off-by Minda Chen <[email protected]>--- drivers/phy/starfive/Kconfig | 7 + drivers/phy/starfive/Makefile | 1 + drivers/phy/starfive/phy-jh7110-pcie.c | 202 +++++++++++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 drivers/phy/starfive/phy-jh7110-pcie.cdrivers/phy/starfive/Kconfig +0
-0
drivers/phy/starfive/Kconfig line 12
Quoted 9 lines
drivers/phy/starfive/Kconfig +6
-0@@ -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.
Should be aligned to previous line.
Quoted 31 lines
drivers/phy/starfive/Kconfig +1
-0+ config PHY_STARFIVE_JH7110_USB2 bool "Starfive JH7110 USB 2.0 PHY driver" select PHYdrivers/phy/starfive/Makefile +1
-0@@ -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.odrivers/phy/starfive/phy-jh7110-pcie.c new file +11
-0@@ -0,0 +1,202 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* StarFive JH7110 PCIe 2.0 PHY driver +* +* Copyright (C) 2024 StarFive Technology Co., Ltd. +* Author: Minda Chen <[email protected]> +*/ +#include <asm/io.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <errno.h>
drivers/phy/starfive/phy-jh7110-pcie.c line 21
Quoted 10 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +10
-0+#include <generic-phy.h> +#include <regmap.h> +#include <soc.h> +#include <syscon.h> +#include <linux/bitops.h> +#include <linux/err.h> + +#define PCIE_KVCO_LEVEL_OFF 0x28 +#define PCIE_USB3_PHY_PLL_CTL_OFF 0x7c +#define PCIE_USB3_PHY_SS_MODE BIT(4)
extra tab?
drivers/phy/starfive/phy-jh7110-pcie.c line 34
Quoted 13 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +13
-0+#define PCIE_KVCO_TUNE_SIGNAL_OFF 0x80 +#define PHY_KVCO_FINE_TUNE_LEVEL 0x91 +#define PHY_KVCO_FINE_TUNE_SIGNALS 0xc + +#define USB_PDRSTN_SPLIT BIT(17) + +#define PCIE_USB3_PHY_MODE BIT(20) +#define PCIE_PHY_MODE_MASK GENMASK(21, 20) +#define PCIE_USB3_BUS_WIDTH_MASK GENMASK(3, 2) +#define PCIE_BUS_WIDTH BIT(3) +#define PCIE_USB3_RATE_MASK GENMASK(6, 5) +#define PCIE_USB3_RX_STANDBY_MASK BIT(7) +#define PCIE_USB3_PHY_ENABLE BIT(4)
Why not use define and use regmap_fields? You are already using regmap.
Quoted 113 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +113
-0+ +struct jh7110_pcie_phy { +struct phy *phy; +struct regmap *stg_syscon; +struct regmap *sys_syscon; +void __iomem *regs; +u32 sys_phy_connect; +u32 stg_pcie_mode; +u32 stg_pcie_usb; +enum phy_mode mode; +}; + +static int phy_pcie_mode_set (struct jh7110_pcie_phy *data,bool usb_mode) +{ +unsigned int phy_mode, width, usb3_phy, ss_mode; + +/* 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" ); +return -EINVAL ; + } +return 0 ; + } + +if (usb_mode) { + phy_mode =PCIE_USB3_PHY_MODE ; + width =0 ; + usb3_phy =PCIE_USB3_PHY_ENABLE ; + ss_mode =PCIE_USB3_PHY_SS_MODE ; + }else { + phy_mode =0 ; + width =PCIE_BUS_WIDTH ; + usb3_phy =0 ; + ss_mode =0 ; + } + +regmap_update_bits (data->stg_syscon, data->stg_pcie_mode, +PCIE_PHY_MODE_MASK , phy_mode); +regmap_update_bits (data->stg_syscon, data->stg_pcie_usb, +PCIE_USB3_BUS_WIDTH_MASK , width); +regmap_update_bits (data->stg_syscon, data->stg_pcie_usb, +PCIE_USB3_PHY_ENABLE , usb3_phy); +clrsetbits_le32 (data->regs +PCIE_USB3_PHY_PLL_CTL_OFF , +PCIE_USB3_PHY_SS_MODE , ss_mode); + +regmap_update_bits (data->sys_syscon, data->sys_phy_connect, +USB_PDRSTN_SPLIT ,0 ); + +return 0 ; +} + +static void phy_kvco_gain_set (struct jh7110_pcie_phy *phy) +{ +/* PCIe Multi-PHY PLL KVCO Gain fine tune settings: */ +writel (PHY_KVCO_FINE_TUNE_LEVEL , phy->regs +PCIE_KVCO_LEVEL_OFF ); +writel (PHY_KVCO_FINE_TUNE_SIGNALS , phy->regs +PCIE_KVCO_TUNE_SIGNAL_OFF ); +} + +static int jh7110_pcie_phy_set_mode (struct phy *_phy, +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) +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->mode = mode; + +return 0 ; +} + +static const struct phy_ops jh7110_pcie_phy_ops = { + .set_mode = jh7110_pcie_phy_set_mode, +}; + +static int starfive_pcie_phy_get_syscon (struct udevice *dev) +{ +struct jh7110_pcie_phy *phy =dev_get_priv (dev); +struct ofnode_phandle_args sys_phandle, stg_phandle; +int ret; + +/* get corresponding syscon phandle */ + ret =dev_read_phandle_with_args (dev,"starfive,sys-syscon" ,NULL ,1 ,0 , + &sys_phandle); + +if (ret <0 ) { +dev_err (dev,"Can't get sys cfg phandle: %d\n" , ret); +return ret; + } + + ret =dev_read_phandle_with_args (dev,"starfive,stg-syscon" ,NULL ,2 ,0 , + &stg_phandle); + +if (ret <0 ) {
drivers/phy/starfive/phy-jh7110-pcie.c line 157
Quoted 10 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +10
-0+dev_err (dev,"Can't get stg cfg phandle: %d\n" , ret); +return ret; + } + + phy->sys_syscon =syscon_node_to_regmap (sys_phandle.node); +if (!IS_ERR_OR_NULL (phy->sys_syscon)) { +/* get syscon register offset */ + phy->sys_phy_connect = sys_phandle.args[0 ]; + }else { + phy->sys_syscon =NULL ;
Why not error out if you could not get the sys_syscon regmap?
drivers/phy/starfive/phy-jh7110-pcie.c line 165
Quoted 8 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +8
-0+ } + + phy->stg_syscon =syscon_node_to_regmap (stg_phandle.node); +if (!IS_ERR_OR_NULL (phy->stg_syscon)) { + phy->stg_pcie_mode = stg_phandle.args[0 ]; + phy->stg_pcie_usb = stg_phandle.args[1 ]; + }else { + phy->stg_syscon =NULL ;
same here?
Quoted 25 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +25
-0+ } + +return 0 ; +} + +int jh7110_pcie_phy_probe (struct udevice *dev) +{ +struct jh7110_pcie_phy *phy =dev_get_priv (dev); +int rc; + + phy->regs =dev_read_addr_ptr (dev); +if (!phy->regs) +return -EINVAL ; + + rc =starfive_pcie_phy_get_syscon (dev); +if (rc) +return rc; + +phy_kvco_gain_set (phy); + +return 0 ; +} + +static const struct udevice_id jh7110_pcie_phy[] = { + { .compatible ="starfive,jh7110-pcie-phy" },
drivers/phy/starfive/phy-jh7110-pcie.c line 200
Quoted 10 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +10
-0+ {}, +}; + +U_BOOT_DRIVER (jh7110_pcie_phy) = { + .name ="jh7110_pcie_phy" , + .id =UCLASS_PHY , + .of_match = jh7110_pcie_phy, + .probe = jh7110_pcie_phy_probe, + .ops = &jh7110_pcie_phy_ops, + .priv_auto =sizeof (struct jh7110_pcie_phy ),
need space instead of tab?
Quoted 2 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +2
-0+}; +
Signature · 2 lines
cheers, -roger
Roger Quadros
reviewerRe: [PATCH v2 3/8] phy: starfive: Add Starfive JH7110 PCIe 2.0 PHY driver
In reply to Minda ChenQuoted 237 lines · Minda Chen
Add Starfive JH7110 PCIe 2.0 PHY driver, which is generic PHY driver and can be used as USB 3.0 driver.
Signed-off-by Minda Chen <[email protected]>--- drivers/phy/starfive/Kconfig | 7 + drivers/phy/starfive/Makefile | 1 + drivers/phy/starfive/phy-jh7110-pcie.c | 202 +++++++++++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 drivers/phy/starfive/phy-jh7110-pcie.cdrivers/phy/starfive/Kconfig +7
-0@@ -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 PHYdrivers/phy/starfive/Makefile +1
-0@@ -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.odrivers/phy/starfive/phy-jh7110-pcie.c new file +192
-0@@ -0,0 +1,202 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* StarFive JH7110 PCIe 2.0 PHY driver +* +* Copyright (C) 2024 StarFive Technology Co., Ltd. +* Author: Minda Chen <[email protected]> +*/ +#include <asm/io.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <errno.h> +#include <generic-phy.h> +#include <regmap.h> +#include <soc.h> +#include <syscon.h> +#include <linux/bitops.h> +#include <linux/err.h> + +#define PCIE_KVCO_LEVEL_OFF 0x28 +#define PCIE_USB3_PHY_PLL_CTL_OFF 0x7c +#define PCIE_USB3_PHY_SS_MODE BIT(4) +#define PCIE_KVCO_TUNE_SIGNAL_OFF 0x80 +#define PHY_KVCO_FINE_TUNE_LEVEL 0x91 +#define PHY_KVCO_FINE_TUNE_SIGNALS 0xc + +#define USB_PDRSTN_SPLIT BIT(17) + +#define PCIE_USB3_PHY_MODE BIT(20) +#define PCIE_PHY_MODE_MASK GENMASK(21, 20) +#define PCIE_USB3_BUS_WIDTH_MASK GENMASK(3, 2) +#define PCIE_BUS_WIDTH BIT(3) +#define PCIE_USB3_RATE_MASK GENMASK(6, 5) +#define PCIE_USB3_RX_STANDBY_MASK BIT(7) +#define PCIE_USB3_PHY_ENABLE BIT(4) + +struct jh7110_pcie_phy { +struct phy *phy; +struct regmap *stg_syscon; +struct regmap *sys_syscon; +void __iomem *regs; +u32 sys_phy_connect; +u32 stg_pcie_mode; +u32 stg_pcie_usb; +enum phy_mode mode; +}; + +static int phy_pcie_mode_set (struct jh7110_pcie_phy *data,bool usb_mode) +{ +unsigned int phy_mode, width, usb3_phy, ss_mode; + +/* 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" ); +return -EINVAL ; + } +return 0 ; + } + +if (usb_mode) { + phy_mode =PCIE_USB3_PHY_MODE ; + width =0 ; + usb3_phy =PCIE_USB3_PHY_ENABLE ; + ss_mode =PCIE_USB3_PHY_SS_MODE ; + }else { + phy_mode =0 ; + width =PCIE_BUS_WIDTH ; + usb3_phy =0 ; + ss_mode =0 ; + } + +regmap_update_bits (data->stg_syscon, data->stg_pcie_mode, +PCIE_PHY_MODE_MASK , phy_mode); +regmap_update_bits (data->stg_syscon, data->stg_pcie_usb, +PCIE_USB3_BUS_WIDTH_MASK , width); +regmap_update_bits (data->stg_syscon, data->stg_pcie_usb, +PCIE_USB3_PHY_ENABLE , usb3_phy); +clrsetbits_le32 (data->regs +PCIE_USB3_PHY_PLL_CTL_OFF , +PCIE_USB3_PHY_SS_MODE , ss_mode); + +regmap_update_bits (data->sys_syscon, data->sys_phy_connect, +USB_PDRSTN_SPLIT ,0 ); + +return 0 ; +} + +static void phy_kvco_gain_set (struct jh7110_pcie_phy *phy) +{ +/* PCIe Multi-PHY PLL KVCO Gain fine tune settings: */ +writel (PHY_KVCO_FINE_TUNE_LEVEL , phy->regs +PCIE_KVCO_LEVEL_OFF ); +writel (PHY_KVCO_FINE_TUNE_SIGNALS , phy->regs +PCIE_KVCO_TUNE_SIGNAL_OFF ); +} + +static int jh7110_pcie_phy_set_mode (struct phy *_phy, +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) +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->mode = mode; + +return 0 ; +} + +static const struct phy_ops jh7110_pcie_phy_ops = { + .set_mode = jh7110_pcie_phy_set_mode, +}; + +static int starfive_pcie_phy_get_syscon (struct udevice *dev) +{ +struct jh7110_pcie_phy *phy =dev_get_priv (dev); +struct ofnode_phandle_args sys_phandle, stg_phandle; +int ret; + +/* get corresponding syscon phandle */ + ret =dev_read_phandle_with_args (dev,"starfive,sys-syscon" ,NULL ,1 ,0 , + &sys_phandle); + +if (ret <0 ) { +dev_err (dev,"Can't get sys cfg phandle: %d\n" , ret); +return ret; + } + + ret =dev_read_phandle_with_args (dev,"starfive,stg-syscon" ,NULL ,2 ,0 , + &stg_phandle); + +if (ret <0 ) { +dev_err (dev,"Can't get stg cfg phandle: %d\n" , ret); +return ret; + } + + phy->sys_syscon =syscon_node_to_regmap (sys_phandle.node); +if (!IS_ERR_OR_NULL (phy->sys_syscon)) { +/* get syscon register offset */ + phy->sys_phy_connect = sys_phandle.args[0 ]; + }else { + phy->sys_syscon =NULL ; + } + + phy->stg_syscon =syscon_node_to_regmap (stg_phandle.node); +if (!IS_ERR_OR_NULL (phy->stg_syscon)) { + phy->stg_pcie_mode = stg_phandle.args[0 ]; + phy->stg_pcie_usb = stg_phandle.args[1 ]; + }else { + phy->stg_syscon =NULL ; + } + +return 0 ; +} + +int jh7110_pcie_phy_probe (struct udevice *dev) +{ +struct jh7110_pcie_phy *phy =dev_get_priv (dev); +int rc; + + phy->regs =dev_read_addr_ptr (dev); +if (!phy->regs) +return -EINVAL ; + + rc =starfive_pcie_phy_get_syscon (dev); +if (rc) +return rc; + +phy_kvco_gain_set (phy); + +return 0 ; +} + +static const struct udevice_id jh7110_pcie_phy[] = { + { .compatible ="starfive,jh7110-pcie-phy" }, + {}, +};
drivers/phy/starfive/phy-jh7110-pcie.c line 202
Quoted 10 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +10
-0+ +U_BOOT_DRIVER (jh7110_pcie_phy) = { + .name ="jh7110_pcie_phy" , + .id =UCLASS_PHY , + .of_match = jh7110_pcie_phy, + .probe = jh7110_pcie_phy_probe, + .ops = &jh7110_pcie_phy_ops, + .priv_auto =sizeof (struct jh7110_pcie_phy ), +}; +
Please drop the new blank line at the end.
Signature · 2 lines
cheers, -roger
Roger Quadros
reviewerRe: [PATCH v2 4/8] usb: cdns: starfive: Add cdns USB driver
In reply to Minda ChenQuoted 149 lines · Minda Chen
Add cdns USB3 wrapper driver.
Signed-off-by Minda Chen <[email protected]>--- drivers/usb/cdns3/Kconfig | 7 ++ drivers/usb/cdns3/Makefile | 2 + drivers/usb/cdns3/cdns3-starfive.c | 183 +++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 drivers/usb/cdns3/cdns3-starfive.cdrivers/usb/cdns3/Kconfig +7
-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 + help + Say 'Y' here if you are building for Starfive platforms + that contain Cadence USB3 controller core. E.g.: JH7110. endifdrivers/usb/cdns3/Makefile +2
-0@@ -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.odrivers/usb/cdns3/cdns3-starfive.c new file +107
-0@@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* cdns3-starfive.c - StarFive specific Glue layer for Cadence USB Controller +* +* Copyright (C) 2024 StarFive Technology Co., Ltd. +* +* Author: Minda Chen <[email protected]> +*/ + +#include <asm/io.h> +#include <clk.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <linux/bitops.h> +#include <linux/usb/otg.h> +#include <reset.h> +#include <regmap.h> +#include <syscon.h> +#include <malloc.h> + +#include "core.h" + +#define USB_STRAP_HOST BIT(17) +#define USB_STRAP_DEVICE BIT(18) +#define USB_STRAP_MASK GENMASK(18, 16) + +#define USB_SUSPENDM_HOST BIT(19) +#define USB_SUSPENDM_MASK BIT(19) + +#define USB_MISC_CFG_MASK GENMASK(23, 20) +#define USB_SUSPENDM_BYPS BIT(20) +#define USB_PLL_EN BIT(22) +#define USB_REFCLK_MODE BIT(23) + +struct cdns_starfive { +struct udevice *dev; +struct regmap *stg_syscon; +struct reset_ctl_bulk resets; +struct clk_bulk clks; +u32 stg_usb_mode; +enum usb_dr_mode mode; +}; + +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 ; + 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); +} + +static void cdns_clk_rst_deinit (struct cdns_starfive *data) +{ +reset_assert_bulk (&data->resets); +clk_disable_bulk (&data->clks); +} + +static int cdns_clk_rst_init (struct cdns_starfive *data) +{ +int ret; + + ret =clk_get_bulk (data->dev, &data->clks); +if (ret) +return ret; + + ret =reset_get_bulk (data->dev, &data->resets); +if (ret) + goto err_clk; + + ret =clk_enable_bulk (&data->clks); +if (ret) + goto err_en_clk; + + ret =reset_deassert_bulk (&data->resets); +if (ret) + goto err_reset; + +return 0 ; + +err_reset: +clk_disable_bulk (&data->clks); +err_en_clk: +reset_release_bulk (&data->resets); +err_clk: +clk_release_bulk (&data->clks); + +return ret;
drivers/usb/cdns3/cdns3-starfive.c line 117
Quoted 10 lines
drivers/usb/cdns3/cdns3-starfive.c new file +10
-0+} + +static int cdns_starfive_get_syscon (struct cdns_starfive *data) +{ +struct ofnode_phandle_args phandle; +int ret; + + ret =dev_read_phandle_with_args (data->dev,"starfive,stg-syscon" ,NULL ,1 ,0 , + &phandle); +
unnecessary blank line
drivers/usb/cdns3/cdns3-starfive.c line 127
Quoted 10 lines
drivers/usb/cdns3/cdns3-starfive.c new file +10
-0+if (ret <0 ) { +dev_err (data->dev,"Can't get stg cfg phandle: %d\n" , ret); +return ret; + } + + data->stg_syscon =syscon_node_to_regmap (phandle.node); +if (IS_ERR (data->stg_syscon)) { +dev_err (data->dev,"fail to get regmap: %d\n" , (int )PTR_ERR (data->stg_syscon)); +return PTR_ERR (data->stg_syscon); + }
Need a new blank line?
Quoted 6 lines
drivers/usb/cdns3/cdns3-starfive.c new file +6
-0+ data->stg_usb_mode = phandle.args[0 ]; + +return 0 ; +} + +static int cdns_starfive_probe (struct udevice *dev)
drivers/usb/cdns3/cdns3-starfive.c line 143
Quoted 10 lines
drivers/usb/cdns3/cdns3-starfive.c new file +10
-0+{ +struct cdns_starfive *data =dev_get_plat (dev); +enum usb_dr_mode dr_mode; +ofnode node; +int ret; + + data->dev = dev; + + ret =cdns_starfive_get_syscon (data); +
unnecessary blank new lines.
drivers/usb/cdns3/cdns3-starfive.c line 156
Quoted 13 lines
drivers/usb/cdns3/cdns3-starfive.c new file +13
-0+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" ); +return -ENODEV ; + } + + dr_mode =usb_get_dr_mode (node); + + data->mode = dr_mode; +cdns_mode_init (data, dr_mode);
Don't you need to release reset and enable clock before doing cdns_mode_init()?
Quoted 27 lines
drivers/usb/cdns3/cdns3-starfive.c new file +27
-0+ +return cdns_clk_rst_init (data); +} + +static int cdns_starfive_remove (struct udevice *dev) +{ +struct cdns_starfive *data =dev_get_plat (dev); + +cdns_clk_rst_deinit (data); +return 0 ; +} + +static const struct udevice_id cdns_starfive_of_match[] = { + { .compatible ="starfive,jh7110-usb" , }, + {}, +}; + +U_BOOT_DRIVER (cdns_starfive) = { + .name ="cdns-starfive" , + .id =UCLASS_NOP , + .of_match = cdns_starfive_of_match, + .bind = cdns3_bind, + .probe = cdns_starfive_probe, + .remove = cdns_starfive_remove, + .plat_auto =sizeof (struct cdns_starfive ), + .flags =DM_FLAG_OS_PREPARE , +};
Signature · 2 lines
cheers, -roger
Quoted 5 lines · Heinrich Schuchardt
Quoted 3 lines · Minda Chen
Add Starfive JH7110 Cadence USB driver and related PHY driver. So the codes can be used in visionfive2 and star64 7110 board.
Quoted 8 lines
Quoted 6 lines
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.
- Star64 using USB 3.0 and USB 2.0 host must add below board dts setting.
Does this mean a future patch for
spl_fdt_fixup_star64()is needed?
As said by Hal they will be introducing a patchset to OF_UPSTREAM the JH7110 board support so we should pursue that first to get dts upstream (Linux?) aligned with U-Boot.
Quoted 2 lines
Did you also have a look at the USB on the Milk V Mars CM?
With Minda's advice for Star64 applied to jh7110-starfive-visionfive-2.dtsi directly as a test on Milk-V Mars CM Lite:
StarFive # usb info
1: Hub, USB Revision 3.0
- U-Boot XHCI Host Controller
- Class: Hub
- PacketSize: 512 Configurations: 1
- Vendor: 0x0000 Product 0x0000 Version 1.0
Configuration: 1
- Interfaces: 1 Self Powered 0mA
Interface: 0
- Alternate Setting 0, Endpoints: 1
- Class Hub
- Endpoint 1 In Interrupt MaxPacket 8 Interval 255ms
Quoted 29 lines
Best regards
Heinrich
Quoted 24 lines
1. usb pin setting
usb_pins: usb0-0 { driver-vbus-pin { pinmux = <GPIOMUX(25, GPOUT_SYS_USB_DRIVE_VBUS, GPOEN_ENABLE, GPI_NONE)>; bias-disable; input-disable; input-schmitt-disable; slew-rate = <0>; }; };2. related dts node setting.
&pcie0 { status = "disabled"; };&pciephy0 { starfive,sys-syscon = <&sys_syscon 0x18>; starfive,stg-syscon = <&stg_syscon 0x148 0x1f4>; status = "okay"; };
Question I have is: Where is the documentation for these "magical"
numbers 0x18 00x148 0x1f4 ? Is this a defined constant, or else where is this in the Technical Reference Manual?
Quoted 67 lines
Quoted 67 lines
&usb0 { pinctrl-names = "default"; pinctrl-0 = <&usb_pins>; status = "okay"; };&usb_cdns3 { phys = <&usbphy0>, <&pciephy0>; phy-names = "cdns3,usb2-phy", "cdns3,usb3-phy"; dr_mode = "host"; status = "okay"; };- previous version
v1: 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-8 dts, config and maintainers update.- change:
v2:
- patch 1 Move the added code tocdns3_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 (8):
usb: cdns3: Set USB PHY mode incdns3_core_init_role()
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
pinctrl: starfive: Setup USB default disable overcurrent pin
configs: starfive: Add visionfive2 cadence USB configuration
dts: starfive: Add JH7110 Cadence USB dts node
MAINTAINERS: Update Starfive visionfive2 maintain files..../dts/jh7110-starfive-visionfive-2.dtsi | 5 + arch/riscv/dts/jh7110.dtsi | 52 +++++ board/starfive/visionfive2/MAINTAINERS | 2 + 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 | 202 ++++++++++++++++++ drivers/phy/starfive/phy-jh7110-usb2.c | 135 ++++++++++++ drivers/pinctrl/starfive/pinctrl-jh7110-sys.c | 11 +- drivers/usb/cdns3/Kconfig | 7 + drivers/usb/cdns3/Makefile | 2 + drivers/usb/cdns3/cdns3-starfive.c | 183 ++++++++++++++++ drivers/usb/cdns3/core.c | 25 +++ 15 files changed, 661 insertions(+), 2 deletions(-)create mode 100644
drivers/phy/starfive/Kconfigcreate mode 100644drivers/phy/starfive/Makefilecreate mode 100644drivers/phy/starfive/phy-jh7110-pcie.ccreate mode 100644drivers/phy/starfive/phy-jh7110-usb2.ccreate mode 100644drivers/usb/cdns3/cdns3-starfive.c
Quoted 2 lines
Quoted 1 line
base-commit:
8937bb265a7f2251c1bd999784a4ef10e9c6080d
Thanks very much Minda, I am happy to see some USB Host function on
Milk-V Mars CM Lite here. -E Shattow
Minda Chen
maintainerQuoted 74 lines
Quoted 5 lines · Heinrich Schuchardt
Quoted 3 lines · Minda Chen
Add Starfive JH7110 Cadence USB driver and related PHY driver. So the codes can be used in visionfive2 and star64 7110 board.
Quoted 8 lines
Quoted 6 lines
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.
- Star64 using USB 3.0 and USB 2.0 host must add below board dts setting.
Does this mean a future patch for
spl_fdt_fixup_star64()is needed?As said by Hal they will be introducing a patchset to
OF_UPSTREAMthe JH7110 board support so we should pursue that first to get dts upstream (Linux?) aligned with U-Boot.Quoted 2 lines
Did you also have a look at the USB on the Milk V Mars CM?
With Minda's advice for Star64 applied to
jh7110-starfive-visionfive-2.dtsidirectly as a test on Milk-V Mars CM
Lite:StarFive # usb info
1: Hub, USB Revision 3.0
- U-Boot XHCI Host Controller
- Class: Hub
- PacketSize: 512 Configurations: 1
- Vendor:0x0000Product0x0000Version 1.0
Configuration: 1
- Interfaces: 1 Self Powered 0mA
Interface: 0
- Alternate Setting 0, Endpoints: 1
- Class Hub
- Endpoint 1 In Interrupt MaxPacket 8 Interval 255msQuoted 10 lines
Best regards
Heinrich
Quoted 5 lines
1. usb pin setting
usb_pins: usb0-0 { driver-vbus-pin { pinmux = <GPIOMUX(25,
GPOUT_SYS_USB_DRIVE_VBUS,Quoted 14 lines
Quoted 14 lines
GPOEN_ENABLE, GPI_NONE)>; bias-disable; input-disable; input-schmitt-disable; slew-rate = <0>; }; };2. related dts node setting.
&pcie0 { status = "disabled"; };Quoted 5 lines
Quoted 5 lines
&pciephy0 { starfive,sys-syscon = <&sys_syscon 0x18>; starfive,stg-syscon = <&stg_syscon 0x148 0x1f4>; status = "okay"; };
Quoted 4 lines
Question I have is: Where is the documentation for these "magical"
numbers0x1800x1480x1f4? Is this a defined constant, or else where is this in the Technical Reference Manual?
This is USB 3.0 configuration. 0x18 0x148 and 0x1f4 is register offset. MilkV CM is USB 2.0 host. It is not needed.
And I don't know whether Vbus pin is GPIO25 in CM board. If not, I think Just set dr mode to host is OK in Milk-V CM board.
Quoted 76 lines
Quoted 46 lines
Quoted 46 lines
&usb0 { pinctrl-names = "default"; pinctrl-0 = <&usb_pins>; status = "okay"; };&usb_cdns3 { phys = <&usbphy0>, <&pciephy0>; phy-names = "cdns3,usb2-phy", "cdns3,usb3-phy"; dr_mode = "host"; status = "okay"; };- previous version
v1:
https://patchwork.ozlabs.org/project/uboot/cover/20240504150358.1960
[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-8 dts, config and maintainers update.- change:
v2:
- patch 1 Move the added code tocdns3_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 (8):
usb: cdns3: Set USB PHY mode incdns3_core_init_role()
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
pinctrl: starfive: Setup USB default disable overcurrent pin
configs: starfive: Add visionfive2 cadence USB configuration
dts: starfive: Add JH7110 Cadence USB dts node
MAINTAINERS: Update Starfive visionfive2 maintain files.Quoted 9 lines
Quoted 9 lines
.../dts/jh7110-starfive-visionfive-2.dtsi | 5 + arch/riscv/dts/jh7110.dtsi | 52 +++++ board/starfive/visionfive2/MAINTAINERS | 2 + 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 | 202++++++++++++++++++
Quoted 5 lines
Quoted 5 lines
drivers/phy/starfive/phy-jh7110-usb2.c | 135 ++++++++++++ drivers/pinctrl/starfive/pinctrl-jh7110-sys.c | 11 +- drivers/usb/cdns3/Kconfig | 7 + drivers/usb/cdns3/Makefile | 2 + drivers/usb/cdns3/cdns3-starfive.c | 183++++++++++++++++
Quoted 11 lines
Quoted 10 lines
drivers/usb/cdns3/core.c | 25 +++ 15 files changed, 661 insertions(+), 2 deletions(-)create mode 100644
drivers/phy/starfive/Kconfigcreate mode 100644drivers/phy/starfive/Makefilecreate mode 100644drivers/phy/starfive/phy-jh7110-pcie.ccreate mode 100644drivers/phy/starfive/phy-jh7110-usb2.ccreate mode 100644drivers/usb/cdns3/cdns3-starfive.cbase-commit:
8937bb265a7f2251c1bd999784a4ef10e9c6080dThanks very much Minda, I am happy to see some USB Host function on
Milk-V Mars CM Lite here. -E Shattow
Minda Chen
maintainerRe: [PATCH v2 1/8] usb: cdns3: Set USB PHY mode in cdns3_core_init_role()
In reply to Roger QuadrosQuoted 50 lines
Hi,
Quoted 44 lines · Minda Chen
USB PHY maybe need to set PHY mode in different USB dr mode. So translate to generic PHY mode and call
generic_phy_set_mode().Signed-off-by Minda Chen <[email protected]>--- drivers/usb/cdns3/core.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)drivers/usb/cdns3/core.c index renamed from drivers/usb/cdns3/core.c +0
-0
12a741c6ea..1e863bed89100644drivers/usb/cdns3/core.c +20
-0@@ -107,6 +107,7 @@ static int cdns3_core_init_role(struct cdns3 *cdns) {struct udevice *dev = cdns->dev;enum usb_dr_mode best_dr_mode; +int mode =PHY_MODE_INVALID ;enum usb_dr_mode dr_mode;int ret =0 ;@@ -173,6 +174,30 @@ static int cdns3_core_init_role(struct cdns3 *cdns) cdns->dr_mode = dr_mode; +if (cdns->dr_mode ==USB_DR_MODE_HOST ) { + mode =PHY_MODE_USB_HOST ; + }else if (cdns->dr_mode ==USB_DR_MODE_PERIPHERAL ) { + mode =PHY_MODE_USB_DEVICE ; + }else if (cdns->dr_mode ==USB_DR_MODE_OTG ) { + mode =PHY_MODE_USB_OTG ; + }else { +dev_err (dev,"Unknown dr mode %d\n" , cdns->dr_mode); + ret = -EINVAL ; + goto err; + } + + ret =generic_phy_set_mode (&cdns->usb2_phy, mode,0 ); +if (ret) { +dev_err (dev,"Set usb 2.0 PHY mode failed %d\n" , ret); + goto err; + } + + ret =generic_phy_set_mode (&cdns->usb3_phy, mode,0 );
Quoted 9 lines
drivers/usb/cdns3/core.c static int cdns3_core_init_role(struct cdns3 *cdns) · line 200
Quoted 5 lines
drivers/usb/cdns3/core.c +5
-0+if (ret) { +dev_err (dev,"Set usb 3.0 PHY mode failed %d\n" , ret); + goto err; + } +Should we be doing the above inside
cdns3_drd_update_mode()so that the PHY can be put in the correct state even during role switches?
OK, Thanks.
Quoted 7 lines
Quoted 3 lines
drivers/usb/cdns3/core.c +0
-0ret =cdns3_drd_update_mode (cdns);if (ret)goto err;
--
cheers,
-roger
Minda Chen
maintainerRe: [PATCH v2 3/8] phy: starfive: Add Starfive JH7110 PCIe 2.0 PHY driver
In reply to Roger QuadrosQuoted 203 lines · Minda Chen
Quoted 17 lines
Add Starfive JH7110 PCIe 2.0 PHY driver, which is generic PHY driver and can be used as USB 3.0 driver.
Signed-off-by Minda Chen <[email protected]>--- drivers/phy/starfive/Kconfig | 7 + drivers/phy/starfive/Makefile | 1 + drivers/phy/starfive/phy-jh7110-pcie.c | 202 +++++++++++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 drivers/phy/starfive/phy-jh7110-pcie.c(quoted diff) +0
-0b/drivers/phy/starfive/Kconfig index
11a819f8b2..5d49684bc7100644drivers/phy/starfive/Kconfig line 12
Quoted 9 lines
drivers/phy/starfive/Kconfig +6
-0@@ -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.Should be aligned to previous line.
Quoted 25 lines
drivers/phy/starfive/Kconfig +1
-0+ config PHY_STARFIVE_JH7110_USB2 bool "Starfive JH7110 USB 2.0 PHY driver" select PHY(quoted diff) +0
-0b/drivers/phy/starfive/Makefile index
a405a75e34..82f25aa21b100644drivers/phy/starfive/Makefile +1
-0@@ -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.odrivers/phy/starfive/phy-jh7110-pcie.c new file +4
-0@@ -0,0 +1,202 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* StarFive JH7110 PCIe 2.0 PHY driver +* drivers/phy/starfive/phy-jh7110-pcie.c line 14
Quoted 10 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +10
-0+* Copyright (C) 2024 StarFive Technology Co., Ltd. +* Author: Minda Chen <[email protected]> */ #include +<asm/io.h> #include <dm.h> #include <dm/device_compat.h> #include +<errno.h> #include <generic-phy.h> #include <regmap.h> #include +<soc.h> #include <syscon.h> #include <linux/bitops.h> #include +<linux/err.h> + +#define PCIE_KVCO_LEVEL_OFF 0x28 +#define PCIE_USB3_PHY_PLL_CTL_OFF 0x7c +#define PCIE_USB3_PHY_SS_MODE BIT(4)extra tab?
drivers/phy/starfive/phy-jh7110-pcie.c line 34
Quoted 13 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +13
-0+#define PCIE_KVCO_TUNE_SIGNAL_OFF 0x80 +#define PHY_KVCO_FINE_TUNE_LEVEL 0x91 +#define PHY_KVCO_FINE_TUNE_SIGNALS 0xc + +#define USB_PDRSTN_SPLIT BIT(17) + +#define PCIE_USB3_PHY_MODE BIT(20) +#define PCIE_PHY_MODE_MASK GENMASK(21, 20) +#define PCIE_USB3_BUS_WIDTH_MASK GENMASK(3, 2) +#define PCIE_BUS_WIDTH BIT(3) +#define PCIE_USB3_RATE_MASK GENMASK(6, 5) +#define PCIE_USB3_RX_STANDBY_MASK BIT(7) +#define PCIE_USB3_PHY_ENABLE BIT(4)Why not use define and use
regmap_fields? You are already using regmap.Quoted 45 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +45
-0+ +struct jh7110_pcie_phy { +struct phy *phy; +struct regmap *stg_syscon; +struct regmap *sys_syscon; +void __iomem *regs; +u32 sys_phy_connect; +u32 stg_pcie_mode; +u32 stg_pcie_usb; +enum phy_mode mode; +}; + +static int phy_pcie_mode_set (struct jh7110_pcie_phy *data,bool +usb_mode) { +unsigned int phy_mode, width, usb3_phy, ss_mode; + +/* 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" ); +return -EINVAL ; + } +return 0 ; + } + +if (usb_mode) { + phy_mode =PCIE_USB3_PHY_MODE ; + width =0 ; + usb3_phy =PCIE_USB3_PHY_ENABLE ; + ss_mode =PCIE_USB3_PHY_SS_MODE ; + }else { + phy_mode =0 ; + width =PCIE_BUS_WIDTH ; + usb3_phy =0 ; + ss_mode =0 ; + } + +regmap_update_bits (data->stg_syscon, data->stg_pcie_mode, +PCIE_PHY_MODE_MASK , phy_mode); +regmap_update_bits (data->stg_syscon, data->stg_pcie_usb, +PCIE_USB3_BUS_WIDTH_MASK , width); +regmap_update_bits (data->stg_syscon, data->stg_pcie_usb, +PCIE_USB3_PHY_ENABLE , usb3_phy); +clrsetbits_le32 (data->regs +PCIE_USB3_PHY_PLL_CTL_OFF , +PCIE_USB3_PHY_SS_MODE , ss_mode);drivers/phy/starfive/phy-jh7110-pcie.c
Quoted 10 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +10
-0+ +regmap_update_bits (data->sys_syscon, data->sys_phy_connect, +USB_PDRSTN_SPLIT ,0 ); + +return 0 ; +} + +static void phy_kvco_gain_set (struct jh7110_pcie_phy *phy) { +/* PCIe Multi-PHY PLL KVCO Gain fine tune settings: */ + writel(PHY_KVCO_FINE_TUNE_LEVEL, phy->regs +
PCIE_KVCO_LEVEL_OFF);Quoted 59 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +59
-0+writel (PHY_KVCO_FINE_TUNE_SIGNALS , phy->regs + +PCIE_KVCO_TUNE_SIGNAL_OFF ); } + +static int jh7110_pcie_phy_set_mode (struct phy *_phy, +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) +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->mode = mode; + +return 0 ; +} + +static const struct phy_ops jh7110_pcie_phy_ops = { + .set_mode = jh7110_pcie_phy_set_mode, +}; + +static int starfive_pcie_phy_get_syscon (struct udevice *dev) { +struct jh7110_pcie_phy *phy =dev_get_priv (dev); +struct ofnode_phandle_args sys_phandle, stg_phandle; +int ret; + +/* get corresponding syscon phandle */ + ret =dev_read_phandle_with_args (dev,"starfive,sys-syscon" ,NULL ,1 ,0 , + &sys_phandle); + +if (ret <0 ) { +dev_err (dev,"Can't get sys cfg phandle: %d\n" , ret); +return ret; + } + + ret =dev_read_phandle_with_args (dev,"starfive,stg-syscon" ,NULL ,2 ,0 , + &stg_phandle); + +if (ret <0 ) { +dev_err (dev,"Can't get stg cfg phandle: %d\n" , ret); +return ret; + } +
Quoted 9 lines
drivers/phy/starfive/phy-jh7110-pcie.c line 157
Quoted 6 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +6
-0+ phy->sys_syscon =syscon_node_to_regmap (sys_phandle.node); +if (!IS_ERR_OR_NULL (phy->sys_syscon)) { +/* get syscon register offset */ + phy->sys_phy_connect = sys_phandle.args[0 ]; + }else { + phy->sys_syscon =NULL ;Why not error out if you could not get the
sys_sysconregmap?
The syscon is optional in USB2.0 only case.
Quoted 54 lines
drivers/phy/starfive/phy-jh7110-pcie.c line 165
Quoted 8 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +8
-0+ } + + phy->stg_syscon =syscon_node_to_regmap (stg_phandle.node); +if (!IS_ERR_OR_NULL (phy->stg_syscon)) { + phy->stg_pcie_mode = stg_phandle.args[0 ]; + phy->stg_pcie_usb = stg_phandle.args[1 ]; + }else { + phy->stg_syscon =NULL ;same here?
Quoted 24 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +24
-0+ } + +return 0 ; +} + +int jh7110_pcie_phy_probe (struct udevice *dev) { +struct jh7110_pcie_phy *phy =dev_get_priv (dev); +int rc; + + phy->regs =dev_read_addr_ptr (dev); +if (!phy->regs) +return -EINVAL ; + + rc =starfive_pcie_phy_get_syscon (dev); +if (rc) +return rc; + +phy_kvco_gain_set (phy); + +return 0 ; +} + +static const struct udevice_id jh7110_pcie_phy[] = { + { .compatible ="starfive,jh7110-pcie-phy" },drivers/phy/starfive/phy-jh7110-pcie.c line 200
Quoted 10 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +10
-0+ {}, +}; + +U_BOOT_DRIVER (jh7110_pcie_phy) = { + .name ="jh7110_pcie_phy" , + .id =UCLASS_PHY , + .of_match = jh7110_pcie_phy, + .probe = jh7110_pcie_phy_probe, + .ops = &jh7110_pcie_phy_ops, + .priv_auto =sizeof (struct jh7110_pcie_phy ),need space instead of tab?
drivers/phy/starfive/phy-jh7110-pcie.c line 191
Quoted 2 lines
drivers/phy/starfive/phy-jh7110-pcie.c new file +2
-0+}; +--
cheers,
-roger
Minda Chen
maintainerQuoted 13 lines · Minda Chen
Quoted 9 lines
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.
- Star64 using USB 3.0 and USB 2.0 host must add below board dts setting.
Quoted 8 lines
Does this mean a future patch for
spl_fdt_fixup_star64()is needed?Did you also have a look at the USB on the Milk V Mars CM?
Best regards
Heinrich
Maybe the USB pin setting can be added to dts. But VF2 do not contain USB vbus pin defaut setting.
Quoted 95 lines
Quoted 38 lines
1. usb pin setting
usb_pins: usb0-0 { driver-vbus-pin { pinmux = <GPIOMUX(25, GPOUT_SYS_USB_DRIVE_VBUS, GPOEN_ENABLE, GPI_NONE)>; bias-disable; input-disable; input-schmitt-disable; slew-rate = <0>; }; };2. related dts node setting.
&pcie0 { status = "disabled"; };&pciephy0 { starfive,sys-syscon = <&sys_syscon 0x18>; starfive,stg-syscon = <&stg_syscon 0x148 0x1f4>; status = "okay"; };&usb0 { pinctrl-names = "default"; pinctrl-0 = <&usb_pins>; status = "okay"; };&usb_cdns3 { phys = <&usbphy0>, <&pciephy0>; phy-names = "cdns3,usb2-phy", "cdns3,usb3-phy"; dr_mode = "host"; status = "okay"; };Quoted 2 lines
- previous version
v1:https://patchwork.ozlabs.org/project/uboot/cover/20240504150358.19600-1-
[email protected]/Quoted 28 lines
- 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-8 dts, config and maintainers update.- change:
v2:
- patch 1 Move the added code tocdns3_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 (8):
usb: cdns3: Set USB PHY mode incdns3_core_init_role()
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
pinctrl: starfive: Setup USB default disable overcurrent pin
configs: starfive: Add visionfive2 cadence USB configuration
dts: starfive: Add JH7110 Cadence USB dts node
MAINTAINERS: Update Starfive visionfive2 maintain files.Quoted 9 lines
.../dts/jh7110-starfive-visionfive-2.dtsi | 5 + arch/riscv/dts/jh7110.dtsi | 52 +++++ board/starfive/visionfive2/MAINTAINERS | 2 + 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 | 202++++++++++++++++++
Quoted 15 lines
drivers/phy/starfive/phy-jh7110-usb2.c | 135 ++++++++++++ drivers/pinctrl/starfive/pinctrl-jh7110-sys.c | 11 +- drivers/usb/cdns3/Kconfig | 7 + drivers/usb/cdns3/Makefile | 2 + drivers/usb/cdns3/cdns3-starfive.c | 183 ++++++++++++++++ drivers/usb/cdns3/core.c | 25 +++ 15 files changed, 661 insertions(+), 2 deletions(-)create mode 100644
drivers/phy/starfive/Kconfigcreate mode 100644drivers/phy/starfive/Makefilecreate mode 100644drivers/phy/starfive/phy-jh7110-pcie.ccreate mode 100644drivers/phy/starfive/phy-jh7110-usb2.ccreate mode 100644drivers/usb/cdns3/cdns3-starfive.cbase-commit:
8937bb265a7f2251c1bd999784a4ef10e9c6080d