Kirkwoode cpufreq driver
Subsystems (5)
Andrew Lunn
maintainerv2 cover Kirkwoode cpufreq driver
This patchset adds a cpufreq driver for Marvell Kirkwood SoCs.
The changes to kirkwood_defconfig enable it and set the default governor to ondemand.
Changes since v1:
tabify Kconfig.arm entry
Sort order of include files
Remove some unnecassary include files Reformat multiline comment to be coding style conform.
Andrew Lunn (3):
cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
arm: kirkwood: Instantiate cpufreq driver
arm: kirkwood: Enable cpufreq and ondemand on kirkwood_defconfig
arch/arm/Kconfig | 1 + arch/arm/configs/kirkwood_defconfig | 3 + arch/arm/mach-kirkwood/board-dt.c | 3 +- arch/arm/mach-kirkwood/common.c | 23 ++ arch/arm/mach-kirkwood/common.h | 2 + arch/arm/mach-kirkwood/include/mach/bridge-regs.h | 2 + drivers/clk/mvebu/clk-gating-ctrl.c | 1 + drivers/cpufreq/Kconfig.arm | 6 + drivers/cpufreq/Makefile | 1 + drivers/cpufreq/kirkwood-cpufreq.c | 271 +++++++++++++++++++++ 10 files changed, 312 insertions(+), 1 deletion(-) create mode 100644 drivers/cpufreq/kirkwood-cpufreq.c
Signature · 1 line
1.7.10.4
Andrew Lunn
maintainerPATCH v2 1/3 cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
The Marvell Kirkwood SoCs have simple cpufreq support in hardware. The CPU can either use the a high speed cpu clock, or the slower DDR clock. Add a driver to swap between these two clock sources.
--- drivers/clk/mvebu/clk-gating-ctrl.c | 1 + drivers/cpufreq/Kconfig.arm | 6 + drivers/cpufreq/Makefile | 1 + drivers/cpufreq/kirkwood-cpufreq.c | 271 +++++++++++++++++++++++++++++++++++ 4 files changed, 279 insertions(+) create mode 100644 drivers/cpufreq/kirkwood-cpufreq.c
drivers/clk/mvebu/clk-gating-ctrl.c +1 -0
@@ -193,6 +193,7 @@ static const struct mvebu_soc_descr __initconst kirkwood_gating_descr[] = { { "runit", NULL, 7 }, { "xor0", NULL, 8 }, { "audio", NULL, 9 }, + { "powersave", "cpuclk", 11 }, { "sata0", NULL, 14 }, { "sata1", NULL, 15 }, { "xor1", NULL, 16 },
drivers/cpufreq/Kconfig.arm +6 -0
@@ -77,6 +77,12 @@ config ARM_EXYNOS5250_CPUFREQ This adds the CPUFreq driver for Samsung EXYNOS5250 SoC. +config ARM_KIRKWOOD_CPUFREQ + def_bool ARCH_KIRKWOOD && OF + help + This adds the CPUFreq driver for Marvell Kirkwood + SoCs. + config ARM_SPEAR_CPUFREQ bool "SPEAr CPUFreq support" depends on PLAT_SPEAR
drivers/cpufreq/Makefile +1 -0
@@ -50,6 +50,7 @@ obj-$(CONFIG_ARM_EXYNOS_CPUFREQ) += exynos-cpufreq.o obj-$(CONFIG_ARM_EXYNOS4210_CPUFREQ) += exynos4210-cpufreq.o obj-$(CONFIG_ARM_EXYNOS4X12_CPUFREQ) += exynos4x12-cpufreq.o obj-$(CONFIG_ARM_EXYNOS5250_CPUFREQ) += exynos5250-cpufreq.o +obj-$(CONFIG_ARM_KIRKWOOD_CPUFREQ) += kirkwood-cpufreq.o obj-$(CONFIG_ARM_OMAP2PLUS_CPUFREQ) += omap-cpufreq.o obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
drivers/cpufreq/kirkwood-cpufreq.c new file +271 -0
271 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Viresh Kumar
maintainerRe: [PATCH v2 1/3] cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
Hi Andrew,
Few more comments from my side :(
Quoted 4 lines · Andrew Lunn
drivers/cpufreq/kirkwood-cpufreq.c +3
-0+#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/clk.h>
drivers/cpufreq/kirkwood-cpufreq.c line 24
Quoted 10 lines
drivers/cpufreq/kirkwood-cpufreq.c +10
-0+#include <linux/cpufreq.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/io.h> +#include <asm/proc-fns.h> + +#define CPU_SW_INT_BLK BIT(28) + + +#include <linux/clk-private.h>
Any specific reason for keeping it together with other #includes?
drivers/cpufreq/kirkwood-cpufreq.c line 62
Quoted 3 lines
drivers/cpufreq/kirkwood-cpufreq.c +3
-0+static void kirkwood_cpufreq_set_cpu_state (unsigned int index) +{ +
Can remove extra blank line.
drivers/cpufreq/kirkwood-cpufreq.c line 84
Quoted 7 lines
drivers/cpufreq/kirkwood-cpufreq.c +7
-0+if (freqs.old != freqs.new) { +local_irq_disable (); + +/* Disable interrupts to the CPU */ + reg =readl_relaxed (priv.base); + reg |=CPU_SW_INT_BLK ; +writel (reg, priv.base);
Any specific reason for calling writel() instead of writel_relaxed()? relaxed one would take less time and would be much more efficient.
same for all other writel's too.
drivers/cpufreq/kirkwood-cpufreq.c line 112
Quoted 5 lines
drivers/cpufreq/kirkwood-cpufreq.c +5
-0+}; + +static int kirkwood_cpufreq_verify (struct cpufreq_policy *policy) +{ +return cpufreq_frequency_table_verify (policy, &kirkwood_freq_table[0 ]);
return cpufreq_frequency_table_verify(policy, kirkwood_freq_table); ??
drivers/cpufreq/kirkwood-cpufreq.c line 125
Quoted 13 lines
drivers/cpufreq/kirkwood-cpufreq.c +13
-0+} + +static int kirkwood_cpufreq_target (struct cpufreq_policy *policy, +unsigned int target_freq, +unsigned int relation) +{ +unsigned int index =0 ; + +if (cpufreq_frequency_table_target (policy, kirkwood_freq_table, + target_freq, relation, &index)) +return -EINVAL ; + +kirkwood_cpufreq_set_cpu_state (index);
This routine does have error cases, like: wrong value of "state" variable, so returning int from it might make sense. Though i believe state can't be anything else then STATE_CPU_FREQ or STATE_DDR_FREQ. In which case, switch must be modified?
drivers/cpufreq/kirkwood-cpufreq.c line 132
Quoted 6 lines
drivers/cpufreq/kirkwood-cpufreq.c +6
-0+return 0 ; +} + +/* +* Module init and exit code +*/
Can be converted to a single line comment if you want. :)
drivers/cpufreq/kirkwood-cpufreq.c line 154
Quoted 5 lines
drivers/cpufreq/kirkwood-cpufreq.c +5
-0+static int kirkwood_cpufreq_cpu_exit (struct cpufreq_policy *policy) +{ +cpufreq_frequency_table_put_attr (policy->cpu); +return 0 ; +}
Hmm.. Exit is normally called in two cases. Either cpufreq driver is unregistered
or cpu is removed. In that case i am not sure if this routine makes sense? As we have a uniprocessor SoC here.
@Rafael?
drivers/cpufreq/kirkwood-cpufreq.c line 161
Quoted 6 lines
drivers/cpufreq/kirkwood-cpufreq.c +6
-0+static struct freq_attr *kirkwood_cpufreq_attr[] = { + &cpufreq_freq_attr_scaling_available_freqs, +NULL , +}; + +
Can remove extra blank line.
Andrew Lunn
maintainerRe: [PATCH v2 1/3] cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
Quoted 3 lines · Viresh Kumar
Hi Andrew,
Few more comments from my side :(
No problems...
Quoted 10 lines · Andrew Lunn
Quoted 8 lines
drivers/cpufreq/kirkwood-cpufreq.c +7
-0+#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/clk.h> +#include <linux/cpufreq.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/io.h>
Quoted 8 lines
drivers/cpufreq/kirkwood-cpufreq.c line 24
Quoted 6 lines
drivers/cpufreq/kirkwood-cpufreq.c +6
-0+#include <asm/proc-fns.h> + +#define CPU_SW_INT_BLK BIT(28) + + +#include <linux/clk-private.h> Any specific reason for keeping it together with other #includes?
Ah, yes, there is a good reason. I added this in for debugging purposes. I needed to look inside the clk cookie, which required this include file. But because it was for debug only, to be removed later, i kept it separate, easier to find and remove. I just forgot to remove it :-(
Quoted 15 lines
Quoted 15 lines
drivers/cpufreq/kirkwood-cpufreq.c +15
-0+if (freqs.old != freqs.new) { +local_irq_disable (); + +/* Disable interrupts to the CPU */ + reg =readl_relaxed (priv.base); + reg |=CPU_SW_INT_BLK ; +writel (reg, priv.base); +static int kirkwood_cpufreq_target (struct cpufreq_policy *policy, +unsigned int target_freq, +unsigned int relation) +{ +unsigned int index =0 ; + +if (cpufreq_frequency_table_target (policy, kirkwood_freq_table, + target_freq, relation, &index))
Quoted 8 lines
drivers/cpufreq/kirkwood-cpufreq.c line 125
Quoted 3 lines
drivers/cpufreq/kirkwood-cpufreq.c +3
-0+return -EINVAL ; + +kirkwood_cpufreq_set_cpu_state (index);This routine does have error cases, like: wrong value of "state" variable, so returning int from it might make sense. Though i believe state can't be anything else then
STATE_CPU_FREQorSTATE_DDR_FREQ. In which case, switch must be modified?
As you say, state cannot be anything else that the two expected values. I've just been taught that switch statements should always have a default clause. I also thought that a BUG() is too strong, no need to kill the machine. It is better to spam the kernel log so it gets noticed. I can swap to a WARN_ON(1). I don't really think this is an error that needs to be reported back to the framework. Its an implementation problem, not a runtime problem. So i would prefer to keep to void.
Quoted 10 lines
drivers/cpufreq/kirkwood-cpufreq.c line 154
Quoted 5 lines
drivers/cpufreq/kirkwood-cpufreq.c +5
-0+static int kirkwood_cpufreq_cpu_exit (struct cpufreq_policy *policy) +{ +cpufreq_frequency_table_put_attr (policy->cpu); +return 0 ; +}Hmm.. Exit is normally called in two cases. Either cpufreq driver is unregistered
or cpu is removed. In that case i am not sure if this routine makes sense? As we have a uniprocessor SoC here.
The current Kconfig entry does not allow it to be compiled as a module. But the code does allow for it. With the current trend of making the ARM kernel multiplatform, its likely that cpufreq drivers will become modular so that only the appropriate driver gets loaded in a multiplatform kernel. The question then becomes, is it O.K. not being able to unload the module?
Andrew
Viresh Kumar
maintainerRe: [PATCH v2 1/3] cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
Quoted 9 lines · Andrew Lunn
Quoted 6 lines · Viresh Kumar
Quoted 1 line
+
kirkwood_cpufreq_set_cpu_state(index);This routine does have error cases, like: wrong value of "state" variable, so returning int from it might make sense. Though i believe state can't be anything else then
STATE_CPU_FREQorSTATE_DDR_FREQ. In which case, switch must be modified?
Quoted 8 lines
As you say, state cannot be anything else that the two expected values. I've just been taught that switch statements should always have a default clause. I also thought that a
BUG()is too strong, no need to kill the machine. It is better to spam the kernel log so it gets noticed. I can swap to aWARN_ON(1). I don't really think this is an error that needs to be reported back to the framework. Its an implementation problem, not a runtime problem. So i would prefer to keep to void.
Hmm. What i meant to say was, you just need an if,else instead of switch and you really don't have to take care of anything else than these two values. As that can't happen. Even the WARN_ON(). Its useless. Just believe on what is returned from cpufreq_frequency_table_target(). You really don't need to validate index returned from it, but only the return value (which you are already doing)
Quoted 11 lines
Quoted 10 lines
drivers/cpufreq/kirkwood-cpufreq.c line 154
Quoted 5 lines
drivers/cpufreq/kirkwood-cpufreq.c new file +5
-0+static int kirkwood_cpufreq_cpu_exit (struct cpufreq_policy *policy) +{ +cpufreq_frequency_table_put_attr (policy->cpu); +return 0 ; +}Hmm.. Exit is normally called in two cases. Either cpufreq driver is unregistered
or cpu is removed. In that case i am not sure if this routine makes sense? As we have a uniprocessor SoC here.
Quoted 6 lines
The current
Kconfigentry does not allow it to be compiled as a module. But the code does allow for it. With the current trend of making the ARM kernel multiplatform, its likely that cpufreq drivers will become modular so that only the appropriate driver gets loaded in a multiplatform kernel. The question then becomes, is it O.K. not being able to unload the module?
You got me wrong. What i wanted to say is, even if you have it as module and "rmmod" it, then also calling this routine wouldn't make any difference.
Then i went into the code to see the effect. So, this will set freq_table for a cpu as NULL which will be returned by calling cpufreq_frequency_get_table(). And i now feel we must have this routine because once cpufreq driver isn't there for a cpu, we must not return any table for it. :)
Andrew Lunn
maintainerPATCH v2 2/3 arm: kirkwood: Instantiate cpufreq driver
In reply to Andrew LunnRegister a platform driver structure for the cpufreq driver.
--- arch/arm/Kconfig | 1 + arch/arm/mach-kirkwood/board-dt.c | 3 ++- arch/arm/mach-kirkwood/common.c | 23 +++++++++++++++++++++ arch/arm/mach-kirkwood/common.h | 2 ++ arch/arm/mach-kirkwood/include/mach/bridge-regs.h | 2 ++ 5 files changed, 30 insertions(+), 1 deletion(-)
arch/arm/Kconfig +1 -0
@@ -543,6 +543,7 @@ config ARCH_DOVE config ARCH_KIRKWOOD bool "Marvell Kirkwood" + select ARCH_HAS_CPUFREQ select ARCH_REQUIRE_GPIOLIB select CPU_FEROCEON select GENERIC_CLOCKEVENTS
arch/arm/mach-kirkwood/board-dt.c +2 -1
@@ -70,7 +70,6 @@ static void __init kirkwood_legacy_clk_init(void) clkspec.args[0 ] =CGC_BIT_SDIO ;orion_clkdev_add (NULL ,"mvsdio" ,of_clk_get_from_provider (&clkspec)); - }static void __init kirkwood_of_clk_init (void )
@@ -95,6 +94,8 @@ static void __init kirkwood_dt_init(void)kirkwood_l2_init (); +kirkwood_cpufreq_init (); +/* Setup root of clk tree */ kirkwood_of_clk_init ();
arch/arm/mach-kirkwood/common.c +23 -0
@@ -584,6 +584,29 @@ void __init kirkwood_audio_init(void) }/***************************************************************************** +* CPU Frequency +****************************************************************************/ +static struct resource kirkwood_cpufreq_resources[] = { + [0 ] = { + .start =CPU_CONTROL_PHYS , + .end =CPU_CONTROL_PHYS +3 , + .flags =IORESOURCE_MEM , + }, +}; + +static struct platform_device kirkwood_cpufreq_device = { + .name ="kirkwood-cpufreq" , + .id =-1 , + .num_resources =ARRAY_SIZE (kirkwood_cpufreq_resources), + .resource = kirkwood_cpufreq_resources, +}; + +void __init kirkwood_cpufreq_init (void ) +{ +platform_device_register (&kirkwood_cpufreq_device); +} + +/***************************************************************************** * General ****************************************************************************/ /*
arch/arm/mach-kirkwood/common.h +2 -0
@@ -50,6 +50,8 @@ void kirkwood_nand_init(struct mtd_partition *parts, int nr_parts, int delay);void kirkwood_nand_init_rnb (struct mtd_partition *parts,int nr_parts,int (*dev_ready)(struct mtd_info *));void kirkwood_audio_init (void ); +void kirkwood_cpufreq_init (void ); +void kirkwood_restart (char ,const char *);void kirkwood_clk_init (void );
arch/arm/mach-kirkwood/include/mach/bridge-regs.h +2 -0
@@ -17,6 +17,7 @@#define CPU_CONFIG_ERROR_PROP 0x00000004#define CPU_CONTROL (BRIDGE_VIRT_BASE + 0x0104) +#define CPU_CONTROL_PHYS (BRIDGE_PHYS_BASE + 0x0104)#define CPU_RESET 0x00000002#define RSTOUTn_MASK (BRIDGE_VIRT_BASE + 0x0108)
@@ -69,6 +70,7 @@#define CGC_RUNIT (1 << 7)#define CGC_XOR0 (1 << 8)#define CGC_AUDIO (1 << 9) +#define CGC_POWERSAVE (1 << 11)#define CGC_SATA0 (1 << 14)#define CGC_SATA1 (1 << 15)#define CGC_XOR1 (1 << 16)
Signature · 1 line
1.7.10.4
Andrew Lunn
maintainerPATCH v2 3/3 arm: kirkwood: Enable cpufreq and ondemand on kirkwood_defconfig
In reply to Andrew LunnNow that we have a cpufreq driver for kirkwood, enable it in kirkwood_defconfig and set the default governer to ondemand.
--- arch/arm/configs/kirkwood_defconfig | 3 +++ 1 file changed, 3 insertions(+)
arch/arm/configs/kirkwood_defconfig +3 -0
@@ -55,6 +55,9 @@ CONFIG_AEABI=y # CONFIG_OABI_COMPAT is not set CONFIG_ZBOOT_ROM_TEXT=0x0 CONFIG_ZBOOT_ROM_BSS=0x0 +CONFIG_CPU_FREQ=y +CONFIG_CPU_FREQ_STAT_DETAILS=y +CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y CONFIG_CPU_IDLE=y CONFIG_NET=y CONFIG_PACKET=y
Signature · 1 line
1.7.10.4
Quoted 12 lines · Andrew Lunn
This patchset adds a cpufreq driver for Marvell Kirkwood SoCs.
The changes to
kirkwood_defconfigenable it and set the default governor to ondemand.Changes since v1:
tabify
Kconfig.armentry
Sort order of include files
Remove some unnecassary include files Reformat multiline comment to be coding style conform.
Quoted 4 lines
Andrew Lunn (3):
cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
arm: kirkwood: Instantiate cpufreq driver
arm: kirkwood: Enable cpufreq and ondemand onkirkwood_defconfig
If you want me to take this, it'll need some ACKs from the clk people and arm-soc maintainers at least.
An ACK from Viresh would be welcome too.
Thanks,
Rafael
Quoted 14 lines
arch/arm/Kconfig | 1 + arch/arm/configs/kirkwood_defconfig | 3 + arch/arm/mach-kirkwood/board-dt.c | 3 +- arch/arm/mach-kirkwood/common.c | 23 ++ arch/arm/mach-kirkwood/common.h | 2 + arch/arm/mach-kirkwood/include/mach/bridge-regs.h | 2 + drivers/clk/mvebu/clk-gating-ctrl.c | 1 + drivers/cpufreq/Kconfig.arm | 6 + drivers/cpufreq/Makefile | 1 + drivers/cpufreq/kirkwood-cpufreq.c | 271 +++++++++++++++++++++ 10 files changed, 312 insertions(+), 1 deletion(-) create mode 100644 drivers/cpufreq/kirkwood-cpufreq.c
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Jason Cooper
Acked-byQuoted 13 lines · Rafael J. Wysocki
Quoted 12 lines · Andrew Lunn
This patchset adds a cpufreq driver for Marvell Kirkwood SoCs.
The changes to
kirkwood_defconfigenable it and set the default governor to ondemand.Changes since v1:
tabify
Kconfig.armentry
Sort order of include files
Remove some unnecassary include files Reformat multiline comment to be coding style conform.
Quoted 7 lines
Quoted 4 lines
Andrew Lunn (3):
cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
arm: kirkwood: Instantiate cpufreq driver
arm: kirkwood: Enable cpufreq and ondemand onkirkwood_defconfigIf you want me to take this, it'll need some ACKs from the clk people and arm-soc maintainers at least.
In the past, we've sent the driver changes (patch #1) through the appropriate driver maintainer's tree, and the subsequent patches (2 & 3) through arm-soc with a listed dependency on the driver maintainer's tree/branch. We've found that causes the fewest conflicts/headaches that way.
If you're Ok with that, just let me know which tree and branch you pull it in to.
Quoted 1 line
An ACK from Viresh would be welcome too.
fwiw:
thx,
Jason.
Quoted 22 lines · Jason Cooper
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 lines · Andrew Lunn
This patchset adds a cpufreq driver for Marvell Kirkwood SoCs.
The changes to
kirkwood_defconfigenable it and set the default governor to ondemand.Changes since v1:
tabify
Kconfig.armentry
Sort order of include files
Remove some unnecassary include files Reformat multiline comment to be coding style conform.Quoted 7 lines
Quoted 4 lines
Andrew Lunn (3):
cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
arm: kirkwood: Instantiate cpufreq driver
arm: kirkwood: Enable cpufreq and ondemand onkirkwood_defconfigIf you want me to take this, it'll need some ACKs from the clk people and arm-soc maintainers at least.
Quoted 8 lines
In the past, we've sent the driver changes (patch #1) through the appropriate driver maintainer's tree, and the subsequent patches (2 & 3) through arm-soc with a listed dependency on the driver maintainer's tree/branch. We've found that causes the fewest conflicts/headaches that way.
If you're Ok with that, just let me know which tree and branch you pull it in to.
Yes, that would be fine by me. In the future, though, please say in the comment part of the changelog (i.e. between the sign-off tag and the actual patch) who's the target maintainer of the patch.
When patch [1/3] is ready, it will be applied to the pm-cpufreq branch of the linux-pm.git tree (that branch doesn't contain any new material at the moment, because I'm having issues with one of the candidate commits and I'm debugging them).
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.