aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/devfreq/devfreq.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-02-20 08:23:40 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-02-20 08:23:40 -0500
commit41ef3d1df037a429703db503e98fa948ee34b895 (patch)
tree611d15d08b45efd9c8c9ea0ae1aa8b4498b1ba7e /drivers/devfreq/devfreq.c
parentad7eec4244a8c6b53a0d38d6fd674e9d2c92897f (diff)
parent23b017a623a0bd19c24e6c1c41fe587c644e9dbc (diff)
Merge branch 'pm-devfreq'
* pm-devfreq: PM / devfreq: Modify the device name as devfreq(X) for sysfs PM / devfreq: Simplify the sysfs name of devfreq-event device PM / devfreq: Remove unnecessary separate _remove_devfreq() PM / devfreq: Fix wrong trans_stat of passive devfreq device PM / devfreq: Fix available_governor sysfs PM / devfreq: exynos-ppmu: Show the registred device for ppmu device PM / devfreq: Fix the wrong description for userspace governor PM / devfreq: Fix the checkpatch warnings PM / devfreq: exynos-bus: Print the real clock rate of bus PM / devfreq: exynos-ppmu: Use the regmap interface to handle the registers PM / devfreq: exynos-bus: Add the detailed correlation for Exynos5433 PM / devfreq: Don't delete sysfs group twice
Diffstat (limited to 'drivers/devfreq/devfreq.c')
-rw-r--r--drivers/devfreq/devfreq.c74
1 files changed, 46 insertions, 28 deletions
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 253525ea17af..551a271353d2 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -128,7 +128,7 @@ static void devfreq_set_freq_table(struct devfreq *devfreq)
128 * @devfreq: the devfreq instance 128 * @devfreq: the devfreq instance
129 * @freq: the update target frequency 129 * @freq: the update target frequency
130 */ 130 */
131static int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) 131int devfreq_update_status(struct devfreq *devfreq, unsigned long freq)
132{ 132{
133 int lev, prev_lev, ret = 0; 133 int lev, prev_lev, ret = 0;
134 unsigned long cur_time; 134 unsigned long cur_time;
@@ -164,6 +164,7 @@ out:
164 devfreq->last_stat_updated = cur_time; 164 devfreq->last_stat_updated = cur_time;
165 return ret; 165 return ret;
166} 166}
167EXPORT_SYMBOL(devfreq_update_status);
167 168
168/** 169/**
169 * find_devfreq_governor() - find devfreq governor from name 170 * find_devfreq_governor() - find devfreq governor from name
@@ -472,11 +473,15 @@ static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type,
472} 473}
473 474
474/** 475/**
475 * _remove_devfreq() - Remove devfreq from the list and release its resources. 476 * devfreq_dev_release() - Callback for struct device to release the device.
476 * @devfreq: the devfreq struct 477 * @dev: the devfreq device
478 *
479 * Remove devfreq from the list and release its resources.
477 */ 480 */
478static void _remove_devfreq(struct devfreq *devfreq) 481static void devfreq_dev_release(struct device *dev)
479{ 482{
483 struct devfreq *devfreq = to_devfreq(dev);
484
480 mutex_lock(&devfreq_list_lock); 485 mutex_lock(&devfreq_list_lock);
481 if (IS_ERR(find_device_devfreq(devfreq->dev.parent))) { 486 if (IS_ERR(find_device_devfreq(devfreq->dev.parent))) {
482 mutex_unlock(&devfreq_list_lock); 487 mutex_unlock(&devfreq_list_lock);
@@ -498,19 +503,6 @@ static void _remove_devfreq(struct devfreq *devfreq)
498} 503}
499 504
500/** 505/**
501 * devfreq_dev_release() - Callback for struct device to release the device.
502 * @dev: the devfreq device
503 *
504 * This calls _remove_devfreq() if _remove_devfreq() is not called.
505 */
506static void devfreq_dev_release(struct device *dev)
507{
508 struct devfreq *devfreq = to_devfreq(dev);
509
510 _remove_devfreq(devfreq);
511}
512
513/**
514 * devfreq_add_device() - Add devfreq feature to the device 506 * devfreq_add_device() - Add devfreq feature to the device
515 * @dev: the device to add devfreq feature. 507 * @dev: the device to add devfreq feature.
516 * @profile: device-specific profile to run devfreq. 508 * @profile: device-specific profile to run devfreq.
@@ -525,6 +517,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
525{ 517{
526 struct devfreq *devfreq; 518 struct devfreq *devfreq;
527 struct devfreq_governor *governor; 519 struct devfreq_governor *governor;
520 static atomic_t devfreq_no = ATOMIC_INIT(-1);
528 int err = 0; 521 int err = 0;
529 522
530 if (!dev || !profile || !governor_name) { 523 if (!dev || !profile || !governor_name) {
@@ -536,15 +529,14 @@ struct devfreq *devfreq_add_device(struct device *dev,
536 devfreq = find_device_devfreq(dev); 529 devfreq = find_device_devfreq(dev);
537 mutex_unlock(&devfreq_list_lock); 530 mutex_unlock(&devfreq_list_lock);
538 if (!IS_ERR(devfreq)) { 531 if (!IS_ERR(devfreq)) {
539 dev_err(dev, "%s: Unable to create devfreq for the device. It already has one.\n", __func__); 532 dev_err(dev, "%s: Unable to create devfreq for the device.\n",
533 __func__);
540 err = -EINVAL; 534 err = -EINVAL;
541 goto err_out; 535 goto err_out;
542 } 536 }
543 537
544 devfreq = kzalloc(sizeof(struct devfreq), GFP_KERNEL); 538 devfreq = kzalloc(sizeof(struct devfreq), GFP_KERNEL);
545 if (!devfreq) { 539 if (!devfreq) {
546 dev_err(dev, "%s: Unable to create devfreq for the device\n",
547 __func__);
548 err = -ENOMEM; 540 err = -ENOMEM;
549 goto err_out; 541 goto err_out;
550 } 542 }
@@ -567,18 +559,21 @@ struct devfreq *devfreq_add_device(struct device *dev,
567 mutex_lock(&devfreq->lock); 559 mutex_lock(&devfreq->lock);
568 } 560 }
569 561
570 dev_set_name(&devfreq->dev, "%s", dev_name(dev)); 562 dev_set_name(&devfreq->dev, "devfreq%d",
563 atomic_inc_return(&devfreq_no));
571 err = device_register(&devfreq->dev); 564 err = device_register(&devfreq->dev);
572 if (err) { 565 if (err) {
573 mutex_unlock(&devfreq->lock); 566 mutex_unlock(&devfreq->lock);
574 goto err_out; 567 goto err_out;
575 } 568 }
576 569
577 devfreq->trans_table = devm_kzalloc(&devfreq->dev, sizeof(unsigned int) * 570 devfreq->trans_table = devm_kzalloc(&devfreq->dev,
571 sizeof(unsigned int) *
578 devfreq->profile->max_state * 572 devfreq->profile->max_state *
579 devfreq->profile->max_state, 573 devfreq->profile->max_state,
580 GFP_KERNEL); 574 GFP_KERNEL);
581 devfreq->time_in_state = devm_kzalloc(&devfreq->dev, sizeof(unsigned long) * 575 devfreq->time_in_state = devm_kzalloc(&devfreq->dev,
576 sizeof(unsigned long) *
582 devfreq->profile->max_state, 577 devfreq->profile->max_state,
583 GFP_KERNEL); 578 GFP_KERNEL);
584 devfreq->last_stat_updated = jiffies; 579 devfreq->last_stat_updated = jiffies;
@@ -937,6 +932,9 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
937 if (df->governor == governor) { 932 if (df->governor == governor) {
938 ret = 0; 933 ret = 0;
939 goto out; 934 goto out;
935 } else if (df->governor->immutable || governor->immutable) {
936 ret = -EINVAL;
937 goto out;
940 } 938 }
941 939
942 if (df->governor) { 940 if (df->governor) {
@@ -966,13 +964,33 @@ static ssize_t available_governors_show(struct device *d,
966 struct device_attribute *attr, 964 struct device_attribute *attr,
967 char *buf) 965 char *buf)
968{ 966{
969 struct devfreq_governor *tmp_governor; 967 struct devfreq *df = to_devfreq(d);
970 ssize_t count = 0; 968 ssize_t count = 0;
971 969
972 mutex_lock(&devfreq_list_lock); 970 mutex_lock(&devfreq_list_lock);
973 list_for_each_entry(tmp_governor, &devfreq_governor_list, node) 971
974 count += scnprintf(&buf[count], (PAGE_SIZE - count - 2), 972 /*
975 "%s ", tmp_governor->name); 973 * The devfreq with immutable governor (e.g., passive) shows
974 * only own governor.
975 */
976 if (df->governor->immutable) {
977 count = scnprintf(&buf[count], DEVFREQ_NAME_LEN,
978 "%s ", df->governor_name);
979 /*
980 * The devfreq device shows the registered governor except for
981 * immutable governors such as passive governor .
982 */
983 } else {
984 struct devfreq_governor *governor;
985
986 list_for_each_entry(governor, &devfreq_governor_list, node) {
987 if (governor->immutable)
988 continue;
989 count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
990 "%s ", governor->name);
991 }
992 }
993
976 mutex_unlock(&devfreq_list_lock); 994 mutex_unlock(&devfreq_list_lock);
977 995
978 /* Truncate the trailing space */ 996 /* Truncate the trailing space */
@@ -993,7 +1011,7 @@ static ssize_t cur_freq_show(struct device *dev, struct device_attribute *attr,
993 1011
994 if (devfreq->profile->get_cur_freq && 1012 if (devfreq->profile->get_cur_freq &&
995 !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq)) 1013 !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
996 return sprintf(buf, "%lu\n", freq); 1014 return sprintf(buf, "%lu\n", freq);
997 1015
998 return sprintf(buf, "%lu\n", devfreq->previous_freq); 1016 return sprintf(buf, "%lu\n", devfreq->previous_freq);
999} 1017}