Re: [PATCH v1 10/11] cpufreq: tegra20: Wrap cpufreq into platform driver

Thierry Reding
2018-05-18T09:08:02Z

[-- Attachment #1: Type: text/plain, Size: 3142 bytes --]

On Thu, May 17, 2018 at 09:00:55PM +0300, Dmitry Osipenko wrote:
> Currently tegra20-cpufreq kernel module isn't getting autoloaded because
> there is no device associated with the module, this is one of two patches
> that resolves the module autoloading. This patch adds a module alias that
> will associate the tegra20-cpufreq kernel module with the platform device,
> other patch will instantiate the actual platform device. And now it makes
> sense to wrap cpufreq driver into a platform driver for consistency.
>
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
> drivers/cpufreq/tegra20-cpufreq.c | 116 +++++++++++++++++++-----------
> 1 file changed, 73 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/cpufreq/tegra20-cpufreq.c b/drivers/cpufreq/tegra20-cpufreq.c
> index c0a7b5a78aa6..f9d02a28df9e 100644
> --- a/drivers/cpufreq/tegra20-cpufreq.c
> +++ b/drivers/cpufreq/tegra20-cpufreq.c
> @@ -19,7 +19,7 @@
> #include <linux/clk.h>
> #include <linux/cpufreq.h>
> #include <linux/module.h>
> -#include <linux/of.h>
> +#include <linux/platform_device.h>
>
> static struct cpufreq_frequency_table freq_table[] = {
> { .frequency = 216000 },
> @@ -33,15 +33,19 @@ static struct cpufreq_frequency_table freq_table[] = {
> { .frequency = CPUFREQ_TABLE_END },
> };
>
> -static struct clk *cpu_clk;
> -static struct clk *pll_x_clk;
> -static struct clk *pll_p_clk;
> -static bool pll_x_prepared;
> +struct tegra20_cpufreq_data {

Nit: I'm not a big fan of _data suffixes because they are completely
redundant. Any data structure by definition hosts data, so I'd just drop
that.

[...]
> @@ -152,55 +161,76 @@ static struct cpufreq_driver tegra_cpufreq_driver = {
> .suspend = cpufreq_generic_suspend,
> };
>
> -static int __init tegra_cpufreq_init(void)
> +static int tegra20_cpufreq_probe(struct platform_device *pdev)
> {
> + struct tegra20_cpufreq_data *data;
> int err;
>
> - if (!of_machine_is_compatible("nvidia,tegra20"))
> - return -ENODEV;
> + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
>
> - cpu_clk = clk_get_sys(NULL, "cclk");
> - if (IS_ERR(cpu_clk))
> - return PTR_ERR(cpu_clk);
> + data->cpu_clk = clk_get_sys(NULL, "cclk");
> + if (IS_ERR(data->cpu_clk))
> + return PTR_ERR(data->cpu_clk);
>
> - pll_x_clk = clk_get_sys(NULL, "pll_x");
> - if (IS_ERR(pll_x_clk)) {
> - err = PTR_ERR(pll_x_clk);
> + data->pll_x_clk = clk_get_sys(NULL, "pll_x");
> + if (IS_ERR(data->pll_x_clk)) {
> + err = PTR_ERR(data->pll_x_clk);
> goto put_cpu;
> }
>
> - pll_p_clk = clk_get_sys(NULL, "pll_p");
> - if (IS_ERR(pll_p_clk)) {
> - err = PTR_ERR(pll_p_clk);
> + data->pll_p_clk = clk_get_sys(NULL, "pll_p");
> + if (IS_ERR(data->pll_p_clk)) {
> + err = PTR_ERR(data->pll_p_clk);
> goto put_pll_x;
> }
>
> + data->dev = &pdev->dev;
> +
> + tegra_cpufreq_driver.driver_data = data;

Couldn't this be embedded into struct tegra20_cpufreq_data? Moving
everything but this into a per-device data structure seems half-baked.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]