i.MX53 cpufreq support
Subsystems (7)
cover i.MX53 cpufreq support
This series implements cpufreq support for the i.MX53 SoC using the generic cpufreq-cpu0 driver. The design is based on feedback I got on the last round of patches.
Basically this implements a CPU clock type that abstracts away all the clock handling required for reprogramming the PLL feeding the CPU, so we don't have to worry about this in the cpufreq driver. For now this is only used on MX53, but looking forward the same approach (and code) could be used on MX6.
The first patch allows cpufreq-cpu0 to deactivate OPPs where the regulator isn't able to provide the required voltage. This has been tested on custom a MX53 board.
Lucas Stach (5):
cpufreq: cpu0: disable unsupported OPPs
clk: imx5: add step clock, used when reprogramming PLL1
clk: imx: add CPU clock type
arm: imx53: clk: add ARM clock
ARM: imx53: add cpufreq support
arch/arm/boot/dts/imx53.dtsi | 13 ++++- arch/arm/mach-imx/Makefile | 2 +- arch/arm/mach-imx/clk-cpu.c | 104 +++++++++++++++++++++++++++++++++ arch/arm/mach-imx/clk-imx51-imx53.c | 14 ++++- arch/arm/mach-imx/clk.h | 4 ++ arch/arm/mach-imx/mach-imx53.c | 4 ++ drivers/cpufreq/cpufreq-cpu0.c | 60 +++++++++++-------- include/dt-bindings/clock/imx5-clock.h | 5 +- 8 files changed, 179 insertions(+), 27 deletions(-) create mode 100644 arch/arm/mach-imx/clk-cpu.c
Signature · 1 line
2.1.0
PATCH 1/5 cpufreq: cpu0: disable unsupported OPPs
If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.
--- drivers/cpufreq/cpufreq-cpu0.c | 60 ++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 23 deletions(-)
drivers/cpufreq/cpufreq-cpu0.c +37 -23
@@ -117,6 +117,7 @@ static int cpu0_cpufreq_probe(struct platform_device *pdev) {struct device_node *np;int ret; +unsigned long opp_freq =0 , min_uV = ~0 , max_uV =0 , tol; cpu_dev =get_cpu_device (0 );if (!cpu_dev) {
@@ -155,42 +156,55 @@ static int cpu0_cpufreq_probe(struct platform_device *pdev)/* OPPs might be populated at runtime, don't check for error here */ of_init_opp_table (cpu_dev); - ret =dev_pm_opp_init_cpufreq_table (cpu_dev, &freq_table); -if (ret) { -pr_err ("failed to init cpufreq table: %d\n" , ret); - goto out_put_clk; - } -of_property_read_u32 (np,"voltage-tolerance" , &voltage_tolerance);if (of_property_read_u32 (np,"clock-latency" , &transition_latency)) transition_latency =CPUFREQ_ETERNAL ;if (!IS_ERR (cpu_reg)) { -struct dev_pm_opp *opp; -unsigned long min_uV, max_uV; -int i; -/* -* OPP is maintained in order of increasing frequency, and -* freq_table initialised from OPP is therefore sorted in the -* same order. +* Disable any OPPs where the connected regulator isn't able to +* provide the specified voltage and record minimum and maximum +* voltage levels. */ -for (i =0 ; freq_table[i].frequency !=CPUFREQ_TABLE_END ; i++) - ; -rcu_read_lock (); - opp =dev_pm_opp_find_freq_exact (cpu_dev, - freq_table[0 ].frequency *1000 , true); - min_uV =dev_pm_opp_get_voltage (opp); - opp =dev_pm_opp_find_freq_exact (cpu_dev, - freq_table[i-1 ].frequency *1000 , true); - max_uV =dev_pm_opp_get_voltage (opp); -rcu_read_unlock (); +while (1 ) { +struct dev_pm_opp *opp; +unsigned long opp_uV; + +rcu_read_lock (); + opp =dev_pm_opp_find_freq_ceil (cpu_dev, &opp_freq); +if (IS_ERR (opp)) { +rcu_read_unlock (); +break ; + } + opp_uV =dev_pm_opp_get_voltage (opp); +rcu_read_unlock (); + + tol = opp_uV * voltage_tolerance /100 ; +if (regulator_is_supported_voltage (cpu_reg, opp_uV, + opp_uV + tol)) { +if (opp_uV < min_uV) + min_uV = opp_uV; +if (opp_uV > max_uV) + max_uV = opp_uV; + }else { +dev_pm_opp_disable (cpu_dev, opp_freq); + } + + opp_freq++; + } + ret =regulator_set_voltage_time (cpu_reg, min_uV, max_uV);if (ret >0 ) transition_latency += ret *1000 ; } + ret =dev_pm_opp_init_cpufreq_table (cpu_dev, &freq_table); +if (ret) { +pr_err ("failed to init cpufreq table: %d\n" , ret); + goto out_put_clk; + } + ret =cpufreq_register_driver (&cpu0_cpufreq_driver);if (ret) {pr_err ("failed register driver: %d\n" , ret);
Signature · 1 line
2.1.0
Viresh Kumar
maintainerPATCH 1/5 cpufreq: cpu0: disable unsupported OPPs
Cc'ing Mark Brown to get his views on the idea.
Quoted 9 lines · Lucas Stach
If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.
Signed-off-by Lucas Stach <[email protected]>--- drivers/cpufreq/cpufreq-cpu0.c | 60 ++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 23 deletions(-)
And this file doesn't exist anymore (its renamed). Rebase over Rafael's linux-next branch for that.
PATCH 2/5 clk: imx5: add step clock, used when reprogramming PLL1
In reply to Lucas StachThis is the bypass clock used to feed the ARM partition while we reprogram PLL1 to another clock.
--- arch/arm/mach-imx/clk-imx51-imx53.c | 9 ++++++++- include/dt-bindings/clock/imx5-clock.h | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-)
arch/arm/mach-imx/clk-imx51-imx53.c +8 -1
@@ -125,6 +125,8 @@ static const char *mx53_spdif_xtal_sel[] = { "osc", "ckih", "ckih2", "pll4_sw",static const char *spdif_sel[] = {"pll1_sw" ,"pll2_sw" ,"pll3_sw" ,"spdif_xtal_sel" , };static const char *spdif0_com_sel[] = {"spdif0_podf" ,"ssi1_root_gate" , };static const char *mx51_spdif1_com_sel[] = {"spdif1_podf" ,"ssi2_root_gate" , }; +static const char *step_sels[] = {"lp_apm" , }; +static const char *cpu_podf_sels[] = {"pll1_sw" ,"step_sel" };static struct clk *clk[IMX5_CLK_END ];static struct clk_onecell_data clk_data;
@@ -193,7 +195,9 @@ static void __init mx5_clocks_common_init(void __iomem *ccm_base) clk[IMX5_CLK_USB_PHY_PODF ] =imx_clk_divider ("usb_phy_podf" ,"usb_phy_pred" ,MXC_CCM_CDCDR ,0 ,3 ); clk[IMX5_CLK_USB_PHY_SEL ] =imx_clk_mux ("usb_phy_sel" ,MXC_CCM_CSCMR1 ,26 ,1 , usb_phy_sel_str,ARRAY_SIZE (usb_phy_sel_str)); - clk[IMX5_CLK_CPU_PODF ] =imx_clk_divider ("cpu_podf" ,"pll1_sw" ,MXC_CCM_CACRR ,0 ,3 ); + clk[IMX5_CLK_STEP_SEL ] =imx_clk_mux ("step_sel" ,MXC_CCM_CCSR ,7 ,2 , step_sels,ARRAY_SIZE (step_sels)); + clk[IMX5_CLK_CPU_PODF_SEL ] =imx_clk_mux ("cpu_podf_sel" ,MXC_CCM_CCSR ,2 ,1 , cpu_podf_sels,ARRAY_SIZE (cpu_podf_sels)); + clk[IMX5_CLK_CPU_PODF ] =imx_clk_divider ("cpu_podf" ,"cpu_podf_sel" ,MXC_CCM_CACRR ,0 ,3 ); clk[IMX5_CLK_DI_PRED ] =imx_clk_divider ("di_pred" ,"pll3_sw" ,MXC_CCM_CDCDR ,6 ,3 ); clk[IMX5_CLK_IIM_GATE ] =imx_clk_gate2 ("iim_gate" ,"ipg" ,MXC_CCM_CCGR0 ,30 ); clk[IMX5_CLK_UART1_IPG_GATE ] =imx_clk_gate2 ("uart1_ipg_gate" ,"ipg" ,MXC_CCM_CCGR1 ,6 );
@@ -551,6 +555,9 @@ static void __init mx53_clocks_init(struct device_node *np)/* move can bus clk to 24MHz */ clk_set_parent (clk[IMX5_CLK_CAN_SEL ], clk[IMX5_CLK_LP_APM ]); +/* make sure step clock is running from 24MHz */ +clk_set_parent (clk[IMX5_CLK_STEP_SEL ], clk[IMX5_CLK_LP_APM ]); +clk_prepare_enable (clk[IMX5_CLK_IIM_GATE ]);imx_print_silicon_rev ("i.MX53" ,mx53_revision ());clk_disable_unprepare (clk[IMX5_CLK_IIM_GATE ]);
include/dt-bindings/clock/imx5-clock.h +3 -1
@@ -198,6 +198,8 @@#define IMX5_CLK_OCRAM 186#define IMX5_CLK_SAHARA_IPG_GATE 187#define IMX5_CLK_SATA_REF 188 -#define IMX5_CLK_END 189 +#define IMX5_CLK_STEP_SEL 189 +#define IMX5_CLK_CPU_PODF_SEL 190 +#define IMX5_CLK_END 191#endif /* __DT_BINDINGS_CLOCK_IMX5_H */
Signature · 1 line
2.1.0
PATCH 3/5 clk: imx: add CPU clock type
In reply to Lucas StachFrom: Lucas Stach <[email protected]>
This implements a virtual clock used to abstract away all the steps needed in order to change the ARM clock, so we don't have to push all this clock handling into the cpufreq driver.
While it will be used for i.MX53 at first it is generic enough to be used on i.MX6 later on.
--- arch/arm/mach-imx/Makefile | 2 +- arch/arm/mach-imx/clk-cpu.c | 104 ++++++++++++++++++++++++++++++++++++++++++++ arch/arm/mach-imx/clk.h | 4 ++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 arch/arm/mach-imx/clk-cpu.c
arch/arm/mach-imx/Makefile +1 -1
@@ -12,7 +12,7 @@ obj-$(CONFIG_SOC_IMX31) += mm-imx3.o cpu-imx31.o clk-imx31.o iomux-imx31.o ehci- obj-$(CONFIG_SOC_IMX35) += mm-imx3.o cpu-imx35.o clk-imx35.o ehci-imx35.o pm-imx3.o imx5-pm-$(CONFIG_PM) += pm-imx5.o -obj-$(CONFIG_SOC_IMX5) += cpu-imx5.o clk-imx51-imx53.o $(imx5-pm-y) +obj-$(CONFIG_SOC_IMX5) += cpu-imx5.o clk-imx51-imx53.o clk-cpu.o $(imx5-pm-y) obj-$(CONFIG_COMMON_CLK) += clk-pllv1.o clk-pllv2.o clk-pllv3.o clk-gate2.o \ clk-pfd.o clk-busy.o clk.o \
arch/arm/mach-imx/clk-cpu.c new file +104 -0
104 lines not on this page · raw message
arch/arm/mach-imx/clk.h +4 -0
@@ -128,4 +128,8 @@ static inline struct clk *imx_clk_fixed_factor(const char *name, CLK_SET_RATE_PARENT, mult, div); } +struct clk *imx_clk_cpu (const char *name,const char *parent_name, +struct clk *div,struct clk *mux,struct clk *pll, +struct clk *step); +#endif
Signature · 1 line
2.1.0
PATCH 3/5 clk: imx: add CPU clock type
Quoted 11 lines · Lucas Stach
From: Lucas Stach <[email protected]>
This implements a virtual clock used to abstract away all the steps needed in order to change the ARM clock, so we don't have to push all this clock handling into the cpufreq driver.
While it will be used for i.MX53 at first it is generic enough to be used on i.MX6 later on.
Signed-off-by Lucas Stach <[email protected]>
Is this intentional to use a different email address than your usual one?
Quoted 34 lines
--- arch/arm/mach-imx/Makefile | 2 +- arch/arm/mach-imx/clk-cpu.c | 104 ++++++++++++++++++++++++++++++++++++++++++++ arch/arm/mach-imx/clk.h | 4 ++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 arch/arm/mach-imx/clk-cpu.carch/arm/mach-imx/Makefile +1
-1@@ -12,7 +12,7 @@ obj-$(CONFIG_SOC_IMX31) += mm-imx3.o cpu-imx31.o clk-imx31.o iomux-imx31.o ehci- obj-$(CONFIG_SOC_IMX35) += mm-imx3.o cpu-imx35.o clk-imx35.o ehci-imx35.o pm-imx3.o imx5-pm-$(CONFIG_PM) += pm-imx5.o -obj-$(CONFIG_SOC_IMX5) += cpu-imx5.o clk-imx51-imx53.o $(imx5-pm-y) +obj-$(CONFIG_SOC_IMX5) += cpu-imx5.o clk-imx51-imx53.o clk-cpu.o $(imx5-pm-y) obj-$(CONFIG_COMMON_CLK) += clk-pllv1.o clk-pllv2.o clk-pllv3.o clk-gate2.o \ clk-pfd.o clk-busy.o clk.o \arch/arm/mach-imx/clk-cpu.c new file +8
-0@@ -0,0 +1,104 @@ +/* +* Copyright (c) 2014 Lucas Stach <[email protected]>, Pengutronix +* +* The code contained herein is licensed under the GNU General Public +* License. You may obtain a copy of the GNU General Public License +* Version 2 or later at the following locations: +* +* http://www.opensource.org/licenses/gpl-license.html
arch/arm/mach-imx/clk-cpu.c line 18
Quoted 10 lines
arch/arm/mach-imx/clk-cpu.c new file +10
-0+* http://www.gnu.org/copyleft/gpl.html +*/ + +#include <linux/clk.h> +#include <linux/clk-provider.h> +#include <linux/slab.h> + +struct clk_cpu { +struct clk_hw hw; +struct clk *div, *mux, *pll, *step;
This is personal taste, so I'm not strong on this. But I feel having them on multiple lines makes the later addition/removal of struct clk pointers a bit easier.
Other than these trivial comments, the patch looks good to me.
Shawn
Quoted 1 line
arch/arm/mach-imx/clk-cpu.c new file +1
-0+};
PATCH 3/5 clk: imx: add CPU clock type
Am Freitag, den 26.09.2014, 10:59 +0800 schrieb Shawn Guo:
Quoted 8 lines · Lucas Stach
Quoted 7 lines
From: Lucas Stach <[email protected]>
This implements a virtual clock used to abstract away all the steps needed in order to change the ARM clock, so we don't have to push all this clock handling into the cpufreq driver.
Quoted 7 lines
Quoted 4 lines
While it will be used for i.MX53 at first it is generic enough to be used on i.MX6 later on.
Signed-off-by Lucas Stach <[email protected]>Is this intentional to use a different email address than your usual one?
Urgh no. That's a remnant from starting this code at home without setting the proper git environment. Thanks for the hint.
Quoted 59 lines
Quoted 35 lines
--- arch/arm/mach-imx/Makefile | 2 +- arch/arm/mach-imx/clk-cpu.c | 104 ++++++++++++++++++++++++++++++++++++++++++++ arch/arm/mach-imx/clk.h | 4 ++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 arch/arm/mach-imx/clk-cpu.carch/arm/mach-imx/Makefile +1
-1@@ -12,7 +12,7 @@ obj-$(CONFIG_SOC_IMX31) += mm-imx3.o cpu-imx31.o clk-imx31.o iomux-imx31.o ehci- obj-$(CONFIG_SOC_IMX35) += mm-imx3.o cpu-imx35.o clk-imx35.o ehci-imx35.o pm-imx3.o imx5-pm-$(CONFIG_PM) += pm-imx5.o -obj-$(CONFIG_SOC_IMX5) += cpu-imx5.o clk-imx51-imx53.o $(imx5-pm-y) +obj-$(CONFIG_SOC_IMX5) += cpu-imx5.o clk-imx51-imx53.o clk-cpu.o $(imx5-pm-y) obj-$(CONFIG_COMMON_CLK) += clk-pllv1.o clk-pllv2.o clk-pllv3.o clk-gate2.o \ clk-pfd.o clk-busy.o clk.o \arch/arm/mach-imx/clk-cpu.c new file +8
-0@@ -0,0 +1,104 @@ +/* +* Copyright (c) 2014 Lucas Stach <[email protected]>, Pengutronix +* +* The code contained herein is licensed under the GNU General Public +* License. You may obtain a copy of the GNU General Public License +* Version 2 or later at the following locations: +* +* http://www.opensource.org/licenses/gpl-license.html arch/arm/mach-imx/clk-cpu.c line 18
Quoted 10 lines
arch/arm/mach-imx/clk-cpu.c new file +10
-0+* http://www.gnu.org/copyleft/gpl.html +*/ + +#include <linux/clk.h> +#include <linux/clk-provider.h> +#include <linux/slab.h> + +struct clk_cpu { +struct clk_hw hw; +struct clk *div, *mux, *pll, *step;This is personal taste, so I'm not strong on this. But I feel having them on multiple lines makes the later addition/removal of struct clk pointers a bit easier.
Other than these trivial comments, the patch looks good to me.
Shawn
arch/arm/mach-imx/clk-cpu.c line 19
Quoted 1 line
arch/arm/mach-imx/clk-cpu.c new file +1
-0+};--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Pengutronix e.K. | Lucas Stach | Industrial Linux Solutions | http://www.pengutronix.de/ |
PATCH 4/5 arm: imx53: clk: add ARM clock
In reply to Lucas StachThe ARM clock is a virtual clock feeding the ARM partition of the SoC. It controls multiple other clocks to ensure the right sequencing when cpufreq changes the CPU clock rate.
--- arch/arm/mach-imx/clk-imx51-imx53.c | 5 +++++ include/dt-bindings/clock/imx5-clock.h | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-)
arch/arm/mach-imx/clk-imx51-imx53.c +5 -0
@@ -541,6 +541,11 @@ static void __init mx53_clocks_init(struct device_node *np) clk[IMX5_CLK_CKO2 ] =imx_clk_gate2 ("cko2" ,"cko2_podf" ,MXC_CCM_CCOSR ,24 ); clk[IMX5_CLK_SPDIF_XTAL_SEL ] =imx_clk_mux ("spdif_xtal_sel" ,MXC_CCM_CSCMR1 ,2 ,2 , mx53_spdif_xtal_sel,ARRAY_SIZE (mx53_spdif_xtal_sel)); + clk[IMX5_CLK_ARM ] =imx_clk_cpu ("arm" ,"cpu_podf" , + clk[IMX5_CLK_CPU_PODF ], + clk[IMX5_CLK_CPU_PODF_SEL ], + clk[IMX5_CLK_PLL1_SW ], + clk[IMX5_CLK_STEP_SEL ]);imx_check_clocks (clk,ARRAY_SIZE (clk));
include/dt-bindings/clock/imx5-clock.h +2 -1
@@ -200,6 +200,7 @@#define IMX5_CLK_SATA_REF 188#define IMX5_CLK_STEP_SEL 189#define IMX5_CLK_CPU_PODF_SEL 190 -#define IMX5_CLK_END 191 +#define IMX5_CLK_ARM 191 +#define IMX5_CLK_END 192#endif /* __DT_BINDINGS_CLOCK_IMX5_H */
Signature · 1 line
2.1.0
PATCH 5/5 ARM: imx53: add cpufreq support
In reply to Lucas StachInstanciate the platform device for the generic cpufreq-cpu0 driver and add all required properties to the DT.
--- arch/arm/boot/dts/imx53.dtsi | 13 ++++++++++++- arch/arm/mach-imx/mach-imx53.c | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-)
arch/arm/boot/dts/imx53.dtsi +12 -1
@@ -46,10 +46,21 @@ cpus { #address-cells = <1>; #size-cells = <0>; - cpu at 0 { + cpu0: cpu at 0 { device_type = "cpu"; compatible = "arm,cortex-a8"; reg = <0x0>; + clocks = <&clks IMX5_CLK_ARM>; + clock-latency = <61036>; + voltage-tolerance = <5>; + operating-points = < + /* kHz */ + 166666 850000 + 400000 900000 + 800000 1050000 + 1000000 1200000 + 1200000 1300000 + >; }; };
arch/arm/mach-imx/mach-imx53.c +4 -0
@@ -38,9 +38,13 @@ static void __init imx53_dt_init(void)imx_aips_allow_unprivileged_access ("fsl,imx53-aipstz" ); } +static struct platform_device imx53_cpufreq_pdev = { .name ="cpufreq-cpu0" , }; +static void __init imx53_init_late (void ) {imx53_pm_init (); + +platform_device_register (&imx53_cpufreq_pdev); }static const char *const imx53_dt_board_compat[]__initconst = {
Signature · 1 line
2.1.0
PATCH 5/5 ARM: imx53: add cpufreq support
Quoted 7 lines · Lucas Stach
Instanciate the platform device for the generic cpufreq-cpu0 driver and add all required properties to the DT.
Signed-off-by Lucas Stach <[email protected]>--- arch/arm/boot/dts/imx53.dtsi | 13 ++++++++++++- arch/arm/mach-imx/mach-imx53.c | 4 ++++
Please split dts and kernel changes.
Quoted 34 lines
2 files changed, 16 insertions(+), 1 deletion(-)arch/arm/boot/dts/imx53.dtsi +12
-1@@ -46,10 +46,21 @@ cpus { #address-cells = <1>; #size-cells = <0>; - cpu at 0 { + cpu0: cpu at 0 { device_type = "cpu"; compatible = "arm,cortex-a8"; reg = <0x0>; + clocks = <&clks IMX5_CLK_ARM>; + clock-latency = <61036>; + voltage-tolerance = <5>; + operating-points = < + /* kHz */ + 166666 850000 + 400000 900000 + 800000 1050000 + 1000000 1200000 + 1200000 1300000 + >; }; };arch/arm/mach-imx/mach-imx53.c +0
-0
arch/arm/mach-imx/mach-imx53.c static void __init imx53_dt_init(void) · line 47
Quoted 10 lines
arch/arm/mach-imx/mach-imx53.c +4
-0@@ -38,9 +38,13 @@ static void __init imx53_dt_init(void)imx_aips_allow_unprivileged_access ("fsl,imx53-aipstz" ); } +static struct platform_device imx53_cpufreq_pdev = { .name ="cpufreq-cpu0" , }; +static void __init imx53_init_late (void ) {imx53_pm_init (); + +platform_device_register (&imx53_cpufreq_pdev);
It should be a bit easier to call the following.
platform_device_register_simple("cpufreq-cpu0", -1, NULL, 0);Shawn
Quoted 6 lines
arch/arm/mach-imx/mach-imx53.c +0
-0}static const char *const imx53_dt_board_compat[]__initconst = {Signature · 1 line
2.1.0