Skip to contentSkip to conversation

usb: Add cadence USB3 gadget/host/phy driver

PATCH Superseded Sherry Sun 5 participants 19 messages Aug 21, 2019 – Aug 30, 2019

Subsystems (7)
lore
Share & tools
lore

Sherry Sun

author
#0 lore raw

v5 cover usb: Add cadence USB3 gadget/host/phy driver

These patches introduce new Cadence driver to U-Boot.
The first patch is to add the Cadence USB3 IP(CDNS3) core and driver for the usb gadget.
The second patch introduce the xhci-imx8 usb host driver separately. The third patch introduce the cdns3 phy driver which can be used for both cdns3 host driver and gadget driver.
The cdns3 usb gadget/host/phy driver are all used DM mode.

The current driver has been validated on i.MX8 platform.
If someone want to test it, please note that the additional dts nodes/ config macros/clock driver are also essential. You can also get my test patches at https://github.com/sherrysun1/u-boot-imx.git to start your test quickly.

Changes in v5:
- Delete some unnecessary code.
- Fix some issues about lack of parentheses.
- Add separate patch for core framework changes.
- Add "reg-names" for usb nodes in DT and use it to get reg values.
- Use "cdns,usb3-1.0.0" compatible instead "cdns,usb3".
- Add DM_FLAG_OS_PREPARE flag to xhci-imx8 driver.

Sherry Sun (7):
dt-bindings: add dt-binding doc for CDNS3 controller
usb: gadget: Add the cadence USB3 gadget driver
usb: gadget: Add match_ep call back to usb_gadget_ops
usb: gadget: Add gadget_is_cdns3 checking to provide bcdUSB value
usb: host: Add the USB3 host driver
phy: Add USB PHY driver for the cadence USB3
usb: gadget: core: introduce ->udc_set_speed() method

 Makefile                                   |    1 +
 doc/device-tree-bindings/usb/cdns-usb3.txt |   53 +
 drivers/phy/Kconfig                        |    8 +
 drivers/phy/Makefile                       |    1 +
 drivers/phy/cdns3-usb-phy.c                |  241 +++
 drivers/usb/Kconfig                        |    2 +
 drivers/usb/cdns3/Kconfig                  |   20 +
 drivers/usb/cdns3/Makefile                 |    5 +
 drivers/usb/cdns3/cdns3-generic.c          |  114 +
 drivers/usb/cdns3/cdns3-nxp-reg-def.h      |   93 +
 drivers/usb/cdns3/core.c                   |  203 ++
 drivers/usb/cdns3/core.h                   |  118 ++
 drivers/usb/cdns3/dev-regs-macro.h         |  116 ++
 drivers/usb/cdns3/dev-regs-map.h           |  117 ++
 drivers/usb/cdns3/gadget-export.h          |   26 +
 drivers/usb/cdns3/gadget.c                 | 2183 ++++++++++++++++++++
 drivers/usb/cdns3/gadget.h                 |  225 ++
 drivers/usb/cdns3/io.h                     |   27 +
 drivers/usb/gadget/epautoconf.c            |    4 +
 drivers/usb/gadget/gadget_chips.h          |    7 +
 drivers/usb/gadget/udc/Makefile            |    1 +
 drivers/usb/gadget/udc/udc-core.c          |   23 +
 drivers/usb/host/Kconfig                   |    9 +
 drivers/usb/host/Makefile                  |    1 +
 drivers/usb/host/xhci-imx8.c               |  210 ++
 include/linux/usb/gadget.h                 |    5 +
 scripts/Makefile.spl                       |    1 +
 27 files changed, 3814 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/cdns-usb3.txt
 create mode 100644 drivers/phy/cdns3-usb-phy.c
 create mode 100644 drivers/usb/cdns3/Kconfig
 create mode 100644 drivers/usb/cdns3/Makefile
 create mode 100644 drivers/usb/cdns3/cdns3-generic.c
 create mode 100644 drivers/usb/cdns3/cdns3-nxp-reg-def.h
 create mode 100644 drivers/usb/cdns3/core.c
 create mode 100644 drivers/usb/cdns3/core.h
 create mode 100644 drivers/usb/cdns3/dev-regs-macro.h
 create mode 100644 drivers/usb/cdns3/dev-regs-map.h
 create mode 100644 drivers/usb/cdns3/gadget-export.h
 create mode 100644 drivers/usb/cdns3/gadget.c
 create mode 100644 drivers/usb/cdns3/gadget.h
 create mode 100644 drivers/usb/cdns3/io.h
 create mode 100644 drivers/usb/host/xhci-imx8.c
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v5 1/7 dt-bindings: add dt-binding doc for CDNS3 controller

This patch aim at documenting USB related dt-bindings for the Cadence USB controller.

---
 doc/device-tree-bindings/usb/cdns-usb3.txt | 53 ++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/cdns-usb3.txt
doc/device-tree-bindings/usb/cdns-usb3.txt new file +53 -0
new file mode 100644
index 0000000000..8aba13b88a
@@ -0,0 +1,53 @@
+* Cadence USB3 Controller
+
+Required properties:
+- compatible: should contain: "cdns,usb3-1.0.0"
+- reg: physical base address and size of the controller's register areas
+	Controller has 5 different regions:
+	region 1 - NONE-CORE registers area
+	region 2 - HOST registers area
+	region 3 - DEVICE registers area
+	region 4 - PHY registers area
+	region 5 - OTG registers area
+- reg-names - register memory area names:
+	"none-core" - for NONE-CORE registers space
+	"xhci" - for HOST registers space
+	"dev" - for DEVICE registers space
+	"phy" - for PHY registers space
+	"otg" - for OTG registers space
+- interrupts: interrupts used by cdns3 controller
+- interrupt-parent: the interrupt parent for this module
+- clocks: reference to the USB clock
+- clock-names: the name of clocks
+- phys: reference to the USB PHY
+
+Optional properties:
+- dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"
+- extcon: extcon phandler for cdns3 device
+- power-domains: the power domain for cdns3 controller and phy
+
+Examples:
+
+usbotg3: cdns3 at 5b110000 {
+	compatible = "cdns,usb3-1.0.0";
+	reg = <0x0 0x5B110000 0x0 0x10000>,
+		<0x0 0x5B130000 0x0 0x10000>,
+		<0x0 0x5B140000 0x0 0x10000>,
+		<0x0 0x5B160000 0x0 0x40000>,
+		<0x0 0x5B120000 0x0 0x10000>;
+	reg-names = "none-core", "xhci", "dev", "phy", "otg";
+	interrupt-parent = <&gic>;
+	interrupts = <GIC_SPI 271 IRQ_TYPE_LEVEL_HIGH>;
+	clocks = <&clk IMX8QM_USB3_LPM_CLK>,
+		<&clk IMX8QM_USB3_BUS_CLK>,
+		<&clk IMX8QM_USB3_ACLK>,
+		<&clk IMX8QM_USB3_IPG_CLK>,
+		<&clk IMX8QM_USB3_CORE_PCLK>;
+	clock-names = "usb3_lpm_clk", "usb3_bus_clk", "usb3_aclk",
+		"usb3_ipg_clk", "usb3_core_pclk";
+	power-domains = <&pd_conn_usb2>;
+	phys = <&usbphy1>;
+	dr_mode = "otg";
+	extcon = <&typec_ptn5150>;
+	status = "disabled";
+};
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v5 2/7 usb: gadget: Add the cadence USB3 gadget driver

In reply to Sherry Sun

This driver is ported from NXP i.MX U-Boot version imx_v2019.04 and some changes have also been made to adapt to U-Boot.

Add the Cadence USB3 IP(CDNS3) driver for the gadget (device mode). The CDNS3 gadget driver support DM mode. CONFIG_DM_USB_GADGET should be enabled when use this driver.

---
 Makefile                              |    1 +
 drivers/usb/Kconfig                   |    2 +
 drivers/usb/cdns3/Kconfig             |   20 +
 drivers/usb/cdns3/Makefile            |    5 +
 drivers/usb/cdns3/cdns3-generic.c     |  114 ++
 drivers/usb/cdns3/cdns3-nxp-reg-def.h |   93 ++
 drivers/usb/cdns3/core.c              |  203 +++
 drivers/usb/cdns3/core.h              |  118 ++
 drivers/usb/cdns3/dev-regs-macro.h    |  116 ++
 drivers/usb/cdns3/dev-regs-map.h      |  117 ++
 drivers/usb/cdns3/gadget-export.h     |   26 +
 drivers/usb/cdns3/gadget.c            | 2183 +++++++++++++++++++++++++
 drivers/usb/cdns3/gadget.h            |  225 +++
 drivers/usb/cdns3/io.h                |   27 +
 drivers/usb/gadget/udc/Makefile       |    1 +
 scripts/Makefile.spl                  |    1 +
 16 files changed, 3252 insertions(+)
 create mode 100644 drivers/usb/cdns3/Kconfig
 create mode 100644 drivers/usb/cdns3/Makefile
 create mode 100644 drivers/usb/cdns3/cdns3-generic.c
 create mode 100644 drivers/usb/cdns3/cdns3-nxp-reg-def.h
 create mode 100644 drivers/usb/cdns3/core.c
 create mode 100644 drivers/usb/cdns3/core.h
 create mode 100644 drivers/usb/cdns3/dev-regs-macro.h
 create mode 100644 drivers/usb/cdns3/dev-regs-map.h
 create mode 100644 drivers/usb/cdns3/gadget-export.h
 create mode 100644 drivers/usb/cdns3/gadget.c
 create mode 100644 drivers/usb/cdns3/gadget.h
 create mode 100644 drivers/usb/cdns3/io.h
Makefile +1 -0
index 3b0864ae8e..37b82eff05 100644
@@ -728,6 +728,7 @@ libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
 libs-$(CONFIG_SYS_FSL_MMDC) += drivers/ddr/fsl/
 libs-$(CONFIG_$(SPL_)ALTERA_SDRAM) += drivers/ddr/altera/
 libs-y += drivers/serial/
+libs-y += drivers/usb/cdns3/
 libs-y += drivers/usb/dwc3/
 libs-y += drivers/usb/common/
 libs-y += drivers/usb/emul/
drivers/usb/Kconfig +2 -0
index 3b53bf2c58..98f5e936e5 100644
@@ -70,6 +70,8 @@ source "drivers/usb/host/Kconfig"
 
 source "drivers/usb/dwc3/Kconfig"
 
+source "drivers/usb/cdns3/Kconfig"
+
 source "drivers/usb/musb/Kconfig"
 
 source "drivers/usb/musb-new/Kconfig"
drivers/usb/cdns3/Kconfig new file +20 -0
new file mode 100644
index 0000000000..11a7144b05
@@ -0,0 +1,20 @@
+config USB_CDNS3
+	tristate "Cadence USB3 Dual-Role Controller"
+    depends on (USB && USB_GADGET)
+	help
+	  Say Y here if your system has a cadence USB3 dual-role controller.
+	  It supports: dual-role switch Host-only, and Peripheral-only.
+
+	  When compiled dynamically, the module will be called cdns3.ko.
+
+if USB_CDNS3
+
+config USB_CDNS3_GADGET
+	bool "Cadence USB3 device controller"
+	depends on USB_GADGET
+    select USB_GADGET_DUALSPEED
+	help
+	  Say Y here to enable device controller functionality of the
+	  cadence usb3 driver.
+
+endif
drivers/usb/cdns3/Makefile new file +5 -0
new file mode 100644
index 0000000000..374fa06efa
@@ -0,0 +1,5 @@
+obj-$(CONFIG_USB_CDNS3)		+= cdns3.o
+
+cdns3-y				:= core.o
+cdns3-$(CONFIG_USB_CDNS3_GADGET)	+= gadget.o
+cdns3-$(CONFIG_$(SPL_)DM_USB_GADGET)	+= cdns3-generic.o
drivers/usb/cdns3/cdns3-generic.c new file +114 -0

114 lines not on this page · raw message

drivers/usb/cdns3/cdns3-nxp-reg-def.h new file +93 -0

93 lines not on this page · raw message

drivers/usb/cdns3/core.c new file +203 -0

203 lines not on this page · raw message

drivers/usb/cdns3/core.h new file +118 -0

118 lines not on this page · raw message

drivers/usb/cdns3/dev-regs-macro.h new file +116 -0

116 lines not on this page · raw message

drivers/usb/cdns3/dev-regs-map.h new file +117 -0

117 lines not on this page · raw message

drivers/usb/cdns3/gadget-export.h new file +26 -0
new file mode 100644
index 0000000000..0b011b56c6
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2019 NXP
+ */
+
+#ifndef __CDNS3_GADGET_EXPORT_H
+#define __CDNS3_GADGET_EXPORT_H
+
+#ifdef CONFIG_USB_CDNS3_GADGET
+
+int cdns3_gadget_init(struct cdns3 *cdns);
+void cdns3_gadget_remove(struct cdns3 *cdns);
+#else
+
+static inline int cdns3_gadget_init(struct cdns3 *cdns)
+{
+	return -ENXIO;
+}
+
+static inline void cdns3_gadget_remove(struct cdns3 *cdns)
+{
+}
+
+#endif
+
+#endif /* __CDNS3_GADGET_EXPORT_H */
drivers/usb/cdns3/gadget.c new file +2183 -0

2,173 lines not on this page · raw message

drivers/usb/cdns3/gadget.h new file +225 -0

225 lines not on this page · raw message

drivers/usb/cdns3/io.h new file +27 -0
new file mode 100644
index 0000000000..6bc7cfe978

Lines of this file are not shown. View the raw message.

drivers/usb/gadget/udc/Makefile +1 -0
index 95dbf0c82e..414edad921 100644

Lines of this file are not shown. View the raw message.

scripts/Makefile.spl +1 -0
index 7af6b120b6..d731c21aa4 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.17.1

Part of the diff is not shown here. View the raw message.

author
#3 lore raw

PATCH v5 3/7 usb: gadget: Add match_ep call back to usb_gadget_ops

In reply to Sherry Sun

Since some new fields in usb_ep structure been moved to usb_ss_ep. The CDNS3 gadget driver should replies on this operation to bind the usb_ss_ep with the endpoint descriptor when function layer uses usb_ep_autoconfig to add endpoint descriptors to gadget. So that CDNS3 driver can know the EP information and configure the EP once the set configuration request is received.

