7 * Device and/or Interface Class codes
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
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)
32 #define USB_RECIP_DEVICE 0x00
33 #define USB_RECIP_INTERFACE 0x01
34 #define USB_RECIP_ENDPOINT 0x02
35 #define USB_RECIP_OTHER 0x03
41 #define USB_DIR_IN 0x80
46 #define USB_DT_DEVICE 0x01
47 #define USB_DT_CONFIG 0x02
48 #define USB_DT_STRING 0x03
49 #define USB_DT_INTERFACE 0x04
50 #define USB_DT_ENDPOINT 0x05
52 #define USB_DT_HID (USB_TYPE_CLASS | 0x01)
53 #define USB_DT_REPORT (USB_TYPE_CLASS | 0x02)
54 #define USB_DT_PHYSICAL (USB_TYPE_CLASS | 0x03)
55 #define USB_DT_HUB (USB_TYPE_CLASS | 0x09)
58 * Descriptor sizes per descriptor type
60 #define USB_DT_DEVICE_SIZE 18
61 #define USB_DT_CONFIG_SIZE 9
62 #define USB_DT_INTERFACE_SIZE 9
63 #define USB_DT_ENDPOINT_SIZE 7
64 #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
65 #define USB_DT_HUB_NONVAR_SIZE 7
66 #define USB_DT_HID_SIZE 9
71 #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
72 #define USB_ENDPOINT_DIR_MASK 0x80
74 #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
75 #define USB_ENDPOINT_XFER_CONTROL 0
76 #define USB_ENDPOINT_XFER_ISOC 1
77 #define USB_ENDPOINT_XFER_BULK 2
78 #define USB_ENDPOINT_XFER_INT 3
81 * USB Packet IDs (PIDs)
83 #define USB_PID_UNDEF_0 0xf0
84 #define USB_PID_OUT 0xe1
85 #define USB_PID_ACK 0xd2
86 #define USB_PID_DATA0 0xc3
87 #define USB_PID_PING 0xb4 /* USB 2.0 */
88 #define USB_PID_SOF 0xa5
89 #define USB_PID_NYET 0x96 /* USB 2.0 */
90 #define USB_PID_DATA2 0x87 /* USB 2.0 */
91 #define USB_PID_SPLIT 0x78 /* USB 2.0 */
92 #define USB_PID_IN 0x69
93 #define USB_PID_NAK 0x5a
94 #define USB_PID_DATA1 0x4b
95 #define USB_PID_PREAMBLE 0x3c /* Token mode */
96 #define USB_PID_ERR 0x3c /* USB 2.0: handshake mode */
97 #define USB_PID_SETUP 0x2d
98 #define USB_PID_STALL 0x1e
99 #define USB_PID_MDATA 0x0f /* USB 2.0 */
104 #define USB_REQ_GET_STATUS 0x00
105 #define USB_REQ_CLEAR_FEATURE 0x01
106 #define USB_REQ_SET_FEATURE 0x03
107 #define USB_REQ_SET_ADDRESS 0x05
108 #define USB_REQ_GET_DESCRIPTOR 0x06
109 #define USB_REQ_SET_DESCRIPTOR 0x07
110 #define USB_REQ_GET_CONFIGURATION 0x08
111 #define USB_REQ_SET_CONFIGURATION 0x09
112 #define USB_REQ_GET_INTERFACE 0x0A
113 #define USB_REQ_SET_INTERFACE 0x0B
114 #define USB_REQ_SYNCH_FRAME 0x0C
119 #define USB_REQ_GET_REPORT 0x01
120 #define USB_REQ_GET_IDLE 0x02
121 #define USB_REQ_GET_PROTOCOL 0x03
122 #define USB_REQ_SET_REPORT 0x09
123 #define USB_REQ_SET_IDLE 0x0A
124 #define USB_REQ_SET_PROTOCOL 0x0B
129 #include <linux/types.h>
130 #include <linux/ioctl.h>
131 #include <linux/version.h>
132 #include <linux/sched.h>
133 #include <linux/delay.h>
134 #include <linux/interrupt.h> /* for in_interrupt() */
135 #include <linux/config.h>
136 #include <linux/list.h>
138 #define USB_MAJOR 180
140 static __inline__
void wait_ms(unsigned int ms
)
142 if(!in_interrupt()) {
143 current
->state
= TASK_UNINTERRUPTIBLE
;
144 schedule_timeout(1 + ms
* HZ
/ 1000);
156 } devrequest
__attribute__ ((packed
));
160 * USB_ST* maps to -E* and should go away in the future
163 #define USB_ST_NOERROR 0
164 #define USB_ST_CRC (-EILSEQ)
165 #define USB_ST_BITSTUFF (-EPROTO)
166 #define USB_ST_NORESPONSE (-ETIMEDOUT) /* device not responding/handshaking */
167 #define USB_ST_DATAOVERRUN (-EOVERFLOW)
168 #define USB_ST_DATAUNDERRUN (-EREMOTEIO)
169 #define USB_ST_BUFFEROVERRUN (-ECOMM)
170 #define USB_ST_BUFFERUNDERRUN (-ENOSR)
171 #define USB_ST_INTERNALERROR (-EPROTO) /* unknown error */
172 #define USB_ST_SHORT_PACKET (-EREMOTEIO)
173 #define USB_ST_PARTIAL_ERROR (-EXDEV) /* ISO transfer only partially completed */
174 #define USB_ST_URB_KILLED (-ENOENT) /* URB canceled by user */
175 #define USB_ST_URB_PENDING (-EINPROGRESS)
176 #define USB_ST_REMOVED (-ENODEV) /* device not existing or removed */
177 #define USB_ST_TIMEOUT (-ETIMEDOUT) /* communication timed out, also in urb->status**/
178 #define USB_ST_NOTSUPPORTED (-ENOSYS)
179 #define USB_ST_BANDWIDTH_ERROR (-ENOSPC) /* too much bandwidth used */
180 #define USB_ST_URB_INVALID_ERROR (-EINVAL) /* invalid value/transfer type */
181 #define USB_ST_URB_REQUEST_ERROR (-ENXIO) /* invalid endpoint */
182 #define USB_ST_STALL (-EPIPE) /* pipe stalled, also in urb->status*/
185 * USB device number allocation bitmap. There's one bitmap
189 unsigned long devicemap
[128 / (8*sizeof(unsigned long))];
192 #define USB_MAXBUS 64
195 unsigned long busmap
[USB_MAXBUS
/ (8*sizeof(unsigned long))];
199 * This is a USB device descriptor.
201 * USB device information
204 /* Everything but the endpoint maximums are aribtrary */
205 #define USB_MAXCONFIG 8
206 #define USB_ALTSETTINGALLOC 4
207 #define USB_MAXALTSETTING 128 /* Hard limit */
208 #define USB_MAXINTERFACES 32
209 #define USB_MAXENDPOINTS 32
211 /* All standard descriptors have these 2 fields in common */
212 struct usb_descriptor_header
{
214 __u8 bDescriptorType
;
215 } __attribute__ ((packed
));
217 /* Device descriptor */
218 struct usb_device_descriptor
{
220 __u8 bDescriptorType
;
223 __u8 bDeviceSubClass
;
224 __u8 bDeviceProtocol
;
225 __u8 bMaxPacketSize0
;
232 __u8 bNumConfigurations
;
233 } __attribute__ ((packed
));
235 /* Endpoint descriptor */
236 struct usb_endpoint_descriptor
{
238 __u8 bDescriptorType
;
239 __u8 bEndpointAddress
;
241 __u16 wMaxPacketSize
;
246 unsigned char *extra
; /* Extra descriptors */
248 } __attribute__ ((packed
));
250 /* Interface descriptor */
251 struct usb_interface_descriptor
{
253 __u8 bDescriptorType
;
254 __u8 bInterfaceNumber
;
255 __u8 bAlternateSetting
;
257 __u8 bInterfaceClass
;
258 __u8 bInterfaceSubClass
;
259 __u8 bInterfaceProtocol
;
262 struct usb_endpoint_descriptor
*endpoint
;
264 unsigned char *extra
; /* Extra descriptors */
266 } __attribute__ ((packed
));
268 struct usb_interface
{
269 struct usb_interface_descriptor
*altsetting
;
271 int act_altsetting
; /* active alternate setting */
272 int num_altsetting
; /* number of alternate settings */
273 int max_altsetting
; /* total memory allocated */
275 struct usb_driver
*driver
; /* driver */
279 /* Configuration descriptor information.. */
280 struct usb_config_descriptor
{
282 __u8 bDescriptorType
;
285 __u8 bConfigurationValue
;
290 struct usb_interface
*interface
;
292 unsigned char *extra
; /* Extra descriptors */
294 } __attribute__ ((packed
));
296 /* String descriptor */
297 struct usb_string_descriptor
{
299 __u8 bDescriptorType
;
301 } __attribute__ ((packed
));
308 void * (*probe
)(struct usb_device
*, unsigned int);
309 void (*disconnect
)(struct usb_device
*, void *);
311 struct list_head driver_list
;
313 struct file_operations
*fops
;
316 struct semaphore serialize
;
318 int (*ioctl
)(struct usb_device
*dev
, unsigned int code
, void *buf
);
322 * Pointer to a device endpoint interrupt function -greg
324 * int status - This needs to be defined. Right now each HCD
325 * passes different transfer status bits back. Don't use it
326 * until we come up with a common meaning.
327 * void *buffer - This is a pointer to the data used in this
329 * int length - This is the number of bytes transferred in or out
330 * of the buffer by this transfer. (-1 = unknown/unsupported)
331 * void *dev_id - This is a user defined pointer set when the IRQ
332 * is requested that is passed back.
335 * if (status == USB_ST_REMOVED), don't trust buffer or len.
337 typedef int (*usb_device_irq
)(int, void *, int, void *);
339 /*----------------------------------------------------------------------------*
340 * New USB Structures *
341 *----------------------------------------------------------------------------*/
344 * urb->transfer_flags:
346 #define USB_DISABLE_SPD 0x0001
347 #define USB_ISO_ASAP 0x0002
348 #define USB_URB_EARLY_COMPLETE 0x0004
349 #define USB_ASYNC_UNLINK 0x0008
350 #define USB_QUEUE_BULK 0x0010
351 #define USB_TIMEOUT_KILLED 0x1000 // only set by HCD!
356 unsigned int length
; // expected length
357 unsigned int actual_length
;
359 } iso_packet_descriptor_t
, *piso_packet_descriptor_t
;
362 typedef void (*usb_complete_t
)(struct urb
*);
366 spinlock_t lock
; // lock for the URB
367 void *hcpriv
; // private data for host controller
368 struct list_head urb_list
; // list pointer to all active urbs
369 struct urb
*next
; // pointer to next URB
370 struct usb_device
*dev
; // pointer to associated USB device
371 unsigned int pipe
; // pipe information
372 int status
; // returned status
373 unsigned int transfer_flags
; // USB_DISABLE_SPD | USB_ISO_ASAP | USB_URB_EARLY_COMPLETE
374 void *transfer_buffer
; // associated data buffer
375 int transfer_buffer_length
; // data buffer length
376 int actual_length
; // actual data buffer length
377 int bandwidth
; // bandwidth for this transfer request (INT or ISO)
378 unsigned char *setup_packet
; // setup packet (control only)
380 int start_frame
; // start frame (iso/irq only)
381 int number_of_packets
; // number of packets in this request (iso)
382 int interval
; // polling interval (irq only)
383 int error_count
; // number of errors in this transfer (iso only)
384 int timeout
; // timeout (in jiffies)
386 void *context
; // context for completion routine
387 usb_complete_t complete
; // pointer to completion routine
389 iso_packet_descriptor_t iso_frame_desc
[0];
392 #define FILL_CONTROL_URB(a,aa,b,c,d,e,f,g) \
394 spin_lock_init(&(a)->lock);\
397 (a)->setup_packet=c;\
398 (a)->transfer_buffer=d;\
399 (a)->transfer_buffer_length=e;\
404 #define FILL_BULK_URB(a,aa,b,c,d,e,f) \
406 spin_lock_init(&(a)->lock);\
409 (a)->transfer_buffer=c;\
410 (a)->transfer_buffer_length=d;\
415 #define FILL_INT_URB(a,aa,b,c,d,e,f,g) \
417 spin_lock_init(&(a)->lock);\
420 (a)->transfer_buffer=c;\
421 (a)->transfer_buffer_length=d;\
425 (a)->start_frame=-1;\
428 #define FILL_CONTROL_URB_TO(a,aa,b,c,d,e,f,g,h) \
430 spin_lock_init(&(a)->lock);\
433 (a)->setup_packet=c;\
434 (a)->transfer_buffer=d;\
435 (a)->transfer_buffer_length=e;\
441 #define FILL_BULK_URB_TO(a,aa,b,c,d,e,f,g) \
443 spin_lock_init(&(a)->lock);\
446 (a)->transfer_buffer=c;\
447 (a)->transfer_buffer_length=d;\
453 purb_t
usb_alloc_urb(int iso_packets
);
454 void usb_free_urb (purb_t purb
);
455 int usb_submit_urb(purb_t purb
);
456 int usb_unlink_urb(purb_t purb
);
457 int usb_internal_control_msg(struct usb_device
*usb_dev
, unsigned int pipe
, devrequest
*cmd
, void *data
, int len
, int timeout
);
458 int usb_bulk_msg(struct usb_device
*usb_dev
, unsigned int pipe
, void *data
, int len
, int *actual_length
, int timeout
);
460 /*-------------------------------------------------------------------*
461 * COMPATIBILITY STUFF *
462 *-------------------------------------------------------------------*/
465 wait_queue_head_t
*wakeup
;
467 usb_device_irq handler
;
472 struct irq_wrapper_data
{
474 usb_device_irq handler
;
477 /* -------------------------------------------------------------------------- */
479 struct usb_operations
{
480 int (*allocate
)(struct usb_device
*);
481 int (*deallocate
)(struct usb_device
*);
482 int (*get_frame_number
) (struct usb_device
*usb_dev
);
483 int (*submit_urb
) (struct urb
* purb
);
484 int (*unlink_urb
) (struct urb
* purb
);
488 * Allocated per bus we have
491 int busnum
; /* Bus number (in order of reg) */
493 struct usb_devmap devmap
; /* Device map */
494 struct usb_operations
*op
; /* Operations (specific to the HC) */
495 struct usb_device
*root_hub
; /* Root hub */
496 struct list_head bus_list
;
497 void *hcpriv
; /* Host Controller private data */
499 int bandwidth_allocated
; /* on this Host Controller; */
500 /* applies to Int. and Isoc. pipes; */
501 /* measured in microseconds/frame; */
502 /* range is 0..900, where 900 = */
503 /* 90% of a 1-millisecond frame */
504 int bandwidth_int_reqs
; /* number of Interrupt requesters */
505 int bandwidth_isoc_reqs
; /* number of Isoc. requesters */
507 /* usbdevfs inode list */
508 struct list_head inodes
;
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 unsigned int toggle
[2]; /* one bit for each endpoint ([0] = IN, [1] = OUT) */
520 unsigned int halted
[2]; /* endpoint halts; one bit per endpoint # & direction; */
521 /* [0] = IN, [1] = OUT */
522 int epmaxpacketin
[16]; /* INput endpoint specific maximums */
523 int epmaxpacketout
[16]; /* OUTput endpoint specific maximums */
525 struct usb_device
*parent
;
526 struct usb_bus
*bus
; /* Bus we're part of */
528 struct usb_device_descriptor descriptor
;/* Descriptor */
529 struct usb_config_descriptor
*config
; /* All of the configs */
530 struct usb_config_descriptor
*actconfig
;/* the active configuration */
532 char **rawdescriptors
; /* Raw descriptors for each config */
534 int have_langid
; /* whether string_langid is valid yet */
535 int string_langid
; /* language ID for strings */
537 void *hcpriv
; /* Host Controller private data */
539 /* usbdevfs inode list */
540 struct list_head inodes
;
541 struct list_head filelist
;
544 * Child devices - these can be either new devices
545 * (if this is a hub device), or different instances
546 * of this same device.
548 * Each instance needs its own set of data structures.
551 int maxchild
; /* Number of ports if hub */
552 struct usb_device
*children
[USB_MAXCHILDREN
];
555 extern struct usb_interface
*usb_ifnum_to_if(struct usb_device
*dev
, unsigned ifnum
);
557 extern int usb_register(struct usb_driver
*);
558 extern void usb_deregister(struct usb_driver
*);
559 extern void usb_scan_devices(void);
561 /* used these for multi-interface device registration */
562 extern void usb_driver_claim_interface(struct usb_driver
*driver
, struct usb_interface
*iface
, void* priv
);
563 extern int usb_interface_claimed(struct usb_interface
*iface
);
564 extern void usb_driver_release_interface(struct usb_driver
*driver
, struct usb_interface
*iface
);
566 extern struct usb_bus
*usb_alloc_bus(struct usb_operations
*);
567 extern void usb_free_bus(struct usb_bus
*);
568 extern void usb_register_bus(struct usb_bus
*);
569 extern void usb_deregister_bus(struct usb_bus
*);
571 extern struct usb_device
*usb_alloc_dev(struct usb_device
*parent
, struct usb_bus
*);
572 extern void usb_free_dev(struct usb_device
*);
573 extern void usb_inc_dev_use(struct usb_device
*);
574 #define usb_dec_dev_use usb_free_dev
576 extern int usb_check_bandwidth (struct usb_device
*dev
, struct urb
*urb
);
577 extern void usb_claim_bandwidth (struct usb_device
*dev
, struct urb
*urb
, int bustime
, int isoc
);
578 extern void usb_release_bandwidth(struct usb_device
*dev
, struct urb
*urb
, int isoc
);
580 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
);
582 extern int usb_root_hub_string(int id
, int serial
, char *type
, __u8
*data
, int len
);
583 extern void usb_connect(struct usb_device
*dev
);
584 extern void usb_disconnect(struct usb_device
**);
586 extern void usb_destroy_configuration(struct usb_device
*dev
);
588 int usb_get_current_frame_number (struct usb_device
*usb_dev
);
591 * Calling this entity a "pipe" is glorifying it. A USB pipe
592 * is something embarrassingly simple: it basically consists
593 * of the following information:
594 * - device number (7 bits)
595 * - endpoint number (4 bits)
596 * - current Data0/1 state (1 bit)
597 * - direction (1 bit)
599 * - max packet size (2 bits: 8, 16, 32 or 64) [Historical; now gone.]
600 * - pipe type (2 bits: control, interrupt, bulk, isochronous)
602 * That's 18 bits. Really. Nothing more. And the USB people have
603 * documented these eighteen bits as some kind of glorious
604 * virtual data structure.
606 * Let's not fall in that trap. We'll just encode it as a simple
607 * unsigned int. The encoding is:
609 * - max size: bits 0-1 (00 = 8, 01 = 16, 10 = 32, 11 = 64) [Historical; now gone.]
610 * - direction: bit 7 (0 = Host-to-Device [Out], 1 = Device-to-Host [In])
611 * - device: bits 8-14
612 * - endpoint: bits 15-18
614 * - speed: bit 26 (0 = Full, 1 = Low Speed)
615 * - pipe type: bits 30-31 (00 = isochronous, 01 = interrupt, 10 = control, 11 = bulk)
617 * Why? Because it's arbitrary, and whatever encoding we select is really
618 * up to us. This one happens to share a lot of bit positions with the UHCI
619 * specification, so that much of the uhci driver can just mask the bits
623 #define PIPE_ISOCHRONOUS 0
624 #define PIPE_INTERRUPT 1
625 #define PIPE_CONTROL 2
628 #define usb_maxpacket(dev, pipe, out) (out \
629 ? (dev)->epmaxpacketout[usb_pipeendpoint(pipe)] \
630 : (dev)->epmaxpacketin [usb_pipeendpoint(pipe)] )
631 #define usb_packetid(pipe) (((pipe) & USB_DIR_IN) ? USB_PID_IN : USB_PID_OUT)
633 #define usb_pipeout(pipe) ((((pipe) >> 7) & 1) ^ 1)
634 #define usb_pipein(pipe) (((pipe) >> 7) & 1)
635 #define usb_pipedevice(pipe) (((pipe) >> 8) & 0x7f)
636 #define usb_pipe_endpdev(pipe) (((pipe) >> 8) & 0x7ff)
637 #define usb_pipeendpoint(pipe) (((pipe) >> 15) & 0xf)
638 #define usb_pipedata(pipe) (((pipe) >> 19) & 1)
639 #define usb_pipeslow(pipe) (((pipe) >> 26) & 1)
640 #define usb_pipetype(pipe) (((pipe) >> 30) & 3)
641 #define usb_pipeisoc(pipe) (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
642 #define usb_pipeint(pipe) (usb_pipetype((pipe)) == PIPE_INTERRUPT)
643 #define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL)
644 #define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK)
646 #define PIPE_DEVEP_MASK 0x0007ff00
648 /* The D0/D1 toggle bits */
649 #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1)
650 #define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << ep))
651 #define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = ((dev)->toggle[out] & ~(1 << ep)) | ((bit) << ep))
653 /* Endpoint halt control/status */
654 #define usb_endpoint_out(ep_dir) (((ep_dir >> 7) & 1) ^ 1)
655 #define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
656 #define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
657 #define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
659 static inline unsigned int __create_pipe(struct usb_device
*dev
, unsigned int endpoint
)
661 return (dev
->devnum
<< 8) | (endpoint
<< 15) | (dev
->slow
<< 26);
664 static inline unsigned int __default_pipe(struct usb_device
*dev
)
666 return (dev
->slow
<< 26);
669 /* Create various pipes... */
670 #define usb_sndctrlpipe(dev,endpoint) ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint))
671 #define usb_rcvctrlpipe(dev,endpoint) ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
672 #define usb_sndisocpipe(dev,endpoint) ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint))
673 #define usb_rcvisocpipe(dev,endpoint) ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
674 #define usb_sndbulkpipe(dev,endpoint) ((PIPE_BULK << 30) | __create_pipe(dev,endpoint))
675 #define usb_rcvbulkpipe(dev,endpoint) ((PIPE_BULK << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
676 #define usb_sndintpipe(dev,endpoint) ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint))
677 #define usb_rcvintpipe(dev,endpoint) ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
678 #define usb_snddefctrl(dev) ((PIPE_CONTROL << 30) | __default_pipe(dev))
679 #define usb_rcvdefctrl(dev) ((PIPE_CONTROL << 30) | __default_pipe(dev) | USB_DIR_IN)
682 * Send and receive control messages..
684 int usb_new_device(struct usb_device
*dev
);
685 int usb_reset_device(struct usb_device
*dev
);
686 int usb_set_address(struct usb_device
*dev
);
687 int usb_get_descriptor(struct usb_device
*dev
, unsigned char desctype
,
688 unsigned char descindex
, void *buf
, int size
);
689 int usb_get_class_descriptor(struct usb_device
*dev
, int ifnum
, unsigned char desctype
,
690 unsigned char descindex
, void *buf
, int size
);
691 int usb_get_device_descriptor(struct usb_device
*dev
);
692 int __usb_get_extra_descriptor(char *buffer
, unsigned size
, unsigned char type
, void **ptr
);
693 int usb_get_status(struct usb_device
*dev
, int type
, int target
, void *data
);
694 int usb_get_configuration(struct usb_device
*dev
);
695 int usb_get_protocol(struct usb_device
*dev
, int ifnum
);
696 int usb_set_protocol(struct usb_device
*dev
, int ifnum
, int protocol
);
697 int usb_set_interface(struct usb_device
*dev
, int ifnum
, int alternate
);
698 int usb_set_idle(struct usb_device
*dev
, int ifnum
, int duration
, int report_id
);
699 int usb_set_configuration(struct usb_device
*dev
, int configuration
);
700 int usb_get_report(struct usb_device
*dev
, int ifnum
, unsigned char type
,
701 unsigned char id
, void *buf
, int size
);
702 int usb_set_report(struct usb_device
*dev
, int ifnum
, unsigned char type
,
703 unsigned char id
, void *buf
, int size
);
704 int usb_string(struct usb_device
*dev
, int index
, char *buf
, size_t size
);
705 int usb_clear_halt(struct usb_device
*dev
, int pipe
);
706 void usb_set_maxpacket(struct usb_device
*dev
);
708 #define usb_get_extra_descriptor(ifpoint,type,ptr)\
709 __usb_get_extra_descriptor((ifpoint)->extra,(ifpoint)->extralen,type,(void**)ptr)
712 * Some USB bandwidth allocation constants.
714 #define BW_HOST_DELAY 1000L /* nanoseconds */
715 #define BW_HUB_LS_SETUP 333L /* nanoseconds */
716 /* 4 full-speed bit times (est.) */
718 #define FRAME_TIME_BITS 12000L /* frame = 1 millisecond */
719 #define FRAME_TIME_MAX_BITS_ALLOC (90L * FRAME_TIME_BITS / 100L)
720 #define FRAME_TIME_USECS 1000L
721 #define FRAME_TIME_MAX_USECS_ALLOC (90L * FRAME_TIME_USECS / 100L)
723 #define BitTime(bytecount) (7 * 8 * bytecount / 6) /* with integer truncation */
724 /* Trying not to use worst-case bit-stuffing
725 of (7/6 * 8 * bytecount) = 9.33 * bytecount */
726 /* bytecount = data payload byte count */
728 #define NS_TO_US(ns) ((ns + 500L) / 1000L)
729 /* convert & round nanoseconds to microseconds */
732 * Debugging helpers..
734 void usb_show_device_descriptor(struct usb_device_descriptor
*);
735 void usb_show_config_descriptor(struct usb_config_descriptor
*);
736 void usb_show_interface_descriptor(struct usb_interface_descriptor
*);
737 void usb_show_endpoint_descriptor(struct usb_endpoint_descriptor
*);
738 void usb_show_device(struct usb_device
*);
739 void usb_show_string(struct usb_device
*dev
, char *id
, int index
);
742 #define dbg(format, arg...) printk(KERN_DEBUG __FILE__ ": " format "\n" , ## arg)
744 #define dbg(format, arg...) do {} while (0)
746 #define err(format, arg...) printk(KERN_ERR __FILE__ ": " format "\n" , ## arg)
747 #define info(format, arg...) printk(KERN_INFO __FILE__ ": " format "\n" , ## arg)
748 #define warn(format, arg...) printk(KERN_WARNING __FILE__ ": " format "\n" , ## arg)
752 * bus and driver list
755 extern struct list_head usb_driver_list
;
756 extern struct list_head usb_bus_list
;
759 * USB device fs stuff
762 #ifdef CONFIG_USB_DEVICEFS
765 * these are expected to be called from the USB core/hub thread
766 * with the kernel lock held
768 extern void usbdevfs_add_bus(struct usb_bus
*bus
);
769 extern void usbdevfs_remove_bus(struct usb_bus
*bus
);
770 extern void usbdevfs_add_device(struct usb_device
*dev
);
771 extern void usbdevfs_remove_device(struct usb_device
*dev
);
773 extern int usbdevfs_init(void);
774 extern void usbdevfs_cleanup(void);
776 #else /* CONFIG_USB_DEVICEFS */
778 extern inline void usbdevfs_add_bus(struct usb_bus
*bus
) {}
779 extern inline void usbdevfs_remove_bus(struct usb_bus
*bus
) {}
780 extern inline void usbdevfs_add_device(struct usb_device
*dev
) {}
781 extern inline void usbdevfs_remove_device(struct usb_device
*dev
) {}
783 extern inline int usbdevfs_init(void) { return 0; }
784 extern inline void usbdevfs_cleanup(void) { }
786 #endif /* CONFIG_USB_DEVICEFS */
788 #endif /* __KERNEL__ */