R-Car/Change-probing-timing-of-USB-2-function-driver

From eLinux.org
Jump to: navigation, search

Overview

Until v5.12, if we use the USB 2.0 function (renesas_usbhs) and USB 3.0 function (renesas_usb3) drivers as built-in, the HS-USB channel 0 on r8a77951-salvator-xs was probed at first like the following.

# dmesg | grep -e e659 -e ee02
[    3.013125] renesas_usbhs e6590000.usb: host probed
[    3.018118] renesas_usbhs e6590000.usb: no transceiver found
[    3.024441] renesas_usbhs e6590000.usb: gadget probed
[    3.029885] renesas_usbhs e6590000.usb: probed
[    3.035699] renesas_usbhs e659c000.usb: host probed
[    3.040751] renesas_usbhs e659c000.usb: no transceiver found
[    3.046848] renesas_usbhs e659c000.usb: gadget probed
[    3.052308] renesas_usbhs e659c000.usb: probed
[    3.059663] renesas_usb3 ee020000.usb: probed with phy

However, from v5.13-rc1, the HS-USB channel 3 was probed at first. Second, the USB 3.0 peripheral was probed, and then the HS-USB channel 0 was probed finally:

# dmesg | grep -e e65 -e 9 -e  -e ee02
[    3.150070] renesas_usbhs e659c000.usb: host probed
[    3.155062] renesas_usbhs e659c000.usb: no transceiver found
[    3.161374] renesas_usbhs e659c000.usb: gadget probed
[    3.166794] renesas_usbhs e659c000.usb: probed
[    3.173950] renesas_usb3 ee020000.usb: probed with phy
[    4.010558] renesas_usbhs e6590000.usb: host probed
[    4.015548] renesas_usbhs e6590000.usb: no transceiver found
[    4.021870] renesas_usbhs e6590000.usb: gadget probed
[    4.027315] renesas_usbhs e6590000.usb: probed

So, if we use a "USB Gadget precomposed configrations" driver like g_mass_storage on v5.13-rc1, a gadget driver will bind the HS-USB channel 3 at first.

How to use the HS-USB channel 0 on v5.13-rc1?

We have some solutions to use it like below:

  • Unbind other UDC instances at first
  • Use kernel modules of renesas_usbhs and renesas_usb3 drivers instead
  • Use "USB Gadget functions configurable through configfs" instead
  • Use fw_devlink=permissive

Unbind other UDC instances at first

# e659c000.usb > /sys/bus/platform/drivers/renesas_usbhs/unbind
# ee020000.usb > /sys/bus/platform/drivers/renesas_usb3/unbind
# modprobe <gadget driver>

Use kernel modules of renesas_usbhs and renesas_usb3 drivers instead

In kernel config,

CONFIG_USB_RENESAS_USBHS=m
CONFIG_USB_RENESAS_USBHS_UDC=m
CONFIG_USB_RENESAS_USB3=m

and we input the following on the board:

# modprobe renesas_usbhs
# modprobe <gadget driver>

Use "USB Gadget functions configurable through configfs" instead

This is an example how to use HS-USB channel 0 acts as a mass storage device.

# modprobe libcomposite
# mkdir /dev/shm/config
# mount -t configfs none /dev/shm/config
# mkdir /dev/shm/config/usb_gadget/g1
# cd /dev/shm/config/usb_gadget/g1

# echo <your vendor id> > idVendor
# echo <your product id> > idProduct

# mkdir strings/0x409
# echo <your serial number string> > strings/0x409/serialnumber
# echo <your manufacturer string> > strings/0x409/manufacturer
# echo <your products string> > strings/0x409/product

# mkdir configs/c.1
# mkdir configs/c.1/strings/0x409

# dd if=/dev/zero of=/dev/shm/storage.bin bs=1M count=350
# modprobe usb_f_mass_storage
# mkdir functions/mass_storage.usb0
# echo /dev/shm/storage.bin > functions/mass_storage.usb0/lun.0/file

# ln -s functions/mass_storage.usb0 configs/c.1/
# echo e6590000.usb > UDC

Use fw_devlink=permissive

This kernel parameter will act like v5.12.


Why was the behavior change from v5.13-rc1?

This is related to 2 things:

  • Board specification of the Salvator-XS
  • Kernel parameter "fw_devlink"

The usb2_phy0 node has vbus-supply property. However, other nodes of usb[23]_phy* don't have vbus-supply property. And, the following commit is applied on v5.13-rc1.

