1 // USB functions and data.
5 // Local information for a usb controller.
17 struct ohci_regs *regs;
23 #define USB_TYPE_UHCI 1
24 #define USB_TYPE_OHCI 2
26 extern struct usb_s USBControllers[];
32 #define USB_MAXADDR 127
36 int configure_usb_device(struct usb_s *cntl, int lowspeed);
37 struct usb_ctrlrequest;
38 int send_default_control(u32 endp, const struct usb_ctrlrequest *req
40 struct usb_pipe *alloc_intr_pipe(u32 endp, int period);
41 int usb_poll_intr(struct usb_pipe *pipe, void *data);
44 /****************************************************************
46 ****************************************************************/
49 mkendp(struct usb_s *cntl, u8 devaddr, u8 ep, u8 lowspeed, u8 maxsize)
51 u8 bus = cntl-USBControllers;
52 u8 size = __ffs(maxsize);
53 return (size<<25) | (lowspeed<<24) | (bus<<16) | (devaddr<<8) | ep;
56 static inline u8 endp2ep(u32 endp) {
59 static inline u8 endp2devaddr(u32 endp) {
62 static inline struct usb_s *endp2cntl(u32 endp) {
64 return &USBControllers[bus];
66 static inline u8 endp2speed(u32 endp) {
67 return (endp>>24) & 1;
69 static inline u8 endp2maxsize(u32 endp) {
70 return 1 << (endp>>25);
74 /****************************************************************
75 * usb structs and flags
76 ****************************************************************/
78 // USB mandated timings (in ms)
79 #define USB_TIME_SIGATT 100
80 #define USB_TIME_ATTDB 100
81 #define USB_TIME_DRST 10
82 #define USB_TIME_DRSTR 50
83 #define USB_TIME_RSTRCY 10
85 #define USB_TIME_SETADDR_RECOVERY 2
87 #define USB_PID_OUT 0xe1
88 #define USB_PID_IN 0x69
89 #define USB_PID_SETUP 0x2d
91 #define USB_DIR_OUT 0 /* to device */
92 #define USB_DIR_IN 0x80 /* to host */
94 #define USB_TYPE_MASK (0x03 << 5)
95 #define USB_TYPE_STANDARD (0x00 << 5)
96 #define USB_TYPE_CLASS (0x01 << 5)
97 #define USB_TYPE_VENDOR (0x02 << 5)
98 #define USB_TYPE_RESERVED (0x03 << 5)
100 #define USB_RECIP_MASK 0x1f
101 #define USB_RECIP_DEVICE 0x00
102 #define USB_RECIP_INTERFACE 0x01
103 #define USB_RECIP_ENDPOINT 0x02
104 #define USB_RECIP_OTHER 0x03
106 #define USB_REQ_GET_STATUS 0x00
107 #define USB_REQ_CLEAR_FEATURE 0x01
108 #define USB_REQ_SET_FEATURE 0x03
109 #define USB_REQ_SET_ADDRESS 0x05
110 #define USB_REQ_GET_DESCRIPTOR 0x06
111 #define USB_REQ_SET_DESCRIPTOR 0x07
112 #define USB_REQ_GET_CONFIGURATION 0x08
113 #define USB_REQ_SET_CONFIGURATION 0x09
114 #define USB_REQ_GET_INTERFACE 0x0A
115 #define USB_REQ_SET_INTERFACE 0x0B
116 #define USB_REQ_SYNCH_FRAME 0x0C
118 struct usb_ctrlrequest {
126 #define USB_DT_DEVICE 0x01
127 #define USB_DT_CONFIG 0x02
128 #define USB_DT_STRING 0x03
129 #define USB_DT_INTERFACE 0x04
130 #define USB_DT_ENDPOINT 0x05
131 #define USB_DT_DEVICE_QUALIFIER 0x06
132 #define USB_DT_OTHER_SPEED_CONFIG 0x07
134 struct usb_device_descriptor {
149 u8 bNumConfigurations;
152 #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
153 #define USB_CLASS_AUDIO 1
154 #define USB_CLASS_COMM 2
155 #define USB_CLASS_HID 3
156 #define USB_CLASS_PHYSICAL 5
157 #define USB_CLASS_STILL_IMAGE 6
158 #define USB_CLASS_PRINTER 7
159 #define USB_CLASS_MASS_STORAGE 8
160 #define USB_CLASS_HUB 9
162 struct usb_config_descriptor {
168 u8 bConfigurationValue;
174 struct usb_interface_descriptor {
179 u8 bAlternateSetting;
182 u8 bInterfaceSubClass;
183 u8 bInterfaceProtocol;
187 struct usb_endpoint_descriptor {
197 #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
198 #define USB_ENDPOINT_DIR_MASK 0x80
200 #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
201 #define USB_ENDPOINT_XFER_CONTROL 0
202 #define USB_ENDPOINT_XFER_ISOC 1
203 #define USB_ENDPOINT_XFER_BULK 2
204 #define USB_ENDPOINT_XFER_INT 3
205 #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80