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/cleanup.h>
15 #include <linux/energy_model.h>
16 #include <linux/err.h>
17 #include <linux/notifier.h>
18
19 struct clk;
20 struct cpufreq_frequency_table;
21 struct regulator;
22 struct dev_pm_opp;
23 struct device;
24 struct opp_table;
25
26 enum dev_pm_opp_event {
27 OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE,
28 OPP_EVENT_ADJUST_VOLTAGE,
29 };
30
31 /**
32 * struct dev_pm_opp_supply - Power supply voltage/current values
33 * @u_volt: Target voltage in microvolts corresponding to this OPP
34 * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP
35 * @u_volt_max: Maximum voltage in microvolts corresponding to this OPP
36 * @u_amp: Maximum current drawn by the device in microamperes
37 * @u_watt: Power used by the device in microwatts
38 *
39 * This structure stores the voltage/current/power values for a single power
40 * supply.
41 */
42 struct dev_pm_opp_supply {
43 unsigned long u_volt;
44 unsigned long u_volt_min;
45 unsigned long u_volt_max;
46 unsigned long u_amp;
47 unsigned long u_watt;
48 };
49
50 typedef int (*config_regulators_t)(struct device *dev,
51 struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp,
52 struct regulator **regulators, unsigned int count);
53
54 typedef int (*config_clks_t)(struct device *dev, struct opp_table *opp_table,
55 struct dev_pm_opp *opp, void *data, bool scaling_down);
56
57 /**
58 * struct dev_pm_opp_config - Device OPP configuration values
59 * @clk_names: Clk names, NULL terminated array.
60 * @config_clks: Custom set clk helper.
61 * @prop_name: Name to postfix to properties.
62 * @config_regulators: Custom set regulator helper.
63 * @supported_hw: Array of hierarchy of versions to match.
64 * @supported_hw_count: Number of elements in the array.
65 * @regulator_names: Array of pointers to the names of the regulator, NULL terminated.
66 * @required_dev: The required OPP device.
67 * @required_dev_index: The index of the required OPP for the @required_dev.
68 *
69 * This structure contains platform specific OPP configurations for the device.
70 */
71 struct dev_pm_opp_config {
72 /* NULL terminated */
73 const char * const *clk_names;
74 config_clks_t config_clks;
75 const char *prop_name;
76 config_regulators_t config_regulators;
77 const unsigned int *supported_hw;
78 unsigned int supported_hw_count;
79 const char * const *regulator_names;
80 struct device *required_dev;
81 unsigned int required_dev_index;
82 };
83
84 #define OPP_LEVEL_UNSET U32_MAX
85
86 /**
87 * struct dev_pm_opp_data - The data to use to initialize an OPP.
88 * @turbo: Flag to indicate whether the OPP is to be marked turbo or not.
89 * @level: The performance level for the OPP. Set level to OPP_LEVEL_UNSET if
90 * level field isn't used.
91 * @freq: The clock rate in Hz for the OPP.
92 * @u_volt: The voltage in uV for the OPP.
93 */
94 struct dev_pm_opp_data {
95 bool turbo;
96 unsigned int level;
97 unsigned long freq;
98 unsigned long u_volt;
99 };
100
101 /**
102 * struct dev_pm_opp_key - Key used to identify OPP entries
103 * @freq: Frequency in Hz. Use 0 if frequency is not to be matched.
104 * @level: Performance level associated with the OPP entry.
105 * Use OPP_LEVEL_UNSET if level is not to be matched.
106 * @bw: Bandwidth associated with the OPP entry.
107 * Use 0 if bandwidth is not to be matched.
108 *
109 * This structure is used to uniquely identify an OPP entry based on
110 * frequency, performance level, and bandwidth. Each field can be
111 * selectively ignored during matching by setting it to its respective
112 * NOP value.
113 */
114 struct dev_pm_opp_key {
115 unsigned long freq;
116 unsigned int level;
117 u32 bw;
118 };
119
120 #if defined(CONFIG_PM_OPP)
121
122 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
123 struct opp_table *dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table);
124 void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
125
126 unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index);
127
128 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
129
130 int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies);
131
132 unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp);
133
134 unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index);
135
136 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
137
138 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
139 unsigned int index);
140
141 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
142
143 int dev_pm_opp_get_opp_count(struct device *dev);
144 unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
145 unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
146 unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
147 unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
148
149 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
150 unsigned long freq,
151 bool available);
152
153 struct dev_pm_opp *dev_pm_opp_find_key_exact(struct device *dev,
154 struct dev_pm_opp_key *key,
155 bool available);
156
157 struct dev_pm_opp *
158 dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq,
159 u32 index, bool available);
160
161 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
162 unsigned long *freq);
163
164 struct dev_pm_opp *dev_pm_opp_find_freq_floor_indexed(struct device *dev,
165 unsigned long *freq, u32 index);
166
167 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
168 unsigned long *freq);
169
170 struct dev_pm_opp *dev_pm_opp_find_freq_ceil_indexed(struct device *dev,
171 unsigned long *freq, u32 index);
172
173 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
174 unsigned int level);
175
176 struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
177 unsigned int *level);
178
179 struct dev_pm_opp *dev_pm_opp_find_level_floor(struct device *dev,
180 unsigned int *level);
181
182 struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
183 unsigned int *bw, int index);
184
185 struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
186 unsigned int *bw, int index);
187
188 struct dev_pm_opp *dev_pm_opp_get(struct dev_pm_opp *opp);
189 void dev_pm_opp_put(struct dev_pm_opp *opp);
190
191 int dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp);
192
193 void dev_pm_opp_remove(struct device *dev, unsigned long freq);
194 void dev_pm_opp_remove_all_dynamic(struct device *dev);
195
196 int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
197 unsigned long u_volt, unsigned long u_volt_min,
198 unsigned long u_volt_max);
199
200 int dev_pm_opp_enable(struct device *dev, unsigned long freq);
201
202 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
203
204 int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
205 int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
206
207 int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
208 int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
209 void dev_pm_opp_clear_config(int token);
210 int dev_pm_opp_config_clks_simple(struct device *dev,
211 struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
212 bool scaling_down);
213
214 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);
215 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
216 int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
217 int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp);
218 int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
219 int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
220 void dev_pm_opp_remove_table(struct device *dev);
221 void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
222 int dev_pm_opp_sync_regulators(struct device *dev);
223
224 #else
dev_pm_opp_get_opp_table(struct device * dev)225 static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
226 {
227 return ERR_PTR(-EOPNOTSUPP);
228 }
229
dev_pm_opp_get_opp_table_indexed(struct device * dev,int index)230 static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
231 {
232 return ERR_PTR(-EOPNOTSUPP);
233 }
234
dev_pm_opp_get_opp_table_ref(struct opp_table * opp_table)235 static inline struct opp_table *dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table)
236 {
237 return opp_table;
238 }
239
dev_pm_opp_put_opp_table(struct opp_table * opp_table)240 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
241
dev_pm_opp_get_bw(struct dev_pm_opp * opp,bool peak,int index)242 static inline unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index)
243 {
244 return 0;
245 }
246
dev_pm_opp_get_voltage(struct dev_pm_opp * opp)247 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
248 {
249 return 0;
250 }
251
dev_pm_opp_get_supplies(struct dev_pm_opp * opp,struct dev_pm_opp_supply * supplies)252 static inline int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies)
253 {
254 return -EOPNOTSUPP;
255 }
256
dev_pm_opp_get_power(struct dev_pm_opp * opp)257 static inline unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp)
258 {
259 return 0;
260 }
261
dev_pm_opp_get_freq_indexed(struct dev_pm_opp * opp,u32 index)262 static inline unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index)
263 {
264 return 0;
265 }
266
dev_pm_opp_get_level(struct dev_pm_opp * opp)267 static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
268 {
269 return 0;
270 }
271
272 static inline
dev_pm_opp_get_required_pstate(struct dev_pm_opp * opp,unsigned int index)273 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
274 unsigned int index)
275 {
276 return 0;
277 }
278
dev_pm_opp_is_turbo(struct dev_pm_opp * opp)279 static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
280 {
281 return false;
282 }
283
dev_pm_opp_get_opp_count(struct device * dev)284 static inline int dev_pm_opp_get_opp_count(struct device *dev)
285 {
286 return 0;
287 }
288
dev_pm_opp_get_max_clock_latency(struct device * dev)289 static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
290 {
291 return 0;
292 }
293
dev_pm_opp_get_max_volt_latency(struct device * dev)294 static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
295 {
296 return 0;
297 }
298
dev_pm_opp_get_max_transition_latency(struct device * dev)299 static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
300 {
301 return 0;
302 }
303
dev_pm_opp_get_suspend_opp_freq(struct device * dev)304 static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
305 {
306 return 0;
307 }
308
dev_pm_opp_find_freq_exact(struct device * dev,unsigned long freq,bool available)309 static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
310 unsigned long freq, bool available)
311 {
312 return ERR_PTR(-EOPNOTSUPP);
313 }
314
dev_pm_opp_find_key_exact(struct device * dev,struct dev_pm_opp_key * key,bool available)315 static inline struct dev_pm_opp *dev_pm_opp_find_key_exact(struct device *dev,
316 struct dev_pm_opp_key *key,
317 bool available)
318 {
319 return ERR_PTR(-EOPNOTSUPP);
320 }
321
322 static inline struct dev_pm_opp *
dev_pm_opp_find_freq_exact_indexed(struct device * dev,unsigned long freq,u32 index,bool available)323 dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq,
324 u32 index, bool available)
325 {
326 return ERR_PTR(-EOPNOTSUPP);
327 }
328
dev_pm_opp_find_freq_floor(struct device * dev,unsigned long * freq)329 static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
330 unsigned long *freq)
331 {
332 return ERR_PTR(-EOPNOTSUPP);
333 }
334
335 static inline struct dev_pm_opp *
dev_pm_opp_find_freq_floor_indexed(struct device * dev,unsigned long * freq,u32 index)336 dev_pm_opp_find_freq_floor_indexed(struct device *dev, unsigned long *freq, u32 index)
337 {
338 return ERR_PTR(-EOPNOTSUPP);
339 }
340
dev_pm_opp_find_freq_ceil(struct device * dev,unsigned long * freq)341 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
342 unsigned long *freq)
343 {
344 return ERR_PTR(-EOPNOTSUPP);
345 }
346
347 static inline struct dev_pm_opp *
dev_pm_opp_find_freq_ceil_indexed(struct device * dev,unsigned long * freq,u32 index)348 dev_pm_opp_find_freq_ceil_indexed(struct device *dev, unsigned long *freq, u32 index)
349 {
350 return ERR_PTR(-EOPNOTSUPP);
351 }
352
dev_pm_opp_find_level_exact(struct device * dev,unsigned int level)353 static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
354 unsigned int level)
355 {
356 return ERR_PTR(-EOPNOTSUPP);
357 }
358
dev_pm_opp_find_level_ceil(struct device * dev,unsigned int * level)359 static inline struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
360 unsigned int *level)
361 {
362 return ERR_PTR(-EOPNOTSUPP);
363 }
364
dev_pm_opp_find_level_floor(struct device * dev,unsigned int * level)365 static inline struct dev_pm_opp *dev_pm_opp_find_level_floor(struct device *dev,
366 unsigned int *level)
367 {
368 return ERR_PTR(-EOPNOTSUPP);
369 }
370
dev_pm_opp_find_bw_ceil(struct device * dev,unsigned int * bw,int index)371 static inline struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
372 unsigned int *bw, int index)
373 {
374 return ERR_PTR(-EOPNOTSUPP);
375 }
376
dev_pm_opp_find_bw_floor(struct device * dev,unsigned int * bw,int index)377 static inline struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
378 unsigned int *bw, int index)
379 {
380 return ERR_PTR(-EOPNOTSUPP);
381 }
382
dev_pm_opp_get(struct dev_pm_opp * opp)383 static inline struct dev_pm_opp *dev_pm_opp_get(struct dev_pm_opp *opp)
384 {
385 return opp;
386 }
387
dev_pm_opp_put(struct dev_pm_opp * opp)388 static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
389
390 static inline int
dev_pm_opp_add_dynamic(struct device * dev,struct dev_pm_opp_data * opp)391 dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp)
392 {
393 return -EOPNOTSUPP;
394 }
395
dev_pm_opp_remove(struct device * dev,unsigned long freq)396 static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
397 {
398 }
399
dev_pm_opp_remove_all_dynamic(struct device * dev)400 static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
401 {
402 }
403
404 static inline int
dev_pm_opp_adjust_voltage(struct device * dev,unsigned long freq,unsigned long u_volt,unsigned long u_volt_min,unsigned long u_volt_max)405 dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
406 unsigned long u_volt, unsigned long u_volt_min,
407 unsigned long u_volt_max)
408 {
409 return 0;
410 }
411
dev_pm_opp_enable(struct device * dev,unsigned long freq)412 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
413 {
414 return 0;
415 }
416
dev_pm_opp_disable(struct device * dev,unsigned long freq)417 static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
418 {
419 return 0;
420 }
421
dev_pm_opp_register_notifier(struct device * dev,struct notifier_block * nb)422 static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
423 {
424 return -EOPNOTSUPP;
425 }
426
dev_pm_opp_unregister_notifier(struct device * dev,struct notifier_block * nb)427 static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
428 {
429 return -EOPNOTSUPP;
430 }
431
dev_pm_opp_set_config(struct device * dev,struct dev_pm_opp_config * config)432 static inline int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
433 {
434 return -EOPNOTSUPP;
435 }
436
devm_pm_opp_set_config(struct device * dev,struct dev_pm_opp_config * config)437 static inline int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
438 {
439 return -EOPNOTSUPP;
440 }
441
dev_pm_opp_clear_config(int token)442 static inline void dev_pm_opp_clear_config(int token) {}
443
dev_pm_opp_config_clks_simple(struct device * dev,struct opp_table * opp_table,struct dev_pm_opp * opp,void * data,bool scaling_down)444 static inline int dev_pm_opp_config_clks_simple(struct device *dev,
445 struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
446 bool scaling_down)
447 {
448 return -EOPNOTSUPP;
449 }
450
dev_pm_opp_xlate_required_opp(struct opp_table * src_table,struct opp_table * dst_table,struct dev_pm_opp * src_opp)451 static inline struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table,
452 struct opp_table *dst_table, struct dev_pm_opp *src_opp)
453 {
454 return ERR_PTR(-EOPNOTSUPP);
455 }
456
dev_pm_opp_xlate_performance_state(struct opp_table * src_table,struct opp_table * dst_table,unsigned int pstate)457 static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
458 {
459 return -EOPNOTSUPP;
460 }
461
dev_pm_opp_set_rate(struct device * dev,unsigned long target_freq)462 static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
463 {
464 return -EOPNOTSUPP;
465 }
466
dev_pm_opp_set_opp(struct device * dev,struct dev_pm_opp * opp)467 static inline int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp)
468 {
469 return -EOPNOTSUPP;
470 }
471
dev_pm_opp_set_sharing_cpus(struct device * cpu_dev,const struct cpumask * cpumask)472 static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
473 {
474 return -EOPNOTSUPP;
475 }
476
dev_pm_opp_get_sharing_cpus(struct device * cpu_dev,struct cpumask * cpumask)477 static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
478 {
479 return -EINVAL;
480 }
481
dev_pm_opp_remove_table(struct device * dev)482 static inline void dev_pm_opp_remove_table(struct device *dev)
483 {
484 }
485
dev_pm_opp_cpumask_remove_table(const struct cpumask * cpumask)486 static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
487 {
488 }
489
dev_pm_opp_sync_regulators(struct device * dev)490 static inline int dev_pm_opp_sync_regulators(struct device *dev)
491 {
492 return -EOPNOTSUPP;
493 }
494
495 #endif /* CONFIG_PM_OPP */
496
497 #if defined(CONFIG_CPU_FREQ) && defined(CONFIG_PM_OPP)
498 int dev_pm_opp_init_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table);
499 void dev_pm_opp_free_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table);
500 #else
dev_pm_opp_init_cpufreq_table(struct device * dev,struct cpufreq_frequency_table ** table)501 static inline int dev_pm_opp_init_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table)
502 {
503 return -EINVAL;
504 }
505
dev_pm_opp_free_cpufreq_table(struct device * dev,struct cpufreq_frequency_table ** table)506 static inline void dev_pm_opp_free_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table)
507 {
508 }
509 #endif
510
511
512 #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
513 int dev_pm_opp_of_add_table(struct device *dev);
514 int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
515 int devm_pm_opp_of_add_table_indexed(struct device *dev, int index);
516 void dev_pm_opp_of_remove_table(struct device *dev);
517 int devm_pm_opp_of_add_table(struct device *dev);
518 int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
519 void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
520 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
521 struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
522 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
523 int of_get_required_opp_performance_state(struct device_node *np, int index);
524 bool dev_pm_opp_of_has_required_opp(struct device *dev);
525 int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
526 int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
527 int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW,
528 unsigned long *kHz);
dev_pm_opp_of_unregister_em(struct device * dev)529 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
530 {
531 em_dev_unregister_perf_domain(dev);
532 }
533 #else
dev_pm_opp_of_add_table(struct device * dev)534 static inline int dev_pm_opp_of_add_table(struct device *dev)
535 {
536 return -EOPNOTSUPP;
537 }
538
dev_pm_opp_of_add_table_indexed(struct device * dev,int index)539 static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
540 {
541 return -EOPNOTSUPP;
542 }
543
devm_pm_opp_of_add_table_indexed(struct device * dev,int index)544 static inline int devm_pm_opp_of_add_table_indexed(struct device *dev, int index)
545 {
546 return -EOPNOTSUPP;
547 }
548
dev_pm_opp_of_remove_table(struct device * dev)549 static inline void dev_pm_opp_of_remove_table(struct device *dev)
550 {
551 }
552
devm_pm_opp_of_add_table(struct device * dev)553 static inline int devm_pm_opp_of_add_table(struct device *dev)
554 {
555 return -EOPNOTSUPP;
556 }
557
dev_pm_opp_of_cpumask_add_table(const struct cpumask * cpumask)558 static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
559 {
560 return -EOPNOTSUPP;
561 }
562
dev_pm_opp_of_cpumask_remove_table(const struct cpumask * cpumask)563 static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
564 {
565 }
566
dev_pm_opp_of_get_sharing_cpus(struct device * cpu_dev,struct cpumask * cpumask)567 static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
568 {
569 return -EOPNOTSUPP;
570 }
571
dev_pm_opp_of_get_opp_desc_node(struct device * dev)572 static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
573 {
574 return NULL;
575 }
576
dev_pm_opp_get_of_node(struct dev_pm_opp * opp)577 static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
578 {
579 return NULL;
580 }
581
dev_pm_opp_of_register_em(struct device * dev,struct cpumask * cpus)582 static inline int dev_pm_opp_of_register_em(struct device *dev,
583 struct cpumask *cpus)
584 {
585 return -EOPNOTSUPP;
586 }
587
dev_pm_opp_of_unregister_em(struct device * dev)588 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
589 {
590 }
591
dev_pm_opp_calc_power(struct device * dev,unsigned long * uW,unsigned long * kHz)592 static inline int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW,
593 unsigned long *kHz)
594 {
595 return -EOPNOTSUPP;
596 }
597
of_get_required_opp_performance_state(struct device_node * np,int index)598 static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
599 {
600 return -EOPNOTSUPP;
601 }
602
dev_pm_opp_of_has_required_opp(struct device * dev)603 static inline bool dev_pm_opp_of_has_required_opp(struct device *dev)
604 {
605 return false;
606 }
607
dev_pm_opp_of_find_icc_paths(struct device * dev,struct opp_table * opp_table)608 static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table)
609 {
610 return -EOPNOTSUPP;
611 }
612 #endif
613
614 /* Scope based cleanup macro for OPP reference counting */
615 DEFINE_FREE(put_opp, struct dev_pm_opp *, if (!IS_ERR_OR_NULL(_T)) dev_pm_opp_put(_T))
616
617 /* Scope based cleanup macro for OPP table reference counting */
618 DEFINE_FREE(put_opp_table, struct opp_table *, if (!IS_ERR_OR_NULL(_T)) dev_pm_opp_put_opp_table(_T))
619
620 /* OPP Configuration helpers */
621
dev_pm_opp_add(struct device * dev,unsigned long freq,unsigned long u_volt)622 static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
623 unsigned long u_volt)
624 {
625 struct dev_pm_opp_data data = {
626 .freq = freq,
627 .u_volt = u_volt,
628 };
629
630 return dev_pm_opp_add_dynamic(dev, &data);
631 }
632
633 /* Regulators helpers */
dev_pm_opp_set_regulators(struct device * dev,const char * const names[])634 static inline int dev_pm_opp_set_regulators(struct device *dev,
635 const char * const names[])
636 {
637 struct dev_pm_opp_config config = {
638 .regulator_names = names,
639 };
640
641 return dev_pm_opp_set_config(dev, &config);
642 }
643
dev_pm_opp_put_regulators(int token)644 static inline void dev_pm_opp_put_regulators(int token)
645 {
646 dev_pm_opp_clear_config(token);
647 }
648
devm_pm_opp_set_regulators(struct device * dev,const char * const names[])649 static inline int devm_pm_opp_set_regulators(struct device *dev,
650 const char * const names[])
651 {
652 struct dev_pm_opp_config config = {
653 .regulator_names = names,
654 };
655
656 return devm_pm_opp_set_config(dev, &config);
657 }
658
659 /* Supported-hw helpers */
dev_pm_opp_set_supported_hw(struct device * dev,const u32 * versions,unsigned int count)660 static inline int dev_pm_opp_set_supported_hw(struct device *dev,
661 const u32 *versions,
662 unsigned int count)
663 {
664 struct dev_pm_opp_config config = {
665 .supported_hw = versions,
666 .supported_hw_count = count,
667 };
668
669 return dev_pm_opp_set_config(dev, &config);
670 }
671
dev_pm_opp_put_supported_hw(int token)672 static inline void dev_pm_opp_put_supported_hw(int token)
673 {
674 dev_pm_opp_clear_config(token);
675 }
676
devm_pm_opp_set_supported_hw(struct device * dev,const u32 * versions,unsigned int count)677 static inline int devm_pm_opp_set_supported_hw(struct device *dev,
678 const u32 *versions,
679 unsigned int count)
680 {
681 struct dev_pm_opp_config config = {
682 .supported_hw = versions,
683 .supported_hw_count = count,
684 };
685
686 return devm_pm_opp_set_config(dev, &config);
687 }
688
689 /* clkname helpers */
dev_pm_opp_set_clkname(struct device * dev,const char * name)690 static inline int dev_pm_opp_set_clkname(struct device *dev, const char *name)
691 {
692 const char *names[] = { name, NULL };
693 struct dev_pm_opp_config config = {
694 .clk_names = names,
695 };
696
697 return dev_pm_opp_set_config(dev, &config);
698 }
699
dev_pm_opp_put_clkname(int token)700 static inline void dev_pm_opp_put_clkname(int token)
701 {
702 dev_pm_opp_clear_config(token);
703 }
704
devm_pm_opp_set_clkname(struct device * dev,const char * name)705 static inline int devm_pm_opp_set_clkname(struct device *dev, const char *name)
706 {
707 const char *names[] = { name, NULL };
708 struct dev_pm_opp_config config = {
709 .clk_names = names,
710 };
711
712 return devm_pm_opp_set_config(dev, &config);
713 }
714
715 /* config-regulators helpers */
dev_pm_opp_set_config_regulators(struct device * dev,config_regulators_t helper)716 static inline int dev_pm_opp_set_config_regulators(struct device *dev,
717 config_regulators_t helper)
718 {
719 struct dev_pm_opp_config config = {
720 .config_regulators = helper,
721 };
722
723 return dev_pm_opp_set_config(dev, &config);
724 }
725
dev_pm_opp_put_config_regulators(int token)726 static inline void dev_pm_opp_put_config_regulators(int token)
727 {
728 dev_pm_opp_clear_config(token);
729 }
730
731 /* prop-name helpers */
dev_pm_opp_set_prop_name(struct device * dev,const char * name)732 static inline int dev_pm_opp_set_prop_name(struct device *dev, const char *name)
733 {
734 struct dev_pm_opp_config config = {
735 .prop_name = name,
736 };
737
738 return dev_pm_opp_set_config(dev, &config);
739 }
740
dev_pm_opp_put_prop_name(int token)741 static inline void dev_pm_opp_put_prop_name(int token)
742 {
743 dev_pm_opp_clear_config(token);
744 }
745
dev_pm_opp_get_freq(struct dev_pm_opp * opp)746 static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
747 {
748 return dev_pm_opp_get_freq_indexed(opp, 0);
749 }
750
dev_pm_opp_set_level(struct device * dev,unsigned int level)751 static inline int dev_pm_opp_set_level(struct device *dev, unsigned int level)
752 {
753 struct dev_pm_opp *opp __free(put_opp) = dev_pm_opp_find_level_exact(dev, level);
754
755 if (IS_ERR(opp))
756 return PTR_ERR(opp);
757
758 return dev_pm_opp_set_opp(dev, opp);
759 }
760
761 #endif /* __LINUX_OPP_H__ */
762