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