xref: /linux-6.15/include/linux/pm_opp.h (revision 8b235f2f)
1 /*
2  * Generic OPP Interface
3  *
4  * Copyright (C) 2009-2010 Texas Instruments Incorporated.
5  *	Nishanth Menon
6  *	Romit Dasgupta
7  *	Kevin Hilman
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13 
14 #ifndef __LINUX_OPP_H__
15 #define __LINUX_OPP_H__
16 
17 #include <linux/err.h>
18 #include <linux/notifier.h>
19 
20 struct dev_pm_opp;
21 struct device;
22 
23 enum dev_pm_opp_event {
24 	OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE,
25 };
26 
27 #if defined(CONFIG_PM_OPP)
28 
29 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
30 
31 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
32 
33 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
34 
35 int dev_pm_opp_get_opp_count(struct device *dev);
36 unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
37 
38 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
39 					      unsigned long freq,
40 					      bool available);
41 
42 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
43 					      unsigned long *freq);
44 
45 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
46 					     unsigned long *freq);
47 
48 int dev_pm_opp_add(struct device *dev, unsigned long freq,
49 		   unsigned long u_volt);
50 void dev_pm_opp_remove(struct device *dev, unsigned long freq);
51 
52 int dev_pm_opp_enable(struct device *dev, unsigned long freq);
53 
54 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
55 
56 struct srcu_notifier_head *dev_pm_opp_get_notifier(struct device *dev);
57 #else
58 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
59 {
60 	return 0;
61 }
62 
63 static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
64 {
65 	return 0;
66 }
67 
68 static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
69 {
70 	return false;
71 }
72 
73 static inline int dev_pm_opp_get_opp_count(struct device *dev)
74 {
75 	return 0;
76 }
77 
78 static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
79 {
80 	return 0;
81 }
82 
83 static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
84 					unsigned long freq, bool available)
85 {
86 	return ERR_PTR(-EINVAL);
87 }
88 
89 static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
90 					unsigned long *freq)
91 {
92 	return ERR_PTR(-EINVAL);
93 }
94 
95 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
96 					unsigned long *freq)
97 {
98 	return ERR_PTR(-EINVAL);
99 }
100 
101 static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
102 					unsigned long u_volt)
103 {
104 	return -EINVAL;
105 }
106 
107 static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
108 {
109 }
110 
111 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
112 {
113 	return 0;
114 }
115 
116 static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
117 {
118 	return 0;
119 }
120 
121 static inline struct srcu_notifier_head *dev_pm_opp_get_notifier(
122 							struct device *dev)
123 {
124 	return ERR_PTR(-EINVAL);
125 }
126 #endif		/* CONFIG_PM_OPP */
127 
128 #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
129 int of_init_opp_table(struct device *dev);
130 void of_free_opp_table(struct device *dev);
131 int of_cpumask_init_opp_table(cpumask_var_t cpumask);
132 void of_cpumask_free_opp_table(cpumask_var_t cpumask);
133 int of_get_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask);
134 int set_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask);
135 #else
136 static inline int of_init_opp_table(struct device *dev)
137 {
138 	return -EINVAL;
139 }
140 
141 static inline void of_free_opp_table(struct device *dev)
142 {
143 }
144 
145 static inline int of_cpumask_init_opp_table(cpumask_var_t cpumask)
146 {
147 	return -ENOSYS;
148 }
149 
150 static inline void of_cpumask_free_opp_table(cpumask_var_t cpumask)
151 {
152 }
153 
154 static inline int of_get_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask)
155 {
156 	return -ENOSYS;
157 }
158 
159 static inline int set_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask)
160 {
161 	return -ENOSYS;
162 }
163 #endif
164 
165 #endif		/* __LINUX_OPP_H__ */
166