diff options
author | MyungJoo Ham <myungjoo.ham@samsung.com> | 2011-12-09 02:42:19 -0500 |
---|---|---|
committer | MyungJoo Ham <myungjoo.ham@samsung.com> | 2012-01-19 20:12:38 -0500 |
commit | 6530b9dea1b7f33eaf79ba625e3a99f2455f3eb1 (patch) | |
tree | 70beddf04779d5941ba6ef851b30e02c7fa0c86c /drivers/devfreq/devfreq.c | |
parent | a95e1f5dbca385908aa4087bb98470b0e0ac58d8 (diff) |
PM / devfreq: add min/max_freq limit requested by users.
The frequency requested to devfreq device driver from devfreq governors
is restricted by min_freq and max_freq input.
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Diffstat (limited to 'drivers/devfreq/devfreq.c')
-rw-r--r-- | drivers/devfreq/devfreq.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index c189b82f5ece..a129a7b6bfd1 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c | |||
@@ -501,12 +501,82 @@ static ssize_t show_central_polling(struct device *dev, | |||
501 | !to_devfreq(dev)->governor->no_central_polling); | 501 | !to_devfreq(dev)->governor->no_central_polling); |
502 | } | 502 | } |
503 | 503 | ||
504 | static ssize_t store_min_freq(struct device *dev, struct device_attribute *attr, | ||
505 | const char *buf, size_t count) | ||
506 | { | ||
507 | struct devfreq *df = to_devfreq(dev); | ||
508 | unsigned long value; | ||
509 | int ret; | ||
510 | unsigned long max; | ||
511 | |||
512 | ret = sscanf(buf, "%lu", &value); | ||
513 | if (ret != 1) | ||
514 | goto out; | ||
515 | |||
516 | mutex_lock(&df->lock); | ||
517 | max = df->max_freq; | ||
518 | if (value && max && value > max) { | ||
519 | ret = -EINVAL; | ||
520 | goto unlock; | ||
521 | } | ||
522 | |||
523 | df->min_freq = value; | ||
524 | update_devfreq(df); | ||
525 | ret = count; | ||
526 | unlock: | ||
527 | mutex_unlock(&df->lock); | ||
528 | out: | ||
529 | return ret; | ||
530 | } | ||
531 | |||
532 | static ssize_t show_min_freq(struct device *dev, struct device_attribute *attr, | ||
533 | char *buf) | ||
534 | { | ||
535 | return sprintf(buf, "%lu\n", to_devfreq(dev)->min_freq); | ||
536 | } | ||
537 | |||
538 | static ssize_t store_max_freq(struct device *dev, struct device_attribute *attr, | ||
539 | const char *buf, size_t count) | ||
540 | { | ||
541 | struct devfreq *df = to_devfreq(dev); | ||
542 | unsigned long value; | ||
543 | int ret; | ||
544 | unsigned long min; | ||
545 | |||
546 | ret = sscanf(buf, "%lu", &value); | ||
547 | if (ret != 1) | ||
548 | goto out; | ||
549 | |||
550 | mutex_lock(&df->lock); | ||
551 | min = df->min_freq; | ||
552 | if (value && min && value < min) { | ||
553 | ret = -EINVAL; | ||
554 | goto unlock; | ||
555 | } | ||
556 | |||
557 | df->max_freq = value; | ||
558 | update_devfreq(df); | ||
559 | ret = count; | ||
560 | unlock: | ||
561 | mutex_unlock(&df->lock); | ||
562 | out: | ||
563 | return ret; | ||
564 | } | ||
565 | |||
566 | static ssize_t show_max_freq(struct device *dev, struct device_attribute *attr, | ||
567 | char *buf) | ||
568 | { | ||
569 | return sprintf(buf, "%lu\n", to_devfreq(dev)->max_freq); | ||
570 | } | ||
571 | |||
504 | static struct device_attribute devfreq_attrs[] = { | 572 | static struct device_attribute devfreq_attrs[] = { |
505 | __ATTR(governor, S_IRUGO, show_governor, NULL), | 573 | __ATTR(governor, S_IRUGO, show_governor, NULL), |
506 | __ATTR(cur_freq, S_IRUGO, show_freq, NULL), | 574 | __ATTR(cur_freq, S_IRUGO, show_freq, NULL), |
507 | __ATTR(central_polling, S_IRUGO, show_central_polling, NULL), | 575 | __ATTR(central_polling, S_IRUGO, show_central_polling, NULL), |
508 | __ATTR(polling_interval, S_IRUGO | S_IWUSR, show_polling_interval, | 576 | __ATTR(polling_interval, S_IRUGO | S_IWUSR, show_polling_interval, |
509 | store_polling_interval), | 577 | store_polling_interval), |
578 | __ATTR(min_freq, S_IRUGO | S_IWUSR, show_min_freq, store_min_freq), | ||
579 | __ATTR(max_freq, S_IRUGO | S_IWUSR, show_max_freq, store_max_freq), | ||
510 | { }, | 580 | { }, |
511 | }; | 581 | }; |
512 | 582 | ||