blob: abfa14dd8b4c992317a90b22471fa4e3d710111a [file] [log] [blame]
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001/*
2 * devfreq: Generic Dynamic Voltage and Frequency Scaling (DVFS) Framework
3 * for Non-CPU Devices.
4 *
5 * Copyright (C) 2011 Samsung Electronics
6 * MyungJoo Ham <myungjoo.ham@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/kernel.h>
14#include <linux/sched.h>
15#include <linux/errno.h>
16#include <linux/err.h>
17#include <linux/init.h>
MyungJoo Ham952f6d12011-11-10 10:16:23 +010018#include <linux/module.h>
MyungJoo Hama3c98b82011-10-02 00:19:15 +020019#include <linux/slab.h>
MyungJoo Ham952f6d12011-11-10 10:16:23 +010020#include <linux/stat.h>
MyungJoo Hama3c98b82011-10-02 00:19:15 +020021#include <linux/opp.h>
22#include <linux/devfreq.h>
23#include <linux/workqueue.h>
24#include <linux/platform_device.h>
25#include <linux/list.h>
26#include <linux/printk.h>
27#include <linux/hrtimer.h>
28#include "governor.h"
29
Nishanth Menon1a1357e2012-10-26 01:50:53 +020030static struct class *devfreq_class;
MyungJoo Hama3c98b82011-10-02 00:19:15 +020031
32/*
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +020033 * devfreq core provides delayed work based load monitoring helper
34 * functions. Governors can use these or can implement their own
35 * monitoring mechanism.
MyungJoo Hama3c98b82011-10-02 00:19:15 +020036 */
MyungJoo Hama3c98b82011-10-02 00:19:15 +020037static struct workqueue_struct *devfreq_wq;
MyungJoo Hama3c98b82011-10-02 00:19:15 +020038
Nishanth Menon3aa173b2012-10-29 15:01:43 -050039/* The list of all device-devfreq governors */
40static LIST_HEAD(devfreq_governor_list);
MyungJoo Hama3c98b82011-10-02 00:19:15 +020041/* The list of all device-devfreq */
42static LIST_HEAD(devfreq_list);
43static DEFINE_MUTEX(devfreq_list_lock);
44
45/**
46 * find_device_devfreq() - find devfreq struct using device pointer
47 * @dev: device pointer used to lookup device devfreq.
48 *
49 * Search the list of device devfreqs and return the matched device's
50 * devfreq info. devfreq_list_lock should be held by the caller.
51 */
52static struct devfreq *find_device_devfreq(struct device *dev)
53{
54 struct devfreq *tmp_devfreq;
55
56 if (unlikely(IS_ERR_OR_NULL(dev))) {
57 pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
58 return ERR_PTR(-EINVAL);
59 }
60 WARN(!mutex_is_locked(&devfreq_list_lock),
61 "devfreq_list_lock must be locked.");
62
63 list_for_each_entry(tmp_devfreq, &devfreq_list, node) {
64 if (tmp_devfreq->dev.parent == dev)
65 return tmp_devfreq;
66 }
67
68 return ERR_PTR(-ENODEV);
69}
70
71/**
Jonghwa Leee552bba2012-08-23 20:00:46 +090072 * devfreq_get_freq_level() - Lookup freq_table for the frequency
73 * @devfreq: the devfreq instance
74 * @freq: the target frequency
75 */
76static 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 */
92static 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
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500116/**
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 */
123static 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
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200142/* Load monitoring helper functions for governors use */
143
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200144/**
145 * update_devfreq() - Reevaluate the device and configure frequency.
146 * @devfreq: the devfreq instance.
147 *
148 * Note: Lock devfreq->lock before calling update_devfreq
149 * This function is exported for governors.
150 */
151int update_devfreq(struct devfreq *devfreq)
152{
153 unsigned long freq;
154 int err = 0;
MyungJoo Hamab5f2992012-03-16 21:54:53 +0100155 u32 flags = 0;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200156
157 if (!mutex_is_locked(&devfreq->lock)) {
158 WARN(true, "devfreq->lock must be locked by the caller.\n");
159 return -EINVAL;
160 }
161
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500162 if (!devfreq->governor)
163 return -EINVAL;
164
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200165 /* Reevaluate the proper frequency */
166 err = devfreq->governor->get_target_freq(devfreq, &freq);
167 if (err)
168 return err;
169
MyungJoo Hamab5f2992012-03-16 21:54:53 +0100170 /*
171 * Adjust the freuqency with user freq and QoS.
172 *
173 * List from the highest proiority
174 * max_freq (probably called by thermal when it's too hot)
175 * min_freq
176 */
177
178 if (devfreq->min_freq && freq < devfreq->min_freq) {
179 freq = devfreq->min_freq;
180 flags &= ~DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use GLB */
181 }
182 if (devfreq->max_freq && freq > devfreq->max_freq) {
183 freq = devfreq->max_freq;
184 flags |= DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use LUB */
185 }
186
187 err = devfreq->profile->target(devfreq->dev.parent, &freq, flags);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200188 if (err)
189 return err;
190
Jonghwa Leee552bba2012-08-23 20:00:46 +0900191 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
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200196 devfreq->previous_freq = freq;
197 return err;
198}
Nishanth Menon2df50212012-10-29 15:01:42 -0500199EXPORT_SYMBOL(update_devfreq);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200200
201/**
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200202 * devfreq_monitor() - Periodically poll devfreq objects.
203 * @work: the work struct used to run devfreq_monitor periodically.
204 *
205 */
206static 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 */
231void 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}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100238EXPORT_SYMBOL(devfreq_monitor_start);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200239
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 */
248void devfreq_monitor_stop(struct devfreq *devfreq)
249{
250 cancel_delayed_work_sync(&devfreq->work);
251}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100252EXPORT_SYMBOL(devfreq_monitor_stop);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200253
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 */
266void 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
Rajagopal Venkat39688ce62013-01-08 11:20:39 +0530274 devfreq_update_status(devfreq, devfreq->previous_freq);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200275 devfreq->stop_polling = true;
276 mutex_unlock(&devfreq->lock);
277 cancel_delayed_work_sync(&devfreq->work);
278}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100279EXPORT_SYMBOL(devfreq_monitor_suspend);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200280
281/**
282 * devfreq_monitor_resume() - Resume load monitoring of a devfreq instance
283 * @devfreq: the devfreq instance.
284 *
285 * Helper function to resume devfreq device load monitoing. Function
286 * to be called from governor in response to DEVFREQ_GOV_RESUME
287 * event or when polling interval is set to non-zero.
288 */
289void devfreq_monitor_resume(struct devfreq *devfreq)
290{
Rajagopal Venkat39688ce62013-01-08 11:20:39 +0530291 unsigned long freq;
292
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200293 mutex_lock(&devfreq->lock);
294 if (!devfreq->stop_polling)
295 goto out;
296
297 if (!delayed_work_pending(&devfreq->work) &&
298 devfreq->profile->polling_ms)
299 queue_delayed_work(devfreq_wq, &devfreq->work,
300 msecs_to_jiffies(devfreq->profile->polling_ms));
Rajagopal Venkat39688ce62013-01-08 11:20:39 +0530301
302 devfreq->last_stat_updated = jiffies;
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200303 devfreq->stop_polling = false;
304
Rajagopal Venkat39688ce62013-01-08 11:20:39 +0530305 if (devfreq->profile->get_cur_freq &&
306 !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
307 devfreq->previous_freq = freq;
308
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200309out:
310 mutex_unlock(&devfreq->lock);
311}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100312EXPORT_SYMBOL(devfreq_monitor_resume);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200313
314/**
315 * devfreq_interval_update() - Update device devfreq monitoring interval
316 * @devfreq: the devfreq instance.
317 * @delay: new polling interval to be set.
318 *
319 * Helper function to set new load monitoring polling interval. Function
320 * to be called from governor in response to DEVFREQ_GOV_INTERVAL event.
321 */
322void devfreq_interval_update(struct devfreq *devfreq, unsigned int *delay)
323{
324 unsigned int cur_delay = devfreq->profile->polling_ms;
325 unsigned int new_delay = *delay;
326
327 mutex_lock(&devfreq->lock);
328 devfreq->profile->polling_ms = new_delay;
329
330 if (devfreq->stop_polling)
331 goto out;
332
333 /* if new delay is zero, stop polling */
334 if (!new_delay) {
335 mutex_unlock(&devfreq->lock);
336 cancel_delayed_work_sync(&devfreq->work);
337 return;
338 }
339
340 /* if current delay is zero, start polling with new delay */
341 if (!cur_delay) {
342 queue_delayed_work(devfreq_wq, &devfreq->work,
343 msecs_to_jiffies(devfreq->profile->polling_ms));
344 goto out;
345 }
346
347 /* if current delay is greater than new delay, restart polling */
348 if (cur_delay > new_delay) {
349 mutex_unlock(&devfreq->lock);
350 cancel_delayed_work_sync(&devfreq->work);
351 mutex_lock(&devfreq->lock);
352 if (!devfreq->stop_polling)
353 queue_delayed_work(devfreq_wq, &devfreq->work,
354 msecs_to_jiffies(devfreq->profile->polling_ms));
355 }
356out:
357 mutex_unlock(&devfreq->lock);
358}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100359EXPORT_SYMBOL(devfreq_interval_update);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200360
361/**
362 * devfreq_notifier_call() - Notify that the device frequency requirements
363 * has been changed out of devfreq framework.
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +0200364 * @nb: the notifier_block (supposed to be devfreq->nb)
365 * @type: not used
366 * @devp: not used
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200367 *
368 * Called by a notifier that uses devfreq->nb.
369 */
370static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type,
371 void *devp)
372{
373 struct devfreq *devfreq = container_of(nb, struct devfreq, nb);
374 int ret;
375
376 mutex_lock(&devfreq->lock);
377 ret = update_devfreq(devfreq);
378 mutex_unlock(&devfreq->lock);
379
380 return ret;
381}
382
383/**
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200384 * _remove_devfreq() - Remove devfreq from the list and release its resources.
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200385 * @devfreq: the devfreq struct
386 * @skip: skip calling device_unregister().
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200387 */
388static void _remove_devfreq(struct devfreq *devfreq, bool skip)
389{
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200390 mutex_lock(&devfreq_list_lock);
391 if (IS_ERR(find_device_devfreq(devfreq->dev.parent))) {
392 mutex_unlock(&devfreq_list_lock);
393 dev_warn(&devfreq->dev, "releasing devfreq which doesn't exist\n");
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200394 return;
395 }
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200396 list_del(&devfreq->node);
397 mutex_unlock(&devfreq_list_lock);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200398
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500399 if (devfreq->governor)
400 devfreq->governor->event_handler(devfreq,
401 DEVFREQ_GOV_STOP, NULL);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200402
403 if (devfreq->profile->exit)
404 devfreq->profile->exit(devfreq->dev.parent);
405
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200406 if (!skip && get_device(&devfreq->dev)) {
407 device_unregister(&devfreq->dev);
408 put_device(&devfreq->dev);
409 }
410
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200411 mutex_destroy(&devfreq->lock);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200412 kfree(devfreq);
413}
414
415/**
416 * devfreq_dev_release() - Callback for struct device to release the device.
417 * @dev: the devfreq device
418 *
419 * This calls _remove_devfreq() if _remove_devfreq() is not called.
420 * Note that devfreq_dev_release() could be called by _remove_devfreq() as
421 * well as by others unregistering the device.
422 */
423static void devfreq_dev_release(struct device *dev)
424{
425 struct devfreq *devfreq = to_devfreq(dev);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200426
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200427 _remove_devfreq(devfreq, true);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200428}
429
430/**
431 * devfreq_add_device() - Add devfreq feature to the device
432 * @dev: the device to add devfreq feature.
433 * @profile: device-specific profile to run devfreq.
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500434 * @governor_name: name of the policy to choose frequency.
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200435 * @data: private data for the governor. The devfreq framework does not
436 * touch this value.
437 */
438struct devfreq *devfreq_add_device(struct device *dev,
439 struct devfreq_dev_profile *profile,
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500440 const char *governor_name,
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200441 void *data)
442{
443 struct devfreq *devfreq;
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500444 struct devfreq_governor *governor;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200445 int err = 0;
446
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500447 if (!dev || !profile || !governor_name) {
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200448 dev_err(dev, "%s: Invalid parameters.\n", __func__);
449 return ERR_PTR(-EINVAL);
450 }
451
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200452 mutex_lock(&devfreq_list_lock);
453 devfreq = find_device_devfreq(dev);
454 mutex_unlock(&devfreq_list_lock);
455 if (!IS_ERR(devfreq)) {
456 dev_err(dev, "%s: Unable to create devfreq for the device. It already has one.\n", __func__);
457 err = -EINVAL;
458 goto err_out;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200459 }
460
461 devfreq = kzalloc(sizeof(struct devfreq), GFP_KERNEL);
462 if (!devfreq) {
463 dev_err(dev, "%s: Unable to create devfreq for the device\n",
464 __func__);
465 err = -ENOMEM;
Axel Lin3f19f082011-11-15 21:59:09 +0100466 goto err_out;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200467 }
468
469 mutex_init(&devfreq->lock);
470 mutex_lock(&devfreq->lock);
471 devfreq->dev.parent = dev;
472 devfreq->dev.class = devfreq_class;
473 devfreq->dev.release = devfreq_dev_release;
474 devfreq->profile = profile;
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500475 strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200476 devfreq->previous_freq = profile->initial_freq;
477 devfreq->data = data;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200478 devfreq->nb.notifier_call = devfreq_notifier_call;
479
Jonghwa Leee552bba2012-08-23 20:00:46 +0900480 devfreq->trans_table = devm_kzalloc(dev, sizeof(unsigned int) *
481 devfreq->profile->max_state *
482 devfreq->profile->max_state,
483 GFP_KERNEL);
484 devfreq->time_in_state = devm_kzalloc(dev, sizeof(unsigned int) *
485 devfreq->profile->max_state,
486 GFP_KERNEL);
487 devfreq->last_stat_updated = jiffies;
488
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200489 dev_set_name(&devfreq->dev, dev_name(dev));
490 err = device_register(&devfreq->dev);
491 if (err) {
492 put_device(&devfreq->dev);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200493 mutex_unlock(&devfreq->lock);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200494 goto err_dev;
495 }
496
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200497 mutex_unlock(&devfreq->lock);
498
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200499 mutex_lock(&devfreq_list_lock);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200500 list_add(&devfreq->node, &devfreq_list);
501
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500502 governor = find_devfreq_governor(devfreq->governor_name);
503 if (!IS_ERR(governor))
504 devfreq->governor = governor;
505 if (devfreq->governor)
506 err = devfreq->governor->event_handler(devfreq,
507 DEVFREQ_GOV_START, NULL);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200508 mutex_unlock(&devfreq_list_lock);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200509 if (err) {
510 dev_err(dev, "%s: Unable to start governor for the device\n",
511 __func__);
512 goto err_init;
513 }
514
Axel Lin3f19f082011-11-15 21:59:09 +0100515 return devfreq;
516
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200517err_init:
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200518 list_del(&devfreq->node);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200519 device_unregister(&devfreq->dev);
520err_dev:
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200521 kfree(devfreq);
Axel Lin3f19f082011-11-15 21:59:09 +0100522err_out:
523 return ERR_PTR(err);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200524}
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200525EXPORT_SYMBOL(devfreq_add_device);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200526
527/**
528 * devfreq_remove_device() - Remove devfreq feature from a device.
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +0200529 * @devfreq: the devfreq instance to be removed
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200530 */
531int devfreq_remove_device(struct devfreq *devfreq)
532{
533 if (!devfreq)
534 return -EINVAL;
535
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200536 _remove_devfreq(devfreq, false);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200537
538 return 0;
539}
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200540EXPORT_SYMBOL(devfreq_remove_device);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200541
Rajagopal Venkat206c30c2012-10-26 01:50:18 +0200542/**
543 * devfreq_suspend_device() - Suspend devfreq of a device.
544 * @devfreq: the devfreq instance to be suspended
545 */
546int devfreq_suspend_device(struct devfreq *devfreq)
547{
548 if (!devfreq)
549 return -EINVAL;
550
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500551 if (!devfreq->governor)
552 return 0;
553
Rajagopal Venkat206c30c2012-10-26 01:50:18 +0200554 return devfreq->governor->event_handler(devfreq,
555 DEVFREQ_GOV_SUSPEND, NULL);
556}
557EXPORT_SYMBOL(devfreq_suspend_device);
558
559/**
560 * devfreq_resume_device() - Resume devfreq of a device.
561 * @devfreq: the devfreq instance to be resumed
562 */
563int devfreq_resume_device(struct devfreq *devfreq)
564{
565 if (!devfreq)
566 return -EINVAL;
567
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500568 if (!devfreq->governor)
569 return 0;
570
Rajagopal Venkat206c30c2012-10-26 01:50:18 +0200571 return devfreq->governor->event_handler(devfreq,
572 DEVFREQ_GOV_RESUME, NULL);
573}
574EXPORT_SYMBOL(devfreq_resume_device);
575
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500576/**
577 * devfreq_add_governor() - Add devfreq governor
578 * @governor: the devfreq governor to be added
579 */
580int devfreq_add_governor(struct devfreq_governor *governor)
581{
582 struct devfreq_governor *g;
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500583 struct devfreq *devfreq;
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500584 int err = 0;
585
586 if (!governor) {
587 pr_err("%s: Invalid parameters.\n", __func__);
588 return -EINVAL;
589 }
590
591 mutex_lock(&devfreq_list_lock);
592 g = find_devfreq_governor(governor->name);
593 if (!IS_ERR(g)) {
594 pr_err("%s: governor %s already registered\n", __func__,
595 g->name);
596 err = -EINVAL;
597 goto err_out;
598 }
599
600 list_add(&governor->node, &devfreq_governor_list);
601
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500602 list_for_each_entry(devfreq, &devfreq_list, node) {
603 int ret = 0;
604 struct device *dev = devfreq->dev.parent;
605
606 if (!strncmp(devfreq->governor_name, governor->name,
607 DEVFREQ_NAME_LEN)) {
608 /* The following should never occur */
609 if (devfreq->governor) {
610 dev_warn(dev,
611 "%s: Governor %s already present\n",
612 __func__, devfreq->governor->name);
613 ret = devfreq->governor->event_handler(devfreq,
614 DEVFREQ_GOV_STOP, NULL);
615 if (ret) {
616 dev_warn(dev,
617 "%s: Governor %s stop = %d\n",
618 __func__,
619 devfreq->governor->name, ret);
620 }
621 /* Fall through */
622 }
623 devfreq->governor = governor;
624 ret = devfreq->governor->event_handler(devfreq,
625 DEVFREQ_GOV_START, NULL);
626 if (ret) {
627 dev_warn(dev, "%s: Governor %s start=%d\n",
628 __func__, devfreq->governor->name,
629 ret);
630 }
631 }
632 }
633
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500634err_out:
635 mutex_unlock(&devfreq_list_lock);
636
637 return err;
638}
639EXPORT_SYMBOL(devfreq_add_governor);
640
641/**
642 * devfreq_remove_device() - Remove devfreq feature from a device.
643 * @governor: the devfreq governor to be removed
644 */
645int devfreq_remove_governor(struct devfreq_governor *governor)
646{
647 struct devfreq_governor *g;
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500648 struct devfreq *devfreq;
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500649 int err = 0;
650
651 if (!governor) {
652 pr_err("%s: Invalid parameters.\n", __func__);
653 return -EINVAL;
654 }
655
656 mutex_lock(&devfreq_list_lock);
657 g = find_devfreq_governor(governor->name);
658 if (IS_ERR(g)) {
659 pr_err("%s: governor %s not registered\n", __func__,
Sachin Kamatb9e1c8e2012-11-21 10:36:13 +0530660 governor->name);
Sachin Kamatf9c08e22012-11-21 10:36:14 +0530661 err = PTR_ERR(g);
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500662 goto err_out;
663 }
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500664 list_for_each_entry(devfreq, &devfreq_list, node) {
665 int ret;
666 struct device *dev = devfreq->dev.parent;
667
668 if (!strncmp(devfreq->governor_name, governor->name,
669 DEVFREQ_NAME_LEN)) {
670 /* we should have a devfreq governor! */
671 if (!devfreq->governor) {
672 dev_warn(dev, "%s: Governor %s NOT present\n",
673 __func__, governor->name);
674 continue;
675 /* Fall through */
676 }
677 ret = devfreq->governor->event_handler(devfreq,
678 DEVFREQ_GOV_STOP, NULL);
679 if (ret) {
680 dev_warn(dev, "%s: Governor %s stop=%d\n",
681 __func__, devfreq->governor->name,
682 ret);
683 }
684 devfreq->governor = NULL;
685 }
686 }
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500687
688 list_del(&governor->node);
689err_out:
690 mutex_unlock(&devfreq_list_lock);
691
692 return err;
693}
694EXPORT_SYMBOL(devfreq_remove_governor);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200695
MyungJoo Ham9005b652011-10-02 00:19:28 +0200696static ssize_t show_governor(struct device *dev,
697 struct device_attribute *attr, char *buf)
698{
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500699 if (!to_devfreq(dev)->governor)
700 return -EINVAL;
701
MyungJoo Ham9005b652011-10-02 00:19:28 +0200702 return sprintf(buf, "%s\n", to_devfreq(dev)->governor->name);
703}
704
Nishanth Menon0359d1a2012-10-29 15:01:47 -0500705static ssize_t store_governor(struct device *dev, struct device_attribute *attr,
706 const char *buf, size_t count)
707{
708 struct devfreq *df = to_devfreq(dev);
709 int ret;
710 char str_governor[DEVFREQ_NAME_LEN + 1];
711 struct devfreq_governor *governor;
712
713 ret = sscanf(buf, "%" __stringify(DEVFREQ_NAME_LEN) "s", str_governor);
714 if (ret != 1)
715 return -EINVAL;
716
717 mutex_lock(&devfreq_list_lock);
718 governor = find_devfreq_governor(str_governor);
719 if (IS_ERR(governor)) {
720 ret = PTR_ERR(governor);
721 goto out;
722 }
723 if (df->governor == governor)
724 goto out;
725
726 if (df->governor) {
727 ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL);
728 if (ret) {
729 dev_warn(dev, "%s: Governor %s not stopped(%d)\n",
730 __func__, df->governor->name, ret);
731 goto out;
732 }
733 }
734 df->governor = governor;
735 strncpy(df->governor_name, governor->name, DEVFREQ_NAME_LEN);
736 ret = df->governor->event_handler(df, DEVFREQ_GOV_START, NULL);
737 if (ret)
738 dev_warn(dev, "%s: Governor %s not started(%d)\n",
739 __func__, df->governor->name, ret);
740out:
741 mutex_unlock(&devfreq_list_lock);
742
743 if (!ret)
744 ret = count;
745 return ret;
746}
Nishanth Menon50a5b332012-10-29 15:01:48 -0500747static ssize_t show_available_governors(struct device *d,
748 struct device_attribute *attr,
749 char *buf)
750{
751 struct devfreq_governor *tmp_governor;
752 ssize_t count = 0;
753
754 mutex_lock(&devfreq_list_lock);
755 list_for_each_entry(tmp_governor, &devfreq_governor_list, node)
756 count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
757 "%s ", tmp_governor->name);
758 mutex_unlock(&devfreq_list_lock);
759
760 /* Truncate the trailing space */
761 if (count)
762 count--;
763
764 count += sprintf(&buf[count], "\n");
765
766 return count;
767}
Nishanth Menon0359d1a2012-10-29 15:01:47 -0500768
MyungJoo Ham9005b652011-10-02 00:19:28 +0200769static ssize_t show_freq(struct device *dev,
770 struct device_attribute *attr, char *buf)
771{
Rajagopal Venkat7f98a902012-10-26 01:50:26 +0200772 unsigned long freq;
773 struct devfreq *devfreq = to_devfreq(dev);
774
775 if (devfreq->profile->get_cur_freq &&
776 !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
777 return sprintf(buf, "%lu\n", freq);
778
779 return sprintf(buf, "%lu\n", devfreq->previous_freq);
780}
781
782static ssize_t show_target_freq(struct device *dev,
783 struct device_attribute *attr, char *buf)
784{
MyungJoo Ham9005b652011-10-02 00:19:28 +0200785 return sprintf(buf, "%lu\n", to_devfreq(dev)->previous_freq);
786}
787
788static ssize_t show_polling_interval(struct device *dev,
789 struct device_attribute *attr, char *buf)
790{
791 return sprintf(buf, "%d\n", to_devfreq(dev)->profile->polling_ms);
792}
793
794static ssize_t store_polling_interval(struct device *dev,
795 struct device_attribute *attr,
796 const char *buf, size_t count)
797{
798 struct devfreq *df = to_devfreq(dev);
799 unsigned int value;
800 int ret;
801
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500802 if (!df->governor)
803 return -EINVAL;
804
MyungJoo Ham9005b652011-10-02 00:19:28 +0200805 ret = sscanf(buf, "%u", &value);
806 if (ret != 1)
Nishanth Menon12e26262012-10-26 01:50:43 +0200807 return -EINVAL;
MyungJoo Ham9005b652011-10-02 00:19:28 +0200808
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200809 df->governor->event_handler(df, DEVFREQ_GOV_INTERVAL, &value);
MyungJoo Ham9005b652011-10-02 00:19:28 +0200810 ret = count;
811
MyungJoo Ham9005b652011-10-02 00:19:28 +0200812 return ret;
813}
814
MyungJoo Ham6530b9de2011-12-09 16:42:19 +0900815static ssize_t store_min_freq(struct device *dev, struct device_attribute *attr,
816 const char *buf, size_t count)
817{
818 struct devfreq *df = to_devfreq(dev);
819 unsigned long value;
820 int ret;
821 unsigned long max;
822
823 ret = sscanf(buf, "%lu", &value);
824 if (ret != 1)
Nishanth Menon12e26262012-10-26 01:50:43 +0200825 return -EINVAL;
MyungJoo Ham6530b9de2011-12-09 16:42:19 +0900826
827 mutex_lock(&df->lock);
828 max = df->max_freq;
829 if (value && max && value > max) {
830 ret = -EINVAL;
831 goto unlock;
832 }
833
834 df->min_freq = value;
835 update_devfreq(df);
836 ret = count;
837unlock:
838 mutex_unlock(&df->lock);
MyungJoo Ham6530b9de2011-12-09 16:42:19 +0900839 return ret;
840}
841
842static ssize_t show_min_freq(struct device *dev, struct device_attribute *attr,
843 char *buf)
844{
845 return sprintf(buf, "%lu\n", to_devfreq(dev)->min_freq);
846}
847
848static ssize_t store_max_freq(struct device *dev, struct device_attribute *attr,
849 const char *buf, size_t count)
850{
851 struct devfreq *df = to_devfreq(dev);
852 unsigned long value;
853 int ret;
854 unsigned long min;
855
856 ret = sscanf(buf, "%lu", &value);
857 if (ret != 1)
Nishanth Menon12e26262012-10-26 01:50:43 +0200858 return -EINVAL;
MyungJoo Ham6530b9de2011-12-09 16:42:19 +0900859
860 mutex_lock(&df->lock);
861 min = df->min_freq;
862 if (value && min && value < min) {
863 ret = -EINVAL;
864 goto unlock;
865 }
866
867 df->max_freq = value;
868 update_devfreq(df);
869 ret = count;
870unlock:
871 mutex_unlock(&df->lock);
MyungJoo Ham6530b9de2011-12-09 16:42:19 +0900872 return ret;
873}
874
875static ssize_t show_max_freq(struct device *dev, struct device_attribute *attr,
876 char *buf)
877{
878 return sprintf(buf, "%lu\n", to_devfreq(dev)->max_freq);
879}
880
Nishanth Menond287de82012-10-25 19:48:59 -0500881static ssize_t show_available_freqs(struct device *d,
882 struct device_attribute *attr,
883 char *buf)
884{
885 struct devfreq *df = to_devfreq(d);
886 struct device *dev = df->dev.parent;
887 struct opp *opp;
888 ssize_t count = 0;
889 unsigned long freq = 0;
890
891 rcu_read_lock();
892 do {
893 opp = opp_find_freq_ceil(dev, &freq);
894 if (IS_ERR(opp))
895 break;
896
897 count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
898 "%lu ", freq);
899 freq++;
900 } while (1);
901 rcu_read_unlock();
902
903 /* Truncate the trailing space */
904 if (count)
905 count--;
906
907 count += sprintf(&buf[count], "\n");
908
909 return count;
910}
911
Jonghwa Leee552bba2012-08-23 20:00:46 +0900912static ssize_t show_trans_table(struct device *dev, struct device_attribute *attr,
913 char *buf)
914{
915 struct devfreq *devfreq = to_devfreq(dev);
916 ssize_t len;
Rajagopal Venkat39688ce62013-01-08 11:20:39 +0530917 int i, j;
Jonghwa Leee552bba2012-08-23 20:00:46 +0900918 unsigned int max_state = devfreq->profile->max_state;
919
Rajagopal Venkat39688ce62013-01-08 11:20:39 +0530920 if (!devfreq->stop_polling &&
921 devfreq_update_status(devfreq, devfreq->previous_freq))
Jonghwa Leee552bba2012-08-23 20:00:46 +0900922 return 0;
923
924 len = sprintf(buf, " From : To\n");
925 len += sprintf(buf + len, " :");
926 for (i = 0; i < max_state; i++)
927 len += sprintf(buf + len, "%8u",
928 devfreq->profile->freq_table[i]);
929
930 len += sprintf(buf + len, " time(ms)\n");
931
932 for (i = 0; i < max_state; i++) {
933 if (devfreq->profile->freq_table[i]
934 == devfreq->previous_freq) {
935 len += sprintf(buf + len, "*");
936 } else {
937 len += sprintf(buf + len, " ");
938 }
939 len += sprintf(buf + len, "%8u:",
940 devfreq->profile->freq_table[i]);
941 for (j = 0; j < max_state; j++)
942 len += sprintf(buf + len, "%8u",
943 devfreq->trans_table[(i * max_state) + j]);
944 len += sprintf(buf + len, "%10u\n",
945 jiffies_to_msecs(devfreq->time_in_state[i]));
946 }
947
948 len += sprintf(buf + len, "Total transition : %u\n",
949 devfreq->total_trans);
950 return len;
951}
952
MyungJoo Ham9005b652011-10-02 00:19:28 +0200953static struct device_attribute devfreq_attrs[] = {
Nishanth Menon0359d1a2012-10-29 15:01:47 -0500954 __ATTR(governor, S_IRUGO | S_IWUSR, show_governor, store_governor),
Nishanth Menon50a5b332012-10-29 15:01:48 -0500955 __ATTR(available_governors, S_IRUGO, show_available_governors, NULL),
MyungJoo Ham9005b652011-10-02 00:19:28 +0200956 __ATTR(cur_freq, S_IRUGO, show_freq, NULL),
Nishanth Menond287de82012-10-25 19:48:59 -0500957 __ATTR(available_frequencies, S_IRUGO, show_available_freqs, NULL),
Rajagopal Venkat7f98a902012-10-26 01:50:26 +0200958 __ATTR(target_freq, S_IRUGO, show_target_freq, NULL),
MyungJoo Ham9005b652011-10-02 00:19:28 +0200959 __ATTR(polling_interval, S_IRUGO | S_IWUSR, show_polling_interval,
960 store_polling_interval),
MyungJoo Ham6530b9de2011-12-09 16:42:19 +0900961 __ATTR(min_freq, S_IRUGO | S_IWUSR, show_min_freq, store_min_freq),
962 __ATTR(max_freq, S_IRUGO | S_IWUSR, show_max_freq, store_max_freq),
Jonghwa Leee552bba2012-08-23 20:00:46 +0900963 __ATTR(trans_stat, S_IRUGO, show_trans_table, NULL),
MyungJoo Ham9005b652011-10-02 00:19:28 +0200964 { },
965};
966
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200967static int __init devfreq_init(void)
968{
969 devfreq_class = class_create(THIS_MODULE, "devfreq");
970 if (IS_ERR(devfreq_class)) {
971 pr_err("%s: couldn't create class\n", __FILE__);
972 return PTR_ERR(devfreq_class);
973 }
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200974
975 devfreq_wq = create_freezable_workqueue("devfreq_wq");
976 if (IS_ERR(devfreq_wq)) {
977 class_destroy(devfreq_class);
978 pr_err("%s: couldn't create workqueue\n", __FILE__);
979 return PTR_ERR(devfreq_wq);
980 }
MyungJoo Ham9005b652011-10-02 00:19:28 +0200981 devfreq_class->dev_attrs = devfreq_attrs;
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200982
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200983 return 0;
984}
985subsys_initcall(devfreq_init);
986
987static void __exit devfreq_exit(void)
988{
989 class_destroy(devfreq_class);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200990 destroy_workqueue(devfreq_wq);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200991}
992module_exit(devfreq_exit);
993
994/*
995 * The followings are helper functions for devfreq user device drivers with
996 * OPP framework.
997 */
998
999/**
1000 * devfreq_recommended_opp() - Helper function to get proper OPP for the
1001 * freq value given to target callback.
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +02001002 * @dev: The devfreq user device. (parent of devfreq)
1003 * @freq: The frequency given to target function
1004 * @flags: Flags handed from devfreq framework.
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001005 *
Nishanth Menonbcb27542013-01-18 19:52:34 +00001006 * Locking: This function must be called under rcu_read_lock(). opp is a rcu
1007 * protected pointer. The reason for the same is that the opp pointer which is
1008 * returned will remain valid for use with opp_get_{voltage, freq} only while
1009 * under the locked area. The pointer returned must be used prior to unlocking
1010 * with rcu_read_unlock() to maintain the integrity of the pointer.
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001011 */
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001012struct opp *devfreq_recommended_opp(struct device *dev, unsigned long *freq,
1013 u32 flags)
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001014{
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001015 struct opp *opp;
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001016
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001017 if (flags & DEVFREQ_FLAG_LEAST_UPPER_BOUND) {
1018 /* The freq is an upper bound. opp should be lower */
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001019 opp = opp_find_freq_floor(dev, freq);
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001020
1021 /* If not available, use the closest opp */
Nishanth Menon07797262012-10-24 22:00:12 +02001022 if (opp == ERR_PTR(-ERANGE))
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001023 opp = opp_find_freq_ceil(dev, freq);
1024 } else {
1025 /* The freq is an lower bound. opp should be higher */
1026 opp = opp_find_freq_ceil(dev, freq);
1027
1028 /* If not available, use the closest opp */
Nishanth Menon07797262012-10-24 22:00:12 +02001029 if (opp == ERR_PTR(-ERANGE))
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001030 opp = opp_find_freq_floor(dev, freq);
1031 }
1032
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001033 return opp;
1034}
1035
1036/**
1037 * devfreq_register_opp_notifier() - Helper function to get devfreq notified
1038 * for any changes in the OPP availability
1039 * changes
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +02001040 * @dev: The devfreq user device. (parent of devfreq)
1041 * @devfreq: The devfreq object.
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001042 */
1043int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq)
1044{
MyungJoo Ham389baed2012-11-21 19:04:51 +09001045 struct srcu_notifier_head *nh;
1046 int ret = 0;
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001047
MyungJoo Ham389baed2012-11-21 19:04:51 +09001048 rcu_read_lock();
1049 nh = opp_get_notifier(dev);
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001050 if (IS_ERR(nh))
MyungJoo Ham389baed2012-11-21 19:04:51 +09001051 ret = PTR_ERR(nh);
1052 rcu_read_unlock();
1053 if (!ret)
1054 ret = srcu_notifier_chain_register(nh, &devfreq->nb);
1055
1056 return ret;
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001057}
1058
1059/**
1060 * devfreq_unregister_opp_notifier() - Helper function to stop getting devfreq
1061 * notified for any changes in the OPP
1062 * availability changes anymore.
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +02001063 * @dev: The devfreq user device. (parent of devfreq)
1064 * @devfreq: The devfreq object.
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001065 *
1066 * At exit() callback of devfreq_dev_profile, this must be included if
1067 * devfreq_recommended_opp is used.
1068 */
1069int devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq)
1070{
MyungJoo Ham389baed2012-11-21 19:04:51 +09001071 struct srcu_notifier_head *nh;
1072 int ret = 0;
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001073
MyungJoo Ham389baed2012-11-21 19:04:51 +09001074 rcu_read_lock();
1075 nh = opp_get_notifier(dev);
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001076 if (IS_ERR(nh))
MyungJoo Ham389baed2012-11-21 19:04:51 +09001077 ret = PTR_ERR(nh);
1078 rcu_read_unlock();
1079 if (!ret)
1080 ret = srcu_notifier_chain_unregister(nh, &devfreq->nb);
1081
1082 return ret;
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001083}
1084
1085MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>");
1086MODULE_DESCRIPTION("devfreq class support");
1087MODULE_LICENSE("GPL");