Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #include <linux/pm_qos.h>
0003 
0004 static inline void device_pm_init_common(struct device *dev)
0005 {
0006     if (!dev->power.early_init) {
0007         spin_lock_init(&dev->power.lock);
0008         dev->power.qos = NULL;
0009         dev->power.early_init = true;
0010     }
0011 }
0012 
0013 #ifdef CONFIG_PM
0014 
0015 static inline void pm_runtime_early_init(struct device *dev)
0016 {
0017     dev->power.disable_depth = 1;
0018     device_pm_init_common(dev);
0019 }
0020 
0021 extern void pm_runtime_init(struct device *dev);
0022 extern void pm_runtime_reinit(struct device *dev);
0023 extern void pm_runtime_remove(struct device *dev);
0024 extern u64 pm_runtime_active_time(struct device *dev);
0025 
0026 #define WAKE_IRQ_DEDICATED_ALLOCATED    BIT(0)
0027 #define WAKE_IRQ_DEDICATED_MANAGED  BIT(1)
0028 #define WAKE_IRQ_DEDICATED_REVERSE  BIT(2)
0029 #define WAKE_IRQ_DEDICATED_MASK     (WAKE_IRQ_DEDICATED_ALLOCATED | \
0030                      WAKE_IRQ_DEDICATED_MANAGED | \
0031                      WAKE_IRQ_DEDICATED_REVERSE)
0032 
0033 struct wake_irq {
0034     struct device *dev;
0035     unsigned int status;
0036     int irq;
0037     const char *name;
0038 };
0039 
0040 extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
0041 extern void dev_pm_disarm_wake_irq(struct wake_irq *wirq);
0042 extern void dev_pm_enable_wake_irq_check(struct device *dev,
0043                      bool can_change_status);
0044 extern void dev_pm_disable_wake_irq_check(struct device *dev, bool cond_disable);
0045 extern void dev_pm_enable_wake_irq_complete(struct device *dev);
0046 
0047 #ifdef CONFIG_PM_SLEEP
0048 
0049 extern void device_wakeup_attach_irq(struct device *dev, struct wake_irq *wakeirq);
0050 extern void device_wakeup_detach_irq(struct device *dev);
0051 extern void device_wakeup_arm_wake_irqs(void);
0052 extern void device_wakeup_disarm_wake_irqs(void);
0053 
0054 #else
0055 
0056 static inline void device_wakeup_attach_irq(struct device *dev,
0057                         struct wake_irq *wakeirq) {}
0058 
0059 static inline void device_wakeup_detach_irq(struct device *dev)
0060 {
0061 }
0062 
0063 #endif /* CONFIG_PM_SLEEP */
0064 
0065 /*
0066  * sysfs.c
0067  */
0068 
0069 extern int dpm_sysfs_add(struct device *dev);
0070 extern void dpm_sysfs_remove(struct device *dev);
0071 extern void rpm_sysfs_remove(struct device *dev);
0072 extern int wakeup_sysfs_add(struct device *dev);
0073 extern void wakeup_sysfs_remove(struct device *dev);
0074 extern int pm_qos_sysfs_add_resume_latency(struct device *dev);
0075 extern void pm_qos_sysfs_remove_resume_latency(struct device *dev);
0076 extern int pm_qos_sysfs_add_flags(struct device *dev);
0077 extern void pm_qos_sysfs_remove_flags(struct device *dev);
0078 extern int pm_qos_sysfs_add_latency_tolerance(struct device *dev);
0079 extern void pm_qos_sysfs_remove_latency_tolerance(struct device *dev);
0080 extern int dpm_sysfs_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid);
0081 
0082 #else /* CONFIG_PM */
0083 
0084 static inline void pm_runtime_early_init(struct device *dev)
0085 {
0086     device_pm_init_common(dev);
0087 }
0088 
0089 static inline void pm_runtime_init(struct device *dev) {}
0090 static inline void pm_runtime_reinit(struct device *dev) {}
0091 static inline void pm_runtime_remove(struct device *dev) {}
0092 
0093 static inline int dpm_sysfs_add(struct device *dev) { return 0; }
0094 static inline void dpm_sysfs_remove(struct device *dev) {}
0095 static inline int dpm_sysfs_change_owner(struct device *dev, kuid_t kuid,
0096                      kgid_t kgid) { return 0; }
0097 
0098 #endif
0099 
0100 #ifdef CONFIG_PM_SLEEP
0101 
0102 /* kernel/power/main.c */
0103 extern int pm_async_enabled;
0104 
0105 /* drivers/base/power/main.c */
0106 extern struct list_head dpm_list;   /* The active device list */
0107 
0108 static inline struct device *to_device(struct list_head *entry)
0109 {
0110     return container_of(entry, struct device, power.entry);
0111 }
0112 
0113 extern void device_pm_sleep_init(struct device *dev);
0114 extern void device_pm_add(struct device *);
0115 extern void device_pm_remove(struct device *);
0116 extern void device_pm_move_before(struct device *, struct device *);
0117 extern void device_pm_move_after(struct device *, struct device *);
0118 extern void device_pm_move_last(struct device *);
0119 extern void device_pm_check_callbacks(struct device *dev);
0120 
0121 static inline bool device_pm_initialized(struct device *dev)
0122 {
0123     return dev->power.in_dpm_list;
0124 }
0125 
0126 /* drivers/base/power/wakeup_stats.c */
0127 extern int wakeup_source_sysfs_add(struct device *parent,
0128                    struct wakeup_source *ws);
0129 extern void wakeup_source_sysfs_remove(struct wakeup_source *ws);
0130 
0131 extern int pm_wakeup_source_sysfs_add(struct device *parent);
0132 
0133 #else /* !CONFIG_PM_SLEEP */
0134 
0135 static inline void device_pm_sleep_init(struct device *dev) {}
0136 
0137 static inline void device_pm_add(struct device *dev) {}
0138 
0139 static inline void device_pm_remove(struct device *dev)
0140 {
0141     pm_runtime_remove(dev);
0142 }
0143 
0144 static inline void device_pm_move_before(struct device *deva,
0145                      struct device *devb) {}
0146 static inline void device_pm_move_after(struct device *deva,
0147                     struct device *devb) {}
0148 static inline void device_pm_move_last(struct device *dev) {}
0149 
0150 static inline void device_pm_check_callbacks(struct device *dev) {}
0151 
0152 static inline bool device_pm_initialized(struct device *dev)
0153 {
0154     return device_is_registered(dev);
0155 }
0156 
0157 static inline int pm_wakeup_source_sysfs_add(struct device *parent)
0158 {
0159     return 0;
0160 }
0161 
0162 #endif /* !CONFIG_PM_SLEEP */
0163 
0164 static inline void device_pm_init(struct device *dev)
0165 {
0166     device_pm_init_common(dev);
0167     device_pm_sleep_init(dev);
0168     pm_runtime_init(dev);
0169 }