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 {
61 * struct dev_pm_opp_info - OPP freq/voltage/current values
62 * @rate: Target clk rate in hz
63 * @supplies: Array of voltage/current values for all power supplies
65 * This structure stores the freq/voltage/current values for a single OPP.
67 struct dev_pm_opp_info {
69 struct dev_pm_opp_supply *supplies;
73 * struct dev_pm_set_opp_data - Set OPP data
74 * @old_opp: Old OPP info
75 * @new_opp: New OPP info
76 * @regulators: Array of regulator pointers
77 * @regulator_count: Number of regulators
78 * @clk: Pointer to clk
79 * @dev: Pointer to the struct device
81 * This structure contains all information required for setting an OPP.
83 struct dev_pm_set_opp_data {
84 struct dev_pm_opp_info old_opp;
85 struct dev_pm_opp_info new_opp;
87 struct regulator **regulators;
88 unsigned int regulator_count;
93 #if defined(CONFIG_PM_OPP)
95 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
96 void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
98 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
100 unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp);
102 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
104 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
106 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
109 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
111 int dev_pm_opp_get_opp_count(struct device *dev);
112 unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
113 unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
114 unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
115 unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
117 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
120 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
121 unsigned long *freq);
122 struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
123 unsigned long u_volt);
125 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
127 struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
128 unsigned int *level);
130 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
131 unsigned long *freq);
133 struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
134 unsigned int *bw, int index);
136 struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
137 unsigned int *bw, int index);
139 void dev_pm_opp_put(struct dev_pm_opp *opp);
141 int dev_pm_opp_add(struct device *dev, unsigned long freq,
142 unsigned long u_volt);
143 void dev_pm_opp_remove(struct device *dev, unsigned long freq);
144 void dev_pm_opp_remove_all_dynamic(struct device *dev);
146 int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
147 unsigned long u_volt, unsigned long u_volt_min,
148 unsigned long u_volt_max);
150 int dev_pm_opp_enable(struct device *dev, unsigned long freq);
152 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
154 int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
155 int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
157 struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
158 void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
159 int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
160 struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
161 void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
162 struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
163 void dev_pm_opp_put_regulators(struct opp_table *opp_table);
164 int devm_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
165 struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name);
166 void dev_pm_opp_put_clkname(struct opp_table *opp_table);
167 int devm_pm_opp_set_clkname(struct device *dev, const char *name);
168 struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
169 void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table);
170 int devm_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
171 struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char * const *names, struct device ***virt_devs);
172 void dev_pm_opp_detach_genpd(struct opp_table *opp_table);
173 int devm_pm_opp_attach_genpd(struct device *dev, const char * const *names, struct device ***virt_devs);
174 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);
175 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
176 int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
177 int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp);
178 int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
179 int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
180 void dev_pm_opp_remove_table(struct device *dev);
181 void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
182 int dev_pm_opp_sync_regulators(struct device *dev);
184 static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
186 return ERR_PTR(-EOPNOTSUPP);
189 static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
191 return ERR_PTR(-EOPNOTSUPP);
194 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
196 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
201 static inline unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp)
206 static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
211 static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
217 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
223 static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
228 static inline int dev_pm_opp_get_opp_count(struct device *dev)
233 static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
238 static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
243 static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
248 static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
253 static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
256 return ERR_PTR(-EOPNOTSUPP);
259 static inline struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
262 return ERR_PTR(-EOPNOTSUPP);
265 static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
266 unsigned long freq, bool available)
268 return ERR_PTR(-EOPNOTSUPP);
271 static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
274 return ERR_PTR(-EOPNOTSUPP);
277 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
278 unsigned long u_volt)
280 return ERR_PTR(-EOPNOTSUPP);
283 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
286 return ERR_PTR(-EOPNOTSUPP);
289 static inline struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
290 unsigned int *bw, int index)
292 return ERR_PTR(-EOPNOTSUPP);
295 static inline struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
296 unsigned int *bw, int index)
298 return ERR_PTR(-EOPNOTSUPP);
301 static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
303 static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
304 unsigned long u_volt)
309 static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
313 static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
318 dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
319 unsigned long u_volt, unsigned long u_volt_min,
320 unsigned long u_volt_max)
325 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
330 static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
335 static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
340 static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
345 static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
349 return ERR_PTR(-EOPNOTSUPP);
352 static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
354 static inline int devm_pm_opp_set_supported_hw(struct device *dev,
361 static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
362 int (*set_opp)(struct dev_pm_set_opp_data *data))
364 return ERR_PTR(-EOPNOTSUPP);
367 static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {}
369 static inline int devm_pm_opp_register_set_opp_helper(struct device *dev,
370 int (*set_opp)(struct dev_pm_set_opp_data *data))
375 static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
377 return ERR_PTR(-EOPNOTSUPP);
380 static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
382 static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
384 return ERR_PTR(-EOPNOTSUPP);
387 static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
389 static inline int devm_pm_opp_set_regulators(struct device *dev,
390 const char * const names[],
396 static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name)
398 return ERR_PTR(-EOPNOTSUPP);
401 static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {}
403 static inline int devm_pm_opp_set_clkname(struct device *dev, const char *name)
408 static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char * const *names, struct device ***virt_devs)
410 return ERR_PTR(-EOPNOTSUPP);
413 static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {}
415 static inline int devm_pm_opp_attach_genpd(struct device *dev,
416 const char * const *names,
417 struct device ***virt_devs)
422 static inline struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table,
423 struct opp_table *dst_table, struct dev_pm_opp *src_opp)
425 return ERR_PTR(-EOPNOTSUPP);
428 static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
433 static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
438 static inline int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp)
443 static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
448 static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
453 static inline void dev_pm_opp_remove_table(struct device *dev)
457 static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
461 static inline int dev_pm_opp_sync_regulators(struct device *dev)
466 #endif /* CONFIG_PM_OPP */
468 #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
469 int dev_pm_opp_of_add_table(struct device *dev);
470 int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
471 int devm_pm_opp_of_add_table_indexed(struct device *dev, int index);
472 int dev_pm_opp_of_add_table_noclk(struct device *dev, int index);
473 int devm_pm_opp_of_add_table_noclk(struct device *dev, int index);
474 void dev_pm_opp_of_remove_table(struct device *dev);
475 int devm_pm_opp_of_add_table(struct device *dev);
476 int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
477 void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
478 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
479 struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
480 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
481 int of_get_required_opp_performance_state(struct device_node *np, int index);
482 int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
483 int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
484 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
486 em_dev_unregister_perf_domain(dev);
489 static inline int dev_pm_opp_of_add_table(struct device *dev)
494 static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
499 static inline int devm_pm_opp_of_add_table_indexed(struct device *dev, int index)
504 static inline int dev_pm_opp_of_add_table_noclk(struct device *dev, int index)
509 static inline int devm_pm_opp_of_add_table_noclk(struct device *dev, int index)
514 static inline void dev_pm_opp_of_remove_table(struct device *dev)
518 static inline int devm_pm_opp_of_add_table(struct device *dev)
523 static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
528 static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
532 static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
537 static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
542 static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
547 static inline int dev_pm_opp_of_register_em(struct device *dev,
548 struct cpumask *cpus)
553 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
557 static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
562 static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table)
568 #endif /* __LINUX_OPP_H__ */