diff options
author | Jiri Kosina <jkosina@suse.cz> | 2013-01-29 04:48:30 -0500 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2013-01-29 04:48:30 -0500 |
commit | 617677295b53a40d0e54aac4cbbc216ffbc755dd (patch) | |
tree | 51b9e87213243ed5efff252c8e8d8fec4eebc588 /drivers/devfreq | |
parent | 5c8d1b68e01a144813e38795fe6dbe7ebb506131 (diff) | |
parent | 6abb7c25775b7fb2225ad0508236d63ca710e65f (diff) |
Merge branch 'master' into for-next
Conflicts:
drivers/devfreq/exynos4_bus.c
Sync with Linus' tree to be able to apply patches that are
against newer code (mvneta).
Diffstat (limited to 'drivers/devfreq')
-rw-r--r-- | drivers/devfreq/Kconfig | 8 | ||||
-rw-r--r-- | drivers/devfreq/devfreq.c | 926 | ||||
-rw-r--r-- | drivers/devfreq/exynos4_bus.c | 145 | ||||
-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, 912 insertions, 360 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 b146d76f04cf..3b367973a802 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,10 +990,15 @@ 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 | * |
997 | * Locking: This function must be called under rcu_read_lock(). opp is a rcu | ||
998 | * protected pointer. The reason for the same is that the opp pointer which is | ||
999 | * returned will remain valid for use with opp_get_{voltage, freq} only while | ||
1000 | * under the locked area. The pointer returned must be used prior to unlocking | ||
1001 | * with rcu_read_unlock() to maintain the integrity of the pointer. | ||
648 | */ | 1002 | */ |
649 | struct opp *devfreq_recommended_opp(struct device *dev, unsigned long *freq, | 1003 | struct opp *devfreq_recommended_opp(struct device *dev, unsigned long *freq, |
650 | u32 flags) | 1004 | u32 flags) |
@@ -656,14 +1010,14 @@ struct opp *devfreq_recommended_opp(struct device *dev, unsigned long *freq, | |||
656 | opp = opp_find_freq_floor(dev, freq); | 1010 | opp = opp_find_freq_floor(dev, freq); |
657 | 1011 | ||
658 | /* If not available, use the closest opp */ | 1012 | /* If not available, use the closest opp */ |
659 | if (opp == ERR_PTR(-ENODEV)) | 1013 | if (opp == ERR_PTR(-ERANGE)) |
660 | opp = opp_find_freq_ceil(dev, freq); | 1014 | opp = opp_find_freq_ceil(dev, freq); |
661 | } else { | 1015 | } else { |
662 | /* The freq is an lower bound. opp should be higher */ | 1016 | /* The freq is an lower bound. opp should be higher */ |
663 | opp = opp_find_freq_ceil(dev, freq); | 1017 | opp = opp_find_freq_ceil(dev, freq); |
664 | 1018 | ||
665 | /* If not available, use the closest opp */ | 1019 | /* If not available, use the closest opp */ |
666 | if (opp == ERR_PTR(-ENODEV)) | 1020 | if (opp == ERR_PTR(-ERANGE)) |
667 | opp = opp_find_freq_floor(dev, freq); | 1021 | opp = opp_find_freq_floor(dev, freq); |
668 | } | 1022 | } |
669 | 1023 | ||
@@ -674,35 +1028,49 @@ struct opp *devfreq_recommended_opp(struct device *dev, unsigned long *freq, | |||
674 | * devfreq_register_opp_notifier() - Helper function to get devfreq notified | 1028 | * devfreq_register_opp_notifier() - Helper function to get devfreq notified |
675 | * for any changes in the OPP availability | 1029 | * for any changes in the OPP availability |
676 | * changes | 1030 | * changes |
677 | * @dev The devfreq user device. (parent of devfreq) | 1031 | * @dev: The devfreq user device. (parent of devfreq) |
678 | * @devfreq The devfreq object. | 1032 | * @devfreq: The devfreq object. |
679 | */ | 1033 | */ |
680 | int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq) | 1034 | int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq) |
681 | { | 1035 | { |
682 | struct srcu_notifier_head *nh = opp_get_notifier(dev); | 1036 | struct srcu_notifier_head *nh; |
1037 | int ret = 0; | ||
683 | 1038 | ||
1039 | rcu_read_lock(); | ||
1040 | nh = opp_get_notifier(dev); | ||
684 | if (IS_ERR(nh)) | 1041 | if (IS_ERR(nh)) |
685 | return PTR_ERR(nh); | 1042 | ret = PTR_ERR(nh); |
686 | return srcu_notifier_chain_register(nh, &devfreq->nb); | 1043 | rcu_read_unlock(); |
1044 | if (!ret) | ||
1045 | ret = srcu_notifier_chain_register(nh, &devfreq->nb); | ||
1046 | |||
1047 | return ret; | ||
687 | } | 1048 | } |
688 | 1049 | ||
689 | /** | 1050 | /** |
690 | * devfreq_unregister_opp_notifier() - Helper function to stop getting devfreq | 1051 | * devfreq_unregister_opp_notifier() - Helper function to stop getting devfreq |
691 | * notified for any changes in the OPP | 1052 | * notified for any changes in the OPP |
692 | * availability changes anymore. | 1053 | * availability changes anymore. |
693 | * @dev The devfreq user device. (parent of devfreq) | 1054 | * @dev: The devfreq user device. (parent of devfreq) |
694 | * @devfreq The devfreq object. | 1055 | * @devfreq: The devfreq object. |
695 | * | 1056 | * |
696 | * At exit() callback of devfreq_dev_profile, this must be included if | 1057 | * At exit() callback of devfreq_dev_profile, this must be included if |
697 | * devfreq_recommended_opp is used. | 1058 | * devfreq_recommended_opp is used. |
698 | */ | 1059 | */ |
699 | int devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq) | 1060 | int devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq) |
700 | { | 1061 | { |
701 | struct srcu_notifier_head *nh = opp_get_notifier(dev); | 1062 | struct srcu_notifier_head *nh; |
1063 | int ret = 0; | ||
702 | 1064 | ||
1065 | rcu_read_lock(); | ||
1066 | nh = opp_get_notifier(dev); | ||
703 | if (IS_ERR(nh)) | 1067 | if (IS_ERR(nh)) |
704 | return PTR_ERR(nh); | 1068 | ret = PTR_ERR(nh); |
705 | return srcu_notifier_chain_unregister(nh, &devfreq->nb); | 1069 | rcu_read_unlock(); |
1070 | if (!ret) | ||
1071 | ret = srcu_notifier_chain_unregister(nh, &devfreq->nb); | ||
1072 | |||
1073 | return ret; | ||
706 | } | 1074 | } |
707 | 1075 | ||
708 | MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); | 1076 | MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); |
diff --git a/drivers/devfreq/exynos4_bus.c b/drivers/devfreq/exynos4_bus.c index e1ac076c2917..3f37f3b3f268 100644 --- a/drivers/devfreq/exynos4_bus.c +++ b/drivers/devfreq/exynos4_bus.c | |||
@@ -73,6 +73,16 @@ enum busclk_level_idx { | |||
73 | #define EX4210_LV_NUM (LV_2 + 1) | 73 | #define EX4210_LV_NUM (LV_2 + 1) |
74 | #define EX4x12_LV_NUM (LV_4 + 1) | 74 | #define EX4x12_LV_NUM (LV_4 + 1) |
75 | 75 | ||
76 | /** | ||
77 | * struct busfreq_opp_info - opp information for bus | ||
78 | * @rate: Frequency in hertz | ||
79 | * @volt: Voltage in microvolts corresponding to this OPP | ||
80 | */ | ||
81 | struct busfreq_opp_info { | ||
82 | unsigned long rate; | ||
83 | unsigned long volt; | ||
84 | }; | ||
85 | |||
76 | struct busfreq_data { | 86 | struct busfreq_data { |
77 | enum exynos4_busf_type type; | 87 | enum exynos4_busf_type type; |
78 | struct device *dev; | 88 | struct device *dev; |
@@ -80,7 +90,7 @@ struct busfreq_data { | |||
80 | bool disabled; | 90 | bool disabled; |
81 | struct regulator *vdd_int; | 91 | struct regulator *vdd_int; |
82 | struct regulator *vdd_mif; /* Exynos4412/4212 only */ | 92 | struct regulator *vdd_mif; /* Exynos4412/4212 only */ |
83 | struct opp *curr_opp; | 93 | struct busfreq_opp_info curr_oppinfo; |
84 | struct exynos4_ppmu dmc[2]; | 94 | struct exynos4_ppmu dmc[2]; |
85 | 95 | ||
86 | struct notifier_block pm_notifier; | 96 | struct notifier_block pm_notifier; |
@@ -296,13 +306,14 @@ static unsigned int exynos4x12_clkdiv_sclkip[][3] = { | |||
296 | }; | 306 | }; |
297 | 307 | ||
298 | 308 | ||
299 | static int exynos4210_set_busclk(struct busfreq_data *data, struct opp *opp) | 309 | static int exynos4210_set_busclk(struct busfreq_data *data, |
310 | struct busfreq_opp_info *oppi) | ||
300 | { | 311 | { |
301 | unsigned int index; | 312 | unsigned int index; |
302 | unsigned int tmp; | 313 | unsigned int tmp; |
303 | 314 | ||
304 | for (index = LV_0; index < EX4210_LV_NUM; index++) | 315 | for (index = LV_0; index < EX4210_LV_NUM; index++) |
305 | if (opp_get_freq(opp) == exynos4210_busclk_table[index].clk) | 316 | if (oppi->rate == exynos4210_busclk_table[index].clk) |
306 | break; | 317 | break; |
307 | 318 | ||
308 | if (index == EX4210_LV_NUM) | 319 | if (index == EX4210_LV_NUM) |
@@ -361,13 +372,14 @@ static int exynos4210_set_busclk(struct busfreq_data *data, struct opp *opp) | |||
361 | return 0; | 372 | return 0; |
362 | } | 373 | } |
363 | 374 | ||
364 | static int exynos4x12_set_busclk(struct busfreq_data *data, struct opp *opp) | 375 | static int exynos4x12_set_busclk(struct busfreq_data *data, |
376 | struct busfreq_opp_info *oppi) | ||
365 | { | 377 | { |
366 | unsigned int index; | 378 | unsigned int index; |
367 | unsigned int tmp; | 379 | unsigned int tmp; |
368 | 380 | ||
369 | for (index = LV_0; index < EX4x12_LV_NUM; index++) | 381 | for (index = LV_0; index < EX4x12_LV_NUM; index++) |
370 | if (opp_get_freq(opp) == exynos4x12_mifclk_table[index].clk) | 382 | if (oppi->rate == exynos4x12_mifclk_table[index].clk) |
371 | break; | 383 | break; |
372 | 384 | ||
373 | if (index == EX4x12_LV_NUM) | 385 | if (index == EX4x12_LV_NUM) |
@@ -576,11 +588,12 @@ static int exynos4x12_get_intspec(unsigned long mifclk) | |||
576 | return -EINVAL; | 588 | return -EINVAL; |
577 | } | 589 | } |
578 | 590 | ||
579 | static int exynos4_bus_setvolt(struct busfreq_data *data, struct opp *opp, | 591 | static int exynos4_bus_setvolt(struct busfreq_data *data, |
580 | struct opp *oldopp) | 592 | struct busfreq_opp_info *oppi, |
593 | struct busfreq_opp_info *oldoppi) | ||
581 | { | 594 | { |
582 | int err = 0, tmp; | 595 | int err = 0, tmp; |
583 | unsigned long volt = opp_get_voltage(opp); | 596 | unsigned long volt = oppi->volt; |
584 | 597 | ||
585 | switch (data->type) { | 598 | switch (data->type) { |
586 | case TYPE_BUSF_EXYNOS4210: | 599 | case TYPE_BUSF_EXYNOS4210: |
@@ -595,11 +608,11 @@ static int exynos4_bus_setvolt(struct busfreq_data *data, struct opp *opp, | |||
595 | if (err) | 608 | if (err) |
596 | break; | 609 | break; |
597 | 610 | ||
598 | tmp = exynos4x12_get_intspec(opp_get_freq(opp)); | 611 | tmp = exynos4x12_get_intspec(oppi->rate); |
599 | if (tmp < 0) { | 612 | if (tmp < 0) { |
600 | err = tmp; | 613 | err = tmp; |
601 | regulator_set_voltage(data->vdd_mif, | 614 | regulator_set_voltage(data->vdd_mif, |
602 | opp_get_voltage(oldopp), | 615 | oldoppi->volt, |
603 | MAX_SAFEVOLT); | 616 | MAX_SAFEVOLT); |
604 | break; | 617 | break; |
605 | } | 618 | } |
@@ -609,7 +622,7 @@ static int exynos4_bus_setvolt(struct busfreq_data *data, struct opp *opp, | |||
609 | /* Try to recover */ | 622 | /* Try to recover */ |
610 | if (err) | 623 | if (err) |
611 | regulator_set_voltage(data->vdd_mif, | 624 | regulator_set_voltage(data->vdd_mif, |
612 | opp_get_voltage(oldopp), | 625 | oldoppi->volt, |
613 | MAX_SAFEVOLT); | 626 | MAX_SAFEVOLT); |
614 | break; | 627 | break; |
615 | default: | 628 | default: |
@@ -626,17 +639,26 @@ static int exynos4_bus_target(struct device *dev, unsigned long *_freq, | |||
626 | struct platform_device *pdev = container_of(dev, struct platform_device, | 639 | struct platform_device *pdev = container_of(dev, struct platform_device, |
627 | dev); | 640 | dev); |
628 | struct busfreq_data *data = platform_get_drvdata(pdev); | 641 | struct busfreq_data *data = platform_get_drvdata(pdev); |
629 | struct opp *opp = devfreq_recommended_opp(dev, _freq, flags); | 642 | struct opp *opp; |
630 | unsigned long freq = opp_get_freq(opp); | 643 | unsigned long freq; |
631 | unsigned long old_freq = opp_get_freq(data->curr_opp); | 644 | unsigned long old_freq = data->curr_oppinfo.rate; |
645 | struct busfreq_opp_info new_oppinfo; | ||
632 | 646 | ||
633 | if (IS_ERR(opp)) | 647 | rcu_read_lock(); |
648 | opp = devfreq_recommended_opp(dev, _freq, flags); | ||
649 | if (IS_ERR(opp)) { | ||
650 | rcu_read_unlock(); | ||
634 | return PTR_ERR(opp); | 651 | return PTR_ERR(opp); |
652 | } | ||
653 | new_oppinfo.rate = opp_get_freq(opp); | ||
654 | new_oppinfo.volt = opp_get_voltage(opp); | ||
655 | rcu_read_unlock(); | ||
656 | freq = new_oppinfo.rate; | ||
635 | 657 | ||
636 | if (old_freq == freq) | 658 | if (old_freq == freq) |
637 | return 0; | 659 | return 0; |
638 | 660 | ||
639 | dev_dbg(dev, "targeting %lukHz %luuV\n", freq, opp_get_voltage(opp)); | 661 | dev_dbg(dev, "targeting %lukHz %luuV\n", freq, new_oppinfo.volt); |
640 | 662 | ||
641 | mutex_lock(&data->lock); | 663 | mutex_lock(&data->lock); |
642 | 664 | ||
@@ -644,17 +666,18 @@ static int exynos4_bus_target(struct device *dev, unsigned long *_freq, | |||
644 | goto out; | 666 | goto out; |
645 | 667 | ||
646 | if (old_freq < freq) | 668 | if (old_freq < freq) |
647 | err = exynos4_bus_setvolt(data, opp, data->curr_opp); | 669 | err = exynos4_bus_setvolt(data, &new_oppinfo, |
670 | &data->curr_oppinfo); | ||
648 | if (err) | 671 | if (err) |
649 | goto out; | 672 | goto out; |
650 | 673 | ||
651 | if (old_freq != freq) { | 674 | if (old_freq != freq) { |
652 | switch (data->type) { | 675 | switch (data->type) { |
653 | case TYPE_BUSF_EXYNOS4210: | 676 | case TYPE_BUSF_EXYNOS4210: |
654 | err = exynos4210_set_busclk(data, opp); | 677 | err = exynos4210_set_busclk(data, &new_oppinfo); |
655 | break; | 678 | break; |
656 | case TYPE_BUSF_EXYNOS4x12: | 679 | case TYPE_BUSF_EXYNOS4x12: |
657 | err = exynos4x12_set_busclk(data, opp); | 680 | err = exynos4x12_set_busclk(data, &new_oppinfo); |
658 | break; | 681 | break; |
659 | default: | 682 | default: |
660 | err = -EINVAL; | 683 | err = -EINVAL; |
@@ -664,11 +687,12 @@ static int exynos4_bus_target(struct device *dev, unsigned long *_freq, | |||
664 | goto out; | 687 | goto out; |
665 | 688 | ||
666 | if (old_freq > freq) | 689 | if (old_freq > freq) |
667 | err = exynos4_bus_setvolt(data, opp, data->curr_opp); | 690 | err = exynos4_bus_setvolt(data, &new_oppinfo, |
691 | &data->curr_oppinfo); | ||
668 | if (err) | 692 | if (err) |
669 | goto out; | 693 | goto out; |
670 | 694 | ||
671 | data->curr_opp = opp; | 695 | data->curr_oppinfo = new_oppinfo; |
672 | out: | 696 | out: |
673 | mutex_unlock(&data->lock); | 697 | mutex_unlock(&data->lock); |
674 | return err; | 698 | return err; |
@@ -702,7 +726,7 @@ static int exynos4_bus_get_dev_status(struct device *dev, | |||
702 | 726 | ||
703 | exynos4_read_ppmu(data); | 727 | exynos4_read_ppmu(data); |
704 | busier_dmc = exynos4_get_busier_dmc(data); | 728 | busier_dmc = exynos4_get_busier_dmc(data); |
705 | stat->current_frequency = opp_get_freq(data->curr_opp); | 729 | stat->current_frequency = data->curr_oppinfo.rate; |
706 | 730 | ||
707 | if (busier_dmc) | 731 | if (busier_dmc) |
708 | addr = S5P_VA_DMC1; | 732 | addr = S5P_VA_DMC1; |
@@ -933,6 +957,7 @@ static int exynos4_busfreq_pm_notifier_event(struct notifier_block *this, | |||
933 | struct busfreq_data *data = container_of(this, struct busfreq_data, | 957 | struct busfreq_data *data = container_of(this, struct busfreq_data, |
934 | pm_notifier); | 958 | pm_notifier); |
935 | struct opp *opp; | 959 | struct opp *opp; |
960 | struct busfreq_opp_info new_oppinfo; | ||
936 | unsigned long maxfreq = ULONG_MAX; | 961 | unsigned long maxfreq = ULONG_MAX; |
937 | int err = 0; | 962 | int err = 0; |
938 | 963 | ||
@@ -943,18 +968,29 @@ static int exynos4_busfreq_pm_notifier_event(struct notifier_block *this, | |||
943 | 968 | ||
944 | data->disabled = true; | 969 | data->disabled = true; |
945 | 970 | ||
971 | rcu_read_lock(); | ||
946 | opp = opp_find_freq_floor(data->dev, &maxfreq); | 972 | opp = opp_find_freq_floor(data->dev, &maxfreq); |
973 | if (IS_ERR(opp)) { | ||
974 | rcu_read_unlock(); | ||
975 | dev_err(data->dev, "%s: unable to find a min freq\n", | ||
976 | __func__); | ||
977 | return PTR_ERR(opp); | ||
978 | } | ||
979 | new_oppinfo.rate = opp_get_freq(opp); | ||
980 | new_oppinfo.volt = opp_get_voltage(opp); | ||
981 | rcu_read_unlock(); | ||
947 | 982 | ||
948 | err = exynos4_bus_setvolt(data, opp, data->curr_opp); | 983 | err = exynos4_bus_setvolt(data, &new_oppinfo, |
984 | &data->curr_oppinfo); | ||
949 | if (err) | 985 | if (err) |
950 | goto unlock; | 986 | goto unlock; |
951 | 987 | ||
952 | switch (data->type) { | 988 | switch (data->type) { |
953 | case TYPE_BUSF_EXYNOS4210: | 989 | case TYPE_BUSF_EXYNOS4210: |
954 | err = exynos4210_set_busclk(data, opp); | 990 | err = exynos4210_set_busclk(data, &new_oppinfo); |
955 | break; | 991 | break; |
956 | case TYPE_BUSF_EXYNOS4x12: | 992 | case TYPE_BUSF_EXYNOS4x12: |
957 | err = exynos4x12_set_busclk(data, opp); | 993 | err = exynos4x12_set_busclk(data, &new_oppinfo); |
958 | break; | 994 | break; |
959 | default: | 995 | default: |
960 | err = -EINVAL; | 996 | err = -EINVAL; |
@@ -962,7 +998,7 @@ static int exynos4_busfreq_pm_notifier_event(struct notifier_block *this, | |||
962 | if (err) | 998 | if (err) |
963 | goto unlock; | 999 | goto unlock; |
964 | 1000 | ||
965 | data->curr_opp = opp; | 1001 | data->curr_oppinfo = new_oppinfo; |
966 | unlock: | 1002 | unlock: |
967 | mutex_unlock(&data->lock); | 1003 | mutex_unlock(&data->lock); |
968 | if (err) | 1004 | if (err) |
@@ -980,14 +1016,14 @@ unlock: | |||
980 | return NOTIFY_DONE; | 1016 | return NOTIFY_DONE; |
981 | } | 1017 | } |
982 | 1018 | ||
983 | static __devinit int exynos4_busfreq_probe(struct platform_device *pdev) | 1019 | static int exynos4_busfreq_probe(struct platform_device *pdev) |
984 | { | 1020 | { |
985 | struct busfreq_data *data; | 1021 | struct busfreq_data *data; |
986 | struct opp *opp; | 1022 | struct opp *opp; |
987 | struct device *dev = &pdev->dev; | 1023 | struct device *dev = &pdev->dev; |
988 | int err = 0; | 1024 | int err = 0; |
989 | 1025 | ||
990 | data = kzalloc(sizeof(struct busfreq_data), GFP_KERNEL); | 1026 | data = devm_kzalloc(&pdev->dev, sizeof(struct busfreq_data), GFP_KERNEL); |
991 | if (data == NULL) { | 1027 | if (data == NULL) { |
992 | dev_err(dev, "Cannot allocate memory.\n"); | 1028 | dev_err(dev, "Cannot allocate memory.\n"); |
993 | return -ENOMEM; | 1029 | return -ENOMEM; |
@@ -1012,75 +1048,60 @@ static __devinit int exynos4_busfreq_probe(struct platform_device *pdev) | |||
1012 | err = -EINVAL; | 1048 | err = -EINVAL; |
1013 | } | 1049 | } |
1014 | if (err) | 1050 | if (err) |
1015 | goto err_regulator; | 1051 | return err; |
1016 | 1052 | ||
1017 | data->vdd_int = regulator_get(dev, "vdd_int"); | 1053 | data->vdd_int = devm_regulator_get(dev, "vdd_int"); |
1018 | if (IS_ERR(data->vdd_int)) { | 1054 | if (IS_ERR(data->vdd_int)) { |
1019 | dev_err(dev, "Cannot get the regulator \"vdd_int\"\n"); | 1055 | dev_err(dev, "Cannot get the regulator \"vdd_int\"\n"); |
1020 | err = PTR_ERR(data->vdd_int); | 1056 | return PTR_ERR(data->vdd_int); |
1021 | goto err_regulator; | ||
1022 | } | 1057 | } |
1023 | if (data->type == TYPE_BUSF_EXYNOS4x12) { | 1058 | if (data->type == TYPE_BUSF_EXYNOS4x12) { |
1024 | data->vdd_mif = regulator_get(dev, "vdd_mif"); | 1059 | data->vdd_mif = devm_regulator_get(dev, "vdd_mif"); |
1025 | if (IS_ERR(data->vdd_mif)) { | 1060 | if (IS_ERR(data->vdd_mif)) { |
1026 | dev_err(dev, "Cannot get the regulator \"vdd_mif\"\n"); | 1061 | dev_err(dev, "Cannot get the regulator \"vdd_mif\"\n"); |
1027 | err = PTR_ERR(data->vdd_mif); | 1062 | return PTR_ERR(data->vdd_mif); |
1028 | regulator_put(data->vdd_int); | ||
1029 | goto err_regulator; | ||
1030 | |||
1031 | } | 1063 | } |
1032 | } | 1064 | } |
1033 | 1065 | ||
1066 | rcu_read_lock(); | ||
1034 | opp = opp_find_freq_floor(dev, &exynos4_devfreq_profile.initial_freq); | 1067 | opp = opp_find_freq_floor(dev, &exynos4_devfreq_profile.initial_freq); |
1035 | if (IS_ERR(opp)) { | 1068 | if (IS_ERR(opp)) { |
1069 | rcu_read_unlock(); | ||
1036 | dev_err(dev, "Invalid initial frequency %lu kHz.\n", | 1070 | dev_err(dev, "Invalid initial frequency %lu kHz.\n", |
1037 | exynos4_devfreq_profile.initial_freq); | 1071 | exynos4_devfreq_profile.initial_freq); |
1038 | err = PTR_ERR(opp); | 1072 | return PTR_ERR(opp); |
1039 | goto err_opp_add; | ||
1040 | } | 1073 | } |
1041 | data->curr_opp = opp; | 1074 | data->curr_oppinfo.rate = opp_get_freq(opp); |
1075 | data->curr_oppinfo.volt = opp_get_voltage(opp); | ||
1076 | rcu_read_unlock(); | ||
1042 | 1077 | ||
1043 | platform_set_drvdata(pdev, data); | 1078 | platform_set_drvdata(pdev, data); |
1044 | 1079 | ||
1045 | busfreq_mon_reset(data); | 1080 | busfreq_mon_reset(data); |
1046 | 1081 | ||
1047 | data->devfreq = devfreq_add_device(dev, &exynos4_devfreq_profile, | 1082 | data->devfreq = devfreq_add_device(dev, &exynos4_devfreq_profile, |
1048 | &devfreq_simple_ondemand, NULL); | 1083 | "simple_ondemand", NULL); |
1049 | if (IS_ERR(data->devfreq)) { | 1084 | if (IS_ERR(data->devfreq)) |
1050 | err = PTR_ERR(data->devfreq); | 1085 | return PTR_ERR(data->devfreq); |
1051 | goto err_opp_add; | ||
1052 | } | ||
1053 | 1086 | ||
1054 | devfreq_register_opp_notifier(dev, data->devfreq); | 1087 | devfreq_register_opp_notifier(dev, data->devfreq); |
1055 | 1088 | ||
1056 | err = register_pm_notifier(&data->pm_notifier); | 1089 | err = register_pm_notifier(&data->pm_notifier); |
1057 | if (err) { | 1090 | if (err) { |
1058 | dev_err(dev, "Failed to setup pm notifier\n"); | 1091 | dev_err(dev, "Failed to setup pm notifier\n"); |
1059 | goto err_devfreq_add; | 1092 | devfreq_remove_device(data->devfreq); |
1093 | return err; | ||
1060 | } | 1094 | } |
1061 | 1095 | ||
1062 | return 0; | 1096 | 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 | } | 1097 | } |
1073 | 1098 | ||
1074 | static __devexit int exynos4_busfreq_remove(struct platform_device *pdev) | 1099 | static int exynos4_busfreq_remove(struct platform_device *pdev) |
1075 | { | 1100 | { |
1076 | struct busfreq_data *data = platform_get_drvdata(pdev); | 1101 | struct busfreq_data *data = platform_get_drvdata(pdev); |
1077 | 1102 | ||
1078 | unregister_pm_notifier(&data->pm_notifier); | 1103 | unregister_pm_notifier(&data->pm_notifier); |
1079 | devfreq_remove_device(data->devfreq); | 1104 | 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 | 1105 | ||
1085 | return 0; | 1106 | return 0; |
1086 | } | 1107 | } |
@@ -1106,7 +1127,7 @@ static const struct platform_device_id exynos4_busfreq_id[] = { | |||
1106 | 1127 | ||
1107 | static struct platform_driver exynos4_busfreq_driver = { | 1128 | static struct platform_driver exynos4_busfreq_driver = { |
1108 | .probe = exynos4_busfreq_probe, | 1129 | .probe = exynos4_busfreq_probe, |
1109 | .remove = __devexit_p(exynos4_busfreq_remove), | 1130 | .remove = exynos4_busfreq_remove, |
1110 | .id_table = exynos4_busfreq_id, | 1131 | .id_table = exynos4_busfreq_id, |
1111 | .driver = { | 1132 | .driver = { |
1112 | .name = "exynos4-busfreq", | 1133 | .name = "exynos4-busfreq", |
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"); | ||