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