1 // USB functions and data.
9 // Local information for a usb controller.
14 struct usb_pipe *defaultpipe;
19 void *control_qh, *bulk_qh, *framelist;
22 struct ohci_regs *regs;
27 #define USB_TYPE_UHCI 1
28 #define USB_TYPE_OHCI 2
30 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(struct usb_pipe *pipe, const struct usb_ctrlrequest *req
40 int usb_send_bulk(struct usb_pipe *pipe, int dir, void *data, int datasize);
41 void free_pipe(struct usb_pipe *pipe);
42 struct usb_pipe *alloc_bulk_pipe(u32 endp);
43 struct usb_pipe *alloc_intr_pipe(u32 endp, int period);
44 int usb_poll_intr(struct usb_pipe *pipe, void *data);
45 struct usb_interface_descriptor;
46 struct usb_endpoint_descriptor *findEndPointDesc(
47 struct usb_interface_descriptor *iface, int imax, int type, int dir);
48 u32 mkendpFromDesc(struct usb_pipe *pipe
49 , struct usb_endpoint_descriptor *epdesc);
52 /****************************************************************
54 ****************************************************************/
57 mkendp(struct usb_s *cntl, u8 devaddr, u8 ep, u8 lowspeed, u8 maxsize)
59 u8 bus = cntl-USBControllers;
60 u8 size = __ffs(maxsize);
61 return (size<<25) | (lowspeed<<24) | (bus<<16) | (devaddr<<8) | ep;
64 static inline u8 endp2ep(u32 endp) {
67 static inline u8 endp2devaddr(u32 endp) {
70 static inline struct usb_s *endp2cntl(u32 endp) {
72 return &USBControllers[bus];
74 static inline u8 endp2speed(u32 endp) {
75 return (endp>>24) & 1;
77 static inline u8 endp2maxsize(u32 endp) {
78 return 1 << (endp>>25);
82 /****************************************************************
83 * usb structs and flags
84 ****************************************************************/
86 // USB mandated timings (in ms)
87 #define USB_TIME_SIGATT 100
88 #define USB_TIME_ATTDB 100
89 #define USB_TIME_DRST 10
90 #define USB_TIME_DRSTR 50
91 #define USB_TIME_RSTRCY 10
93 #define USB_TIME_SETADDR_RECOVERY 2
95 #define USB_PID_OUT 0xe1
96 #define USB_PID_IN 0x69
97 #define USB_PID_SETUP 0x2d
99 #define USB_DIR_OUT 0 /* to device */
100 #define USB_DIR_IN 0x80 /* to host */
102 #define USB_TYPE_MASK (0x03 << 5)
103 #define USB_TYPE_STANDARD (0x00 << 5)
104 #define USB_TYPE_CLASS (0x01 << 5)
105 #define USB_TYPE_VENDOR (0x02 << 5)
106 #define USB_TYPE_RESERVED (0x03 << 5)
108 #define USB_RECIP_MASK 0x1f
109 #define USB_RECIP_DEVICE 0x00
110 #define USB_RECIP_INTERFACE 0x01
111 #define USB_RECIP_ENDPOINT 0x02
112 #define USB_RECIP_OTHER 0x03
114 #define USB_REQ_GET_STATUS 0x00
115 #define USB_REQ_CLEAR_FEATURE 0x01
116 #define USB_REQ_SET_FEATURE 0x03
117 #define USB_REQ_SET_ADDRESS 0x05
118 #define USB_REQ_GET_DESCRIPTOR 0x06
119 #define USB_REQ_SET_DESCRIPTOR 0x07
120 #define USB_REQ_GET_CONFIGURATION 0x08
121 #define USB_REQ_SET_CONFIGURATION 0x09
122 #define USB_REQ_GET_INTERFACE 0x0A
123 #define USB_REQ_SET_INTERFACE 0x0B
124 #define USB_REQ_SYNCH_FRAME 0x0C
126 struct usb_ctrlrequest {
134 #define USB_DT_DEVICE 0x01
135 #define USB_DT_CONFIG 0x02
136 #define USB_DT_STRING 0x03
137 #define USB_DT_INTERFACE 0x04
138 #define USB_DT_ENDPOINT 0x05
139 #define USB_DT_DEVICE_QUALIFIER 0x06
140 #define USB_DT_OTHER_SPEED_CONFIG 0x07
142 struct usb_device_descriptor {
157 u8 bNumConfigurations;
160 #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
161 #define USB_CLASS_AUDIO 1
162 #define USB_CLASS_COMM 2
163 #define USB_CLASS_HID 3
164 #define USB_CLASS_PHYSICAL 5
165 #define USB_CLASS_STILL_IMAGE 6
166 #define USB_CLASS_PRINTER 7
167 #define USB_CLASS_MASS_STORAGE 8
168 #define USB_CLASS_HUB 9
170 struct usb_config_descriptor {
176 u8 bConfigurationValue;
182 struct usb_interface_descriptor {
187 u8 bAlternateSetting;
190 u8 bInterfaceSubClass;
191 u8 bInterfaceProtocol;
195 struct usb_endpoint_descriptor {
205 #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
206 #define USB_ENDPOINT_DIR_MASK 0x80
208 #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
209 #define USB_ENDPOINT_XFER_CONTROL 0
210 #define USB_ENDPOINT_XFER_ISOC 1
211 #define USB_ENDPOINT_XFER_BULK 2
212 #define USB_ENDPOINT_XFER_INT 3
213 #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80