diff mbox

[v3,1/8] PM / devfreq: Set min/max_freq when adding the devfreq device

Message ID 1507691364-3899-2-git-send-email-cw00.choi@samsung.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Chanwoo Choi Oct. 11, 2017, 3:09 a.m. UTC
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>
---
 drivers/devfreq/devfreq.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

Comments

MyungJoo Ham Oct. 11, 2017, 11:09 a.m. UTC | #1
> 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>
> ---
>  drivers/devfreq/devfreq.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
> 
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index a1c4ee818614..ae8717a6eee1 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index a1c4ee818614..ae8717a6eee1 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -69,6 +69,34 @@ static struct devfreq *find_device_devfreq(struct device *dev)
>  	return ERR_PTR(-ENODEV);
>  }
>  
> +static unsigned long find_available_min_freq(struct devfreq *devfreq)
> +{
> +	struct dev_pm_opp *opp;
> +	unsigned long min_freq = 0;
> +
> +	opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &min_freq);

When min_freq is 0, dev_pm_opp_find_freq_ceil will return ERR_PTR(-EINVAL);

--- from drivers/base/power/opp/core.c ------ 
struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
                                             unsigned long *freq)
{
        struct opp_table *opp_table;
        struct dev_pm_opp *opp;

        if (!dev || !freq) {
                dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq);
                return ERR_PTR(-EINVAL);
        }
---------------------------------------------

Cheers,
MyungJoo
MyungJoo Ham Oct. 11, 2017, 11:22 a.m. UTC | #2
> > 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>
> > ---
> >  drivers/devfreq/devfreq.c | 43 +++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 43 insertions(+)
> > 
> > diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> > index a1c4ee818614..ae8717a6eee1 100644
> > --- a/drivers/devfreq/devfreq.c
> > +++ b/drivers/devfreq/devfreq.c
> > diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> > index a1c4ee818614..ae8717a6eee1 100644
> > --- a/drivers/devfreq/devfreq.c
> > +++ b/drivers/devfreq/devfreq.c
> > @@ -69,6 +69,34 @@ static struct devfreq *find_device_devfreq(struct device *dev)
> >  	return ERR_PTR(-ENODEV);
> >  }
> >  
> > +static unsigned long find_available_min_freq(struct devfreq *devfreq)
> > +{
> > +	struct dev_pm_opp *opp;
> > +	unsigned long min_freq = 0;
> > +
> > +	opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &min_freq);
> 
> When min_freq is 0, dev_pm_opp_find_freq_ceil will return ERR_PTR(-EINVAL);
> 
> --- from drivers/base/power/opp/core.c ------ 
> struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
>                                              unsigned long *freq)
> {
>         struct opp_table *opp_table;
>         struct dev_pm_opp *opp;
> 
>         if (!dev || !freq) {
>                 dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq);
>                 return ERR_PTR(-EINVAL);
>         }
> ---------------------------------------------

Sorry, please never mind. My Bad. Your code had no such issues.

So, I'm adding:
Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com>

> 
> Cheers,
> MyungJoo
>
diff mbox

Patch

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index a1c4ee818614..ae8717a6eee1 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -69,6 +69,34 @@  static struct devfreq *find_device_devfreq(struct device *dev)
 	return ERR_PTR(-ENODEV);
 }
 
+static unsigned long find_available_min_freq(struct devfreq *devfreq)
+{
+	struct dev_pm_opp *opp;
+	unsigned long min_freq = 0;
+
+	opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &min_freq);
+	if (IS_ERR(opp))
+		min_freq = 0;
+	else
+		dev_pm_opp_put(opp);
+
+	return min_freq;
+}
+
+static unsigned long find_available_max_freq(struct devfreq *devfreq)
+{
+	struct dev_pm_opp *opp;
+	unsigned long max_freq = ULONG_MAX;
+
+	opp = dev_pm_opp_find_freq_floor(devfreq->dev.parent, &max_freq);
+	if (IS_ERR(opp))
+		max_freq = 0;
+	else
+		dev_pm_opp_put(opp);
+
+	return max_freq;
+}
+
 /**
  * devfreq_get_freq_level() - Lookup freq_table for the frequency
  * @devfreq:	the devfreq instance
@@ -559,6 +587,21 @@  struct devfreq *devfreq_add_device(struct device *dev,
 		mutex_lock(&devfreq->lock);
 	}
 
+	/* Set the scaling available min_freq and max_freq */
+	devfreq->min_freq = find_available_min_freq(devfreq);
+	if (!devfreq->min_freq) {
+		mutex_unlock(&devfreq->lock);
+		err = -EINVAL;
+		goto err_dev;
+	}
+
+	devfreq->max_freq = find_available_max_freq(devfreq);
+	if (!devfreq->max_freq) {
+		mutex_unlock(&devfreq->lock);
+		err = -EINVAL;
+		goto err_dev;
+	}
+
 	dev_set_name(&devfreq->dev, "devfreq%d",
 				atomic_inc_return(&devfreq_no));
 	err = device_register(&devfreq->dev);