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_info - OPP freq/voltage/current values
46 * @rate: Target clk rate in hz
47 * @supplies: Array of voltage/current values for all power supplies
49 * This structure stores the freq/voltage/current values for a single OPP.
51 struct dev_pm_opp_info {
53 struct dev_pm_opp_supply *supplies;
57 * struct dev_pm_set_opp_data - Set OPP data
58 * @old_opp: Old OPP info
59 * @new_opp: New OPP info
60 * @regulators: Array of regulator pointers
61 * @regulator_count: Number of regulators
62 * @clk: Pointer to clk
63 * @dev: Pointer to the struct device
65 * This structure contains all information required for setting an OPP.
67 struct dev_pm_set_opp_data {
68 struct dev_pm_opp_info old_opp;
69 struct dev_pm_opp_info new_opp;
71 struct regulator **regulators;
72 unsigned int regulator_count;
77 #if defined(CONFIG_PM_OPP)
79 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
80 struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index);
81 void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
83 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
85 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
87 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
89 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
91 int dev_pm_opp_get_opp_count(struct device *dev);
92 unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
93 unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
94 unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
95 unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
97 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
100 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
103 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
104 unsigned long *freq);
105 struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
106 unsigned long u_volt);
108 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
109 unsigned long *freq);
110 void dev_pm_opp_put(struct dev_pm_opp *opp);
112 int dev_pm_opp_add(struct device *dev, unsigned long freq,
113 unsigned long u_volt);
114 void dev_pm_opp_remove(struct device *dev, unsigned long freq);
115 void dev_pm_opp_remove_all_dynamic(struct device *dev);
117 int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
118 unsigned long u_volt, unsigned long u_volt_min,
119 unsigned long u_volt_max);
121 int dev_pm_opp_enable(struct device *dev, unsigned long freq);
123 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
125 int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
126 int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
128 struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
129 void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
130 struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
131 void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
132 struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
133 void dev_pm_opp_put_regulators(struct opp_table *opp_table);
134 struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name);
135 void dev_pm_opp_put_clkname(struct opp_table *opp_table);
136 struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
137 void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table);
138 struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs);
139 void dev_pm_opp_detach_genpd(struct opp_table *opp_table);
140 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
141 int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
142 int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
143 int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
144 void dev_pm_opp_remove_table(struct device *dev);
145 void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
147 static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
149 return ERR_PTR(-ENOTSUPP);
152 static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
154 return ERR_PTR(-ENOTSUPP);
157 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
159 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
164 static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
169 static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
174 static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
179 static inline int dev_pm_opp_get_opp_count(struct device *dev)
184 static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
189 static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
194 static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
199 static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
204 static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
205 unsigned long freq, bool available)
207 return ERR_PTR(-ENOTSUPP);
210 static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
213 return ERR_PTR(-ENOTSUPP);
216 static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
219 return ERR_PTR(-ENOTSUPP);
222 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
223 unsigned long u_volt)
225 return ERR_PTR(-ENOTSUPP);
228 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
231 return ERR_PTR(-ENOTSUPP);
234 static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
236 static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
237 unsigned long u_volt)
242 static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
246 static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
251 dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
252 unsigned long u_volt, unsigned long u_volt_min,
253 unsigned long u_volt_max)
258 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
263 static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
268 static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
273 static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
278 static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
282 return ERR_PTR(-ENOTSUPP);
285 static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
287 static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
288 int (*set_opp)(struct dev_pm_set_opp_data *data))
290 return ERR_PTR(-ENOTSUPP);
293 static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {}
295 static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
297 return ERR_PTR(-ENOTSUPP);
300 static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
302 static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
304 return ERR_PTR(-ENOTSUPP);
307 static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
309 static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name)
311 return ERR_PTR(-ENOTSUPP);
314 static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {}
316 static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs)
318 return ERR_PTR(-ENOTSUPP);
321 static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {}
323 static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
328 static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
333 static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
338 static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
343 static inline void dev_pm_opp_remove_table(struct device *dev)
347 static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
351 #endif /* CONFIG_PM_OPP */
353 #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
354 int dev_pm_opp_of_add_table(struct device *dev);
355 int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
356 void dev_pm_opp_of_remove_table(struct device *dev);
357 int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
358 void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
359 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
360 struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
361 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
362 int of_get_required_opp_performance_state(struct device_node *np, int index);
363 void dev_pm_opp_of_register_em(struct cpumask *cpus);
365 static inline int dev_pm_opp_of_add_table(struct device *dev)
370 static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
375 static inline void dev_pm_opp_of_remove_table(struct device *dev)
379 static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
384 static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
388 static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
393 static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
398 static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
403 static inline void dev_pm_opp_of_register_em(struct cpumask *cpus)
407 static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
413 #endif /* __LINUX_OPP_H__ */