Merge branch 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[sfrench/cifs-2.6.git] / include / linux / pm_opp.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Generic OPP Interface
4  *
5  * Copyright (C) 2009-2010 Texas Instruments Incorporated.
6  *      Nishanth Menon
7  *      Romit Dasgupta
8  *      Kevin Hilman
9  */
10
11 #ifndef __LINUX_OPP_H__
12 #define __LINUX_OPP_H__
13
14 #include <linux/err.h>
15 #include <linux/notifier.h>
16
17 struct clk;
18 struct regulator;
19 struct dev_pm_opp;
20 struct device;
21 struct opp_table;
22
23 enum dev_pm_opp_event {
24         OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE,
25         OPP_EVENT_ADJUST_VOLTAGE,
26 };
27
28 /**
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
34  *
35  * This structure stores the voltage/current values for a single power supply.
36  */
37 struct dev_pm_opp_supply {
38         unsigned long u_volt;
39         unsigned long u_volt_min;
40         unsigned long u_volt_max;
41         unsigned long u_amp;
42 };
43
44 /**
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
48  *
49  * This structure stores the freq/voltage/current values for a single OPP.
50  */
51 struct dev_pm_opp_info {
52         unsigned long rate;
53         struct dev_pm_opp_supply *supplies;
54 };
55
56 /**
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
64  *
65  * This structure contains all information required for setting an OPP.
66  */
67 struct dev_pm_set_opp_data {
68         struct dev_pm_opp_info old_opp;
69         struct dev_pm_opp_info new_opp;
70
71         struct regulator **regulators;
72         unsigned int regulator_count;
73         struct clk *clk;
74         struct device *dev;
75 };
76
77 #if defined(CONFIG_PM_OPP)
78
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);
82
83 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
84
85 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
86
87 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
88
89 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
90
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);
96
97 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
98                                               unsigned long freq,
99                                               bool available);
100 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
101                                                unsigned int level);
102
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);
107
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);
111
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);
116
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);
120
121 int dev_pm_opp_enable(struct device *dev, unsigned long freq);
122
123 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
124
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);
127
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);
146 #else
147 static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
148 {
149         return ERR_PTR(-ENOTSUPP);
150 }
151
152 static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
153 {
154         return ERR_PTR(-ENOTSUPP);
155 }
156
157 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
158
159 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
160 {
161         return 0;
162 }
163
164 static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
165 {
166         return 0;
167 }
168
169 static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
170 {
171         return 0;
172 }
173
174 static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
175 {
176         return false;
177 }
178
179 static inline int dev_pm_opp_get_opp_count(struct device *dev)
180 {
181         return 0;
182 }
183
184 static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
185 {
186         return 0;
187 }
188
189 static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
190 {
191         return 0;
192 }
193
194 static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
195 {
196         return 0;
197 }
198
199 static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
200 {
201         return 0;
202 }
203
204 static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
205                                         unsigned long freq, bool available)
206 {
207         return ERR_PTR(-ENOTSUPP);
208 }
209
210 static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
211                                         unsigned int level)
212 {
213         return ERR_PTR(-ENOTSUPP);
214 }
215
216 static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
217                                         unsigned long *freq)
218 {
219         return ERR_PTR(-ENOTSUPP);
220 }
221
222 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
223                                         unsigned long u_volt)
224 {
225         return ERR_PTR(-ENOTSUPP);
226 }
227
228 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
229                                         unsigned long *freq)
230 {
231         return ERR_PTR(-ENOTSUPP);
232 }
233
234 static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
235
236 static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
237                                         unsigned long u_volt)
238 {
239         return -ENOTSUPP;
240 }
241
242 static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
243 {
244 }
245
246 static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
247 {
248 }
249
250 static inline int
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)
254 {
255         return 0;
256 }
257
258 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
259 {
260         return 0;
261 }
262
263 static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
264 {
265         return 0;
266 }
267
268 static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
269 {
270         return -ENOTSUPP;
271 }
272
273 static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
274 {
275         return -ENOTSUPP;
276 }
277
278 static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
279                                                             const u32 *versions,
280                                                             unsigned int count)
281 {
282         return ERR_PTR(-ENOTSUPP);
283 }
284
285 static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
286
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))
289 {
290         return ERR_PTR(-ENOTSUPP);
291 }
292
293 static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {}
294
295 static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
296 {
297         return ERR_PTR(-ENOTSUPP);
298 }
299
300 static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
301
302 static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
303 {
304         return ERR_PTR(-ENOTSUPP);
305 }
306
307 static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
308
309 static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name)
310 {
311         return ERR_PTR(-ENOTSUPP);
312 }
313
314 static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {}
315
316 static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs)
317 {
318         return ERR_PTR(-ENOTSUPP);
319 }
320
321 static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {}
322
323 static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
324 {
325         return -ENOTSUPP;
326 }
327
328 static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
329 {
330         return -ENOTSUPP;
331 }
332
333 static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
334 {
335         return -ENOTSUPP;
336 }
337
338 static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
339 {
340         return -EINVAL;
341 }
342
343 static inline void dev_pm_opp_remove_table(struct device *dev)
344 {
345 }
346
347 static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
348 {
349 }
350
351 #endif          /* CONFIG_PM_OPP */
352
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);
364 #else
365 static inline int dev_pm_opp_of_add_table(struct device *dev)
366 {
367         return -ENOTSUPP;
368 }
369
370 static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
371 {
372         return -ENOTSUPP;
373 }
374
375 static inline void dev_pm_opp_of_remove_table(struct device *dev)
376 {
377 }
378
379 static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
380 {
381         return -ENOTSUPP;
382 }
383
384 static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
385 {
386 }
387
388 static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
389 {
390         return -ENOTSUPP;
391 }
392
393 static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
394 {
395         return NULL;
396 }
397
398 static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
399 {
400         return NULL;
401 }
402
403 static inline void dev_pm_opp_of_register_em(struct cpumask *cpus)
404 {
405 }
406
407 static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
408 {
409         return -ENOTSUPP;
410 }
411 #endif
412
413 #endif          /* __LINUX_OPP_H__ */