Allwinner H6 USB3 support
v3 cover Allwinner H6 USB3 support
This series adds PHY and XHCI driver support for the USB3 controller found in the Allwinner H6 SoC. It has been tested and working on both boards enabled in patch 4, although some users experience issues[1].
[1]: https://lists.denx.de/pipermail/u-boot/2021-February/440767.html
Changes from v2:
- Fix xhci-pci.c compilation (RPi4 and other boards)
Changes from v1:
- Dropped patches 1-2 (already in u-boot-sunxi/master) and rebased
- Added Andre's Reviewed-by on the PHY driver
- Fixed error handling in xhci_pci_probe
Samuel Holland (4):
phy: sun50i-usb3: Add a driver for the H6 USB3 PHY
usb: xhci-pci: Move reset logic out of XHCI core
usb: xhci-dwc3: Add support for clocks/resets
configs: Enable USB3 on Allwinner H6 boards
configs/orangepi_3_defconfig | 5 + configs/pine_h64_defconfig | 5 + drivers/phy/allwinner/Kconfig | 8 ++ drivers/phy/allwinner/Makefile | 1 + drivers/phy/allwinner/phy-sun50i-usb3.c | 171 ++++++++++++++++++++++++ drivers/usb/host/xhci-dwc3.c | 56 ++++++++ drivers/usb/host/xhci-mem.c | 2 - drivers/usb/host/xhci-pci.c | 52 ++++++- drivers/usb/host/xhci.c | 35 ----- include/usb/xhci.h | 2 - 10 files changed, 294 insertions(+), 43 deletions(-) create mode 100644 drivers/phy/allwinner/phy-sun50i-usb3.c
Signature · 1 line
2.17.5
PATCH v3 1/4 phy: sun50i-usb3: Add a driver for the H6 USB3 PHY
From: Samuel Holland <[email protected]>
This driver is needed for XHCI to work on the Allwinner H6 SoC. The driver is copied from Linux v5.10.
--- drivers/phy/allwinner/Kconfig | 8 ++ drivers/phy/allwinner/Makefile | 1 + drivers/phy/allwinner/phy-sun50i-usb3.c | 171 ++++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 drivers/phy/allwinner/phy-sun50i-usb3.c
drivers/phy/allwinner/Kconfig +8 -0
@@ -11,3 +11,11 @@ config PHY_SUN4I_USB This driver controls the entire USB PHY block, both the USB OTG parts, as well as the 2 regular USB 2 host PHYs. + +config PHY_SUN50I_USB3 + bool "Allwinner sun50i USB3 PHY driver" + depends on ARCH_SUNXI + select PHY + help + Enable this to support the USB3 transceiver that is part of + Allwinner sun50i SoCs.
drivers/phy/allwinner/Makefile +1 -0
@@ -4,3 +4,4 @@ # obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o +obj-$(CONFIG_PHY_SUN50I_USB3) += phy-sun50i-usb3.o
drivers/phy/allwinner/phy-sun50i-usb3.c new file +171 -0
171 lines not on this page · raw message
Signature · 1 line
2.17.5
PATCH v3 2/4 usb: xhci-pci: Move reset logic out of XHCI core
In reply to Andre PrzywaraFrom: Samuel Holland <[email protected]>
Resetting an XHCI controller inside xhci_register undoes any register setup performed by the platform driver. And at least on the Allwinner H6, resetting the XHCI controller also resets the PHY, which prevents the controller from working. That means the controller must be taken out of reset before initializing the PHY, which must be done before calling xhci_register.
The logic in the XHCI core was added to support the Raspberry Pi 4 (although this was not mentioned in the commit log!), which uses the xhci-pci platform driver. Move the reset logic to the platform driver, where it belongs, and where it cannot interfere with other platform drivers.
This also fixes a failure to call reset_free if xhci_register failed.
--- drivers/usb/host/xhci-mem.c | 2 -- drivers/usb/host/xhci-pci.c | 52 ++++++++++++++++++++++++++++++++++--- drivers/usb/host/xhci.c | 35 ------------------------- include/usb/xhci.h | 2 -- 4 files changed, 48 insertions(+), 43 deletions(-)
drivers/usb/host/xhci-mem.c +0 -2
@@ -180,8 +180,6 @@ void xhci_cleanup(struct xhci_ctrl *ctrl)xhci_free_virt_devices (ctrl);free (ctrl->erst.entries);free (ctrl->dcbaa); -if (reset_valid (&ctrl->reset)) -reset_free (&ctrl->reset);memset (ctrl,'\0' ,sizeof (struct xhci_ctrl )); }
drivers/usb/host/xhci-pci.c +48 -4
85 lines not on this page · raw message
drivers/usb/host/xhci.c +0 -35
@@ -188,37 +188,6 @@ static int xhci_start(struct xhci_hcor *hcor)return ret; } -#if CONFIG_IS_ENABLED (DM_USB ) -/** -* Resets XHCI Hardware -* -* @param ctrl pointer to host controller -* @return 0 if OK, or a negative error code. -*/ -static int xhci_reset_hw (struct xhci_ctrl *ctrl) -{ -int ret; - - ret =reset_get_by_index (ctrl->dev,0 , &ctrl->reset); -if (ret && ret != -ENOENT && ret != -ENOTSUPP ) { -dev_err (ctrl->dev,"failed to get reset\n" ); -return ret; - } - -if (reset_valid (&ctrl->reset)) { - ret =reset_assert (&ctrl->reset); -if (ret) -return ret; - - ret =reset_deassert (&ctrl->reset); -if (ret) -return ret; - } - -return 0 ; -} -#endif -/** * Resets the XHCI Controller *
@@ -1534,10 +1503,6 @@ int xhci_register(struct udevice *dev, struct xhci_hccr *hccr, ctrl->dev = dev; - ret =xhci_reset_hw (ctrl); -if (ret) - goto err; -/* * XHCI needs to issue a Address device command to setup * proper device context structures, before it can interact
include/usb/xhci.h +0 -2
@@ -17,7 +17,6 @@#define HOST_XHCI_H_ #include <phys2bus.h> -#include <reset.h> #include <asm/types.h> #include <asm/cache.h> #include <asm/io.h>
@@ -1200,7 +1199,6 @@ struct xhci_ctrl {#if CONFIG_IS_ENABLED (DM_USB )struct udevice *dev;#endif -struct reset_ctl reset;struct xhci_hccr *hccr;/* R/O registers, not need for volatile */ struct xhci_hcor *hcor;struct xhci_doorbell_array *dba;
Signature · 1 line
2.17.5
PATCH v3 3/4 usb: xhci-dwc3: Add support for clocks/resets
In reply to Andre PrzywaraFrom: Samuel Holland <[email protected]>
Some platforms, like the Allwinner H6, do not have a separate glue layer around the dwc3. Instead, they rely on the clocks/resets/phys referenced from the dwc3 DT node itself. Add support for enabling the clocks/resets referenced from the dwc3 DT node.
--- drivers/usb/host/xhci-dwc3.c | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
drivers/usb/host/xhci-dwc3.c +56 -0
@@ -7,10 +7,12 @@* Author: Ramneek Mehresh<[email protected]> */ +#include <clk.h> #include <common.h> #include <dm.h> #include <generic-phy.h> #include <log.h> +#include <reset.h> #include <usb.h> #include <dwc3-uboot.h> #include <linux/delay.h>
@@ -21,7 +23,9 @@#include <linux/usb/otg.h> struct xhci_dwc3_plat { +struct clk_bulk clks;struct phy_bulk phys; +struct reset_ctl_bulk resets; };void dwc3_set_mode (struct dwc3 *dwc3_reg,u32 mode)
@@ -111,6 +115,46 @@ void dwc3_set_fladj(struct dwc3 *dwc3_reg, u32 val) }#if CONFIG_IS_ENABLED (DM_USB ) +static int xhci_dwc3_reset_init (struct udevice *dev, +struct xhci_dwc3_plat *plat) +{ +int ret; + + ret =reset_get_bulk (dev, &plat->resets); +if (ret == -ENOTSUPP || ret == -ENOENT ) +return 0 ; +else if (ret) +return ret; + + ret =reset_deassert_bulk (&plat->resets); +if (ret) { +reset_release_bulk (&plat->resets); +return ret; + } + +return 0 ; +} + +static int xhci_dwc3_clk_init (struct udevice *dev, +struct xhci_dwc3_plat *plat) +{ +int ret; + + ret =clk_get_bulk (dev, &plat->clks); +if (ret == -ENOSYS || ret == -ENOENT ) +return 0 ; +if (ret) +return ret; + + ret =clk_enable_bulk (&plat->clks); +if (ret) { +clk_release_bulk (&plat->clks); +return ret; + } + +return 0 ; +} +static int xhci_dwc3_probe (struct udevice *dev) {struct xhci_hcor *hcor;
@@ -122,6 +166,14 @@ static int xhci_dwc3_probe(struct udevice *dev)u32 reg;int ret; + ret =xhci_dwc3_reset_init (dev, plat); +if (ret) +return ret; + + ret =xhci_dwc3_clk_init (dev, plat); +if (ret) +return ret; + hccr = (struct xhci_hccr *)((uintptr_t )dev_remap_addr (dev)); hcor = (struct xhci_hcor *)((uintptr_t )hccr +HC_LENGTH (xhci_readl (&(hccr)->cr_capbase)));
@@ -171,6 +223,10 @@ static int xhci_dwc3_remove(struct udevice *dev)dwc3_shutdown_phy (dev, &plat->phys); +clk_release_bulk (&plat->clks); + +reset_release_bulk (&plat->resets); +return xhci_deregister (dev); }
Signature · 1 line
2.17.5
PATCH v3 4/4 configs: Enable USB3 on Allwinner H6 boards
In reply to Andre PrzywaraFrom: Samuel Holland <[email protected]>
Pine H64 and Orange Pi 3 both provide a USB3 type A port. Enable it in U-Boot.
--- configs/orangepi_3_defconfig | 5 +++++ configs/pine_h64_defconfig | 5 +++++ 2 files changed, 10 insertions(+)
configs/orangepi_3_defconfig +5 -0
@@ -8,5 +8,10 @@ CONFIG_MMC0_CD_PIN="PF6" CONFIG_MMC_SUNXI_SLOT_EXTRA=2 CONFIG_BLUETOOTH_DT_DEVICE_FIXUP="brcm,bcm4345c5" # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set +CONFIG_PHY_SUN50I_USB3=y +CONFIG_USB_XHCI_HCD=y +CONFIG_USB_XHCI_DWC3=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_OHCI_HCD=y +CONFIG_USB_DWC3=y +# CONFIG_USB_DWC3_GADGET is not set
configs/pine_h64_defconfig +5 -0
@@ -12,5 +12,10 @@ CONFIG_SPL_SPI_SUNXI=y # CONFIG_PSCI_RESET is not set # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set CONFIG_SUN8I_EMAC=y +CONFIG_PHY_SUN50I_USB3=y +CONFIG_USB_XHCI_HCD=y +CONFIG_USB_XHCI_DWC3=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_OHCI_HCD=y +CONFIG_USB_DWC3=y +# CONFIG_USB_DWC3_GADGET is not set
Signature · 1 line
2.17.5