^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/pm_qos.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) static inline void device_pm_init_common(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) if (!dev->power.early_init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) spin_lock_init(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) dev->power.qos = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) dev->power.early_init = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static inline void pm_runtime_early_init(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) dev->power.disable_depth = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) device_pm_init_common(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) extern void pm_runtime_init(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) extern void pm_runtime_reinit(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) extern void pm_runtime_remove(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) extern u64 pm_runtime_active_time(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define WAKE_IRQ_DEDICATED_ALLOCATED BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define WAKE_IRQ_DEDICATED_MANAGED BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define WAKE_IRQ_DEDICATED_MASK (WAKE_IRQ_DEDICATED_ALLOCATED | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) WAKE_IRQ_DEDICATED_MANAGED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct wake_irq {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) unsigned int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) extern void dev_pm_disarm_wake_irq(struct wake_irq *wirq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) extern void dev_pm_enable_wake_irq_check(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) bool can_change_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) extern void dev_pm_disable_wake_irq_check(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) extern void device_wakeup_attach_irq(struct device *dev, struct wake_irq *wakeirq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) extern void device_wakeup_detach_irq(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) extern void device_wakeup_arm_wake_irqs(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) extern void device_wakeup_disarm_wake_irqs(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static inline void device_wakeup_attach_irq(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct wake_irq *wakeirq) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static inline void device_wakeup_detach_irq(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #endif /* CONFIG_PM_SLEEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * sysfs.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) extern int dpm_sysfs_add(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) extern void dpm_sysfs_remove(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) extern void rpm_sysfs_remove(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) extern int wakeup_sysfs_add(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) extern void wakeup_sysfs_remove(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) extern int pm_qos_sysfs_add_resume_latency(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) extern void pm_qos_sysfs_remove_resume_latency(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) extern int pm_qos_sysfs_add_flags(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) extern void pm_qos_sysfs_remove_flags(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) extern int pm_qos_sysfs_add_latency_tolerance(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) extern void pm_qos_sysfs_remove_latency_tolerance(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) extern int dpm_sysfs_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #else /* CONFIG_PM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static inline void pm_runtime_early_init(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) device_pm_init_common(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static inline void pm_runtime_init(struct device *dev) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static inline void pm_runtime_reinit(struct device *dev) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static inline void pm_runtime_remove(struct device *dev) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static inline int dpm_sysfs_add(struct device *dev) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static inline void dpm_sysfs_remove(struct device *dev) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static inline int dpm_sysfs_change_owner(struct device *dev, kuid_t kuid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) kgid_t kgid) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* kernel/power/main.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) extern int pm_async_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* drivers/base/power/main.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) extern struct list_head dpm_list; /* The active device list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static inline struct device *to_device(struct list_head *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return container_of(entry, struct device, power.entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) extern void device_pm_sleep_init(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) extern void device_pm_add(struct device *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) extern void device_pm_remove(struct device *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) extern void device_pm_move_before(struct device *, struct device *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) extern void device_pm_move_after(struct device *, struct device *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) extern void device_pm_move_last(struct device *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) extern void device_pm_check_callbacks(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static inline bool device_pm_initialized(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return dev->power.in_dpm_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* drivers/base/power/wakeup_stats.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) extern int wakeup_source_sysfs_add(struct device *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct wakeup_source *ws);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) extern void wakeup_source_sysfs_remove(struct wakeup_source *ws);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) extern int pm_wakeup_source_sysfs_add(struct device *parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #else /* !CONFIG_PM_SLEEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static inline void device_pm_sleep_init(struct device *dev) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static inline void device_pm_add(struct device *dev) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static inline void device_pm_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) pm_runtime_remove(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static inline void device_pm_move_before(struct device *deva,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct device *devb) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static inline void device_pm_move_after(struct device *deva,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct device *devb) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static inline void device_pm_move_last(struct device *dev) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static inline void device_pm_check_callbacks(struct device *dev) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static inline bool device_pm_initialized(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return device_is_registered(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static inline int pm_wakeup_source_sysfs_add(struct device *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #endif /* !CONFIG_PM_SLEEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static inline void device_pm_init(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) device_pm_init_common(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) device_pm_sleep_init(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) pm_runtime_init(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }