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

cancel
Showing results for 
Search instead for 
Did you mean: 

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

1,248 Views
wooosaiiii
Contributor III

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

Labels (4)
0 Kudos
3 Replies

245 Views
miguelhortelano
Contributor II

Although it's been some time since you posted this question, from userspace you can read.

 /sys/bus/platform/drivers/ci_hdrc/ci_hdrc.0/power/runtime_status

or the same from here:

         /sys/devices/soc0/soc/2100000.aips-bus/2184000.usb/power/runtime_status

If USB cable is plugged/unplugged you'll read active/suspended.

Regards 

0 Kudos

245 Views
CarlosCasillas
NXP Employee
NXP Employee

Hi Primoz,

You could take a look at USB erratas of i.MX6, which are related to suspend/resume issues:

http://www.nxp.com/files/32bit/doc/errata/IMX6DQCE.pdf

Hope this will be useful for you.
Best regards!
/Carlos
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

245 Views
wooosaiiii
Contributor III

Hello,

here is a quick update on how USB device port is actually wired to SoC:

USB_device.jpg

As you can see I have just D+ and D- routed to my SoC, while +5V (from host) is basically just wired to capacitor and then to the GND.

VBUS sensing/detection over extcon framework is probably not possible with such configuration...?

Any other ideas?

Primoz

0 Kudos