cpufreq for freescale mx51
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 cpufreq for freescale mx51
Add'ed linaro-dev and linux-arm-kernel to CC.
Thanks Yong, some feeback follows inline.
Quoted 47 lines · Yong Shen
From: Yong Shen <[email protected]>
--- arch/arm/Kconfig | 6 + arch/arm/mach-mx5/Kconfig | 1 + arch/arm/mach-mx5/board-mx51_babbage.c | 32 ++++ arch/arm/mach-mx5/clock-mx51.c | 53 ++++++ arch/arm/plat-mxc/Makefile | 2 + arch/arm/plat-mxc/cpufreq.c | 282 ++++++++++++++++++++++++++++++++ arch/arm/plat-mxc/include/mach/mxc.h | 20 +++ 7 files changed, 396 insertions(+), 0 deletions(-) create mode 100644 arch/arm/plat-mxc/cpufreq.carch/arm/Kconfig +6
-0@@ -1517,6 +1517,12 @@ if ARCH_HAS_CPUFREQ source "drivers/cpufreq/Kconfig" +config CPU_FREQ_IMX + tristate "CPUfreq driver for i.MX CPUs" + depends on ARCH_MXC && CPU_FREQ + help + This enables the CPUfreq driver for i.MX CPUs. + config CPU_FREQ_SA1100 boolarch/arm/mach-mx5/Kconfig +1
-0@@ -5,6 +5,7 @@ config ARCH_MX51 default y select MXC_TZIC select ARCH_MXC_IOMUX_V3 + select ARCH_HAS_CPUFREQ comment "MX5 platforms:"arch/arm/mach-mx5/board-mx51_babbage.c +0
-0
arch/arm/mach-mx5/board-mx51_babbage.c line 47
Quoted 5 lines
arch/arm/mach-mx5/board-mx51_babbage.c +2
-0@@ -43,6 +43,31 @@#define MX51_USB_PLL_DIV_19_2_MHZ 0x01#define MX51_USB_PLL_DIV_24_MHZ 0x02 +struct cpu_wp *(*get_cpu_wp)(int *wp); +static int num_cpu_wp =2 ;
use sizeof(array) instead of hard coding this.
Quoted 11 lines
arch/arm/mach-mx5/board-mx51_babbage.c +11
-0+/* working point(wp): 0 - 800MHz; 1 - 166.25MHz; */ +static struct cpu_wp cpu_wp_auto[] = { + { + .pll_rate =800000000 , + .cpu_rate =800000000 , + .pdf =0 , + .mfi =8 , + .mfd =2 , + .mfn =1 , + .cpu_podf =0 , + .cpu_voltage =1100000 ,},
arch/arm/mach-mx5/board-mx51_babbage.c line 68
Quoted 10 lines
arch/arm/mach-mx5/board-mx51_babbage.c +10
-0+ { + .pll_rate = 800000000, + .cpu_rate = 160000000, + .pdf = 4, + .mfi = 8, + .mfd = 2, + .mfn = 1, + .cpu_podf = 4, + .cpu_voltage = 850000,}, +};
This data should be moved out to a separate file (e.g. mx51_ratetable.h) since it will be useful to other boards too.
If other boards can have different rate tables (and they can, depending on the revision of the silicon), then we can either 'assemble' the correct rate table based on a flag field or have explicit separate rate tables for each silicon revision.
In any case, I suspect that there will be some core rates that will be common across silicon revisions.
Quoted 174 lines
arch/arm/mach-mx5/board-mx51_babbage.c +7
-0static struct platform_device *devices[]__initdata = { &mxc_fec_device, };@@ -87,6 +112,12 @@ static struct imxuart_platform_data uart_pdata = { .flags = IMXUART_HAVE_RTSCTS, }; +struct cpu_wp *mx51_babbage_get_cpu_wp (int *wp) +{ + *wp = num_cpu_wp; +return cpu_wp_auto; +} +static inline void mxc_init_imx_uart (void ) {mxc_register_device (&mxc_uart_device0, &uart_pdata);@@ -246,6 +277,7 @@ static void __init mxc_board_init(void)static void __init mx51_babbage_timer_init (void ) { + get_cpu_wp = mx51_babbage_get_cpu_wp;mx51_clocks_init (32768 ,24000000 ,22579200 ,0 ); }arch/arm/mach-mx5/clock-mx51.c +53
-0@@ -14,6 +14,7 @@#include <linux/delay.h> #include <linux/clk.h> #include <linux/io.h> +#include <linux/time.h> #include <asm/clkdev.h> #include <asm/div64.h> @@ -28,6 +29,11 @@static unsigned long external_high_reference, external_low_reference;static unsigned long oscillator_reference, ckih2_reference; +extern struct cpu_wp *(*get_cpu_wp)(int *wp); +static int cpu_wp_nr; +static int cpu_curr_wp; +static struct cpu_wp *cpu_wp_tbl; +static struct clk osc_clk;static struct clk pll1_main_clk;static struct clk pll1_sw_clk;@@ -38,7 +44,9 @@ static struct clk periph_apm_clk;static struct clk ahb_clk;static struct clk ipg_clk;static struct clk usboh3_clk; +static void __iomem *pll1_base; +#define SPIN_DELAY 1000000/* in nanoseconds */ #define MAX_DPLL_WAIT_TRIES 1000/* 1000 * udelay(1) = 1ms */ static int _clk_ccgr_enable (struct clk *clk)@@ -330,6 +338,32 @@ static int _clk_lp_apm_set_parent(struct clk *clk, struct clk *parent)return 0 ; } +/*! +* Setup cpu clock based on working point. +* @param wp cpu freq working point +* @return 0 on success or error code on failure. +*/ +int cpu_clk_set_wp (int wp) +{ +struct cpu_wp *p; +u32 reg; + +if (wp == cpu_curr_wp) +return 0 ; + + p = &cpu_wp_tbl[wp]; + +/*use post divider to change freq +*/ + reg =__raw_readl (MXC_CCM_CACRR ); + reg &= ~MXC_CCM_CACRR_ARM_PODF_MASK ; + reg |= cpu_wp_tbl[wp].cpu_podf <<MXC_CCM_CACRR_ARM_PODF_OFFSET ; +__raw_writel (reg,MXC_CCM_CACRR ); + cpu_curr_wp = wp; + +return 0 ; +} +static unsigned long clk_arm_get_rate (struct clk *clk) {u32 cacrr, div;@@ -342,6 +376,20 @@ static unsigned long clk_arm_get_rate(struct clk *clk)return parent_rate / div; } +int _clk_cpu_set_rate (struct clk *clk,unsigned long rate) +{ +u32 i; +for (i =0 ; i < cpu_wp_nr; i++) { +if (rate == cpu_wp_tbl[i].cpu_rate) +break ; + } +if (i >= cpu_wp_nr) +return -EINVAL ; +cpu_clk_set_wp (i); + +return 0 ; +} +static int _clk_periph_apm_set_parent (struct clk *clk,struct clk *parent) {u32 reg, mux;@@ -694,6 +742,7 @@ static struct clk periph_apm_clk = {static struct clk cpu_clk = { .parent = &pll1_sw_clk, .get_rate = clk_arm_get_rate, + .set_rate = _clk_cpu_set_rate, };static struct clk ahb_clk = {@@ -821,6 +870,7 @@ static struct clk_lookup lookups[] = { _REGISTER_CLOCK("mxc-ehci.1", "usb_ahb", ahb_clk) _REGISTER_CLOCK("fsl-usb2-udc", "usb", usboh3_clk) _REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", ahb_clk) + _REGISTER_CLOCK(NULL, "cpu_clk", cpu_clk) };static void clk_tree_init (void )@@ -848,10 +898,13 @@ int __init mx51_clocks_init(unsigned long ckil, unsigned long osc, {int i; + pll1_base =ioremap (MX51_PLL1_BASE_ADDR ,SZ_4K ); + external_low_reference = ckil; external_high_reference = ckih1; ckih2_reference = ckih2; oscillator_reference = osc; + cpu_wp_tbl =get_cpu_wp (&cpu_wp_nr);for (i =0 ; i <ARRAY_SIZE (lookups); i++)clkdev_add (&lookups[i]);arch/arm/plat-mxc/Makefile +2
-0@@ -17,6 +17,8 @@ obj-$(CONFIG_USB_EHCI_MXC) += ehci.o obj-$(CONFIG_MXC_ULPI) += ulpi.o obj-$(CONFIG_ARCH_MXC_AUDMUX_V1) += audmux-v1.o obj-$(CONFIG_ARCH_MXC_AUDMUX_V2) += audmux-v2.o +# CPU FREQ support +obj-$(CONFIG_CPU_FREQ_IMX) += cpufreq.o ifdef CONFIG_SND_IMX_SOC obj-y += ssi-fiq.o obj-y += ssi-fiq-ksym.oarch/arm/plat-mxc/cpufreq.c new file +13
-0@@ -0,0 +1,282 @@ +/* +* Copyright (C) 2010 Freescale Semiconductor, Inc. All Rights Reserved. +*/ + +/* +* 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 +* http://www.gnu.org/copyleft/gpl.html +*/ +
arch/arm/plat-mxc/cpufreq.c line 23
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+/*! +* @file cpufreq.c +* +* @brief A driver for the Freescale Semiconductor i.MXC CPUfreq module. +* +* The CPUFREQ driver is for controling CPU frequency. It allows you to change +* the CPU clock speed on the fly. +* +* @ingroup PM +*/
Fix these comments to follow the kernel commenting style.
Quoted 116 lines
arch/arm/plat-mxc/cpufreq.c new file +116
-0+#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/cpufreq.h> +#include <linux/init.h> +#include <linux/proc_fs.h> +#include <linux/regulator/consumer.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <mach/hardware.h> +#include <asm/setup.h> +#include <mach/clock.h> +#include <asm/cacheflush.h> +#include <linux/hrtimer.h> + +int cpu_freq_khz_min; +int cpu_freq_khz_max; +int arm_lpm_clk; +int arm_normal_clk; +int cpufreq_suspended; +int cpufreq_trig_needed; + +static struct clk *cpu_clk; +static struct cpufreq_frequency_table imx_freq_table[4 ]; + +extern int set_low_bus_freq (void ); +extern int set_high_bus_freq (int high_bus_speed); +extern int low_freq_bus_used (void ); + +extern struct cpu_wp *(*get_cpu_wp)(int *wp); +static int cpu_wp_nr; +static struct cpu_wp *cpu_wp_tbl; + +int set_cpu_freq (int freq) +{ +int ret =0 ; +int org_cpu_rate; +int gp_volt =0 ; +int i; + + org_cpu_rate =clk_get_rate (cpu_clk); +if (org_cpu_rate == freq) +return ret; + +for (i =0 ; i < cpu_wp_nr; i++) { +if (freq == cpu_wp_tbl[i].cpu_rate) + gp_volt = cpu_wp_tbl[i].cpu_voltage; + } + +if (gp_volt ==0 ) +return ret; + + ret =clk_set_rate (cpu_clk, freq); +if (ret !=0 ) { +printk (KERN_DEBUG "cannot set CPU clock rate\n" ); +return ret; + } + +return ret; +} + +static int mxc_verify_speed (struct cpufreq_policy *policy) +{ +if (policy->cpu !=0 ) +return -EINVAL ; + +return cpufreq_frequency_table_verify (policy, imx_freq_table); +} + +static unsigned int mxc_get_speed (unsigned int cpu) +{ +if (cpu) +return 0 ; + +return clk_get_rate (cpu_clk) /1000 ; +} + +static int calc_frequency_khz (int target,unsigned int relation) +{ +int i; + +if ((target *1000 ) ==clk_get_rate (cpu_clk)) +return target; + +if (relation ==CPUFREQ_RELATION_H ) { +for (i = cpu_wp_nr -1 ; i >=0 ; i--) { +if (imx_freq_table[i].frequency <= target) +return imx_freq_table[i].frequency; + } + }else if (relation ==CPUFREQ_RELATION_L ) { +for (i =0 ; i < cpu_wp_nr; i++) { +if (imx_freq_table[i].frequency >= target) +return imx_freq_table[i].frequency; + } + } +printk (KERN_ERR "Error: No valid cpufreq relation\n" ); +return cpu_freq_khz_max; +} + +static int mxc_set_target (struct cpufreq_policy *policy, +unsigned int target_freq,unsigned int relation) +{ +struct cpufreq_freqs freqs; +int freq_Hz; +int ret =0 ; + +if (cpufreq_suspended) { + target_freq =clk_get_rate (cpu_clk) /1000 ; + freq_Hz =calc_frequency_khz (target_freq, relation) *1000 ; +if (freq_Hz == arm_lpm_clk) + freqs.old = cpu_wp_tbl[cpu_wp_nr -2 ].cpu_rate /1000 ; +else + freqs.old = arm_lpm_clk /1000 ; + + freqs.new = freq_Hz /1000 ; + freqs.cpu =0 ;
arch/arm/plat-mxc/cpufreq.c line 149
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+ freqs.flags =0 ; +cpufreq_notify_transition (&freqs,CPUFREQ_PRECHANGE ); +cpufreq_notify_transition (&freqs,CPUFREQ_POSTCHANGE ); +return ret; + } +/* +* Some governors do not respects CPU and policy lower limits +* which leads to bad things (division by zero etc), ensure +* that such things do not happen. +*/
Isn't that a bug in the governor? Can you explain a bit?
Quoted 36 lines
arch/arm/plat-mxc/cpufreq.c new file +36
-0+if (target_freq < policy->cpuinfo.min_freq) + target_freq = policy->cpuinfo.min_freq; + +if (target_freq < policy->min) + target_freq = policy->min; + + freq_Hz =calc_frequency_khz (target_freq, relation) *1000 ; + + freqs.old =clk_get_rate (cpu_clk) /1000 ; + freqs.new = freq_Hz /1000 ; + freqs.cpu =0 ; + freqs.flags =0 ; +cpufreq_notify_transition (&freqs,CPUFREQ_PRECHANGE ); + +if (freqs.old != freqs.new) + ret =set_cpu_freq (freq_Hz); + +cpufreq_notify_transition (&freqs,CPUFREQ_POSTCHANGE ); + +return ret; +} + +static int __init mxc_cpufreq_driver_init (struct cpufreq_policy *policy) +{ +int ret; +int i; + +printk (KERN_INFO "i.MXC CPU frequency driver\n" ); + +if (policy->cpu !=0 ) +return -EINVAL ; + + cpu_clk =clk_get (NULL ,"cpu_clk" ); +if (IS_ERR (cpu_clk)) { +printk (KERN_ERR "%s: failed to get cpu clock\n" , __func__); +return PTR_ERR (cpu_clk);
arch/arm/plat-mxc/cpufreq.c line 195
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+ } + +/* Set the current working point. */ + cpu_wp_tbl =get_cpu_wp (&cpu_wp_nr); + + cpu_freq_khz_min = cpu_wp_tbl[0 ].cpu_rate /1000 ; + cpu_freq_khz_max = cpu_wp_tbl[0 ].cpu_rate /1000 ; + +for (i =0 ; i < cpu_wp_nr; i++) { + imx_freq_table[cpu_wp_nr -1 - i].index = cpu_wp_nr - i;
cpu_wp_nr = 2 here
1st iteration of for loop:
imx_freq_table[2 - 1 - 0].index = 2 - 0
so, imx_freq_table[1].index = 2
2nd iteration:
imx_freq_table[2 - 1 - 1].index = 2 - 1
imx_freq_table[0].index = 1So you're trying to reverse the table order? Why not just sort the table date in the way you want and add a comment on the top to keep it sorted.
arch/arm/plat-mxc/cpufreq.c line 206
Quoted 11 lines
arch/arm/plat-mxc/cpufreq.c new file +11
-0+ imx_freq_table[cpu_wp_nr -1 - i].frequency = + cpu_wp_tbl[i].cpu_rate /1000 ; + +if ((cpu_wp_tbl[i].cpu_rate /1000 ) < cpu_freq_khz_min) + cpu_freq_khz_min = cpu_wp_tbl[i].cpu_rate /1000 ; + +if ((cpu_wp_tbl[i].cpu_rate /1000 ) > cpu_freq_khz_max) + cpu_freq_khz_max = cpu_wp_tbl[i].cpu_rate /1000 ; + } + + imx_freq_table[i].index =0 ;
imx_freq_table[i].index = i ?
Quoted 21 lines
arch/arm/plat-mxc/cpufreq.c new file +21
-0+ imx_freq_table[i].frequency =CPUFREQ_TABLE_END ; + + policy->cur =clk_get_rate (cpu_clk) /1000 ; + policy->governor =CPUFREQ_DEFAULT_GOVERNOR ; + policy->min = policy->cpuinfo.min_freq = cpu_freq_khz_min; + policy->max = policy->cpuinfo.max_freq = cpu_freq_khz_max; + + arm_lpm_clk = cpu_freq_khz_min *1000 ; + arm_normal_clk = cpu_freq_khz_max *1000 ; + +/* Manual states, that PLL stabilizes in two CLK32 periods */ + policy->cpuinfo.transition_latency =10 ; + + ret =cpufreq_frequency_table_cpuinfo (policy, imx_freq_table); + +if (ret <0 ) { +clk_put (cpu_clk); +printk (KERN_ERR "%s: failed to register i.MXC CPUfreq\n" , + __func__); +return ret; + }
arch/arm/plat-mxc/cpufreq.c line 237
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+ +cpufreq_frequency_table_get_attr (imx_freq_table, policy->cpu); +return 0 ; +} + +static int mxc_cpufreq_suspend (struct cpufreq_policy *policy, +pm_message_t state) +{ +return 0 ; +}
Get rid of these, since you don't use them.
arch/arm/plat-mxc/cpufreq.c line 241
Quoted 4 lines
arch/arm/plat-mxc/cpufreq.c new file +4
-0+static int mxc_cpufreq_resume (struct cpufreq_policy *policy) +{ +return 0 ; +}
Same here.
Quoted 6 lines
arch/arm/plat-mxc/cpufreq.c new file +6
-0+static int mxc_cpufreq_driver_exit (struct cpufreq_policy *policy) +{ +cpufreq_frequency_table_put_attr (policy->cpu); + +/* Reset CPU to 665MHz */ +set_cpu_freq (arm_normal_clk);
arch/arm/plat-mxc/cpufreq.c line 257
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+clk_put (cpu_clk); +return 0 ; +} + +static struct cpufreq_driver mxc_driver = { + .flags =CPUFREQ_STICKY , + .verify = mxc_verify_speed, + .target = mxc_set_target, + .get = mxc_get_speed, + .init = mxc_cpufreq_driver_init,
mxc_cpufreq_init is ok. Lose the driver.
arch/arm/plat-mxc/cpufreq.c line 258
Quoted 1 line
arch/arm/plat-mxc/cpufreq.c new file +1
-0+ .exit = mxc_cpufreq_driver_exit,
same.
arch/arm/plat-mxc/cpufreq.c line 260
Quoted 2 lines
arch/arm/plat-mxc/cpufreq.c new file +2
-0+ .suspend = mxc_cpufreq_suspend, + .resume = mxc_cpufreq_resume,
Get rid of suspend/resume
Quoted 53 lines
arch/arm/plat-mxc/cpufreq.c new file +19
-0+ .name = "imx", +}; + +static int __devinit mxc_cpufreq_init (void ) +{ +return cpufreq_register_driver (&mxc_driver); +} + +static void mxc_cpufreq_exit (void ) +{ +cpufreq_unregister_driver (&mxc_driver); +} + +module_init (mxc_cpufreq_init); +module_exit (mxc_cpufreq_exit); + +MODULE_AUTHOR ("Freescale Semiconductor, Inc." ); +MODULE_DESCRIPTION ("CPUfreq driver for i.MX" ); +MODULE_LICENSE ("GPL" );arch/arm/plat-mxc/include/mach/mxc.h +20
-0@@ -133,6 +133,26 @@ extern unsigned int __mxc_cpu_type;# define cpu_is_mxc91231 () (0)#endif +#ifndef __ASSEMBLY__ + +struct cpu_wp { +u32 pll_reg; +u32 pll_rate; +u32 cpu_rate; +u32 pdr0_reg; +u32 pdf; +u32 mfi; +u32 mfd; +u32 mfn; +u32 cpu_voltage; +u32 cpu_podf; +}; + +#ifndef CONFIG_ARCH_MX5 +struct cpu_wp *get_cpu_wp (int *wp); +#endif +#endif +#if defined(CONFIG_ARCH_MX3 ) || defined(CONFIG_ARCH_MX2 )/* These are deprecated, use mx[23][157]_setup_weimcs instead. */ #define CSCR_U (n) (IO_ADDRESS(WEIM_BASE_ADDR + n * 0x10))Signature · 1 line
1.6.3.3
PATCH 1/1 cpufreq for freescale mx51
Hi Amit,
Please see my feedback embedded.
Quoted 57 lines · Amit Kucheria
Add'ed linaro-dev and linux-arm-kernel to CC.
Thanks Yong, some feeback follows inline.
Quoted 9 lines · Yong Shen
From: Yong Shen <[email protected]>
--- arch/arm/Kconfig | 6 + arch/arm/mach-mx5/Kconfig | 1 + arch/arm/mach-mx5/board-mx51_babbage.c | 32 ++++ arch/arm/mach-mx5/clock-mx51.c | 53 ++++++ arch/arm/plat-mxc/Makefile | 2 + arch/arm/plat-mxc/cpufreq.c | 282++++++++++++++++++++++++++++++++
Review
Quoted 34 lines
arch/arm/plat-mxc/include/mach/mxc.h | 20 +++ 7 files changed, 396 insertions(+), 0 deletions(-) create mode 100644 arch/arm/plat-mxc/cpufreq.carch/arm/Kconfig +6
-0@@ -1517,6 +1517,12 @@ if ARCH_HAS_CPUFREQ source "drivers/cpufreq/Kconfig" +config CPU_FREQ_IMX + tristate "CPUfreq driver for i.MX CPUs" + depends on ARCH_MXC && CPU_FREQ + help + This enables the CPUfreq driver for i.MX CPUs. + config CPU_FREQ_SA1100 boolarch/arm/mach-mx5/Kconfig +1
-0@@ -5,6 +5,7 @@ config ARCH_MX51 default y select MXC_TZIC select ARCH_MXC_IOMUX_V3 + select ARCH_HAS_CPUFREQ comment "MX5 platforms:"(quoted diff) +0
-0
b/arch/arm/mach-mx5/board-mx51_babbage.cQuoted 7 lines
index ed885f9..e449e0b 100644
arch/arm/mach-mx5/board-mx51_babbage.c +0
-0@@ -43,6 +43,31 @@#define MX51_USB_PLL_DIV_19_2_MHZ 0x01#define MX51_USB_PLL_DIV_24_MHZ 0x02
Quoted 5 lines
arch/arm/mach-mx5/board-mx51_babbage.c line 47
Quoted 2 lines
arch/arm/mach-mx5/board-mx51_babbage.c +2
-0+struct cpu_wp *(*get_cpu_wp)(int *wp); +static int num_cpu_wp =2 ;use sizeof(array) instead of hard coding this.
yong: Agreed.
Quoted 33 lines
Quoted 12 lines
arch/arm/mach-mx5/board-mx51_babbage.c +11
-0+/* working point(wp): 0 - 800MHz; 1 - 166.25MHz; */ +static struct cpu_wp cpu_wp_auto[] = { + { + .pll_rate =800000000 , + .cpu_rate =800000000 , + .pdf =0 , + .mfi =8 , + .mfd =2 , + .mfn =1 , + .cpu_podf =0 , + .cpu_voltage =1100000 ,},arch/arm/mach-mx5/board-mx51_babbage.c line 68
Quoted 10 lines
arch/arm/mach-mx5/board-mx51_babbage.c +10
-0+ { + .pll_rate = 800000000, + .cpu_rate = 160000000, + .pdf = 4, + .mfi = 8, + .mfd = 2, + .mfn = 1, + .cpu_podf = 4, + .cpu_voltage = 850000,}, +};This data should be moved out to a separate file (e.g.
mx51_ratetable.h) since it will be useful to other boards too.If other boards can have different rate tables (and they can, depending on the revision of the silicon), then we can either 'assemble' the correct rate
table based on a flag field or have explicit separate rate tables for each silicon revision.
Quoted 5 lines
In any case, I suspect that there will be some core rates that will be common
across silicon revisions.
Yong: We keep it in a board related file because we may have different voltage set to various boards. But like what you think, in most of case, we can use this table for different boards.
Quoted 186 lines
Review
Quoted 25 lines
arch/arm/mach-mx5/board-mx51_babbage.c +7
-0static struct platform_device *devices[]__initdata = { &mxc_fec_device, };@@ -87,6 +112,12 @@ static struct imxuart_platform_data uart_pdata = { .flags = IMXUART_HAVE_RTSCTS, }; +struct cpu_wp *mx51_babbage_get_cpu_wp (int *wp) +{ + *wp = num_cpu_wp; +return cpu_wp_auto; +} +static inline void mxc_init_imx_uart (void ) {mxc_register_device (&mxc_uart_device0, &uart_pdata);@@ -246,6 +277,7 @@ static void __init mxc_board_init(void)static void __init mx51_babbage_timer_init (void ) { + get_cpu_wp = mx51_babbage_get_cpu_wp;mx51_clocks_init (32768 ,24000000 ,22579200 ,0 ); }(quoted diff) +0
-0
b/arch/arm/mach-mx5/clock-mx51.carch/arm/mach-mx5/clock-mx51.c static int _clk_lp_apm_set_parent(struct clk *clk,
Quoted 34 lines
index d9f612d..f2488e6 100644
arch/arm/mach-mx5/clock-mx51.c +8
-0@@ -14,6 +14,7 @@#include <linux/delay.h> #include <linux/clk.h> #include <linux/io.h> +#include <linux/time.h> #include <asm/clkdev.h> #include <asm/div64.h> @@ -28,6 +29,11 @@static unsigned long external_high_reference, external_low_reference;static unsigned long oscillator_reference, ckih2_reference; +extern struct cpu_wp *(*get_cpu_wp)(int *wp); +static int cpu_wp_nr; +static int cpu_curr_wp; +static struct cpu_wp *cpu_wp_tbl; +static struct clk osc_clk;static struct clk pll1_main_clk;static struct clk pll1_sw_clk;@@ -38,7 +44,9 @@ static struct clk periph_apm_clk;static struct clk ahb_clk;static struct clk ipg_clk;static struct clk usboh3_clk; +static void __iomem *pll1_base; +#define SPIN_DELAY 1000000/* in nanoseconds */ #define MAX_DPLL_WAIT_TRIES 1000/* 1000 * udelay(1) = 1ms */ static int _clk_ccgr_enable (struct clk *clk)@@ -330,6 +338,32 @@ static int _clk_lp_apm_set_parent(struct clk *clk,struct clk *parent)
arch/arm/mach-mx5/clock-mx51.c static unsigned long clk_arm_get_rate(struct clk
Quoted 33 lines
arch/arm/mach-mx5/clock-mx51.c +26
-0return 0 ; } +/*! +* Setup cpu clock based on working point. +* @param wp cpu freq working point +* @return 0 on success or error code on failure. +*/ +int cpu_clk_set_wp (int wp) +{ +struct cpu_wp *p; +u32 reg; + +if (wp == cpu_curr_wp) +return 0 ; + + p = &cpu_wp_tbl[wp]; + +/*use post divider to change freq +*/ + reg =__raw_readl (MXC_CCM_CACRR ); + reg &= ~MXC_CCM_CACRR_ARM_PODF_MASK ; + reg |= cpu_wp_tbl[wp].cpu_podf <<MXC_CCM_CACRR_ARM_PODF_OFFSET ; +__raw_writel (reg,MXC_CCM_CACRR ); + cpu_curr_wp = wp; + +return 0 ; +} +static unsigned long clk_arm_get_rate (struct clk *clk) {u32 cacrr, div;@@ -342,6 +376,20 @@ static unsigned long clk_arm_get_rate(struct clk*clk)
Quoted 8 lines
arch/arm/mach-mx5/clock-mx51.c +5
-0return parent_rate / div; } +int _clk_cpu_set_rate (struct clk *clk,unsigned long rate) +{ +u32 i; +for (i =0 ; i < cpu_wp_nr; i++) { +if (rate == cpu_wp_tbl[i].cpu_rate)arch/arm/mach-mx5/clock-mx51.c static unsigned long clk_arm_get_rate(struct clk · line 393
Quoted 10 lines
arch/arm/mach-mx5/clock-mx51.c +9
-0+break ; + } +if (i >= cpu_wp_nr) +return -EINVAL ; +cpu_clk_set_wp (i); + +return 0 ; +} + static int _clk_periph_apm_set_parent(struct clk *clk, struct clk*parent)
arch/arm/mach-mx5/clock-mx51.c int __init mx51_clocks_init(unsigned long ckil,
Quoted 19 lines
arch/arm/mach-mx5/clock-mx51.c +2
-0{u32 reg, mux;@@ -694,6 +742,7 @@ static struct clk periph_apm_clk = {static struct clk cpu_clk = { .parent = &pll1_sw_clk, .get_rate = clk_arm_get_rate, + .set_rate = _clk_cpu_set_rate, };static struct clk ahb_clk = {@@ -821,6 +870,7 @@ static struct clk_lookup lookups[] = { _REGISTER_CLOCK("mxc-ehci.1", "usb_ahb", ahb_clk) _REGISTER_CLOCK("fsl-usb2-udc", "usb", usboh3_clk) _REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", ahb_clk) + _REGISTER_CLOCK(NULL, "cpu_clk", cpu_clk) };static void clk_tree_init (void )@@ -848,10 +898,13 @@ int __init mx51_clocks_init(unsigned long ckil,unsigned long osc,
Quoted 41 lines
arch/arm/mach-mx5/clock-mx51.c +3
-0{int i; + pll1_base =ioremap (MX51_PLL1_BASE_ADDR ,SZ_4K ); + external_low_reference = ckil; external_high_reference = ckih1; ckih2_reference = ckih2; oscillator_reference = osc; + cpu_wp_tbl =get_cpu_wp (&cpu_wp_nr);for (i =0 ; i <ARRAY_SIZE (lookups); i++)clkdev_add (&lookups[i]);arch/arm/plat-mxc/Makefile +2
-0@@ -17,6 +17,8 @@ obj-$(CONFIG_USB_EHCI_MXC) += ehci.o obj-$(CONFIG_MXC_ULPI) += ulpi.o obj-$(CONFIG_ARCH_MXC_AUDMUX_V1) += audmux-v1.o obj-$(CONFIG_ARCH_MXC_AUDMUX_V2) += audmux-v2.o +# CPU FREQ support +obj-$(CONFIG_CPU_FREQ_IMX) += cpufreq.o ifdef CONFIG_SND_IMX_SOC obj-y += ssi-fiq.o obj-y += ssi-fiq-ksym.oarch/arm/plat-mxc/cpufreq.c new file +9
-0@@ -0,0 +1,282 @@ +/* +* Copyright (C) 2010 Freescale Semiconductor, Inc. All Rights Reserved. +*/ + +/* +* 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: +* arch/arm/plat-mxc/cpufreq.c line 19
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+* http://www.opensource.org/licenses/gpl-license.html +* http://www.gnu.org/copyleft/gpl.html +*/ + +/*! +* @file cpufreq.c +* +* @brief A driver for the Freescale Semiconductor i.MXC CPUfreq module. +* +* The CPUFREQ driver is for controling CPU frequency. It allows you to change
Quoted 7 lines
arch/arm/plat-mxc/cpufreq.c line 23
Quoted 4 lines
arch/arm/plat-mxc/cpufreq.c new file +4
-0+* the CPU clock speed on the fly. +* +* @ingroup PM +*/ Fix these comments to follow the kernel commenting style.
Yong: OK
Quoted 129 lines
Quoted 102 lines
arch/arm/plat-mxc/cpufreq.c new file +101
-0+#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/cpufreq.h> +#include <linux/init.h> +#include <linux/proc_fs.h> +#include <linux/regulator/consumer.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <mach/hardware.h> +#include <asm/setup.h> +#include <mach/clock.h> +#include <asm/cacheflush.h> +#include <linux/hrtimer.h> + +int cpu_freq_khz_min; +int cpu_freq_khz_max; +int arm_lpm_clk; +int arm_normal_clk; +int cpufreq_suspended; +int cpufreq_trig_needed; + +static struct clk *cpu_clk; +static struct cpufreq_frequency_table imx_freq_table[4 ]; + +extern int set_low_bus_freq (void ); +extern int set_high_bus_freq (int high_bus_speed); +extern int low_freq_bus_used (void ); + +extern struct cpu_wp *(*get_cpu_wp)(int *wp); +static int cpu_wp_nr; +static struct cpu_wp *cpu_wp_tbl; + +int set_cpu_freq (int freq) +{ +int ret =0 ; +int org_cpu_rate; +int gp_volt =0 ; +int i; + + org_cpu_rate =clk_get_rate (cpu_clk); +if (org_cpu_rate == freq) +return ret; + +for (i =0 ; i < cpu_wp_nr; i++) { +if (freq == cpu_wp_tbl[i].cpu_rate) + gp_volt = cpu_wp_tbl[i].cpu_voltage; + } + +if (gp_volt ==0 ) +return ret; + + ret =clk_set_rate (cpu_clk, freq); +if (ret !=0 ) { +printk (KERN_DEBUG "cannot set CPU clock rate\n" ); +return ret; + } + +return ret; +} + +static int mxc_verify_speed (struct cpufreq_policy *policy) +{ +if (policy->cpu !=0 ) +return -EINVAL ; + +return cpufreq_frequency_table_verify (policy, imx_freq_table); +} + +static unsigned int mxc_get_speed (unsigned int cpu) +{ +if (cpu) +return 0 ; + +return clk_get_rate (cpu_clk) /1000 ; +} + +static int calc_frequency_khz (int target,unsigned int relation) +{ +int i; + +if ((target *1000 ) ==clk_get_rate (cpu_clk)) +return target; + +if (relation ==CPUFREQ_RELATION_H ) { +for (i = cpu_wp_nr -1 ; i >=0 ; i--) { +if (imx_freq_table[i].frequency <= target) +return imx_freq_table[i].frequency; + } + }else if (relation ==CPUFREQ_RELATION_L ) { +for (i =0 ; i < cpu_wp_nr; i++) { +if (imx_freq_table[i].frequency >= target) +return imx_freq_table[i].frequency; + } + } +printk (KERN_ERR "Error: No valid cpufreq relation\n" ); +return cpu_freq_khz_max; +} + +static int mxc_set_target (struct cpufreq_policy *policy, +unsigned int target_freq,unsigned int relation)arch/arm/plat-mxc/cpufreq.c line 134
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+{ +struct cpufreq_freqs freqs; +int freq_Hz; +int ret =0 ; + +if (cpufreq_suspended) { + target_freq =clk_get_rate (cpu_clk) /1000 ; + freq_Hz =calc_frequency_khz (target_freq, relation) *1000 ; +if (freq_Hz == arm_lpm_clk) + freqs.old = cpu_wp_tbl[cpu_wp_nr - 2].cpu_rate /1000;
Quoted 5 lines
arch/arm/plat-mxc/cpufreq.c new file +5
-0+else + freqs.old = arm_lpm_clk /1000 ; + + freqs.new = freq_Hz /1000 ; + freqs.cpu =0 ;arch/arm/plat-mxc/cpufreq.c line 149
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+ freqs.flags =0 ; +cpufreq_notify_transition (&freqs,CPUFREQ_PRECHANGE ); +cpufreq_notify_transition (&freqs,CPUFREQ_POSTCHANGE ); +return ret; + } +/* +* Some governors do not respects CPU and policy lower limits +* which leads to bad things (division by zero etc), ensure +* that such things do not happen. +*/
Quoted 2 lines
Isn't that a bug in the governor? Can you explain a bit?
Yong: the original driver writer might have concern that some governor implementations will not care about the low limit suggested by cpu policy, therefore it is a change to correct them.
Quoted 54 lines
Quoted 37 lines
arch/arm/plat-mxc/cpufreq.c new file +36
-0+if (target_freq < policy->cpuinfo.min_freq) + target_freq = policy->cpuinfo.min_freq; + +if (target_freq < policy->min) + target_freq = policy->min; + + freq_Hz =calc_frequency_khz (target_freq, relation) *1000 ; + + freqs.old =clk_get_rate (cpu_clk) /1000 ; + freqs.new = freq_Hz /1000 ; + freqs.cpu =0 ; + freqs.flags =0 ; +cpufreq_notify_transition (&freqs,CPUFREQ_PRECHANGE ); + +if (freqs.old != freqs.new) + ret =set_cpu_freq (freq_Hz); + +cpufreq_notify_transition (&freqs,CPUFREQ_POSTCHANGE ); + +return ret; +} + +static int __init mxc_cpufreq_driver_init (struct cpufreq_policy *policy) +{ +int ret; +int i; + +printk (KERN_INFO "i.MXC CPU frequency driver\n" ); + +if (policy->cpu !=0 ) +return -EINVAL ; + + cpu_clk =clk_get (NULL ,"cpu_clk" ); +if (IS_ERR (cpu_clk)) { +printk (KERN_ERR "%s: failed to get cpu clock\n" , __func__); +return PTR_ERR (cpu_clk);arch/arm/plat-mxc/cpufreq.c line 195
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+ } + +/* Set the current working point. */ + cpu_wp_tbl =get_cpu_wp (&cpu_wp_nr); + + cpu_freq_khz_min = cpu_wp_tbl[0 ].cpu_rate /1000 ; + cpu_freq_khz_max = cpu_wp_tbl[0 ].cpu_rate /1000 ; + +for (i =0 ; i < cpu_wp_nr; i++) { + imx_freq_table[cpu_wp_nr -1 - i].index = cpu_wp_nr - i;
cpu_wp_nr= 2 here1st iteration of for loop:
imx_freq_table[2 - 1 - 0].index = 2 - 0so, imx_freq_table[1].index = 2
Quoted 8 lines
2nd iteration:
imx_freq_table[2 - 1 - 1].index = 2 - 1 imx_freq_table[0].index = 1So you're trying to reverse the table order? Why not just sort the table date
in the way you want and add a comment on the top to keep it sorted.
Yong: my understanding is that the freq table defined in another file is sorted in descending order, so the writer tends to make imx_freq_table in a descending order.
Quoted 15 lines
arch/arm/plat-mxc/cpufreq.c line 206
Quoted 12 lines
arch/arm/plat-mxc/cpufreq.c new file +11
-0+ imx_freq_table[cpu_wp_nr -1 - i].frequency = + cpu_wp_tbl[i].cpu_rate /1000 ; + +if ((cpu_wp_tbl[i].cpu_rate /1000 ) < cpu_freq_khz_min) + cpu_freq_khz_min = cpu_wp_tbl[i].cpu_rate /1000 ; + +if ((cpu_wp_tbl[i].cpu_rate /1000 ) > cpu_freq_khz_max) + cpu_freq_khz_max = cpu_wp_tbl[i].cpu_rate /1000 ; + } + + imx_freq_table[i].index =0 ;imx_freq_table[i].index = i ?
Yong: this should be a place holder, no meaning.
Quoted 118 lines
Quoted 22 lines
arch/arm/plat-mxc/cpufreq.c new file +21
-0+ imx_freq_table[i].frequency =CPUFREQ_TABLE_END ; + + policy->cur =clk_get_rate (cpu_clk) /1000 ; + policy->governor =CPUFREQ_DEFAULT_GOVERNOR ; + policy->min = policy->cpuinfo.min_freq = cpu_freq_khz_min; + policy->max = policy->cpuinfo.max_freq = cpu_freq_khz_max; + + arm_lpm_clk = cpu_freq_khz_min *1000 ; + arm_normal_clk = cpu_freq_khz_max *1000 ; + +/* Manual states, that PLL stabilizes in two CLK32 periods */ + policy->cpuinfo.transition_latency =10 ; + + ret =cpufreq_frequency_table_cpuinfo (policy, imx_freq_table); + +if (ret <0 ) { +clk_put (cpu_clk); +printk (KERN_ERR "%s: failed to register i.MXC CPUfreq\n" , + __func__); +return ret; + }arch/arm/plat-mxc/cpufreq.c line 237
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+ +cpufreq_frequency_table_get_attr (imx_freq_table, policy->cpu); +return 0 ; +} + +static int mxc_cpufreq_suspend (struct cpufreq_policy *policy, +pm_message_t state) +{ +return 0 ; +}Get rid of these, since you don't use them.
yong:Ok about this and below
arch/arm/plat-mxc/cpufreq.c line 241
Quoted 4 lines
arch/arm/plat-mxc/cpufreq.c new file +4
-0+static int mxc_cpufreq_resume (struct cpufreq_policy *policy) +{ +return 0 ; +}Same here.
Quoted 6 lines
arch/arm/plat-mxc/cpufreq.c new file +6
-0+static int mxc_cpufreq_driver_exit (struct cpufreq_policy *policy) +{ +cpufreq_frequency_table_put_attr (policy->cpu); + +/* Reset CPU to 665MHz */ +set_cpu_freq (arm_normal_clk);arch/arm/plat-mxc/cpufreq.c line 257
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+clk_put (cpu_clk); +return 0 ; +} + +static struct cpufreq_driver mxc_driver = { + .flags =CPUFREQ_STICKY , + .verify = mxc_verify_speed, + .target = mxc_set_target, + .get = mxc_get_speed, + .init = mxc_cpufreq_driver_init,
mxc_cpufreq_initis ok. Lose the driver.arch/arm/plat-mxc/cpufreq.c line 258
Quoted 1 line
arch/arm/plat-mxc/cpufreq.c new file +1
-0+ .exit = mxc_cpufreq_driver_exit,same.
arch/arm/plat-mxc/cpufreq.c line 260
Quoted 2 lines
arch/arm/plat-mxc/cpufreq.c new file +2
-0+ .suspend = mxc_cpufreq_suspend, + .resume = mxc_cpufreq_resume,Get rid of suspend/resume
Review
Quoted 20 lines
arch/arm/plat-mxc/cpufreq.c new file +19
-0+ .name = "imx", +}; + +static int __devinit mxc_cpufreq_init (void ) +{ +return cpufreq_register_driver (&mxc_driver); +} + +static void mxc_cpufreq_exit (void ) +{ +cpufreq_unregister_driver (&mxc_driver); +} + +module_init (mxc_cpufreq_init); +module_exit (mxc_cpufreq_exit); + +MODULE_AUTHOR ("Freescale Semiconductor, Inc." ); +MODULE_DESCRIPTION ("CPUfreq driver for i.MX" ); +MODULE_LICENSE ("GPL" );(quoted diff) +0
-0
b/arch/arm/plat-mxc/include/mach/mxc.hQuoted 25 lines
index a790bf2..14003b9 100644
arch/arm/plat-mxc/include/mach/mxc.h +18
-0@@ -133,6 +133,26 @@ extern unsigned int __mxc_cpu_type;# define cpu_is_mxc91231 () (0)#endif +#ifndef __ASSEMBLY__ + +struct cpu_wp { +u32 pll_reg; +u32 pll_rate; +u32 cpu_rate; +u32 pdr0_reg; +u32 pdf; +u32 mfi; +u32 mfd; +u32 mfn; +u32 cpu_voltage; +u32 cpu_podf; +}; + +#ifndef CONFIG_ARCH_MX5 +struct cpu_wp *get_cpu_wp (int *wp); +#endif
Quoted 9 lines
Quoted 8 lines
arch/arm/plat-mxc/include/mach/mxc.h +2
-1+#endif +#if defined(CONFIG_ARCH_MX3 ) || defined(CONFIG_ARCH_MX2 )/* These are deprecated, use mx[23][157]_setup_weimcs instead. */ #define CSCR_U (n) (IO_ADDRESS(WEIM_BASE_ADDR + n * 0x10)) --1.6.3.3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20101001/3febe223/attachment-0001.html>
PATCH 1/1 cpufreq for freescale mx51
More comments.
Quoted 6 lines · Yong Shen
Hi Amit,
Please see my feedback embedded.
On Thu, Sep 30, 2010 at 6:48 PM, Amit Kucheria <[email protected]> wrote:
[snip]
Quoted 32 lines
Quoted 23 lines
Quoted 23 lines
(quoted diff) +10
-0+static int mxc_set_target(struct cpufreq_policy *policy, + ? ? ? ? ? ? ? ? ? ? ? unsigned int target_freq, unsigned int relation) +{ + ? ? struct cpufreq_freqs freqs; + ? ? int freq_Hz; + ? ? int ret = 0; + + ? ? if (cpufreq_suspended) { + ? ? ? ? ? ? target_freq = clk_get_rate(cpu_clk) / 1000; + ? ? ? ? ? ? freq_Hz = calc_frequency_khz(target_freq, relation) *1000;
+ ? ? ? ? ? ? if (freq_Hz==arm_lpm_clk)
+ ? ? ? ? ? ? ? ? ? ? freqs.old = cpu_wp_tbl[cpu_wp_nr - 2].cpu_rate / 1000;
+ ? ? ? ? ? ? else
+ ? ? ? ? ? ? ? ? ? ? freqs.old =arm_lpm_clk/ 1000;
+
+ ? ? ? ? ? ? freqs.new =freq_Hz/ 1000;
+ ? ? ? ? ? ? freqs.cpu = 0;
+ ? ? ? ? ? ? freqs.flags = 0;
+ ? ? ? ? ? ?cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
+ ? ? ? ? ? ?cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
+ ? ? ? ? ? ? return ret;Quoted 8 lines
Quoted 6 lines
+ ? ? }
+ ? ? /*
+ ? ? ?* Some governors do not respects CPU and policy lower limits
+ ? ? ?* which leads to bad things (division by zero etc), ensure
+ ? ? ?* that such things do not happen.
+ ? ? ?*/Isn't that a bug in the governor? Can you explain a bit?
Quoted 3 lines
Yong: the original driver writer might have concern that some governor implementations will not care about the low limit suggested by cpu policy, therefore it is a change to correct them.
Could you confirm if this is still the case, and if not, get rid of this code/comment?
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ ? ? if (
target_freq<policy->cpuinfo.min_freq)
+ ? ? ? ? ? ?target_freq=policy->cpuinfo.min_freq;(quoted diff) +6
-0+ + ? ? if (target_freq < policy->min) + ? ? ? ? ? ? target_freq = policy->min; + + ? ? freq_Hz = calc_frequency_khz(target_freq, relation) * 1000; +
[snip]
Quoted 19 lines
Quoted 19 lines
Review
Quoted 8 lines
+ ? ? /* Set the current working point. */
+ ? ?cpu_wp_tbl=get_cpu_wp(&cpu_wp_nr);(quoted diff) +6
-0+ + ? ? cpu_freq_khz_min = cpu_wp_tbl[0].cpu_rate / 1000; + ? ? cpu_freq_khz_max = cpu_wp_tbl[0].cpu_rate / 1000; + + ? ? for (i = 0; i < cpu_wp_nr; i++) { + ? ? ? ? ? ? imx_freq_table[cpu_wp_nr - 1 - i].index = cpu_wp_nr - i;
cpu_wp_nr= 2 here1st iteration of for loop:
? ?imx_freq_table[2 - 1 - 0].index = 2 - 0
so, imx_freq_table[1].index = 22nd iteration:
? ?imx_freq_table[2 - 1 - 1].index = 2 - 1
? ?imx_freq_table[0].index = 1
Quoted 7 lines
Quoted 3 lines
So you're trying to reverse the table order? Why not just sort the table date
in the way you want and add a comment on the top to keep it sorted.Yong: my understanding is that the freq table defined in another file is sorted in descending order, so the writer tends to make
imx_freq_tablein a descending order.
Just change the order of the wp_table instead of this confusing math to re-sort it. Look at other cpufreq rate tables in the kernel.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
+ ? ? ? ? ? ? imx_freq_table[cpu_wp_nr - 1 - i].frequency =
+ ? ? ? ? ? ? ? ? cpu_wp_tbl[i].cpu_rate / 1000;(quoted diff) +4
-0+ + ? ? ? ? ? ? if ((cpu_wp_tbl[i].cpu_rate / 1000) < cpu_freq_khz_min) + ? ? ? ? ? ? ? ? ? ? cpu_freq_khz_min = cpu_wp_tbl[i].cpu_rate / 1000; +
PATCH 1/1 cpufreq for freescale mx51
In reply to Amit KucheriaQuoted 55 lines · Amit Kucheria
Add'ed linaro-dev and linux-arm-kernel to CC.
Thanks Yong, some feeback follows inline.
Quoted 50 lines · Yong Shen
From: Yong Shen <[email protected]>
--- arch/arm/Kconfig | 6 + arch/arm/mach-mx5/Kconfig | 1 + arch/arm/mach-mx5/board-mx51_babbage.c | 32 ++++ arch/arm/mach-mx5/clock-mx51.c | 53 ++++++ arch/arm/plat-mxc/Makefile | 2 + arch/arm/plat-mxc/cpufreq.c | 282 ++++++++++++++++++++++++++++++++ arch/arm/plat-mxc/include/mach/mxc.h | 20 +++ 7 files changed, 396 insertions(+), 0 deletions(-) create mode 100644 arch/arm/plat-mxc/cpufreq.carch/arm/Kconfig +6
-0@@ -1517,6 +1517,12 @@ if ARCH_HAS_CPUFREQ source "drivers/cpufreq/Kconfig" +config CPU_FREQ_IMX + tristate "CPUfreq driver for i.MX CPUs" + depends on ARCH_MXC && CPU_FREQ + help + This enables the CPUfreq driver for i.MX CPUs. + config CPU_FREQ_SA1100 boolarch/arm/mach-mx5/Kconfig +1
-0@@ -5,6 +5,7 @@ config ARCH_MX51 default y select MXC_TZIC select ARCH_MXC_IOMUX_V3 + select ARCH_HAS_CPUFREQ comment "MX5 platforms:"arch/arm/mach-mx5/board-mx51_babbage.c +0
-0@@ -43,6 +43,31 @@#define MX51_USB_PLL_DIV_19_2_MHZ 0x01#define MX51_USB_PLL_DIV_24_MHZ 0x02
Quoted 1 line
arch/arm/mach-mx5/board-mx51_babbage.c line 46
Quoted 1 line
arch/arm/mach-mx5/board-mx51_babbage.c +1
-0+struct cpu_wp *(*get_cpu_wp)(int *wp);
This should be moved to a generic place, otherwise it breaks the build when multiple boards are selected.
Quoted 38 lines
arch/arm/mach-mx5/board-mx51_babbage.c line 47
Quoted 1 line
arch/arm/mach-mx5/board-mx51_babbage.c +1
-0+static int num_cpu_wp =2 ;use sizeof(array) instead of hard coding this.
Quoted 11 lines
arch/arm/mach-mx5/board-mx51_babbage.c +11
-0+/* working point(wp): 0 - 800MHz; 1 - 166.25MHz; */ +static struct cpu_wp cpu_wp_auto[] = { + { + .pll_rate =800000000 , + .cpu_rate =800000000 , + .pdf =0 , + .mfi =8 , + .mfd =2 , + .mfn =1 , + .cpu_podf =0 , + .cpu_voltage =1100000 ,},arch/arm/mach-mx5/board-mx51_babbage.c line 68
Quoted 10 lines
arch/arm/mach-mx5/board-mx51_babbage.c +10
-0+ { + .pll_rate = 800000000, + .cpu_rate = 160000000, + .pdf = 4, + .mfi = 8, + .mfd = 2, + .mfn = 1, + .cpu_podf = 4, + .cpu_voltage = 850000,}, +};This data should be moved out to a separate file (e.g.
mx51_ratetable.h) since it will be useful to other boards too.If other boards can have different rate tables (and they can, depending on the revision of the silicon), then we can either 'assemble' the correct rate table based on a flag field or have explicit separate rate tables for each silicon revision.
In any case, I suspect that there will be some core rates that will be common across silicon revisions.
Quoted 8 lines
arch/arm/mach-mx5/board-mx51_babbage.c static struct imxuart_platform_data uart_pdata = { · line 115
Quoted 8 lines
arch/arm/mach-mx5/board-mx51_babbage.c +1
-0static struct platform_device *devices[]__initdata = { &mxc_fec_device, };@@ -87,6 +112,12 @@ static struct imxuart_platform_data uart_pdata = { .flags = IMXUART_HAVE_RTSCTS, }; +struct cpu_wp *mx51_babbage_get_cpu_wp (int *wp)
static
Quoted 10 lines
Quoted 10 lines
arch/arm/mach-mx5/board-mx51_babbage.c +5
-0+{ + *wp = num_cpu_wp; +return cpu_wp_auto; +} +static inline void mxc_init_imx_uart (void ) {mxc_register_device (&mxc_uart_device0, &uart_pdata);@@ -246,6 +277,7 @@ static void __init mxc_board_init(void)
Quoted 3 lines
arch/arm/mach-mx5/board-mx51_babbage.c static void __init mxc_board_init(void) · line 280
Quoted 3 lines
arch/arm/mach-mx5/board-mx51_babbage.c +1
-0static void __init mx51_babbage_timer_init (void ) { + get_cpu_wp = mx51_babbage_get_cpu_wp;
It looks strange to have a global function pointer which gets overwritten by the boards. I would expect a
imx_add_cpu_workpoints(cpu_wp_auto, ARRAY_SIZE(cpu_wp_auto));
here.
Quoted 12 lines
arch/arm/mach-mx5/clock-mx51.c line 17
Quoted 12 lines
arch/arm/mach-mx5/board-mx51_babbage.c +0
-0mx51_clocks_init (32768 ,24000000 ,22579200 ,0 ); }arch/arm/mach-mx5/clock-mx51.c +1
-0@@ -14,6 +14,7 @@#include <linux/delay.h> #include <linux/clk.h> #include <linux/io.h> +#include <linux/time.h>
unneeded include
Quoted 21 lines
Quoted 21 lines
arch/arm/mach-mx5/clock-mx51.c +6
-0#include <asm/clkdev.h> #include <asm/div64.h> @@ -28,6 +29,11 @@static unsigned long external_high_reference, external_low_reference;static unsigned long oscillator_reference, ckih2_reference; +extern struct cpu_wp *(*get_cpu_wp)(int *wp); +static int cpu_wp_nr; +static int cpu_curr_wp; +static struct cpu_wp *cpu_wp_tbl; +static struct clk osc_clk;static struct clk pll1_main_clk;static struct clk pll1_sw_clk;@@ -38,7 +44,9 @@ static struct clk periph_apm_clk;static struct clk ahb_clk;static struct clk ipg_clk;static struct clk usboh3_clk; +static void __iomem *pll1_base;
Quoted 1 line
arch/arm/mach-mx5/clock-mx51.c static struct clk periph_apm_clk; · line 49
Quoted 1 line
arch/arm/mach-mx5/clock-mx51.c +1
-0+#define SPIN_DELAY 1000000/* in nanoseconds */
unused
Quoted 7 lines
Quoted 7 lines
arch/arm/mach-mx5/clock-mx51.c +0
-0#define MAX_DPLL_WAIT_TRIES 1000/* 1000 * udelay(1) = 1ms */ static int _clk_ccgr_enable (struct clk *clk)@@ -330,6 +338,32 @@ static int _clk_lp_apm_set_parent(struct clk *clk, struct clk *parent)return 0 ; }
Quoted 6 lines
arch/arm/mach-mx5/clock-mx51.c static int _clk_lp_apm_set_parent(struct clk *clk, struct clk *parent) · line 346
Quoted 6 lines
arch/arm/mach-mx5/clock-mx51.c +6
-0+/*! +* Setup cpu clock based on working point. +* @param wp cpu freq working point +* @return 0 on success or error code on failure. +*/ +int cpu_clk_set_wp (int wp)
static
Quoted 7 lines
Quoted 7 lines
arch/arm/mach-mx5/clock-mx51.c +7
-0+{ +struct cpu_wp *p; +u32 reg; + +if (wp == cpu_curr_wp) +return 0 ; +
Quoted 8 lines
arch/arm/mach-mx5/clock-mx51.c static int _clk_lp_apm_set_parent(struct clk *clk, struct clk *parent) · line 361
Quoted 8 lines
arch/arm/mach-mx5/clock-mx51.c +8
-0+ p = &cpu_wp_tbl[wp]; + +/*use post divider to change freq +*/ + reg =__raw_readl (MXC_CCM_CACRR ); + reg &= ~MXC_CCM_CACRR_ARM_PODF_MASK ; + reg |= cpu_wp_tbl[wp].cpu_podf <<MXC_CCM_CACRR_ARM_PODF_OFFSET ; +__raw_writel (reg,MXC_CCM_CACRR );
We have a simple divider here. Why do we need a reference to struct cpu_wp then? This code could look much simpler.
(side note: I'm aware that the original Freescale code is also able to change the cpu frequency using the pll instead of the divider, but is this really necessary?)
Quoted 44 lines
Quoted 44 lines
arch/arm/mach-mx5/clock-mx51.c +21
-0+ cpu_curr_wp = wp; + +return 0 ; +} +static unsigned long clk_arm_get_rate (struct clk *clk) {u32 cacrr, div;@@ -342,6 +376,20 @@ static unsigned long clk_arm_get_rate(struct clk *clk)return parent_rate / div; } +int _clk_cpu_set_rate (struct clk *clk,unsigned long rate) +{ +u32 i; +for (i =0 ; i < cpu_wp_nr; i++) { +if (rate == cpu_wp_tbl[i].cpu_rate) +break ; + } +if (i >= cpu_wp_nr) +return -EINVAL ; +cpu_clk_set_wp (i); + +return 0 ; +} +static int _clk_periph_apm_set_parent (struct clk *clk,struct clk *parent) {u32 reg, mux;@@ -694,6 +742,7 @@ static struct clk periph_apm_clk = {static struct clk cpu_clk = { .parent = &pll1_sw_clk, .get_rate = clk_arm_get_rate, + .set_rate = _clk_cpu_set_rate, };static struct clk ahb_clk = {@@ -821,6 +870,7 @@ static struct clk_lookup lookups[] = { _REGISTER_CLOCK("mxc-ehci.1", "usb_ahb", ahb_clk) _REGISTER_CLOCK("fsl-usb2-udc", "usb", usboh3_clk) _REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", ahb_clk) + _REGISTER_CLOCK(NULL, "cpu_clk", cpu_clk) };
Quoted 7 lines
arch/arm/mach-mx5/clock-mx51.c int __init mx51_clocks_init(unsigned long ckil, unsigned long osc, · line 902
Quoted 7 lines
arch/arm/mach-mx5/clock-mx51.c +2
-0static void clk_tree_init (void )@@ -848,10 +898,13 @@ int __init mx51_clocks_init(unsigned long ckil, unsigned long osc, {int i; + pll1_base =ioremap (MX51_PLL1_BASE_ADDR ,SZ_4K ); +
this is unused.
Quoted 69 lines
Quoted 40 lines
arch/arm/mach-mx5/clock-mx51.c +1
-0external_low_reference = ckil; external_high_reference = ckih1; ckih2_reference = ckih2; oscillator_reference = osc; + cpu_wp_tbl =get_cpu_wp (&cpu_wp_nr);for (i =0 ; i <ARRAY_SIZE (lookups); i++)clkdev_add (&lookups[i]);arch/arm/plat-mxc/Makefile +2
-0@@ -17,6 +17,8 @@ obj-$(CONFIG_USB_EHCI_MXC) += ehci.o obj-$(CONFIG_MXC_ULPI) += ulpi.o obj-$(CONFIG_ARCH_MXC_AUDMUX_V1) += audmux-v1.o obj-$(CONFIG_ARCH_MXC_AUDMUX_V2) += audmux-v2.o +# CPU FREQ support +obj-$(CONFIG_CPU_FREQ_IMX) += cpufreq.o ifdef CONFIG_SND_IMX_SOC obj-y += ssi-fiq.o obj-y += ssi-fiq-ksym.oarch/arm/plat-mxc/cpufreq.c new file +13
-0@@ -0,0 +1,282 @@ +/* +* Copyright (C) 2010 Freescale Semiconductor, Inc. All Rights Reserved. +*/ + +/* +* 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 +* http://www.gnu.org/copyleft/gpl.html +*/ +arch/arm/plat-mxc/cpufreq.c line 23
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+/*! +* @file cpufreq.c +* +* @brief A driver for the Freescale Semiconductor i.MXC CPUfreq module. +* +* The CPUFREQ driver is for controling CPU frequency. It allows you to change +* the CPU clock speed on the fly. +* +* @ingroup PM +*/ Fix these comments to follow the kernel commenting style.
Quoted 16 lines
arch/arm/plat-mxc/cpufreq.c new file +16
-0+#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/cpufreq.h> +#include <linux/init.h> +#include <linux/proc_fs.h> +#include <linux/regulator/consumer.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <mach/hardware.h> +#include <asm/setup.h> +#include <mach/clock.h> +#include <asm/cacheflush.h> +#include <linux/hrtimer.h> + +int cpu_freq_khz_min;
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c line 47
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c new file +8
-0+int cpu_freq_khz_max; +int arm_lpm_clk; +int arm_normal_clk; +int cpufreq_suspended; +int cpufreq_trig_needed; + +static struct clk *cpu_clk; +static struct cpufreq_frequency_table imx_freq_table[4 ];
Three frequencies should be enough for everyone, right? This should be dynamically allocated like in other cpufreq drivers.
Quoted 4 lines
arch/arm/plat-mxc/cpufreq.c line 51
Quoted 4 lines
arch/arm/plat-mxc/cpufreq.c new file +4
-0+ +extern int set_low_bus_freq (void ); +extern int set_high_bus_freq (int high_bus_speed); +extern int low_freq_bus_used (void );
declared but never used.
Quoted 22 lines
Quoted 22 lines
arch/arm/plat-mxc/cpufreq.c new file +22
-0+ +extern struct cpu_wp *(*get_cpu_wp)(int *wp); +static int cpu_wp_nr; +static struct cpu_wp *cpu_wp_tbl; + +int set_cpu_freq (int freq) +{ +int ret =0 ; +int org_cpu_rate; +int gp_volt =0 ; +int i; + + org_cpu_rate =clk_get_rate (cpu_clk); +if (org_cpu_rate == freq) +return ret; + +for (i =0 ; i < cpu_wp_nr; i++) { +if (freq == cpu_wp_tbl[i].cpu_rate) + gp_volt = cpu_wp_tbl[i].cpu_voltage; + } + +if (gp_volt ==0 )
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c line 81
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c new file +8
-0+return ret; + + ret =clk_set_rate (cpu_clk, freq); +if (ret !=0 ) { +printk (KERN_DEBUG "cannot set CPU clock rate\n" ); +return ret; + } +
Please remove trailing whitespaces.
Quoted 29 lines
Quoted 29 lines
arch/arm/plat-mxc/cpufreq.c new file +29
-0+return ret; +} + +static int mxc_verify_speed (struct cpufreq_policy *policy) +{ +if (policy->cpu !=0 ) +return -EINVAL ; + +return cpufreq_frequency_table_verify (policy, imx_freq_table); +} + +static unsigned int mxc_get_speed (unsigned int cpu) +{ +if (cpu) +return 0 ; + +return clk_get_rate (cpu_clk) /1000 ; +} + +static int calc_frequency_khz (int target,unsigned int relation) +{ +int i; + +if ((target *1000 ) ==clk_get_rate (cpu_clk)) +return target; + +if (relation ==CPUFREQ_RELATION_H ) { +for (i = cpu_wp_nr -1 ; i >=0 ; i--) { +if (imx_freq_table[i].frequency <= target)
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c line 118
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c new file +8
-0+return imx_freq_table[i].frequency; + } + }else if (relation ==CPUFREQ_RELATION_L ) { +for (i =0 ; i < cpu_wp_nr; i++) { +if (imx_freq_table[i].frequency >= target) +return imx_freq_table[i].frequency; + } + }
It looks like cpufreq_frequency_table_target could help here.
Quoted 236 lines
Quoted 21 lines
arch/arm/plat-mxc/cpufreq.c new file +21
-0+printk (KERN_ERR "Error: No valid cpufreq relation\n" ); +return cpu_freq_khz_max; +} + +static int mxc_set_target (struct cpufreq_policy *policy, +unsigned int target_freq,unsigned int relation) +{ +struct cpufreq_freqs freqs; +int freq_Hz; +int ret =0 ; + +if (cpufreq_suspended) { + target_freq =clk_get_rate (cpu_clk) /1000 ; + freq_Hz =calc_frequency_khz (target_freq, relation) *1000 ; +if (freq_Hz == arm_lpm_clk) + freqs.old = cpu_wp_tbl[cpu_wp_nr -2 ].cpu_rate /1000 ; +else + freqs.old = arm_lpm_clk /1000 ; + + freqs.new = freq_Hz /1000 ; + freqs.cpu =0 ;arch/arm/plat-mxc/cpufreq.c line 149
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+ freqs.flags =0 ; +cpufreq_notify_transition (&freqs,CPUFREQ_PRECHANGE ); +cpufreq_notify_transition (&freqs,CPUFREQ_POSTCHANGE ); +return ret; + } +/* +* Some governors do not respects CPU and policy lower limits +* which leads to bad things (division by zero etc), ensure +* that such things do not happen. +*/ Isn't that a bug in the governor? Can you explain a bit?
Quoted 36 lines
arch/arm/plat-mxc/cpufreq.c new file +36
-0+if (target_freq < policy->cpuinfo.min_freq) + target_freq = policy->cpuinfo.min_freq; + +if (target_freq < policy->min) + target_freq = policy->min; + + freq_Hz =calc_frequency_khz (target_freq, relation) *1000 ; + + freqs.old =clk_get_rate (cpu_clk) /1000 ; + freqs.new = freq_Hz /1000 ; + freqs.cpu =0 ; + freqs.flags =0 ; +cpufreq_notify_transition (&freqs,CPUFREQ_PRECHANGE ); + +if (freqs.old != freqs.new) + ret =set_cpu_freq (freq_Hz); + +cpufreq_notify_transition (&freqs,CPUFREQ_POSTCHANGE ); + +return ret; +} + +static int __init mxc_cpufreq_driver_init (struct cpufreq_policy *policy) +{ +int ret; +int i; + +printk (KERN_INFO "i.MXC CPU frequency driver\n" ); + +if (policy->cpu !=0 ) +return -EINVAL ; + + cpu_clk =clk_get (NULL ,"cpu_clk" ); +if (IS_ERR (cpu_clk)) { +printk (KERN_ERR "%s: failed to get cpu clock\n" , __func__); +return PTR_ERR (cpu_clk);arch/arm/plat-mxc/cpufreq.c line 195
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+ } + +/* Set the current working point. */ + cpu_wp_tbl =get_cpu_wp (&cpu_wp_nr); + + cpu_freq_khz_min = cpu_wp_tbl[0 ].cpu_rate /1000 ; + cpu_freq_khz_max = cpu_wp_tbl[0 ].cpu_rate /1000 ; + +for (i =0 ; i < cpu_wp_nr; i++) { + imx_freq_table[cpu_wp_nr -1 - i].index = cpu_wp_nr - i;
cpu_wp_nr= 2 here1st iteration of for loop:
imx_freq_table[2 - 1 - 0].index = 2 - 0so, imx_freq_table[1].index = 2
2nd iteration:
imx_freq_table[2 - 1 - 1].index = 2 - 1 imx_freq_table[0].index = 1So you're trying to reverse the table order? Why not just sort the table date in the way you want and add a comment on the top to keep it sorted.
arch/arm/plat-mxc/cpufreq.c line 206
Quoted 11 lines
arch/arm/plat-mxc/cpufreq.c new file +11
-0+ imx_freq_table[cpu_wp_nr -1 - i].frequency = + cpu_wp_tbl[i].cpu_rate /1000 ; + +if ((cpu_wp_tbl[i].cpu_rate /1000 ) < cpu_freq_khz_min) + cpu_freq_khz_min = cpu_wp_tbl[i].cpu_rate /1000 ; + +if ((cpu_wp_tbl[i].cpu_rate /1000 ) > cpu_freq_khz_max) + cpu_freq_khz_max = cpu_wp_tbl[i].cpu_rate /1000 ; + } + + imx_freq_table[i].index =0 ;imx_freq_table[i].index = i ?
Quoted 21 lines
arch/arm/plat-mxc/cpufreq.c new file +21
-0+ imx_freq_table[i].frequency =CPUFREQ_TABLE_END ; + + policy->cur =clk_get_rate (cpu_clk) /1000 ; + policy->governor =CPUFREQ_DEFAULT_GOVERNOR ; + policy->min = policy->cpuinfo.min_freq = cpu_freq_khz_min; + policy->max = policy->cpuinfo.max_freq = cpu_freq_khz_max; + + arm_lpm_clk = cpu_freq_khz_min *1000 ; + arm_normal_clk = cpu_freq_khz_max *1000 ; + +/* Manual states, that PLL stabilizes in two CLK32 periods */ + policy->cpuinfo.transition_latency =10 ; + + ret =cpufreq_frequency_table_cpuinfo (policy, imx_freq_table); + +if (ret <0 ) { +clk_put (cpu_clk); +printk (KERN_ERR "%s: failed to register i.MXC CPUfreq\n" , + __func__); +return ret; + }arch/arm/plat-mxc/cpufreq.c line 237
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+ +cpufreq_frequency_table_get_attr (imx_freq_table, policy->cpu); +return 0 ; +} + +static int mxc_cpufreq_suspend (struct cpufreq_policy *policy, +pm_message_t state) +{ +return 0 ; +}Get rid of these, since you don't use them.
arch/arm/plat-mxc/cpufreq.c line 241
Quoted 4 lines
arch/arm/plat-mxc/cpufreq.c new file +4
-0+static int mxc_cpufreq_resume (struct cpufreq_policy *policy) +{ +return 0 ; +}Same here.
Quoted 6 lines
arch/arm/plat-mxc/cpufreq.c new file +6
-0+static int mxc_cpufreq_driver_exit (struct cpufreq_policy *policy) +{ +cpufreq_frequency_table_put_attr (policy->cpu); + +/* Reset CPU to 665MHz */ +set_cpu_freq (arm_normal_clk);arch/arm/plat-mxc/cpufreq.c line 257
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+clk_put (cpu_clk); +return 0 ; +} + +static struct cpufreq_driver mxc_driver = { + .flags =CPUFREQ_STICKY , + .verify = mxc_verify_speed, + .target = mxc_set_target, + .get = mxc_get_speed, + .init = mxc_cpufreq_driver_init,
mxc_cpufreq_initis ok. Lose the driver.arch/arm/plat-mxc/cpufreq.c line 258
Quoted 1 line
arch/arm/plat-mxc/cpufreq.c new file +1
-0+ .exit = mxc_cpufreq_driver_exit,same.
arch/arm/plat-mxc/cpufreq.c line 260
Quoted 2 lines
arch/arm/plat-mxc/cpufreq.c new file +2
-0+ .suspend = mxc_cpufreq_suspend, + .resume = mxc_cpufreq_resume,Get rid of suspend/resume
Quoted 53 lines
arch/arm/plat-mxc/cpufreq.c new file +19
-0+ .name = "imx", +}; + +static int __devinit mxc_cpufreq_init (void ) +{ +return cpufreq_register_driver (&mxc_driver); +} + +static void mxc_cpufreq_exit (void ) +{ +cpufreq_unregister_driver (&mxc_driver); +} + +module_init (mxc_cpufreq_init); +module_exit (mxc_cpufreq_exit); + +MODULE_AUTHOR ("Freescale Semiconductor, Inc." ); +MODULE_DESCRIPTION ("CPUfreq driver for i.MX" ); +MODULE_LICENSE ("GPL" );arch/arm/plat-mxc/include/mach/mxc.h +20
-0@@ -133,6 +133,26 @@ extern unsigned int __mxc_cpu_type;# define cpu_is_mxc91231 () (0)#endif +#ifndef __ASSEMBLY__ + +struct cpu_wp { +u32 pll_reg; +u32 pll_rate; +u32 cpu_rate; +u32 pdr0_reg; +u32 pdf; +u32 mfi; +u32 mfd; +u32 mfn; +u32 cpu_voltage; +u32 cpu_podf; +}; + +#ifndef CONFIG_ARCH_MX5 +struct cpu_wp *get_cpu_wp (int *wp); +#endif +#endif +#if defined(CONFIG_ARCH_MX3 ) || defined(CONFIG_ARCH_MX2 )/* These are deprecated, use mx[23][157]_setup_weimcs instead. */ #define CSCR_U (n) (IO_ADDRESS(WEIM_BASE_ADDR + n * 0x10))Signature · 1 line
1.6.3.3_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH 1/1 cpufreq for freescale mx51
Hi Sascha,
Thanks for your thorough comments.
I have already received comments from Arnd before yours arrived. So some of the commends you two provided are common.
I acknowledge most of your opinions, except for two, I have some explanations.
Quoted 6 lines
Quoted 5 lines
+ */
Quoted 4 lines
(quoted diff) +4
-0+ reg = __raw_readl(MXC_CCM_CACRR); + reg &= ~MXC_CCM_CACRR_ARM_PODF_MASK; + reg |= cpu_wp_tbl[wp].cpu_podf << MXC_CCM_CACRR_ARM_PODF_OFFSET; + __raw_writel(reg, MXC_CCM_CACRR);
Quoted 7 lines
We have a simple divider here. Why do we need a reference to struct
cpu_wpthen? This code could look much simpler.(side note: I'm aware that the original Freescale code is also able to change the cpu frequency using the pll instead of the divider, but is this really necessary?)
Using wp_tbl is because that it also contains information like regulator voltage. Since the regulator driver for imx51 have not been upstreamed, you don't see any regulator operation here. Also, like you mentioned, there are two ways to change cpufreq, by post divider or pll change. And post divider change is a simpler way and also the only way for babbage, since cpu freq and ddr freq are all root from the same pll on babbage and they will interfere each other.
Quoted 5 lines
Quoted 1 line
+static struct
cpufreq_frequency_tableimx_freq_table[4];Three frequencies should be enough for everyone, right? This should be dynamically allocated like in other cpufreq drivers.
Yes, we only support 3 work points, which is for sure. Actually, we only support 2 points on most mx51 chips. I supposed it is ok to use static array here.
Thanks again for review. I will send out updated patch again.
Yong
Quoted 680 lines · Sascha Hauer
Quoted 14 lines · Amit Kucheria
Add'ed linaro-dev and linux-arm-kernel to CC.
Thanks Yong, some feeback follows inline.
Quoted 9 lines · Yong Shen
From: Yong Shen <[email protected]>
--- arch/arm/Kconfig | 6 + arch/arm/mach-mx5/Kconfig | 1 + arch/arm/mach-mx5/board-mx51_babbage.c | 32 ++++ arch/arm/mach-mx5/clock-mx51.c | 53 ++++++ arch/arm/plat-mxc/Makefile | 2 + arch/arm/plat-mxc/cpufreq.c | 282++++++++++++++++++++++++++++++++
Quoted 31 lines
Quoted 31 lines
arch/arm/plat-mxc/include/mach/mxc.h | 20 +++ 7 files changed, 396 insertions(+), 0 deletions(-) create mode 100644 arch/arm/plat-mxc/cpufreq.carch/arm/Kconfig +6
-0@@ -1517,6 +1517,12 @@ if ARCH_HAS_CPUFREQ source "drivers/cpufreq/Kconfig" +config CPU_FREQ_IMX + tristate "CPUfreq driver for i.MX CPUs" + depends on ARCH_MXC && CPU_FREQ + help + This enables the CPUfreq driver for i.MX CPUs. + config CPU_FREQ_SA1100 boolarch/arm/mach-mx5/Kconfig +1
-0@@ -5,6 +5,7 @@ config ARCH_MX51 default y select MXC_TZIC select ARCH_MXC_IOMUX_V3 + select ARCH_HAS_CPUFREQQuoted 3 lines
Review
Quoted 3 lines
arch/arm/mach-mx5/Kconfig +0
-0comment "MX5 platforms:"(quoted diff) +0
-0
b/arch/arm/mach-mx5/board-mx51_babbage.cQuoted 8 lines
arch/arm/mach-mx5/board-mx51_babbage.c line 46
Quoted 8 lines
index ed885f9..e449e0b 100644
arch/arm/mach-mx5/board-mx51_babbage.c +1
-0@@ -43,6 +43,31 @@#define MX51_USB_PLL_DIV_19_2_MHZ 0x01#define MX51_USB_PLL_DIV_24_MHZ 0x02 +struct cpu_wp *(*get_cpu_wp)(int *wp);This should be moved to a generic place, otherwise it breaks the build when multiple boards are selected.
Quoted 30 lines
arch/arm/mach-mx5/board-mx51_babbage.c line 47
Quoted 1 line
arch/arm/mach-mx5/board-mx51_babbage.c +1
-0+static int num_cpu_wp =2 ;use sizeof(array) instead of hard coding this.
Quoted 11 lines
arch/arm/mach-mx5/board-mx51_babbage.c +11
-0+/* working point(wp): 0 - 800MHz; 1 - 166.25MHz; */ +static struct cpu_wp cpu_wp_auto[] = { + { + .pll_rate =800000000 , + .cpu_rate =800000000 , + .pdf =0 , + .mfi =8 , + .mfd =2 , + .mfn =1 , + .cpu_podf =0 , + .cpu_voltage =1100000 ,},arch/arm/mach-mx5/board-mx51_babbage.c line 68
Quoted 10 lines
arch/arm/mach-mx5/board-mx51_babbage.c +10
-0+ { + .pll_rate = 800000000, + .cpu_rate = 160000000, + .pdf = 4, + .mfi = 8, + .mfd = 2, + .mfn = 1, + .cpu_podf = 4, + .cpu_voltage = 850000,}, +};This data should be moved out to a separate file (e.g.
mx51_ratetable.h) since it will be useful to other boards too.Quoted 1 line
If other boards can have different rate tables (and they can, depending
on
Quoted 1 line
the revision of the silicon), then we can either 'assemble' the correct
rate
Quoted 1 line
table based on a flag field or have explicit separate rate tables for
each
Quoted 3 lines
silicon revision.
In any case, I suspect that there will be some core rates that will be
common
Quoted 10 lines
across silicon revisions.
arch/arm/mach-mx5/board-mx51_babbage.c static struct imxuart_platform_data uart_pdata = { · line 115
Quoted 8 lines
arch/arm/mach-mx5/board-mx51_babbage.c +1
-0static struct platform_device *devices[]__initdata = { &mxc_fec_device, };@@ -87,6 +112,12 @@ static struct imxuart_platform_data uart_pdata = { .flags = IMXUART_HAVE_RTSCTS, }; +struct cpu_wp *mx51_babbage_get_cpu_wp (int *wp)static
Quoted 10 lines
Quoted 10 lines
arch/arm/mach-mx5/board-mx51_babbage.c +5
-0+{ + *wp = num_cpu_wp; +return cpu_wp_auto; +} +static inline void mxc_init_imx_uart (void ) {mxc_register_device (&mxc_uart_device0, &uart_pdata);@@ -246,6 +277,7 @@ static void __init mxc_board_init(void)Quoted 3 lines
arch/arm/mach-mx5/board-mx51_babbage.c static void __init mxc_board_init(void) · line 280
Quoted 3 lines
arch/arm/mach-mx5/board-mx51_babbage.c +1
-0static void __init mx51_babbage_timer_init (void ) { + get_cpu_wp = mx51_babbage_get_cpu_wp;It looks strange to have a global function pointer which gets overwritten by the boards. I would expect a
imx_add_cpu_workpoints(cpu_wp_auto, ARRAY_SIZE(cpu_wp_auto));here.
Quoted 4 lines
Review
Quoted 4 lines
arch/arm/mach-mx5/board-mx51_babbage.c +0
-0mx51_clocks_init (32768 ,24000000 ,22579200 ,0 ); }(quoted diff) +0
-0
b/arch/arm/mach-mx5/clock-mx51.cQuoted 8 lines
arch/arm/mach-mx5/clock-mx51.c line 17
Quoted 8 lines
index d9f612d..f2488e6 100644
arch/arm/mach-mx5/clock-mx51.c +1
-0@@ -14,6 +14,7 @@#include <linux/delay.h> #include <linux/clk.h> #include <linux/io.h> +#include <linux/time.h> unneeded include
Quoted 21 lines
Quoted 21 lines
arch/arm/mach-mx5/clock-mx51.c +6
-0#include <asm/clkdev.h> #include <asm/div64.h> @@ -28,6 +29,11 @@static unsigned long external_high_reference, external_low_reference;static unsigned long oscillator_reference, ckih2_reference; +extern struct cpu_wp *(*get_cpu_wp)(int *wp); +static int cpu_wp_nr; +static int cpu_curr_wp; +static struct cpu_wp *cpu_wp_tbl; +static struct clk osc_clk;static struct clk pll1_main_clk;static struct clk pll1_sw_clk;@@ -38,7 +44,9 @@ static struct clk periph_apm_clk;static struct clk ahb_clk;static struct clk ipg_clk;static struct clk usboh3_clk; +static void __iomem *pll1_base;Quoted 1 line
arch/arm/mach-mx5/clock-mx51.c static struct clk periph_apm_clk; · line 49
Quoted 1 line
arch/arm/mach-mx5/clock-mx51.c +1
-0+#define SPIN_DELAY 1000000/* in nanoseconds */ unused
Quoted 4 lines
arch/arm/mach-mx5/clock-mx51.c static int _clk_lp_apm_set_parent(struct clk *clk,
Quoted 4 lines
arch/arm/mach-mx5/clock-mx51.c +0
-0#define MAX_DPLL_WAIT_TRIES 1000/* 1000 * udelay(1) = 1ms */ static int _clk_ccgr_enable (struct clk *clk)@@ -330,6 +338,32 @@ static int _clk_lp_apm_set_parent(struct clk *clk,struct clk *parent)
Quoted 9 lines
arch/arm/mach-mx5/clock-mx51.c static int _clk_lp_apm_set_parent(struct clk *clk, · line 346
Quoted 9 lines
arch/arm/mach-mx5/clock-mx51.c +6
-0return 0 ; } +/*! +* Setup cpu clock based on working point. +* @param wp cpu freq working point +* @return 0 on success or error code on failure. +*/ +int cpu_clk_set_wp (int wp)static
Quoted 7 lines
Quoted 7 lines
arch/arm/mach-mx5/clock-mx51.c +7
-0+{ +struct cpu_wp *p; +u32 reg; + +if (wp == cpu_curr_wp) +return 0 ; +Quoted 8 lines
arch/arm/mach-mx5/clock-mx51.c static int _clk_lp_apm_set_parent(struct clk *clk, · line 361
Quoted 8 lines
arch/arm/mach-mx5/clock-mx51.c +8
-0+ p = &cpu_wp_tbl[wp]; + +/*use post divider to change freq +*/ + reg =__raw_readl (MXC_CCM_CACRR ); + reg &= ~MXC_CCM_CACRR_ARM_PODF_MASK ; + reg |= cpu_wp_tbl[wp].cpu_podf <<MXC_CCM_CACRR_ARM_PODF_OFFSET ; +__raw_writel (reg,MXC_CCM_CACRR );We have a simple divider here. Why do we need a reference to struct
cpu_wpthen? This code could look much simpler.(side note: I'm aware that the original Freescale code is also able to change the cpu frequency using the pll instead of the divider, but is this really necessary?)
Quoted 9 lines
arch/arm/mach-mx5/clock-mx51.c static unsigned long clk_arm_get_rate(struct clk
Quoted 9 lines
arch/arm/mach-mx5/clock-mx51.c +5
-0+ cpu_curr_wp = wp; + +return 0 ; +} +static unsigned long clk_arm_get_rate (struct clk *clk) {u32 cacrr, div;@@ -342,6 +376,20 @@ static unsigned long clk_arm_get_rate(struct clk*clk)
Quoted 18 lines
Quoted 8 lines
arch/arm/mach-mx5/clock-mx51.c +5
-0return parent_rate / div; } +int _clk_cpu_set_rate (struct clk *clk,unsigned long rate) +{ +u32 i; +for (i =0 ; i < cpu_wp_nr; i++) { +if (rate == cpu_wp_tbl[i].cpu_rate)arch/arm/mach-mx5/clock-mx51.c static unsigned long clk_arm_get_rate(struct clk · line 393
Quoted 10 lines
arch/arm/mach-mx5/clock-mx51.c +9
-0+break ; + } +if (i >= cpu_wp_nr) +return -EINVAL ; +cpu_clk_set_wp (i); + +return 0 ; +} + static int _clk_periph_apm_set_parent(struct clk *clk, struct clk*parent)
Quoted 17 lines
Quoted 17 lines
arch/arm/mach-mx5/clock-mx51.c +2
-0{u32 reg, mux;@@ -694,6 +742,7 @@ static struct clk periph_apm_clk = {static struct clk cpu_clk = { .parent = &pll1_sw_clk, .get_rate = clk_arm_get_rate, + .set_rate = _clk_cpu_set_rate, };static struct clk ahb_clk = {@@ -821,6 +870,7 @@ static struct clk_lookup lookups[] = { _REGISTER_CLOCK("mxc-ehci.1", "usb_ahb", ahb_clk) _REGISTER_CLOCK("fsl-usb2-udc", "usb", usboh3_clk) _REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", ahb_clk) + _REGISTER_CLOCK(NULL, "cpu_clk", cpu_clk) };Quoted 2 lines
arch/arm/mach-mx5/clock-mx51.c int __init mx51_clocks_init(unsigned long ckil,
Quoted 2 lines
arch/arm/mach-mx5/clock-mx51.c +0
-0static void clk_tree_init (void )@@ -848,10 +898,13 @@ int __init mx51_clocks_init(unsigned long ckil,unsigned long osc,
Quoted 5 lines
arch/arm/mach-mx5/clock-mx51.c int __init mx51_clocks_init(unsigned long ckil, · line 902
Quoted 5 lines
arch/arm/mach-mx5/clock-mx51.c +2
-0{int i; + pll1_base =ioremap (MX51_PLL1_BASE_ADDR ,SZ_4K ); +this is unused.
Quoted 21 lines
Quoted 21 lines
arch/arm/mach-mx5/clock-mx51.c +1
-0external_low_reference = ckil; external_high_reference = ckih1; ckih2_reference = ckih2; oscillator_reference = osc; + cpu_wp_tbl =get_cpu_wp (&cpu_wp_nr);for (i =0 ; i <ARRAY_SIZE (lookups); i++)clkdev_add (&lookups[i]);arch/arm/plat-mxc/Makefile +2
-0@@ -17,6 +17,8 @@ obj-$(CONFIG_USB_EHCI_MXC) += ehci.o obj-$(CONFIG_MXC_ULPI) += ulpi.o obj-$(CONFIG_ARCH_MXC_AUDMUX_V1) += audmux-v1.o obj-$(CONFIG_ARCH_MXC_AUDMUX_V2) += audmux-v2.o +# CPU FREQ support +obj-$(CONFIG_CPU_FREQ_IMX) += cpufreq.o ifdef CONFIG_SND_IMX_SOC obj-y += ssi-fiq.o obj-y += ssi-fiq-ksym.oQuoted 8 lines
arch/arm/plat-mxc/cpufreq.c line 2
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c new file +2
-0@@ -0,0 +1,282 @@ +/* +* Copyright (C) 2010 Freescale Semiconductor, Inc. All Rights Reserved.
Quoted 7 lines
Quoted 7 lines
arch/arm/plat-mxc/cpufreq.c new file +7
-0+*/ + +/* +* 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: +* Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c line 17
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c new file +8
-0+* http://www.opensource.org/licenses/gpl-license.html +* http://www.gnu.org/copyleft/gpl.html +*/ + +/*! +* @file cpufreq.c +* +* @brief A driver for the Freescale Semiconductor i.MXC CPUfreq module.
Quoted 2 lines
arch/arm/plat-mxc/cpufreq.c line 19
Quoted 2 lines
arch/arm/plat-mxc/cpufreq.c new file +2
-0+* +* The CPUFREQ driver is for controling CPU frequency. It allows you to change
Quoted 23 lines
arch/arm/plat-mxc/cpufreq.c line 23
Quoted 4 lines
arch/arm/plat-mxc/cpufreq.c new file +4
-0+* the CPU clock speed on the fly. +* +* @ingroup PM +*/ Fix these comments to follow the kernel commenting style.
Quoted 16 lines
arch/arm/plat-mxc/cpufreq.c new file +16
-0+#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/cpufreq.h> +#include <linux/init.h> +#include <linux/proc_fs.h> +#include <linux/regulator/consumer.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <mach/hardware.h> +#include <asm/setup.h> +#include <mach/clock.h> +#include <asm/cacheflush.h> +#include <linux/hrtimer.h> + +int cpu_freq_khz_min;Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c line 47
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c new file +8
-0+int cpu_freq_khz_max; +int arm_lpm_clk; +int arm_normal_clk; +int cpufreq_suspended; +int cpufreq_trig_needed; + +static struct clk *cpu_clk; +static struct cpufreq_frequency_table imx_freq_table[4 ];Three frequencies should be enough for everyone, right? This should be dynamically allocated like in other cpufreq drivers.
Quoted 4 lines
arch/arm/plat-mxc/cpufreq.c line 51
Quoted 4 lines
arch/arm/plat-mxc/cpufreq.c new file +4
-0+ +extern int set_low_bus_freq (void ); +extern int set_high_bus_freq (int high_bus_speed); +extern int low_freq_bus_used (void );declared but never used.
Quoted 22 lines
Quoted 22 lines
arch/arm/plat-mxc/cpufreq.c new file +22
-0+ +extern struct cpu_wp *(*get_cpu_wp)(int *wp); +static int cpu_wp_nr; +static struct cpu_wp *cpu_wp_tbl; + +int set_cpu_freq (int freq) +{ +int ret =0 ; +int org_cpu_rate; +int gp_volt =0 ; +int i; + + org_cpu_rate =clk_get_rate (cpu_clk); +if (org_cpu_rate == freq) +return ret; + +for (i =0 ; i < cpu_wp_nr; i++) { +if (freq == cpu_wp_tbl[i].cpu_rate) + gp_volt = cpu_wp_tbl[i].cpu_voltage; + } + +if (gp_volt ==0 )Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c line 81
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c new file +8
-0+return ret; + + ret =clk_set_rate (cpu_clk, freq); +if (ret !=0 ) { +printk (KERN_DEBUG "cannot set CPU clock rate\n" ); +return ret; + } +Please remove trailing whitespaces.
Quoted 29 lines
Quoted 29 lines
arch/arm/plat-mxc/cpufreq.c new file +29
-0+return ret; +} + +static int mxc_verify_speed (struct cpufreq_policy *policy) +{ +if (policy->cpu !=0 ) +return -EINVAL ; + +return cpufreq_frequency_table_verify (policy, imx_freq_table); +} + +static unsigned int mxc_get_speed (unsigned int cpu) +{ +if (cpu) +return 0 ; + +return clk_get_rate (cpu_clk) /1000 ; +} + +static int calc_frequency_khz (int target,unsigned int relation) +{ +int i; + +if ((target *1000 ) ==clk_get_rate (cpu_clk)) +return target; + +if (relation ==CPUFREQ_RELATION_H ) { +for (i = cpu_wp_nr -1 ; i >=0 ; i--) { +if (imx_freq_table[i].frequency <= target)Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c line 118
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c new file +8
-0+return imx_freq_table[i].frequency; + } + }else if (relation ==CPUFREQ_RELATION_L ) { +for (i =0 ; i < cpu_wp_nr; i++) { +if (imx_freq_table[i].frequency >= target) +return imx_freq_table[i].frequency; + } + }It looks like
cpufreq_frequency_table_targetcould help here.Quoted 8 lines
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c new file +8
-0+printk (KERN_ERR "Error: No valid cpufreq relation\n" ); +return cpu_freq_khz_max; +} + +static int mxc_set_target (struct cpufreq_policy *policy, +unsigned int target_freq,unsigned int relation) +{ +struct cpufreq_freqs freqs;Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c line 134
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c new file +8
-0+int freq_Hz; +int ret =0 ; + +if (cpufreq_suspended) { + target_freq =clk_get_rate (cpu_clk) /1000 ; + freq_Hz =calc_frequency_khz (target_freq, relation) *1000 ; +if (freq_Hz == arm_lpm_clk) + freqs.old = cpu_wp_tbl[cpu_wp_nr - 2].cpu_rate /1000;
Quoted 33 lines
Quoted 5 lines
arch/arm/plat-mxc/cpufreq.c new file +5
-0+else + freqs.old = arm_lpm_clk /1000 ; + + freqs.new = freq_Hz /1000 ; + freqs.cpu =0 ;arch/arm/plat-mxc/cpufreq.c line 149
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+ freqs.flags =0 ; +cpufreq_notify_transition (&freqs,CPUFREQ_PRECHANGE ); +cpufreq_notify_transition (&freqs,CPUFREQ_POSTCHANGE ); +return ret; + } +/* +* Some governors do not respects CPU and policy lower limits +* which leads to bad things (division by zero etc), ensure +* that such things do not happen. +*/ Isn't that a bug in the governor? Can you explain a bit?
Quoted 15 lines
arch/arm/plat-mxc/cpufreq.c new file +15
-0+if (target_freq < policy->cpuinfo.min_freq) + target_freq = policy->cpuinfo.min_freq; + +if (target_freq < policy->min) + target_freq = policy->min; + + freq_Hz =calc_frequency_khz (target_freq, relation) *1000 ; + + freqs.old =clk_get_rate (cpu_clk) /1000 ; + freqs.new = freq_Hz /1000 ; + freqs.cpu =0 ; + freqs.flags =0 ; +cpufreq_notify_transition (&freqs,CPUFREQ_PRECHANGE ); + +if (freqs.old != freqs.new)Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c line 172
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c new file +8
-0+ ret =set_cpu_freq (freq_Hz); + +cpufreq_notify_transition (&freqs,CPUFREQ_POSTCHANGE ); + +return ret; +} + +static int __init mxc_cpufreq_driver_init(struct cpufreq_policy*policy)
Quoted 27 lines
Quoted 13 lines
arch/arm/plat-mxc/cpufreq.c new file +13
-0+{ +int ret; +int i; + +printk (KERN_INFO "i.MXC CPU frequency driver\n" ); + +if (policy->cpu !=0 ) +return -EINVAL ; + + cpu_clk =clk_get (NULL ,"cpu_clk" ); +if (IS_ERR (cpu_clk)) { +printk (KERN_ERR "%s: failed to get cpu clock\n" , __func__); +return PTR_ERR (cpu_clk);arch/arm/plat-mxc/cpufreq.c line 195
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+ } + +/* Set the current working point. */ + cpu_wp_tbl =get_cpu_wp (&cpu_wp_nr); + + cpu_freq_khz_min = cpu_wp_tbl[0 ].cpu_rate /1000 ; + cpu_freq_khz_max = cpu_wp_tbl[0 ].cpu_rate /1000 ; + +for (i =0 ; i < cpu_wp_nr; i++) { + imx_freq_table[cpu_wp_nr -1 - i].index = cpu_wp_nr - i;
cpu_wp_nr= 2 here1st iteration of for loop:
Quoted 8 lines
imx_freq_table[2 - 1 - 0].index = 2 - 0so, imx_freq_table[1].index = 2
2nd iteration:
imx_freq_table[2 - 1 - 1].index = 2 - 1 imx_freq_table[0].index = 1So you're trying to reverse the table order? Why not just sort the table
date
Quoted 97 lines
in the way you want and add a comment on the top to keep it sorted.
arch/arm/plat-mxc/cpufreq.c line 206
Quoted 11 lines
arch/arm/plat-mxc/cpufreq.c new file +11
-0+ imx_freq_table[cpu_wp_nr -1 - i].frequency = + cpu_wp_tbl[i].cpu_rate /1000 ; + +if ((cpu_wp_tbl[i].cpu_rate /1000 ) < cpu_freq_khz_min) + cpu_freq_khz_min = cpu_wp_tbl[i].cpu_rate /1000 ; + +if ((cpu_wp_tbl[i].cpu_rate /1000 ) > cpu_freq_khz_max) + cpu_freq_khz_max = cpu_wp_tbl[i].cpu_rate /1000 ; + } + + imx_freq_table[i].index =0 ;imx_freq_table[i].index = i ?
Quoted 21 lines
arch/arm/plat-mxc/cpufreq.c new file +21
-0+ imx_freq_table[i].frequency =CPUFREQ_TABLE_END ; + + policy->cur =clk_get_rate (cpu_clk) /1000 ; + policy->governor =CPUFREQ_DEFAULT_GOVERNOR ; + policy->min = policy->cpuinfo.min_freq = cpu_freq_khz_min; + policy->max = policy->cpuinfo.max_freq = cpu_freq_khz_max; + + arm_lpm_clk = cpu_freq_khz_min *1000 ; + arm_normal_clk = cpu_freq_khz_max *1000 ; + +/* Manual states, that PLL stabilizes in two CLK32 periods */ + policy->cpuinfo.transition_latency =10 ; + + ret =cpufreq_frequency_table_cpuinfo (policy, imx_freq_table); + +if (ret <0 ) { +clk_put (cpu_clk); +printk (KERN_ERR "%s: failed to register i.MXC CPUfreq\n" , + __func__); +return ret; + }arch/arm/plat-mxc/cpufreq.c line 237
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+ +cpufreq_frequency_table_get_attr (imx_freq_table, policy->cpu); +return 0 ; +} + +static int mxc_cpufreq_suspend (struct cpufreq_policy *policy, +pm_message_t state) +{ +return 0 ; +}Get rid of these, since you don't use them.
arch/arm/plat-mxc/cpufreq.c line 241
Quoted 4 lines
arch/arm/plat-mxc/cpufreq.c new file +4
-0+static int mxc_cpufreq_resume (struct cpufreq_policy *policy) +{ +return 0 ; +}Same here.
Quoted 6 lines
arch/arm/plat-mxc/cpufreq.c new file +6
-0+static int mxc_cpufreq_driver_exit (struct cpufreq_policy *policy) +{ +cpufreq_frequency_table_put_attr (policy->cpu); + +/* Reset CPU to 665MHz */ +set_cpu_freq (arm_normal_clk);arch/arm/plat-mxc/cpufreq.c line 257
Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10
-0+clk_put (cpu_clk); +return 0 ; +} + +static struct cpufreq_driver mxc_driver = { + .flags =CPUFREQ_STICKY , + .verify = mxc_verify_speed, + .target = mxc_set_target, + .get = mxc_get_speed, + .init = mxc_cpufreq_driver_init,
mxc_cpufreq_initis ok. Lose the driver.arch/arm/plat-mxc/cpufreq.c line 258
Quoted 1 line
arch/arm/plat-mxc/cpufreq.c new file +1
-0+ .exit = mxc_cpufreq_driver_exit,same.
arch/arm/plat-mxc/cpufreq.c line 260
Quoted 2 lines
arch/arm/plat-mxc/cpufreq.c new file +2
-0+ .suspend = mxc_cpufreq_suspend, + .resume = mxc_cpufreq_resume,Get rid of suspend/resume
Quoted 12 lines
arch/arm/plat-mxc/cpufreq.c new file +12
-0+ .name = "imx", +}; + +static int __devinit mxc_cpufreq_init (void ) +{ +return cpufreq_register_driver (&mxc_driver); +} + +static void mxc_cpufreq_exit (void ) +{ +cpufreq_unregister_driver (&mxc_driver); +}Quoted 8 lines
Review
Quoted 8 lines
arch/arm/plat-mxc/cpufreq.c new file +7
-0+ +module_init (mxc_cpufreq_init); +module_exit (mxc_cpufreq_exit); + +MODULE_AUTHOR ("Freescale Semiconductor, Inc." ); +MODULE_DESCRIPTION ("CPUfreq driver for i.MX" ); +MODULE_LICENSE ("GPL" );(quoted diff) +0
-0
b/arch/arm/plat-mxc/include/mach/mxc.hQuoted 30 lines
Quoted 30 lines
index a790bf2..14003b9 100644
arch/arm/plat-mxc/include/mach/mxc.h +20
-0@@ -133,6 +133,26 @@ extern unsigned int __mxc_cpu_type;# define cpu_is_mxc91231 () (0)#endif +#ifndef __ASSEMBLY__ + +struct cpu_wp { +u32 pll_reg; +u32 pll_rate; +u32 cpu_rate; +u32 pdr0_reg; +u32 pdf; +u32 mfi; +u32 mfd; +u32 mfn; +u32 cpu_voltage; +u32 cpu_podf; +}; + +#ifndef CONFIG_ARCH_MX5 +struct cpu_wp *get_cpu_wp (int *wp); +#endif +#endif +#if defined(CONFIG_ARCH_MX3 ) || defined(CONFIG_ARCH_MX2 )/* These are deprecated, use mx[23][157]_setup_weimcs instead. */ #define CSCR_U (n) (IO_ADDRESS(WEIM_BASE_ADDR + n * 0x10))Quoted 9 lines
Quoted 3 lines
--
1.6.3.3_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 6 lines
--
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20101007/4f4a5b6a/attachment-0001.html>
PATCH 1/1 cpufreq for freescale mx51
Quoted 17 lines · Yong Shen
Hi Sascha,
Thanks for your thorough comments.
I have already received comments from Arnd before yours arrived. So some of the commends you two provided are common.
I acknowledge most of your opinions, except for two, I have some explanations.Quoted 9 lines
Quoted 5 lines
+ */
Quoted 4 lines
(quoted diff) +4
-0+ reg = __raw_readl(MXC_CCM_CACRR); + reg &= ~MXC_CCM_CACRR_ARM_PODF_MASK; + reg |= cpu_wp_tbl[wp].cpu_podf << MXC_CCM_CACRR_ARM_PODF_OFFSET; + __raw_writel(reg, MXC_CCM_CACRR);We have a simple divider here. Why do we need a reference to struct
cpu_wpthen? This code could look much simpler.
Quoted 6 lines
Quoted 4 lines
(side note: I'm aware that the original Freescale code is also able to change the cpu frequency using the pll instead of the divider, but is this really necessary?)
Using
wp_tblis because that it also contains information like regulator voltage.
The clock code does not handle the regulators, not even in the fsl kernel.
Quoted 6 lines
Since the regulator driver for imx51 have not been upstreamed, you don't see any regulator operation here. Also, like you mentioned, there are two ways to change cpufreq, by post divider or pll change. And post divider change is a simpler way and also the only way for babbage, since cpu freq and ddr freq are all root from the same pll on babbage and they will interfere each other.
I understand what you have to do, but the way you did really looks strange. You introduce get_cpu_wp() to get the complete array of workpoints. In the cpufreq driver you have this complete array, pick the desired workpoint, pass the frequency to the clock layer which in turn calls get_cpu_wp() to get the array and loop around it to get the workpoint from the frequency again. Addionally you maintain a pointer to what the clock code thinks the current workpoint is.
How about making the clock code agnostic of such workpoints and calculate the pll values and dividers for a given frequency based on the frequency. If that's to complicated you could maintain a table in the clock code. If that's not flexible enough you could pass a pointer to this table to mx51_clocks_init. This array could carry information relevant only to the clock code and only relevant to the i.MX51, In the fsl kernel struct cpu_wp is a catch-all struct for all i.MXs. The i.MX51 uses the pdf/mfi/mfd/mfn/cpu_podf fields, the i.MX35 uses the pll_reg and pdr0_reg fields and who knows what the next i.MX needs.
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines
+static struct
cpufreq_frequency_tableimx_freq_table[4];Three frequencies should be enough for everyone, right? This should be dynamically allocated like in other cpufreq drivers.
Yes, we only support 3 work points, which is for sure. Actually, we only support 2 points on most mx51 chips. I supposed it is ok to use static array here.
Please just add dynamic allocation, then we are safe for any potential future use.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH 1/1 cpufreq for freescale mx51
Quoted 6 lines
Quoted 2 lines
Using
wp_tblis because that it also contains information like regulator voltage.The clock code does not handle the regulators, not even in the fsl kernel.
I did not mean to say clock code will handle regulators. I mean this table also contains such information which may be needed in other freescale drivers, like dvfs and busfreq.
Quoted 19 lines
Since the regulator driver for imx51 have not been upstreamed, you
Quoted 1 line
don't see any regulator operation here. Also, like you mentioned, there
are
Quoted 1 line
two ways to change cpufreq, by post divider or pll change. And post
divider
Quoted 3 lines
change is a simpler way and also the only way for babbage, since cpu freq and ddr freq are all root from the same pll on babbage and they will interfere each other.
I understand what you have to do, but the way you did really looks strange. You introduce
get_cpu_wp()to get the complete array of workpoints. In the cpufreq driver you have this complete array, pick the desired workpoint, pass the frequency to the clock layer which in turn callsget_cpu_wp()to get the array and loop around it to get the workpoint from the frequency again. Addionally you maintain a pointer to what the clock code thinks the current workpoint is.
Quoted 11 lines
How about making the clock code agnostic of such workpoints and calculate the pll values and dividers for a given frequency based on the frequency. If that's to complicated you could maintain a table in the clock code. If that's not flexible enough you could pass a pointer to this table to
mx51_clocks_init. This array could carry information relevant only to the clock code and only relevant to the i.MX51, In the fsl kernel structcpu_wpis a catch-all struct for all i.MXs. The i.MX51 uses the pdf/mfi/mfd/mfn/cpu_podf fields, the i.MX35 uses thepll_regandpdr0_regfields and who knows what the next i.MX needs.
I strongly agree with you about this, and it is better to letter clock calculate by itself.
Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
+static struct
cpufreq_frequency_tableimx_freq_table[4];Three frequencies should be enough for everyone, right? This should be dynamically allocated like in other cpufreq drivers.
Yes, we only support 3 work points, which is for sure. Actually, we only support 2 points on most mx51 chips. I supposed it is ok to use static
Quoted 7 lines
array
Quoted 1 line
here.
Please just add dynamic allocation, then we are safe for any potential future use.
Ok! sorry for misunderstanding.
Here, I am not trying to find excuse for the cpufreq driver designer which is my colleague, however the truth is that since in our company the schedule is tight for all the tasks, that's why we always code with the first rough idea in the head, and having less time to think about the flexibility and other good conventions in programming. You can see that even freescale code upstreaming is done by people out of freescale, because of we lacking of resource.
Therefore, I would say we did not mean to have some short-sight design, we also want to achieve a better life of coding like you guys are doing, which is my direct feeling while I am in Linaro. :)
Thanks for comments.
Yong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20101007/62053234/attachment-0001.html>
PATCH v2 1/1 cpufreq for freescale mx51
Does anybody have more comments on [PATCHv2] ?
Quoted 77 lines · Yong Shen
Quoted 7 lines
Using
wp_tblis because that it also contains information like regulatorQuoted 1 line
voltage.
The clock code does not handle the regulators, not even in the fsl kernel.
I did not mean to say clock code will handle regulators. I mean this table also contains such information which may be needed in other freescale drivers, like dvfs and busfreq.
Quoted 20 lines
Since the regulator driver for imx51 have not been upstreamed, you
Quoted 1 line
don't see any regulator operation here. Also, like you mentioned, there
are
Quoted 1 line
two ways to change cpufreq, by post divider or pll change. And post
divider
Quoted 1 line
change is a simpler way and also the only way for babbage, since cpu
freq
Quoted 2 lines
and ddr freq are all root from the same pll on babbage and they will interfere each other.
I understand what you have to do, but the way you did really looks strange. You introduce
get_cpu_wp()to get the complete array of workpoints. In the cpufreq driver you have this complete array, pick the desired workpoint, pass the frequency to the clock layer which in turn callsget_cpu_wp()to get the array and loop around it to get the workpoint from the frequency again. Addionally you maintain a pointer to what the clock code thinks the current workpoint is.Quoted 11 lines
How about making the clock code agnostic of such workpoints and calculate the pll values and dividers for a given frequency based on the frequency. If that's to complicated you could maintain a table in the clock code. If that's not flexible enough you could pass a pointer to this table to
mx51_clocks_init. This array could carry information relevant only to the clock code and only relevant to the i.MX51, In the fsl kernel structcpu_wpis a catch-all struct for all i.MXs. The i.MX51 uses the pdf/mfi/mfd/mfn/cpu_podf fields, the i.MX35 uses thepll_regandpdr0_regfields and who knows what the next i.MX needs.I strongly agree with you about this, and it is better to letter clock calculate by itself.
Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
+static struct
cpufreq_frequency_tableimx_freq_table[4];Three frequencies should be enough for everyone, right? This should be dynamically allocated like in other cpufreq drivers.
Yes, we only support 3 work points, which is for sure. Actually, we only support 2 points on most mx51 chips. I supposed it is ok to use static
Quoted 7 lines
array
Quoted 1 line
here.
Please just add dynamic allocation, then we are safe for any potential future use.
Ok! sorry for misunderstanding.
Here, I am not trying to find excuse for the cpufreq driver designer which is my colleague, however the truth is that since in our company the schedule is tight for all the tasks, that's why we always code with the first rough idea in the head, and having less time to think about the flexibility and other good conventions in programming. You can see that even freescale code upstreaming is done by people out of freescale, because of we lacking of resource.
Therefore, I would say we did not mean to have some short-sight design, we also want to achieve a better life of coding like you guys are doing, which is my direct feeling while I am in Linaro. :)
Thanks for comments.
Quoted 2 lines
Yong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20101012/c5d94aa6/attachment-0001.html>
PATCH 1/1 cpufreq for freescale mx51
In reply to Yong ShenQuoted 10 lines · Yong Shen
Quoted 6 lines
Quoted 2 lines
+static struct
cpufreq_frequency_tableimx_freq_table[4];Three frequencies should be enough for everyone, right? This should be dynamically allocated like in other cpufreq drivers.
Yes, we only support 3 work points, which is for sure. Actually, we only support 2 points on most mx51 chips. I supposed it is ok to use static array here.
This can become a common cpufreq driver for all i.MX platforms. We don't know how many work points will be supported in future versions of the silicon. That is why a static array is not ok.
I think Sascha was being ironic when he said "Three frequencies should be enough for everyone, right?" :)
/Amit
PATCH 1/1 cpufreq for freescale mx51
Quoted 12 lines · Amit Kucheria
Quoted 10 lines · Yong Shen
Quoted 6 lines
Quoted 2 lines
+static struct
cpufreq_frequency_tableimx_freq_table[4];Three frequencies should be enough for everyone, right? This should be dynamically allocated like in other cpufreq drivers.
Yes, we only support 3 work points, which is for sure. Actually, we only support 2 points on most mx51 chips. I supposed it is ok to use static array here.
Quoted 6 lines
This can become a common cpufreq driver for all i.MX platforms. We don't know how many work points will be supported in future versions of the silicon. That is why a static array is not ok.
I think Sascha was being ironic when he said "Three frequencies should be enough for everyone, right?" :)
Yes, the old 640k-is-enough-for-anyone joke.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |