usb_hub.h 4.2 KB

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