blob: df62e38de5f5c17c0ff0cefff6ed00480273be96 [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>
Paul Gortmaker417dc4b2016-06-26 03:43:47 +090018#include <linux/export.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>
Nishanth Menone4db1c72013-09-19 16:03:52 -050021#include <linux/pm_opp.h>
MyungJoo Hama3c98b82011-10-02 00:19:15 +020022#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>
Chanwoo Choi8f510ae2015-11-10 20:31:07 +090028#include <linux/of.h>
MyungJoo Hama3c98b82011-10-02 00:19:15 +020029#include "governor.h"
30
Nishanth Menon1a1357e2012-10-26 01:50:53 +020031static struct class *devfreq_class;
MyungJoo Hama3c98b82011-10-02 00:19:15 +020032
33/*
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +020034 * devfreq core provides delayed work based load monitoring helper
35 * functions. Governors can use these or can implement their own
36 * monitoring mechanism.
MyungJoo Hama3c98b82011-10-02 00:19:15 +020037 */
MyungJoo Hama3c98b82011-10-02 00:19:15 +020038static struct workqueue_struct *devfreq_wq;
MyungJoo Hama3c98b82011-10-02 00:19:15 +020039
Nishanth Menon3aa173b2012-10-29 15:01:43 -050040/* The list of all device-devfreq governors */
41static LIST_HEAD(devfreq_governor_list);
MyungJoo Hama3c98b82011-10-02 00:19:15 +020042/* The list of all device-devfreq */
43static LIST_HEAD(devfreq_list);
44static DEFINE_MUTEX(devfreq_list_lock);
45
46/**
47 * find_device_devfreq() - find devfreq struct using device pointer
48 * @dev: device pointer used to lookup device devfreq.
49 *
50 * Search the list of device devfreqs and return the matched device's
51 * devfreq info. devfreq_list_lock should be held by the caller.
52 */
53static struct devfreq *find_device_devfreq(struct device *dev)
54{
55 struct devfreq *tmp_devfreq;
56
Viresh Kumar9348da22015-08-10 11:42:25 +053057 if (IS_ERR_OR_NULL(dev)) {
MyungJoo Hama3c98b82011-10-02 00:19:15 +020058 pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
59 return ERR_PTR(-EINVAL);
60 }
61 WARN(!mutex_is_locked(&devfreq_list_lock),
62 "devfreq_list_lock must be locked.");
63
64 list_for_each_entry(tmp_devfreq, &devfreq_list, node) {
65 if (tmp_devfreq->dev.parent == dev)
66 return tmp_devfreq;
67 }
68
69 return ERR_PTR(-ENODEV);
70}
71
72/**
Jonghwa Leee552bba2012-08-23 20:00:46 +090073 * devfreq_get_freq_level() - Lookup freq_table for the frequency
74 * @devfreq: the devfreq instance
75 * @freq: the target frequency
76 */
77static int devfreq_get_freq_level(struct devfreq *devfreq, unsigned long freq)
78{
79 int lev;
80
81 for (lev = 0; lev < devfreq->profile->max_state; lev++)
82 if (freq == devfreq->profile->freq_table[lev])
83 return lev;
84
85 return -EINVAL;
86}
87
88/**
Chanwoo Choi0ec09ac2015-11-18 14:49:02 +090089 * devfreq_set_freq_table() - Initialize freq_table for the frequency
90 * @devfreq: the devfreq instance
91 */
92static void devfreq_set_freq_table(struct devfreq *devfreq)
93{
94 struct devfreq_dev_profile *profile = devfreq->profile;
95 struct dev_pm_opp *opp;
96 unsigned long freq;
97 int i, count;
98
99 /* Initialize the freq_table from OPP table */
100 count = dev_pm_opp_get_opp_count(devfreq->dev.parent);
101 if (count <= 0)
102 return;
103
104 profile->max_state = count;
105 profile->freq_table = devm_kcalloc(devfreq->dev.parent,
106 profile->max_state,
107 sizeof(*profile->freq_table),
108 GFP_KERNEL);
109 if (!profile->freq_table) {
110 profile->max_state = 0;
111 return;
112 }
113
114 rcu_read_lock();
115 for (i = 0, freq = 0; i < profile->max_state; i++, freq++) {
116 opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &freq);
117 if (IS_ERR(opp)) {
118 devm_kfree(devfreq->dev.parent, profile->freq_table);
119 profile->max_state = 0;
120 rcu_read_unlock();
121 return;
122 }
123 profile->freq_table[i] = freq;
124 }
125 rcu_read_unlock();
126}
127
128/**
Jonghwa Leee552bba2012-08-23 20:00:46 +0900129 * devfreq_update_status() - Update statistics of devfreq behavior
130 * @devfreq: the devfreq instance
131 * @freq: the update target frequency
132 */
Chanwoo Choife8f92c2017-01-31 15:38:17 +0900133int devfreq_update_status(struct devfreq *devfreq, unsigned long freq)
Jonghwa Leee552bba2012-08-23 20:00:46 +0900134{
Saravana Kannane35d35a2014-02-27 19:38:57 -0800135 int lev, prev_lev, ret = 0;
Jonghwa Leee552bba2012-08-23 20:00:46 +0900136 unsigned long cur_time;
137
Leonard Crestezb99f20c2019-09-24 10:52:23 +0300138 lockdep_assert_held(&devfreq->lock);
Jonghwa Leee552bba2012-08-23 20:00:46 +0900139 cur_time = jiffies;
Saravana Kannane35d35a2014-02-27 19:38:57 -0800140
Tobias Jakobid0563a02016-09-29 14:36:36 +0200141 /* Immediately exit if previous_freq is not initialized yet. */
142 if (!devfreq->previous_freq)
143 goto out;
144
Saravana Kannane35d35a2014-02-27 19:38:57 -0800145 prev_lev = devfreq_get_freq_level(devfreq, devfreq->previous_freq);
146 if (prev_lev < 0) {
147 ret = prev_lev;
148 goto out;
149 }
150
151 devfreq->time_in_state[prev_lev] +=
Jonghwa Leee552bba2012-08-23 20:00:46 +0900152 cur_time - devfreq->last_stat_updated;
Saravana Kannane35d35a2014-02-27 19:38:57 -0800153
154 lev = devfreq_get_freq_level(devfreq, freq);
155 if (lev < 0) {
156 ret = lev;
157 goto out;
158 }
159
160 if (lev != prev_lev) {
Jonghwa Leee552bba2012-08-23 20:00:46 +0900161 devfreq->trans_table[(prev_lev *
162 devfreq->profile->max_state) + lev]++;
163 devfreq->total_trans++;
164 }
Jonghwa Leee552bba2012-08-23 20:00:46 +0900165
Saravana Kannane35d35a2014-02-27 19:38:57 -0800166out:
167 devfreq->last_stat_updated = cur_time;
168 return ret;
Jonghwa Leee552bba2012-08-23 20:00:46 +0900169}
Chanwoo Choife8f92c2017-01-31 15:38:17 +0900170EXPORT_SYMBOL(devfreq_update_status);
Jonghwa Leee552bba2012-08-23 20:00:46 +0900171
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500172/**
173 * find_devfreq_governor() - find devfreq governor from name
174 * @name: name of the governor
175 *
176 * Search the list of devfreq governors and return the matched
177 * governor's pointer. devfreq_list_lock should be held by the caller.
178 */
179static struct devfreq_governor *find_devfreq_governor(const char *name)
180{
181 struct devfreq_governor *tmp_governor;
182
Viresh Kumar9348da22015-08-10 11:42:25 +0530183 if (IS_ERR_OR_NULL(name)) {
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500184 pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
185 return ERR_PTR(-EINVAL);
186 }
187 WARN(!mutex_is_locked(&devfreq_list_lock),
188 "devfreq_list_lock must be locked.");
189
190 list_for_each_entry(tmp_governor, &devfreq_governor_list, node) {
191 if (!strncmp(tmp_governor->name, name, DEVFREQ_NAME_LEN))
192 return tmp_governor;
193 }
194
195 return ERR_PTR(-ENODEV);
196}
197
Chanwoo Choi0fe3a662016-01-26 13:21:26 +0900198static int devfreq_notify_transition(struct devfreq *devfreq,
199 struct devfreq_freqs *freqs, unsigned int state)
200{
201 if (!devfreq)
202 return -EINVAL;
203
204 switch (state) {
205 case DEVFREQ_PRECHANGE:
206 srcu_notifier_call_chain(&devfreq->transition_notifier_list,
207 DEVFREQ_PRECHANGE, freqs);
208 break;
209
210 case DEVFREQ_POSTCHANGE:
211 srcu_notifier_call_chain(&devfreq->transition_notifier_list,
212 DEVFREQ_POSTCHANGE, freqs);
213 break;
214 default:
215 return -EINVAL;
216 }
217
218 return 0;
219}
220
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200221/* Load monitoring helper functions for governors use */
222
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200223/**
224 * update_devfreq() - Reevaluate the device and configure frequency.
225 * @devfreq: the devfreq instance.
226 *
227 * Note: Lock devfreq->lock before calling update_devfreq
228 * This function is exported for governors.
229 */
230int update_devfreq(struct devfreq *devfreq)
231{
Chanwoo Choi0fe3a662016-01-26 13:21:26 +0900232 struct devfreq_freqs freqs;
233 unsigned long freq, cur_freq;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200234 int err = 0;
MyungJoo Hamab5f2992012-03-16 21:54:53 +0100235 u32 flags = 0;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200236
237 if (!mutex_is_locked(&devfreq->lock)) {
238 WARN(true, "devfreq->lock must be locked by the caller.\n");
239 return -EINVAL;
240 }
241
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500242 if (!devfreq->governor)
243 return -EINVAL;
244
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200245 /* Reevaluate the proper frequency */
246 err = devfreq->governor->get_target_freq(devfreq, &freq);
247 if (err)
248 return err;
249
MyungJoo Hamab5f2992012-03-16 21:54:53 +0100250 /*
Javi Merinod3b7e172015-08-14 18:57:00 +0100251 * Adjust the frequency with user freq and QoS.
MyungJoo Hamab5f2992012-03-16 21:54:53 +0100252 *
Javi Merinod3b7e172015-08-14 18:57:00 +0100253 * List from the highest priority
254 * max_freq
MyungJoo Hamab5f2992012-03-16 21:54:53 +0100255 * min_freq
256 */
257
258 if (devfreq->min_freq && freq < devfreq->min_freq) {
259 freq = devfreq->min_freq;
260 flags &= ~DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use GLB */
261 }
262 if (devfreq->max_freq && freq > devfreq->max_freq) {
263 freq = devfreq->max_freq;
264 flags |= DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use LUB */
265 }
266
Chanwoo Choi0fe3a662016-01-26 13:21:26 +0900267 if (devfreq->profile->get_cur_freq)
268 devfreq->profile->get_cur_freq(devfreq->dev.parent, &cur_freq);
269 else
270 cur_freq = devfreq->previous_freq;
271
272 freqs.old = cur_freq;
273 freqs.new = freq;
274 devfreq_notify_transition(devfreq, &freqs, DEVFREQ_PRECHANGE);
275
MyungJoo Hamab5f2992012-03-16 21:54:53 +0100276 err = devfreq->profile->target(devfreq->dev.parent, &freq, flags);
Chanwoo Choi0d371892016-06-23 11:18:43 +0900277 if (err) {
278 freqs.new = cur_freq;
279 devfreq_notify_transition(devfreq, &freqs, DEVFREQ_POSTCHANGE);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200280 return err;
Chanwoo Choi0d371892016-06-23 11:18:43 +0900281 }
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200282
Chanwoo Choi0fe3a662016-01-26 13:21:26 +0900283 freqs.new = freq;
284 devfreq_notify_transition(devfreq, &freqs, DEVFREQ_POSTCHANGE);
285
Jonghwa Leee552bba2012-08-23 20:00:46 +0900286 if (devfreq->profile->freq_table)
287 if (devfreq_update_status(devfreq, freq))
288 dev_err(&devfreq->dev,
289 "Couldn't update frequency transition information.\n");
290
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200291 devfreq->previous_freq = freq;
292 return err;
293}
Nishanth Menon2df50212012-10-29 15:01:42 -0500294EXPORT_SYMBOL(update_devfreq);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200295
296/**
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200297 * devfreq_monitor() - Periodically poll devfreq objects.
298 * @work: the work struct used to run devfreq_monitor periodically.
299 *
300 */
301static void devfreq_monitor(struct work_struct *work)
302{
303 int err;
304 struct devfreq *devfreq = container_of(work,
305 struct devfreq, work.work);
306
307 mutex_lock(&devfreq->lock);
308 err = update_devfreq(devfreq);
309 if (err)
310 dev_err(&devfreq->dev, "dvfs failed with (%d) error\n", err);
311
312 queue_delayed_work(devfreq_wq, &devfreq->work,
313 msecs_to_jiffies(devfreq->profile->polling_ms));
314 mutex_unlock(&devfreq->lock);
315}
316
317/**
318 * devfreq_monitor_start() - Start load monitoring of devfreq instance
319 * @devfreq: the devfreq instance.
320 *
321 * Helper function for starting devfreq device load monitoing. By
322 * default delayed work based monitoring is supported. Function
323 * to be called from governor in response to DEVFREQ_GOV_START
324 * event when device is added to devfreq framework.
325 */
326void devfreq_monitor_start(struct devfreq *devfreq)
327{
328 INIT_DEFERRABLE_WORK(&devfreq->work, devfreq_monitor);
329 if (devfreq->profile->polling_ms)
330 queue_delayed_work(devfreq_wq, &devfreq->work,
331 msecs_to_jiffies(devfreq->profile->polling_ms));
332}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100333EXPORT_SYMBOL(devfreq_monitor_start);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200334
335/**
336 * devfreq_monitor_stop() - Stop load monitoring of a devfreq instance
337 * @devfreq: the devfreq instance.
338 *
339 * Helper function to stop devfreq device load monitoing. Function
340 * to be called from governor in response to DEVFREQ_GOV_STOP
341 * event when device is removed from devfreq framework.
342 */
343void devfreq_monitor_stop(struct devfreq *devfreq)
344{
345 cancel_delayed_work_sync(&devfreq->work);
346}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100347EXPORT_SYMBOL(devfreq_monitor_stop);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200348
349/**
350 * devfreq_monitor_suspend() - Suspend load monitoring of a devfreq instance
351 * @devfreq: the devfreq instance.
352 *
353 * Helper function to suspend devfreq device load monitoing. Function
354 * to be called from governor in response to DEVFREQ_GOV_SUSPEND
355 * event or when polling interval is set to zero.
356 *
357 * Note: Though this function is same as devfreq_monitor_stop(),
358 * intentionally kept separate to provide hooks for collecting
359 * transition statistics.
360 */
361void devfreq_monitor_suspend(struct devfreq *devfreq)
362{
363 mutex_lock(&devfreq->lock);
364 if (devfreq->stop_polling) {
365 mutex_unlock(&devfreq->lock);
366 return;
367 }
368
Rajagopal Venkat39688ce2013-01-08 11:20:39 +0530369 devfreq_update_status(devfreq, devfreq->previous_freq);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200370 devfreq->stop_polling = true;
371 mutex_unlock(&devfreq->lock);
372 cancel_delayed_work_sync(&devfreq->work);
373}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100374EXPORT_SYMBOL(devfreq_monitor_suspend);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200375
376/**
377 * devfreq_monitor_resume() - Resume load monitoring of a devfreq instance
378 * @devfreq: the devfreq instance.
379 *
380 * Helper function to resume devfreq device load monitoing. Function
381 * to be called from governor in response to DEVFREQ_GOV_RESUME
382 * event or when polling interval is set to non-zero.
383 */
384void devfreq_monitor_resume(struct devfreq *devfreq)
385{
Rajagopal Venkat39688ce2013-01-08 11:20:39 +0530386 unsigned long freq;
387
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200388 mutex_lock(&devfreq->lock);
389 if (!devfreq->stop_polling)
390 goto out;
391
392 if (!delayed_work_pending(&devfreq->work) &&
393 devfreq->profile->polling_ms)
394 queue_delayed_work(devfreq_wq, &devfreq->work,
395 msecs_to_jiffies(devfreq->profile->polling_ms));
Rajagopal Venkat39688ce2013-01-08 11:20:39 +0530396
397 devfreq->last_stat_updated = jiffies;
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200398 devfreq->stop_polling = false;
399
Rajagopal Venkat39688ce2013-01-08 11:20:39 +0530400 if (devfreq->profile->get_cur_freq &&
401 !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
402 devfreq->previous_freq = freq;
403
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200404out:
405 mutex_unlock(&devfreq->lock);
406}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100407EXPORT_SYMBOL(devfreq_monitor_resume);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200408
409/**
410 * devfreq_interval_update() - Update device devfreq monitoring interval
411 * @devfreq: the devfreq instance.
412 * @delay: new polling interval to be set.
413 *
414 * Helper function to set new load monitoring polling interval. Function
415 * to be called from governor in response to DEVFREQ_GOV_INTERVAL event.
416 */
417void devfreq_interval_update(struct devfreq *devfreq, unsigned int *delay)
418{
419 unsigned int cur_delay = devfreq->profile->polling_ms;
420 unsigned int new_delay = *delay;
421
422 mutex_lock(&devfreq->lock);
423 devfreq->profile->polling_ms = new_delay;
424
425 if (devfreq->stop_polling)
426 goto out;
427
428 /* if new delay is zero, stop polling */
429 if (!new_delay) {
430 mutex_unlock(&devfreq->lock);
431 cancel_delayed_work_sync(&devfreq->work);
432 return;
433 }
434
435 /* if current delay is zero, start polling with new delay */
436 if (!cur_delay) {
437 queue_delayed_work(devfreq_wq, &devfreq->work,
438 msecs_to_jiffies(devfreq->profile->polling_ms));
439 goto out;
440 }
441
442 /* if current delay is greater than new delay, restart polling */
443 if (cur_delay > new_delay) {
444 mutex_unlock(&devfreq->lock);
445 cancel_delayed_work_sync(&devfreq->work);
446 mutex_lock(&devfreq->lock);
447 if (!devfreq->stop_polling)
448 queue_delayed_work(devfreq_wq, &devfreq->work,
449 msecs_to_jiffies(devfreq->profile->polling_ms));
450 }
451out:
452 mutex_unlock(&devfreq->lock);
453}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100454EXPORT_SYMBOL(devfreq_interval_update);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200455
456/**
457 * devfreq_notifier_call() - Notify that the device frequency requirements
458 * has been changed out of devfreq framework.
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +0200459 * @nb: the notifier_block (supposed to be devfreq->nb)
460 * @type: not used
461 * @devp: not used
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200462 *
463 * Called by a notifier that uses devfreq->nb.
464 */
465static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type,
466 void *devp)
467{
468 struct devfreq *devfreq = container_of(nb, struct devfreq, nb);
469 int ret;
470
471 mutex_lock(&devfreq->lock);
472 ret = update_devfreq(devfreq);
473 mutex_unlock(&devfreq->lock);
474
475 return ret;
476}
477
478/**
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200479 * _remove_devfreq() - Remove devfreq from the list and release its resources.
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200480 * @devfreq: the devfreq struct
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200481 */
Chanwoo Choi585fc832014-05-09 16:43:07 +0900482static void _remove_devfreq(struct devfreq *devfreq)
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200483{
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200484 mutex_lock(&devfreq_list_lock);
485 if (IS_ERR(find_device_devfreq(devfreq->dev.parent))) {
486 mutex_unlock(&devfreq_list_lock);
487 dev_warn(&devfreq->dev, "releasing devfreq which doesn't exist\n");
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200488 return;
489 }
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200490 list_del(&devfreq->node);
491 mutex_unlock(&devfreq_list_lock);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200492
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500493 if (devfreq->governor)
494 devfreq->governor->event_handler(devfreq,
495 DEVFREQ_GOV_STOP, NULL);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200496
497 if (devfreq->profile->exit)
498 devfreq->profile->exit(devfreq->dev.parent);
499
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200500 mutex_destroy(&devfreq->lock);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200501 kfree(devfreq);
502}
503
504/**
505 * devfreq_dev_release() - Callback for struct device to release the device.
506 * @dev: the devfreq device
507 *
508 * This calls _remove_devfreq() if _remove_devfreq() is not called.
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200509 */
510static void devfreq_dev_release(struct device *dev)
511{
512 struct devfreq *devfreq = to_devfreq(dev);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200513
Chanwoo Choi585fc832014-05-09 16:43:07 +0900514 _remove_devfreq(devfreq);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200515}
516
517/**
518 * devfreq_add_device() - Add devfreq feature to the device
519 * @dev: the device to add devfreq feature.
520 * @profile: device-specific profile to run devfreq.
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500521 * @governor_name: name of the policy to choose frequency.
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200522 * @data: private data for the governor. The devfreq framework does not
523 * touch this value.
524 */
525struct devfreq *devfreq_add_device(struct device *dev,
526 struct devfreq_dev_profile *profile,
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500527 const char *governor_name,
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200528 void *data)
529{
530 struct devfreq *devfreq;
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500531 struct devfreq_governor *governor;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200532 int err = 0;
533
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500534 if (!dev || !profile || !governor_name) {
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200535 dev_err(dev, "%s: Invalid parameters.\n", __func__);
536 return ERR_PTR(-EINVAL);
537 }
538
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200539 mutex_lock(&devfreq_list_lock);
540 devfreq = find_device_devfreq(dev);
541 mutex_unlock(&devfreq_list_lock);
542 if (!IS_ERR(devfreq)) {
543 dev_err(dev, "%s: Unable to create devfreq for the device. It already has one.\n", __func__);
544 err = -EINVAL;
545 goto err_out;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200546 }
547
548 devfreq = kzalloc(sizeof(struct devfreq), GFP_KERNEL);
549 if (!devfreq) {
550 dev_err(dev, "%s: Unable to create devfreq for the device\n",
551 __func__);
552 err = -ENOMEM;
Axel Lin3f19f082011-11-15 21:59:09 +0100553 goto err_out;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200554 }
555
556 mutex_init(&devfreq->lock);
557 mutex_lock(&devfreq->lock);
558 devfreq->dev.parent = dev;
559 devfreq->dev.class = devfreq_class;
560 devfreq->dev.release = devfreq_dev_release;
561 devfreq->profile = profile;
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500562 strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200563 devfreq->previous_freq = profile->initial_freq;
Lukasz Luba8d39fc02016-05-31 11:25:09 +0100564 devfreq->last_status.current_frequency = profile->initial_freq;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200565 devfreq->data = data;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200566 devfreq->nb.notifier_call = devfreq_notifier_call;
567
Chanwoo Choi0ec09ac2015-11-18 14:49:02 +0900568 if (!devfreq->profile->max_state && !devfreq->profile->freq_table) {
569 mutex_unlock(&devfreq->lock);
570 devfreq_set_freq_table(devfreq);
571 mutex_lock(&devfreq->lock);
572 }
573
Kees Cook02aa2a32013-07-03 15:04:56 -0700574 dev_set_name(&devfreq->dev, "%s", dev_name(dev));
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200575 err = device_register(&devfreq->dev);
576 if (err) {
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200577 mutex_unlock(&devfreq->lock);
Chanwoo Choif5c3fd82017-08-24 10:42:48 +0900578 goto err_dev;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200579 }
580
MyungJoo Ham3e1d7fb2015-10-02 12:39:23 +0900581 devfreq->trans_table = devm_kzalloc(&devfreq->dev, sizeof(unsigned int) *
582 devfreq->profile->max_state *
583 devfreq->profile->max_state,
584 GFP_KERNEL);
585 devfreq->time_in_state = devm_kzalloc(&devfreq->dev, sizeof(unsigned long) *
586 devfreq->profile->max_state,
587 GFP_KERNEL);
588 devfreq->last_stat_updated = jiffies;
589
Chanwoo Choi0fe3a662016-01-26 13:21:26 +0900590 srcu_init_notifier_head(&devfreq->transition_notifier_list);
591
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200592 mutex_unlock(&devfreq->lock);
593
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200594 mutex_lock(&devfreq_list_lock);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200595 list_add(&devfreq->node, &devfreq_list);
596
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500597 governor = find_devfreq_governor(devfreq->governor_name);
Chanwoo Choiebdfcaa2016-12-28 20:52:35 +0900598 if (IS_ERR(governor)) {
599 dev_err(dev, "%s: Unable to find governor for the device\n",
600 __func__);
601 err = PTR_ERR(governor);
602 goto err_init;
603 }
604
605 devfreq->governor = governor;
606 err = devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_START,
607 NULL);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200608 if (err) {
609 dev_err(dev, "%s: Unable to start governor for the device\n",
610 __func__);
611 goto err_init;
612 }
Axel Lin0f376c92016-09-29 10:13:28 +0800613 mutex_unlock(&devfreq_list_lock);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200614
Axel Lin3f19f082011-11-15 21:59:09 +0100615 return devfreq;
616
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200617err_init:
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200618 list_del(&devfreq->node);
Axel Lin0f376c92016-09-29 10:13:28 +0800619 mutex_unlock(&devfreq_list_lock);
620
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200621 device_unregister(&devfreq->dev);
Chanwoo Choif5c3fd82017-08-24 10:42:48 +0900622err_dev:
623 if (devfreq)
624 kfree(devfreq);
Axel Lin3f19f082011-11-15 21:59:09 +0100625err_out:
626 return ERR_PTR(err);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200627}
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200628EXPORT_SYMBOL(devfreq_add_device);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200629
630/**
631 * devfreq_remove_device() - Remove devfreq feature from a device.
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +0200632 * @devfreq: the devfreq instance to be removed
MyungJoo Hamde9c7392013-02-05 18:40:17 +0900633 *
634 * The opposite of devfreq_add_device().
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200635 */
636int devfreq_remove_device(struct devfreq *devfreq)
637{
638 if (!devfreq)
639 return -EINVAL;
640
Chanwoo Choi585fc832014-05-09 16:43:07 +0900641 device_unregister(&devfreq->dev);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200642
643 return 0;
644}
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200645EXPORT_SYMBOL(devfreq_remove_device);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200646
Chanwoo Choi8cd84092014-05-09 16:43:08 +0900647static int devm_devfreq_dev_match(struct device *dev, void *res, void *data)
648{
649 struct devfreq **r = res;
650
651 if (WARN_ON(!r || !*r))
652 return 0;
653
654 return *r == data;
655}
656
657static void devm_devfreq_dev_release(struct device *dev, void *res)
658{
659 devfreq_remove_device(*(struct devfreq **)res);
660}
661
662/**
663 * devm_devfreq_add_device() - Resource-managed devfreq_add_device()
664 * @dev: the device to add devfreq feature.
665 * @profile: device-specific profile to run devfreq.
666 * @governor_name: name of the policy to choose frequency.
667 * @data: private data for the governor. The devfreq framework does not
668 * touch this value.
669 *
670 * This function manages automatically the memory of devfreq device using device
671 * resource management and simplify the free operation for memory of devfreq
672 * device.
673 */
674struct devfreq *devm_devfreq_add_device(struct device *dev,
675 struct devfreq_dev_profile *profile,
676 const char *governor_name,
677 void *data)
678{
679 struct devfreq **ptr, *devfreq;
680
681 ptr = devres_alloc(devm_devfreq_dev_release, sizeof(*ptr), GFP_KERNEL);
682 if (!ptr)
683 return ERR_PTR(-ENOMEM);
684
685 devfreq = devfreq_add_device(dev, profile, governor_name, data);
686 if (IS_ERR(devfreq)) {
687 devres_free(ptr);
Bjorn Anderssonb3685e82017-11-05 21:27:41 -0800688 return devfreq;
Chanwoo Choi8cd84092014-05-09 16:43:08 +0900689 }
690
691 *ptr = devfreq;
692 devres_add(dev, ptr);
693
694 return devfreq;
695}
696EXPORT_SYMBOL(devm_devfreq_add_device);
697
Chanwoo Choi8f510ae2015-11-10 20:31:07 +0900698#ifdef CONFIG_OF
699/*
700 * devfreq_get_devfreq_by_phandle - Get the devfreq device from devicetree
701 * @dev - instance to the given device
702 * @index - index into list of devfreq
703 *
704 * return the instance of devfreq device
705 */
706struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index)
707{
708 struct device_node *node;
709 struct devfreq *devfreq;
710
711 if (!dev)
712 return ERR_PTR(-EINVAL);
713
714 if (!dev->of_node)
715 return ERR_PTR(-EINVAL);
716
717 node = of_parse_phandle(dev->of_node, "devfreq", index);
718 if (!node)
719 return ERR_PTR(-ENODEV);
720
721 mutex_lock(&devfreq_list_lock);
722 list_for_each_entry(devfreq, &devfreq_list, node) {
723 if (devfreq->dev.parent
724 && devfreq->dev.parent->of_node == node) {
725 mutex_unlock(&devfreq_list_lock);
Peter Chen3427c6f2016-07-01 17:42:00 +0800726 of_node_put(node);
Chanwoo Choi8f510ae2015-11-10 20:31:07 +0900727 return devfreq;
728 }
729 }
730 mutex_unlock(&devfreq_list_lock);
Peter Chen3427c6f2016-07-01 17:42:00 +0800731 of_node_put(node);
Chanwoo Choi8f510ae2015-11-10 20:31:07 +0900732
733 return ERR_PTR(-EPROBE_DEFER);
734}
735#else
736struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index)
737{
738 return ERR_PTR(-ENODEV);
739}
740#endif /* CONFIG_OF */
741EXPORT_SYMBOL_GPL(devfreq_get_devfreq_by_phandle);
742
Chanwoo Choi8cd84092014-05-09 16:43:08 +0900743/**
744 * devm_devfreq_remove_device() - Resource-managed devfreq_remove_device()
745 * @dev: the device to add devfreq feature.
746 * @devfreq: the devfreq instance to be removed
747 */
748void devm_devfreq_remove_device(struct device *dev, struct devfreq *devfreq)
749{
750 WARN_ON(devres_release(dev, devm_devfreq_dev_release,
751 devm_devfreq_dev_match, devfreq));
752}
753EXPORT_SYMBOL(devm_devfreq_remove_device);
754
Rajagopal Venkat206c30c2012-10-26 01:50:18 +0200755/**
756 * devfreq_suspend_device() - Suspend devfreq of a device.
757 * @devfreq: the devfreq instance to be suspended
MyungJoo Hamde9c7392013-02-05 18:40:17 +0900758 *
759 * This function is intended to be called by the pm callbacks
760 * (e.g., runtime_suspend, suspend) of the device driver that
761 * holds the devfreq.
Rajagopal Venkat206c30c2012-10-26 01:50:18 +0200762 */
763int devfreq_suspend_device(struct devfreq *devfreq)
764{
765 if (!devfreq)
766 return -EINVAL;
767
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500768 if (!devfreq->governor)
769 return 0;
770
Rajagopal Venkat206c30c2012-10-26 01:50:18 +0200771 return devfreq->governor->event_handler(devfreq,
772 DEVFREQ_GOV_SUSPEND, NULL);
773}
774EXPORT_SYMBOL(devfreq_suspend_device);
775
776/**
777 * devfreq_resume_device() - Resume devfreq of a device.
778 * @devfreq: the devfreq instance to be resumed
MyungJoo Hamde9c7392013-02-05 18:40:17 +0900779 *
780 * This function is intended to be called by the pm callbacks
781 * (e.g., runtime_resume, resume) of the device driver that
782 * holds the devfreq.
Rajagopal Venkat206c30c2012-10-26 01:50:18 +0200783 */
784int devfreq_resume_device(struct devfreq *devfreq)
785{
786 if (!devfreq)
787 return -EINVAL;
788
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500789 if (!devfreq->governor)
790 return 0;
791
Rajagopal Venkat206c30c2012-10-26 01:50:18 +0200792 return devfreq->governor->event_handler(devfreq,
793 DEVFREQ_GOV_RESUME, NULL);
794}
795EXPORT_SYMBOL(devfreq_resume_device);
796
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500797/**
798 * devfreq_add_governor() - Add devfreq governor
799 * @governor: the devfreq governor to be added
800 */
801int devfreq_add_governor(struct devfreq_governor *governor)
802{
803 struct devfreq_governor *g;
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500804 struct devfreq *devfreq;
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500805 int err = 0;
806
807 if (!governor) {
808 pr_err("%s: Invalid parameters.\n", __func__);
809 return -EINVAL;
810 }
811
812 mutex_lock(&devfreq_list_lock);
813 g = find_devfreq_governor(governor->name);
814 if (!IS_ERR(g)) {
815 pr_err("%s: governor %s already registered\n", __func__,
816 g->name);
817 err = -EINVAL;
818 goto err_out;
819 }
820
821 list_add(&governor->node, &devfreq_governor_list);
822
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500823 list_for_each_entry(devfreq, &devfreq_list, node) {
824 int ret = 0;
825 struct device *dev = devfreq->dev.parent;
826
827 if (!strncmp(devfreq->governor_name, governor->name,
828 DEVFREQ_NAME_LEN)) {
829 /* The following should never occur */
830 if (devfreq->governor) {
831 dev_warn(dev,
832 "%s: Governor %s already present\n",
833 __func__, devfreq->governor->name);
834 ret = devfreq->governor->event_handler(devfreq,
835 DEVFREQ_GOV_STOP, NULL);
836 if (ret) {
837 dev_warn(dev,
838 "%s: Governor %s stop = %d\n",
839 __func__,
840 devfreq->governor->name, ret);
841 }
842 /* Fall through */
843 }
844 devfreq->governor = governor;
845 ret = devfreq->governor->event_handler(devfreq,
846 DEVFREQ_GOV_START, NULL);
847 if (ret) {
848 dev_warn(dev, "%s: Governor %s start=%d\n",
849 __func__, devfreq->governor->name,
850 ret);
851 }
852 }
853 }
854
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500855err_out:
856 mutex_unlock(&devfreq_list_lock);
857
858 return err;
859}
860EXPORT_SYMBOL(devfreq_add_governor);
861
862/**
863 * devfreq_remove_device() - Remove devfreq feature from a device.
864 * @governor: the devfreq governor to be removed
865 */
866int devfreq_remove_governor(struct devfreq_governor *governor)
867{
868 struct devfreq_governor *g;
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500869 struct devfreq *devfreq;
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500870 int err = 0;
871
872 if (!governor) {
873 pr_err("%s: Invalid parameters.\n", __func__);
874 return -EINVAL;
875 }
876
877 mutex_lock(&devfreq_list_lock);
878 g = find_devfreq_governor(governor->name);
879 if (IS_ERR(g)) {
880 pr_err("%s: governor %s not registered\n", __func__,
Sachin Kamatb9e1c8e2012-11-21 10:36:13 +0530881 governor->name);
Sachin Kamatf9c08e22012-11-21 10:36:14 +0530882 err = PTR_ERR(g);
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500883 goto err_out;
884 }
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500885 list_for_each_entry(devfreq, &devfreq_list, node) {
886 int ret;
887 struct device *dev = devfreq->dev.parent;
888
889 if (!strncmp(devfreq->governor_name, governor->name,
890 DEVFREQ_NAME_LEN)) {
891 /* we should have a devfreq governor! */
892 if (!devfreq->governor) {
893 dev_warn(dev, "%s: Governor %s NOT present\n",
894 __func__, governor->name);
895 continue;
896 /* Fall through */
897 }
898 ret = devfreq->governor->event_handler(devfreq,
899 DEVFREQ_GOV_STOP, NULL);
900 if (ret) {
901 dev_warn(dev, "%s: Governor %s stop=%d\n",
902 __func__, devfreq->governor->name,
903 ret);
904 }
905 devfreq->governor = NULL;
906 }
907 }
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500908
909 list_del(&governor->node);
910err_out:
911 mutex_unlock(&devfreq_list_lock);
912
913 return err;
914}
915EXPORT_SYMBOL(devfreq_remove_governor);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200916
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -0700917static ssize_t governor_show(struct device *dev,
MyungJoo Ham9005b652011-10-02 00:19:28 +0200918 struct device_attribute *attr, char *buf)
919{
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500920 if (!to_devfreq(dev)->governor)
921 return -EINVAL;
922
MyungJoo Ham9005b652011-10-02 00:19:28 +0200923 return sprintf(buf, "%s\n", to_devfreq(dev)->governor->name);
924}
925
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -0700926static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
Nishanth Menon0359d1a2012-10-29 15:01:47 -0500927 const char *buf, size_t count)
928{
929 struct devfreq *df = to_devfreq(dev);
930 int ret;
931 char str_governor[DEVFREQ_NAME_LEN + 1];
932 struct devfreq_governor *governor;
933
934 ret = sscanf(buf, "%" __stringify(DEVFREQ_NAME_LEN) "s", str_governor);
935 if (ret != 1)
936 return -EINVAL;
937
938 mutex_lock(&devfreq_list_lock);
939 governor = find_devfreq_governor(str_governor);
940 if (IS_ERR(governor)) {
941 ret = PTR_ERR(governor);
942 goto out;
943 }
Tobias Jakobi14a21e72015-09-21 20:23:52 +0200944 if (df->governor == governor) {
945 ret = 0;
Nishanth Menon0359d1a2012-10-29 15:01:47 -0500946 goto out;
Gustavo A. R. Silva715f7e32017-12-06 14:20:15 -0600947 } else if ((df->governor && df->governor->immutable) ||
948 governor->immutable) {
Chanwoo Choi2294b772017-01-31 15:38:16 +0900949 ret = -EINVAL;
950 goto out;
Tobias Jakobi14a21e72015-09-21 20:23:52 +0200951 }
Nishanth Menon0359d1a2012-10-29 15:01:47 -0500952
953 if (df->governor) {
954 ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL);
955 if (ret) {
956 dev_warn(dev, "%s: Governor %s not stopped(%d)\n",
957 __func__, df->governor->name, ret);
958 goto out;
959 }
960 }
961 df->governor = governor;
962 strncpy(df->governor_name, governor->name, DEVFREQ_NAME_LEN);
963 ret = df->governor->event_handler(df, DEVFREQ_GOV_START, NULL);
964 if (ret)
965 dev_warn(dev, "%s: Governor %s not started(%d)\n",
966 __func__, df->governor->name, ret);
967out:
968 mutex_unlock(&devfreq_list_lock);
969
970 if (!ret)
971 ret = count;
972 return ret;
973}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -0700974static DEVICE_ATTR_RW(governor);
975
976static ssize_t available_governors_show(struct device *d,
977 struct device_attribute *attr,
978 char *buf)
Nishanth Menon50a5b332012-10-29 15:01:48 -0500979{
Chanwoo Choi2294b772017-01-31 15:38:16 +0900980 struct devfreq *df = to_devfreq(d);
Nishanth Menon50a5b332012-10-29 15:01:48 -0500981 ssize_t count = 0;
982
983 mutex_lock(&devfreq_list_lock);
Chanwoo Choi2294b772017-01-31 15:38:16 +0900984
985 /*
986 * The devfreq with immutable governor (e.g., passive) shows
987 * only own governor.
988 */
989 if (df->governor->immutable) {
990 count = scnprintf(&buf[count], DEVFREQ_NAME_LEN,
991 "%s ", df->governor_name);
992 /*
993 * The devfreq device shows the registered governor except for
994 * immutable governors such as passive governor .
995 */
996 } else {
997 struct devfreq_governor *governor;
998
999 list_for_each_entry(governor, &devfreq_governor_list, node) {
1000 if (governor->immutable)
1001 continue;
1002 count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
1003 "%s ", governor->name);
1004 }
1005 }
1006
Nishanth Menon50a5b332012-10-29 15:01:48 -05001007 mutex_unlock(&devfreq_list_lock);
1008
1009 /* Truncate the trailing space */
1010 if (count)
1011 count--;
1012
1013 count += sprintf(&buf[count], "\n");
1014
1015 return count;
1016}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001017static DEVICE_ATTR_RO(available_governors);
Nishanth Menon0359d1a2012-10-29 15:01:47 -05001018
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001019static ssize_t cur_freq_show(struct device *dev, struct device_attribute *attr,
1020 char *buf)
MyungJoo Ham9005b652011-10-02 00:19:28 +02001021{
Rajagopal Venkat7f98a902012-10-26 01:50:26 +02001022 unsigned long freq;
1023 struct devfreq *devfreq = to_devfreq(dev);
1024
1025 if (devfreq->profile->get_cur_freq &&
1026 !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
1027 return sprintf(buf, "%lu\n", freq);
1028
1029 return sprintf(buf, "%lu\n", devfreq->previous_freq);
1030}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001031static DEVICE_ATTR_RO(cur_freq);
Rajagopal Venkat7f98a902012-10-26 01:50:26 +02001032
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001033static ssize_t target_freq_show(struct device *dev,
1034 struct device_attribute *attr, char *buf)
Rajagopal Venkat7f98a902012-10-26 01:50:26 +02001035{
MyungJoo Ham9005b652011-10-02 00:19:28 +02001036 return sprintf(buf, "%lu\n", to_devfreq(dev)->previous_freq);
1037}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001038static DEVICE_ATTR_RO(target_freq);
MyungJoo Ham9005b652011-10-02 00:19:28 +02001039
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001040static ssize_t polling_interval_show(struct device *dev,
MyungJoo Ham9005b652011-10-02 00:19:28 +02001041 struct device_attribute *attr, char *buf)
1042{
1043 return sprintf(buf, "%d\n", to_devfreq(dev)->profile->polling_ms);
1044}
1045
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001046static ssize_t polling_interval_store(struct device *dev,
MyungJoo Ham9005b652011-10-02 00:19:28 +02001047 struct device_attribute *attr,
1048 const char *buf, size_t count)
1049{
1050 struct devfreq *df = to_devfreq(dev);
1051 unsigned int value;
1052 int ret;
1053
Nishanth Menon1b5c1be2012-10-29 15:01:45 -05001054 if (!df->governor)
1055 return -EINVAL;
1056
MyungJoo Ham9005b652011-10-02 00:19:28 +02001057 ret = sscanf(buf, "%u", &value);
1058 if (ret != 1)
Nishanth Menon12e26262012-10-26 01:50:43 +02001059 return -EINVAL;
MyungJoo Ham9005b652011-10-02 00:19:28 +02001060
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +02001061 df->governor->event_handler(df, DEVFREQ_GOV_INTERVAL, &value);
MyungJoo Ham9005b652011-10-02 00:19:28 +02001062 ret = count;
1063
MyungJoo Ham9005b652011-10-02 00:19:28 +02001064 return ret;
1065}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001066static DEVICE_ATTR_RW(polling_interval);
MyungJoo Ham9005b652011-10-02 00:19:28 +02001067
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001068static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr,
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001069 const char *buf, size_t count)
1070{
1071 struct devfreq *df = to_devfreq(dev);
1072 unsigned long value;
1073 int ret;
1074 unsigned long max;
1075
1076 ret = sscanf(buf, "%lu", &value);
1077 if (ret != 1)
Nishanth Menon12e26262012-10-26 01:50:43 +02001078 return -EINVAL;
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001079
1080 mutex_lock(&df->lock);
1081 max = df->max_freq;
1082 if (value && max && value > max) {
1083 ret = -EINVAL;
1084 goto unlock;
1085 }
1086
1087 df->min_freq = value;
1088 update_devfreq(df);
1089 ret = count;
1090unlock:
1091 mutex_unlock(&df->lock);
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001092 return ret;
1093}
1094
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001095static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr,
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001096 const char *buf, size_t count)
1097{
1098 struct devfreq *df = to_devfreq(dev);
1099 unsigned long value;
1100 int ret;
1101 unsigned long min;
1102
1103 ret = sscanf(buf, "%lu", &value);
1104 if (ret != 1)
Nishanth Menon12e26262012-10-26 01:50:43 +02001105 return -EINVAL;
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001106
1107 mutex_lock(&df->lock);
1108 min = df->min_freq;
1109 if (value && min && value < min) {
1110 ret = -EINVAL;
1111 goto unlock;
1112 }
1113
1114 df->max_freq = value;
1115 update_devfreq(df);
1116 ret = count;
1117unlock:
1118 mutex_unlock(&df->lock);
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001119 return ret;
1120}
1121
Chanwoo Choi3104fa32015-11-13 19:25:28 +09001122#define show_one(name) \
1123static ssize_t name##_show \
1124(struct device *dev, struct device_attribute *attr, char *buf) \
1125{ \
1126 return sprintf(buf, "%lu\n", to_devfreq(dev)->name); \
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001127}
Chanwoo Choi3104fa32015-11-13 19:25:28 +09001128show_one(min_freq);
1129show_one(max_freq);
1130
1131static DEVICE_ATTR_RW(min_freq);
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001132static DEVICE_ATTR_RW(max_freq);
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001133
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001134static ssize_t available_frequencies_show(struct device *d,
1135 struct device_attribute *attr,
1136 char *buf)
Nishanth Menond287de82012-10-25 19:48:59 -05001137{
1138 struct devfreq *df = to_devfreq(d);
1139 struct device *dev = df->dev.parent;
Nishanth Menon47d43ba2013-09-19 16:03:51 -05001140 struct dev_pm_opp *opp;
Nishanth Menond287de82012-10-25 19:48:59 -05001141 ssize_t count = 0;
1142 unsigned long freq = 0;
1143
1144 rcu_read_lock();
1145 do {
Nishanth Menon5d4879c2013-09-19 16:03:50 -05001146 opp = dev_pm_opp_find_freq_ceil(dev, &freq);
Nishanth Menond287de82012-10-25 19:48:59 -05001147 if (IS_ERR(opp))
1148 break;
1149
1150 count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
1151 "%lu ", freq);
1152 freq++;
1153 } while (1);
1154 rcu_read_unlock();
1155
1156 /* Truncate the trailing space */
1157 if (count)
1158 count--;
1159
1160 count += sprintf(&buf[count], "\n");
1161
1162 return count;
1163}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001164static DEVICE_ATTR_RO(available_frequencies);
Nishanth Menond287de82012-10-25 19:48:59 -05001165
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001166static ssize_t trans_stat_show(struct device *dev,
1167 struct device_attribute *attr, char *buf)
Jonghwa Leee552bba2012-08-23 20:00:46 +09001168{
1169 struct devfreq *devfreq = to_devfreq(dev);
1170 ssize_t len;
Rajagopal Venkat39688ce2013-01-08 11:20:39 +05301171 int i, j;
Jonghwa Leee552bba2012-08-23 20:00:46 +09001172 unsigned int max_state = devfreq->profile->max_state;
1173
MyungJoo Ham34bd3222015-11-23 15:45:36 +09001174 if (max_state == 0)
1175 return sprintf(buf, "Not Supported.\n");
Jonghwa Leee552bba2012-08-23 20:00:46 +09001176
Leonard Crestezb99f20c2019-09-24 10:52:23 +03001177 mutex_lock(&devfreq->lock);
1178 if (!devfreq->stop_polling &&
1179 devfreq_update_status(devfreq, devfreq->previous_freq)) {
1180 mutex_unlock(&devfreq->lock);
1181 return 0;
1182 }
1183 mutex_unlock(&devfreq->lock);
1184
Chanwoo Choid7df1e42015-11-19 16:28:46 +09001185 len = sprintf(buf, " From : To\n");
1186 len += sprintf(buf + len, " :");
Jonghwa Leee552bba2012-08-23 20:00:46 +09001187 for (i = 0; i < max_state; i++)
Chanwoo Choid7df1e42015-11-19 16:28:46 +09001188 len += sprintf(buf + len, "%10lu",
Jonghwa Leee552bba2012-08-23 20:00:46 +09001189 devfreq->profile->freq_table[i]);
1190
1191 len += sprintf(buf + len, " time(ms)\n");
1192
1193 for (i = 0; i < max_state; i++) {
1194 if (devfreq->profile->freq_table[i]
1195 == devfreq->previous_freq) {
1196 len += sprintf(buf + len, "*");
1197 } else {
1198 len += sprintf(buf + len, " ");
1199 }
Chanwoo Choid7df1e42015-11-19 16:28:46 +09001200 len += sprintf(buf + len, "%10lu:",
Jonghwa Leee552bba2012-08-23 20:00:46 +09001201 devfreq->profile->freq_table[i]);
1202 for (j = 0; j < max_state; j++)
Chanwoo Choid7df1e42015-11-19 16:28:46 +09001203 len += sprintf(buf + len, "%10u",
Jonghwa Leee552bba2012-08-23 20:00:46 +09001204 devfreq->trans_table[(i * max_state) + j]);
1205 len += sprintf(buf + len, "%10u\n",
1206 jiffies_to_msecs(devfreq->time_in_state[i]));
1207 }
1208
1209 len += sprintf(buf + len, "Total transition : %u\n",
1210 devfreq->total_trans);
1211 return len;
1212}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001213static DEVICE_ATTR_RO(trans_stat);
Jonghwa Leee552bba2012-08-23 20:00:46 +09001214
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001215static struct attribute *devfreq_attrs[] = {
1216 &dev_attr_governor.attr,
1217 &dev_attr_available_governors.attr,
1218 &dev_attr_cur_freq.attr,
1219 &dev_attr_available_frequencies.attr,
1220 &dev_attr_target_freq.attr,
1221 &dev_attr_polling_interval.attr,
1222 &dev_attr_min_freq.attr,
1223 &dev_attr_max_freq.attr,
1224 &dev_attr_trans_stat.attr,
1225 NULL,
MyungJoo Ham9005b652011-10-02 00:19:28 +02001226};
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001227ATTRIBUTE_GROUPS(devfreq);
MyungJoo Ham9005b652011-10-02 00:19:28 +02001228
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001229static int __init devfreq_init(void)
1230{
1231 devfreq_class = class_create(THIS_MODULE, "devfreq");
1232 if (IS_ERR(devfreq_class)) {
1233 pr_err("%s: couldn't create class\n", __FILE__);
1234 return PTR_ERR(devfreq_class);
1235 }
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +02001236
1237 devfreq_wq = create_freezable_workqueue("devfreq_wq");
Dan Carpenterea7f4542013-08-15 10:55:10 +03001238 if (!devfreq_wq) {
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +02001239 class_destroy(devfreq_class);
1240 pr_err("%s: couldn't create workqueue\n", __FILE__);
Dan Carpenterea7f4542013-08-15 10:55:10 +03001241 return -ENOMEM;
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +02001242 }
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001243 devfreq_class->dev_groups = devfreq_groups;
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +02001244
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001245 return 0;
1246}
1247subsys_initcall(devfreq_init);
1248
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001249/*
1250 * The followings are helper functions for devfreq user device drivers with
1251 * OPP framework.
1252 */
1253
1254/**
1255 * devfreq_recommended_opp() - Helper function to get proper OPP for the
1256 * freq value given to target callback.
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +02001257 * @dev: The devfreq user device. (parent of devfreq)
1258 * @freq: The frequency given to target function
1259 * @flags: Flags handed from devfreq framework.
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001260 *
Nishanth Menonbcb27542013-01-18 19:52:34 +00001261 * Locking: This function must be called under rcu_read_lock(). opp is a rcu
1262 * protected pointer. The reason for the same is that the opp pointer which is
1263 * returned will remain valid for use with opp_get_{voltage, freq} only while
1264 * under the locked area. The pointer returned must be used prior to unlocking
1265 * with rcu_read_unlock() to maintain the integrity of the pointer.
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001266 */
Nishanth Menon47d43ba2013-09-19 16:03:51 -05001267struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
1268 unsigned long *freq,
1269 u32 flags)
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001270{
Nishanth Menon47d43ba2013-09-19 16:03:51 -05001271 struct dev_pm_opp *opp;
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001272
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001273 if (flags & DEVFREQ_FLAG_LEAST_UPPER_BOUND) {
1274 /* The freq is an upper bound. opp should be lower */
Nishanth Menon5d4879c2013-09-19 16:03:50 -05001275 opp = dev_pm_opp_find_freq_floor(dev, freq);
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001276
1277 /* If not available, use the closest opp */
Nishanth Menon07797262012-10-24 22:00:12 +02001278 if (opp == ERR_PTR(-ERANGE))
Nishanth Menon5d4879c2013-09-19 16:03:50 -05001279 opp = dev_pm_opp_find_freq_ceil(dev, freq);
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001280 } else {
1281 /* The freq is an lower bound. opp should be higher */
Nishanth Menon5d4879c2013-09-19 16:03:50 -05001282 opp = dev_pm_opp_find_freq_ceil(dev, freq);
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001283
1284 /* If not available, use the closest opp */
Nishanth Menon07797262012-10-24 22:00:12 +02001285 if (opp == ERR_PTR(-ERANGE))
Nishanth Menon5d4879c2013-09-19 16:03:50 -05001286 opp = dev_pm_opp_find_freq_floor(dev, freq);
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001287 }
1288
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001289 return opp;
1290}
Ãrjan Eidebd7e9272014-07-18 15:09:53 +01001291EXPORT_SYMBOL(devfreq_recommended_opp);
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001292
1293/**
1294 * devfreq_register_opp_notifier() - Helper function to get devfreq notified
1295 * for any changes in the OPP availability
1296 * changes
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +02001297 * @dev: The devfreq user device. (parent of devfreq)
1298 * @devfreq: The devfreq object.
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001299 */
1300int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq)
1301{
MyungJoo Ham389baed2012-11-21 19:04:51 +09001302 struct srcu_notifier_head *nh;
1303 int ret = 0;
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001304
MyungJoo Ham389baed2012-11-21 19:04:51 +09001305 rcu_read_lock();
Nishanth Menon5d4879c2013-09-19 16:03:50 -05001306 nh = dev_pm_opp_get_notifier(dev);
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001307 if (IS_ERR(nh))
MyungJoo Ham389baed2012-11-21 19:04:51 +09001308 ret = PTR_ERR(nh);
1309 rcu_read_unlock();
1310 if (!ret)
1311 ret = srcu_notifier_chain_register(nh, &devfreq->nb);
1312
1313 return ret;
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001314}
Ãrjan Eidebd7e9272014-07-18 15:09:53 +01001315EXPORT_SYMBOL(devfreq_register_opp_notifier);
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001316
1317/**
1318 * devfreq_unregister_opp_notifier() - Helper function to stop getting devfreq
1319 * notified for any changes in the OPP
1320 * availability changes anymore.
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +02001321 * @dev: The devfreq user device. (parent of devfreq)
1322 * @devfreq: The devfreq object.
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001323 *
1324 * At exit() callback of devfreq_dev_profile, this must be included if
1325 * devfreq_recommended_opp is used.
1326 */
1327int devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq)
1328{
MyungJoo Ham389baed2012-11-21 19:04:51 +09001329 struct srcu_notifier_head *nh;
1330 int ret = 0;
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001331
MyungJoo Ham389baed2012-11-21 19:04:51 +09001332 rcu_read_lock();
Nishanth Menon5d4879c2013-09-19 16:03:50 -05001333 nh = dev_pm_opp_get_notifier(dev);
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001334 if (IS_ERR(nh))
MyungJoo Ham389baed2012-11-21 19:04:51 +09001335 ret = PTR_ERR(nh);
1336 rcu_read_unlock();
1337 if (!ret)
1338 ret = srcu_notifier_chain_unregister(nh, &devfreq->nb);
1339
1340 return ret;
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001341}
Ãrjan Eidebd7e9272014-07-18 15:09:53 +01001342EXPORT_SYMBOL(devfreq_unregister_opp_notifier);
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001343
Chanwoo Choid5b040d2014-05-09 16:43:09 +09001344static void devm_devfreq_opp_release(struct device *dev, void *res)
1345{
1346 devfreq_unregister_opp_notifier(dev, *(struct devfreq **)res);
1347}
1348
1349/**
1350 * devm_ devfreq_register_opp_notifier()
1351 * - Resource-managed devfreq_register_opp_notifier()
1352 * @dev: The devfreq user device. (parent of devfreq)
1353 * @devfreq: The devfreq object.
1354 */
1355int devm_devfreq_register_opp_notifier(struct device *dev,
1356 struct devfreq *devfreq)
1357{
1358 struct devfreq **ptr;
1359 int ret;
1360
1361 ptr = devres_alloc(devm_devfreq_opp_release, sizeof(*ptr), GFP_KERNEL);
1362 if (!ptr)
1363 return -ENOMEM;
1364
1365 ret = devfreq_register_opp_notifier(dev, devfreq);
1366 if (ret) {
1367 devres_free(ptr);
1368 return ret;
1369 }
1370
1371 *ptr = devfreq;
1372 devres_add(dev, ptr);
1373
1374 return 0;
1375}
1376EXPORT_SYMBOL(devm_devfreq_register_opp_notifier);
1377
1378/**
1379 * devm_devfreq_unregister_opp_notifier()
1380 * - Resource-managed devfreq_unregister_opp_notifier()
1381 * @dev: The devfreq user device. (parent of devfreq)
1382 * @devfreq: The devfreq object.
1383 */
1384void devm_devfreq_unregister_opp_notifier(struct device *dev,
1385 struct devfreq *devfreq)
1386{
1387 WARN_ON(devres_release(dev, devm_devfreq_opp_release,
1388 devm_devfreq_dev_match, devfreq));
1389}
1390EXPORT_SYMBOL(devm_devfreq_unregister_opp_notifier);
1391
Chanwoo Choi0fe3a662016-01-26 13:21:26 +09001392/**
1393 * devfreq_register_notifier() - Register a driver with devfreq
1394 * @devfreq: The devfreq object.
1395 * @nb: The notifier block to register.
1396 * @list: DEVFREQ_TRANSITION_NOTIFIER.
1397 */
1398int devfreq_register_notifier(struct devfreq *devfreq,
1399 struct notifier_block *nb,
1400 unsigned int list)
1401{
1402 int ret = 0;
1403
1404 if (!devfreq)
1405 return -EINVAL;
1406
1407 switch (list) {
1408 case DEVFREQ_TRANSITION_NOTIFIER:
1409 ret = srcu_notifier_chain_register(
1410 &devfreq->transition_notifier_list, nb);
1411 break;
1412 default:
1413 ret = -EINVAL;
1414 }
1415
1416 return ret;
1417}
1418EXPORT_SYMBOL(devfreq_register_notifier);
1419
1420/*
1421 * devfreq_unregister_notifier() - Unregister a driver with devfreq
1422 * @devfreq: The devfreq object.
1423 * @nb: The notifier block to be unregistered.
1424 * @list: DEVFREQ_TRANSITION_NOTIFIER.
1425 */
1426int devfreq_unregister_notifier(struct devfreq *devfreq,
1427 struct notifier_block *nb,
1428 unsigned int list)
1429{
1430 int ret = 0;
1431
1432 if (!devfreq)
1433 return -EINVAL;
1434
1435 switch (list) {
1436 case DEVFREQ_TRANSITION_NOTIFIER:
1437 ret = srcu_notifier_chain_unregister(
1438 &devfreq->transition_notifier_list, nb);
1439 break;
1440 default:
1441 ret = -EINVAL;
1442 }
1443
1444 return ret;
1445}
1446EXPORT_SYMBOL(devfreq_unregister_notifier);
1447
1448struct devfreq_notifier_devres {
1449 struct devfreq *devfreq;
1450 struct notifier_block *nb;
1451 unsigned int list;
1452};
1453
1454static void devm_devfreq_notifier_release(struct device *dev, void *res)
1455{
1456 struct devfreq_notifier_devres *this = res;
1457
1458 devfreq_unregister_notifier(this->devfreq, this->nb, this->list);
1459}
1460
1461/**
1462 * devm_devfreq_register_notifier()
1463 - Resource-managed devfreq_register_notifier()
1464 * @dev: The devfreq user device. (parent of devfreq)
1465 * @devfreq: The devfreq object.
1466 * @nb: The notifier block to be unregistered.
1467 * @list: DEVFREQ_TRANSITION_NOTIFIER.
1468 */
1469int devm_devfreq_register_notifier(struct device *dev,
1470 struct devfreq *devfreq,
1471 struct notifier_block *nb,
1472 unsigned int list)
1473{
1474 struct devfreq_notifier_devres *ptr;
1475 int ret;
1476
1477 ptr = devres_alloc(devm_devfreq_notifier_release, sizeof(*ptr),
1478 GFP_KERNEL);
1479 if (!ptr)
1480 return -ENOMEM;
1481
1482 ret = devfreq_register_notifier(devfreq, nb, list);
1483 if (ret) {
1484 devres_free(ptr);
1485 return ret;
1486 }
1487
1488 ptr->devfreq = devfreq;
1489 ptr->nb = nb;
1490 ptr->list = list;
1491 devres_add(dev, ptr);
1492
1493 return 0;
1494}
1495EXPORT_SYMBOL(devm_devfreq_register_notifier);
1496
1497/**
1498 * devm_devfreq_unregister_notifier()
1499 - Resource-managed devfreq_unregister_notifier()
1500 * @dev: The devfreq user device. (parent of devfreq)
1501 * @devfreq: The devfreq object.
1502 * @nb: The notifier block to be unregistered.
1503 * @list: DEVFREQ_TRANSITION_NOTIFIER.
1504 */
1505void devm_devfreq_unregister_notifier(struct device *dev,
1506 struct devfreq *devfreq,
1507 struct notifier_block *nb,
1508 unsigned int list)
1509{
1510 WARN_ON(devres_release(dev, devm_devfreq_notifier_release,
1511 devm_devfreq_dev_match, devfreq));
1512}
1513EXPORT_SYMBOL(devm_devfreq_unregister_notifier);