USB Dual Role/OTG on Amlogic S905X

Hello,

I’m trying to configure the USB OTG port in “device” mode.

According to the Device Tree, the DWC3 driver seems to be the one used to control the USB OTG port.

However, it seems to be working only in “host” mode.

After searching the web for a while, I found these two sources, explaining that USB device mode is not available by default, that the DWC3 driver is responsible for the “host” mode and that we have to add a DWC2 driver to support the “device” mode.

http://lists.infradead.org/pipermail/linux-amlogic/2017-July/004321.html

please note that device mode and OTG support on Amlogic Meson GXL is
more complicated, as it uses dwc2 and dwc3 controllers in combination:
- dwc3 is reponsible for host-only mode
- dwc2 is responsible for device-only mode
- OTG detection is done by the USB3 PHY

https://lwn.net/Articles/734837/

The dwc3 controller supports host mode only. Peripheral mode is implemented through an additional dwc2 controller (which only enables device mode). The USB3 PHY has register bits which allow a driver to detect the current mode - however this is currently not implemented as the dwc2 controller seems to hang during reset (and I do not have a use-case where I need peripheral/device mode).

I tried adding a DWC2 driver in the DTS file, however I don’t know how to configure it propertly.

Have you ever faced this issue?

Do you have any ideas about how to configure USB OTG?

Thanks for your help,

Mathieu

Hello @mat77164

@hyphop will help you on this.

which kernel source and version are u using ?
u can get any our krescue or openwrt systems
all of them use usb otg, and check how its works

Hello,

I’m using Amlogic S905X Kernel available here:
https://github.com/150balbes/Amlogic_s905-kernel.git

Custom repository version: v20191120 (1a725d6).
Kernel version 5.3.0

I use Buildroot to generate U-Boot, Kernel and rootfs.

When I mount a debugfs with
$ mount -t debugfs none /d

I go to /d/<dwc3_driver>/, there are some files, one of them is called “mode”.
I tried doing
$ echo "device">mode

but there is a crash, here is the log:

[   48.694235] ------------[ cut here ]------------
[   48.694272] WARNING: CPU: 3 PID: 1478 at kernel/workqueue.c:1444 __queue_work+0x29c/0x3c0
[   48.701328] Modules linked in: dwc3 udc_core meson_gxbb_wdt dwc3_of_simple meson_rng rng_core snd_
 soc_hdmi_codec meson_ir rc_core dw_hdmi_i2s_audio meson_dw_hdmi meson_drm dw_hdmi drm_kms_helper drm
meson_gxl dwmac_meson8b snd_soc_meson_aiu_i2s_dma dwmac_generic stmmac_platform stmmac snd_soc_meson_
 i2s_dai snd_soc_meson_audio_core crct10dif_ce crc32_ce
[   48.732295] CPU: 3 PID: 1478 Comm: sh Not tainted 4.14.55 #3
[   48.737898] Hardware name: Libre Technology CC (DT)
[   48.742728] task: ffff80007cd48000 task.stack: ffff00000baf8000
[...]
[   48.846659] Call trace:
[   48.849076] Exception stack(0xffff00000bafbb10 to 0xffff00000bafbc50)
[...]
<b>[   48.937913] [<ffff0000080e739c>] __queue_work+0x29c/0x3c0</b>
<b>[   48.943261] [<ffff0000080e7520>] queue_work_on+0x60/0x80</b>
<b>[   48.948541] [<ffff000000b7fda8>] dwc3_set_mode+0x48/0x60 [dwc3]</b>
<b>[   48.954400] [<ffff000000b86300>] dwc3_mode_write+0xc0/0x120 [dwc3]</b>
<b>[   48.960513] [<ffff0000083693c0>] full_proxy_write+0x60/0xb0</b>
<b>[   48.966033] [<ffff000008217fac>] __vfs_write+0x1c/0x120</b>
<b>[   48.971206] [<ffff0000082182a4>] vfs_write+0xa4/0x1b0</b>
**[   48.976208] [<ffff000008218554>] SyS_write+0x44/0xa0**
[   48.981123] Exception stack(0xffff00000bafbec0 to 0xffff00000bafc000)
[...]
[   49.065134] [<ffff000008083880>] el0_svc_naked+0x34/0x38
[   49.070392] ---[ end trace daf60cd2937c2f92 ]---

Should I install DWC2 driver to make USB work in “device” mode?

Thanks,

Mathieu

Check my github reps its checked by me I can’t confirm other sources

Or u can use Khadas fenix sources its same works

This one?

https://github.com/hyphop/linux

Have you already tested USB OTG on your kernel version?

all of them repos have workable and tested USB OTG

all system use USB otg ( usb-ethernet and usb-storage ) - u can check how-to from sources

1 Like