162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Released under the GPLv2 only. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#include <linux/pm.h> 762306a36Sopenharmony_ci#include <linux/acpi.h> 862306a36Sopenharmony_ci 962306a36Sopenharmony_cistruct usb_hub_descriptor; 1062306a36Sopenharmony_cistruct usb_dev_state; 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci/* Functions local to drivers/usb/core/ */ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ciextern int usb_create_sysfs_dev_files(struct usb_device *dev); 1562306a36Sopenharmony_ciextern void usb_remove_sysfs_dev_files(struct usb_device *dev); 1662306a36Sopenharmony_ciextern void usb_create_sysfs_intf_files(struct usb_interface *intf); 1762306a36Sopenharmony_ciextern void usb_remove_sysfs_intf_files(struct usb_interface *intf); 1862306a36Sopenharmony_ciextern int usb_update_wireless_status_attr(struct usb_interface *intf); 1962306a36Sopenharmony_ciextern int usb_create_ep_devs(struct device *parent, 2062306a36Sopenharmony_ci struct usb_host_endpoint *endpoint, 2162306a36Sopenharmony_ci struct usb_device *udev); 2262306a36Sopenharmony_ciextern void usb_remove_ep_devs(struct usb_host_endpoint *endpoint); 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ciextern void usb_enable_endpoint(struct usb_device *dev, 2562306a36Sopenharmony_ci struct usb_host_endpoint *ep, bool reset_toggle); 2662306a36Sopenharmony_ciextern void usb_enable_interface(struct usb_device *dev, 2762306a36Sopenharmony_ci struct usb_interface *intf, bool reset_toggles); 2862306a36Sopenharmony_ciextern void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr, 2962306a36Sopenharmony_ci bool reset_hardware); 3062306a36Sopenharmony_ciextern void usb_disable_interface(struct usb_device *dev, 3162306a36Sopenharmony_ci struct usb_interface *intf, bool reset_hardware); 3262306a36Sopenharmony_ciextern void usb_release_interface_cache(struct kref *ref); 3362306a36Sopenharmony_ciextern void usb_disable_device(struct usb_device *dev, int skip_ep0); 3462306a36Sopenharmony_ciextern int usb_deauthorize_device(struct usb_device *); 3562306a36Sopenharmony_ciextern int usb_authorize_device(struct usb_device *); 3662306a36Sopenharmony_ciextern void usb_deauthorize_interface(struct usb_interface *); 3762306a36Sopenharmony_ciextern void usb_authorize_interface(struct usb_interface *); 3862306a36Sopenharmony_ciextern void usb_detect_quirks(struct usb_device *udev); 3962306a36Sopenharmony_ciextern void usb_detect_interface_quirks(struct usb_device *udev); 4062306a36Sopenharmony_ciextern void usb_release_quirk_list(void); 4162306a36Sopenharmony_ciextern bool usb_endpoint_is_ignored(struct usb_device *udev, 4262306a36Sopenharmony_ci struct usb_host_interface *intf, 4362306a36Sopenharmony_ci struct usb_endpoint_descriptor *epd); 4462306a36Sopenharmony_ciextern int usb_remove_device(struct usb_device *udev); 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ciextern struct usb_device_descriptor *usb_get_device_descriptor( 4762306a36Sopenharmony_ci struct usb_device *udev); 4862306a36Sopenharmony_ciextern int usb_set_isoch_delay(struct usb_device *dev); 4962306a36Sopenharmony_ciextern int usb_get_bos_descriptor(struct usb_device *dev); 5062306a36Sopenharmony_ciextern void usb_release_bos_descriptor(struct usb_device *dev); 5162306a36Sopenharmony_ciextern int usb_set_configuration(struct usb_device *dev, int configuration); 5262306a36Sopenharmony_ciextern int usb_choose_configuration(struct usb_device *udev); 5362306a36Sopenharmony_ciextern int usb_generic_driver_probe(struct usb_device *udev); 5462306a36Sopenharmony_ciextern void usb_generic_driver_disconnect(struct usb_device *udev); 5562306a36Sopenharmony_ciextern int usb_generic_driver_suspend(struct usb_device *udev, 5662306a36Sopenharmony_ci pm_message_t msg); 5762306a36Sopenharmony_ciextern int usb_generic_driver_resume(struct usb_device *udev, 5862306a36Sopenharmony_ci pm_message_t msg); 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_cistatic inline unsigned usb_get_max_power(struct usb_device *udev, 6162306a36Sopenharmony_ci struct usb_host_config *c) 6262306a36Sopenharmony_ci{ 6362306a36Sopenharmony_ci /* SuperSpeed power is in 8 mA units; others are in 2 mA units */ 6462306a36Sopenharmony_ci unsigned mul = (udev->speed >= USB_SPEED_SUPER ? 8 : 2); 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci return c->desc.bMaxPower * mul; 6762306a36Sopenharmony_ci} 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ciextern void usb_kick_hub_wq(struct usb_device *dev); 7062306a36Sopenharmony_ciextern int usb_match_one_id_intf(struct usb_device *dev, 7162306a36Sopenharmony_ci struct usb_host_interface *intf, 7262306a36Sopenharmony_ci const struct usb_device_id *id); 7362306a36Sopenharmony_ciextern int usb_match_device(struct usb_device *dev, 7462306a36Sopenharmony_ci const struct usb_device_id *id); 7562306a36Sopenharmony_ciextern const struct usb_device_id *usb_device_match_id(struct usb_device *udev, 7662306a36Sopenharmony_ci const struct usb_device_id *id); 7762306a36Sopenharmony_ciextern bool usb_driver_applicable(struct usb_device *udev, 7862306a36Sopenharmony_ci struct usb_device_driver *udrv); 7962306a36Sopenharmony_ciextern void usb_forced_unbind_intf(struct usb_interface *intf); 8062306a36Sopenharmony_ciextern void usb_unbind_and_rebind_marked_interfaces(struct usb_device *udev); 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ciextern void usb_hub_release_all_ports(struct usb_device *hdev, 8362306a36Sopenharmony_ci struct usb_dev_state *owner); 8462306a36Sopenharmony_ciextern bool usb_device_is_owned(struct usb_device *udev); 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ciextern int usb_hub_init(void); 8762306a36Sopenharmony_ciextern void usb_hub_cleanup(void); 8862306a36Sopenharmony_ciextern int usb_major_init(void); 8962306a36Sopenharmony_ciextern void usb_major_cleanup(void); 9062306a36Sopenharmony_ciextern int usb_device_supports_lpm(struct usb_device *udev); 9162306a36Sopenharmony_ciextern int usb_port_disable(struct usb_device *udev); 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci#ifdef CONFIG_PM 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ciextern int usb_suspend(struct device *dev, pm_message_t msg); 9662306a36Sopenharmony_ciextern int usb_resume(struct device *dev, pm_message_t msg); 9762306a36Sopenharmony_ciextern int usb_resume_complete(struct device *dev); 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ciextern int usb_port_suspend(struct usb_device *dev, pm_message_t msg); 10062306a36Sopenharmony_ciextern int usb_port_resume(struct usb_device *dev, pm_message_t msg); 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ciextern void usb_autosuspend_device(struct usb_device *udev); 10362306a36Sopenharmony_ciextern int usb_autoresume_device(struct usb_device *udev); 10462306a36Sopenharmony_ciextern int usb_remote_wakeup(struct usb_device *dev); 10562306a36Sopenharmony_ciextern int usb_runtime_suspend(struct device *dev); 10662306a36Sopenharmony_ciextern int usb_runtime_resume(struct device *dev); 10762306a36Sopenharmony_ciextern int usb_runtime_idle(struct device *dev); 10862306a36Sopenharmony_ciextern int usb_enable_usb2_hardware_lpm(struct usb_device *udev); 10962306a36Sopenharmony_ciextern int usb_disable_usb2_hardware_lpm(struct usb_device *udev); 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ciextern void usbfs_notify_suspend(struct usb_device *udev); 11262306a36Sopenharmony_ciextern void usbfs_notify_resume(struct usb_device *udev); 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci#else 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_cistatic inline int usb_port_suspend(struct usb_device *udev, pm_message_t msg) 11762306a36Sopenharmony_ci{ 11862306a36Sopenharmony_ci return 0; 11962306a36Sopenharmony_ci} 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_cistatic inline int usb_port_resume(struct usb_device *udev, pm_message_t msg) 12262306a36Sopenharmony_ci{ 12362306a36Sopenharmony_ci return 0; 12462306a36Sopenharmony_ci} 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci#define usb_autosuspend_device(udev) do {} while (0) 12762306a36Sopenharmony_cistatic inline int usb_autoresume_device(struct usb_device *udev) 12862306a36Sopenharmony_ci{ 12962306a36Sopenharmony_ci return 0; 13062306a36Sopenharmony_ci} 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_cistatic inline int usb_enable_usb2_hardware_lpm(struct usb_device *udev) 13362306a36Sopenharmony_ci{ 13462306a36Sopenharmony_ci return 0; 13562306a36Sopenharmony_ci} 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_cistatic inline int usb_disable_usb2_hardware_lpm(struct usb_device *udev) 13862306a36Sopenharmony_ci{ 13962306a36Sopenharmony_ci return 0; 14062306a36Sopenharmony_ci} 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci#endif 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ciextern const struct class usbmisc_class; 14562306a36Sopenharmony_ciextern const struct bus_type usb_bus_type; 14662306a36Sopenharmony_ciextern struct mutex usb_port_peer_mutex; 14762306a36Sopenharmony_ciextern struct device_type usb_device_type; 14862306a36Sopenharmony_ciextern struct device_type usb_if_device_type; 14962306a36Sopenharmony_ciextern struct device_type usb_ep_device_type; 15062306a36Sopenharmony_ciextern struct device_type usb_port_device_type; 15162306a36Sopenharmony_ciextern struct usb_device_driver usb_generic_driver; 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_cistatic inline int is_usb_device(const struct device *dev) 15462306a36Sopenharmony_ci{ 15562306a36Sopenharmony_ci return dev->type == &usb_device_type; 15662306a36Sopenharmony_ci} 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_cistatic inline int is_usb_interface(const struct device *dev) 15962306a36Sopenharmony_ci{ 16062306a36Sopenharmony_ci return dev->type == &usb_if_device_type; 16162306a36Sopenharmony_ci} 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_cistatic inline int is_usb_endpoint(const struct device *dev) 16462306a36Sopenharmony_ci{ 16562306a36Sopenharmony_ci return dev->type == &usb_ep_device_type; 16662306a36Sopenharmony_ci} 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_cistatic inline int is_usb_port(const struct device *dev) 16962306a36Sopenharmony_ci{ 17062306a36Sopenharmony_ci return dev->type == &usb_port_device_type; 17162306a36Sopenharmony_ci} 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_cistatic inline int is_root_hub(struct usb_device *udev) 17462306a36Sopenharmony_ci{ 17562306a36Sopenharmony_ci return (udev->parent == NULL); 17662306a36Sopenharmony_ci} 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci/* Do the same for device drivers and interface drivers. */ 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_cistatic inline int is_usb_device_driver(struct device_driver *drv) 18162306a36Sopenharmony_ci{ 18262306a36Sopenharmony_ci return container_of(drv, struct usbdrv_wrap, driver)-> 18362306a36Sopenharmony_ci for_devices; 18462306a36Sopenharmony_ci} 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_ci/* for labeling diagnostics */ 18762306a36Sopenharmony_ciextern const char *usbcore_name; 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci/* sysfs stuff */ 19062306a36Sopenharmony_ciextern const struct attribute_group *usb_device_groups[]; 19162306a36Sopenharmony_ciextern const struct attribute_group *usb_interface_groups[]; 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci/* usbfs stuff */ 19462306a36Sopenharmony_ciextern struct usb_driver usbfs_driver; 19562306a36Sopenharmony_ciextern const struct file_operations usbfs_devices_fops; 19662306a36Sopenharmony_ciextern const struct file_operations usbdev_file_operations; 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ciextern int usb_devio_init(void); 19962306a36Sopenharmony_ciextern void usb_devio_cleanup(void); 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ci/* 20262306a36Sopenharmony_ci * Firmware specific cookie identifying a port's location. '0' == no location 20362306a36Sopenharmony_ci * data available 20462306a36Sopenharmony_ci */ 20562306a36Sopenharmony_citypedef u32 usb_port_location_t; 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ci/* internal notify stuff */ 20862306a36Sopenharmony_ciextern void usb_notify_add_device(struct usb_device *udev); 20962306a36Sopenharmony_ciextern void usb_notify_remove_device(struct usb_device *udev); 21062306a36Sopenharmony_ciextern void usb_notify_add_bus(struct usb_bus *ubus); 21162306a36Sopenharmony_ciextern void usb_notify_remove_bus(struct usb_bus *ubus); 21262306a36Sopenharmony_ciextern void usb_hub_adjust_deviceremovable(struct usb_device *hdev, 21362306a36Sopenharmony_ci struct usb_hub_descriptor *desc); 21462306a36Sopenharmony_ci 21562306a36Sopenharmony_ci#ifdef CONFIG_ACPI 21662306a36Sopenharmony_ciextern int usb_acpi_register(void); 21762306a36Sopenharmony_ciextern void usb_acpi_unregister(void); 21862306a36Sopenharmony_ciextern acpi_handle usb_get_hub_port_acpi_handle(struct usb_device *hdev, 21962306a36Sopenharmony_ci int port1); 22062306a36Sopenharmony_ci#else 22162306a36Sopenharmony_cistatic inline int usb_acpi_register(void) { return 0; }; 22262306a36Sopenharmony_cistatic inline void usb_acpi_unregister(void) { }; 22362306a36Sopenharmony_ci#endif 224