Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
e1f60b29 NM |
2 | /* |
3 | * Generic OPP Interface | |
4 | * | |
5 | * Copyright (C) 2009-2010 Texas Instruments Incorporated. | |
6 | * Nishanth Menon | |
7 | * Romit Dasgupta | |
8 | * Kevin Hilman | |
e1f60b29 NM |
9 | */ |
10 | ||
11 | #ifndef __LINUX_OPP_H__ | |
12 | #define __LINUX_OPP_H__ | |
13 | ||
0e0ffa85 | 14 | #include <linux/energy_model.h> |
e1f60b29 | 15 | #include <linux/err.h> |
03ca370f | 16 | #include <linux/notifier.h> |
e1f60b29 | 17 | |
94735585 VK |
18 | struct clk; |
19 | struct regulator; | |
47d43ba7 | 20 | struct dev_pm_opp; |
313162d0 | 21 | struct device; |
91291d9a | 22 | struct opp_table; |
e1f60b29 | 23 | |
47d43ba7 | 24 | enum dev_pm_opp_event { |
129eec55 | 25 | OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE, |
25cb20a2 | 26 | OPP_EVENT_ADJUST_VOLTAGE, |
03ca370f MH |
27 | }; |
28 | ||
0f0fe7e0 VK |
29 | /** |
30 | * struct dev_pm_opp_supply - Power supply voltage/current values | |
31 | * @u_volt: Target voltage in microvolts corresponding to this OPP | |
32 | * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP | |
33 | * @u_volt_max: Maximum voltage in microvolts corresponding to this OPP | |
34 | * @u_amp: Maximum current drawn by the device in microamperes | |
35 | * | |
36 | * This structure stores the voltage/current values for a single power supply. | |
37 | */ | |
38 | struct dev_pm_opp_supply { | |
39 | unsigned long u_volt; | |
40 | unsigned long u_volt_min; | |
41 | unsigned long u_volt_max; | |
42 | unsigned long u_amp; | |
43 | }; | |
44 | ||
6d3f922c GD |
45 | /** |
46 | * struct dev_pm_opp_icc_bw - Interconnect bandwidth values | |
47 | * @avg: Average bandwidth corresponding to this OPP (in icc units) | |
48 | * @peak: Peak bandwidth corresponding to this OPP (in icc units) | |
49 | * | |
50 | * This structure stores the bandwidth values for a single interconnect path. | |
51 | */ | |
52 | struct dev_pm_opp_icc_bw { | |
53 | u32 avg; | |
54 | u32 peak; | |
55 | }; | |
56 | ||
94735585 VK |
57 | /** |
58 | * struct dev_pm_opp_info - OPP freq/voltage/current values | |
59 | * @rate: Target clk rate in hz | |
60 | * @supplies: Array of voltage/current values for all power supplies | |
61 | * | |
62 | * This structure stores the freq/voltage/current values for a single OPP. | |
63 | */ | |
64 | struct dev_pm_opp_info { | |
65 | unsigned long rate; | |
66 | struct dev_pm_opp_supply *supplies; | |
67 | }; | |
68 | ||
69 | /** | |
70 | * struct dev_pm_set_opp_data - Set OPP data | |
71 | * @old_opp: Old OPP info | |
72 | * @new_opp: New OPP info | |
73 | * @regulators: Array of regulator pointers | |
74 | * @regulator_count: Number of regulators | |
75 | * @clk: Pointer to clk | |
76 | * @dev: Pointer to the struct device | |
77 | * | |
78 | * This structure contains all information required for setting an OPP. | |
79 | */ | |
80 | struct dev_pm_set_opp_data { | |
81 | struct dev_pm_opp_info old_opp; | |
82 | struct dev_pm_opp_info new_opp; | |
83 | ||
84 | struct regulator **regulators; | |
85 | unsigned int regulator_count; | |
86 | struct clk *clk; | |
87 | struct device *dev; | |
88 | }; | |
89 | ||
e1f60b29 NM |
90 | #if defined(CONFIG_PM_OPP) |
91 | ||
f067a982 VK |
92 | struct opp_table *dev_pm_opp_get_opp_table(struct device *dev); |
93 | void dev_pm_opp_put_opp_table(struct opp_table *opp_table); | |
94 | ||
47d43ba7 | 95 | unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp); |
e1f60b29 | 96 | |
47d43ba7 | 97 | unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp); |
e1f60b29 | 98 | |
5b93ac54 RN |
99 | unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp); |
100 | ||
19445b25 BZ |
101 | bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp); |
102 | ||
5d4879cd | 103 | int dev_pm_opp_get_opp_count(struct device *dev); |
3ca9bb33 | 104 | unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev); |
655c9df9 | 105 | unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev); |
21743447 | 106 | unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev); |
3aa26a3b | 107 | unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev); |
e1f60b29 | 108 | |
47d43ba7 NM |
109 | struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, |
110 | unsigned long freq, | |
111 | bool available); | |
71419d84 NC |
112 | struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, |
113 | unsigned int level); | |
e1f60b29 | 114 | |
47d43ba7 NM |
115 | struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, |
116 | unsigned long *freq); | |
2f36bde0 AC |
117 | struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev, |
118 | unsigned long u_volt); | |
e1f60b29 | 119 | |
47d43ba7 NM |
120 | struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, |
121 | unsigned long *freq); | |
7034764a | 122 | void dev_pm_opp_put(struct dev_pm_opp *opp); |
e1f60b29 | 123 | |
5d4879cd NM |
124 | int dev_pm_opp_add(struct device *dev, unsigned long freq, |
125 | unsigned long u_volt); | |
129eec55 | 126 | void dev_pm_opp_remove(struct device *dev, unsigned long freq); |
1690d8bb | 127 | void dev_pm_opp_remove_all_dynamic(struct device *dev); |
e1f60b29 | 128 | |
25cb20a2 SB |
129 | int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq, |
130 | unsigned long u_volt, unsigned long u_volt_min, | |
131 | unsigned long u_volt_max); | |
132 | ||
5d4879cd | 133 | int dev_pm_opp_enable(struct device *dev, unsigned long freq); |
e1f60b29 | 134 | |
5d4879cd | 135 | int dev_pm_opp_disable(struct device *dev, unsigned long freq); |
e1f60b29 | 136 | |
dc2c9ad5 VK |
137 | int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb); |
138 | int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb); | |
139 | ||
fa30184d VK |
140 | struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count); |
141 | void dev_pm_opp_put_supported_hw(struct opp_table *opp_table); | |
142 | struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name); | |
143 | void dev_pm_opp_put_prop_name(struct opp_table *opp_table); | |
dfbe4678 VK |
144 | struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count); |
145 | void dev_pm_opp_put_regulators(struct opp_table *opp_table); | |
829a4e8c VK |
146 | struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name); |
147 | void dev_pm_opp_put_clkname(struct opp_table *opp_table); | |
fa30184d | 148 | struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data)); |
604a7aeb | 149 | void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table); |
17a8f868 | 150 | struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs); |
6319aee1 | 151 | void dev_pm_opp_detach_genpd(struct opp_table *opp_table); |
c8a59103 | 152 | int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate); |
6a0712f6 | 153 | int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); |
3ae1f39a | 154 | int dev_pm_opp_set_bw(struct device *dev, struct dev_pm_opp *opp); |
ddbb74bc AB |
155 | int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask); |
156 | int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); | |
411466c5 SH |
157 | void dev_pm_opp_remove_table(struct device *dev); |
158 | void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask); | |
e1f60b29 | 159 | #else |
f067a982 VK |
160 | static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) |
161 | { | |
162 | return ERR_PTR(-ENOTSUPP); | |
163 | } | |
164 | ||
eb7c8743 VK |
165 | static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index) |
166 | { | |
167 | return ERR_PTR(-ENOTSUPP); | |
168 | } | |
169 | ||
f067a982 VK |
170 | static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {} |
171 | ||
47d43ba7 | 172 | static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) |
e1f60b29 NM |
173 | { |
174 | return 0; | |
175 | } | |
176 | ||
47d43ba7 | 177 | static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp) |
e1f60b29 NM |
178 | { |
179 | return 0; | |
180 | } | |
181 | ||
5b93ac54 RN |
182 | static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp) |
183 | { | |
184 | return 0; | |
185 | } | |
186 | ||
19445b25 BZ |
187 | static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp) |
188 | { | |
189 | return false; | |
190 | } | |
191 | ||
5d4879cd | 192 | static inline int dev_pm_opp_get_opp_count(struct device *dev) |
e1f60b29 NM |
193 | { |
194 | return 0; | |
195 | } | |
196 | ||
3ca9bb33 VK |
197 | static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev) |
198 | { | |
199 | return 0; | |
200 | } | |
201 | ||
655c9df9 VK |
202 | static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev) |
203 | { | |
204 | return 0; | |
205 | } | |
206 | ||
21743447 VK |
207 | static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev) |
208 | { | |
209 | return 0; | |
210 | } | |
211 | ||
3aa26a3b | 212 | static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev) |
4eafbd15 | 213 | { |
3aa26a3b | 214 | return 0; |
4eafbd15 BZ |
215 | } |
216 | ||
47d43ba7 | 217 | static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, |
e1f60b29 NM |
218 | unsigned long freq, bool available) |
219 | { | |
d708b384 | 220 | return ERR_PTR(-ENOTSUPP); |
e1f60b29 NM |
221 | } |
222 | ||
71419d84 NC |
223 | static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, |
224 | unsigned int level) | |
225 | { | |
226 | return ERR_PTR(-ENOTSUPP); | |
227 | } | |
228 | ||
47d43ba7 | 229 | static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, |
e1f60b29 NM |
230 | unsigned long *freq) |
231 | { | |
d708b384 | 232 | return ERR_PTR(-ENOTSUPP); |
e1f60b29 NM |
233 | } |
234 | ||
2f36bde0 AC |
235 | static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev, |
236 | unsigned long u_volt) | |
237 | { | |
238 | return ERR_PTR(-ENOTSUPP); | |
239 | } | |
240 | ||
47d43ba7 | 241 | static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, |
e1f60b29 NM |
242 | unsigned long *freq) |
243 | { | |
d708b384 | 244 | return ERR_PTR(-ENOTSUPP); |
e1f60b29 NM |
245 | } |
246 | ||
7034764a VK |
247 | static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {} |
248 | ||
5d4879cd | 249 | static inline int dev_pm_opp_add(struct device *dev, unsigned long freq, |
e1f60b29 NM |
250 | unsigned long u_volt) |
251 | { | |
d708b384 | 252 | return -ENOTSUPP; |
e1f60b29 NM |
253 | } |
254 | ||
129eec55 VK |
255 | static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq) |
256 | { | |
257 | } | |
258 | ||
1690d8bb VK |
259 | static inline void dev_pm_opp_remove_all_dynamic(struct device *dev) |
260 | { | |
261 | } | |
262 | ||
25cb20a2 SB |
263 | static inline int |
264 | dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq, | |
265 | unsigned long u_volt, unsigned long u_volt_min, | |
266 | unsigned long u_volt_max) | |
267 | { | |
268 | return 0; | |
269 | } | |
270 | ||
5d4879cd | 271 | static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq) |
e1f60b29 NM |
272 | { |
273 | return 0; | |
274 | } | |
275 | ||
5d4879cd | 276 | static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq) |
e1f60b29 NM |
277 | { |
278 | return 0; | |
279 | } | |
03ca370f | 280 | |
dc2c9ad5 | 281 | static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb) |
03ca370f | 282 | { |
dc2c9ad5 VK |
283 | return -ENOTSUPP; |
284 | } | |
285 | ||
286 | static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb) | |
287 | { | |
288 | return -ENOTSUPP; | |
03ca370f | 289 | } |
7de36b0a | 290 | |
fa30184d VK |
291 | static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, |
292 | const u32 *versions, | |
293 | unsigned int count) | |
7de36b0a | 294 | { |
fa30184d | 295 | return ERR_PTR(-ENOTSUPP); |
7de36b0a VK |
296 | } |
297 | ||
fa30184d | 298 | static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {} |
7de36b0a | 299 | |
fa30184d | 300 | static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, |
4dab160e VK |
301 | int (*set_opp)(struct dev_pm_set_opp_data *data)) |
302 | { | |
fa30184d | 303 | return ERR_PTR(-ENOTSUPP); |
4dab160e VK |
304 | } |
305 | ||
604a7aeb | 306 | static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {} |
4dab160e | 307 | |
fa30184d | 308 | static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name) |
01fb4d3c | 309 | { |
fa30184d | 310 | return ERR_PTR(-ENOTSUPP); |
01fb4d3c VK |
311 | } |
312 | ||
fa30184d | 313 | static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {} |
01fb4d3c | 314 | |
dfbe4678 | 315 | static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count) |
9f8ea969 | 316 | { |
91291d9a | 317 | return ERR_PTR(-ENOTSUPP); |
9f8ea969 VK |
318 | } |
319 | ||
dfbe4678 | 320 | static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {} |
9f8ea969 | 321 | |
829a4e8c VK |
322 | static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name) |
323 | { | |
324 | return ERR_PTR(-ENOTSUPP); | |
325 | } | |
326 | ||
327 | static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {} | |
328 | ||
17a8f868 | 329 | static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs) |
4f018bc0 VK |
330 | { |
331 | return ERR_PTR(-ENOTSUPP); | |
332 | } | |
333 | ||
6319aee1 | 334 | static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {} |
c8a59103 VK |
335 | |
336 | static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate) | |
337 | { | |
338 | return -ENOTSUPP; | |
339 | } | |
340 | ||
6a0712f6 VK |
341 | static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) |
342 | { | |
d708b384 | 343 | return -ENOTSUPP; |
6a0712f6 VK |
344 | } |
345 | ||
3ae1f39a SS |
346 | static inline int dev_pm_opp_set_bw(struct device *dev, struct dev_pm_opp *opp) |
347 | { | |
348 | return -EOPNOTSUPP; | |
349 | } | |
350 | ||
ddbb74bc | 351 | static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask) |
642aa8ce | 352 | { |
d708b384 | 353 | return -ENOTSUPP; |
642aa8ce VK |
354 | } |
355 | ||
ddbb74bc | 356 | static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask) |
6f707daa VK |
357 | { |
358 | return -EINVAL; | |
359 | } | |
360 | ||
411466c5 SH |
361 | static inline void dev_pm_opp_remove_table(struct device *dev) |
362 | { | |
363 | } | |
364 | ||
365 | static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask) | |
366 | { | |
367 | } | |
368 | ||
a96d69d1 | 369 | #endif /* CONFIG_PM_OPP */ |
e1f60b29 | 370 | |
d6561bb2 | 371 | #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF) |
8f8d37b2 | 372 | int dev_pm_opp_of_add_table(struct device *dev); |
fa9b274f | 373 | int dev_pm_opp_of_add_table_indexed(struct device *dev, int index); |
8f8d37b2 | 374 | void dev_pm_opp_of_remove_table(struct device *dev); |
ddbb74bc AB |
375 | int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask); |
376 | void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask); | |
377 | int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); | |
0764c604 | 378 | struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev); |
e2f4b5f8 | 379 | struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp); |
2feb5a89 | 380 | int of_get_required_opp_performance_state(struct device_node *np, int index); |
6d3f922c | 381 | int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table); |
0e0ffa85 LL |
382 | int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus); |
383 | static inline void dev_pm_opp_of_unregister_em(struct device *dev) | |
384 | { | |
385 | em_dev_unregister_perf_domain(dev); | |
386 | } | |
d6561bb2 | 387 | #else |
8f8d37b2 | 388 | static inline int dev_pm_opp_of_add_table(struct device *dev) |
d6561bb2 | 389 | { |
d708b384 | 390 | return -ENOTSUPP; |
d6561bb2 | 391 | } |
129eec55 | 392 | |
fa9b274f VK |
393 | static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) |
394 | { | |
395 | return -ENOTSUPP; | |
396 | } | |
397 | ||
8f8d37b2 | 398 | static inline void dev_pm_opp_of_remove_table(struct device *dev) |
129eec55 VK |
399 | { |
400 | } | |
8d4d4e98 | 401 | |
ddbb74bc | 402 | static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask) |
8d4d4e98 | 403 | { |
d708b384 | 404 | return -ENOTSUPP; |
8d4d4e98 VK |
405 | } |
406 | ||
ddbb74bc | 407 | static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask) |
8d4d4e98 VK |
408 | { |
409 | } | |
410 | ||
ddbb74bc | 411 | static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask) |
8d4d4e98 | 412 | { |
d708b384 | 413 | return -ENOTSUPP; |
8d4d4e98 | 414 | } |
0764c604 DG |
415 | |
416 | static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev) | |
417 | { | |
418 | return NULL; | |
419 | } | |
a88bd2a5 | 420 | |
e2f4b5f8 VK |
421 | static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp) |
422 | { | |
423 | return NULL; | |
424 | } | |
a4f342b9 | 425 | |
0e0ffa85 LL |
426 | static inline int dev_pm_opp_of_register_em(struct device *dev, |
427 | struct cpumask *cpus) | |
428 | { | |
429 | return -ENOTSUPP; | |
430 | } | |
431 | ||
432 | static inline void dev_pm_opp_of_unregister_em(struct device *dev) | |
a4f342b9 QP |
433 | { |
434 | } | |
435 | ||
2feb5a89 | 436 | static inline int of_get_required_opp_performance_state(struct device_node *np, int index) |
4c6a343e | 437 | { |
2feb5a89 | 438 | return -ENOTSUPP; |
4c6a343e | 439 | } |
6d3f922c GD |
440 | |
441 | static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table) | |
442 | { | |
443 | return -ENOTSUPP; | |
444 | } | |
d6561bb2 SG |
445 | #endif |
446 | ||
e1f60b29 | 447 | #endif /* __LINUX_OPP_H__ */ |