---
 drivers/usb/gadget/epautoconf.c | 4 ++++
 include/linux/usb/gadget.h      | 3 +++
 2 files changed, 7 insertions(+)
drivers/usb/gadget/epautoconf.c +4 -0
index 179b94cdd0..360f2b75ff 100644
@@ -167,6 +167,10 @@ static int ep_matches(
 			size = 64;
 		put_unaligned(cpu_to_le16(size), &desc->wMaxPacketSize);
 	}
+
+	if (gadget->ops->match_ep)
+		return gadget->ops->match_ep(gadget, ep, desc);
+
 	return 1;
 }
 
include/linux/usb/gadget.h +3 -0
index 497798a32a..a34f3478f3 100644
@@ -447,6 +447,9 @@ struct usb_gadget_ops {
 	int	(*udc_start)(struct usb_gadget *,
 			     struct usb_gadget_driver *);
 	int	(*udc_stop)(struct usb_gadget *);
+	int   (*match_ep)(struct usb_gadget *gadget,
+			  struct usb_ep *ep,
+			  struct usb_endpoint_descriptor *desc);
 };
 
 /**
Signature · 1 line
2.17.1
author
#4 lore raw

PATCH v5 4/7 usb: gadget: Add gadget_is_cdns3 checking to provide bcdUSB value

In reply to Sherry Sun

Like other usb controllers, add gadget_is_cdns3 checking to provide bcdUSB value in device descriptor.

---
 drivers/usb/gadget/gadget_chips.h | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/usb/gadget/gadget_chips.h +7 -0
index 2c8f235d51..ba9114cf37 100644
@@ -149,6 +149,11 @@
 #define gadget_is_dwc3(g)        0
 #endif
 
+#ifdef CONFIG_USB_CDNS3_GADGET
+#define gadget_is_cdns3(g)        (!strcmp("cdns3-gadget", (g)->name))
+#else
+#define gadget_is_cdns3(g)        0
+#endif
 /**
  * usb_gadget_controller_number - support bcdDevice id convention
  * @gadget: the controller being driven
@@ -208,5 +213,7 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
 		return 0x22;
 	else if (gadget_is_dwc3(gadget))
 		return 0x23;
+	else if (gadget_is_cdns3(gadget))
+		return 0x24;
 	return -ENOENT;
 }
Signature · 1 line
2.17.1
author
#5 lore raw

PATCH v5 5/7 usb: host: Add the USB3 host driver

In reply to Sherry Sun

Add the USB3 host driver for NXP imx8 platform, and the cadence IP is in it. The USB3 host driver support DM mode, it will probe USB3 host node in dts.

---
 drivers/usb/host/Kconfig     |   9 ++
 drivers/usb/host/Makefile    |   1 +
 drivers/usb/host/xhci-imx8.c | 210 +++++++++++++++++++++++++++++++++++
 3 files changed, 220 insertions(+)
 create mode 100644 drivers/usb/host/xhci-imx8.c
drivers/usb/host/Kconfig +9 -0
index 42046c8062..e3d9717b33 100644
@@ -95,6 +95,15 @@ config USB_XHCI_FSL
 	depends on !SPL_NO_USB
 	help
 	  Enables support for the on-chip xHCI controller on NXP Layerscape SoCs.
+
+config USB_XHCI_IMX8
+	bool "XHCI support for i.MX8"
+	depends on ARCH_IMX8
+	default y
+	help
+	  Enables support for the on-chip xHCI controller on i.MX8QM and
+	  i.MX8QXP SoCs.
+
 endif # USB_XHCI_HCD
 
 config USB_EHCI_HCD
drivers/usb/host/Makefile +1 -0
index dd13528475..d40a236be0 100644
@@ -56,6 +56,7 @@ obj-$(CONFIG_USB_XHCI_OMAP) += xhci-omap.o
 obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
 obj-$(CONFIG_USB_XHCI_RCAR) += xhci-rcar.o
 obj-$(CONFIG_USB_XHCI_STI) += dwc3-sti-glue.o
+obj-$(CONFIG_USB_XHCI_IMX8) += xhci-imx8.o
 
 # designware
 obj-$(CONFIG_USB_DWC2) += dwc2.o
drivers/usb/host/xhci-imx8.c new file +210 -0

210 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#6 lore raw

PATCH v5 6/7 phy: Add USB PHY driver for the cadence USB3

In reply to Sherry Sun

The cdns3-usb-phy driver supports both host and peripheral mode of usb driver which use cadence usb3 IP.

---
 drivers/phy/Kconfig         |   8 ++
 drivers/phy/Makefile        |   1 +
 drivers/phy/cdns3-usb-phy.c | 241 ++++++++++++++++++++++++++++++++++++
 3 files changed, 250 insertions(+)
 create mode 100644 drivers/phy/cdns3-usb-phy.c
drivers/phy/Kconfig +8 -0
index 3942f035eb..1837b32c31 100644
@@ -205,4 +205,12 @@ config MT76X8_USB_PHY
 
 	  This PHY is found on MT76x8 devices supporting USB.
 
+config CDNS3_USB_PHY
+	bool "Support CDNS3 USB PHY"
+	depends on PHY
+	help
+	  Support for the USB PHY in CDNS3 IP.
+
+	  This PHY is found on CDNS3 IP devices supporting USB.
+
 endmenu
drivers/phy/Makefile +1 -0
index 3157f1b7ee..0e062214d3 100644
@@ -22,4 +22,5 @@ obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o
 obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
 obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
 obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
+obj-$(CONFIG_CDNS3_USB_PHY) += cdns3-usb-phy.o
 obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o
drivers/phy/cdns3-usb-phy.c new file +241 -0

241 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

PATCH v5 6/7 phy: Add USB PHY driver for the cadence USB3

Hi Sherry,

Quoted 212 lines · Sherry Sun

The cdns3-usb-phy driver supports both host and peripheral mode of usb driver which use cadence usb3 IP.

---
  drivers/phy/Kconfig         |   8 ++
  drivers/phy/Makefile        |   1 +
  drivers/phy/cdns3-usb-phy.c | 241 ++++++++++++++++++++++++++++++++++++
  3 files changed, 250 insertions(+)

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

drivers/phy/Kconfig +8 -0
index 3942f035eb..1837b32c31 100644
@@ -205,4 +205,12 @@ config MT76X8_USB_PHY
 
  	  This PHY is found on MT76x8 devices supporting USB.
 
+config CDNS3_USB_PHY
+	bool "Support CDNS3 USB PHY"
+	depends on PHY
+	help
+	  Support for the USB PHY in CDNS3 IP.
+
+	  This PHY is found on CDNS3 IP devices supporting USB.
+
  endmenu
drivers/phy/Makefile +1 -0
index 3157f1b7ee..0e062214d3 100644
@@ -22,4 +22,5 @@ obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o
  obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
  obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
  obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
+obj-$(CONFIG_CDNS3_USB_PHY) += cdns3-usb-phy.o
  obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o
drivers/phy/cdns3-usb-phy.c new file +168 -0
new file mode 100644
index 0000000000..c0d308075b
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ *
+ * Cadence3 USB PHY driver
+ *
+ * Author: Sherry Sun <[email protected]>
+ */
+
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+#include <generic-phy.h>
+#include <asm/io.h>
+
+/* PHY registers */
+#define PHY_PMA_CMN_CTRL1			(0xC800 * 4)
+#define TB_ADDR_CMN_DIAG_HSCLK_SEL		(0x01e0 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR	(0x0084 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR	(0x0085 * 4)
+#define TB_ADDR_CMN_PLL0_INTDIV	                (0x0094 * 4)
+#define TB_ADDR_CMN_PLL0_FRACDIV		(0x0095 * 4)
+#define TB_ADDR_CMN_PLL0_HIGH_THR		(0x0096 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL1		(0x0098 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL2		(0x0099 * 4)
+#define TB_ADDR_CMN_PLL0_DSM_DIAG		(0x0097 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_OVRD		(0x01c2 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD		(0x01c0 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD		(0x01c1 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE          (0x01C5 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_CP_TUNE           (0x01C6 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_LF_PROG           (0x01C7 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_TEST_MODE		(0x01c4 * 4)
+#define TB_ADDR_CMN_PSM_CLK_CTRL		(0x0061 * 4)
+#define TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR	(0x40ea * 4)
+#define TB_ADDR_XCVR_PSM_RCTRL	                (0x4001 * 4)
+#define TB_ADDR_TX_PSC_A0		        (0x4100 * 4)
+#define TB_ADDR_TX_PSC_A1		        (0x4101 * 4)
+#define TB_ADDR_TX_PSC_A2		        (0x4102 * 4)
+#define TB_ADDR_TX_PSC_A3		        (0x4103 * 4)
+#define TB_ADDR_TX_DIAG_ECTRL_OVRD		(0x41f5 * 4)
+#define TB_ADDR_TX_PSC_CAL		        (0x4106 * 4)
+#define TB_ADDR_TX_PSC_RDY		        (0x4107 * 4)
+#define TB_ADDR_RX_PSC_A0	                (0x8000 * 4)
+#define TB_ADDR_RX_PSC_A1	                (0x8001 * 4)
+#define TB_ADDR_RX_PSC_A2	                (0x8002 * 4)
+#define TB_ADDR_RX_PSC_A3	                (0x8003 * 4)
+#define TB_ADDR_RX_PSC_CAL	                (0x8006 * 4)
+#define TB_ADDR_RX_PSC_RDY	                (0x8007 * 4)
+#define TB_ADDR_TX_TXCC_MGNLS_MULT_000		(0x4058 * 4)
+#define TB_ADDR_TX_DIAG_BGREF_PREDRV_DELAY	(0x41e7 * 4)
+#define TB_ADDR_RX_SLC_CU_ITER_TMR		(0x80e3 * 4)
+#define TB_ADDR_RX_SIGDET_HL_FILT_TMR		(0x8090 * 4)
+#define TB_ADDR_RX_SAMP_DAC_CTRL		(0x8058 * 4)
+#define TB_ADDR_RX_DIAG_SIGDET_TUNE		(0x81dc * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE2		(0x81df * 4)
+#define TB_ADDR_RX_DIAG_BS_TM	                (0x81f5 * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL1		(0x81d3 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM4		(0x81c7 * 4)
+#define TB_ADDR_RX_DIAG_ILL_E_TRIM0		(0x81c2 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQ_TRIM0		(0x81c1 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM6		(0x81c9 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM3		(0x81f8 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM4		(0x81f9 * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE		(0x81dd * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL3		(0x81d5 * 4)
+#define TB_ADDR_RX_DIAG_SC2C_DELAY		(0x81e1 * 4)
+#define TB_ADDR_RX_REE_VGA_GAIN_NODFE		(0x81bf * 4)
+#define TB_ADDR_XCVR_PSM_CAL_TMR		(0x4002 * 4)
+#define TB_ADDR_XCVR_PSM_A0BYP_TMR		(0x4004 * 4)
+#define TB_ADDR_XCVR_PSM_A0IN_TMR		(0x4003 * 4)
+#define TB_ADDR_XCVR_PSM_A1IN_TMR		(0x4005 * 4)
+#define TB_ADDR_XCVR_PSM_A2IN_TMR		(0x4006 * 4)
+#define TB_ADDR_XCVR_PSM_A3IN_TMR		(0x4007 * 4)
+#define TB_ADDR_XCVR_PSM_A4IN_TMR		(0x4008 * 4)
+#define TB_ADDR_XCVR_PSM_A5IN_TMR		(0x4009 * 4)
+#define TB_ADDR_XCVR_PSM_A0OUT_TMR		(0x400a * 4)
+#define TB_ADDR_XCVR_PSM_A1OUT_TMR		(0x400b * 4)
+#define TB_ADDR_XCVR_PSM_A2OUT_TMR		(0x400c * 4)
+#define TB_ADDR_XCVR_PSM_A3OUT_TMR		(0x400d * 4)
+#define TB_ADDR_XCVR_PSM_A4OUT_TMR		(0x400e * 4)
+#define TB_ADDR_XCVR_PSM_A5OUT_TMR		(0x400f * 4)
+#define TB_ADDR_TX_RCVDET_EN_TMR	        (0x4122 * 4)
+#define TB_ADDR_TX_RCVDET_ST_TMR	        (0x4123 * 4)
+#define TB_ADDR_XCVR_DIAG_LANE_FCM_EN_MGN_TMR	(0x40f2 * 4)
+
+struct cdns3_usb_phy {
+	struct clk phy_clk;
+	void __iomem *phy_regs;
+};
+
+static int cdns3_usb_phy_init(struct phy *phy)
+{
+	struct udevice *dev = phy->dev;
+	struct cdns3_usb_phy *priv = dev_get_priv(dev);
+	void __iomem *regs = priv->phy_regs;
+
+	writel(0x0830, regs + PHY_PMA_CMN_CTRL1);
+	writel(0x10, regs + TB_ADDR_CMN_DIAG_HSCLK_SEL);
+	writel(0x00F0, regs + TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR);
+	writel(0x0018, regs + TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR);
+	writel(0x00D0, regs + TB_ADDR_CMN_PLL0_INTDIV);
+	writel(0x4aaa, regs + TB_ADDR_CMN_PLL0_FRACDIV);
+	writel(0x0034, regs + TB_ADDR_CMN_PLL0_HIGH_THR);
+	writel(0x1ee, regs + TB_ADDR_CMN_PLL0_SS_CTRL1);
+	writel(0x7F03, regs + TB_ADDR_CMN_PLL0_SS_CTRL2);
+	writel(0x0020, regs + TB_ADDR_CMN_PLL0_DSM_DIAG);
+	writel(0x0000, regs + TB_ADDR_CMN_DIAG_PLL0_OVRD);
+	writel(0x0000, regs + TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD);
+	writel(0x0000, regs + TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD);
+	writel(0x0007, regs + TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE);
+	writel(0x0027, regs + TB_ADDR_CMN_DIAG_PLL0_CP_TUNE);
+	writel(0x0008, regs + TB_ADDR_CMN_DIAG_PLL0_LF_PROG);
+	writel(0x0022, regs + TB_ADDR_CMN_DIAG_PLL0_TEST_MODE);
+	writel(0x000a, regs + TB_ADDR_CMN_PSM_CLK_CTRL);
+	writel(0x139, regs + TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR);
+	writel(0xbefc, regs + TB_ADDR_XCVR_PSM_RCTRL);
+
+	writel(0x7799, regs + TB_ADDR_TX_PSC_A0);
+	writel(0x7798, regs + TB_ADDR_TX_PSC_A1);
+	writel(0x509b, regs + TB_ADDR_TX_PSC_A2);
+	writel(0x3, regs + TB_ADDR_TX_DIAG_ECTRL_OVRD);
+	writel(0x509b, regs + TB_ADDR_TX_PSC_A3);
+	writel(0x2090, regs + TB_ADDR_TX_PSC_CAL);
+	writel(0x2090, regs + TB_ADDR_TX_PSC_RDY);
+
+	writel(0xA6FD, regs + TB_ADDR_RX_PSC_A0);
+	writel(0xA6FD, regs + TB_ADDR_RX_PSC_A1);
+	writel(0xA410, regs + TB_ADDR_RX_PSC_A2);
+	writel(0x2410, regs + TB_ADDR_RX_PSC_A3);
+
+	writel(0x23FF, regs + TB_ADDR_RX_PSC_CAL);
+	writel(0x2010, regs + TB_ADDR_RX_PSC_RDY);
+
+	writel(0x0020, regs + TB_ADDR_TX_TXCC_MGNLS_MULT_000);
+	writel(0x00ff, regs + TB_ADDR_TX_DIAG_BGREF_PREDRV_DELAY);
+	writel(0x0002, regs + TB_ADDR_RX_SLC_CU_ITER_TMR);
+	writel(0x0013, regs + TB_ADDR_RX_SIGDET_HL_FILT_TMR);
+	writel(0x0000, regs + TB_ADDR_RX_SAMP_DAC_CTRL);
+	writel(0x1004, regs + TB_ADDR_RX_DIAG_SIGDET_TUNE);
+	writel(0x4041, regs + TB_ADDR_RX_DIAG_LFPSDET_TUNE2);
+	writel(0x0480, regs + TB_ADDR_RX_DIAG_BS_TM);
+	writel(0x8006, regs + TB_ADDR_RX_DIAG_DFE_CTRL1);
+	writel(0x003f, regs + TB_ADDR_RX_DIAG_ILL_IQE_TRIM4);
+	writel(0x543f, regs + TB_ADDR_RX_DIAG_ILL_E_TRIM0);
+	writel(0x543f, regs + TB_ADDR_RX_DIAG_ILL_IQ_TRIM0);
+	writel(0x0000, regs + TB_ADDR_RX_DIAG_ILL_IQE_TRIM6);
+	writel(0x8000, regs + TB_ADDR_RX_DIAG_RXFE_TM3);
+	writel(0x0003, regs + TB_ADDR_RX_DIAG_RXFE_TM4);
+	writel(0x2408, regs + TB_ADDR_RX_DIAG_LFPSDET_TUNE);
+	writel(0x05ca, regs + TB_ADDR_RX_DIAG_DFE_CTRL3);
+	writel(0x0258, regs + TB_ADDR_RX_DIAG_SC2C_DELAY);
+	writel(0x1fff, regs + TB_ADDR_RX_REE_VGA_GAIN_NODFE);
+
+	writel(0x02c6, regs + TB_ADDR_XCVR_PSM_CAL_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A0BYP_TMR);
+	writel(0x02c6, regs + TB_ADDR_XCVR_PSM_A0IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A1IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A2IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A3IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A4IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A5IN_TMR);
+
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A0OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A1OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A2OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A3OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A4OUT_TMR);

