Skip to content

Add USB Controller Auto-Detection and Configuration #7

@mihai-chiorean

Description

@mihai-chiorean

Description

Different boards use different USB controllers (dwc2, dwc3, tegra-xudc). The gadget should auto-detect and configure appropriately.

Current Problem

The current implementation assumes dwc2 controller and doesn't adapt to different hardware platforms.

Implementation

Detect USB controller type and configure:

  • USB version (2.0 vs 3.0)
  • Power settings (bus-powered vs self-powered)
  • Device class and attributes

Detection Logic

# Check for dwc3 (USB 3.x)
if lsmod | grep -q "dwc3" || find /sys/class/udc -name "*dwc3*"; then
    USB_VERSION="0x0300"  # USB 3.0
    USB_CONTROLLER="dwc3"
# Check for dwc2 (USB 2.0)
elif lsmod | grep -q "dwc2" || find /sys/class/udc -name "*dwc2*"; then
    USB_VERSION="0x0200"  # USB 2.0
    USB_CONTROLLER="dwc2"
# Check for Tegra (Jetson)
elif lsmod | grep -q "tegra_xudc" || find /sys/class/udc -name "*tegra*"; then
    USB_VERSION="0x0300"  # USB 3.0
    USB_CONTROLLER="tegra-xudc"
fi

Power Configuration

if [ "$USB_CONTROLLER" = "dwc3" ]; then
    # Self-powered device
    echo 0xC0 > configs/c.1/bmAttributes
else
    # Bus-powered device
    echo 0x80 > configs/c.1/bmAttributes
    echo 250 > configs/c.1/MaxPower
fi

Acceptance Criteria

  • Correctly identifies dwc2, dwc3, tegra-xudc controllers
  • Sets USB version based on controller capabilities
  • Configures power settings appropriately
  • Works across RPi, Jetson, and generic ARM platforms
  • Logs detected controller for debugging
  • Handles unknown controllers gracefully

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions