xref: /openbmc/linux/drivers/usb/core/usb.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1e6075b66SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
2b65fba3dSGreg Kroah-Hartman /*
3b65fba3dSGreg Kroah-Hartman  * Released under the GPLv2 only.
4b65fba3dSGreg Kroah-Hartman  */
5b65fba3dSGreg Kroah-Hartman 
665bfd296SAlan Stern #include <linux/pm.h>
7d5575424SLan Tianyu #include <linux/acpi.h>
865bfd296SAlan Stern 
9d2123fd9SLan Tianyu struct usb_hub_descriptor;
109b6f0c4bSValentina Manea struct usb_dev_state;
11336c5c31SLan Tianyu 
121da177e4SLinus Torvalds /* Functions local to drivers/usb/core/ */
131da177e4SLinus Torvalds 
141b21d5e1SGreg Kroah-Hartman extern int usb_create_sysfs_dev_files(struct usb_device *dev);
151da177e4SLinus Torvalds extern void usb_remove_sysfs_dev_files(struct usb_device *dev);
16643de624SMichal Nazarewicz extern void usb_create_sysfs_intf_files(struct usb_interface *intf);
171da177e4SLinus Torvalds extern void usb_remove_sysfs_intf_files(struct usb_interface *intf);
18f98e0640SBastien Nocera extern int usb_update_wireless_status_attr(struct usb_interface *intf);
193b23dd6fSAlan Stern extern int usb_create_ep_devs(struct device *parent,
2084cca820SGreg Kroah-Hartman 				struct usb_host_endpoint *endpoint,
2184412f62SGreg Kroah-Hartman 				struct usb_device *udev);
223b23dd6fSAlan Stern extern void usb_remove_ep_devs(struct usb_host_endpoint *endpoint);
231da177e4SLinus Torvalds 
24bdd016baSAlan Stern extern void usb_enable_endpoint(struct usb_device *dev,
252caf7fcdSAlan Stern 		struct usb_host_endpoint *ep, bool reset_toggle);
262caf7fcdSAlan Stern extern void usb_enable_interface(struct usb_device *dev,
272caf7fcdSAlan Stern 		struct usb_interface *intf, bool reset_toggles);
28ddeac4e7SAlan Stern extern void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr,
29ddeac4e7SAlan Stern 		bool reset_hardware);
301da177e4SLinus Torvalds extern void usb_disable_interface(struct usb_device *dev,
31ddeac4e7SAlan Stern 		struct usb_interface *intf, bool reset_hardware);
321da177e4SLinus Torvalds extern void usb_release_interface_cache(struct kref *ref);
331da177e4SLinus Torvalds extern void usb_disable_device(struct usb_device *dev, int skip_ep0);
3493993a0aSInaky Perez-Gonzalez extern int usb_deauthorize_device(struct usb_device *);
3593993a0aSInaky Perez-Gonzalez extern int usb_authorize_device(struct usb_device *);
36b3910cefSStefan Koch extern void usb_deauthorize_interface(struct usb_interface *);
37b3910cefSStefan Koch extern void usb_authorize_interface(struct usb_interface *);
387ceec1f1SOliver Neukum extern void usb_detect_quirks(struct usb_device *udev);
3980da2e0dSLaurent Pinchart extern void usb_detect_interface_quirks(struct usb_device *udev);
40027bd6caSKai-Heng Feng extern void usb_release_quirk_list(void);
4191c7eaa6SGreg Kroah-Hartman extern bool usb_endpoint_is_ignored(struct usb_device *udev,
4273f8bda9SJohan Hovold 		struct usb_host_interface *intf,
4373f8bda9SJohan Hovold 		struct usb_endpoint_descriptor *epd);
44253e0572SAlan Stern extern int usb_remove_device(struct usb_device *udev);
451da177e4SLinus Torvalds 
46*de28e469SAlan Stern extern struct usb_device_descriptor *usb_get_device_descriptor(
47*de28e469SAlan Stern 		struct usb_device *udev);
48886ee36eSFelipe Balbi extern int usb_set_isoch_delay(struct usb_device *dev);
493148bf04SAndiry Xu extern int usb_get_bos_descriptor(struct usb_device *dev);
503148bf04SAndiry Xu extern void usb_release_bos_descriptor(struct usb_device *dev);
511da177e4SLinus Torvalds extern int usb_set_configuration(struct usb_device *dev, int configuration);
52b5ea060fSGreg Kroah-Hartman extern int usb_choose_configuration(struct usb_device *udev);
53ef0f7d18SBastien Nocera extern int usb_generic_driver_probe(struct usb_device *udev);
54ef0f7d18SBastien Nocera extern void usb_generic_driver_disconnect(struct usb_device *udev);
55ef0f7d18SBastien Nocera extern int usb_generic_driver_suspend(struct usb_device *udev,
56ef0f7d18SBastien Nocera 		pm_message_t msg);
57ef0f7d18SBastien Nocera extern int usb_generic_driver_resume(struct usb_device *udev,
58ef0f7d18SBastien Nocera 		pm_message_t msg);
591da177e4SLinus Torvalds 
usb_get_max_power(struct usb_device * udev,struct usb_host_config * c)608d8479dbSSebastian Andrzej Siewior static inline unsigned usb_get_max_power(struct usb_device *udev,
618d8479dbSSebastian Andrzej Siewior 		struct usb_host_config *c)
628d8479dbSSebastian Andrzej Siewior {
638d8479dbSSebastian Andrzej Siewior 	/* SuperSpeed power is in 8 mA units; others are in 2 mA units */
648a1b2725SMathias Nyman 	unsigned mul = (udev->speed >= USB_SPEED_SUPER ? 8 : 2);
658d8479dbSSebastian Andrzej Siewior 
668d8479dbSSebastian Andrzej Siewior 	return c->desc.bMaxPower * mul;
678d8479dbSSebastian Andrzej Siewior }
688d8479dbSSebastian Andrzej Siewior 
6959d48b3fSPetr Mladek extern void usb_kick_hub_wq(struct usb_device *dev);
7080da2e0dSLaurent Pinchart extern int usb_match_one_id_intf(struct usb_device *dev,
7180da2e0dSLaurent Pinchart 				 struct usb_host_interface *intf,
7280da2e0dSLaurent Pinchart 				 const struct usb_device_id *id);
73bb417020SGreg Kroah-Hartman extern int usb_match_device(struct usb_device *dev,
74bb417020SGreg Kroah-Hartman 			    const struct usb_device_id *id);
75aeebf2b5SBastien Nocera extern const struct usb_device_id *usb_device_match_id(struct usb_device *udev,
76aeebf2b5SBastien Nocera 				const struct usb_device_id *id);
770942d59bSBastien Nocera extern bool usb_driver_applicable(struct usb_device *udev,
780942d59bSBastien Nocera 				  struct usb_device_driver *udrv);
7978d9a487SAlan Stern extern void usb_forced_unbind_intf(struct usb_interface *intf);
806aec044cSAlan Stern extern void usb_unbind_and_rebind_marked_interfaces(struct usb_device *udev);
811da177e4SLinus Torvalds 
82336c5c31SLan Tianyu extern void usb_hub_release_all_ports(struct usb_device *hdev,
839b6f0c4bSValentina Manea 		struct usb_dev_state *owner);
847cbe5dcaSAlan Stern extern bool usb_device_is_owned(struct usb_device *udev);
857cbe5dcaSAlan Stern 
866d5e8254SGreg KH extern int  usb_hub_init(void);
876d5e8254SGreg KH extern void usb_hub_cleanup(void);
886d5e8254SGreg KH extern int usb_major_init(void);
896d5e8254SGreg KH extern void usb_major_cleanup(void);
902d2a3167SLu Baolu extern int usb_device_supports_lpm(struct usb_device *udev);
918dd8d2c9SDaniel Drake extern int usb_port_disable(struct usb_device *udev);
926d5e8254SGreg KH 
93d388dab7SAlan Stern #ifdef	CONFIG_PM
94d388dab7SAlan Stern 
95f2189c47SAlan Stern extern int usb_suspend(struct device *dev, pm_message_t msg);
9665bfd296SAlan Stern extern int usb_resume(struct device *dev, pm_message_t msg);
9798d9a82eSOliver Neukum extern int usb_resume_complete(struct device *dev);
98f2189c47SAlan Stern 
9965bfd296SAlan Stern extern int usb_port_suspend(struct usb_device *dev, pm_message_t msg);
10065bfd296SAlan Stern extern int usb_port_resume(struct usb_device *dev, pm_message_t msg);
101e0318ebfSAlan Stern 
102ceb6c9c8SRafael J. Wysocki extern void usb_autosuspend_device(struct usb_device *udev);
103ceb6c9c8SRafael J. Wysocki extern int usb_autoresume_device(struct usb_device *udev);
104ceb6c9c8SRafael J. Wysocki extern int usb_remote_wakeup(struct usb_device *dev);
105ceb6c9c8SRafael J. Wysocki extern int usb_runtime_suspend(struct device *dev);
106ceb6c9c8SRafael J. Wysocki extern int usb_runtime_resume(struct device *dev);
107ceb6c9c8SRafael J. Wysocki extern int usb_runtime_idle(struct device *dev);
1087529b257SKai-Heng Feng extern int usb_enable_usb2_hardware_lpm(struct usb_device *udev);
1097529b257SKai-Heng Feng extern int usb_disable_usb2_hardware_lpm(struct usb_device *udev);
110ceb6c9c8SRafael J. Wysocki 
1117794f486SAlan Stern extern void usbfs_notify_suspend(struct usb_device *udev);
1127794f486SAlan Stern extern void usbfs_notify_resume(struct usb_device *udev);
1137794f486SAlan Stern 
114d388dab7SAlan Stern #else
115d388dab7SAlan Stern 
usb_port_suspend(struct usb_device * udev,pm_message_t msg)11665bfd296SAlan Stern static inline int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
1174956eccdSAlan Stern {
1184956eccdSAlan Stern 	return 0;
1194956eccdSAlan Stern }
1204956eccdSAlan Stern 
usb_port_resume(struct usb_device * udev,pm_message_t msg)12165bfd296SAlan Stern static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg)
1224956eccdSAlan Stern {
1234956eccdSAlan Stern 	return 0;
1244956eccdSAlan Stern }
1254956eccdSAlan Stern 
12694fcda1fSAlan Stern #define usb_autosuspend_device(udev)		do {} while (0)
usb_autoresume_device(struct usb_device * udev)12794fcda1fSAlan Stern static inline int usb_autoresume_device(struct usb_device *udev)
128e0318ebfSAlan Stern {
129e0318ebfSAlan Stern 	return 0;
130e0318ebfSAlan Stern }
131645daaabSAlan Stern 
usb_enable_usb2_hardware_lpm(struct usb_device * udev)1327529b257SKai-Heng Feng static inline int usb_enable_usb2_hardware_lpm(struct usb_device *udev)
1337529b257SKai-Heng Feng {
1347529b257SKai-Heng Feng 	return 0;
1357529b257SKai-Heng Feng }
1367529b257SKai-Heng Feng 
usb_disable_usb2_hardware_lpm(struct usb_device * udev)1377529b257SKai-Heng Feng static inline int usb_disable_usb2_hardware_lpm(struct usb_device *udev)
13865580b43SAndiry Xu {
13965580b43SAndiry Xu 	return 0;
14065580b43SAndiry Xu }
141ceb6c9c8SRafael J. Wysocki 
142645daaabSAlan Stern #endif
143645daaabSAlan Stern 
144015fbddeSIvan Orlov extern const struct class usbmisc_class;
1459d11b134SGreg Kroah-Hartman extern const struct bus_type usb_bus_type;
146d8521afeSDan Williams extern struct mutex usb_port_peer_mutex;
1479f8b17e6SKay Sievers extern struct device_type usb_device_type;
1489f8b17e6SKay Sievers extern struct device_type usb_if_device_type;
14955129666SKay Sievers extern struct device_type usb_ep_device_type;
150d5575424SLan Tianyu extern struct device_type usb_port_device_type;
1518bb54ab5SAlan Stern extern struct usb_device_driver usb_generic_driver;
1528bb54ab5SAlan Stern 
is_usb_device(const struct device * dev)153095bc335SLuiz Fernando N. Capitulino static inline int is_usb_device(const struct device *dev)
1548bb54ab5SAlan Stern {
1559f8b17e6SKay Sievers 	return dev->type == &usb_device_type;
1568bb54ab5SAlan Stern }
1578bb54ab5SAlan Stern 
is_usb_interface(const struct device * dev)15855129666SKay Sievers static inline int is_usb_interface(const struct device *dev)
15955129666SKay Sievers {
16055129666SKay Sievers 	return dev->type == &usb_if_device_type;
16155129666SKay Sievers }
16255129666SKay Sievers 
is_usb_endpoint(const struct device * dev)16355129666SKay Sievers static inline int is_usb_endpoint(const struct device *dev)
16455129666SKay Sievers {
16555129666SKay Sievers 	return dev->type == &usb_ep_device_type;
16655129666SKay Sievers }
16755129666SKay Sievers 
is_usb_port(const struct device * dev)168d5575424SLan Tianyu static inline int is_usb_port(const struct device *dev)
169d5575424SLan Tianyu {
170d5575424SLan Tianyu 	return dev->type == &usb_port_device_type;
171d5575424SLan Tianyu }
172d5575424SLan Tianyu 
is_root_hub(struct usb_device * udev)17327709ae4SThiébaud Weksteen static inline int is_root_hub(struct usb_device *udev)
17427709ae4SThiébaud Weksteen {
17527709ae4SThiébaud Weksteen 	return (udev->parent == NULL);
17627709ae4SThiébaud Weksteen }
17727709ae4SThiébaud Weksteen 
1788bb54ab5SAlan Stern /* Do the same for device drivers and interface drivers. */
1798bb54ab5SAlan Stern 
is_usb_device_driver(struct device_driver * drv)1808bb54ab5SAlan Stern static inline int is_usb_device_driver(struct device_driver *drv)
1818bb54ab5SAlan Stern {
1828bb54ab5SAlan Stern 	return container_of(drv, struct usbdrv_wrap, driver)->
1838bb54ab5SAlan Stern 			for_devices;
1848bb54ab5SAlan Stern }
1855edbfb7cSDavid Brownell 
1861da177e4SLinus Torvalds /* for labeling diagnostics */
1871da177e4SLinus Torvalds extern const char *usbcore_name;
1881da177e4SLinus Torvalds 
1892e5f10e4SAlan Stern /* sysfs stuff */
190a4dbd674SDavid Brownell extern const struct attribute_group *usb_device_groups[];
191a4dbd674SDavid Brownell extern const struct attribute_group *usb_interface_groups[];
1922e5f10e4SAlan Stern 
1931da177e4SLinus Torvalds /* usbfs stuff */
1941da177e4SLinus Torvalds extern struct usb_driver usbfs_driver;
195066202ddSLuiz Fernando N. Capitulino extern const struct file_operations usbfs_devices_fops;
1969f8b17e6SKay Sievers extern const struct file_operations usbdev_file_operations;
1971da177e4SLinus Torvalds 
1989f8b17e6SKay Sievers extern int usb_devio_init(void);
1999f8b17e6SKay Sievers extern void usb_devio_cleanup(void);
2006d5e8254SGreg KH 
2013bfd659bSDan Williams /*
2023bfd659bSDan Williams  * Firmware specific cookie identifying a port's location. '0' == no location
2033bfd659bSDan Williams  * data available
2043bfd659bSDan Williams  */
2053bfd659bSDan Williams typedef u32 usb_port_location_t;
2063bfd659bSDan Williams 
2073099e75aSGreg Kroah-Hartman /* internal notify stuff */
2083099e75aSGreg Kroah-Hartman extern void usb_notify_add_device(struct usb_device *udev);
2093099e75aSGreg Kroah-Hartman extern void usb_notify_remove_device(struct usb_device *udev);
2103099e75aSGreg Kroah-Hartman extern void usb_notify_add_bus(struct usb_bus *ubus);
2113099e75aSGreg Kroah-Hartman extern void usb_notify_remove_bus(struct usb_bus *ubus);
212d2123fd9SLan Tianyu extern void usb_hub_adjust_deviceremovable(struct usb_device *hdev,
213d2123fd9SLan Tianyu 		struct usb_hub_descriptor *desc);
2143099e75aSGreg Kroah-Hartman 
215da0af6e7SMatthew Garrett #ifdef CONFIG_ACPI
216da0af6e7SMatthew Garrett extern int usb_acpi_register(void);
217da0af6e7SMatthew Garrett extern void usb_acpi_unregister(void);
218d5575424SLan Tianyu extern acpi_handle usb_get_hub_port_acpi_handle(struct usb_device *hdev,
219d5575424SLan Tianyu 	int port1);
220da0af6e7SMatthew Garrett #else
usb_acpi_register(void)221da0af6e7SMatthew Garrett static inline int usb_acpi_register(void) { return 0; };
usb_acpi_unregister(void)222da0af6e7SMatthew Garrett static inline void usb_acpi_unregister(void) { };
223da0af6e7SMatthew Garrett #endif
224