usb_defs.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * (C) Copyright 2001
  3. * Denis Peter, MPL AG Switzerland
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. *
  23. * Note: Part of this code has been derived from linux
  24. *
  25. */
  26. #ifndef _USB_DEFS_H_
  27. #define _USB_DEFS_H_
  28. /* Everything is aribtrary */
  29. #define USB_ALTSETTINGALLOC 4
  30. #define USB_MAXALTSETTING 128 /* Hard limit */
  31. #define USB_MAX_DEVICE 32
  32. #define USB_MAXCONFIG 8
  33. #define USB_MAXINTERFACES 8
  34. #define USB_MAXENDPOINTS 16
  35. #define USB_MAXCHILDREN 8 /* This is arbitrary */
  36. #define USB_MAX_HUB 16
  37. #define USB_CNTL_TIMEOUT 100 /* 100ms timeout */
  38. /* USB constants */
  39. /* Device and/or Interface Class codes */
  40. #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
  41. #define USB_CLASS_AUDIO 1
  42. #define USB_CLASS_COMM 2
  43. #define USB_CLASS_HID 3
  44. #define USB_CLASS_PRINTER 7
  45. #define USB_CLASS_MASS_STORAGE 8
  46. #define USB_CLASS_HUB 9
  47. #define USB_CLASS_DATA 10
  48. #define USB_CLASS_VENDOR_SPEC 0xff
  49. /* some HID sub classes */
  50. #define USB_SUB_HID_NONE 0
  51. #define USB_SUB_HID_BOOT 1
  52. /* some UID Protocols */
  53. #define USB_PROT_HID_NONE 0
  54. #define USB_PROT_HID_KEYBOARD 1
  55. #define USB_PROT_HID_MOUSE 2
  56. /* Sub STORAGE Classes */
  57. #define US_SC_RBC 1 /* Typically, flash devices */
  58. #define US_SC_8020 2 /* CD-ROM */
  59. #define US_SC_QIC 3 /* QIC-157 Tapes */
  60. #define US_SC_UFI 4 /* Floppy */
  61. #define US_SC_8070 5 /* Removable media */
  62. #define US_SC_SCSI 6 /* Transparent */
  63. #define US_SC_MIN US_SC_RBC
  64. #define US_SC_MAX US_SC_SCSI
  65. /* STORAGE Protocols */
  66. #define US_PR_CB 1 /* Control/Bulk w/o interrupt */
  67. #define US_PR_CBI 0 /* Control/Bulk/Interrupt */
  68. #define US_PR_BULK 0x50 /* bulk only */
  69. /* USB types */
  70. #define USB_TYPE_STANDARD (0x00 << 5)
  71. #define USB_TYPE_CLASS (0x01 << 5)
  72. #define USB_TYPE_VENDOR (0x02 << 5)
  73. #define USB_TYPE_RESERVED (0x03 << 5)
  74. /* USB recipients */
  75. #define USB_RECIP_DEVICE 0x00
  76. #define USB_RECIP_INTERFACE 0x01
  77. #define USB_RECIP_ENDPOINT 0x02
  78. #define USB_RECIP_OTHER 0x03
  79. /* USB directions */
  80. #define USB_DIR_OUT 0
  81. #define USB_DIR_IN 0x80
  82. /* Descriptor types */
  83. #define USB_DT_DEVICE 0x01
  84. #define USB_DT_CONFIG 0x02
  85. #define USB_DT_STRING 0x03
  86. #define USB_DT_INTERFACE 0x04
  87. #define USB_DT_ENDPOINT 0x05
  88. #define USB_DT_HID (USB_TYPE_CLASS | 0x01)
  89. #define USB_DT_REPORT (USB_TYPE_CLASS | 0x02)
  90. #define USB_DT_PHYSICAL (USB_TYPE_CLASS | 0x03)
  91. #define USB_DT_HUB (USB_TYPE_CLASS | 0x09)
  92. /* Descriptor sizes per descriptor type */
  93. #define USB_DT_DEVICE_SIZE 18
  94. #define USB_DT_CONFIG_SIZE 9
  95. #define USB_DT_INTERFACE_SIZE 9
  96. #define USB_DT_ENDPOINT_SIZE 7
  97. #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
  98. #define USB_DT_HUB_NONVAR_SIZE 7
  99. #define USB_DT_HID_SIZE 9
  100. /* Endpoints */
  101. #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
  102. #define USB_ENDPOINT_DIR_MASK 0x80
  103. #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
  104. #define USB_ENDPOINT_XFER_CONTROL 0
  105. #define USB_ENDPOINT_XFER_ISOC 1
  106. #define USB_ENDPOINT_XFER_BULK 2
  107. #define USB_ENDPOINT_XFER_INT 3
  108. /* USB Packet IDs (PIDs) */
  109. #define USB_PID_UNDEF_0 0xf0
  110. #define USB_PID_OUT 0xe1
  111. #define USB_PID_ACK 0xd2
  112. #define USB_PID_DATA0 0xc3
  113. #define USB_PID_UNDEF_4 0xb4
  114. #define USB_PID_SOF 0xa5
  115. #define USB_PID_UNDEF_6 0x96
  116. #define USB_PID_UNDEF_7 0x87
  117. #define USB_PID_UNDEF_8 0x78
  118. #define USB_PID_IN 0x69
  119. #define USB_PID_NAK 0x5a
  120. #define USB_PID_DATA1 0x4b
  121. #define USB_PID_PREAMBLE 0x3c
  122. #define USB_PID_SETUP 0x2d
  123. #define USB_PID_STALL 0x1e
  124. #define USB_PID_UNDEF_F 0x0f
  125. /* Standard requests */
  126. #define USB_REQ_GET_STATUS 0x00
  127. #define USB_REQ_CLEAR_FEATURE 0x01
  128. #define USB_REQ_SET_FEATURE 0x03
  129. #define USB_REQ_SET_ADDRESS 0x05
  130. #define USB_REQ_GET_DESCRIPTOR 0x06
  131. #define USB_REQ_SET_DESCRIPTOR 0x07
  132. #define USB_REQ_GET_CONFIGURATION 0x08
  133. #define USB_REQ_SET_CONFIGURATION 0x09
  134. #define USB_REQ_GET_INTERFACE 0x0A
  135. #define USB_REQ_SET_INTERFACE 0x0B
  136. #define USB_REQ_SYNCH_FRAME 0x0C
  137. /* HID requests */
  138. #define USB_REQ_GET_REPORT 0x01
  139. #define USB_REQ_GET_IDLE 0x02
  140. #define USB_REQ_GET_PROTOCOL 0x03
  141. #define USB_REQ_SET_REPORT 0x09
  142. #define USB_REQ_SET_IDLE 0x0A
  143. #define USB_REQ_SET_PROTOCOL 0x0B
  144. /* "pipe" definitions */
  145. #define PIPE_ISOCHRONOUS 0
  146. #define PIPE_INTERRUPT 1
  147. #define PIPE_CONTROL 2
  148. #define PIPE_BULK 3
  149. #define PIPE_DEVEP_MASK 0x0007ff00
  150. #define USB_ISOCHRONOUS 0
  151. #define USB_INTERRUPT 1
  152. #define USB_CONTROL 2
  153. #define USB_BULK 3
  154. /* USB-status codes: */
  155. #define USB_ST_ACTIVE 0x1 /* TD is active */
  156. #define USB_ST_STALLED 0x2 /* TD is stalled */
  157. #define USB_ST_BUF_ERR 0x4 /* buffer error */
  158. #define USB_ST_BABBLE_DET 0x8 /* Babble detected */
  159. #define USB_ST_NAK_REC 0x10 /* NAK Received*/
  160. #define USB_ST_CRC_ERR 0x20 /* CRC/timeout Error */
  161. #define USB_ST_BIT_ERR 0x40 /* Bitstuff error */
  162. #define USB_ST_NOT_PROC 0x80000000L /* Not yet processed */
  163. /*************************************************************************
  164. * Hub defines
  165. */
  166. /*
  167. * Hub request types
  168. */
  169. #define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE)
  170. #define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER)
  171. /*
  172. * Hub Class feature numbers
  173. */
  174. #define C_HUB_LOCAL_POWER 0
  175. #define C_HUB_OVER_CURRENT 1
  176. /*
  177. * Port feature numbers
  178. */
  179. #define USB_PORT_FEAT_CONNECTION 0
  180. #define USB_PORT_FEAT_ENABLE 1
  181. #define USB_PORT_FEAT_SUSPEND 2
  182. #define USB_PORT_FEAT_OVER_CURRENT 3
  183. #define USB_PORT_FEAT_RESET 4
  184. #define USB_PORT_FEAT_POWER 8
  185. #define USB_PORT_FEAT_LOWSPEED 9
  186. #define USB_PORT_FEAT_C_CONNECTION 16
  187. #define USB_PORT_FEAT_C_ENABLE 17
  188. #define USB_PORT_FEAT_C_SUSPEND 18
  189. #define USB_PORT_FEAT_C_OVER_CURRENT 19
  190. #define USB_PORT_FEAT_C_RESET 20
  191. /* wPortStatus bits */
  192. #define USB_PORT_STAT_CONNECTION 0x0001
  193. #define USB_PORT_STAT_ENABLE 0x0002
  194. #define USB_PORT_STAT_SUSPEND 0x0004
  195. #define USB_PORT_STAT_OVERCURRENT 0x0008
  196. #define USB_PORT_STAT_RESET 0x0010
  197. #define USB_PORT_STAT_POWER 0x0100
  198. #define USB_PORT_STAT_LOW_SPEED 0x0200
  199. /* wPortChange bits */
  200. #define USB_PORT_STAT_C_CONNECTION 0x0001
  201. #define USB_PORT_STAT_C_ENABLE 0x0002
  202. #define USB_PORT_STAT_C_SUSPEND 0x0004
  203. #define USB_PORT_STAT_C_OVERCURRENT 0x0008
  204. #define USB_PORT_STAT_C_RESET 0x0010
  205. /* wHubCharacteristics (masks) */
  206. #define HUB_CHAR_LPSM 0x0003
  207. #define HUB_CHAR_COMPOUND 0x0004
  208. #define HUB_CHAR_OCPM 0x0018
  209. /*
  210. *Hub Status & Hub Change bit masks
  211. */
  212. #define HUB_STATUS_LOCAL_POWER 0x0001
  213. #define HUB_STATUS_OVERCURRENT 0x0002
  214. #define HUB_CHANGE_LOCAL_POWER 0x0001
  215. #define HUB_CHANGE_OVERCURRENT 0x0002
  216. #endif /*_USB_DEFS_H_ */