USB: Add cadence USB3 gadget driver and host driver
Subsystems (7)
v2 cover USB: Add cadence USB3 gadget driver and host driver
From: Sherry Sun <[email protected]>
These patches introduce new Cadence USBSS 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 driver/host/phy driver are all used DM mode.
The current driver has been validated on i.MX8 platform. If anyone 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.
Changes in v2:
- Add doc/device-tree-bindings/usb/cdns-usb3.txt to describe the usb node properties in dts.
- Add cdns3 usb phy driver instead of implementing it in cdns3 gadget/host driver.
- Use clrbits_le32() and setbits_le32() globally.
- Remove some macros that are not used temporarily.
Sherry Sun (4):
USB: gadget: Add the cadence USB3 gadget driver
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 | 39 + drivers/phy/Kconfig | 8 + drivers/phy/Makefile | 1 + drivers/phy/cdns3-usb-phy.c | 242 +++ drivers/usb/Kconfig | 2 + drivers/usb/cdns3/Kconfig | 20 + drivers/usb/cdns3/Makefile | 5 + drivers/usb/cdns3/cdns3-generic.c | 115 + drivers/usb/cdns3/cdns3-nxp-reg-def.h | 89 + drivers/usb/cdns3/core.c | 197 ++ 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 | 2222 ++++++++++++++++++++ drivers/usb/cdns3/gadget.h | 225 ++ drivers/usb/cdns3/io.h | 30 + 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 | 201 ++ include/linux/usb/gadget.h | 5 + scripts/Makefile.spl | 1 + 27 files changed, 3825 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
PATCH v2 1/4 USB: gadget: Add the cadence USB3 gadget driver
From: Sherry Sun <[email protected]>
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. And gadget_is_cdns3 checking is added to provide bcdUSB value in device descriptor.
--- Makefile | 1 + doc/device-tree-bindings/usb/cdns-usb3.txt | 39 + drivers/usb/Kconfig | 2 + drivers/usb/cdns3/Kconfig | 20 + drivers/usb/cdns3/Makefile | 5 + drivers/usb/cdns3/cdns3-generic.c | 115 + drivers/usb/cdns3/cdns3-nxp-reg-def.h | 89 + drivers/usb/cdns3/core.c | 197 ++ 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 | 2222 ++++++++++++++++++++ drivers/usb/cdns3/gadget.h | 225 ++ drivers/usb/cdns3/io.h | 30 + drivers/usb/gadget/epautoconf.c | 4 + drivers/usb/gadget/gadget_chips.h | 7 + drivers/usb/gadget/udc/Makefile | 1 + include/linux/usb/gadget.h | 3 + scripts/Makefile.spl | 1 + 20 files changed, 3338 insertions(+) create mode 100644 doc/device-tree-bindings/usb/cdns-usb3.txt 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
@@ -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/
doc/device-tree-bindings/usb/cdns-usb3.txt new file +39 -0
@@ -0,0 +1,39 @@ +* Cadence USB3 Controller + +Required properties: +- compatible: "Cadence,usb3"; +- reg: base address and length of the registers +- interrupts: interrupt for the USB 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 = "Cadence,usb3"; + reg = <0x0 0x5B110000 0x0 0x10000>, + <0x0 0x5B130000 0x0 0x10000>, + <0x0 0x5B140000 0x0 0x10000>, + <0x0 0x5B160000 0x0 0x40000>; + 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"; +};
drivers/usb/Kconfig +2 -0
@@ -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
@@ -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
@@ -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 +115 -0
115 lines not on this page · raw message
drivers/usb/cdns3/cdns3-nxp-reg-def.h new file +89 -0
89 lines not on this page · raw message
drivers/usb/cdns3/core.c new file +197 -0
197 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
@@ -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 +2222 -0
2,143 lines not on this page · raw message
drivers/usb/cdns3/gadget.h new file +225 -0
225 lines not on this page · 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.
PATCH v2 1/4 USB: gadget: Add the cadence USB3 gadget driver
Quoted 9 lines · sherry sun
From: Sherry Sun <[email protected]>
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_GADGETshould be enabled when use this driver. Andgadget_is_cdns3checking is added to provide bcdUSB value in device descriptor.
The cadence core isn't xhci compatible ? Sigh ...
[...]
doc/device-tree-bindings/usb/cdns-usb3.txt line 4
Quoted 6 lines
+++
b/doc/device-tree-bindings/usb/cdns-usb3.txtdoc/device-tree-bindings/usb/cdns-usb3.txt new file +4
-0@@ -0,0 +1,39 @@ +* Cadence USB3 Controller + +Required properties: +- compatible: "Cadence,usb3";
cdns , no ?
[...]
drivers/usb/cdns3/cdns3-generic.c line 29
Quoted 11 lines
drivers/usb/cdns3/cdns3-generic.c new file +11
-0+static int cdns3_generic_peripheral_clk_init (struct udevice *dev, +struct cdns3_generic_peripheral + *priv) +{ +int ret; + + ret =clk_get_bulk (dev, &priv->clks); +if (ret) +return ret; + +#if CONFIG_IS_ENABLED (CLK )
Why is the ifdef protecting only half of the clock functions ?
Quoted 9 lines
drivers/usb/cdns3/cdns3-generic.c new file +9
-0+ ret =clk_enable_bulk (&priv->clks); +if (ret) { +clk_release_bulk (&priv->clks); +return ret; + } +#endif + +return 0 ; +}
[...]
Quoted 9 lines
drivers/usb/cdns3/core.c new file +9
-0+static void cdns3_set_role (struct cdns3 *cdns,enum cdns3_roles role) +{ +u32 value; +int timeout_us =100000 ; +struct cdns3_generic_peripheral *priv =container_of (cdns, + struct cdns3_generic_peripheral, cdns3); + +if (role ==CDNS3_ROLE_END ) +return ;
drivers/usb/cdns3/core.c line 45
Quoted 10 lines
drivers/usb/cdns3/core.c new file +10
-0+ +/* Wait clk value */ + value =readl (cdns->none_core_regs +USB3_SSPHY_STATUS ); +writel (value, cdns->none_core_regs +USB3_SSPHY_STATUS ); +udelay (1 ); + value =readl (cdns->none_core_regs +USB3_SSPHY_STATUS ); +while ((value &0xf0000000 ) !=0xf0000000 && timeout_us-- >0 ) { + value =readl (cdns->none_core_regs +USB3_SSPHY_STATUS ); +udelay (1 ); + }
Is this like wait_for_bit() ?
drivers/usb/cdns3/core.c line 54
Quoted 8 lines
drivers/usb/cdns3/core.c new file +8
-0+if (timeout_us <=0 ) +dev_err (cdns->dev,"wait clkvld timeout\n" ); + +/* Set all Reset bits */ +setbits_le32 (cdns->none_core_regs +USB3_CORE_CTRL1 ,ALL_SW_RESET ); +udelay (1 ); + +if (role ==CDNS3_ROLE_HOST ) {
Do we need custom controller role definition ? I don't think so, just use the one in the USB stack.
Also, use clrsetbits_le32()
Quoted 23 lines
drivers/usb/cdns3/core.c new file +23
-0+ value =readl (cdns->none_core_regs +USB3_CORE_CTRL1 ); + value = (value & ~MODE_STRAP_MASK ) |HOST_MODE |OC_DISABLE ; +writel (value, cdns->none_core_regs +USB3_CORE_CTRL1 ); +clrbits_le32 (cdns->none_core_regs +USB3_CORE_CTRL1 , +PHYAHB_SW_RESET ); +mdelay (1 ); +generic_phy_init (&priv->phy); +setbits_le32 (cdns->phy_regs +TB_ADDR_TX_RCVDETSC_CTRL , +RXDET_IN_P3_32KHZ ); +udelay (10 ); +/* Force B Session Valid as 1 */ +writel (0x0060 , cdns->phy_regs +0x380a4 ); +mdelay (1 ); + +setbits_le32 (cdns->none_core_regs +USB3_INT_REG ,HOST_INT1_EN ); + +clrbits_le32 (cdns->none_core_regs +USB3_CORE_CTRL1 , +ALL_SW_RESET ); + +dev_dbg (cdns->dev,"wait xhci_power_on_ready\n" ); + + value =readl (cdns->none_core_regs +USB3_CORE_STATUS ); + timeout_us =100000 ;
drivers/usb/cdns3/core.c line 87
Quoted 10 lines
drivers/usb/cdns3/core.c new file +10
-0+while (!(value &HOST_POWER_ON_READY ) && timeout_us-- >0 ) { + value =readl (cdns->none_core_regs +USB3_CORE_STATUS ); +udelay (1 ); + } + +if (timeout_us <=0 ) +dev_err (cdns->dev,"wait xhci_power_on_ready timeout\n" ); + +dev_dbg (cdns->dev,"switch to host role successfully\n" ); + }else {/* gadget mode */
Split this into sensibly long funtions please.
Quoted 15 lines
drivers/usb/cdns3/core.c new file +15
-0+ value =readl (cdns->none_core_regs +USB3_CORE_CTRL1 ); + value = (value & ~MODE_STRAP_MASK ) |DEV_MODE ; +writel (value, cdns->none_core_regs +USB3_CORE_CTRL1 ); +clrbits_le32 (cdns->none_core_regs +USB3_CORE_CTRL1 , +PHYAHB_SW_RESET ); + +generic_phy_init (&priv->phy); +setbits_le32 (cdns->phy_regs +TB_ADDR_TX_RCVDETSC_CTRL , +RXDET_IN_P3_32KHZ ); +udelay (10 ); +/* Force B Session Valid as 1 */ +writel (0x0060 , cdns->phy_regs +0x380a4 ); +setbits_le32 (cdns->none_core_regs +USB3_INT_REG ,DEV_INT_EN ); + + clrbits_le32(cdns->none_core_regs + USB3_CORE_CTRL1,
drivers/usb/cdns3/core.c line 112
Quoted 10 lines
drivers/usb/cdns3/core.c new file +10
-0+ ALL_SW_RESET); + +dev_dbg (cdns->dev,"wait gadget_power_on_ready\n" ); + + value =readl (cdns->none_core_regs +USB3_CORE_STATUS ); + timeout_us =100000 ; +while (!(value &DEV_POWER_ON_READY ) && timeout_us-- >0 ) { + value =readl (cdns->none_core_regs +USB3_CORE_STATUS ); +udelay (1 ); + }
wait_for_bit()
[...]
drivers/usb/cdns3/dev-regs-macro.h line 26
Quoted 3 lines
drivers/usb/cdns3/dev-regs-macro.h new file +3
-0+/* macros for field CFGSTS */ +#define USB_STS__CFGSTS__MASK 0x00000001U +#define USB_STS__USBSPEED__READ (src) (((uint32_t)(src) & 0x00000070U) >> 4)
u32, fix globally
[...]
Quoted 28 lines
drivers/usb/cdns3/gadget.c new file +28
-0+static void __cdns3_gadget_start (struct usb_ss_dev *usb_ss) +{ +u32 usb_conf_reg =0 ; + +/* configure endpoint 0 hardware */ +cdns_ep0_config (usb_ss); + +/* enable interrupts for endpoint 0 (in and out) */ +cdns_writel (&usb_ss->regs->ep_ien, +EP_IEN__EOUTEN0__MASK |EP_IEN__EINEN0__MASK ); + +/* enable interrupt for device */ +cdns_writel (&usb_ss->regs->usb_ien, +USB_IEN__U2RESIEN__MASK + |USB_ISTS__DIS2I__MASK + |USB_IEN__CON2IEN__MASK + |USB_IEN__UHRESIEN__MASK + |USB_IEN__UWRESIEN__MASK + |USB_IEN__DISIEN__MASK + |USB_IEN__CONIEN__MASK + |USB_IEN__U3EXTIEN__MASK + |USB_IEN__L2ENTIEN__MASK + |USB_IEN__L2EXTIEN__MASK ); + + usb_conf_reg =USB_CONF__CLK2OFFDS__MASK | +USB_CONF__L1DS__MASK ; +if (usb_ss->gadget.max_speed ==USB_SPEED_HIGH ) + usb_conf_reg |=USB_CONF__USB3DIS__MASK ;
drivers/usb/cdns3/gadget.c line 2145
Quoted 10 lines
drivers/usb/cdns3/gadget.c new file +10
-0+cdns_writel (&usb_ss->regs->usb_conf, usb_conf_reg); + +cdns_writel (&usb_ss->regs->usb_conf, +USB_CONF__U1DS__MASK + |USB_CONF__U2DS__MASK +/* +* TODO: +* | USB_CONF__L1EN__MASK +*/ + );
Fix the TODO ?
[U-Boot] 答复: [PATCH v2 1/4] USB: gadget: Add the cadence USB3 gadget driver
Hi Marek
Quoted 7 lines · sherry sun
Quoted 5 lines
From: Sherry Sun <[email protected]>
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.
Quoted 8 lines
Quoted 2 lines
Add the Cadence USB3 IP(CDNS3) driver for the gadget (device mode). The CDNS3 gadget driver support DM mode.
CONFIG_DM_USB_GADGETshould
Quoted 2 lines
be enabled when use this driver. And
gadget_is_cdns3checking is added to provide bcdUSB value in device descriptor.The cadence core isn't xhci compatible ? Sigh ...
Actually, I'm not very understand what the xhci compatible means? The cadence core can support usb peripheral and host. But for now, we just done the gadget part in the core code. If it needed later, we can add the host part to it.
Quoted 10 lines
[...]
doc/device-tree-bindings/usb/cdns-usb3.txt line 4
Quoted 6 lines
+++
b/doc/device-tree-bindings/usb/cdns-usb3.txtdoc/device-tree-bindings/usb/cdns-usb3.txt new file +4
-0@@ -0,0 +1,39 @@ +* Cadence USB3 Controller + +Required properties: +- compatible: "Cadence,usb3";cdns , no ?
Yes, I have already changed all compatible to "cdns,usb3".
Quoted 16 lines
[...]
drivers/usb/cdns3/cdns3-generic.c line 29
Quoted 11 lines
drivers/usb/cdns3/cdns3-generic.c new file +11
-0+static int cdns3_generic_peripheral_clk_init (struct udevice *dev, +struct cdns3_generic_peripheral + *priv) +{ +int ret; + + ret =clk_get_bulk (dev, &priv->clks); +if (ret) +return ret; + +#if CONFIG_IS_ENABLED (CLK )Why is the ifdef protecting only half of the clock functions ?
Because the clk_get_bulk() also has function define even if CONFIG_CLK is not defined. So this way would not cause undefined reference error.
But for the sake of uniformity, I will move clk_get_bulk() into the ifdef protecting.
Quoted 27 lines
Quoted 10 lines
drivers/usb/cdns3/cdns3-generic.c new file +9
-0+ ret =clk_enable_bulk (&priv->clks); +if (ret) { +clk_release_bulk (&priv->clks); +return ret; + } +#endif + +return 0 ; +}[...]
Quoted 13 lines
drivers/usb/cdns3/core.c new file +13
-0+static void cdns3_set_role (struct cdns3 *cdns,enum cdns3_roles role) +{ +u32 value; +int timeout_us =100000 ; +struct cdns3_generic_peripheral *priv =container_of (cdns, + struct cdns3_generic_peripheral, cdns3); + +if (role ==CDNS3_ROLE_END ) +return ; + +/* Wait clk value */ + value =readl (cdns->none_core_regs +USB3_SSPHY_STATUS ); +writel (value, cdns->none_core_regs +USB3_SSPHY_STATUS );
Quoted 8 lines
drivers/usb/cdns3/core.c line 45
Quoted 6 lines
drivers/usb/cdns3/core.c new file +6
-0+udelay (1 ); + value =readl (cdns->none_core_regs +USB3_SSPHY_STATUS ); +while ((value &0xf0000000 ) !=0xf0000000 && timeout_us-- >0 ) { + value =readl (cdns->none_core_regs +USB3_SSPHY_STATUS ); +udelay (1 ); + }Is this like
wait_for_bit()?
Yes, thanks for the reminder, I have already use wait_for_bit_le32() to replace these.
Quoted 7 lines
drivers/usb/cdns3/core.c
Quoted 6 lines
drivers/usb/cdns3/core.c new file +5
-0+if (timeout_us <=0 ) +dev_err (cdns->dev,"wait clkvld timeout\n" ); + +/* Set all Reset bits */ + setbits_le32(cdns->none_core_regs + USB3_CORE_CTRL1,
ALL_SW_RESET);
Quoted 7 lines
drivers/usb/cdns3/core.c line 54
Quoted 3 lines
drivers/usb/cdns3/core.c new file +3
-0+udelay (1 ); + +if (role ==CDNS3_ROLE_HOST ) {Do we need custom controller role definition ? I don't think so, just use the one in the USB stack.
Actually we need create an array with two elements to store the corresponding host/gadge function pointer in struct cdns3. And use CDNS3_ROLE_END to do the check.
If we use the role define in USB stack, the array[USB_DR_MODE_UNKNOWN] will always be defined but not used. So I think the controller role definition is needed here. But if you really think the controller role definition isn’t appropriate, I will change it.
10 enum cdns3_roles {
11 CDNS3_ROLE_HOST = 0, 12 CDNS3_ROLE_GADGET, 13 CDNS3_ROLE_END,
14 };
12 enum usb_dr_mode {
13 USB_DR_MODE_UNKNOWN, 14 USB_DR_MODE_HOST, 15 USB_DR_MODE_PERIPHERAL, 16 USB_DR_MODE_OTG,
17 };
Quoted 1 line
Also, use
clrsetbits_le32()
Sure.
Quoted 30 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ value = readl(cdns->none_core_regs + USB3_CORE_CTRL1); + value = (value & ~MODE_STRAP_MASK) | HOST_MODE |
OC_DISABLE;drivers/usb/cdns3/core.c
Quoted 13 lines
drivers/usb/cdns3/core.c new file +13
-0+writel (value, cdns->none_core_regs +USB3_CORE_CTRL1 ); +clrbits_le32 (cdns->none_core_regs +USB3_CORE_CTRL1 , +PHYAHB_SW_RESET ); +mdelay (1 ); +generic_phy_init (&priv->phy); +setbits_le32 (cdns->phy_regs +TB_ADDR_TX_RCVDETSC_CTRL , +RXDET_IN_P3_32KHZ ); +udelay (10 ); +/* Force B Session Valid as 1 */ +writel (0x0060 , cdns->phy_regs +0x380a4 ); +mdelay (1 ); + + setbits_le32(cdns->none_core_regs + USB3_INT_REG,
HOST_INT1_EN);Quoted 12 lines
drivers/usb/cdns3/core.c new file +12
-0+ +clrbits_le32 (cdns->none_core_regs +USB3_CORE_CTRL1 , +ALL_SW_RESET ); + +dev_dbg (cdns->dev,"wait xhci_power_on_ready\n" ); + + value =readl (cdns->none_core_regs +USB3_CORE_STATUS ); + timeout_us =100000 ; +while (!(value &HOST_POWER_ON_READY ) && timeout_us-- >0 ) { + value =readl (cdns->none_core_regs +USB3_CORE_STATUS ); +udelay (1 ); + }
Quoted 8 lines
drivers/usb/cdns3/core.c line 87
Quoted 6 lines
drivers/usb/cdns3/core.c new file +6
-0+ +if (timeout_us <=0 ) +dev_err (cdns->dev,"wait xhci_power_on_ready timeout\n" ); + +dev_dbg (cdns->dev,"switch to host role successfully\n" ); + }else {/* gadget mode */ Split this into sensibly long funtions please.
Yes, I have done this.
Quoted 31 lines
Quoted 16 lines
drivers/usb/cdns3/core.c new file +15
-0+ value =readl (cdns->none_core_regs +USB3_CORE_CTRL1 ); + value = (value & ~MODE_STRAP_MASK ) |DEV_MODE ; +writel (value, cdns->none_core_regs +USB3_CORE_CTRL1 ); +clrbits_le32 (cdns->none_core_regs +USB3_CORE_CTRL1 , +PHYAHB_SW_RESET ); + +generic_phy_init (&priv->phy); +setbits_le32 (cdns->phy_regs +TB_ADDR_TX_RCVDETSC_CTRL , +RXDET_IN_P3_32KHZ ); +udelay (10 ); +/* Force B Session Valid as 1 */ +writel (0x0060 , cdns->phy_regs +0x380a4 ); +setbits_le32 (cdns->none_core_regs +USB3_INT_REG ,DEV_INT_EN ); + + clrbits_le32(cdns->none_core_regs + USB3_CORE_CTRL1,drivers/usb/cdns3/core.c line 112
Quoted 10 lines
drivers/usb/cdns3/core.c new file +10
-0+ ALL_SW_RESET); + +dev_dbg (cdns->dev,"wait gadget_power_on_ready\n" ); + + value =readl (cdns->none_core_regs +USB3_CORE_STATUS ); + timeout_us =100000 ; +while (!(value &DEV_POWER_ON_READY ) && timeout_us-- >0 ) { + value =readl (cdns->none_core_regs +USB3_CORE_STATUS ); +udelay (1 ); + }
wait_for_bit()[...]
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+/* macros for field CFGSTS */ +#define USB_STS__CFGSTS__MASK
0x00000001UQuoted 1 line
+#define
USB_STS__USBSPEED__READ(src)(((uint32_t)(src) &
0x00000070U) >> 4)u32, fix globally
Yes, I have fixed this.
Quoted 34 lines
[...]
Quoted 31 lines
drivers/usb/cdns3/gadget.c new file +31
-0+static void __cdns3_gadget_start (struct usb_ss_dev *usb_ss) { +u32 usb_conf_reg =0 ; + +/* configure endpoint 0 hardware */ +cdns_ep0_config (usb_ss); + +/* enable interrupts for endpoint 0 (in and out) */ +cdns_writel (&usb_ss->regs->ep_ien, +EP_IEN__EOUTEN0__MASK |EP_IEN__EINEN0__MASK ); + +/* enable interrupt for device */ +cdns_writel (&usb_ss->regs->usb_ien, +USB_IEN__U2RESIEN__MASK + |USB_ISTS__DIS2I__MASK + |USB_IEN__CON2IEN__MASK + |USB_IEN__UHRESIEN__MASK + |USB_IEN__UWRESIEN__MASK + |USB_IEN__DISIEN__MASK + |USB_IEN__CONIEN__MASK + |USB_IEN__U3EXTIEN__MASK + |USB_IEN__L2ENTIEN__MASK + |USB_IEN__L2EXTIEN__MASK ); + + usb_conf_reg =USB_CONF__CLK2OFFDS__MASK | +USB_CONF__L1DS__MASK ; +if (usb_ss->gadget.max_speed ==USB_SPEED_HIGH ) + usb_conf_reg |=USB_CONF__USB3DIS__MASK ; +cdns_writel (&usb_ss->regs->usb_conf, usb_conf_reg); + +cdns_writel (&usb_ss->regs->usb_conf, + USB_CONF__U1DS__MASK
Quoted 8 lines
drivers/usb/cdns3/gadget.c line 2145
Quoted 6 lines
drivers/usb/cdns3/gadget.c new file +6
-0+ | USB_CONF__U2DS__MASK +/* +* TODO: +* | USB_CONF__L1EN__MASK +*/ + );Fix the TODO ?
I have already fixed this.
Best regards
Sherry sun
[U-Boot] 答复: [PATCH v2 1/4] USB: gadget: Add the cadence USB3 gadget driver
Quoted 15 lines · Sherry Sun
Hi Marek
Quoted 13 lines · sherry sun
Quoted 7 lines
From: Sherry Sun <[email protected]>
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_GADGETshould
Quoted 2 lines
be enabled when use this driver. And
gadget_is_cdns3checking is added to provide bcdUSB value in device descriptor.
Quoted 7 lines
Quoted 2 lines
The cadence core isn't xhci compatible ? Sigh ...
Actually, I'm not very understand what the xhci compatible means? The cadence core can support usb peripheral and host. But for now, we just done the gadget part in the core code. If it needed later, we can add the host part to it.
So this is all needed to support gadget on the cadence3 ?
[U-Boot] 答复: 答复: [PATCH v2 1/4] USB: gadget: Add the cadence USB3 gadget driver
Hi Marek
Quoted 20 lines · Sherry Sun
Quoted 18 lines
Hi Marek
Quoted 15 lines · sherry sun
Quoted 7 lines
From: Sherry Sun <[email protected]>
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_GADGETshould
Quoted 2 lines
be enabled when use this driver. And
gadget_is_cdns3checking is added to provide bcdUSB value in device descriptor.The cadence core isn't xhci compatible ? Sigh ...
Quoted 6 lines
Quoted 4 lines
Actually, I'm not very understand what the xhci compatible means? The cadence core can support usb peripheral and host. But for now, we just done the gadget part in the core code. If it needed later, we can add the host part to it.
So this is all needed to support gadget on the cadence3 ?
Yes, this patch is all needed for cdns3 usb gadget driver. I have already validated this on i.MX8 platform.
PATCH v2 2/4 USB: host: Add the USB3 host driver
In reply to sherry sunFrom: Sherry Sun <[email protected]>
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 | 201 +++++++++++++++++++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 drivers/usb/host/xhci-imx8.c
drivers/usb/host/Kconfig +9 -0
@@ -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 imx8" + depends on ARCH_IMX8 + default y + help + Enables support for the on-chip xHCI controller on imx8qm and + imx8qxp SoCs. + endif # USB_XHCI_HCD config USB_EHCI_HCD
drivers/usb/host/Makefile +1 -0
@@ -55,6 +55,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 +201 -0
201 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 2/4 USB: host: Add the USB3 host driver
Quoted 5 lines · sherry sun
From: Sherry Sun <[email protected]>
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.
We already have a generic xhci driver, so why do we need that massive custom cadence driver ?
[U-Boot] 答复: [PATCH v2 2/4] USB: host: Add the USB3 host driver
Hi Marek,
Quoted 10 lines · sherry sun
Quoted 5 lines
From: Sherry Sun <[email protected]>
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.
We already have a generic xhci driver, so why do we need that massive custom cadence driver ?
Sorry, may I ask which generic xhci driver do you mean?
Best regards
Sherry sun
[U-Boot] 答复: [PATCH v2 2/4] USB: host: Add the USB3 host driver
Hi Marek,
Quoted 7 lines
Hi Marek,
Quoted 4 lines · sherry sun
Quoted 2 lines
From: Sherry Sun <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
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.
We already have a generic xhci driver, so why do we need that massive custom cadence driver ?
Sorry, may I ask which generic xhci driver do you mean?
Actually, this xhci-imx8 driver only did some specific work, such as call phy driver, non-core registers configurate and so on.
The generic xhci configurate work still done in xhci.c by calling xhci_register() in xhci_imx8_probe(). So I think this specific driver is needed.
Best regards
Sherry sun
Quoted 11 lines
Best regards
Sherry sun
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.de
nx.de%2Flistinfo%2Fu-boot&data=02%7C01%7Csherry.sun%40nxp.com% 7C568638198c214b189ffe08d721215f9c%7C686ea1d3bc2b4c6fa92cd99c5c3 01635%7C0%7C0%7C637014299551499522&sdata=jg%2BsBQWN4BxBt UPbpOEQdl%2F2JppSg5NSfsb0fWQkIk0%3D&reserved=0
[U-Boot] 答复: [PATCH v2 2/4] USB: host: Add the USB3 host driver
In reply to Sherry SunQuoted 6 lines · Sherry Sun
Hi Marek,
Quoted 4 lines · sherry sun
Quoted 2 lines
From: Sherry Sun <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
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.
We already have a generic xhci driver, so why do we need that massive custom cadence driver ?
Sorry, may I ask which generic xhci driver do you mean?
See drivers/usb/host/xhci*
PATCH v2 3/4 phy: Add USB PHY driver for the cadence USB3
In reply to sherry sunFrom: Sherry Sun <[email protected]>
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 | 242 ++++++++++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 drivers/phy/cdns3-usb-phy.c
drivers/phy/Kconfig +8 -0
@@ -190,4 +190,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
@@ -21,3 +21,4 @@ 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
drivers/phy/cdns3-usb-phy.c new file +242 -0
242 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 4/4 USB: gadget: core: introduce ->udc_set_speed() method
In reply to sherry sunFrom: Sherry Sun <[email protected]>
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
@@ -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
@@ -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