1
2
3
4
5
6
7
8
9
10#ifndef __LINUX_DEVFREQ_H__
11#define __LINUX_DEVFREQ_H__
12
13#include <linux/device.h>
14#include <linux/notifier.h>
15#include <linux/pm_opp.h>
16#include <linux/pm_qos.h>
17
18
19#define DEVFREQ_GOV_SIMPLE_ONDEMAND "simple_ondemand"
20#define DEVFREQ_GOV_PERFORMANCE "performance"
21#define DEVFREQ_GOV_POWERSAVE "powersave"
22#define DEVFREQ_GOV_USERSPACE "userspace"
23#define DEVFREQ_GOV_PASSIVE "passive"
24
25
26#define DEVFREQ_TRANSITION_NOTIFIER (0)
27
28
29#define DEVFREQ_PRECHANGE (0)
30#define DEVFREQ_POSTCHANGE (1)
31
32
33enum devfreq_timer {
34 DEVFREQ_TIMER_DEFERRABLE = 0,
35 DEVFREQ_TIMER_DELAYED,
36 DEVFREQ_TIMER_NUM,
37};
38
39struct devfreq;
40struct devfreq_governor;
41struct devfreq_cpu_data;
42struct thermal_cooling_device;
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59struct devfreq_dev_status {
60
61 unsigned long total_time;
62 unsigned long busy_time;
63 unsigned long current_frequency;
64 void *private_data;
65};
66
67
68
69
70
71
72
73#define DEVFREQ_FLAG_LEAST_UPPER_BOUND 0x1
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107struct devfreq_dev_profile {
108 unsigned long initial_freq;
109 unsigned int polling_ms;
110 enum devfreq_timer timer;
111 bool is_cooling_device;
112
113 int (*target)(struct device *dev, unsigned long *freq, u32 flags);
114 int (*get_dev_status)(struct device *dev,
115 struct devfreq_dev_status *stat);
116 int (*get_cur_freq)(struct device *dev, unsigned long *freq);
117 void (*exit)(struct device *dev);
118
119 unsigned long *freq_table;
120 unsigned int max_state;
121};
122
123
124
125
126
127
128
129
130struct devfreq_stats {
131 unsigned int total_trans;
132 unsigned int *trans_table;
133 u64 *time_in_state;
134 u64 last_update;
135};
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179struct devfreq {
180 struct list_head node;
181
182 struct mutex lock;
183 struct device dev;
184 struct devfreq_dev_profile *profile;
185 const struct devfreq_governor *governor;
186 struct opp_table *opp_table;
187 struct notifier_block nb;
188 struct delayed_work work;
189
190 unsigned long *freq_table;
191 unsigned int max_state;
192
193 unsigned long previous_freq;
194 struct devfreq_dev_status last_status;
195
196 void *data;
197
198 struct dev_pm_qos_request user_min_freq_req;
199 struct dev_pm_qos_request user_max_freq_req;
200 unsigned long scaling_min_freq;
201 unsigned long scaling_max_freq;
202 bool stop_polling;
203
204 unsigned long suspend_freq;
205 unsigned long resume_freq;
206 atomic_t suspend_count;
207
208
209 struct devfreq_stats stats;
210
211 struct srcu_notifier_head transition_notifier_list;
212
213
214 struct thermal_cooling_device *cdev;
215
216 struct notifier_block nb_min;
217 struct notifier_block nb_max;
218};
219
220struct devfreq_freqs {
221 unsigned long old;
222 unsigned long new;
223};
224
225#if defined(CONFIG_PM_DEVFREQ)
226struct devfreq *devfreq_add_device(struct device *dev,
227 struct devfreq_dev_profile *profile,
228 const char *governor_name,
229 void *data);
230int devfreq_remove_device(struct devfreq *devfreq);
231struct devfreq *devm_devfreq_add_device(struct device *dev,
232 struct devfreq_dev_profile *profile,
233 const char *governor_name,
234 void *data);
235void devm_devfreq_remove_device(struct device *dev, struct devfreq *devfreq);
236
237
238int devfreq_suspend_device(struct devfreq *devfreq);
239int devfreq_resume_device(struct devfreq *devfreq);
240
241void devfreq_suspend(void);
242void devfreq_resume(void);
243
244
245int update_devfreq(struct devfreq *devfreq);
246
247
248struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
249 unsigned long *freq, u32 flags);
250int devfreq_register_opp_notifier(struct device *dev,
251 struct devfreq *devfreq);
252int devfreq_unregister_opp_notifier(struct device *dev,
253 struct devfreq *devfreq);
254int devm_devfreq_register_opp_notifier(struct device *dev,
255 struct devfreq *devfreq);
256void devm_devfreq_unregister_opp_notifier(struct device *dev,
257 struct devfreq *devfreq);
258int devfreq_register_notifier(struct devfreq *devfreq,
259 struct notifier_block *nb,
260 unsigned int list);
261int devfreq_unregister_notifier(struct devfreq *devfreq,
262 struct notifier_block *nb,
263 unsigned int list);
264int devm_devfreq_register_notifier(struct device *dev,
265 struct devfreq *devfreq,
266 struct notifier_block *nb,
267 unsigned int list);
268void devm_devfreq_unregister_notifier(struct device *dev,
269 struct devfreq *devfreq,
270 struct notifier_block *nb,
271 unsigned int list);
272struct devfreq *devfreq_get_devfreq_by_node(struct device_node *node);
273struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev,
274 const char *phandle_name, int index);
275
276#if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND)
277
278
279
280
281
282
283
284
285
286
287
288
289
290struct devfreq_simple_ondemand_data {
291 unsigned int upthreshold;
292 unsigned int downdifferential;
293};
294#endif
295
296#if IS_ENABLED(CONFIG_DEVFREQ_GOV_PASSIVE)
297enum devfreq_parent_dev_type {
298 DEVFREQ_PARENT_DEV,
299 CPUFREQ_PARENT_DEV,
300};
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324struct devfreq_passive_data {
325
326 struct devfreq *parent;
327
328
329 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
330
331
332 enum devfreq_parent_dev_type parent_type;
333
334
335 struct devfreq *this;
336 struct notifier_block nb;
337 struct list_head cpu_data_list;
338};
339#endif
340
341#else
342static inline struct devfreq *devfreq_add_device(struct device *dev,
343 struct devfreq_dev_profile *profile,
344 const char *governor_name,
345 void *data)
346{
347 return ERR_PTR(-ENOSYS);
348}
349
350static inline int devfreq_remove_device(struct devfreq *devfreq)
351{
352 return 0;
353}
354
355static inline struct devfreq *devm_devfreq_add_device(struct device *dev,
356 struct devfreq_dev_profile *profile,
357 const char *governor_name,
358 void *data)
359{
360 return ERR_PTR(-ENOSYS);
361}
362
363static inline void devm_devfreq_remove_device(struct device *dev,
364 struct devfreq *devfreq)
365{
366}
367
368static inline int devfreq_suspend_device(struct devfreq *devfreq)
369{
370 return 0;
371}
372
373static inline int devfreq_resume_device(struct devfreq *devfreq)
374{
375 return 0;
376}
377
378static inline void devfreq_suspend(void) {}
379static inline void devfreq_resume(void) {}
380
381static inline struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
382 unsigned long *freq, u32 flags)
383{
384 return ERR_PTR(-EINVAL);
385}
386
387static inline int devfreq_register_opp_notifier(struct device *dev,
388 struct devfreq *devfreq)
389{
390 return -EINVAL;
391}
392
393static inline int devfreq_unregister_opp_notifier(struct device *dev,
394 struct devfreq *devfreq)
395{
396 return -EINVAL;
397}
398
399static inline int devm_devfreq_register_opp_notifier(struct device *dev,
400 struct devfreq *devfreq)
401{
402 return -EINVAL;
403}
404
405static inline void devm_devfreq_unregister_opp_notifier(struct device *dev,
406 struct devfreq *devfreq)
407{
408}
409
410static inline int devfreq_register_notifier(struct devfreq *devfreq,
411 struct notifier_block *nb,
412 unsigned int list)
413{
414 return 0;
415}
416
417static inline int devfreq_unregister_notifier(struct devfreq *devfreq,
418 struct notifier_block *nb,
419 unsigned int list)
420{
421 return 0;
422}
423
424static inline int devm_devfreq_register_notifier(struct device *dev,
425 struct devfreq *devfreq,
426 struct notifier_block *nb,
427 unsigned int list)
428{
429 return 0;
430}
431
432static inline void devm_devfreq_unregister_notifier(struct device *dev,
433 struct devfreq *devfreq,
434 struct notifier_block *nb,
435 unsigned int list)
436{
437}
438
439static inline struct devfreq *devfreq_get_devfreq_by_node(struct device_node *node)
440{
441 return ERR_PTR(-ENODEV);
442}
443
444static inline struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev,
445 const char *phandle_name, int index)
446{
447 return ERR_PTR(-ENODEV);
448}
449
450static inline int devfreq_update_stats(struct devfreq *df)
451{
452 return -EINVAL;
453}
454#endif
455
456#endif
457