UDM-usb.txt 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. The U-Boot Driver Model Project
  2. ===============================
  3. USB analysis
  4. ============
  5. Marek Vasut <marek.vasut@gmail.com>
  6. 2012-02-16
  7. I) Overview
  8. -----------
  9. 1) The USB Host driver
  10. ----------------------
  11. There are basically four or five USB host drivers. All such drivers currently
  12. provide at least the following fuctions:
  13. usb_lowlevel_init() ... Do the initialization of the USB controller hardware
  14. usb_lowlevel_stop() ... Do the shutdown of the USB controller hardware
  15. usb_event_poll() ...... Poll interrupt from USB device, often used by KBD
  16. submit_control_msg() .. Submit message via Control endpoint
  17. submit_int_msg() ...... Submit message via Interrupt endpoint
  18. submit_bulk_msg() ..... Submit message via Bulk endpoint
  19. This allows for the host driver to be easily abstracted.
  20. 2) The USB hierarchy
  21. --------------------
  22. In the current implementation, the USB Host driver provides operations to
  23. communicate via the USB bus. This is realised by providing access to a USB
  24. root port to which an USB root hub is attached. The USB bus is scanned and for
  25. each newly found device, a struct usb_device is allocated. See common/usb.c
  26. and include/usb.h for details.
  27. II) Approach
  28. ------------
  29. 1) The USB Host driver
  30. ----------------------
  31. Converting the host driver will follow the classic driver model consideration.
  32. Though, the host driver will have to call a function that registers a root
  33. port with the USB core in it's probe() function, let's call this function
  34. usb_register_root_port(&ops);
  35. This will allow the USB core to track all available root ports. The ops
  36. parameter will contain structure describing operations supported by the root
  37. port:
  38. struct usb_port_ops {
  39. void (*usb_event_poll)();
  40. int (*submit_control_msg)();
  41. int (*submit_int_msg)();
  42. int (*submit_bulk_msg)();
  43. }
  44. 2) The USB hierarchy and hub drivers
  45. ------------------------------------
  46. Converting the USB heirarchy should be fairy simple, considering the already
  47. dynamic nature of the implementation. The current usb_hub_device structure
  48. will have to be converted to a struct instance. Every such instance will
  49. contain components of struct usb_device and struct usb_hub_device in it's
  50. private data, providing only accessors in order to properly encapsulate the
  51. driver.
  52. By registering the root port, the USB framework will instantiate a USB hub
  53. driver, which is always present, the root hub. The root hub and any subsequent
  54. hub instance is represented by struct instance and it's private data contain
  55. amongst others common bits from struct usb_device.
  56. Note the USB hub driver is partly defying the usual method of registering a
  57. set of callbacks to a particular core driver. Instead, a static set of
  58. functions is defined and the USB hub instance is passed to those. This creates
  59. certain restrictions as of how the USB hub driver looks, but considering the
  60. specification for USB hub is given and a different type of USB hub won't ever
  61. exist, this approach is ok:
  62. - Report how many ports does this hub have:
  63. uint get_nr_ports(struct instance *hub);
  64. - Get pointer to device connected to a port:
  65. struct instance *(*get_child)(struct instance *hub, int port);
  66. - Instantiate and configure device on port:
  67. struct instance *(*enum_dev_on_port)(struct instance *hub, int port);
  68. 3) USB device drivers
  69. ---------------------
  70. The USB device driver, in turn, will have to register various ops structures
  71. with certain cores. For example, USB disc driver will have to register it's
  72. ops with core handling USB discs etc.