18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Released under the GPLv2 only.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <linux/pm.h>
78c2ecf20Sopenharmony_ci#include <linux/acpi.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_cistruct usb_hub_descriptor;
108c2ecf20Sopenharmony_cistruct usb_dev_state;
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/* Functions local to drivers/usb/core/ */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciextern int usb_create_sysfs_dev_files(struct usb_device *dev);
158c2ecf20Sopenharmony_ciextern void usb_remove_sysfs_dev_files(struct usb_device *dev);
168c2ecf20Sopenharmony_ciextern void usb_create_sysfs_intf_files(struct usb_interface *intf);
178c2ecf20Sopenharmony_ciextern void usb_remove_sysfs_intf_files(struct usb_interface *intf);
188c2ecf20Sopenharmony_ciextern int usb_create_ep_devs(struct device *parent,
198c2ecf20Sopenharmony_ci				struct usb_host_endpoint *endpoint,
208c2ecf20Sopenharmony_ci				struct usb_device *udev);
218c2ecf20Sopenharmony_ciextern void usb_remove_ep_devs(struct usb_host_endpoint *endpoint);
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ciextern void usb_enable_endpoint(struct usb_device *dev,
248c2ecf20Sopenharmony_ci		struct usb_host_endpoint *ep, bool reset_toggle);
258c2ecf20Sopenharmony_ciextern void usb_enable_interface(struct usb_device *dev,
268c2ecf20Sopenharmony_ci		struct usb_interface *intf, bool reset_toggles);
278c2ecf20Sopenharmony_ciextern void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr,
288c2ecf20Sopenharmony_ci		bool reset_hardware);
298c2ecf20Sopenharmony_ciextern void usb_disable_interface(struct usb_device *dev,
308c2ecf20Sopenharmony_ci		struct usb_interface *intf, bool reset_hardware);
318c2ecf20Sopenharmony_ciextern void usb_release_interface_cache(struct kref *ref);
328c2ecf20Sopenharmony_ciextern void usb_disable_device(struct usb_device *dev, int skip_ep0);
338c2ecf20Sopenharmony_ciextern int usb_deauthorize_device(struct usb_device *);
348c2ecf20Sopenharmony_ciextern int usb_authorize_device(struct usb_device *);
358c2ecf20Sopenharmony_ciextern void usb_deauthorize_interface(struct usb_interface *);
368c2ecf20Sopenharmony_ciextern void usb_authorize_interface(struct usb_interface *);
378c2ecf20Sopenharmony_ciextern void usb_detect_quirks(struct usb_device *udev);
388c2ecf20Sopenharmony_ciextern void usb_detect_interface_quirks(struct usb_device *udev);
398c2ecf20Sopenharmony_ciextern void usb_release_quirk_list(void);
408c2ecf20Sopenharmony_ciextern bool usb_endpoint_is_ignored(struct usb_device *udev,
418c2ecf20Sopenharmony_ci		struct usb_host_interface *intf,
428c2ecf20Sopenharmony_ci		struct usb_endpoint_descriptor *epd);
438c2ecf20Sopenharmony_ciextern int usb_remove_device(struct usb_device *udev);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ciextern struct usb_device_descriptor *usb_get_device_descriptor(
468c2ecf20Sopenharmony_ci		struct usb_device *udev);
478c2ecf20Sopenharmony_ciextern int usb_set_isoch_delay(struct usb_device *dev);
488c2ecf20Sopenharmony_ciextern int usb_get_bos_descriptor(struct usb_device *dev);
498c2ecf20Sopenharmony_ciextern void usb_release_bos_descriptor(struct usb_device *dev);
508c2ecf20Sopenharmony_ciextern char *usb_cache_string(struct usb_device *udev, int index);
518c2ecf20Sopenharmony_ciextern int usb_set_configuration(struct usb_device *dev, int configuration);
528c2ecf20Sopenharmony_ciextern int usb_choose_configuration(struct usb_device *udev);
538c2ecf20Sopenharmony_ciextern int usb_generic_driver_probe(struct usb_device *udev);
548c2ecf20Sopenharmony_ciextern void usb_generic_driver_disconnect(struct usb_device *udev);
558c2ecf20Sopenharmony_ciextern int usb_generic_driver_suspend(struct usb_device *udev,
568c2ecf20Sopenharmony_ci		pm_message_t msg);
578c2ecf20Sopenharmony_ciextern int usb_generic_driver_resume(struct usb_device *udev,
588c2ecf20Sopenharmony_ci		pm_message_t msg);
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic inline unsigned usb_get_max_power(struct usb_device *udev,
618c2ecf20Sopenharmony_ci		struct usb_host_config *c)
628c2ecf20Sopenharmony_ci{
638c2ecf20Sopenharmony_ci	/* SuperSpeed power is in 8 mA units; others are in 2 mA units */
648c2ecf20Sopenharmony_ci	unsigned mul = (udev->speed >= USB_SPEED_SUPER ? 8 : 2);
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci	return c->desc.bMaxPower * mul;
678c2ecf20Sopenharmony_ci}
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciextern void usb_kick_hub_wq(struct usb_device *dev);
708c2ecf20Sopenharmony_ciextern int usb_match_one_id_intf(struct usb_device *dev,
718c2ecf20Sopenharmony_ci				 struct usb_host_interface *intf,
728c2ecf20Sopenharmony_ci				 const struct usb_device_id *id);
738c2ecf20Sopenharmony_ciextern int usb_match_device(struct usb_device *dev,
748c2ecf20Sopenharmony_ci			    const struct usb_device_id *id);
758c2ecf20Sopenharmony_ciextern const struct usb_device_id *usb_device_match_id(struct usb_device *udev,
768c2ecf20Sopenharmony_ci				const struct usb_device_id *id);
778c2ecf20Sopenharmony_ciextern bool usb_driver_applicable(struct usb_device *udev,
788c2ecf20Sopenharmony_ci				  struct usb_device_driver *udrv);
798c2ecf20Sopenharmony_ciextern void usb_forced_unbind_intf(struct usb_interface *intf);
808c2ecf20Sopenharmony_ciextern void usb_unbind_and_rebind_marked_interfaces(struct usb_device *udev);
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ciextern void usb_hub_release_all_ports(struct usb_device *hdev,
838c2ecf20Sopenharmony_ci		struct usb_dev_state *owner);
848c2ecf20Sopenharmony_ciextern bool usb_device_is_owned(struct usb_device *udev);
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ciextern int  usb_hub_init(void);
878c2ecf20Sopenharmony_ciextern void usb_hub_cleanup(void);
888c2ecf20Sopenharmony_ciextern int usb_major_init(void);
898c2ecf20Sopenharmony_ciextern void usb_major_cleanup(void);
908c2ecf20Sopenharmony_ciextern int usb_device_supports_lpm(struct usb_device *udev);
918c2ecf20Sopenharmony_ciextern int usb_port_disable(struct usb_device *udev);
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#ifdef	CONFIG_PM
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ciextern int usb_suspend(struct device *dev, pm_message_t msg);
968c2ecf20Sopenharmony_ciextern int usb_resume(struct device *dev, pm_message_t msg);
978c2ecf20Sopenharmony_ciextern int usb_resume_complete(struct device *dev);
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ciextern int usb_port_suspend(struct usb_device *dev, pm_message_t msg);
1008c2ecf20Sopenharmony_ciextern int usb_port_resume(struct usb_device *dev, pm_message_t msg);
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ciextern void usb_autosuspend_device(struct usb_device *udev);
1038c2ecf20Sopenharmony_ciextern int usb_autoresume_device(struct usb_device *udev);
1048c2ecf20Sopenharmony_ciextern int usb_remote_wakeup(struct usb_device *dev);
1058c2ecf20Sopenharmony_ciextern int usb_runtime_suspend(struct device *dev);
1068c2ecf20Sopenharmony_ciextern int usb_runtime_resume(struct device *dev);
1078c2ecf20Sopenharmony_ciextern int usb_runtime_idle(struct device *dev);
1088c2ecf20Sopenharmony_ciextern int usb_enable_usb2_hardware_lpm(struct usb_device *udev);
1098c2ecf20Sopenharmony_ciextern int usb_disable_usb2_hardware_lpm(struct usb_device *udev);
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ciextern void usbfs_notify_suspend(struct usb_device *udev);
1128c2ecf20Sopenharmony_ciextern void usbfs_notify_resume(struct usb_device *udev);
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci#else
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistatic inline int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
1178c2ecf20Sopenharmony_ci{
1188c2ecf20Sopenharmony_ci	return 0;
1198c2ecf20Sopenharmony_ci}
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistatic inline int usb_port_resume(struct usb_device *udev, pm_message_t msg)
1228c2ecf20Sopenharmony_ci{
1238c2ecf20Sopenharmony_ci	return 0;
1248c2ecf20Sopenharmony_ci}
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#define usb_autosuspend_device(udev)		do {} while (0)
1278c2ecf20Sopenharmony_cistatic inline int usb_autoresume_device(struct usb_device *udev)
1288c2ecf20Sopenharmony_ci{
1298c2ecf20Sopenharmony_ci	return 0;
1308c2ecf20Sopenharmony_ci}
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistatic inline int usb_enable_usb2_hardware_lpm(struct usb_device *udev)
1338c2ecf20Sopenharmony_ci{
1348c2ecf20Sopenharmony_ci	return 0;
1358c2ecf20Sopenharmony_ci}
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cistatic inline int usb_disable_usb2_hardware_lpm(struct usb_device *udev)
1388c2ecf20Sopenharmony_ci{
1398c2ecf20Sopenharmony_ci	return 0;
1408c2ecf20Sopenharmony_ci}
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci#endif
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ciextern struct bus_type usb_bus_type;
1458c2ecf20Sopenharmony_ciextern struct mutex usb_port_peer_mutex;
1468c2ecf20Sopenharmony_ciextern struct device_type usb_device_type;
1478c2ecf20Sopenharmony_ciextern struct device_type usb_if_device_type;
1488c2ecf20Sopenharmony_ciextern struct device_type usb_ep_device_type;
1498c2ecf20Sopenharmony_ciextern struct device_type usb_port_device_type;
1508c2ecf20Sopenharmony_ciextern struct usb_device_driver usb_generic_driver;
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_cistatic inline int is_usb_device(const struct device *dev)
1538c2ecf20Sopenharmony_ci{
1548c2ecf20Sopenharmony_ci	return dev->type == &usb_device_type;
1558c2ecf20Sopenharmony_ci}
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_cistatic inline int is_usb_interface(const struct device *dev)
1588c2ecf20Sopenharmony_ci{
1598c2ecf20Sopenharmony_ci	return dev->type == &usb_if_device_type;
1608c2ecf20Sopenharmony_ci}
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_cistatic inline int is_usb_endpoint(const struct device *dev)
1638c2ecf20Sopenharmony_ci{
1648c2ecf20Sopenharmony_ci	return dev->type == &usb_ep_device_type;
1658c2ecf20Sopenharmony_ci}
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cistatic inline int is_usb_port(const struct device *dev)
1688c2ecf20Sopenharmony_ci{
1698c2ecf20Sopenharmony_ci	return dev->type == &usb_port_device_type;
1708c2ecf20Sopenharmony_ci}
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_cistatic inline int is_root_hub(struct usb_device *udev)
1738c2ecf20Sopenharmony_ci{
1748c2ecf20Sopenharmony_ci	return (udev->parent == NULL);
1758c2ecf20Sopenharmony_ci}
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci/* Do the same for device drivers and interface drivers. */
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_cistatic inline int is_usb_device_driver(struct device_driver *drv)
1808c2ecf20Sopenharmony_ci{
1818c2ecf20Sopenharmony_ci	return container_of(drv, struct usbdrv_wrap, driver)->
1828c2ecf20Sopenharmony_ci			for_devices;
1838c2ecf20Sopenharmony_ci}
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci/* for labeling diagnostics */
1868c2ecf20Sopenharmony_ciextern const char *usbcore_name;
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci/* sysfs stuff */
1898c2ecf20Sopenharmony_ciextern const struct attribute_group *usb_device_groups[];
1908c2ecf20Sopenharmony_ciextern const struct attribute_group *usb_interface_groups[];
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci/* usbfs stuff */
1938c2ecf20Sopenharmony_ciextern struct usb_driver usbfs_driver;
1948c2ecf20Sopenharmony_ciextern const struct file_operations usbfs_devices_fops;
1958c2ecf20Sopenharmony_ciextern const struct file_operations usbdev_file_operations;
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ciextern int usb_devio_init(void);
1988c2ecf20Sopenharmony_ciextern void usb_devio_cleanup(void);
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci/*
2018c2ecf20Sopenharmony_ci * Firmware specific cookie identifying a port's location. '0' == no location
2028c2ecf20Sopenharmony_ci * data available
2038c2ecf20Sopenharmony_ci */
2048c2ecf20Sopenharmony_citypedef u32 usb_port_location_t;
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci/* internal notify stuff */
2078c2ecf20Sopenharmony_ciextern void usb_notify_add_device(struct usb_device *udev);
2088c2ecf20Sopenharmony_ciextern void usb_notify_remove_device(struct usb_device *udev);
2098c2ecf20Sopenharmony_ciextern void usb_notify_add_bus(struct usb_bus *ubus);
2108c2ecf20Sopenharmony_ciextern void usb_notify_remove_bus(struct usb_bus *ubus);
2118c2ecf20Sopenharmony_ciextern void usb_hub_adjust_deviceremovable(struct usb_device *hdev,
2128c2ecf20Sopenharmony_ci		struct usb_hub_descriptor *desc);
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI
2158c2ecf20Sopenharmony_ciextern int usb_acpi_register(void);
2168c2ecf20Sopenharmony_ciextern void usb_acpi_unregister(void);
2178c2ecf20Sopenharmony_ciextern acpi_handle usb_get_hub_port_acpi_handle(struct usb_device *hdev,
2188c2ecf20Sopenharmony_ci	int port1);
2198c2ecf20Sopenharmony_ci#else
2208c2ecf20Sopenharmony_cistatic inline int usb_acpi_register(void) { return 0; };
2218c2ecf20Sopenharmony_cistatic inline void usb_acpi_unregister(void) { };
2228c2ecf20Sopenharmony_ci#endif
223