blob: 53318126ed91b24603934030702a0dae178cc5d1 [file] [log] [blame]
Alan Stern65bfd292008-11-25 16:39:18 -05001#include <linux/pm.h>
Lan Tianyud5575422012-09-05 13:44:33 +08002#include <linux/acpi.h>
Alan Stern65bfd292008-11-25 16:39:18 -05003
Lan Tianyud2123fd2013-01-21 22:18:00 +08004struct usb_hub_descriptor;
Valentina Manea9b6f0c42014-03-10 10:36:40 +02005struct usb_dev_state;
Lan Tianyu336c5c32012-07-06 14:13:52 +08006
Linus Torvalds1da177e2005-04-16 15:20:36 -07007/* Functions local to drivers/usb/core/ */
8
Greg Kroah-Hartman84cca822008-01-30 15:21:33 -08009extern int usb_create_sysfs_dev_files(struct usb_device *dev);
10extern void usb_remove_sysfs_dev_files(struct usb_device *dev);
Michal Nazarewicz643de622011-04-14 17:47:09 +020011extern void usb_create_sysfs_intf_files(struct usb_interface *intf);
Greg Kroah-Hartman84cca822008-01-30 15:21:33 -080012extern void usb_remove_sysfs_intf_files(struct usb_interface *intf);
Alan Stern3b23dd62008-12-05 14:10:34 -050013extern int usb_create_ep_devs(struct device *parent,
Greg Kroah-Hartman84cca822008-01-30 15:21:33 -080014 struct usb_host_endpoint *endpoint,
Greg Kroah-Hartman84412f62006-06-14 12:14:34 -070015 struct usb_device *udev);
Alan Stern3b23dd62008-12-05 14:10:34 -050016extern void usb_remove_ep_devs(struct usb_host_endpoint *endpoint);
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Alan Sternbdd016b2007-07-30 17:05:22 -040018extern void usb_enable_endpoint(struct usb_device *dev,
Alan Stern2caf7fc2008-12-31 11:31:33 -050019 struct usb_host_endpoint *ep, bool reset_toggle);
20extern void usb_enable_interface(struct usb_device *dev,
21 struct usb_interface *intf, bool reset_toggles);
Alan Sternddeac4e72009-01-15 17:03:33 -050022extern void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr,
23 bool reset_hardware);
Greg Kroah-Hartman84cca822008-01-30 15:21:33 -080024extern void usb_disable_interface(struct usb_device *dev,
Alan Sternddeac4e72009-01-15 17:03:33 -050025 struct usb_interface *intf, bool reset_hardware);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026extern void usb_release_interface_cache(struct kref *ref);
Greg Kroah-Hartman84cca822008-01-30 15:21:33 -080027extern void usb_disable_device(struct usb_device *dev, int skip_ep0);
28extern int usb_deauthorize_device(struct usb_device *);
29extern int usb_authorize_device(struct usb_device *);
Stefan Kochb3910ce2015-08-25 21:10:08 +020030extern void usb_deauthorize_interface(struct usb_interface *);
31extern void usb_authorize_interface(struct usb_interface *);
Oliver Neukum7ceec1f2007-01-26 14:26:21 +010032extern void usb_detect_quirks(struct usb_device *udev);
Laurent Pinchart80da2e02012-07-19 12:39:13 +020033extern void usb_detect_interface_quirks(struct usb_device *udev);
Alan Stern253e0572009-10-27 15:20:13 -040034extern int usb_remove_device(struct usb_device *udev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36extern int usb_get_device_descriptor(struct usb_device *dev,
37 unsigned int size);
Andiry Xu3148bf02011-09-23 14:19:47 -070038extern int usb_get_bos_descriptor(struct usb_device *dev);
39extern void usb_release_bos_descriptor(struct usb_device *dev);
Alan Stern4f62efe2005-10-24 16:24:14 -040040extern char *usb_cache_string(struct usb_device *udev, int index);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041extern int usb_set_configuration(struct usb_device *dev, int configuration);
Greg Kroah-Hartmanb5ea0602007-08-02 22:44:27 -060042extern int usb_choose_configuration(struct usb_device *udev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Sebastian Andrzej Siewior8d8479d2012-12-18 15:25:46 +010044static inline unsigned usb_get_max_power(struct usb_device *udev,
45 struct usb_host_config *c)
46{
47 /* SuperSpeed power is in 8 mA units; others are in 2 mA units */
Mathias Nyman8a1b2722015-12-10 09:59:25 +020048 unsigned mul = (udev->speed >= USB_SPEED_SUPER ? 8 : 2);
Sebastian Andrzej Siewior8d8479d2012-12-18 15:25:46 +010049
50 return c->desc.bMaxPower * mul;
51}
52
Petr Mladek59d48b32014-09-19 17:32:22 +020053extern void usb_kick_hub_wq(struct usb_device *dev);
Laurent Pinchart80da2e02012-07-19 12:39:13 +020054extern int usb_match_one_id_intf(struct usb_device *dev,
55 struct usb_host_interface *intf,
56 const struct usb_device_id *id);
Greg Kroah-Hartmanbb417022007-01-26 14:26:21 +010057extern int usb_match_device(struct usb_device *dev,
58 const struct usb_device_id *id);
Alan Stern78d9a482008-06-23 16:00:40 -040059extern void usb_forced_unbind_intf(struct usb_interface *intf);
Alan Stern6aec0442014-03-12 11:30:38 -040060extern void usb_unbind_and_rebind_marked_interfaces(struct usb_device *udev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Lan Tianyu336c5c32012-07-06 14:13:52 +080062extern void usb_hub_release_all_ports(struct usb_device *hdev,
Valentina Manea9b6f0c42014-03-10 10:36:40 +020063 struct usb_dev_state *owner);
Alan Stern7cbe5dc2009-06-29 10:56:54 -040064extern bool usb_device_is_owned(struct usb_device *udev);
65
Greg KH6d5e8252005-04-18 17:39:24 -070066extern int usb_hub_init(void);
67extern void usb_hub_cleanup(void);
68extern int usb_major_init(void);
69extern void usb_major_cleanup(void);
Lu Baolu2d2a3162015-06-16 09:08:26 +080070extern int usb_device_supports_lpm(struct usb_device *udev);
Greg KH6d5e8252005-04-18 17:39:24 -070071
Alan Sternd388dab2006-07-01 22:14:24 -040072#ifdef CONFIG_PM
73
Alan Sternf2189c42008-08-12 14:34:10 -040074extern int usb_suspend(struct device *dev, pm_message_t msg);
Alan Stern65bfd292008-11-25 16:39:18 -050075extern int usb_resume(struct device *dev, pm_message_t msg);
Oliver Neukum98d9a822012-01-11 08:38:35 +010076extern int usb_resume_complete(struct device *dev);
Alan Sternf2189c42008-08-12 14:34:10 -040077
Alan Stern65bfd292008-11-25 16:39:18 -050078extern int usb_port_suspend(struct usb_device *dev, pm_message_t msg);
79extern int usb_port_resume(struct usb_device *dev, pm_message_t msg);
Alan Sterne0318eb2006-09-26 14:50:20 -040080
Rafael J. Wysockiceb6c9c2014-11-29 23:47:05 +010081extern void usb_autosuspend_device(struct usb_device *udev);
82extern int usb_autoresume_device(struct usb_device *udev);
83extern int usb_remote_wakeup(struct usb_device *dev);
84extern int usb_runtime_suspend(struct device *dev);
85extern int usb_runtime_resume(struct device *dev);
86extern int usb_runtime_idle(struct device *dev);
87extern int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable);
88
Alan Sternd388dab2006-07-01 22:14:24 -040089#else
90
Alan Stern65bfd292008-11-25 16:39:18 -050091static inline int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
Alan Stern4956ecc2007-05-30 16:51:28 -040092{
93 return 0;
94}
95
Alan Stern65bfd292008-11-25 16:39:18 -050096static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg)
Alan Stern4956ecc2007-05-30 16:51:28 -040097{
98 return 0;
99}
100
Alan Stern19c26232007-02-20 15:03:32 -0500101#define usb_autosuspend_device(udev) do {} while (0)
Alan Stern94fcda12006-11-20 11:38:46 -0500102static inline int usb_autoresume_device(struct usb_device *udev)
Alan Sterne0318eb2006-09-26 14:50:20 -0400103{
104 return 0;
105}
Alan Stern645daaa2006-08-30 15:47:02 -0400106
Andiry Xu65580b432011-09-23 14:19:52 -0700107static inline int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable)
108{
109 return 0;
110}
Rafael J. Wysockiceb6c9c2014-11-29 23:47:05 +0100111
Alan Stern645daaa2006-08-30 15:47:02 -0400112#endif
113
Alan Stern36e56a32006-07-01 22:08:06 -0400114extern struct bus_type usb_bus_type;
Dan Williamsd8521af2014-05-20 18:08:28 -0700115extern struct mutex usb_port_peer_mutex;
Kay Sievers9f8b17e2007-03-13 15:59:31 +0100116extern struct device_type usb_device_type;
117extern struct device_type usb_if_device_type;
Kay Sievers55129662009-05-04 19:48:32 +0200118extern struct device_type usb_ep_device_type;
Lan Tianyud5575422012-09-05 13:44:33 +0800119extern struct device_type usb_port_device_type;
Alan Stern8bb54ab2006-07-01 22:08:49 -0400120extern struct usb_device_driver usb_generic_driver;
121
Luiz Fernando N. Capitulino095bc332006-08-26 23:48:11 -0300122static inline int is_usb_device(const struct device *dev)
Alan Stern8bb54ab2006-07-01 22:08:49 -0400123{
Kay Sievers9f8b17e2007-03-13 15:59:31 +0100124 return dev->type == &usb_device_type;
Alan Stern8bb54ab2006-07-01 22:08:49 -0400125}
126
Kay Sievers55129662009-05-04 19:48:32 +0200127static inline int is_usb_interface(const struct device *dev)
128{
129 return dev->type == &usb_if_device_type;
130}
131
132static inline int is_usb_endpoint(const struct device *dev)
133{
134 return dev->type == &usb_ep_device_type;
135}
136
Lan Tianyud5575422012-09-05 13:44:33 +0800137static inline int is_usb_port(const struct device *dev)
138{
139 return dev->type == &usb_port_device_type;
140}
141
Alan Stern8bb54ab2006-07-01 22:08:49 -0400142/* Do the same for device drivers and interface drivers. */
143
144static inline int is_usb_device_driver(struct device_driver *drv)
145{
146 return container_of(drv, struct usbdrv_wrap, driver)->
147 for_devices;
148}
David Brownell5edbfb72005-09-22 22:45:26 -0700149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150/* for labeling diagnostics */
151extern const char *usbcore_name;
152
Alan Stern2e5f10e2008-04-30 15:37:19 -0400153/* sysfs stuff */
David Brownella4dbd672009-06-24 10:06:31 -0700154extern const struct attribute_group *usb_device_groups[];
155extern const struct attribute_group *usb_interface_groups[];
Alan Stern2e5f10e2008-04-30 15:37:19 -0400156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157/* usbfs stuff */
Alan Stern4a2a8a22006-07-01 22:05:01 -0400158extern struct mutex usbfs_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159extern struct usb_driver usbfs_driver;
Luiz Fernando N. Capitulino066202d2006-08-05 20:37:11 -0300160extern const struct file_operations usbfs_devices_fops;
Kay Sievers9f8b17e2007-03-13 15:59:31 +0100161extern const struct file_operations usbdev_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162extern void usbfs_conn_disc_event(void);
163
Kay Sievers9f8b17e2007-03-13 15:59:31 +0100164extern int usb_devio_init(void);
165extern void usb_devio_cleanup(void);
Greg KH6d5e8252005-04-18 17:39:24 -0700166
Dan Williams3bfd6592014-05-20 18:08:40 -0700167/*
168 * Firmware specific cookie identifying a port's location. '0' == no location
169 * data available
170 */
171typedef u32 usb_port_location_t;
172
Greg Kroah-Hartman3099e752005-06-20 21:15:16 -0700173/* internal notify stuff */
174extern void usb_notify_add_device(struct usb_device *udev);
175extern void usb_notify_remove_device(struct usb_device *udev);
176extern void usb_notify_add_bus(struct usb_bus *ubus);
177extern void usb_notify_remove_bus(struct usb_bus *ubus);
Lan Tianyud2123fd2013-01-21 22:18:00 +0800178extern void usb_hub_adjust_deviceremovable(struct usb_device *hdev,
179 struct usb_hub_descriptor *desc);
Greg Kroah-Hartman3099e752005-06-20 21:15:16 -0700180
Matthew Garrettda0af6e2012-05-11 16:08:27 +0800181#ifdef CONFIG_ACPI
182extern int usb_acpi_register(void);
183extern void usb_acpi_unregister(void);
Lan Tianyud5575422012-09-05 13:44:33 +0800184extern acpi_handle usb_get_hub_port_acpi_handle(struct usb_device *hdev,
185 int port1);
Matthew Garrettda0af6e2012-05-11 16:08:27 +0800186#else
187static inline int usb_acpi_register(void) { return 0; };
188static inline void usb_acpi_unregister(void) { };
189#endif