]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - rpmsg/hwspinlock.git/blobdiff - arch/arm/mach-omap2/pm33xx-core.c
ARM: OMAP2+: pm33xx-core: Add cpuidle_ops for am335x/am437x
[rpmsg/hwspinlock.git] / arch / arm / mach-omap2 / pm33xx-core.c
index f4971e4a86b26893578badccb6c0828a4c8821ab..b16fed8911be696ef4609183c5e7512a4b12620b 100644 (file)
@@ -6,10 +6,18 @@
  *     Dave Gerlach
  */
 
+#include <linux/cpuidle.h>
+#include <linux/platform_data/pm33xx.h>
+#include <asm/cpuidle.h>
 #include <asm/smp_scu.h>
 #include <asm/suspend.h>
 #include <linux/errno.h>
-#include <linux/platform_data/pm33xx.h>
+#include <linux/clk.h>
+#include <linux/platform_data/gpio-omap.h>
+#include <linux/pinctrl/pinmux.h>
+#include <linux/wkup_m3_ipc.h>
+#include <linux/of.h>
+#include <linux/rtc.h>
 
 #include "cm33xx.h"
 #include "common.h"
@@ -28,6 +36,14 @@ static struct clockdomain *gfx_l4ls_clkdm;
 static void __iomem *scu_base;
 static struct omap_hwmod *rtc_oh;
 
+static int (*idle_fn)(u32 wfi_flags);
+
+struct amx3_idle_state {
+       int wfi_flags;
+};
+
+static struct amx3_idle_state *idle_states;
+
 static int __init am43xx_map_scu(void)
 {
        scu_base = ioremap(scu_a9_get_base(), SZ_256);
@@ -38,6 +54,29 @@ static int __init am43xx_map_scu(void)
        return 0;
 }
 
+static int am33xx_check_off_mode_enable(void)
+{
+       if (enable_off_mode)
+               pr_warn("WARNING: This platform does not support off-mode, entering DeepSleep suspend.\n");
+
+       /* off mode not supported on am335x so return 0 always */
+       return 0;
+}
+
+static int am43xx_check_off_mode_enable(void)
+{
+       /*
+        * Check for am437x-sk-evm which due to HW design cannot support
+        * this mode reliably.
+        */
+       if (of_machine_is_compatible("ti,am437x-sk-evm") && enable_off_mode) {
+               pr_warn("WARNING: This platform does not support off-mode, entering DeepSleep suspend.\n");
+               return 0;
+       }
+
+       return enable_off_mode;
+}
+
 static int amx3_common_init(void)
 {
        gfx_pwrdm = pwrdm_lookup("gfx_pwrdm");
@@ -139,7 +178,9 @@ static int am43xx_suspend(unsigned int state, int (*fn)(unsigned long),
        scu_power_mode(scu_base, SCU_PM_POWEROFF);
        ret = cpu_suspend(args, fn);
        scu_power_mode(scu_base, SCU_PM_NORMAL);
-       amx3_post_suspend_common();
+
+       if (!am43xx_check_off_mode_enable())
+               amx3_post_suspend_common();
 
        return ret;
 }
@@ -161,10 +202,48 @@ void __iomem *am43xx_get_rtc_base_addr(void)
        return omap_hwmod_get_mpu_rt_va(rtc_oh);
 }
 
+static void am43xx_save_context(void)
+{
+}
+
+static void am33xx_save_context(void)
+{
+       omap_intc_save_context();
+}
+
+static void am33xx_restore_context(void)
+{
+       omap_intc_restore_context();
+}
+
+static void am43xx_restore_context(void)
+{
+       /*
+        * HACK: restore dpll_per_clkdcoldo register contents, to avoid
+        * breaking suspend-resume
+        */
+       writel_relaxed(0x0, AM33XX_L4_WK_IO_ADDRESS(0x44df2e14));
+}
+
+static void am43xx_prepare_rtc_suspend(void)
+{
+       omap_hwmod_enable(rtc_oh);
+}
+
+static void am43xx_prepare_rtc_resume(void)
+{
+       omap_hwmod_idle(rtc_oh);
+}
+
 static struct am33xx_pm_platform_data am33xx_ops = {
        .init = am33xx_suspend_init,
        .soc_suspend = am33xx_suspend,
        .get_sram_addrs = amx3_get_sram_addrs,
+       .save_context = am33xx_save_context,
+       .restore_context = am33xx_restore_context,
+       .prepare_rtc_suspend = am43xx_prepare_rtc_suspend,
+       .prepare_rtc_resume = am43xx_prepare_rtc_resume,
+       .check_off_mode_enable = am33xx_check_off_mode_enable,
        .get_rtc_base_addr = am43xx_get_rtc_base_addr,
 };
 
@@ -172,6 +251,11 @@ static struct am33xx_pm_platform_data am43xx_ops = {
        .init = am43xx_suspend_init,
        .soc_suspend = am43xx_suspend,
        .get_sram_addrs = amx3_get_sram_addrs,
+       .save_context = am43xx_save_context,
+       .restore_context = am43xx_restore_context,
+       .prepare_rtc_suspend = am43xx_prepare_rtc_suspend,
+       .prepare_rtc_resume = am43xx_prepare_rtc_resume,
+       .check_off_mode_enable = am43xx_check_off_mode_enable,
        .get_rtc_base_addr = am43xx_get_rtc_base_addr,
 };
 
@@ -201,3 +285,64 @@ int __init amx3_common_pm_init(void)
 
        return 0;
 }
+
+static int __init amx3_idle_init(struct device_node *cpu_node, int cpu)
+{
+       struct device_node *state_node;
+       struct amx3_idle_state states[CPUIDLE_STATE_MAX];
+       int i;
+       int state_count = 1;
+
+       for (i = 0; ; i++) {
+               state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i);
+               if (!state_node)
+                       break;
+
+               if (!of_device_is_available(state_node))
+                       continue;
+
+               if (i == CPUIDLE_STATE_MAX) {
+                       pr_warn("%s: cpuidle states reached max possible\n",
+                               __func__);
+                       break;
+               }
+
+               states[state_count].wfi_flags = 0;
+
+               if (of_property_read_bool(state_node, "ti,idle-wkup-m3"))
+                       states[state_count].wfi_flags |= WFI_FLAG_WAKE_M3 |
+                                                        WFI_FLAG_FLUSH_CACHE;
+
+               state_count++;
+       }
+
+       idle_states = kcalloc(state_count, sizeof(*idle_states), GFP_KERNEL);
+       if (!idle_states)
+               return -ENOMEM;
+
+       for (i = 1; i < state_count; i++)
+               idle_states[i].wfi_flags = states[i].wfi_flags;
+
+       return 0;
+}
+
+static int amx3_idle_enter(unsigned long index)
+{
+       struct amx3_idle_state *idle_state = &idle_states[index];
+
+       if (!idle_state)
+               return -EINVAL;
+
+       if (idle_fn)
+               idle_fn(idle_state->wfi_flags);
+
+       return 0;
+}
+
+static struct cpuidle_ops amx3_cpuidle_ops __initdata = {
+       .init = amx3_idle_init,
+       .suspend = amx3_idle_enter,
+};
+
+CPUIDLE_METHOD_OF_DECLARE(pm33xx_idle, "ti,am3352", &amx3_cpuidle_ops);
+CPUIDLE_METHOD_OF_DECLARE(pm43xx_idle, "ti,am4372", &amx3_cpuidle_ops);