USB Driver

The JH-7110 SoC Platform supports the following features and specifications for the USB module.

  • As the master device, connect mass storage devices, USB mouse and other USB devices.
  • As the slave device, perform ADB debugs and mass storage device

USB Driver Framework

The following figure shows the block diagram of the PWM driver for JH-7110.

Linux kernel provides a complete set of USB driver programs. The USB framework uses a tree structure and only allows to have one host device on a bus.

The following diagram shows the USB framework from the host or slave’s point of view.
Figure 1. Driver Framework

The main tasks of the USB subsystem include:

  • Register and manage device drivers
  • Locate drivers for USB devices, then initialize and configure the device
  • Display device tree in the kernel
  • Interact with devices

USB Driver Device Tree Source Code

The following code block shows the device tree source code of the USB driver in the jh7110.dtsi file.
 usbdrd30: usbdrd{
compatible = "starfive,jh7110-cdns3";
         reg = <0x0 0x10210000 0x0 0x1000>,
                   <0x0 0x10200000 0x0 0x1000>;
         clocks = <&clkgen JH7110_USB_125M>,
                       <&clkgen JH7110_USB0_CLK_APP_125>,
                       <&clkgen JH7110_USB0_CLK_LPM>,
                        <&clkgen JH7110_USB0_CLK_STB>,
                        <&clkgen JH7110_USB0_CLK_USB_APB>,
                        <&clkgen JH7110_USB0_CLK_AXI>,
                        <&clkgen JH7110_USB0_CLK_UTMI_APB>,
                        <&clkgen JH7110_PCIE0_CLK_APB>;
           clock-names = "125m","app","lpm","stb","apb","axi","utmi", "phy";
           resets = <&rstgen RSTN_U0_CDN_USB_PWRUP>,
                         <&rstgen RSTN_U0_CDN_USB_APB>,
                         <&rstgen RSTN_U0_CDN_USB_AXI>,
                         <&rstgen RSTN_U0_CDN_USB_UTMI_APB>,
                          <&rstgen RSTN_U0_PLDA_PCIE_APB>;
             reset-names = "pwrup","apb","axi","utmi", "phy";
             starfive,stg-syscon = <&stg_syscon 0x4 0xc4 0x148 0x1f4>;
             starfive,sys-syscon = <&sys_syscon 0x18>;
             status = "disabled";
             #address-cells = <2>;
             #size-cells = <2>;
             #interrupt-cells = <1>;
             ranges;
             usbdrd_cdns3: usb@10100000 {
                   compatible = "cdns,usb3";
                   reg = <0x0 0x10100000 0x0 0x10000>,
                              <0x0 0x10110000 0x0 0x10000>,
                              <0x0 0x10120000 0x0 0x10000>;
                    reg-names = "otg", "xhci", "dev";
                    interrupts = <100>, <108>, <110>;
                    interrupt-names = "host", "peripheral", "otg";
                    phy-names = "cdns3,usb3-phy", "cnds3,usb2-phy";
                    maximum-speed = "super-speed";
             };
 };
The following table describes the DT parameters:
Table 1. USB DT Parameters
Parameter Description
Parameters common to usbdrd30: usbdrd (main node) and usbdrd_cdns3 nodes
compatible Compatibility information, used to associate the driver and its target device
reg Register base address "0x10030000" and range "0x4000".
clocks The clocks used by the USB module
clock-names The names of the clocks used by the USB module
resets The reset signals used by the USB module
reset_names The names of the reset signals
starfive,stg-syscon The register values for the StarFive STG SYSCON control registers
starfive,sys-syscon The register values for the StarFive SYS SYSCON control registers
status

The work status of the USB module. To enable the module, set this bit to okay. To disable the module, set this bit to disabled.

Parameters specific to usbdrd_cdns3 node
interrupts Hardware interrupt ID
interrupt-names Hardware interrupt names
phy-names USB PHY names
maximum-speed Whether to support USB 3.0 super-speed

Driver Source Code Structure

The following code block displays the source code structure for the USB Subsystem.

Table 2. USB Host Driver Source Code Structure
Node Stricture
USB on the core level
drivers/usb/core
├── Makefile
├── usb.c
├── hub.c
├── hcd.c
├── urb.c
├── message.c
├── driver.c
├── config.c
├── file.c
├── buffer.c
├── sysfs.c
├── endpoint.c
├── devio.c
├── notify.c
├── generic.c
├── quirks.c
├── devices.c
├── phy.c
├── port.c
├── of.c
├── hcd-pci.c
├── usb-acpi.c
├── Kconfig
xHCI-host
drivers/usb/host/
├── Makefile
├── Kconfig
├── xhci.c
├── xhci-plat.c
├── xhci-mem.c
├── xhci-ext-caps.c
├── xhci-ring.c
├── xhci-hub.c
├── xhci-dbg.c
├── xhci-trace.c
├── xhci-pci.c
├── xhci-debugfs.c
CDNS3 on the core and role level
drivers/usb/cdns3/
├── Makefile
├── core.c
├── drd.c
├── Kconfig
CDNS3 on the platform level
drivers/usb/cdns3/
├── cdns3-plat.c
├── cdns3-starfive.c
CDN3 host
drivers/usb/cdn3/
├── host.c
Table 3. USB Device Driver Source Code Structure
Node Structure
USB gadget driver
drivers/usb/gadget/
├── usbstring.c
├── config.c
├── epautoconf.c
├── composite.c
├── functions.c
├── configfs.c
├── u_f.c
├── Makefile
├── Kconfig
USB device function (mass storage and functionfs)
drivers/usb/gadget/function/
├── f_mass_storage.c
├── storage_common.c
├── f_fs.c
├── Makefile
├── Kconfig
USB UDC driver
drivers/usb/gadget/udc/
├── core.c
├── trace.c
├── Makefile
├── Kconfig
CDN3 USB device driver
  • For Linux 5.15:
    drivers/usb/cdn3/
    ├── cdns3-gadget.c
    ├── cdns3-ep0.c
    
  • For Linux 5.10:
    drivers/usb/cdn3/
    ├── gadget.c
    ├── ep0.c