Kirkwoode cpufreq driver
Subsystems (6)
Andrew Lunn
maintainerv5 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 v4:
Add DT cpus/cpu@0 node with needed clocks.
Add documentation of this DT node.
Changes since v3:
Check return value of of_find_compatible_node() Return -EADDRNOTAVAIL when devm_request_and_ioremap() fails. Remove default: clause.
Made .name consistent.
Changes since v2:
Remove unneeded #include file left over from debugging. WARN_ON(1) instead of dev_err() for unexpected state Various blank lines removed.
Reformat comment.
writel -> writel_relaxed
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
Documentation/devicetree/bindings/arm/kirkwood.txt | 27 ++ arch/arm/Kconfig | 1 + arch/arm/boot/dts/kirkwood.dtsi | 13 + 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 | 259 ++++++++++++++++++++ 12 files changed, 340 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/arm/kirkwood.txt create mode 100644 drivers/cpufreq/kirkwood-cpufreq.c
Signature · 1 line
1.7.10.4
Andrew Lunn
maintainerPATCH v5 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.
--- Documentation/devicetree/bindings/arm/kirkwood.txt | 27 ++ drivers/clk/mvebu/clk-gating-ctrl.c | 1 + drivers/cpufreq/Kconfig.arm | 6 + drivers/cpufreq/Makefile | 1 + drivers/cpufreq/kirkwood-cpufreq.c | 259 ++++++++++++++++++++ 5 files changed, 294 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/kirkwood.txt create mode 100644 drivers/cpufreq/kirkwood-cpufreq.c
Documentation/devicetree/bindings/arm/kirkwood.txt new file +27 -0
@@ -0,0 +1,27 @@ +Marvell Kirkwood Platforms Device Tree Bindings +----------------------------------------------- + +Boards with a SoC of the Marvell Kirkwood +shall have the following property: + +Required root node property: + +compatible: must contain "marvell,kirkwood"; + +In order to support the kirkwood cpufreq driver, there must be a node +cpus/cpu@0 with three clocks, "cpu_clk", "ddrclk" and "powersave", +where the "powersave" clock is a gating clock used to switch the CPU +between the "cpu_clk" and the "ddrclk". + +Example: + + cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu@0 { + device_type = "cpu"; + compatible = "marvell,sheeva-88SV131"; + clocks = <&core_clk 1>, <&core_clk 3>, <&gate_clk 11>; + clock-names = "cpu_clk", "ddrclk", "powersave"; + };
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 +259 -0
259 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v5 1/3] cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
Quoted 6 lines · Andrew Lunn
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.
Signed-off-by Andrew Lunn <[email protected]>Acked-by Jason Cooper <[email protected]>
This has been ACKed by Viresh already IIRC, right?
Rafael
Quoted 350 lines
--- Documentation/devicetree/bindings/arm/kirkwood.txt | 27 ++ drivers/clk/mvebu/clk-gating-ctrl.c | 1 + drivers/cpufreq/Kconfig.arm | 6 + drivers/cpufreq/Makefile | 1 + drivers/cpufreq/kirkwood-cpufreq.c | 259 ++++++++++++++++++++ 5 files changed, 294 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/kirkwood.txt create mode 100644 drivers/cpufreq/kirkwood-cpufreq.cDocumentation/devicetree/bindings/arm/kirkwood.txt new file +27
-0@@ -0,0 +1,27 @@ +Marvell Kirkwood Platforms Device Tree Bindings +----------------------------------------------- + +Boards with a SoC of the Marvell Kirkwood +shall have the following property: + +Required root node property: + +compatible: must contain "marvell,kirkwood"; + +In order to support the kirkwood cpufreq driver, there must be a node +cpus/cpu@0 with three clocks, "cpu_clk", "ddrclk" and "powersave", +where the "powersave" clock is a gating clock used to switch the CPU +between the "cpu_clk" and the "ddrclk". + +Example: + + cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu@0 { + device_type = "cpu"; + compatible = "marvell,sheeva-88SV131"; + clocks = <&core_clk 1>, <&core_clk 3>, <&gate_clk 11>; + clock-names = "cpu_clk", "ddrclk", "powersave"; + };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_SPEARdrivers/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.odrivers/cpufreq/kirkwood-cpufreq.c new file +259
-0@@ -0,0 +1,259 @@ +/* +* kirkwood_freq.c: cpufreq driver for the Marvell kirkwood +* +* Copyright (C) 2013 Andrew Lunn <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/clk.h> +#include <linux/clk-provider.h> +#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) + +static struct priv +{ +struct clk *cpu_clk; +struct clk *ddr_clk; +struct clk *powersave_clk; +struct device *dev; +void __iomem *base; +} priv; + +#define STATE_CPU_FREQ 0x01 +#define STATE_DDR_FREQ 0x02 + +/* +* Kirkwood can swap the clock to the CPU between two clocks: +* +* - cpu clk +* - ddr clk +* +* The frequencies are set at runtime before registering this * +* table. +*/ +static struct cpufreq_frequency_table kirkwood_freq_table[] = { + {STATE_CPU_FREQ ,0 },/* CPU uses cpuclk */ + {STATE_DDR_FREQ ,0 },/* CPU uses ddrclk */ + {0 ,CPUFREQ_TABLE_END }, +}; + +static unsigned int kirkwood_cpufreq_get_cpu_frequency (unsigned int cpu) +{ +if (__clk_is_enabled (priv.powersave_clk)) +return kirkwood_freq_table[1 ].frequency; +return kirkwood_freq_table[0 ].frequency; +} + +static void kirkwood_cpufreq_set_cpu_state (unsigned int index) +{ +struct cpufreq_freqs freqs; +unsigned int state = kirkwood_freq_table[index].index; +unsigned long reg; + + freqs.old =kirkwood_cpufreq_get_cpu_frequency (0 ); + freqs.new = kirkwood_freq_table[index].frequency; + freqs.cpu =0 ;/* Kirkwood is UP */ + +cpufreq_notify_transition (&freqs,CPUFREQ_PRECHANGE ); + +dev_dbg (priv.dev,"Attempting to set frequency to %i KHz\n" , + kirkwood_freq_table[index].frequency); +dev_dbg (priv.dev,"old frequency was %i KHz\n" , +kirkwood_cpufreq_get_cpu_frequency (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_relaxed (reg, priv.base); + +switch (state) { +case STATE_CPU_FREQ : +clk_disable (priv.powersave_clk); +break ; +case STATE_DDR_FREQ : +clk_enable (priv.powersave_clk); +break ; + } + +/* Wait-for-Interrupt, while the hardware changes frequency */ +cpu_do_idle (); + +/* Enable interrupts to the CPU */ + reg =readl_relaxed (priv.base); + reg &= ~CPU_SW_INT_BLK ; +writel_relaxed (reg, priv.base); + +local_irq_enable (); + } +cpufreq_notify_transition (&freqs,CPUFREQ_POSTCHANGE ); +}; + +static int kirkwood_cpufreq_verify (struct cpufreq_policy *policy) +{ +return cpufreq_frequency_table_verify (policy, kirkwood_freq_table); +} + +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); + +return 0 ; +} + +/* Module init and exit code */ +static int kirkwood_cpufreq_cpu_init (struct cpufreq_policy *policy) +{ +int result; + +/* cpuinfo and default policy values */ + policy->cpuinfo.transition_latency =5000 ;/* 5uS */ + policy->cur =kirkwood_cpufreq_get_cpu_frequency (0 ); + + result =cpufreq_frequency_table_cpuinfo (policy, kirkwood_freq_table); +if (result) +return result; + +cpufreq_frequency_table_get_attr (kirkwood_freq_table, policy->cpu); + +return 0 ; +} + +static int kirkwood_cpufreq_cpu_exit (struct cpufreq_policy *policy) +{ +cpufreq_frequency_table_put_attr (policy->cpu); +return 0 ; +} + +static struct freq_attr *kirkwood_cpufreq_attr[] = { + &cpufreq_freq_attr_scaling_available_freqs, +NULL , +}; + +static struct cpufreq_driver kirkwood_cpufreq_driver = { + .get = kirkwood_cpufreq_get_cpu_frequency, + .verify = kirkwood_cpufreq_verify, + .target = kirkwood_cpufreq_target, + .init = kirkwood_cpufreq_cpu_init, + .exit = kirkwood_cpufreq_cpu_exit, + .name ="kirkwood-cpufreq" , + .owner =THIS_MODULE , + .attr = kirkwood_cpufreq_attr, +}; + +static int kirkwood_cpufreq_probe (struct platform_device *pdev) +{ +struct device_node *np; +struct resource *res; +int err; + + priv.dev = &pdev->dev; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"Cannot get memory resource\n" ); +return -ENODEV ; + } + priv.base =devm_request_and_ioremap (&pdev->dev, res); +if (!priv.base) { +dev_err (&pdev->dev,"Cannot ioremap\n" ); +return -EADDRNOTAVAIL ; + } + + np =of_find_node_by_path ("/cpus/cpu@0" ); +if (!np) +return -ENODEV ; + + priv.cpu_clk =of_clk_get_by_name (np,"cpu_clk" ); +if (IS_ERR (priv.cpu_clk)) { +dev_err (priv.dev,"Unable to get cpuclk" ); +return PTR_ERR (priv.cpu_clk); + } + +clk_prepare_enable (priv.cpu_clk); + kirkwood_freq_table[0 ].frequency =clk_get_rate (priv.cpu_clk) /1000 ; + + priv.ddr_clk =of_clk_get_by_name (np,"ddrclk" ); +if (IS_ERR (priv.ddr_clk)) { +dev_err (priv.dev,"Unable to get ddrclk" ); + err =PTR_ERR (priv.ddr_clk); + goto out_cpu; + } + +clk_prepare_enable (priv.ddr_clk); + kirkwood_freq_table[1 ].frequency =clk_get_rate (priv.ddr_clk) /1000 ; + + priv.powersave_clk =of_clk_get_by_name (np,"powersave" ); +if (IS_ERR (priv.powersave_clk)) { +dev_err (priv.dev,"Unable to get powersave" ); + err =PTR_ERR (priv.powersave_clk); + goto out_ddr; + } +clk_prepare (priv.powersave_clk); + +of_node_put (np); + np =NULL ; + + err =cpufreq_register_driver (&kirkwood_cpufreq_driver); +if (!err) +return 0 ; + +dev_err (priv.dev,"Failed to register cpufreq driver" ); + +clk_disable_unprepare (priv.powersave_clk); +out_ddr: +clk_disable_unprepare (priv.ddr_clk); +out_cpu: +clk_disable_unprepare (priv.cpu_clk); +of_node_put (np); + +return err; +} + +static int kirkwood_cpufreq_remove (struct platform_device *pdev) +{ +cpufreq_unregister_driver (&kirkwood_cpufreq_driver); + +clk_disable_unprepare (priv.powersave_clk); +clk_disable_unprepare (priv.ddr_clk); +clk_disable_unprepare (priv.cpu_clk); + +return 0 ; +} + +static struct platform_driver kirkwood_cpufreq_platform_driver = { + .probe = kirkwood_cpufreq_probe, + .remove = kirkwood_cpufreq_remove, + .driver = { + .name ="kirkwood-cpufreq" , + .owner =THIS_MODULE , + }, +}; + +module_platform_driver (kirkwood_cpufreq_platform_driver); + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("Andrew Lunn <[email protected]" ); +MODULE_DESCRIPTION ("cpufreq driver for Marvell's kirkwood CPU" ); +MODULE_ALIAS ("platform:kirkwood-cpufreq" );
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Viresh Kumar
maintainerRe: [PATCH v5 1/3] cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
Quoted 9 lines · Rafael J. Wysocki
Quoted 6 lines · Andrew Lunn
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.
Signed-off-by Andrew Lunn <[email protected]>Acked-by Jason Cooper <[email protected]>This has been ACKed by Viresh already IIRC, right?
Yes.
Andrew Lunn
maintainerRe: [PATCH v5 1/3] cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
In reply to Rafael J. WysockiQuoted 9 lines · Rafael J. Wysocki
Quoted 6 lines · Andrew Lunn
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.
Signed-off-by Andrew Lunn <[email protected]>Acked-by Jason Cooper <[email protected]>This has been ACKed by Viresh already IIRC, right?
Yes, it has. Also the ARM parts have been asked by Jason Cooper.
However, the changes to the clocks are not that small....
Andrew
Re: [PATCH v5 1/3] cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
In reply to Andrew Lunndrivers/cpufreq/kirkwood-cpufreq.c line 15
Quoted 4 lines · Andrew Lunn
drivers/cpufreq/kirkwood-cpufreq.c new file +4
-0+#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/clk.h> +#include <linux/clk-provider.h>
Again, why do you need this header? It's supposed to only be included by clock drivers who provide clocks.
Quoted 5 lines
drivers/cpufreq/kirkwood-cpufreq.c new file +5
-0+#include <linux/cpufreq.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/io.h> +#include <asm/proc-fns.h>
...
Quoted 12 lines
drivers/cpufreq/kirkwood-cpufreq.c new file +12
-0+static int kirkwood_cpufreq_probe (struct platform_device *pdev) +{ +struct device_node *np; +struct resource *res; +int err; + + priv.dev = &pdev->dev; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"Cannot get memory resource\n" ); +return -ENODEV ;
drivers/cpufreq/kirkwood-cpufreq.c line 186
Quoted 10 lines
drivers/cpufreq/kirkwood-cpufreq.c new file +10
-0+ } + priv.base =devm_request_and_ioremap (&pdev->dev, res); +if (!priv.base) { +dev_err (&pdev->dev,"Cannot ioremap\n" ); +return -EADDRNOTAVAIL ; + } + + np =of_find_node_by_path ("/cpus/cpu@0" ); +if (!np) +return -ENODEV ;
pdev->dev.of_node = np;
Review
Quoted 2 lines
(quoted diff) +2
-0+ + priv.cpu_clk = of_clk_get_by_name(np, "cpu_clk");
Then, devm_clk_get(pdev->dev, "cpu_clk") should just work for you. You are really hating to use devm_clk_get()?
Shawn
Quoted 4 lines
drivers/cpufreq/kirkwood-cpufreq.c new file +4
-0+if (IS_ERR (priv.cpu_clk)) { +dev_err (priv.dev,"Unable to get cpuclk" ); +return PTR_ERR (priv.cpu_clk); + }
Andrew Lunn
maintainerRe: [PATCH v5 1/3] cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
Quoted 8 lines · Shawn Guo
drivers/cpufreq/kirkwood-cpufreq.c line 15
Quoted 4 lines · Andrew Lunn
drivers/cpufreq/kirkwood-cpufreq.c new file +4
-0+#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/clk.h> +#include <linux/clk-provider.h> Again, why do you need this header? It's supposed to only be included by clock drivers who provide clocks.
I already answered this a few times....
http://permalink.gmane.org/gmane.linux.kernel.cpufreq/9008
http://permalink.gmane.org/gmane.linux.kernel.cpufreq/9011
Quoted 25 lines
Quoted 12 lines
drivers/cpufreq/kirkwood-cpufreq.c new file +12
-0+static int kirkwood_cpufreq_probe (struct platform_device *pdev) +{ +struct device_node *np; +struct resource *res; +int err; + + priv.dev = &pdev->dev; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"Cannot get memory resource\n" ); +return -ENODEV ;drivers/cpufreq/kirkwood-cpufreq.c line 186
Quoted 10 lines
drivers/cpufreq/kirkwood-cpufreq.c new file +10
-0+ } + priv.base =devm_request_and_ioremap (&pdev->dev, res); +if (!priv.base) { +dev_err (&pdev->dev,"Cannot ioremap\n" ); +return -EADDRNOTAVAIL ; + } + + np =of_find_node_by_path ("/cpus/cpu@0" ); +if (!np) +return -ENODEV ;pdev->dev.of_node = np;
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + priv.cpu_clk = of_clk_get_by_name(np, "cpu_clk");Then,
devm_clk_get(pdev->dev, "cpu_clk")should just work for you. You are really hating to usedevm_clk_get()?
What i don't like is it gives the idea the driver is using its own DT node. Its not, the driver does not have a node in the tree, it is using some other node from within the tree. What assumptions are made about pdev->dev.of_node? e.g. of_find_device_by_node() would now return this driver if somebody was to lookup the cpu@0 node. You could imaging in the future a thermal driver using this node, a voltage scaling driver, etc.
What other uses are there of dev.of_node and do they make sense when it points to some random node in the tree?
Andrew
Re: [PATCH v5 1/3] cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
Quoted 10 lines · Andrew Lunn
Quoted 8 lines · Shawn Guo
drivers/cpufreq/kirkwood-cpufreq.c line 15
Quoted 4 lines · Andrew Lunn
drivers/cpufreq/kirkwood-cpufreq.c new file +4
-0+#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/clk.h> +#include <linux/clk-provider.h> Again, why do you need this header? It's supposed to only be included by clock drivers who provide clocks.
Quoted 5 lines
I already answered this a few times....
http://permalink.gmane.org/gmane.linux.kernel.cpufreq/9008
http://permalink.gmane.org/gmane.linux.kernel.cpufreq/9011
Sorry, I missed those. Well, it's clearly a layering violation to clk subsystem.
Quoted 31 lines
Quoted 25 lines
Quoted 12 lines
drivers/cpufreq/kirkwood-cpufreq.c new file +12
-0+static int kirkwood_cpufreq_probe (struct platform_device *pdev) +{ +struct device_node *np; +struct resource *res; +int err; + + priv.dev = &pdev->dev; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"Cannot get memory resource\n" ); +return -ENODEV ;drivers/cpufreq/kirkwood-cpufreq.c line 186
Quoted 10 lines
drivers/cpufreq/kirkwood-cpufreq.c new file +10
-0+ } + priv.base =devm_request_and_ioremap (&pdev->dev, res); +if (!priv.base) { +dev_err (&pdev->dev,"Cannot ioremap\n" ); +return -EADDRNOTAVAIL ; + } + + np =of_find_node_by_path ("/cpus/cpu@0" ); +if (!np) +return -ENODEV ;pdev->dev.of_node = np;Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + priv.cpu_clk = of_clk_get_by_name(np, "cpu_clk");Then,
devm_clk_get(pdev->dev, "cpu_clk")should just work for you. You are really hating to usedevm_clk_get()?
Quoted 8 lines
What i don't like is it gives the idea the driver is using its own DT node. Its not, the driver does not have a node in the tree, it is using some other node from within the tree. What assumptions are made about
pdev->dev.of_node? e.g.of_find_device_by_node()would now return this driver if somebody was to lookup the cpu@0 node. You could imaging in the future a thermal driver using this node, a voltage scaling driver, etc.
Well, we are just manipulating pdev->dev.of_node to get resources from device tree with standard API (unified between DT and non-DT), and we can even set it back to NULL when we're done here.
But I shut up my mouth now, since you seem strongly against that.
Shawn
Re: [PATCH v5 1/3] cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
In reply to Andrew LunnHi,
I have just a small problem with this.
Quoted 24 lines · Andrew Lunn
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.
Signed-off-by Andrew Lunn <[email protected]>Acked-by Jason Cooper <[email protected]>--- Documentation/devicetree/bindings/arm/kirkwood.txt | 27 ++ drivers/clk/mvebu/clk-gating-ctrl.c | 1 + drivers/cpufreq/Kconfig.arm | 6 + drivers/cpufreq/Makefile | 1 + drivers/cpufreq/kirkwood-cpufreq.c | 259 ++++++++++++++++++++ 5 files changed, 294 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/kirkwood.txt create mode 100644 drivers/cpufreq/kirkwood-cpufreq.cDocumentation/devicetree/bindings/arm/kirkwood.txt new file +2
-0@@ -0,0 +1,27 @@ +Marvell Kirkwood Platforms Device Tree Bindings +-----------------------------------------------
Documentation/devicetree/bindings/arm/kirkwood.txt line 12
Quoted 10 lines
Documentation/devicetree/bindings/arm/kirkwood.txt new file +10
-0+ +Boards with a SoC of the Marvell Kirkwood +shall have the following property: + +Required root node property: + +compatible: must contain "marvell,kirkwood"; + +In order to support the kirkwood cpufreq driver, there must be a node +cpus/cpu@0 with three clocks, "cpu_clk", "ddrclk" and "powersave",
Devicetree unit-addresses are meant to correspond to the node's reg property.
As the cpu does not have an MPIDR, and thus the node has no reg (by the general arm cpu binding), this should just be /cpus/cpu.
Quoted 238 lines
Documentation/devicetree/bindings/arm/kirkwood.txt new file +15
-0+where the "powersave" clock is a gating clock used to switch the CPU +between the "cpu_clk" and the "ddrclk". + +Example: + + cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu@0 { + device_type = "cpu"; + compatible = "marvell,sheeva-88SV131"; + clocks = <&core_clk 1>, <&core_clk 3>, <&gate_clk 11>; + clock-names = "cpu_clk", "ddrclk", "powersave"; + };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_SPEARdrivers/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.odrivers/cpufreq/kirkwood-cpufreq.c new file +176
-0@@ -0,0 +1,259 @@ +/* +* kirkwood_freq.c: cpufreq driver for the Marvell kirkwood +* +* Copyright (C) 2013 Andrew Lunn <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/clk.h> +#include <linux/clk-provider.h> +#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) + +static struct priv +{ +struct clk *cpu_clk; +struct clk *ddr_clk; +struct clk *powersave_clk; +struct device *dev; +void __iomem *base; +} priv; + +#define STATE_CPU_FREQ 0x01 +#define STATE_DDR_FREQ 0x02 + +/* +* Kirkwood can swap the clock to the CPU between two clocks: +* +* - cpu clk +* - ddr clk +* +* The frequencies are set at runtime before registering this * +* table. +*/ +static struct cpufreq_frequency_table kirkwood_freq_table[] = { + {STATE_CPU_FREQ ,0 },/* CPU uses cpuclk */ + {STATE_DDR_FREQ ,0 },/* CPU uses ddrclk */ + {0 ,CPUFREQ_TABLE_END }, +}; + +static unsigned int kirkwood_cpufreq_get_cpu_frequency (unsigned int cpu) +{ +if (__clk_is_enabled (priv.powersave_clk)) +return kirkwood_freq_table[1 ].frequency; +return kirkwood_freq_table[0 ].frequency; +} + +static void kirkwood_cpufreq_set_cpu_state (unsigned int index) +{ +struct cpufreq_freqs freqs; +unsigned int state = kirkwood_freq_table[index].index; +unsigned long reg; + + freqs.old =kirkwood_cpufreq_get_cpu_frequency (0 ); + freqs.new = kirkwood_freq_table[index].frequency; + freqs.cpu =0 ;/* Kirkwood is UP */ + +cpufreq_notify_transition (&freqs,CPUFREQ_PRECHANGE ); + +dev_dbg (priv.dev,"Attempting to set frequency to %i KHz\n" , + kirkwood_freq_table[index].frequency); +dev_dbg (priv.dev,"old frequency was %i KHz\n" , +kirkwood_cpufreq_get_cpu_frequency (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_relaxed (reg, priv.base); + +switch (state) { +case STATE_CPU_FREQ : +clk_disable (priv.powersave_clk); +break ; +case STATE_DDR_FREQ : +clk_enable (priv.powersave_clk); +break ; + } + +/* Wait-for-Interrupt, while the hardware changes frequency */ +cpu_do_idle (); + +/* Enable interrupts to the CPU */ + reg =readl_relaxed (priv.base); + reg &= ~CPU_SW_INT_BLK ; +writel_relaxed (reg, priv.base); + +local_irq_enable (); + } +cpufreq_notify_transition (&freqs,CPUFREQ_POSTCHANGE ); +}; + +static int kirkwood_cpufreq_verify (struct cpufreq_policy *policy) +{ +return cpufreq_frequency_table_verify (policy, kirkwood_freq_table); +} + +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); + +return 0 ; +} + +/* Module init and exit code */ +static int kirkwood_cpufreq_cpu_init (struct cpufreq_policy *policy) +{ +int result; + +/* cpuinfo and default policy values */ + policy->cpuinfo.transition_latency =5000 ;/* 5uS */ + policy->cur =kirkwood_cpufreq_get_cpu_frequency (0 ); + + result =cpufreq_frequency_table_cpuinfo (policy, kirkwood_freq_table); +if (result) +return result; + +cpufreq_frequency_table_get_attr (kirkwood_freq_table, policy->cpu); + +return 0 ; +} + +static int kirkwood_cpufreq_cpu_exit (struct cpufreq_policy *policy) +{ +cpufreq_frequency_table_put_attr (policy->cpu); +return 0 ; +} + +static struct freq_attr *kirkwood_cpufreq_attr[] = { + &cpufreq_freq_attr_scaling_available_freqs, +NULL , +}; + +static struct cpufreq_driver kirkwood_cpufreq_driver = { + .get = kirkwood_cpufreq_get_cpu_frequency, + .verify = kirkwood_cpufreq_verify, + .target = kirkwood_cpufreq_target, + .init = kirkwood_cpufreq_cpu_init, + .exit = kirkwood_cpufreq_cpu_exit, + .name ="kirkwood-cpufreq" , + .owner =THIS_MODULE , + .attr = kirkwood_cpufreq_attr, +}; + +static int kirkwood_cpufreq_probe (struct platform_device *pdev) +{ +struct device_node *np; +struct resource *res; +int err; + + priv.dev = &pdev->dev; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"Cannot get memory resource\n" ); +return -ENODEV ;
drivers/cpufreq/kirkwood-cpufreq.c line 186
Quoted 10 lines
drivers/cpufreq/kirkwood-cpufreq.c new file +10
-0+ } + priv.base =devm_request_and_ioremap (&pdev->dev, res); +if (!priv.base) { +dev_err (&pdev->dev,"Cannot ioremap\n" ); +return -EADDRNOTAVAIL ; + } + + np =of_find_node_by_path ("/cpus/cpu@0" ); +if (!np) +return -ENODEV ;
Thus this should grab "/cpus/cpu".
[...]
Thanks,
Mark.
Andrew Lunn
maintainerPATCH v5 2/3 arm: kirkwood: Instantiate cpufreq driver
In reply to Andrew LunnRegister a platform driver structure for the cpufreq driver. Add a DT binding for cpus/cpu@0 with the needed clocks.
--- arch/arm/Kconfig | 1 + arch/arm/boot/dts/kirkwood.dtsi | 13 ++++++++++++ arch/arm/mach-kirkwood/board-dt.c | 2 ++ arch/arm/mach-kirkwood/common.c | 23 +++++++++++++++++++++ arch/arm/mach-kirkwood/common.h | 2 ++ arch/arm/mach-kirkwood/include/mach/bridge-regs.h | 2 ++ 6 files changed, 43 insertions(+)
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/boot/dts/kirkwood.dtsi +13 -0
@@ -8,6 +8,19 @@ gpio0 = &gpio0; gpio1 = &gpio1; }; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu@0 { + device_type = "cpu"; + compatible = "marvell,sheeva-88SV131"; + clocks = <&core_clk 1>, <&core_clk 3>, <&gate_clk 11>; + clock-names = "cpu_clk", "ddrclk", "powersave"; + }; + }; + intc: interrupt-controller { compatible = "marvell,orion-intc", "marvell,intc"; interrupt-controller;
arch/arm/mach-kirkwood/board-dt.c +2 -0
@@ -95,6 +95,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
Re: [PATCH v5 2/3] arm: kirkwood: Instantiate cpufreq driver
Quoted 5 lines · Andrew Lunn
Register a platform driver structure for the cpufreq driver. Add a DT binding for cpus/cpu@0 with the needed clocks.
Signed-off-by Andrew Lunn <[email protected]>Acked-by Jason Cooper <[email protected]>
Quoted 8 lines
--- arch/arm/Kconfig | 1 + arch/arm/boot/dts/kirkwood.dtsi | 13 ++++++++++++ arch/arm/mach-kirkwood/board-dt.c | 2 ++ arch/arm/mach-kirkwood/common.c | 23 +++++++++++++++++++++ arch/arm/mach-kirkwood/common.h | 2 ++ arch/arm/mach-kirkwood/include/mach/bridge-regs.h | 2 ++ 6 files changed, 43 insertions(+)
Patches 2 and 3 applied to mvebu/dt_deps with depends on linux-pm/pm-cpufreq up to:
2a4bd9f cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs
thx,
Jason.
Andrew Lunn
maintainerPATCH v5 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