blob: 34605847957269635b650997d51ac7eb9062416f [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>
24#include <linux/init.h>
25#include <linux/io.h>
26#include <linux/of.h>
27#include <linux/time.h>
28#include <linux/delay.h>
29#include <linux/suspend.h>
30#include <asm/cpuidle.h>
31#include <asm/proc-fns.h>
32#include <asm/smp_scu.h>
33#include <asm/suspend.h>
34#include <asm/cacheflush.h>
35#include <asm/cp15.h>
36
37extern void highbank_set_cpu_jump(int cpu, void *jump_addr);
Jingoo Han3e0c1902013-08-09 16:09:15 +090038extern void __iomem *scu_base_addr;
Rob Herringbe6a98d2012-10-12 12:45:34 -050039
Rob Herringbe6a98d2012-10-12 12:45:34 -050040static noinline void calxeda_idle_restore(void)
41{
42 set_cr(get_cr() | CR_C);
43 set_auxcr(get_auxcr() | 0x40);
44 scu_power_mode(scu_base_addr, SCU_PM_NORMAL);
45}
46
47static int calxeda_idle_finish(unsigned long val)
48{
49 /* Already flushed cache, but do it again as the outer cache functions
50 * dirty the cache with spinlocks */
51 flush_cache_all();
52
53 set_auxcr(get_auxcr() & ~0x40);
54 set_cr(get_cr() & ~CR_C);
55
56 scu_power_mode(scu_base_addr, SCU_PM_DORMANT);
57
58 cpu_do_idle();
59
60 /* Restore things if we didn't enter power-gating */
61 calxeda_idle_restore();
62 return 1;
63}
64
65static int calxeda_pwrdown_idle(struct cpuidle_device *dev,
66 struct cpuidle_driver *drv,
67 int index)
68{
69 highbank_set_cpu_jump(smp_processor_id(), cpu_resume);
70 cpu_suspend(0, calxeda_idle_finish);
71 return index;
72}
73
Rob Herringbe6a98d2012-10-12 12:45:34 -050074static struct cpuidle_driver calxeda_idle_driver = {
75 .name = "calxeda_idle",
Rob Herringbe6a98d2012-10-12 12:45:34 -050076 .states = {
77 ARM_CPUIDLE_WFI_STATE,
78 {
79 .name = "PG",
80 .desc = "Power Gate",
81 .flags = CPUIDLE_FLAG_TIME_VALID,
82 .exit_latency = 30,
83 .power_usage = 50,
84 .target_residency = 200,
85 .enter = calxeda_pwrdown_idle,
86 },
87 },
88 .state_count = 2,
89};
90
91static int __init calxeda_cpuidle_init(void)
92{
Rob Herringbe6a98d2012-10-12 12:45:34 -050093 if (!of_machine_is_compatible("calxeda,highbank"))
94 return -ENODEV;
95
Daniel Lezcano0b210d92013-04-23 08:54:42 +000096 return cpuidle_register(&calxeda_idle_driver, NULL);
Rob Herringbe6a98d2012-10-12 12:45:34 -050097}
98module_init(calxeda_cpuidle_init);