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


i have embedded device runs linux 2.6.37.

i want application know when usb connected.

currently can achieve pooling /sys/devices/platform/musb/musb-hdrc.0/vbus.

however approach not distinguish between usb charger or usb host.

i found udev approach don't think it's available in version of kernel. because did not find usb related nodes in /dev. this discussing shows might not feasible, ether.

i found linux hotplug , tried netlink example, didn't see output running example when connect/disconnect usb cable.

what want detect connection type on device, when usb connected, , prepare (unmount file system) , switch g_file_storage if device connected host, , nothing if device connect charger.

how shall achieve this?

to achieve that, can use inotify(7) feature, available in linux kernels awaken device node gets created in /sys.

to know type of device have, have read usb info proper usb ioctl call (or if not kernel interface expert, using libusb interface) device vendor, device id , device class fields coming device. normally, hotplug software gets informed on these clase of events (via special socket). reason don't device initialized misconfiguration in config files udev system, has 1 entry each possible device vendor/device id pair , allows load appropiate device driver control it. process continues device driver module creating dynamically actual devices, , they'll appear in /dev/ filesystem consequence of other kernel event udevd.

read apropiate documents in <linux_src>/documentation (this directory directory belongs linux kernel source code, you'll need install it), , udevd(8) man pages able add new usb.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -