blob: 57f6944d65a6d21f4b5c87e3d1b8e4c43152bfdf [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
MyungJoo Hama3c98b82011-10-02 00:19:15 +02002/*
3 * devfreq: Generic Dynamic Voltage and Frequency Scaling (DVFS) Framework
4 * for Non-CPU Devices.
5 *
6 * Copyright (C) 2011 Samsung Electronics
7 * MyungJoo Ham <myungjoo.ham@samsung.com>
MyungJoo Hama3c98b82011-10-02 00:19:15 +02008 */
9
10#include <linux/kernel.h>
Enric Balletbo i Serra23c7b542018-07-04 10:45:50 +020011#include <linux/kmod.h>
MyungJoo Hama3c98b82011-10-02 00:19:15 +020012#include <linux/sched.h>
13#include <linux/errno.h>
14#include <linux/err.h>
15#include <linux/init.h>
Paul Gortmaker417dc4b2016-06-26 03:43:47 +090016#include <linux/export.h>
MyungJoo Hama3c98b82011-10-02 00:19:15 +020017#include <linux/slab.h>
MyungJoo Ham952f6d12011-11-10 10:16:23 +010018#include <linux/stat.h>
Nishanth Menone4db1c72013-09-19 16:03:52 -050019#include <linux/pm_opp.h>
MyungJoo Hama3c98b82011-10-02 00:19:15 +020020#include <linux/devfreq.h>
21#include <linux/workqueue.h>
22#include <linux/platform_device.h>
23#include <linux/list.h>
24#include <linux/printk.h>
25#include <linux/hrtimer.h>
Chanwoo Choi8f510ae2015-11-10 20:31:07 +090026#include <linux/of.h>
Leonard Crestez05d7ae12019-12-05 12:05:06 +020027#include <linux/pm_qos.h>
MyungJoo Hama3c98b82011-10-02 00:19:15 +020028#include "governor.h"
29
Lukasz Lubacf451ad2019-02-18 19:21:09 +010030#define CREATE_TRACE_POINTS
31#include <trace/events/devfreq.h>
32
Leonard Crestez05d7ae12019-12-05 12:05:06 +020033#define HZ_PER_KHZ 1000
34
Nishanth Menon1a1357e2012-10-26 01:50:53 +020035static struct class *devfreq_class;
MyungJoo Hama3c98b82011-10-02 00:19:15 +020036
37/*
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +020038 * devfreq core provides delayed work based load monitoring helper
39 * functions. Governors can use these or can implement their own
40 * monitoring mechanism.
MyungJoo Hama3c98b82011-10-02 00:19:15 +020041 */
MyungJoo Hama3c98b82011-10-02 00:19:15 +020042static struct workqueue_struct *devfreq_wq;
MyungJoo Hama3c98b82011-10-02 00:19:15 +020043
Nishanth Menon3aa173b2012-10-29 15:01:43 -050044/* The list of all device-devfreq governors */
45static LIST_HEAD(devfreq_governor_list);
MyungJoo Hama3c98b82011-10-02 00:19:15 +020046/* The list of all device-devfreq */
47static LIST_HEAD(devfreq_list);
48static DEFINE_MUTEX(devfreq_list_lock);
49
50/**
51 * find_device_devfreq() - find devfreq struct using device pointer
52 * @dev: device pointer used to lookup device devfreq.
53 *
54 * Search the list of device devfreqs and return the matched device's
55 * devfreq info. devfreq_list_lock should be held by the caller.
56 */
57static struct devfreq *find_device_devfreq(struct device *dev)
58{
59 struct devfreq *tmp_devfreq;
60
Viresh Kumar9348da22015-08-10 11:42:25 +053061 if (IS_ERR_OR_NULL(dev)) {
MyungJoo Hama3c98b82011-10-02 00:19:15 +020062 pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
63 return ERR_PTR(-EINVAL);
64 }
65 WARN(!mutex_is_locked(&devfreq_list_lock),
66 "devfreq_list_lock must be locked.");
67
68 list_for_each_entry(tmp_devfreq, &devfreq_list, node) {
69 if (tmp_devfreq->dev.parent == dev)
70 return tmp_devfreq;
71 }
72
73 return ERR_PTR(-ENODEV);
74}
75
Chanwoo Choiab8f58a2017-10-23 10:32:06 +090076static unsigned long find_available_min_freq(struct devfreq *devfreq)
77{
78 struct dev_pm_opp *opp;
79 unsigned long min_freq = 0;
80
81 opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &min_freq);
82 if (IS_ERR(opp))
83 min_freq = 0;
84 else
85 dev_pm_opp_put(opp);
86
87 return min_freq;
88}
89
90static unsigned long find_available_max_freq(struct devfreq *devfreq)
91{
92 struct dev_pm_opp *opp;
93 unsigned long max_freq = ULONG_MAX;
94
95 opp = dev_pm_opp_find_freq_floor(devfreq->dev.parent, &max_freq);
96 if (IS_ERR(opp))
97 max_freq = 0;
98 else
99 dev_pm_opp_put(opp);
100
101 return max_freq;
102}
103
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200104/**
Leonard Crestez46cecc02019-10-31 23:34:26 +0200105 * get_freq_range() - Get the current freq range
106 * @devfreq: the devfreq instance
107 * @min_freq: the min frequency
108 * @max_freq: the max frequency
109 *
110 * This takes into consideration all constraints.
111 */
112static void get_freq_range(struct devfreq *devfreq,
113 unsigned long *min_freq,
114 unsigned long *max_freq)
115{
116 unsigned long *freq_table = devfreq->profile->freq_table;
Leonard Crestez05d7ae12019-12-05 12:05:06 +0200117 s32 qos_min_freq, qos_max_freq;
Leonard Crestez46cecc02019-10-31 23:34:26 +0200118
119 lockdep_assert_held(&devfreq->lock);
120
121 /*
122 * Initialize minimum/maximum frequency from freq table.
123 * The devfreq drivers can initialize this in either ascending or
124 * descending order and devfreq core supports both.
125 */
126 if (freq_table[0] < freq_table[devfreq->profile->max_state - 1]) {
127 *min_freq = freq_table[0];
128 *max_freq = freq_table[devfreq->profile->max_state - 1];
129 } else {
130 *min_freq = freq_table[devfreq->profile->max_state - 1];
131 *max_freq = freq_table[0];
132 }
133
Leonard Crestez05d7ae12019-12-05 12:05:06 +0200134 /* Apply constraints from PM QoS */
135 qos_min_freq = dev_pm_qos_read_value(devfreq->dev.parent,
136 DEV_PM_QOS_MIN_FREQUENCY);
137 qos_max_freq = dev_pm_qos_read_value(devfreq->dev.parent,
138 DEV_PM_QOS_MAX_FREQUENCY);
139 *min_freq = max(*min_freq, (unsigned long)HZ_PER_KHZ * qos_min_freq);
140 if (qos_max_freq != PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE)
141 *max_freq = min(*max_freq,
142 (unsigned long)HZ_PER_KHZ * qos_max_freq);
143
Leonard Crestez46cecc02019-10-31 23:34:26 +0200144 /* Apply constraints from OPP interface */
145 *min_freq = max(*min_freq, devfreq->scaling_min_freq);
146 *max_freq = min(*max_freq, devfreq->scaling_max_freq);
147
148 if (*min_freq > *max_freq)
149 *min_freq = *max_freq;
150}
151
152/**
Jonghwa Leee552bba2012-08-23 20:00:46 +0900153 * devfreq_get_freq_level() - Lookup freq_table for the frequency
154 * @devfreq: the devfreq instance
155 * @freq: the target frequency
156 */
157static int devfreq_get_freq_level(struct devfreq *devfreq, unsigned long freq)
158{
159 int lev;
160
161 for (lev = 0; lev < devfreq->profile->max_state; lev++)
162 if (freq == devfreq->profile->freq_table[lev])
163 return lev;
164
165 return -EINVAL;
166}
167
Chanwoo Choiea572f82017-10-23 10:32:09 +0900168static int set_freq_table(struct devfreq *devfreq)
Chanwoo Choi0ec09ac2015-11-18 14:49:02 +0900169{
170 struct devfreq_dev_profile *profile = devfreq->profile;
171 struct dev_pm_opp *opp;
172 unsigned long freq;
173 int i, count;
174
175 /* Initialize the freq_table from OPP table */
176 count = dev_pm_opp_get_opp_count(devfreq->dev.parent);
177 if (count <= 0)
Chanwoo Choiea572f82017-10-23 10:32:09 +0900178 return -EINVAL;
Chanwoo Choi0ec09ac2015-11-18 14:49:02 +0900179
180 profile->max_state = count;
181 profile->freq_table = devm_kcalloc(devfreq->dev.parent,
182 profile->max_state,
183 sizeof(*profile->freq_table),
184 GFP_KERNEL);
185 if (!profile->freq_table) {
186 profile->max_state = 0;
Chanwoo Choiea572f82017-10-23 10:32:09 +0900187 return -ENOMEM;
Chanwoo Choi0ec09ac2015-11-18 14:49:02 +0900188 }
189
Chanwoo Choi0ec09ac2015-11-18 14:49:02 +0900190 for (i = 0, freq = 0; i < profile->max_state; i++, freq++) {
191 opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &freq);
192 if (IS_ERR(opp)) {
193 devm_kfree(devfreq->dev.parent, profile->freq_table);
194 profile->max_state = 0;
Chanwoo Choiea572f82017-10-23 10:32:09 +0900195 return PTR_ERR(opp);
Chanwoo Choi0ec09ac2015-11-18 14:49:02 +0900196 }
Viresh Kumar8a31d9d92017-01-23 10:11:47 +0530197 dev_pm_opp_put(opp);
Chanwoo Choi0ec09ac2015-11-18 14:49:02 +0900198 profile->freq_table[i] = freq;
199 }
Chanwoo Choiea572f82017-10-23 10:32:09 +0900200
201 return 0;
Chanwoo Choi0ec09ac2015-11-18 14:49:02 +0900202}
203
204/**
Jonghwa Leee552bba2012-08-23 20:00:46 +0900205 * devfreq_update_status() - Update statistics of devfreq behavior
206 * @devfreq: the devfreq instance
207 * @freq: the update target frequency
208 */
Chanwoo Choi30582c22017-01-31 15:38:17 +0900209int devfreq_update_status(struct devfreq *devfreq, unsigned long freq)
Jonghwa Leee552bba2012-08-23 20:00:46 +0900210{
Saravana Kannane35d35a2014-02-27 19:38:57 -0800211 int lev, prev_lev, ret = 0;
Jonghwa Leee552bba2012-08-23 20:00:46 +0900212 unsigned long cur_time;
213
Leonard Crestez2abb0d52019-09-24 10:52:23 +0300214 lockdep_assert_held(&devfreq->lock);
Jonghwa Leee552bba2012-08-23 20:00:46 +0900215 cur_time = jiffies;
Saravana Kannane35d35a2014-02-27 19:38:57 -0800216
Tobias Jakobid0563a02016-09-29 14:36:36 +0200217 /* Immediately exit if previous_freq is not initialized yet. */
218 if (!devfreq->previous_freq)
219 goto out;
220
Saravana Kannane35d35a2014-02-27 19:38:57 -0800221 prev_lev = devfreq_get_freq_level(devfreq, devfreq->previous_freq);
222 if (prev_lev < 0) {
223 ret = prev_lev;
224 goto out;
225 }
226
227 devfreq->time_in_state[prev_lev] +=
Jonghwa Leee552bba2012-08-23 20:00:46 +0900228 cur_time - devfreq->last_stat_updated;
Saravana Kannane35d35a2014-02-27 19:38:57 -0800229
230 lev = devfreq_get_freq_level(devfreq, freq);
231 if (lev < 0) {
232 ret = lev;
233 goto out;
234 }
235
236 if (lev != prev_lev) {
Jonghwa Leee552bba2012-08-23 20:00:46 +0900237 devfreq->trans_table[(prev_lev *
238 devfreq->profile->max_state) + lev]++;
239 devfreq->total_trans++;
240 }
Jonghwa Leee552bba2012-08-23 20:00:46 +0900241
Saravana Kannane35d35a2014-02-27 19:38:57 -0800242out:
243 devfreq->last_stat_updated = cur_time;
244 return ret;
Jonghwa Leee552bba2012-08-23 20:00:46 +0900245}
Chanwoo Choi30582c22017-01-31 15:38:17 +0900246EXPORT_SYMBOL(devfreq_update_status);
Jonghwa Leee552bba2012-08-23 20:00:46 +0900247
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500248/**
249 * find_devfreq_governor() - find devfreq governor from name
250 * @name: name of the governor
251 *
252 * Search the list of devfreq governors and return the matched
253 * governor's pointer. devfreq_list_lock should be held by the caller.
254 */
255static struct devfreq_governor *find_devfreq_governor(const char *name)
256{
257 struct devfreq_governor *tmp_governor;
258
Viresh Kumar9348da22015-08-10 11:42:25 +0530259 if (IS_ERR_OR_NULL(name)) {
Nishanth Menon3aa173b2012-10-29 15:01:43 -0500260 pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
261 return ERR_PTR(-EINVAL);
262 }
263 WARN(!mutex_is_locked(&devfreq_list_lock),
264 "devfreq_list_lock must be locked.");
265
266 list_for_each_entry(tmp_governor, &devfreq_governor_list, node) {
267 if (!strncmp(tmp_governor->name, name, DEVFREQ_NAME_LEN))
268 return tmp_governor;
269 }
270
271 return ERR_PTR(-ENODEV);
272}
273
Enric Balletbo i Serra23c7b542018-07-04 10:45:50 +0200274/**
275 * try_then_request_governor() - Try to find the governor and request the
276 * module if is not found.
277 * @name: name of the governor
278 *
279 * Search the list of devfreq governors and request the module and try again
280 * if is not found. This can happen when both drivers (the governor driver
281 * and the driver that call devfreq_add_device) are built as modules.
282 * devfreq_list_lock should be held by the caller. Returns the matched
Enric Balletbo i Serrab53b0122019-03-13 13:22:53 +0100283 * governor's pointer or an error pointer.
Enric Balletbo i Serra23c7b542018-07-04 10:45:50 +0200284 */
285static struct devfreq_governor *try_then_request_governor(const char *name)
286{
287 struct devfreq_governor *governor;
288 int err = 0;
289
290 if (IS_ERR_OR_NULL(name)) {
291 pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
292 return ERR_PTR(-EINVAL);
293 }
294 WARN(!mutex_is_locked(&devfreq_list_lock),
295 "devfreq_list_lock must be locked.");
296
297 governor = find_devfreq_governor(name);
298 if (IS_ERR(governor)) {
299 mutex_unlock(&devfreq_list_lock);
300
301 if (!strncmp(name, DEVFREQ_GOV_SIMPLE_ONDEMAND,
302 DEVFREQ_NAME_LEN))
303 err = request_module("governor_%s", "simpleondemand");
304 else
305 err = request_module("governor_%s", name);
306 /* Restore previous state before return */
307 mutex_lock(&devfreq_list_lock);
308 if (err)
Ezequiel Garcia7544fd72019-06-21 18:39:49 -0300309 return (err < 0) ? ERR_PTR(err) : ERR_PTR(-EINVAL);
Enric Balletbo i Serra23c7b542018-07-04 10:45:50 +0200310
311 governor = find_devfreq_governor(name);
312 }
313
314 return governor;
315}
316
Chanwoo Choi0fe3a662016-01-26 13:21:26 +0900317static int devfreq_notify_transition(struct devfreq *devfreq,
318 struct devfreq_freqs *freqs, unsigned int state)
319{
320 if (!devfreq)
321 return -EINVAL;
322
323 switch (state) {
324 case DEVFREQ_PRECHANGE:
325 srcu_notifier_call_chain(&devfreq->transition_notifier_list,
326 DEVFREQ_PRECHANGE, freqs);
327 break;
328
329 case DEVFREQ_POSTCHANGE:
330 srcu_notifier_call_chain(&devfreq->transition_notifier_list,
331 DEVFREQ_POSTCHANGE, freqs);
332 break;
333 default:
334 return -EINVAL;
335 }
336
337 return 0;
338}
339
Lukasz Luba63314172018-12-05 12:05:52 +0100340static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq,
341 u32 flags)
342{
343 struct devfreq_freqs freqs;
344 unsigned long cur_freq;
345 int err = 0;
346
347 if (devfreq->profile->get_cur_freq)
348 devfreq->profile->get_cur_freq(devfreq->dev.parent, &cur_freq);
349 else
350 cur_freq = devfreq->previous_freq;
351
352 freqs.old = cur_freq;
353 freqs.new = new_freq;
354 devfreq_notify_transition(devfreq, &freqs, DEVFREQ_PRECHANGE);
355
356 err = devfreq->profile->target(devfreq->dev.parent, &new_freq, flags);
357 if (err) {
358 freqs.new = cur_freq;
359 devfreq_notify_transition(devfreq, &freqs, DEVFREQ_POSTCHANGE);
360 return err;
361 }
362
363 freqs.new = new_freq;
364 devfreq_notify_transition(devfreq, &freqs, DEVFREQ_POSTCHANGE);
365
366 if (devfreq_update_status(devfreq, new_freq))
367 dev_err(&devfreq->dev,
368 "Couldn't update frequency transition information.\n");
369
370 devfreq->previous_freq = new_freq;
Lukasz Luba83f8ca42018-12-05 12:05:53 +0100371
372 if (devfreq->suspend_freq)
373 devfreq->resume_freq = cur_freq;
374
Lukasz Luba63314172018-12-05 12:05:52 +0100375 return err;
376}
377
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200378/* Load monitoring helper functions for governors use */
379
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200380/**
381 * update_devfreq() - Reevaluate the device and configure frequency.
382 * @devfreq: the devfreq instance.
383 *
384 * Note: Lock devfreq->lock before calling update_devfreq
385 * This function is exported for governors.
386 */
387int update_devfreq(struct devfreq *devfreq)
388{
Lukasz Luba63314172018-12-05 12:05:52 +0100389 unsigned long freq, min_freq, max_freq;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200390 int err = 0;
MyungJoo Hamab5f2992012-03-16 21:54:53 +0100391 u32 flags = 0;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200392
393 if (!mutex_is_locked(&devfreq->lock)) {
394 WARN(true, "devfreq->lock must be locked by the caller.\n");
395 return -EINVAL;
396 }
397
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500398 if (!devfreq->governor)
399 return -EINVAL;
400
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200401 /* Reevaluate the proper frequency */
402 err = devfreq->governor->get_target_freq(devfreq, &freq);
403 if (err)
404 return err;
Leonard Crestez46cecc02019-10-31 23:34:26 +0200405 get_freq_range(devfreq, &min_freq, &max_freq);
MyungJoo Hamab5f2992012-03-16 21:54:53 +0100406
Matthias Kaehlckedf5cf4a2018-08-03 13:05:09 -0700407 if (freq < min_freq) {
Chanwoo Choif1d981e2017-10-23 10:32:08 +0900408 freq = min_freq;
MyungJoo Hamab5f2992012-03-16 21:54:53 +0100409 flags &= ~DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use GLB */
410 }
Matthias Kaehlckedf5cf4a2018-08-03 13:05:09 -0700411 if (freq > max_freq) {
Chanwoo Choif1d981e2017-10-23 10:32:08 +0900412 freq = max_freq;
MyungJoo Hamab5f2992012-03-16 21:54:53 +0100413 flags |= DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use LUB */
414 }
415
Lukasz Luba63314172018-12-05 12:05:52 +0100416 return devfreq_set_target(devfreq, freq, flags);
Chanwoo Choi0fe3a662016-01-26 13:21:26 +0900417
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200418}
Nishanth Menon2df50212012-10-29 15:01:42 -0500419EXPORT_SYMBOL(update_devfreq);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200420
421/**
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200422 * devfreq_monitor() - Periodically poll devfreq objects.
423 * @work: the work struct used to run devfreq_monitor periodically.
424 *
425 */
426static void devfreq_monitor(struct work_struct *work)
427{
428 int err;
429 struct devfreq *devfreq = container_of(work,
430 struct devfreq, work.work);
431
432 mutex_lock(&devfreq->lock);
433 err = update_devfreq(devfreq);
434 if (err)
435 dev_err(&devfreq->dev, "dvfs failed with (%d) error\n", err);
436
437 queue_delayed_work(devfreq_wq, &devfreq->work,
438 msecs_to_jiffies(devfreq->profile->polling_ms));
439 mutex_unlock(&devfreq->lock);
Lukasz Lubacf451ad2019-02-18 19:21:09 +0100440
441 trace_devfreq_monitor(devfreq);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200442}
443
444/**
445 * devfreq_monitor_start() - Start load monitoring of devfreq instance
446 * @devfreq: the devfreq instance.
447 *
Gaël PORTAY2c090832019-05-02 14:27:36 -0400448 * Helper function for starting devfreq device load monitoring. By
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200449 * default delayed work based monitoring is supported. Function
450 * to be called from governor in response to DEVFREQ_GOV_START
451 * event when device is added to devfreq framework.
452 */
453void devfreq_monitor_start(struct devfreq *devfreq)
454{
Dmitry Osipenko5c0f6c72019-11-05 00:56:14 +0300455 if (devfreq->governor->interrupt_driven)
456 return;
457
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200458 INIT_DEFERRABLE_WORK(&devfreq->work, devfreq_monitor);
459 if (devfreq->profile->polling_ms)
460 queue_delayed_work(devfreq_wq, &devfreq->work,
461 msecs_to_jiffies(devfreq->profile->polling_ms));
462}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100463EXPORT_SYMBOL(devfreq_monitor_start);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200464
465/**
466 * devfreq_monitor_stop() - Stop load monitoring of a devfreq instance
467 * @devfreq: the devfreq instance.
468 *
Gaël PORTAY2c090832019-05-02 14:27:36 -0400469 * Helper function to stop devfreq device load monitoring. Function
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200470 * to be called from governor in response to DEVFREQ_GOV_STOP
471 * event when device is removed from devfreq framework.
472 */
473void devfreq_monitor_stop(struct devfreq *devfreq)
474{
Dmitry Osipenko5c0f6c72019-11-05 00:56:14 +0300475 if (devfreq->governor->interrupt_driven)
476 return;
477
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200478 cancel_delayed_work_sync(&devfreq->work);
479}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100480EXPORT_SYMBOL(devfreq_monitor_stop);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200481
482/**
483 * devfreq_monitor_suspend() - Suspend load monitoring of a devfreq instance
484 * @devfreq: the devfreq instance.
485 *
Gaël PORTAY2c090832019-05-02 14:27:36 -0400486 * Helper function to suspend devfreq device load monitoring. Function
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200487 * to be called from governor in response to DEVFREQ_GOV_SUSPEND
488 * event or when polling interval is set to zero.
489 *
490 * Note: Though this function is same as devfreq_monitor_stop(),
491 * intentionally kept separate to provide hooks for collecting
492 * transition statistics.
493 */
494void devfreq_monitor_suspend(struct devfreq *devfreq)
495{
496 mutex_lock(&devfreq->lock);
497 if (devfreq->stop_polling) {
498 mutex_unlock(&devfreq->lock);
499 return;
500 }
501
Rajagopal Venkat39688ce62013-01-08 11:20:39 +0530502 devfreq_update_status(devfreq, devfreq->previous_freq);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200503 devfreq->stop_polling = true;
504 mutex_unlock(&devfreq->lock);
Dmitry Osipenko5c0f6c72019-11-05 00:56:14 +0300505
506 if (devfreq->governor->interrupt_driven)
507 return;
508
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200509 cancel_delayed_work_sync(&devfreq->work);
510}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100511EXPORT_SYMBOL(devfreq_monitor_suspend);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200512
513/**
514 * devfreq_monitor_resume() - Resume load monitoring of a devfreq instance
515 * @devfreq: the devfreq instance.
516 *
Gaël PORTAY2c090832019-05-02 14:27:36 -0400517 * Helper function to resume devfreq device load monitoring. Function
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200518 * to be called from governor in response to DEVFREQ_GOV_RESUME
519 * event or when polling interval is set to non-zero.
520 */
521void devfreq_monitor_resume(struct devfreq *devfreq)
522{
Rajagopal Venkat39688ce62013-01-08 11:20:39 +0530523 unsigned long freq;
524
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200525 mutex_lock(&devfreq->lock);
526 if (!devfreq->stop_polling)
527 goto out;
528
Dmitry Osipenko5c0f6c72019-11-05 00:56:14 +0300529 if (devfreq->governor->interrupt_driven)
530 goto out_update;
531
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200532 if (!delayed_work_pending(&devfreq->work) &&
533 devfreq->profile->polling_ms)
534 queue_delayed_work(devfreq_wq, &devfreq->work,
535 msecs_to_jiffies(devfreq->profile->polling_ms));
Rajagopal Venkat39688ce62013-01-08 11:20:39 +0530536
Dmitry Osipenko5c0f6c72019-11-05 00:56:14 +0300537out_update:
Rajagopal Venkat39688ce62013-01-08 11:20:39 +0530538 devfreq->last_stat_updated = jiffies;
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200539 devfreq->stop_polling = false;
540
Rajagopal Venkat39688ce62013-01-08 11:20:39 +0530541 if (devfreq->profile->get_cur_freq &&
542 !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
543 devfreq->previous_freq = freq;
544
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200545out:
546 mutex_unlock(&devfreq->lock);
547}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100548EXPORT_SYMBOL(devfreq_monitor_resume);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200549
550/**
551 * devfreq_interval_update() - Update device devfreq monitoring interval
552 * @devfreq: the devfreq instance.
553 * @delay: new polling interval to be set.
554 *
555 * Helper function to set new load monitoring polling interval. Function
556 * to be called from governor in response to DEVFREQ_GOV_INTERVAL event.
557 */
558void devfreq_interval_update(struct devfreq *devfreq, unsigned int *delay)
559{
560 unsigned int cur_delay = devfreq->profile->polling_ms;
561 unsigned int new_delay = *delay;
562
563 mutex_lock(&devfreq->lock);
564 devfreq->profile->polling_ms = new_delay;
565
566 if (devfreq->stop_polling)
567 goto out;
568
Dmitry Osipenko5c0f6c72019-11-05 00:56:14 +0300569 if (devfreq->governor->interrupt_driven)
570 goto out;
571
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200572 /* if new delay is zero, stop polling */
573 if (!new_delay) {
574 mutex_unlock(&devfreq->lock);
575 cancel_delayed_work_sync(&devfreq->work);
576 return;
577 }
578
579 /* if current delay is zero, start polling with new delay */
580 if (!cur_delay) {
581 queue_delayed_work(devfreq_wq, &devfreq->work,
582 msecs_to_jiffies(devfreq->profile->polling_ms));
583 goto out;
584 }
585
586 /* if current delay is greater than new delay, restart polling */
587 if (cur_delay > new_delay) {
588 mutex_unlock(&devfreq->lock);
589 cancel_delayed_work_sync(&devfreq->work);
590 mutex_lock(&devfreq->lock);
591 if (!devfreq->stop_polling)
592 queue_delayed_work(devfreq_wq, &devfreq->work,
MyungJoo Ham6d690f72019-01-21 11:11:07 +0900593 msecs_to_jiffies(devfreq->profile->polling_ms));
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200594 }
595out:
596 mutex_unlock(&devfreq->lock);
597}
MyungJoo Ham6dcdd8e2012-11-28 20:29:17 +0100598EXPORT_SYMBOL(devfreq_interval_update);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200599
600/**
601 * devfreq_notifier_call() - Notify that the device frequency requirements
MyungJoo Ham6d690f72019-01-21 11:11:07 +0900602 * has been changed out of devfreq framework.
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +0200603 * @nb: the notifier_block (supposed to be devfreq->nb)
604 * @type: not used
605 * @devp: not used
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200606 *
607 * Called by a notifier that uses devfreq->nb.
608 */
609static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type,
610 void *devp)
611{
612 struct devfreq *devfreq = container_of(nb, struct devfreq, nb);
Leonard Cresteze876e712019-10-31 23:34:18 +0200613 int err = -EINVAL;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200614
615 mutex_lock(&devfreq->lock);
Chanwoo Choif1d981e2017-10-23 10:32:08 +0900616
617 devfreq->scaling_min_freq = find_available_min_freq(devfreq);
Leonard Cresteze876e712019-10-31 23:34:18 +0200618 if (!devfreq->scaling_min_freq)
619 goto out;
Chanwoo Choif1d981e2017-10-23 10:32:08 +0900620
621 devfreq->scaling_max_freq = find_available_max_freq(devfreq);
Leonard Cresteze7cc7922019-10-31 23:34:19 +0200622 if (!devfreq->scaling_max_freq) {
623 devfreq->scaling_max_freq = ULONG_MAX;
Leonard Cresteze876e712019-10-31 23:34:18 +0200624 goto out;
Leonard Cresteze7cc7922019-10-31 23:34:19 +0200625 }
Chanwoo Choif1d981e2017-10-23 10:32:08 +0900626
Leonard Cresteze876e712019-10-31 23:34:18 +0200627 err = update_devfreq(devfreq);
628
629out:
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200630 mutex_unlock(&devfreq->lock);
Leonard Cresteze876e712019-10-31 23:34:18 +0200631 if (err)
632 dev_err(devfreq->dev.parent,
633 "failed to update frequency from OPP notifier (%d)\n",
634 err);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200635
Leonard Cresteze876e712019-10-31 23:34:18 +0200636 return NOTIFY_OK;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200637}
638
639/**
Leonard Crestez05d7ae12019-12-05 12:05:06 +0200640 * qos_notifier_call() - Common handler for QoS constraints.
641 * @devfreq: the devfreq instance.
642 */
643static int qos_notifier_call(struct devfreq *devfreq)
644{
645 int err;
646
647 mutex_lock(&devfreq->lock);
648 err = update_devfreq(devfreq);
649 mutex_unlock(&devfreq->lock);
650 if (err)
651 dev_err(devfreq->dev.parent,
652 "failed to update frequency from PM QoS (%d)\n",
653 err);
654
655 return NOTIFY_OK;
656}
657
658/**
659 * qos_min_notifier_call() - Callback for QoS min_freq changes.
660 * @nb: Should be devfreq->nb_min
661 */
662static int qos_min_notifier_call(struct notifier_block *nb,
663 unsigned long val, void *ptr)
664{
665 return qos_notifier_call(container_of(nb, struct devfreq, nb_min));
666}
667
668/**
669 * qos_max_notifier_call() - Callback for QoS max_freq changes.
670 * @nb: Should be devfreq->nb_max
671 */
672static int qos_max_notifier_call(struct notifier_block *nb,
673 unsigned long val, void *ptr)
674{
675 return qos_notifier_call(container_of(nb, struct devfreq, nb_max));
676}
677
678/**
Chanwoo Choi29b69682017-01-31 15:38:18 +0900679 * devfreq_dev_release() - Callback for struct device to release the device.
680 * @dev: the devfreq device
681 *
682 * Remove devfreq from the list and release its resources.
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200683 */
Chanwoo Choi29b69682017-01-31 15:38:18 +0900684static void devfreq_dev_release(struct device *dev)
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200685{
Chanwoo Choi29b69682017-01-31 15:38:18 +0900686 struct devfreq *devfreq = to_devfreq(dev);
Leonard Crestez05d7ae12019-12-05 12:05:06 +0200687 int err;
Chanwoo Choi29b69682017-01-31 15:38:18 +0900688
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200689 mutex_lock(&devfreq_list_lock);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200690 list_del(&devfreq->node);
691 mutex_unlock(&devfreq_list_lock);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200692
Leonard Crestez05d7ae12019-12-05 12:05:06 +0200693 err = dev_pm_qos_remove_notifier(devfreq->dev.parent, &devfreq->nb_max,
694 DEV_PM_QOS_MAX_FREQUENCY);
695 if (err && err != -ENOENT)
696 dev_warn(dev->parent,
697 "Failed to remove max_freq notifier: %d\n", err);
698 err = dev_pm_qos_remove_notifier(devfreq->dev.parent, &devfreq->nb_min,
699 DEV_PM_QOS_MIN_FREQUENCY);
700 if (err && err != -ENOENT)
701 dev_warn(dev->parent,
702 "Failed to remove min_freq notifier: %d\n", err);
703
Leonard Crestez27dbc542019-12-05 12:05:07 +0200704 if (dev_pm_qos_request_active(&devfreq->user_max_freq_req)) {
705 err = dev_pm_qos_remove_request(&devfreq->user_max_freq_req);
706 if (err)
707 dev_warn(dev->parent,
708 "Failed to remove max_freq request: %d\n", err);
709 }
710 if (dev_pm_qos_request_active(&devfreq->user_min_freq_req)) {
711 err = dev_pm_qos_remove_request(&devfreq->user_min_freq_req);
712 if (err)
713 dev_warn(dev->parent,
714 "Failed to remove min_freq request: %d\n", err);
715 }
716
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200717 if (devfreq->profile->exit)
718 devfreq->profile->exit(devfreq->dev.parent);
719
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200720 mutex_destroy(&devfreq->lock);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200721 kfree(devfreq);
722}
723
724/**
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200725 * devfreq_add_device() - Add devfreq feature to the device
726 * @dev: the device to add devfreq feature.
727 * @profile: device-specific profile to run devfreq.
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500728 * @governor_name: name of the policy to choose frequency.
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200729 * @data: private data for the governor. The devfreq framework does not
730 * touch this value.
731 */
732struct devfreq *devfreq_add_device(struct device *dev,
733 struct devfreq_dev_profile *profile,
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500734 const char *governor_name,
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200735 void *data)
736{
737 struct devfreq *devfreq;
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500738 struct devfreq_governor *governor;
Chanwoo Choi4585fbc2017-01-31 16:47:57 +0900739 static atomic_t devfreq_no = ATOMIC_INIT(-1);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200740 int err = 0;
741
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500742 if (!dev || !profile || !governor_name) {
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200743 dev_err(dev, "%s: Invalid parameters.\n", __func__);
744 return ERR_PTR(-EINVAL);
745 }
746
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200747 mutex_lock(&devfreq_list_lock);
748 devfreq = find_device_devfreq(dev);
749 mutex_unlock(&devfreq_list_lock);
750 if (!IS_ERR(devfreq)) {
Matthias Kaehlckedf4d7b12019-09-18 17:09:46 -0700751 dev_err(dev, "%s: devfreq device already exists!\n",
Chanwoo Choi9d0109b2016-11-19 22:47:36 +0900752 __func__);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200753 err = -EINVAL;
754 goto err_out;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200755 }
756
757 devfreq = kzalloc(sizeof(struct devfreq), GFP_KERNEL);
758 if (!devfreq) {
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200759 err = -ENOMEM;
Axel Lin3f19f082011-11-15 21:59:09 +0100760 goto err_out;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200761 }
762
763 mutex_init(&devfreq->lock);
764 mutex_lock(&devfreq->lock);
765 devfreq->dev.parent = dev;
766 devfreq->dev.class = devfreq_class;
767 devfreq->dev.release = devfreq_dev_release;
Leonard Crestez42a6b252019-11-14 01:21:31 +0200768 INIT_LIST_HEAD(&devfreq->node);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200769 devfreq->profile = profile;
Nishanth Menon1b5c1be2012-10-29 15:01:45 -0500770 strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200771 devfreq->previous_freq = profile->initial_freq;
Lukasz Luba8d39fc082016-05-31 11:25:09 +0100772 devfreq->last_status.current_frequency = profile->initial_freq;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200773 devfreq->data = data;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200774 devfreq->nb.notifier_call = devfreq_notifier_call;
775
Chanwoo Choi0ec09ac2015-11-18 14:49:02 +0900776 if (!devfreq->profile->max_state && !devfreq->profile->freq_table) {
777 mutex_unlock(&devfreq->lock);
Chanwoo Choiea572f82017-10-23 10:32:09 +0900778 err = set_freq_table(devfreq);
779 if (err < 0)
Yangtao Lia9487912019-01-19 11:04:54 -0500780 goto err_dev;
Chanwoo Choi0ec09ac2015-11-18 14:49:02 +0900781 mutex_lock(&devfreq->lock);
782 }
783
Matthias Kaehlcke2c2cb1e62018-05-25 13:30:33 -0700784 devfreq->scaling_min_freq = find_available_min_freq(devfreq);
785 if (!devfreq->scaling_min_freq) {
Chanwoo Choiab8f58a2017-10-23 10:32:06 +0900786 mutex_unlock(&devfreq->lock);
787 err = -EINVAL;
788 goto err_dev;
789 }
790
Matthias Kaehlcke2c2cb1e62018-05-25 13:30:33 -0700791 devfreq->scaling_max_freq = find_available_max_freq(devfreq);
792 if (!devfreq->scaling_max_freq) {
Chanwoo Choiab8f58a2017-10-23 10:32:06 +0900793 mutex_unlock(&devfreq->lock);
794 err = -EINVAL;
795 goto err_dev;
796 }
797
Lukasz Luba83f8ca42018-12-05 12:05:53 +0100798 devfreq->suspend_freq = dev_pm_opp_get_suspend_opp_freq(dev);
799 atomic_set(&devfreq->suspend_count, 0);
800
Chanwoo Choi4585fbc2017-01-31 16:47:57 +0900801 dev_set_name(&devfreq->dev, "devfreq%d",
802 atomic_inc_return(&devfreq_no));
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200803 err = device_register(&devfreq->dev);
804 if (err) {
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200805 mutex_unlock(&devfreq->lock);
Arvind Yadav2d803dc2018-03-30 17:14:03 +0530806 put_device(&devfreq->dev);
807 goto err_out;
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200808 }
809
MyungJoo Ham6d690f72019-01-21 11:11:07 +0900810 devfreq->trans_table = devm_kzalloc(&devfreq->dev,
811 array3_size(sizeof(unsigned int),
812 devfreq->profile->max_state,
813 devfreq->profile->max_state),
814 GFP_KERNEL);
Yangtao Li25846fa2019-01-19 11:04:53 -0500815 if (!devfreq->trans_table) {
816 mutex_unlock(&devfreq->lock);
817 err = -ENOMEM;
818 goto err_devfreq;
819 }
820
Kees Cooka86854d2018-06-12 14:07:58 -0700821 devfreq->time_in_state = devm_kcalloc(&devfreq->dev,
MyungJoo Ham6d690f72019-01-21 11:11:07 +0900822 devfreq->profile->max_state,
823 sizeof(unsigned long),
824 GFP_KERNEL);
Yangtao Li25846fa2019-01-19 11:04:53 -0500825 if (!devfreq->time_in_state) {
826 mutex_unlock(&devfreq->lock);
827 err = -ENOMEM;
828 goto err_devfreq;
829 }
830
MyungJoo Ham3e1d7fb2015-10-02 12:39:23 +0900831 devfreq->last_stat_updated = jiffies;
832
Chanwoo Choi0fe3a662016-01-26 13:21:26 +0900833 srcu_init_notifier_head(&devfreq->transition_notifier_list);
834
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200835 mutex_unlock(&devfreq->lock);
836
Leonard Crestez27dbc542019-12-05 12:05:07 +0200837 err = dev_pm_qos_add_request(dev, &devfreq->user_min_freq_req,
838 DEV_PM_QOS_MIN_FREQUENCY, 0);
839 if (err < 0)
840 goto err_devfreq;
841 err = dev_pm_qos_add_request(dev, &devfreq->user_max_freq_req,
842 DEV_PM_QOS_MAX_FREQUENCY,
843 PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE);
844 if (err < 0)
845 goto err_devfreq;
846
Leonard Crestez05d7ae12019-12-05 12:05:06 +0200847 devfreq->nb_min.notifier_call = qos_min_notifier_call;
848 err = dev_pm_qos_add_notifier(devfreq->dev.parent, &devfreq->nb_min,
849 DEV_PM_QOS_MIN_FREQUENCY);
850 if (err)
851 goto err_devfreq;
852
853 devfreq->nb_max.notifier_call = qos_max_notifier_call;
854 err = dev_pm_qos_add_notifier(devfreq->dev.parent, &devfreq->nb_max,
855 DEV_PM_QOS_MAX_FREQUENCY);
856 if (err)
857 goto err_devfreq;
858
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200859 mutex_lock(&devfreq_list_lock);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200860
Enric Balletbo i Serra23c7b542018-07-04 10:45:50 +0200861 governor = try_then_request_governor(devfreq->governor_name);
Chanwoo Choi73613b12016-12-28 20:52:35 +0900862 if (IS_ERR(governor)) {
863 dev_err(dev, "%s: Unable to find governor for the device\n",
864 __func__);
865 err = PTR_ERR(governor);
866 goto err_init;
867 }
868
869 devfreq->governor = governor;
870 err = devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_START,
871 NULL);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200872 if (err) {
873 dev_err(dev, "%s: Unable to start governor for the device\n",
874 __func__);
875 goto err_init;
876 }
Enric Balletbo i Serra23c7b542018-07-04 10:45:50 +0200877
878 list_add(&devfreq->node, &devfreq_list);
879
Axel Lin0f376c92016-09-29 10:13:28 +0800880 mutex_unlock(&devfreq_list_lock);
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200881
Axel Lin3f19f082011-11-15 21:59:09 +0100882 return devfreq;
883
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200884err_init:
Axel Lin0f376c92016-09-29 10:13:28 +0800885 mutex_unlock(&devfreq_list_lock);
Yangtao Li25846fa2019-01-19 11:04:53 -0500886err_devfreq:
Vincent Donnefort2f061fd2018-09-03 09:02:07 +0900887 devfreq_remove_device(devfreq);
Arvind Yadav2d803dc2018-03-30 17:14:03 +0530888 devfreq = NULL;
Chanwoo Choi9e14de12017-08-24 10:42:48 +0900889err_dev:
zhong jiang8188b152018-09-21 21:18:43 +0800890 kfree(devfreq);
Axel Lin3f19f082011-11-15 21:59:09 +0100891err_out:
892 return ERR_PTR(err);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200893}
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200894EXPORT_SYMBOL(devfreq_add_device);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200895
896/**
897 * devfreq_remove_device() - Remove devfreq feature from a device.
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +0200898 * @devfreq: the devfreq instance to be removed
MyungJoo Hamde9c7392013-02-05 18:40:17 +0900899 *
900 * The opposite of devfreq_add_device().
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200901 */
902int devfreq_remove_device(struct devfreq *devfreq)
903{
904 if (!devfreq)
905 return -EINVAL;
906
Vincent Donnefort2f061fd2018-09-03 09:02:07 +0900907 if (devfreq->governor)
908 devfreq->governor->event_handler(devfreq,
909 DEVFREQ_GOV_STOP, NULL);
Chanwoo Choi585fc832014-05-09 16:43:07 +0900910 device_unregister(&devfreq->dev);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200911
912 return 0;
913}
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +0200914EXPORT_SYMBOL(devfreq_remove_device);
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200915
Chanwoo Choi8cd84092014-05-09 16:43:08 +0900916static int devm_devfreq_dev_match(struct device *dev, void *res, void *data)
917{
918 struct devfreq **r = res;
919
920 if (WARN_ON(!r || !*r))
921 return 0;
922
923 return *r == data;
924}
925
926static void devm_devfreq_dev_release(struct device *dev, void *res)
927{
928 devfreq_remove_device(*(struct devfreq **)res);
929}
930
931/**
932 * devm_devfreq_add_device() - Resource-managed devfreq_add_device()
933 * @dev: the device to add devfreq feature.
934 * @profile: device-specific profile to run devfreq.
935 * @governor_name: name of the policy to choose frequency.
936 * @data: private data for the governor. The devfreq framework does not
937 * touch this value.
938 *
939 * This function manages automatically the memory of devfreq device using device
940 * resource management and simplify the free operation for memory of devfreq
941 * device.
942 */
943struct devfreq *devm_devfreq_add_device(struct device *dev,
944 struct devfreq_dev_profile *profile,
945 const char *governor_name,
946 void *data)
947{
948 struct devfreq **ptr, *devfreq;
949
950 ptr = devres_alloc(devm_devfreq_dev_release, sizeof(*ptr), GFP_KERNEL);
951 if (!ptr)
952 return ERR_PTR(-ENOMEM);
953
954 devfreq = devfreq_add_device(dev, profile, governor_name, data);
955 if (IS_ERR(devfreq)) {
956 devres_free(ptr);
Bjorn Anderssond1bf2d302017-11-05 21:27:41 -0800957 return devfreq;
Chanwoo Choi8cd84092014-05-09 16:43:08 +0900958 }
959
960 *ptr = devfreq;
961 devres_add(dev, ptr);
962
963 return devfreq;
964}
965EXPORT_SYMBOL(devm_devfreq_add_device);
966
Chanwoo Choi8f510ae2015-11-10 20:31:07 +0900967#ifdef CONFIG_OF
968/*
969 * devfreq_get_devfreq_by_phandle - Get the devfreq device from devicetree
970 * @dev - instance to the given device
971 * @index - index into list of devfreq
972 *
973 * return the instance of devfreq device
974 */
975struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index)
976{
977 struct device_node *node;
978 struct devfreq *devfreq;
979
980 if (!dev)
981 return ERR_PTR(-EINVAL);
982
983 if (!dev->of_node)
984 return ERR_PTR(-EINVAL);
985
986 node = of_parse_phandle(dev->of_node, "devfreq", index);
987 if (!node)
988 return ERR_PTR(-ENODEV);
989
990 mutex_lock(&devfreq_list_lock);
991 list_for_each_entry(devfreq, &devfreq_list, node) {
992 if (devfreq->dev.parent
993 && devfreq->dev.parent->of_node == node) {
994 mutex_unlock(&devfreq_list_lock);
Peter Chen3427c6f2016-07-01 17:42:00 +0800995 of_node_put(node);
Chanwoo Choi8f510ae2015-11-10 20:31:07 +0900996 return devfreq;
997 }
998 }
999 mutex_unlock(&devfreq_list_lock);
Peter Chen3427c6f2016-07-01 17:42:00 +08001000 of_node_put(node);
Chanwoo Choi8f510ae2015-11-10 20:31:07 +09001001
1002 return ERR_PTR(-EPROBE_DEFER);
1003}
1004#else
1005struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index)
1006{
1007 return ERR_PTR(-ENODEV);
1008}
1009#endif /* CONFIG_OF */
1010EXPORT_SYMBOL_GPL(devfreq_get_devfreq_by_phandle);
1011
Chanwoo Choi8cd84092014-05-09 16:43:08 +09001012/**
1013 * devm_devfreq_remove_device() - Resource-managed devfreq_remove_device()
Krzysztof Kozlowskie2fc1672019-07-24 20:59:53 +02001014 * @dev: the device from which to remove devfreq feature.
Chanwoo Choi8cd84092014-05-09 16:43:08 +09001015 * @devfreq: the devfreq instance to be removed
1016 */
1017void devm_devfreq_remove_device(struct device *dev, struct devfreq *devfreq)
1018{
1019 WARN_ON(devres_release(dev, devm_devfreq_dev_release,
1020 devm_devfreq_dev_match, devfreq));
1021}
1022EXPORT_SYMBOL(devm_devfreq_remove_device);
1023
Rajagopal Venkat206c30c2012-10-26 01:50:18 +02001024/**
1025 * devfreq_suspend_device() - Suspend devfreq of a device.
1026 * @devfreq: the devfreq instance to be suspended
MyungJoo Hamde9c7392013-02-05 18:40:17 +09001027 *
1028 * This function is intended to be called by the pm callbacks
1029 * (e.g., runtime_suspend, suspend) of the device driver that
1030 * holds the devfreq.
Rajagopal Venkat206c30c2012-10-26 01:50:18 +02001031 */
1032int devfreq_suspend_device(struct devfreq *devfreq)
1033{
Lukasz Luba83f8ca42018-12-05 12:05:53 +01001034 int ret;
1035
Rajagopal Venkat206c30c2012-10-26 01:50:18 +02001036 if (!devfreq)
1037 return -EINVAL;
1038
Lukasz Luba83f8ca42018-12-05 12:05:53 +01001039 if (atomic_inc_return(&devfreq->suspend_count) > 1)
Nishanth Menon1b5c1be2012-10-29 15:01:45 -05001040 return 0;
1041
Lukasz Luba83f8ca42018-12-05 12:05:53 +01001042 if (devfreq->governor) {
1043 ret = devfreq->governor->event_handler(devfreq,
1044 DEVFREQ_GOV_SUSPEND, NULL);
1045 if (ret)
1046 return ret;
1047 }
1048
1049 if (devfreq->suspend_freq) {
Marek Szyprowskie1e047a2019-11-12 11:47:34 +01001050 mutex_lock(&devfreq->lock);
Lukasz Luba83f8ca42018-12-05 12:05:53 +01001051 ret = devfreq_set_target(devfreq, devfreq->suspend_freq, 0);
Marek Szyprowskie1e047a2019-11-12 11:47:34 +01001052 mutex_unlock(&devfreq->lock);
Lukasz Luba83f8ca42018-12-05 12:05:53 +01001053 if (ret)
1054 return ret;
1055 }
1056
1057 return 0;
Rajagopal Venkat206c30c2012-10-26 01:50:18 +02001058}
1059EXPORT_SYMBOL(devfreq_suspend_device);
1060
1061/**
1062 * devfreq_resume_device() - Resume devfreq of a device.
1063 * @devfreq: the devfreq instance to be resumed
MyungJoo Hamde9c7392013-02-05 18:40:17 +09001064 *
1065 * This function is intended to be called by the pm callbacks
1066 * (e.g., runtime_resume, resume) of the device driver that
1067 * holds the devfreq.
Rajagopal Venkat206c30c2012-10-26 01:50:18 +02001068 */
1069int devfreq_resume_device(struct devfreq *devfreq)
1070{
Lukasz Luba83f8ca42018-12-05 12:05:53 +01001071 int ret;
1072
Rajagopal Venkat206c30c2012-10-26 01:50:18 +02001073 if (!devfreq)
1074 return -EINVAL;
1075
Lukasz Luba83f8ca42018-12-05 12:05:53 +01001076 if (atomic_dec_return(&devfreq->suspend_count) >= 1)
Nishanth Menon1b5c1be2012-10-29 15:01:45 -05001077 return 0;
1078
Lukasz Luba83f8ca42018-12-05 12:05:53 +01001079 if (devfreq->resume_freq) {
Marek Szyprowskie1e047a2019-11-12 11:47:34 +01001080 mutex_lock(&devfreq->lock);
Lukasz Luba83f8ca42018-12-05 12:05:53 +01001081 ret = devfreq_set_target(devfreq, devfreq->resume_freq, 0);
Marek Szyprowskie1e047a2019-11-12 11:47:34 +01001082 mutex_unlock(&devfreq->lock);
Lukasz Luba83f8ca42018-12-05 12:05:53 +01001083 if (ret)
1084 return ret;
1085 }
1086
1087 if (devfreq->governor) {
1088 ret = devfreq->governor->event_handler(devfreq,
1089 DEVFREQ_GOV_RESUME, NULL);
1090 if (ret)
1091 return ret;
1092 }
1093
1094 return 0;
Rajagopal Venkat206c30c2012-10-26 01:50:18 +02001095}
1096EXPORT_SYMBOL(devfreq_resume_device);
1097
Nishanth Menon3aa173b2012-10-29 15:01:43 -05001098/**
Lukasz Luba59031952018-12-05 12:05:54 +01001099 * devfreq_suspend() - Suspend devfreq governors and devices
1100 *
1101 * Called during system wide Suspend/Hibernate cycles for suspending governors
1102 * and devices preserving the state for resume. On some platforms the devfreq
1103 * device must have precise state (frequency) after resume in order to provide
1104 * fully operating setup.
1105 */
1106void devfreq_suspend(void)
1107{
1108 struct devfreq *devfreq;
1109 int ret;
1110
1111 mutex_lock(&devfreq_list_lock);
1112 list_for_each_entry(devfreq, &devfreq_list, node) {
1113 ret = devfreq_suspend_device(devfreq);
1114 if (ret)
1115 dev_err(&devfreq->dev,
1116 "failed to suspend devfreq device\n");
1117 }
1118 mutex_unlock(&devfreq_list_lock);
1119}
1120
1121/**
1122 * devfreq_resume() - Resume devfreq governors and devices
1123 *
1124 * Called during system wide Suspend/Hibernate cycle for resuming governors and
1125 * devices that are suspended with devfreq_suspend().
1126 */
1127void devfreq_resume(void)
1128{
1129 struct devfreq *devfreq;
1130 int ret;
1131
1132 mutex_lock(&devfreq_list_lock);
1133 list_for_each_entry(devfreq, &devfreq_list, node) {
1134 ret = devfreq_resume_device(devfreq);
1135 if (ret)
1136 dev_warn(&devfreq->dev,
1137 "failed to resume devfreq device\n");
1138 }
1139 mutex_unlock(&devfreq_list_lock);
1140}
1141
1142/**
Nishanth Menon3aa173b2012-10-29 15:01:43 -05001143 * devfreq_add_governor() - Add devfreq governor
1144 * @governor: the devfreq governor to be added
1145 */
1146int devfreq_add_governor(struct devfreq_governor *governor)
1147{
1148 struct devfreq_governor *g;
Nishanth Menon1b5c1be2012-10-29 15:01:45 -05001149 struct devfreq *devfreq;
Nishanth Menon3aa173b2012-10-29 15:01:43 -05001150 int err = 0;
1151
1152 if (!governor) {
1153 pr_err("%s: Invalid parameters.\n", __func__);
1154 return -EINVAL;
1155 }
1156
1157 mutex_lock(&devfreq_list_lock);
1158 g = find_devfreq_governor(governor->name);
1159 if (!IS_ERR(g)) {
1160 pr_err("%s: governor %s already registered\n", __func__,
1161 g->name);
1162 err = -EINVAL;
1163 goto err_out;
1164 }
1165
1166 list_add(&governor->node, &devfreq_governor_list);
1167
Nishanth Menon1b5c1be2012-10-29 15:01:45 -05001168 list_for_each_entry(devfreq, &devfreq_list, node) {
1169 int ret = 0;
1170 struct device *dev = devfreq->dev.parent;
1171
1172 if (!strncmp(devfreq->governor_name, governor->name,
1173 DEVFREQ_NAME_LEN)) {
1174 /* The following should never occur */
1175 if (devfreq->governor) {
1176 dev_warn(dev,
1177 "%s: Governor %s already present\n",
1178 __func__, devfreq->governor->name);
1179 ret = devfreq->governor->event_handler(devfreq,
1180 DEVFREQ_GOV_STOP, NULL);
1181 if (ret) {
1182 dev_warn(dev,
1183 "%s: Governor %s stop = %d\n",
1184 __func__,
1185 devfreq->governor->name, ret);
1186 }
1187 /* Fall through */
1188 }
1189 devfreq->governor = governor;
1190 ret = devfreq->governor->event_handler(devfreq,
1191 DEVFREQ_GOV_START, NULL);
1192 if (ret) {
1193 dev_warn(dev, "%s: Governor %s start=%d\n",
1194 __func__, devfreq->governor->name,
1195 ret);
1196 }
1197 }
1198 }
1199
Nishanth Menon3aa173b2012-10-29 15:01:43 -05001200err_out:
1201 mutex_unlock(&devfreq_list_lock);
1202
1203 return err;
1204}
1205EXPORT_SYMBOL(devfreq_add_governor);
1206
1207/**
MyungJoo Hambafeb422016-11-09 10:29:14 +09001208 * devfreq_remove_governor() - Remove devfreq feature from a device.
Nishanth Menon3aa173b2012-10-29 15:01:43 -05001209 * @governor: the devfreq governor to be removed
1210 */
1211int devfreq_remove_governor(struct devfreq_governor *governor)
1212{
1213 struct devfreq_governor *g;
Nishanth Menon1b5c1be2012-10-29 15:01:45 -05001214 struct devfreq *devfreq;
Nishanth Menon3aa173b2012-10-29 15:01:43 -05001215 int err = 0;
1216
1217 if (!governor) {
1218 pr_err("%s: Invalid parameters.\n", __func__);
1219 return -EINVAL;
1220 }
1221
1222 mutex_lock(&devfreq_list_lock);
1223 g = find_devfreq_governor(governor->name);
1224 if (IS_ERR(g)) {
1225 pr_err("%s: governor %s not registered\n", __func__,
Sachin Kamatb9e1c8e2012-11-21 10:36:13 +05301226 governor->name);
Sachin Kamatf9c08e22012-11-21 10:36:14 +05301227 err = PTR_ERR(g);
Nishanth Menon3aa173b2012-10-29 15:01:43 -05001228 goto err_out;
1229 }
Nishanth Menon1b5c1be2012-10-29 15:01:45 -05001230 list_for_each_entry(devfreq, &devfreq_list, node) {
1231 int ret;
1232 struct device *dev = devfreq->dev.parent;
1233
1234 if (!strncmp(devfreq->governor_name, governor->name,
1235 DEVFREQ_NAME_LEN)) {
1236 /* we should have a devfreq governor! */
1237 if (!devfreq->governor) {
1238 dev_warn(dev, "%s: Governor %s NOT present\n",
1239 __func__, governor->name);
1240 continue;
1241 /* Fall through */
1242 }
1243 ret = devfreq->governor->event_handler(devfreq,
1244 DEVFREQ_GOV_STOP, NULL);
1245 if (ret) {
1246 dev_warn(dev, "%s: Governor %s stop=%d\n",
1247 __func__, devfreq->governor->name,
1248 ret);
1249 }
1250 devfreq->governor = NULL;
1251 }
1252 }
Nishanth Menon3aa173b2012-10-29 15:01:43 -05001253
1254 list_del(&governor->node);
1255err_out:
1256 mutex_unlock(&devfreq_list_lock);
1257
1258 return err;
1259}
1260EXPORT_SYMBOL(devfreq_remove_governor);
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001261
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001262static ssize_t governor_show(struct device *dev,
MyungJoo Ham9005b652011-10-02 00:19:28 +02001263 struct device_attribute *attr, char *buf)
1264{
Nishanth Menon1b5c1be2012-10-29 15:01:45 -05001265 if (!to_devfreq(dev)->governor)
1266 return -EINVAL;
1267
MyungJoo Ham9005b652011-10-02 00:19:28 +02001268 return sprintf(buf, "%s\n", to_devfreq(dev)->governor->name);
1269}
1270
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001271static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
Nishanth Menon0359d1a2012-10-29 15:01:47 -05001272 const char *buf, size_t count)
1273{
1274 struct devfreq *df = to_devfreq(dev);
1275 int ret;
1276 char str_governor[DEVFREQ_NAME_LEN + 1];
Saravana Kannanbc658be2019-03-11 15:36:30 +05301277 const struct devfreq_governor *governor, *prev_governor;
Nishanth Menon0359d1a2012-10-29 15:01:47 -05001278
1279 ret = sscanf(buf, "%" __stringify(DEVFREQ_NAME_LEN) "s", str_governor);
1280 if (ret != 1)
1281 return -EINVAL;
1282
1283 mutex_lock(&devfreq_list_lock);
Enric Balletbo i Serra23c7b542018-07-04 10:45:50 +02001284 governor = try_then_request_governor(str_governor);
Nishanth Menon0359d1a2012-10-29 15:01:47 -05001285 if (IS_ERR(governor)) {
1286 ret = PTR_ERR(governor);
1287 goto out;
1288 }
Tobias Jakobi14a21e72015-09-21 20:23:52 +02001289 if (df->governor == governor) {
1290 ret = 0;
Nishanth Menon0359d1a2012-10-29 15:01:47 -05001291 goto out;
Gustavo A. R. Silva63f1e052017-12-06 14:20:15 -06001292 } else if ((df->governor && df->governor->immutable) ||
1293 governor->immutable) {
Chanwoo Choibcf23c72017-01-31 15:38:16 +09001294 ret = -EINVAL;
1295 goto out;
Tobias Jakobi14a21e72015-09-21 20:23:52 +02001296 }
Nishanth Menon0359d1a2012-10-29 15:01:47 -05001297
1298 if (df->governor) {
1299 ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL);
1300 if (ret) {
1301 dev_warn(dev, "%s: Governor %s not stopped(%d)\n",
1302 __func__, df->governor->name, ret);
1303 goto out;
1304 }
1305 }
Saravana Kannanbc658be2019-03-11 15:36:30 +05301306 prev_governor = df->governor;
Nishanth Menon0359d1a2012-10-29 15:01:47 -05001307 df->governor = governor;
1308 strncpy(df->governor_name, governor->name, DEVFREQ_NAME_LEN);
1309 ret = df->governor->event_handler(df, DEVFREQ_GOV_START, NULL);
Saravana Kannanbc658be2019-03-11 15:36:30 +05301310 if (ret) {
Nishanth Menon0359d1a2012-10-29 15:01:47 -05001311 dev_warn(dev, "%s: Governor %s not started(%d)\n",
1312 __func__, df->governor->name, ret);
Saravana Kannanbc658be2019-03-11 15:36:30 +05301313 df->governor = prev_governor;
1314 strncpy(df->governor_name, prev_governor->name,
1315 DEVFREQ_NAME_LEN);
1316 ret = df->governor->event_handler(df, DEVFREQ_GOV_START, NULL);
1317 if (ret) {
1318 dev_err(dev,
1319 "%s: reverting to Governor %s failed (%d)\n",
1320 __func__, df->governor_name, ret);
1321 df->governor = NULL;
1322 }
1323 }
Nishanth Menon0359d1a2012-10-29 15:01:47 -05001324out:
1325 mutex_unlock(&devfreq_list_lock);
1326
1327 if (!ret)
1328 ret = count;
1329 return ret;
1330}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001331static DEVICE_ATTR_RW(governor);
1332
1333static ssize_t available_governors_show(struct device *d,
1334 struct device_attribute *attr,
1335 char *buf)
Nishanth Menon50a5b332012-10-29 15:01:48 -05001336{
Chanwoo Choibcf23c72017-01-31 15:38:16 +09001337 struct devfreq *df = to_devfreq(d);
Nishanth Menon50a5b332012-10-29 15:01:48 -05001338 ssize_t count = 0;
1339
1340 mutex_lock(&devfreq_list_lock);
Chanwoo Choibcf23c72017-01-31 15:38:16 +09001341
1342 /*
1343 * The devfreq with immutable governor (e.g., passive) shows
1344 * only own governor.
1345 */
Leonard Crestezd68adc82019-09-24 10:26:53 +03001346 if (df->governor && df->governor->immutable) {
Chanwoo Choibcf23c72017-01-31 15:38:16 +09001347 count = scnprintf(&buf[count], DEVFREQ_NAME_LEN,
MyungJoo Ham6d690f72019-01-21 11:11:07 +09001348 "%s ", df->governor_name);
Chanwoo Choibcf23c72017-01-31 15:38:16 +09001349 /*
1350 * The devfreq device shows the registered governor except for
1351 * immutable governors such as passive governor .
1352 */
1353 } else {
1354 struct devfreq_governor *governor;
1355
1356 list_for_each_entry(governor, &devfreq_governor_list, node) {
1357 if (governor->immutable)
1358 continue;
1359 count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
1360 "%s ", governor->name);
1361 }
1362 }
1363
Nishanth Menon50a5b332012-10-29 15:01:48 -05001364 mutex_unlock(&devfreq_list_lock);
1365
1366 /* Truncate the trailing space */
1367 if (count)
1368 count--;
1369
1370 count += sprintf(&buf[count], "\n");
1371
1372 return count;
1373}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001374static DEVICE_ATTR_RO(available_governors);
Nishanth Menon0359d1a2012-10-29 15:01:47 -05001375
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001376static ssize_t cur_freq_show(struct device *dev, struct device_attribute *attr,
1377 char *buf)
MyungJoo Ham9005b652011-10-02 00:19:28 +02001378{
Rajagopal Venkat7f98a902012-10-26 01:50:26 +02001379 unsigned long freq;
1380 struct devfreq *devfreq = to_devfreq(dev);
1381
1382 if (devfreq->profile->get_cur_freq &&
1383 !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
Chanwoo Choi9d0109b2016-11-19 22:47:36 +09001384 return sprintf(buf, "%lu\n", freq);
Rajagopal Venkat7f98a902012-10-26 01:50:26 +02001385
1386 return sprintf(buf, "%lu\n", devfreq->previous_freq);
1387}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001388static DEVICE_ATTR_RO(cur_freq);
Rajagopal Venkat7f98a902012-10-26 01:50:26 +02001389
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001390static ssize_t target_freq_show(struct device *dev,
1391 struct device_attribute *attr, char *buf)
Rajagopal Venkat7f98a902012-10-26 01:50:26 +02001392{
MyungJoo Ham9005b652011-10-02 00:19:28 +02001393 return sprintf(buf, "%lu\n", to_devfreq(dev)->previous_freq);
1394}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001395static DEVICE_ATTR_RO(target_freq);
MyungJoo Ham9005b652011-10-02 00:19:28 +02001396
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001397static ssize_t polling_interval_show(struct device *dev,
MyungJoo Ham9005b652011-10-02 00:19:28 +02001398 struct device_attribute *attr, char *buf)
1399{
1400 return sprintf(buf, "%d\n", to_devfreq(dev)->profile->polling_ms);
1401}
1402
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001403static ssize_t polling_interval_store(struct device *dev,
MyungJoo Ham9005b652011-10-02 00:19:28 +02001404 struct device_attribute *attr,
1405 const char *buf, size_t count)
1406{
1407 struct devfreq *df = to_devfreq(dev);
1408 unsigned int value;
1409 int ret;
1410
Nishanth Menon1b5c1be2012-10-29 15:01:45 -05001411 if (!df->governor)
1412 return -EINVAL;
1413
MyungJoo Ham9005b652011-10-02 00:19:28 +02001414 ret = sscanf(buf, "%u", &value);
1415 if (ret != 1)
Nishanth Menon12e26262012-10-26 01:50:43 +02001416 return -EINVAL;
MyungJoo Ham9005b652011-10-02 00:19:28 +02001417
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +02001418 df->governor->event_handler(df, DEVFREQ_GOV_INTERVAL, &value);
MyungJoo Ham9005b652011-10-02 00:19:28 +02001419 ret = count;
1420
MyungJoo Ham9005b652011-10-02 00:19:28 +02001421 return ret;
1422}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001423static DEVICE_ATTR_RW(polling_interval);
MyungJoo Ham9005b652011-10-02 00:19:28 +02001424
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001425static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr,
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001426 const char *buf, size_t count)
1427{
1428 struct devfreq *df = to_devfreq(dev);
1429 unsigned long value;
1430 int ret;
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001431
Leonard Crestez27dbc542019-12-05 12:05:07 +02001432 /*
1433 * Protect against theoretical sysfs writes between
1434 * device_add and dev_pm_qos_add_request
1435 */
1436 if (!dev_pm_qos_request_active(&df->user_min_freq_req))
1437 return -EAGAIN;
1438
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001439 ret = sscanf(buf, "%lu", &value);
1440 if (ret != 1)
Nishanth Menon12e26262012-10-26 01:50:43 +02001441 return -EINVAL;
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001442
Leonard Crestez27dbc542019-12-05 12:05:07 +02001443 /* Round down to kHz for PM QoS */
1444 ret = dev_pm_qos_update_request(&df->user_min_freq_req,
1445 value / HZ_PER_KHZ);
1446 if (ret < 0)
1447 return ret;
Leonard Crestez46cecc02019-10-31 23:34:26 +02001448
1449 return count;
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001450}
1451
Chanwoo Choi1051e2c2017-10-23 10:32:07 +09001452static ssize_t min_freq_show(struct device *dev, struct device_attribute *attr,
1453 char *buf)
1454{
Chanwoo Choif1d981e2017-10-23 10:32:08 +09001455 struct devfreq *df = to_devfreq(dev);
Leonard Crestez46cecc02019-10-31 23:34:26 +02001456 unsigned long min_freq, max_freq;
Chanwoo Choif1d981e2017-10-23 10:32:08 +09001457
Leonard Crestez46cecc02019-10-31 23:34:26 +02001458 mutex_lock(&df->lock);
1459 get_freq_range(df, &min_freq, &max_freq);
1460 mutex_unlock(&df->lock);
1461
1462 return sprintf(buf, "%lu\n", min_freq);
Chanwoo Choi1051e2c2017-10-23 10:32:07 +09001463}
1464
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001465static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr,
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001466 const char *buf, size_t count)
1467{
1468 struct devfreq *df = to_devfreq(dev);
1469 unsigned long value;
1470 int ret;
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001471
Leonard Crestez27dbc542019-12-05 12:05:07 +02001472 /*
1473 * Protect against theoretical sysfs writes between
1474 * device_add and dev_pm_qos_add_request
1475 */
1476 if (!dev_pm_qos_request_active(&df->user_max_freq_req))
1477 return -EINVAL;
1478
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001479 ret = sscanf(buf, "%lu", &value);
1480 if (ret != 1)
Nishanth Menon12e26262012-10-26 01:50:43 +02001481 return -EINVAL;
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001482
Leonard Crestez27dbc542019-12-05 12:05:07 +02001483 /*
1484 * PM QoS frequencies are in kHz so we need to convert. Convert by
1485 * rounding upwards so that the acceptable interval never shrinks.
1486 *
1487 * For example if the user writes "666666666" to sysfs this value will
1488 * be converted to 666667 kHz and back to 666667000 Hz before an OPP
1489 * lookup, this ensures that an OPP of 666666666Hz is still accepted.
1490 *
1491 * A value of zero means "no limit".
1492 */
1493 if (value)
1494 value = DIV_ROUND_UP(value, HZ_PER_KHZ);
1495 else
1496 value = PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE;
Matthias Kaehlckedf5cf4a2018-08-03 13:05:09 -07001497
Leonard Crestez27dbc542019-12-05 12:05:07 +02001498 ret = dev_pm_qos_update_request(&df->user_max_freq_req, value);
1499 if (ret < 0)
1500 return ret;
Leonard Crestez46cecc02019-10-31 23:34:26 +02001501
1502 return count;
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001503}
Chanwoo Choi3104fa32015-11-13 19:25:28 +09001504static DEVICE_ATTR_RW(min_freq);
Chanwoo Choi1051e2c2017-10-23 10:32:07 +09001505
1506static ssize_t max_freq_show(struct device *dev, struct device_attribute *attr,
1507 char *buf)
1508{
Chanwoo Choif1d981e2017-10-23 10:32:08 +09001509 struct devfreq *df = to_devfreq(dev);
Leonard Crestez46cecc02019-10-31 23:34:26 +02001510 unsigned long min_freq, max_freq;
Chanwoo Choif1d981e2017-10-23 10:32:08 +09001511
Leonard Crestez46cecc02019-10-31 23:34:26 +02001512 mutex_lock(&df->lock);
1513 get_freq_range(df, &min_freq, &max_freq);
1514 mutex_unlock(&df->lock);
1515
1516 return sprintf(buf, "%lu\n", max_freq);
Chanwoo Choi1051e2c2017-10-23 10:32:07 +09001517}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001518static DEVICE_ATTR_RW(max_freq);
MyungJoo Ham6530b9de2011-12-09 16:42:19 +09001519
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001520static ssize_t available_frequencies_show(struct device *d,
1521 struct device_attribute *attr,
1522 char *buf)
Nishanth Menond287de82012-10-25 19:48:59 -05001523{
1524 struct devfreq *df = to_devfreq(d);
Nishanth Menond287de82012-10-25 19:48:59 -05001525 ssize_t count = 0;
Chanwoo Choi416b46a2017-10-23 10:32:10 +09001526 int i;
Nishanth Menond287de82012-10-25 19:48:59 -05001527
Chanwoo Choi416b46a2017-10-23 10:32:10 +09001528 mutex_lock(&df->lock);
Nishanth Menond287de82012-10-25 19:48:59 -05001529
Chanwoo Choi416b46a2017-10-23 10:32:10 +09001530 for (i = 0; i < df->profile->max_state; i++)
Nishanth Menond287de82012-10-25 19:48:59 -05001531 count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
Chanwoo Choi416b46a2017-10-23 10:32:10 +09001532 "%lu ", df->profile->freq_table[i]);
Nishanth Menond287de82012-10-25 19:48:59 -05001533
Chanwoo Choi416b46a2017-10-23 10:32:10 +09001534 mutex_unlock(&df->lock);
Nishanth Menond287de82012-10-25 19:48:59 -05001535 /* Truncate the trailing space */
1536 if (count)
1537 count--;
1538
1539 count += sprintf(&buf[count], "\n");
1540
1541 return count;
1542}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001543static DEVICE_ATTR_RO(available_frequencies);
Nishanth Menond287de82012-10-25 19:48:59 -05001544
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001545static ssize_t trans_stat_show(struct device *dev,
1546 struct device_attribute *attr, char *buf)
Jonghwa Leee552bba2012-08-23 20:00:46 +09001547{
1548 struct devfreq *devfreq = to_devfreq(dev);
1549 ssize_t len;
Rajagopal Venkat39688ce62013-01-08 11:20:39 +05301550 int i, j;
Jonghwa Leee552bba2012-08-23 20:00:46 +09001551 unsigned int max_state = devfreq->profile->max_state;
1552
MyungJoo Ham34bd3222015-11-23 15:45:36 +09001553 if (max_state == 0)
1554 return sprintf(buf, "Not Supported.\n");
Jonghwa Leee552bba2012-08-23 20:00:46 +09001555
Leonard Crestez2abb0d52019-09-24 10:52:23 +03001556 mutex_lock(&devfreq->lock);
1557 if (!devfreq->stop_polling &&
1558 devfreq_update_status(devfreq, devfreq->previous_freq)) {
1559 mutex_unlock(&devfreq->lock);
1560 return 0;
1561 }
1562 mutex_unlock(&devfreq->lock);
1563
Chanwoo Choid7df1e42015-11-19 16:28:46 +09001564 len = sprintf(buf, " From : To\n");
1565 len += sprintf(buf + len, " :");
Jonghwa Leee552bba2012-08-23 20:00:46 +09001566 for (i = 0; i < max_state; i++)
Chanwoo Choid7df1e42015-11-19 16:28:46 +09001567 len += sprintf(buf + len, "%10lu",
Jonghwa Leee552bba2012-08-23 20:00:46 +09001568 devfreq->profile->freq_table[i]);
1569
1570 len += sprintf(buf + len, " time(ms)\n");
1571
1572 for (i = 0; i < max_state; i++) {
1573 if (devfreq->profile->freq_table[i]
1574 == devfreq->previous_freq) {
1575 len += sprintf(buf + len, "*");
1576 } else {
1577 len += sprintf(buf + len, " ");
1578 }
Chanwoo Choid7df1e42015-11-19 16:28:46 +09001579 len += sprintf(buf + len, "%10lu:",
Jonghwa Leee552bba2012-08-23 20:00:46 +09001580 devfreq->profile->freq_table[i]);
1581 for (j = 0; j < max_state; j++)
Chanwoo Choid7df1e42015-11-19 16:28:46 +09001582 len += sprintf(buf + len, "%10u",
Jonghwa Leee552bba2012-08-23 20:00:46 +09001583 devfreq->trans_table[(i * max_state) + j]);
1584 len += sprintf(buf + len, "%10u\n",
1585 jiffies_to_msecs(devfreq->time_in_state[i]));
1586 }
1587
1588 len += sprintf(buf + len, "Total transition : %u\n",
1589 devfreq->total_trans);
1590 return len;
1591}
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001592static DEVICE_ATTR_RO(trans_stat);
Jonghwa Leee552bba2012-08-23 20:00:46 +09001593
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001594static struct attribute *devfreq_attrs[] = {
1595 &dev_attr_governor.attr,
1596 &dev_attr_available_governors.attr,
1597 &dev_attr_cur_freq.attr,
1598 &dev_attr_available_frequencies.attr,
1599 &dev_attr_target_freq.attr,
1600 &dev_attr_polling_interval.attr,
1601 &dev_attr_min_freq.attr,
1602 &dev_attr_max_freq.attr,
1603 &dev_attr_trans_stat.attr,
1604 NULL,
MyungJoo Ham9005b652011-10-02 00:19:28 +02001605};
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001606ATTRIBUTE_GROUPS(devfreq);
MyungJoo Ham9005b652011-10-02 00:19:28 +02001607
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001608static int __init devfreq_init(void)
1609{
1610 devfreq_class = class_create(THIS_MODULE, "devfreq");
1611 if (IS_ERR(devfreq_class)) {
1612 pr_err("%s: couldn't create class\n", __FILE__);
1613 return PTR_ERR(devfreq_class);
1614 }
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +02001615
1616 devfreq_wq = create_freezable_workqueue("devfreq_wq");
Dan Carpenterea7f4542013-08-15 10:55:10 +03001617 if (!devfreq_wq) {
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +02001618 class_destroy(devfreq_class);
1619 pr_err("%s: couldn't create workqueue\n", __FILE__);
Dan Carpenterea7f4542013-08-15 10:55:10 +03001620 return -ENOMEM;
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +02001621 }
Greg Kroah-Hartmana93d6b02013-07-24 15:05:09 -07001622 devfreq_class->dev_groups = devfreq_groups;
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +02001623
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001624 return 0;
1625}
1626subsys_initcall(devfreq_init);
1627
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001628/*
Masahiro Yamada4091fb92017-02-27 14:29:56 -08001629 * The following are helper functions for devfreq user device drivers with
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001630 * OPP framework.
1631 */
1632
1633/**
1634 * devfreq_recommended_opp() - Helper function to get proper OPP for the
1635 * freq value given to target callback.
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +02001636 * @dev: The devfreq user device. (parent of devfreq)
1637 * @freq: The frequency given to target function
1638 * @flags: Flags handed from devfreq framework.
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001639 *
Viresh Kumar8a31d9d92017-01-23 10:11:47 +05301640 * The callers are required to call dev_pm_opp_put() for the returned OPP after
1641 * use.
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001642 */
Nishanth Menon47d43ba2013-09-19 16:03:51 -05001643struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
1644 unsigned long *freq,
1645 u32 flags)
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001646{
Nishanth Menon47d43ba2013-09-19 16:03:51 -05001647 struct dev_pm_opp *opp;
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001648
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001649 if (flags & DEVFREQ_FLAG_LEAST_UPPER_BOUND) {
1650 /* The freq is an upper bound. opp should be lower */
Nishanth Menon5d4879c2013-09-19 16:03:50 -05001651 opp = dev_pm_opp_find_freq_floor(dev, freq);
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001652
1653 /* If not available, use the closest opp */
Nishanth Menon07797262012-10-24 22:00:12 +02001654 if (opp == ERR_PTR(-ERANGE))
Nishanth Menon5d4879c2013-09-19 16:03:50 -05001655 opp = dev_pm_opp_find_freq_ceil(dev, freq);
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001656 } else {
1657 /* The freq is an lower bound. opp should be higher */
Nishanth Menon5d4879c2013-09-19 16:03:50 -05001658 opp = dev_pm_opp_find_freq_ceil(dev, freq);
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001659
1660 /* If not available, use the closest opp */
Nishanth Menon07797262012-10-24 22:00:12 +02001661 if (opp == ERR_PTR(-ERANGE))
Nishanth Menon5d4879c2013-09-19 16:03:50 -05001662 opp = dev_pm_opp_find_freq_floor(dev, freq);
MyungJoo Hamab5f2992012-03-16 21:54:53 +01001663 }
1664
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001665 return opp;
1666}
Ãrjan Eidebd7e9272014-07-18 15:09:53 +01001667EXPORT_SYMBOL(devfreq_recommended_opp);
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001668
1669/**
1670 * devfreq_register_opp_notifier() - Helper function to get devfreq notified
MyungJoo Ham6d690f72019-01-21 11:11:07 +09001671 * for any changes in the OPP availability
1672 * changes
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +02001673 * @dev: The devfreq user device. (parent of devfreq)
1674 * @devfreq: The devfreq object.
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001675 */
1676int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq)
1677{
Viresh Kumardc2c9ad2017-01-02 14:41:03 +05301678 return dev_pm_opp_register_notifier(dev, &devfreq->nb);
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001679}
Ãrjan Eidebd7e9272014-07-18 15:09:53 +01001680EXPORT_SYMBOL(devfreq_register_opp_notifier);
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001681
1682/**
1683 * devfreq_unregister_opp_notifier() - Helper function to stop getting devfreq
MyungJoo Ham6d690f72019-01-21 11:11:07 +09001684 * notified for any changes in the OPP
1685 * availability changes anymore.
Nishanth Menonc5b4a1c12012-10-26 01:50:35 +02001686 * @dev: The devfreq user device. (parent of devfreq)
1687 * @devfreq: The devfreq object.
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001688 *
1689 * At exit() callback of devfreq_dev_profile, this must be included if
1690 * devfreq_recommended_opp is used.
1691 */
1692int devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq)
1693{
Viresh Kumardc2c9ad2017-01-02 14:41:03 +05301694 return dev_pm_opp_unregister_notifier(dev, &devfreq->nb);
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001695}
Ãrjan Eidebd7e9272014-07-18 15:09:53 +01001696EXPORT_SYMBOL(devfreq_unregister_opp_notifier);
MyungJoo Hama3c98b82011-10-02 00:19:15 +02001697
Chanwoo Choid5b040d2014-05-09 16:43:09 +09001698static void devm_devfreq_opp_release(struct device *dev, void *res)
1699{
1700 devfreq_unregister_opp_notifier(dev, *(struct devfreq **)res);
1701}
1702
1703/**
MyungJoo Ham6d690f72019-01-21 11:11:07 +09001704 * devm_devfreq_register_opp_notifier() - Resource-managed
1705 * devfreq_register_opp_notifier()
Chanwoo Choid5b040d2014-05-09 16:43:09 +09001706 * @dev: The devfreq user device. (parent of devfreq)
1707 * @devfreq: The devfreq object.
1708 */
1709int devm_devfreq_register_opp_notifier(struct device *dev,
1710 struct devfreq *devfreq)
1711{
1712 struct devfreq **ptr;
1713 int ret;
1714
1715 ptr = devres_alloc(devm_devfreq_opp_release, sizeof(*ptr), GFP_KERNEL);
1716 if (!ptr)
1717 return -ENOMEM;
1718
1719 ret = devfreq_register_opp_notifier(dev, devfreq);
1720 if (ret) {
1721 devres_free(ptr);
1722 return ret;
1723 }
1724
1725 *ptr = devfreq;
1726 devres_add(dev, ptr);
1727
1728 return 0;
1729}
1730EXPORT_SYMBOL(devm_devfreq_register_opp_notifier);
1731
1732/**
MyungJoo Ham6d690f72019-01-21 11:11:07 +09001733 * devm_devfreq_unregister_opp_notifier() - Resource-managed
1734 * devfreq_unregister_opp_notifier()
Chanwoo Choid5b040d2014-05-09 16:43:09 +09001735 * @dev: The devfreq user device. (parent of devfreq)
1736 * @devfreq: The devfreq object.
1737 */
1738void devm_devfreq_unregister_opp_notifier(struct device *dev,
1739 struct devfreq *devfreq)
1740{
1741 WARN_ON(devres_release(dev, devm_devfreq_opp_release,
1742 devm_devfreq_dev_match, devfreq));
1743}
1744EXPORT_SYMBOL(devm_devfreq_unregister_opp_notifier);
1745
Chanwoo Choi0fe3a662016-01-26 13:21:26 +09001746/**
1747 * devfreq_register_notifier() - Register a driver with devfreq
1748 * @devfreq: The devfreq object.
1749 * @nb: The notifier block to register.
1750 * @list: DEVFREQ_TRANSITION_NOTIFIER.
1751 */
1752int devfreq_register_notifier(struct devfreq *devfreq,
MyungJoo Ham6d690f72019-01-21 11:11:07 +09001753 struct notifier_block *nb,
1754 unsigned int list)
Chanwoo Choi0fe3a662016-01-26 13:21:26 +09001755{
1756 int ret = 0;
1757
1758 if (!devfreq)
1759 return -EINVAL;
1760
1761 switch (list) {
1762 case DEVFREQ_TRANSITION_NOTIFIER:
1763 ret = srcu_notifier_chain_register(
1764 &devfreq->transition_notifier_list, nb);
1765 break;
1766 default:
1767 ret = -EINVAL;
1768 }
1769
1770 return ret;
1771}
1772EXPORT_SYMBOL(devfreq_register_notifier);
1773
1774/*
1775 * devfreq_unregister_notifier() - Unregister a driver with devfreq
1776 * @devfreq: The devfreq object.
1777 * @nb: The notifier block to be unregistered.
1778 * @list: DEVFREQ_TRANSITION_NOTIFIER.
1779 */
1780int devfreq_unregister_notifier(struct devfreq *devfreq,
1781 struct notifier_block *nb,
1782 unsigned int list)
1783{
1784 int ret = 0;
1785
1786 if (!devfreq)
1787 return -EINVAL;
1788
1789 switch (list) {
1790 case DEVFREQ_TRANSITION_NOTIFIER:
1791 ret = srcu_notifier_chain_unregister(
1792 &devfreq->transition_notifier_list, nb);
1793 break;
1794 default:
1795 ret = -EINVAL;
1796 }
1797
1798 return ret;
1799}
1800EXPORT_SYMBOL(devfreq_unregister_notifier);
1801
1802struct devfreq_notifier_devres {
1803 struct devfreq *devfreq;
1804 struct notifier_block *nb;
1805 unsigned int list;
1806};
1807
1808static void devm_devfreq_notifier_release(struct device *dev, void *res)
1809{
1810 struct devfreq_notifier_devres *this = res;
1811
1812 devfreq_unregister_notifier(this->devfreq, this->nb, this->list);
1813}
1814
1815/**
1816 * devm_devfreq_register_notifier()
1817 - Resource-managed devfreq_register_notifier()
1818 * @dev: The devfreq user device. (parent of devfreq)
1819 * @devfreq: The devfreq object.
1820 * @nb: The notifier block to be unregistered.
1821 * @list: DEVFREQ_TRANSITION_NOTIFIER.
1822 */
1823int devm_devfreq_register_notifier(struct device *dev,
1824 struct devfreq *devfreq,
1825 struct notifier_block *nb,
1826 unsigned int list)
1827{
1828 struct devfreq_notifier_devres *ptr;
1829 int ret;
1830
1831 ptr = devres_alloc(devm_devfreq_notifier_release, sizeof(*ptr),
1832 GFP_KERNEL);
1833 if (!ptr)
1834 return -ENOMEM;
1835
1836 ret = devfreq_register_notifier(devfreq, nb, list);
1837 if (ret) {
1838 devres_free(ptr);
1839 return ret;
1840 }
1841
1842 ptr->devfreq = devfreq;
1843 ptr->nb = nb;
1844 ptr->list = list;
1845 devres_add(dev, ptr);
1846
1847 return 0;
1848}
1849EXPORT_SYMBOL(devm_devfreq_register_notifier);
1850
1851/**
1852 * devm_devfreq_unregister_notifier()
1853 - Resource-managed devfreq_unregister_notifier()
1854 * @dev: The devfreq user device. (parent of devfreq)
1855 * @devfreq: The devfreq object.
1856 * @nb: The notifier block to be unregistered.
1857 * @list: DEVFREQ_TRANSITION_NOTIFIER.
1858 */
1859void devm_devfreq_unregister_notifier(struct device *dev,
MyungJoo Ham6d690f72019-01-21 11:11:07 +09001860 struct devfreq *devfreq,
1861 struct notifier_block *nb,
1862 unsigned int list)
Chanwoo Choi0fe3a662016-01-26 13:21:26 +09001863{
1864 WARN_ON(devres_release(dev, devm_devfreq_notifier_release,
1865 devm_devfreq_dev_match, devfreq));
1866}
1867EXPORT_SYMBOL(devm_devfreq_unregister_notifier);