📄 usb.h
字号:
u8 level; /* Number of USB hub ancestors */ unsigned discon_suspended:1; /* Disconnected while suspended */ unsigned have_langid:1; /* whether string_langid is valid */ int string_langid; /* language ID for strings */ /* static strings from the device */ char *product; /* iProduct string, if present */ char *manufacturer; /* iManufacturer string, if present */ char *serial; /* iSerialNumber string, if present */ struct list_head filelist; struct class_device *class_dev; struct dentry *usbfs_dentry; /* usbfs dentry entry for the device */ /* * Child devices - these can be either new devices * (if this is a hub device), or different instances * of this same device. * * Each instance needs its own set of data structures. */ int maxchild; /* Number of ports if hub */ struct usb_device *children[USB_MAXCHILDREN]; int pm_usage_cnt; /* usage counter for autosuspend */#ifdef CONFIG_PM struct delayed_work autosuspend; /* for delayed autosuspends */ struct mutex pm_mutex; /* protects PM operations */ unsigned auto_pm:1; /* autosuspend/resume in progress */ unsigned do_remote_wakeup:1; /* remote wakeup should be enabled */#endif};#define to_usb_device(d) container_of(d, struct usb_device, dev)extern struct usb_device *usb_get_dev(struct usb_device *dev);extern void usb_put_dev(struct usb_device *dev);/* USB device locking */#define usb_lock_device(udev) down(&(udev)->dev.sem)#define usb_unlock_device(udev) up(&(udev)->dev.sem)#define usb_trylock_device(udev) down_trylock(&(udev)->dev.sem)extern int usb_lock_device_for_reset(struct usb_device *udev, const struct usb_interface *iface);/* USB port reset for device reinitialization */extern int usb_reset_device(struct usb_device *dev);extern int usb_reset_composite_device(struct usb_device *dev, struct usb_interface *iface);extern struct usb_device *usb_find_device(u16 vendor_id, u16 product_id);/* USB autosuspend and autoresume */#ifdef CONFIG_USB_SUSPENDextern int usb_autopm_set_interface(struct usb_interface *intf);extern int usb_autopm_get_interface(struct usb_interface *intf);extern void usb_autopm_put_interface(struct usb_interface *intf);static inline void usb_autopm_enable(struct usb_interface *intf){ intf->pm_usage_cnt = 0; usb_autopm_set_interface(intf);}static inline void usb_autopm_disable(struct usb_interface *intf){ intf->pm_usage_cnt = 1; usb_autopm_set_interface(intf);}#elsestatic inline int usb_autopm_set_interface(struct usb_interface *intf){ return 0; }static inline int usb_autopm_get_interface(struct usb_interface *intf){ return 0; }static inline void usb_autopm_put_interface(struct usb_interface *intf){ }static inline void usb_autopm_enable(struct usb_interface *intf){ }static inline void usb_autopm_disable(struct usb_interface *intf){ }#endif/*-------------------------------------------------------------------------*//* for drivers using iso endpoints */extern int usb_get_current_frame_number (struct usb_device *usb_dev);/* used these for multi-interface device registration */extern int usb_driver_claim_interface(struct usb_driver *driver, struct usb_interface *iface, void* priv);/** * usb_interface_claimed - returns true iff an interface is claimed * @iface: the interface being checked * * Returns true (nonzero) iff the interface is claimed, else false (zero). * Callers must own the driver model's usb bus readlock. So driver * probe() entries don't need extra locking, but other call contexts * may need to explicitly claim that lock. * */static inline int usb_interface_claimed(struct usb_interface *iface) { return (iface->dev.driver != NULL);}extern void usb_driver_release_interface(struct usb_driver *driver, struct usb_interface *iface);const struct usb_device_id *usb_match_id(struct usb_interface *interface, const struct usb_device_id *id);extern struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor);extern struct usb_interface *usb_ifnum_to_if(const struct usb_device *dev, unsigned ifnum);extern struct usb_host_interface *usb_altnum_to_altsetting( const struct usb_interface *intf, unsigned int altnum);/** * usb_make_path - returns stable device path in the usb tree * @dev: the device whose path is being constructed * @buf: where to put the string * @size: how big is "buf"? * * Returns length of the string (> 0) or negative if size was too small. * * This identifier is intended to be "stable", reflecting physical paths in * hardware such as physical bus addresses for host controllers or ports on * USB hubs. That makes it stay the same until systems are physically * reconfigured, by re-cabling a tree of USB devices or by moving USB host * controllers. Adding and removing devices, including virtual root hubs * in host controller driver modules, does not change these path identifers; * neither does rebooting or re-enumerating. These are more useful identifiers * than changeable ("unstable") ones like bus numbers or device addresses. * * With a partial exception for devices connected to USB 2.0 root hubs, these * identifiers are also predictable. So long as the device tree isn't changed, * plugging any USB device into a given hub port always gives it the same path. * Because of the use of "companion" controllers, devices connected to ports on * USB 2.0 root hubs (EHCI host controllers) will get one path ID if they are * high speed, and a different one if they are full or low speed. */static inline int usb_make_path (struct usb_device *dev, char *buf, int size){ int actual; actual = snprintf (buf, size, "usb-%s-%s", dev->bus->bus_name, dev->devpath); return (actual >= (int)size) ? -1 : actual;}/*-------------------------------------------------------------------------*//** * usb_endpoint_dir_in - check if the endpoint has IN direction * @epd: endpoint to be checked * * Returns true if the endpoint is of type IN, otherwise it returns false. */static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd){ return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);}/** * usb_endpoint_dir_out - check if the endpoint has OUT direction * @epd: endpoint to be checked * * Returns true if the endpoint is of type OUT, otherwise it returns false. */static inline int usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd){ return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);}/** * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type * @epd: endpoint to be checked * * Returns true if the endpoint is of type bulk, otherwise it returns false. */static inline int usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd){ return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK);}/** * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type * @epd: endpoint to be checked * * Returns true if the endpoint is of type interrupt, otherwise it returns * false. */static inline int usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd){ return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT);}/** * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type * @epd: endpoint to be checked * * Returns true if the endpoint is of type isochronous, otherwise it returns * false. */static inline int usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd){ return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_ISOC);}/** * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN * @epd: endpoint to be checked * * Returns true if the endpoint has bulk transfer type and IN direction, * otherwise it returns false. */static inline int usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd){ return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd));}/** * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT * @epd: endpoint to be checked * * Returns true if the endpoint has bulk transfer type and OUT direction, * otherwise it returns false. */static inline int usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd){ return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd));}/** * usb_endpoint_is_int_in - check if the endpoint is interrupt IN * @epd: endpoint to be checked * * Returns true if the endpoint has interrupt transfer type and IN direction, * otherwise it returns false. */static inline int usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd){ return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd));}/** * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT * @epd: endpoint to be checked * * Returns true if the endpoint has interrupt transfer type and OUT direction, * otherwise it returns false. */static inline int usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *epd){ return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd));}/** * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN * @epd: endpoint to be checked * * Returns true if the endpoint has isochronous transfer type and IN direction, * otherwise it returns false. */static inline int usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *epd){ return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd));}/** * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT * @epd: endpoint to be checked * * Returns true if the endpoint has isochronous transfer type and OUT direction, * otherwise it returns false. */static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor *epd){ return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd));}/*-------------------------------------------------------------------------*/#define USB_DEVICE_ID_MATCH_DEVICE \ (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)#define USB_DEVICE_ID_MATCH_DEV_RANGE \ (USB_DEVICE_ID_MATCH_DEV_LO | USB_DEVICE_ID_MATCH_DEV_HI)#define USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION \ (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_RANGE)#define USB_DEVICE_ID_MATCH_DEV_INFO \ (USB_DEVICE_ID_MATCH_DEV_CLASS | \ USB_DEVICE_ID_MATCH_DEV_SUBCLASS | \ USB_DEVICE_ID_MATCH_DEV_PROTOCOL)#define USB_DEVICE_ID_MATCH_INT_INFO \ (USB_DEVICE_ID_MATCH_INT_CLASS | \ USB_DEVICE_ID_MATCH_INT_SUBCLASS | \ USB_DEVICE_ID_MATCH_INT_PROTOCOL)/** * USB_DEVICE - macro used to describe a specific usb device * @vend: the 16 bit USB Vendor ID * @prod: the 16 bit USB Product ID * * This macro is used to create a struct usb_device_id that matches a * specific device. */#define USB_DEVICE(vend,prod) \ .match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = (vend), \ .idProduct = (prod)/** * USB_DEVICE_VER - macro used to describe a specific usb device with a * version range * @vend: the 16 bit USB Vendor ID * @prod: the 16 bit USB Product ID * @lo: the bcdDevice_lo value * @hi: the bcdDevice_hi value * * This macro is used to create a struct usb_device_id that matches a * specific device, with a version range. */#define USB_DEVICE_VER(vend,prod,lo,hi) \ .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, \ .idVendor = (vend), .idProduct = (prod), \ .bcdDevice_lo = (lo), .bcdDevice_hi = (hi)/** * USB_DEVICE_INFO - macro used to describe a class of usb devices * @cl: bDeviceClass value * @sc: bDeviceSubClass value * @pr: bDeviceProtocol value * * This macro is used to create a struct usb_device_id that matches a * specific class of devices. */#define USB_DEVICE_INFO(cl,sc,pr) \ .match_flags = USB_DEVICE_ID_MATCH_DEV_INFO, .bDeviceClass = (cl), \ .bDeviceSubClass = (sc), .bDeviceProtocol = (pr)/** * USB_INTERFACE_INFO - macro used to describe a class of usb interfaces * @cl: bInterfaceClass value * @sc: bInterfaceSubClass value * @pr: bInterfaceProtocol value * * This macro is used to create a struct usb_device_id that matches a * specific class of interfaces.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -