|
|
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 {
1.1.1.6 ! root 9: union {
! 10: struct usb_s *cntl;
! 11: struct usb_pipe *freenext;
! 12: };
1.1.1.3 root 13: u8 type;
14: u8 ep;
15: u8 devaddr;
16: u8 speed;
17: u16 maxpacket;
1.1.1.6 ! root 18: u8 eptype;
! 19: };
! 20:
! 21: // Common information for usb devices.
! 22: struct usbdevice_s {
! 23: struct usbhub_s *hub;
! 24: struct usb_pipe *defpipe;
! 25: u32 port;
! 26: struct usb_config_descriptor *config;
! 27: struct usb_interface_descriptor *iface;
! 28: int imax;
! 29: u8 speed;
! 30: u8 devaddr;
1.1.1.3 root 31: };
32:
33: // Common information for usb controllers.
1.1 root 34: struct usb_s {
1.1.1.6 ! root 35: struct usb_pipe *freelist;
1.1.1.3 root 36: struct mutex_s resetlock;
1.1.1.5 root 37: struct pci_device *pci;
1.1.1.3 root 38: int busid;
1.1 root 39: u8 type;
40: u8 maxaddr;
1.1.1.3 root 41: };
42:
43: // Information for enumerating USB hubs
44: struct usbhub_s {
45: struct usbhub_op_s *op;
1.1.1.6 ! root 46: struct usbdevice_s *usbdev;
1.1.1.3 root 47: struct usb_s *cntl;
48: struct mutex_s lock;
49: u32 powerwait;
50: u32 port;
51: u32 threads;
52: u32 portcount;
53: u32 devcount;
54: };
1.1 root 55:
1.1.1.3 root 56: // Hub callback (32bit) info
57: struct usbhub_op_s {
58: int (*detect)(struct usbhub_s *hub, u32 port);
59: int (*reset)(struct usbhub_s *hub, u32 port);
60: void (*disconnect)(struct usbhub_s *hub, u32 port);
1.1 root 61: };
62:
63: #define USB_TYPE_UHCI 1
64: #define USB_TYPE_OHCI 2
1.1.1.3 root 65: #define USB_TYPE_EHCI 3
1.1 root 66:
1.1.1.3 root 67: #define USB_FULLSPEED 0
68: #define USB_LOWSPEED 1
69: #define USB_HIGHSPEED 2
1.1 root 70:
71: #define USB_MAXADDR 127
72:
73:
74: /****************************************************************
1.1.1.3 root 75: * usb structs and flags
1.1 root 76: ****************************************************************/
77:
1.1.1.3 root 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
1.1 root 84:
1.1.1.3 root 85: #define USB_TIME_SETADDR_RECOVERY 2
1.1 root 86:
87: #define USB_PID_OUT 0xe1
88: #define USB_PID_IN 0x69
89: #define USB_PID_SETUP 0x2d
90:
91: #define USB_DIR_OUT 0 /* to device */
92: #define USB_DIR_IN 0x80 /* to host */
93:
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)
99:
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
105:
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
117:
118: struct usb_ctrlrequest {
119: u8 bRequestType;
120: u8 bRequest;
121: u16 wValue;
122: u16 wIndex;
123: u16 wLength;
124: } PACKED;
125:
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
133:
134: struct usb_device_descriptor {
135: u8 bLength;
136: u8 bDescriptorType;
137:
138: u16 bcdUSB;
139: u8 bDeviceClass;
140: u8 bDeviceSubClass;
141: u8 bDeviceProtocol;
142: u8 bMaxPacketSize0;
143: u16 idVendor;
144: u16 idProduct;
145: u16 bcdDevice;
146: u8 iManufacturer;
147: u8 iProduct;
148: u8 iSerialNumber;
149: u8 bNumConfigurations;
150: } PACKED;
151:
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
161:
162: struct usb_config_descriptor {
163: u8 bLength;
164: u8 bDescriptorType;
165:
166: u16 wTotalLength;
167: u8 bNumInterfaces;
168: u8 bConfigurationValue;
169: u8 iConfiguration;
170: u8 bmAttributes;
171: u8 bMaxPower;
172: } PACKED;
173:
174: struct usb_interface_descriptor {
175: u8 bLength;
176: u8 bDescriptorType;
177:
178: u8 bInterfaceNumber;
179: u8 bAlternateSetting;
180: u8 bNumEndpoints;
181: u8 bInterfaceClass;
182: u8 bInterfaceSubClass;
183: u8 bInterfaceProtocol;
184: u8 iInterface;
185: } PACKED;
186:
187: struct usb_endpoint_descriptor {
188: u8 bLength;
189: u8 bDescriptorType;
190:
191: u8 bEndpointAddress;
192: u8 bmAttributes;
193: u16 wMaxPacketSize;
194: u8 bInterval;
195: } PACKED;
196:
197: #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
198: #define USB_ENDPOINT_DIR_MASK 0x80
199:
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
206:
1.1.1.3 root 207:
208: /****************************************************************
209: * function defs
210: ****************************************************************/
211:
212: // usb.c
1.1.1.6 ! root 213: struct usb_pipe *usb_alloc_pipe(struct usbdevice_s *usbdev
! 214: , struct usb_endpoint_descriptor *epdesc);
! 215: int usb_send_bulk(struct usb_pipe *pipe, int dir, void *data, int datasize);
! 216: int usb_poll_intr(struct usb_pipe *pipe, void *data);
1.1.1.3 root 217: int send_default_control(struct usb_pipe *pipe, const struct usb_ctrlrequest *req
218: , void *data);
219: void free_pipe(struct usb_pipe *pipe);
1.1.1.6 ! root 220: struct usb_pipe *usb_getFreePipe(struct usb_s *cntl, u8 eptype);
! 221: void usb_desc2pipe(struct usb_pipe *pipe, struct usbdevice_s *usbdev
1.1.1.3 root 222: , struct usb_endpoint_descriptor *epdesc);
1.1.1.6 ! root 223: int usb_getFrameExp(struct usbdevice_s *usbdev
! 224: , struct usb_endpoint_descriptor *epdesc);
! 225: struct usb_endpoint_descriptor *findEndPointDesc(struct usbdevice_s *usbdev
! 226: , int type, int dir);
! 227: void usb_enumerate(struct usbhub_s *hub);
! 228: void usb_setup(void);
1.1.1.3 root 229:
1.1 root 230: #endif // usb.h
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.