Hi Amit,<br><br>Please see my feedback embedded.<br><br><div class="gmail_quote">On Thu, Sep 30, 2010 at 6:48 PM, Amit Kucheria <span dir="ltr">&lt;<a href="mailto:amit.kucheria@linaro.org">amit.kucheria@linaro.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Add&#39;ed linaro-dev and linux-arm-kernel to CC.<br>
<br>
Thanks Yong, some feeback follows inline.<br>
<div><div></div><div class="h5"><br>
On 10 Sep 29, Yong Shen wrote:<br>
&gt; From: Yong Shen &lt;<a href="mailto:yong.shen@linaro.org">yong.shen@linaro.org</a>&gt;<br>
&gt;<br>
&gt; ---<br>
&gt;  arch/arm/Kconfig                       |    6 +<br>
&gt;  arch/arm/mach-mx5/Kconfig              |    1 +<br>
&gt;  arch/arm/mach-mx5/board-mx51_babbage.c |   32 ++++<br>
&gt;  arch/arm/mach-mx5/clock-mx51.c         |   53 ++++++<br>
&gt;  arch/arm/plat-mxc/Makefile             |    2 +<br>
&gt;  arch/arm/plat-mxc/cpufreq.c            |  282 ++++++++++++++++++++++++++++++++<br>
&gt;  arch/arm/plat-mxc/include/mach/mxc.h   |   20 +++<br>
&gt;  7 files changed, 396 insertions(+), 0 deletions(-)<br>
&gt;  create mode 100644 arch/arm/plat-mxc/cpufreq.c<br>
&gt;<br>
&gt; diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig<br>
&gt; index 4db064e..64ebbc0 100644<br>
&gt; --- a/arch/arm/Kconfig<br>
&gt; +++ b/arch/arm/Kconfig<br>
&gt; @@ -1517,6 +1517,12 @@ if ARCH_HAS_CPUFREQ<br>
&gt;<br>
&gt;  source &quot;drivers/cpufreq/Kconfig&quot;<br>
&gt;<br>
&gt; +config CPU_FREQ_IMX<br>
&gt; +     tristate &quot;CPUfreq driver for i.MX CPUs&quot;<br>
&gt; +     depends on ARCH_MXC &amp;&amp; CPU_FREQ<br>
&gt; +     help<br>
&gt; +     This enables the CPUfreq driver for i.MX CPUs.<br>
&gt; +<br>
&gt;  config CPU_FREQ_SA1100<br>
&gt;       bool<br>
&gt;<br>
&gt; diff --git a/arch/arm/mach-mx5/Kconfig b/arch/arm/mach-mx5/Kconfig<br>
&gt; index 1576d51..5956fee 100644<br>
&gt; --- a/arch/arm/mach-mx5/Kconfig<br>
&gt; +++ b/arch/arm/mach-mx5/Kconfig<br>
&gt; @@ -5,6 +5,7 @@ config ARCH_MX51<br>
&gt;       default y<br>
&gt;       select MXC_TZIC<br>
&gt;       select ARCH_MXC_IOMUX_V3<br>
&gt; +     select ARCH_HAS_CPUFREQ<br>
&gt;<br>
&gt;  comment &quot;MX5 platforms:&quot;<br>
&gt;<br>
&gt; diff --git a/arch/arm/mach-mx5/board-mx51_babbage.c b/arch/arm/mach-mx5/board-mx51_babbage.c<br>
&gt; index ed885f9..e449e0b 100644<br>
&gt; --- a/arch/arm/mach-mx5/board-mx51_babbage.c<br>
&gt; +++ b/arch/arm/mach-mx5/board-mx51_babbage.c<br>
&gt; @@ -43,6 +43,31 @@<br>
&gt;  #define      MX51_USB_PLL_DIV_19_2_MHZ       0x01<br>
&gt;  #define      MX51_USB_PLL_DIV_24_MHZ 0x02<br>
&gt;<br>
&gt; +struct cpu_wp *(*get_cpu_wp)(int *wp);<br>
&gt; +static int num_cpu_wp = 2;<br>
<br>
</div></div>use sizeof(array) instead of hard coding this.<br></blockquote><div>yong: Agreed. <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div class="im"><br>
&gt; +/* working point(wp): 0 - 800MHz; 1 - 166.25MHz; */<br>
&gt; +static struct cpu_wp cpu_wp_auto[] = {<br>
&gt; +     {<br>
&gt; +     .pll_rate = 800000000,<br>
&gt; +     .cpu_rate = 800000000,<br>
&gt; +     .pdf = 0,<br>
&gt; +     .mfi = 8,<br>
&gt; +     .mfd = 2,<br>
&gt; +     .mfn = 1,<br>
&gt; +     .cpu_podf = 0,<br>
&gt; +     .cpu_voltage = 1100000,},<br>
&gt; +     {<br>
&gt; +     .pll_rate = 800000000,<br>
&gt; +     .cpu_rate = 160000000,<br>
&gt; +     .pdf = 4,<br>
&gt; +     .mfi = 8,<br>
&gt; +     .mfd = 2,<br>
&gt; +     .mfn = 1,<br>
&gt; +     .cpu_podf = 4,<br>
&gt; +     .cpu_voltage = 850000,},<br>
&gt; +};<br>
<br>
<br>
</div>This data should be moved out to a separate file (e.g. mx51_ratetable.h)<br>
since it will be useful to other boards too.<br>
<br>
If other boards can have different rate tables (and they can, depending on<br>
the revision of the silicon), then we can either &#39;assemble&#39; the correct rate<br>
table based on a flag field or have explicit separate rate tables for each<br>
silicon revision.<br>
<br>
In any case, I suspect that there will be some core rates that will be common<br>
across silicon revisions.<br>
<div><div></div><div class="h5"><br></div></div></blockquote><div><br>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.<br>
 <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div class="h5">
