USB: Add cadence USB3 gadget/host/phy driver
Subsystems (7)
v3 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 v3:
- Changed all compatible from "Cadence,usb3" to "cdns,usb3".
- Use wait_for_bit_le32() and clrsetbits_le32() globally.
- Use u32 instead of unint_32 globally.
- Split cdns3_set_role() into two functions:
cdns3_host_role_set() and cdns3_gadget_role_set().
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 | 243 +++ 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 | 194 ++ 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 | 2218 ++++++++++++++++++++ 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 | 189 ++ include/linux/usb/gadget.h | 5 + scripts/Makefile.spl | 1 + 27 files changed, 3807 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 v3 1/4 USB: gadget: Add the cadence USB3 gadget driver
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 + 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 | 194 ++ 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 | 2218 ++++++++++++++++++++ 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, 3331 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: "cdns,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 = "cdns,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 +194 -0
194 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 +2218 -0
2,146 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 v3 2/4 USB: host: Add the USB3 host driver
In reply to Sherry SunAdd 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 | 189 +++++++++++++++++++++++++++++++++++ 3 files changed, 199 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 +189 -0
189 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 2/4 USB: host: Add the USB3 host driver
On 8/16/19 8:10 AM, Sherry Sun wrote:
[...]
drivers/usb/host/Kconfig config USB_XHCI_FSL · line 100
Quoted 11 lines
drivers/usb/host/Kconfig +3
-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"
i.MX8 I guess ?
[...]
Quoted 16 lines
drivers/usb/host/xhci-imx8.c new file +10
-0@@ -0,0 +1,189 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright 2019 NXP +* +* NXP i.MX8 USB HOST xHCI Controller (Cadence IP) +* +* Author: Peter Chen <[email protected]> +*/ + +#include <common.h>
drivers/usb/host/xhci-imx8.c line 20
Quoted 10 lines
drivers/usb/host/xhci-imx8.c new file +10
-0+#include <usb.h> +#include <malloc.h> +#include <dm.h> +#include <dm/device-internal.h> +#include <clk.h> +#include <wait_bit.h> +#include <power-domain.h> +#include <generic-phy.h> +#include <asm/arch/clock.h> +#include <linux/compat.h>
Keep the list sorted
Quoted 20 lines
drivers/usb/host/xhci-imx8.c new file +20
-0+#include "xhci.h" + +/* Declare global data pointer */ +DECLARE_GLOBAL_DATA_PTR ; + +/* Host registers */ +#define HCIVERSION_CAPLENGTH 0x10000 +#define USBSTS 0x10084 + +/* None-core registers */ +#define USB3_CORE_CTRL1 0x00 +#define USB3_CORE_STATUS 0x0c +#define USB3_SSPHY_STATUS 0x4c + +struct xhci_imx8_data { +void __iomem *usb3_ctrl_base; +void __iomem *usb3_core_base; +struct clk_bulk clks; +struct phy phy; +};
drivers/usb/host/xhci-imx8.c line 50
Quoted 10 lines
drivers/usb/host/xhci-imx8.c new file +10
-0+ +static struct xhci_imx8_data imx8_data; + +static void imx8_xhci_init (void ) +{ +u32 tmp_data; +int ret; + + tmp_data =readl (imx8_data.usb3_ctrl_base +USB3_SSPHY_STATUS ); +writel (tmp_data, imx8_data.usb3_ctrl_base +USB3_SSPHY_STATUS );
Is this read-write really needed ?
drivers/usb/host/xhci-imx8.c line 55
Quoted 5 lines
drivers/usb/host/xhci-imx8.c new file +5
-0+ tmp_data =readl (imx8_data.usb3_ctrl_base +USB3_SSPHY_STATUS ); + ret =wait_for_bit_le32 (imx8_data.usb3_ctrl_base +USB3_SSPHY_STATUS , +0xf0000000 , true,100 , false); +if (ret) +printf ("clkvld is incorrect\n" );
Shouldn't this return ret ?
drivers/usb/host/xhci-imx8.c line 69
Quoted 13 lines
drivers/usb/host/xhci-imx8.c new file +13
-0+clrsetbits_le32 (imx8_data.usb3_ctrl_base +USB3_CORE_CTRL1 , +0x7 ,0x202 ); +clrbits_le32 (imx8_data.usb3_ctrl_base +USB3_CORE_CTRL1 ,1 <<26 ); +generic_phy_init (&imx8_data.phy); + +/* clear all sw_rst */ +clrbits_le32 (imx8_data.usb3_ctrl_base +USB3_CORE_CTRL1 ,0xFC <<24 ); + +debug ("wait xhci_power_on_ready\n" ); + ret =wait_for_bit_le32 (imx8_data.usb3_ctrl_base +USB3_CORE_STATUS , +0x1000 , true,100 , false); +if (ret) +printf ("wait xhci_power_on_ready timeout\n" );
return ret on failure ?
drivers/usb/host/xhci-imx8.c line 76
Quoted 7 lines
drivers/usb/host/xhci-imx8.c new file +7
-0+debug ("xhci_power_on_ready\n" ); + +debug ("waiting CNR 0x%x\n" , tmp_data); + ret =wait_for_bit_le32 (imx8_data.usb3_core_base +USBSTS , +0x800 , false,100 , false); +if (ret) +printf ("wait CNR timeout\n" );
return ret on failure ?
drivers/usb/host/xhci-imx8.c line 83
Quoted 7 lines
drivers/usb/host/xhci-imx8.c new file +7
-0+debug ("check CNR has finished\n" ); +} + +static void imx8_xhci_reset (void ) +{ +/* Set CORE ctrl to default value, that all rst are hold */ +writel (0xfc000001 , imx8_data.usb3_ctrl_base +USB3_CORE_CTRL1 );
What are these magic values ? Add macros for them.
Quoted 40 lines
drivers/usb/host/xhci-imx8.c new file +40
-0+} + +static int xhci_imx8_clk_init (struct udevice *dev) +{ +int ret; + + ret =clk_get_bulk (dev, &imx8_data.clks); +if (ret) +return ret; + + ret =clk_enable_bulk (&imx8_data.clks); +if (ret) +return ret; + +return 0 ; +} + +static int xhci_imx8_get_reg_addr (struct udevice *dev) +{ + imx8_data.usb3_ctrl_base = + (void __iomem *)devfdt_get_addr_index (dev,0 ); + imx8_data.usb3_core_base = + (void __iomem *)devfdt_get_addr_index (dev,4 ); + +return 0 ; +} + +static int xhci_imx8_probe (struct udevice *dev) +{ +struct xhci_hccr *hccr; +struct xhci_hcor *hcor; +struct udevice usbotg_dev; +struct power_domain pd; +int usbotg_off; +int ret =0 ; +int len; + + usbotg_off =fdtdec_lookup_phandle (gd->fdt_blob, +dev_of_offset (dev), +"cdns3,usb" );
drivers/usb/host/xhci-imx8.c line 133
Quoted 10 lines
drivers/usb/host/xhci-imx8.c new file +10
-0+if (usbotg_off <0 ) +return -EINVAL ; + usbotg_dev.node =offset_to_ofnode (usbotg_off); + usbotg_dev.parent = dev->parent; +xhci_imx8_get_reg_addr (&usbotg_dev); + +#if CONFIG_IS_ENABLED (POWER_DOMAIN ) +if (!power_domain_get (&usbotg_dev, &pd)) { +if (power_domain_on (&pd)) +return -EINVAL ;
ret = power_domain_on()
if (ret)
return ret;
[...]
PATCH v3 3/4 phy: Add USB PHY driver for the cadence USB3
In reply to Sherry SunThe 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 | 243 ++++++++++++++++++++++++++++++++++++ 3 files changed, 252 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 +243 -0
243 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 4/4 USB: gadget: core: introduce ->udc_set_speed() method
In reply to Sherry SunThis 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