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