&gt;  static struct platform_device *devices[] __initdata = {<br>
&gt;       &amp;mxc_fec_device,<br>
&gt;  };<br>
&gt; @@ -87,6 +112,12 @@ static struct imxuart_platform_data uart_pdata = {<br>
&gt;       .flags = IMXUART_HAVE_RTSCTS,<br>
&gt;  };<br>
&gt;<br>
&gt; +struct cpu_wp *mx51_babbage_get_cpu_wp(int *wp)<br>
&gt; +{<br>
&gt; +     *wp = num_cpu_wp;<br>
&gt; +     return cpu_wp_auto;<br>
&gt; +}<br>
&gt; +<br>
&gt;  static inline void mxc_init_imx_uart(void)<br>
&gt;  {<br>
&gt;       mxc_register_device(&amp;mxc_uart_device0, &amp;uart_pdata);<br>
&gt; @@ -246,6 +277,7 @@ static void __init mxc_board_init(void)<br>
&gt;<br>
&gt;  static void __init mx51_babbage_timer_init(void)<br>
&gt;  {<br>
&gt; +     get_cpu_wp = mx51_babbage_get_cpu_wp;<br>
&gt;       mx51_clocks_init(32768, 24000000, 22579200, 0);<br>
&gt;  }<br>
&gt;<br>
&gt; diff --git a/arch/arm/mach-mx5/clock-mx51.c b/arch/arm/mach-mx5/clock-mx51.c<br>
&gt; index d9f612d..f2488e6 100644<br>
&gt; --- a/arch/arm/mach-mx5/clock-mx51.c<br>
&gt; +++ b/arch/arm/mach-mx5/clock-mx51.c<br>
&gt; @@ -14,6 +14,7 @@<br>
&gt;  #include &lt;linux/delay.h&gt;<br>
&gt;  #include &lt;linux/clk.h&gt;<br>
&gt;  #include &lt;linux/io.h&gt;<br>
&gt; +#include &lt;linux/time.h&gt;<br>
&gt;<br>
&gt;  #include &lt;asm/clkdev.h&gt;<br>
&gt;  #include &lt;asm/div64.h&gt;<br>
&gt; @@ -28,6 +29,11 @@<br>
&gt;  static unsigned long external_high_reference, external_low_reference;<br>
&gt;  static unsigned long oscillator_reference, ckih2_reference;<br>
&gt;<br>
&gt; +extern struct cpu_wp *(*get_cpu_wp)(int *wp);<br>
&gt; +static int cpu_wp_nr;<br>
&gt; +static int cpu_curr_wp;<br>
&gt; +static struct cpu_wp *cpu_wp_tbl;<br>
&gt; +<br>
&gt;  static struct clk osc_clk;<br>
&gt;  static struct clk pll1_main_clk;<br>
&gt;  static struct clk pll1_sw_clk;<br>
&gt; @@ -38,7 +44,9 @@ static struct clk periph_apm_clk;<br>
&gt;  static struct clk ahb_clk;<br>
&gt;  static struct clk ipg_clk;<br>
&gt;  static struct clk usboh3_clk;<br>
&gt; +static void __iomem *pll1_base;<br>
&gt;<br>
&gt; +#define SPIN_DELAY   1000000 /* in nanoseconds */<br>
&gt;  #define MAX_DPLL_WAIT_TRIES  1000 /* 1000 * udelay(1) = 1ms */<br>
&gt;<br>
&gt;  static int _clk_ccgr_enable(struct clk *clk)<br>
&gt; @@ -330,6 +338,32 @@ static int _clk_lp_apm_set_parent(struct clk *clk, struct clk *parent)<br>
&gt;       return 0;<br>
&gt;  }<br>
&gt;<br>
&gt; +/*!<br>
&gt; + * Setup cpu clock based on working point.<br>
&gt; + * @param    wp      cpu freq working point<br>
&gt; + * @return           0 on success or error code on failure.<br>
&gt; + */<br>
&gt; +int cpu_clk_set_wp(int wp)<br>
&gt; +{<br>
&gt; +     struct cpu_wp *p;<br>
&gt; +     u32 reg;<br>
&gt; +<br>
&gt; +     if (wp == cpu_curr_wp)<br>
&gt; +             return 0;<br>
&gt; +<br>
&gt; +     p = &amp;cpu_wp_tbl[wp];<br>
&gt; +<br>
&gt; +     /*use post divider to change freq<br>
&gt; +      */<br>
&gt; +     reg = __raw_readl(MXC_CCM_CACRR);<br>
&gt; +     reg &amp;= ~MXC_CCM_CACRR_ARM_PODF_MASK;<br>
&gt; +     reg |= cpu_wp_tbl[wp].cpu_podf &lt;&lt; MXC_CCM_CACRR_ARM_PODF_OFFSET;<br>
&gt; +     __raw_writel(reg, MXC_CCM_CACRR);<br>
&gt; +     cpu_curr_wp = wp;<br>
&gt; +<br>
&gt; +     return 0;<br>
&gt; +}<br>
&gt; +<br>
&gt;  static unsigned long clk_arm_get_rate(struct clk *clk)<br>
&gt;  {<br>
&gt;       u32 cacrr, div;<br>
&gt; @@ -342,6 +376,20 @@ static unsigned long clk_arm_get_rate(struct clk *clk)<br>
&gt;       return parent_rate / div;<br>
&gt;  }<br>
&gt;<br>
&gt; +int _clk_cpu_set_rate(struct clk *clk, unsigned long rate)<br>
&gt; +{<br>
&gt; +     u32 i;<br>
&gt; +     for (i = 0; i &lt; cpu_wp_nr; i++) {<br>
&gt; +             if (rate == cpu_wp_tbl[i].cpu_rate)<br>
&gt; +                     break;<br>
&gt; +     }<br>
&gt; +     if (i &gt;= cpu_wp_nr)<br>
&gt; +             return -EINVAL;<br>
&gt; +     cpu_clk_set_wp(i);<br>
&gt; +<br>
&gt; +     return 0;<br>
&gt; +}<br>
&gt; +<br>
&gt;  static int _clk_periph_apm_set_parent(struct clk *clk, struct clk *parent)<br>
&gt;  {<br>
&gt;       u32 reg, mux;<br>
&gt; @@ -694,6 +742,7 @@ static struct clk periph_apm_clk = {<br>
&gt;  static struct clk cpu_clk = {<br>
&gt;       .parent = &amp;pll1_sw_clk,<br>
&gt;       .get_rate = clk_arm_get_rate,<br>
&gt; +     .set_rate = _clk_cpu_set_rate,<br>
&gt;  };<br>
&gt;<br>
&gt;  static struct clk ahb_clk = {<br>
&gt; @@ -821,6 +870,7 @@ static struct clk_lookup lookups[] = {<br>
&gt;       _REGISTER_CLOCK(&quot;mxc-ehci.1&quot;, &quot;usb_ahb&quot;, ahb_clk)<br>
&gt;       _REGISTER_CLOCK(&quot;fsl-usb2-udc&quot;, &quot;usb&quot;, usboh3_clk)<br>
&gt;       _REGISTER_CLOCK(&quot;fsl-usb2-udc&quot;, &quot;usb_ahb&quot;, ahb_clk)<br>
&gt; +     _REGISTER_CLOCK(NULL, &quot;cpu_clk&quot;, cpu_clk)<br>
&gt;  };<br>
&gt;<br>
&gt;  static void clk_tree_init(void)<br>
&gt; @@ -848,10 +898,13 @@ int __init mx51_clocks_init(unsigned long ckil, unsigned long osc,<br>
&gt;  {<br>
&gt;       int i;<br>
&gt;<br>
&gt; +     pll1_base = ioremap(MX51_PLL1_BASE_ADDR, SZ_4K);<br>
&gt; +<br>
&gt;       external_low_reference = ckil;<br>
&gt;       external_high_reference = ckih1;<br>
&gt;       ckih2_reference = ckih2;<br>
&gt;       oscillator_reference = osc;<br>
&gt; +     cpu_wp_tbl = get_cpu_wp(&amp;cpu_wp_nr);<br>
&gt;<br>
&gt;       for (i = 0; i &lt; ARRAY_SIZE(lookups); i++)<br>
&gt;               clkdev_add(&amp;lookups[i]);<br>
&gt; diff --git a/arch/arm/plat-mxc/Makefile b/arch/arm/plat-mxc/Makefile<br>
&gt; index 895bc3c..c1bb400 100644<br>
&gt; --- a/arch/arm/plat-mxc/Makefile<br>
&gt; +++ b/arch/arm/plat-mxc/Makefile<br>
&gt; @@ -17,6 +17,8 @@ obj-$(CONFIG_USB_EHCI_MXC) += ehci.o<br>
&gt;  obj-$(CONFIG_MXC_ULPI) += ulpi.o<br>
&gt;  obj-$(CONFIG_ARCH_MXC_AUDMUX_V1) += audmux-v1.o<br>
&gt;  obj-$(CONFIG_ARCH_MXC_AUDMUX_V2) += audmux-v2.o<br>
&gt; +# CPU FREQ support<br>
&gt; +obj-$(CONFIG_CPU_FREQ_IMX)    += cpufreq.o<br>
&gt;  ifdef CONFIG_SND_IMX_SOC<br>
&gt;  obj-y += ssi-fiq.o<br>
&gt;  obj-y += ssi-fiq-ksym.o<br>
&gt; diff --git a/arch/arm/plat-mxc/cpufreq.c b/arch/arm/plat-mxc/cpufreq.c<br>
&gt; new file mode 100644<br>
&gt; index 0000000..cae40f1<br>
&gt; --- /dev/null<br>
&gt; +++ b/arch/arm/plat-mxc/cpufreq.c<br>
&gt; @@ -0,0 +1,282 @@<br>
&gt; +/*<br>
&gt; + * Copyright (C) 2010 Freescale Semiconductor, Inc. All Rights Reserved.<br>
&gt; + */<br>
&gt; +<br>
&gt; +/*<br>
&gt; + * The code contained herein is licensed under the GNU General Public<br>
&gt; + * License. You may obtain a copy of the GNU General Public License<br>
&gt; + * Version 2 or later at the following locations:<br>
&gt; + *<br>
&gt; + * <a href="http://www.opensource.org/licenses/gpl-license.html" target="_blank">http://www.opensource.org/licenses/gpl-license.html</a><br>
&gt; + * <a href="http://www.gnu.org/copyleft/gpl.html" target="_blank">http://www.gnu.org/copyleft/gpl.html</a><br>
&gt; + */<br>
&gt; +<br>
&gt; +/*!<br>
&gt; + * @file cpufreq.c<br>
&gt; + *<br>
&gt; + * @brief A driver for the Freescale Semiconductor i.MXC CPUfreq module.<br>
&gt; + *<br>
&gt; + * The CPUFREQ driver is for controling CPU frequency. It allows you to change<br>
&gt; + * the CPU clock speed on the fly.<br>
&gt; + *<br>
&gt; + * @ingroup PM<br>
&gt; + */<br>
<br>
</div></div>Fix these comments to follow the kernel commenting style.<br></blockquote><div><br>Yong: OK <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><div></div><div class="h5"><br>
&gt; +#include &lt;linux/types.h&gt;<br>
&gt; +#include &lt;linux/kernel.h&gt;<br>
&gt; +#include &lt;linux/cpufreq.h&gt;<br>
&gt; +#include &lt;linux/init.h&gt;<br>
&gt; +#include &lt;linux/proc_fs.h&gt;<br>
&gt; +#include &lt;linux/regulator/consumer.h&gt;<br>
&gt; +#include &lt;linux/clk.h&gt;<br>
&gt; +#include &lt;linux/delay.h&gt;<br>
&gt; +#include &lt;linux/io.h&gt;<br>
&gt; +#include &lt;mach/hardware.h&gt;<br>
&gt; +#include &lt;asm/setup.h&gt;<br>
&gt; +#include &lt;mach/clock.h&gt;<br>
&gt; +#include &lt;asm/cacheflush.h&gt;<br>
&gt; +#include &lt;linux/hrtimer.h&gt;<br>
&gt; +<br>
&gt; +int cpu_freq_khz_min;<br>
&gt; +int cpu_freq_khz_max;<br>
&gt; +int arm_lpm_clk;<br>
&gt; +int arm_normal_clk;<br>
&gt; +int cpufreq_suspended;<br>
&gt; +int cpufreq_trig_needed;<br>
&gt; +<br>
&gt; +static struct clk *cpu_clk;<br>
&gt; +static struct cpufreq_frequency_table imx_freq_table[4];<br>
&gt; +<br>
&gt; +extern int set_low_bus_freq(void);<br>
&gt; +extern int set_high_bus_freq(int high_bus_speed);<br>
&gt; +extern int low_freq_bus_used(void);<br>
&gt; +<br>
&gt; +extern struct cpu_wp *(*get_cpu_wp)(int *wp);<br>
&gt; +static int cpu_wp_nr;<br>
&gt; +static struct cpu_wp *cpu_wp_tbl;<br>
&gt; +<br>
&gt; +int set_cpu_freq(int freq)<br>
&gt; +{<br>
&gt; +     int ret = 0;<br>
&gt; +     int org_cpu_rate;<br>
&gt; +     int gp_volt = 0;<br>
&gt; +     int i;<br>
&gt; +<br>
&gt; +     org_cpu_rate = clk_get_rate(cpu_clk);<br>
&gt; +     if (org_cpu_rate == freq)<br>
&gt; +             return ret;<br>
&gt; +<br>
&gt; +     for (i = 0; i &lt; cpu_wp_nr; i++) {<br>
&gt; +             if (freq == cpu_wp_tbl[i].cpu_rate)<br>
&gt; +                     gp_volt = cpu_wp_tbl[i].cpu_voltage;<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     if (gp_volt == 0)<br>
&gt; +             return ret;<br>
&gt; +<br>
&gt; +     ret = clk_set_rate(cpu_clk, freq);<br>
&gt; +     if (ret != 0) {<br>
&gt; +             printk(KERN_DEBUG &quot;cannot set CPU clock rate\n&quot;);<br>
&gt; +             return ret;<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     return ret;<br>
&gt; +}<br>
&gt; +<br>
&gt; +static int mxc_verify_speed(struct cpufreq_policy *policy)<br>
&gt; +{<br>
&gt; +     if (policy-&gt;cpu != 0)<br>
&gt; +             return -EINVAL;<br>
&gt; +<br>
&gt; +     return cpufreq_frequency_table_verify(policy, imx_freq_table);<br>
&gt; +}<br>
&gt; +<br>
&gt; +static unsigned int mxc_get_speed(unsigned int cpu)<br>
&gt; +{<br>
&gt; +     if (cpu)<br>
&gt; +             return 0;<br>
&gt; +<br>
&gt; +     return clk_get_rate(cpu_clk) / 1000;<br>
&gt; +}<br>
&gt; +<br>
&gt; +static int calc_frequency_khz(int target, unsigned int relation)<br>
&gt; +{<br>
&gt; +     int i;<br>
&gt; +<br>
&gt; +     if ((target * 1000) == clk_get_rate(cpu_clk))<br>
&gt; +             return target;<br>
&gt; +<br>
&gt; +     if (relation == CPUFREQ_RELATION_H) {<br>
&gt; +             for (i = cpu_wp_nr - 1; i &gt;= 0; i--) {<br>
&gt; +                     if (imx_freq_table[i].frequency &lt;= target)<br>
&gt; +                             return imx_freq_table[i].frequency;<br>
&gt; +             }<br>
&gt; +     } else if (relation == CPUFREQ_RELATION_L) {<br>
&gt; +             for (i = 0; i &lt; cpu_wp_nr; i++) {<br>
&gt; +                     if (imx_freq_table[i].frequency &gt;= target)<br>
&gt; +                             return imx_freq_table[i].frequency;<br>
&gt; +             }<br>
&gt; +     }<br>
&gt; +     printk(KERN_ERR &quot;Error: No valid cpufreq relation\n&quot;);<br>
&gt; +     return cpu_freq_khz_max;<br>
&gt; +}<br>
&gt; +<br>
&gt; +static int mxc_set_target(struct cpufreq_policy *policy,<br>
&gt; +                       unsigned int target_freq, unsigned int relation)<br>
&gt; +{<br>
&gt; +     struct cpufreq_freqs freqs;<br>
&gt; +     int freq_Hz;<br>
&gt; +     int ret = 0;<br>
&gt; +<br>
&gt; +     if (cpufreq_suspended) {<br>
&gt; +             target_freq = clk_get_rate(cpu_clk) / 1000;<br>
&gt; +             freq_Hz = calc_frequency_khz(target_freq, relation) * 1000;<br>
&gt; +             if (freq_Hz == arm_lpm_clk)<br>
&gt; +                     freqs.old = cpu_wp_tbl[cpu_wp_nr - 2].cpu_rate / 1000;<br>
&gt; +             else<br>
&gt; +                     freqs.old = arm_lpm_clk / 1000;<br>
&gt; +<br>
&gt; +             freqs.new = freq_Hz / 1000;<br>
&gt; +             freqs.cpu = 0;<br>
&gt; +             freqs.flags = 0;<br>
&gt; +             cpufreq_notify_transition(&amp;freqs, CPUFREQ_PRECHANGE);<br>
&gt; +             cpufreq_notify_transition(&amp;freqs, CPUFREQ_POSTCHANGE);<br>
&gt; +             return ret;<br>
&gt; +     }<br>
&gt; +     /*<br>
&gt; +      * Some governors do not respects CPU and policy lower limits<br>
&gt; +      * which leads to bad things (division by zero etc), ensure<br>
&gt; +      * that such things do not happen.<br>
&gt; +      */<br>
<br>
</div></div>Isn&#39;t that a bug in the governor? Can you explain a bit?<br></blockquote><div>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. <br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5"><br>
&gt; +     if (target_freq &lt; policy-&gt;cpuinfo.min_freq)<br>
&gt; +             target_freq = policy-&gt;cpuinfo.min_freq;<br>
&gt; +<br>
&gt; +     if (target_freq &lt; policy-&gt;min)<br>
&gt; +             target_freq = policy-&gt;min;<br>
&gt; +<br>
&gt; +     freq_Hz = calc_frequency_khz(target_freq, relation) * 1000;<br>
&gt; +<br>
&gt; +     freqs.old = clk_get_rate(cpu_clk) / 1000;<br>
&gt; +     freqs.new = freq_Hz / 1000;<br>
&gt; +     freqs.cpu = 0;<br>
&gt; +     freqs.flags = 0;<br>
&gt; +     cpufreq_notify_transition(&amp;freqs, CPUFREQ_PRECHANGE);<br>
&gt; +<br>
&gt; +     if (freqs.old != freqs.new)<br>
&gt; +             ret = set_cpu_freq(freq_Hz);<br>
&gt; +<br>
&gt; +     cpufreq_notify_transition(&amp;freqs, CPUFREQ_POSTCHANGE);<br>
&gt; +<br>
&gt; +     return ret;<br>
&gt; +}<br>
&gt; +<br>
&gt; +static int __init mxc_cpufreq_driver_init(struct cpufreq_policy *policy)<br>
&gt; +{<br>
&gt; +     int ret;<br>
&gt; +     int i;<br>
&gt; +<br>
&gt; +     printk(KERN_INFO &quot;i.MXC CPU frequency driver\n&quot;);<br>
&gt; +<br>
&gt; +     if (policy-&gt;cpu != 0)<br>
&gt; +             return -EINVAL;<br>
&gt; +<br>
&gt; +     cpu_clk = clk_get(NULL, &quot;cpu_clk&quot;);<br>
&gt; +     if (IS_ERR(cpu_clk)) {<br>
&gt; +             printk(KERN_ERR &quot;%s: failed to get cpu clock\n&quot;, __func__);<br>
&gt; +             return PTR_ERR(cpu_clk);<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     /* Set the current working point. */<br>
&gt; +     cpu_wp_tbl = get_cpu_wp(&amp;cpu_wp_nr);<br>
&gt; +<br>
&gt; +     cpu_freq_khz_min = cpu_wp_tbl[0].cpu_rate / 1000;<br>
&gt; +     cpu_freq_khz_max = cpu_wp_tbl[0].cpu_rate / 1000;<br>
&gt; +<br>
&gt; +     for (i = 0; i &lt; cpu_wp_nr; i++) {<br>
&gt; +             imx_freq_table[cpu_wp_nr - 1 - i].index = cpu_wp_nr - i;<br>
<br>
</div></div>cpu_wp_nr = 2 here<br>
<br>
1st iteration of for loop:<br>
    imx_freq_table[2 - 1 - 0].index = 2 - 0<br>
so, imx_freq_table[1].index = 2<br>
<br>
2nd iteration:<br>
    imx_freq_table[2 - 1 - 1].index = 2 - 1<br>
    imx_freq_table[0].index = 1<br>
<br>
So you&#39;re trying to reverse the table order? Why not just sort the table date<br>
in the way you want and add a comment on the top to keep it sorted.<br></blockquote><div>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. <br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><br>
&gt; +             imx_freq_table[cpu_wp_nr - 1 - i].frequency =<br>
&gt; +                 cpu_wp_tbl[i].cpu_rate / 1000;<br>
&gt; +<br>
&gt; +             if ((cpu_wp_tbl[i].cpu_rate / 1000) &lt; cpu_freq_khz_min)<br>
&gt; +                     cpu_freq_khz_min = cpu_wp_tbl[i].cpu_rate / 1000;<br>
&gt; +<br>
&gt; +             if ((cpu_wp_tbl[i].cpu_rate / 1000) &gt; cpu_freq_khz_max)<br>
&gt; +                     cpu_freq_khz_max = cpu_wp_tbl[i].cpu_rate / 1000;<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     imx_freq_table[i].index = 0;<br>
<br>
</div>imx_freq_table[i].index = i ?<br></blockquote><div>Yong: this should be a place holder, no meaning. <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div class="im"><br>
&gt; +     imx_freq_table[i].frequency = CPUFREQ_TABLE_END;<br>
&gt; +<br>
&gt; +     policy-&gt;cur = clk_get_rate(cpu_clk) / 1000;<br>
&gt; +     policy-&gt;governor = CPUFREQ_DEFAULT_GOVERNOR;<br>
&gt; +     policy-&gt;min = policy-&gt;cpuinfo.min_freq = cpu_freq_khz_min;<br>
&gt; +     policy-&gt;max = policy-&gt;cpuinfo.max_freq = cpu_freq_khz_max;<br>
&gt; +<br>
&gt; +     arm_lpm_clk = cpu_freq_khz_min * 1000;<br>
&gt; +     arm_normal_clk = cpu_freq_khz_max * 1000;<br>
&gt; +<br>
&gt; +     /* Manual states, that PLL stabilizes in two CLK32 periods */<br>
&gt; +     policy-&gt;cpuinfo.transition_latency = 10;<br>
&gt; +<br>
&gt; +     ret = cpufreq_frequency_table_cpuinfo(policy, imx_freq_table);<br>
&gt; +<br>
&gt; +     if (ret &lt; 0) {<br>
&gt; +             clk_put(cpu_clk);<br>
&gt; +             printk(KERN_ERR &quot;%s: failed to register i.MXC CPUfreq\n&quot;,<br>
&gt; +                    __func__);<br>
&gt; +             return ret;<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     cpufreq_frequency_table_get_attr(imx_freq_table, policy-&gt;cpu);<br>
&gt; +     return 0;<br>
&gt; +}<br>
&gt; +<br>
&gt; +static int mxc_cpufreq_suspend(struct cpufreq_policy *policy,<br>
&gt; +                                  pm_message_t state)<br>
&gt; +{<br>
&gt; +     return 0;<br>
&gt; +}<br>
<br>
</div>Get rid of these, since you don&#39;t use them.<br>
<div class="im"><br></div></blockquote><div>yong:Ok about this and below <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">

&gt; +static int mxc_cpufreq_resume(struct cpufreq_policy *policy)<br>
&gt; +{<br>
&gt; +     return 0;<br>
&gt; +}<br>
<br>
</div>Same here.<br>
<div class="im"><br>
&gt; +static int mxc_cpufreq_driver_exit(struct cpufreq_policy *policy)<br>
&gt; +{<br>
&gt; +     cpufreq_frequency_table_put_attr(policy-&gt;cpu);<br>
&gt; +<br>
&gt; +     /* Reset CPU to 665MHz */<br>
&gt; +     set_cpu_freq(arm_normal_clk);<br>
&gt; +     clk_put(cpu_clk);<br>
&gt; +     return 0;<br>
&gt; +}<br>
&gt; +<br>
&gt; +static struct cpufreq_driver mxc_driver = {<br>
&gt; +     .flags = CPUFREQ_STICKY,<br>
&gt; +     .verify = mxc_verify_speed,<br>
&gt; +     .target = mxc_set_target,<br>
&gt; +     .get = mxc_get_speed,<br>
&gt; +     .init = mxc_cpufreq_driver_init,<br>
<br>
</div>mxc_cpufreq_init is ok. Lose the driver.<br>
<div class="im"><br>
&gt; +     .exit = mxc_cpufreq_driver_exit,<br>
<br>
</div>same.<br>
<div class="im"><br>
&gt; +     .suspend = mxc_cpufreq_suspend,<br>
&gt; +     .resume = mxc_cpufreq_resume,<br>
<br>
</div>Get rid of suspend/resume<br>
<div><div></div><div class="h5"><br>
&gt; +     .name = &quot;imx&quot;,<br>
&gt; +};<br>
&gt; +<br>
&gt; +static int __devinit mxc_cpufreq_init(void)<br>
&gt; +{<br>
&gt; +     return cpufreq_register_driver(&amp;mxc_driver);<br>
&gt; +}<br>
&gt; +<br>
&gt; +static void mxc_cpufreq_exit(void)<br>
&gt; +{<br>
&gt; +     cpufreq_unregister_driver(&amp;mxc_driver);<br>
&gt; +}<br>
&gt; +<br>
&gt; +module_init(mxc_cpufreq_init);<br>
&gt; +module_exit(mxc_cpufreq_exit);<br>
&gt; +<br>
&gt; +MODULE_AUTHOR(&quot;Freescale Semiconductor, Inc.&quot;);<br>
&gt; +MODULE_DESCRIPTION(&quot;CPUfreq driver for i.MX&quot;);<br>
&gt; +MODULE_LICENSE(&quot;GPL&quot;);<br>
&gt; diff --git a/arch/arm/plat-mxc/include/mach/mxc.h b/arch/arm/plat-mxc/include/mach/mxc.h<br>
&gt; index a790bf2..14003b9 100644<br>
&gt; --- a/arch/arm/plat-mxc/include/mach/mxc.h<br>
&gt; +++ b/arch/arm/plat-mxc/include/mach/mxc.h<br>
&gt; @@ -133,6 +133,26 @@ extern unsigned int __mxc_cpu_type;<br>
&gt;  # define cpu_is_mxc91231()   (0)<br>
&gt;  #endif<br>
&gt;<br>
&gt; +#ifndef __ASSEMBLY__<br>
&gt; +<br>
&gt; +struct cpu_wp {<br>
&gt; +     u32 pll_reg;<br>
&gt; +     u32 pll_rate;<br>
&gt; +     u32 cpu_rate;<br>
&gt; +     u32 pdr0_reg;<br>
&gt; +     u32 pdf;<br>
&gt; +     u32 mfi;<br>
&gt; +     u32 mfd;<br>
&gt; +     u32 mfn;<br>
&gt; +     u32 cpu_voltage;<br>
&gt; +     u32 cpu_podf;<br>
&gt; +};<br>
&gt; +<br>
&gt; +#ifndef CONFIG_ARCH_MX5<br>
&gt; +struct cpu_wp *get_cpu_wp(int *wp);<br>
&gt; +#endif<br>
&gt; +#endif<br>
&gt; +<br>
&gt;  #if defined(CONFIG_ARCH_MX3) || defined(CONFIG_ARCH_MX2)<br>
&gt;  /* These are deprecated, use mx[23][157]_setup_weimcs instead. */<br>
&gt;  #define CSCR_U(n) (IO_ADDRESS(WEIM_BASE_ADDR + n * 0x10))<br>
&gt; --<br>
&gt; 1.6.3.3<br>
&gt;<br>
</div></div></blockquote></div><br>