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