blob: c52626c51f70bd99859c170739eb20b7695937bb [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);
Inaky Perez-Gonzalez93993a02007-07-31 20:34:06 -070018extern int usb_deauthorize_device (struct usb_device *);
19extern int usb_authorize_device (struct usb_device *);
Oliver Neukum7ceec1f2007-01-26 14:26:21 +010020extern void usb_detect_quirks(struct usb_device *udev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22extern int usb_get_device_descriptor(struct usb_device *dev,
23 unsigned int size);
Alan Stern4f62efe2005-10-24 16:24:14 -040024extern char *usb_cache_string(struct usb_device *udev, int index);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025extern int usb_set_configuration(struct usb_device *dev, int configuration);
Greg Kroah-Hartmanb5ea0602007-08-02 22:44:27 -060026extern int usb_choose_configuration(struct usb_device *udev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Linus Torvalds1da177e2005-04-16 15:20:36 -070028extern void usb_kick_khubd(struct usb_device *dev);
Greg Kroah-Hartmanbb417022007-01-26 14:26:21 +010029extern int usb_match_device(struct usb_device *dev,
30 const struct usb_device_id *id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Greg KH6d5e8252005-04-18 17:39:24 -070032extern int usb_hub_init(void);
33extern void usb_hub_cleanup(void);
34extern int usb_major_init(void);
35extern void usb_major_cleanup(void);
36extern int usb_host_init(void);
37extern void usb_host_cleanup(void);
38
Alan Sternd388dab2006-07-01 22:14:24 -040039#ifdef CONFIG_PM
40
Alan Stern718efa62007-03-09 15:41:13 -050041extern void usb_autosuspend_work(struct work_struct *work);
Alan Stern140d8f62006-07-01 22:07:21 -040042extern int usb_port_suspend(struct usb_device *dev);
43extern int usb_port_resume(struct usb_device *dev);
Alan Stern6b157c92007-03-13 16:37:30 -040044extern int usb_external_suspend_device(struct usb_device *udev,
45 pm_message_t msg);
46extern int usb_external_resume_device(struct usb_device *udev);
David Brownell5edbfb72005-09-22 22:45:26 -070047
Alan Sterne0318eb2006-09-26 14:50:20 -040048static inline void usb_pm_lock(struct usb_device *udev)
49{
50 mutex_lock_nested(&udev->pm_mutex, udev->level);
51}
52
53static inline void usb_pm_unlock(struct usb_device *udev)
54{
55 mutex_unlock(&udev->pm_mutex);
56}
57
Alan Sternd388dab2006-07-01 22:14:24 -040058#else
59
Alan Stern4956ecc2007-05-30 16:51:28 -040060static inline int usb_port_suspend(struct usb_device *udev)
61{
62 return 0;
63}
64
65static inline int usb_port_resume(struct usb_device *udev)
66{
67 return 0;
68}
69
Alan Sterne0318eb2006-09-26 14:50:20 -040070static inline void usb_pm_lock(struct usb_device *udev) {}
71static inline void usb_pm_unlock(struct usb_device *udev) {}
Alan Sternd388dab2006-07-01 22:14:24 -040072
73#endif
74
Alan Stern645daaa2006-08-30 15:47:02 -040075#ifdef CONFIG_USB_SUSPEND
76
Alan Stern94fcda12006-11-20 11:38:46 -050077extern void usb_autosuspend_device(struct usb_device *udev);
Alan Stern19c26232007-02-20 15:03:32 -050078extern void usb_try_autosuspend_device(struct usb_device *udev);
Alan Stern94fcda12006-11-20 11:38:46 -050079extern int usb_autoresume_device(struct usb_device *udev);
Alan Stern645daaa2006-08-30 15:47:02 -040080
81#else
82
Alan Stern19c26232007-02-20 15:03:32 -050083#define usb_autosuspend_device(udev) do {} while (0)
84#define usb_try_autosuspend_device(udev) do {} while (0)
Alan Stern94fcda12006-11-20 11:38:46 -050085static inline int usb_autoresume_device(struct usb_device *udev)
Alan Sterne0318eb2006-09-26 14:50:20 -040086{
87 return 0;
88}
Alan Stern645daaa2006-08-30 15:47:02 -040089
90#endif
91
Alan Sternbd859282006-09-19 10:14:07 -040092extern struct workqueue_struct *ksuspend_usb_wq;
Alan Stern36e56a32006-07-01 22:08:06 -040093extern struct bus_type usb_bus_type;
Kay Sievers9f8b17e2007-03-13 15:59:31 +010094extern struct device_type usb_device_type;
95extern struct device_type usb_if_device_type;
Alan Stern8bb54ab2006-07-01 22:08:49 -040096extern struct usb_device_driver usb_generic_driver;
97
Luiz Fernando N. Capitulino095bc332006-08-26 23:48:11 -030098static inline int is_usb_device(const struct device *dev)
Alan Stern8bb54ab2006-07-01 22:08:49 -040099{
Kay Sievers9f8b17e2007-03-13 15:59:31 +0100100 return dev->type == &usb_device_type;
Alan Stern8bb54ab2006-07-01 22:08:49 -0400101}
102
103/* Do the same for device drivers and interface drivers. */
104
105static inline int is_usb_device_driver(struct device_driver *drv)
106{
107 return container_of(drv, struct usbdrv_wrap, driver)->
108 for_devices;
109}
David Brownell5edbfb72005-09-22 22:45:26 -0700110
David Brownelldb690872005-09-13 19:56:33 -0700111/* Interfaces and their "power state" are owned by usbcore */
112
113static inline void mark_active(struct usb_interface *f)
114{
Alan Stern4d064c02006-07-01 22:11:44 -0400115 f->is_active = 1;
Alan Stern784a6e12007-05-04 11:49:57 -0400116 f->dev.power.power_state.event = PM_EVENT_ON;
David Brownelldb690872005-09-13 19:56:33 -0700117}
118
119static inline void mark_quiesced(struct usb_interface *f)
120{
Alan Stern4d064c02006-07-01 22:11:44 -0400121 f->is_active = 0;
Alan Stern784a6e12007-05-04 11:49:57 -0400122 f->dev.power.power_state.event = PM_EVENT_SUSPEND;
David Brownelldb690872005-09-13 19:56:33 -0700123}
124
Luiz Fernando N. Capitulino095bc332006-08-26 23:48:11 -0300125static inline int is_active(const struct usb_interface *f)
David Brownelldb690872005-09-13 19:56:33 -0700126{
Alan Stern4d064c02006-07-01 22:11:44 -0400127 return f->is_active;
David Brownelldb690872005-09-13 19:56:33 -0700128}
129
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131/* for labeling diagnostics */
132extern const char *usbcore_name;
133
134/* usbfs stuff */
Alan Stern4a2a8a22006-07-01 22:05:01 -0400135extern struct mutex usbfs_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136extern struct usb_driver usbfs_driver;
Luiz Fernando N. Capitulino066202d2006-08-05 20:37:11 -0300137extern const struct file_operations usbfs_devices_fops;
Kay Sievers9f8b17e2007-03-13 15:59:31 +0100138extern const struct file_operations usbdev_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139extern void usbfs_conn_disc_event(void);
140
Kay Sievers9f8b17e2007-03-13 15:59:31 +0100141extern int usb_devio_init(void);
142extern void usb_devio_cleanup(void);
Greg KH6d5e8252005-04-18 17:39:24 -0700143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144struct dev_state {
145 struct list_head list; /* state list */
146 struct usb_device *dev;
147 struct file *file;
148 spinlock_t lock; /* protects the async urb lists */
149 struct list_head async_pending;
150 struct list_head async_completed;
151 wait_queue_head_t wait; /* wake up if a request completed */
152 unsigned int discsignr;
Eric W. Biederman2425c082006-10-02 02:17:28 -0700153 struct pid *disc_pid;
Linus Torvaldsd7dd8a72005-10-10 16:31:30 -0700154 uid_t disc_uid, disc_euid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 void __user *disccontext;
156 unsigned long ifclaimed;
David Quigley7a019552006-06-30 01:55:48 -0700157 u32 secid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158};
159
Greg Kroah-Hartman3099e752005-06-20 21:15:16 -0700160/* internal notify stuff */
161extern void usb_notify_add_device(struct usb_device *udev);
162extern void usb_notify_remove_device(struct usb_device *udev);
163extern void usb_notify_add_bus(struct usb_bus *ubus);
164extern void usb_notify_remove_bus(struct usb_bus *ubus);
165