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
36 * This structure stores the voltage/current values for a single power supply.
38 struct dev_pm_opp_supply {
40 unsigned long u_volt_min;
41 unsigned long u_volt_max;
46 * struct dev_pm_opp_icc_bw - Interconnect bandwidth values
47 * @avg: Average bandwidth corresponding to this OPP (in icc units)
48 * @peak: Peak bandwidth corresponding to this OPP (in icc units)
50 * This structure stores the bandwidth values for a single interconnect path.
52 struct dev_pm_opp_icc_bw {
58 * struct dev_pm_opp_info - OPP freq/voltage/current values
59 * @rate: Target clk rate in hz
60 * @supplies: Array of voltage/current values for all power supplies
62 * This structure stores the freq/voltage/current values for a single OPP.
64 struct dev_pm_opp_info {
66 struct dev_pm_opp_supply *supplies;
70 * struct dev_pm_set_opp_data - Set OPP data
71 * @old_opp: Old OPP info
72 * @new_opp: New OPP info
73 * @regulators: Array of regulator pointers
74 * @regulator_count: Number of regulators
75 * @clk: Pointer to clk
76 * @dev: Pointer to the struct device
78 * This structure contains all information required for setting an OPP.
80 struct dev_pm_set_opp_data {
81 struct dev_pm_opp_info old_opp;
82 struct dev_pm_opp_info new_opp;
84 struct regulator **regulators;
85 unsigned int regulator_count;
90 #if defined(CONFIG_PM_OPP)
92 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
93 struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index);
94 void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
96 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
98 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
100 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
102 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
104 int dev_pm_opp_get_opp_count(struct device *dev);
105 unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
106 unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
107 unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
108 unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
110 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
113 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
116 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
117 unsigned long *freq);
118 struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
119 unsigned long u_volt);
121 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
122 unsigned long *freq);
123 void dev_pm_opp_put(struct dev_pm_opp *opp);
125 int dev_pm_opp_add(struct device *dev, unsigned long freq,
126 unsigned long u_volt);
127 void dev_pm_opp_remove(struct device *dev, unsigned long freq);
128 void dev_pm_opp_remove_all_dynamic(struct device *dev);
130 int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
131 unsigned long u_volt, unsigned long u_volt_min,
132 unsigned long u_volt_max);
134 int dev_pm_opp_enable(struct device *dev, unsigned long freq);
136 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
138 int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
139 int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
141 struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
142 void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
143 struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
144 void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
145 struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
146 void dev_pm_opp_put_regulators(struct opp_table *opp_table);
147 struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name);
148 void dev_pm_opp_put_clkname(struct opp_table *opp_table);
149 struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
150 void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table);
151 struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs);
152 void dev_pm_opp_detach_genpd(struct opp_table *opp_table);
153 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
154 int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
155 int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
156 int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
157 void dev_pm_opp_remove_table(struct device *dev);
158 void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
160 static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
162 return ERR_PTR(-ENOTSUPP);
165 static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
167 return ERR_PTR(-ENOTSUPP);
170 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
172 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
177 static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
182 static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
187 static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
192 static inline int dev_pm_opp_get_opp_count(struct device *dev)
197 static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
202 static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
207 static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
212 static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
217 static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
218 unsigned long freq, bool available)
220 return ERR_PTR(-ENOTSUPP);
223 static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
226 return ERR_PTR(-ENOTSUPP);
229 static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
232 return ERR_PTR(-ENOTSUPP);
235 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
236 unsigned long u_volt)
238 return ERR_PTR(-ENOTSUPP);
241 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
244 return ERR_PTR(-ENOTSUPP);
247 static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
249 static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
250 unsigned long u_volt)
255 static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
259 static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
264 dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
265 unsigned long u_volt, unsigned long u_volt_min,
266 unsigned long u_volt_max)
271 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
276 static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
281 static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
286 static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
291 static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
295 return ERR_PTR(-ENOTSUPP);
298 static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
300 static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
301 int (*set_opp)(struct dev_pm_set_opp_data *data))
303 return ERR_PTR(-ENOTSUPP);
306 static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {}
308 static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
310 return ERR_PTR(-ENOTSUPP);
313 static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
315 static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
317 return ERR_PTR(-ENOTSUPP);
320 static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
322 static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name)
324 return ERR_PTR(-ENOTSUPP);
327 static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {}
329 static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs)
331 return ERR_PTR(-ENOTSUPP);
334 static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {}
336 static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
341 static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
346 static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
351 static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
356 static inline void dev_pm_opp_remove_table(struct device *dev)
360 static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
364 #endif /* CONFIG_PM_OPP */
366 #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
367 int dev_pm_opp_of_add_table(struct device *dev);
368 int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
369 void dev_pm_opp_of_remove_table(struct device *dev);
370 int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
371 void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
372 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
373 struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
374 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
375 int of_get_required_opp_performance_state(struct device_node *np, int index);
376 int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
377 int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
378 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
380 em_dev_unregister_perf_domain(dev);
383 static inline int dev_pm_opp_of_add_table(struct device *dev)
388 static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
393 static inline void dev_pm_opp_of_remove_table(struct device *dev)
397 static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
402 static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
406 static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
411 static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
416 static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
421 static inline int dev_pm_opp_of_register_em(struct device *dev,
422 struct cpumask *cpus)
427 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
431 static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
436 static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table)
442 #endif /* __LINUX_OPP_H__ */