13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/errno.h>
18 #include <linux/module.h>
19 #include <linux/slab.h>
20 #include <linux/stat.h>
25 #include <linux/list.h>
27 #include <linux/hrtimer.h>
43 static struct devfreq *wait_remove_device;
61 pr_err(
"DEVFREQ: %s: Invalid parameters\n", __func__);
64 WARN(!mutex_is_locked(&devfreq_list_lock),
65 "devfreq_list_lock must be locked.");
68 if (tmp_devfreq->
dev.parent == dev)
88 if (!mutex_is_locked(&devfreq->
lock)) {
89 WARN(
true,
"devfreq->lock must be locked by the caller.\n");
94 err = devfreq->
governor->get_target_freq(devfreq, &freq);
115 err = devfreq->
profile->target(devfreq->
dev.parent, &freq, flags);
167 if (!mutex_is_locked(&devfreq->
lock)) {
168 WARN(
true,
"devfreq->lock must be locked by the caller.\n");
171 if (!devfreq->
governor->no_central_polling &&
172 !mutex_is_locked(&devfreq_list_lock)) {
173 WARN(
true,
"devfreq_list_lock must be locked by the caller.\n");
193 if (!devfreq->
governor->no_central_polling)
210 static void devfreq_dev_release(
struct device *dev)
213 bool central_polling = !devfreq->
governor->no_central_polling;
246 _remove_devfreq(devfreq,
true);
260 static unsigned long last_polled_at;
261 struct devfreq *devfreq, *
tmp;
263 unsigned long jiffies_passed;
268 jiffies_passed = now - last_polled_at;
269 last_polled_at = now;
270 if (jiffies_passed == 0)
276 dev = devfreq->
dev.parent;
279 wait_remove_device =
tmp;
281 if (devfreq->
governor->no_central_polling ||
296 if (error && error != -
EAGAIN) {
298 dev_err(dev,
"Due to update_devfreq error(%d), devfreq(%s) is removed from the device\n",
309 if (IS_ERR(find_device_devfreq(dev)))
313 _remove_devfreq(devfreq,
false);
328 wait_remove_device =
NULL;
331 if (next_jiffies > 0 && next_jiffies <
ULONG_MAX) {
352 struct devfreq *devfreq;
355 if (!dev || !profile || !governor) {
356 dev_err(dev,
"%s: Invalid parameters.\n", __func__);
363 devfreq = find_device_devfreq(dev);
365 if (!IS_ERR(devfreq)) {
366 dev_err(dev,
"%s: Unable to create devfreq for the device. It already has one.\n", __func__);
372 devfreq = kzalloc(
sizeof(
struct devfreq),
GFP_KERNEL);
374 dev_err(dev,
"%s: Unable to create devfreq for the device\n",
382 devfreq->
dev.parent =
dev;
384 devfreq->
dev.release = devfreq_dev_release;
391 devfreq->
nb.notifier_call = devfreq_notifier_call;
401 err = governor->
init(devfreq);
412 list_add(&devfreq->
node, &devfreq_list);
438 bool central_polling;
443 central_polling = !devfreq->
governor->no_central_polling;
445 if (central_polling) {
447 while (wait_remove_device == devfreq) {
455 _remove_devfreq(devfreq,
false);
483 const char *buf,
size_t count)
489 ret =
sscanf(buf,
"%u", &value);
501 if (df->
governor->no_central_polling)
523 const char *buf,
size_t count)
530 ret =
sscanf(buf,
"%lu", &value);
536 if (value && max && value > max) {
557 const char *buf,
size_t count)
564 ret =
sscanf(buf,
"%lu", &value);
570 if (value && min && value < min) {
595 store_polling_interval),
605 static int __init devfreq_start_polling(
void)
613 devfreq_monitor(&devfreq_work.work);
618 static int __init devfreq_init(
void)
621 if (IS_ERR(devfreq_class)) {
622 pr_err(
"%s: couldn't create class\n", __FILE__);
623 return PTR_ERR(devfreq_class);
625 devfreq_class->
dev_attrs = devfreq_attrs;
630 static void __exit devfreq_exit(
void)
659 if (opp == ERR_PTR(-
ENODEV))
666 if (opp == ERR_PTR(-
ENODEV))