drivers/phy/cdns3-usb-phy.c line 178

Quoted 10 lines
drivers/phy/cdns3-usb-phy.c new file +10 -0
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A5OUT_TMR);
+
+	/* Change rx detect parameter */
+	writel(0x960, regs + TB_ADDR_TX_RCVDET_EN_TMR);
+	writel(0x01e0, regs + TB_ADDR_TX_RCVDET_ST_TMR);
+	writel(0x0090, regs + TB_ADDR_XCVR_DIAG_LANE_FCM_EN_MGN_TMR);
+
+	udelay(10);
+	return 0;
+}

Where do all those hard-coded values come from? Is this something that would work for all platforms implementing this PHY ?

Is there a linux driver for this PHY ?

JJ

Quoted 65 lines
drivers/phy/cdns3-usb-phy.c new file +63 -0
+
+struct phy_ops cdns3_usb_phy_ops = {
+	.init = cdns3_usb_phy_init,
+};
+
+static int cdns3_usb_phy_remove(struct udevice *dev)
+{
+#if CONFIG_IS_ENABLED(CLK)
+	struct cdns3_usb_phy *priv = dev_get_priv(dev);
+	int ret;
+
+	if (priv->phy_clk.dev) {
+		ret = clk_disable(&priv->phy_clk);
+		if (ret)
+			return ret;
+
+		ret = clk_free(&priv->phy_clk);
+		if (ret)
+			return ret;
+	}
+#endif
+
+	return 0;
+}
+
+static int cdns3_usb_phy_probe(struct udevice *dev)
+{
+	struct cdns3_usb_phy *priv = dev_get_priv(dev);
+
+#if CONFIG_IS_ENABLED(CLK)
+	int ret;
+
+	ret = clk_get_by_name(dev, "main_clk", &priv->phy_clk);
+	if (ret) {
+		printf("Failed to get phy_clk\n");
+		return ret;
+	}
+
+	ret = clk_enable(&priv->phy_clk);
+	if (ret) {
+		printf("Failed to enable phy_clk\n");
+		return ret;
+	}
+#endif
+	priv->phy_regs = (void *__iomem)devfdt_get_addr(dev);
+
+	return 0;
+}
+
+static const struct udevice_id cdns3_usb_phy_ids[] = {
+	{ .compatible = "cdns,usb3-phy" },
 
 
+	{ }
+};
+
+U_BOOT_DRIVER(cdns3_usb_phy) = {
+	.name = "cdns3_usb_phy",
+	.id = UCLASS_PHY,
+	.of_match = cdns3_usb_phy_ids,
+	.probe = cdns3_usb_phy_probe,
+	.remove = cdns3_usb_phy_remove,
+	.ops = &cdns3_usb_phy_ops,
+	.priv_auto_alloc_size = sizeof(struct cdns3_usb_phy),
+};
author
#8 lore raw

PATCH v5 6/7 phy: Add USB PHY driver for the cadence USB3

Hi Jean,

Quoted 222 lines

Hi Sherry,

Quoted 8 lines · Sherry Sun

The cdns3-usb-phy driver supports both host and peripheral mode of usb driver which use cadence usb3 IP.

---
  drivers/phy/Kconfig         |   8 ++
  drivers/phy/Makefile        |   1 +
  drivers/phy/cdns3-usb-phy.c | 241

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

drivers/phy/Makefile obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-

Quoted 25 lines
  3 files changed, 250 insertions(+)

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

drivers/phy/Kconfig index renamed from drivers/phy/Kconfig +0 -0

3942f035eb..1837b32c31 100644

drivers/phy/Kconfig +8 -0
@@ -205,4 +205,12 @@ config MT76X8_USB_PHY
 
  	  This PHY is found on MT76x8 devices supporting USB.
 
+config CDNS3_USB_PHY
+	bool "Support CDNS3 USB PHY"
+	depends on PHY
+	help
+	  Support for the USB PHY in CDNS3 IP.
+
+	  This PHY is found on CDNS3 IP devices supporting USB.
+
  endmenu
drivers/phy/Makefile index renamed from drivers/phy/Makefile +0 -0

3157f1b7ee..0e062214d3 100644

drivers/phy/Makefile +0 -0
@@ -22,4 +22,5 @@ obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-

usbh-phy.o

Quoted 172 lines
drivers/phy/Makefile +1 -0
  obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
  obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
  obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
+obj-$(CONFIG_CDNS3_USB_PHY) += cdns3-usb-phy.o
  obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o diff --git

a/drivers/phy/cdns3-usb-phy.c b/drivers/phy/cdns3-usb-phy.c new file mode 100644 index 0000000000..c0d308075b

drivers/phy/cdns3-usb-phy.c new file +162 -0
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ *
+ * Cadence3 USB PHY driver
+ *
+ * Author: Sherry Sun <[email protected]>  */
+
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+#include <generic-phy.h>
+#include <asm/io.h>
+
+/* PHY registers */
+#define PHY_PMA_CMN_CTRL1			(0xC800 * 4)
+#define TB_ADDR_CMN_DIAG_HSCLK_SEL		(0x01e0 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR	(0x0084 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR	(0x0085 * 4)
+#define TB_ADDR_CMN_PLL0_INTDIV	                (0x0094 * 4)
+#define TB_ADDR_CMN_PLL0_FRACDIV		(0x0095 * 4)
+#define TB_ADDR_CMN_PLL0_HIGH_THR		(0x0096 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL1		(0x0098 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL2		(0x0099 * 4)
+#define TB_ADDR_CMN_PLL0_DSM_DIAG		(0x0097 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_OVRD		(0x01c2 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD		(0x01c0 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD		(0x01c1 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE          (0x01C5 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_CP_TUNE           (0x01C6 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_LF_PROG           (0x01C7 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_TEST_MODE		(0x01c4 * 4)
+#define TB_ADDR_CMN_PSM_CLK_CTRL		(0x0061 * 4)
+#define TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR	(0x40ea * 4)
+#define TB_ADDR_XCVR_PSM_RCTRL	                (0x4001 * 4)
+#define TB_ADDR_TX_PSC_A0		        (0x4100 * 4)
+#define TB_ADDR_TX_PSC_A1		        (0x4101 * 4)
+#define TB_ADDR_TX_PSC_A2		        (0x4102 * 4)
+#define TB_ADDR_TX_PSC_A3		        (0x4103 * 4)
+#define TB_ADDR_TX_DIAG_ECTRL_OVRD		(0x41f5 * 4)
+#define TB_ADDR_TX_PSC_CAL		        (0x4106 * 4)
+#define TB_ADDR_TX_PSC_RDY		        (0x4107 * 4)
+#define TB_ADDR_RX_PSC_A0	                (0x8000 * 4)
+#define TB_ADDR_RX_PSC_A1	                (0x8001 * 4)
+#define TB_ADDR_RX_PSC_A2	                (0x8002 * 4)
+#define TB_ADDR_RX_PSC_A3	                (0x8003 * 4)
+#define TB_ADDR_RX_PSC_CAL	                (0x8006 * 4)
+#define TB_ADDR_RX_PSC_RDY	                (0x8007 * 4)
+#define TB_ADDR_TX_TXCC_MGNLS_MULT_000		(0x4058 * 4)
+#define TB_ADDR_TX_DIAG_BGREF_PREDRV_DELAY	(0x41e7 * 4)
+#define TB_ADDR_RX_SLC_CU_ITER_TMR		(0x80e3 * 4)
+#define TB_ADDR_RX_SIGDET_HL_FILT_TMR		(0x8090 * 4)
+#define TB_ADDR_RX_SAMP_DAC_CTRL		(0x8058 * 4)
+#define TB_ADDR_RX_DIAG_SIGDET_TUNE		(0x81dc * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE2		(0x81df * 4)
+#define TB_ADDR_RX_DIAG_BS_TM	                (0x81f5 * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL1		(0x81d3 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM4		(0x81c7 * 4)
+#define TB_ADDR_RX_DIAG_ILL_E_TRIM0		(0x81c2 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQ_TRIM0		(0x81c1 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM6		(0x81c9 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM3		(0x81f8 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM4		(0x81f9 * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE		(0x81dd * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL3		(0x81d5 * 4)
+#define TB_ADDR_RX_DIAG_SC2C_DELAY		(0x81e1 * 4)
+#define TB_ADDR_RX_REE_VGA_GAIN_NODFE		(0x81bf * 4)
+#define TB_ADDR_XCVR_PSM_CAL_TMR		(0x4002 * 4)
+#define TB_ADDR_XCVR_PSM_A0BYP_TMR		(0x4004 * 4)
+#define TB_ADDR_XCVR_PSM_A0IN_TMR		(0x4003 * 4)
+#define TB_ADDR_XCVR_PSM_A1IN_TMR		(0x4005 * 4)
+#define TB_ADDR_XCVR_PSM_A2IN_TMR		(0x4006 * 4)
+#define TB_ADDR_XCVR_PSM_A3IN_TMR		(0x4007 * 4)
+#define TB_ADDR_XCVR_PSM_A4IN_TMR		(0x4008 * 4)
+#define TB_ADDR_XCVR_PSM_A5IN_TMR		(0x4009 * 4)
+#define TB_ADDR_XCVR_PSM_A0OUT_TMR		(0x400a * 4)
+#define TB_ADDR_XCVR_PSM_A1OUT_TMR		(0x400b * 4)
+#define TB_ADDR_XCVR_PSM_A2OUT_TMR		(0x400c * 4)
+#define TB_ADDR_XCVR_PSM_A3OUT_TMR		(0x400d * 4)
+#define TB_ADDR_XCVR_PSM_A4OUT_TMR		(0x400e * 4)
+#define TB_ADDR_XCVR_PSM_A5OUT_TMR		(0x400f * 4)
+#define TB_ADDR_TX_RCVDET_EN_TMR	        (0x4122 * 4)
+#define TB_ADDR_TX_RCVDET_ST_TMR	        (0x4123 * 4)
+#define TB_ADDR_XCVR_DIAG_LANE_FCM_EN_MGN_TMR	(0x40f2 * 4)
+
+struct cdns3_usb_phy {
+	struct clk phy_clk;
+	void __iomem *phy_regs;
+};
+
+static int cdns3_usb_phy_init(struct phy *phy) {
+	struct udevice *dev = phy->dev;
+	struct cdns3_usb_phy *priv = dev_get_priv(dev);
+	void __iomem *regs = priv->phy_regs;
+
+	writel(0x0830, regs + PHY_PMA_CMN_CTRL1);
+	writel(0x10, regs + TB_ADDR_CMN_DIAG_HSCLK_SEL);
+	writel(0x00F0, regs + TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR);
+	writel(0x0018, regs + TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR);
+	writel(0x00D0, regs + TB_ADDR_CMN_PLL0_INTDIV);
+	writel(0x4aaa, regs + TB_ADDR_CMN_PLL0_FRACDIV);
+	writel(0x0034, regs + TB_ADDR_CMN_PLL0_HIGH_THR);
+	writel(0x1ee, regs + TB_ADDR_CMN_PLL0_SS_CTRL1);
+	writel(0x7F03, regs + TB_ADDR_CMN_PLL0_SS_CTRL2);
+	writel(0x0020, regs + TB_ADDR_CMN_PLL0_DSM_DIAG);
+	writel(0x0000, regs + TB_ADDR_CMN_DIAG_PLL0_OVRD);
+	writel(0x0000, regs + TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD);
+	writel(0x0000, regs + TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD);
+	writel(0x0007, regs + TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE);
+	writel(0x0027, regs + TB_ADDR_CMN_DIAG_PLL0_CP_TUNE);
+	writel(0x0008, regs + TB_ADDR_CMN_DIAG_PLL0_LF_PROG);
+	writel(0x0022, regs + TB_ADDR_CMN_DIAG_PLL0_TEST_MODE);
+	writel(0x000a, regs + TB_ADDR_CMN_PSM_CLK_CTRL);
+	writel(0x139, regs + TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR);
+	writel(0xbefc, regs + TB_ADDR_XCVR_PSM_RCTRL);
+
+	writel(0x7799, regs + TB_ADDR_TX_PSC_A0);
+	writel(0x7798, regs + TB_ADDR_TX_PSC_A1);
+	writel(0x509b, regs + TB_ADDR_TX_PSC_A2);
+	writel(0x3, regs + TB_ADDR_TX_DIAG_ECTRL_OVRD);
+	writel(0x509b, regs + TB_ADDR_TX_PSC_A3);
+	writel(0x2090, regs + TB_ADDR_TX_PSC_CAL);
+	writel(0x2090, regs + TB_ADDR_TX_PSC_RDY);
+
+	writel(0xA6FD, regs + TB_ADDR_RX_PSC_A0);
+	writel(0xA6FD, regs + TB_ADDR_RX_PSC_A1);
+	writel(0xA410, regs + TB_ADDR_RX_PSC_A2);
+	writel(0x2410, regs + TB_ADDR_RX_PSC_A3);
+
+	writel(0x23FF, regs + TB_ADDR_RX_PSC_CAL);
+	writel(0x2010, regs + TB_ADDR_RX_PSC_RDY);
+
+	writel(0x0020, regs + TB_ADDR_TX_TXCC_MGNLS_MULT_000);
+	writel(0x00ff, regs + TB_ADDR_TX_DIAG_BGREF_PREDRV_DELAY);
+	writel(0x0002, regs + TB_ADDR_RX_SLC_CU_ITER_TMR);
+	writel(0x0013, regs + TB_ADDR_RX_SIGDET_HL_FILT_TMR);
+	writel(0x0000, regs + TB_ADDR_RX_SAMP_DAC_CTRL);
+	writel(0x1004, regs + TB_ADDR_RX_DIAG_SIGDET_TUNE);
+	writel(0x4041, regs + TB_ADDR_RX_DIAG_LFPSDET_TUNE2);
+	writel(0x0480, regs + TB_ADDR_RX_DIAG_BS_TM);
+	writel(0x8006, regs + TB_ADDR_RX_DIAG_DFE_CTRL1);
+	writel(0x003f, regs + TB_ADDR_RX_DIAG_ILL_IQE_TRIM4);
+	writel(0x543f, regs + TB_ADDR_RX_DIAG_ILL_E_TRIM0);
+	writel(0x543f, regs + TB_ADDR_RX_DIAG_ILL_IQ_TRIM0);
+	writel(0x0000, regs + TB_ADDR_RX_DIAG_ILL_IQE_TRIM6);
+	writel(0x8000, regs + TB_ADDR_RX_DIAG_RXFE_TM3);
+	writel(0x0003, regs + TB_ADDR_RX_DIAG_RXFE_TM4);
+	writel(0x2408, regs + TB_ADDR_RX_DIAG_LFPSDET_TUNE);
+	writel(0x05ca, regs + TB_ADDR_RX_DIAG_DFE_CTRL3);
+	writel(0x0258, regs + TB_ADDR_RX_DIAG_SC2C_DELAY);
+	writel(0x1fff, regs + TB_ADDR_RX_REE_VGA_GAIN_NODFE);
+
+	writel(0x02c6, regs + TB_ADDR_XCVR_PSM_CAL_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A0BYP_TMR);
+	writel(0x02c6, regs + TB_ADDR_XCVR_PSM_A0IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A1IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A2IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A3IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A4IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A5IN_TMR);
+
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A0OUT_TMR);

