Skip to contentSkip to conversation

cpufreq for freescale mx51

PATCH Superseded yong.shen at linaro.org 3 participants 10 messages Oct 8, 2010 – Oct 19, 2010

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/1 cpufreq for freescale mx51

From: Yong Shen <[email protected]>

it is tested on babbage 3.0

---
 arch/arm/Kconfig                       |    6 +
 arch/arm/mach-mx5/Kconfig              |    1 +
 arch/arm/mach-mx5/Makefile             |    1 +
 arch/arm/mach-mx5/board-mx51_babbage.c |   12 ++-
 arch/arm/mach-mx5/clock-mx51.c         |   24 ++++
 arch/arm/mach-mx5/cpu.c                |    2 +
 arch/arm/mach-mx5/cpu_wp-mx51.c        |   42 ++++++
 arch/arm/mach-mx5/cpu_wp-mx51.h        |   14 ++
 arch/arm/plat-mxc/Makefile             |    2 +
 arch/arm/plat-mxc/cpufreq.c            |  236 ++++++++++++++++++++++++++++++++
 arch/arm/plat-mxc/include/mach/mxc.h   |   20 +++-
 11 files changed, 358 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/mach-mx5/cpu_wp-mx51.c
 create mode 100644 arch/arm/mach-mx5/cpu_wp-mx51.h
 create mode 100644 arch/arm/plat-mxc/cpufreq.c
arch/arm/Kconfig +6 -0
index d203b84..71a572a 100644
@@ -1690,6 +1690,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
 	bool
 
arch/arm/mach-mx5/Kconfig +1 -0
index 0848db5..7a621b4 100644
@@ -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/Makefile +1 -0
index 86c66e7..e2af3fb 100644
@@ -5,6 +5,7 @@
 # Object file lists.
 obj-y   := cpu.o mm.o clock-mx51.o devices.o
 
+obj-$(CONFIG_CPU_FREQ_IMX)    += cpu_wp-mx51.o
 obj-$(CONFIG_MACH_MX51_BABBAGE) += board-mx51_babbage.o
 obj-$(CONFIG_MACH_MX51_3DS) += board-mx51_3ds.o
 obj-$(CONFIG_MACH_EUKREA_CPUIMX51) += board-cpuimx51.o
arch/arm/mach-mx5/board-mx51_babbage.c +11 -1
index 6e384d9..2d2a052 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
  * Copyright (C) 2009-2010 Amit Kucheria <[email protected]>
  *
  * The code contained herein is licensed under the GNU General Public
@@ -32,6 +32,7 @@
 #include <asm/mach/time.h>
 
 #include "devices.h"
+#include "cpu_wp-mx51.h"
 
 #define BABBAGE_USB_HUB_RESET	(0*32 + 7)	/* GPIO_1_7 */
 #define BABBAGE_USBH1_STP	(0*32 + 27)	/* GPIO_1_27 */
@@ -279,8 +280,17 @@ static struct sys_timer mxc_timer = {
 	.init	= mx51_babbage_timer_init,
 };
 
+static void __init fixup_mxc_board(struct machine_desc *desc, struct tag *tags,
+				   char **cmdline, struct meminfo *mi)
+{
+#if defined(CONFIG_CPU_FREQ_IMX)
+	get_cpu_wp = mx51_get_cpu_wp;
+#endif
+}
+
 MACHINE_START(MX51_BABBAGE, "Freescale MX51 Babbage Board")
 	/* Maintainer: Amit Kucheria <[email protected]> */
