diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2012-12-07 17:13:36 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2012-12-07 17:13:36 -0500 |
commit | bf58cdffac931ff387c657395742a737837b93ca (patch) | |
tree | 8e5a16a2ece40502f700212220c23c866470d2ff /drivers/devfreq | |
parent | 6b728f1a906976ec658827adc9c2d27608aa8517 (diff) | |
parent | 6dcdd8e3cadd8dfcfe63d231631d70e2670970f9 (diff) |
Merge branch 'pm-devfreq'
* pm-devfreq: (23 commits)
PM / devfreq: remove compiler error with module governors (2)
PM / devfreq: Fix return value in devfreq_remove_governor()
PM / devfreq: Fix incorrect argument in error message
PM / devfreq: missing rcu_read_lock() added for find_device_opp()
PM / devfreq: remove compiler error when a governor is module
PM / devfreq: exynos4_bus.c: Fixed an alignment of the func call args.
PM / devfreq: Add sysfs node to expose available governors
PM / devfreq: allow sysfs governor node to switch governor
PM / devfreq: governors: add GPL module license and allow module build
PM / devfreq: map devfreq drivers to governor using name
PM / devfreq: register governors with devfreq framework
PM / devfreq: provide hooks for governors to be registered
PM / devfreq: export update_devfreq
PM / devfreq: Add sysfs node for representing frequency transition information.
PM / devfreq: Add sysfs node to expose available frequencies
PM / devfreq: documentation cleanups for devfreq header
PM / devfreq: Use devm_* functions in exynos4_bus.c
PM / devfreq: make devfreq_class static
PM / devfreq: fix sscanf handling for writable sysfs entries
PM / devfreq: kernel-doc typo corrections
...
Diffstat (limited to 'drivers/devfreq')
-rw-r--r-- | drivers/devfreq/Kconfig | 8 | ||||
-rw-r--r-- | drivers/devfreq/devfreq.c | 917 | ||||
-rw-r--r-- | drivers/devfreq/exynos4_bus.c | 45 | ||||
-rw-r--r-- | drivers/devfreq/governor.h | 17 | ||||
-rw-r--r-- | drivers/devfreq/governor_performance.c | 38 | ||||
-rw-r--r-- | drivers/devfreq/governor_powersave.c | 38 | ||||
-rw-r--r-- | drivers/devfreq/governor_simpleondemand.c | 55 | ||||
-rw-r--r-- | drivers/devfreq/governor_userspace.c | 45 |
8 files changed, 835 insertions, 328 deletions
diff --git a/drivers/devfreq/Kconfig b/drivers/devfreq/Kconfig index f6b0a6e2ea50..0f079be13305 100644 --- a/drivers/devfreq/Kconfig +++ b/drivers/devfreq/Kconfig | |||
@@ -30,7 +30,7 @@ if PM_DEVFREQ | |||
30 | comment "DEVFREQ Governors" | 30 | comment "DEVFREQ Governors" |
31 | 31 | ||
32 | config DEVFREQ_GOV_SIMPLE_ONDEMAND | 32 | config DEVFREQ_GOV_SIMPLE_ONDEMAND |
33 | bool "Simple Ondemand" | 33 | tristate "Simple Ondemand" |
34 | help | 34 | help |
35 | Chooses frequency based on the recent load on the device. Works | 35 | Chooses frequency based on the recent load on the device. Works |
36 | similar as ONDEMAND governor of CPUFREQ does. A device with | 36 | similar as ONDEMAND governor of CPUFREQ does. A device with |
@@ -39,7 +39,7 @@ config DEVFREQ_GOV_SIMPLE_ONDEMAND | |||
39 | values to the governor with data field at devfreq_add_device(). | 39 | values to the governor with data field at devfreq_add_device(). |
40 | 40 | ||
41 | config DEVFREQ_GOV_PERFORMANCE | 41 | config DEVFREQ_GOV_PERFORMANCE |
42 | bool "Performance" | 42 | tristate "Performance" |
43 | help | 43 | help |
44 | Sets the frequency at the maximum available frequency. | 44 | Sets the frequency at the maximum available frequency. |
45 | This governor always returns UINT_MAX as frequency so that | 45 | This governor always returns UINT_MAX as frequency so that |
@@ -47,7 +47,7 @@ config DEVFREQ_GOV_PERFORMANCE | |||
47 | at any time. | 47 | at any time. |
48 | 48 | ||
49 | config DEVFREQ_GOV_POWERSAVE | 49 | config DEVFREQ_GOV_POWERSAVE |
50 | bool "Powersave" | 50 | tristate "Powersave" |
51 | help | 51 | help |
52 | Sets the frequency at the minimum available frequency. | 52 | Sets the frequency at the minimum available frequency. |
53 | This governor always returns 0 as frequency so that | 53 | This governor always returns 0 as frequency so that |
@@ -55,7 +55,7 @@ config DEVFREQ_GOV_POWERSAVE | |||
55 | at any time. | 55 | at any time. |
56 | 56 | ||
57 | config DEVFREQ_GOV_USERSPACE | 57 | config DEVFREQ_GOV_USERSPACE |
58 | bool "Userspace" | 58 | tristate "Userspace" |
59 | help | 59 | help |
60 | Sets the frequency at the user specified one. | 60 | Sets the frequency at the user specified one. |
61 | This governor returns the user configured frequency if there | 61 | This governor returns the user configured frequency if there |
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 4fa1a22c55ea..53766f39aadd 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c | |||
@@ -27,21 +27,17 @@ | |||
27 | #include <linux/hrtimer.h> | 27 | #include <linux/hrtimer.h> |
28 | #include "governor.h" | 28 | #include "governor.h" |
29 | 29 | ||
30 | struct class *devfreq_class; | 30 | static struct class *devfreq_class; |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * devfreq_work periodically monitors every registered device. | 33 | * devfreq core provides delayed work based load monitoring helper |
34 | * The minimum polling interval is one jiffy. The polling interval is | 34 | * functions. Governors can use these or can implement their own |
35 | * determined by the minimum polling period among all polling devfreq | 35 | * monitoring mechanism. |
36 | * devices. The resolution of polling interval is one jiffy. | ||
37 | */ | 36 | */ |
38 | static bool polling; | ||
39 | static struct workqueue_struct *devfreq_wq; | 37 | static struct workqueue_struct *devfreq_wq; |
40 | static struct delayed_work devfreq_work; | ||
41 | |||
42 | /* wait removing if this is to be removed */ | ||
43 | static struct devfreq *wait_remove_device; | ||
44 | 38 | ||
39 | /* The list of all device-devfreq governors */ | ||
40 | static LIST_HEAD(devfreq_governor_list); | ||
45 | /* The list of all device-devfreq */ | 41 | /* The list of all device-devfreq */ |
46 | static LIST_HEAD(devfreq_list); | 42 | static LIST_HEAD(devfreq_list); |
47 | static DEFINE_MUTEX(devfreq_list_lock); | 43 | static DEFINE_MUTEX(devfreq_list_lock); |
@@ -73,6 +69,79 @@ static struct devfreq *find_device_devfreq(struct device *dev) | |||
73 | } | 69 | } |
74 | 70 | ||
75 | /** | 71 | /** |
72 | * devfreq_get_freq_level() - Lookup freq_table for the frequency | ||
73 | * @devfreq: the devfreq instance | ||
74 | * @freq: the target frequency | ||
75 | */ | ||
76 | static int devfreq_get_freq_level(struct devfreq *devfreq, unsigned long freq) | ||
77 | { | ||
78 | int lev; | ||
79 | |||
80 | for (lev = 0; lev < devfreq->profile->max_state; lev++) | ||
81 | if (freq == devfreq->profile->freq_table[lev]) | ||
82 | return lev; | ||
83 | |||
84 | return -EINVAL; | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * devfreq_update_status() - Update statistics of devfreq behavior | ||
89 | * @devfreq: the devfreq instance | ||
90 | * @freq: the update target frequency | ||
91 | */ | ||
92 | static int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) | ||
93 | { | ||
94 | int lev, prev_lev; | ||
95 | unsigned long cur_time; | ||
96 | |||
97 | lev = devfreq_get_freq_level(devfreq, freq); | ||
98 | if (lev < 0) | ||
99 | return lev; | ||
100 | |||
101 | cur_time = jiffies; | ||
102 | devfreq->time_in_state[lev] += | ||
103 | cur_time - devfreq->last_stat_updated; | ||
104 | if (freq != devfreq->previous_freq) { | ||
105 | prev_lev = devfreq_get_freq_level(devfreq, | ||
106 | devfreq->previous_freq); | ||
107 | devfreq->trans_table[(prev_lev * | ||
108 | devfreq->profile->max_state) + lev]++; | ||
109 | devfreq->total_trans++; | ||
110 | } | ||
111 | devfreq->last_stat_updated = cur_time; | ||
112 | |||
113 | return 0; | ||
114 | } | ||
115 | |||
116 | /** | ||
117 | * find_devfreq_governor() - find devfreq governor from name | ||
118 | * @name: name of the governor | ||
119 | * | ||
120 | * Search the list of devfreq governors and return the matched | ||
121 | * governor's pointer. devfreq_list_lock should be held by the caller. | ||
122 | */ | ||
123 | static struct devfreq_governor *find_devfreq_governor(const char *name) | ||
124 | { | ||
125 | struct devfreq_governor *tmp_governor; | ||
126 | |||
127 | if (unlikely(IS_ERR_OR_NULL(name))) { | ||
128 | pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); | ||
129 | return ERR_PTR(-EINVAL); | ||
130 | } | ||
131 | WARN(!mutex_is_locked(&devfreq_list_lock), | ||
132 | "devfreq_list_lock must be locked."); | ||
133 | |||
134 | list_for_each_entry(tmp_governor, &devfreq_governor_list, node) { | ||
135 | if (!strncmp(tmp_governor->name, name, DEVFREQ_NAME_LEN)) | ||
136 | return tmp_governor; | ||
137 | } | ||
138 | |||
139 | return ERR_PTR(-ENODEV); | ||
140 | } | ||
141 | |||
142 | /* Load monitoring helper functions for governors use */ | ||
143 | |||
144 | /** | ||
76 | * update_devfreq() - Reevaluate the device and configure frequency. | 145 | * update_devfreq() - Reevaluate the device and configure frequency. |
77 | * @devfreq: the devfreq instance. | 146 | * @devfreq: the devfreq instance. |
78 | * | 147 | * |
@@ -90,6 +159,9 @@ int update_devfreq(struct devfreq *devfreq) | |||
90 | return -EINVAL; | 159 | return -EINVAL; |
91 | } | 160 | } |
92 | 161 | ||
162 | if (!devfreq->governor) | ||
163 | return -EINVAL; | ||
164 | |||
93 | /* Reevaluate the proper frequency */ | 165 | /* Reevaluate the proper frequency */ |
94 | err = devfreq->governor->get_target_freq(devfreq, &freq); | 166 | err = devfreq->governor->get_target_freq(devfreq, &freq); |
95 | if (err) | 167 | if (err) |
@@ -116,16 +188,173 @@ int update_devfreq(struct devfreq *devfreq) | |||
116 | if (err) | 188 | if (err) |
117 | return err; | 189 | return err; |
118 | 190 | ||
191 | if (devfreq->profile->freq_table) | ||
192 | if (devfreq_update_status(devfreq, freq)) | ||
193 | dev_err(&devfreq->dev, | ||
194 | "Couldn't update frequency transition information.\n"); | ||
195 | |||
119 | devfreq->previous_freq = freq; | 196 | devfreq->previous_freq = freq; |
120 | return err; | 197 | return err; |
121 | } | 198 | } |
199 | EXPORT_SYMBOL(update_devfreq); | ||
200 | |||
201 | /** | ||
202 | * devfreq_monitor() - Periodically poll devfreq objects. | ||
203 | * @work: the work struct used to run devfreq_monitor periodically. | ||
204 | * | ||
205 | */ | ||
206 | static void devfreq_monitor(struct work_struct *work) | ||
207 | { | ||
208 | int err; | ||
209 | struct devfreq *devfreq = container_of(work, | ||
210 | struct devfreq, work.work); | ||
211 | |||
212 | mutex_lock(&devfreq->lock); | ||
213 | err = update_devfreq(devfreq); | ||
214 | if (err) | ||
215 | dev_err(&devfreq->dev, "dvfs failed with (%d) error\n", err); | ||
216 | |||
217 | queue_delayed_work(devfreq_wq, &devfreq->work, | ||
218 | msecs_to_jiffies(devfreq->profile->polling_ms)); | ||
219 | mutex_unlock(&devfreq->lock); | ||
220 | } | ||
221 | |||
222 | /** | ||
223 | * devfreq_monitor_start() - Start load monitoring of devfreq instance | ||
224 | * @devfreq: the devfreq instance. | ||
225 | * | ||
226 | * Helper function for starting devfreq device load monitoing. By | ||
227 | * default delayed work based monitoring is supported. Function | ||
228 | * to be called from governor in response to DEVFREQ_GOV_START | ||
229 | * event when device is added to devfreq framework. | ||
230 | */ | ||
231 | void devfreq_monitor_start(struct devfreq *devfreq) | ||
232 | { | ||
233 | INIT_DEFERRABLE_WORK(&devfreq->work, devfreq_monitor); | ||
234 | if (devfreq->profile->polling_ms) | ||
235 | queue_delayed_work(devfreq_wq, &devfreq->work, | ||
236 | msecs_to_jiffies(devfreq->profile->polling_ms)); | ||
237 | } | ||
238 | EXPORT_SYMBOL(devfreq_monitor_start); | ||
239 | |||
240 | /** | ||
241 | * devfreq_monitor_stop() - Stop load monitoring of a devfreq instance | ||
242 | * @devfreq: the devfreq instance. | ||
243 | * | ||
244 | * Helper function to stop devfreq device load monitoing. Function | ||
245 | * to be called from governor in response to DEVFREQ_GOV_STOP | ||
246 | * event when device is removed from devfreq framework. | ||
247 | */ | ||
248 | void devfreq_monitor_stop(struct devfreq *devfreq) | ||
249 | { | ||
250 | cancel_delayed_work_sync(&devfreq->work); | ||
251 | } | ||
252 | EXPORT_SYMBOL(devfreq_monitor_stop); | ||
253 | |||
254 | /** | ||
255 | * devfreq_monitor_suspend() - Suspend load monitoring of a devfreq instance | ||
256 | * @devfreq: the devfreq instance. | ||
257 | * | ||
258 | * Helper function to suspend devfreq device load monitoing. Function | ||
259 | * to be called from governor in response to DEVFREQ_GOV_SUSPEND | ||
260 | * event or when polling interval is set to zero. | ||
261 | * | ||
262 | * Note: Though this function is same as devfreq_monitor_stop(), | ||
263 | * intentionally kept separate to provide hooks for collecting | ||
264 | * transition statistics. | ||
265 | */ | ||
266 | void devfreq_monitor_suspend(struct devfreq *devfreq) | ||
267 | { | ||
268 | mutex_lock(&devfreq->lock); | ||
269 | if (devfreq->stop_polling) { | ||
270 | mutex_unlock(&devfreq->lock); | ||
271 | return; | ||
272 | } | ||
273 | |||
274 | devfreq->stop_polling = true; | ||
275 | mutex_unlock(&devfreq->lock); | ||
276 | cancel_delayed_work_sync(&devfreq->work); | ||
277 | } | ||
278 | EXPORT_SYMBOL(devfreq_monitor_suspend); | ||
279 | |||
280 | /** | ||
281 | * devfreq_monitor_resume() - Resume load monitoring of a devfreq instance | ||
282 | * @devfreq: the devfreq instance. | ||
283 | * | ||
284 | * Helper function to resume devfreq device load monitoing. Function | ||
285 | * to be called from governor in response to DEVFREQ_GOV_RESUME | ||
286 | * event or when polling interval is set to non-zero. | ||
287 | */ | ||
288 | void devfreq_monitor_resume(struct devfreq *devfreq) | ||
289 | { | ||
290 | mutex_lock(&devfreq->lock); | ||
291 | if (!devfreq->stop_polling) | ||
292 | goto out; | ||
293 | |||
294 | if (!delayed_work_pending(&devfreq->work) && | ||
295 | devfreq->profile->polling_ms) | ||
296 | queue_delayed_work(devfreq_wq, &devfreq->work, | ||
297 | msecs_to_jiffies(devfreq->profile->polling_ms)); | ||
298 | devfreq->stop_polling = false; | ||
299 | |||
300 | out: | ||
301 | mutex_unlock(&devfreq->lock); | ||
302 | } | ||
303 | EXPORT_SYMBOL(devfreq_monitor_resume); | ||
304 | |||
305 | /** | ||
306 | * devfreq_interval_update() - Update device devfreq monitoring interval | ||
307 | * @devfreq: the devfreq instance. | ||
308 | * @delay: new polling interval to be set. | ||
309 | * | ||
310 | * Helper function to set new load monitoring polling interval. Function | ||
311 | * to be called from governor in response to DEVFREQ_GOV_INTERVAL event. | ||
312 | */ | ||
313 | void devfreq_interval_update(struct devfreq *devfreq, unsigned int *delay) | ||
314 | { | ||
315 | unsigned int cur_delay = devfreq->profile->polling_ms; | ||
316 | unsigned int new_delay = *delay; | ||
317 | |||
318 | mutex_lock(&devfreq->lock); | ||
319 | devfreq->profile->polling_ms = new_delay; | ||
320 | |||
321 | if (devfreq->stop_polling) | ||
322 | goto out; | ||
323 | |||
324 | /* if new delay is zero, stop polling */ | ||
325 | if (!new_delay) { | ||
326 | mutex_unlock(&devfreq->lock); | ||
327 | cancel_delayed_work_sync(&devfreq->work); | ||
328 | return; | ||
329 | } | ||
330 | |||
331 | /* if current delay is zero, start polling with new delay */ | ||
332 | if (!cur_delay) { | ||
333 | queue_delayed_work(devfreq_wq, &devfreq->work, | ||
334 | msecs_to_jiffies(devfreq->profile->polling_ms)); | ||
335 | goto out; | ||
336 | } | ||
337 | |||
338 | /* if current delay is greater than new delay, restart polling */ | ||
339 | if (cur_delay > new_delay) { | ||
340 | mutex_unlock(&devfreq->lock); | ||
341 | cancel_delayed_work_sync(&devfreq->work); | ||
342 | mutex_lock(&devfreq->lock); | ||
343 | if (!devfreq->stop_polling) | ||
344 | queue_delayed_work(devfreq_wq, &devfreq->work, | ||
345 | msecs_to_jiffies(devfreq->profile->polling_ms)); | ||
346 | } | ||
347 | out: | ||
348 | mutex_unlock(&devfreq->lock); | ||
349 | } | ||
350 | EXPORT_SYMBOL(devfreq_interval_update); | ||
122 | 351 | ||
123 | /** | 352 | /** |
124 | * devfreq_notifier_call() - Notify that the device frequency requirements | 353 | * devfreq_notifier_call() - Notify that the device frequency requirements |
125 | * has been changed out of devfreq framework. | 354 | * has been changed out of devfreq framework. |
126 | * @nb the notifier_block (supposed to be devfreq->nb) | 355 | * @nb: the notifier_block (supposed to be devfreq->nb) |
127 | * @type not used | 356 | * @type: not used |
128 | * @devp not used | 357 | * @devp: not used |
129 | * | 358 | * |
130 | * Called by a notifier that uses devfreq->nb. | 359 | * Called by a notifier that uses devfreq->nb. |
131 | */ | 360 | */ |
@@ -143,59 +372,34 @@ static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type, | |||
143 | } | 372 | } |
144 | 373 | ||
145 | /** | 374 | /** |
146 | * _remove_devfreq() - Remove devfreq from the device. | 375 | * _remove_devfreq() - Remove devfreq from the list and release its resources. |
147 | * @devfreq: the devfreq struct | 376 | * @devfreq: the devfreq struct |
148 | * @skip: skip calling device_unregister(). | 377 | * @skip: skip calling device_unregister(). |
149 | * | ||
150 | * Note that the caller should lock devfreq->lock before calling | ||
151 | * this. _remove_devfreq() will unlock it and free devfreq | ||
152 | * internally. devfreq_list_lock should be locked by the caller | ||
153 | * as well (not relased at return) | ||
154 | * | ||
155 | * Lock usage: | ||
156 | * devfreq->lock: locked before call. | ||
157 | * unlocked at return (and freed) | ||
158 | * devfreq_list_lock: locked before call. | ||
159 | * kept locked at return. | ||
160 | * if devfreq is centrally polled. | ||
161 | * | ||
162 | * Freed memory: | ||
163 | * devfreq | ||
164 | */ | 378 | */ |
165 | static void _remove_devfreq(struct devfreq *devfreq, bool skip) | 379 | static void _remove_devfreq(struct devfreq *devfreq, bool skip) |
166 | { | 380 | { |
167 | if (!mutex_is_locked(&devfreq->lock)) { | 381 | mutex_lock(&devfreq_list_lock); |
168 | WARN(true, "devfreq->lock must be locked by the caller.\n"); | 382 | if (IS_ERR(find_device_devfreq(devfreq->dev.parent))) { |
169 | return; | 383 | mutex_unlock(&devfreq_list_lock); |
170 | } | 384 | dev_warn(&devfreq->dev, "releasing devfreq which doesn't exist\n"); |
171 | if (!devfreq->governor->no_central_polling && | ||
172 | !mutex_is_locked(&devfreq_list_lock)) { | ||
173 | WARN(true, "devfreq_list_lock must be locked by the caller.\n"); | ||
174 | return; | 385 | return; |
175 | } | 386 | } |
387 | list_del(&devfreq->node); | ||
388 | mutex_unlock(&devfreq_list_lock); | ||
176 | 389 | ||
177 | if (devfreq->being_removed) | 390 | if (devfreq->governor) |
178 | return; | 391 | devfreq->governor->event_handler(devfreq, |
179 | 392 | DEVFREQ_GOV_STOP, NULL); | |
180 | devfreq->being_removed = true; | ||
181 | 393 | ||
182 | if (devfreq->profile->exit) | 394 | if (devfreq->profile->exit) |
183 | devfreq->profile->exit(devfreq->dev.parent); | 395 | devfreq->profile->exit(devfreq->dev.parent); |
184 | 396 | ||
185 | if (devfreq->governor->exit) | ||
186 | devfreq->governor->exit(devfreq); | ||
187 | |||
188 | if (!skip && get_device(&devfreq->dev)) { | 397 | if (!skip && get_device(&devfreq->dev)) { |
189 | device_unregister(&devfreq->dev); | 398 | device_unregister(&devfreq->dev); |
190 | put_device(&devfreq->dev); | 399 | put_device(&devfreq->dev); |
191 | } | 400 | } |
192 | 401 | ||
193 | if (!devfreq->governor->no_central_polling) | ||
194 | list_del(&devfreq->node); | ||
195 | |||
196 | mutex_unlock(&devfreq->lock); | ||
197 | mutex_destroy(&devfreq->lock); | 402 | mutex_destroy(&devfreq->lock); |
198 | |||
199 | kfree(devfreq); | 403 | kfree(devfreq); |
200 | } | 404 | } |
201 | 405 | ||
@@ -210,163 +414,39 @@ static void _remove_devfreq(struct devfreq *devfreq, bool skip) | |||
210 | static void devfreq_dev_release(struct device *dev) | 414 | static void devfreq_dev_release(struct device *dev) |
211 | { | 415 | { |
212 | struct devfreq *devfreq = to_devfreq(dev); | 416 | struct devfreq *devfreq = to_devfreq(dev); |
213 | bool central_polling = !devfreq->governor->no_central_polling; | ||
214 | |||
215 | /* | ||
216 | * If devfreq_dev_release() was called by device_unregister() of | ||
217 | * _remove_devfreq(), we cannot mutex_lock(&devfreq->lock) and | ||
218 | * being_removed is already set. This also partially checks the case | ||
219 | * where devfreq_dev_release() is called from a thread other than | ||
220 | * the one called _remove_devfreq(); however, this case is | ||
221 | * dealt completely with another following being_removed check. | ||
222 | * | ||
223 | * Because being_removed is never being | ||
224 | * unset, we do not need to worry about race conditions on | ||
225 | * being_removed. | ||
226 | */ | ||
227 | if (devfreq->being_removed) | ||
228 | return; | ||
229 | |||
230 | if (central_polling) | ||
231 | mutex_lock(&devfreq_list_lock); | ||
232 | |||
233 | mutex_lock(&devfreq->lock); | ||
234 | 417 | ||
235 | /* | ||
236 | * Check being_removed flag again for the case where | ||
237 | * devfreq_dev_release() was called in a thread other than the one | ||
238 | * possibly called _remove_devfreq(). | ||
239 | */ | ||
240 | if (devfreq->being_removed) { | ||
241 | mutex_unlock(&devfreq->lock); | ||
242 | goto out; | ||
243 | } | ||
244 | |||
245 | /* devfreq->lock is unlocked and removed in _removed_devfreq() */ | ||
246 | _remove_devfreq(devfreq, true); | 418 | _remove_devfreq(devfreq, true); |
247 | |||
248 | out: | ||
249 | if (central_polling) | ||
250 | mutex_unlock(&devfreq_list_lock); | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * devfreq_monitor() - Periodically poll devfreq objects. | ||
255 | * @work: the work struct used to run devfreq_monitor periodically. | ||
256 | * | ||
257 | */ | ||
258 | static void devfreq_monitor(struct work_struct *work) | ||
259 | { | ||
260 | static unsigned long last_polled_at; | ||
261 | struct devfreq *devfreq, *tmp; | ||
262 | int error; | ||
263 | unsigned long jiffies_passed; | ||
264 | unsigned long next_jiffies = ULONG_MAX, now = jiffies; | ||
265 | struct device *dev; | ||
266 | |||
267 | /* Initially last_polled_at = 0, polling every device at bootup */ | ||
268 | jiffies_passed = now - last_polled_at; | ||
269 | last_polled_at = now; | ||
270 | if (jiffies_passed == 0) | ||
271 | jiffies_passed = 1; | ||
272 | |||
273 | mutex_lock(&devfreq_list_lock); | ||
274 | list_for_each_entry_safe(devfreq, tmp, &devfreq_list, node) { | ||
275 | mutex_lock(&devfreq->lock); | ||
276 | dev = devfreq->dev.parent; | ||
277 | |||
278 | /* Do not remove tmp for a while */ | ||
279 | wait_remove_device = tmp; | ||
280 | |||
281 | if (devfreq->governor->no_central_polling || | ||
282 | devfreq->next_polling == 0) { | ||
283 | mutex_unlock(&devfreq->lock); | ||
284 | continue; | ||
285 | } | ||
286 | mutex_unlock(&devfreq_list_lock); | ||
287 | |||
288 | /* | ||
289 | * Reduce more next_polling if devfreq_wq took an extra | ||
290 | * delay. (i.e., CPU has been idled.) | ||
291 | */ | ||
292 | if (devfreq->next_polling <= jiffies_passed) { | ||
293 | error = update_devfreq(devfreq); | ||
294 | |||
295 | /* Remove a devfreq with an error. */ | ||
296 | if (error && error != -EAGAIN) { | ||
297 | |||
298 | dev_err(dev, "Due to update_devfreq error(%d), devfreq(%s) is removed from the device\n", | ||
299 | error, devfreq->governor->name); | ||
300 | |||
301 | /* | ||
302 | * Unlock devfreq before locking the list | ||
303 | * in order to avoid deadlock with | ||
304 | * find_device_devfreq or others | ||
305 | */ | ||
306 | mutex_unlock(&devfreq->lock); | ||
307 | mutex_lock(&devfreq_list_lock); | ||
308 | /* Check if devfreq is already removed */ | ||
309 | if (IS_ERR(find_device_devfreq(dev))) | ||
310 | continue; | ||
311 | mutex_lock(&devfreq->lock); | ||
312 | /* This unlocks devfreq->lock and free it */ | ||
313 | _remove_devfreq(devfreq, false); | ||
314 | continue; | ||
315 | } | ||
316 | devfreq->next_polling = devfreq->polling_jiffies; | ||
317 | } else { | ||
318 | devfreq->next_polling -= jiffies_passed; | ||
319 | } | ||
320 | |||
321 | if (devfreq->next_polling) | ||
322 | next_jiffies = (next_jiffies > devfreq->next_polling) ? | ||
323 | devfreq->next_polling : next_jiffies; | ||
324 | |||
325 | mutex_unlock(&devfreq->lock); | ||
326 | mutex_lock(&devfreq_list_lock); | ||
327 | } | ||
328 | wait_remove_device = NULL; | ||
329 | mutex_unlock(&devfreq_list_lock); | ||
330 | |||
331 | if (next_jiffies > 0 && next_jiffies < ULONG_MAX) { | ||
332 | polling = true; | ||
333 | queue_delayed_work(devfreq_wq, &devfreq_work, next_jiffies); | ||
334 | } else { | ||
335 | polling = false; | ||
336 | } | ||
337 | } | 419 | } |
338 | 420 | ||
339 | /** | 421 | /** |
340 | * devfreq_add_device() - Add devfreq feature to the device | 422 | * devfreq_add_device() - Add devfreq feature to the device |
341 | * @dev: the device to add devfreq feature. | 423 | * @dev: the device to add devfreq feature. |
342 | * @profile: device-specific profile to run devfreq. | 424 | * @profile: device-specific profile to run devfreq. |
343 | * @governor: the policy to choose frequency. | 425 | * @governor_name: name of the policy to choose frequency. |
344 | * @data: private data for the governor. The devfreq framework does not | 426 | * @data: private data for the governor. The devfreq framework does not |
345 | * touch this value. | 427 | * touch this value. |
346 | */ | 428 | */ |
347 | struct devfreq *devfreq_add_device(struct device *dev, | 429 | struct devfreq *devfreq_add_device(struct device *dev, |
348 | struct devfreq_dev_profile *profile, | 430 | struct devfreq_dev_profile *profile, |
349 | const struct devfreq_governor *governor, | 431 | const char *governor_name, |
350 | void *data) | 432 | void *data) |
351 | { | 433 | { |
352 | struct devfreq *devfreq; | 434 | struct devfreq *devfreq; |
435 | struct devfreq_governor *governor; | ||
353 | int err = 0; | 436 | int err = 0; |
354 | 437 | ||
355 | if (!dev || !profile || !governor) { | 438 | if (!dev || !profile || !governor_name) { |
356 | dev_err(dev, "%s: Invalid parameters.\n", __func__); | 439 | dev_err(dev, "%s: Invalid parameters.\n", __func__); |
357 | return ERR_PTR(-EINVAL); | 440 | return ERR_PTR(-EINVAL); |
358 | } | 441 | } |
359 | 442 | ||
360 | 443 | mutex_lock(&devfreq_list_lock); | |
361 | if (!governor->no_central_polling) { | 444 | devfreq = find_device_devfreq(dev); |
362 | mutex_lock(&devfreq_list_lock); | 445 | mutex_unlock(&devfreq_list_lock); |
363 | devfreq = find_device_devfreq(dev); | 446 | if (!IS_ERR(devfreq)) { |
364 | mutex_unlock(&devfreq_list_lock); | 447 | dev_err(dev, "%s: Unable to create devfreq for the device. It already has one.\n", __func__); |
365 | if (!IS_ERR(devfreq)) { | 448 | err = -EINVAL; |
366 | dev_err(dev, "%s: Unable to create devfreq for the device. It already has one.\n", __func__); | 449 | goto err_out; |
367 | err = -EINVAL; | ||
368 | goto err_out; | ||
369 | } | ||
370 | } | 450 | } |
371 | 451 | ||
372 | devfreq = kzalloc(sizeof(struct devfreq), GFP_KERNEL); | 452 | devfreq = kzalloc(sizeof(struct devfreq), GFP_KERNEL); |
@@ -383,92 +463,316 @@ struct devfreq *devfreq_add_device(struct device *dev, | |||
383 | devfreq->dev.class = devfreq_class; | 463 | devfreq->dev.class = devfreq_class; |
384 | devfreq->dev.release = devfreq_dev_release; | 464 | devfreq->dev.release = devfreq_dev_release; |
385 | devfreq->profile = profile; | 465 | devfreq->profile = profile; |
386 | devfreq->governor = governor; | 466 | strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN); |
387 | devfreq->previous_freq = profile->initial_freq; | 467 | devfreq->previous_freq = profile->initial_freq; |
388 | devfreq->data = data; | 468 | devfreq->data = data; |
389 | devfreq->next_polling = devfreq->polling_jiffies | ||
390 | = msecs_to_jiffies(devfreq->profile->polling_ms); | ||
391 | devfreq->nb.notifier_call = devfreq_notifier_call; | 469 | devfreq->nb.notifier_call = devfreq_notifier_call; |
392 | 470 | ||
471 | devfreq->trans_table = devm_kzalloc(dev, sizeof(unsigned int) * | ||
472 | devfreq->profile->max_state * | ||
473 | devfreq->profile->max_state, | ||
474 | GFP_KERNEL); | ||
475 | devfreq->time_in_state = devm_kzalloc(dev, sizeof(unsigned int) * | ||
476 | devfreq->profile->max_state, | ||
477 | GFP_KERNEL); | ||
478 | devfreq->last_stat_updated = jiffies; | ||
479 | |||
393 | dev_set_name(&devfreq->dev, dev_name(dev)); | 480 | dev_set_name(&devfreq->dev, dev_name(dev)); |
394 | err = device_register(&devfreq->dev); | 481 | err = device_register(&devfreq->dev); |
395 | if (err) { | 482 | if (err) { |
396 | put_device(&devfreq->dev); | 483 | put_device(&devfreq->dev); |
484 | mutex_unlock(&devfreq->lock); | ||
397 | goto err_dev; | 485 | goto err_dev; |
398 | } | 486 | } |
399 | 487 | ||
400 | if (governor->init) | ||
401 | err = governor->init(devfreq); | ||
402 | if (err) | ||
403 | goto err_init; | ||
404 | |||
405 | mutex_unlock(&devfreq->lock); | 488 | mutex_unlock(&devfreq->lock); |
406 | 489 | ||
407 | if (governor->no_central_polling) | ||
408 | goto out; | ||
409 | |||
410 | mutex_lock(&devfreq_list_lock); | 490 | mutex_lock(&devfreq_list_lock); |
411 | |||
412 | list_add(&devfreq->node, &devfreq_list); | 491 | list_add(&devfreq->node, &devfreq_list); |
413 | 492 | ||
414 | if (devfreq_wq && devfreq->next_polling && !polling) { | 493 | governor = find_devfreq_governor(devfreq->governor_name); |
415 | polling = true; | 494 | if (!IS_ERR(governor)) |
416 | queue_delayed_work(devfreq_wq, &devfreq_work, | 495 | devfreq->governor = governor; |
417 | devfreq->next_polling); | 496 | if (devfreq->governor) |
418 | } | 497 | err = devfreq->governor->event_handler(devfreq, |
498 | DEVFREQ_GOV_START, NULL); | ||
419 | mutex_unlock(&devfreq_list_lock); | 499 | mutex_unlock(&devfreq_list_lock); |
420 | out: | 500 | if (err) { |
501 | dev_err(dev, "%s: Unable to start governor for the device\n", | ||
502 | __func__); | ||
503 | goto err_init; | ||
504 | } | ||
505 | |||
421 | return devfreq; | 506 | return devfreq; |
422 | 507 | ||
423 | err_init: | 508 | err_init: |
509 | list_del(&devfreq->node); | ||
424 | device_unregister(&devfreq->dev); | 510 | device_unregister(&devfreq->dev); |
425 | err_dev: | 511 | err_dev: |
426 | mutex_unlock(&devfreq->lock); | ||
427 | kfree(devfreq); | 512 | kfree(devfreq); |
428 | err_out: | 513 | err_out: |
429 | return ERR_PTR(err); | 514 | return ERR_PTR(err); |
430 | } | 515 | } |
516 | EXPORT_SYMBOL(devfreq_add_device); | ||
431 | 517 | ||
432 | /** | 518 | /** |
433 | * devfreq_remove_device() - Remove devfreq feature from a device. | 519 | * devfreq_remove_device() - Remove devfreq feature from a device. |
434 | * @devfreq the devfreq instance to be removed | 520 | * @devfreq: the devfreq instance to be removed |
435 | */ | 521 | */ |
436 | int devfreq_remove_device(struct devfreq *devfreq) | 522 | int devfreq_remove_device(struct devfreq *devfreq) |
437 | { | 523 | { |
438 | bool central_polling; | 524 | if (!devfreq) |
525 | return -EINVAL; | ||
526 | |||
527 | _remove_devfreq(devfreq, false); | ||
439 | 528 | ||
529 | return 0; | ||
530 | } | ||
531 | EXPORT_SYMBOL(devfreq_remove_device); | ||
532 | |||
533 | /** | ||
534 | * devfreq_suspend_device() - Suspend devfreq of a device. | ||
535 | * @devfreq: the devfreq instance to be suspended | ||
536 | */ | ||
537 | int devfreq_suspend_device(struct devfreq *devfreq) | ||
538 | { | ||
440 | if (!devfreq) | 539 | if (!devfreq) |
441 | return -EINVAL; | 540 | return -EINVAL; |
442 | 541 | ||
443 | central_polling = !devfreq->governor->no_central_polling; | 542 | if (!devfreq->governor) |
543 | return 0; | ||
544 | |||
545 | return devfreq->governor->event_handler(devfreq, | ||
546 | DEVFREQ_GOV_SUSPEND, NULL); | ||
547 | } | ||
548 | EXPORT_SYMBOL(devfreq_suspend_device); | ||
549 | |||
550 | /** | ||
551 | * devfreq_resume_device() - Resume devfreq of a device. | ||
552 | * @devfreq: the devfreq instance to be resumed | ||
553 | */ | ||
554 | int devfreq_resume_device(struct devfreq *devfreq) | ||
555 | { | ||
556 | if (!devfreq) | ||
557 | return -EINVAL; | ||
558 | |||
559 | if (!devfreq->governor) | ||
560 | return 0; | ||
561 | |||
562 | return devfreq->governor->event_handler(devfreq, | ||
563 | DEVFREQ_GOV_RESUME, NULL); | ||
564 | } | ||
565 | EXPORT_SYMBOL(devfreq_resume_device); | ||
566 | |||
567 | /** | ||
568 | * devfreq_add_governor() - Add devfreq governor | ||
569 | * @governor: the devfreq governor to be added | ||
570 | */ | ||
571 | int devfreq_add_governor(struct devfreq_governor *governor) | ||
572 | { | ||
573 | struct devfreq_governor *g; | ||
574 | struct devfreq *devfreq; | ||
575 | int err = 0; | ||
576 | |||
577 | if (!governor) { | ||
578 | pr_err("%s: Invalid parameters.\n", __func__); | ||
579 | return -EINVAL; | ||
580 | } | ||
581 | |||
582 | mutex_lock(&devfreq_list_lock); | ||
583 | g = find_devfreq_governor(governor->name); | ||
584 | if (!IS_ERR(g)) { | ||
585 | pr_err("%s: governor %s already registered\n", __func__, | ||
586 | g->name); | ||
587 | err = -EINVAL; | ||
588 | goto err_out; | ||
589 | } | ||
444 | 590 | ||
445 | if (central_polling) { | 591 | list_add(&governor->node, &devfreq_governor_list); |
446 | mutex_lock(&devfreq_list_lock); | 592 | |
447 | while (wait_remove_device == devfreq) { | 593 | list_for_each_entry(devfreq, &devfreq_list, node) { |
448 | mutex_unlock(&devfreq_list_lock); | 594 | int ret = 0; |
449 | schedule(); | 595 | struct device *dev = devfreq->dev.parent; |
450 | mutex_lock(&devfreq_list_lock); | 596 | |
597 | if (!strncmp(devfreq->governor_name, governor->name, | ||
598 | DEVFREQ_NAME_LEN)) { | ||
599 | /* The following should never occur */ | ||
600 | if (devfreq->governor) { | ||
601 | dev_warn(dev, | ||
602 | "%s: Governor %s already present\n", | ||
603 | __func__, devfreq->governor->name); | ||
604 | ret = devfreq->governor->event_handler(devfreq, | ||
605 | DEVFREQ_GOV_STOP, NULL); | ||
606 | if (ret) { | ||
607 | dev_warn(dev, | ||
608 | "%s: Governor %s stop = %d\n", | ||
609 | __func__, | ||
610 | devfreq->governor->name, ret); | ||
611 | } | ||
612 | /* Fall through */ | ||
613 | } | ||
614 | devfreq->governor = governor; | ||
615 | ret = devfreq->governor->event_handler(devfreq, | ||
616 | DEVFREQ_GOV_START, NULL); | ||
617 | if (ret) { | ||
618 | dev_warn(dev, "%s: Governor %s start=%d\n", | ||
619 | __func__, devfreq->governor->name, | ||
620 | ret); | ||
621 | } | ||
451 | } | 622 | } |
452 | } | 623 | } |
453 | 624 | ||
454 | mutex_lock(&devfreq->lock); | 625 | err_out: |
455 | _remove_devfreq(devfreq, false); /* it unlocks devfreq->lock */ | 626 | mutex_unlock(&devfreq_list_lock); |
456 | 627 | ||
457 | if (central_polling) | 628 | return err; |
458 | mutex_unlock(&devfreq_list_lock); | 629 | } |
630 | EXPORT_SYMBOL(devfreq_add_governor); | ||
459 | 631 | ||
460 | return 0; | 632 | /** |
633 | * devfreq_remove_device() - Remove devfreq feature from a device. | ||
634 | * @governor: the devfreq governor to be removed | ||
635 | */ | ||
636 | int devfreq_remove_governor(struct devfreq_governor *governor) | ||
637 | { | ||
638 | struct devfreq_governor *g; | ||
639 | struct devfreq *devfreq; | ||
640 | int err = 0; | ||
641 | |||
642 | if (!governor) { | ||
643 | pr_err("%s: Invalid parameters.\n", __func__); | ||
644 | return -EINVAL; | ||
645 | } | ||
646 | |||
647 | mutex_lock(&devfreq_list_lock); | ||
648 | g = find_devfreq_governor(governor->name); | ||
649 | if (IS_ERR(g)) { | ||
650 | pr_err("%s: governor %s not registered\n", __func__, | ||
651 | governor->name); | ||
652 | err = PTR_ERR(g); | ||
653 | goto err_out; | ||
654 | } | ||
655 | list_for_each_entry(devfreq, &devfreq_list, node) { | ||
656 | int ret; | ||
657 | struct device *dev = devfreq->dev.parent; | ||
658 | |||
659 | if (!strncmp(devfreq->governor_name, governor->name, | ||
660 | DEVFREQ_NAME_LEN)) { | ||
661 | /* we should have a devfreq governor! */ | ||
662 | if (!devfreq->governor) { | ||
663 | dev_warn(dev, "%s: Governor %s NOT present\n", | ||
664 | __func__, governor->name); | ||
665 | continue; | ||
666 | /* Fall through */ | ||
667 | } | ||
668 | ret = devfreq->governor->event_handler(devfreq, | ||
669 | DEVFREQ_GOV_STOP, NULL); | ||
670 | if (ret) { | ||
671 | dev_warn(dev, "%s: Governor %s stop=%d\n", | ||
672 | __func__, devfreq->governor->name, | ||
673 | ret); | ||
674 | } | ||
675 | devfreq->governor = NULL; | ||
676 | } | ||
677 | } | ||
678 | |||
679 | list_del(&governor->node); | ||
680 | err_out: | ||
681 | mutex_unlock(&devfreq_list_lock); | ||
682 | |||
683 | return err; | ||
461 | } | 684 | } |
685 | EXPORT_SYMBOL(devfreq_remove_governor); | ||
462 | 686 | ||
463 | static ssize_t show_governor(struct device *dev, | 687 | static ssize_t show_governor(struct device *dev, |
464 | struct device_attribute *attr, char *buf) | 688 | struct device_attribute *attr, char *buf) |
465 | { | 689 | { |
690 | if (!to_devfreq(dev)->governor) | ||
691 | return -EINVAL; | ||
692 | |||
466 | return sprintf(buf, "%s\n", to_devfreq(dev)->governor->name); | 693 | return sprintf(buf, "%s\n", to_devfreq(dev)->governor->name); |
467 | } | 694 | } |
468 | 695 | ||
696 | static ssize_t store_governor(struct device *dev, struct device_attribute *attr, | ||
697 | const char *buf, size_t count) | ||
698 | { | ||
699 | struct devfreq *df = to_devfreq(dev); | ||
700 | int ret; | ||
701 | char str_governor[DEVFREQ_NAME_LEN + 1]; | ||
702 | struct devfreq_governor *governor; | ||
703 | |||
704 | ret = sscanf(buf, "%" __stringify(DEVFREQ_NAME_LEN) "s", str_governor); | ||
705 | if (ret != 1) | ||
706 | return -EINVAL; | ||
707 | |||
708 | mutex_lock(&devfreq_list_lock); | ||
709 | governor = find_devfreq_governor(str_governor); | ||
710 | if (IS_ERR(governor)) { | ||
711 | ret = PTR_ERR(governor); | ||
712 | goto out; | ||
713 | } | ||
714 | if (df->governor == governor) | ||
715 | goto out; | ||
716 | |||
717 | if (df->governor) { | ||
718 | ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL); | ||
719 | if (ret) { | ||
720 | dev_warn(dev, "%s: Governor %s not stopped(%d)\n", | ||
721 | __func__, df->governor->name, ret); | ||
722 | goto out; | ||
723 | } | ||
724 | } | ||
725 | df->governor = governor; | ||
726 | strncpy(df->governor_name, governor->name, DEVFREQ_NAME_LEN); | ||
727 | ret = df->governor->event_handler(df, DEVFREQ_GOV_START, NULL); | ||
728 | if (ret) | ||
729 | dev_warn(dev, "%s: Governor %s not started(%d)\n", | ||
730 | __func__, df->governor->name, ret); | ||
731 | out: | ||
732 | mutex_unlock(&devfreq_list_lock); | ||
733 | |||
734 | if (!ret) | ||
735 | ret = count; | ||
736 | return ret; | ||
737 | } | ||
738 | static ssize_t show_available_governors(struct device *d, | ||
739 | struct device_attribute *attr, | ||
740 | char *buf) | ||
741 | { | ||
742 | struct devfreq_governor *tmp_governor; | ||
743 | ssize_t count = 0; | ||
744 | |||
745 | mutex_lock(&devfreq_list_lock); | ||
746 | list_for_each_entry(tmp_governor, &devfreq_governor_list, node) | ||
747 | count += scnprintf(&buf[count], (PAGE_SIZE - count - 2), | ||
748 | "%s ", tmp_governor->name); | ||
749 | mutex_unlock(&devfreq_list_lock); | ||
750 | |||
751 | /* Truncate the trailing space */ | ||
752 | if (count) | ||
753 | count--; | ||
754 | |||
755 | count += sprintf(&buf[count], "\n"); | ||
756 | |||
757 | return count; | ||
758 | } | ||
759 | |||
469 | static ssize_t show_freq(struct device *dev, | 760 | static ssize_t show_freq(struct device *dev, |
470 | struct device_attribute *attr, char *buf) | 761 | struct device_attribute *attr, char *buf) |
471 | { | 762 | { |
763 | unsigned long freq; | ||
764 | struct devfreq *devfreq = to_devfreq(dev); | ||
765 | |||
766 | if (devfreq->profile->get_cur_freq && | ||
767 | !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq)) | ||
768 | return sprintf(buf, "%lu\n", freq); | ||
769 | |||
770 | return sprintf(buf, "%lu\n", devfreq->previous_freq); | ||
771 | } | ||
772 | |||
773 | static ssize_t show_target_freq(struct device *dev, | ||
774 | struct device_attribute *attr, char *buf) | ||
775 | { | ||
472 | return sprintf(buf, "%lu\n", to_devfreq(dev)->previous_freq); | 776 | return sprintf(buf, "%lu\n", to_devfreq(dev)->previous_freq); |
473 | } | 777 | } |
474 | 778 | ||
@@ -486,39 +790,19 @@ static ssize_t store_polling_interval(struct device *dev, | |||
486 | unsigned int value; | 790 | unsigned int value; |
487 | int ret; | 791 | int ret; |
488 | 792 | ||
793 | if (!df->governor) | ||
794 | return -EINVAL; | ||
795 | |||
489 | ret = sscanf(buf, "%u", &value); | 796 | ret = sscanf(buf, "%u", &value); |
490 | if (ret != 1) | 797 | if (ret != 1) |
491 | goto out; | 798 | return -EINVAL; |
492 | |||
493 | mutex_lock(&df->lock); | ||
494 | df->profile->polling_ms = value; | ||
495 | df->next_polling = df->polling_jiffies | ||
496 | = msecs_to_jiffies(value); | ||
497 | mutex_unlock(&df->lock); | ||
498 | 799 | ||
800 | df->governor->event_handler(df, DEVFREQ_GOV_INTERVAL, &value); | ||
499 | ret = count; | 801 | ret = count; |
500 | 802 | ||
501 | if (df->governor->no_central_polling) | ||
502 | goto out; | ||
503 | |||
504 | mutex_lock(&devfreq_list_lock); | ||
505 | if (df->next_polling > 0 && !polling) { | ||
506 | polling = true; | ||
507 | queue_delayed_work(devfreq_wq, &devfreq_work, | ||
508 | df->next_polling); | ||
509 | } | ||
510 | mutex_unlock(&devfreq_list_lock); | ||
511 | out: | ||
512 | return ret; | 803 | return ret; |
513 | } | 804 | } |
514 | 805 | ||
515 | static ssize_t show_central_polling(struct device *dev, | ||
516 | struct device_attribute *attr, char *buf) | ||
517 | { | ||
518 | return sprintf(buf, "%d\n", | ||
519 | !to_devfreq(dev)->governor->no_central_polling); | ||
520 | } | ||
521 | |||
522 | static ssize_t store_min_freq(struct device *dev, struct device_attribute *attr, | 806 | static ssize_t store_min_freq(struct device *dev, struct device_attribute *attr, |
523 | const char *buf, size_t count) | 807 | const char *buf, size_t count) |
524 | { | 808 | { |
@@ -529,7 +813,7 @@ static ssize_t store_min_freq(struct device *dev, struct device_attribute *attr, | |||
529 | 813 | ||
530 | ret = sscanf(buf, "%lu", &value); | 814 | ret = sscanf(buf, "%lu", &value); |
531 | if (ret != 1) | 815 | if (ret != 1) |
532 | goto out; | 816 | return -EINVAL; |
533 | 817 | ||
534 | mutex_lock(&df->lock); | 818 | mutex_lock(&df->lock); |
535 | max = df->max_freq; | 819 | max = df->max_freq; |
@@ -543,7 +827,6 @@ static ssize_t store_min_freq(struct device *dev, struct device_attribute *attr, | |||
543 | ret = count; | 827 | ret = count; |
544 | unlock: | 828 | unlock: |
545 | mutex_unlock(&df->lock); | 829 | mutex_unlock(&df->lock); |
546 | out: | ||
547 | return ret; | 830 | return ret; |
548 | } | 831 | } |
549 | 832 | ||
@@ -563,7 +846,7 @@ static ssize_t store_max_freq(struct device *dev, struct device_attribute *attr, | |||
563 | 846 | ||
564 | ret = sscanf(buf, "%lu", &value); | 847 | ret = sscanf(buf, "%lu", &value); |
565 | if (ret != 1) | 848 | if (ret != 1) |
566 | goto out; | 849 | return -EINVAL; |
567 | 850 | ||
568 | mutex_lock(&df->lock); | 851 | mutex_lock(&df->lock); |
569 | min = df->min_freq; | 852 | min = df->min_freq; |
@@ -577,7 +860,6 @@ static ssize_t store_max_freq(struct device *dev, struct device_attribute *attr, | |||
577 | ret = count; | 860 | ret = count; |
578 | unlock: | 861 | unlock: |
579 | mutex_unlock(&df->lock); | 862 | mutex_unlock(&df->lock); |
580 | out: | ||
581 | return ret; | 863 | return ret; |
582 | } | 864 | } |
583 | 865 | ||
@@ -587,34 +869,92 @@ static ssize_t show_max_freq(struct device *dev, struct device_attribute *attr, | |||
587 | return sprintf(buf, "%lu\n", to_devfreq(dev)->max_freq); | 869 | return sprintf(buf, "%lu\n", to_devfreq(dev)->max_freq); |
588 | } | 870 | } |
589 | 871 | ||
872 | static ssize_t show_available_freqs(struct device *d, | ||
873 | struct device_attribute *attr, | ||
874 | char *buf) | ||
875 | { | ||
876 | struct devfreq *df = to_devfreq(d); | ||
877 | struct device *dev = df->dev.parent; | ||
878 | struct opp *opp; | ||
879 | ssize_t count = 0; | ||
880 | unsigned long freq = 0; | ||
881 | |||
882 | rcu_read_lock(); | ||
883 | do { | ||
884 | opp = opp_find_freq_ceil(dev, &freq); | ||
885 | if (IS_ERR(opp)) | ||
886 | break; | ||
887 | |||
888 | count += scnprintf(&buf[count], (PAGE_SIZE - count - 2), | ||
889 | "%lu ", freq); | ||
890 | freq++; | ||
891 | } while (1); | ||
892 | rcu_read_unlock(); | ||
893 | |||
894 | /* Truncate the trailing space */ | ||
895 | if (count) | ||
896 | count--; | ||
897 | |||
898 | count += sprintf(&buf[count], "\n"); | ||
899 | |||
900 | return count; | ||
901 | } | ||
902 | |||
903 | static ssize_t show_trans_table(struct device *dev, struct device_attribute *attr, | ||
904 | char *buf) | ||
905 | { | ||
906 | struct devfreq *devfreq = to_devfreq(dev); | ||
907 | ssize_t len; | ||
908 | int i, j, err; | ||
909 | unsigned int max_state = devfreq->profile->max_state; | ||
910 | |||
911 | err = devfreq_update_status(devfreq, devfreq->previous_freq); | ||
912 | if (err) | ||
913 | return 0; | ||
914 | |||
915 | len = sprintf(buf, " From : To\n"); | ||
916 | len += sprintf(buf + len, " :"); | ||
917 | for (i = 0; i < max_state; i++) | ||
918 | len += sprintf(buf + len, "%8u", | ||
919 | devfreq->profile->freq_table[i]); | ||
920 | |||
921 | len += sprintf(buf + len, " time(ms)\n"); | ||
922 | |||
923 | for (i = 0; i < max_state; i++) { | ||
924 | if (devfreq->profile->freq_table[i] | ||
925 | == devfreq->previous_freq) { | ||
926 | len += sprintf(buf + len, "*"); | ||
927 | } else { | ||
928 | len += sprintf(buf + len, " "); | ||
929 | } | ||
930 | len += sprintf(buf + len, "%8u:", | ||
931 | devfreq->profile->freq_table[i]); | ||
932 | for (j = 0; j < max_state; j++) | ||
933 | len += sprintf(buf + len, "%8u", | ||
934 | devfreq->trans_table[(i * max_state) + j]); | ||
935 | len += sprintf(buf + len, "%10u\n", | ||
936 | jiffies_to_msecs(devfreq->time_in_state[i])); | ||
937 | } | ||
938 | |||
939 | len += sprintf(buf + len, "Total transition : %u\n", | ||
940 | devfreq->total_trans); | ||
941 | return len; | ||
942 | } | ||
943 | |||
590 | static struct device_attribute devfreq_attrs[] = { | 944 | static struct device_attribute devfreq_attrs[] = { |
591 | __ATTR(governor, S_IRUGO, show_governor, NULL), | 945 | __ATTR(governor, S_IRUGO | S_IWUSR, show_governor, store_governor), |
946 | __ATTR(available_governors, S_IRUGO, show_available_governors, NULL), | ||
592 | __ATTR(cur_freq, S_IRUGO, show_freq, NULL), | 947 | __ATTR(cur_freq, S_IRUGO, show_freq, NULL), |
593 | __ATTR(central_polling, S_IRUGO, show_central_polling, NULL), | 948 | __ATTR(available_frequencies, S_IRUGO, show_available_freqs, NULL), |
949 | __ATTR(target_freq, S_IRUGO, show_target_freq, NULL), | ||
594 | __ATTR(polling_interval, S_IRUGO | S_IWUSR, show_polling_interval, | 950 | __ATTR(polling_interval, S_IRUGO | S_IWUSR, show_polling_interval, |
595 | store_polling_interval), | 951 | store_polling_interval), |
596 | __ATTR(min_freq, S_IRUGO | S_IWUSR, show_min_freq, store_min_freq), | 952 | __ATTR(min_freq, S_IRUGO | S_IWUSR, show_min_freq, store_min_freq), |
597 | __ATTR(max_freq, S_IRUGO | S_IWUSR, show_max_freq, store_max_freq), | 953 | __ATTR(max_freq, S_IRUGO | S_IWUSR, show_max_freq, store_max_freq), |
954 | __ATTR(trans_stat, S_IRUGO, show_trans_table, NULL), | ||
598 | { }, | 955 | { }, |
599 | }; | 956 | }; |
600 | 957 | ||
601 | /** | ||
602 | * devfreq_start_polling() - Initialize data structure for devfreq framework and | ||
603 | * start polling registered devfreq devices. | ||
604 | */ | ||
605 | static int __init devfreq_start_polling(void) | ||
606 | { | ||
607 | mutex_lock(&devfreq_list_lock); | ||
608 | polling = false; | ||
609 | devfreq_wq = create_freezable_workqueue("devfreq_wq"); | ||
610 | INIT_DEFERRABLE_WORK(&devfreq_work, devfreq_monitor); | ||
611 | mutex_unlock(&devfreq_list_lock); | ||
612 | |||
613 | devfreq_monitor(&devfreq_work.work); | ||
614 | return 0; | ||
615 | } | ||
616 | late_initcall(devfreq_start_polling); | ||
617 | |||
618 | static int __init devfreq_init(void) | 958 | static int __init devfreq_init(void) |
619 | { | 959 | { |
620 | devfreq_class = class_create(THIS_MODULE, "devfreq"); | 960 | devfreq_class = class_create(THIS_MODULE, "devfreq"); |
@@ -622,7 +962,15 @@ static int __init devfreq_init(void) | |||
622 | pr_err("%s: couldn't create class\n", __FILE__); | 962 | pr_err("%s: couldn't create class\n", __FILE__); |
623 | return PTR_ERR(devfreq_class); | 963 | return PTR_ERR(devfreq_class); |
624 | } | 964 | } |
965 | |||
966 | devfreq_wq = create_freezable_workqueue("devfreq_wq"); | ||
967 | if (IS_ERR(devfreq_wq)) { | ||
968 | class_destroy(devfreq_class); | ||
969 | pr_err("%s: couldn't create workqueue\n", __FILE__); | ||
970 | return PTR_ERR(devfreq_wq); | ||
971 | } | ||
625 | devfreq_class->dev_attrs = devfreq_attrs; | 972 | devfreq_class->dev_attrs = devfreq_attrs; |
973 | |||
626 | return 0; | 974 | return 0; |
627 | } | 975 | } |
628 | subsys_initcall(devfreq_init); | 976 | subsys_initcall(devfreq_init); |
@@ -630,6 +978,7 @@ subsys_initcall(devfreq_init); | |||
630 | static void __exit devfreq_exit(void) | 978 | static void __exit devfreq_exit(void) |
631 | { | 979 | { |
632 | class_destroy(devfreq_class); | 980 | class_destroy(devfreq_class); |
981 | destroy_workqueue(devfreq_wq); | ||
633 | } | 982 | } |
634 | module_exit(devfreq_exit); | 983 | module_exit(devfreq_exit); |
635 | 984 | ||
@@ -641,9 +990,9 @@ module_exit(devfreq_exit); | |||
641 | /** | 990 | /** |
642 | * devfreq_recommended_opp() - Helper function to get proper OPP for the | 991 | * devfreq_recommended_opp() - Helper function to get proper OPP for the |
643 | * freq value given to target callback. | 992 | * freq value given to target callback. |
644 | * @dev The devfreq user device. (parent of devfreq) | 993 | * @dev: The devfreq user device. (parent of devfreq) |
645 | * @freq The frequency given to target function | 994 | * @freq: The frequency given to target function |
646 | * @flags Flags handed from devfreq framework. | 995 | * @flags: Flags handed from devfreq framework. |
647 | * | 996 | * |
648 | */ | 997 | */ |
649 | struct opp *devfreq_recommended_opp(struct device *dev, unsigned long *freq, | 998 | struct opp *devfreq_recommended_opp(struct device *dev, unsigned long *freq, |
@@ -674,35 +1023,49 @@ struct opp *devfreq_recommended_opp(struct device *dev, unsigned long *freq, | |||
674 | * devfreq_register_opp_notifier() - Helper function to get devfreq notified | 1023 | * devfreq_register_opp_notifier() - Helper function to get devfreq notified |
675 | * for any changes in the OPP availability | 1024 | * for any changes in the OPP availability |
676 | * changes | 1025 | * changes |
677 | * @dev The devfreq user device. (parent of devfreq) | 1026 | * @dev: The devfreq user device. (parent of devfreq) |
678 | * @devfreq The devfreq object. | 1027 | * @devfreq: The devfreq object. |
679 | */ | 1028 | */ |
680 | int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq) | 1029 | int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq) |
681 | { | 1030 | { |
682 | struct srcu_notifier_head *nh = opp_get_notifier(dev); | 1031 | struct srcu_notifier_head *nh; |
1032 | int ret = 0; | ||
683 | 1033 | ||
1034 | rcu_read_lock(); | ||
1035 | nh = opp_get_notifier(dev); | ||
684 | if (IS_ERR(nh)) | 1036 | if (IS_ERR(nh)) |
685 | return PTR_ERR(nh); | 1037 | ret = PTR_ERR(nh); |
686 | return srcu_notifier_chain_register(nh, &devfreq->nb); | 1038 | rcu_read_unlock(); |
1039 | if (!ret) | ||
1040 | ret = srcu_notifier_chain_register(nh, &devfreq->nb); | ||
1041 | |||
1042 | return ret; | ||
687 | } | 1043 | } |
688 | 1044 | ||
689 | /** | 1045 | /** |
690 | * devfreq_unregister_opp_notifier() - Helper function to stop getting devfreq | 1046 | * devfreq_unregister_opp_notifier() - Helper function to stop getting devfreq |
691 | * notified for any changes in the OPP | 1047 | * notified for any changes in the OPP |
692 | * availability changes anymore. | 1048 | * availability changes anymore. |
693 | * @dev The devfreq user device. (parent of devfreq) | 1049 | * @dev: The devfreq user device. (parent of devfreq) |
694 | * @devfreq The devfreq object. | 1050 | * @devfreq: The devfreq object. |
695 | * | 1051 | * |
696 | * At exit() callback of devfreq_dev_profile, this must be included if | 1052 | * At exit() callback of devfreq_dev_profile, this must be included if |
697 | * devfreq_recommended_opp is used. | 1053 | * devfreq_recommended_opp is used. |
698 | */ | 1054 | */ |
699 | int devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq) | 1055 | int devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq) |
700 | { | 1056 | { |
701 | struct srcu_notifier_head *nh = opp_get_notifier(dev); | 1057 | struct srcu_notifier_head *nh; |
1058 | int ret = 0; | ||
702 | 1059 | ||
1060 | rcu_read_lock(); | ||
1061 | nh = opp_get_notifier(dev); | ||
703 | if (IS_ERR(nh)) | 1062 | if (IS_ERR(nh)) |
704 | return PTR_ERR(nh); | 1063 | ret = PTR_ERR(nh); |
705 | return srcu_notifier_chain_unregister(nh, &devfreq->nb); | 1064 | rcu_read_unlock(); |
1065 | if (!ret) | ||
1066 | ret = srcu_notifier_chain_unregister(nh, &devfreq->nb); | ||
1067 | |||
1068 | return ret; | ||
706 | } | 1069 | } |
707 | 1070 | ||
708 | MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); | 1071 | MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); |
diff --git a/drivers/devfreq/exynos4_bus.c b/drivers/devfreq/exynos4_bus.c index 88ddc77a9bb1..741837208716 100644 --- a/drivers/devfreq/exynos4_bus.c +++ b/drivers/devfreq/exynos4_bus.c | |||
@@ -987,7 +987,7 @@ static __devinit int exynos4_busfreq_probe(struct platform_device *pdev) | |||
987 | struct device *dev = &pdev->dev; | 987 | struct device *dev = &pdev->dev; |
988 | int err = 0; | 988 | int err = 0; |
989 | 989 | ||
990 | data = kzalloc(sizeof(struct busfreq_data), GFP_KERNEL); | 990 | data = devm_kzalloc(&pdev->dev, sizeof(struct busfreq_data), GFP_KERNEL); |
991 | if (data == NULL) { | 991 | if (data == NULL) { |
992 | dev_err(dev, "Cannot allocate memory.\n"); | 992 | dev_err(dev, "Cannot allocate memory.\n"); |
993 | return -ENOMEM; | 993 | return -ENOMEM; |
@@ -1012,31 +1012,26 @@ static __devinit int exynos4_busfreq_probe(struct platform_device *pdev) | |||
1012 | err = -EINVAL; | 1012 | err = -EINVAL; |
1013 | } | 1013 | } |
1014 | if (err) | 1014 | if (err) |
1015 | goto err_regulator; | 1015 | return err; |
1016 | 1016 | ||
1017 | data->vdd_int = regulator_get(dev, "vdd_int"); | 1017 | data->vdd_int = devm_regulator_get(dev, "vdd_int"); |
1018 | if (IS_ERR(data->vdd_int)) { | 1018 | if (IS_ERR(data->vdd_int)) { |
1019 | dev_err(dev, "Cannot get the regulator \"vdd_int\"\n"); | 1019 | dev_err(dev, "Cannot get the regulator \"vdd_int\"\n"); |
1020 | err = PTR_ERR(data->vdd_int); | 1020 | return PTR_ERR(data->vdd_int); |
1021 | goto err_regulator; | ||
1022 | } | 1021 | } |
1023 | if (data->type == TYPE_BUSF_EXYNOS4x12) { | 1022 | if (data->type == TYPE_BUSF_EXYNOS4x12) { |
1024 | data->vdd_mif = regulator_get(dev, "vdd_mif"); | 1023 | data->vdd_mif = devm_regulator_get(dev, "vdd_mif"); |
1025 | if (IS_ERR(data->vdd_mif)) { | 1024 | if (IS_ERR(data->vdd_mif)) { |
1026 | dev_err(dev, "Cannot get the regulator \"vdd_mif\"\n"); | 1025 | dev_err(dev, "Cannot get the regulator \"vdd_mif\"\n"); |
1027 | err = PTR_ERR(data->vdd_mif); | 1026 | return PTR_ERR(data->vdd_mif); |
1028 | regulator_put(data->vdd_int); | ||
1029 | goto err_regulator; | ||
1030 | |||
1031 | } | 1027 | } |
1032 | } | 1028 | } |
1033 | 1029 | ||
1034 | opp = opp_find_freq_floor(dev, &exynos4_devfreq_profile.initial_freq); | 1030 | opp = opp_find_freq_floor(dev, &exynos4_devfreq_profile.initial_freq); |
1035 | if (IS_ERR(opp)) { | 1031 | if (IS_ERR(opp)) { |
1036 | dev_err(dev, "Invalid initial frequency %lu kHz.\n", | 1032 | dev_err(dev, "Invalid initial frequency %lu kHz.\n", |
1037 | exynos4_devfreq_profile.initial_freq); | 1033 | exynos4_devfreq_profile.initial_freq); |
1038 | err = PTR_ERR(opp); | 1034 | return PTR_ERR(opp); |
1039 | goto err_opp_add; | ||
1040 | } | 1035 | } |
1041 | data->curr_opp = opp; | 1036 | data->curr_opp = opp; |
1042 | 1037 | ||
@@ -1045,30 +1040,20 @@ static __devinit int exynos4_busfreq_probe(struct platform_device *pdev) | |||
1045 | busfreq_mon_reset(data); | 1040 | busfreq_mon_reset(data); |
1046 | 1041 | ||
1047 | data->devfreq = devfreq_add_device(dev, &exynos4_devfreq_profile, | 1042 | data->devfreq = devfreq_add_device(dev, &exynos4_devfreq_profile, |
1048 | &devfreq_simple_ondemand, NULL); | 1043 | "simple_ondemand", NULL); |
1049 | if (IS_ERR(data->devfreq)) { | 1044 | if (IS_ERR(data->devfreq)) |
1050 | err = PTR_ERR(data->devfreq); | 1045 | return PTR_ERR(data->devfreq); |
1051 | goto err_opp_add; | ||
1052 | } | ||
1053 | 1046 | ||
1054 | devfreq_register_opp_notifier(dev, data->devfreq); | 1047 | devfreq_register_opp_notifier(dev, data->devfreq); |
1055 | 1048 | ||
1056 | err = register_pm_notifier(&data->pm_notifier); | 1049 | err = register_pm_notifier(&data->pm_notifier); |
1057 | if (err) { | 1050 | if (err) { |
1058 | dev_err(dev, "Failed to setup pm notifier\n"); | 1051 | dev_err(dev, "Failed to setup pm notifier\n"); |
1059 | goto err_devfreq_add; | 1052 | devfreq_remove_device(data->devfreq); |
1053 | return err; | ||
1060 | } | 1054 | } |
1061 | 1055 | ||
1062 | return 0; | 1056 | return 0; |
1063 | err_devfreq_add: | ||
1064 | devfreq_remove_device(data->devfreq); | ||
1065 | err_opp_add: | ||
1066 | if (data->vdd_mif) | ||
1067 | regulator_put(data->vdd_mif); | ||
1068 | regulator_put(data->vdd_int); | ||
1069 | err_regulator: | ||
1070 | kfree(data); | ||
1071 | return err; | ||
1072 | } | 1057 | } |
1073 | 1058 | ||
1074 | static __devexit int exynos4_busfreq_remove(struct platform_device *pdev) | 1059 | static __devexit int exynos4_busfreq_remove(struct platform_device *pdev) |
@@ -1077,10 +1062,6 @@ static __devexit int exynos4_busfreq_remove(struct platform_device *pdev) | |||
1077 | 1062 | ||
1078 | unregister_pm_notifier(&data->pm_notifier); | 1063 | unregister_pm_notifier(&data->pm_notifier); |
1079 | devfreq_remove_device(data->devfreq); | 1064 | devfreq_remove_device(data->devfreq); |
1080 | regulator_put(data->vdd_int); | ||
1081 | if (data->vdd_mif) | ||
1082 | regulator_put(data->vdd_mif); | ||
1083 | kfree(data); | ||
1084 | 1065 | ||
1085 | return 0; | 1066 | return 0; |
1086 | } | 1067 | } |
diff --git a/drivers/devfreq/governor.h b/drivers/devfreq/governor.h index ea7f13c58ded..fad7d6321978 100644 --- a/drivers/devfreq/governor.h +++ b/drivers/devfreq/governor.h | |||
@@ -18,7 +18,24 @@ | |||
18 | 18 | ||
19 | #define to_devfreq(DEV) container_of((DEV), struct devfreq, dev) | 19 | #define to_devfreq(DEV) container_of((DEV), struct devfreq, dev) |
20 | 20 | ||
21 | /* Devfreq events */ | ||
22 | #define DEVFREQ_GOV_START 0x1 | ||
23 | #define DEVFREQ_GOV_STOP 0x2 | ||
24 | #define DEVFREQ_GOV_INTERVAL 0x3 | ||
25 | #define DEVFREQ_GOV_SUSPEND 0x4 | ||
26 | #define DEVFREQ_GOV_RESUME 0x5 | ||
27 | |||
21 | /* Caution: devfreq->lock must be locked before calling update_devfreq */ | 28 | /* Caution: devfreq->lock must be locked before calling update_devfreq */ |
22 | extern int update_devfreq(struct devfreq *devfreq); | 29 | extern int update_devfreq(struct devfreq *devfreq); |
23 | 30 | ||
31 | extern void devfreq_monitor_start(struct devfreq *devfreq); | ||
32 | extern void devfreq_monitor_stop(struct devfreq *devfreq); | ||
33 | extern void devfreq_monitor_suspend(struct devfreq *devfreq); | ||
34 | extern void devfreq_monitor_resume(struct devfreq *devfreq); | ||
35 | extern void devfreq_interval_update(struct devfreq *devfreq, | ||
36 | unsigned int *delay); | ||
37 | |||
38 | extern int devfreq_add_governor(struct devfreq_governor *governor); | ||
39 | extern int devfreq_remove_governor(struct devfreq_governor *governor); | ||
40 | |||
24 | #endif /* _GOVERNOR_H */ | 41 | #endif /* _GOVERNOR_H */ |
diff --git a/drivers/devfreq/governor_performance.c b/drivers/devfreq/governor_performance.c index af75ddd4f158..c72f942f30a8 100644 --- a/drivers/devfreq/governor_performance.c +++ b/drivers/devfreq/governor_performance.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/devfreq.h> | 12 | #include <linux/devfreq.h> |
13 | #include <linux/module.h> | ||
13 | #include "governor.h" | 14 | #include "governor.h" |
14 | 15 | ||
15 | static int devfreq_performance_func(struct devfreq *df, | 16 | static int devfreq_performance_func(struct devfreq *df, |
@@ -26,14 +27,41 @@ static int devfreq_performance_func(struct devfreq *df, | |||
26 | return 0; | 27 | return 0; |
27 | } | 28 | } |
28 | 29 | ||
29 | static int performance_init(struct devfreq *devfreq) | 30 | static int devfreq_performance_handler(struct devfreq *devfreq, |
31 | unsigned int event, void *data) | ||
30 | { | 32 | { |
31 | return update_devfreq(devfreq); | 33 | int ret = 0; |
34 | |||
35 | if (event == DEVFREQ_GOV_START) { | ||
36 | mutex_lock(&devfreq->lock); | ||
37 | ret = update_devfreq(devfreq); | ||
38 | mutex_unlock(&devfreq->lock); | ||
39 | } | ||
40 | |||
41 | return ret; | ||
32 | } | 42 | } |
33 | 43 | ||
34 | const struct devfreq_governor devfreq_performance = { | 44 | static struct devfreq_governor devfreq_performance = { |
35 | .name = "performance", | 45 | .name = "performance", |
36 | .init = performance_init, | ||
37 | .get_target_freq = devfreq_performance_func, | 46 | .get_target_freq = devfreq_performance_func, |
38 | .no_central_polling = true, | 47 | .event_handler = devfreq_performance_handler, |
39 | }; | 48 | }; |
49 | |||
50 | static int __init devfreq_performance_init(void) | ||
51 | { | ||
52 | return devfreq_add_governor(&devfreq_performance); | ||
53 | } | ||
54 | subsys_initcall(devfreq_performance_init); | ||
55 | |||
56 | static void __exit devfreq_performance_exit(void) | ||
57 | { | ||
58 | int ret; | ||
59 | |||
60 | ret = devfreq_remove_governor(&devfreq_performance); | ||
61 | if (ret) | ||
62 | pr_err("%s: failed remove governor %d\n", __func__, ret); | ||
63 | |||
64 | return; | ||
65 | } | ||
66 | module_exit(devfreq_performance_exit); | ||
67 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/devfreq/governor_powersave.c b/drivers/devfreq/governor_powersave.c index fec0cdbd2477..0c6bed567e6d 100644 --- a/drivers/devfreq/governor_powersave.c +++ b/drivers/devfreq/governor_powersave.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/devfreq.h> | 12 | #include <linux/devfreq.h> |
13 | #include <linux/module.h> | ||
13 | #include "governor.h" | 14 | #include "governor.h" |
14 | 15 | ||
15 | static int devfreq_powersave_func(struct devfreq *df, | 16 | static int devfreq_powersave_func(struct devfreq *df, |
@@ -23,14 +24,41 @@ static int devfreq_powersave_func(struct devfreq *df, | |||
23 | return 0; | 24 | return 0; |
24 | } | 25 | } |
25 | 26 | ||
26 | static int powersave_init(struct devfreq *devfreq) | 27 | static int devfreq_powersave_handler(struct devfreq *devfreq, |
28 | unsigned int event, void *data) | ||
27 | { | 29 | { |
28 | return update_devfreq(devfreq); | 30 | int ret = 0; |
31 | |||
32 | if (event == DEVFREQ_GOV_START) { | ||
33 | mutex_lock(&devfreq->lock); | ||
34 | ret = update_devfreq(devfreq); | ||
35 | mutex_unlock(&devfreq->lock); | ||
36 | } | ||
37 | |||
38 | return ret; | ||
29 | } | 39 | } |
30 | 40 | ||
31 | const struct devfreq_governor devfreq_powersave = { | 41 | static struct devfreq_governor devfreq_powersave = { |
32 | .name = "powersave", | 42 | .name = "powersave", |
33 | .init = powersave_init, | ||
34 | .get_target_freq = devfreq_powersave_func, | 43 | .get_target_freq = devfreq_powersave_func, |
35 | .no_central_polling = true, | 44 | .event_handler = devfreq_powersave_handler, |
36 | }; | 45 | }; |
46 | |||
47 | static int __init devfreq_powersave_init(void) | ||
48 | { | ||
49 | return devfreq_add_governor(&devfreq_powersave); | ||
50 | } | ||
51 | subsys_initcall(devfreq_powersave_init); | ||
52 | |||
53 | static void __exit devfreq_powersave_exit(void) | ||
54 | { | ||
55 | int ret; | ||
56 | |||
57 | ret = devfreq_remove_governor(&devfreq_powersave); | ||
58 | if (ret) | ||
59 | pr_err("%s: failed remove governor %d\n", __func__, ret); | ||
60 | |||
61 | return; | ||
62 | } | ||
63 | module_exit(devfreq_powersave_exit); | ||
64 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/devfreq/governor_simpleondemand.c b/drivers/devfreq/governor_simpleondemand.c index a2e3eae79011..0720ba84ca92 100644 --- a/drivers/devfreq/governor_simpleondemand.c +++ b/drivers/devfreq/governor_simpleondemand.c | |||
@@ -10,8 +10,10 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/errno.h> | 12 | #include <linux/errno.h> |
13 | #include <linux/module.h> | ||
13 | #include <linux/devfreq.h> | 14 | #include <linux/devfreq.h> |
14 | #include <linux/math64.h> | 15 | #include <linux/math64.h> |
16 | #include "governor.h" | ||
15 | 17 | ||
16 | /* Default constants for DevFreq-Simple-Ondemand (DFSO) */ | 18 | /* Default constants for DevFreq-Simple-Ondemand (DFSO) */ |
17 | #define DFSO_UPTHRESHOLD (90) | 19 | #define DFSO_UPTHRESHOLD (90) |
@@ -88,7 +90,58 @@ static int devfreq_simple_ondemand_func(struct devfreq *df, | |||
88 | return 0; | 90 | return 0; |
89 | } | 91 | } |
90 | 92 | ||
91 | const struct devfreq_governor devfreq_simple_ondemand = { | 93 | static int devfreq_simple_ondemand_handler(struct devfreq *devfreq, |
94 | unsigned int event, void *data) | ||
95 | { | ||
96 | switch (event) { | ||
97 | case DEVFREQ_GOV_START: | ||
98 | devfreq_monitor_start(devfreq); | ||
99 | break; | ||
100 | |||
101 | case DEVFREQ_GOV_STOP: | ||
102 | devfreq_monitor_stop(devfreq); | ||
103 | break; | ||
104 | |||
105 | case DEVFREQ_GOV_INTERVAL: | ||
106 | devfreq_interval_update(devfreq, (unsigned int *)data); | ||
107 | break; | ||
108 | |||
109 | case DEVFREQ_GOV_SUSPEND: | ||
110 | devfreq_monitor_suspend(devfreq); | ||
111 | break; | ||
112 | |||
113 | case DEVFREQ_GOV_RESUME: | ||
114 | devfreq_monitor_resume(devfreq); | ||
115 | break; | ||
116 | |||
117 | default: | ||
118 | break; | ||
119 | } | ||
120 | |||
121 | return 0; | ||
122 | } | ||
123 | |||
124 | static struct devfreq_governor devfreq_simple_ondemand = { | ||
92 | .name = "simple_ondemand", | 125 | .name = "simple_ondemand", |
93 | .get_target_freq = devfreq_simple_ondemand_func, | 126 | .get_target_freq = devfreq_simple_ondemand_func, |
127 | .event_handler = devfreq_simple_ondemand_handler, | ||
94 | }; | 128 | }; |
129 | |||
130 | static int __init devfreq_simple_ondemand_init(void) | ||
131 | { | ||
132 | return devfreq_add_governor(&devfreq_simple_ondemand); | ||
133 | } | ||
134 | subsys_initcall(devfreq_simple_ondemand_init); | ||
135 | |||
136 | static void __exit devfreq_simple_ondemand_exit(void) | ||
137 | { | ||
138 | int ret; | ||
139 | |||
140 | ret = devfreq_remove_governor(&devfreq_simple_ondemand); | ||
141 | if (ret) | ||
142 | pr_err("%s: failed remove governor %d\n", __func__, ret); | ||
143 | |||
144 | return; | ||
145 | } | ||
146 | module_exit(devfreq_simple_ondemand_exit); | ||
147 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/devfreq/governor_userspace.c b/drivers/devfreq/governor_userspace.c index 0681246fc89d..35de6e83c1fe 100644 --- a/drivers/devfreq/governor_userspace.c +++ b/drivers/devfreq/governor_userspace.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/devfreq.h> | 14 | #include <linux/devfreq.h> |
15 | #include <linux/pm.h> | 15 | #include <linux/pm.h> |
16 | #include <linux/mutex.h> | 16 | #include <linux/mutex.h> |
17 | #include <linux/module.h> | ||
17 | #include "governor.h" | 18 | #include "governor.h" |
18 | 19 | ||
19 | struct userspace_data { | 20 | struct userspace_data { |
@@ -116,10 +117,46 @@ static void userspace_exit(struct devfreq *devfreq) | |||
116 | devfreq->data = NULL; | 117 | devfreq->data = NULL; |
117 | } | 118 | } |
118 | 119 | ||
119 | const struct devfreq_governor devfreq_userspace = { | 120 | static int devfreq_userspace_handler(struct devfreq *devfreq, |
121 | unsigned int event, void *data) | ||
122 | { | ||
123 | int ret = 0; | ||
124 | |||
125 | switch (event) { | ||
126 | case DEVFREQ_GOV_START: | ||
127 | ret = userspace_init(devfreq); | ||
128 | break; | ||
129 | case DEVFREQ_GOV_STOP: | ||
130 | userspace_exit(devfreq); | ||
131 | break; | ||
132 | default: | ||
133 | break; | ||
134 | } | ||
135 | |||
136 | return ret; | ||
137 | } | ||
138 | |||
139 | static struct devfreq_governor devfreq_userspace = { | ||
120 | .name = "userspace", | 140 | .name = "userspace", |
121 | .get_target_freq = devfreq_userspace_func, | 141 | .get_target_freq = devfreq_userspace_func, |
122 | .init = userspace_init, | 142 | .event_handler = devfreq_userspace_handler, |
123 | .exit = userspace_exit, | ||
124 | .no_central_polling = true, | ||
125 | }; | 143 | }; |
144 | |||
145 | static int __init devfreq_userspace_init(void) | ||
146 | { | ||
147 | return devfreq_add_governor(&devfreq_userspace); | ||
148 | } | ||
149 | subsys_initcall(devfreq_userspace_init); | ||
150 | |||
151 | static void __exit devfreq_userspace_exit(void) | ||
152 | { | ||
153 | int ret; | ||
154 | |||
155 | ret = devfreq_remove_governor(&devfreq_userspace); | ||
156 | if (ret) | ||
157 | pr_err("%s: failed remove governor %d\n", __func__, ret); | ||
158 | |||
159 | return; | ||
160 | } | ||
161 | module_exit(devfreq_userspace_exit); | ||
162 | MODULE_LICENSE("GPL"); | ||