xref: /linux/include/linux/pm_opp.h (revision 0be3ff0c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Generic OPP Interface
4  *
5  * Copyright (C) 2009-2010 Texas Instruments Incorporated.
6  *	Nishanth Menon
7  *	Romit Dasgupta
8  *	Kevin Hilman
9  */
10 
11 #ifndef __LINUX_OPP_H__
12 #define __LINUX_OPP_H__
13 
14 #include <linux/energy_model.h>
15 #include <linux/err.h>
16 #include <linux/notifier.h>
17 
18 struct clk;
19 struct regulator;
20 struct dev_pm_opp;
21 struct device;
22 struct opp_table;
23 
24 enum dev_pm_opp_event {
25 	OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE,
26 	OPP_EVENT_ADJUST_VOLTAGE,
27 };
28 
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  * @u_watt:	Power used by the device in microwatts
36  *
37  * This structure stores the voltage/current/power values for a single power
38  * supply.
39  */
40 struct dev_pm_opp_supply {
41 	unsigned long u_volt;
42 	unsigned long u_volt_min;
43 	unsigned long u_volt_max;
44 	unsigned long u_amp;
45 	unsigned long u_watt;
46 };
47 
48 /**
49  * struct dev_pm_opp_icc_bw - Interconnect bandwidth values
50  * @avg:	Average bandwidth corresponding to this OPP (in icc units)
51  * @peak:	Peak bandwidth corresponding to this OPP (in icc units)
52  *
53  * This structure stores the bandwidth values for a single interconnect path.
54  */
55 struct dev_pm_opp_icc_bw {
56 	u32 avg;
57 	u32 peak;
58 };
59 
60 /**
61  * struct dev_pm_opp_info - OPP freq/voltage/current values
62  * @rate:	Target clk rate in hz
63  * @supplies:	Array of voltage/current values for all power supplies
64  *
65  * This structure stores the freq/voltage/current values for a single OPP.
66  */
67 struct dev_pm_opp_info {
68 	unsigned long rate;
69 	struct dev_pm_opp_supply *supplies;
70 };
71 
72 /**
73  * struct dev_pm_set_opp_data - Set OPP data
74  * @old_opp:	Old OPP info
75  * @new_opp:	New OPP info
76  * @regulators:	Array of regulator pointers
77  * @regulator_count: Number of regulators
78  * @clk:	Pointer to clk
79  * @dev:	Pointer to the struct device
80  *
81  * This structure contains all information required for setting an OPP.
82  */
83 struct dev_pm_set_opp_data {
84 	struct dev_pm_opp_info old_opp;
85 	struct dev_pm_opp_info new_opp;
86 
87 	struct regulator **regulators;
88 	unsigned int regulator_count;
89 	struct clk *clk;
90 	struct device *dev;
91 };
92 
93 #if defined(CONFIG_PM_OPP)
94 
95 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
96 void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
97 
98 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
99 
100 unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp);
101 
102 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
103 
104 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
105 
106 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
107 					    unsigned int index);
108 
109 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
110 
111 int dev_pm_opp_get_opp_count(struct device *dev);
112 unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
113 unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
114 unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
115 unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
116 
117 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
118 					      unsigned long freq,
119 					      bool available);
120 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
121 					       unsigned int level);
122 struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
123 					      unsigned int *level);
124 
125 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
126 					      unsigned long *freq);
127 struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
128 						     unsigned long u_volt);
129 
130 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
131 					     unsigned long *freq);
132 void dev_pm_opp_put(struct dev_pm_opp *opp);
133 
134 int dev_pm_opp_add(struct device *dev, unsigned long freq,
135 		   unsigned long u_volt);
136 void dev_pm_opp_remove(struct device *dev, unsigned long freq);
137 void dev_pm_opp_remove_all_dynamic(struct device *dev);
138 
139 int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
140 			      unsigned long u_volt, unsigned long u_volt_min,
141 			      unsigned long u_volt_max);
142 
143 int dev_pm_opp_enable(struct device *dev, unsigned long freq);
144 
145 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
146 
147 int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
148 int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
149 
150 struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
151 void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
152 int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
153 struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
154 void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
155 struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
156 void dev_pm_opp_put_regulators(struct opp_table *opp_table);
157 int devm_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
158 struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name);
159 void dev_pm_opp_put_clkname(struct opp_table *opp_table);
160 int devm_pm_opp_set_clkname(struct device *dev, const char *name);
161 struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
162 void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table);
163 int devm_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
164 struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char * const *names, struct device ***virt_devs);
165 void dev_pm_opp_detach_genpd(struct opp_table *opp_table);
166 int devm_pm_opp_attach_genpd(struct device *dev, const char * const *names, struct device ***virt_devs);
167 struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table, struct opp_table *dst_table, struct dev_pm_opp *src_opp);
168 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
169 int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
170 int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp);
171 int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
172 int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
173 void dev_pm_opp_remove_table(struct device *dev);
174 void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
175 int dev_pm_opp_sync_regulators(struct device *dev);
176 #else
177 static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
178 {
179 	return ERR_PTR(-EOPNOTSUPP);
180 }
181 
182 static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
183 {
184 	return ERR_PTR(-EOPNOTSUPP);
185 }
186 
187 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
188 
189 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
190 {
191 	return 0;
192 }
193 
194 static inline unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp)
195 {
196 	return 0;
197 }
198 
199 static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
200 {
201 	return 0;
202 }
203 
204 static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
205 {
206 	return 0;
207 }
208 
209 static inline
210 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
211 					    unsigned int index)
212 {
213 	return 0;
214 }
215 
216 static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
217 {
218 	return false;
219 }
220 
221 static inline int dev_pm_opp_get_opp_count(struct device *dev)
222 {
223 	return 0;
224 }
225 
226 static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
227 {
228 	return 0;
229 }
230 
231 static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
232 {
233 	return 0;
234 }
235 
236 static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
237 {
238 	return 0;
239 }
240 
241 static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
242 {
243 	return 0;
244 }
245 
246 static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
247 					unsigned long freq, bool available)
248 {
249 	return ERR_PTR(-EOPNOTSUPP);
250 }
251 
252 static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
253 					unsigned int level)
254 {
255 	return ERR_PTR(-EOPNOTSUPP);
256 }
257 
258 static inline struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
259 					unsigned int *level)
260 {
261 	return ERR_PTR(-EOPNOTSUPP);
262 }
263 
264 static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
265 					unsigned long *freq)
266 {
267 	return ERR_PTR(-EOPNOTSUPP);
268 }
269 
270 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
271 					unsigned long u_volt)
272 {
273 	return ERR_PTR(-EOPNOTSUPP);
274 }
275 
276 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
277 					unsigned long *freq)
278 {
279 	return ERR_PTR(-EOPNOTSUPP);
280 }
281 
282 static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
283 
284 static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
285 					unsigned long u_volt)
286 {
287 	return -EOPNOTSUPP;
288 }
289 
290 static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
291 {
292 }
293 
294 static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
295 {
296 }
297 
298 static inline int
299 dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
300 			  unsigned long u_volt, unsigned long u_volt_min,
301 			  unsigned long u_volt_max)
302 {
303 	return 0;
304 }
305 
306 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
307 {
308 	return 0;
309 }
310 
311 static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
312 {
313 	return 0;
314 }
315 
316 static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
317 {
318 	return -EOPNOTSUPP;
319 }
320 
321 static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
322 {
323 	return -EOPNOTSUPP;
324 }
325 
326 static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
327 							    const u32 *versions,
328 							    unsigned int count)
329 {
330 	return ERR_PTR(-EOPNOTSUPP);
331 }
332 
333 static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
334 
335 static inline int devm_pm_opp_set_supported_hw(struct device *dev,
336 					       const u32 *versions,
337 					       unsigned int count)
338 {
339 	return -EOPNOTSUPP;
340 }
341 
342 static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
343 			int (*set_opp)(struct dev_pm_set_opp_data *data))
344 {
345 	return ERR_PTR(-EOPNOTSUPP);
346 }
347 
348 static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {}
349 
350 static inline int devm_pm_opp_register_set_opp_helper(struct device *dev,
351 				    int (*set_opp)(struct dev_pm_set_opp_data *data))
352 {
353 	return -EOPNOTSUPP;
354 }
355 
356 static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
357 {
358 	return ERR_PTR(-EOPNOTSUPP);
359 }
360 
361 static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
362 
363 static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
364 {
365 	return ERR_PTR(-EOPNOTSUPP);
366 }
367 
368 static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
369 
370 static inline int devm_pm_opp_set_regulators(struct device *dev,
371 					     const char * const names[],
372 					     unsigned int count)
373 {
374 	return -EOPNOTSUPP;
375 }
376 
377 static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name)
378 {
379 	return ERR_PTR(-EOPNOTSUPP);
380 }
381 
382 static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {}
383 
384 static inline int devm_pm_opp_set_clkname(struct device *dev, const char *name)
385 {
386 	return -EOPNOTSUPP;
387 }
388 
389 static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char * const *names, struct device ***virt_devs)
390 {
391 	return ERR_PTR(-EOPNOTSUPP);
392 }
393 
394 static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {}
395 
396 static inline int devm_pm_opp_attach_genpd(struct device *dev,
397 					   const char * const *names,
398 					   struct device ***virt_devs)
399 {
400 	return -EOPNOTSUPP;
401 }
402 
403 static inline struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table,
404 				struct opp_table *dst_table, struct dev_pm_opp *src_opp)
405 {
406 	return ERR_PTR(-EOPNOTSUPP);
407 }
408 
409 static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
410 {
411 	return -EOPNOTSUPP;
412 }
413 
414 static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
415 {
416 	return -EOPNOTSUPP;
417 }
418 
419 static inline int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp)
420 {
421 	return -EOPNOTSUPP;
422 }
423 
424 static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
425 {
426 	return -EOPNOTSUPP;
427 }
428 
429 static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
430 {
431 	return -EINVAL;
432 }
433 
434 static inline void dev_pm_opp_remove_table(struct device *dev)
435 {
436 }
437 
438 static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
439 {
440 }
441 
442 static inline int dev_pm_opp_sync_regulators(struct device *dev)
443 {
444 	return -EOPNOTSUPP;
445 }
446 
447 #endif		/* CONFIG_PM_OPP */
448 
449 #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
450 int dev_pm_opp_of_add_table(struct device *dev);
451 int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
452 int devm_pm_opp_of_add_table_indexed(struct device *dev, int index);
453 int dev_pm_opp_of_add_table_noclk(struct device *dev, int index);
454 int devm_pm_opp_of_add_table_noclk(struct device *dev, int index);
455 void dev_pm_opp_of_remove_table(struct device *dev);
456 int devm_pm_opp_of_add_table(struct device *dev);
457 int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
458 void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
459 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
460 struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
461 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
462 int of_get_required_opp_performance_state(struct device_node *np, int index);
463 int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
464 int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
465 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
466 {
467 	em_dev_unregister_perf_domain(dev);
468 }
469 #else
470 static inline int dev_pm_opp_of_add_table(struct device *dev)
471 {
472 	return -EOPNOTSUPP;
473 }
474 
475 static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
476 {
477 	return -EOPNOTSUPP;
478 }
479 
480 static inline int devm_pm_opp_of_add_table_indexed(struct device *dev, int index)
481 {
482 	return -EOPNOTSUPP;
483 }
484 
485 static inline int dev_pm_opp_of_add_table_noclk(struct device *dev, int index)
486 {
487 	return -EOPNOTSUPP;
488 }
489 
490 static inline int devm_pm_opp_of_add_table_noclk(struct device *dev, int index)
491 {
492 	return -EOPNOTSUPP;
493 }
494 
495 static inline void dev_pm_opp_of_remove_table(struct device *dev)
496 {
497 }
498 
499 static inline int devm_pm_opp_of_add_table(struct device *dev)
500 {
501 	return -EOPNOTSUPP;
502 }
503 
504 static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
505 {
506 	return -EOPNOTSUPP;
507 }
508 
509 static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
510 {
511 }
512 
513 static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
514 {
515 	return -EOPNOTSUPP;
516 }
517 
518 static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
519 {
520 	return NULL;
521 }
522 
523 static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
524 {
525 	return NULL;
526 }
527 
528 static inline int dev_pm_opp_of_register_em(struct device *dev,
529 					    struct cpumask *cpus)
530 {
531 	return -EOPNOTSUPP;
532 }
533 
534 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
535 {
536 }
537 
538 static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
539 {
540 	return -EOPNOTSUPP;
541 }
542 
543 static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table)
544 {
545 	return -EOPNOTSUPP;
546 }
547 #endif
548 
549 #endif		/* __LINUX_OPP_H__ */
550