LAN966x UDPHS

SoC Resources

LAN966x SoC supports one instance of the UDPHS (USB High Speed Device Port) controller.

Kernel configurations

Following kernel config options should be enabled to use LAN966x UDPHS:

  • CONFIG_USB_GADGET - USB gadget config option

  • CONFIG_USB_ATMEL_USBA - LAN966x USB device driver config option

Built-in USB gadget

If using a static built-in gadget, the gadget choosen from a precomposed one provided by the kernel must be enabled. For instance, if you need the serial over USB gadget:

  • CONFIG_USB_G_SERIAL - USB serial gadget config option

This is the default option used by the kernels that are provided by the BSP.

ConfigFS USB gadget

If using a gadget configured from the user-space using ConfigFS. The USB functions used must be enabled.

  • CONFIG_USB_CONFIGFS - USB ConfigFS config option

  • USB_CONFIGFS_ACM - USB CDC-ACM (serial overs USB) config option

When a built-in gadget is used, it cannot be overriden from the user-space by an ConfigFS one.

Kernel console on Serial USB gadget

The Serial USB gadget can be used as a kernel console.

  • CONFIG_U_SERIAL_CONSOLE - USB serial as a kernel console config option

To activate the console on the USB serial gadget the kernel parameter console=ttyGS0,115200 must be present.

Kernel messages can be available on the USB serial gadget with CONFIG_U_SERIAL_CONSOLE enabled. Kernel boot messages are only available if the built-in gadget is used. If a ConfigFS gadget is used, only messages sent by the Kernel after the ConfigFS setup from user-space will be available.
Make sure that on the Host PC, ModemManager daemon is disabled, otherwise on the console will be printed some unexpected characters.

Devicetree Configuration

To enable LAN966x UDPHS, following configurations are required in device tree:

  • compatible string must be set to microchip,lan9662-udc and atmel,sama5d3-udc as a fallback.

  • reg property must be set to <0x00200000 0x80000> and <0xe0808000 0x400>.

  • interrupts property must be set to <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>.

  • clocks property must be set to <&clks GCK_GATE_UDPHS>, <&nic_clk>.

  • clock-names must be set to pclk and hclk.

Example

Following example shows how the LAN966x UDPHS controller should be defined in DT:

dtsi file:

udc: usb@e0808000 {
	compatible = "microchip,lan9662-udc",
		     "atmel,sama5d3-udc";
	reg = <0x00200000 0x80000>,
	      <0xe0808000 0x400>;
	interrupts = <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>;
	clocks = <&clks GCK_GATE_UDPHS>, <&nic_clk>;
	clock-names = "pclk", "hclk";
	status = "disabled";
};

dts file changes:

&gpio {
	udc_pins: ucd-pins {
		/* VBUS_DET B */
		pins = "GPIO_8";
		function = "usb_slave_b";
	};
};

&udc {
	pinctrl-0 = <&udc_pins>;
	pinctrl-names = "default";
	atmel,vbus-gpio = <&gpio 8 GPIO_ACTIVE_HIGH>;
	status = "okay";
};

UserSpace

If a built-in USB gadget is used, the USB gadget functionnality is present without particular settings. For instance, with the Serial USB gadget, /dev/ttyGS0 is available on the target. With the Ethernet USB gadget, ip link command lists the interface, usually usb0.

On the host side, the USB device is enumerated and available. For instance, with the Serial USB gadget, /dev/ttyACM0 is present.

ConfigFS gadget

Using a ConfigFS gadget needs some settings from the user-space. Here is a example showing how to setup the CDC-ACM (serial over USB) gadget.

# load libcomposite module.
modprobe libcomposite

# mount configfs
mkdir -p /tmp/config
mount none -t configfs /tmp/config

# Create gadget
mkdir /tmp/config/usb_gadget/my_gadget
cd /tmp/config/usb_gadget/my_gadget

# Set Vendor and Product IDs (Should be set to real values)
echo "0xabcd" > idVendor
echo "0x1234" > idProduct

# Set serial number, manufacturer and product string
mkdir strings/0x409
echo SN000000 > strings/0x409/serialnumber
echo Microchip > strings/0x409/manufacturer
echo LAN966x > strings/0x409/product

# Create the configuration
mkdir configs/c.1
mkdir configs/c.1/strings/0x409
echo Configuration > configs/c.1/strings/0x409/configuration

# Set some configuration attributes
echo 120 > configs/c.1/MaxPower

# Create the function
mkdir functions/acm.usb0

# Associate the function with the configuration
ln -s functions/acm.usb0 configs/c.1

# Enable the gadget
echo 200000.usb > UDC

The available UDC devices that can be used to enable the gadget can be found using ls /sys/class/udc/.

After the execution of these commands, the '/dev/ttyGS0' appears on the target. On the host side, the device is enumerated.

$ dmesg
...
[349700.188862] usb 3-4.4.3: new high-speed USB device number 64 using xhci_hcd
[349700.266456] usb 3-4.4.3: New USB device found, idVendor=abcd, idProduct=1234, bcdDevice= 5.17
[349700.266468] usb 3-4.4.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[349700.266471] usb 3-4.4.3: Product: LAN966x
[349700.266474] usb 3-4.4.3: Manufacturer: Microchip
[349700.266476] usb 3-4.4.3: SerialNumber: SN000000
[349700.273296] cdc_acm 3-4.4.3:1.0: ttyACM0: USB ACM device
...

Attach a shell to the USB serial device.

At startup a shell can be attached to the USB serial device. This can be done adding the following line in /etc/inittab

ttyGS0::respawn:/sbin/getty -L  ttyGS0 0 vt100

or any other configuration settings depending on your init system (busybox init, systemd, …​) related to TTY shell configuration.