From: Viresh Kumar <viresh.kumar@linaro.org>
To: Markus Mayer <code@mmayer.net>
Cc: Ralf Baechle <ralf@linux-mips.org>,
"Rafael J . Wysocki" <rjw@rjwysocki.net>,
Markus Mayer <mmayer@broadcom.com>,
MIPS Linux Kernel List <linux-mips@linux-mips.org>,
Power Management List <linux-pm@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/3] cpufreq: bmips-cpufreq: CPUfreq driver for Broadcom's BMIPS SoCs
Date: Fri, 3 Feb 2017 09:58:06 +0530 [thread overview]
Message-ID: <20170203042805.GK7458@vireshk-i7> (raw)
In-Reply-To: <20170202010601.75995-3-code@mmayer.net>
You must be a cpufreq driver expert by now. What's the count? Is this the 3rd
one you have written ? :)
On 01-02-17, 17:06, Markus Mayer wrote:
> diff --git a/drivers/cpufreq/bmips-cpufreq.c b/drivers/cpufreq/bmips-cpufreq.c
> +static struct cpufreq_frequency_table *
> +bmips_cpufreq_get_freq_table(const struct cpufreq_policy *policy)
Maybe call it bmips_cpufreq_create_freq_table() as that's what you are doing.
But its all up to you only.
> +{
> + struct cpufreq_frequency_table *table;
> + struct cpufreq_compat *cc;
> + unsigned long cpu_freq;
> + int i;
> +
> + cc = policy->driver_data;
> + cpu_freq = htp_freq_to_cpu_freq(cc->clk_mult);
> +
> + table = kzalloc((cc->max_freqs + 1) * sizeof(*table), GFP_KERNEL);
Maybe kmalloc as you are updating all the entries.
> + if (!table)
> + return ERR_PTR(-ENOMEM);
> +
> + for (i = 0; i < cc->max_freqs; i++) {
> + table[i].frequency = cpu_freq / (1 << i);
> + table[i].driver_data = i;
> + }
> + table[i].frequency = CPUFREQ_TABLE_END;
> +
> + return table;
> +}
> +
> +static unsigned int bmips_cpufreq_get(unsigned int cpu)
> +{
> + struct cpufreq_policy *policy;
> + struct cpufreq_compat *cc;
> + unsigned long freq, cpu_freq;
> + unsigned int div;
> + uint32_t mode;
> +
> + policy = cpufreq_cpu_get(cpu);
You need to do a corresponding cpufreq_cpu_put().
> + cc = policy->driver_data;
> +
> + switch (cc->bmips_type) {
> + case BMIPS5200:
> + case BMIPS5000:
> + mode = read_c0_brcm_mode();
> + div = ((mode >> BMIPS5_CLK_DIV_SHIFT) & BMIPS5_CLK_DIV_MASK);
> + break;
> + default:
> + div = 0;
> + }
> +
> + cpu_freq = htp_freq_to_cpu_freq(cc->clk_mult);
> + freq = cpu_freq / (1 << div);
> +
> + return freq;
> +}
> +
> +static int bmips_cpufreq_target_index(struct cpufreq_policy *policy,
> + unsigned int index)
> +{
> + struct cpufreq_compat *cc;
> + unsigned int div;
> +
> + cc = policy->driver_data;
> + div = policy->freq_table[index].driver_data;
> +
> + switch (cc->bmips_type) {
> + case BMIPS5200:
> + case BMIPS5000:
> + change_c0_brcm_mode(BMIPS5_CLK_DIV_MASK << BMIPS5_CLK_DIV_SHIFT,
> + (1 << BMIPS5_CLK_DIV_SET_SHIFT) |
> + (div << BMIPS5_CLK_DIV_SHIFT));
> + break;
> + default:
> + return -ENOTSUPP;
> + }
> +
> + return 0;
> +}
> +
> +static int bmips_cpufreq_exit(struct cpufreq_policy *policy)
> +{
> + kfree(policy->freq_table);
> + policy->freq_table = NULL;
No need to set it to NULL.
> +
> + return 0;
> +}
> +
> +static int bmips_cpufreq_init(struct cpufreq_policy *policy)
> +{
> + struct cpufreq_frequency_table *freq_table;
> + int ret;
> +
> + /* Store the compatibility data with the policy. */
> + policy->driver_data = cpufreq_get_driver_data();
Hmm, I wouldn't mind keeping a global variable for this. This driver will be
probed only once and so we can simplify the code a bit. Up to you.
> +
> + freq_table = bmips_cpufreq_get_freq_table(policy);
> + if (IS_ERR(freq_table)) {
> + ret = PTR_ERR(freq_table);
> + pr_err("%s: couldn't determine frequency table (%d).\n",
> + BMIPS_CPUFREQ_NAME, ret);
> + return ret;
> + }
> +
> + ret = cpufreq_generic_init(policy, freq_table, TRANSITION_LATENCY);
> + if (ret)
> + bmips_cpufreq_exit(policy);
> + else
> + pr_info("%s: registered\n", BMIPS_CPUFREQ_NAME);
> +
> + return ret;
> +}
> +
> +static struct cpufreq_driver bmips_cpufreq_driver = {
> + .flags = CPUFREQ_NEED_INITIAL_FREQ_CHECK,
> + .verify = cpufreq_generic_frequency_table_verify,
> + .target_index = bmips_cpufreq_target_index,
> + .get = bmips_cpufreq_get,
> + .init = bmips_cpufreq_init,
> + .exit = bmips_cpufreq_exit,
> + .attr = cpufreq_generic_attr,
> + .name = BMIPS_CPUFREQ_PREFIX,
> +};
> +
> +static int __init bmips_cpufreq_probe(void)
> +{
> + struct cpufreq_compat *cc;
> + struct device_node *np;
> +
> + for (cc = bmips_cpufreq_compat; cc->compatible; cc++) {
> + np = of_find_compatible_node(NULL, "cpu", cc->compatible);
> + if (np) {
> + of_node_put(np);
> + bmips_cpufreq_driver.driver_data = cc;
> + break;
> + }
> + }
> +
> + /* We hit the guard element of the array. No compatible CPU found. */
> + if (!cc->compatible)
> + return -ENODEV;
> +
> + return cpufreq_register_driver(&bmips_cpufreq_driver);
> +}
> +device_initcall(bmips_cpufreq_probe);
> +
> +MODULE_AUTHOR("Markus Mayer <mmayer@broadcom.com>");
> +MODULE_DESCRIPTION("CPUfreq driver for Broadcom BMIPS SoCs");
> +MODULE_LICENSE("GPL");
> --
> 2.7.4
--
viresh
next prev parent reply other threads:[~2017-02-03 4:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-02 1:05 [PATCH 0/3] cpufreq: bmips-cpufreq: CPUfreq driver for Broadcom's BMIPS SoCs Markus Mayer
2017-02-02 1:05 ` [PATCH 1/3] BMIPS: Enable prerequisites for CPUfreq in MIPS Kconfig Markus Mayer
2017-02-02 1:06 ` [PATCH 2/3] cpufreq: bmips-cpufreq: CPUfreq driver for Broadcom's BMIPS SoCs Markus Mayer
2017-02-03 4:28 ` Viresh Kumar [this message]
2017-02-06 21:22 ` Markus Mayer
2017-02-02 1:06 ` [PATCH 3/3] MIPS: BMIPS: enable CPUfreq Markus Mayer
2017-02-03 4:29 ` Viresh Kumar
2017-02-04 1:00 ` Markus Mayer
2017-02-06 3:35 ` Viresh Kumar
2017-02-06 6:38 ` Markus Mayer
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=20170203042805.GK7458@vireshk-i7 \
--to=viresh.kumar@linaro.org \
--cc=code@mmayer.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=linux-pm@vger.kernel.org \
--cc=mmayer@broadcom.com \
--cc=ralf@linux-mips.org \
--cc=rjw@rjwysocki.net \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox