1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Generic OPP Interface
5 * Copyright (C) 2009-2010 Texas Instruments Incorporated.
11 #ifndef __LINUX_OPP_H__
12 #define __LINUX_OPP_H__
14 #include <linux/energy_model.h>
15 #include <linux/err.h>
16 #include <linux/notifier.h>
24 enum dev_pm_opp_event {
25 OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE,
26 OPP_EVENT_ADJUST_VOLTAGE,
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
37 * This structure stores the voltage/current/power values for a single power
40 struct dev_pm_opp_supply {
42 unsigned long u_volt_min;
43 unsigned long u_volt_max;
49 * struct dev_pm_opp_icc_bw - Interconnect bandwidth values
50 * @avg: Average bandwidth corresponding to this OPP (in icc units)
51 * @peak: Peak bandwidth corresponding to this OPP (in icc units)
53 * This structure stores the bandwidth values for a single interconnect path.
55 struct dev_pm_opp_icc_bw {
60 typedef int (*config_regulators_t)(struct device *dev,
61 struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp,
62 struct regulator **regulators, unsigned int count);
64 typedef int (*config_clks_t)(struct device *dev, struct opp_table *opp_table,
65 struct dev_pm_opp *opp, void *data, bool scaling_down);
68 * struct dev_pm_opp_config - Device OPP configuration values
69 * @clk_names: Clk names, NULL terminated array.
70 * @config_clks: Custom set clk helper.
71 * @prop_name: Name to postfix to properties.
72 * @config_regulators: Custom set regulator helper.
73 * @supported_hw: Array of hierarchy of versions to match.
74 * @supported_hw_count: Number of elements in the array.
75 * @regulator_names: Array of pointers to the names of the regulator, NULL terminated.
76 * @genpd_names: Null terminated array of pointers containing names of genpd to
78 * @virt_devs: Pointer to return the array of virtual devices.
80 * This structure contains platform specific OPP configurations for the device.
82 struct dev_pm_opp_config {
84 const char * const *clk_names;
85 config_clks_t config_clks;
86 const char *prop_name;
87 config_regulators_t config_regulators;
88 const unsigned int *supported_hw;
89 unsigned int supported_hw_count;
90 const char * const *regulator_names;
91 const char * const *genpd_names;
92 struct device ***virt_devs;
95 #if defined(CONFIG_PM_OPP)
97 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
98 void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
100 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
102 int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies);
104 unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp);
106 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
108 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
110 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
113 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
115 int dev_pm_opp_get_opp_count(struct device *dev);
116 unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
117 unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
118 unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
119 unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
121 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
124 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
125 unsigned long *freq);
127 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
129 struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
130 unsigned int *level);
132 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
133 unsigned long *freq);
135 struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
136 unsigned int *bw, int index);
138 struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
139 unsigned int *bw, int index);
141 void dev_pm_opp_put(struct dev_pm_opp *opp);
143 int dev_pm_opp_add(struct device *dev, unsigned long freq,
144 unsigned long u_volt);
145 void dev_pm_opp_remove(struct device *dev, unsigned long freq);
146 void dev_pm_opp_remove_all_dynamic(struct device *dev);
148 int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
149 unsigned long u_volt, unsigned long u_volt_min,
150 unsigned long u_volt_max);
152 int dev_pm_opp_enable(struct device *dev, unsigned long freq);
154 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
156 int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
157 int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
159 int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
160 int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
161 void dev_pm_opp_clear_config(int token);
162 int dev_pm_opp_config_clks_simple(struct device *dev,
163 struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
166 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);
167 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
168 int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
169 int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp);
170 int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
171 int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
172 void dev_pm_opp_remove_table(struct device *dev);
173 void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
174 int dev_pm_opp_sync_regulators(struct device *dev);
176 static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
178 return ERR_PTR(-EOPNOTSUPP);
181 static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
183 return ERR_PTR(-EOPNOTSUPP);
186 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
188 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
193 static inline int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies)
198 static inline unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp)
203 static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
208 static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
214 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
220 static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
225 static inline int dev_pm_opp_get_opp_count(struct device *dev)
230 static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
235 static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
240 static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
245 static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
250 static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
253 return ERR_PTR(-EOPNOTSUPP);
256 static inline struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
259 return ERR_PTR(-EOPNOTSUPP);
262 static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
263 unsigned long freq, bool available)
265 return ERR_PTR(-EOPNOTSUPP);
268 static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
271 return ERR_PTR(-EOPNOTSUPP);
274 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
277 return ERR_PTR(-EOPNOTSUPP);
280 static inline struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
281 unsigned int *bw, int index)
283 return ERR_PTR(-EOPNOTSUPP);
286 static inline struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
287 unsigned int *bw, int index)
289 return ERR_PTR(-EOPNOTSUPP);
292 static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
294 static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
295 unsigned long u_volt)
300 static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
304 static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
309 dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
310 unsigned long u_volt, unsigned long u_volt_min,
311 unsigned long u_volt_max)
316 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
321 static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
326 static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
331 static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
336 static inline int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
341 static inline int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
346 static inline void dev_pm_opp_clear_config(int token) {}
348 static inline int dev_pm_opp_config_clks_simple(struct device *dev,
349 struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
355 static inline struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table,
356 struct opp_table *dst_table, struct dev_pm_opp *src_opp)
358 return ERR_PTR(-EOPNOTSUPP);
361 static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
366 static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
371 static inline int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp)
376 static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
381 static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
386 static inline void dev_pm_opp_remove_table(struct device *dev)
390 static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
394 static inline int dev_pm_opp_sync_regulators(struct device *dev)
399 #endif /* CONFIG_PM_OPP */
401 #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
402 int dev_pm_opp_of_add_table(struct device *dev);
403 int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
404 int devm_pm_opp_of_add_table_indexed(struct device *dev, int index);
405 void dev_pm_opp_of_remove_table(struct device *dev);
406 int devm_pm_opp_of_add_table(struct device *dev);
407 int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
408 void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
409 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
410 struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
411 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
412 int of_get_required_opp_performance_state(struct device_node *np, int index);
413 int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
414 int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
415 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
417 em_dev_unregister_perf_domain(dev);
420 static inline int dev_pm_opp_of_add_table(struct device *dev)
425 static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
430 static inline int devm_pm_opp_of_add_table_indexed(struct device *dev, int index)
435 static inline void dev_pm_opp_of_remove_table(struct device *dev)
439 static inline int devm_pm_opp_of_add_table(struct device *dev)
444 static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
449 static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
453 static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
458 static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
463 static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
468 static inline int dev_pm_opp_of_register_em(struct device *dev,
469 struct cpumask *cpus)
474 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
478 static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
483 static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table)
489 /* OPP Configuration helpers */
491 /* Regulators helpers */
492 static inline int dev_pm_opp_set_regulators(struct device *dev,
493 const char * const names[])
495 struct dev_pm_opp_config config = {
496 .regulator_names = names,
499 return dev_pm_opp_set_config(dev, &config);
502 static inline void dev_pm_opp_put_regulators(int token)
504 dev_pm_opp_clear_config(token);
507 static inline int devm_pm_opp_set_regulators(struct device *dev,
508 const char * const names[])
510 struct dev_pm_opp_config config = {
511 .regulator_names = names,
514 return devm_pm_opp_set_config(dev, &config);
517 /* Supported-hw helpers */
518 static inline int dev_pm_opp_set_supported_hw(struct device *dev,
522 struct dev_pm_opp_config config = {
523 .supported_hw = versions,
524 .supported_hw_count = count,
527 return dev_pm_opp_set_config(dev, &config);
530 static inline void dev_pm_opp_put_supported_hw(int token)
532 dev_pm_opp_clear_config(token);
535 static inline int devm_pm_opp_set_supported_hw(struct device *dev,
539 struct dev_pm_opp_config config = {
540 .supported_hw = versions,
541 .supported_hw_count = count,
544 return devm_pm_opp_set_config(dev, &config);
547 /* clkname helpers */
548 static inline int dev_pm_opp_set_clkname(struct device *dev, const char *name)
550 const char *names[] = { name, NULL };
551 struct dev_pm_opp_config config = {
555 return dev_pm_opp_set_config(dev, &config);
558 static inline void dev_pm_opp_put_clkname(int token)
560 dev_pm_opp_clear_config(token);
563 static inline int devm_pm_opp_set_clkname(struct device *dev, const char *name)
565 const char *names[] = { name, NULL };
566 struct dev_pm_opp_config config = {
570 return devm_pm_opp_set_config(dev, &config);
573 /* config-regulators helpers */
574 static inline int dev_pm_opp_set_config_regulators(struct device *dev,
575 config_regulators_t helper)
577 struct dev_pm_opp_config config = {
578 .config_regulators = helper,
581 return dev_pm_opp_set_config(dev, &config);
584 static inline void dev_pm_opp_put_config_regulators(int token)
586 dev_pm_opp_clear_config(token);
590 static inline int dev_pm_opp_attach_genpd(struct device *dev,
591 const char * const *names,
592 struct device ***virt_devs)
594 struct dev_pm_opp_config config = {
595 .genpd_names = names,
596 .virt_devs = virt_devs,
599 return dev_pm_opp_set_config(dev, &config);
602 static inline void dev_pm_opp_detach_genpd(int token)
604 dev_pm_opp_clear_config(token);
607 static inline int devm_pm_opp_attach_genpd(struct device *dev,
608 const char * const *names,
609 struct device ***virt_devs)
611 struct dev_pm_opp_config config = {
612 .genpd_names = names,
613 .virt_devs = virt_devs,
616 return devm_pm_opp_set_config(dev, &config);
619 /* prop-name helpers */
620 static inline int dev_pm_opp_set_prop_name(struct device *dev, const char *name)
622 struct dev_pm_opp_config config = {
626 return dev_pm_opp_set_config(dev, &config);
629 static inline void dev_pm_opp_put_prop_name(int token)
631 dev_pm_opp_clear_config(token);
634 #endif /* __LINUX_OPP_H__ */