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
19struct clk;
20struct cpufreq_frequency_table;
21struct regulator;
22struct dev_pm_opp;
23struct device;
24struct opp_table;
25
26enum 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 */
42struct 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
50typedef 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
54typedef 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 */
71struct 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 */
94struct 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 */
114struct dev_pm_opp_key {
115 unsigned long freq;
116 unsigned int level;
117 u32 bw;
118};
119
120#if defined(CONFIG_PM_OPP)
121
122struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
123struct opp_table *dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table);
124void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
125
126unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index);
127
128unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
129
130int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies);
131
132unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp);
133
134unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index);
135
136unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
137
138unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
139 unsigned int index);
140
141bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
142
143int dev_pm_opp_get_opp_count(struct device *dev);
144unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
145unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
146unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
147unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
148
149struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
150 unsigned long freq,
151 bool available);
152
153struct dev_pm_opp *dev_pm_opp_find_key_exact(struct device *dev,
154 struct dev_pm_opp_key *key,
155 bool available);
156
157struct dev_pm_opp *
158dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq,
159 u32 index, bool available);
160
161struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
162 unsigned long *freq);
163
164struct dev_pm_opp *dev_pm_opp_find_freq_floor_indexed(struct device *dev,
165 unsigned long *freq, u32 index);
166
167struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
168 unsigned long *freq);
169
170struct dev_pm_opp *dev_pm_opp_find_freq_ceil_indexed(struct device *dev,
171 unsigned long *freq, u32 index);
172
173struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
174 unsigned int level);
175
176struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
177 unsigned int *level);
178
179struct dev_pm_opp *dev_pm_opp_find_level_floor(struct device *dev,
180 unsigned int *level);
181
182struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
183 unsigned int *bw, int index);
184
185struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
186 unsigned int *bw, int index);
187
188struct dev_pm_opp *dev_pm_opp_get(struct dev_pm_opp *opp);
189void dev_pm_opp_put(struct dev_pm_opp *opp);
190
191int dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp);
192
193void dev_pm_opp_remove(struct device *dev, unsigned long freq);
194void dev_pm_opp_remove_all_dynamic(struct device *dev);
195
196int 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
200int dev_pm_opp_enable(struct device *dev, unsigned long freq);
201
202int dev_pm_opp_disable(struct device *dev, unsigned long freq);
203
204int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
205int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
206
207int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
208int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
209void dev_pm_opp_clear_config(int token);
210int 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
214struct 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);
215int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
216int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
217int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp);
218int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
219int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
220void dev_pm_opp_remove_table(struct device *dev);
221void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
222int dev_pm_opp_sync_regulators(struct device *dev);
223
224#else
225static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
226{
227 return ERR_PTR(error: -EOPNOTSUPP);
228}
229
230static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
231{
232 return ERR_PTR(error: -EOPNOTSUPP);
233}
234
235static inline struct opp_table *dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table)
236{
237 return opp_table;
238}
239
240static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
241
242static inline unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index)
243{
244 return 0;
245}
246
247static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
248{
249 return 0;
250}
251
252static inline int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies)
253{
254 return -EOPNOTSUPP;
255}
256
257static inline unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp)
258{
259 return 0;
260}
261
262static inline unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index)
263{
264 return 0;
265}
266
267static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
268{
269 return 0;
270}
271
272static inline
273unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
274 unsigned int index)
275{
276 return 0;
277}
278
279static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
280{
281 return false;
282}
283
284static inline int dev_pm_opp_get_opp_count(struct device *dev)
285{
286 return 0;
287}
288
289static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
290{
291 return 0;
292}
293
294static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
295{
296 return 0;
297}
298
299static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
300{
301 return 0;
302}
303
304static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
305{
306 return 0;
307}
308
309static 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(error: -EOPNOTSUPP);
313}
314
315static 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(error: -EOPNOTSUPP);
320}
321
322static inline struct dev_pm_opp *
323dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq,
324 u32 index, bool available)
325{
326 return ERR_PTR(error: -EOPNOTSUPP);
327}
328
329static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
330 unsigned long *freq)
331{
332 return ERR_PTR(error: -EOPNOTSUPP);
333}
334
335static inline struct dev_pm_opp *
336dev_pm_opp_find_freq_floor_indexed(struct device *dev, unsigned long *freq, u32 index)
337{
338 return ERR_PTR(error: -EOPNOTSUPP);
339}
340
341static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
342 unsigned long *freq)
343{
344 return ERR_PTR(error: -EOPNOTSUPP);
345}
346
347static inline struct dev_pm_opp *
348dev_pm_opp_find_freq_ceil_indexed(struct device *dev, unsigned long *freq, u32 index)
349{
350 return ERR_PTR(error: -EOPNOTSUPP);
351}
352
353static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
354 unsigned int level)
355{
356 return ERR_PTR(error: -EOPNOTSUPP);
357}
358
359static inline struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
360 unsigned int *level)
361{
362 return ERR_PTR(error: -EOPNOTSUPP);
363}
364
365static inline struct dev_pm_opp *dev_pm_opp_find_level_floor(struct device *dev,
366 unsigned int *level)
367{
368 return ERR_PTR(error: -EOPNOTSUPP);
369}
370
371static 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(error: -EOPNOTSUPP);
375}
376
377static 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(error: -EOPNOTSUPP);
381}
382
383static inline struct dev_pm_opp *dev_pm_opp_get(struct dev_pm_opp *opp)
384{
385 return opp;
386}
387
388static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
389
390static inline int
391dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp)
392{
393 return -EOPNOTSUPP;
394}
395
396static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
397{
398}
399
400static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
401{
402}
403
404static inline int
405dev_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
412static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
413{
414 return 0;
415}
416
417static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
418{
419 return 0;
420}
421
422static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
423{
424 return -EOPNOTSUPP;
425}
426
427static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
428{
429 return -EOPNOTSUPP;
430}
431
432static inline int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
433{
434 return -EOPNOTSUPP;
435}
436
437static inline int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
438{
439 return -EOPNOTSUPP;
440}
441
442static inline void dev_pm_opp_clear_config(int token) {}
443
444static 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
451static 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(error: -EOPNOTSUPP);
455}
456
457static 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
462static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
463{
464 return -EOPNOTSUPP;
465}
466
467static inline int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp)
468{
469 return -EOPNOTSUPP;
470}
471
472static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
473{
474 return -EOPNOTSUPP;
475}
476
477static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
478{
479 return -EINVAL;
480}
481
482static inline void dev_pm_opp_remove_table(struct device *dev)
483{
484}
485
486static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
487{
488}
489
490static 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)
498int dev_pm_opp_init_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table);
499void dev_pm_opp_free_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table);
500#else
501static inline int dev_pm_opp_init_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table)
502{
503 return -EINVAL;
504}
505
506static 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)
513int dev_pm_opp_of_add_table(struct device *dev);
514int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
515int devm_pm_opp_of_add_table_indexed(struct device *dev, int index);
516void dev_pm_opp_of_remove_table(struct device *dev);
517int devm_pm_opp_of_add_table(struct device *dev);
518int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
519void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
520int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
521struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
522struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
523int of_get_required_opp_performance_state(struct device_node *np, int index);
524bool dev_pm_opp_of_has_required_opp(struct device *dev);
525int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
526int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
527int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW,
528 unsigned long *kHz);
529static inline void dev_pm_opp_of_unregister_em(struct device *dev)
530{
531 em_dev_unregister_perf_domain(dev);
532}
533#else
534static inline int dev_pm_opp_of_add_table(struct device *dev)
535{
536 return -EOPNOTSUPP;
537}
538
539static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
540{
541 return -EOPNOTSUPP;
542}
543
544static inline int devm_pm_opp_of_add_table_indexed(struct device *dev, int index)
545{
546 return -EOPNOTSUPP;
547}
548
549static inline void dev_pm_opp_of_remove_table(struct device *dev)
550{
551}
552
553static inline int devm_pm_opp_of_add_table(struct device *dev)
554{
555 return -EOPNOTSUPP;
556}
557
558static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
559{
560 return -EOPNOTSUPP;
561}
562
563static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
564{
565}
566
567static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
568{
569 return -EOPNOTSUPP;
570}
571
572static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
573{
574 return NULL;
575}
576
577static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
578{
579 return NULL;
580}
581
582static inline int dev_pm_opp_of_register_em(struct device *dev,
583 struct cpumask *cpus)
584{
585 return -EOPNOTSUPP;
586}
587
588static inline void dev_pm_opp_of_unregister_em(struct device *dev)
589{
590}
591
592static inline int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW,
593 unsigned long *kHz)
594{
595 return -EOPNOTSUPP;
596}
597
598static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
599{
600 return -EOPNOTSUPP;
601}
602
603static inline bool dev_pm_opp_of_has_required_opp(struct device *dev)
604{
605 return false;
606}
607
608static 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 */
615DEFINE_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 */
618DEFINE_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
622static 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, opp: &data);
631}
632
633/* Regulators helpers */
634static 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: &config);
642}
643
644static inline void dev_pm_opp_put_regulators(int token)
645{
646 dev_pm_opp_clear_config(token);
647}
648
649static 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: &config);
657}
658
659/* Supported-hw helpers */
660static 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: &config);
670}
671
672static inline void dev_pm_opp_put_supported_hw(int token)
673{
674 dev_pm_opp_clear_config(token);
675}
676
677static 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: &config);
687}
688
689/* clkname helpers */
690static 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: &config);
698}
699
700static inline void dev_pm_opp_put_clkname(int token)
701{
702 dev_pm_opp_clear_config(token);
703}
704
705static 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: &config);
713}
714
715/* config-regulators helpers */
716static 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: &config);
724}
725
726static inline void dev_pm_opp_put_config_regulators(int token)
727{
728 dev_pm_opp_clear_config(token);
729}
730
731/* prop-name helpers */
732static 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: &config);
739}
740
741static inline void dev_pm_opp_put_prop_name(int token)
742{
743 dev_pm_opp_clear_config(token);
744}
745
746static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
747{
748 return dev_pm_opp_get_freq_indexed(opp, index: 0);
749}
750
751static 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(ptr: opp))
756 return PTR_ERR(ptr: opp);
757
758 return dev_pm_opp_set_opp(dev, opp);
759}
760
761#endif /* __LINUX_OPP_H__ */
762