Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[linux-block.git] / include / linux / pm_opp.h
CommitLineData
d2912cb1 1/* SPDX-License-Identifier: GPL-2.0-only */
e1f60b29
NM
2/*
3 * Generic OPP Interface
4 *
5 * Copyright (C) 2009-2010 Texas Instruments Incorporated.
6 * Nishanth Menon
7 * Romit Dasgupta
8 * Kevin Hilman
e1f60b29
NM
9 */
10
11#ifndef __LINUX_OPP_H__
12#define __LINUX_OPP_H__
13
0e0ffa85 14#include <linux/energy_model.h>
e1f60b29 15#include <linux/err.h>
03ca370f 16#include <linux/notifier.h>
e1f60b29 17
94735585
VK
18struct clk;
19struct regulator;
47d43ba7 20struct dev_pm_opp;
313162d0 21struct device;
91291d9a 22struct opp_table;
e1f60b29 23
47d43ba7 24enum dev_pm_opp_event {
129eec55 25 OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE,
25cb20a2 26 OPP_EVENT_ADJUST_VOLTAGE,
03ca370f
MH
27};
28
0f0fe7e0
VK
29/**
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 *
36 * This structure stores the voltage/current values for a single power supply.
37 */
38struct dev_pm_opp_supply {
39 unsigned long u_volt;
40 unsigned long u_volt_min;
41 unsigned long u_volt_max;
42 unsigned long u_amp;
43};
44
6d3f922c
GD
45/**
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)
49 *
50 * This structure stores the bandwidth values for a single interconnect path.
51 */
52struct dev_pm_opp_icc_bw {
53 u32 avg;
54 u32 peak;
55};
56
94735585
VK
57/**
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
61 *
62 * This structure stores the freq/voltage/current values for a single OPP.
63 */
64struct dev_pm_opp_info {
65 unsigned long rate;
66 struct dev_pm_opp_supply *supplies;
67};
68
69/**
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
77 *
78 * This structure contains all information required for setting an OPP.
79 */
80struct dev_pm_set_opp_data {
81 struct dev_pm_opp_info old_opp;
82 struct dev_pm_opp_info new_opp;
83
84 struct regulator **regulators;
85 unsigned int regulator_count;
86 struct clk *clk;
87 struct device *dev;
88};
89
e1f60b29
NM
90#if defined(CONFIG_PM_OPP)
91
f067a982 92struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
eb7c8743 93struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index);
f067a982
VK
94void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
95
47d43ba7 96unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
e1f60b29 97
47d43ba7 98unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
e1f60b29 99
5b93ac54
RN
100unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
101
19445b25
BZ
102bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
103
5d4879cd 104int dev_pm_opp_get_opp_count(struct device *dev);
3ca9bb33 105unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
655c9df9 106unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
21743447 107unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
3aa26a3b 108unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
e1f60b29 109
47d43ba7
NM
110struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
111 unsigned long freq,
112 bool available);
71419d84
NC
113struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
114 unsigned int level);
e1f60b29 115
47d43ba7
NM
116struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
117 unsigned long *freq);
2f36bde0
AC
118struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
119 unsigned long u_volt);
e1f60b29 120
47d43ba7
NM
121struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
122 unsigned long *freq);
7034764a 123void dev_pm_opp_put(struct dev_pm_opp *opp);
e1f60b29 124
5d4879cd
NM
125int dev_pm_opp_add(struct device *dev, unsigned long freq,
126 unsigned long u_volt);
129eec55 127void dev_pm_opp_remove(struct device *dev, unsigned long freq);
1690d8bb 128void dev_pm_opp_remove_all_dynamic(struct device *dev);
e1f60b29 129
25cb20a2
SB
130int 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);
133
5d4879cd 134int dev_pm_opp_enable(struct device *dev, unsigned long freq);
e1f60b29 135
5d4879cd 136int dev_pm_opp_disable(struct device *dev, unsigned long freq);
e1f60b29 137
dc2c9ad5
VK
138int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
139int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
140
fa30184d
VK
141struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
142void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
143struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
144void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
dfbe4678
VK
145struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
146void dev_pm_opp_put_regulators(struct opp_table *opp_table);
829a4e8c
VK
147struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name);
148void dev_pm_opp_put_clkname(struct opp_table *opp_table);
fa30184d 149struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
604a7aeb 150void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table);
17a8f868 151struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs);
6319aee1 152void dev_pm_opp_detach_genpd(struct opp_table *opp_table);
c8a59103 153int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
6a0712f6 154int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
3ae1f39a 155int dev_pm_opp_set_bw(struct device *dev, struct dev_pm_opp *opp);
ddbb74bc
AB
156int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
157int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
411466c5
SH
158void dev_pm_opp_remove_table(struct device *dev);
159void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
e1f60b29 160#else
f067a982
VK
161static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
162{
163 return ERR_PTR(-ENOTSUPP);
164}
165
eb7c8743
VK
166static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
167{
168 return ERR_PTR(-ENOTSUPP);
169}
170
f067a982
VK
171static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
172
47d43ba7 173static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
e1f60b29
NM
174{
175 return 0;
176}
177
47d43ba7 178static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
e1f60b29
NM
179{
180 return 0;
181}
182
5b93ac54
RN
183static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
184{
185 return 0;
186}
187
19445b25
BZ
188static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
189{
190 return false;
191}
192
5d4879cd 193static inline int dev_pm_opp_get_opp_count(struct device *dev)
e1f60b29
NM
194{
195 return 0;
196}
197
3ca9bb33
VK
198static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
199{
200 return 0;
201}
202
655c9df9
VK
203static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
204{
205 return 0;
206}
207
21743447
VK
208static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
209{
210 return 0;
211}
212
3aa26a3b 213static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
4eafbd15 214{
3aa26a3b 215 return 0;
4eafbd15
BZ
216}
217
47d43ba7 218static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
e1f60b29
NM
219 unsigned long freq, bool available)
220{
d708b384 221 return ERR_PTR(-ENOTSUPP);
e1f60b29
NM
222}
223
71419d84
NC
224static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
225 unsigned int level)
226{
227 return ERR_PTR(-ENOTSUPP);
228}
229
47d43ba7 230static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
e1f60b29
NM
231 unsigned long *freq)
232{
d708b384 233 return ERR_PTR(-ENOTSUPP);
e1f60b29
NM
234}
235
2f36bde0
AC
236static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
237 unsigned long u_volt)
238{
239 return ERR_PTR(-ENOTSUPP);
240}
241
47d43ba7 242static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
e1f60b29
NM
243 unsigned long *freq)
244{
d708b384 245 return ERR_PTR(-ENOTSUPP);
e1f60b29
NM
246}
247
7034764a
VK
248static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
249
5d4879cd 250static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
e1f60b29
NM
251 unsigned long u_volt)
252{
d708b384 253 return -ENOTSUPP;
e1f60b29
NM
254}
255
129eec55
VK
256static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
257{
258}
259
1690d8bb
VK
260static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
261{
262}
263
25cb20a2
SB
264static inline int
265dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
266 unsigned long u_volt, unsigned long u_volt_min,
267 unsigned long u_volt_max)
268{
269 return 0;
270}
271
5d4879cd 272static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
e1f60b29
NM
273{
274 return 0;
275}
276
5d4879cd 277static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
e1f60b29
NM
278{
279 return 0;
280}
03ca370f 281
dc2c9ad5 282static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
03ca370f 283{
dc2c9ad5
VK
284 return -ENOTSUPP;
285}
286
287static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
288{
289 return -ENOTSUPP;
03ca370f 290}
7de36b0a 291
fa30184d
VK
292static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
293 const u32 *versions,
294 unsigned int count)
7de36b0a 295{
fa30184d 296 return ERR_PTR(-ENOTSUPP);
7de36b0a
VK
297}
298
fa30184d 299static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
7de36b0a 300
fa30184d 301static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
4dab160e
VK
302 int (*set_opp)(struct dev_pm_set_opp_data *data))
303{
fa30184d 304 return ERR_PTR(-ENOTSUPP);
4dab160e
VK
305}
306
604a7aeb 307static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {}
4dab160e 308
fa30184d 309static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
01fb4d3c 310{
fa30184d 311 return ERR_PTR(-ENOTSUPP);
01fb4d3c
VK
312}
313
fa30184d 314static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
01fb4d3c 315
dfbe4678 316static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
9f8ea969 317{
91291d9a 318 return ERR_PTR(-ENOTSUPP);
9f8ea969
VK
319}
320
dfbe4678 321static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
9f8ea969 322
829a4e8c
VK
323static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name)
324{
325 return ERR_PTR(-ENOTSUPP);
326}
327
328static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {}
329
17a8f868 330static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs)
4f018bc0
VK
331{
332 return ERR_PTR(-ENOTSUPP);
333}
334
6319aee1 335static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {}
c8a59103
VK
336
337static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
338{
339 return -ENOTSUPP;
340}
341
6a0712f6
VK
342static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
343{
d708b384 344 return -ENOTSUPP;
6a0712f6
VK
345}
346
3ae1f39a
SS
347static inline int dev_pm_opp_set_bw(struct device *dev, struct dev_pm_opp *opp)
348{
349 return -EOPNOTSUPP;
350}
351
ddbb74bc 352static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
642aa8ce 353{
d708b384 354 return -ENOTSUPP;
642aa8ce
VK
355}
356
ddbb74bc 357static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
6f707daa
VK
358{
359 return -EINVAL;
360}
361
411466c5
SH
362static inline void dev_pm_opp_remove_table(struct device *dev)
363{
364}
365
366static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
367{
368}
369
a96d69d1 370#endif /* CONFIG_PM_OPP */
e1f60b29 371
d6561bb2 372#if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
8f8d37b2 373int dev_pm_opp_of_add_table(struct device *dev);
fa9b274f 374int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
8f8d37b2 375void dev_pm_opp_of_remove_table(struct device *dev);
ddbb74bc
AB
376int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
377void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
378int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
0764c604 379struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
e2f4b5f8 380struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
2feb5a89 381int of_get_required_opp_performance_state(struct device_node *np, int index);
6d3f922c 382int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
0e0ffa85
LL
383int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
384static inline void dev_pm_opp_of_unregister_em(struct device *dev)
385{
386 em_dev_unregister_perf_domain(dev);
387}
d6561bb2 388#else
8f8d37b2 389static inline int dev_pm_opp_of_add_table(struct device *dev)
d6561bb2 390{
d708b384 391 return -ENOTSUPP;
d6561bb2 392}
129eec55 393
fa9b274f
VK
394static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
395{
396 return -ENOTSUPP;
397}
398
8f8d37b2 399static inline void dev_pm_opp_of_remove_table(struct device *dev)
129eec55
VK
400{
401}
8d4d4e98 402
ddbb74bc 403static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
8d4d4e98 404{
d708b384 405 return -ENOTSUPP;
8d4d4e98
VK
406}
407
ddbb74bc 408static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
8d4d4e98
VK
409{
410}
411
ddbb74bc 412static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
8d4d4e98 413{
d708b384 414 return -ENOTSUPP;
8d4d4e98 415}
0764c604
DG
416
417static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
418{
419 return NULL;
420}
a88bd2a5 421
e2f4b5f8
VK
422static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
423{
424 return NULL;
425}
a4f342b9 426
0e0ffa85
LL
427static inline int dev_pm_opp_of_register_em(struct device *dev,
428 struct cpumask *cpus)
429{
430 return -ENOTSUPP;
431}
432
433static inline void dev_pm_opp_of_unregister_em(struct device *dev)
a4f342b9
QP
434{
435}
436
2feb5a89 437static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
4c6a343e 438{
2feb5a89 439 return -ENOTSUPP;
4c6a343e 440}
6d3f922c
GD
441
442static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table)
443{
444 return -ENOTSUPP;
445}
d6561bb2
SG
446#endif
447
e1f60b29 448#endif /* __LINUX_OPP_H__ */