- Alan Cox: synch. PA-RISC arch and bitops cleanups
[davej-history.git] / include / linux / usb.h
blob42f0011cdc6e8fd9f1f665f4282da05455c3ec63
1 #ifndef __LINUX_USB_H
2 #define __LINUX_USB_H
4 /* USB constants */
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
22 * USB types
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)
30 * USB recipients
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
39 * USB directions
41 #define USB_DIR_OUT 0
42 #define USB_DIR_IN 0x80
45 * Descriptor types
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
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)
59 * Descriptor sizes per descriptor type
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
70 * Endpoints
72 #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
73 #define USB_ENDPOINT_DIR_MASK 0x80
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
82 * USB Packet IDs (PIDs)
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 */
103 * Standard requests
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
118 * HID requests
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
128 #ifdef __KERNEL__
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>
139 #define USB_MAJOR 180
141 static __inline__ void wait_ms(unsigned int ms)
143 if(!in_interrupt()) {
144 current->state = TASK_UNINTERRUPTIBLE;
145 schedule_timeout(1 + ms * HZ / 1000);
147 else
148 mdelay(ms);
151 typedef struct {
152 __u8 requesttype;
153 __u8 request;
154 __u16 value;
155 __u16 index;
156 __u16 length;
157 } devrequest __attribute__ ((packed));
160 * USB-status codes:
161 * USB_ST* maps to -E* and should go away in the future
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*/
186 * USB device number allocation bitmap. There's one bitmap
187 * per USB tree.
189 struct usb_devmap {
190 unsigned long devicemap[128 / (8*sizeof(unsigned long))];
193 #define USB_MAXBUS 64
195 struct usb_busmap {
196 unsigned long busmap[USB_MAXBUS / (8*sizeof(unsigned long))];
200 * This is a USB device descriptor.
202 * USB device information
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
212 /* All standard descriptors have these 2 fields in common */
213 struct usb_descriptor_header {
214 __u8 bLength;
215 __u8 bDescriptorType;
216 } __attribute__ ((packed));
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));
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));
247 unsigned char *extra; /* Extra descriptors */
248 int extralen;
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));
263 struct usb_endpoint_descriptor *endpoint;
265 unsigned char *extra; /* Extra descriptors */
266 int extralen;
269 struct usb_interface {
270 struct usb_interface_descriptor *altsetting;
272 int act_altsetting; /* active alternate setting */
273 int num_altsetting; /* number of alternate settings */
274 int max_altsetting; /* total memory allocated */
276 struct usb_driver *driver; /* driver */
277 void *private_data;
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));
291 struct usb_interface *interface;
293 unsigned char *extra; /* Extra descriptors */
294 int extralen;
297 /* String descriptor */
298 struct usb_string_descriptor {
299 __u8 bLength;
300 __u8 bDescriptorType;
301 __u16 wData[1];
302 } __attribute__ ((packed));
304 struct usb_device;
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.
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.)
315 * Terminate the driver's table with an all-zeroes entry.
316 * Init the fields you care about; zeroes are not used in comparisons.
318 struct usb_device_id {
320 * vendor/product codes are checked, if vendor is nonzero
321 * Range is for device revision (bcdDevice), inclusive;
322 * zero values here mean range isn't considered
324 __u16 idVendor;
325 __u16 idProduct;
326 __u16 bcdDevice_lo, bcdDevice_hi;
329 * if device class != 0, these can be match criteria;
330 * but only if this bDeviceClass value is nonzero
332 __u8 bDeviceClass;
333 __u8 bDeviceSubClass;
334 __u8 bDeviceProtocol;
337 * if interface class != 0, these can be match criteria;
338 * but only if this bInterfaceClass value is nonzero
340 __u8 bInterfaceClass;
341 __u8 bInterfaceSubClass;
342 __u8 bInterfaceProtocol;
345 * for driver's use; not involved in driver matching.
347 unsigned long driver_info;
350 struct usb_driver {
351 const char *name;
353 void *(*probe)(
354 struct usb_device *dev, /* the device */
355 unsigned intf, /* what interface */
356 const struct usb_device_id *id /* from id_table */
358 void (*disconnect)(struct usb_device *, void *);
360 struct list_head driver_list;
362 struct file_operations *fops;
363 int minor;
365 struct semaphore serialize;
367 /* ioctl -- userspace apps can talk to drivers through usbdevfs */
368 int (*ioctl)(struct usb_device *dev, unsigned int code, void *buf);
370 /* support for "new-style" USB hotplugging
371 * binding policy can be driven from user mode too
373 const struct usb_device_id *id_table;
375 /* suspend before the bus suspends;
376 * disconnect or resume when the bus resumes */
377 // void (*suspend)(struct usb_device *dev);
378 // void (*resume)(struct usb_device *dev);
381 /*----------------------------------------------------------------------------*
382 * New USB Structures *
383 *----------------------------------------------------------------------------*/
386 * urb->transfer_flags:
388 #define USB_DISABLE_SPD 0x0001
389 #define USB_ISO_ASAP 0x0002
390 #define USB_ASYNC_UNLINK 0x0008
391 #define USB_QUEUE_BULK 0x0010
392 #define USB_NO_FSBR 0x0020
393 #define USB_TIMEOUT_KILLED 0x1000 // only set by HCD!
395 typedef struct
397 unsigned int offset;
398 unsigned int length; // expected length
399 unsigned int actual_length;
400 unsigned int status;
401 } iso_packet_descriptor_t, *piso_packet_descriptor_t;
403 struct urb;
404 typedef void (*usb_complete_t)(struct urb *);
406 typedef struct urb
408 spinlock_t lock; // lock for the URB
409 void *hcpriv; // private data for host controller
410 struct list_head urb_list; // list pointer to all active urbs
411 struct urb *next; // pointer to next URB
412 struct usb_device *dev; // pointer to associated USB device
413 unsigned int pipe; // pipe information
414 int status; // returned status
415 unsigned int transfer_flags; // USB_DISABLE_SPD | USB_ISO_ASAP | etc.
416 void *transfer_buffer; // associated data buffer
417 int transfer_buffer_length; // data buffer length
418 int actual_length; // actual data buffer length
419 int bandwidth; // bandwidth for this transfer request (INT or ISO)
420 unsigned char *setup_packet; // setup packet (control only)
422 int start_frame; // start frame (iso/irq only)
423 int number_of_packets; // number of packets in this request (iso)
424 int interval; // polling interval (irq only)
425 int error_count; // number of errors in this transfer (iso only)
426 int timeout; // timeout (in jiffies)
428 void *context; // context for completion routine
429 usb_complete_t complete; // pointer to completion routine
431 iso_packet_descriptor_t iso_frame_desc[0];
432 } urb_t, *purb_t;
434 #define FILL_CONTROL_URB(a,aa,b,c,d,e,f,g) \
435 do {\
436 spin_lock_init(&(a)->lock);\
437 (a)->dev=aa;\
438 (a)->pipe=b;\
439 (a)->setup_packet=c;\
440 (a)->transfer_buffer=d;\
441 (a)->transfer_buffer_length=e;\
442 (a)->complete=f;\
443 (a)->context=g;\
444 } while (0)
446 #define FILL_BULK_URB(a,aa,b,c,d,e,f) \
447 do {\
448 spin_lock_init(&(a)->lock);\
449 (a)->dev=aa;\
450 (a)->pipe=b;\
451 (a)->transfer_buffer=c;\
452 (a)->transfer_buffer_length=d;\
453 (a)->complete=e;\
454 (a)->context=f;\
455 } while (0)
457 #define FILL_INT_URB(a,aa,b,c,d,e,f,g) \
458 do {\
459 spin_lock_init(&(a)->lock);\
460 (a)->dev=aa;\
461 (a)->pipe=b;\
462 (a)->transfer_buffer=c;\
463 (a)->transfer_buffer_length=d;\
464 (a)->complete=e;\
465 (a)->context=f;\
466 (a)->interval=g;\
467 (a)->start_frame=-1;\
468 } while (0)
470 #define FILL_CONTROL_URB_TO(a,aa,b,c,d,e,f,g,h) \
471 do {\
472 spin_lock_init(&(a)->lock);\
473 (a)->dev=aa;\
474 (a)->pipe=b;\
475 (a)->setup_packet=c;\
476 (a)->transfer_buffer=d;\
477 (a)->transfer_buffer_length=e;\
478 (a)->complete=f;\
479 (a)->context=g;\
480 (a)->timeout=h;\
481 } while (0)
483 #define FILL_BULK_URB_TO(a,aa,b,c,d,e,f,g) \
484 do {\
485 spin_lock_init(&(a)->lock);\
486 (a)->dev=aa;\
487 (a)->pipe=b;\
488 (a)->transfer_buffer=c;\
489 (a)->transfer_buffer_length=d;\
490 (a)->complete=e;\
491 (a)->context=f;\
492 (a)->timeout=g;\
493 } while (0)
495 purb_t usb_alloc_urb(int iso_packets);
496 void usb_free_urb (purb_t purb);
497 int usb_submit_urb(purb_t purb);
498 int usb_unlink_urb(purb_t purb);
499 int usb_internal_control_msg(struct usb_device *usb_dev, unsigned int pipe, devrequest *cmd, void *data, int len, int timeout);
500 int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout);
502 /*-------------------------------------------------------------------*
503 * SYNCHRONOUS CALL SUPPORT *
504 *-------------------------------------------------------------------*/
506 typedef struct
508 wait_queue_head_t *wakeup;
510 void* stuff;
511 /* more to follow */
512 } api_wrapper_data;
514 /* -------------------------------------------------------------------------- */
516 struct usb_operations {
517 int (*allocate)(struct usb_device *);
518 int (*deallocate)(struct usb_device *);
519 int (*get_frame_number) (struct usb_device *usb_dev);
520 int (*submit_urb) (struct urb* purb);
521 int (*unlink_urb) (struct urb* purb);
525 * Allocated per bus we have
527 struct usb_bus {
528 int busnum; /* Bus number (in order of reg) */
530 struct usb_devmap devmap; /* Device map */
531 struct usb_operations *op; /* Operations (specific to the HC) */
532 struct usb_device *root_hub; /* Root hub */
533 struct list_head bus_list;
534 void *hcpriv; /* Host Controller private data */
536 int bandwidth_allocated; /* on this Host Controller; */
537 /* applies to Int. and Isoc. pipes; */
538 /* measured in microseconds/frame; */
539 /* range is 0..900, where 900 = */
540 /* 90% of a 1-millisecond frame */
541 int bandwidth_int_reqs; /* number of Interrupt requesters */
542 int bandwidth_isoc_reqs; /* number of Isoc. requesters */
544 /* usbdevfs inode list */
545 struct list_head inodes;
548 #define USB_MAXCHILDREN (8) /* This is arbitrary */
550 struct usb_device {
551 int devnum; /* Device number on USB bus */
552 int slow; /* Slow device? */
554 atomic_t refcnt; /* Reference count */
556 unsigned int toggle[2]; /* one bit for each endpoint ([0] = IN, [1] = OUT) */
557 unsigned int halted[2]; /* endpoint halts; one bit per endpoint # & direction; */
558 /* [0] = IN, [1] = OUT */
559 int epmaxpacketin[16]; /* INput endpoint specific maximums */
560 int epmaxpacketout[16]; /* OUTput endpoint specific maximums */
562 struct usb_device *parent;
563 struct usb_bus *bus; /* Bus we're part of */
565 struct usb_device_descriptor descriptor;/* Descriptor */
566 struct usb_config_descriptor *config; /* All of the configs */
567 struct usb_config_descriptor *actconfig;/* the active configuration */
569 char **rawdescriptors; /* Raw descriptors for each config */
571 int have_langid; /* whether string_langid is valid yet */
572 int string_langid; /* language ID for strings */
574 void *hcpriv; /* Host Controller private data */
576 /* usbdevfs inode list */
577 struct list_head inodes;
578 struct list_head filelist;
581 * Child devices - these can be either new devices
582 * (if this is a hub device), or different instances
583 * of this same device.
585 * Each instance needs its own set of data structures.
588 int maxchild; /* Number of ports if hub */
589 struct usb_device *children[USB_MAXCHILDREN];
592 extern struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum);
593 extern struct usb_endpoint_descriptor *usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum);
595 extern int usb_register(struct usb_driver *);
596 extern void usb_deregister(struct usb_driver *);
597 extern void usb_scan_devices(void);
599 /* used these for multi-interface device registration */
600 extern void usb_driver_claim_interface(struct usb_driver *driver, struct usb_interface *iface, void* priv);
601 extern int usb_interface_claimed(struct usb_interface *iface);
602 extern void usb_driver_release_interface(struct usb_driver *driver, struct usb_interface *iface);
603 const struct usb_device_id *usb_match_id(struct usb_device *dev,
604 struct usb_interface *interface,
605 const struct usb_device_id *id);
607 extern struct usb_bus *usb_alloc_bus(struct usb_operations *);
608 extern void usb_free_bus(struct usb_bus *);
609 extern void usb_register_bus(struct usb_bus *);
610 extern void usb_deregister_bus(struct usb_bus *);
612 extern struct usb_device *usb_alloc_dev(struct usb_device *parent, struct usb_bus *);
613 extern void usb_free_dev(struct usb_device *);
614 extern void usb_inc_dev_use(struct usb_device *);
615 #define usb_dec_dev_use usb_free_dev
617 extern int usb_check_bandwidth (struct usb_device *dev, struct urb *urb);
618 extern void usb_claim_bandwidth (struct usb_device *dev, struct urb *urb, int bustime, int isoc);
619 extern void usb_release_bandwidth(struct usb_device *dev, struct urb *urb, int isoc);
621 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);
623 extern int usb_root_hub_string(int id, int serial, char *type, __u8 *data, int len);
624 extern void usb_connect(struct usb_device *dev);
625 extern void usb_disconnect(struct usb_device **);
627 extern void usb_destroy_configuration(struct usb_device *dev);
629 int usb_get_current_frame_number (struct usb_device *usb_dev);
632 * Calling this entity a "pipe" is glorifying it. A USB pipe
633 * is something embarrassingly simple: it basically consists
634 * of the following information:
635 * - device number (7 bits)
636 * - endpoint number (4 bits)
637 * - current Data0/1 state (1 bit)
638 * - direction (1 bit)
639 * - speed (1 bit)
640 * - max packet size (2 bits: 8, 16, 32 or 64) [Historical; now gone.]
641 * - pipe type (2 bits: control, interrupt, bulk, isochronous)
643 * That's 18 bits. Really. Nothing more. And the USB people have
644 * documented these eighteen bits as some kind of glorious
645 * virtual data structure.
647 * Let's not fall in that trap. We'll just encode it as a simple
648 * unsigned int. The encoding is:
650 * - max size: bits 0-1 (00 = 8, 01 = 16, 10 = 32, 11 = 64) [Historical; now gone.]
651 * - direction: bit 7 (0 = Host-to-Device [Out], 1 = Device-to-Host [In])
652 * - device: bits 8-14
653 * - endpoint: bits 15-18
654 * - Data0/1: bit 19
655 * - speed: bit 26 (0 = Full, 1 = Low Speed)
656 * - pipe type: bits 30-31 (00 = isochronous, 01 = interrupt, 10 = control, 11 = bulk)
658 * Why? Because it's arbitrary, and whatever encoding we select is really
659 * up to us. This one happens to share a lot of bit positions with the UHCI
660 * specification, so that much of the uhci driver can just mask the bits
661 * appropriately.
664 #define PIPE_ISOCHRONOUS 0
665 #define PIPE_INTERRUPT 1
666 #define PIPE_CONTROL 2
667 #define PIPE_BULK 3
669 #define usb_maxpacket(dev, pipe, out) (out \
670 ? (dev)->epmaxpacketout[usb_pipeendpoint(pipe)] \
671 : (dev)->epmaxpacketin [usb_pipeendpoint(pipe)] )
672 #define usb_packetid(pipe) (((pipe) & USB_DIR_IN) ? USB_PID_IN : USB_PID_OUT)
674 #define usb_pipeout(pipe) ((((pipe) >> 7) & 1) ^ 1)
675 #define usb_pipein(pipe) (((pipe) >> 7) & 1)
676 #define usb_pipedevice(pipe) (((pipe) >> 8) & 0x7f)
677 #define usb_pipe_endpdev(pipe) (((pipe) >> 8) & 0x7ff)
678 #define usb_pipeendpoint(pipe) (((pipe) >> 15) & 0xf)
679 #define usb_pipedata(pipe) (((pipe) >> 19) & 1)
680 #define usb_pipeslow(pipe) (((pipe) >> 26) & 1)
681 #define usb_pipetype(pipe) (((pipe) >> 30) & 3)
682 #define usb_pipeisoc(pipe) (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
683 #define usb_pipeint(pipe) (usb_pipetype((pipe)) == PIPE_INTERRUPT)
684 #define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL)
685 #define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK)
687 #define PIPE_DEVEP_MASK 0x0007ff00
689 /* The D0/D1 toggle bits */
690 #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1)
691 #define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << ep))
692 #define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = ((dev)->toggle[out] & ~(1 << ep)) | ((bit) << ep))
694 /* Endpoint halt control/status */
695 #define usb_endpoint_out(ep_dir) (((ep_dir >> 7) & 1) ^ 1)
696 #define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
697 #define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
698 #define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
700 static inline unsigned int __create_pipe(struct usb_device *dev, unsigned int endpoint)
702 return (dev->devnum << 8) | (endpoint << 15) | (dev->slow << 26);
705 static inline unsigned int __default_pipe(struct usb_device *dev)
707 return (dev->slow << 26);
710 /* Create various pipes... */
711 #define usb_sndctrlpipe(dev,endpoint) ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint))
712 #define usb_rcvctrlpipe(dev,endpoint) ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
713 #define usb_sndisocpipe(dev,endpoint) ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint))
714 #define usb_rcvisocpipe(dev,endpoint) ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
715 #define usb_sndbulkpipe(dev,endpoint) ((PIPE_BULK << 30) | __create_pipe(dev,endpoint))
716 #define usb_rcvbulkpipe(dev,endpoint) ((PIPE_BULK << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
717 #define usb_sndintpipe(dev,endpoint) ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint))
718 #define usb_rcvintpipe(dev,endpoint) ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
719 #define usb_snddefctrl(dev) ((PIPE_CONTROL << 30) | __default_pipe(dev))
720 #define usb_rcvdefctrl(dev) ((PIPE_CONTROL << 30) | __default_pipe(dev) | USB_DIR_IN)
723 * Send and receive control messages..
725 int usb_new_device(struct usb_device *dev);
726 int usb_reset_device(struct usb_device *dev);
727 int usb_set_address(struct usb_device *dev);
728 int usb_get_descriptor(struct usb_device *dev, unsigned char desctype,
729 unsigned char descindex, void *buf, int size);
730 int usb_get_class_descriptor(struct usb_device *dev, int ifnum, unsigned char desctype,
731 unsigned char descindex, void *buf, int size);
732 int usb_get_device_descriptor(struct usb_device *dev);
733 int __usb_get_extra_descriptor(char *buffer, unsigned size, unsigned char type, void **ptr);
734 int usb_get_status(struct usb_device *dev, int type, int target, void *data);
735 int usb_get_configuration(struct usb_device *dev);
736 int usb_get_protocol(struct usb_device *dev, int ifnum);
737 int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol);
738 int usb_set_interface(struct usb_device *dev, int ifnum, int alternate);
739 int usb_set_idle(struct usb_device *dev, int ifnum, int duration, int report_id);
740 int usb_set_configuration(struct usb_device *dev, int configuration);
741 int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type,
742 unsigned char id, void *buf, int size);
743 int usb_set_report(struct usb_device *dev, int ifnum, unsigned char type,
744 unsigned char id, void *buf, int size);
745 int usb_string(struct usb_device *dev, int index, char *buf, size_t size);
746 int usb_clear_halt(struct usb_device *dev, int pipe);
747 void usb_set_maxpacket(struct usb_device *dev);
749 #define usb_get_extra_descriptor(ifpoint,type,ptr)\
750 __usb_get_extra_descriptor((ifpoint)->extra,(ifpoint)->extralen,type,(void**)ptr)
753 * Some USB bandwidth allocation constants.
755 #define BW_HOST_DELAY 1000L /* nanoseconds */
756 #define BW_HUB_LS_SETUP 333L /* nanoseconds */
757 /* 4 full-speed bit times (est.) */
759 #define FRAME_TIME_BITS 12000L /* frame = 1 millisecond */
760 #define FRAME_TIME_MAX_BITS_ALLOC (90L * FRAME_TIME_BITS / 100L)
761 #define FRAME_TIME_USECS 1000L
762 #define FRAME_TIME_MAX_USECS_ALLOC (90L * FRAME_TIME_USECS / 100L)
764 #define BitTime(bytecount) (7 * 8 * bytecount / 6) /* with integer truncation */
765 /* Trying not to use worst-case bit-stuffing
766 of (7/6 * 8 * bytecount) = 9.33 * bytecount */
767 /* bytecount = data payload byte count */
769 #define NS_TO_US(ns) ((ns + 500L) / 1000L)
770 /* convert & round nanoseconds to microseconds */
773 * Debugging helpers..
775 void usb_show_device_descriptor(struct usb_device_descriptor *);
776 void usb_show_config_descriptor(struct usb_config_descriptor *);
777 void usb_show_interface_descriptor(struct usb_interface_descriptor *);
778 void usb_show_endpoint_descriptor(struct usb_endpoint_descriptor *);
779 void usb_show_device(struct usb_device *);
780 void usb_show_string(struct usb_device *dev, char *id, int index);
782 #ifdef DEBUG
783 #define dbg(format, arg...) printk(KERN_DEBUG __FILE__ ": " format "\n" , ## arg)
784 #else
785 #define dbg(format, arg...) do {} while (0)
786 #endif
787 #define err(format, arg...) printk(KERN_ERR __FILE__ ": " format "\n" , ## arg)
788 #define info(format, arg...) printk(KERN_INFO __FILE__ ": " format "\n" , ## arg)
789 #define warn(format, arg...) printk(KERN_WARNING __FILE__ ": " format "\n" , ## arg)
793 * bus and driver list
796 extern struct list_head usb_driver_list;
797 extern struct list_head usb_bus_list;
800 * USB device fs stuff
803 #ifdef CONFIG_USB_DEVICEFS
806 * these are expected to be called from the USB core/hub thread
807 * with the kernel lock held
809 extern void usbdevfs_add_bus(struct usb_bus *bus);
810 extern void usbdevfs_remove_bus(struct usb_bus *bus);
811 extern void usbdevfs_add_device(struct usb_device *dev);
812 extern void usbdevfs_remove_device(struct usb_device *dev);
814 extern int usbdevfs_init(void);
815 extern void usbdevfs_cleanup(void);
817 #else /* CONFIG_USB_DEVICEFS */
819 static inline void usbdevfs_add_bus(struct usb_bus *bus) {}
820 static inline void usbdevfs_remove_bus(struct usb_bus *bus) {}
821 static inline void usbdevfs_add_device(struct usb_device *dev) {}
822 static inline void usbdevfs_remove_device(struct usb_device *dev) {}
824 static inline int usbdevfs_init(void) { return 0; }
825 static inline void usbdevfs_cleanup(void) { }
827 #endif /* CONFIG_USB_DEVICEFS */
829 #endif /* __KERNEL__ */
831 #endif