--- zzzz-none-000/linux-3.10.107/drivers/usb/core/usb.h 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/usb/core/usb.h 2021-02-04 17:41:59.000000000 +0000 @@ -1,8 +1,25 @@ #include #include +#if defined CONFIG_AVM_USB_PM && !defined (CONFIG_PM) +#error CONFIG_AVM_USB_PM needs CONFIG_PM +#endif + +#if defined (CONFIG_AVM_USB_PM) +#define AVM_USB_PM_MAX_BLACKLIST_SIZE 8 +#define AVM_USB_PM_SPINDOWN_DELAY (630*1000) // 10.5 min in ms +#define AVM_USB_PM_FLASH_DELAY (20*1000) // 20 s in ms +#define AVM_USB_PM_MIN_DELAY 2000 // 2 s in ms + +struct avm_usb_pm_blacklist { + unsigned int idVendor; + unsigned int idProduct; + unsigned int bcdDevice; +}; +#endif + struct usb_hub_descriptor; -struct dev_state; +struct usb_dev_state; /* Functions local to drivers/usb/core/ */ @@ -27,6 +44,8 @@ extern void usb_disable_device(struct usb_device *dev, int skip_ep0); extern int usb_deauthorize_device(struct usb_device *); extern int usb_authorize_device(struct usb_device *); +extern void usb_deauthorize_interface(struct usb_interface *); +extern void usb_authorize_interface(struct usb_interface *); extern void usb_detect_quirks(struct usb_device *udev); extern void usb_detect_interface_quirks(struct usb_device *udev); extern int usb_remove_device(struct usb_device *udev); @@ -43,12 +62,12 @@ struct usb_host_config *c) { /* SuperSpeed power is in 8 mA units; others are in 2 mA units */ - unsigned mul = (udev->speed == USB_SPEED_SUPER ? 8 : 2); + unsigned mul = (udev->speed >= USB_SPEED_SUPER ? 8 : 2); return c->desc.bMaxPower * mul; } -extern void usb_kick_khubd(struct usb_device *dev); +extern void usb_kick_hub_wq(struct usb_device *dev); extern int usb_match_one_id_intf(struct usb_device *dev, struct usb_host_interface *intf, const struct usb_device_id *id); @@ -57,18 +76,15 @@ extern void usb_forced_unbind_intf(struct usb_interface *intf); extern void usb_unbind_and_rebind_marked_interfaces(struct usb_device *udev); -extern int usb_hub_claim_port(struct usb_device *hdev, unsigned port, - struct dev_state *owner); -extern int usb_hub_release_port(struct usb_device *hdev, unsigned port, - struct dev_state *owner); extern void usb_hub_release_all_ports(struct usb_device *hdev, - struct dev_state *owner); + struct usb_dev_state *owner); extern bool usb_device_is_owned(struct usb_device *udev); extern int usb_hub_init(void); extern void usb_hub_cleanup(void); extern int usb_major_init(void); extern void usb_major_cleanup(void); +extern int usb_device_supports_lpm(struct usb_device *udev); #ifdef CONFIG_PM @@ -79,39 +95,67 @@ extern int usb_port_suspend(struct usb_device *dev, pm_message_t msg); extern int usb_port_resume(struct usb_device *dev, pm_message_t msg); -#else +extern void usb_autosuspend_device(struct usb_device *udev); +extern int usb_autoresume_device(struct usb_device *udev); +extern int usb_remote_wakeup(struct usb_device *dev); +extern int usb_runtime_suspend(struct device *dev); +extern int usb_runtime_resume(struct device *dev); +extern int usb_runtime_idle(struct device *dev); +extern int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable); -static inline int usb_port_suspend(struct usb_device *udev, pm_message_t msg) +#if defined (CONFIG_AVM_USB_PM) +extern int suspend_error_count; + +extern int avm_usb_pm_is_blacklisted(struct usb_device *udev); +extern void avm_usb_pm_add_to_blacklist(struct usb_device *udev); + +static inline void avm_usb_pm_min_delay(struct usb_device *udev, unsigned msecs) { - return 0; + if ((udev->dev.power.autosuspend_delay > 0) && (udev->dev.power.autosuspend_delay < msecs)) { + pm_runtime_set_autosuspend_delay(&udev->dev, msecs); + printk(KERN_INFO "set suspend delay %u ms\n", msecs); + } } -static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg) +static inline void avm_usb_pm_max_delay(struct usb_device *udev, unsigned msecs) { - return 0; + if (udev->dev.power.autosuspend_delay > msecs) { + pm_runtime_set_autosuspend_delay(&udev->dev, msecs); + printk(KERN_INFO "set suspend delay %u ms\n", msecs); + } } -#endif +static inline unsigned int avm_usb_pm_get_idle_ms(struct usb_device *udev) +{ + if (atomic_read(&udev->dev.power.usage_count) > 0) { + return 0; + } -#ifdef CONFIG_PM_RUNTIME + return jiffies_to_msecs(jiffies - ACCESS_ONCE(udev->dev.power.last_busy)); +} -extern void usb_autosuspend_device(struct usb_device *udev); -extern int usb_autoresume_device(struct usb_device *udev); -extern int usb_remote_wakeup(struct usb_device *dev); -extern int usb_runtime_suspend(struct device *dev); -extern int usb_runtime_resume(struct device *dev); -extern int usb_runtime_idle(struct device *dev); -extern int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable); +#else + +#define avm_usb_pm_min_delay(udev_p,delay) do {} while (0) +#define avm_usb_pm_max_delay(udev_p,delay) do {} while (0) +#define avm_usb_pm_get_idle_ms(udev_p) (0) + +#endif #else -#define usb_autosuspend_device(udev) do {} while (0) -static inline int usb_autoresume_device(struct usb_device *udev) +static inline int usb_port_suspend(struct usb_device *udev, pm_message_t msg) { return 0; } -static inline int usb_remote_wakeup(struct usb_device *udev) +static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg) +{ + return 0; +} + +#define usb_autosuspend_device(udev) do {} while (0) +static inline int usb_autoresume_device(struct usb_device *udev) { return 0; } @@ -120,9 +164,11 @@ { return 0; } + #endif extern struct bus_type usb_bus_type; +extern struct mutex usb_port_peer_mutex; extern struct device_type usb_device_type; extern struct device_type usb_if_device_type; extern struct device_type usb_ep_device_type; @@ -174,15 +220,17 @@ extern int usb_devio_init(void); extern void usb_devio_cleanup(void); +/* + * Firmware specific cookie identifying a port's location. '0' == no location + * data available + */ +typedef u32 usb_port_location_t; + /* internal notify stuff */ extern void usb_notify_add_device(struct usb_device *udev); extern void usb_notify_remove_device(struct usb_device *udev); extern void usb_notify_add_bus(struct usb_bus *ubus); extern void usb_notify_remove_bus(struct usb_bus *ubus); -extern enum usb_port_connect_type - usb_get_hub_port_connect_type(struct usb_device *hdev, int port1); -extern void usb_set_hub_port_connect_type(struct usb_device *hdev, int port1, - enum usb_port_connect_type type); extern void usb_hub_adjust_deviceremovable(struct usb_device *hdev, struct usb_hub_descriptor *desc);