4 #include <linux/types.h>
5 #include <linux/ioctl.h>
10 * Device and/or Interface Class codes
12 #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
13 #define USB_CLASS_AUDIO 1
14 #define USB_CLASS_COMM 2
15 #define USB_CLASS_HID 3
16 #define USB_CLASS_PRINTER 7
17 #define USB_CLASS_MASS_STORAGE 8
18 #define USB_CLASS_HUB 9
19 #define USB_CLASS_DATA 10
20 #define USB_CLASS_VENDOR_SPEC 0xff
25 #define USB_DT_DEVICE 0x01
26 #define USB_DT_CONFIG 0x02
27 #define USB_DT_STRING 0x03
28 #define USB_DT_INTERFACE 0x04
29 #define USB_DT_ENDPOINT 0x05
31 #define USB_DT_HUB 0x29
32 #define USB_DT_HID 0x21
33 #define USB_DT_REPORT 0x22
34 #define USB_DT_PHYSICAL 0x23
37 * Descriptor sizes per descriptor type
39 #define USB_DT_DEVICE_SIZE 18
40 #define USB_DT_CONFIG_SIZE 9
41 #define USB_DT_INTERFACE_SIZE 9
42 #define USB_DT_ENDPOINT_SIZE 7
43 #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
44 #define USB_DT_HUB_NONVAR_SIZE 7
47 * USB Request Type and Endpoint Directions
50 #define USB_DIR_IN 0x80
52 #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
53 #define USB_ENDPOINT_DIR_MASK 0x80
55 #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
56 #define USB_ENDPOINT_XFER_CONTROL 0
57 #define USB_ENDPOINT_XFER_ISOC 1
58 #define USB_ENDPOINT_XFER_BULK 2
59 #define USB_ENDPOINT_XFER_INT 3
62 * USB Packet IDs (PIDs)
64 #define USB_PID_OUT 0xe1
65 #define USB_PID_IN 0x69
66 #define USB_PID_SETUP 0x2d
71 #define USB_REQ_GET_STATUS 0x00
72 #define USB_REQ_CLEAR_FEATURE 0x01
73 /* 0x02 is reserved */
74 #define USB_REQ_SET_FEATURE 0x03
75 /* 0x04 is reserved */
76 #define USB_REQ_SET_ADDRESS 0x05
77 #define USB_REQ_GET_DESCRIPTOR 0x06
78 #define USB_REQ_SET_DESCRIPTOR 0x07
79 #define USB_REQ_GET_CONFIGURATION 0x08
80 #define USB_REQ_SET_CONFIGURATION 0x09
81 #define USB_REQ_GET_INTERFACE 0x0A
82 #define USB_REQ_SET_INTERFACE 0x0B
83 #define USB_REQ_SYNCH_FRAME 0x0C
88 #define USB_REQ_GET_REPORT 0x01
89 #define USB_REQ_GET_IDLE 0x02
90 #define USB_REQ_GET_PROTOCOL 0x03
91 #define USB_REQ_SET_REPORT 0x09
92 #define USB_REQ_SET_IDLE 0x0A
93 #define USB_REQ_SET_PROTOCOL 0x0B
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)
100 #define USB_RECIP_DEVICE 0x00
101 #define USB_RECIP_INTERFACE 0x01
102 #define USB_RECIP_ENDPOINT 0x02
103 #define USB_RECIP_OTHER 0x03
105 #define USB_HID_RPT_INPUT 0x01
106 #define USB_HID_RPT_OUTPUT 0x02
107 #define USB_HID_RPT_FEATURE 0x03
110 * Request target types.
112 #define USB_RT_DEVICE 0x00
113 #define USB_RT_INTERFACE 0x01
114 #define USB_RT_ENDPOINT 0x02
116 #define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE)
117 #define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER)
119 #define USB_RT_HIDD (USB_TYPE_CLASS | USB_RECIP_INTERFACE)
121 /* /proc/bus/usb/xxx/yyy ioctl codes */
123 struct usb_proc_ctrltransfer
{
129 __u32 timeout
; /* in milliseconds */
133 struct usb_proc_bulktransfer
{
136 unsigned int timeout
; /* in milliseconds */
140 struct usb_proc_old_ctrltransfer
{
146 /* pointer to data */
150 struct usb_proc_old_bulktransfer
{
156 struct usb_proc_setinterface
{
157 unsigned int interface
;
158 unsigned int altsetting
;
161 #define USB_PROC_CONTROL _IOWR('U', 0, struct usb_proc_ctrltransfer)
162 #define USB_PROC_BULK _IOWR('U', 2, struct usb_proc_bulktransfer)
163 #define USB_PROC_OLD_CONTROL _IOWR('U', 0, struct usb_proc_old_ctrltransfer)
164 #define USB_PROC_OLD_BULK _IOWR('U', 2, struct usb_proc_old_bulktransfer)
165 #define USB_PROC_RESETEP _IOR('U', 3, unsigned int)
166 #define USB_PROC_SETINTERFACE _IOR('U', 4, struct usb_proc_setinterface)
167 #define USB_PROC_SETCONFIGURATION _IOR('U', 5, unsigned int)
174 #include <linux/config.h>
175 #include <linux/list.h>
176 #include <linux/sched.h>
178 #define USB_MAJOR 180
180 extern int usb_hub_init(void);
181 extern int usb_kbd_init(void);
182 extern int usb_cpia_init(void);
183 extern int usb_mouse_init(void);
184 extern int usb_printer_init(void);
186 extern void usb_hub_cleanup(void);
187 extern void usb_mouse_cleanup(void);
189 static __inline__
void wait_ms(unsigned int ms
)
191 current
->state
= TASK_UNINTERRUPTIBLE
;
192 schedule_timeout(1 + ms
* HZ
/ 1000);
201 } devrequest
__attribute__ ((packed
));
204 * Status codes (these [used to] follow OHCI controllers condition codes)
206 #define USB_ST_NOERROR 0
207 #define USB_ST_CRC -1
208 #define USB_ST_BITSTUFF -2
209 #define USB_ST_DTMISMATCH -3 /* data toggle mismatch */
210 #define USB_ST_STALL -4
211 #define USB_ST_NORESPONSE -5 /* device not responding/handshaking */
212 #define USB_ST_PIDCHECK -6 /* Check bits on PID failed */
213 #define USB_ST_PIDUNDEF -7 /* PID unexpected/undefined */
214 #define USB_ST_DATAOVERRUN -8
215 #define USB_ST_DATAUNDERRUN -9
216 #define USB_ST_RESERVED1 -10
217 #define USB_ST_RESERVED2 -11
218 #define USB_ST_BUFFEROVERRUN -12
219 #define USB_ST_BUFFERUNDERRUN -13
220 #define USB_ST_RESERVED3 -14
221 #define USB_ST_RESERVED4 -15
223 /* internal errors */
224 #define USB_ST_REMOVED -100
225 #define USB_ST_TIMEOUT -101
226 #define USB_ST_INTERNALERROR -200
227 #define USB_ST_NOTSUPPORTED -201
228 #define USB_ST_BANDWIDTH_ERROR -202
229 #define USB_ST_NOCHANGE -203
233 * USB device number allocation bitmap. There's one bitmap
237 unsigned long devicemap
[128 / (8*sizeof(unsigned long))];
240 #define USB_MAXBUS 64
243 unsigned long busmap
[USB_MAXBUS
/ (8*sizeof(unsigned long))];
247 * This is a USB device descriptor.
249 * USB device information
252 /* Everything but the endpoint maximums are aribtrary */
253 #define USB_MAXCONFIG 8
254 #define USB_MAXALTSETTING 16
255 #define USB_MAXINTERFACES 32
256 #define USB_MAXENDPOINTS 32
258 /* All standard descriptors have these 2 fields in common */
259 struct usb_descriptor_header
{
261 __u8 bDescriptorType
;
262 } __attribute__ ((packed
));
264 /* Device descriptor */
265 struct usb_device_descriptor
{
267 __u8 bDescriptorType
;
270 __u8 bDeviceSubClass
;
271 __u8 bDeviceProtocol
;
272 __u8 bMaxPacketSize0
;
279 __u8 bNumConfigurations
;
280 } __attribute__ ((packed
));
282 /* Endpoint descriptor */
283 struct usb_endpoint_descriptor
{
285 __u8 bDescriptorType
;
286 __u8 bEndpointAddress
;
288 __u16 wMaxPacketSize
;
292 } __attribute__ ((packed
));
295 struct usb_hid_class_descriptor
{
296 __u8 bDescriptorType
;
297 __u16 wDescriptorLength
;
298 } __attribute__ ((packed
));
300 struct usb_hid_descriptor
{
302 __u8 bDescriptorType
;
305 __u8 bNumDescriptors
;
307 struct usb_hid_class_descriptor desc
[1];
308 } __attribute__ ((packed
));
310 /* Interface descriptor */
311 struct usb_interface_descriptor
{
313 __u8 bDescriptorType
;
314 __u8 bInterfaceNumber
;
315 __u8 bAlternateSetting
;
317 __u8 bInterfaceClass
;
318 __u8 bInterfaceSubClass
;
319 __u8 bInterfaceProtocol
;
322 struct usb_hid_descriptor
*hid
;
323 struct usb_endpoint_descriptor
*endpoint
;
324 } __attribute__ ((packed
));
326 struct usb_interface
{
327 struct usb_interface_descriptor
*altsetting
;
329 int act_altsetting
; /* active alternate setting */
330 int num_altsetting
; /* number of alternate settings */
332 struct usb_driver
*driver
; /* driver */
336 /* Configuration descriptor information.. */
337 struct usb_config_descriptor
{
339 __u8 bDescriptorType
;
342 __u8 bConfigurationValue
;
347 struct usb_interface
*interface
;
348 } __attribute__ ((packed
));
350 /* String descriptor */
351 struct usb_string_descriptor
{
353 __u8 bDescriptorType
;
355 } __attribute__ ((packed
));
362 void * (*probe
)(struct usb_device
*, unsigned int);
363 void (*disconnect
)(struct usb_device
*, void *);
365 struct list_head driver_list
;
367 struct file_operations
*fops
;
372 * Pointer to a device endpoint interrupt function -greg
374 * int status - This needs to be defined. Right now each HCD
375 * passes different transfer status bits back. Don't use it
376 * until we come up with a common meaning.
377 * void *buffer - This is a pointer to the data used in this
379 * int length - This is the number of bytes transferred in or out
380 * of the buffer by this transfer. (-1 = unknown/unsupported)
381 * void *dev_id - This is a user defined pointer set when the IRQ
382 * is requested that is passed back.
385 * if (status == USB_ST_REMOVED), don't trust buffer or len.
387 typedef int (*usb_device_irq
)(int, void *, int, void *);
390 * Isoc. support additions
392 #define START_FRAME_FUDGE 3
394 #define USB_WRAP_FRAMENR(x) ((x) & 2047)
396 /* for start_type: */
402 #define START_TYPE_MAX START_RELATIVE
405 * Completion/Callback routine returns an enum,
406 * which tells the interrupt handler what to do
407 * with the completed frames (TDs).
410 CB_CONTINUE
= 0, /* OK, remove all TDs;
411 needs to be 0 to be consistent with
412 current callback function ret. values */
413 CB_REUSE
, /* leave descriptors as NULL, not active */
414 CB_RESTART
, /* leave descriptors as they are, alive */
415 CB_ABORT
, /* kill this USB transfer request */
416 CB_CONT_RUN
/* append the isoc_desc at the end of all active isoc_desc */
419 struct isoc_frame_desc
{
420 int frame_length
; /* may be 0 (i.e., allowed) */
421 /* set by driver for OUTs to devices;
422 * set by USBD for INs from devices,
423 * after I/O complete */
424 unsigned int frame_status
;
425 /* set by USBD after I/O complete */
428 struct usb_isoc_desc
{
430 * The following fields are set by the usb_init_isoc() call.
432 struct usb_device
*usb_dev
;
435 void *context
; /* driver context (private) ptr */
438 * The following fields are set by the driver between the
439 * usb_init_isoc() and usb_run_isoc() calls
440 * (along with the "frames" array for OUTput).
443 int start_frame
; /* optional, depending on start_type */
444 int frame_spacing
; /* not using (yet?) */
445 int callback_frames
; /* every # frames + last one */
446 /* 0 means no callbacks until IOC on last frame */
447 usb_device_irq callback_fn
;
450 struct usb_isoc_desc
*prev_isocdesc
; /* previous isoc_desc, for CB_CONT_RUN */
452 * The following fields are set by the usb_run_isoc() call.
455 void *td
; /* UHCI or OHCI TD ptr */
457 * The following fields are set by the USB HCD interrupt handler
458 * before calling the driver's callback function.
460 int total_completed_frames
;
461 int prev_completed_frame
; /* from the previous callback */
462 int cur_completed_frame
; /* from this callback */
463 int total_length
; /* accumulated */
464 int error_count
; /* accumulated */
465 struct isoc_frame_desc frames
[0]; /* variable size: [frame_count] */
468 struct usb_operations
{
469 int (*allocate
)(struct usb_device
*);
470 int (*deallocate
)(struct usb_device
*);
471 int (*control_msg
)(struct usb_device
*, unsigned int, devrequest
*, void *, int, int);
472 int (*bulk_msg
)(struct usb_device
*, unsigned int, void *, int, unsigned long *, int);
473 int (*request_irq
)(struct usb_device
*, unsigned int, usb_device_irq
, int, void *, void **, long);
474 int (*release_irq
)(struct usb_device
*, void *);
475 void *(*request_bulk
)(struct usb_device
*, unsigned int, usb_device_irq
,
476 void *, int, void *);
477 int (*terminate_bulk
)(struct usb_device
*, void *);
478 int (*get_frame_number
) (struct usb_device
*usb_dev
);
479 int (*init_isoc
) (struct usb_device
*usb_dev
, unsigned int pipe
,
480 int frame_count
, void *context
, struct usb_isoc_desc
**isocdesc
);
481 void (*free_isoc
) (struct usb_isoc_desc
*isocdesc
);
482 int (*run_isoc
) (struct usb_isoc_desc
*isocdesc
, struct usb_isoc_desc
*pr_isocdesc
);
483 int (*kill_isoc
) (struct usb_isoc_desc
*isocdesc
);
487 * Allocated per bus we have
490 int busnum
; /* Bus number (in order of reg) */
492 struct usb_devmap devmap
; /* Device map */
493 struct usb_operations
*op
; /* Operations (specific to the HC) */
494 struct usb_device
*root_hub
; /* Root hub */
495 struct list_head bus_list
;
496 void *hcpriv
; /* Host Controller private data */
498 unsigned int bandwidth_allocated
; /* on this Host Controller; */
499 /* applies to Int. and Isoc. pipes; */
500 /* measured in microseconds/frame; */
501 /* range is 0..900, where 900 = */
502 /* 90% of a 1-millisecond frame */
503 int bandwidth_int_reqs
; /* number of Interrupt requesters */
504 int bandwidth_isoc_reqs
; /* number of Isoc. requesters */
508 struct proc_dir_entry
*proc_entry
;
511 #define USB_MAXCHILDREN (8) /* This is arbitrary */
514 int devnum
; /* Device number on USB bus */
515 int slow
; /* Slow device? */
517 atomic_t refcnt
; /* Reference count */
519 int maxpacketsize
; /* Maximum packet size; encoded as 0,1,2,3 = 8,16,32,64 */
520 unsigned int toggle
[2]; /* one bit for each endpoint ([0] = IN, [1] = OUT) */
521 unsigned int halted
[2]; /* endpoint halts; one bit per endpoint # & direction; */
522 /* [0] = IN, [1] = OUT */
523 struct usb_config_descriptor
*actconfig
;/* the active configuration */
524 int epmaxpacketin
[16]; /* INput endpoint specific maximums */
525 int epmaxpacketout
[16]; /* OUTput endpoint specific maximums */
527 struct usb_device
*parent
;
528 struct usb_bus
*bus
; /* Bus we're part of */
530 struct usb_device_descriptor descriptor
;/* Descriptor */
531 struct usb_config_descriptor
*config
; /* All of the configs */
533 char *string
; /* pointer to the last string read from the device */
534 int string_langid
; /* language ID for strings */
536 void *hcpriv
; /* Host Controller private data */
537 void *audiopriv
; /* May be both audio and HID */
539 struct proc_dir_entry
*proc_entry
;
542 * Child devices - these can be either new devices
543 * (if this is a hub device), or different instances
544 * of this same device.
546 * Each instance needs its own set of data structures.
549 int maxchild
; /* Number of ports if hub */
550 struct usb_device
*children
[USB_MAXCHILDREN
];
553 extern int usb_register(struct usb_driver
*);
554 extern void usb_deregister(struct usb_driver
*);
556 /* used these for multi-interface device registration */
557 extern void usb_driver_claim_interface(struct usb_driver
*driver
, struct usb_interface
*iface
, void* priv
);
558 extern int usb_interface_claimed(struct usb_interface
*iface
);
559 extern void usb_driver_release_interface(struct usb_driver
*driver
, struct usb_interface
*iface
);
561 extern struct usb_bus
*usb_alloc_bus(struct usb_operations
*);
562 extern void usb_free_bus(struct usb_bus
*);
563 extern void usb_register_bus(struct usb_bus
*);
564 extern void usb_deregister_bus(struct usb_bus
*);
566 extern struct usb_device
*usb_alloc_dev(struct usb_device
*parent
, struct usb_bus
*);
567 extern void usb_free_dev(struct usb_device
*);
568 extern void usb_inc_dev_use(struct usb_device
*);
569 #define usb_dec_dev_use usb_free_dev
570 extern void usb_release_bandwidth(struct usb_device
*, int);
572 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
);
574 extern int usb_request_irq(struct usb_device
*, unsigned int, usb_device_irq
, int, void *, void **);
575 extern int usb_release_irq(struct usb_device
*dev
, void *handle
, unsigned int pipe
);
577 extern void *usb_request_bulk(struct usb_device
*, unsigned int, usb_device_irq
, void *, int, void *);
578 extern int usb_terminate_bulk(struct usb_device
*, void *);
580 extern void usb_init_root_hub(struct usb_device
*dev
);
581 extern void usb_connect(struct usb_device
*dev
);
582 extern void usb_disconnect(struct usb_device
**);
584 extern void usb_destroy_configuration(struct usb_device
*dev
);
586 int usb_get_current_frame_number (struct usb_device
*usb_dev
);
588 int usb_init_isoc (struct usb_device
*usb_dev
,
592 struct usb_isoc_desc
**isocdesc
);
594 void usb_free_isoc (struct usb_isoc_desc
*isocdesc
);
596 int usb_run_isoc (struct usb_isoc_desc
*isocdesc
,
597 struct usb_isoc_desc
*pr_isocdesc
);
599 int usb_kill_isoc (struct usb_isoc_desc
*isocdesc
);
602 * Calling this entity a "pipe" is glorifying it. A USB pipe
603 * is something embarrassingly simple: it basically consists
604 * of the following information:
605 * - device number (7 bits)
606 * - endpoint number (4 bits)
607 * - current Data0/1 state (1 bit)
608 * - direction (1 bit)
610 * - max packet size (2 bits: 8, 16, 32 or 64)
611 * - pipe type (2 bits: control, interrupt, bulk, isochronous)
613 * That's 18 bits. Really. Nothing more. And the USB people have
614 * documented these eighteen bits as some kind of glorious
615 * virtual data structure.
617 * Let's not fall in that trap. We'll just encode it as a simple
618 * unsigned int. The encoding is:
620 * - max size: bits 0-1 (00 = 8, 01 = 16, 10 = 32, 11 = 64)
621 * - direction: bit 7 (0 = Host-to-Device [Out], 1 = Device-to-Host [In])
622 * - device: bits 8-14
623 * - endpoint: bits 15-18
625 * - speed: bit 26 (0 = Full, 1 = Low Speed)
626 * - pipe type: bits 30-31 (00 = isochronous, 01 = interrupt, 10 = control, 11 = bulk)
628 * Why? Because it's arbitrary, and whatever encoding we select is really
629 * up to us. This one happens to share a lot of bit positions with the UHCI
630 * specification, so that much of the uhci driver can just mask the bits
634 #define PIPE_ISOCHRONOUS 0
635 #define PIPE_INTERRUPT 1
636 #define PIPE_CONTROL 2
639 #define USB_ISOCHRONOUS 0
640 #define USB_INTERRUPT 1
641 #define USB_CONTROL 2
644 #define usb_maxpacket(dev, pipe, out) (out \
645 ? (dev)->epmaxpacketout[usb_pipeendpoint(pipe)] \
646 : (dev)->epmaxpacketin [usb_pipeendpoint(pipe)] )
647 #define usb_packetid(pipe) (((pipe) & USB_DIR_IN) ? USB_PID_IN : USB_PID_OUT)
649 #define usb_pipeout(pipe) ((((pipe) >> 7) & 1) ^ 1)
650 #define usb_pipein(pipe) (((pipe) >> 7) & 1)
651 #define usb_pipedevice(pipe) (((pipe) >> 8) & 0x7f)
652 #define usb_pipe_endpdev(pipe) (((pipe) >> 8) & 0x7ff)
653 #define usb_pipeendpoint(pipe) (((pipe) >> 15) & 0xf)
654 #define usb_pipedata(pipe) (((pipe) >> 19) & 1)
655 #define usb_pipeslow(pipe) (((pipe) >> 26) & 1)
656 #define usb_pipetype(pipe) (((pipe) >> 30) & 3)
657 #define usb_pipeisoc(pipe) (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
658 #define usb_pipeint(pipe) (usb_pipetype((pipe)) == PIPE_INTERRUPT)
659 #define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL)
660 #define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK)
662 #define PIPE_DEVEP_MASK 0x0007ff00
664 /* The D0/D1 toggle bits */
665 #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1)
666 #define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << ep))
667 #define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = ((dev)->toggle[out] & ~(1 << ep)) | ((bit) << ep))
669 /* Endpoint halt control/status */
670 #define usb_endpoint_out(ep_dir) (((ep_dir >> 7) & 1) ^ 1)
671 #define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
672 #define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
673 #define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
675 static inline unsigned int __create_pipe(struct usb_device
*dev
, unsigned int endpoint
)
677 return (dev
->devnum
<< 8) | (endpoint
<< 15) | (dev
->slow
<< 26) | dev
->maxpacketsize
;
680 static inline unsigned int __default_pipe(struct usb_device
*dev
)
682 return (dev
->slow
<< 26);
685 /* Create various pipes... */
686 #define usb_sndctrlpipe(dev,endpoint) ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint))
687 #define usb_rcvctrlpipe(dev,endpoint) ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
688 #define usb_sndisocpipe(dev,endpoint) ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint))
689 #define usb_rcvisocpipe(dev,endpoint) ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
690 #define usb_sndbulkpipe(dev,endpoint) ((PIPE_BULK << 30) | __create_pipe(dev,endpoint))
691 #define usb_rcvbulkpipe(dev,endpoint) ((PIPE_BULK << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
692 #define usb_snddefctrl(dev) ((PIPE_CONTROL << 30) | __default_pipe(dev))
693 #define usb_rcvdefctrl(dev) ((PIPE_CONTROL << 30) | __default_pipe(dev) | USB_DIR_IN)
696 * Send and receive control messages..
698 int usb_new_device(struct usb_device
*dev
);
699 int usb_set_address(struct usb_device
*dev
);
700 int usb_get_descriptor(struct usb_device
*dev
, unsigned char desctype
, unsigned
701 char descindex
, void *buf
, int size
);
702 int usb_get_device_descriptor(struct usb_device
*dev
);
703 int usb_get_status (struct usb_device
*dev
, int type
, int target
, void *data
);
704 int usb_get_protocol(struct usb_device
*dev
);
705 int usb_set_protocol(struct usb_device
*dev
, int protocol
);
706 int usb_set_interface(struct usb_device
*dev
, int interface
, int alternate
);
707 int usb_set_idle(struct usb_device
*dev
, int duration
, int report_id
);
708 int usb_set_configuration(struct usb_device
*dev
, int configuration
);
709 int usb_get_report(struct usb_device
*dev
, unsigned char type
, unsigned char id
, unsigned char index
, void *buf
, int size
);
710 char *usb_string(struct usb_device
*dev
, int index
);
711 int usb_clear_halt(struct usb_device
*dev
, int endp
);
714 * Some USB bandwidth allocation constants.
716 #define BW_HOST_DELAY 1000L /* nanoseconds */
717 #define BW_HUB_LS_SETUP 333L /* nanoseconds */
718 /* 4 full-speed bit times (est.) */
720 #define FRAME_TIME_BITS 12000L /* frame = 1 millisecond */
721 #define FRAME_TIME_MAX_BITS_ALLOC (90L * FRAME_TIME_BITS / 100L)
722 #define FRAME_TIME_USECS 1000L
723 #define FRAME_TIME_MAX_USECS_ALLOC (90L * FRAME_TIME_USECS / 100L)
725 #define BitTime(bytecount) (7 * 8 * bytecount / 6) /* with integer truncation */
726 /* Trying not to use worst-case bit-stuffing
727 of (7/6 * 8 * bytecount) = 9.33 * bytecount */
728 /* bytecount = data payload byte count */
730 #define NS_TO_US(ns) ((ns + 500L) / 1000L)
731 /* convert & round nanoseconds to microseconds */
734 * Debugging helpers..
736 void usb_show_device_descriptor(struct usb_device_descriptor
*);
737 void usb_show_config_descriptor(struct usb_config_descriptor
*);
738 void usb_show_interface_descriptor(struct usb_interface_descriptor
*);
739 void usb_show_hid_descriptor(struct usb_hid_descriptor
* desc
);
740 void usb_show_endpoint_descriptor(struct usb_endpoint_descriptor
*);
741 void usb_show_device(struct usb_device
*);
742 void usb_show_string(struct usb_device
*dev
, char *id
, int index
);
745 #define PRINTD(format, args...) printk(KERN_DEBUG "usb: " format "\n" , ## args);
746 #else /* NOT DEBUGGING */
747 #define PRINTD(fmt, arg...) do {} while (0)
748 #endif /* USB_DEBUG */
749 /* A simple way to change one line from DEBUG to NOT DEBUG: */
750 #define XPRINTD(fmt, arg...) do {} while (0)
756 #ifdef CONFIG_USB_PROC
757 void proc_usb_add_bus(struct usb_bus
*bus
);
758 void proc_usb_remove_bus(struct usb_bus
*bus
);
759 void proc_usb_add_device(struct usb_device
*dev
);
760 void proc_usb_remove_device(struct usb_device
*dev
);
762 extern inline void proc_usb_add_bus(struct usb_bus
*bus
) {}
763 extern inline void proc_usb_remove_bus(struct usb_bus
*bus
) {}
764 extern inline void proc_usb_add_device(struct usb_device
*dev
) {}
765 extern inline void proc_usb_remove_device(struct usb_device
*dev
) {}
768 #endif /* __KERNEL__ */