?? usb.h
字號(hào):
/* * if device class != 0, these can be match criteria; * but only if this bDeviceClass value is nonzero */ __u8 bDeviceClass; __u8 bDeviceSubClass; __u8 bDeviceProtocol; /* * if interface class != 0, these can be match criteria; * but only if this bInterfaceClass value is nonzero */ __u8 bInterfaceClass; __u8 bInterfaceSubClass; __u8 bInterfaceProtocol; /* * for driver's use; not involved in driver matching. */ unsigned long driver_info;};/** * struct usb_driver - identifies USB driver to usbcore * @owner: Pointer to the module owner of this driver; initialize * it using THIS_MODULE. * @name: The driver name should be unique among USB drivers, * and should normally be the same as the module name. * @probe: Called to see if the driver is willing to manage a particular * interface on a device. The probe routine returns a handle that * will later be provided to disconnect(), or a null pointer to * indicate that the driver will not handle the interface. * The handle is normally a pointer to driver-specific data. * If the probe() routine needs to access the interface * structure itself, use usb_ifnum_to_if() to make sure it's using * the right one. * @disconnect: Called when the interface is no longer accessible, usually * because its device has been (or is being) disconnected. The * handle passed is what was returned by probe(), or was provided * to usb_driver_claim_interface(). * @ioctl: Used for drivers that want to talk to userspace through * the "usbfs" filesystem. This lets devices provide ways to * expose information to user space regardless of where they * do (or don't) show up otherwise in the filesystem. * @fops: pointer to a fops structure if the driver wants to use the USB * major number. * @minor: the starting minor number for this driver, if the fops * pointer is set. * @id_table: USB drivers use ID table to support hotplugging. * Export this with MODULE_DEVICE_TABLE(usb,...), or use NULL to * say that probe() should be called for any unclaimed interface. * * USB drivers must provide a name, probe() and disconnect() methods, * and an id_table. Other driver fields are optional. * * The id_table is used in hotplugging. It holds a set of descriptors, * and specialized data may be associated with each entry. That table * is used by both user and kernel mode hotplugging support. * The probe() and disconnect() methods are called in a context where * they can sleep, but they should avoid abusing the privilege. Most * work to connect to a device should be done when the device is opened, * and undone at the last close. The disconnect code needs to address * concurrency issues with respect to open() and close() methods, as * well as forcing all pending I/O requests to complete (by unlinking * them as necessary, and blocking until the unlinks complete). */struct usb_driver { struct module *owner; const char *name; void *(*probe)( struct usb_device *dev, /* the device */ unsigned intf, /* what interface */ const struct usb_device_id *id /* from id_table */ ); void (*disconnect)(struct usb_device *, void *); struct list_head driver_list; struct file_operations *fops; int minor; struct semaphore serialize; int (*ioctl)(struct usb_device *dev, unsigned int code, void *buf); const struct usb_device_id *id_table;}; /*----------------------------------------------------------------------------* * New USB Structures * *----------------------------------------------------------------------------*//* * urb->transfer_flags: */#define USB_DISABLE_SPD 0x0001#define URB_SHORT_NOT_OK USB_DISABLE_SPD#define USB_ISO_ASAP 0x0002#define USB_ASYNC_UNLINK 0x0008#define USB_QUEUE_BULK 0x0010#define USB_NO_FSBR 0x0020#define USB_ZERO_PACKET 0x0040 // Finish bulk OUTs always with zero length packet#define URB_NO_INTERRUPT 0x0080 /* HINT: no non-error interrupt needed */ /* ... less overhead for QUEUE_BULK */#define USB_TIMEOUT_KILLED 0x1000 // only set by HCD!struct iso_packet_descriptor{ unsigned int offset; unsigned int length; // expected length unsigned int actual_length; unsigned int status;};#define usb_iso_packet_descriptor iso_packet_descriptorstruct urb;typedef void (*usb_complete_t)(struct urb *);struct urb{ spinlock_t lock; // lock for the URB void *hcpriv; // private data for host controller struct list_head urb_list; // list pointer to all active urbs struct urb *next; // pointer to next URB struct usb_device *dev; // pointer to associated USB device unsigned int pipe; // pipe information int status; // returned status unsigned int transfer_flags; // USB_DISABLE_SPD | USB_ISO_ASAP | etc. void *transfer_buffer; // associated data buffer dma_addr_t transfer_dma; // dma addr for transfer_buffer int transfer_buffer_length; // data buffer length int actual_length; // actual data buffer length int bandwidth; // bandwidth for this transfer request (INT or ISO) unsigned char *setup_packet; // setup packet (control only) dma_addr_t setup_dma; // dma addr for setup_packet // int start_frame; // start frame (iso/irq only) int number_of_packets; // number of packets in this request (iso) int interval; // polling interval (irq only) int error_count; // number of errors in this transfer (iso only) int timeout; // timeout (in jiffies) // void *context; // context for completion routine usb_complete_t complete; // pointer to completion routine // struct iso_packet_descriptor iso_frame_desc[0];};/** * FILL_CONTROL_URB - macro to help initialize a control urb * @URB: pointer to the urb to initialize. * @DEV: pointer to the struct usb_device for this urb. * @PIPE: the endpoint pipe * @SETUP_PACKET: pointer to the setup_packet buffer * @TRANSFER_BUFFER: pointer to the transfer buffer * @BUFFER_LENGTH: length of the transfer buffer * @COMPLETE: pointer to the usb_complete_t function * @CONTEXT: what to set the urb context to. * * Initializes a control urb with the proper information needed to submit * it to a device. This macro is depreciated, the usb_fill_control_urb() * function should be used instead. */#define FILL_CONTROL_URB(URB,DEV,PIPE,SETUP_PACKET,TRANSFER_BUFFER,BUFFER_LENGTH,COMPLETE,CONTEXT) \ do {\ spin_lock_init(&(URB)->lock);\ (URB)->dev=DEV;\ (URB)->pipe=PIPE;\ (URB)->setup_packet=SETUP_PACKET;\ (URB)->transfer_buffer=TRANSFER_BUFFER;\ (URB)->transfer_buffer_length=BUFFER_LENGTH;\ (URB)->complete=COMPLETE;\ (URB)->context=CONTEXT;\ } while (0)/** * FILL_BULK_URB - macro to help initialize a bulk urb * @URB: pointer to the urb to initialize. * @DEV: pointer to the struct usb_device for this urb. * @PIPE: the endpoint pipe * @TRANSFER_BUFFER: pointer to the transfer buffer * @BUFFER_LENGTH: length of the transfer buffer * @COMPLETE: pointer to the usb_complete_t function * @CONTEXT: what to set the urb context to. * * Initializes a bulk urb with the proper information needed to submit it * to a device. This macro is depreciated, the usb_fill_bulk_urb() * function should be used instead. */#define FILL_BULK_URB(URB,DEV,PIPE,TRANSFER_BUFFER,BUFFER_LENGTH,COMPLETE,CONTEXT) \ do {\ spin_lock_init(&(URB)->lock);\ (URB)->dev=DEV;\ (URB)->pipe=PIPE;\ (URB)->transfer_buffer=TRANSFER_BUFFER;\ (URB)->transfer_buffer_length=BUFFER_LENGTH;\ (URB)->complete=COMPLETE;\ (URB)->context=CONTEXT;\ } while (0) /** * FILL_INT_URB - macro to help initialize a interrupt urb * @URB: pointer to the urb to initialize. * @DEV: pointer to the struct usb_device for this urb. * @PIPE: the endpoint pipe * @TRANSFER_BUFFER: pointer to the transfer buffer * @BUFFER_LENGTH: length of the transfer buffer * @COMPLETE: pointer to the usb_complete_t function * @CONTEXT: what to set the urb context to. * @INTERVAL: what to set the urb interval to. * * Initializes a interrupt urb with the proper information needed to submit * it to a device. This macro is depreciated, the usb_fill_int_urb() * function should be used instead. */#define FILL_INT_URB(URB,DEV,PIPE,TRANSFER_BUFFER,BUFFER_LENGTH,COMPLETE,CONTEXT,INTERVAL) \ do {\ spin_lock_init(&(URB)->lock);\ (URB)->dev=DEV;\ (URB)->pipe=PIPE;\ (URB)->transfer_buffer=TRANSFER_BUFFER;\ (URB)->transfer_buffer_length=BUFFER_LENGTH;\ (URB)->complete=COMPLETE;\ (URB)->context=CONTEXT;\ (URB)->interval=INTERVAL;\ (URB)->start_frame=-1;\ } while (0)#define FILL_CONTROL_URB_TO(a,aa,b,c,d,e,f,g,h) \ do {\ spin_lock_init(&(a)->lock);\ (a)->dev=aa;\ (a)->pipe=b;\ (a)->setup_packet=c;\ (a)->transfer_buffer=d;\ (a)->transfer_buffer_length=e;\ (a)->complete=f;\ (a)->context=g;\ (a)->timeout=h;\ } while (0)#define FILL_BULK_URB_TO(a,aa,b,c,d,e,f,g) \ do {\ spin_lock_init(&(a)->lock);\ (a)->dev=aa;\ (a)->pipe=b;\ (a)->transfer_buffer=c;\ (a)->transfer_buffer_length=d;\ (a)->complete=e;\ (a)->context=f;\ (a)->timeout=g;\ } while (0) /** * usb_fill_control_urb - initializes a control urb * @urb: pointer to the urb to initialize. * @dev: pointer to the struct usb_device for this urb. * @pipe: the endpoint pipe * @setup_packet: pointer to the setup_packet buffer * @transfer_buffer: pointer to the transfer buffer * @buffer_length: length of the transfer buffer * @complete: pointer to the usb_complete_t function * @context: what to set the urb context to. * * Initializes a control urb with the proper information needed to submit * it to a device. */static inline void usb_fill_control_urb (struct urb *urb, struct usb_device *dev, unsigned int pipe, unsigned char *setup_packet, void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context){ spin_lock_init(&urb->lock); urb->dev = dev; urb->pipe = pipe; urb->setup_packet = setup_packet; urb->transfer_buffer = transfer_buffer; urb->transfer_buffer_length = buffer_length; urb->complete = complete; urb->context = context;}/** * usb_fill_bulk_urb - macro to help initialize a bulk urb * @urb: pointer to the urb to initialize. * @dev: pointer to the struct usb_device for this urb. * @pipe: the endpoint pipe * @transfer_buffer: pointer to the transfer buffer * @buffer_length: length of the transfer buffer * @complete: pointer to the usb_complete_t function * @context: what to set the urb context to. * * Initializes a bulk urb with the proper information needed to submit it * to a device. */static inline void usb_fill_bulk_urb (struct urb *urb, struct usb_device *dev, unsigned int pipe, void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context) { spin_lock_init(&urb->lock); urb->dev = dev; urb->pipe = pipe; urb->transfer_buffer = transfer_buffer; urb->transfer_buffer_length = buffer_length; urb->complete = complete; urb->context = context;} /** * usb_fill_int_urb - macro to help initialize a interrupt urb * @urb: pointer to the urb to initialize. * @dev: pointer to the struct usb_device for this urb. * @pipe: the endpoint pipe * @transfer_buffer: pointer to the transfer buffer * @buffer_length: length of the transfer buffer * @complete: pointer to the usb_complete_t function * @context: what to set the urb context to. * @interval: what to set the urb interval to. * * Initializes a interrupt urb with the proper information needed to submit * it to a device. */static inline void usb_fill_int_urb (struct urb *urb, struct usb_device *dev, unsigned int pipe, void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context, int interval){ spin_lock_init(&urb->lock); urb->dev = dev; urb->pipe = pipe; urb->transfer_buffer = transfer_buffer; urb->transfer_buffer_length = buffer_length; urb->complete = complete; urb->context = context; urb->interval = interval; urb->start_frame = -1;}struct urb *usb_alloc_urb(int iso_packets);void usb_free_urb (struct urb *urb);int usb_submit_urb(struct urb *urb);int usb_unlink_urb(struct urb *urb);int usb_internal_control_msg(struct usb_device *usb_dev, unsigned int pipe, struct usb_ctrlrequest *cmd, void *data, int len, int timeout);int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout);/*-------------------------------------------------------------------* * SYNCHRONOUS CALL SUPPORT * *-------------------------------------------------------------------*/struct usb_api_data{ wait_queue_head_t wqh; int done; /* void* stuff; */ /* Possible extension later. */};/* -------------------------------------------------------------------------- */struct usb_operations { int (*allocate)(struct usb_device *); int (*deallocate)(struct usb_device *); int (*get_frame_number) (struct usb_device *usb_dev);
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -