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