opp: Fix "foo * bar" should be "foo *bar"
[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
VK
92struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
93void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
94
47d43ba7 95unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
e1f60b29 96
47d43ba7 97unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
e1f60b29 98
5b93ac54
RN
99unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
100
597ff543
DO
101unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
102 unsigned int index);
103
19445b25
BZ
104bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
105
5d4879cd 106int dev_pm_opp_get_opp_count(struct device *dev);
3ca9bb33 107unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
655c9df9 108unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
21743447 109unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
3aa26a3b 110unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
e1f60b29 111
47d43ba7
NM
112struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
113 unsigned long freq,
114 bool available);
71419d84
NC
115struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
116 unsigned int level);
8dd5cada
DO
117struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
118 unsigned int *level);
e1f60b29 119
47d43ba7
NM
120struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
121 unsigned long *freq);
2f36bde0
AC
122struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
123 unsigned long u_volt);
e1f60b29 124
47d43ba7
NM
125struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
126 unsigned long *freq);
7034764a 127void dev_pm_opp_put(struct dev_pm_opp *opp);
e1f60b29 128
5d4879cd
NM
129int dev_pm_opp_add(struct device *dev, unsigned long freq,
130 unsigned long u_volt);
129eec55 131void dev_pm_opp_remove(struct device *dev, unsigned long freq);
1690d8bb 132void dev_pm_opp_remove_all_dynamic(struct device *dev);
e1f60b29 133
25cb20a2
SB
134int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
135 unsigned long u_volt, unsigned long u_volt_min,
136 unsigned long u_volt_max);
137
5d4879cd 138int dev_pm_opp_enable(struct device *dev, unsigned long freq);
e1f60b29 139
5d4879cd 140int dev_pm_opp_disable(struct device *dev, unsigned long freq);
e1f60b29 141
dc2c9ad5
VK
142int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
143int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
144
fa30184d
VK
145struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
146void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
147struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
148void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
dfbe4678
VK
149struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
150void dev_pm_opp_put_regulators(struct opp_table *opp_table);
f3988bc5 151struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name);
829a4e8c 152void dev_pm_opp_put_clkname(struct opp_table *opp_table);
fa30184d 153struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
604a7aeb 154void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table);
a3c47af6 155struct opp_table *devm_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
17a8f868 156struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs);
6319aee1 157void dev_pm_opp_detach_genpd(struct opp_table *opp_table);
b4b9e223 158struct opp_table *devm_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs);
c8a59103 159int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
6a0712f6 160int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
abbe3483 161int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp);
ddbb74bc
AB
162int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
163int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
411466c5
SH
164void dev_pm_opp_remove_table(struct device *dev);
165void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
ce8073d8 166int dev_pm_opp_sync_regulators(struct device *dev);
e1f60b29 167#else
f067a982
VK
168static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
169{
170 return ERR_PTR(-ENOTSUPP);
171}
172
eb7c8743
VK
173static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
174{
175 return ERR_PTR(-ENOTSUPP);
176}
177
f067a982
VK
178static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
179
47d43ba7 180static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
e1f60b29
NM
181{
182 return 0;
183}
184
47d43ba7 185static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
e1f60b29
NM
186{
187 return 0;
188}
189
5b93ac54
RN
190static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
191{
192 return 0;
193}
194
597ff543
DO
195static inline
196unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
197 unsigned int index)
198{
199 return 0;
200}
201
19445b25
BZ
202static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
203{
204 return false;
205}
206
5d4879cd 207static inline int dev_pm_opp_get_opp_count(struct device *dev)
e1f60b29
NM
208{
209 return 0;
210}
211
3ca9bb33
VK
212static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
213{
214 return 0;
215}
216
655c9df9
VK
217static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
218{
219 return 0;
220}
221
21743447
VK
222static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
223{
224 return 0;
225}
226
3aa26a3b 227static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
4eafbd15 228{
3aa26a3b 229 return 0;
4eafbd15
BZ
230}
231
47d43ba7 232static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
e1f60b29
NM
233 unsigned long freq, bool available)
234{
d708b384 235 return ERR_PTR(-ENOTSUPP);
e1f60b29
NM
236}
237
71419d84
NC
238static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
239 unsigned int level)
240{
241 return ERR_PTR(-ENOTSUPP);
242}
243
8dd5cada
DO
244static inline struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
245 unsigned int *level)
246{
247 return ERR_PTR(-ENOTSUPP);
248}
249
47d43ba7 250static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
e1f60b29
NM
251 unsigned long *freq)
252{
d708b384 253 return ERR_PTR(-ENOTSUPP);
e1f60b29
NM
254}
255
2f36bde0
AC
256static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
257 unsigned long u_volt)
258{
259 return ERR_PTR(-ENOTSUPP);
260}
261
47d43ba7 262static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
e1f60b29
NM
263 unsigned long *freq)
264{
d708b384 265 return ERR_PTR(-ENOTSUPP);
e1f60b29
NM
266}
267
7034764a
VK
268static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
269
5d4879cd 270static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
e1f60b29
NM
271 unsigned long u_volt)
272{
d708b384 273 return -ENOTSUPP;
e1f60b29
NM
274}
275
129eec55
VK
276static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
277{
278}
279
1690d8bb
VK
280static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
281{
282}
283
25cb20a2
SB
284static inline int
285dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
286 unsigned long u_volt, unsigned long u_volt_min,
287 unsigned long u_volt_max)
288{
289 return 0;
290}
291
5d4879cd 292static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
e1f60b29
NM
293{
294 return 0;
295}
296
5d4879cd 297static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
e1f60b29
NM
298{
299 return 0;
300}
03ca370f 301
dc2c9ad5 302static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
03ca370f 303{
dc2c9ad5
VK
304 return -ENOTSUPP;
305}
306
307static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
308{
309 return -ENOTSUPP;
03ca370f 310}
7de36b0a 311
fa30184d
VK
312static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
313 const u32 *versions,
314 unsigned int count)
7de36b0a 315{
fa30184d 316 return ERR_PTR(-ENOTSUPP);
7de36b0a
VK
317}
318
fa30184d 319static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
7de36b0a 320
fa30184d 321static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
4dab160e
VK
322 int (*set_opp)(struct dev_pm_set_opp_data *data))
323{
fa30184d 324 return ERR_PTR(-ENOTSUPP);
4dab160e
VK
325}
326
604a7aeb 327static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {}
4dab160e 328
a3c47af6
DO
329static inline struct opp_table *
330devm_pm_opp_register_set_opp_helper(struct device *dev,
331 int (*set_opp)(struct dev_pm_set_opp_data *data))
332{
333 return ERR_PTR(-ENOTSUPP);
334}
335
fa30184d 336static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
01fb4d3c 337{
fa30184d 338 return ERR_PTR(-ENOTSUPP);
01fb4d3c
VK
339}
340
fa30184d 341static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
01fb4d3c 342
dfbe4678 343static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
9f8ea969 344{
91291d9a 345 return ERR_PTR(-ENOTSUPP);
9f8ea969
VK
346}
347
dfbe4678 348static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
9f8ea969 349
f3988bc5 350static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name)
829a4e8c
VK
351{
352 return ERR_PTR(-ENOTSUPP);
353}
354
355static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {}
356
17a8f868 357static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs)
4f018bc0
VK
358{
359 return ERR_PTR(-ENOTSUPP);
360}
361
6319aee1 362static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {}
c8a59103 363
b4b9e223
DO
364static inline struct opp_table *devm_pm_opp_attach_genpd(struct device *dev,
365 const char **names, struct device ***virt_devs)
366{
367 return ERR_PTR(-ENOTSUPP);
368}
369
c8a59103
VK
370static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
371{
372 return -ENOTSUPP;
373}
374
6a0712f6
VK
375static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
376{
d708b384 377 return -ENOTSUPP;
6a0712f6
VK
378}
379
abbe3483
VK
380static inline int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp)
381{
382 return -ENOTSUPP;
383}
384
ddbb74bc 385static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
642aa8ce 386{
d708b384 387 return -ENOTSUPP;
642aa8ce
VK
388}
389
ddbb74bc 390static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
6f707daa
VK
391{
392 return -EINVAL;
393}
394
411466c5
SH
395static inline void dev_pm_opp_remove_table(struct device *dev)
396{
397}
398
399static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
400{
401}
402
ce8073d8
DO
403static inline int dev_pm_opp_sync_regulators(struct device *dev)
404{
405 return -ENOTSUPP;
406}
407
a96d69d1 408#endif /* CONFIG_PM_OPP */
e1f60b29 409
d6561bb2 410#if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
8f8d37b2 411int dev_pm_opp_of_add_table(struct device *dev);
fa9b274f 412int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
559fef0d 413int dev_pm_opp_of_add_table_noclk(struct device *dev, int index);
8f8d37b2 414void dev_pm_opp_of_remove_table(struct device *dev);
ddbb74bc
AB
415int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
416void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
417int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
0764c604 418struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
e2f4b5f8 419struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
2feb5a89 420int of_get_required_opp_performance_state(struct device_node *np, int index);
6d3f922c 421int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
0e0ffa85
LL
422int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
423static inline void dev_pm_opp_of_unregister_em(struct device *dev)
424{
425 em_dev_unregister_perf_domain(dev);
426}
d6561bb2 427#else
8f8d37b2 428static inline int dev_pm_opp_of_add_table(struct device *dev)
d6561bb2 429{
d708b384 430 return -ENOTSUPP;
d6561bb2 431}
129eec55 432
fa9b274f
VK
433static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
434{
435 return -ENOTSUPP;
436}
437
559fef0d
VK
438static inline int dev_pm_opp_of_add_table_noclk(struct device *dev, int index)
439{
440 return -ENOTSUPP;
441}
442
8f8d37b2 443static inline void dev_pm_opp_of_remove_table(struct device *dev)
129eec55
VK
444{
445}
8d4d4e98 446
ddbb74bc 447static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
8d4d4e98 448{
d708b384 449 return -ENOTSUPP;
8d4d4e98
VK
450}
451
ddbb74bc 452static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
8d4d4e98
VK
453{
454}
455
ddbb74bc 456static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
8d4d4e98 457{
d708b384 458 return -ENOTSUPP;
8d4d4e98 459}
0764c604
DG
460
461static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
462{
463 return NULL;
464}
a88bd2a5 465
e2f4b5f8
VK
466static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
467{
468 return NULL;
469}
a4f342b9 470
0e0ffa85
LL
471static inline int dev_pm_opp_of_register_em(struct device *dev,
472 struct cpumask *cpus)
473{
474 return -ENOTSUPP;
475}
476
477static inline void dev_pm_opp_of_unregister_em(struct device *dev)
a4f342b9
QP
478{
479}
480
2feb5a89 481static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
4c6a343e 482{
2feb5a89 483 return -ENOTSUPP;
4c6a343e 484}
6d3f922c
GD
485
486static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table)
487{
488 return -ENOTSUPP;
489}
d6561bb2
SG
490#endif
491
e1f60b29 492#endif /* __LINUX_OPP_H__ */