ea718c699055 Revert "Revert "driver core: Set fw_devlink=on by default""

So, creating devlinks differs between fw_devlink=on (v5.13-rc1) and fw_devlink=permissive (v5.12) like below.

fw_devlink=on

# cd /sys/class/devlink
ls | grep usb
phy:phy-e65ee000.usb-phy.12--platform:ee020000.usb
phy:phy-ee080200.usb-phy.14--platform:ee080000.usb
phy:phy-ee080200.usb-phy.15--platform:ee080100.usb
phy:phy-ee0a0200.usb-phy.1--platform:ee0a0000.usb
phy:phy-ee0a0200.usb-phy.2--platform:ee0a0100.usb
phy:phy-ee0c0200.usb-phy.5--platform:ee0c0000.usb
phy:phy-ee0c0200.usb-phy.6--platform:ee0c0100.usb
phy:phy-ee0e0200.usb-phy.10--platform:ee0e0100.usb
phy:phy-ee0e0200.usb-phy.9--platform:ee0e0000.usb
platform:e6055400.gpio--platform:regulator-vbus0-usb2
platform:e6060000.pinctrl--platform:ee000000.usb
platform:e6060000.pinctrl--platform:ee080200.usb-phy
platform:e6060000.pinctrl--platform:ee0a0200.usb-phy
platform:e6060000.pinctrl--platform:ee0c0200.usb-phy
platform:e6060000.pinctrl--platform:ee0e0200.usb-phy
platform:e6150000.clock-controller--platform:e6590000.usb
platform:e6150000.clock-controller--platform:e659c000.usb
platform:e6150000.clock-controller--platform:e65ee000.usb-phy
platform:e6150000.clock-controller--platform:ee000000.usb
platform:e6150000.clock-controller--platform:ee020000.usb
platform:e6150000.clock-controller--platform:ee080000.usb
platform:e6150000.clock-controller--platform:ee080100.usb
platform:e6150000.clock-controller--platform:ee080200.usb-phy
platform:e6150000.clock-controller--platform:ee0a0000.usb
platform:e6150000.clock-controller--platform:ee0a0100.usb
platform:e6150000.clock-controller--platform:ee0a0200.usb-phy
platform:e6150000.clock-controller--platform:ee0c0000.usb
platform:e6150000.clock-controller--platform:ee0c0100.usb
platform:e6150000.clock-controller--platform:ee0c0200.usb-phy
platform:e6150000.clock-controller--platform:ee0e0000.usb
platform:e6150000.clock-controller--platform:ee0e0100.usb
platform:e6150000.clock-controller--platform:ee0e0200.usb-phy
platform:e65ee000.usb-phy--platform:ee020000.usb
platform:ee080200.usb-phy--platform:e6590000.usb
platform:ee080200.usb-phy--platform:ee080000.usb
platform:ee080200.usb-phy--platform:ee080100.usb
platform:ee0a0200.usb-phy--platform:ee0a0000.usb
platform:ee0a0200.usb-phy--platform:ee0a0100.usb
platform:ee0c0200.usb-phy--platform:ee0c0000.usb
platform:ee0c0200.usb-phy--platform:ee0c0100.usb
platform:ee0e0200.usb-phy--platform:e659c000.usb
platform:ee0e0200.usb-phy--platform:ee0e0000.usb
platform:ee0e0200.usb-phy--platform:ee0e0100.usb
platform:regulator-vbus0-usb2--platform:ee080200.usb-phy
regulator:regulator.4--platform:ee080200.usb-phy

fw_devlink=permissive

phy:phy-e65ee000.usb-phy.12--platform:ee020000.usb
phy:phy-ee080200.usb-phy.14--platform:ee080000.usb
phy:phy-ee080200.usb-phy.15--platform:ee080100.usb
phy:phy-ee0a0200.usb-phy.1--platform:ee0a0000.usb
phy:phy-ee0a0200.usb-phy.2--platform:ee0a0100.usb
phy:phy-ee0c0200.usb-phy.5--platform:ee0c0000.usb
phy:phy-ee0c0200.usb-phy.6--platform:ee0c0100.usb
phy:phy-ee0e0200.usb-phy.10--platform:ee0e0100.usb
phy:phy-ee0e0200.usb-phy.9--platform:ee0e0000.usb
platform:e6060000.pinctrl--platform:ee000000.usb
platform:e6150000.clock-controller--platform:ee000000.usb
regulator:regulator.4--platform:ee080200.usb-phy