lib: stackdepot: add support to disable stack depot
[linux-2.6-microblaze.git] / include / linux / pm_opp.h
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  *
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
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
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
90 #if defined(CONFIG_PM_OPP)
91
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
95 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
96
97 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
98
99 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
100
101 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
102                                             unsigned int index);
103
104 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
105
106 int dev_pm_opp_get_opp_count(struct device *dev);
107 unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
108 unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
109 unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
110 unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
111
112 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
113                                               unsigned long freq,
114                                               bool available);
115 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
116                                                unsigned int level);
117 struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
118                                               unsigned int *level);
119
120 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
121                                               unsigned long *freq);
122 struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
123                                                      unsigned long u_volt);
124
125 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
126                                              unsigned long *freq);
127 void dev_pm_opp_put(struct dev_pm_opp *opp);
128
129 int dev_pm_opp_add(struct device *dev, unsigned long freq,
130                    unsigned long u_volt);
131 void dev_pm_opp_remove(struct device *dev, unsigned long freq);
132 void dev_pm_opp_remove_all_dynamic(struct device *dev);
133
134 int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
135                               unsigned long u_volt, unsigned long u_volt_min,
136                               unsigned long u_volt_max);
137
138 int dev_pm_opp_enable(struct device *dev, unsigned long freq);
139
140 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
141
142 int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
143 int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
144
145 struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
146 void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
147 struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
148 void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
149 struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
150 void dev_pm_opp_put_regulators(struct opp_table *opp_table);
151 struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name);
152 void dev_pm_opp_put_clkname(struct opp_table *opp_table);
153 struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
154 void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table);
155 struct opp_table *devm_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
156 struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs);
157 void dev_pm_opp_detach_genpd(struct opp_table *opp_table);
158 struct opp_table *devm_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs);
159 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);
160 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
161 int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
162 int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp);
163 int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
164 int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
165 void dev_pm_opp_remove_table(struct device *dev);
166 void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
167 int dev_pm_opp_sync_regulators(struct device *dev);
168 #else
169 static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
170 {
171         return ERR_PTR(-EOPNOTSUPP);
172 }
173
174 static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
175 {
176         return ERR_PTR(-EOPNOTSUPP);
177 }
178
179 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
180
181 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
182 {
183         return 0;
184 }
185
186 static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
187 {
188         return 0;
189 }
190
191 static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
192 {
193         return 0;
194 }
195
196 static inline
197 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
198                                             unsigned int index)
199 {
200         return 0;
201 }
202
203 static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
204 {
205         return false;
206 }
207
208 static inline int dev_pm_opp_get_opp_count(struct device *dev)
209 {
210         return 0;
211 }
212
213 static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
214 {
215         return 0;
216 }
217
218 static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
219 {
220         return 0;
221 }
222
223 static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
224 {
225         return 0;
226 }
227
228 static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
229 {
230         return 0;
231 }
232
233 static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
234                                         unsigned long freq, bool available)
235 {
236         return ERR_PTR(-EOPNOTSUPP);
237 }
238
239 static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
240                                         unsigned int level)
241 {
242         return ERR_PTR(-EOPNOTSUPP);
243 }
244
245 static inline struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
246                                         unsigned int *level)
247 {
248         return ERR_PTR(-EOPNOTSUPP);
249 }
250
251 static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
252                                         unsigned long *freq)
253 {
254         return ERR_PTR(-EOPNOTSUPP);
255 }
256
257 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
258                                         unsigned long u_volt)
259 {
260         return ERR_PTR(-EOPNOTSUPP);
261 }
262
263 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
264                                         unsigned long *freq)
265 {
266         return ERR_PTR(-EOPNOTSUPP);
267 }
268
269 static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
270
271 static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
272                                         unsigned long u_volt)
273 {
274         return -EOPNOTSUPP;
275 }
276
277 static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
278 {
279 }
280
281 static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
282 {
283 }
284
285 static inline int
286 dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
287                           unsigned long u_volt, unsigned long u_volt_min,
288                           unsigned long u_volt_max)
289 {
290         return 0;
291 }
292
293 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
294 {
295         return 0;
296 }
297
298 static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
299 {
300         return 0;
301 }
302
303 static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
304 {
305         return -EOPNOTSUPP;
306 }
307
308 static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
309 {
310         return -EOPNOTSUPP;
311 }
312
313 static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
314                                                             const u32 *versions,
315                                                             unsigned int count)
316 {
317         return ERR_PTR(-EOPNOTSUPP);
318 }
319
320 static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
321
322 static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
323                         int (*set_opp)(struct dev_pm_set_opp_data *data))
324 {
325         return ERR_PTR(-EOPNOTSUPP);
326 }
327
328 static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {}
329
330 static inline struct opp_table *
331 devm_pm_opp_register_set_opp_helper(struct device *dev,
332                                     int (*set_opp)(struct dev_pm_set_opp_data *data))
333 {
334         return ERR_PTR(-EOPNOTSUPP);
335 }
336
337 static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
338 {
339         return ERR_PTR(-EOPNOTSUPP);
340 }
341
342 static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
343
344 static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
345 {
346         return ERR_PTR(-EOPNOTSUPP);
347 }
348
349 static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
350
351 static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name)
352 {
353         return ERR_PTR(-EOPNOTSUPP);
354 }
355
356 static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {}
357
358 static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs)
359 {
360         return ERR_PTR(-EOPNOTSUPP);
361 }
362
363 static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {}
364
365 static inline struct opp_table *devm_pm_opp_attach_genpd(struct device *dev,
366                                 const char **names, struct device ***virt_devs)
367 {
368         return ERR_PTR(-EOPNOTSUPP);
369 }
370
371 static inline struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table,
372                                 struct opp_table *dst_table, struct dev_pm_opp *src_opp)
373 {
374         return ERR_PTR(-EOPNOTSUPP);
375 }
376
377 static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
378 {
379         return -EOPNOTSUPP;
380 }
381
382 static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
383 {
384         return -EOPNOTSUPP;
385 }
386
387 static inline int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp)
388 {
389         return -EOPNOTSUPP;
390 }
391
392 static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
393 {
394         return -EOPNOTSUPP;
395 }
396
397 static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
398 {
399         return -EINVAL;
400 }
401
402 static inline void dev_pm_opp_remove_table(struct device *dev)
403 {
404 }
405
406 static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
407 {
408 }
409
410 static inline int dev_pm_opp_sync_regulators(struct device *dev)
411 {
412         return -EOPNOTSUPP;
413 }
414
415 #endif          /* CONFIG_PM_OPP */
416
417 #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
418 int dev_pm_opp_of_add_table(struct device *dev);
419 int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
420 int dev_pm_opp_of_add_table_noclk(struct device *dev, int index);
421 void dev_pm_opp_of_remove_table(struct device *dev);
422 int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
423 void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
424 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
425 struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
426 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
427 int of_get_required_opp_performance_state(struct device_node *np, int index);
428 int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
429 int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
430 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
431 {
432         em_dev_unregister_perf_domain(dev);
433 }
434 #else
435 static inline int dev_pm_opp_of_add_table(struct device *dev)
436 {
437         return -EOPNOTSUPP;
438 }
439
440 static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
441 {
442         return -EOPNOTSUPP;
443 }
444
445 static inline int dev_pm_opp_of_add_table_noclk(struct device *dev, int index)
446 {
447         return -EOPNOTSUPP;
448 }
449
450 static inline void dev_pm_opp_of_remove_table(struct device *dev)
451 {
452 }
453
454 static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
455 {
456         return -EOPNOTSUPP;
457 }
458
459 static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
460 {
461 }
462
463 static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
464 {
465         return -EOPNOTSUPP;
466 }
467
468 static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
469 {
470         return NULL;
471 }
472
473 static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
474 {
475         return NULL;
476 }
477
478 static inline int dev_pm_opp_of_register_em(struct device *dev,
479                                             struct cpumask *cpus)
480 {
481         return -EOPNOTSUPP;
482 }
483
484 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
485 {
486 }
487
488 static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
489 {
490         return -EOPNOTSUPP;
491 }
492
493 static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table)
494 {
495         return -EOPNOTSUPP;
496 }
497 #endif
498
499 #endif          /* __LINUX_OPP_H__ */