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/err.h>
15 #include <linux/notifier.h>
23 enum dev_pm_opp_event {
24 OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE,
25 OPP_EVENT_ADJUST_VOLTAGE,
29 * struct dev_pm_opp_supply - Power supply voltage/current values
30 * @u_volt: Target voltage in microvolts corresponding to this OPP
31 * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP
32 * @u_volt_max: Maximum voltage in microvolts corresponding to this OPP
33 * @u_amp: Maximum current drawn by the device in microamperes
35 * This structure stores the voltage/current values for a single power supply.
37 struct dev_pm_opp_supply {
39 unsigned long u_volt_min;
40 unsigned long u_volt_max;
45 * struct dev_pm_opp_icc_bw - Interconnect bandwidth values
46 * @avg: Average bandwidth corresponding to this OPP (in icc units)
47 * @peak: Peak bandwidth corresponding to this OPP (in icc units)
49 * This structure stores the bandwidth values for a single interconnect path.
51 struct dev_pm_opp_icc_bw {
57 * struct dev_pm_opp_info - OPP freq/voltage/current values
58 * @rate: Target clk rate in hz
59 * @supplies: Array of voltage/current values for all power supplies
61 * This structure stores the freq/voltage/current values for a single OPP.
63 struct dev_pm_opp_info {
65 struct dev_pm_opp_supply *supplies;
69 * struct dev_pm_set_opp_data - Set OPP data
70 * @old_opp: Old OPP info
71 * @new_opp: New OPP info
72 * @regulators: Array of regulator pointers
73 * @regulator_count: Number of regulators
74 * @clk: Pointer to clk
75 * @dev: Pointer to the struct device
77 * This structure contains all information required for setting an OPP.
79 struct dev_pm_set_opp_data {
80 struct dev_pm_opp_info old_opp;
81 struct dev_pm_opp_info new_opp;
83 struct regulator **regulators;
84 unsigned int regulator_count;
89 #if defined(CONFIG_PM_OPP)
91 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
92 struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index);
93 void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
95 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
97 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
99 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
101 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
103 int dev_pm_opp_get_opp_count(struct device *dev);
104 unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
105 unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
106 unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
107 unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
109 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
112 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
115 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
116 unsigned long *freq);
117 struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
118 unsigned long u_volt);
120 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
121 unsigned long *freq);
122 void dev_pm_opp_put(struct dev_pm_opp *opp);
124 int dev_pm_opp_add(struct device *dev, unsigned long freq,
125 unsigned long u_volt);
126 void dev_pm_opp_remove(struct device *dev, unsigned long freq);
127 void dev_pm_opp_remove_all_dynamic(struct device *dev);
129 int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
130 unsigned long u_volt, unsigned long u_volt_min,
131 unsigned long u_volt_max);
133 int dev_pm_opp_enable(struct device *dev, unsigned long freq);
135 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
137 int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
138 int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
140 struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
141 void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
142 struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
143 void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
144 struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
145 void dev_pm_opp_put_regulators(struct opp_table *opp_table);
146 struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name);
147 void dev_pm_opp_put_clkname(struct opp_table *opp_table);
148 struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
149 void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table);
150 struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs);
151 void dev_pm_opp_detach_genpd(struct opp_table *opp_table);
152 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
153 int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
154 int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
155 int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
156 void dev_pm_opp_remove_table(struct device *dev);
157 void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
159 static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
161 return ERR_PTR(-ENOTSUPP);
164 static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
166 return ERR_PTR(-ENOTSUPP);
169 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
171 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
176 static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
181 static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
186 static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
191 static inline int dev_pm_opp_get_opp_count(struct device *dev)
196 static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
201 static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
206 static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
211 static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
216 static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
217 unsigned long freq, bool available)
219 return ERR_PTR(-ENOTSUPP);
222 static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
225 return ERR_PTR(-ENOTSUPP);
228 static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
231 return ERR_PTR(-ENOTSUPP);
234 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
235 unsigned long u_volt)
237 return ERR_PTR(-ENOTSUPP);
240 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
243 return ERR_PTR(-ENOTSUPP);
246 static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
248 static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
249 unsigned long u_volt)
254 static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
258 static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
263 dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
264 unsigned long u_volt, unsigned long u_volt_min,
265 unsigned long u_volt_max)
270 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
275 static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
280 static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
285 static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
290 static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
294 return ERR_PTR(-ENOTSUPP);
297 static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
299 static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
300 int (*set_opp)(struct dev_pm_set_opp_data *data))
302 return ERR_PTR(-ENOTSUPP);
305 static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {}
307 static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
309 return ERR_PTR(-ENOTSUPP);
312 static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
314 static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
316 return ERR_PTR(-ENOTSUPP);
319 static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
321 static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name)
323 return ERR_PTR(-ENOTSUPP);
326 static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {}
328 static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs)
330 return ERR_PTR(-ENOTSUPP);
333 static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {}
335 static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
340 static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
345 static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
350 static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
355 static inline void dev_pm_opp_remove_table(struct device *dev)
359 static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
363 #endif /* CONFIG_PM_OPP */
365 #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
366 int dev_pm_opp_of_add_table(struct device *dev);
367 int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
368 void dev_pm_opp_of_remove_table(struct device *dev);
369 int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
370 void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
371 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
372 struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
373 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
374 int of_get_required_opp_performance_state(struct device_node *np, int index);
375 int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
376 void dev_pm_opp_of_register_em(struct cpumask *cpus);
378 static inline int dev_pm_opp_of_add_table(struct device *dev)
383 static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
388 static inline void dev_pm_opp_of_remove_table(struct device *dev)
392 static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
397 static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
401 static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
406 static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
411 static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
416 static inline void dev_pm_opp_of_register_em(struct cpumask *cpus)
420 static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
425 static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table)
431 #endif /* __LINUX_OPP_H__ */