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