5

I'd like to know, which part of the system is responsible for detection of plugged-in device in the USB port

It may be a USB host port, so that a plugged-in device will be considered a USB client (so port owner is host),
or it may be a USB client port, so that a plugged-in device will be considered a USB host (so port owner is client)

What I am interested in is a moment WHEN the system actually detects (by change of resistance maybe) that something has been plugged in, and based on from which port the signal is coming (host port or client port), either host port driver or client port driver is deployed
I want to know, HOW system picks up this or that driver, based on that "plugged-in" event

Where should I look for that ? In USB core maybe ?

3
  • 1
    "It may be a USB host port ... or it may be a USB client port" - A USB will either be a host port OR a device (aka gadget) port. The port is hardwired to be only one kind. You don't get to choose how to use a USB port. Systems that have both types of USB ports are rare, such as on SoC evaluation boards. You might find both host and device USB ports on a SoC, but when installed on a board for a real product, typically only one type of USB port is actually available.
    – sawdust
    Oct 22, 2012 at 19:40
  • Yes, sorry for confusion, I meant that "there may be a USB host port(s) or a USB gadget port(s) or both, on the system", I didn't mean that they may change their host-client roles
    – mangusta
    Oct 23, 2012 at 12:55
  • Android devices which are host-capable typically determine their mode by the state of the extra pin on the connected micro/mini USB cable. Typically to use such a device as a host, you need an adapter cable with that pin grounded on the mini/micro end, and a USB "A" socket on other end, to which a normal USB device cable can be connected. As already mentioned, this along with the detection of presence within either mode, will all go through the Linux kernel before it hits Android APIs or fixed-mode drivers, though some built-in functionality such as charge may be out of the kernel's realm. Feb 17, 2014 at 18:23

3 Answers 3

1

I understand what you are asking, and rightly when a usb device is connected then the current fluctuation (across resistors) leads to notification. Then the host (there can be negotiation that who will be host in OTG mode but that also happens after enumeration process).

Enumeration is main process which is most important. USB follows star tier topology and whole system is based on same.

NOTE: It is very important to note that all the transactions of packets are initiated by host. The client is at mercy of host. This is very important in understanding the usb system.

Pls refer: http://www.beyondlogic.org/usbnutshell/usb1.shtml

1
  • Thanks for reply, maybe you could answer to this one as well: do you know when and where the system is set into host/client mode ? for example, in which mode is android device by default ? if it is in client mode, how to change it into host mode ?
    – mangusta
    Oct 23, 2012 at 13:02
1

Hi when android device is connected then it is in client mode (atleast in samsung devices it is) and when the device is connected then at first the address of the device is set to 0x0 so that the default address is known by the host. Then there is endpoint 0 through which all the setup is done (configuration, interface, endpoints).

enter image description here

The above image will help you to understand. This is taken from USB 2.0 manual. Remember that all the setting during initialization are done through endpoint 0 which is present in every device.

And i dont know how to change it from client to host mode. (My knowledge is limited to that there is negotiation done after setup in OTG mode). I hope i helped.

1
1

The usb subsystem is responsible for detecting and probing newly added/hotplugged USB devices. Look in the kernel logs for messages like:

usb usb4: New USB device found, idVendor=1d6b, idProduct=0001
usb usb4: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb4: Product: OHCI Host Controller
usb usb4: Manufacturer: Linux 2.6.32 ohci_hcd
usb usb4: SerialNumber: 0000:00:12.1
usb usb4: configuration #1 chosen from 1 choice

The code which handles all this is located in drivers/usb/core

The usb subsystem sits below the scsi subsystem and hence your newly allocated devices will have device names like /dev/sdX. Its the job of udev to create a new device node corresponding to this USB device in /dev. If you are interested in capturing this event and running a script that does some notifications you may wanna read up on how to edit udevd rules: http://www.reactivated.net/writing_udev_rules.html#external-run

2
  • thanks for reply. actually i'm not that much interested in udev rules. what i'm interested in, is that USB device detect/probe procedure you've mentioned. so you mean that the usb subsystem monitors all usb host/client ports available on the system and deploys usb host/client drivers correspondingly ? Do you know how and where the system is set into host/client mode ? As far as I understand, the system may simultaneously act as a host in one usb connection, and as a client in another usb connection
    – mangusta
    Oct 19, 2012 at 19:28
  • 2
    "The usb subsystem sits below the scsi subsystem ..." A bogus generalization that does not apply to USB gadgets that are not mass storage devices. There are USB devices for serial ports, Ethernet, keyboards, mice, audio and video. None of these would "have device names like /dev/sdX".
    – sawdust
    Oct 22, 2012 at 19:30

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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