1 #ifndef __LINUX_USB_H
2 #define __LINUX_USB_H
3
4 /* USB constants */
5
6 /*
7 * Device and/or Interface Class codes
8 */
9 #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
10 #define USB_CLASS_AUDIO 1
11 #define USB_CLASS_COMM 2
12 #define USB_CLASS_HID 3
13 #define USB_CLASS_PHYSICAL 5
14 #define USB_CLASS_PRINTER 7
15 #define USB_CLASS_MASS_STORAGE 8
16 #define USB_CLASS_HUB 9
17 #define USB_CLASS_DATA 10
18 #define USB_CLASS_APP_SPEC 0xfe
19 #define USB_CLASS_VENDOR_SPEC 0xff
20
21 /*
22 * USB types
23 */
24 #define USB_TYPE_STANDARD (0x00 << 5)
25 #define USB_TYPE_CLASS (0x01 << 5)
26 #define USB_TYPE_VENDOR (0x02 << 5)
27 #define USB_TYPE_RESERVED (0x03 << 5)
28
29 /*
30 * USB recipients
31 */
32 #define USB_RECIP_MASK 0x1f
33 #define USB_RECIP_DEVICE 0x00
34 #define USB_RECIP_INTERFACE 0x01
35 #define USB_RECIP_ENDPOINT 0x02
36 #define USB_RECIP_OTHER 0x03
37
38 /*
39 * USB directions
40 */
41 #define USB_DIR_OUT 0
42 #define USB_DIR_IN 0x80
43
44 /*
45 * Descriptor types
46 */
47 #define USB_DT_DEVICE 0x01
48 #define USB_DT_CONFIG 0x02
49 #define USB_DT_STRING 0x03
50 #define USB_DT_INTERFACE 0x04
51 #define USB_DT_ENDPOINT 0x05
52
53 #define USB_DT_HID (USB_TYPE_CLASS | 0x01)
54 #define USB_DT_REPORT (USB_TYPE_CLASS | 0x02)
55 #define USB_DT_PHYSICAL (USB_TYPE_CLASS | 0x03)
56 #define USB_DT_HUB (USB_TYPE_CLASS | 0x09)
57
58 /*
59 * Descriptor sizes per descriptor type
60 */
61 #define USB_DT_DEVICE_SIZE 18
62 #define USB_DT_CONFIG_SIZE 9
63 #define USB_DT_INTERFACE_SIZE 9
64 #define USB_DT_ENDPOINT_SIZE 7
65 #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
66 #define USB_DT_HUB_NONVAR_SIZE 7
67 #define USB_DT_HID_SIZE 9
68
69 /*
70 * Endpoints
71 */
72 #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
73 #define USB_ENDPOINT_DIR_MASK 0x80
74
75 #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
76 #define USB_ENDPOINT_XFER_CONTROL 0
77 #define USB_ENDPOINT_XFER_ISOC 1
78 #define USB_ENDPOINT_XFER_BULK 2
79 #define USB_ENDPOINT_XFER_INT 3
80
81 /*
82 * USB Packet IDs (PIDs)
83 */
84 #define USB_PID_UNDEF_0 0xf0
85 #define USB_PID_OUT 0xe1
86 #define USB_PID_ACK 0xd2
87 #define USB_PID_DATA0 0xc3
88 #define USB_PID_PING 0xb4 /* USB 2.0 */
89 #define USB_PID_SOF 0xa5
90 #define USB_PID_NYET 0x96 /* USB 2.0 */
91 #define USB_PID_DATA2 0x87 /* USB 2.0 */
92 #define USB_PID_SPLIT 0x78 /* USB 2.0 */
93 #define USB_PID_IN 0x69
94 #define USB_PID_NAK 0x5a
95 #define USB_PID_DATA1 0x4b
96 #define USB_PID_PREAMBLE 0x3c /* Token mode */
97 #define USB_PID_ERR 0x3c /* USB 2.0: handshake mode */
98 #define USB_PID_SETUP 0x2d
99 #define USB_PID_STALL 0x1e
100 #define USB_PID_MDATA 0x0f /* USB 2.0 */
101
102 /*
103 * Standard requests
104 */
105 #define USB_REQ_GET_STATUS 0x00
106 #define USB_REQ_CLEAR_FEATURE 0x01
107 #define USB_REQ_SET_FEATURE 0x03
108 #define USB_REQ_SET_ADDRESS 0x05
109 #define USB_REQ_GET_DESCRIPTOR 0x06
110 #define USB_REQ_SET_DESCRIPTOR 0x07
111 #define USB_REQ_GET_CONFIGURATION 0x08
112 #define USB_REQ_SET_CONFIGURATION 0x09
113 #define USB_REQ_GET_INTERFACE 0x0A
114 #define USB_REQ_SET_INTERFACE 0x0B
115 #define USB_REQ_SYNCH_FRAME 0x0C
116
117 /*
118 * HID requests
119 */
120 #define USB_REQ_GET_REPORT 0x01
121 #define USB_REQ_GET_IDLE 0x02
122 #define USB_REQ_GET_PROTOCOL 0x03
123 #define USB_REQ_SET_REPORT 0x09
124 #define USB_REQ_SET_IDLE 0x0A
125 #define USB_REQ_SET_PROTOCOL 0x0B
126
127
128 #ifdef __KERNEL__
129
130 #include <linux/types.h>
131 #include <linux/ioctl.h>
132 #include <linux/version.h>
133 #include <linux/sched.h>
134 #include <linux/delay.h>
135 #include <linux/interrupt.h> /* for in_interrupt() */
136 #include <linux/config.h>
137 #include <linux/list.h>
138
139 #define USB_MAJOR 180
140
141 static __inline__ void wait_ms(unsigned int ms)
142 {
143 if(!in_interrupt()) {
144 current->state = TASK_UNINTERRUPTIBLE;
145 schedule_timeout(1 + ms * HZ / 1000);
146 }
147 else
148 mdelay(ms);
149 }
150
151 typedef struct {
152 __u8 requesttype;
153 __u8 request;
154 __u16 value;
155 __u16 index;
156 __u16 length;
157 } devrequest __attribute__ ((packed));
158
159 /*
160 * USB-status codes:
161 * USB_ST* maps to -E* and should go away in the future
162 */
163
164 #define USB_ST_NOERROR 0
165 #define USB_ST_CRC (-EILSEQ)
166 #define USB_ST_BITSTUFF (-EPROTO)
167 #define USB_ST_NORESPONSE (-ETIMEDOUT) /* device not responding/handshaking */
168 #define USB_ST_DATAOVERRUN (-EOVERFLOW)
169 #define USB_ST_DATAUNDERRUN (-EREMOTEIO)
170 #define USB_ST_BUFFEROVERRUN (-ECOMM)
171 #define USB_ST_BUFFERUNDERRUN (-ENOSR)
172 #define USB_ST_INTERNALERROR (-EPROTO) /* unknown error */
173 #define USB_ST_SHORT_PACKET (-EREMOTEIO)
174 #define USB_ST_PARTIAL_ERROR (-EXDEV) /* ISO transfer only partially completed */
175 #define USB_ST_URB_KILLED (-ENOENT) /* URB canceled by user */
176 #define USB_ST_URB_PENDING (-EINPROGRESS)
177 #define USB_ST_REMOVED (-ENODEV) /* device not existing or removed */
178 #define USB_ST_TIMEOUT (-ETIMEDOUT) /* communication timed out, also in urb->status**/
179 #define USB_ST_NOTSUPPORTED (-ENOSYS)
180 #define USB_ST_BANDWIDTH_ERROR (-ENOSPC) /* too much bandwidth used */
181 #define USB_ST_URB_INVALID_ERROR (-EINVAL) /* invalid value/transfer type */
182 #define USB_ST_URB_REQUEST_ERROR (-ENXIO) /* invalid endpoint */
183 #define USB_ST_STALL (-EPIPE) /* pipe stalled, also in urb->status*/
184
185 /*
186 * USB device number allocation bitmap. There's one bitmap
187 * per USB tree.
188 */
189 struct usb_devmap {
190 unsigned long devicemap[128 / (8*sizeof(unsigned long))];
191 };
192
193 #define USB_MAXBUS 64
194
195 struct usb_busmap {
196 unsigned long busmap[USB_MAXBUS / (8*sizeof(unsigned long))];
197 };
198
199 /*
200 * This is a USB device descriptor.
201 *
202 * USB device information
203 */
204
205 /* Everything but the endpoint maximums are aribtrary */
206 #define USB_MAXCONFIG 8
207 #define USB_ALTSETTINGALLOC 4
208 #define USB_MAXALTSETTING 128 /* Hard limit */
209 #define USB_MAXINTERFACES 32
210 #define USB_MAXENDPOINTS 32
211
212 /* All standard descriptors have these 2 fields in common */
213 struct usb_descriptor_header {
214 __u8 bLength;
215 __u8 bDescriptorType;
216 } __attribute__ ((packed));
217
218 /* Device descriptor */
219 struct usb_device_descriptor {
220 __u8 bLength;
221 __u8 bDescriptorType;
222 __u16 bcdUSB;
223 __u8 bDeviceClass;
224 __u8 bDeviceSubClass;
225 __u8 bDeviceProtocol;
226 __u8 bMaxPacketSize0;
227 __u16 idVendor;
228 __u16 idProduct;
229 __u16 bcdDevice;
230 __u8 iManufacturer;
231 __u8 iProduct;
232 __u8 iSerialNumber;
233 __u8 bNumConfigurations;
234 } __attribute__ ((packed));
235
236 /* Endpoint descriptor */
237 struct usb_endpoint_descriptor {
238 __u8 bLength __attribute__ ((packed));
239 __u8 bDescriptorType __attribute__ ((packed));
240 __u8 bEndpointAddress __attribute__ ((packed));
241 __u8 bmAttributes __attribute__ ((packed));
242 __u16 wMaxPacketSize __attribute__ ((packed));
243 __u8 bInterval __attribute__ ((packed));
244 __u8 bRefresh __attribute__ ((packed));
245 __u8 bSynchAddress __attribute__ ((packed));
246
247 unsigned char *extra; /* Extra descriptors */
248 int extralen;
249 };
250
251 /* Interface descriptor */
252 struct usb_interface_descriptor {
253 __u8 bLength __attribute__ ((packed));
254 __u8 bDescriptorType __attribute__ ((packed));
255 __u8 bInterfaceNumber __attribute__ ((packed));
256 __u8 bAlternateSetting __attribute__ ((packed));
257 __u8 bNumEndpoints __attribute__ ((packed));
258 __u8 bInterfaceClass __attribute__ ((packed));
259 __u8 bInterfaceSubClass __attribute__ ((packed));
260 __u8 bInterfaceProtocol __attribute__ ((packed));
261 __u8 iInterface __attribute__ ((packed));
262
263 struct usb_endpoint_descriptor *endpoint;
264
265 unsigned char *extra; /* Extra descriptors */
266 int extralen;
267 };
268
269 struct usb_interface {
270 struct usb_interface_descriptor *altsetting;
271
272 int act_altsetting; /* active alternate setting */
273 int num_altsetting; /* number of alternate settings */
274 int max_altsetting; /* total memory allocated */
275
276 struct usb_driver *driver; /* driver */
277 void *private_data;
278 };
279
280 /* Configuration descriptor information.. */
281 struct usb_config_descriptor {
282 __u8 bLength __attribute__ ((packed));
283 __u8 bDescriptorType __attribute__ ((packed));
284 __u16 wTotalLength __attribute__ ((packed));
285 __u8 bNumInterfaces __attribute__ ((packed));
286 __u8 bConfigurationValue __attribute__ ((packed));
287 __u8 iConfiguration __attribute__ ((packed));
288 __u8 bmAttributes __attribute__ ((packed));
289 __u8 MaxPower __attribute__ ((packed));
290
291 struct usb_interface *interface;
292
293 unsigned char *extra; /* Extra descriptors */
294 int extralen;
295 };
296
297 /* String descriptor */
298 struct usb_string_descriptor {
299 __u8 bLength;
300 __u8 bDescriptorType;
301 __u16 wData[1];
302 } __attribute__ ((packed));
303
304 struct usb_device;
305
306 /*
307 * Device table entry for "new style" table-driven USB drivers.
308 * User mode code can read these tables to choose which modules to load.
309 * Declare the table as __devinitdata, and as a MODULE_DEVICE_TABLE.
310 *
311 * With a device table provide bind() instead of probe(). Then the
312 * third bind() parameter will point to a matching entry from this
313 * table. (Null value reserved.)
314 *
315 * Terminate the driver's table with an all-zeroes entry.
316 * Init the fields you care about; zeroes are not used in comparisons.
317 */
318 #define USB_DEVICE_ID_MATCH_VENDOR 0x0001
319 #define USB_DEVICE_ID_MATCH_PRODUCT 0x0002
320 #define USB_DEVICE_ID_MATCH_DEV_LO 0x0004
321 #define USB_DEVICE_ID_MATCH_DEV_HI 0x0008
322 #define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010
323 #define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020
324 #define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040
325 #define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080
326 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
327 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
328
329 #define USB_DEVICE_ID_MATCH_DEVICE (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
330 #define USB_DEVICE_ID_MATCH_DEV_RANGE (USB_DEVICE_ID_MATCH_DEV_LO | USB_DEVICE_ID_MATCH_DEV_HI)
331 #define USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_RANGE)
332 #define USB_DEVICE_ID_MATCH_DEV_INFO \
333 (USB_DEVICE_ID_MATCH_DEV_CLASS | USB_DEVICE_ID_MATCH_DEV_SUBCLASS | USB_DEVICE_ID_MATCH_DEV_PROTOCOL)
334 #define USB_DEVICE_ID_MATCH_INT_INFO \
335 (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS | USB_DEVICE_ID_MATCH_INT_PROTOCOL)
336
337 /* Some useful macros */
338 #define USB_DEVICE(vend,prod) \
339 match_flags: USB_DEVICE_ID_MATCH_DEVICE, idVendor: (vend), idProduct: (prod)
340 #define USB_DEVICE_VER(vend,prod,lo,hi) \
341 match_flags: USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, idVendor: (vend), idProduct: (prod), bcdDevice_lo: (lo), bcdDevice_hi: (hi)
342 #define USB_DEVICE_INFO(cl,sc,pr) \
343 match_flags: USB_DEVICE_ID_MATCH_DEV_INFO, bDeviceClass: (cl), bDeviceSubClass: (sc), bDeviceProtocol: (pr)
344 #define USB_INTERFACE_INFO(cl,sc,pr) \
345 match_flags: USB_DEVICE_ID_MATCH_INT_INFO, bInterfaceClass: (cl), bInterfaceSubClass: (sc), bInterfaceProtocol: (pr)
346
347 struct usb_device_id {
348 /* This bitmask is used to determine which of the following fields
349 * are to be used for matching.
350 */
351 __u16 match_flags;
352
353 /*
354 * vendor/product codes are checked, if vendor is nonzero
355 * Range is for device revision (bcdDevice), inclusive;
356 * zero values here mean range isn't considered
357 */
358 __u16 idVendor;
359 __u16 idProduct;
360 __u16 bcdDevice_lo, bcdDevice_hi;
361
362 /*
363 * if device class != 0, these can be match criteria;
364 * but only if this bDeviceClass value is nonzero
365 */
366 __u8 bDeviceClass;
367 __u8 bDeviceSubClass;
368 __u8 bDeviceProtocol;
369
370 /*
371 * if interface class != 0, these can be match criteria;
372 * but only if this bInterfaceClass value is nonzero
373 */
374 __u8 bInterfaceClass;
375 __u8 bInterfaceSubClass;
376 __u8 bInterfaceProtocol;
377
378 /*
379 * for driver's use; not involved in driver matching.
380 */
381 unsigned long driver_info;
382 };
383
384 struct usb_driver {
385 const char *name;
386
387 void *(*probe)(
388 struct usb_device *dev, /* the device */
389 unsigned intf, /* what interface */
390 const struct usb_device_id *id /* from id_table */
391 );
392 void (*disconnect)(struct usb_device *, void *);
393
394 struct list_head driver_list;
395
396 struct file_operations *fops;
397 int minor;
398
399 struct semaphore serialize;
400
401 /* ioctl -- userspace apps can talk to drivers through usbdevfs */
402 int (*ioctl)(struct usb_device *dev, unsigned int code, void *buf);
403
404 /* support for "new-style" USB hotplugging
405 * binding policy can be driven from user mode too
406 */
407 const struct usb_device_id *id_table;
408
409 /* suspend before the bus suspends;
410 * disconnect or resume when the bus resumes */
411 // void (*suspend)(struct usb_device *dev);
412 // void (*resume)(struct usb_device *dev);
413 };
414
415 /*----------------------------------------------------------------------------*
416 * New USB Structures *
417 *----------------------------------------------------------------------------*/
418
419 /*
420 * urb->transfer_flags:
421 */
422 #define USB_DISABLE_SPD 0x0001
423 #define USB_ISO_ASAP 0x0002
424 #define USB_ASYNC_UNLINK 0x0008
425 #define USB_QUEUE_BULK 0x0010
426 #define USB_NO_FSBR 0x0020
427 #define USB_TIMEOUT_KILLED 0x1000 // only set by HCD!
428
429 typedef struct
430 {
431 unsigned int offset;
432 unsigned int length; // expected length
433 unsigned int actual_length;
434 unsigned int status;
435 } iso_packet_descriptor_t, *piso_packet_descriptor_t;
436
437 struct urb;
438 typedef void (*usb_complete_t)(struct urb *);
439
440 typedef struct urb
441 {
442 spinlock_t lock; // lock for the URB
443 void *hcpriv; // private data for host controller
444 struct list_head urb_list; // list pointer to all active urbs
445 struct urb *next; // pointer to next URB
446 struct usb_device *dev; // pointer to associated USB device
447 unsigned int pipe; // pipe information
448 int status; // returned status
449 unsigned int transfer_flags; // USB_DISABLE_SPD | USB_ISO_ASAP | etc.
450 void *transfer_buffer; // associated data buffer
451 int transfer_buffer_length; // data buffer length
452 int actual_length; // actual data buffer length
453 int bandwidth; // bandwidth for this transfer request (INT or ISO)
454 unsigned char *setup_packet; // setup packet (control only)
455 //
456 int start_frame; // start frame (iso/irq only)
457 int number_of_packets; // number of packets in this request (iso)
458 int interval; // polling interval (irq only)
459 int error_count; // number of errors in this transfer (iso only)
460 int timeout; // timeout (in jiffies)
461 //
462 void *context; // context for completion routine
463 usb_complete_t complete; // pointer to completion routine
464 //
465 iso_packet_descriptor_t iso_frame_desc[0];
466 } urb_t, *purb_t;
467
468 #define FILL_CONTROL_URB(a,aa,b,c,d,e,f,g) \
469 do {\
470 spin_lock_init(&(a)->lock);\
471 (a)->dev=aa;\
472 (a)->pipe=b;\
473 (a)->setup_packet=c;\
474 (a)->transfer_buffer=d;\
475 (a)->transfer_buffer_length=e;\
476 (a)->complete=f;\
477 (a)->context=g;\
478 } while (0)
479
480 #define FILL_BULK_URB(a,aa,b,c,d,e,f) \
481 do {\
482 spin_lock_init(&(a)->lock);\
483 (a)->dev=aa;\
484 (a)->pipe=b;\
485 (a)->transfer_buffer=c;\
486 (a)->transfer_buffer_length=d;\
487 (a)->complete=e;\
488 (a)->context=f;\
489 } while (0)
490
491 #define FILL_INT_URB(a,aa,b,c,d,e,f,g) \
492 do {\
493 spin_lock_init(&(a)->lock);\
494 (a)->dev=aa;\
495 (a)->pipe=b;\
496 (a)->transfer_buffer=c;\
497 (a)->transfer_buffer_length=d;\
498 (a)->complete=e;\
499 (a)->context=f;\
500 (a)->interval=g;\
501 (a)->start_frame=-1;\
502 } while (0)
503
504 #define FILL_CONTROL_URB_TO(a,aa,b,c,d,e,f,g,h) \
505 do {\
506 spin_lock_init(&(a)->lock);\
507 (a)->dev=aa;\
508 (a)->pipe=b;\
509 (a)->setup_packet=c;\
510 (a)->transfer_buffer=d;\
511 (a)->transfer_buffer_length=e;\
512 (a)->complete=f;\
513 (a)->context=g;\
514 (a)->timeout=h;\
515 } while (0)
516
517 #define FILL_BULK_URB_TO(a,aa,b,c,d,e,f,g) \
518 do {\
519 spin_lock_init(&(a)->lock);\
520 (a)->dev=aa;\
521 (a)->pipe=b;\
522 (a)->transfer_buffer=c;\
523 (a)->transfer_buffer_length=d;\
524 (a)->complete=e;\
525 (a)->context=f;\
526 (a)->timeout=g;\
527 } while (0)
528
529 purb_t usb_alloc_urb(int iso_packets);
530 void usb_free_urb (purb_t purb);
531 int usb_submit_urb(purb_t purb);
532 int usb_unlink_urb(purb_t purb);
533 int usb_internal_control_msg(struct usb_device *usb_dev, unsigned int pipe, devrequest *cmd, void *data, int len, int timeout);
534 int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout);
535
536 /*-------------------------------------------------------------------*
537 * SYNCHRONOUS CALL SUPPORT *
538 *-------------------------------------------------------------------*/
539
540 typedef struct
541 {
542 wait_queue_head_t *wakeup;
543
544 void* stuff;
545 /* more to follow */
546 } api_wrapper_data;
547
548 /* -------------------------------------------------------------------------- */
549
550 struct usb_operations {
551 int (*allocate)(struct usb_device *);
552 int (*deallocate)(struct usb_device *);
553 int (*get_frame_number) (struct usb_device *usb_dev);
554 int (*submit_urb) (struct urb* purb);
555 int (*unlink_urb) (struct urb* purb);
556 };
557
558 /*
559 * Allocated per bus we have
560 */
561 struct usb_bus {
562 int busnum; /* Bus number (in order of reg) */
563
564 struct usb_devmap devmap; /* Device map */
565 struct usb_operations *op; /* Operations (specific to the HC) */
566 struct usb_device *root_hub; /* Root hub */
567 struct list_head bus_list;
568 void *hcpriv; /* Host Controller private data */
569
570 int bandwidth_allocated; /* on this Host Controller; */
571 /* applies to Int. and Isoc. pipes; */
572 /* measured in microseconds/frame; */
573 /* range is 0..900, where 900 = */
574 /* 90% of a 1-millisecond frame */
575 int bandwidth_int_reqs; /* number of Interrupt requesters */
576 int bandwidth_isoc_reqs; /* number of Isoc. requesters */
577
578 /* usbdevfs inode list */
579 struct list_head inodes;
580 };
581
582 #define USB_MAXCHILDREN (16) /* This is arbitrary */
583
584 struct usb_device {
585 int devnum; /* Device number on USB bus */
586 int slow; /* Slow device? */
587
588 atomic_t refcnt; /* Reference count */
589
590 unsigned int toggle[2]; /* one bit for each endpoint ([0] = IN, [1] = OUT) */
591 unsigned int halted[2]; /* endpoint halts; one bit per endpoint # & direction; */
592 /* [0] = IN, [1] = OUT */
593 int epmaxpacketin[16]; /* INput endpoint specific maximums */
594 int epmaxpacketout[16]; /* OUTput endpoint specific maximums */
595
596 struct usb_device *parent;
597 struct usb_bus *bus; /* Bus we're part of */
598
599 struct usb_device_descriptor descriptor;/* Descriptor */
600 struct usb_config_descriptor *config; /* All of the configs */
601 struct usb_config_descriptor *actconfig;/* the active configuration */
602
603 char **rawdescriptors; /* Raw descriptors for each config */
604
605 int have_langid; /* whether string_langid is valid yet */
606 int string_langid; /* language ID for strings */
607
608 void *hcpriv; /* Host Controller private data */
609
610 /* usbdevfs inode list */
611 struct list_head inodes;
612 struct list_head filelist;
613
614 /*
615 * Child devices - these can be either new devices
616 * (if this is a hub device), or different instances
617 * of this same device.
618 *
619 * Each instance needs its own set of data structures.
620 */
621
622 int maxchild; /* Number of ports if hub */
623 struct usb_device *children[USB_MAXCHILDREN];
624 };
625
626 extern struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum);
627 extern struct usb_endpoint_descriptor *usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum);
628
629 extern int usb_register(struct usb_driver *);
630 extern void usb_deregister(struct usb_driver *);
631 extern void usb_scan_devices(void);
632
633 /* used these for multi-interface device registration */
634 extern void usb_driver_claim_interface(struct usb_driver *driver, struct usb_interface *iface, void* priv);
635 extern int usb_interface_claimed(struct usb_interface *iface);
636 extern void usb_driver_release_interface(struct usb_driver *driver, struct usb_interface *iface);
637 const struct usb_device_id *usb_match_id(struct usb_device *dev,
638 struct usb_interface *interface,
639 const struct usb_device_id *id);
640
641 extern struct usb_bus *usb_alloc_bus(struct usb_operations *);
642 extern void usb_free_bus(struct usb_bus *);
643 extern void usb_register_bus(struct usb_bus *);
644 extern void usb_deregister_bus(struct usb_bus *);
645
646 extern struct usb_device *usb_alloc_dev(struct usb_device *parent, struct usb_bus *);
647 extern void usb_free_dev(struct usb_device *);
648 extern void usb_inc_dev_use(struct usb_device *);
649 #define usb_dec_dev_use usb_free_dev
650
651 extern int usb_check_bandwidth (struct usb_device *dev, struct urb *urb);
652 extern void usb_claim_bandwidth (struct usb_device *dev, struct urb *urb, int bustime, int isoc);
653 extern void usb_release_bandwidth(struct usb_device *dev, struct urb *urb, int isoc);
654
655 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 requesttype, __u16 value, __u16 index, void *data, __u16 size, int timeout);
656
657 extern int usb_root_hub_string(int id, int serial, char *type, __u8 *data, int len);
658 extern void usb_connect(struct usb_device *dev);
659 extern void usb_disconnect(struct usb_device **);
660
661 extern void usb_destroy_configuration(struct usb_device *dev);
662
663 int usb_get_current_frame_number (struct usb_device *usb_dev);
664
665 /*
666 * Calling this entity a "pipe" is glorifying it. A USB pipe
667 * is something embarrassingly simple: it basically consists
668 * of the following information:
669 * - device number (7 bits)
670 * - endpoint number (4 bits)
671 * - current Data0/1 state (1 bit)
672 * - direction (1 bit)
673 * - speed (1 bit)
674 * - max packet size (2 bits: 8, 16, 32 or 64) [Historical; now gone.]
675 * - pipe type (2 bits: control, interrupt, bulk, isochronous)
676 *
677 * That's 18 bits. Really. Nothing more. And the USB people have
678 * documented these eighteen bits as some kind of glorious
679 * virtual data structure.
680 *
681 * Let's not fall in that trap. We'll just encode it as a simple
682 * unsigned int. The encoding is:
683 *
684 * - max size: bits 0-1 (00 = 8, 01 = 16, 10 = 32, 11 = 64) [Historical; now gone.]
685 * - direction: bit 7 (0 = Host-to-Device [Out], 1 = Device-to-Host [In])
686 * - device: bits 8-14
687 * - endpoint: bits 15-18
688 * - Data0/1: bit 19
689 * - speed: bit 26 (0 = Full, 1 = Low Speed)
690 * - pipe type: bits 30-31 (00 = isochronous, 01 = interrupt, 10 = control, 11 = bulk)
691 *
692 * Why? Because it's arbitrary, and whatever encoding we select is really
693 * up to us. This one happens to share a lot of bit positions with the UHCI
694 * specification, so that much of the uhci driver can just mask the bits
695 * appropriately.
696 */
697
698 #define PIPE_ISOCHRONOUS 0
699 #define PIPE_INTERRUPT 1
700 #define PIPE_CONTROL 2
701 #define PIPE_BULK 3
702
703 #define usb_maxpacket(dev, pipe, out) (out \
704 ? (dev)->epmaxpacketout[usb_pipeendpoint(pipe)] \
705 : (dev)->epmaxpacketin [usb_pipeendpoint(pipe)] )
706 #define usb_packetid(pipe) (((pipe) & USB_DIR_IN) ? USB_PID_IN : USB_PID_OUT)
707
708 #define usb_pipeout(pipe) ((((pipe) >> 7) & 1) ^ 1)
709 #define usb_pipein(pipe) (((pipe) >> 7) & 1)
710 #define usb_pipedevice(pipe) (((pipe) >> 8) & 0x7f)
711 #define usb_pipe_endpdev(pipe) (((pipe) >> 8) & 0x7ff)
712 #define usb_pipeendpoint(pipe) (((pipe) >> 15) & 0xf)
713 #define usb_pipedata(pipe) (((pipe) >> 19) & 1)
714 #define usb_pipeslow(pipe) (((pipe) >> 26) & 1)
715 #define usb_pipetype(pipe) (((pipe) >> 30) & 3)
716 #define usb_pipeisoc(pipe) (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
717 #define usb_pipeint(pipe) (usb_pipetype((pipe)) == PIPE_INTERRUPT)
718 #define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL)
719 #define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK)
720
721 #define PIPE_DEVEP_MASK 0x0007ff00
722
723 /* The D0/D1 toggle bits */
724 #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1)
725 #define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << ep))
726 #define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = ((dev)->toggle[out] & ~(1 << ep)) | ((bit) << ep))
727
728 /* Endpoint halt control/status */
729 #define usb_endpoint_out(ep_dir) (((ep_dir >> 7) & 1) ^ 1)
730 #define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
731 #define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
732 #define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
733
734 static inline unsigned int __create_pipe(struct usb_device *dev, unsigned int endpoint)
735 {
736 return (dev->devnum << 8) | (endpoint << 15) | (dev->slow << 26);
737 }
738
739 static inline unsigned int __default_pipe(struct usb_device *dev)
740 {
741 return (dev->slow << 26);
742 }
743
744 /* Create various pipes... */
745 #define usb_sndctrlpipe(dev,endpoint) ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint))
746 #define usb_rcvctrlpipe(dev,endpoint) ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
747 #define usb_sndisocpipe(dev,endpoint) ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint))
748 #define usb_rcvisocpipe(dev,endpoint) ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
749 #define usb_sndbulkpipe(dev,endpoint) ((PIPE_BULK << 30) | __create_pipe(dev,endpoint))
750 #define usb_rcvbulkpipe(dev,endpoint) ((PIPE_BULK << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
751 #define usb_sndintpipe(dev,endpoint) ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint))
752 #define usb_rcvintpipe(dev,endpoint) ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
753 #define usb_snddefctrl(dev) ((PIPE_CONTROL << 30) | __default_pipe(dev))
754 #define usb_rcvdefctrl(dev) ((PIPE_CONTROL << 30) | __default_pipe(dev) | USB_DIR_IN)
755
756 /*
757 * Send and receive control messages..
758 */
759 int usb_new_device(struct usb_device *dev);
760 int usb_reset_device(struct usb_device *dev);
761 int usb_set_address(struct usb_device *dev);
762 int usb_get_descriptor(struct usb_device *dev, unsigned char desctype,
763 unsigned char descindex, void *buf, int size);
764 int usb_get_class_descriptor(struct usb_device *dev, int ifnum, unsigned char desctype,
765 unsigned char descindex, void *buf, int size);
766 int usb_get_device_descriptor(struct usb_device *dev);
767 int __usb_get_extra_descriptor(char *buffer, unsigned size, unsigned char type, void **ptr);
768 int usb_get_status(struct usb_device *dev, int type, int target, void *data);
769 int usb_get_configuration(struct usb_device *dev);
770 int usb_get_protocol(struct usb_device *dev, int ifnum);
771 int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol);
772 int usb_set_interface(struct usb_device *dev, int ifnum, int alternate);
773 int usb_set_idle(struct usb_device *dev, int ifnum, int duration, int report_id);
774 int usb_set_configuration(struct usb_device *dev, int configuration);
775 int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type,
776 unsigned char id, void *buf, int size);
777 int usb_set_report(struct usb_device *dev, int ifnum, unsigned char type,
778 unsigned char id, void *buf, int size);
779 int usb_string(struct usb_device *dev, int index, char *buf, size_t size);
780 int usb_clear_halt(struct usb_device *dev, int pipe);
781 void usb_set_maxpacket(struct usb_device *dev);
782
783 #define usb_get_extra_descriptor(ifpoint,type,ptr)\
784 __usb_get_extra_descriptor((ifpoint)->extra,(ifpoint)->extralen,type,(void**)ptr)
785
786 /*
787 * Some USB bandwidth allocation constants.
788 */
789 #define BW_HOST_DELAY 1000L /* nanoseconds */
790 #define BW_HUB_LS_SETUP 333L /* nanoseconds */
791 /* 4 full-speed bit times (est.) */
792
793 #define FRAME_TIME_BITS 12000L /* frame = 1 millisecond */
794 #define FRAME_TIME_MAX_BITS_ALLOC (90L * FRAME_TIME_BITS / 100L)
795 #define FRAME_TIME_USECS 1000L
796 #define FRAME_TIME_MAX_USECS_ALLOC (90L * FRAME_TIME_USECS / 100L)
797
798 #define BitTime(bytecount) (7 * 8 * bytecount / 6) /* with integer truncation */
799 /* Trying not to use worst-case bit-stuffing
800 of (7/6 * 8 * bytecount) = 9.33 * bytecount */
801 /* bytecount = data payload byte count */
802
803 #define NS_TO_US(ns) ((ns + 500L) / 1000L)
804 /* convert & round nanoseconds to microseconds */
805
806 /*
807 * Debugging helpers..
808 */
809 void usb_show_device_descriptor(struct usb_device_descriptor *);
810 void usb_show_config_descriptor(struct usb_config_descriptor *);
811 void usb_show_interface_descriptor(struct usb_interface_descriptor *);
812 void usb_show_endpoint_descriptor(struct usb_endpoint_descriptor *);
813 void usb_show_device(struct usb_device *);
814 void usb_show_string(struct usb_device *dev, char *id, int index);
815
816 #ifdef DEBUG
817 #define dbg(format, arg...) printk(KERN_DEBUG __FILE__ ": " format "\n" , ## arg)
818 #else
819 #define dbg(format, arg...) do {} while (0)
820 #endif
821 #define err(format, arg...) printk(KERN_ERR __FILE__ ": " format "\n" , ## arg)
822 #define info(format, arg...) printk(KERN_INFO __FILE__ ": " format "\n" , ## arg)
823 #define warn(format, arg...) printk(KERN_WARNING __FILE__ ": " format "\n" , ## arg)
824
825
826 /*
827 * bus and driver list
828 */
829
830 extern struct list_head usb_driver_list;
831 extern struct list_head usb_bus_list;
832
833 /*
834 * USB device fs stuff
835 */
836
837 #ifdef CONFIG_USB_DEVICEFS
838
839 /*
840 * these are expected to be called from the USB core/hub thread
841 * with the kernel lock held
842 */
843 extern void usbdevfs_add_bus(struct usb_bus *bus);
844 extern void usbdevfs_remove_bus(struct usb_bus *bus);
845 extern void usbdevfs_add_device(struct usb_device *dev);
846 extern void usbdevfs_remove_device(struct usb_device *dev);
847
848 extern int usbdevfs_init(void);
849 extern void usbdevfs_cleanup(void);
850
851 #else /* CONFIG_USB_DEVICEFS */
852
853 static inline void usbdevfs_add_bus(struct usb_bus *bus) {}
854 static inline void usbdevfs_remove_bus(struct usb_bus *bus) {}
855 static inline void usbdevfs_add_device(struct usb_device *dev) {}
856 static inline void usbdevfs_remove_device(struct usb_device *dev) {}
857
858 static inline int usbdevfs_init(void) { return 0; }
859 static inline void usbdevfs_cleanup(void) { }
860
861 #endif /* CONFIG_USB_DEVICEFS */
862
863 #endif /* __KERNEL__ */
864
865 #endif
866
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.