U-boot not finding USB3.0 port on BPI-R3

I am building the latest MTK U-boot from GitHub - mtk-openwrt/u-boot: "Das U-Boot" Source Tree and have customised the configuration to enable USB storage devices.

However after plugging in a USB 2.0 stick into the blue USB 3.0 port on the front edge of the BPI R3 board, U-boot isn’t able to find the USB stick. If I boot into OpenWRT then lsusb finds the USB stick.

U-boot doesn’t find the USB 2.0 hub chip on the board that is connected to the MT7986 USB 2.0 port and provides the 4G card slot and USB 2.0 header connections.

It seems that the U-boot MTK driver doesn’t try scanning the USB 3.0 port.

On @frank-w page en:bpi-r3:uboot [FW-WEB Wiki] there is a USB log that looks the same as my USB log, but they were testing using the USB 2.0 headers. I also don’t see any related commits in Commits · frank-w/u-boot · GitHub that might fix the issue.

Has anyone tried a booting off a USB stick in the USB 3.0 port? If you have and it worked, please let me know what you did.

Here are the U-boot USB config options:

  │ │                                                    --- USB support                                                                                                           │ │  
  │ │                                                    [ ]   Enable driver model for USB Gadget                                                                                  │ │  
  │ │                                                          *** USB Host Controller Drivers ***                                                                                 │ │  
  │ │                                                    [*]   xHCI HCD (USB 3.0) support                                                                                          │ │  
  │ │                                                    [ ]     DesignWare USB3 DRD Core Support                                                                                  │ │  
  │ │                                                    [ ]     DesignWare USB3 DRD Generic OF Simple Glue Layer                                                                  │ │  
  │ │                                                    [*]     Support for MediaTek on-chip xHCI USB controller                                                                  │ │  
  │ │                                                    [ ]     Support for PCI-based xHCI USB controller                                                                         │ │  
  │ │                                                    [ ]     Support for NXP Layerscape on-chip xHCI USB controller                                                            │ │  
  │ │                                                    [ ]     Broadcom USB3 Host XHCI controller                                                                                │ │  
  │ │                                                    [ ]   EHCI HCD (USB 2.0) support                                                                                          │ │  
  │ │                                                    [ ]   OHCI HCD (USB 1.1) support                                                                                          │ │  
  │ │                                                    [ ]   UHCI HCD (most Intel and VIA) support                                                                               │ │  
  │ │                                                    [ ]   DesignWare USB2 Core support                                                                                        │ │  
  │ │                                                    [ ]   Renesas R8A66597 USB Core support                                                                                   │ │  
  │ │                                                    [ ]   NXP ISP 1760/1761/1763 support                                                                                      │ │  
  │ │                                                    [ ]   Cadence USB3 Dual-Role Controller                                                                                   │ │  
  │ │                                                    [ ]   DesignWare USB3 DRD Core Support                                                                                    │ │  
  │ │                                                    [*]   MediaTek USB3 Dual Role controller                                                                                  │ │  
  │ │                                                            MTU3 Mode Selection (Host only mode)  --->                                                                        │ │  
  │ │                                                    [ ]     Enable Debugging Messages                                                                                         │ │  
  │ │                                                          *** Legacy MUSB Support ***                                                                                         │ │  
  │ │                                                    [ ]   Legacy MUSB Host Controller                                                                                         │ │  
  │ │                                                    [ ]   Legacy USB Device Controller                                                                                        │ │  
  │ │                                                          *** MUSB Controller Driver ***                                                                                      │ │  
  │ │                                                    [ ]   MUSB host mode support                                                                                              │ │  
  │ │                                                    [ ]   Disable DMA (always use PIO)                                                                                        │ │  
  │ │                                                          *** USB Phy ***                                                                                                     │ │  
  │ │                                                    [ ]   TWL4030 PHY                                                                                                         │ │  
  │ │                                                    [ ]   Rockchip USB2 PHY                                                                                                   │ │  
  │ │                                                          *** ULPI drivers ***                                                                                                │ │  
  │ │                                                    [ ]   ULPI Viewport type                                                                                                  │ │  
  │ │                                                          *** USB peripherals ***                                                                                             │ │  
  │ │                                                    [*]   USB Mass Storage support                                                                                            │ │  
  │ │                                                    [ ]   USB Keyboard support                                                                                                │ │  
  │ │                                                    [ ]   Onboard USB hub support                                                                                             │ │  
  │ │                                                    (1000) Timeout in milliseconds for USB HUB connection                                                                     │ │  
  │ │                                                    [ ]   USB to Ethernet Controller Drivers  ----                                                                            │ │  
  │ │                                                    [ ]   USB Gadget Support  ----                                                                                            │ │  
  │ │                                                    [ ]   USB Gadget Support in SPL

Here is the U-boot usb info and usb tree output:

