1 // USB functions and data.
5 // Local information for a usb controller.
13 extern struct usb_s USBControllers[];
15 #define USB_MAXADDR 127
19 int configure_usb_device(struct usb_s *cntl, int lowspeed);
20 struct usb_ctrlrequest;
21 int send_default_control(u32 endp, const struct usb_ctrlrequest *req
23 void *alloc_intr_pipe(u32 endp, int period);
24 int usb_poll_intr(void *pipe, void *data);
27 /****************************************************************
29 ****************************************************************/
32 mkendp(struct usb_s *cntl, u8 devaddr, u8 ep, u8 lowspeed, u8 maxsize)
34 u8 bus = cntl-USBControllers;
35 u8 size = __ffs(maxsize);
36 return (size<<25) | (lowspeed<<24) | (bus<<16) | (devaddr<<8) | ep;
39 static inline u8 endp2ep(u32 endp) {
42 static inline u8 endp2devaddr(u32 endp) {
45 static inline struct usb_s *endp2cntl(u32 endp) {
47 return &USBControllers[bus];
49 static inline u8 endp2speed(u32 endp) {
50 return (endp>>24) & 1;
52 static inline u8 endp2maxsize(u32 endp) {
53 return 1 << (endp>>25);
57 /****************************************************************
58 * usb structs and flags
59 ****************************************************************/
61 #define USB_PID_OUT 0xe1
62 #define USB_PID_IN 0x69
63 #define USB_PID_SETUP 0x2d
65 #define USB_DIR_OUT 0 /* to device */
66 #define USB_DIR_IN 0x80 /* to host */
68 #define USB_TYPE_MASK (0x03 << 5)
69 #define USB_TYPE_STANDARD (0x00 << 5)
70 #define USB_TYPE_CLASS (0x01 << 5)
71 #define USB_TYPE_VENDOR (0x02 << 5)
72 #define USB_TYPE_RESERVED (0x03 << 5)
74 #define USB_RECIP_MASK 0x1f
75 #define USB_RECIP_DEVICE 0x00
76 #define USB_RECIP_INTERFACE 0x01
77 #define USB_RECIP_ENDPOINT 0x02
78 #define USB_RECIP_OTHER 0x03
80 #define USB_REQ_GET_STATUS 0x00
81 #define USB_REQ_CLEAR_FEATURE 0x01
82 #define USB_REQ_SET_FEATURE 0x03
83 #define USB_REQ_SET_ADDRESS 0x05
84 #define USB_REQ_GET_DESCRIPTOR 0x06
85 #define USB_REQ_SET_DESCRIPTOR 0x07
86 #define USB_REQ_GET_CONFIGURATION 0x08
87 #define USB_REQ_SET_CONFIGURATION 0x09
88 #define USB_REQ_GET_INTERFACE 0x0A
89 #define USB_REQ_SET_INTERFACE 0x0B
90 #define USB_REQ_SYNCH_FRAME 0x0C
92 struct usb_ctrlrequest {
100 #define USB_DT_DEVICE 0x01
101 #define USB_DT_CONFIG 0x02
102 #define USB_DT_STRING 0x03
103 #define USB_DT_INTERFACE 0x04
104 #define USB_DT_ENDPOINT 0x05
105 #define USB_DT_DEVICE_QUALIFIER 0x06
106 #define USB_DT_OTHER_SPEED_CONFIG 0x07
108 struct usb_device_descriptor {
123 u8 bNumConfigurations;
126 #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
127 #define USB_CLASS_AUDIO 1
128 #define USB_CLASS_COMM 2
129 #define USB_CLASS_HID 3
130 #define USB_CLASS_PHYSICAL 5
131 #define USB_CLASS_STILL_IMAGE 6
132 #define USB_CLASS_PRINTER 7
133 #define USB_CLASS_MASS_STORAGE 8
134 #define USB_CLASS_HUB 9
136 struct usb_config_descriptor {
142 u8 bConfigurationValue;
148 struct usb_interface_descriptor {
153 u8 bAlternateSetting;
156 u8 bInterfaceSubClass;
157 u8 bInterfaceProtocol;
161 struct usb_endpoint_descriptor {
171 #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
172 #define USB_ENDPOINT_DIR_MASK 0x80
174 #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
175 #define USB_ENDPOINT_XFER_CONTROL 0
176 #define USB_ENDPOINT_XFER_ISOC 1
177 #define USB_ENDPOINT_XFER_BULK 2
178 #define USB_ENDPOINT_XFER_INT 3
179 #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80