drivers/phy/cdns3-usb-phy.c line 172

Quoted 10 lines
drivers/phy/cdns3-usb-phy.c new file +10 -0
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A1OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A2OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A3OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A4OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A5OUT_TMR);
+
+	/* Change rx detect parameter */
+	writel(0x960, regs + TB_ADDR_TX_RCVDET_EN_TMR);
+	writel(0x01e0, regs + TB_ADDR_TX_RCVDET_ST_TMR);
+	writel(0x0090, regs +

TB_ADDR_XCVR_DIAG_LANE_FCM_EN_MGN_TMR);

Quoted 8 lines

drivers/phy/cdns3-usb-phy.c line 178

Quoted 4 lines
drivers/phy/cdns3-usb-phy.c new file +4 -0
+
+	udelay(10);
+	return 0;
+}

Where do all those hard-coded values come from? Is this something that would work for all platforms implementing this PHY ?

These values are from Cadence USB 3.0 PHY User Guide, and certainly it can work for all platforms which use this PHY.

Quoted 1 line

Is there a linux driver for this PHY ?

Yes, the cdns3 phy driver in kernel is phy-cadence-sierra.c,
but it is shared with pcie, and it has a lot of differences with this PHY driver in uboot.

Best regards
Sherry sun

Quoted 65 lines

JJ

Quoted 62 lines
drivers/phy/cdns3-usb-phy.c new file +60 -0
+
+struct phy_ops cdns3_usb_phy_ops = {
+	.init = cdns3_usb_phy_init,
+};
+
+static int cdns3_usb_phy_remove(struct udevice *dev) { #if
+CONFIG_IS_ENABLED(CLK)
+	struct cdns3_usb_phy *priv = dev_get_priv(dev);
+	int ret;
+
+	if (priv->phy_clk.dev) {
+		ret = clk_disable(&priv->phy_clk);
+		if (ret)
+			return ret;
+
+		ret = clk_free(&priv->phy_clk);
+		if (ret)
+			return ret;
+	}
+#endif
+
+	return 0;
+}
+
+static int cdns3_usb_phy_probe(struct udevice *dev) {
+	struct cdns3_usb_phy *priv = dev_get_priv(dev);
+
+#if CONFIG_IS_ENABLED(CLK)
+	int ret;
+
+	ret = clk_get_by_name(dev, "main_clk", &priv->phy_clk);
+	if (ret) {
+		printf("Failed to get phy_clk\n");
+		return ret;
+	}
+
+	ret = clk_enable(&priv->phy_clk);
+	if (ret) {
+		printf("Failed to enable phy_clk\n");
+		return ret;
+	}
+#endif
+	priv->phy_regs = (void *__iomem)devfdt_get_addr(dev);
+
+	return 0;
+}
+
+static const struct udevice_id cdns3_usb_phy_ids[] = {
+	{ .compatible = "cdns,usb3-phy" },
 
 
+	{ }
+};
+
+U_BOOT_DRIVER(cdns3_usb_phy) = {
+	.name = "cdns3_usb_phy",
+	.id = UCLASS_PHY,
+	.of_match = cdns3_usb_phy_ids,
+	.probe = cdns3_usb_phy_probe,
+	.remove = cdns3_usb_phy_remove,
+	.ops = &cdns3_usb_phy_ops,
+	.priv_auto_alloc_size = sizeof(struct cdns3_usb_phy), };
#9 lore raw

PATCH v5 6/7 phy: Add USB PHY driver for the cadence USB3

+Kishon who worked on this PHY under linux

Hi Sherry,

Quoted 230 lines · Sherry Sun

Hi Jean,

Quoted 221 lines

Hi Sherry,

Quoted 8 lines · Sherry Sun

The cdns3-usb-phy driver supports both host and peripheral mode of usb driver which use cadence usb3 IP.

---
   drivers/phy/Kconfig         |   8 ++
   drivers/phy/Makefile        |   1 +
   drivers/phy/cdns3-usb-phy.c | 241

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

drivers/phy/Makefile obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-

Quoted 25 lines
   3 files changed, 250 insertions(+)

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

drivers/phy/Kconfig index renamed from drivers/phy/Kconfig +0 -0

3942f035eb..1837b32c31 100644

drivers/phy/Kconfig +8 -0
@@ -205,4 +205,12 @@ config MT76X8_USB_PHY
 
   	  This PHY is found on MT76x8 devices supporting USB.
 
+config CDNS3_USB_PHY
+	bool "Support CDNS3 USB PHY"
+	depends on PHY
+	help
+	  Support for the USB PHY in CDNS3 IP.
+
+	  This PHY is found on CDNS3 IP devices supporting USB.
+
   endmenu
drivers/phy/Makefile index renamed from drivers/phy/Makefile +0 -0

3157f1b7ee..0e062214d3 100644

drivers/phy/Makefile +0 -0
@@ -22,4 +22,5 @@ obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-

usbh-phy.o

Quoted 172 lines
drivers/phy/Makefile +1 -0
   obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
   obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
   obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
+obj-$(CONFIG_CDNS3_USB_PHY) += cdns3-usb-phy.o
   obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o diff --git

a/drivers/phy/cdns3-usb-phy.c b/drivers/phy/cdns3-usb-phy.c new file mode 100644 index 0000000000..c0d308075b

