I am trying to understand how devices are communicating over USB in linux, specifically for mobile android devices, so I can connect a DIY project to my phone via USB. After doing some search, I only found some general explanations of USB drivers specific for certain devices.

I would like to know a few things:

  1. how can I find for a specific device connected to a mobile device which driver is used? Where can I find it's code?
  2. how does the USB stack looks like? Couldn't find a good documentation.
  3. How can I develop drivers for USB devices? (Again, for android)
  4. how can I embed these drivers into the kernel or load them dynamically on my phone?


1 Answer 1


Partial answer: USB drivers generally are kernel modules that are loaded for specific USB devices by looking at vendor/device id's and other patterns embedded into the module. You can find this information for existing drivers with modinfo, e.g.

$ sudo modinfo usbhid
filename:       /lib/modules/4.12.13/kernel/drivers/hid/usbhid/usbhid.ko
license:        GPL
description:    USB HID core driver
author:         Jiri Kosina
author:         Vojtech Pavlik
author:         Andreas Gal
alias:          usb:v*p*d*dc*dsc*dp*ic03isc*ip*in*
depends:        hid,usbcore
intree:         Y
vermagic:       4.12.13 SMP preempt mod_unload modversions 686 
parm:           mousepoll:Polling interval of mice (uint)
parm:           jspoll:Polling interval of joysticks (uint)
parm:           ignoreled:Autosuspend with active leds (uint)
parm:           quirks:Add/modify USB HID quirks by specifying  
quirks=vendorID:productID:quirks where vendorID, productID, and quirks are all in 0x-prefixed hex (array of charp)

There are also various tools that can show for an existing device which driver is in use. I believe these all end up using the information from the /sys hierarchy eventually.

So if you want to write a new driver, you need to learn how to write a kernel module (google, there are tutorials). Pick an existing driver and modify it.

You can also write "drivers" (or rather appliation programs) in user space with a library like libusb.

The kernel documentation also includes information about the USB API, and by extension, information how the USB stack works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.