hub.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /************************************************************************************
  2. * include/nuttx/usb/hub.h
  3. *
  4. * Copyright (C) 2015 Gregory Nutt. All rights reserved.
  5. * Author: Kaushal Parikh <kaushal@dspworks.in>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ************************************************************************************/
  35. #ifndef __INCLUDE_NUTTX_USB_HUB_H
  36. #define __INCLUDE_NUTTX_USB_HUB_H
  37. /************************************************************************************
  38. * Included Files
  39. ************************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <stdint.h>
  42. /************************************************************************************
  43. * Pre-processor Definitions
  44. ************************************************************************************/
  45. /* Hub request types */
  46. #define USBHUB_REQ_TYPE_HUB (USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_DEVICE)
  47. #define USBHUB_REQ_TYPE_PORT (USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_OTHER)
  48. /* Hub class requests */
  49. #define USBHUB_REQ_GETSTATUS USB_REQ_GETSTATUS
  50. #define USBHUB_REQ_CLEARFEATURE USB_REQ_CLEARFEATURE
  51. #define USBHUB_REQ_SETFEATURE USB_REQ_SETFEATURE
  52. #define USBHUB_REQ_GETDESCRIPTOR USB_REQ_GETDESCRIPTOR
  53. #define USBHUB_REQ_SETDESCRIPTOR USB_REQ_SETDESCRIPTOR
  54. #define USBHUB_REQ_CLEARTTBUFFER (0x08)
  55. #define USBHUB_REQ_RESETTT (0x09)
  56. #define USBHUB_REQ_GETTTSTATE (0x0a)
  57. #define USBHUB_REQ_STOPTT (0x0b)
  58. /* Hub class features */
  59. #define USBHUB_FEAT_CHUBLOCALPOWER (0x0)
  60. #define USBHUB_FEAT_CHUBOVERCURRENT (0x1)
  61. /* Port features */
  62. #define USBHUB_PORT_FEAT_CONNECTION (0x00)
  63. #define USBHUB_PORT_FEAT_ENABLE (0x01)
  64. #define USBHUB_PORT_FEAT_SUSPEND (0x02)
  65. #define USBHUB_PORT_FEAT_OVERCURRENT (0x03)
  66. #define USBHUB_PORT_FEAT_RESET (0x04)
  67. #define USBHUB_PORT_FEAT_L1 (0x05)
  68. #define USBHUB_PORT_FEAT_POWER (0x08)
  69. #define USBHUB_PORT_FEAT_LOWSPEED (0x09)
  70. #define USBHUB_PORT_FEAT_HIGHSPEED (0x0a)
  71. #define USBHUB_PORT_FEAT_CCONNECTION (0x10)
  72. #define USBHUB_PORT_FEAT_CENABLE (0x11)
  73. #define USBHUB_PORT_FEAT_CSUSPEND (0x12)
  74. #define USBHUB_PORT_FEAT_COVER_CURRENT (0x13)
  75. #define USBHUB_PORT_FEAT_CRESET (0x14)
  76. #define USBHUB_PORT_FEAT_TEST (0x15)
  77. #define USBHUB_PORT_FEAT_INDICATOR (0x16)
  78. #define USBHUB_PORT_FEAT_CPORTL1 (0x17)
  79. /* Hub characteristics */
  80. #define USBHUB_CHAR_LPSM_SHIFT (0) /* Bits 0-1: Logical Power Switching Mode */
  81. #define USBHUB_CHAR_LPSM_MASK (3 << USBHUB_CHAR_LPSM_SHIFT)
  82. # define USBHUB_CHAR_LPSM_GANGED (0 << USBHUB_CHAR_LPSM_SHIFT)
  83. # define USBHUB_CHAR_LPSM_INDIVIDUAL (1 << USBHUB_CHAR_LPSM_SHIFT)
  84. #define USBHUB_CHAR_COMPOUND (1 << 2) /* Bit 2: Compound device */
  85. #define USBHUB_CHAR_OCPM_SHIFT (3) /* Bits 3-4: Over-current Protection Mode */
  86. #define USBHUB_CHAR_OCPM_MASK (3 << USBHUB_CHAR_OCPM_SHIFT)
  87. # define USBHUB_CHAR_OCPM_GLOBAL (0 << USBHUB_CHAR_OCPM_SHIFT)
  88. # define USBHUB_CHAR_OCPM_INDIVIDUAL (1 << USBHUB_CHAR_OCPM_SHIFT)
  89. #define USBHUB_CHAR_TTTT_SHIFT (5) /* Bits 5-6: TT Think Time */
  90. #define USBHUB_CHAR_TTTT_MASK (3 << USBHUB_CHAR_TTTT_SHIFT)
  91. # define USBHUB_CHAR_TTTT_8_BITS (0 << USBHUB_CHAR_TTTT_SHIFT)
  92. # define USBHUB_CHAR_TTTT_16_BITS (1 << USBHUB_CHAR_TTTT_SHIFT)
  93. # define USBHUB_CHAR_TTTT_24_BITS (2 << USBHUB_CHAR_TTTT_SHIFT)
  94. # define USBHUB_CHAR_TTTT_32_BITS (3 << USBHUB_CHAR_TTTT_SHIFT)
  95. #define USBHUB_CHAR_PORTIND (1 << 7) /* Bit 7: Port Indicators Supported */
  96. /* Hub status */
  97. #define USBHUB_STAT_LOCALPOWER (1 << 0)
  98. #define USBHUB_STAT_OVERCURRENT (1 << 1)
  99. /* Hub status change */
  100. #define USBHUB_STAT_CLOCALPOWER (1 << 0)
  101. #define USBHUB_STAT_COVERCURRENT (1 << 1)
  102. /* Hub port status */
  103. #define USBHUB_PORT_STAT_CONNECTION (1 << 0)
  104. #define USBHUB_PORT_STAT_ENABLE (1 << 1)
  105. #define USBHUB_PORT_STAT_SUSPEND (1 << 2)
  106. #define USBHUB_PORT_STAT_OVERCURRENT (1 << 3)
  107. #define USBHUB_PORT_STAT_RESET (1 << 4)
  108. #define USBHUB_PORT_STAT_L1 (1 << 5)
  109. #define USBHUB_PORT_STAT_POWER (1 << 8)
  110. #define USBHUB_PORT_STAT_LOW_SPEED (1 << 9)
  111. #define USBHUB_PORT_STAT_HIGH_SPEED (1 << 10)
  112. #define USBHUB_PORT_STAT_TEST (1 << 11)
  113. #define USBHUB_PORT_STAT_INDICATOR (1 << 12)
  114. /* Hub port status change */
  115. #define USBHUB_PORT_STAT_CCONNECTION (1 << 0)
  116. #define USBHUB_PORT_STAT_CENABLE (1 << 1)
  117. #define USBHUB_PORT_STAT_CSUSPEND (1 << 2)
  118. #define USBHUB_PORT_STAT_COVERCURRENT (1 << 3)
  119. #define USBHUB_PORT_STAT_CRESET (1 << 4)
  120. #define USBHUB_PORT_STAT_CL1 (1 << 5)
  121. /* Hub descriptor type */
  122. #define USB_DESC_TYPE_HUB (USB_REQ_TYPE_CLASS | USB_CLASS_HUB)
  123. /* Hub max ports */
  124. #define USBHUB_MAX_PORTS (7)
  125. /************************************************************************************
  126. * Public Types
  127. ************************************************************************************/
  128. /* Hub descriptor */
  129. struct usb_hubdesc_s
  130. {
  131. uint8_t len;
  132. uint8_t type;
  133. uint8_t nports;
  134. uint8_t characteristics[2];
  135. uint8_t pwrondelay;
  136. uint8_t ctrlcurrent;
  137. uint8_t devattached;
  138. uint8_t pwrctrlmask;
  139. };
  140. #define USB_SIZEOF_HUBDESC 9
  141. /* Hub status */
  142. struct usb_hubstatus_s
  143. {
  144. uint8_t status[2];
  145. uint8_t change[2];
  146. };
  147. #define USB_SIZEOF_HUBSTS 4
  148. /* Hub port status */
  149. struct usb_portstatus_s
  150. {
  151. uint8_t status[2];
  152. uint8_t change[2];
  153. };
  154. #define USB_SIZEOF_PORTSTS 4
  155. /* Hub transaction translator */
  156. struct usb_hubtt_s
  157. {
  158. /* Hub class that is the transaction translator for device */
  159. FAR struct usbhost_class_s *class;
  160. /* Transaction translator think time */
  161. uint16_t thinktime;
  162. };
  163. #endif /* __INCLUDE_NUTTX_USB_HUB_H */