+	.fixup = fixup_mxc_board,
 	.phys_io = MX51_AIPS1_BASE_ADDR,
 	.io_pg_offst = ((MX51_AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
 	.boot_params = PHYS_OFFSET + 0x100,
arch/arm/mach-mx5/clock-mx51.c +24 -0
index 6af69de..f23cfab 100644
@@ -39,6 +39,8 @@ static struct clk ahb_clk;
 static struct clk ipg_clk;
 static struct clk usboh3_clk;
 
+DEFINE_SPINLOCK(clk_lock);
+
 #define MAX_DPLL_WAIT_TRIES	1000 /* 1000 * udelay(1) = 1ms */
 
 static int _clk_ccgr_enable(struct clk *clk)
@@ -342,6 +344,26 @@ static unsigned long clk_arm_get_rate(struct clk *clk)
 	return parent_rate / div;
 }
 
+static int _clk_cpu_set_rate(struct clk *clk, unsigned long rate)
+{
+	u32 reg, cpu_podf;
+	unsigned long flags, parent_rate;
+
+	parent_rate = clk_get_rate(clk->parent);
+	cpu_podf = parent_rate / rate - 1;
+	/* use post divider to change freq */
+	spin_lock_irqsave(&clk_lock, flags);
+
+	reg = __raw_readl(MXC_CCM_CACRR);
+	reg &= ~MXC_CCM_CACRR_ARM_PODF_MASK;
+	reg |= cpu_podf << MXC_CCM_CACRR_ARM_PODF_OFFSET;
+	__raw_writel(reg, MXC_CCM_CACRR);
+
+	spin_unlock_irqrestore(&clk_lock, flags);
+
+	return 0;
+}
+
 static int _clk_periph_apm_set_parent(struct clk *clk, struct clk *parent)
 {
 	u32 reg, mux;
@@ -694,6 +716,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 = {
@@ -837,6 +860,7 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("fsl-usb2-udc", "usb", usboh3_clk)
 	_REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", ahb_clk)
 	_REGISTER_CLOCK("imx-keypad.0", NULL, kpp_clk)
+	_REGISTER_CLOCK(NULL, "cpu_clk", cpu_clk)
 };
 
 static void clk_tree_init(void)
arch/arm/mach-mx5/cpu.c +2 -0
index 2d37785..83add9c 100644
@@ -22,6 +22,8 @@ static int cpu_silicon_rev = -1;
 
 #define SI_REV 0x48
 
+struct cpu_wp *(*get_cpu_wp)(int *wp);
+
 static void query_silicon_parameter(void)
 {
 	void __iomem *rom = ioremap(MX51_IROM_BASE_ADDR, MX51_IROM_SIZE);
arch/arm/mach-mx5/cpu_wp-mx51.c new file +42 -0

42 lines not on this page · raw message

arch/arm/mach-mx5/cpu_wp-mx51.h new file +14 -0
new file mode 100644
index 0000000..8038b62
@@ -0,0 +1,14 @@
+/*
+ * 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
+ */
+
+extern struct cpu_wp *mx51_get_cpu_wp(int *wp);
arch/arm/plat-mxc/Makefile +2 -0
index 78d405e..0b8464f 100644
@@ -16,6 +16,8 @@ obj-$(CONFIG_MXC_ULPI) += ulpi.o
 obj-$(CONFIG_ARCH_MXC_AUDMUX_V1) += audmux-v1.o
 obj-$(CONFIG_ARCH_MXC_AUDMUX_V2) += audmux-v2.o
 obj-$(CONFIG_MXC_DEBUG_BOARD) += 3ds_debugboard.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.o
arch/arm/plat-mxc/cpufreq.c new file +236 -0

236 lines not on this page · raw message

arch/arm/plat-mxc/include/mach/mxc.h +19 -1
index a790bf2..31df991 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
  * Copyright (C) 2008 Juergen Beisert (kernel at pengutronix.de)
  *
  * This program is free software; you can redistribute it and/or
@@ -133,6 +133,24 @@ 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;
+};
+
+extern struct cpu_wp *(*get_cpu_wp)(int *wp);
+#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
#2 lore raw

PATCH v2 1/1 cpufreq for freescale mx51

Yong,

Some more comments. But the patch is looking good now.

Quoted 3 lines · On Fri, Oct 8, 2010 at 11:08 AM, <[email protected]> wrote:

From: Yong Shen <[email protected]>

it is tested on babbage 3.0

Change to

"Cpufreq driver for imx51. The operating points are currently tested on babbage 3.0."

Quoted 55 lines

---

?arch/arm/Kconfig ? ? ? ? ? ? ? ? ? ? ? | ? ?6 +
?arch/arm/mach-mx5/Kconfig ? ? ? ? ? ? ?| ? ?1 +
?arch/arm/mach-mx5/Makefile ? ? ? ? ? ? | ? ?1 +
?arch/arm/mach-mx5/board-mx51_babbage.c | ? 12 ++-
?arch/arm/mach-mx5/clock-mx51.c ? ? ? ? | ? 24 ++++
?arch/arm/mach-mx5/cpu.c ? ? ? ? ? ? ? ?| ? ?2 +
?arch/arm/mach-mx5/cpu_wp-mx51.c ? ? ? ?| ? 42 ++++++
?arch/arm/mach-mx5/cpu_wp-mx51.h ? ? ? ?| ? 14 ++
?arch/arm/plat-mxc/Makefile ? ? ? ? ? ? | ? ?2 +
?arch/arm/plat-mxc/cpufreq.c ? ? ? ? ? ?| ?236 ++++++++++++++++++++++++++++++++
?arch/arm/plat-mxc/include/mach/mxc.h ? | ? 20 +++-

?11 files changed, 358 insertions(+), 2 deletions(-) ?create mode 100644 arch/arm/mach-mx5/cpu_wp-mx51.c ?create mode 100644 arch/arm/mach-mx5/cpu_wp-mx51.h ?create mode 100644 arch/arm/plat-mxc/cpufreq.c

arch/arm/Kconfig +0 -0
index d203b84..71a572a 100644
@@ -1690,6 +1690,12 @@ if ARCH_HAS_CPUFREQ
 

?source "drivers/cpufreq/Kconfig"

arch/arm/Kconfig +6 -0
+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
? ? ? ?bool

arch/arm/mach-mx5/Kconfig +0 -0
index 0848db5..7a621b4 100644
@@ -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/Makefile +0 -0
index 86c66e7..e2af3fb 100644
@@ -5,6 +5,7 @@

?# Object file lists.
?obj-y ? := cpu.o mm.o clock-mx51.o devices.o

Quoted 1 line

+obj-$(CONFIG_CPU_FREQ_IMX) ? ?+= cpu_wp-mx51.o

s/wp/op/ ?

Operating point is a more widely used word for frequency/voltage pairs in the ARM world. We will also want to consider using the OPP library currently being discussed elsewhere on LAKML. So change all instances of working point or wp to operating point or op.

Quoted 23 lines

?obj-$(CONFIG_MACH_MX51_BABBAGE) += board-mx51_babbage.o ?obj-$(CONFIG_MACH_MX51_3DS) += board-mx51_3ds.o ?obj-$(CONFIG_MACH_EUKREA_CPUIMX51) += board-cpuimx51.o

arch/arm/mach-mx5/board-mx51_babbage.c +0 -0
index 6e384d9..2d2a052 100644
@@ -1,5 +1,5 @@

?/*
- * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved. ?* Copyright (C) 2009-2010 Amit Kucheria <[email protected]> ?*
?* The code contained herein is licensed under the GNU General Public

arch/arm/mach-mx5/board-mx51_babbage.c +0 -0
@@ -32,6 +32,7 @@

?#include <asm/mach/time.h>

?#include "devices.h"
+#include "cpu_wp-mx51.h"

?#define BABBAGE_USB_HUB_RESET ?(0*32 + 7) ? ? ?/* GPIO_1_7 */ ?#define BABBAGE_USBH1_STP ? ? ?(0*32 + 27) ? ? /* GPIO_1_27 */

arch/arm/mach-mx5/board-mx51_babbage.c static struct sys_timer mxc_timer = { · line 287

Quoted 8 lines
arch/arm/mach-mx5/board-mx51_babbage.c +5 -0
@@ -279,8 +280,17 @@ static struct sys_timer mxc_timer = {
 ? ? ? ?.init ? = mx51_babbage_timer_init,
 ?};
 
+static void __init fixup_mxc_board(struct machine_desc *desc, struct tag *tags,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?char **cmdline, struct meminfo *mi)
+{
+#if defined(CONFIG_CPU_FREQ_IMX)
+ ? ? ? get_cpu_wp = mx51_get_cpu_wp;

s/wp/op

Quoted 73 lines
arch/arm/mach-mx5/board-mx51_babbage.c +3 -0
+#endif
+}
+
 ?MACHINE_START(MX51_BABBAGE, "Freescale MX51 Babbage Board")

? ? ? ?/* Maintainer: Amit Kucheria <[email protected]> */
+ ? ? ? .fixup = fixup_mxc_board,
? ? ? ?.phys_io = MX51_AIPS1_BASE_ADDR,
? ? ? ?.io_pg_offst = ((MX51_AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc, ? ? ? ?.boot_params = PHYS_OFFSET + 0x100,

arch/arm/mach-mx5/clock-mx51.c +2 -0
index 6af69de..f23cfab 100644
@@ -39,6 +39,8 @@ static struct clk ahb_clk;
 ?static struct clk ipg_clk;
 ?static struct clk usboh3_clk;
 
+DEFINE_SPINLOCK(clk_lock);
+

?#define MAX_DPLL_WAIT_TRIES ? ?1000 /* 1000 * udelay(1) = 1ms */

?static int _clk_ccgr_enable(struct clk *clk)

arch/arm/mach-mx5/clock-mx51.c +22 -0
@@ -342,6 +344,26 @@ static unsigned long clk_arm_get_rate(struct clk *clk)
 ? ? ? ?return parent_rate / div;
 ?}
 
+static int _clk_cpu_set_rate(struct clk *clk, unsigned long rate)
+{
+ ? ? ? u32 reg, cpu_podf;
+ ? ? ? unsigned long flags, parent_rate;
+
+ ? ? ? parent_rate = clk_get_rate(clk->parent);
+ ? ? ? cpu_podf = parent_rate / rate - 1;
+ ? ? ? /* use post divider to change freq */
+ ? ? ? spin_lock_irqsave(&clk_lock, flags);
+
+ ? ? ? reg = __raw_readl(MXC_CCM_CACRR);
+ ? ? ? reg &= ~MXC_CCM_CACRR_ARM_PODF_MASK;
+ ? ? ? reg |= cpu_podf << MXC_CCM_CACRR_ARM_PODF_OFFSET;
+ ? ? ? __raw_writel(reg, MXC_CCM_CACRR);
+
+ ? ? ? spin_unlock_irqrestore(&clk_lock, flags);
+
+ ? ? ? return 0;
+}
+
 ?static int _clk_periph_apm_set_parent(struct clk *clk, struct clk *parent)
 ?{
 ? ? ? ?u32 reg, mux;
@@ -694,6 +716,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 = {
@@ -837,6 +860,7 @@ static struct clk_lookup lookups[] = {
 ? ? ? ?_REGISTER_CLOCK("fsl-usb2-udc", "usb", usboh3_clk)
 ? ? ? ?_REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", ahb_clk)
 ? ? ? ?_REGISTER_CLOCK("imx-keypad.0", NULL, kpp_clk)
+ ? ? ? _REGISTER_CLOCK(NULL, "cpu_clk", cpu_clk)
 ?};
 
 ?static void clk_tree_init(void)
arch/arm/mach-mx5/cpu.c +0 -0
index 2d37785..83add9c 100644
@@ -22,6 +22,8 @@ static int cpu_silicon_rev = -1;
 

?#define SI_REV 0x48

arch/arm/mach-mx5/cpu.c static int cpu_silicon_rev = -1; · line 26

Quoted 2 lines
arch/arm/mach-mx5/cpu.c +2 -0
+struct cpu_wp *(*get_cpu_wp)(int *wp);
+

s/wp/op

arch/arm/mach-mx5/cpu_wp-mx51.c

Quoted 8 lines

?static void query_silicon_parameter(void)
?{
? ? ? ?void __iomem *rom = ioremap(MX51_IROM_BASE_ADDR, MX51_IROM_SIZE);

arch/arm/mach-mx5/cpu_wp-mx51.c new file +0 -0
new file mode 100644
index 0000000..51bde45

filename s/wp/op

Quoted 8 lines
arch/arm/mach-mx5/cpu_wp-mx51.c new file +7 -0
@@ -0,0 +1,42 @@
+/*
+ * 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

arch/arm/mach-mx5/cpu_wp-mx51.c line 17

Quoted 10 lines
arch/arm/mach-mx5/cpu_wp-mx51.c new file +10 -0
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/types.h>
+#include <mach/hardware.h>
+
+static struct cpu_wp cpu_wp_auto[] = {

s/cpu_wp/mx51_cpu_wp

This also makes this struct explicity to mx51.

Quoted 9 lines
arch/arm/mach-mx5/cpu_wp-mx51.c new file +9 -0
+ ? ? ? {
+ ? ? ? .pll_rate = 800000000,
+ ? ? ? .cpu_rate = 160000000,
+ ? ? ? .pdf = 4,
+ ? ? ? .mfi = 8,
+ ? ? ? .mfd = 2,
+ ? ? ? .mfn = 1,
+ ? ? ? .cpu_podf = 4,
+ ? ? ? .cpu_voltage = 850000,},

arch/arm/mach-mx5/cpu_wp-mx51.c line 36

Quoted 10 lines
arch/arm/mach-mx5/cpu_wp-mx51.c new file +10 -0
+ ? ? ? {
+ ? ? ? .pll_rate = 800000000,
+ ? ? ? .cpu_rate = 800000000,
+ ? ? ? .pdf = 0,
+ ? ? ? .mfi = 8,
+ ? ? ? .mfd = 2,
+ ? ? ? .mfn = 1,
+ ? ? ? .cpu_podf = 0,
+ ? ? ? .cpu_voltage = 1100000,},
+};

Except for cpu_rate and cpu_voltage, I don't see the other fields being used anywhere.

arch/arm/mach-mx5/cpu_wp-mx51.c line 42

Quoted 5 lines
arch/arm/mach-mx5/cpu_wp-mx51.c new file +5 -0
+struct cpu_wp *mx51_get_cpu_wp(int *wp)
+{
+ ? ? ? *wp = sizeof(cpu_wp_auto) / sizeof(struct cpu_wp);
+ ? ? ? return cpu_wp_auto;
+}

s/wp/op

Quoted 135 lines
arch/arm/mach-mx5/cpu_wp-mx51.h new file +14 -0
new file mode 100644
index 0000000..8038b62
@@ -0,0 +1,14 @@
+/*
+ * 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
+ */
+
+extern struct cpu_wp *mx51_get_cpu_wp(int *wp);
arch/arm/plat-mxc/Makefile +0 -0
index 78d405e..0b8464f 100644
@@ -16,6 +16,8 @@ obj-$(CONFIG_MXC_ULPI) += ulpi.o

?obj-$(CONFIG_ARCH_MXC_AUDMUX_V1) += audmux-v1.o ?obj-$(CONFIG_ARCH_MXC_AUDMUX_V2) += audmux-v2.o ?obj-$(CONFIG_MXC_DEBUG_BOARD) += 3ds_debugboard.o

arch/arm/plat-mxc/Makefile +2 -0
+# 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.o

arch/arm/plat-mxc/cpufreq.c new file +96 -0
new file mode 100644
index 0000000..9990ea8
@@ -0,0 +1,236 @@
+/*
+ * 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
+ */
+
+/*
+ * 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.
+ */
+
+#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>
+
+static int cpu_freq_khz_min;
+static int cpu_freq_khz_max;
+static int arm_lpm_clk;
+static int arm_normal_clk;
+static int cpufreq_suspended;
+
+static struct clk *cpu_clk;
+static struct cpufreq_frequency_table *imx_freq_table;
+
+static int cpu_wp_nr;
+static struct cpu_wp *cpu_wp_tbl;
+
+static 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 mxc_set_target(struct cpufreq_policy *policy,
+ ? ? ? ? ? ? ? ? ? ? ? ? unsigned int target_freq, unsigned int relation)
+{
+ ? ? ? struct cpufreq_freqs freqs;
+ ? ? ? int freq_Hz;
+ ? ? ? int ret = 0;

arch/arm/plat-mxc/cpufreq.c line 106

Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10 -0
+ ? ? ? unsigned int index;
+
+ ? ? ? if (cpufreq_suspended) {
+ ? ? ? ? ? ? ? target_freq = clk_get_rate(cpu_clk) / 1000;
+ ? ? ? ? ? ? ? cpufreq_frequency_table_target(policy, imx_freq_table,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? target_freq, relation, &index);
+ ? ? ? ? ? ? ? freq_Hz = imx_freq_table[index].frequency * 1000;
+
+ ? ? ? ? ? ? ? if (freq_Hz == arm_lpm_clk)
+ ? ? ? ? ? ? ? ? ? ? ? freqs.old = cpu_wp_tbl[cpu_wp_nr - 2].cpu_rate / 1000;
                                                             ^^^^^^^^^^^^^

Use an enum for the various OP names instead of depending on an operating point to be at a certain place in the table.

Quoted 135 lines
arch/arm/plat-mxc/cpufreq.c new file +130 -0
+ ? ? ? ? ? ? ? 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;
+ ? ? ? }
+
+ ? ? ? cpufreq_frequency_table_target(policy, imx_freq_table,
+ ? ? ? ? ? ? ? ? ? ? ? target_freq, relation, &index);
+ ? ? ? freq_Hz = imx_freq_table[index].frequency * 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_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);
+ ? ? ? }
+
+ ? ? ? /* 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;
+
+ ? ? ? imx_freq_table = kmalloc(
+ ? ? ? ? ? ? ? sizeof(struct cpufreq_frequency_table) * (cpu_wp_nr + 1),
+ ? ? ? ? ? ? ? ? ? ? ? GFP_KERNEL);
+
+ ? ? ? for (i = 0; i < cpu_wp_nr; i++) {
+ ? ? ? ? ? ? ? imx_freq_table[i].index = i;
+ ? ? ? ? ? ? ? imx_freq_table[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 = i;
+ ? ? ? 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;
+ ? ? ? }
+
+ ? ? ? cpufreq_frequency_table_get_attr(imx_freq_table, policy->cpu);
+ ? ? ? return 0;
+}
+
+static int mxc_cpufreq_exit(struct cpufreq_policy *policy)
+{
+ ? ? ? cpufreq_frequency_table_put_attr(policy->cpu);
+
+ ? ? ? /* Reset CPU to 665MHz */
+ ? ? ? set_cpu_freq(arm_normal_clk);
+ ? ? ? 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_init,
+ ? ? ? .exit = mxc_cpufreq_exit,
+ ? ? ? .name = "imx",
+};
+
+static int __devinit mxc_cpufreq_driver_init(void)
+{
+ ? ? ? return cpufreq_register_driver(&mxc_driver);
+}
+
+static void mxc_cpufreq_driver_exit(void)
+{
+ ? ? ? cpufreq_unregister_driver(&mxc_driver);
+}
+
+module_init(mxc_cpufreq_driver_init);
+module_exit(mxc_cpufreq_driver_exit);
+
+MODULE_AUTHOR("Freescale Semiconductor Inc. Yong Shen <[email protected]>");
+MODULE_DESCRIPTION("CPUfreq driver for i.MX");
+MODULE_LICENSE("GPL");
arch/arm/plat-mxc/include/mach/mxc.h +0 -0
index a790bf2..31df991 100644
@@ -1,5 +1,5 @@
Quoted 3 lines

?/*
- * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.

Copyright 2004-2007,2010 ?

arch/arm/plat-mxc/include/mach/mxc.h extern unsigned int __mxc_cpu_type; · line 138

Quoted 10 lines

?* Copyright (C) 2008 Juergen Beisert (kernel at pengutronix.de) ?*
?* This program is free software; you can redistribute it and/or

arch/arm/plat-mxc/include/mach/mxc.h +0 -0
@@ -133,6 +133,24 @@ extern unsigned int __mxc_cpu_type;
 ?# define cpu_is_mxc91231() ? ? (0)

?#endif

arch/arm/plat-mxc/include/mach/mxc.h +3 -0
+#ifndef __ASSEMBLY__
+
+struct cpu_wp {

s/cpu_wp/mx51_cpu_wp

Quoted 20 lines

+ ? ? ? 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;

arch/arm/plat-mxc/include/mach/mxc.h +5 -0
+};
+
+extern struct cpu_wp *(*get_cpu_wp)(int *wp);
+#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

author
#3 lore raw

PATCH v2 1/1 cpufreq for freescale mx51

Hi Amit,

I agree about all the comments. New patch is coming.

Yong

Quoted 587 lines · Amit Kucheria

Yong,

Some more comments. But the patch is looking good now.

Quoted 3 lines · On Fri, Oct 8, 2010 at 11:08 AM, <[email protected]> wrote:

From: Yong Shen <[email protected]>

it is tested on babbage 3.0

Change to

"Cpufreq driver for imx51. The operating points are currently tested on babbage 3.0."

Quoted 12 lines
---
 arch/arm/Kconfig                       |    6 +
 arch/arm/mach-mx5/Kconfig              |    1 +
 arch/arm/mach-mx5/Makefile             |    1 +
 arch/arm/mach-mx5/board-mx51_babbage.c |   12 ++-
 arch/arm/mach-mx5/clock-mx51.c         |   24 ++++
 arch/arm/mach-mx5/cpu.c                |    2 +
 arch/arm/mach-mx5/cpu_wp-mx51.c        |   42 ++++++
 arch/arm/mach-mx5/cpu_wp-mx51.h        |   14 ++
 arch/arm/plat-mxc/Makefile             |    2 +
 arch/arm/plat-mxc/cpufreq.c            |  236

++++++++++++++++++++++++++++++++

Quoted 40 lines
 arch/arm/plat-mxc/include/mach/mxc.h   |   20 +++-
 11 files changed, 358 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/mach-mx5/cpu_wp-mx51.c
 create mode 100644 arch/arm/mach-mx5/cpu_wp-mx51.h
 create mode 100644 arch/arm/plat-mxc/cpufreq.c
arch/arm/Kconfig +6 -0
index d203b84..71a572a 100644
@@ -1690,6 +1690,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
       bool
 
arch/arm/mach-mx5/Kconfig +1 -0
index 0848db5..7a621b4 100644
@@ -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/Makefile +0 -0
index 86c66e7..e2af3fb 100644

arch/arm/mach-mx5/Makefile line 8

Quoted 4 lines
arch/arm/mach-mx5/Makefile +1 -0
@@ -5,6 +5,7 @@
 # Object file lists.
 obj-y   := cpu.o mm.o clock-mx51.o devices.o
 
+obj-$(CONFIG_CPU_FREQ_IMX)    += cpu_wp-mx51.o

s/wp/op/ ?

Operating point is a more widely used word for frequency/voltage pairs in the ARM world. We will also want to consider using the OPP library currently being discussed elsewhere on LAKML. So change all instances of working point or wp to operating point or op.

Review

Quoted 4 lines
arch/arm/mach-mx5/Makefile +0 -0
 obj-$(CONFIG_MACH_MX51_BABBAGE) += board-mx51_babbage.o
 obj-$(CONFIG_MACH_MX51_3DS) += board-mx51_3ds.o
 obj-$(CONFIG_MACH_EUKREA_CPUIMX51) += board-cpuimx51.o
(quoted diff) +0 -0

b/arch/arm/mach-mx5/board-mx51_babbage.c

arch/arm/mach-mx5/board-mx51_babbage.c line 2

Quoted 7 lines

index 6e384d9..2d2a052 100644

arch/arm/mach-mx5/board-mx51_babbage.c +1 -1
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2009-2010 Freescale Semiconductor, Inc. All Rights

Reserved.

Quoted 12 lines
arch/arm/mach-mx5/board-mx51_babbage.c +1 -0
 * Copyright (C) 2009-2010 Amit Kucheria <[email protected]>
 *
 * The code contained herein is licensed under the GNU General Public
@@ -32,6 +32,7 @@
 #include <asm/mach/time.h>
 
 #include "devices.h"
+#include "cpu_wp-mx51.h"
 
 #define BABBAGE_USB_HUB_RESET  (0*32 + 7)      /* GPIO_1_7 */
 #define BABBAGE_USBH1_STP      (0*32 + 27)     /* GPIO_1_27 */

arch/arm/mach-mx5/board-mx51_babbage.c static struct sys_timer mxc_timer = { · line 283

Quoted 4 lines
arch/arm/mach-mx5/board-mx51_babbage.c +1 -0
@@ -279,8 +280,17 @@ static struct sys_timer mxc_timer = {
       .init   = mx51_babbage_timer_init,
 };
 
+static void __init fixup_mxc_board(struct machine_desc *desc, struct tag

*tags,

arch/arm/mach-mx5/board-mx51_babbage.c static struct sys_timer mxc_timer = { · line 287

Quoted 4 lines
arch/arm/mach-mx5/board-mx51_babbage.c +4 -0
+                                  char **cmdline, struct meminfo *mi)
+{
+#if defined(CONFIG_CPU_FREQ_IMX)
+       get_cpu_wp = mx51_get_cpu_wp;

s/wp/op

Review

Quoted 10 lines
arch/arm/mach-mx5/board-mx51_babbage.c +4 -0
+#endif
+}
+
 MACHINE_START(MX51_BABBAGE, "Freescale MX51 Babbage Board")
       /* Maintainer: Amit Kucheria <[email protected]> */
+       .fixup = fixup_mxc_board,
       .phys_io = MX51_AIPS1_BASE_ADDR,
       .io_pg_offst = ((MX51_AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
       .boot_params = PHYS_OFFSET + 0x100,
(quoted diff) +0 -0

b/arch/arm/mach-mx5/clock-mx51.c

arch/arm/mach-mx5/clock-mx51.c static unsigned long clk_arm_get_rate(struct clk

Quoted 13 lines

index 6af69de..f23cfab 100644

arch/arm/mach-mx5/clock-mx51.c +2 -0
@@ -39,6 +39,8 @@ static struct clk ahb_clk;
 static struct clk ipg_clk;
 static struct clk usboh3_clk;
 
+DEFINE_SPINLOCK(clk_lock);
+
 #define MAX_DPLL_WAIT_TRIES    1000 /* 1000 * udelay(1) = 1ms */
 
 static int _clk_ccgr_enable(struct clk *clk)
@@ -342,6 +344,26 @@ static unsigned long clk_arm_get_rate(struct clk

*clk)

Quoted 14 lines
arch/arm/mach-mx5/clock-mx51.c +11 -0
       return parent_rate / div;
 }
 
+static int _clk_cpu_set_rate(struct clk *clk, unsigned long rate)
+{
+       u32 reg, cpu_podf;
+       unsigned long flags, parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+       cpu_podf = parent_rate / rate - 1;
+       /* use post divider to change freq */
+       spin_lock_irqsave(&clk_lock, flags);
+
+       reg = __raw_readl(MXC_CCM_CACRR);

arch/arm/mach-mx5/clock-mx51.c static unsigned long clk_arm_get_rate(struct clk *clk)

Quoted 10 lines
arch/arm/mach-mx5/clock-mx51.c +9 -0
+       reg &= ~MXC_CCM_CACRR_ARM_PODF_MASK;
+       reg |= cpu_podf << MXC_CCM_CACRR_ARM_PODF_OFFSET;
+       __raw_writel(reg, MXC_CCM_CACRR);
+
+       spin_unlock_irqrestore(&clk_lock, flags);
+
+       return 0;
+}
+
 static int _clk_periph_apm_set_parent(struct clk *clk, struct clk

*parent)

Quoted 23 lines
arch/arm/mach-mx5/clock-mx51.c +2 -0
 {
       u32 reg, mux;
@@ -694,6 +716,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 = {
@@ -837,6 +860,7 @@ static struct clk_lookup lookups[] = {
       _REGISTER_CLOCK("fsl-usb2-udc", "usb", usboh3_clk)
       _REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", ahb_clk)
       _REGISTER_CLOCK("imx-keypad.0", NULL, kpp_clk)
+       _REGISTER_CLOCK(NULL, "cpu_clk", cpu_clk)
 };
 
 static void clk_tree_init(void)
arch/arm/mach-mx5/cpu.c +0 -0
index 2d37785..83add9c 100644

arch/arm/mach-mx5/cpu.c static int cpu_silicon_rev = -1; · line 26

Quoted 5 lines
arch/arm/mach-mx5/cpu.c +2 -0
@@ -22,6 +22,8 @@ static int cpu_silicon_rev = -1;
 
 #define SI_REV 0x48
 
+struct cpu_wp *(*get_cpu_wp)(int *wp);
+

s/wp/op

Review

Quoted 4 lines
arch/arm/mach-mx5/cpu.c +0 -0
 static void query_silicon_parameter(void)
 {
       void __iomem *rom = ioremap(MX51_IROM_BASE_ADDR, MX51_IROM_SIZE);
(quoted diff) +0 -0

b/arch/arm/mach-mx5/cpu_wp-mx51.c

arch/arm/mach-mx5/cpu_wp-mx51.c

Quoted 4 lines

new file mode 100644
index 0000000..51bde45

arch/arm/mach-mx5/cpu_wp-mx51.c new file +0 -0

filename s/wp/op

Quoted 8 lines
arch/arm/mach-mx5/cpu_wp-mx51.c new file +7 -0
@@ -0,0 +1,42 @@
+/*
+ * 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

arch/arm/mach-mx5/cpu_wp-mx51.c line 17

Quoted 10 lines
arch/arm/mach-mx5/cpu_wp-mx51.c new file +10 -0
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/types.h>
+#include <mach/hardware.h>
+
+static struct cpu_wp cpu_wp_auto[] = {

s/cpu_wp/mx51_cpu_wp

This also makes this struct explicity to mx51.

Quoted 9 lines
arch/arm/mach-mx5/cpu_wp-mx51.c new file +9 -0
+       {
+       .pll_rate = 800000000,
+       .cpu_rate = 160000000,
+       .pdf = 4,
+       .mfi = 8,
+       .mfd = 2,
+       .mfn = 1,
+       .cpu_podf = 4,
+       .cpu_voltage = 850000,},

arch/arm/mach-mx5/cpu_wp-mx51.c line 36

Quoted 10 lines
arch/arm/mach-mx5/cpu_wp-mx51.c new file +10 -0
+       {
+       .pll_rate = 800000000,
+       .cpu_rate = 800000000,
+       .pdf = 0,
+       .mfi = 8,
+       .mfd = 2,
+       .mfn = 1,
+       .cpu_podf = 0,
+       .cpu_voltage = 1100000,},
+};

Except for cpu_rate and cpu_voltage, I don't see the other fields being used anywhere.

arch/arm/mach-mx5/cpu_wp-mx51.c line 42

Quoted 5 lines
arch/arm/mach-mx5/cpu_wp-mx51.c new file +5 -0
+struct cpu_wp *mx51_get_cpu_wp(int *wp)
+{
+       *wp = sizeof(cpu_wp_auto) / sizeof(struct cpu_wp);
+       return cpu_wp_auto;
+}

s/wp/op

Review

Quoted 1 line
(quoted diff) +0 -0

b/arch/arm/mach-mx5/cpu_wp-mx51.h

Quoted 44 lines

new file mode 100644
index 0000000..8038b62

arch/arm/mach-mx5/cpu_wp-mx51.h new file +14 -0
@@ -0,0 +1,14 @@
+/*
+ * 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
+ */
+
+extern struct cpu_wp *mx51_get_cpu_wp(int *wp);
arch/arm/plat-mxc/Makefile +2 -0
index 78d405e..0b8464f 100644
@@ -16,6 +16,8 @@ obj-$(CONFIG_MXC_ULPI) += ulpi.o
 obj-$(CONFIG_ARCH_MXC_AUDMUX_V1) += audmux-v1.o
 obj-$(CONFIG_ARCH_MXC_AUDMUX_V2) += audmux-v2.o
 obj-$(CONFIG_MXC_DEBUG_BOARD) += 3ds_debugboard.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.o
arch/arm/plat-mxc/cpufreq.c new file +6 -0
new file mode 100644
index 0000000..9990ea8
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public

arch/arm/plat-mxc/cpufreq.c line 16

Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10 -0
+ * 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
+ */
+
+/*
+ * A driver for the Freescale Semiconductor i.MXC CPUfreq module.
+ * The CPUFREQ driver is for controling CPU frequency. It allows you to

change

Quoted 66 lines
arch/arm/plat-mxc/cpufreq.c new file +66 -0
+ * the CPU clock speed on the fly.
+ */
+
+#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>
+
+static int cpu_freq_khz_min;
+static int cpu_freq_khz_max;
+static int arm_lpm_clk;
+static int arm_normal_clk;
+static int cpufreq_suspended;
+
+static struct clk *cpu_clk;
+static struct cpufreq_frequency_table *imx_freq_table;
+
+static int cpu_wp_nr;
+static struct cpu_wp *cpu_wp_tbl;
+
+static 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);
+}
+

arch/arm/plat-mxc/cpufreq.c

Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10 -0
+static unsigned int mxc_get_speed(unsigned int cpu)
+{
+       if (cpu)
+               return 0;
+
+       return clk_get_rate(cpu_clk) / 1000;
+}
+
+static int mxc_set_target(struct cpufreq_policy *policy,
+                         unsigned int target_freq, unsigned int

relation)

Quoted 4 lines
arch/arm/plat-mxc/cpufreq.c new file +4 -0
+{
+       struct cpufreq_freqs freqs;
+       int freq_Hz;
+       int ret = 0;

arch/arm/plat-mxc/cpufreq.c

Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10 -0
+       unsigned int index;
+
+       if (cpufreq_suspended) {
+               target_freq = clk_get_rate(cpu_clk) / 1000;
+               cpufreq_frequency_table_target(policy, imx_freq_table,
+                               target_freq, relation, &index);
+               freq_Hz = imx_freq_table[index].frequency * 1000;
+
+               if (freq_Hz == arm_lpm_clk)
+                       freqs.old = cpu_wp_tbl[cpu_wp_nr - 2].cpu_rate /
1000;
                                                             ^^^^^^^^^^^^^

Use an enum for the various OP names instead of depending on an operating point to be at a certain place in the table.

Quoted 32 lines
arch/arm/plat-mxc/cpufreq.c new file +32 -0
+               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;
+       }
+
+       cpufreq_frequency_table_target(policy, imx_freq_table,
+                       target_freq, relation, &index);
+       freq_Hz = imx_freq_table[index].frequency * 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_init(struct cpufreq_policy *policy)
+{
+       int ret;

arch/arm/plat-mxc/cpufreq.c

Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10 -0
+       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__);

Quoted 76 lines
arch/arm/plat-mxc/cpufreq.c new file +76 -0
+               return PTR_ERR(cpu_clk);
+       }
+
+       /* 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;
+
+       imx_freq_table = kmalloc(
+               sizeof(struct cpufreq_frequency_table) * (cpu_wp_nr + 1),
+                       GFP_KERNEL);
+
+       for (i = 0; i < cpu_wp_nr; i++) {
+               imx_freq_table[i].index = i;
+               imx_freq_table[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 = i;
+       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;
+       }
+
+       cpufreq_frequency_table_get_attr(imx_freq_table, policy->cpu);
+       return 0;
+}
+
+static int mxc_cpufreq_exit(struct cpufreq_policy *policy)
+{
+       cpufreq_frequency_table_put_attr(policy->cpu);
+
+       /* Reset CPU to 665MHz */
+       set_cpu_freq(arm_normal_clk);
+       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_init,
+       .exit = mxc_cpufreq_exit,
+       .name = "imx",
+};
+
+static int __devinit mxc_cpufreq_driver_init(void)
+{
+       return cpufreq_register_driver(&mxc_driver);
+}

arch/arm/plat-mxc/cpufreq.c

Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10 -0
+
+static void mxc_cpufreq_driver_exit(void)
+{
+       cpufreq_unregister_driver(&mxc_driver);
+}
+
+module_init(mxc_cpufreq_driver_init);
+module_exit(mxc_cpufreq_driver_exit);
+
+MODULE_AUTHOR("Freescale Semiconductor Inc. Yong Shen <

yong.shen at linaro.org>");

Review

Quoted 3 lines
arch/arm/plat-mxc/cpufreq.c new file +2 -0
+MODULE_DESCRIPTION("CPUfreq driver for i.MX");
+MODULE_LICENSE("GPL");
(quoted diff) +0 -0

b/arch/arm/plat-mxc/include/mach/mxc.h

arch/arm/plat-mxc/include/mach/mxc.h line 2

Quoted 6 lines

index a790bf2..31df991 100644

arch/arm/plat-mxc/include/mach/mxc.h +0 -1
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights

Reserved.

arch/arm/plat-mxc/include/mach/mxc.h line 2

Quoted 1 line
arch/arm/plat-mxc/include/mach/mxc.h +1 -0
+ * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights

Reserved.

Copyright 2004-2007,2010 ?

arch/arm/plat-mxc/include/mach/mxc.h extern unsigned int __mxc_cpu_type; · line 138

Quoted 10 lines
arch/arm/plat-mxc/include/mach/mxc.h +3 -0
 * Copyright (C) 2008 Juergen Beisert (kernel at pengutronix.de)
 *
 * This program is free software; you can redistribute it and/or
@@ -133,6 +133,24 @@ extern unsigned int __mxc_cpu_type;
 # define cpu_is_mxc91231()     (0)
 #endif
 
+#ifndef __ASSEMBLY__
+
+struct cpu_wp {

s/cpu_wp/mx51_cpu_wp

Quoted 12 lines
arch/arm/plat-mxc/include/mach/mxc.h +12 -0
+       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;
+};
+
Quoted 9 lines
Quoted 8 lines
arch/arm/plat-mxc/include/mach/mxc.h +3 -1
+extern struct cpu_wp *(*get_cpu_wp)(int *wp);
+#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/20101018/640ebc87/attachment-0001.html>

maintainer
#4 lore raw

PATCH v2 1/1 cpufreq for freescale mx51

In reply to yong.shen at linaro.org
Quoted 105 lines · yong.shen at linaro.org

From: Yong Shen <[email protected]>

it is tested on babbage 3.0

---
 arch/arm/Kconfig                       |    6 +
 arch/arm/mach-mx5/Kconfig              |    1 +
 arch/arm/mach-mx5/Makefile             |    1 +
 arch/arm/mach-mx5/board-mx51_babbage.c |   12 ++-
 arch/arm/mach-mx5/clock-mx51.c         |   24 ++++
 arch/arm/mach-mx5/cpu.c                |    2 +
 arch/arm/mach-mx5/cpu_wp-mx51.c        |   42 ++++++
 arch/arm/mach-mx5/cpu_wp-mx51.h        |   14 ++
 arch/arm/plat-mxc/Makefile             |    2 +
 arch/arm/plat-mxc/cpufreq.c            |  236 ++++++++++++++++++++++++++++++++
 arch/arm/plat-mxc/include/mach/mxc.h   |   20 +++-
 11 files changed, 358 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/mach-mx5/cpu_wp-mx51.c
 create mode 100644 arch/arm/mach-mx5/cpu_wp-mx51.h
 create mode 100644 arch/arm/plat-mxc/cpufreq.c
arch/arm/Kconfig +6 -0
index d203b84..71a572a 100644
@@ -1690,6 +1690,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
 	bool
 
arch/arm/mach-mx5/Kconfig +1 -0
index 0848db5..7a621b4 100644
@@ -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/Makefile +1 -0
index 86c66e7..e2af3fb 100644
@@ -5,6 +5,7 @@
 # Object file lists.
 obj-y   := cpu.o mm.o clock-mx51.o devices.o
 
+obj-$(CONFIG_CPU_FREQ_IMX)    += cpu_wp-mx51.o
 obj-$(CONFIG_MACH_MX51_BABBAGE) += board-mx51_babbage.o
 obj-$(CONFIG_MACH_MX51_3DS) += board-mx51_3ds.o
 obj-$(CONFIG_MACH_EUKREA_CPUIMX51) += board-cpuimx51.o
arch/arm/mach-mx5/board-mx51_babbage.c +11 -1
index 6e384d9..2d2a052 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
  * Copyright (C) 2009-2010 Amit Kucheria <[email protected]>
  *
  * The code contained herein is licensed under the GNU General Public
@@ -32,6 +32,7 @@
 #include <asm/mach/time.h>
 
 #include "devices.h"
+#include "cpu_wp-mx51.h"
 
 #define BABBAGE_USB_HUB_RESET	(0*32 + 7)	/* GPIO_1_7 */
 #define BABBAGE_USBH1_STP	(0*32 + 27)	/* GPIO_1_27 */
@@ -279,8 +280,17 @@ static struct sys_timer mxc_timer = {
 	.init	= mx51_babbage_timer_init,
 };
 
+static void __init fixup_mxc_board(struct machine_desc *desc, struct tag *tags,
+				   char **cmdline, struct meminfo *mi)
+{
+#if defined(CONFIG_CPU_FREQ_IMX)
+	get_cpu_wp = mx51_get_cpu_wp;
+#endif
+}
+
 MACHINE_START(MX51_BABBAGE, "Freescale MX51 Babbage Board")
 	/* Maintainer: Amit Kucheria <[email protected]> */
+	.fixup = fixup_mxc_board,
 	.phys_io = MX51_AIPS1_BASE_ADDR,
 	.io_pg_offst = ((MX51_AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
 	.boot_params = PHYS_OFFSET + 0x100,
arch/arm/mach-mx5/clock-mx51.c +0 -0
index 6af69de..f23cfab 100644

arch/arm/mach-mx5/clock-mx51.c static struct clk ahb_clk; · line 42

Quoted 4 lines
arch/arm/mach-mx5/clock-mx51.c +1 -0
@@ -39,6 +39,8 @@ static struct clk ahb_clk;
 static struct clk ipg_clk;
 static struct clk usboh3_clk;
 
+DEFINE_SPINLOCK(clk_lock);

static, if needed at all.

Quoted 14 lines
arch/arm/mach-mx5/clock-mx51.c +7 -0
+
 #define MAX_DPLL_WAIT_TRIES	1000 /* 1000 * udelay(1) = 1ms */
 
 static int _clk_ccgr_enable(struct clk *clk)
@@ -342,6 +344,26 @@ static unsigned long clk_arm_get_rate(struct clk *clk)
 	return parent_rate / div;
 }
 
+static int _clk_cpu_set_rate(struct clk *clk, unsigned long rate)
+{
+	u32 reg, cpu_podf;
+	unsigned long flags, parent_rate;
+
+	parent_rate = clk_get_rate(clk->parent);

arch/arm/mach-mx5/clock-mx51.c static unsigned long clk_arm_get_rate(struct clk *clk) · line 362

Quoted 10 lines
arch/arm/mach-mx5/clock-mx51.c +10 -0
+	cpu_podf = parent_rate / rate - 1;
+	/* use post divider to change freq */
+	spin_lock_irqsave(&clk_lock, flags);
+
+	reg = __raw_readl(MXC_CCM_CACRR);
+	reg &= ~MXC_CCM_CACRR_ARM_PODF_MASK;
+	reg |= cpu_podf << MXC_CCM_CACRR_ARM_PODF_OFFSET;
+	__raw_writel(reg, MXC_CCM_CACRR);
+
+	spin_unlock_irqrestore(&clk_lock, flags);

Why this spinlock? The whole clock code is protected by a mutex already.

arch/arm/mach-mx5/clock-mx51.c static struct clk periph_apm_clk = { · line 719

Quoted 12 lines
arch/arm/mach-mx5/clock-mx51.c +5 -0
+
+	return 0;
+}
+
 static int _clk_periph_apm_set_parent(struct clk *clk, struct clk *parent)
 {
 	u32 reg, mux;
@@ -694,6 +716,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,

The names should be consistent. Either clk_arm_[sg]et_rate or clk_cpu. ALso, please remove those leading underscores.

Quoted 16 lines
arch/arm/mach-mx5/clock-mx51.c +1 -0
 };
 
 static struct clk ahb_clk = {
@@ -837,6 +860,7 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("fsl-usb2-udc", "usb", usboh3_clk)
 	_REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", ahb_clk)
 	_REGISTER_CLOCK("imx-keypad.0", NULL, kpp_clk)
+	_REGISTER_CLOCK(NULL, "cpu_clk", cpu_clk)
 };
 
 static void clk_tree_init(void)
arch/arm/mach-mx5/cpu.c +0 -0
index 2d37785..83add9c 100644

arch/arm/mach-mx5/cpu.c static int cpu_silicon_rev = -1; · line 26

Quoted 5 lines
arch/arm/mach-mx5/cpu.c +2 -0
@@ -22,6 +22,8 @@ static int cpu_silicon_rev = -1;
 
 #define SI_REV 0x48
 
+struct cpu_wp *(*get_cpu_wp)(int *wp);
+

This is not needed.

Quoted 39 lines
arch/arm/mach-mx5/cpu.c +0 -0
 static void query_silicon_parameter(void)
 {
 	void __iomem *rom = ioremap(MX51_IROM_BASE_ADDR, MX51_IROM_SIZE);
arch/arm/mach-mx5/cpu_wp-mx51.c new file +30 -0
new file mode 100644
index 0000000..51bde45
@@ -0,0 +1,42 @@
+/*
+ * 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
+ */
+
+#include <linux/types.h>
+#include <mach/hardware.h>
+
+static struct cpu_wp cpu_wp_auto[] = {
+	{
+	.pll_rate = 800000000,
+	.cpu_rate = 160000000,
+	.pdf = 4,
+	.mfi = 8,
+	.mfd = 2,
+	.mfn = 1,
+	.cpu_podf = 4,
+	.cpu_voltage = 850000,},
+	{
+	.pll_rate = 800000000,
+	.cpu_rate = 800000000,
+	.pdf = 0,

arch/arm/mach-mx5/cpu_wp-mx51.c line 40

Quoted 10 lines
arch/arm/mach-mx5/cpu_wp-mx51.c new file +10 -0
+	.mfi = 8,
+	.mfd = 2,
+	.mfn = 1,
+	.cpu_podf = 0,
+	.cpu_voltage = 1100000,},
+};
+
+struct cpu_wp *mx51_get_cpu_wp(int *wp)
+{
+	*wp = sizeof(cpu_wp_auto) / sizeof(struct cpu_wp);

use ARRAY_SIZE here.

Quoted 27 lines
arch/arm/mach-mx5/cpu_wp-mx51.c new file +2 -0
+	return cpu_wp_auto;
+}
arch/arm/mach-mx5/cpu_wp-mx51.h new file +14 -0
new file mode 100644
index 0000000..8038b62
@@ -0,0 +1,14 @@
+/*
+ * 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
+ */
+
+extern struct cpu_wp *mx51_get_cpu_wp(int *wp);
arch/arm/plat-mxc/Makefile +0 -0
index 78d405e..0b8464f 100644

arch/arm/plat-mxc/Makefile obj-$(CONFIG_MXC_ULPI) += ulpi.o · line 20

Quoted 5 lines
arch/arm/plat-mxc/Makefile +2 -0
@@ -16,6 +16,8 @@ obj-$(CONFIG_MXC_ULPI) += ulpi.o
 obj-$(CONFIG_ARCH_MXC_AUDMUX_V1) += audmux-v1.o
 obj-$(CONFIG_ARCH_MXC_AUDMUX_V2) += audmux-v2.o
 obj-$(CONFIG_MXC_DEBUG_BOARD) += 3ds_debugboard.o
+# CPU FREQ support
+obj-$(CONFIG_CPU_FREQ_IMX)    += cpufreq.o

I think most people digging in kernel code get that without the comment.

Quoted 32 lines
arch/arm/plat-mxc/Makefile +0 -0
 ifdef CONFIG_SND_IMX_SOC
 obj-y += ssi-fiq.o
 obj-y += ssi-fiq-ksym.o
arch/arm/plat-mxc/cpufreq.c new file +23 -0
new file mode 100644
index 0000000..9990ea8
@@ -0,0 +1,236 @@
+/*
+ * 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
+ */
+
+/*
+ * 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.
+ */
+
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/cpufreq.h>
+#include <linux/init.h>

arch/arm/plat-mxc/cpufreq.c line 33

Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10 -0
+#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>

Please clean up the includes. At least linux/proc_fs.h, linux/regulator/consumer.h, asm/cacheflush.h and linux/hrtimer.h are unused.

Quoted 21 lines
arch/arm/plat-mxc/cpufreq.c new file +21 -0
+
+static int cpu_freq_khz_min;
+static int cpu_freq_khz_max;
+static int arm_lpm_clk;
+static int arm_normal_clk;
+static int cpufreq_suspended;
+
+static struct clk *cpu_clk;
+static struct cpufreq_frequency_table *imx_freq_table;
+
+static int cpu_wp_nr;
+static struct cpu_wp *cpu_wp_tbl;
+
+static 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);

arch/arm/plat-mxc/cpufreq.c line 64

Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10 -0
+	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;

I can't see why we need this check here. This can only happen when the table is not correctly initialized. Furthermore, cpu voltages are not handled yet. I'm sure we'll find a better place for this check once we start supporting voltage changes, so I think you can remove it here.

Quoted 25 lines
arch/arm/plat-mxc/cpufreq.c new file +25 -0
+
+	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;
+}

arch/arm/plat-mxc/cpufreq.c line 99

Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +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;
+	unsigned int index;
+
+	if (cpufreq_suspended) {

cpufreq_suspended is never set in this code, so please remove this until we get a user for this.

Quoted 44 lines
arch/arm/plat-mxc/cpufreq.c new file +44 -0
+		target_freq = clk_get_rate(cpu_clk) / 1000;
+		cpufreq_frequency_table_target(policy, imx_freq_table,
+				target_freq, relation, &index);
+		freq_Hz = imx_freq_table[index].frequency * 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;
+	}
+
+	cpufreq_frequency_table_target(policy, imx_freq_table,
+			target_freq, relation, &index);
+	freq_Hz = imx_freq_table[index].frequency * 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_init(struct cpufreq_policy *policy)
+{
+	int ret;
+	int i;
+
+	printk(KERN_INFO "i.MXC CPU frequency driver\n");
+
+	if (policy->cpu != 0)

arch/arm/plat-mxc/cpufreq.c line 153

Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10 -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);
+	}
+
+	/* Set the current working point. */
+	cpu_wp_tbl = get_cpu_wp(&cpu_wp_nr);

The comment seems to have nothing to do with what the code does. You don't set a workpoint here but get the table of available workpoints.

arch/arm/plat-mxc/cpufreq.c line 160

Quoted 7 lines
arch/arm/plat-mxc/cpufreq.c new file +7 -0
+
+	cpu_freq_khz_min = cpu_wp_tbl[0].cpu_rate / 1000;
+	cpu_freq_khz_max = cpu_wp_tbl[0].cpu_rate / 1000;
+
+	imx_freq_table = kmalloc(
+		sizeof(struct cpufreq_frequency_table) * (cpu_wp_nr + 1),
+			GFP_KERNEL);

kmalloc can fail.

Quoted 16 lines
arch/arm/plat-mxc/cpufreq.c new file +16 -0
+
+	for (i = 0; i < cpu_wp_nr; i++) {
+		imx_freq_table[i].index = i;
+		imx_freq_table[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 = i;
+	imx_freq_table[i].frequency = CPUFREQ_TABLE_END;
+

arch/arm/plat-mxc/cpufreq.c line 186

Quoted 10 lines
arch/arm/plat-mxc/cpufreq.c new file +10 -0
+	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;

transition_latency is in nano seconds, the correct value here is 2/32768*1000*1000*1000 = 61035.

arch/arm/plat-mxc/cpufreq.c line 193

Quoted 7 lines
arch/arm/plat-mxc/cpufreq.c new file +7 -0
+
+	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__);

It's always good to print the error code with such messages.

arch/arm/plat-mxc/cpufreq.c line 206

Quoted 13 lines
arch/arm/plat-mxc/cpufreq.c new file +13 -0
+		return ret;
+	}
+
+	cpufreq_frequency_table_get_attr(imx_freq_table, policy->cpu);
+	return 0;
+}
+
+static int mxc_cpufreq_exit(struct cpufreq_policy *policy)
+{
+	cpufreq_frequency_table_put_attr(policy->cpu);
+
+	/* Reset CPU to 665MHz */
+	set_cpu_freq(arm_normal_clk);

arm_normal_clk is initialized to cpu_freq_khz_max * 1000 and never touched again. It would be clearer here to remove arm_normal_clk and write cpu_freq_khz_max * 1000 directly here. Then you can also remove the comment which is wrong for most i.MXs, even for the i.MX51.

Also, you forget to kfree the resources alloced above.

Quoted 75 lines
arch/arm/plat-mxc/cpufreq.c new file +30 -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_init,
+	.exit = mxc_cpufreq_exit,
+	.name = "imx",
+};
+
+static int __devinit mxc_cpufreq_driver_init(void)
+{
+	return cpufreq_register_driver(&mxc_driver);
+}
+
+static void mxc_cpufreq_driver_exit(void)
+{
+	cpufreq_unregister_driver(&mxc_driver);
+}
+
+module_init(mxc_cpufreq_driver_init);
+module_exit(mxc_cpufreq_driver_exit);
+
+MODULE_AUTHOR("Freescale Semiconductor Inc. Yong Shen <[email protected]>");
+MODULE_DESCRIPTION("CPUfreq driver for i.MX");
+MODULE_LICENSE("GPL");
arch/arm/plat-mxc/include/mach/mxc.h +19 -1
index a790bf2..31df991 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
  * Copyright (C) 2008 Juergen Beisert (kernel at pengutronix.de)
  *
  * This program is free software; you can redistribute it and/or
@@ -133,6 +133,24 @@ 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;
+};
+
+extern struct cpu_wp *(*get_cpu_wp)(int *wp);
+#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 · 7 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
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 |
author
#5 lore raw

PATCH v2 1/1 cpufreq for freescale mx51

Hi Sascha,

Thanks for your thorough review. I have two feedbacks to your commends. Sorry for delayed response, cause I had a hard time due to my computer crash and data loss.

Quoted 26 lines
arch/arm/mach-mx5/cpu.c +0 -0

arch/arm/mach-mx5/cpu.c static int cpu_silicon_rev = -1; · line 26

Quoted 9 lines

index 2d37785..83add9c 100644

arch/arm/mach-mx5/cpu.c +2 -0
@@ -22,6 +22,8 @@ static int cpu_silicon_rev = -1;
 
 #define SI_REV 0x48
 
+struct cpu_wp *(*get_cpu_wp)(int *wp);
+

This is not needed.

This is needed, otherwise it does not pass compile.

Quoted 10 lines
arch/arm/mach-mx5/cpu.c +10 -0
+             return ret;
+     }
+
+     cpufreq_frequency_table_get_attr(imx_freq_table, policy->cpu);
+     return 0;
+}
+
+static int mxc_cpufreq_exit(struct cpufreq_policy *policy)
+{
+     cpufreq_frequency_table_put_attr(policy->cpu);
Quoted 10 lines

arch/arm/mach-mx5/cpu.c

Quoted 3 lines
arch/arm/mach-mx5/cpu.c +3 -0
+
+     /* Reset CPU to 665MHz */
+     set_cpu_freq(arm_normal_clk);

arm_normal_clk is initialized to cpu_freq_khz_max * 1000 and never touched again. It would be clearer here to remove arm_normal_clk and write cpu_freq_khz_max * 1000 directly here. Then you can also remove the comment which is wrong for most i.MXs, even for the i.MX51.

Actually, this is arm_normal_clk is touched later in mxc_cpufreq_exit() fuction.

Yong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20101018/9e3e23a6/attachment-0001.html>

maintainer
#6 lore raw

PATCH v2 1/1 cpufreq for freescale mx51

Hi Yong,

Quoted 12 lines · Yong Shen

Hi Sascha,

Thanks for your thorough review. I have two feedbacks to your commends. Sorry for delayed response, cause I had a hard time due to my computer crash and data loss.

Quoted 6 lines
arch/arm/mach-mx5/cpu.c +0 -0
Quoted 5 lines

index 2d37785..83add9c 100644

arch/arm/mach-mx5/cpu.c +0 -0
@@ -22,6 +22,8 @@ static int cpu_silicon_rev = -1;
 
Quoted 8 lines
Quoted 7 lines

arch/arm/mach-mx5/cpu.c static int cpu_silicon_rev = -1; · line 26

Quoted 4 lines
arch/arm/mach-mx5/cpu.c +2 -0
 #define SI_REV 0x48
 
+struct cpu_wp *(*get_cpu_wp)(int *wp);
+

This is not needed.

This is needed, otherwise it does not pass compile.

This hunk is the only change to arch/arm/mach-mx5/cpu.c and get_cpu_wp is introduced with this patch, so how can this break compilation? Also, you should move this to a header file. Otherwise you risk of having multiple (and possibly different) declarations of the same function which can lead to hard to find bugs.

Quoted 22 lines
Quoted 12 lines
Quoted 12 lines
arch/arm/mach-mx5/cpu.c +10 -0
+             return ret;
+     }
+
+     cpufreq_frequency_table_get_attr(imx_freq_table, policy->cpu);
+     return 0;
+}
+
+static int mxc_cpufreq_exit(struct cpufreq_policy *policy)
+{
+     cpufreq_frequency_table_put_attr(policy->cpu);
Quoted 10 lines

arch/arm/mach-mx5/cpu.c

Quoted 3 lines
arch/arm/mach-mx5/cpu.c +3 -0
+
+     /* Reset CPU to 665MHz */
+     set_cpu_freq(arm_normal_clk);

arm_normal_clk is initialized to cpu_freq_khz_max * 1000 and never touched again. It would be clearer here to remove arm_normal_clk and write cpu_freq_khz_max * 1000 directly here. Then you can also remove the comment which is wrong for most i.MXs, even for the i.MX51.

Quoted 2 lines

Actually, this is arm_normal_clk is touched later in mxc_cpufreq_exit() fuction.

It's *read* but not changed. That's why I suggested to just remove arm_normal_clk and instead do a set_cpu_freq(cpu_freq_khz_max * 1000) in mxc_cpufreq_exit.

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 |
author
#7 lore raw

PATCH v2 1/1 cpufreq for freescale mx51

Hi Sascha,

Quoted 23 lines · Sascha Hauer

Hi Yong,

Quoted 4 lines · Yong Shen

Hi Sascha,

Thanks for your thorough review. I have two feedbacks to your commends. Sorry for delayed response, cause I had a hard time due to my computer

crash

Quoted 15 lines

and data loss.

Quoted 13 lines
arch/arm/mach-mx5/cpu.c +0 -0

arch/arm/mach-mx5/cpu.c static int cpu_silicon_rev = -1; · line 26

Quoted 9 lines

index 2d37785..83add9c 100644

arch/arm/mach-mx5/cpu.c +2 -0
@@ -22,6 +22,8 @@ static int cpu_silicon_rev = -1;
 
 #define SI_REV 0x48
 
+struct cpu_wp *(*get_cpu_wp)(int *wp);
+

This is not needed.

Quoted 8 lines
Quoted 1 line

This is needed, otherwise it does not pass compile.

This hunk is the only change to arch/arm/mach-mx5/cpu.c and get_cpu_wp is introduced with this patch, so how can this break compilation? Also, you should move this to a header file. Otherwise you risk of having multiple (and possibly different) declarations of the same function which can lead to hard to find bugs.

IMHO, get_cpu_wp is definition rather than a declaration and without it
there will be errors in link phase. its declaration is in arch/arm/plat-mxc/include/mach/mxc.h.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20101018/d4c26487/attachment-0001.html>

maintainer
#8 lore raw

PATCH v2 1/1 cpufreq for freescale mx51

Quoted 36 lines · Yong Shen

Hi Sascha,

Quoted 23 lines · Sascha Hauer

Hi Yong,

Quoted 4 lines · Yong Shen

Hi Sascha,

Thanks for your thorough review. I have two feedbacks to your commends. Sorry for delayed response, cause I had a hard time due to my computer

crash

Quoted 15 lines

and data loss.

Quoted 13 lines
arch/arm/mach-mx5/cpu.c +0 -0

arch/arm/mach-mx5/cpu.c static int cpu_silicon_rev = -1; · line 26

Quoted 9 lines

index 2d37785..83add9c 100644

arch/arm/mach-mx5/cpu.c +2 -0
@@ -22,6 +22,8 @@ static int cpu_silicon_rev = -1;
 
 #define SI_REV 0x48
 
+struct cpu_wp *(*get_cpu_wp)(int *wp);
+

This is not needed.

Quoted 8 lines
Quoted 1 line

This is needed, otherwise it does not pass compile.

This hunk is the only change to arch/arm/mach-mx5/cpu.c and get_cpu_wp is introduced with this patch, so how can this break compilation? Also, you should move this to a header file. Otherwise you risk of having multiple (and possibly different) declarations of the same function which can lead to hard to find bugs.

Quoted 3 lines

IMHO, get_cpu_wp is definition rather than a declaration and without it there will be errors in link phase. its declaration is in arch/arm/plat-mxc/include/mach/mxc.h.

Of course, you are right, my bad. Isn't this function common to al i.MXs? In this case it should be somewhere in plat-mxc. Anyway, it seems very odd to me to provide a global function pointer which gets overwritten by the boards. For me it is more logical to provide a mxc_register_workpoints() function along with a mxc_for_each_workpoint() iterator.

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 |
author
#9 lore raw

PATCH v2 1/1 cpufreq for freescale mx51

Quoted 20 lines
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

arch/arm/mach-mx5/cpu.c static int cpu_silicon_rev = -1; · line 26

Quoted 5 lines
arch/arm/mach-mx5/cpu.c +2 -0
+struct cpu_wp *(*get_cpu_wp)(int *wp);
+

This is not needed.

Quoted 8 lines
Quoted 1 line

This is needed, otherwise it does not pass compile.

This hunk is the only change to arch/arm/mach-mx5/cpu.c and get_cpu_wp is introduced with this patch, so how can this break compilation? Also, you should move this to a header file. Otherwise you risk of having multiple (and possibly different) declarations of the same function which can lead to hard to find bugs.

Quoted 3 lines

IMHO, get_cpu_wp is definition rather than a declaration and without it there will be errors in link phase. its declaration is in arch/arm/plat-mxc/include/mach/mxc.h.

Quoted 8 lines

Of course, you are right, my bad. Isn't this function common to al i.MXs? In this case it should be somewhere in plat-mxc. Anyway, it seems very odd to me to provide a global function pointer which gets overwritten by the boards. For me it is more logical to provide a mxc_register_workpoints() function along with a mxc_for_each_workpoint() iterator.

About this, I am thinking move the global function pointer to

plat-mxc/cpufreq.c and add protection before call the function pointer.
Anyway, it is just about provide cpu operating points to cpufreq driver,
right? Even, mxc_register_workpoints() has to go some where in cpufreq.c and
export a declaration in a head file, also it needs to be called before
cpufreq initialization. IMO, it's merely a preference of individuals. No
offence about that, correct me:)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20101019/505075ec/attachment-0001.html>