AnsweredAssumed Answered

iMX6Q USB in device mode: detect host PC connect/disconnect events

Question asked by Primoz Fiser on Sep 27, 2016
Latest reply on Apr 5, 2018 by Miguel Hortelano

Hello all,

 

SITUATION: We are developing USB device on custom iMX6Q Linux based board (linux-4.1-fslc). Currently we want to use our board as a mass storage device. Loading g_mass_storage module works and host PC is able to access exported secondary disk.

 

PROBLEM: The problem is that before loading g_mass_storage module we need to unmount disk to be later used as an exported file. We want to do this automatically without requiring user input/interaction. 

 

CURRENT PROGRESS: We have tried to use debug options for UDC controller (CHIPIDEA_DEBUG=y) which displays resume/suspend events on dmesg when plug/unplugg-ing USB cable.

Output:

[pluging-in USB cable]

[root@imx6 ~]# dmesg
[ 4106.637189] imx_usb 2184000.usb: at imx_controller_resume
[ 4106.637208] wakeup int at ci_hdrc.0
[ 4106.637225] ci_hdrc ci_hdrc.0: at ci_controller_resume
[ 4109.004585] ci_hdrc ci_hdrc.0: at ci_runtime_suspend
[ 4109.004635] imx_usb 2184000.usb: at imx_controller_suspend

[unpluging USB cable]

[ 4111.910737] imx_usb 2184000.usb: at imx_controller_resume
[ 4111.910753] wakeup int at ci_hdrc.0
[ 4111.910770] ci_hdrc ci_hdrc.0: at ci_controller_resume
[ 4114.004587] ci_hdrc ci_hdrc.0: at ci_runtime_suspend
[ 4114.004632] imx_usb 2184000.usb: at imx_controller_suspend
[root@imx6 ~]#

Also you can see /proc/interrupts increments on such events:

[root@imx6 ~]# cat /proc/interrupts | grep -i 2184000.usb
278:         18          0          0          0       GPC  43 Edge      2184000.usb

[unplugging USB cable]

[root@imx6 ~]# cat /proc/interrupts | grep -i 2184000.usb
278:         21          0          0          0       GPC  43 Edge      2184000.usb
[root@imx6 ~]#

 

But you can actually suppress such events by writing -1 to autosuspend_delay_ms:

echo -1 > /sys/bus/platform/drivers/ci_hdrc/ci_hdrc.0/power/autosuspend_delay_ms

 

QUESTION: How can we detect host PC connect/disconnect events? How to export those events to userspace?

 

We are open for any possible solution whether it is kernelspace (patching kernel) or userspace (daemon)...

 

Thanks,

 

regards!

 

Primoz

Outcomes