Skip to content
Advertisement

How to detect when a usb cable is connected/disconnected on the device side in Linux 2.6.37?

I have a embedded device that runs linux 2.6.37.

I want my application to know when the USB is connected.

Currently I can achieve this by pooling /sys/devices/platform/musb/musb-hdrc.0/vbus.

However this approach does not distinguish between a USB charger or a USB host.

I found this udev approach but I don’t think it’s available in my version of the kernel. because I did not find any USB related nodes in my /dev. This discussing also shows that it might not be feasible, ether.

I also found linux hotplug and tried the netlink example, but I didn’t see any output running the example when I connect/disconnect the USB cable.

What I want to do is to detect connection type on the device, when USB is connected, and prepare (unmount file system) and switch to g_file_storage if device is connected to a host, and do nothing if device is connect to a charger.

How shall I achieve this?

Advertisement

Answer

On 2.6.37 kernel, this could be done by polling

/sys/devices/platform/musb-omap2430.0/musb-hdrc.0/mode

If handshake with host is successful then it will read as “peripheral”, if fail it’ll be “idle”.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement