1 /* 2 * Copyright (c) 2013-2020 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef __HIF_RUNTIME_PM_H__ 18 #define __HIF_RUNTIME_PM_H__ 19 20 #ifdef FEATURE_RUNTIME_PM 21 22 /** 23 * enum hif_pm_runtime_state - Driver States for Runtime Power Management 24 * HIF_PM_RUNTIME_STATE_NONE: runtime pm is off 25 * HIF_PM_RUNTIME_STATE_ON: runtime pm is active and link is active 26 * HIF_PM_RUNTIME_STATE_RESUMING: a runtime resume is in progress 27 * HIF_PM_RUNTIME_STATE_SUSPENDING: a runtime suspend is in progress 28 * HIF_PM_RUNTIME_STATE_SUSPENDED: the driver is runtime suspended 29 */ 30 enum hif_pm_runtime_state { 31 HIF_PM_RUNTIME_STATE_NONE, 32 HIF_PM_RUNTIME_STATE_ON, 33 HIF_PM_RUNTIME_STATE_RESUMING, 34 HIF_PM_RUNTIME_STATE_SUSPENDING, 35 HIF_PM_RUNTIME_STATE_SUSPENDED, 36 }; 37 38 /** 39 * struct hif_pm_runtime_lock - data structure for preventing runtime suspend 40 * @list - global list of runtime locks 41 * @active - true if this lock is preventing suspend 42 * @name - character string for tracking this lock 43 */ 44 struct hif_pm_runtime_lock { 45 struct list_head list; 46 bool active; 47 uint32_t timeout; 48 const char *name; 49 }; 50 51 /* Debugging stats for Runtime PM */ 52 struct hif_pci_pm_stats { 53 u32 suspended; 54 u32 suspend_err; 55 u32 resumed; 56 atomic_t runtime_get; 57 atomic_t runtime_put; 58 atomic_t runtime_get_dbgid[RTPM_ID_MAX]; 59 atomic_t runtime_put_dbgid[RTPM_ID_MAX]; 60 uint64_t runtime_get_timestamp_dbgid[RTPM_ID_MAX]; 61 uint64_t runtime_put_timestamp_dbgid[RTPM_ID_MAX]; 62 u32 request_resume; 63 atomic_t allow_suspend; 64 atomic_t prevent_suspend; 65 u32 prevent_suspend_timeout; 66 u32 allow_suspend_timeout; 67 u32 runtime_get_err; 68 void *last_resume_caller; 69 void *last_busy_marker; 70 qdf_time_t last_busy_timestamp; 71 unsigned long suspend_jiffies; 72 }; 73 74 struct hif_runtime_pm_ctx { 75 atomic_t pm_state; 76 atomic_t monitor_wake_intr; 77 uint32_t prevent_suspend_cnt; 78 struct hif_pci_pm_stats pm_stats; 79 struct work_struct pm_work; 80 spinlock_t runtime_lock; /* Generic spinlock for Runtime PM */ 81 qdf_timer_t runtime_timer; 82 struct list_head prevent_suspend_list; 83 unsigned long runtime_timer_expires; 84 qdf_runtime_lock_t prevent_linkdown_lock; 85 atomic_t pm_dp_rx_busy; 86 qdf_time_t dp_last_busy_timestamp; 87 #ifdef WLAN_OPEN_SOURCE 88 struct dentry *pm_dentry; 89 #endif 90 }; 91 92 #include <linux/pm_runtime.h> 93 94 static inline int hif_pm_request_resume(struct device *dev) 95 { 96 return pm_request_resume(dev); 97 } 98 99 static inline int __hif_pm_runtime_get(struct device *dev) 100 { 101 return pm_runtime_get(dev); 102 } 103 104 static inline int hif_pm_runtime_put_auto(struct device *dev) 105 { 106 return pm_runtime_put_autosuspend(dev); 107 } 108 109 void hif_pm_runtime_open(struct hif_softc *scn); 110 void hif_pm_runtime_start(struct hif_softc *scn); 111 void hif_pm_runtime_stop(struct hif_softc *scn); 112 void hif_pm_runtime_close(struct hif_softc *scn); 113 void hif_runtime_prevent_linkdown(struct hif_softc *scn, bool flag); 114 115 #else 116 static inline void hif_pm_runtime_open(struct hif_softc *scn) {} 117 static inline void hif_pm_runtime_start(struct hif_softc *scn) {} 118 static inline void hif_pm_runtime_stop(struct hif_softc *scn) {} 119 static inline void hif_pm_runtime_close(struct hif_softc *scn) {} 120 static inline void hif_runtime_prevent_linkdown(struct hif_softc *scn, 121 bool flag) {} 122 #endif /* FEATURE_RUNTIME_PM */ 123 #endif /* __HIF_RUNTIME_PM_H__ */ 124