ARM: imx: add cpuidle support for i.mx6sl
authorAnson Huang <b20788@freescale.com>
Thu, 9 Jan 2014 08:03:16 +0000 (16:03 +0800)
committerShawn Guo <shawn.guo@linaro.org>
Wed, 5 Mar 2014 02:35:01 +0000 (10:35 +0800)
Add cpuidle support for i.MX6SL, currently only support
two cpuidle levels(ARM wfi and WAIT mode), and add software
workaround for WAIT mode errata as below:

ERR005311 CCM: After exit from WAIT mode, unwanted interrupt(s) taken
          during WAIT mode entry process could cause cache memory
          corruption.

Software workaround:
    To prevent this issue from occurring, software should ensure that
the ARM to IPG clock ratio is less than 12:5 (that is < 2.4x), before
entering WAIT mode.

Signed-off-by: Anson Huang <b20788@freescale.com>
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
arch/arm/mach-imx/Makefile
arch/arm/mach-imx/clk-imx6sl.c
arch/arm/mach-imx/common.h
arch/arm/mach-imx/cpuidle-imx6sl.c [new file with mode: 0644]
arch/arm/mach-imx/cpuidle.h
arch/arm/mach-imx/mach-imx6sl.c

index ec419649320ffe8fd6cae929d4664ae8071c9fff..21114a9a2ae7983c7cf4630d56b8bef0639aff62 100644 (file)
@@ -30,6 +30,7 @@ obj-$(CONFIG_MXC_DEBUG_BOARD) += 3ds_debugboard.o
 ifeq ($(CONFIG_CPU_IDLE),y)
 obj-$(CONFIG_SOC_IMX5) += cpuidle-imx5.o
 obj-$(CONFIG_SOC_IMX6Q) += cpuidle-imx6q.o
+obj-$(CONFIG_SOC_IMX6SL) += cpuidle-imx6sl.o
 endif
 
 ifdef CONFIG_SND_IMX_SOC
index c5f17c2d4951359ca11f0adfdc6d67a90cf18276..6f21a1333fe4ac8b75c363c7df2f413cd1148378 100644 (file)
@@ -66,6 +66,32 @@ static struct clk_div_table video_div_table[] = {
 static struct clk *clks[IMX6SL_CLK_END];
 static struct clk_onecell_data clk_data;
 
+/*
+ * ERR005311 CCM: After exit from WAIT mode, unwanted interrupt(s) taken
+ *           during WAIT mode entry process could cause cache memory
+ *           corruption.
+ *
+ * Software workaround:
+ *     To prevent this issue from occurring, software should ensure that the
+ * ARM to IPG clock ratio is less than 12:5 (that is < 2.4x), before
+ * entering WAIT mode.
+ *
+ * This function will set the ARM clk to max value within the 12:5 limit.
+ */
+void imx6sl_set_wait_clk(bool enter)
+{
+       static unsigned long saved_arm_rate;
+
+       if (enter) {
+               unsigned long ipg_rate = clk_get_rate(clks[IMX6SL_CLK_IPG]);
+               unsigned long max_arm_wait_rate = (12 * ipg_rate) / 5;
+               saved_arm_rate = clk_get_rate(clks[IMX6SL_CLK_ARM]);
+               clk_set_rate(clks[IMX6SL_CLK_ARM], max_arm_wait_rate);
+       } else {
+               clk_set_rate(clks[IMX6SL_CLK_ARM], saved_arm_rate);
+       }
+}
+
 static void __init imx6sl_clocks_init(struct device_node *ccm_node)
 {
        struct device_node *np;
index cdbddfa2a42f5dd2abe43326c4d033f46a30f8d6..b909b689619b7544972d5e4d1c5b460d489e9d6b 100644 (file)
@@ -140,6 +140,7 @@ void imx_anatop_pre_suspend(void);
 void imx_anatop_post_resume(void);
 int imx6q_set_lpm(enum mxc_cpu_pwr_mode mode);
 void imx6q_set_int_mem_clk_lpm(void);
+void imx6sl_set_wait_clk(bool enter);
 
 void imx_cpu_die(unsigned int cpu);
 int imx_cpu_kill(unsigned int cpu);
diff --git a/arch/arm/mach-imx/cpuidle-imx6sl.c b/arch/arm/mach-imx/cpuidle-imx6sl.c
new file mode 100644 (file)
index 0000000..d4b6b81
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2014 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/cpuidle.h>
+#include <linux/module.h>
+#include <asm/cpuidle.h>
+#include <asm/proc-fns.h>
+
+#include "common.h"
+#include "cpuidle.h"
+
+static int imx6sl_enter_wait(struct cpuidle_device *dev,
+                           struct cpuidle_driver *drv, int index)
+{
+       imx6q_set_lpm(WAIT_UNCLOCKED);
+       /*
+        * Software workaround for ERR005311, see function
+        * description for details.
+        */
+       imx6sl_set_wait_clk(true);
+       cpu_do_idle();
+       imx6sl_set_wait_clk(false);
+       imx6q_set_lpm(WAIT_CLOCKED);
+
+       return index;
+}
+
+static struct cpuidle_driver imx6sl_cpuidle_driver = {
+       .name = "imx6sl_cpuidle",
+       .owner = THIS_MODULE,
+       .states = {
+               /* WFI */
+               ARM_CPUIDLE_WFI_STATE,
+               /* WAIT */
+               {
+                       .exit_latency = 50,
+                       .target_residency = 75,
+                       .flags = CPUIDLE_FLAG_TIME_VALID |
+                               CPUIDLE_FLAG_TIMER_STOP,
+                       .enter = imx6sl_enter_wait,
+                       .name = "WAIT",
+                       .desc = "Clock off",
+               },
+       },
+       .state_count = 2,
+       .safe_state_index = 0,
+};
+
+int __init imx6sl_cpuidle_init(void)
+{
+       return cpuidle_register(&imx6sl_cpuidle_driver, NULL);
+}
index 786f98ecc14578630bdb9351b388135fb51aebad..24e33670417c1dd48f21aa2acf4f8bdfbc16c95a 100644 (file)
@@ -13,6 +13,7 @@
 #ifdef CONFIG_CPU_IDLE
 extern int imx5_cpuidle_init(void);
 extern int imx6q_cpuidle_init(void);
+extern int imx6sl_cpuidle_init(void);
 #else
 static inline int imx5_cpuidle_init(void)
 {
@@ -22,4 +23,8 @@ static inline int imx6q_cpuidle_init(void)
 {
        return 0;
 }
+static inline int imx6sl_cpuidle_init(void)
+{
+       return 0;
+}
 #endif
index 0f4fd4c0ab8e7db0cca2e04e2cb65f6dd43092d6..a26fdb2b1a6f68c8a9edf69fa47817ccc783449f 100644 (file)
@@ -17,6 +17,7 @@
 #include <asm/mach/map.h>
 
 #include "common.h"
+#include "cpuidle.h"
 
 static void __init imx6sl_fec_init(void)
 {
@@ -39,6 +40,8 @@ static void __init imx6sl_init_late(void)
        /* imx6sl reuses imx6q cpufreq driver */
        if (IS_ENABLED(CONFIG_ARM_IMX6Q_CPUFREQ))
                platform_device_register_simple("imx6q-cpufreq", -1, NULL, 0);
+
+       imx6sl_cpuidle_init();
 }
 
 static void __init imx6sl_init_machine(void)