[D18] usb1: add USB DRD support
Add USB DRD support on SoC USB1 interface. Host/Device detection is done by ID pin via usb-role-switch connector.
DRD mode is a reduced functionality OTG mode: in DRD operation, the controller mode (Host/Device) is decided based on the ID pin status. With the ID pin at ground the mode is Host and otherwise it is Device: once a cable plug is attached the controller selects the state and doesn't change it until the cable is unplugged.
* Test details:
root@seco-imx8mp-d18:~# cat /sys/kernel/debug/usb/38100000.dwc3/mode
device
root@seco-imx8mp-d18:~# cat /sys/kernel/debug/gpio | grep -i USB
gpio-10 (USB1_ID_GPIO |id ) in hi IRQ
gpio-12 (USB0_EN_OC#_1V8_OUT_|regulator-usb1-vbus ) out lo
gpio-99 (USB0_VBUS_GPIO )
gpio-115 (USB0_EN_OC_1V8_IN )
root@seco-imx8mp-d18:~# modprobe g_mass_storage iSerialNumber=123456 file=/dev/m mcblk1p1 stall=0 removable=1
[ 145.847608] Mass Storage Function, version: 2009/09/11
[ 145.852770] LUN: removable file: (no medium)
[ 145.857153] LUN: removable file: /dev/mmcblk1p1
[ 145.861712] Number of LUNs=1
[ 145.865014] g_mass_storage gadget: Mass Storage Gadget, version: 2009/09/11
[ 145.872023] g_mass_storage gadget: g_mass_storage ready
root@seco-imx8mp-d18:~# rmmod g_mass_storage
[ 249.908302] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
[ 249.913850] xhci-hcd xhci-hcd.1.auto: new USB bus registered, assigned bus number 3
[ 249.921877] xhci-hcd xhci-hcd.1.auto: hcc params 0x0220fe6c hci version 0x110 quirks 0x0000002001810010
[ 249.931326] xhci-hcd xhci-hcd.1.auto: irq 74, io mem 0x38100000
[ 249.938065] hub 3-0:1.0: USB hub found
[ 249.941879] hub 3-0:1.0: 1 port detected
[ 249.946085] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
[ 249.951631] xhci-hcd xhci-hcd.1.auto: new USB bus registered, assigned bus number 4
[ 249.959332] xhci-hcd xhci-hcd.1.auto: Host supports USB 3.0 SuperSpeed
[ 249.965925] usb usb4: We don't know the algorithms for LPM for this host, disabling LPM.
[ 249.974484] hub 4-0:1.0: USB hub found
[ 249.978275] hub 4-0:1.0: 1 port detected
[ 250.203790] usb 3-1: new high-speed USB device number 2 using xhci-hcd
[ 250.359989] usb-storage 3-1:1.0: USB Mass Storage device detected
[ 250.367004] scsi host0: usb-storage 3-1:1.0
[ 251.393355] scsi 0:0:0:0: Direct-Access SanDisk Cruzer Blade 1.27 PQ: 0 ANSI: 6
[ 251.407656] sd 0:0:0:0: [sda] 31266816 512-byte logical blocks: (16.0 GB/14.9 GiB)
[ 251.416645] sd 0:0:0:0: [sda] Write Protect is off
[ 251.421734] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 251.457705] sda: sda1
[ 251.463757] sd 0:0:0:0: [sda] Attached SCSI removable disk
root@seco-imx8mp-d18:~# cat /sys/kernel/debug/usb/38100000.dwc3/mode
host
root@seco-imx8mp-d18:~# cat /sys/kernel/debug/gpio | grep -i USB
gpio-10 (USB1_ID_GPIO |id ) in lo IRQ
gpio-12 (USB0_EN_OC#_1V8_OUT_|regulator-usb1-vbus ) out hi
gpio-99 (USB0_VBUS_GPIO )
gpio-115 (USB0_EN_OC_1V8_IN )
[ 311.938370] usb 3-1: USB disconnect, device number 2
[ 311.959608] xhci-hcd xhci-hcd.1.auto: remove, state 4
[ 311.964718] usb usb4: USB disconnect, device number 1
[ 311.970368] xhci-hcd xhci-hcd.1.auto: USB bus 4 deregistered
[ 311.976158] xhci-hcd xhci-hcd.1.auto: remove, state 1
[ 311.981472] usb usb3: USB disconnect, device number 1
[ 312.030136] xhci-hcd xhci-hcd.1.auto: USB bus 3 deregistered
root@seco-imx8mp-d18:~# cat /sys/kernel/debug/usb/38100000.dwc3/mode
device
root@seco-imx8mp-d18:~# cat /sys/kernel/debug/gpio | grep -i USB
gpio-10 (USB1_ID_GPIO |id ) in hi IRQ
gpio-12 (USB0_EN_OC#_1V8_OUT_|regulator-usb1-vbus ) out lo
gpio-99 (USB0_VBUS_GPIO )
gpio-115 (USB0_EN_OC_1V8_IN )
Edited by Gianfranco Mariotti