--- zzzz-none-000/linux-5.15.111/drivers/usb/core/usb.h 2023-05-11 14:00:40.000000000 +0000 +++ puma7-atom-6670-761/linux-5.15.111/drivers/usb/core/usb.h 2024-02-07 10:23:21.000000000 +0000 @@ -6,6 +6,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; @@ -111,6 +128,45 @@ extern void usbfs_notify_suspend(struct usb_device *udev); extern void usbfs_notify_resume(struct usb_device *udev); +#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 - READ_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)