1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef __LINUX_DEVFREQ_H__
14#define __LINUX_DEVFREQ_H__
15
16#include <linux/device.h>
17#include <linux/notifier.h>
18#include <linux/pm_opp.h>
19
20#define DEVFREQ_NAME_LEN 16
21
22
23#define DEVFREQ_TRANSITION_NOTIFIER (0)
24
25
26#define DEVFREQ_PRECHANGE (0)
27#define DEVFREQ_POSTCHANGE (1)
28
29struct devfreq;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46struct devfreq_dev_status {
47
48 unsigned long total_time;
49 unsigned long busy_time;
50 unsigned long current_frequency;
51 void *private_data;
52};
53
54
55
56
57
58
59
60#define DEVFREQ_FLAG_LEAST_UPPER_BOUND 0x1
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89struct devfreq_dev_profile {
90 unsigned long initial_freq;
91 unsigned int polling_ms;
92
93 int (*target)(struct device *dev, unsigned long *freq, u32 flags);
94 int (*get_dev_status)(struct device *dev,
95 struct devfreq_dev_status *stat);
96 int (*get_cur_freq)(struct device *dev, unsigned long *freq);
97 void (*exit)(struct device *dev);
98
99 unsigned long *freq_table;
100 unsigned int max_state;
101};
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120struct devfreq_governor {
121 struct list_head node;
122
123 const char name[DEVFREQ_NAME_LEN];
124 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
125 int (*event_handler)(struct devfreq *devfreq,
126 unsigned int event, void *data);
127};
128
129
130
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
163struct devfreq {
164 struct list_head node;
165
166 struct mutex lock;
167 struct device dev;
168 struct devfreq_dev_profile *profile;
169 const struct devfreq_governor *governor;
170 char governor_name[DEVFREQ_NAME_LEN];
171 struct notifier_block nb;
172 struct delayed_work work;
173
174 unsigned long previous_freq;
175 struct devfreq_dev_status last_status;
176
177 void *data;
178
179 unsigned long min_freq;
180 unsigned long max_freq;
181 bool stop_polling;
182
183
184 unsigned int total_trans;
185 unsigned int *trans_table;
186 unsigned long *time_in_state;
187 unsigned long last_stat_updated;
188
189 struct srcu_notifier_head transition_notifier_list;
190};
191
192struct devfreq_freqs {
193 unsigned long old;
194 unsigned long new;
195};
196
197#if defined(CONFIG_PM_DEVFREQ)
198extern struct devfreq *devfreq_add_device(struct device *dev,
199 struct devfreq_dev_profile *profile,
200 const char *governor_name,
201 void *data);
202extern int devfreq_remove_device(struct devfreq *devfreq);
203extern struct devfreq *devm_devfreq_add_device(struct device *dev,
204 struct devfreq_dev_profile *profile,
205 const char *governor_name,
206 void *data);
207extern void devm_devfreq_remove_device(struct device *dev,
208 struct devfreq *devfreq);
209
210
211extern int devfreq_suspend_device(struct devfreq *devfreq);
212extern int devfreq_resume_device(struct devfreq *devfreq);
213
214
215extern struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
216 unsigned long *freq, u32 flags);
217extern int devfreq_register_opp_notifier(struct device *dev,
218 struct devfreq *devfreq);
219extern int devfreq_unregister_opp_notifier(struct device *dev,
220 struct devfreq *devfreq);
221extern int devm_devfreq_register_opp_notifier(struct device *dev,
222 struct devfreq *devfreq);
223extern void devm_devfreq_unregister_opp_notifier(struct device *dev,
224 struct devfreq *devfreq);
225extern int devfreq_register_notifier(struct devfreq *devfreq,
226 struct notifier_block *nb,
227 unsigned int list);
228extern int devfreq_unregister_notifier(struct devfreq *devfreq,
229 struct notifier_block *nb,
230 unsigned int list);
231extern int devm_devfreq_register_notifier(struct device *dev,
232 struct devfreq *devfreq,
233 struct notifier_block *nb,
234 unsigned int list);
235extern void devm_devfreq_unregister_notifier(struct device *dev,
236 struct devfreq *devfreq,
237 struct notifier_block *nb,
238 unsigned int list);
239extern struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev,
240 int index);
241
242
243
244
245
246
247
248
249
250static inline int devfreq_update_stats(struct devfreq *df)
251{
252 return df->profile->get_dev_status(df->dev.parent, &df->last_status);
253}
254
255#if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND)
256
257
258
259
260
261
262
263
264
265
266
267
268
269struct devfreq_simple_ondemand_data {
270 unsigned int upthreshold;
271 unsigned int downdifferential;
272};
273#endif
274
275#if IS_ENABLED(CONFIG_DEVFREQ_GOV_PASSIVE)
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295struct devfreq_passive_data {
296
297 struct devfreq *parent;
298
299
300 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
301
302
303 struct devfreq *this;
304 struct notifier_block nb;
305};
306#endif
307
308#else
309static inline struct devfreq *devfreq_add_device(struct device *dev,
310 struct devfreq_dev_profile *profile,
311 const char *governor_name,
312 void *data)
313{
314 return ERR_PTR(-ENOSYS);
315}
316
317static inline int devfreq_remove_device(struct devfreq *devfreq)
318{
319 return 0;
320}
321
322static inline struct devfreq *devm_devfreq_add_device(struct device *dev,
323 struct devfreq_dev_profile *profile,
324 const char *governor_name,
325 void *data)
326{
327 return ERR_PTR(-ENOSYS);
328}
329
330static inline void devm_devfreq_remove_device(struct device *dev,
331 struct devfreq *devfreq)
332{
333}
334
335static inline int devfreq_suspend_device(struct devfreq *devfreq)
336{
337 return 0;
338}
339
340static inline int devfreq_resume_device(struct devfreq *devfreq)
341{
342 return 0;
343}
344
345static inline struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
346 unsigned long *freq, u32 flags)
347{
348 return ERR_PTR(-EINVAL);
349}
350
351static inline int devfreq_register_opp_notifier(struct device *dev,
352 struct devfreq *devfreq)
353{
354 return -EINVAL;
355}
356
357static inline int devfreq_unregister_opp_notifier(struct device *dev,
358 struct devfreq *devfreq)
359{
360 return -EINVAL;
361}
362
363static inline int devm_devfreq_register_opp_notifier(struct device *dev,
364 struct devfreq *devfreq)
365{
366 return -EINVAL;
367}
368
369static inline void devm_devfreq_unregister_opp_notifier(struct device *dev,
370 struct devfreq *devfreq)
371{
372}
373
374static inline int devfreq_register_notifier(struct devfreq *devfreq,
375 struct notifier_block *nb,
376 unsigned int list)
377{
378 return 0;
379}
380
381static inline int devfreq_unregister_notifier(struct devfreq *devfreq,
382 struct notifier_block *nb,
383 unsigned int list)
384{
385 return 0;
386}
387
388static inline int devm_devfreq_register_notifier(struct device *dev,
389 struct devfreq *devfreq,
390 struct notifier_block *nb,
391 unsigned int list)
392{
393 return 0;
394}
395
396static inline void devm_devfreq_unregister_notifier(struct device *dev,
397 struct devfreq *devfreq,
398 struct notifier_block *nb,
399 unsigned int list)
400{
401}
402
403static inline struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev,
404 int index)
405{
406 return ERR_PTR(-ENODEV);
407}
408
409static inline int devfreq_update_stats(struct devfreq *df)
410{
411 return -EINVAL;
412}
413#endif
414
415#endif
416