drivers/phy/cdns3-usb-phy.c new file +162 -0
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ *
+ * Cadence3 USB PHY driver
+ *
+ * Author: Sherry Sun <[email protected]>  */
+
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+#include <generic-phy.h>
+#include <asm/io.h>
+
+/* PHY registers */
+#define PHY_PMA_CMN_CTRL1			(0xC800 * 4)
+#define TB_ADDR_CMN_DIAG_HSCLK_SEL		(0x01e0 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR	(0x0084 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR	(0x0085 * 4)
+#define TB_ADDR_CMN_PLL0_INTDIV	                (0x0094 * 4)
+#define TB_ADDR_CMN_PLL0_FRACDIV		(0x0095 * 4)
+#define TB_ADDR_CMN_PLL0_HIGH_THR		(0x0096 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL1		(0x0098 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL2		(0x0099 * 4)
+#define TB_ADDR_CMN_PLL0_DSM_DIAG		(0x0097 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_OVRD		(0x01c2 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD		(0x01c0 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD		(0x01c1 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE          (0x01C5 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_CP_TUNE           (0x01C6 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_LF_PROG           (0x01C7 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_TEST_MODE		(0x01c4 * 4)
+#define TB_ADDR_CMN_PSM_CLK_CTRL		(0x0061 * 4)
+#define TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR	(0x40ea * 4)
+#define TB_ADDR_XCVR_PSM_RCTRL	                (0x4001 * 4)
+#define TB_ADDR_TX_PSC_A0		        (0x4100 * 4)
+#define TB_ADDR_TX_PSC_A1		        (0x4101 * 4)
+#define TB_ADDR_TX_PSC_A2		        (0x4102 * 4)
+#define TB_ADDR_TX_PSC_A3		        (0x4103 * 4)
+#define TB_ADDR_TX_DIAG_ECTRL_OVRD		(0x41f5 * 4)
+#define TB_ADDR_TX_PSC_CAL		        (0x4106 * 4)
+#define TB_ADDR_TX_PSC_RDY		        (0x4107 * 4)
+#define TB_ADDR_RX_PSC_A0	                (0x8000 * 4)
+#define TB_ADDR_RX_PSC_A1	                (0x8001 * 4)
+#define TB_ADDR_RX_PSC_A2	                (0x8002 * 4)
+#define TB_ADDR_RX_PSC_A3	                (0x8003 * 4)
+#define TB_ADDR_RX_PSC_CAL	                (0x8006 * 4)
+#define TB_ADDR_RX_PSC_RDY	                (0x8007 * 4)
+#define TB_ADDR_TX_TXCC_MGNLS_MULT_000		(0x4058 * 4)
+#define TB_ADDR_TX_DIAG_BGREF_PREDRV_DELAY	(0x41e7 * 4)
+#define TB_ADDR_RX_SLC_CU_ITER_TMR		(0x80e3 * 4)
+#define TB_ADDR_RX_SIGDET_HL_FILT_TMR		(0x8090 * 4)
+#define TB_ADDR_RX_SAMP_DAC_CTRL		(0x8058 * 4)
+#define TB_ADDR_RX_DIAG_SIGDET_TUNE		(0x81dc * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE2		(0x81df * 4)
+#define TB_ADDR_RX_DIAG_BS_TM	                (0x81f5 * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL1		(0x81d3 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM4		(0x81c7 * 4)
+#define TB_ADDR_RX_DIAG_ILL_E_TRIM0		(0x81c2 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQ_TRIM0		(0x81c1 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM6		(0x81c9 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM3		(0x81f8 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM4		(0x81f9 * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE		(0x81dd * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL3		(0x81d5 * 4)
+#define TB_ADDR_RX_DIAG_SC2C_DELAY		(0x81e1 * 4)
+#define TB_ADDR_RX_REE_VGA_GAIN_NODFE		(0x81bf * 4)
+#define TB_ADDR_XCVR_PSM_CAL_TMR		(0x4002 * 4)
+#define TB_ADDR_XCVR_PSM_A0BYP_TMR		(0x4004 * 4)
+#define TB_ADDR_XCVR_PSM_A0IN_TMR		(0x4003 * 4)
+#define TB_ADDR_XCVR_PSM_A1IN_TMR		(0x4005 * 4)
+#define TB_ADDR_XCVR_PSM_A2IN_TMR		(0x4006 * 4)
+#define TB_ADDR_XCVR_PSM_A3IN_TMR		(0x4007 * 4)
+#define TB_ADDR_XCVR_PSM_A4IN_TMR		(0x4008 * 4)
+#define TB_ADDR_XCVR_PSM_A5IN_TMR		(0x4009 * 4)
+#define TB_ADDR_XCVR_PSM_A0OUT_TMR		(0x400a * 4)
+#define TB_ADDR_XCVR_PSM_A1OUT_TMR		(0x400b * 4)
+#define TB_ADDR_XCVR_PSM_A2OUT_TMR		(0x400c * 4)
+#define TB_ADDR_XCVR_PSM_A3OUT_TMR		(0x400d * 4)
+#define TB_ADDR_XCVR_PSM_A4OUT_TMR		(0x400e * 4)
+#define TB_ADDR_XCVR_PSM_A5OUT_TMR		(0x400f * 4)
+#define TB_ADDR_TX_RCVDET_EN_TMR	        (0x4122 * 4)
+#define TB_ADDR_TX_RCVDET_ST_TMR	        (0x4123 * 4)
+#define TB_ADDR_XCVR_DIAG_LANE_FCM_EN_MGN_TMR	(0x40f2 * 4)
+
+struct cdns3_usb_phy {
+	struct clk phy_clk;
+	void __iomem *phy_regs;
+};
+
+static int cdns3_usb_phy_init(struct phy *phy) {
+	struct udevice *dev = phy->dev;
+	struct cdns3_usb_phy *priv = dev_get_priv(dev);
+	void __iomem *regs = priv->phy_regs;
+
+	writel(0x0830, regs + PHY_PMA_CMN_CTRL1);
+	writel(0x10, regs + TB_ADDR_CMN_DIAG_HSCLK_SEL);
+	writel(0x00F0, regs + TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR);
+	writel(0x0018, regs + TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR);
+	writel(0x00D0, regs + TB_ADDR_CMN_PLL0_INTDIV);
+	writel(0x4aaa, regs + TB_ADDR_CMN_PLL0_FRACDIV);
+	writel(0x0034, regs + TB_ADDR_CMN_PLL0_HIGH_THR);
+	writel(0x1ee, regs + TB_ADDR_CMN_PLL0_SS_CTRL1);
+	writel(0x7F03, regs + TB_ADDR_CMN_PLL0_SS_CTRL2);
+	writel(0x0020, regs + TB_ADDR_CMN_PLL0_DSM_DIAG);
+	writel(0x0000, regs + TB_ADDR_CMN_DIAG_PLL0_OVRD);
+	writel(0x0000, regs + TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD);
+	writel(0x0000, regs + TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD);
+	writel(0x0007, regs + TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE);
+	writel(0x0027, regs + TB_ADDR_CMN_DIAG_PLL0_CP_TUNE);
+	writel(0x0008, regs + TB_ADDR_CMN_DIAG_PLL0_LF_PROG);
+	writel(0x0022, regs + TB_ADDR_CMN_DIAG_PLL0_TEST_MODE);
+	writel(0x000a, regs + TB_ADDR_CMN_PSM_CLK_CTRL);
+	writel(0x139, regs + TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR);
+	writel(0xbefc, regs + TB_ADDR_XCVR_PSM_RCTRL);
+
+	writel(0x7799, regs + TB_ADDR_TX_PSC_A0);
+	writel(0x7798, regs + TB_ADDR_TX_PSC_A1);
+	writel(0x509b, regs + TB_ADDR_TX_PSC_A2);
+	writel(0x3, regs + TB_ADDR_TX_DIAG_ECTRL_OVRD);
+	writel(0x509b, regs + TB_ADDR_TX_PSC_A3);
+	writel(0x2090, regs + TB_ADDR_TX_PSC_CAL);
+	writel(0x2090, regs + TB_ADDR_TX_PSC_RDY);
+
+	writel(0xA6FD, regs + TB_ADDR_RX_PSC_A0);
+	writel(0xA6FD, regs + TB_ADDR_RX_PSC_A1);
+	writel(0xA410, regs + TB_ADDR_RX_PSC_A2);
+	writel(0x2410, regs + TB_ADDR_RX_PSC_A3);
+
+	writel(0x23FF, regs + TB_ADDR_RX_PSC_CAL);
+	writel(0x2010, regs + TB_ADDR_RX_PSC_RDY);
+
+	writel(0x0020, regs + TB_ADDR_TX_TXCC_MGNLS_MULT_000);
+	writel(0x00ff, regs + TB_ADDR_TX_DIAG_BGREF_PREDRV_DELAY);
+	writel(0x0002, regs + TB_ADDR_RX_SLC_CU_ITER_TMR);
+	writel(0x0013, regs + TB_ADDR_RX_SIGDET_HL_FILT_TMR);
+	writel(0x0000, regs + TB_ADDR_RX_SAMP_DAC_CTRL);
+	writel(0x1004, regs + TB_ADDR_RX_DIAG_SIGDET_TUNE);
+	writel(0x4041, regs + TB_ADDR_RX_DIAG_LFPSDET_TUNE2);
+	writel(0x0480, regs + TB_ADDR_RX_DIAG_BS_TM);
+	writel(0x8006, regs + TB_ADDR_RX_DIAG_DFE_CTRL1);
+	writel(0x003f, regs + TB_ADDR_RX_DIAG_ILL_IQE_TRIM4);
+	writel(0x543f, regs + TB_ADDR_RX_DIAG_ILL_E_TRIM0);
+	writel(0x543f, regs + TB_ADDR_RX_DIAG_ILL_IQ_TRIM0);
+	writel(0x0000, regs + TB_ADDR_RX_DIAG_ILL_IQE_TRIM6);
+	writel(0x8000, regs + TB_ADDR_RX_DIAG_RXFE_TM3);
+	writel(0x0003, regs + TB_ADDR_RX_DIAG_RXFE_TM4);
+	writel(0x2408, regs + TB_ADDR_RX_DIAG_LFPSDET_TUNE);
+	writel(0x05ca, regs + TB_ADDR_RX_DIAG_DFE_CTRL3);
+	writel(0x0258, regs + TB_ADDR_RX_DIAG_SC2C_DELAY);
+	writel(0x1fff, regs + TB_ADDR_RX_REE_VGA_GAIN_NODFE);
+
+	writel(0x02c6, regs + TB_ADDR_XCVR_PSM_CAL_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A0BYP_TMR);
+	writel(0x02c6, regs + TB_ADDR_XCVR_PSM_A0IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A1IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A2IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A3IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A4IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A5IN_TMR);
+
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A0OUT_TMR);

drivers/phy/cdns3-usb-phy.c line 172

Quoted 10 lines
drivers/phy/cdns3-usb-phy.c new file +10 -0
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A1OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A2OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A3OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A4OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A5OUT_TMR);
+
+	/* Change rx detect parameter */
+	writel(0x960, regs + TB_ADDR_TX_RCVDET_EN_TMR);
+	writel(0x01e0, regs + TB_ADDR_TX_RCVDET_ST_TMR);
+	writel(0x0090, regs +

TB_ADDR_XCVR_DIAG_LANE_FCM_EN_MGN_TMR);

Quoted 7 lines

drivers/phy/cdns3-usb-phy.c line 178

Quoted 4 lines
drivers/phy/cdns3-usb-phy.c new file +4 -0
+
+	udelay(10);
+	return 0;
+}

Where do all those hard-coded values come from? Is this something that would work for all platforms implementing this PHY ?

Quoted 5 lines

These values are from Cadence USB 3.0 PHY User Guide, and certainly it can work for all platforms which use this PHY.

Quoted 1 line

Is there a linux driver for this PHY ?

Yes, the cdns3 phy driver in kernel is phy-cadence-sierra.c,
but it is shared with pcie, and it has a lot of differences with this PHY driver in uboot.

This is indeed a different driver. IMO it would be better to keep the driver closer to its linux version. The reason for that  is that it is quite new and will be adapted when platforms starts supporting it. If we start with something too far from the original, it will hard to update. Already I see that the registers initialized are not all the same as in the linux driver and not all the values are the same either, nor are the register names

