blob: bed707ab6d6e14f9950b112c3184d2cb0e001f0a [file] [log] [blame]
Rob Herringbe6a98d2012-10-12 12:45:34 -05001/*
2 * Copyright 2012 Calxeda, Inc.
3 *
Daniel Lezcanoa8e39c32013-04-26 11:05:44 +00004 * Based on arch/arm/plat-mxc/cpuidle.c: #v3.7
Rob Herringbe6a98d2012-10-12 12:45:34 -05005 * Copyright 2012 Freescale Semiconductor, Inc.
6 * Copyright 2012 Linaro Ltd.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
Daniel Lezcanoa8e39c32013-04-26 11:05:44 +000019 *
20 * Maintainer: Rob Herring <rob.herring@calxeda.com>
Rob Herringbe6a98d2012-10-12 12:45:34 -050021 */
22
23#include <linux/cpuidle.h>
Rob Herring34a5eeb2013-02-26 16:16:53 -060024#include <linux/cpu_pm.h>
Rob Herringbe6a98d2012-10-12 12:45:34 -050025#include <linux/init.h>
26#include <linux/io.h>
27#include <linux/of.h>
28#include <linux/time.h>
29#include <linux/delay.h>
30#include <linux/suspend.h>
31#include <asm/cpuidle.h>
32#include <asm/proc-fns.h>
33#include <asm/smp_scu.h>
34#include <asm/suspend.h>
35#include <asm/cacheflush.h>
36#include <asm/cp15.h>
37
38extern void highbank_set_cpu_jump(int cpu, void *jump_addr);
Jingoo Han3e0c1902013-08-09 16:09:15 +090039extern void __iomem *scu_base_addr;
Rob Herringbe6a98d2012-10-12 12:45:34 -050040
Rob Herringbe6a98d2012-10-12 12:45:34 -050041static noinline void calxeda_idle_restore(void)
42{
43 set_cr(get_cr() | CR_C);
44 set_auxcr(get_auxcr() | 0x40);
45 scu_power_mode(scu_base_addr, SCU_PM_NORMAL);
46}
47
48static int calxeda_idle_finish(unsigned long val)
49{
50 /* Already flushed cache, but do it again as the outer cache functions
51 * dirty the cache with spinlocks */
52 flush_cache_all();
53
54 set_auxcr(get_auxcr() & ~0x40);
55 set_cr(get_cr() & ~CR_C);
56
57 scu_power_mode(scu_base_addr, SCU_PM_DORMANT);
58
59 cpu_do_idle();
60
61 /* Restore things if we didn't enter power-gating */
62 calxeda_idle_restore();
63 return 1;
64}
65
66static int calxeda_pwrdown_idle(struct cpuidle_device *dev,
67 struct cpuidle_driver *drv,
68 int index)
69{
Rob Herring34a5eeb2013-02-26 16:16:53 -060070 cpu_pm_enter();
Rob Herringbe6a98d2012-10-12 12:45:34 -050071 highbank_set_cpu_jump(smp_processor_id(), cpu_resume);
72 cpu_suspend(0, calxeda_idle_finish);
Rob Herring34a5eeb2013-02-26 16:16:53 -060073 cpu_pm_exit();
74
Rob Herringbe6a98d2012-10-12 12:45:34 -050075 return index;
76}
77
Rob Herringbe6a98d2012-10-12 12:45:34 -050078static struct cpuidle_driver calxeda_idle_driver = {
79 .name = "calxeda_idle",
Rob Herringbe6a98d2012-10-12 12:45:34 -050080 .states = {
81 ARM_CPUIDLE_WFI_STATE,
82 {
83 .name = "PG",
84 .desc = "Power Gate",
85 .flags = CPUIDLE_FLAG_TIME_VALID,
86 .exit_latency = 30,
87 .power_usage = 50,
88 .target_residency = 200,
89 .enter = calxeda_pwrdown_idle,
90 },
91 },
92 .state_count = 2,
93};
94
95static int __init calxeda_cpuidle_init(void)
96{
Rob Herringbe6a98d2012-10-12 12:45:34 -050097 if (!of_machine_is_compatible("calxeda,highbank"))
98 return -ENODEV;
99
Daniel Lezcano0b210d92013-04-23 08:54:42 +0000100 return cpuidle_register(&calxeda_idle_driver, NULL);
Rob Herringbe6a98d2012-10-12 12:45:34 -0500101}
102module_init(calxeda_cpuidle_init);