Re: [U-Boot] [PATCH v2 1/4] USB: gadget: Add the cadence USB3 gadget driver
On 8/14/19 2:16 PM, sherry sun wrote: > From: 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. And gadget_is_cdns3 checking is > added to provide bcdUSB value in device descriptor. The cadence core isn't xhci compatible ? Sigh ... [...] > +++ b/doc/device-tree-bindings/usb/cdns-usb3.txt > @@ -0,0 +1,39 @@ > +* Cadence USB3 Controller > + > +Required properties: > +- compatible: "Cadence,usb3"; cdns , no ? [...] > +static int cdns3_generic_peripheral_clk_init(struct udevice *dev, > + struct cdns3_generic_peripheral > + *priv) > +{ > + int ret; > + > + ret = clk_get_bulk(dev, >clks); > + if (ret) > + return ret; > + > +#if CONFIG_IS_ENABLED(CLK) Why is the ifdef protecting only half of the clock functions ? > + ret = clk_enable_bulk(>clks); > + if (ret) { > + clk_release_bulk(>clks); > + return ret; > + } > +#endif > + > + return 0; > +} [...] > +static void cdns3_set_role(struct cdns3 *cdns, enum cdns3_roles role) > +{ > + u32 value; > + int timeout_us = 10; > + 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); > + udelay(1); > + value = readl(cdns->none_core_regs + USB3_SSPHY_STATUS); > + while ((value & 0xf000) != 0xf000 && timeout_us-- > 0) { > + value = readl(cdns->none_core_regs + USB3_SSPHY_STATUS); > + udelay(1); > + } Is this like wait_for_bit() ? > + 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() > + 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(>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 = 10; > + 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. > + 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(>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, > + ALL_SW_RESET); > + > + dev_dbg(cdns->dev, "wait gadget_power_on_ready\n"); > + > + value = readl(cdns->none_core_regs + USB3_CORE_STATUS);
[U-Boot] [PATCH v2 1/4] USB: gadget: Add the cadence USB3 gadget driver
From: 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. And gadget_is_cdns3 checking is added to provide bcdUSB value in device descriptor. Signed-off-by: Sherry Sun --- 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 | 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 diff --git a/Makefile b/Makefile index 8513db94e3..fab1220114 100644 --- a/Makefile +++ b/Makefile @@ -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/ diff --git a/doc/device-tree-bindings/usb/cdns-usb3.txt b/doc/device-tree-bindings/usb/cdns-usb3.txt new file mode 100644 index 00..613a460e7b --- /dev/null +++ b/doc/device-tree-bindings/usb/cdns-usb3.txt @@ -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@5b11 { + compatible = "Cadence,usb3"; + reg = <0x0 0x5B11 0x0 0x1>, + <0x0 0x5B13 0x0 0x1>, + <0x0 0x5B14 0x0 0x1>, + <0x0 0x5B16 0x0 0x4>; + interrupt-parent = <>; + interrupts = ; + clocks = < IMX8QM_USB3_LPM_CLK>, + < IMX8QM_USB3_BUS_CLK>, + < IMX8QM_USB3_ACLK>, + < IMX8QM_USB3_IPG_CLK>, + < IMX8QM_USB3_CORE_PCLK>; + clock-names = "usb3_lpm_clk", "usb3_bus_clk", "usb3_aclk", + "usb3_ipg_clk", "usb3_core_pclk"; + power-domains = <_conn_usb2>; + phys = <>; + dr_mode = "otg"; + extcon = <_ptn5150>; + status = "disabled"; +}; diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 3b53bf2c58..98f5e936e5 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -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" diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig new file mode 100644 index 00..11a7144b05 --- /dev/null +++ b/drivers/usb/cdns3/Kconfig @@ -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