--- zzzz-none-000/linux-4.4.60/drivers/usb/core/usb.h 2017-04-08 07:53:53.000000000 +0000 +++ scorpion-1750e-727/linux-4.4.60/drivers/usb/core/usb.h 2021-02-04 17:41:59.000000000 +0000 @@ -1,6 +1,23 @@ #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 usb_dev_state; @@ -86,6 +103,45 @@ extern int usb_runtime_idle(struct device *dev); extern int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable); +#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) +{ + 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 void avm_usb_pm_max_delay(struct usb_device *udev, unsigned msecs) +{ + 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); + } +} + +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; + } + + return jiffies_to_msecs(jiffies - ACCESS_ONCE(udev->dev.power.last_busy)); +} + +#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 static inline int usb_port_suspend(struct usb_device *udev, pm_message_t msg)