BPI-R3> usb start
starting USB...
Bus xhci@11200000: xhci-mtk xhci@11200000: hcd: 0x0000000011200000, ippc: 0x0000000011203e00
xhci-mtk xhci@11200000: ports disabled mask: u3p-0x0, u2p-0x0
xhci-mtk xhci@11200000: u2p:2, u3p:1
Register 300010f NbrPorts 3
Starting the controller
USB XHCI 1.10
scanning bus xhci@11200000 for devices... 1 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
BPI-R3> usb info
1: Hub,  USB Revision 3.0
 - U-Boot XHCI Host Controller 
 - Class: Hub
 - PacketSize: 512  Configurations: 1
 - Vendor: 0x0000  Product 0x0000 Version 1.0
   Configuration: 1
   - Interfaces: 1 Self Powered 0mA
     Interface: 0
     - Alternate Setting 0, Endpoints: 1
     - Class Hub
     - Endpoint 1 In Interrupt MaxPacket 8 Interval 255ms

BPI-R3> usb tree
USB device tree:
  1  Hub (5 Gb/s, 0mA)
     U-Boot XHCI Host Controller 
   

Here is the OpenWRT lsusb output:

root@OpenWrt:/# lsusb
Bus 001 Device 003: ID 18a5:0302 Verbatim STORE N GO
Bus 002 Device 001: ID 1d6b:0003 Linux 5.4.188 xhci-hcd xHCI Host Controller
Bus 001 Device 002: ID 1a40:0101  USB 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux 5.4.188 xhci-hcd xHCI Host Controller

I had a look at the DTS file for MT7986 in U-boot versus the one in Linux upstream since I see people have copied bits from the Linux file before to enable PCIe etc as the U-boot file is missing lots and generally out of date.

Comparing the two I noticed the xhci and usbtphy sections in the U-boot file had all these <&dummy_clk> references, while the Linux file has values like CLK_ instead.

So I copied over the Linux CLK_ values, renaming them to CK_ to match the U-boot header files.

But when I run usb start now the serial output starts getting garbage characters.

So I am thinking there is a bug in the U-boot MTK USB drivers to do with clocks, hence the dummy clock stuff. I am thinking some clock needed for USB 3.0 isn’t enabled automatically, but then trying to set the real clock values the driver then messes up something to do with UART.

Here are my DTS changes:

	xhci: xhci@11200000 {
		compatible = "mediatek,mt7986-xhci",
			     "mediatek,mtk-xhci";
		reg = <0x11200000 0x2e00>,
		      <0x11203e00 0x0100>;
		reg-names = "mac", "ippc";
		interrupts = <GIC_SPI 173 IRQ_TYPE_LEVEL_HIGH>;
		phys = <&u2port0 PHY_TYPE_USB2>,
		       <&u3port0 PHY_TYPE_USB3>,
		       <&u2port1 PHY_TYPE_USB2>;
		clocks = <&infracfg CK_INFRA_IUSB_SYS_CK>
			 <&infracfg CK_INFRA_IUSB_CK>,
			 <&infracfg CK_INFRA_IUSB_133_CK>,
			 <&infracfg CK_INFRA_IUSB_66M_CK>,
			 <&topckgen CK_TOP_U2U3_XHCI_SEL>;
		clock-names = "sys_ck",
			      "ref_ck",
			      "mcu_ck",
			      "dma_ck",
			      "xhci_ck";
		tpl-support;
		status = "okay";
	};

	usbtphy: usb-phy@11e10000 {
		compatible = "mediatek,mt7986-tphy",
			     "mediatek,generic-tphy-v2";
		#address-cells = <1>;
		#size-cells = <1>;
		status = "okay";

		u2port0: usb-phy@11e10000 {
			reg = <0x11e10000 0x700>;
			clocks = <&topckgen CK_TOP_DA_U2_REFSEL>,
				 <&topckgen CK_TOP_DA_U2_CK_1P_SEL>;
			clock-names = "ref", "da_ref";
			#phy-cells = <1>;
			status = "okay";
		};

		u3port0: usb-phy@11e10700 {
			reg = <0x11e10700 0x900>;
			clocks = <&topckgen CK_TOP_USB3_PHY_SEL>;
			clock-names = "ref";
			#phy-cells = <1>;
			status = "okay";
		};

		u2port1: usb-phy@11e11000 {
			reg = <0x11e11000 0x700>;
			clocks = <&topckgen CK_TOP_DA_U2_REFSEL>,
				 <&topckgen CK_TOP_DA_U2_CK_1P_SEL>;
			clock-names = "ref", "da_ref";
			#phy-cells = <1>;
			status = "okay";
		};
	};

I guess you miss usb_storage option in defconfig…my uboot supports usb,but have only usb2 usb sticks for testing here

I finally managed to get USB working.

I discovered I also needed to enable:

CONFIG_PHY=y
CONFIG_PHY_MTK_TPHY=y

Which seems obvious now as its in the DTS file.

I discovered this after testing @frank-w U-boot build which was able to read the USB stick. I then was comparing the configurations and discovered this setting.

which config have you used? you can use my defconfig and extend what you need

Btw. Clock driver is completely different to linux,partly it simply enables all clocks,not only needed. Thats one of the main work while converting to of_upstream.