usb_hub.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * @file
  3. * @brief USB HUB Device Class public header
  4. *
  5. */
  6. #ifndef _USB_HUB_H_
  7. #define _USB_HUB_H_
  8. /* HUB Class Descriptor Types */
  9. #define HUB_DESCRIPTOR_TYPE_HUB 0x29
  10. /* Hub class requests */
  11. #define HUB_REQUEST_GET_STATUS USB_REQUEST_GET_STATUS
  12. #define HUB_REQUEST_CLEAR_FEATURE USB_REQUEST_CLEAR_FEATURE
  13. #define HUB_REQUEST_SET_FEATURE USB_REQUEST_SET_FEATURE
  14. #define HUB_REQUEST_GET_DESCRIPTOR USB_REQUEST_GET_DESCRIPTOR
  15. #define HUB_REQUEST_SET_DESCRIPTOR USB_REQUEST_SET_DESCRIPTOR
  16. #define HUB_REQUEST_CLEAR_TT_BUFFER (0x08)
  17. #define HUB_REQUEST_RESET_TT (0x09)
  18. #define HUB_REQUEST_GET_TT_STATE (0x0a)
  19. #define HUB_REQUEST_STOP_TT (0x0b)
  20. /* Hub class features */
  21. #define HUB_FEATURE_HUB_C_LOCALPOWER (0x0)
  22. #define HUB_FEATURE_HUB_C_OVERCURRENT (0x1)
  23. /* Port features */
  24. #define HUB_PORT_FEATURE_CONNECTION (0x00)
  25. #define HUB_PORT_FEATURE_ENABLE (0x01)
  26. #define HUB_PORT_FEATURE_SUSPEND (0x02)
  27. #define HUB_PORT_FEATURE_OVERCURRENT (0x03)
  28. #define HUB_PORT_FEATURE_RESET (0x04)
  29. #define HUB_PORT_FEATURE_L1 (0x05)
  30. #define HUB_PORT_FEATURE_POWER (0x08)
  31. #define HUB_PORT_FEATURE_LOWSPEED (0x09)
  32. #define HUB_PORT_FEATURE_HIGHSPEED (0x0a)
  33. #define HUB_PORT_FEATURE_C_CONNECTION (0x10)
  34. #define HUB_PORT_FEATURE_C_ENABLE (0x11)
  35. #define HUB_PORT_FEATURE_C_SUSPEND (0x12)
  36. #define HUB_PORT_FEATURE_C_OVER_CURREN (0x13)
  37. #define HUB_PORT_FEATURE_C_RESET (0x14)
  38. #define HUB_PORT_FEATURE_TEST (0x15)
  39. #define HUB_PORT_FEATURE_INDICATOR (0x16)
  40. #define HUB_PORT_FEATURE_C_PORTL1 (0x17)
  41. /* Hub status */
  42. #define HUB_STATUS_LOCALPOWER (1 << 0)
  43. #define HUB_STATUS_OVERCURRENT (1 << 1)
  44. /* Hub status change */
  45. #define HUB_STATUS_C_LOCALPOWER (1 << 0)
  46. #define HUB_STATUS_C_OVERCURRENT (1 << 1)
  47. /* Hub port status */
  48. #define HUB_PORT_STATUS_CONNECTION (1 << 0)
  49. #define HUB_PORT_STATUS_ENABLE (1 << 1)
  50. #define HUB_PORT_STATUS_SUSPEND (1 << 2)
  51. #define HUB_PORT_STATUS_OVERCURRENT (1 << 3)
  52. #define HUB_PORT_STATUS_RESET (1 << 4)
  53. #define HUB_PORT_STATUS_L1 (1 << 5)
  54. #define HUB_PORT_STATUS_POWER (1 << 8)
  55. #define HUB_PORT_STATUS_LOW_SPEED (1 << 9)
  56. #define HUB_PORT_STATUS_HIGH_SPEED (1 << 10)
  57. #define HUB_PORT_STATUS_TEST (1 << 11)
  58. #define HUB_PORT_STATUS_INDICATOR (1 << 12)
  59. /* Hub port status change */
  60. #define HUB_PORT_STATUS_C_CONNECTION (1 << 0)
  61. #define HUB_PORT_STATUS_C_ENABLE (1 << 1)
  62. #define HUB_PORT_STATUS_C_SUSPEND (1 << 2)
  63. #define HUB_PORT_STATUS_C_OVERCURRENT (1 << 3)
  64. #define HUB_PORT_STATUS_C_RESET (1 << 4)
  65. #define HUB_PORT_STATUS_C_L1 (1 << 5)
  66. /* Hub characteristics */
  67. #define HUB_CHAR_LPSM_SHIFT (0) /* Bits 0-1: Logical Power Switching Mode */
  68. #define HUB_CHAR_LPSM_MASK (3 << HUB_CHAR_LPSM_SHIFT)
  69. #define HUB_CHAR_LPSM_GANGED (0 << HUB_CHAR_LPSM_SHIFT)
  70. #define HUB_CHAR_LPSM_INDIVIDUAL (1 << HUB_CHAR_LPSM_SHIFT)
  71. #define HUB_CHAR_COMPOUND (1 << 2) /* Bit 2: Compound device */
  72. #define HUB_CHAR_OCPM_SHIFT (3) /* Bits 3-4: Over-current Protection Mode */
  73. #define HUB_CHAR_OCPM_MASK (3 << HUB_CHAR_OCPM_SHIFT)
  74. #define HUB_CHAR_OCPM_GLOBAL (0 << HUB_CHAR_OCPM_SHIFT)
  75. #define HUB_CHAR_OCPM_INDIVIDUAL (1 << HUB_CHAR_OCPM_SHIFT)
  76. #define HUB_CHAR_TTTT_SHIFT (5) /* Bits 5-6: TT Think Time */
  77. #define HUB_CHAR_TTTT_MASK (3 << HUB_CHAR_TTTT_SHIFT)
  78. #define HUB_CHAR_TTTT_8_BITS (0 << HUB_CHAR_TTTT_SHIFT)
  79. #define HUB_CHAR_TTTT_16_BITS (1 << HUB_CHAR_TTTT_SHIFT)
  80. #define HUB_CHAR_TTTT_24_BITS (2 << HUB_CHAR_TTTT_SHIFT)
  81. #define HUB_CHAR_TTTT_32_BITS (3 << HUB_CHAR_TTTT_SHIFT)
  82. #define HUB_CHAR_PORTIND (1 << 7) /* Bit 7: Port Indicators Supported */
  83. /* Hub descriptor */
  84. struct usb_hub_descriptor {
  85. uint8_t bLength;
  86. uint8_t bDescriptorType;
  87. uint8_t bNbrPorts;
  88. uint16_t wHubCharacteristics;
  89. uint8_t bPwrOn2PwrGood;
  90. uint8_t bHubContrCurrent;
  91. uint8_t DeviceRemovable;
  92. uint8_t PortPwrCtrlMask;
  93. } __PACKED;
  94. #define USB_SIZEOF_HUB_DESC 9
  95. /* Hub status */
  96. struct hub_status {
  97. uint16_t wPortStatus;
  98. uint16_t wPortChange;
  99. };
  100. /* Hub port status */
  101. struct hub_port_status {
  102. uint16_t wPortStatus;
  103. uint16_t wPortChange;
  104. };
  105. #endif /* _USB_HUB_H_ */