Hi Amit,<div><br></div><div>I agree about all the comments. New patch is coming.</div><div><br></div><div>Yong</div><div><div><br><div class="gmail_quote">On Wed, Oct 13, 2010 at 6:38 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="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Yong,<br>
<br>
Some more comments. But the patch is looking good now.<br>
<div class="im"><br>
On Fri, Oct 8, 2010 at 11:08 AM,  &lt;<a href="mailto:yong.shen@linaro.org">yong.shen@linaro.org</a>&gt; wrote:<br>
&gt; From: Yong Shen &lt;<a href="mailto:yong.shen@linaro.org">yong.shen@linaro.org</a>&gt;<br>
&gt;<br>
&gt; it is tested on babbage 3.0<br>
<br>
</div>Change to<br>
<br>
&quot;Cpufreq driver for imx51. The operating points are currently tested<br>
<div><div></div><div class="h5">on babbage 3.0.&quot;<br>
<br>
&gt; Signed-off-by: Yong Shen &lt;<a href="mailto:yong.shen@linaro.org">yong.shen@linaro.org</a>&gt;<br>
&gt; ---<br>
&gt;  arch/arm/Kconfig                       |    6 +<br>
&gt;  arch/arm/mach-mx5/Kconfig              |    1 +<br>
&gt;  arch/arm/mach-mx5/Makefile             |    1 +<br>
&gt;  arch/arm/mach-mx5/board-mx51_babbage.c |   12 ++-<br>
&gt;  arch/arm/mach-mx5/clock-mx51.c         |   24 ++++<br>
&gt;  arch/arm/mach-mx5/cpu.c                |    2 +<br>
&gt;  arch/arm/mach-mx5/cpu_wp-mx51.c        |   42 ++++++<br>
&gt;  arch/arm/mach-mx5/cpu_wp-mx51.h        |   14 ++<br>
&gt;  arch/arm/plat-mxc/Makefile             |    2 +<br>
&gt;  arch/arm/plat-mxc/cpufreq.c            |  236 ++++++++++++++++++++++++++++++++<br>
&gt;  arch/arm/plat-mxc/include/mach/mxc.h   |   20 +++-<br>
&gt;  11 files changed, 358 insertions(+), 2 deletions(-)<br>
&gt;  create mode 100644 arch/arm/mach-mx5/cpu_wp-mx51.c<br>
&gt;  create mode 100644 arch/arm/mach-mx5/cpu_wp-mx51.h<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 d203b84..71a572a 100644<br>
&gt; --- a/arch/arm/Kconfig<br>
&gt; +++ b/arch/arm/Kconfig<br>
&gt; @@ -1690,6 +1690,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 0848db5..7a621b4 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/Makefile b/arch/arm/mach-mx5/Makefile<br>
&gt; index 86c66e7..e2af3fb 100644<br>
&gt; --- a/arch/arm/mach-mx5/Makefile<br>
&gt; +++ b/arch/arm/mach-mx5/Makefile<br>
&gt; @@ -5,6 +5,7 @@<br>
&gt;  # Object file lists.<br>
&gt;  obj-y   := cpu.o mm.o clock-mx51.o devices.o<br>
&gt;<br>
&gt; +obj-$(CONFIG_CPU_FREQ_IMX)    += cpu_wp-mx51.o<br>
<br>
</div></div>s/wp/op/ ?<br>
<br>
Operating point is a more widely used word for frequency/voltage pairs<br>
in the ARM world. We will also want to consider using the OPP library<br>
currently being discussed elsewhere on LAKML. So change all instances<br>
of working point or wp to operating point or op.<br>
<div class="im"><br>
&gt;  obj-$(CONFIG_MACH_MX51_BABBAGE) += board-mx51_babbage.o<br>
&gt;  obj-$(CONFIG_MACH_MX51_3DS) += board-mx51_3ds.o<br>
&gt;  obj-$(CONFIG_MACH_EUKREA_CPUIMX51) += board-cpuimx51.o<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 6e384d9..2d2a052 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; @@ -1,5 +1,5 @@<br>
&gt;  /*<br>
&gt; - * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.<br>
&gt; + * Copyright 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.<br>
&gt;  * Copyright (C) 2009-2010 Amit Kucheria &lt;<a href="mailto:amit.kucheria@canonical.com">amit.kucheria@canonical.com</a>&gt;<br>
&gt;  *<br>
&gt;  * The code contained herein is licensed under the GNU General Public<br>
&gt; @@ -32,6 +32,7 @@<br>
&gt;  #include &lt;asm/mach/time.h&gt;<br>
&gt;<br>
&gt;  #include &quot;devices.h&quot;<br>
&gt; +#include &quot;cpu_wp-mx51.h&quot;<br>
&gt;<br>
&gt;  #define BABBAGE_USB_HUB_RESET  (0*32 + 7)      /* GPIO_1_7 */<br>
&gt;  #define BABBAGE_USBH1_STP      (0*32 + 27)     /* GPIO_1_27 */<br>
&gt; @@ -279,8 +280,17 @@ static struct sys_timer mxc_timer = {<br>
&gt;        .init   = mx51_babbage_timer_init,<br>
&gt;  };<br>
&gt;<br>
&gt; +static void __init fixup_mxc_board(struct machine_desc *desc, struct tag *tags,<br>
&gt; +                                  char **cmdline, struct meminfo *mi)<br>
&gt; +{<br>
&gt; +#if defined(CONFIG_CPU_FREQ_IMX)<br>
&gt; +       get_cpu_wp = mx51_get_cpu_wp;<br>
<br>
</div>s/wp/op<br>
<div><div></div><div class="h5"><br>
&gt; +#endif<br>
&gt; +}<br>
&gt; +<br>
&gt;  MACHINE_START(MX51_BABBAGE, &quot;Freescale MX51 Babbage Board&quot;)<br>
&gt;        /* Maintainer: Amit Kucheria &lt;<a href="mailto:amit.kucheria@canonical.com">amit.kucheria@canonical.com</a>&gt; */<br>
&gt; +       .fixup = fixup_mxc_board,<br>
&gt;        .phys_io = MX51_AIPS1_BASE_ADDR,<br>
&gt;        .io_pg_offst = ((MX51_AIPS1_BASE_ADDR_VIRT) &gt;&gt; 18) &amp; 0xfffc,<br>
&gt;        .boot_params = PHYS_OFFSET + 0x100,<br>
&gt; diff --git a/arch/arm/mach-mx5/clock-mx51.c b/arch/arm/mach-mx5/clock-mx51.c<br>
&gt; index 6af69de..f23cfab 100644<br>
&gt; --- a/arch/arm/mach-mx5/clock-mx51.c<br>
&gt; +++ b/arch/arm/mach-mx5/clock-mx51.c<br>
&gt; @@ -39,6 +39,8 @@ static struct clk ahb_clk;<br>
&gt;  static struct clk ipg_clk;<br>
&gt;  static struct clk usboh3_clk;<br>
&gt;<br>
&gt; +DEFINE_SPINLOCK(clk_lock);<br>
&gt; +<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; @@ -342,6 +344,26 @@ static unsigned long clk_arm_get_rate(struct clk *clk)<br>
&gt;        return parent_rate / div;<br>
&gt;  }<br>
&gt;<br>
&gt; +static int _clk_cpu_set_rate(struct clk *clk, unsigned long rate)<br>
&gt; +{<br>
&gt; +       u32 reg, cpu_podf;<br>
&gt; +       unsigned long flags, parent_rate;<br>
&gt; +<br>
&gt; +       parent_rate = clk_get_rate(clk-&gt;parent);<br>
&gt; +       cpu_podf = parent_rate / rate - 1;<br>
&gt; +       /* use post divider to change freq */<br>
&gt; +       spin_lock_irqsave(&amp;clk_lock, flags);<br>
&gt; +<br>
&gt; +       reg = __raw_readl(MXC_CCM_CACRR);<br>
&gt; +       reg &amp;= ~MXC_CCM_CACRR_ARM_PODF_MASK;<br>
&gt; +       reg |= cpu_podf &lt;&lt; MXC_CCM_CACRR_ARM_PODF_OFFSET;<br>
&gt; +       __raw_writel(reg, MXC_CCM_CACRR);<br>
&gt; +<br>
&gt; +       spin_unlock_irqrestore(&amp;clk_lock, flags);<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 +716,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; @@ -837,6 +860,7 @@ static struct clk_lookup lookups[] = {<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(&quot;imx-keypad.0&quot;, NULL, kpp_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; diff --git a/arch/arm/mach-mx5/cpu.c b/arch/arm/mach-mx5/cpu.c<br>
&gt; index 2d37785..83add9c 100644<br>
&gt; --- a/arch/arm/mach-mx5/cpu.c<br>
&gt; +++ b/arch/arm/mach-mx5/cpu.c<br>
&gt; @@ -22,6 +22,8 @@ static int cpu_silicon_rev = -1;<br>
&gt;<br>
&gt;  #define SI_REV 0x48<br>
&gt;<br>
&gt; +struct cpu_wp *(*get_cpu_wp)(int *wp);<br>
&gt; +<br>
<br>
</div></div>s/wp/op<br>
<div class="im"><br>
&gt;  static void query_silicon_parameter(void)<br>
&gt;  {<br>
&gt;        void __iomem *rom = ioremap(MX51_IROM_BASE_ADDR, MX51_IROM_SIZE);<br>
&gt; diff --git a/arch/arm/mach-mx5/cpu_wp-mx51.c b/arch/arm/mach-mx5/cpu_wp-mx51.c<br>
&gt; new file mode 100644<br>
&gt; index 0000000..51bde45<br>
&gt; --- /dev/null<br>
&gt; +++ b/arch/arm/mach-mx5/cpu_wp-mx51.c<br>
<br>
</div>filename s/wp/op<br>
<div class="im"><br>
&gt; @@ -0,0 +1,42 @@<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; +#include &lt;linux/types.h&gt;<br>
&gt; +#include &lt;mach/hardware.h&gt;<br>
&gt; +<br>
&gt; +static struct cpu_wp cpu_wp_auto[] = {<br>
<br>
</div>s/cpu_wp/mx51_cpu_wp<br>
<br>
This also makes this struct explicity to mx51.<br>
<br>
&gt; +       {<br>
&gt; +       .pll_rate = 800000000,<br>
<div class="im">&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>
&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>
<br>
</div>Except for cpu_rate and cpu_voltage, I don&#39;t see the other fields<br>
being used anywhere.<br>
<div class="im"><br>
&gt; +struct cpu_wp *mx51_get_cpu_wp(int *wp)<br>
&gt; +{<br>
&gt; +       *wp = sizeof(cpu_wp_auto) / sizeof(struct cpu_wp);<br>
&gt; +       return cpu_wp_auto;<br>
&gt; +}<br>
<br>
</div>s/wp/op<br>
<div><div></div><div class="h5"><br>
&gt; diff --git a/arch/arm/mach-mx5/cpu_wp-mx51.h b/arch/arm/mach-mx5/cpu_wp-mx51.h<br>
&gt; new file mode 100644<br>
&gt; index 0000000..8038b62<br>
&gt; --- /dev/null<br>
&gt; +++ b/arch/arm/mach-mx5/cpu_wp-mx51.h<br>
&gt; @@ -0,0 +1,14 @@<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; +extern struct cpu_wp *mx51_get_cpu_wp(int *wp);<br>
&gt; diff --git a/arch/arm/plat-mxc/Makefile b/arch/arm/plat-mxc/Makefile<br>
&gt; index 78d405e..0b8464f 100644<br>
&gt; --- a/arch/arm/plat-mxc/Makefile<br>
&gt; +++ b/arch/arm/plat-mxc/Makefile<br>
&gt; @@ -16,6 +16,8 @@ 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;  obj-$(CONFIG_MXC_DEBUG_BOARD) += 3ds_debugboard.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..9990ea8<br>
&gt; --- /dev/null<br>
&gt; +++ b/arch/arm/plat-mxc/cpufreq.c<br>
&gt; @@ -0,0 +1,236 @@<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; + * A driver for the Freescale Semiconductor i.MXC CPUfreq module.<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; +<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; +static int cpu_freq_khz_min;<br>
&gt; +static int cpu_freq_khz_max;<br>
&gt; +static int arm_lpm_clk;<br>
&gt; +static int arm_normal_clk;<br>
&gt; +static int cpufreq_suspended;<br>
&gt; +<br>
&gt; +static struct clk *cpu_clk;<br>
&gt; +static struct cpufreq_frequency_table *imx_freq_table;<br>
&gt; +<br>
&gt; +static int cpu_wp_nr;<br>
&gt; +static struct cpu_wp *cpu_wp_tbl;<br>
&gt; +<br>
&gt; +static 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 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; +       unsigned int index;<br>
&gt; +<br>
&gt; +       if (cpufreq_suspended) {<br>
&gt; +               target_freq = clk_get_rate(cpu_clk) / 1000;<br>
&gt; +               cpufreq_frequency_table_target(policy, imx_freq_table,<br>
&gt; +                               target_freq, relation, &amp;index);<br>
&gt; +               freq_Hz = imx_freq_table[index].frequency * 1000;<br>
&gt; +<br>
&gt; +               if (freq_Hz == arm_lpm_clk)<br>
&gt; +                       freqs.old = cpu_wp_tbl[cpu_wp_nr - 2].cpu_rate / 1000;<br>
</div></div>                                                             ^^^^^^^^^^^^^<br>
Use an enum for the various OP names instead of depending on an<br>
operating point to be at a certain place in the table.<br>
<br>
&gt; +               else<br>
<div><div></div><div class="h5">&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; +       cpufreq_frequency_table_target(policy, imx_freq_table,<br>
&gt; +                       target_freq, relation, &amp;index);<br>
&gt; +       freq_Hz = imx_freq_table[index].frequency * 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_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; +       imx_freq_table = kmalloc(<br>
&gt; +               sizeof(struct cpufreq_frequency_table) * (cpu_wp_nr + 1),<br>
&gt; +                       GFP_KERNEL);<br>
&gt; +<br>
&gt; +       for (i = 0; i &lt; cpu_wp_nr; i++) {<br>
&gt; +               imx_freq_table[i].index = i;<br>
&gt; +               imx_freq_table[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 = i;<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_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_init,<br>
&gt; +       .exit = mxc_cpufreq_exit,<br>
&gt; +       .name = &quot;imx&quot;,<br>
&gt; +};<br>
&gt; +<br>
&gt; +static int __devinit mxc_cpufreq_driver_init(void)<br>
&gt; +{<br>
&gt; +       return cpufreq_register_driver(&amp;mxc_driver);<br>
&gt; +}<br>
&gt; +<br>
&gt; +static void mxc_cpufreq_driver_exit(void)<br>
&gt; +{<br>
&gt; +       cpufreq_unregister_driver(&amp;mxc_driver);<br>
&gt; +}<br>
&gt; +<br>
&gt; +module_init(mxc_cpufreq_driver_init);<br>
&gt; +module_exit(mxc_cpufreq_driver_exit);<br>
&gt; +<br>
&gt; +MODULE_AUTHOR(&quot;Freescale Semiconductor Inc. Yong Shen &lt;<a href="mailto:yong.shen@linaro.org">yong.shen@linaro.org</a>&gt;&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..31df991 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; @@ -1,5 +1,5 @@<br>
&gt;  /*<br>
&gt; - * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.<br>
&gt; + * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.<br>
<br>
</div></div>Copyright 2004-2007,2010 ?<br>
<div class="im"><br>
&gt;  * Copyright (C) 2008 Juergen Beisert (<a href="mailto:kernel@pengutronix.de">kernel@pengutronix.de</a>)<br>
&gt;  *<br>
&gt;  * This program is free software; you can redistribute it and/or<br>
&gt; @@ -133,6 +133,24 @@ 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>
<br>
</div>s/cpu_wp/mx51_cpu_wp<br>
<div><div></div><div class="h5"><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; +extern struct cpu_wp *(*get_cpu_wp)(int *wp);<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>
</div></div></blockquote></div><br></div></div>