]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - include/linux/pm_opp.h
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500
[mirror_ubuntu-hirsute-kernel.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,
03ca370f
MH
25};
26
0f0fe7e0
VK
27/**
28 * struct dev_pm_opp_supply - Power supply voltage/current values
29 * @u_volt: Target voltage in microvolts corresponding to this OPP
30 * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP
31 * @u_volt_max: Maximum voltage in microvolts corresponding to this OPP
32 * @u_amp: Maximum current drawn by the device in microamperes
33 *
34 * This structure stores the voltage/current values for a single power supply.
35 */
36struct dev_pm_opp_supply {
37 unsigned long u_volt;
38 unsigned long u_volt_min;
39 unsigned long u_volt_max;
40 unsigned long u_amp;
41};
42
94735585
VK
43/**
44 * struct dev_pm_opp_info - OPP freq/voltage/current values
45 * @rate: Target clk rate in hz
46 * @supplies: Array of voltage/current values for all power supplies
47 *
48 * This structure stores the freq/voltage/current values for a single OPP.
49 */
50struct dev_pm_opp_info {
51 unsigned long rate;
52 struct dev_pm_opp_supply *supplies;
53};
54
55/**
56 * struct dev_pm_set_opp_data - Set OPP data
57 * @old_opp: Old OPP info
58 * @new_opp: New OPP info
59 * @regulators: Array of regulator pointers
60 * @regulator_count: Number of regulators
61 * @clk: Pointer to clk
62 * @dev: Pointer to the struct device
63 *
64 * This structure contains all information required for setting an OPP.
65 */
66struct dev_pm_set_opp_data {
67 struct dev_pm_opp_info old_opp;
68 struct dev_pm_opp_info new_opp;
69
70 struct regulator **regulators;
71 unsigned int regulator_count;
72 struct clk *clk;
73 struct device *dev;
74};
75
e1f60b29
NM
76#if defined(CONFIG_PM_OPP)
77
f067a982 78struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
eb7c8743 79struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index);
f067a982
VK
80void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
81
47d43ba7 82unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
e1f60b29 83
47d43ba7 84unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
e1f60b29 85
5b93ac54
RN
86unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
87
19445b25
BZ
88bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
89
5d4879cd 90int dev_pm_opp_get_opp_count(struct device *dev);
3ca9bb33 91unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
655c9df9 92unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
21743447 93unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
3aa26a3b 94unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
e1f60b29 95
47d43ba7
NM
96struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
97 unsigned long freq,
98 bool available);
e1f60b29 99
47d43ba7
NM
100struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
101 unsigned long *freq);
2f36bde0
AC
102struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
103 unsigned long u_volt);
e1f60b29 104
47d43ba7
NM
105struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
106 unsigned long *freq);
7034764a 107void dev_pm_opp_put(struct dev_pm_opp *opp);
e1f60b29 108
5d4879cd
NM
109int dev_pm_opp_add(struct device *dev, unsigned long freq,
110 unsigned long u_volt);
129eec55 111void dev_pm_opp_remove(struct device *dev, unsigned long freq);
1690d8bb 112void dev_pm_opp_remove_all_dynamic(struct device *dev);
e1f60b29 113
5d4879cd 114int dev_pm_opp_enable(struct device *dev, unsigned long freq);
e1f60b29 115
5d4879cd 116int dev_pm_opp_disable(struct device *dev, unsigned long freq);
e1f60b29 117
dc2c9ad5
VK
118int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
119int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
120
fa30184d
VK
121struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
122void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
123struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
124void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
dfbe4678
VK
125struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
126void dev_pm_opp_put_regulators(struct opp_table *opp_table);
829a4e8c
VK
127struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name);
128void dev_pm_opp_put_clkname(struct opp_table *opp_table);
fa30184d 129struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
604a7aeb 130void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table);
4f018bc0
VK
131struct opp_table *dev_pm_opp_set_genpd_virt_dev(struct device *dev, struct device *virt_dev, int index);
132void dev_pm_opp_put_genpd_virt_dev(struct opp_table *opp_table, struct device *virt_dev);
c8a59103 133int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
6a0712f6 134int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
ddbb74bc
AB
135int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
136int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
411466c5
SH
137void dev_pm_opp_remove_table(struct device *dev);
138void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
e1f60b29 139#else
f067a982
VK
140static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
141{
142 return ERR_PTR(-ENOTSUPP);
143}
144
eb7c8743
VK
145static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
146{
147 return ERR_PTR(-ENOTSUPP);
148}
149
f067a982
VK
150static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
151
47d43ba7 152static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
e1f60b29
NM
153{
154 return 0;
155}
156
47d43ba7 157static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
e1f60b29
NM
158{
159 return 0;
160}
161
5b93ac54
RN
162static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
163{
164 return 0;
165}
166
19445b25
BZ
167static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
168{
169 return false;
170}
171
5d4879cd 172static inline int dev_pm_opp_get_opp_count(struct device *dev)
e1f60b29
NM
173{
174 return 0;
175}
176
3ca9bb33
VK
177static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
178{
179 return 0;
180}
181
655c9df9
VK
182static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
183{
184 return 0;
185}
186
21743447
VK
187static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
188{
189 return 0;
190}
191
3aa26a3b 192static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
4eafbd15 193{
3aa26a3b 194 return 0;
4eafbd15
BZ
195}
196
47d43ba7 197static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
e1f60b29
NM
198 unsigned long freq, bool available)
199{
d708b384 200 return ERR_PTR(-ENOTSUPP);
e1f60b29
NM
201}
202
47d43ba7 203static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
e1f60b29
NM
204 unsigned long *freq)
205{
d708b384 206 return ERR_PTR(-ENOTSUPP);
e1f60b29
NM
207}
208
2f36bde0
AC
209static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
210 unsigned long u_volt)
211{
212 return ERR_PTR(-ENOTSUPP);
213}
214
47d43ba7 215static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
e1f60b29
NM
216 unsigned long *freq)
217{
d708b384 218 return ERR_PTR(-ENOTSUPP);
e1f60b29
NM
219}
220
7034764a
VK
221static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
222
5d4879cd 223static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
e1f60b29
NM
224 unsigned long u_volt)
225{
d708b384 226 return -ENOTSUPP;
e1f60b29
NM
227}
228
129eec55
VK
229static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
230{
231}
232
1690d8bb
VK
233static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
234{
235}
236
5d4879cd 237static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
e1f60b29
NM
238{
239 return 0;
240}
241
5d4879cd 242static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
e1f60b29
NM
243{
244 return 0;
245}
03ca370f 246
dc2c9ad5 247static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
03ca370f 248{
dc2c9ad5
VK
249 return -ENOTSUPP;
250}
251
252static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
253{
254 return -ENOTSUPP;
03ca370f 255}
7de36b0a 256
fa30184d
VK
257static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
258 const u32 *versions,
259 unsigned int count)
7de36b0a 260{
fa30184d 261 return ERR_PTR(-ENOTSUPP);
7de36b0a
VK
262}
263
fa30184d 264static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
7de36b0a 265
fa30184d 266static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
4dab160e
VK
267 int (*set_opp)(struct dev_pm_set_opp_data *data))
268{
fa30184d 269 return ERR_PTR(-ENOTSUPP);
4dab160e
VK
270}
271
604a7aeb 272static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {}
4dab160e 273
fa30184d 274static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
01fb4d3c 275{
fa30184d 276 return ERR_PTR(-ENOTSUPP);
01fb4d3c
VK
277}
278
fa30184d 279static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
01fb4d3c 280
dfbe4678 281static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
9f8ea969 282{
91291d9a 283 return ERR_PTR(-ENOTSUPP);
9f8ea969
VK
284}
285
dfbe4678 286static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
9f8ea969 287
829a4e8c
VK
288static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name)
289{
290 return ERR_PTR(-ENOTSUPP);
291}
292
293static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {}
294
4f018bc0
VK
295static inline struct opp_table *dev_pm_opp_set_genpd_virt_dev(struct device *dev, struct device *virt_dev, int index)
296{
297 return ERR_PTR(-ENOTSUPP);
298}
299
300static inline void dev_pm_opp_put_genpd_virt_dev(struct opp_table *opp_table, struct device *virt_dev) {}
c8a59103
VK
301
302static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
303{
304 return -ENOTSUPP;
305}
306
6a0712f6
VK
307static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
308{
d708b384 309 return -ENOTSUPP;
6a0712f6
VK
310}
311
ddbb74bc 312static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
642aa8ce 313{
d708b384 314 return -ENOTSUPP;
642aa8ce
VK
315}
316
ddbb74bc 317static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
6f707daa
VK
318{
319 return -EINVAL;
320}
321
411466c5
SH
322static inline void dev_pm_opp_remove_table(struct device *dev)
323{
324}
325
326static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
327{
328}
329
a96d69d1 330#endif /* CONFIG_PM_OPP */
e1f60b29 331
d6561bb2 332#if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
8f8d37b2 333int dev_pm_opp_of_add_table(struct device *dev);
fa9b274f 334int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
8f8d37b2 335void dev_pm_opp_of_remove_table(struct device *dev);
ddbb74bc
AB
336int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
337void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
338int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
0764c604 339struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
e2f4b5f8 340struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
2feb5a89 341int of_get_required_opp_performance_state(struct device_node *np, int index);
a4f342b9 342void dev_pm_opp_of_register_em(struct cpumask *cpus);
d6561bb2 343#else
8f8d37b2 344static inline int dev_pm_opp_of_add_table(struct device *dev)
d6561bb2 345{
d708b384 346 return -ENOTSUPP;
d6561bb2 347}
129eec55 348
fa9b274f
VK
349static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
350{
351 return -ENOTSUPP;
352}
353
8f8d37b2 354static inline void dev_pm_opp_of_remove_table(struct device *dev)
129eec55
VK
355{
356}
8d4d4e98 357
ddbb74bc 358static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
8d4d4e98 359{
d708b384 360 return -ENOTSUPP;
8d4d4e98
VK
361}
362
ddbb74bc 363static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
8d4d4e98
VK
364{
365}
366
ddbb74bc 367static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
8d4d4e98 368{
d708b384 369 return -ENOTSUPP;
8d4d4e98 370}
0764c604
DG
371
372static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
373{
374 return NULL;
375}
a88bd2a5 376
e2f4b5f8
VK
377static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
378{
379 return NULL;
380}
a4f342b9
QP
381
382static inline void dev_pm_opp_of_register_em(struct cpumask *cpus)
383{
384}
385
2feb5a89 386static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
4c6a343e 387{
2feb5a89 388 return -ENOTSUPP;
4c6a343e 389}
d6561bb2
SG
390#endif
391
e1f60b29 392#endif /* __LINUX_OPP_H__ */