aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/devfreq/devfreq.c
diff options
context:
space:
mode:
authorChanwoo Choi <cw00.choi@samsung.com>2017-10-22 21:32:06 -0400
committerMyungJoo Ham <myungjoo.ham@samsung.com>2017-10-26 04:08:40 -0400
commitab8f58ad72c4d1abe59216362ddb8bfa428c9071 (patch)
treecf29661b1dde3436107fcb1b7e40c3b86c37eb89 /drivers/devfreq/devfreq.c
parentbb176f67090ca54869fc1262c913aa69d2ede070 (diff)
PM / devfreq: Set min/max_freq when adding the devfreq device
Prior to that, the min/max_freq of the devfreq device are always zero before the user changes the min/max_freq through sysfs entries. It might make the confusion for the min/max_freq. This patch initializes the available min/max_freq by using the OPP during adding the devfreq device. Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com> Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Diffstat (limited to 'drivers/devfreq/devfreq.c')
-rw-r--r--drivers/devfreq/devfreq.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index a1c4ee818614..6a6f88bccdee 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -69,6 +69,34 @@ static struct devfreq *find_device_devfreq(struct device *dev)
69 return ERR_PTR(-ENODEV); 69 return ERR_PTR(-ENODEV);
70} 70}
71 71
72static unsigned long find_available_min_freq(struct devfreq *devfreq)
73{
74 struct dev_pm_opp *opp;
75 unsigned long min_freq = 0;
76
77 opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &min_freq);
78 if (IS_ERR(opp))
79 min_freq = 0;
80 else
81 dev_pm_opp_put(opp);
82
83 return min_freq;
84}
85
86static unsigned long find_available_max_freq(struct devfreq *devfreq)
87{
88 struct dev_pm_opp *opp;
89 unsigned long max_freq = ULONG_MAX;
90
91 opp = dev_pm_opp_find_freq_floor(devfreq->dev.parent, &max_freq);
92 if (IS_ERR(opp))
93 max_freq = 0;
94 else
95 dev_pm_opp_put(opp);
96
97 return max_freq;
98}
99
72/** 100/**
73 * devfreq_get_freq_level() - Lookup freq_table for the frequency 101 * devfreq_get_freq_level() - Lookup freq_table for the frequency
74 * @devfreq: the devfreq instance 102 * @devfreq: the devfreq instance
@@ -559,6 +587,20 @@ struct devfreq *devfreq_add_device(struct device *dev,
559 mutex_lock(&devfreq->lock); 587 mutex_lock(&devfreq->lock);
560 } 588 }
561 589
590 devfreq->min_freq = find_available_min_freq(devfreq);
591 if (!devfreq->min_freq) {
592 mutex_unlock(&devfreq->lock);
593 err = -EINVAL;
594 goto err_dev;
595 }
596
597 devfreq->max_freq = find_available_max_freq(devfreq);
598 if (!devfreq->max_freq) {
599 mutex_unlock(&devfreq->lock);
600 err = -EINVAL;
601 goto err_dev;
602 }
603
562 dev_set_name(&devfreq->dev, "devfreq%d", 604 dev_set_name(&devfreq->dev, "devfreq%d",
563 atomic_inc_return(&devfreq_no)); 605 atomic_inc_return(&devfreq_no));
564 err = device_register(&devfreq->dev); 606 err = device_register(&devfreq->dev);