|
|
1.1 root 1: // USB functions and data.
2: #ifndef __USB_H
3: #define __USB_H
4:
1.1.1.3 ! root 5: #include "util.h" // struct mutex_s
! 6:
! 7: // Information on a USB end point.
! 8: struct usb_pipe {
! 9: struct usb_s *cntl;
! 10: u8 type;
! 11: u8 ep;
! 12: u8 devaddr;
! 13: u8 speed;
! 14: u16 maxpacket;
! 15: u8 tt_devaddr;
! 16: u8 tt_port;
! 17: };
! 18:
! 19: // Common information for usb controllers.
1.1 root 20: struct usb_s {
1.1.1.3 ! root 21: struct usb_pipe *defaultpipe;
! 22: struct mutex_s resetlock;
! 23: int busid;
1.1 root 24: u8 type;
25: u8 maxaddr;
1.1.1.3 ! root 26: };
! 27:
! 28: // Information for enumerating USB hubs
! 29: struct usbhub_s {
! 30: struct usbhub_op_s *op;
! 31: struct usb_pipe *pipe;
! 32: struct usb_s *cntl;
! 33: struct mutex_s lock;
! 34: u32 powerwait;
! 35: u32 port;
! 36: u32 threads;
! 37: u32 portcount;
! 38: u32 devcount;
! 39: };
1.1 root 40:
1.1.1.3 ! root 41: // Hub callback (32bit) info
! 42: struct usbhub_op_s {
! 43: int (*detect)(struct usbhub_s *hub, u32 port);
! 44: int (*reset)(struct usbhub_s *hub, u32 port);
! 45: void (*disconnect)(struct usbhub_s *hub, u32 port);
1.1 root 46: };
47:
48: #define USB_TYPE_UHCI 1
49: #define USB_TYPE_OHCI 2
1.1.1.3 ! root 50: #define USB_TYPE_EHCI 3
1.1 root 51:
1.1.1.3 ! root 52: #define USB_FULLSPEED 0
! 53: #define USB_LOWSPEED 1
! 54: #define USB_HIGHSPEED 2
1.1 root 55:
56: #define USB_MAXADDR 127
57:
58:
59: /****************************************************************
1.1.1.3 ! root 60: * usb structs and flags
1.1 root 61: ****************************************************************/
62:
1.1.1.3 ! root 63: // USB mandated timings (in ms)
! 64: #define USB_TIME_SIGATT 100
! 65: #define USB_TIME_ATTDB 100
! 66: #define USB_TIME_DRST 10
! 67: #define USB_TIME_DRSTR 50
! 68: #define USB_TIME_RSTRCY 10
1.1 root 69:
1.1.1.3 ! root 70: #define USB_TIME_SETADDR_RECOVERY 2
1.1 root 71:
72: #define USB_PID_OUT 0xe1
73: #define USB_PID_IN 0x69
74: #define USB_PID_SETUP 0x2d
75:
76: #define USB_DIR_OUT 0 /* to device */
77: #define USB_DIR_IN 0x80 /* to host */
78:
79: #define USB_TYPE_MASK (0x03 << 5)
80: #define USB_TYPE_STANDARD (0x00 << 5)
81: #define USB_TYPE_CLASS (0x01 << 5)
82: #define USB_TYPE_VENDOR (0x02 << 5)
83: #define USB_TYPE_RESERVED (0x03 << 5)
84:
85: #define USB_RECIP_MASK 0x1f
86: #define USB_RECIP_DEVICE 0x00
87: #define USB_RECIP_INTERFACE 0x01
88: #define USB_RECIP_ENDPOINT 0x02
89: #define USB_RECIP_OTHER 0x03
90:
91: #define USB_REQ_GET_STATUS 0x00
92: #define USB_REQ_CLEAR_FEATURE 0x01
93: #define USB_REQ_SET_FEATURE 0x03
94: #define USB_REQ_SET_ADDRESS 0x05
95: #define USB_REQ_GET_DESCRIPTOR 0x06
96: #define USB_REQ_SET_DESCRIPTOR 0x07
97: #define USB_REQ_GET_CONFIGURATION 0x08
98: #define USB_REQ_SET_CONFIGURATION 0x09
99: #define USB_REQ_GET_INTERFACE 0x0A
100: #define USB_REQ_SET_INTERFACE 0x0B
101: #define USB_REQ_SYNCH_FRAME 0x0C
102:
103: struct usb_ctrlrequest {
104: u8 bRequestType;
105: u8 bRequest;
106: u16 wValue;
107: u16 wIndex;
108: u16 wLength;
109: } PACKED;
110:
111: #define USB_DT_DEVICE 0x01
112: #define USB_DT_CONFIG 0x02
113: #define USB_DT_STRING 0x03
114: #define USB_DT_INTERFACE 0x04
115: #define USB_DT_ENDPOINT 0x05
116: #define USB_DT_DEVICE_QUALIFIER 0x06
117: #define USB_DT_OTHER_SPEED_CONFIG 0x07
118:
119: struct usb_device_descriptor {
120: u8 bLength;
121: u8 bDescriptorType;
122:
123: u16 bcdUSB;
124: u8 bDeviceClass;
125: u8 bDeviceSubClass;
126: u8 bDeviceProtocol;
127: u8 bMaxPacketSize0;
128: u16 idVendor;
129: u16 idProduct;
130: u16 bcdDevice;
131: u8 iManufacturer;
132: u8 iProduct;
133: u8 iSerialNumber;
134: u8 bNumConfigurations;
135: } PACKED;
136:
137: #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
138: #define USB_CLASS_AUDIO 1
139: #define USB_CLASS_COMM 2
140: #define USB_CLASS_HID 3
141: #define USB_CLASS_PHYSICAL 5
142: #define USB_CLASS_STILL_IMAGE 6
143: #define USB_CLASS_PRINTER 7
144: #define USB_CLASS_MASS_STORAGE 8
145: #define USB_CLASS_HUB 9
146:
147: struct usb_config_descriptor {
148: u8 bLength;
149: u8 bDescriptorType;
150:
151: u16 wTotalLength;
152: u8 bNumInterfaces;
153: u8 bConfigurationValue;
154: u8 iConfiguration;
155: u8 bmAttributes;
156: u8 bMaxPower;
157: } PACKED;
158:
159: struct usb_interface_descriptor {
160: u8 bLength;
161: u8 bDescriptorType;
162:
163: u8 bInterfaceNumber;
164: u8 bAlternateSetting;
165: u8 bNumEndpoints;
166: u8 bInterfaceClass;
167: u8 bInterfaceSubClass;
168: u8 bInterfaceProtocol;
169: u8 iInterface;
170: } PACKED;
171:
172: struct usb_endpoint_descriptor {
173: u8 bLength;
174: u8 bDescriptorType;
175:
176: u8 bEndpointAddress;
177: u8 bmAttributes;
178: u16 wMaxPacketSize;
179: u8 bInterval;
180: } PACKED;
181:
182: #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
183: #define USB_ENDPOINT_DIR_MASK 0x80
184:
185: #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
186: #define USB_ENDPOINT_XFER_CONTROL 0
187: #define USB_ENDPOINT_XFER_ISOC 1
188: #define USB_ENDPOINT_XFER_BULK 2
189: #define USB_ENDPOINT_XFER_INT 3
190: #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80
191:
1.1.1.3 ! root 192:
! 193: /****************************************************************
! 194: * function defs
! 195: ****************************************************************/
! 196:
! 197: // usb.c
! 198: void usb_setup(void);
! 199: void usb_enumerate(struct usbhub_s *hub);
! 200: int send_default_control(struct usb_pipe *pipe, const struct usb_ctrlrequest *req
! 201: , void *data);
! 202: int usb_send_bulk(struct usb_pipe *pipe, int dir, void *data, int datasize);
! 203: void free_pipe(struct usb_pipe *pipe);
! 204: struct usb_pipe *alloc_bulk_pipe(struct usb_pipe *pipe
! 205: , struct usb_endpoint_descriptor *epdesc);
! 206: struct usb_pipe *alloc_intr_pipe(struct usb_pipe *pipe
! 207: , struct usb_endpoint_descriptor *epdesc);
! 208: int usb_poll_intr(struct usb_pipe *pipe, void *data);
! 209: struct usb_endpoint_descriptor *findEndPointDesc(
! 210: struct usb_interface_descriptor *iface, int imax, int type, int dir);
! 211: u32 mkendpFromDesc(struct usb_pipe *pipe
! 212: , struct usb_endpoint_descriptor *epdesc);
! 213:
1.1 root 214: #endif // usb.h
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.