Remodel Tegra cpufreq drivers to support Tegra series SoC
Subsystems (4)
v3 cover Remodel Tegra cpufreq drivers to support Tegra series SoC
This patch series remodel Tegra cpufreq driver to make it more easy to add new SoC support, in addition to that, adding probe function in the driver to let probe defer can be used to control init sequence when we are going to support DVFS.
Changes since v2:
- Fix Kconfig.
- Rebase on top of branch 'cpufreq-next' on git://git.linaro.org/people/vireshk/linux.git.
Changes since v1:
- Split up patches.
- Split configuration-time data out of structure "tegra_cpufreq_data".
- Bug fixes.
Bill Huang (2):
cpufreq: tegra: Call tegra_cpufreq_init() specifically in machine
code
cpufreq: tegra: Re-model Tegra cpufreq driver
arch/arm/mach-tegra/tegra.c | 2 + drivers/cpufreq/Kconfig.arm | 12 +++ drivers/cpufreq/Makefile | 1 + drivers/cpufreq/tegra-cpufreq.c | 188 +++++++++++++++++-------------------- drivers/cpufreq/tegra-cpufreq.h | 40 ++++++++ drivers/cpufreq/tegra20-cpufreq.c | 136 +++++++++++++++++++++++++++ include/linux/tegra-soc.h | 11 ++- 7 files changed, 287 insertions(+), 103 deletions(-) create mode 100644 drivers/cpufreq/tegra-cpufreq.h create mode 100644 drivers/cpufreq/tegra20-cpufreq.c
Signature · 1 line
1.7.9.5
PATCH v3 1/2 cpufreq: tegra: Call tegra_cpufreq_init() specifically in machine code
Move the call from module_init to Tegra machine codes so it won't be called in a multi-platform kernel running on non-Tegra SoCs.
--- arch/arm/mach-tegra/tegra.c | 2 ++ drivers/cpufreq/tegra-cpufreq.c | 13 ++----------- include/linux/tegra-soc.h | 11 ++++++++++- 3 files changed, 14 insertions(+), 12 deletions(-)
arch/arm/mach-tegra/tegra.c +2 -0
@@ -34,6 +34,7 @@#include <linux/usb/tegra_usb_phy.h> #include <linux/clk/tegra.h> #include <linux/irqchip.h> +#include <linux/tegra-soc.h> #include <asm/hardware/cache-l2x0.h> #include <asm/mach-types.h>
@@ -160,6 +161,7 @@ static void __init tegra_dt_init_late(void) {int i; +tegra_cpufreq_init ();tegra_init_suspend ();tegra_cpuidle_init ();tegra_powergate_debugfs_init ();
drivers/cpufreq/tegra-cpufreq.c +2 -11
@@ -155,7 +155,7 @@ static struct cpufreq_driver tegra_cpufreq_driver = {#endif }; -static int __init tegra_cpufreq_init (void ) +int __init tegra_cpufreq_init (void ) { cpu_clk =clk_get_sys (NULL ,"cclk" );if (IS_ERR (cpu_clk))
@@ -177,17 +177,8 @@ static int __init tegra_cpufreq_init(void)return cpufreq_register_driver (&tegra_cpufreq_driver); } - -static void __exit tegra_cpufreq_exit(void) -{ -cpufreq_unregister_driver (&tegra_cpufreq_driver); -clk_put (emc_clk); -clk_put (cpu_clk); -} - +EXPORT_SYMBOL (tegra_cpufreq_init);MODULE_AUTHOR ("Colin Cross <[email protected]>" );MODULE_DESCRIPTION ("cpufreq driver for Nvidia Tegra2" );MODULE_LICENSE ("GPL" ); -module_init (tegra_cpufreq_init); -module_exit (tegra_cpufreq_exit);
include/linux/tegra-soc.h +10 -1
@@ -1,5 +1,5 @@/* -* Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. +* Copyright (c) 2012,2013, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License,
@@ -17,6 +17,15 @@#ifndef __LINUX_TEGRA_SOC_H_#define __LINUX_TEGRA_SOC_H_ +#ifdef CONFIG_ARM_TEGRA_CPUFREQ +int tegra_cpufreq_init (void ); +#else +static inline int tegra_cpufreq_init (void ) +{ +return -EINVAL ; +} +#endif +u32 tegra_read_chipid (void );#endif /* __LINUX_TEGRA_SOC_H_ */
Signature · 1 line
1.7.9.5
Re: [PATCH v3 1/2] cpufreq: tegra: Call tegra_cpufreq_init() specifically in machine code
include/linux/tegra-soc.h
Quoted 4 lines · Bill Huang
Move the call from
module_initto Tegra machine codes so it won't be called in a multi-platform kernel running on non-Tegra SoCs.include/linux/tegra-soc.h +0
-0
It might be better to create <linux/tegra-cpufreq.h> for the interface to the cpufreq driver; tegra-soc.h is for the interface to core Tegra code *from* other drivers.
include/linux/tegra-soc.h line 27
Quoted 8 lines
include/linux/tegra-soc.h +8
-0+#ifdef CONFIG_ARM_TEGRA_CPUFREQ +int tegra_cpufreq_init (void ); +#else +static inline int tegra_cpufreq_init (void ) +{ +return -EINVAL ; +} +#endif
Probably best to "return 0" from the !CONFIG_ARM_TEGRA_CPUFREQ case; the whole point is to isolate callers from having to care whether CONFIG_ARM_TEGRA_CPUFREQ is enabled, and making the function act like it worked OK is part of that isolation.
Re: [PATCH v3 1/2] cpufreq: tegra: Call tegra_cpufreq_init() specifically in machine code
Quoted 9 lines · Stephen Warren
include/linux/tegra-soc.h
Quoted 4 lines · Bill Huang
Move the call from
module_initto Tegra machine codes so it won't be called in a multi-platform kernel running on non-Tegra SoCs.include/linux/tegra-soc.h +0
-0It might be better to create <
linux/tegra-cpufreq.h> for the interface to the cpufreq driver;tegra-soc.his for the interface to core Tegra code *from* other drivers.
Thanks, will do.
Quoted 15 lines
include/linux/tegra-soc.h line 27
Quoted 9 lines
include/linux/tegra-soc.h +8
-0+#ifdef CONFIG_ARM_TEGRA_CPUFREQ +int tegra_cpufreq_init (void ); +#else +static inline int tegra_cpufreq_init (void ) +{ +return -EINVAL ; +} +#endif Probably best to "return 0" from the !CONFIG_ARM_TEGRA_CPUFREQ case; the whole point is to isolate callers from having to care whether
CONFIG_ARM_TEGRA_CPUFREQis enabled, and making the function act like it worked OK is part of that isolation.
OK thanks.
Viresh Kumar
maintainerRe: [PATCH v3 1/2] cpufreq: tegra: Call tegra_cpufreq_init() specifically in machine code
In reply to Bill HuangQuoted 35 lines · Bill Huang
Move the call from
module_initto Tegra machine codes so it won't be called in a multi-platform kernel running on non-Tegra SoCs.Signed-off-by Bill Huang <[email protected]>--- arch/arm/mach-tegra/tegra.c | 2 ++ drivers/cpufreq/tegra-cpufreq.c | 13 ++----------- include/linux/tegra-soc.h | 11 ++++++++++- 3 files changed, 14 insertions(+), 12 deletions(-)arch/arm/mach-tegra/tegra.c +2
-0@@ -34,6 +34,7 @@#include <linux/usb/tegra_usb_phy.h> #include <linux/clk/tegra.h> #include <linux/irqchip.h> +#include <linux/tegra-soc.h> #include <asm/hardware/cache-l2x0.h> #include <asm/mach-types.h> @@ -160,6 +161,7 @@ static void __init tegra_dt_init_late(void) {int i; +tegra_cpufreq_init ();tegra_init_suspend ();tegra_cpuidle_init ();tegra_powergate_debugfs_init ();drivers/cpufreq/tegra-cpufreq.c +0
-0
drivers/cpufreq/tegra-cpufreq.c static struct cpufreq_driver tegra_cpufreq_driver = { · line 156
Quoted 2 lines
drivers/cpufreq/tegra-cpufreq.c +0
-0@@ -155,7 +155,7 @@ static struct cpufreq_driver tegra_cpufreq_driver = {#endif };
Remove module.h as well ??
Quoted 12 lines
drivers/cpufreq/tegra-cpufreq.c +1
-4-static int __init tegra_cpufreq_init (void ) +int __init tegra_cpufreq_init (void ) { cpu_clk =clk_get_sys (NULL ,"cclk" );if (IS_ERR (cpu_clk))@@ -177,17 +177,8 @@ static int __init tegra_cpufreq_init(void)return cpufreq_register_driver (&tegra_cpufreq_driver); } - -static void __exit tegra_cpufreq_exit(void) -{
drivers/cpufreq/tegra-cpufreq.c static int __init tegra_cpufreq_init(void) · line 184
Quoted 10 lines
drivers/cpufreq/tegra-cpufreq.c +1
-5-cpufreq_unregister_driver (&tegra_cpufreq_driver); -clk_put (emc_clk); -clk_put (cpu_clk); -} - +EXPORT_SYMBOL (tegra_cpufreq_init);MODULE_AUTHOR ("Colin Cross <[email protected]>" );MODULE_DESCRIPTION ("cpufreq driver for Nvidia Tegra2" );MODULE_LICENSE ("GPL" );
Remove these as well? As they don't have a meaning for Tegra cpufreq driver which can't be compiled as module.
drivers/cpufreq/tegra-cpufreq.c static int __init tegra_cpufreq_init(void) · line 193
Quoted 2 lines
drivers/cpufreq/tegra-cpufreq.c +0
-2-module_init (tegra_cpufreq_init); -module_exit (tegra_cpufreq_exit);
Rest as what Stephen suggested.
Re: [PATCH v3 1/2] cpufreq: tegra: Call tegra_cpufreq_init() specifically in machine code
Quoted 60 lines · Viresh Kumar
Quoted 35 lines · Bill Huang
Move the call from
module_initto Tegra machine codes so it won't be called in a multi-platform kernel running on non-Tegra SoCs.Signed-off-by Bill Huang <[email protected]>--- arch/arm/mach-tegra/tegra.c | 2 ++ drivers/cpufreq/tegra-cpufreq.c | 13 ++----------- include/linux/tegra-soc.h | 11 ++++++++++- 3 files changed, 14 insertions(+), 12 deletions(-)arch/arm/mach-tegra/tegra.c +2
-0@@ -34,6 +34,7 @@#include <linux/usb/tegra_usb_phy.h> #include <linux/clk/tegra.h> #include <linux/irqchip.h> +#include <linux/tegra-soc.h> #include <asm/hardware/cache-l2x0.h> #include <asm/mach-types.h> @@ -160,6 +161,7 @@ static void __init tegra_dt_init_late(void) {int i; +tegra_cpufreq_init ();tegra_init_suspend ();tegra_cpuidle_init ();tegra_powergate_debugfs_init ();drivers/cpufreq/tegra-cpufreq.c +0
-0drivers/cpufreq/tegra-cpufreq.c static struct cpufreq_driver tegra_cpufreq_driver = { · line 156
Quoted 2 lines
drivers/cpufreq/tegra-cpufreq.c +0
-0@@ -155,7 +155,7 @@ static struct cpufreq_driver tegra_cpufreq_driver = {#endif };Remove
module.has well ??Quoted 19 lines
drivers/cpufreq/tegra-cpufreq.c +2
-9-static int __init tegra_cpufreq_init (void ) +int __init tegra_cpufreq_init (void ) { cpu_clk =clk_get_sys (NULL ,"cclk" );if (IS_ERR (cpu_clk))@@ -177,17 +177,8 @@ static int __init tegra_cpufreq_init(void)return cpufreq_register_driver (&tegra_cpufreq_driver); } - -static void __exit tegra_cpufreq_exit(void) -{ -cpufreq_unregister_driver (&tegra_cpufreq_driver); -clk_put (emc_clk); -clk_put (cpu_clk); -} - +EXPORT_SYMBOL (tegra_cpufreq_init);
Quoted 6 lines
drivers/cpufreq/tegra-cpufreq.c static int __init tegra_cpufreq_init(void) · line 184
Quoted 3 lines
drivers/cpufreq/tegra-cpufreq.c +0
-0MODULE_AUTHOR ("Colin Cross <[email protected]>" );MODULE_DESCRIPTION ("cpufreq driver for Nvidia Tegra2" );MODULE_LICENSE ("GPL" );Remove these as well? As they don't have a meaning for Tegra cpufreq driver which can't be compiled as module.
OK thanks.
Quoted 6 lines
drivers/cpufreq/tegra-cpufreq.c static int __init tegra_cpufreq_init(void) · line 193
Quoted 3 lines
drivers/cpufreq/tegra-cpufreq.c +0
-2-module_init (tegra_cpufreq_init); -module_exit (tegra_cpufreq_exit);Rest as what Stephen suggested.
PATCH v3 2/2 cpufreq: tegra: Re-model Tegra cpufreq driver
In reply to Bill HuangRe-model Tegra cpufreq driver to support all Tegra series of SoCs.
* Make tegra-cpufreq.c a generic Tegra cpufreq driver.
* Move Tegra20 specific codes into tegra20-cpufreq.c.
* Bind Tegra cpufreq dirver with a fake device so defer probe would work when we're going to get regulator in the driver to support voltage scaling (DVFS).
--- drivers/cpufreq/Kconfig.arm | 12 +++ drivers/cpufreq/Makefile | 1 + drivers/cpufreq/tegra-cpufreq.c | 185 ++++++++++++++++++------------------- drivers/cpufreq/tegra-cpufreq.h | 40 ++++++++ drivers/cpufreq/tegra20-cpufreq.c | 136 +++++++++++++++++++++++++++ 5 files changed, 278 insertions(+), 96 deletions(-) create mode 100644 drivers/cpufreq/tegra-cpufreq.h create mode 100644 drivers/cpufreq/tegra20-cpufreq.c
drivers/cpufreq/Kconfig.arm +12 -0
@@ -225,6 +225,18 @@ config ARM_TEGRA_CPUFREQ help This adds the CPUFreq driver support for TEGRA SOCs. +config ARM_TEGRA20_CPUFREQ + bool "NVIDIA TEGRA20" + depends on ARM_TEGRA_CPUFREQ && ARCH_TEGRA_2x_SOC + default y + help + This enables Tegra20 cpufreq functionality, it adds + Tegra20 CPU frequency ladder and the call back functions + to set CPU rate. All the non-SoC dependant codes are + controlled by the config ARM_TEGRA20_CPUFREQ. + + If in doubt, say N. + config ARM_VEXPRESS_SPC_CPUFREQ tristate "Versatile Express SPC based CPUfreq driver" select ARM_BIG_LITTLE_CPUFREQ
drivers/cpufreq/Makefile +1 -0
@@ -74,6 +74,7 @@ obj-$(CONFIG_ARM_SA1100_CPUFREQ) += sa1100-cpufreq.o obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o obj-$(CONFIG_ARM_TEGRA_CPUFREQ) += tegra-cpufreq.o +obj-$(CONFIG_ARM_TEGRA20_CPUFREQ) += tegra20-cpufreq.o obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ) += vexpress-spc-cpufreq.o ##################################################################################
drivers/cpufreq/tegra-cpufreq.c +89 -96
239 lines not on this page · raw message
drivers/cpufreq/tegra-cpufreq.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Copyright (c) 2013, NVIDIA Corporation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +*/ + +#ifndef __LINUX_TEGRA_CPUFREQ_H +#define __LINUX_TEGRA_CPUFREQ_H + +struct tegra_cpufreq_config { +void (*vote_emc_on_cpu_rate)(unsigned long ); +int (*cpu_clk_set_rate)(unsigned long ); +void (*cpufreq_clk_init)(void ); +void (*cpufreq_clk_exit)(void ); +}; + +struct tegra_cpufreq_data { +struct device *dev; +struct clk *cpu_clk; +struct cpufreq_frequency_table *freq_table; +}; + +#ifdef CONFIG_ARM_TEGRA20_CPUFREQ +int tegra20_cpufreq_init (struct tegra_cpufreq_data *data, +const struct tegra_cpufreq_config **config); +#else +static inline int tegra20_cpufreq_init (struct tegra_cpufreq_data *data, +const struct tegra_cpufreq_config **config) +{return -EINVAL ; } +#endif + +#endif /* __LINUX_TEGRA_CPUFREQ_H_ */
drivers/cpufreq/tegra20-cpufreq.c new file +136 -0
136 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH v3 2/2] cpufreq: tegra: Re-model Tegra cpufreq driver
Quoted 11 lines · Bill Huang
Re-model Tegra cpufreq driver to support all Tegra series of SoCs.
* Make
tegra-cpufreq.ca generic Tegra cpufreq driver.
* Move Tegra20 specific codes intotegra20-cpufreq.c.
* Bind Tegra cpufreq dirver with a fake device so defer probe would work when we're going to get regulator in the driver to support voltage scaling (DVFS).drivers/cpufreq/tegra-cpufreq.c +0
-0@@ -91,14 +40,10 @@ static int tegra_update_cpu_speed(struct cpufreq_policy *policy,
...
drivers/cpufreq/tegra-cpufreq.c static int tegra_update_cpu_speed(struct cpufreq_policy *policy, · line 49
Quoted 7 lines
drivers/cpufreq/tegra-cpufreq.c +4
-0+if (soc_config->vote_emc_on_cpu_rate) + soc_config->vote_emc_on_cpu_rate (rate); + + ret = soc_config->cpu_clk_set_rate (rate *1000 );if (ret)pr_err ("cpu-tegra: Failed to set cpu frequency to %lu kHz\n" , rate);
Is there any/much shared code left in this file after this patch? It seems like all this file does now is make each cpufreq callback function call soc_config->the_same_function_name(). If so, wouldn't it be better to simply implement completely separate tegar20-cpufreq and tegra30-cpufreq drivers, and register them each directly with the cpufreq core, to avoid this file doing all the indirection?
Quoted 10 lines
drivers/cpufreq/tegra-cpufreq.c +9
-1-int __init tegra_cpufreq_init (void ) +static struct { +char *compat; +int (*init)(struct tegra_cpufreq_data *, +const struct tegra_cpufreq_config **); +} tegra_init_funcs[] = { + {"nvidia,tegra20" , tegra20_cpufreq_init }, +}; + +static int tegra_cpufreq_probe (struct platform_device *pdev)
...
drivers/cpufreq/tegra-cpufreq.c static struct cpufreq_driver tegra_cpufreq_driver = { · line 135
Quoted 11 lines
drivers/cpufreq/tegra-cpufreq.c +10
-0+for (i =0 ; i <ARRAY_SIZE (tegra_init_funcs); i++) { +if (of_machine_is_compatible (tegra_init_funcs[i].compat)) { + ret = tegra_init_funcs[i].init (tegra_data, &soc_config); +if (!ret) +break ; +else + goto out; + } } +if (i ==ARRAY_SIZE (tegra_init_funcs)) + goto out;
I think there are better ways of doing this than open-coding it. Perhaps of_match_device() or the platform-driver equivalent could be made to work?
drivers/cpufreq/tegra-cpufreq.c static struct cpufreq_driver tegra_cpufreq_driver = { · line 173
Quoted 9 lines
drivers/cpufreq/tegra-cpufreq.c +7
-0+int __init tegra_cpufreq_init (void ) +{ +struct platform_device_info devinfo = { .name ="tegra-cpufreq" , }; + +platform_device_register_full (&devinfo); + +return 0 ; }EXPORT_SYMBOL (tegra_cpufreq_init);
Perhaps instead of hard-coding the name "tegra-cpufreq" here, you could dynamically construct the device name based on the DT's root compatible value, register "${root_compatible}-cpufreq", e.g. "nvidia,tegra20-cpufreq" or "nvidia,tegra30-cpufreq". That would allow the kernel's standard device/driver matching mechanism to pick the correct driver to instantiate. Perhaps you could even dynamically register an OF device so that you can use of_match_device() in probe, if there's some advantage of having a single driver that supports N chips.
Re: [PATCH v3 2/2] cpufreq: tegra: Re-model Tegra cpufreq driver
Quoted 13 lines · Stephen Warren
Quoted 11 lines · Bill Huang
Re-model Tegra cpufreq driver to support all Tegra series of SoCs.
* Make
tegra-cpufreq.ca generic Tegra cpufreq driver.
* Move Tegra20 specific codes intotegra20-cpufreq.c.
* Bind Tegra cpufreq dirver with a fake device so defer probe would work when we're going to get regulator in the driver to support voltage scaling (DVFS).drivers/cpufreq/tegra-cpufreq.c +0
-0@@ -91,14 +40,10 @@ static int tegra_update_cpu_speed(struct cpufreq_policy *policy,...
Quoted 14 lines
drivers/cpufreq/tegra-cpufreq.c static int tegra_update_cpu_speed(struct cpufreq_policy *policy, · line 49
Quoted 7 lines
drivers/cpufreq/tegra-cpufreq.c +4
-0+if (soc_config->vote_emc_on_cpu_rate) + soc_config->vote_emc_on_cpu_rate (rate); + + ret = soc_config->cpu_clk_set_rate (rate *1000 );if (ret)pr_err ("cpu-tegra: Failed to set cpu frequency to %lu kHz\n" , rate);Is there any/much shared code left in this file after this patch? It seems like all this file does now is make each cpufreq callback function call
soc_config->the_same_function_name(). If so, wouldn't it be better to simply implement completely separate tegar20-cpufreq and tegra30-cpufreq drivers, and register them each directly with the cpufreq core, to avoid this file doing all the indirection?
I think this file is needed since we can shared the registration and probe logic for different SoCs.
Quoted 13 lines
Quoted 12 lines
drivers/cpufreq/tegra-cpufreq.c +9
-1-int __init tegra_cpufreq_init (void ) +static struct { +char *compat; +int (*init)(struct tegra_cpufreq_data *, +const struct tegra_cpufreq_config **); +} tegra_init_funcs[] = { + {"nvidia,tegra20" , tegra20_cpufreq_init }, +}; + +static int tegra_cpufreq_probe (struct platform_device *pdev)...
Quoted 14 lines
drivers/cpufreq/tegra-cpufreq.c static struct cpufreq_driver tegra_cpufreq_driver = { · line 135
Quoted 11 lines
drivers/cpufreq/tegra-cpufreq.c +10
-0+for (i =0 ; i <ARRAY_SIZE (tegra_init_funcs); i++) { +if (of_machine_is_compatible (tegra_init_funcs[i].compat)) { + ret = tegra_init_funcs[i].init (tegra_data, &soc_config); +if (!ret) +break ; +else + goto out; + } } +if (i ==ARRAY_SIZE (tegra_init_funcs)) + goto out;I think there are better ways of doing this than open-coding it. Perhaps
of_match_device()or the platform-driver equivalent could be made to work?
Open coding is everywhere in OF helper functions actually. I doubt if we can use of_match_device() if we're not adding node in DT. If we're matching the platform device then we might need open coding, no?
Quoted 11 lines
drivers/cpufreq/tegra-cpufreq.c static struct cpufreq_driver tegra_cpufreq_driver = { · line 173
Quoted 10 lines
drivers/cpufreq/tegra-cpufreq.c +7
-0+int __init tegra_cpufreq_init (void ) +{ +struct platform_device_info devinfo = { .name ="tegra-cpufreq" , }; + +platform_device_register_full (&devinfo); + +return 0 ; }EXPORT_SYMBOL (tegra_cpufreq_init);
Quoted 7 lines
Perhaps instead of hard-coding the name "tegra-cpufreq" here, you could dynamically construct the device name based on the DT's root compatible value, register "${root_compatible}-cpufreq", e.g. "nvidia,tegra20-cpufreq" or "nvidia,tegra30-cpufreq". That would allow the kernel's standard device/driver matching mechanism to pick the correct driver to instantiate. Perhaps you could even dynamically register an OF device so that you can use
of_match_device()in probe, if
I guess what you meant dynamically register an OF device is registering an fake OF device by calling of_device_add(), no? If yes then what of_node should we give?
Quoted 2 lines
there's some advantage of having a single driver that supports N chips.
Re: [PATCH v3 2/2] cpufreq: tegra: Re-model Tegra cpufreq driver
Quoted 31 lines · bilhuang
Quoted 23 lines · Stephen Warren
Quoted 13 lines · Bill Huang
Re-model Tegra cpufreq driver to support all Tegra series of SoCs.
* Make
tegra-cpufreq.ca generic Tegra cpufreq driver.
* Move Tegra20 specific codes intotegra20-cpufreq.c.
* Bind Tegra cpufreq dirver with a fake device so defer probe would work when we're going to get regulator in the driver to support voltage scaling (DVFS).drivers/cpufreq/tegra-cpufreq.c +0
-0@@ -91,14 +40,10 @@ static int tegra_update_cpu_speed(struct cpufreq_policy *policy,...
drivers/cpufreq/tegra-cpufreq.c static int tegra_update_cpu_speed(struct cpufreq_policy *policy, · line 49
Quoted 7 lines
drivers/cpufreq/tegra-cpufreq.c +4
-0+if (soc_config->vote_emc_on_cpu_rate) + soc_config->vote_emc_on_cpu_rate (rate); + + ret = soc_config->cpu_clk_set_rate (rate *1000 );if (ret)pr_err ("cpu-tegra: Failed to set cpu frequency to %lu kHz\n" , rate);Quoted 6 lines
Is there any/much shared code left in this file after this patch? It seems like all this file does now is make each cpufreq callback function call
soc_config->the_same_function_name(). If so, wouldn't it be better to simply implement completely separate tegar20-cpufreq and tegra30-cpufreq drivers, and register them each directly with the cpufreq core, to avoid this file doing all the indirection?
Quoted 2 lines
I think this file is needed since we can shared the registration and probe logic for different SoCs.
But there's basically nothing in probe() already, and if we have a separate driver for each SoC, then there's even less code; just a call to devm_kzalloc() for the device-specific data (which will be SoC-specific in size anyway), and a call to cpufreq_register_driver(). I don't think it's worth sharing that if it means that every other function needs to be an indirect function call.
Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
drivers/cpufreq/tegra-cpufreq.c +9
-1-int __init tegra_cpufreq_init (void ) +static struct { +char *compat; +int (*init)(struct tegra_cpufreq_data *, +const struct tegra_cpufreq_config **); +} tegra_init_funcs[] = { + {"nvidia,tegra20" , tegra20_cpufreq_init }, +}; + +static int tegra_cpufreq_probe (struct platform_device *pdev)...
Quoted 11 lines
drivers/cpufreq/tegra-cpufreq.c +10
-0+for (i =0 ; i <ARRAY_SIZE (tegra_init_funcs); i++) { +if (of_machine_is_compatible (tegra_init_funcs[i].compat)) { + ret = tegra_init_funcs[i].init (tegra_data, &soc_config); +if (!ret) +break ; +else + goto out; + } } +if (i ==ARRAY_SIZE (tegra_init_funcs)) + goto out;
Quoted 7 lines
Quoted 3 lines
I think there are better ways of doing this than open-coding it. Perhaps
of_match_device()or the platform-driver equivalent could be made to work?Open coding is everywhere in OF helper functions actually. I doubt if we can use
of_match_device()if we're not adding node in DT.
If we're matching the platform device then we might need open coding, no?
For platform devices, you can set up the id_table of struct platform_driver, and then simply call platform_get_device_id(pdev) inside probe() to find the matching entry. drivers/i2c/busses/i2c-at91.c is an example of how this works (just some random driver I found using grep).
Quoted 18 lines
Quoted 10 lines
drivers/cpufreq/tegra-cpufreq.c static struct cpufreq_driver tegra_cpufreq_driver = { · line 173
Quoted 9 lines
drivers/cpufreq/tegra-cpufreq.c +7
-0+int __init tegra_cpufreq_init (void ) +{ +struct platform_device_info devinfo = { .name ="tegra-cpufreq" , }; + +platform_device_register_full (&devinfo); + +return 0 ; }EXPORT_SYMBOL (tegra_cpufreq_init);Quoted 7 lines
Perhaps instead of hard-coding the name "tegra-cpufreq" here, you could dynamically construct the device name based on the DT's root compatible value, register "${root_compatible}-cpufreq", e.g. "nvidia,tegra20-cpufreq" or "nvidia,tegra30-cpufreq". That would allow the kernel's standard device/driver matching mechanism to pick the correct driver to instantiate. Perhaps you could even dynamically register an OF device so that you can use
of_match_device()in probe, if
Quoted 3 lines
I guess what you meant dynamically register an OF device is registering an fake OF device by calling
of_device_add(), no? If yes then whatof_nodeshould we give?
Yes. Good question about which node. I guess the root node would be the only one that made any sense at all, and admittedly it doesn't make a huge amount of sense. Perhaps registers a platform device rather than an OF device would make more sense. See platform_device_register() I think.
Re: [PATCH v3 2/2] cpufreq: tegra: Re-model Tegra cpufreq driver
Quoted 35 lines · Stephen Warren
Quoted 31 lines · bilhuang
Quoted 23 lines · Stephen Warren
Quoted 13 lines · Bill Huang
Re-model Tegra cpufreq driver to support all Tegra series of SoCs.
* Make
tegra-cpufreq.ca generic Tegra cpufreq driver.
* Move Tegra20 specific codes intotegra20-cpufreq.c.
* Bind Tegra cpufreq dirver with a fake device so defer probe would work when we're going to get regulator in the driver to support voltage scaling (DVFS).drivers/cpufreq/tegra-cpufreq.c +0
-0@@ -91,14 +40,10 @@ static int tegra_update_cpu_speed(struct cpufreq_policy *policy,...
drivers/cpufreq/tegra-cpufreq.c static int tegra_update_cpu_speed(struct cpufreq_policy *policy, · line 49
Quoted 7 lines
drivers/cpufreq/tegra-cpufreq.c +4
-0+if (soc_config->vote_emc_on_cpu_rate) + soc_config->vote_emc_on_cpu_rate (rate); + + ret = soc_config->cpu_clk_set_rate (rate *1000 );if (ret)pr_err ("cpu-tegra: Failed to set cpu frequency to %lu kHz\n" , rate);Quoted 6 lines
Is there any/much shared code left in this file after this patch? It seems like all this file does now is make each cpufreq callback function call
soc_config->the_same_function_name(). If so, wouldn't it be better to simply implement completely separate tegar20-cpufreq and tegra30-cpufreq drivers, and register them each directly with the cpufreq core, to avoid this file doing all the indirection?Quoted 2 lines
I think this file is needed since we can shared the registration and probe logic for different SoCs.
Quoted 6 lines
But there's basically nothing in
probe()already, and if we have a separate driver for each SoC, then there's even less code; just a call todevm_kzalloc()for the device-specific data (which will be SoC-specific in size anyway), and a call tocpufreq_register_driver(). I don't think it's worth sharing that if it means that every other function needs to be an indirect function call.
OK that makes sense.
Quoted 32 lines
Quoted 24 lines
Quoted 24 lines
Quoted 11 lines
drivers/cpufreq/tegra-cpufreq.c +9
-1-int __init tegra_cpufreq_init (void ) +static struct { +char *compat; +int (*init)(struct tegra_cpufreq_data *, +const struct tegra_cpufreq_config **); +} tegra_init_funcs[] = { + {"nvidia,tegra20" , tegra20_cpufreq_init }, +}; + +static int tegra_cpufreq_probe (struct platform_device *pdev)...
Quoted 11 lines
drivers/cpufreq/tegra-cpufreq.c +10
-0+for (i =0 ; i <ARRAY_SIZE (tegra_init_funcs); i++) { +if (of_machine_is_compatible (tegra_init_funcs[i].compat)) { + ret = tegra_init_funcs[i].init (tegra_data, &soc_config); +if (!ret) +break ; +else + goto out; + } } +if (i ==ARRAY_SIZE (tegra_init_funcs)) + goto out;Quoted 7 lines
Quoted 3 lines
I think there are better ways of doing this than open-coding it. Perhaps
of_match_device()or the platform-driver equivalent could be made to work?Open coding is everywhere in OF helper functions actually. I doubt if we can use
of_match_device()if we're not adding node in DT.
If we're matching the platform device then we might need open coding, no?
Quoted 5 lines
For platform devices, you can set up the
id_tableof structplatform_driver, and then simply callplatform_get_device_id(pdev)insideprobe()to find the matching entry.drivers/i2c/busses/i2c-at91.cis an example of how this works (just some random driver I found using grep).
If we're going to have separate driver for each SoC, then we don't need platform_get_device_id(pdev) stuffs...
What I would like to do is creating platform cpufreq device with name "${root_compatible}-cpufreq" then each SoC cpufreq driver can bind to it, but the question is, which file is the best place to do this? Create a new file for this or use existing file like arch/arm/mach-tegra/tegra.c?
Quoted 28 lines
Quoted 19 lines
Quoted 11 lines
drivers/cpufreq/tegra-cpufreq.c static struct cpufreq_driver tegra_cpufreq_driver = { · line 173
Quoted 10 lines
drivers/cpufreq/tegra-cpufreq.c +7
-0+int __init tegra_cpufreq_init (void ) +{ +struct platform_device_info devinfo = { .name ="tegra-cpufreq" , }; + +platform_device_register_full (&devinfo); + +return 0 ; }EXPORT_SYMBOL (tegra_cpufreq_init);Quoted 7 lines
Perhaps instead of hard-coding the name "tegra-cpufreq" here, you could dynamically construct the device name based on the DT's root compatible value, register "${root_compatible}-cpufreq", e.g. "nvidia,tegra20-cpufreq" or "nvidia,tegra30-cpufreq". That would allow the kernel's standard device/driver matching mechanism to pick the correct driver to instantiate. Perhaps you could even dynamically register an OF device so that you can use
of_match_device()in probe, ifQuoted 3 lines
I guess what you meant dynamically register an OF device is registering an fake OF device by calling
of_device_add(), no? If yes then whatof_nodeshould we give?Yes. Good question about which node. I guess the root node would be the only one that made any sense at all, and admittedly it doesn't make a huge amount of sense. Perhaps registers a platform device rather than an OF device would make more sense. See
platform_device_register()I think.
Re: [PATCH v3 2/2] cpufreq: tegra: Re-model Tegra cpufreq driver
Quoted 80 lines · bilhuang
Quoted 38 lines · Stephen Warren
Quoted 34 lines · bilhuang
Quoted 25 lines · Stephen Warren
Quoted 14 lines · Bill Huang
Re-model Tegra cpufreq driver to support all Tegra series of SoCs.
* Make
tegra-cpufreq.ca generic Tegra cpufreq driver.
* Move Tegra20 specific codes intotegra20-cpufreq.c.
* Bind Tegra cpufreq dirver with a fake device so defer probe would work
when we're going to get regulator in the driver to support voltage scaling (DVFS).drivers/cpufreq/tegra-cpufreq.c +0
-0@@ -91,14 +40,10 @@ static int tegra_update_cpu_speed(struct cpufreq_policy *policy,...
Quoted 8 lines
drivers/cpufreq/tegra-cpufreq.c +4
-0+if (soc_config->vote_emc_on_cpu_rate) + soc_config->vote_emc_on_cpu_rate (rate); + + ret = soc_config->cpu_clk_set_rate (rate *1000 );if (ret) pr_err("cpu-tegra: Failed to set cpu frequency to %lukHz\n",
rate);Quoted 7 lines
Is there any/much shared code left in this file after this patch? It seems like all this file does now is make each cpufreq callback function
callsoc_config->the_same_function_name(). If so, wouldn't it be better to simply implement completely separate tegar20-cpufreq and tegra30-cpufreq drivers, and register them each directly with the cpufreq core, to avoid this file doing all the indirection?Quoted 2 lines
I think this file is needed since we can shared the registration and probe logic for different SoCs.
Quoted 6 lines
But there's basically nothing in
probe()already, and if we have a separate driver for each SoC, then there's even less code; just a call todevm_kzalloc()for the device-specific data (which will be SoC-specific in size anyway), and a call tocpufreq_register_driver(). I don't think it's worth sharing that if it means that every other function needs to be an indirect function call.OK that makes sense.
Quoted 34 lines
Quoted 33 lines
Quoted 24 lines
Quoted 11 lines
drivers/cpufreq/tegra-cpufreq.c +9
-1-int __init tegra_cpufreq_init (void ) +static struct { +char *compat; +int (*init)(struct tegra_cpufreq_data *, +const struct tegra_cpufreq_config **); +} tegra_init_funcs[] = { + {"nvidia,tegra20" , tegra20_cpufreq_init }, +}; + +static int tegra_cpufreq_probe (struct platform_device *pdev)...
drivers/cpufreq/tegra-cpufreq.c static struct cpufreq_driver tegra_cpufreq_driver = { · line 135
Quoted 11 lines
drivers/cpufreq/tegra-cpufreq.c +10
-0+for (i =0 ; i <ARRAY_SIZE (tegra_init_funcs); i++) { +if (of_machine_is_compatible (tegra_init_funcs[i].compat)) { + ret = tegra_init_funcs[i].init (tegra_data, &soc_config); +if (!ret) +break ; +else + goto out; + } } +if (i ==ARRAY_SIZE (tegra_init_funcs)) + goto out;Quoted 4 lines
I think there are better ways of doing this than open-coding it. Perhaps
of_match_device()or the platform-driver equivalent could be made to work?Open coding is everywhere in OF helper functions actually. I doubt if we can use
of_match_device()if we're not adding node in DT.
If we're matching the platform device then we might need open coding, no?
Quoted 8 lines
Quoted 5 lines
For platform devices, you can set up the
id_tableof structplatform_driver, and then simply callplatform_get_device_id(pdev)insideprobe()to find the matching entry.drivers/i2c/busses/i2c-at91.cis an example of how this works (just some random driver I found using grep).If we're going to have separate driver for each SoC, then we don't need
platform_get_device_id(pdev)stuffs...
True.
Quoted 4 lines
What I would like to do is creating platform cpufreq device with name "${root_compatible}-cpufreq" then each SoC cpufreq driver can bind to it, but the question is, which file is the best place to do this? Create a new file for this or use existing file like
arch/arm/mach-tegra/tegra.c?
I think create the device in drivers/cpufreq/cpufreq-tegra.c:tegra_cpufreq_init() (which is possibly all that file would contain), and call that function from arch/arm/mach-tegra/tegra.c. That way, we'll be able to share the implementation of tegra_cpufreq_init() with any ARMv8 CPUs that might appear.
Viresh Kumar
maintainerRe: [PATCH v3 2/2] cpufreq: tegra: Re-model Tegra cpufreq driver
In reply to Bill HuangQuoted 7 lines · Bill Huang
Re-model Tegra cpufreq driver to support all Tegra series of SoCs.
* Make
tegra-cpufreq.ca generic Tegra cpufreq driver.
* Move Tegra20 specific codes intotegra20-cpufreq.c.
* Bind Tegra cpufreq dirver with a fake device so defer probe would work when we're going to get regulator in the driver to support voltage scaling (DVFS).
I strongly feel we must reuse cpufreq-cpu0 driver here after adding a clk/regulator driver for tegra to support all that.
@Stephen: If you want we can keep all that tegra specific stuff (clk/regulator) integra-cpufreq.c, but we can easily use cpufreq-cpu0 driver without much complications..
I have tried it earlier, got some comments and then got busy in other stuff..
https://lkml.org/lkml/2013/8/7/364
drivers/cpufreq/tegra-cpufreq.c static int tegra_cpu_init(struct cpufreq_policy *policy) · line 83
Quoted 5 lines
static int
tegra_cpu_exit(struct cpufreq_policy *policy){drivers/cpufreq/tegra-cpufreq.c +1
-2-clk_disable_unprepare (cpu_clk); -clk_disable_unprepare (emc_clk); +cpufreq_frequency_table_cpuinfo (policy, tegra_data->freq_table);
Btw, why do you need this here?
Re: [PATCH v3 2/2] cpufreq: tegra: Re-model Tegra cpufreq driver
Quoted 11 lines · Viresh Kumar
Quoted 7 lines · Bill Huang
Re-model Tegra cpufreq driver to support all Tegra series of SoCs.
* Make
tegra-cpufreq.ca generic Tegra cpufreq driver.
* Move Tegra20 specific codes intotegra20-cpufreq.c.
* Bind Tegra cpufreq dirver with a fake device so defer probe would work when we're going to get regulator in the driver to support voltage scaling (DVFS).I strongly feel we must reuse cpufreq-cpu0 driver here after adding a clk/regulator driver for tegra to support all that.
Tegra20 DVFS is a little bit complicated due to the fact that we can't scale VDD_CPU directly, there are constraints or relationship to other power rails so I don't think it is a good idea to use generic cpufreq-cpu0 driver if we're going to support voltage scaling.
Quoted 9 lines
@Stephen: If you want we can keep all that tegra specific stuff (clk/regulator) in
tegra-cpufreq.c, but we can easily use cpufreq-cpu0 driver without much complications..I have tried it earlier, got some comments and then got busy in other stuff..
https://lkml.org/lkml/2013/8/7/364
Quoted 8 lines
drivers/cpufreq/tegra-cpufreq.c static int tegra_cpu_init(struct cpufreq_policy *policy) · line 83
Quoted 5 lines
static int tegra_cpu_exit(struct cpufreq_policy *policy) {drivers/cpufreq/tegra-cpufreq.c +1
-2-clk_disable_unprepare (cpu_clk); -clk_disable_unprepare (emc_clk); +cpufreq_frequency_table_cpuinfo (policy, tegra_data->freq_table);Btw, why do you need this here?
Actually the latest version is v4 which is quite different against v3.
Viresh Kumar
maintainerRe: [PATCH v3 2/2] cpufreq: tegra: Re-model Tegra cpufreq driver
Quoted 4 lines · bilhuang
Tegra20 DVFS is a little bit complicated due to the fact that we can't scale
VDD_CPUdirectly, there are constraints or relationship to other power rails so I don't think it is a good idea to use generic cpufreq-cpu0 driver if we're going to support voltage scaling.
But why can't we handle that in a CPU specific regulator code?
Re: [PATCH v3 2/2] cpufreq: tegra: Re-model Tegra cpufreq driver
Quoted 8 lines · Viresh Kumar
Quoted 4 lines · bilhuang
Tegra20 DVFS is a little bit complicated due to the fact that we can't scale
VDD_CPUdirectly, there are constraints or relationship to other power rails so I don't think it is a good idea to use generic cpufreq-cpu0 driver if we're going to support voltage scaling.But why can't we handle that in a CPU specific regulator code?
cpufreq-cpu0 driver will call regulator_set_voltage_tol() directly according to the pre-defined OPP freq/volt pairs, the regulator drivers could be shared by other SoC so is not suitable to handle this, or do I misunderstand?
Viresh Kumar
maintainerRe: [PATCH v3 2/2] cpufreq: tegra: Re-model Tegra cpufreq driver
Quoted 4 lines · bilhuang
cpufreq-cpu0 driver will call
regulator_set_voltage_tol()directly according to the pre-defined OPP freq/volt pairs, the regulator drivers could be shared by other SoC so is not suitable to handle this, or do I misunderstand?
In case regulator's driver is shared, then you can probably add another virtual regulator for CPU which would have the special code you want.
Re: [PATCH v3 2/2] cpufreq: tegra: Re-model Tegra cpufreq driver
Quoted 9 lines · Viresh Kumar
Quoted 4 lines · bilhuang
cpufreq-cpu0 driver will call
regulator_set_voltage_tol()directly according to the pre-defined OPP freq/volt pairs, the regulator drivers could be shared by other SoC so is not suitable to handle this, or do I misunderstand?In case regulator's driver is shared, then you can probably add another virtual regulator for CPU which would have the special code you want.
I'm not sure virtual regulator for CPU is a good idea, in addition to that, we don't have a single SoC OPP table, we need several which are speedo-id and process-id dependant, but generic cpufreq-cpu0 is assuming there is only one statically, for some SoC the frequency table is not fixed, they are created at runtime combining our fast and slow CPU frequency table and dvfs table. So I'm really not sure is it worth adding so many tweaks in order to use the generic cpufreq-cpu0 driver.
Viresh Kumar
maintainerRe: [PATCH v3 2/2] cpufreq: tegra: Re-model Tegra cpufreq driver
Quoted 4 lines · bilhuang
I'm not sure virtual regulator for CPU is a good idea, in addition to that, we don't have a single SoC OPP table, we need several which are speedo-id and process-id dependant, but generic cpufreq-cpu0 is assuming there is only one statically
Can't that be handled via DT ?
Quoted 4 lines
for some SoC the frequency table is not fixed, they are
created at runtime combining our fast and slow CPU frequency table and dvfs table. So I'm really not sure is it worth adding so many tweaks in order to use the generic cpufreq-cpu0 driver.
Hmm, maybe I got confused because I don't have a clear picture in my mind. It might be better to go ahead with your implementation for now and after everything is set, we can choose to use cpufreq-cpu0 if it is worth it.
--
viresh
Re: [PATCH v3 2/2] cpufreq: tegra: Re-model Tegra cpufreq driver
Quoted 7 lines · Viresh Kumar
Quoted 4 lines · bilhuang
I'm not sure virtual regulator for CPU is a good idea, in addition to that, we don't have a single SoC OPP table, we need several which are speedo-id and process-id dependant, but generic cpufreq-cpu0 is assuming there is only one statically
Can't that be handled via DT ?
I don't think it can be handled via DT unless we separate DTB according to different CPU speedo/process-id but that is not a good idea.
Quoted 10 lines
Quoted 5 lines
for some SoC the frequency table is not fixed, they are
created at runtime combining our fast and slow CPU frequency table and dvfs table. So I'm really not sure is it worth adding so many tweaks in order to use the generic cpufreq-cpu0 driver.Hmm, maybe I got confused because I don't have a clear picture in my mind. It might be better to go ahead with your implementation for now and after everything is set, we can choose to use cpufreq-cpu0 if it is worth it.
This makes more sense to me, thanks.
Quoted 3 lines
--
viresh
Viresh Kumar
maintainerQuoted 9 lines · Bill Huang
This patch series remodel Tegra cpufreq driver to make it more easy to add new SoC support, in addition to that, adding probe function in the driver to let probe defer can be used to control init sequence when we are going to support DVFS.
Changes since v2:
- Fix
Kconfig.
- Rebase on top of branch 'cpufreq-next' ongit://git.linaro.org/people/vireshk/linux.git.
That's wrong base.. This branch is used only for Rafael to pull in stuff and so it doesn't
get updated everyday..
You must rebase on Rafael's linux-next branch all the time.
Quoted 8 lines · Viresh Kumar
Quoted 7 lines · Bill Huang
This patch series remodel Tegra cpufreq driver to make it more easy to add new SoC support, in addition to that, adding probe function in the driver to let probe defer can be used to control init sequence when we are going to support DVFS.
Changes since v2:
Quoted 9 lines
Quoted 2 lines
- Fix
Kconfig.
- Rebase on top of branch 'cpufreq-next' ongit://git.linaro.org/people/vireshk/linux.git.That's wrong base.. This branch is used only for Rafael to pull in stuff and so it doesn't
get updated everyday..You must rebase on Rafael's linux-next branch all the time.
OK thanks, is it branch pm-cpufreq?
Viresh Kumar
maintainerQuoted 1 line · bilhuang
OK thanks, is it branch pm-cpufreq?
Rebase on linux-next..