From: Lucas Stach <l.stach@pengutronix.de> To: Shawn Guo <shawn.guo@freescale.com>, Viresh Kumar <viresh.kumar@linaro.org> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH 1/5] cpufreq: cpu0: disable unsupported OPPs Date: Fri, 19 Sep 2014 18:16:17 +0200 [thread overview] Message-ID: <1411143381-10516-2-git-send-email-l.stach@pengutronix.de> (raw) In-Reply-To: <1411143381-10516-1-git-send-email-l.stach@pengutronix.de> If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> --- drivers/cpufreq/cpufreq-cpu0.c | 60 ++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/drivers/cpufreq/cpufreq-cpu0.c b/drivers/cpufreq/cpufreq-cpu0.c index 0d2172b07765..83296bd2089e 100644 --- a/drivers/cpufreq/cpufreq-cpu0.c +++ b/drivers/cpufreq/cpufreq-cpu0.c @@ -117,6 +117,7 @@ static int cpu0_cpufreq_probe(struct platform_device *pdev) { struct device_node *np; int ret; + unsigned long opp_freq = 0, min_uV = ~0, max_uV = 0, tol; cpu_dev = get_cpu_device(0); if (!cpu_dev) { @@ -155,42 +156,55 @@ static int cpu0_cpufreq_probe(struct platform_device *pdev) /* OPPs might be populated at runtime, don't check for error here */ of_init_opp_table(cpu_dev); - ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table); - if (ret) { - pr_err("failed to init cpufreq table: %d\n", ret); - goto out_put_clk; - } - of_property_read_u32(np, "voltage-tolerance", &voltage_tolerance); if (of_property_read_u32(np, "clock-latency", &transition_latency)) transition_latency = CPUFREQ_ETERNAL; if (!IS_ERR(cpu_reg)) { - struct dev_pm_opp *opp; - unsigned long min_uV, max_uV; - int i; - /* - * OPP is maintained in order of increasing frequency, and - * freq_table initialised from OPP is therefore sorted in the - * same order. + * Disable any OPPs where the connected regulator isn't able to + * provide the specified voltage and record minimum and maximum + * voltage levels. */ - for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) - ; - rcu_read_lock(); - opp = dev_pm_opp_find_freq_exact(cpu_dev, - freq_table[0].frequency * 1000, true); - min_uV = dev_pm_opp_get_voltage(opp); - opp = dev_pm_opp_find_freq_exact(cpu_dev, - freq_table[i-1].frequency * 1000, true); - max_uV = dev_pm_opp_get_voltage(opp); - rcu_read_unlock(); + while (1) { + struct dev_pm_opp *opp; + unsigned long opp_uV; + + rcu_read_lock(); + opp = dev_pm_opp_find_freq_ceil(cpu_dev, &opp_freq); + if (IS_ERR(opp)) { + rcu_read_unlock(); + break; + } + opp_uV = dev_pm_opp_get_voltage(opp); + rcu_read_unlock(); + + tol = opp_uV * voltage_tolerance / 100; + if (regulator_is_supported_voltage(cpu_reg, opp_uV, + opp_uV + tol)) { + if (opp_uV < min_uV) + min_uV = opp_uV; + if (opp_uV > max_uV) + max_uV = opp_uV; + } else { + dev_pm_opp_disable(cpu_dev, opp_freq); + } + + opp_freq++; + } + ret = regulator_set_voltage_time(cpu_reg, min_uV, max_uV); if (ret > 0) transition_latency += ret * 1000; } + ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table); + if (ret) { + pr_err("failed to init cpufreq table: %d\n", ret); + goto out_put_clk; + } + ret = cpufreq_register_driver(&cpu0_cpufreq_driver); if (ret) { pr_err("failed register driver: %d\n", ret); -- 2.1.0
WARNING: multiple messages have this Message-ID (diff)
From: l.stach@pengutronix.de (Lucas Stach) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/5] cpufreq: cpu0: disable unsupported OPPs Date: Fri, 19 Sep 2014 18:16:17 +0200 [thread overview] Message-ID: <1411143381-10516-2-git-send-email-l.stach@pengutronix.de> (raw) In-Reply-To: <1411143381-10516-1-git-send-email-l.stach@pengutronix.de> If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> --- drivers/cpufreq/cpufreq-cpu0.c | 60 ++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/drivers/cpufreq/cpufreq-cpu0.c b/drivers/cpufreq/cpufreq-cpu0.c index 0d2172b07765..83296bd2089e 100644 --- a/drivers/cpufreq/cpufreq-cpu0.c +++ b/drivers/cpufreq/cpufreq-cpu0.c @@ -117,6 +117,7 @@ static int cpu0_cpufreq_probe(struct platform_device *pdev) { struct device_node *np; int ret; + unsigned long opp_freq = 0, min_uV = ~0, max_uV = 0, tol; cpu_dev = get_cpu_device(0); if (!cpu_dev) { @@ -155,42 +156,55 @@ static int cpu0_cpufreq_probe(struct platform_device *pdev) /* OPPs might be populated at runtime, don't check for error here */ of_init_opp_table(cpu_dev); - ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table); - if (ret) { - pr_err("failed to init cpufreq table: %d\n", ret); - goto out_put_clk; - } - of_property_read_u32(np, "voltage-tolerance", &voltage_tolerance); if (of_property_read_u32(np, "clock-latency", &transition_latency)) transition_latency = CPUFREQ_ETERNAL; if (!IS_ERR(cpu_reg)) { - struct dev_pm_opp *opp; - unsigned long min_uV, max_uV; - int i; - /* - * OPP is maintained in order of increasing frequency, and - * freq_table initialised from OPP is therefore sorted in the - * same order. + * Disable any OPPs where the connected regulator isn't able to + * provide the specified voltage and record minimum and maximum + * voltage levels. */ - for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) - ; - rcu_read_lock(); - opp = dev_pm_opp_find_freq_exact(cpu_dev, - freq_table[0].frequency * 1000, true); - min_uV = dev_pm_opp_get_voltage(opp); - opp = dev_pm_opp_find_freq_exact(cpu_dev, - freq_table[i-1].frequency * 1000, true); - max_uV = dev_pm_opp_get_voltage(opp); - rcu_read_unlock(); + while (1) { + struct dev_pm_opp *opp; + unsigned long opp_uV; + + rcu_read_lock(); + opp = dev_pm_opp_find_freq_ceil(cpu_dev, &opp_freq); + if (IS_ERR(opp)) { + rcu_read_unlock(); + break; + } + opp_uV = dev_pm_opp_get_voltage(opp); + rcu_read_unlock(); + + tol = opp_uV * voltage_tolerance / 100; + if (regulator_is_supported_voltage(cpu_reg, opp_uV, + opp_uV + tol)) { + if (opp_uV < min_uV) + min_uV = opp_uV; + if (opp_uV > max_uV) + max_uV = opp_uV; + } else { + dev_pm_opp_disable(cpu_dev, opp_freq); + } + + opp_freq++; + } + ret = regulator_set_voltage_time(cpu_reg, min_uV, max_uV); if (ret > 0) transition_latency += ret * 1000; } + ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table); + if (ret) { + pr_err("failed to init cpufreq table: %d\n", ret); + goto out_put_clk; + } + ret = cpufreq_register_driver(&cpu0_cpufreq_driver); if (ret) { pr_err("failed register driver: %d\n", ret); -- 2.1.0
next prev parent reply other threads:[~2014-09-19 16:16 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-09-19 16:16 [PATCH 0/5] i.MX53 cpufreq support Lucas Stach 2014-09-19 16:16 ` Lucas Stach 2014-09-19 16:16 ` Lucas Stach [this message] 2014-09-19 16:16 ` [PATCH 1/5] cpufreq: cpu0: disable unsupported OPPs Lucas Stach 2014-09-19 16:49 ` Viresh Kumar 2014-09-19 16:49 ` Viresh Kumar 2014-09-19 16:16 ` [PATCH 2/5] clk: imx5: add step clock, used when reprogramming PLL1 Lucas Stach 2014-09-19 16:16 ` Lucas Stach 2014-09-19 16:16 ` [PATCH 3/5] clk: imx: add CPU clock type Lucas Stach 2014-09-19 16:16 ` Lucas Stach 2014-09-26 2:59 ` Shawn Guo 2014-09-26 2:59 ` Shawn Guo 2014-09-26 10:10 ` Lucas Stach 2014-09-26 10:10 ` Lucas Stach 2014-09-19 16:16 ` [PATCH 4/5] arm: imx53: clk: add ARM clock Lucas Stach 2014-09-19 16:16 ` Lucas Stach 2014-09-19 16:16 ` [PATCH 5/5] ARM: imx53: add cpufreq support Lucas Stach 2014-09-19 16:16 ` Lucas Stach 2014-09-26 3:02 ` Shawn Guo 2014-09-26 3:02 ` Shawn Guo
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1411143381-10516-2-git-send-email-l.stach@pengutronix.de \ --to=l.stach@pengutronix.de \ --cc=kernel@pengutronix.de \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-pm@vger.kernel.org \ --cc=rjw@rjwysocki.net \ --cc=shawn.guo@freescale.com \ --cc=viresh.kumar@linaro.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.