From: hkallweit1@gmail.com (Heiner Kallweit) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/2] cpufreq: scpi: RfC - Allow to ignore invalid SCPI DVFS clock rates Date: Sat, 4 Feb 2017 22:04:48 +0100 [thread overview] Message-ID: <9a4d7b23-3d5b-b8be-142e-76ded75a5ea4@gmail.com> (raw) In-Reply-To: <3b60654a-88b6-6262-396e-a058ade1c586@gmail.com> Get the highest allowed SCPI DVFS clock rate and ignore all OPP's exceeding this clock rate threshold. Based on DT settings the highest allowed clock rate may be lower than the firmware-offered highest clock rate. This is useful on systems where the firmware offers too optimistic clock rates causing instabilities and crashes. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> --- drivers/cpufreq/scpi-cpufreq.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/cpufreq/scpi-cpufreq.c b/drivers/cpufreq/scpi-cpufreq.c index ea7a4e1b..b5148f3b 100644 --- a/drivers/cpufreq/scpi-cpufreq.c +++ b/drivers/cpufreq/scpi-cpufreq.c @@ -25,6 +25,8 @@ #include <linux/pm_opp.h> #include <linux/scpi_protocol.h> #include <linux/types.h> +#include <linux/of.h> +#include <linux/clk.h> #include "arm_big_little.h" @@ -54,6 +56,20 @@ static int scpi_init_opp_table(const struct cpumask *cpumask) struct scpi_opp *opp; struct device *cpu_dev = get_cpu_device(cpumask_first(cpumask)); struct scpi_dvfs_info *info = scpi_get_dvfs_info(cpu_dev); + u32 max_freq = UINT_MAX; + + if (cpu_dev->of_node) { + struct clk *clk = of_clk_get(cpu_dev->of_node, 0); + + if (!IS_ERR(clk)) { + /* find highest supported rate */ + long tmp = clk_round_rate(clk, UINT_MAX); + + if (tmp > 0) + max_freq = tmp; + clk_put(clk); + } + } if (IS_ERR(info)) return PTR_ERR(info); @@ -62,6 +78,12 @@ static int scpi_init_opp_table(const struct cpumask *cpumask) return -EIO; for (opp = info->opps, idx = 0; idx < info->count; idx++, opp++) { + /* quirk: skip too optimistic firmware-provided rates */ + if (opp->freq > max_freq) { + pr_notice("skip frequency %u\n", opp->freq); + continue; + } + ret = dev_pm_opp_add(cpu_dev, opp->freq, opp->m_volt * 1000); if (ret) { dev_warn(cpu_dev, "failed to add opp %uHz %umV\n", -- 2.11.0
WARNING: multiple messages have this Message-ID (diff)
From: hkallweit1@gmail.com (Heiner Kallweit) To: linus-amlogic@lists.infradead.org Subject: [PATCH 2/2] cpufreq: scpi: RfC - Allow to ignore invalid SCPI DVFS clock rates Date: Sat, 4 Feb 2017 22:04:48 +0100 [thread overview] Message-ID: <9a4d7b23-3d5b-b8be-142e-76ded75a5ea4@gmail.com> (raw) In-Reply-To: <3b60654a-88b6-6262-396e-a058ade1c586@gmail.com> Get the highest allowed SCPI DVFS clock rate and ignore all OPP's exceeding this clock rate threshold. Based on DT settings the highest allowed clock rate may be lower than the firmware-offered highest clock rate. This is useful on systems where the firmware offers too optimistic clock rates causing instabilities and crashes. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> --- drivers/cpufreq/scpi-cpufreq.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/cpufreq/scpi-cpufreq.c b/drivers/cpufreq/scpi-cpufreq.c index ea7a4e1b..b5148f3b 100644 --- a/drivers/cpufreq/scpi-cpufreq.c +++ b/drivers/cpufreq/scpi-cpufreq.c @@ -25,6 +25,8 @@ #include <linux/pm_opp.h> #include <linux/scpi_protocol.h> #include <linux/types.h> +#include <linux/of.h> +#include <linux/clk.h> #include "arm_big_little.h" @@ -54,6 +56,20 @@ static int scpi_init_opp_table(const struct cpumask *cpumask) struct scpi_opp *opp; struct device *cpu_dev = get_cpu_device(cpumask_first(cpumask)); struct scpi_dvfs_info *info = scpi_get_dvfs_info(cpu_dev); + u32 max_freq = UINT_MAX; + + if (cpu_dev->of_node) { + struct clk *clk = of_clk_get(cpu_dev->of_node, 0); + + if (!IS_ERR(clk)) { + /* find highest supported rate */ + long tmp = clk_round_rate(clk, UINT_MAX); + + if (tmp > 0) + max_freq = tmp; + clk_put(clk); + } + } if (IS_ERR(info)) return PTR_ERR(info); @@ -62,6 +78,12 @@ static int scpi_init_opp_table(const struct cpumask *cpumask) return -EIO; for (opp = info->opps, idx = 0; idx < info->count; idx++, opp++) { + /* quirk: skip too optimistic firmware-provided rates */ + if (opp->freq > max_freq) { + pr_notice("skip frequency %u\n", opp->freq); + continue; + } + ret = dev_pm_opp_add(cpu_dev, opp->freq, opp->m_volt * 1000); if (ret) { dev_warn(cpu_dev, "failed to add opp %uHz %umV\n", -- 2.11.0
next prev parent reply other threads:[~2017-02-04 21:04 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <3b60654a-88b6-6262-396e-a058ade1c586@gmail.com> 2017-02-04 21:03 ` [PATCH 1/2] clk: scpi: RfC - Allow to ignore invalid SCPI DVFS clock rates Heiner Kallweit 2017-02-04 21:03 ` Heiner Kallweit 2017-02-08 11:23 ` Sudeep Holla 2017-02-08 11:23 ` Sudeep Holla 2017-02-08 19:45 ` Kevin Hilman 2017-02-08 19:45 ` Kevin Hilman 2017-02-09 10:52 ` Sudeep Holla 2017-02-09 10:52 ` Sudeep Holla 2017-02-09 12:19 ` Michał Zegan 2017-02-09 12:19 ` Michał Zegan 2017-02-09 12:25 ` Sudeep Holla 2017-02-09 12:25 ` Sudeep Holla 2017-02-09 12:51 ` Michał Zegan 2017-02-09 12:51 ` Michał Zegan 2017-02-09 13:31 ` Neil Armstrong 2017-02-09 13:31 ` Neil Armstrong 2017-02-09 14:29 ` Sudeep Holla 2017-02-09 14:29 ` Sudeep Holla 2017-02-04 21:04 ` Heiner Kallweit [this message] 2017-02-04 21:04 ` [PATCH 2/2] cpufreq: " Heiner Kallweit
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=9a4d7b23-3d5b-b8be-142e-76ded75a5ea4@gmail.com \ --to=hkallweit1@gmail.com \ --cc=linux-arm-kernel@lists.infradead.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.