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#define DEVFREQ_NAME_LEN 16
19
20
21#define DEVFREQ_GOV_SIMPLE_ONDEMAND "simple_ondemand"
22#define DEVFREQ_GOV_PERFORMANCE "performance"
23#define DEVFREQ_GOV_POWERSAVE "powersave"
24#define DEVFREQ_GOV_USERSPACE "userspace"
25#define DEVFREQ_GOV_PASSIVE "passive"
26
27
28#define DEVFREQ_TRANSITION_NOTIFIER (0)
29
30
31#define DEVFREQ_PRECHANGE (0)
32#define DEVFREQ_POSTCHANGE (1)
33
34
35enum devfreq_timer {
36 DEVFREQ_TIMER_DEFERRABLE = 0,
37 DEVFREQ_TIMER_DELAYED,
38 DEVFREQ_TIMER_NUM,
39};
40
41struct devfreq;
42struct devfreq_governor;
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
104struct devfreq_dev_profile {
105 unsigned long initial_freq;
106 unsigned int polling_ms;
107 enum devfreq_timer timer;
108
109 int (*target)(struct device *dev, unsigned long *freq, u32 flags);
110 int (*get_dev_status)(struct device *dev,
111 struct devfreq_dev_status *stat);
112 int (*get_cur_freq)(struct device *dev, unsigned long *freq);
113 void (*exit)(struct device *dev);
114
115 unsigned long *freq_table;
116 unsigned int max_state;
117};
118
119
120
121
122
123
124
125
126struct devfreq_stats {
127 unsigned int total_trans;
128 unsigned int *trans_table;
129 u64 *time_in_state;
130 u64 last_update;
131};
132
133
134
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
172struct devfreq {
173 struct list_head node;
174
175 struct mutex lock;
176 struct device dev;
177 struct devfreq_dev_profile *profile;
178 const struct devfreq_governor *governor;
179 char governor_name[DEVFREQ_NAME_LEN];
180 struct notifier_block nb;
181 struct delayed_work work;
182
183 unsigned long previous_freq;
184 struct devfreq_dev_status last_status;
185
186 void *data;
187
188 struct dev_pm_qos_request user_min_freq_req;
189 struct dev_pm_qos_request user_max_freq_req;
190 unsigned long scaling_min_freq;
191 unsigned long scaling_max_freq;
192 bool stop_polling;
193
194 unsigned long suspend_freq;
195 unsigned long resume_freq;
196 atomic_t suspend_count;
197
198
199 struct devfreq_stats stats;
200
201 struct srcu_notifier_head transition_notifier_list;
202
203 struct notifier_block nb_min;
204 struct notifier_block nb_max;
205};
206
207struct devfreq_freqs {
208 unsigned long old;
209 unsigned long new;
210};
211
212#if defined(CONFIG_PM_DEVFREQ)
213struct devfreq *devfreq_add_device(struct device *dev,
214 struct devfreq_dev_profile *profile,
215 const char *governor_name,
216 void *data);
217int devfreq_remove_device(struct devfreq *devfreq);
218struct devfreq *devm_devfreq_add_device(struct device *dev,
219 struct devfreq_dev_profile *profile,
220 const char *governor_name,
221 void *data);
222void devm_devfreq_remove_device(struct device *dev, struct devfreq *devfreq);
223
224
225int devfreq_suspend_device(struct devfreq *devfreq);
226int devfreq_resume_device(struct devfreq *devfreq);
227
228void devfreq_suspend(void);
229void devfreq_resume(void);
230
231
232
233
234
235
236
237int update_devfreq(struct devfreq *devfreq);
238
239
240struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
241 unsigned long *freq, u32 flags);
242int devfreq_register_opp_notifier(struct device *dev,
243 struct devfreq *devfreq);
244int devfreq_unregister_opp_notifier(struct device *dev,
245 struct devfreq *devfreq);
246int devm_devfreq_register_opp_notifier(struct device *dev,
247 struct devfreq *devfreq);
248void devm_devfreq_unregister_opp_notifier(struct device *dev,
249 struct devfreq *devfreq);
250int devfreq_register_notifier(struct devfreq *devfreq,
251 struct notifier_block *nb,
252 unsigned int list);
253int devfreq_unregister_notifier(struct devfreq *devfreq,
254 struct notifier_block *nb,
255 unsigned int list);
256int devm_devfreq_register_notifier(struct device *dev,
257 struct devfreq *devfreq,
258 struct notifier_block *nb,
259 unsigned int list);
260void devm_devfreq_unregister_notifier(struct device *dev,
261 struct devfreq *devfreq,
262 struct notifier_block *nb,
263 unsigned int list);
264struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index);
265
266#if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND)
267
268
269
270
271
272
273
274
275
276
277
278
279
280struct devfreq_simple_ondemand_data {
281 unsigned int upthreshold;
282 unsigned int downdifferential;
283};
284#endif
285
286#if IS_ENABLED(CONFIG_DEVFREQ_GOV_PASSIVE)
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306struct devfreq_passive_data {
307
308 struct devfreq *parent;
309
310
311 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
312
313
314 struct devfreq *this;
315 struct notifier_block nb;
316};
317#endif
318
319#else
320static inline struct devfreq *devfreq_add_device(struct device *dev,
321 struct devfreq_dev_profile *profile,
322 const char *governor_name,
323 void *data)
324{
325 return ERR_PTR(-ENOSYS);
326}
327
328static inline int devfreq_remove_device(struct devfreq *devfreq)
329{
330 return 0;
331}
332
333static inline struct devfreq *devm_devfreq_add_device(struct device *dev,
334 struct devfreq_dev_profile *profile,
335 const char *governor_name,
336 void *data)
337{
338 return ERR_PTR(-ENOSYS);
339}
340
341static inline void devm_devfreq_remove_device(struct device *dev,
342 struct devfreq *devfreq)
343{
344}
345
346static inline int devfreq_suspend_device(struct devfreq *devfreq)
347{
348 return 0;
349}
350
351static inline int devfreq_resume_device(struct devfreq *devfreq)
352{
353 return 0;
354}
355
356static inline void devfreq_suspend(void) {}
357static inline void devfreq_resume(void) {}
358
359static inline struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
360 unsigned long *freq, u32 flags)
361{
362 return ERR_PTR(-EINVAL);
363}
364
365static inline int devfreq_register_opp_notifier(struct device *dev,
366 struct devfreq *devfreq)
367{
368 return -EINVAL;
369}
370
371static inline int devfreq_unregister_opp_notifier(struct device *dev,
372 struct devfreq *devfreq)
373{
374 return -EINVAL;
375}
376
377static inline int devm_devfreq_register_opp_notifier(struct device *dev,
378 struct devfreq *devfreq)
379{
380 return -EINVAL;
381}
382
383static inline void devm_devfreq_unregister_opp_notifier(struct device *dev,
384 struct devfreq *devfreq)
385{
386}
387
388static inline int devfreq_register_notifier(struct devfreq *devfreq,
389 struct notifier_block *nb,
390 unsigned int list)
391{
392 return 0;
393}
394
395static inline int devfreq_unregister_notifier(struct devfreq *devfreq,
396 struct notifier_block *nb,
397 unsigned int list)
398{
399 return 0;
400}
401
402static inline int devm_devfreq_register_notifier(struct device *dev,
403 struct devfreq *devfreq,
404 struct notifier_block *nb,
405 unsigned int list)
406{
407 return 0;
408}
409
410static inline void devm_devfreq_unregister_notifier(struct device *dev,
411 struct devfreq *devfreq,
412 struct notifier_block *nb,
413 unsigned int list)
414{
415}
416
417static inline struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev,
418 int index)
419{
420 return ERR_PTR(-ENODEV);
421}
422
423static inline int devfreq_update_stats(struct devfreq *df)
424{
425 return -EINVAL;
426}
427#endif
428
429#endif
430