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