blob: cde6e52b84fec9c714ed1750ed3515887f89bc41 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Functions local to drivers/usb/core/ */
2
Greg Kroah-Hartman1b21d5e2006-08-28 11:43:25 -07003extern int usb_create_sysfs_dev_files (struct usb_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004extern void usb_remove_sysfs_dev_files (struct usb_device *dev);
Greg Kroah-Hartman1b21d5e2006-08-28 11:43:25 -07005extern int usb_create_sysfs_intf_files (struct usb_interface *intf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006extern void usb_remove_sysfs_intf_files (struct usb_interface *intf);
Greg Kroah-Hartman1b21d5e2006-08-28 11:43:25 -07007extern int usb_create_ep_files(struct device *parent, struct usb_host_endpoint *endpoint,
Greg Kroah-Hartman84412f62006-06-14 12:14:34 -07008 struct usb_device *udev);
9extern void usb_remove_ep_files(struct usb_host_endpoint *endpoint);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Alan Sternbdd016b2007-07-30 17:05:22 -040011extern void usb_enable_endpoint(struct usb_device *dev,
12 struct usb_host_endpoint *ep);
Linus Torvalds1da177e2005-04-16 15:20:36 -070013extern void usb_disable_endpoint (struct usb_device *dev, unsigned int epaddr);
14extern void usb_disable_interface (struct usb_device *dev,
15 struct usb_interface *intf);
16extern void usb_release_interface_cache(struct kref *ref);
17extern void usb_disable_device (struct usb_device *dev, int skip_ep0);
Oliver Neukum7ceec1f2007-01-26 14:26:21 +010018extern void usb_detect_quirks(struct usb_device *udev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20extern int usb_get_device_descriptor(struct usb_device *dev,
21 unsigned int size);
Alan Stern4f62efe2005-10-24 16:24:14 -040022extern char *usb_cache_string(struct usb_device *udev, int index);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023extern int usb_set_configuration(struct usb_device *dev, int configuration);
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025extern void usb_kick_khubd(struct usb_device *dev);
Greg Kroah-Hartmanbb417022007-01-26 14:26:21 +010026extern int usb_match_device(struct usb_device *dev,
27 const struct usb_device_id *id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Greg KH6d5e8252005-04-18 17:39:24 -070029extern int usb_hub_init(void);
30extern void usb_hub_cleanup(void);
31extern int usb_major_init(void);
32extern void usb_major_cleanup(void);
33extern int usb_host_init(void);
34extern void usb_host_cleanup(void);
35
Alan Sternd388dab2006-07-01 22:14:24 -040036#ifdef CONFIG_PM
37
Alan Stern718efa62007-03-09 15:41:13 -050038extern void usb_autosuspend_work(struct work_struct *work);
Alan Stern140d8f62006-07-01 22:07:21 -040039extern int usb_port_suspend(struct usb_device *dev);
40extern int usb_port_resume(struct usb_device *dev);
Alan Stern6b157c92007-03-13 16:37:30 -040041extern int usb_external_suspend_device(struct usb_device *udev,
42 pm_message_t msg);
43extern int usb_external_resume_device(struct usb_device *udev);
David Brownell5edbfb72005-09-22 22:45:26 -070044
Alan Sterne0318eb2006-09-26 14:50:20 -040045static inline void usb_pm_lock(struct usb_device *udev)
46{
47 mutex_lock_nested(&udev->pm_mutex, udev->level);
48}
49
50static inline void usb_pm_unlock(struct usb_device *udev)
51{
52 mutex_unlock(&udev->pm_mutex);
53}
54
Alan Sternd388dab2006-07-01 22:14:24 -040055#else
56
Alan Stern4956ecc2007-05-30 16:51:28 -040057static inline int usb_port_suspend(struct usb_device *udev)
58{
59 return 0;
60}
61
62static inline int usb_port_resume(struct usb_device *udev)
63{
64 return 0;
65}
66
Alan Sterne0318eb2006-09-26 14:50:20 -040067static inline void usb_pm_lock(struct usb_device *udev) {}
68static inline void usb_pm_unlock(struct usb_device *udev) {}
Alan Sternd388dab2006-07-01 22:14:24 -040069
70#endif
71
Alan Stern645daaa2006-08-30 15:47:02 -040072#ifdef CONFIG_USB_SUSPEND
73
Alan Stern94fcda12006-11-20 11:38:46 -050074extern void usb_autosuspend_device(struct usb_device *udev);
Alan Stern19c26232007-02-20 15:03:32 -050075extern void usb_try_autosuspend_device(struct usb_device *udev);
Alan Stern94fcda12006-11-20 11:38:46 -050076extern int usb_autoresume_device(struct usb_device *udev);
Alan Stern645daaa2006-08-30 15:47:02 -040077
78#else
79
Alan Stern19c26232007-02-20 15:03:32 -050080#define usb_autosuspend_device(udev) do {} while (0)
81#define usb_try_autosuspend_device(udev) do {} while (0)
Alan Stern94fcda12006-11-20 11:38:46 -050082static inline int usb_autoresume_device(struct usb_device *udev)
Alan Sterne0318eb2006-09-26 14:50:20 -040083{
84 return 0;
85}
Alan Stern645daaa2006-08-30 15:47:02 -040086
87#endif
88
Alan Sternbd859282006-09-19 10:14:07 -040089extern struct workqueue_struct *ksuspend_usb_wq;
Alan Stern36e56a32006-07-01 22:08:06 -040090extern struct bus_type usb_bus_type;
Kay Sievers9f8b17e2007-03-13 15:59:31 +010091extern struct device_type usb_device_type;
92extern struct device_type usb_if_device_type;
Alan Stern8bb54ab2006-07-01 22:08:49 -040093extern struct usb_device_driver usb_generic_driver;
94
Luiz Fernando N. Capitulino095bc332006-08-26 23:48:11 -030095static inline int is_usb_device(const struct device *dev)
Alan Stern8bb54ab2006-07-01 22:08:49 -040096{
Kay Sievers9f8b17e2007-03-13 15:59:31 +010097 return dev->type == &usb_device_type;
Alan Stern8bb54ab2006-07-01 22:08:49 -040098}
99
100/* Do the same for device drivers and interface drivers. */
101
102static inline int is_usb_device_driver(struct device_driver *drv)
103{
104 return container_of(drv, struct usbdrv_wrap, driver)->
105 for_devices;
106}
David Brownell5edbfb72005-09-22 22:45:26 -0700107
David Brownelldb690872005-09-13 19:56:33 -0700108/* Interfaces and their "power state" are owned by usbcore */
109
110static inline void mark_active(struct usb_interface *f)
111{
Alan Stern4d064c02006-07-01 22:11:44 -0400112 f->is_active = 1;
Alan Stern784a6e12007-05-04 11:49:57 -0400113 f->dev.power.power_state.event = PM_EVENT_ON;
David Brownelldb690872005-09-13 19:56:33 -0700114}
115
116static inline void mark_quiesced(struct usb_interface *f)
117{
Alan Stern4d064c02006-07-01 22:11:44 -0400118 f->is_active = 0;
Alan Stern784a6e12007-05-04 11:49:57 -0400119 f->dev.power.power_state.event = PM_EVENT_SUSPEND;
David Brownelldb690872005-09-13 19:56:33 -0700120}
121
Luiz Fernando N. Capitulino095bc332006-08-26 23:48:11 -0300122static inline int is_active(const struct usb_interface *f)
David Brownelldb690872005-09-13 19:56:33 -0700123{
Alan Stern4d064c02006-07-01 22:11:44 -0400124 return f->is_active;
David Brownelldb690872005-09-13 19:56:33 -0700125}
126
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128/* for labeling diagnostics */
129extern const char *usbcore_name;
130
131/* usbfs stuff */
Alan Stern4a2a8a22006-07-01 22:05:01 -0400132extern struct mutex usbfs_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133extern struct usb_driver usbfs_driver;
Luiz Fernando N. Capitulino066202d2006-08-05 20:37:11 -0300134extern const struct file_operations usbfs_devices_fops;
Kay Sievers9f8b17e2007-03-13 15:59:31 +0100135extern const struct file_operations usbdev_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136extern void usbfs_conn_disc_event(void);
137
Kay Sievers9f8b17e2007-03-13 15:59:31 +0100138extern int usb_devio_init(void);
139extern void usb_devio_cleanup(void);
Greg KH6d5e8252005-04-18 17:39:24 -0700140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141struct dev_state {
142 struct list_head list; /* state list */
143 struct usb_device *dev;
144 struct file *file;
145 spinlock_t lock; /* protects the async urb lists */
146 struct list_head async_pending;
147 struct list_head async_completed;
148 wait_queue_head_t wait; /* wake up if a request completed */
149 unsigned int discsignr;
Eric W. Biederman2425c082006-10-02 02:17:28 -0700150 struct pid *disc_pid;
Linus Torvaldsd7dd8a72005-10-10 16:31:30 -0700151 uid_t disc_uid, disc_euid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 void __user *disccontext;
153 unsigned long ifclaimed;
David Quigley7a019552006-06-30 01:55:48 -0700154 u32 secid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155};
156
Greg Kroah-Hartman3099e752005-06-20 21:15:16 -0700157/* internal notify stuff */
158extern void usb_notify_add_device(struct usb_device *udev);
159extern void usb_notify_remove_device(struct usb_device *udev);
160extern void usb_notify_add_bus(struct usb_bus *ubus);
161extern void usb_notify_remove_bus(struct usb_bus *ubus);
162