TI's J7 platforms is using this PHY driver for USB3/PCIe support, and the linux driver has already seen quite a few modifications to get it to work
(https://git.ti.com/ti-linux-kernel/ti-linux-kernel/blobs/history/ti-linux-4.19.y/drivers/phy/cadence/phy-cadence-sierra.c)
Adding support for it on top of this current version will be rather difficult.

JJ

Quoted 67 lines

Best regards
Sherry sun

Quoted 63 lines

JJ

Quoted 61 lines
drivers/phy/cdns3-usb-phy.c new file +60 -0
+
+struct phy_ops cdns3_usb_phy_ops = {
+	.init = cdns3_usb_phy_init,
+};
+
+static int cdns3_usb_phy_remove(struct udevice *dev) { #if
+CONFIG_IS_ENABLED(CLK)
+	struct cdns3_usb_phy *priv = dev_get_priv(dev);
+	int ret;
+
+	if (priv->phy_clk.dev) {
+		ret = clk_disable(&priv->phy_clk);
+		if (ret)
+			return ret;
+
+		ret = clk_free(&priv->phy_clk);
+		if (ret)
+			return ret;
+	}
+#endif
+
+	return 0;
+}
+
+static int cdns3_usb_phy_probe(struct udevice *dev) {
+	struct cdns3_usb_phy *priv = dev_get_priv(dev);
+
+#if CONFIG_IS_ENABLED(CLK)
+	int ret;
+
+	ret = clk_get_by_name(dev, "main_clk", &priv->phy_clk);
+	if (ret) {
+		printf("Failed to get phy_clk\n");
+		return ret;
+	}
+
+	ret = clk_enable(&priv->phy_clk);
+	if (ret) {
+		printf("Failed to enable phy_clk\n");
+		return ret;
+	}
+#endif
+	priv->phy_regs = (void *__iomem)devfdt_get_addr(dev);
+
+	return 0;
+}
+
+static const struct udevice_id cdns3_usb_phy_ids[] = {
+	{ .compatible = "cdns,usb3-phy" },
 
+	{ }
+};
+
+U_BOOT_DRIVER(cdns3_usb_phy) = {
+	.name = "cdns3_usb_phy",
+	.id = UCLASS_PHY,
+	.of_match = cdns3_usb_phy_ids,
+	.probe = cdns3_usb_phy_probe,
+	.remove = cdns3_usb_phy_remove,
+	.ops = &cdns3_usb_phy_ops,
+	.priv_auto_alloc_size = sizeof(struct cdns3_usb_phy), };
author
#10 lore raw

PATCH v5 6/7 phy: Add USB PHY driver for the cadence USB3

Hi Jean,

Quoted 255 lines

+Kishon who worked on this PHY under linux

Hi Sherry,

Quoted 126 lines · Sherry Sun

Hi Jean,

Quoted 124 lines

Hi Sherry,

Quoted 8 lines · Sherry Sun

The cdns3-usb-phy driver supports both host and peripheral mode of usb driver which use cadence usb3 IP.

---
   drivers/phy/Kconfig         |   8 ++
   drivers/phy/Makefile        |   1 +
   drivers/phy/cdns3-usb-phy.c | 241

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

drivers/phy/Makefile obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-

Quoted 25 lines
   3 files changed, 250 insertions(+)

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

drivers/phy/Kconfig index renamed from drivers/phy/Kconfig +0 -0

3942f035eb..1837b32c31 100644

drivers/phy/Kconfig +8 -0
@@ -205,4 +205,12 @@ config MT76X8_USB_PHY
 
   	  This PHY is found on MT76x8 devices supporting USB.
 
+config CDNS3_USB_PHY
+	bool "Support CDNS3 USB PHY"
+	depends on PHY
+	help
+	  Support for the USB PHY in CDNS3 IP.
+
+	  This PHY is found on CDNS3 IP devices supporting USB.
+
   endmenu
drivers/phy/Makefile index renamed from drivers/phy/Makefile +0 -0

3157f1b7ee..0e062214d3 100644

drivers/phy/Makefile +0 -0
@@ -22,4 +22,5 @@ obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-

usbh-phy.o

Quoted 86 lines
drivers/phy/Makefile +1 -0
   obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
   obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
   obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
+obj-$(CONFIG_CDNS3_USB_PHY) += cdns3-usb-phy.o
   obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o diff --git

a/drivers/phy/cdns3-usb-phy.c b/drivers/phy/cdns3-usb-phy.c new file mode 100644 index 0000000000..c0d308075b

drivers/phy/cdns3-usb-phy.c new file +76 -0
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ *
+ * Cadence3 USB PHY driver
+ *
+ * Author: Sherry Sun <[email protected]>  */
+
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+#include <generic-phy.h>
+#include <asm/io.h>
+
+/* PHY registers */
+#define PHY_PMA_CMN_CTRL1			(0xC800 * 4)
+#define TB_ADDR_CMN_DIAG_HSCLK_SEL		(0x01e0 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR	(0x0084 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR	(0x0085 * 4)
+#define TB_ADDR_CMN_PLL0_INTDIV	                (0x0094 * 4)
+#define TB_ADDR_CMN_PLL0_FRACDIV		(0x0095 * 4)
+#define TB_ADDR_CMN_PLL0_HIGH_THR		(0x0096 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL1		(0x0098 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL2		(0x0099 * 4)
+#define TB_ADDR_CMN_PLL0_DSM_DIAG		(0x0097 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_OVRD		(0x01c2 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD		(0x01c0 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD		(0x01c1 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE          (0x01C5 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_CP_TUNE           (0x01C6 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_LF_PROG           (0x01C7 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_TEST_MODE		(0x01c4 * 4)
+#define TB_ADDR_CMN_PSM_CLK_CTRL		(0x0061 * 4)
+#define TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR	(0x40ea * 4)
+#define TB_ADDR_XCVR_PSM_RCTRL	                (0x4001 * 4)
+#define TB_ADDR_TX_PSC_A0		        (0x4100 * 4)
+#define TB_ADDR_TX_PSC_A1		        (0x4101 * 4)
+#define TB_ADDR_TX_PSC_A2		        (0x4102 * 4)
+#define TB_ADDR_TX_PSC_A3		        (0x4103 * 4)
+#define TB_ADDR_TX_DIAG_ECTRL_OVRD		(0x41f5 * 4)
+#define TB_ADDR_TX_PSC_CAL		        (0x4106 * 4)
+#define TB_ADDR_TX_PSC_RDY		        (0x4107 * 4)
+#define TB_ADDR_RX_PSC_A0	                (0x8000 * 4)
+#define TB_ADDR_RX_PSC_A1	                (0x8001 * 4)
+#define TB_ADDR_RX_PSC_A2	                (0x8002 * 4)
+#define TB_ADDR_RX_PSC_A3	                (0x8003 * 4)
+#define TB_ADDR_RX_PSC_CAL	                (0x8006 * 4)
+#define TB_ADDR_RX_PSC_RDY	                (0x8007 * 4)
+#define TB_ADDR_TX_TXCC_MGNLS_MULT_000		(0x4058 * 4)
+#define TB_ADDR_TX_DIAG_BGREF_PREDRV_DELAY	(0x41e7 * 4)
+#define TB_ADDR_RX_SLC_CU_ITER_TMR		(0x80e3 * 4)
+#define TB_ADDR_RX_SIGDET_HL_FILT_TMR		(0x8090 * 4)
+#define TB_ADDR_RX_SAMP_DAC_CTRL		(0x8058 * 4)
+#define TB_ADDR_RX_DIAG_SIGDET_TUNE		(0x81dc * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE2		(0x81df * 4)
+#define TB_ADDR_RX_DIAG_BS_TM	                (0x81f5 * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL1		(0x81d3 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM4		(0x81c7 * 4)
+#define TB_ADDR_RX_DIAG_ILL_E_TRIM0		(0x81c2 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQ_TRIM0		(0x81c1 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM6		(0x81c9 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM3		(0x81f8 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM4		(0x81f9 * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE		(0x81dd * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL3		(0x81d5 * 4)
+#define TB_ADDR_RX_DIAG_SC2C_DELAY		(0x81e1 * 4)
+#define TB_ADDR_RX_REE_VGA_GAIN_NODFE		(0x81bf * 4)
+#define TB_ADDR_XCVR_PSM_CAL_TMR		(0x4002 * 4)
+#define TB_ADDR_XCVR_PSM_A0BYP_TMR		(0x4004 * 4)
+#define TB_ADDR_XCVR_PSM_A0IN_TMR		(0x4003 * 4)
+#define TB_ADDR_XCVR_PSM_A1IN_TMR		(0x4005 * 4)
+#define TB_ADDR_XCVR_PSM_A2IN_TMR		(0x4006 * 4)
+#define TB_ADDR_XCVR_PSM_A3IN_TMR		(0x4007 * 4)
+#define TB_ADDR_XCVR_PSM_A4IN_TMR		(0x4008 * 4)
+#define TB_ADDR_XCVR_PSM_A5IN_TMR		(0x4009 * 4)
+#define TB_ADDR_XCVR_PSM_A0OUT_TMR		(0x400a * 4)
Quoted 8 lines
Quoted 8 lines

drivers/phy/cdns3-usb-phy.c

Quoted 8 lines
drivers/phy/cdns3-usb-phy.c new file +8 -0
+#define TB_ADDR_XCVR_PSM_A1OUT_TMR		(0x400b * 4)
+#define TB_ADDR_XCVR_PSM_A2OUT_TMR		(0x400c * 4)
+#define TB_ADDR_XCVR_PSM_A3OUT_TMR		(0x400d * 4)
+#define TB_ADDR_XCVR_PSM_A4OUT_TMR		(0x400e * 4)
+#define TB_ADDR_XCVR_PSM_A5OUT_TMR		(0x400f * 4)
+#define TB_ADDR_TX_RCVDET_EN_TMR	        (0x4122 * 4)
+#define TB_ADDR_TX_RCVDET_ST_TMR	        (0x4123 * 4)
+#define TB_ADDR_XCVR_DIAG_LANE_FCM_EN_MGN_TMR
	(0x40f2 * 4)
Quoted 89 lines
Quoted 89 lines
Quoted 78 lines
drivers/phy/cdns3-usb-phy.c new file +78 -0
+
+struct cdns3_usb_phy {
+	struct clk phy_clk;
+	void __iomem *phy_regs;
+};
+
+static int cdns3_usb_phy_init(struct phy *phy) {
+	struct udevice *dev = phy->dev;
+	struct cdns3_usb_phy *priv = dev_get_priv(dev);
+	void __iomem *regs = priv->phy_regs;
+
+	writel(0x0830, regs + PHY_PMA_CMN_CTRL1);
+	writel(0x10, regs + TB_ADDR_CMN_DIAG_HSCLK_SEL);
+	writel(0x00F0, regs + TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR);
+	writel(0x0018, regs + TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR);
+	writel(0x00D0, regs + TB_ADDR_CMN_PLL0_INTDIV);
+	writel(0x4aaa, regs + TB_ADDR_CMN_PLL0_FRACDIV);
+	writel(0x0034, regs + TB_ADDR_CMN_PLL0_HIGH_THR);
+	writel(0x1ee, regs + TB_ADDR_CMN_PLL0_SS_CTRL1);
+	writel(0x7F03, regs + TB_ADDR_CMN_PLL0_SS_CTRL2);
+	writel(0x0020, regs + TB_ADDR_CMN_PLL0_DSM_DIAG);
+	writel(0x0000, regs + TB_ADDR_CMN_DIAG_PLL0_OVRD);
+	writel(0x0000, regs + TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD);
+	writel(0x0000, regs + TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD);
+	writel(0x0007, regs + TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE);
+	writel(0x0027, regs + TB_ADDR_CMN_DIAG_PLL0_CP_TUNE);
+	writel(0x0008, regs + TB_ADDR_CMN_DIAG_PLL0_LF_PROG);
+	writel(0x0022, regs + TB_ADDR_CMN_DIAG_PLL0_TEST_MODE);
+	writel(0x000a, regs + TB_ADDR_CMN_PSM_CLK_CTRL);
+	writel(0x139, regs + TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR);
+	writel(0xbefc, regs + TB_ADDR_XCVR_PSM_RCTRL);
+
+	writel(0x7799, regs + TB_ADDR_TX_PSC_A0);
+	writel(0x7798, regs + TB_ADDR_TX_PSC_A1);
+	writel(0x509b, regs + TB_ADDR_TX_PSC_A2);
+	writel(0x3, regs + TB_ADDR_TX_DIAG_ECTRL_OVRD);
+	writel(0x509b, regs + TB_ADDR_TX_PSC_A3);
+	writel(0x2090, regs + TB_ADDR_TX_PSC_CAL);
+	writel(0x2090, regs + TB_ADDR_TX_PSC_RDY);
+
+	writel(0xA6FD, regs + TB_ADDR_RX_PSC_A0);
+	writel(0xA6FD, regs + TB_ADDR_RX_PSC_A1);
+	writel(0xA410, regs + TB_ADDR_RX_PSC_A2);
+	writel(0x2410, regs + TB_ADDR_RX_PSC_A3);
+
+	writel(0x23FF, regs + TB_ADDR_RX_PSC_CAL);
+	writel(0x2010, regs + TB_ADDR_RX_PSC_RDY);
+
+	writel(0x0020, regs + TB_ADDR_TX_TXCC_MGNLS_MULT_000);
+	writel(0x00ff, regs + TB_ADDR_TX_DIAG_BGREF_PREDRV_DELAY);
+	writel(0x0002, regs + TB_ADDR_RX_SLC_CU_ITER_TMR);
+	writel(0x0013, regs + TB_ADDR_RX_SIGDET_HL_FILT_TMR);
+	writel(0x0000, regs + TB_ADDR_RX_SAMP_DAC_CTRL);
+	writel(0x1004, regs + TB_ADDR_RX_DIAG_SIGDET_TUNE);
+	writel(0x4041, regs + TB_ADDR_RX_DIAG_LFPSDET_TUNE2);
+	writel(0x0480, regs + TB_ADDR_RX_DIAG_BS_TM);
+	writel(0x8006, regs + TB_ADDR_RX_DIAG_DFE_CTRL1);
+	writel(0x003f, regs + TB_ADDR_RX_DIAG_ILL_IQE_TRIM4);
+	writel(0x543f, regs + TB_ADDR_RX_DIAG_ILL_E_TRIM0);
+	writel(0x543f, regs + TB_ADDR_RX_DIAG_ILL_IQ_TRIM0);
+	writel(0x0000, regs + TB_ADDR_RX_DIAG_ILL_IQE_TRIM6);
+	writel(0x8000, regs + TB_ADDR_RX_DIAG_RXFE_TM3);
+	writel(0x0003, regs + TB_ADDR_RX_DIAG_RXFE_TM4);
+	writel(0x2408, regs + TB_ADDR_RX_DIAG_LFPSDET_TUNE);
+	writel(0x05ca, regs + TB_ADDR_RX_DIAG_DFE_CTRL3);
+	writel(0x0258, regs + TB_ADDR_RX_DIAG_SC2C_DELAY);
+	writel(0x1fff, regs + TB_ADDR_RX_REE_VGA_GAIN_NODFE);
+
+	writel(0x02c6, regs + TB_ADDR_XCVR_PSM_CAL_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A0BYP_TMR);
+	writel(0x02c6, regs + TB_ADDR_XCVR_PSM_A0IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A1IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A2IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A3IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A4IN_TMR);
+	writel(0x0010, regs + TB_ADDR_XCVR_PSM_A5IN_TMR);
+
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A0OUT_TMR);

drivers/phy/cdns3-usb-phy.c

Quoted 10 lines
drivers/phy/cdns3-usb-phy.c new file +10 -0
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A1OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A2OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A3OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A4OUT_TMR);
+	writel(0x0002, regs + TB_ADDR_XCVR_PSM_A5OUT_TMR);
+
+	/* Change rx detect parameter */
+	writel(0x960, regs + TB_ADDR_TX_RCVDET_EN_TMR);
+	writel(0x01e0, regs + TB_ADDR_TX_RCVDET_ST_TMR);
+	writel(0x0090, regs +

TB_ADDR_XCVR_DIAG_LANE_FCM_EN_MGN_TMR);

Quoted 8 lines
Quoted 7 lines

drivers/phy/cdns3-usb-phy.c line 178

Quoted 4 lines
drivers/phy/cdns3-usb-phy.c new file +4 -0
+
+	udelay(10);
+	return 0;
+}

Where do all those hard-coded values come from? Is this something that would work for all platforms implementing this PHY ?

These values are from Cadence USB 3.0 PHY User Guide, and certainly it can

work for all platforms which use this PHY.

Quoted 4 lines
Quoted 2 lines

Is there a linux driver for this PHY ?

Yes, the cdns3 phy driver in kernel is phy-cadence-sierra.c, but it is shared with pcie, and it has a lot of differences with this PHY driver in

uboot.

This is indeed a different driver. IMO it would be better to keep the driver closer to its linux version. The reason for that  is that it is quite new and will be adapted when platforms starts supporting it. If we start with something too far from the original, it will hard to update.
Already I see that the registers initialized are not all the same as in the linux driver and not all the values are the same either, nor are the register names

Quoted 11 lines

TI's J7 platforms is using this PHY driver for USB3/PCIe support, and the linux driver has already seen quite a few modifications to get it to work
(https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.ti.
com%2Fti-linux-kernel%2Fti-linux-kernel%2Fblobs%2Fhistory%2Fti-linux- 4.19.y%2Fdrivers%2Fphy%2Fcadence%2Fphy-cadence- sierra.c&amp;data=02%7C01%7Csherry.sun%40nxp.com%7C84f9122d7eb64 9820bae08d72b997681%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0 %7C637025810458595586&amp;sdata=6JpD7VcFudhzXSVP0WaGVEp7Fwrue A%2B4V6eeOfif19w%3D&amp;reserved=0)
Adding support for it on top of this current version will be rather difficult.

Thanks for your advice.
Actually I am not familiar with this phy driver in linux, so also +peter, who worked on this USB driver under linux, maybe he can give some suggestions.

Best regards
Sherry sun

Quoted 71 lines

JJ

Quoted 67 lines

Best regards
Sherry sun

Quoted 63 lines

JJ

Quoted 61 lines
drivers/phy/cdns3-usb-phy.c new file +60 -0
+
+struct phy_ops cdns3_usb_phy_ops = {
+	.init = cdns3_usb_phy_init,
+};
+
+static int cdns3_usb_phy_remove(struct udevice *dev) { #if
+CONFIG_IS_ENABLED(CLK)
+	struct cdns3_usb_phy *priv = dev_get_priv(dev);
+	int ret;
+
+	if (priv->phy_clk.dev) {
+		ret = clk_disable(&priv->phy_clk);
+		if (ret)
+			return ret;
+
+		ret = clk_free(&priv->phy_clk);
+		if (ret)
+			return ret;
+	}
+#endif
+
+	return 0;
+}
+
+static int cdns3_usb_phy_probe(struct udevice *dev) {
+	struct cdns3_usb_phy *priv = dev_get_priv(dev);
+
+#if CONFIG_IS_ENABLED(CLK)
+	int ret;
+
+	ret = clk_get_by_name(dev, "main_clk", &priv->phy_clk);
+	if (ret) {
+		printf("Failed to get phy_clk\n");
+		return ret;
+	}
+
+	ret = clk_enable(&priv->phy_clk);
+	if (ret) {
+		printf("Failed to enable phy_clk\n");
+		return ret;
+	}
+#endif
+	priv->phy_regs = (void *__iomem)devfdt_get_addr(dev);
+
+	return 0;
+}
+
+static const struct udevice_id cdns3_usb_phy_ids[] = {
+	{ .compatible = "cdns,usb3-phy" },
 
+	{ }
+};
+
+U_BOOT_DRIVER(cdns3_usb_phy) = {
+	.name = "cdns3_usb_phy",
+	.id = UCLASS_PHY,
+	.of_match = cdns3_usb_phy_ids,
+	.probe = cdns3_usb_phy_probe,
+	.remove = cdns3_usb_phy_remove,
+	.ops = &cdns3_usb_phy_ops,
+	.priv_auto_alloc_size = sizeof(struct cdns3_usb_phy), };
#11 lore raw

PATCH v5 6/7 phy: Add USB PHY driver for the cadence USB3

Quoted 23 lines
Quoted 10 lines

This is indeed a different driver. IMO it would be better to keep the driver closer to its linux version. The reason for that  is that it is quite new and will be adapted when platforms starts supporting it. If we start with something too far from the original, it will hard to update. Already I see that the registers initialized are not all the same as in the linux driver and not all the values are the same either, nor are the register names

Quoted 3 lines

TI's J7 platforms is using this PHY driver for USB3/PCIe support, and the linux driver has already seen quite a few modifications to get it to work

(https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.ti.

Quoted 8 lines

com%2Fti-linux-kernel%2Fti-linux-kernel%2Fblobs%2Fhistory%2Fti-linux- 4.19.y%2Fdrivers%2Fphy%2Fcadence%2Fphy-cadence- sierra.c&amp;data=02%7C01%7Csherry.sun%40nxp.com%7C84f9122d7eb64 9820bae08d72b997681%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0 %7C637025810458595586&amp;sdata=6JpD7VcFudhzXSVP0WaGVEp7Fwrue A%2B4V6eeOfif19w%3D&amp;reserved=0)
Adding support for it on top of this current version will be rather difficult.

Quoted 4 lines

Thanks for your advice.
Actually I am not familiar with this phy driver in linux, so also +peter, who worked on this USB driver under linux, maybe he can give some suggestions.

Add Alan from Cadence

Alan, we find the suggested value at this driver (drivers/phy/cadence/phy-cadence-sierra.c) is so different with "USB 3.0 PHY User Guide for 28FDSOI" CH 3.1.1 Bring-up Sequence. Does this driver support this 28nm PHY? If it supports, why the initialized value is so different? The UG suggested value can be used at NXP platform.

Peter

#12 lore raw

PATCH v5 6/7 phy: Add USB PHY driver for the cadence USB3

Hi Pawel,

We are discussing if Cadence/TI/NXP could use the same USB PHY driver (drivers/phy/cadence/phy-cadence-sierra.c), I find I can't get Alan Douglas <[email protected]>, would you please forward related people? The question is like below, thanks.

Alan, we find the suggested value at this driver (drivers/phy/cadence/phy-cadence-sierra.c) is so different with "USB 3.0 PHY User Guide for 28FDSOI" CH 3.1.1 Bring-up Sequence. Does this driver support this 28nm PHY? If it supports, why the initialized value is so different? The UG suggested value can be used at NXP platform.

Peter

Quoted 40 lines
Quoted 23 lines
Quoted 9 lines

This is indeed a different driver. IMO it would be better to keep the driver closer to its linux version. The reason for that  is that it is quite new and will be adapted when platforms starts supporting it. If we start with something too far from the original, it will hard to update. Already I see that the registers initialized are not all the same as in the linux driver and not all the values are the same either, nor are the register names

Quoted 3 lines

TI's J7 platforms is using this PHY driver for USB3/PCIe support, and the linux driver has already seen quite a few modifications to get it to work

(https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.ti.

Quoted 9 lines

com%2Fti-linux-kernel%2Fti-linux-kernel%2Fblobs%2Fhistory%2Fti-linux -
4.19.y%2Fdrivers%2Fphy%2Fcadence%2Fphy-cadence- sierra.c&amp;data=02%7C01%7Csherry.sun%40nxp.com%7C84f9122d7eb64 9820bae08d72b997681%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0 %7C637025810458595586&amp;sdata=6JpD7VcFudhzXSVP0WaGVEp7Fwrue A%2B4V6eeOfif19w%3D&amp;reserved=0)
Adding support for it on top of this current version will be rather difficult.

Quoted 3 lines

Thanks for your advice.
Actually I am not familiar with this phy driver in linux, so also +peter, who worked on this USB driver under linux, maybe he can give some

suggestions.

Quoted 1 line

Add Alan from Cadence

Alan, we find the suggested value at this driver (drivers/phy/cadence/phy-cadence- sierra.c)
is so different with "USB 3.0 PHY User Guide for 28FDSOI" CH 3.1.1 Bring-up Sequence.
Does this driver support this 28nm PHY? If it supports, why the initialized value is so different?
The UG suggested value can be used at NXP platform.

Peter

maintainer
#13 lore raw

PATCH v5 6/7 phy: Add USB PHY driver for the cadence USB3

+ Rafal, Anil, Sanket, Jayshri, Rahul

Quoted 106 lines

We are discussing if Cadence/TI/NXP could use the same USB PHY driver

(drivers/phy/cadence/phy-cadence-sierra.c), I find I can't get

Alan Douglas <[email protected]>, would you please forward related

people? The question is like below, thanks.

Alan, we find the suggested value at this driver (drivers/phy/cadence/phy-cadence-sierra.c)

is so different with "USB 3.0 PHY User Guide for 28FDSOI" CH 3.1.1 Bring-up Sequence.

Does this driver support this 28nm PHY? If it supports, why the initialized value is so different?

The UG suggested value can be used at NXP platform.

Peter

Quoted 18 lines
Quoted 17 lines
Quoted 17 lines

This is indeed a different driver. IMO it would be better to keep

the driver closer to its linux version. The reason for that  is that

it is quite new and will be adapted when platforms starts supporting

it. If we start with something too far from the original, it will hard to update.

Already I see that the registers initialized are not all the same as

in the linux driver and not all the values are the same either, nor

are the register names

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

TI's J7 platforms is using this PHY driver for USB3/PCIe support,

and the linux driver has already seen quite a few modifications to

get it to work

(https://urldefense.proofpoint.com/v2/url?u=https-3A__eur01.safelinks.protection.outlook.com_-3Furl-3Dhttps-253A-252F-

252Fgit.ti&d=DwIGaQ&c=aUq983L2pue2FqKFoP6PGHMJQyoJ7kl3s3GZ-_haXqY&r=e1OgxfvkL0qo9XO6fX1gscva-w03uSYC1nIyxl89- rI&m=Ip2RbyxoGLS3zuYNjazxkPFURIUZllrs6iSfUmllZGM&s=MG2JpCkGii7tKv3Sb4ekJ08smJd54TTIC6jmZpOdzY0&e= .

Quoted 53 lines
Quoted 20 lines
Quoted 8 lines

com%2Fti-linux-kernel%2Fti-linux-kernel%2Fblobs%2Fhistory%2Fti-linux

-

4.19.y%2Fdrivers%2Fphy%2Fcadence%2Fphy-cadence-

sierra.c&amp;data=02%7C01%7Csherry.sun%40nxp.com%7C84f9122d7eb64

Quoted 9 lines

9820bae08d72b997681%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0

%7C637025810458595586&amp;sdata=6JpD7VcFudhzXSVP0WaGVEp7Fwrue

A%2B4V6eeOfif19w%3D&amp;reserved=0)

Adding support for it on top of this current version will be rather difficult.

Quoted 5 lines

Thanks for your advice.

Actually I am not familiar with this phy driver in linux, so also

+peter, who worked on this USB driver under linux, maybe he can give some

suggestions.

Quoted 1 line

Add Alan from Cadence

Alan, we find the suggested value at this driver (drivers/phy/cadence/phy-cadence-

sierra.c)

is so different with "USB 3.0 PHY User Guide for 28FDSOI" CH 3.1.1 Bring-up

Sequence.

Does this driver support this 28nm PHY? If it supports, why the initialized value is so

different?

The UG suggested value can be used at NXP platform.

Peter

author
#14 lore raw

PATCH v5 7/7 usb: gadget: core: introduce ->udc_set_speed() method

In reply to Sherry Sun

This patch was copied from kernel commit: 67fdfda4a99ed.

Sometimes, the gadget driver we want to run has max_speed lower than what the UDC supports. In such situations, UDC might want to make sure we don't try to connect on speeds not supported by the gadget driver because that will just fail.

So here introduce a new optional ->udc_set_speed() method which can be implemented by interested UDC drivers to achieve this purpose.

---
 drivers/usb/gadget/udc/udc-core.c | 23 +++++++++++++++++++++++
 include/linux/usb/gadget.h        |  2 ++
 2 files changed, 25 insertions(+)
drivers/usb/gadget/udc/udc-core.c +23 -0
index 62b47781dd..8d1d90e3e3 100644
@@ -267,6 +267,27 @@ EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
 
 /* ------------------------------------------------------------------------- */
 
+/**
+ * usb_gadget_udc_set_speed - tells usb device controller speed supported by
+ *    current driver
+ * @udc: The device we want to set maximum speed
+ * @speed: The maximum speed to allowed to run
+ *
+ * This call is issued by the UDC Class driver before calling
+ * usb_gadget_udc_start() in order to make sure that we don't try to
+ * connect on speeds the gadget driver doesn't support.
+ */
+static inline void usb_gadget_udc_set_speed(struct usb_udc *udc,
+					    enum usb_device_speed speed)
+{
+	if (udc->gadget->ops->udc_set_speed) {
+		enum usb_device_speed s;
+
+		s = min(speed, udc->gadget->max_speed);
+		udc->gadget->ops->udc_set_speed(udc->gadget, s);
+	}
+}
+
 static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver)
 {
 	int ret;
@@ -276,6 +297,8 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
 
 	udc->driver = driver;
 
+	usb_gadget_udc_set_speed(udc, driver->speed);
+
 	ret = driver->bind(udc->gadget);
 	if (ret)
 		goto err1;
include/linux/usb/gadget.h +2 -0
index a34f3478f3..78e245a1b5 100644
@@ -450,6 +450,8 @@ struct usb_gadget_ops {
 	int   (*match_ep)(struct usb_gadget *gadget,
 			  struct usb_ep *ep,
 			  struct usb_endpoint_descriptor *desc);
+	void	(*udc_set_speed)(struct usb_gadget *gadget,
+				 enum usb_device_speed);
 };
 
 /**
Signature · 1 line
2.17.1
#15 lore raw

v5 cover usb: Add cadence USB3 gadget/host/phy driver

In reply to Sherry Sun

Hi Sherry,

Quoted 8 lines · Sherry Sun

These patches introduce new Cadence driver to U-Boot.
The first patch is to add the Cadence USB3 IP(CDNS3) core and driver for the usb gadget.
The second patch introduce the xhci-imx8 usb host driver separately. The third patch introduce the cdns3 phy driver which can be used for both cdns3 host driver and gadget driver.
The cdns3 usb gadget/host/phy driver are all used DM mode.

Quoted 6 lines

The current driver has been validated on i.MX8 platform.
If someone want to test it, please note that the additional dts nodes/ config macros/clock driver are also essential. You can also get my test patches at https://github.com/sherrysun1/u-boot-imx.git to start your test quickly.

I see that Cadence USB driver for Linux kernel is still under development and DT compatible binding is supposed to be "cdns,usb3" not "cdns,usb3-1.0.0". See v11:
https://patchwork.kernel.org/patch/11114415/
Deviating from kernel binding will break sync'ing of DTs b/w kernel and U-Boot.

Also, why not sync the latest host/gadget driver patches from kernel as is? That should help in borrowing bug fixes/features whenever Cadence updates kernel driver in future.

BTW, have you tested gadget driver with functions that use bulk endpoints such as f_mass_storage or f_fastboot?

Regards
Vignesh

Quoted 62 lines

Changes in v5:
- Delete some unnecessary code.
- Fix some issues about lack of parentheses.
- Add separate patch for core framework changes.
- Add "reg-names" for usb nodes in DT and use it to get reg values.
- Use "cdns,usb3-1.0.0" compatible instead "cdns,usb3".
- Add DM_FLAG_OS_PREPARE flag to xhci-imx8 driver.

Sherry Sun (7):
dt-bindings: add dt-binding doc for CDNS3 controller
usb: gadget: Add the cadence USB3 gadget driver
usb: gadget: Add match_ep call back to usb_gadget_ops
usb: gadget: Add gadget_is_cdns3 checking to provide bcdUSB value
usb: host: Add the USB3 host driver
phy: Add USB PHY driver for the cadence USB3
usb: gadget: core: introduce ->udc_set_speed() method

 Makefile                                   |    1 +
 doc/device-tree-bindings/usb/cdns-usb3.txt |   53 +
 drivers/phy/Kconfig                        |    8 +
 drivers/phy/Makefile                       |    1 +
 drivers/phy/cdns3-usb-phy.c                |  241 +++
 drivers/usb/Kconfig                        |    2 +
 drivers/usb/cdns3/Kconfig                  |   20 +
 drivers/usb/cdns3/Makefile                 |    5 +
 drivers/usb/cdns3/cdns3-generic.c          |  114 +
 drivers/usb/cdns3/cdns3-nxp-reg-def.h      |   93 +
 drivers/usb/cdns3/core.c                   |  203 ++
 drivers/usb/cdns3/core.h                   |  118 ++
 drivers/usb/cdns3/dev-regs-macro.h         |  116 ++
 drivers/usb/cdns3/dev-regs-map.h           |  117 ++
 drivers/usb/cdns3/gadget-export.h          |   26 +
 drivers/usb/cdns3/gadget.c                 | 2183 ++++++++++++++++++++
 drivers/usb/cdns3/gadget.h                 |  225 ++
 drivers/usb/cdns3/io.h                     |   27 +
 drivers/usb/gadget/epautoconf.c            |    4 +
 drivers/usb/gadget/gadget_chips.h          |    7 +
 drivers/usb/gadget/udc/Makefile            |    1 +
 drivers/usb/gadget/udc/udc-core.c          |   23 +
 drivers/usb/host/Kconfig                   |    9 +
 drivers/usb/host/Makefile                  |    1 +
 drivers/usb/host/xhci-imx8.c               |  210 ++
 include/linux/usb/gadget.h                 |    5 +
 scripts/Makefile.spl                       |    1 +
 27 files changed, 3814 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/cdns-usb3.txt
 create mode 100644 drivers/phy/cdns3-usb-phy.c
 create mode 100644 drivers/usb/cdns3/Kconfig
 create mode 100644 drivers/usb/cdns3/Makefile
 create mode 100644 drivers/usb/cdns3/cdns3-generic.c
 create mode 100644 drivers/usb/cdns3/cdns3-nxp-reg-def.h
 create mode 100644 drivers/usb/cdns3/core.c
 create mode 100644 drivers/usb/cdns3/core.h
 create mode 100644 drivers/usb/cdns3/dev-regs-macro.h
 create mode 100644 drivers/usb/cdns3/dev-regs-map.h
 create mode 100644 drivers/usb/cdns3/gadget-export.h
 create mode 100644 drivers/usb/cdns3/gadget.c
 create mode 100644 drivers/usb/cdns3/gadget.h
 create mode 100644 drivers/usb/cdns3/io.h
 create mode 100644 drivers/usb/host/xhci-imx8.c
Signature · 2 lines
Regards
Vignesh
author
#16 lore raw

v5 cover usb: Add cadence USB3 gadget/host/phy driver

Hi Vignesh,

Quoted 26 lines

Hi Sherry,

Quoted 9 lines · Sherry Sun

These patches introduce new Cadence driver to U-Boot.
The first patch is to add the Cadence USB3 IP(CDNS3) core and driver for the usb gadget.
The second patch introduce the xhci-imx8 usb host driver separately. The third patch introduce the cdns3 phy driver which can be used for both
cdns3 host driver and gadget driver.
The cdns3 usb gadget/host/phy driver are all used DM mode.

Quoted 5 lines

The current driver has been validated on i.MX8 platform.
If someone want to test it, please note that the additional dts nodes/ config macros/clock driver are also essential. You can also get my test patches at

https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub
.com%2Fsherrysun1%2Fu-boot- imx.git&amp;data=02%7C01%7Csherry.sun%40nxp.com%7C97d431d6b5694 51ff8ac08d72bb5f883%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0% 7C637025932942549390&amp;sdata=XEFSCN0TtgU1H1zhNAgZeZIRgDInL%2B 2Gb8ec3KO4AsI%3D&amp;reserved=0 to start your test quickly.

Quoted 1 line
Quoted 11 lines

I see that Cadence USB driver for Linux kernel is still under development and DT compatible binding is supposed to be "cdns,usb3" not "cdns,usb3-1.0.0". See v11:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatch
work.kernel.org%2Fpatch%2F11114415%2F&amp;data=02%7C01%7Csherry.s un%40nxp.com%7C97d431d6b569451ff8ac08d72bb5f883%7C686ea1d3bc2b 4c6fa92cd99c5c301635%7C0%7C0%7C637025932942549390&amp;sdata=Jltlk Te7SXTAQAKtF7HzOqY291upS67Eixeke9oXQ2w%3D&amp;reserved=0 Deviating from kernel binding will break sync'ing of DTs b/w kernel and U- Boot.

Thanks for your reminder, I only noticed the DT compatible in v5 last time. So I will change it to "cdns,usb3" in next version.

Quoted 3 lines

Also, why not sync the latest host/gadget driver patches from kernel as is? That should help in borrowing bug fixes/features whenever Cadence updates kernel driver in future.

Since there are many differences between the cdns3 driver in uboot and kernel, such as in uboot, we didn't support host mode in cdns3 core.c, instead we add an xhci-imx8 driver as host driver. So the patches from kernel can't be applied to this driver.

Quoted 3 lines

BTW, have you tested gadget driver with functions that use bulk endpoints such as f_mass_storage or f_fastboot?

Yes, I have tested the ums and fastboot function already, and it has proved to work well on i.MX8 platform.

Best regards
Sherry sun

Quoted 68 lines

Regards
Vignesh

Quoted 51 lines

Changes in v5:
- Delete some unnecessary code.
- Fix some issues about lack of parentheses.
- Add separate patch for core framework changes.
- Add "reg-names" for usb nodes in DT and use it to get reg values.
- Use "cdns,usb3-1.0.0" compatible instead "cdns,usb3".
- Add DM_FLAG_OS_PREPARE flag to xhci-imx8 driver.

Sherry Sun (7):
dt-bindings: add dt-binding doc for CDNS3 controller
usb: gadget: Add the cadence USB3 gadget driver
usb: gadget: Add match_ep call back to usb_gadget_ops
usb: gadget: Add gadget_is_cdns3 checking to provide bcdUSB value
usb: host: Add the USB3 host driver
phy: Add USB PHY driver for the cadence USB3
usb: gadget: core: introduce ->udc_set_speed() method

 Makefile                                   |    1 +
 doc/device-tree-bindings/usb/cdns-usb3.txt |   53 +
 drivers/phy/Kconfig                        |    8 +
 drivers/phy/Makefile                       |    1 +
 drivers/phy/cdns3-usb-phy.c                |  241 +++
 drivers/usb/Kconfig                        |    2 +
 drivers/usb/cdns3/Kconfig                  |   20 +
 drivers/usb/cdns3/Makefile                 |    5 +
 drivers/usb/cdns3/cdns3-generic.c          |  114 +
 drivers/usb/cdns3/cdns3-nxp-reg-def.h      |   93 +
 drivers/usb/cdns3/core.c                   |  203 ++
 drivers/usb/cdns3/core.h                   |  118 ++
 drivers/usb/cdns3/dev-regs-macro.h         |  116 ++
 drivers/usb/cdns3/dev-regs-map.h           |  117 ++
 drivers/usb/cdns3/gadget-export.h          |   26 +
 drivers/usb/cdns3/gadget.c                 | 2183 ++++++++++++++++++++
 drivers/usb/cdns3/gadget.h                 |  225 ++
 drivers/usb/cdns3/io.h                     |   27 +
 drivers/usb/gadget/epautoconf.c            |    4 +
 drivers/usb/gadget/gadget_chips.h          |    7 +
 drivers/usb/gadget/udc/Makefile            |    1 +
 drivers/usb/gadget/udc/udc-core.c          |   23 +
 drivers/usb/host/Kconfig                   |    9 +
 drivers/usb/host/Makefile                  |    1 +
 drivers/usb/host/xhci-imx8.c               |  210 ++
 include/linux/usb/gadget.h                 |    5 +
 scripts/Makefile.spl                       |    1 +
 27 files changed, 3814 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/cdns-usb3.txt
 create mode 100644 drivers/phy/cdns3-usb-phy.c  create mode 100644

drivers/usb/cdns3/Kconfig create mode 100644 drivers/usb/cdns3/Makefile create mode 100644 drivers/usb/cdns3/cdns3-generic.c create mode 100644 drivers/usb/cdns3/cdns3-nxp-reg-def.h

Quoted 9 lines
 create mode 100644 drivers/usb/cdns3/core.c  create mode 100644
drivers/usb/cdns3/core.h  create mode 100644
drivers/usb/cdns3/dev-regs-macro.h
 create mode 100644 drivers/usb/cdns3/dev-regs-map.h  create mode

100644 drivers/usb/cdns3/gadget-export.h create mode 100644 drivers/usb/cdns3/gadget.c create mode 100644 drivers/usb/cdns3/gadget.h create mode 100644 drivers/usb/cdns3/io.h create mode 100644 drivers/usb/host/xhci-imx8.c

--
Regards
Vignesh

#17 lore raw

v5 cover usb: Add cadence USB3 gadget/host/phy driver

Hi,

Quoted 1 line · Sherry Sun

Hi Vignesh,

[...]

Quoted 14 lines
Quoted 11 lines

I see that Cadence USB driver for Linux kernel is still under development and DT compatible binding is supposed to be "cdns,usb3" not "cdns,usb3-1.0.0". See v11:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatch
work.kernel.org%2Fpatch%2F11114415%2F&amp;data=02%7C01%7Csherry.s un%40nxp.com%7C97d431d6b569451ff8ac08d72bb5f883%7C686ea1d3bc2b 4c6fa92cd99c5c301635%7C0%7C0%7C637025932942549390&amp;sdata=Jltlk Te7SXTAQAKtF7HzOqY291upS67Eixeke9oXQ2w%3D&amp;reserved=0 Deviating from kernel binding will break sync'ing of DTs b/w kernel and U- Boot.

Thanks for your reminder, I only noticed the DT compatible in v5 last time. So I will change it to "cdns,usb3" in next version.

Quoted 8 lines
Quoted 3 lines

Also, why not sync the latest host/gadget driver patches from kernel as is? That should help in borrowing bug fixes/features whenever Cadence updates kernel driver in future.

Since there are many differences between the cdns3 driver in uboot and kernel, such as in uboot, we didn't support host mode in cdns3 core.c, instead we add an xhci-imx8 driver as host driver. So the patches from kernel can't be applied to this driver.

I see that xhci-imx8.c is generic enough to be used with v11 upstream cdns3/core.c and cdns3/host.c once IMX specific stuff is moved to top level wrapper.

I see you use a separate compatible for host driver which does not match with kernel (as there is no separate node for host vs device). Moreover the dt bindings listed in patch 1/7 lists non core registers as part of Cadence USB3 controller node.

Above issues make it impossible to sync Kernel DT nodes with U-Boot DT nodes which is not acceptable for U-Boot. All non Cadence core registers and configurations need to part of a separate wrapper driver that then binds to appropriate host/device Cadence USB3 controller node based on dr_mode property. E.g: see who dwc3 is modeled [3]:
Also see cdns-ti.c in the TI U-Boot branch [1] [2])

If there are more customization required for host driver cdns3/host.c we can provide vendor specific hooks/callbacks to be called from cdns3/host.c Current series is not usable on TI platform with Cadence USB3 IP at least in host mode and would need core host driver to be ported from kernel.

Keeping Linux kernel and U-Boot driver stack in sync has a big advantage for you as well. It simplifies borrowing bug fixes and new features or functions (especially in subsystems like USB where code is pretty large)

BTW, I have a tree with v10 of Cadence USB3 kernel driver ported to U-Boot here[1]. It is based on 2019.01 U-Boot but should apply as is on the latest tree as well. (Tree is still missing USB3 PHY support and thus USB 3.0 support) and works on TI platform. I am waiting for bindings to be frozen in Linux before posting to U-Boot list.

Hopefully we can find a way to collaborate!

[1] git://git.ti.com/~vigneshr/ti-u-boot/vigneshr-ti-u-boot.git
branch: dfu
[2]
http://git.ti.com/cgit/cgit.cgi/~vigneshr/ti-u-boot/vigneshr-ti-u-boot.git/tree/arch/arm/dts/k3-j721e-main.dtsi?h=dfu#n430
[3]
https://elixir.bootlin.com/u-boot/latest/source/drivers/usb/dwc3/dwc3-generic.c

Signature · 2 lines
Regards
Vignesh
author
#18 lore raw

v5 cover usb: Add cadence USB3 gadget/host/phy driver

Hi Vignesh,

Quoted 61 lines

Hi,

Quoted 1 line · Sherry Sun

Hi Vignesh,

[...]

Quoted 2 lines
Quoted 2 lines

I see that Cadence USB driver for Linux kernel is still under development and DT compatible binding is supposed to be "cdns,usb3"

not "cdns,usb3-1.0.0".

Quoted 3 lines
Quoted 3 lines

See v11:
https://patch

work.kernel.org%2Fpatch%2F11114415%2F&amp;data=02%7C01%7Csherry.s

Quoted 1 line
Quoted 1 line

un%40nxp.com%7C97d431d6b569451ff8ac08d72bb5f883%7C686ea1d3bc2b

Quoted 1 line
Quoted 1 line

4c6fa92cd99c5c301635%7C0%7C0%7C637025932942549390&amp;sdata=Jltlk

Quoted 6 lines
Quoted 4 lines

Te7SXTAQAKtF7HzOqY291upS67Eixeke9oXQ2w%3D&amp;reserved=0 Deviating from kernel binding will break sync'ing of DTs b/w kernel and U- Boot.

Thanks for your reminder, I only noticed the DT compatible in v5 last time.

So I will change it to "cdns,usb3" in next version.

Quoted 9 lines
Quoted 4 lines

Also, why not sync the latest host/gadget driver patches from kernel as is? That should help in borrowing bug fixes/features whenever Cadence updates kernel driver in future.

Since there are many differences between the cdns3 driver in uboot and kernel, such as in uboot, we didn't support host mode in cdns3 core.c, instead we add an
xhci-imx8 driver as host driver. So the patches from kernel can't be applied

to this driver.

Quoted 1 line

I see that xhci-imx8.c is generic enough to be used with v11 upstream cdns3/core.c and cdns3/host.c once IMX specific stuff is moved to top level wrapper.

I see you use a separate compatible for host driver which does not match with kernel (as there is no separate node for host vs device). Moreover the dt bindings listed in patch 1/7 lists non core registers as part of Cadence USB3 controller node.

Above issues make it impossible to sync Kernel DT nodes with U-Boot DT nodes which is not acceptable for U-Boot. All non Cadence core registers and configurations need to part of a separate wrapper driver that then binds to appropriate host/device Cadence USB3 controller node based on dr_mode property. E.g: see who dwc3 is modeled [3]:
Also see cdns-ti.c in the TI U-Boot branch [1] [2])

If there are more customization required for host driver cdns3/host.c we can provide vendor specific hooks/callbacks to be called from cdns3/host.c Current series is not usable on TI platform with Cadence USB3 IP at least in host mode and would need core host driver to be ported from kernel.

Keeping Linux kernel and U-Boot driver stack in sync has a big advantage for you as well. It simplifies borrowing bug fixes and new features or functions (especially in subsystems like USB where code is pretty large)

Quoted 7 lines

BTW, I have a tree with v10 of Cadence USB3 kernel driver ported to U-Boot here[1]. It is based on 2019.01 U-Boot but should apply as is on the latest tree as well. (Tree is still missing USB3 PHY support and thus USB 3.0 support) and works on TI platform. I am waiting for bindings to be frozen in Linux before posting to U-Boot list.

Hopefully we can find a way to collaborate!

I think your suggestions are reasonable, I agree that keep Linux kernel and U-Boot driver stack in sync is a good choice!
So I will try to test your code[1] on i.MX8 platform later, if the common core part can work well, maybe you can post it to U-Boot list after the Linux cdns3 driver version is frozen.

Best regards
Sherry sun

Quoted 25 lines

[1] git://git.ti.com/~vigneshr/ti-u-boot/vigneshr-ti-u-boot.git
branch: dfu
[2]
https://eur01.safelinks.protection.outlook.com/?url=http:%2F%2Fgit.ti.com%
2Fcgit%2Fcgit.cgi%2F~vigneshr%2Fti-u-boot%2Fvigneshr-ti-u- boot.git%2Ftree%2Farch%2Farm%2Fdts%2Fk3-j721e- main.dtsi%3Fh%3Ddfu%23n430&amp;data=02%7C01%7Csherry.sun%40nxp. com%7C25c139bf8e6c4d6575ab08d72c996ba4%7C686ea1d3bc2b4c6fa92cd9 9c5c301635%7C0%7C0%7C637026909770138936&amp;sdata=lj44%2BFC0AKi cD%2BY81zHKhUl23DzxY4b%2Fu9fGstr3nOI%3D&amp;reserved=0
[3]
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felixir.
bootlin.com%2Fu- boot%2Flatest%2Fsource%2Fdrivers%2Fusb%2Fdwc3%2Fdwc3- generic.c&amp;data=02%7C01%7Csherry.sun%40nxp.com%7C25c139bf8e6c 4d6575ab08d72c996ba4%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0 %7C637026909770138936&amp;sdata=mGur%2FVZFiUef5tblBuVPh3i86FQpe yunPg15m%2Bwh1mk%3D&amp;reserved=0

--
Regards
Vignesh