ARM: calxeda: cpuidle: use init/exit common routine
[deliverable/linux.git] / drivers / cpuidle / cpuidle-calxeda.c
CommitLineData
be6a98d3
RH
1/*
2 * Copyright 2012 Calxeda, Inc.
3 *
4 * Based on arch/arm/plat-mxc/cpuidle.c:
5 * 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/>.
19 */
20
21#include <linux/cpuidle.h>
22#include <linux/init.h>
23#include <linux/io.h>
24#include <linux/of.h>
25#include <linux/time.h>
26#include <linux/delay.h>
27#include <linux/suspend.h>
28#include <asm/cpuidle.h>
29#include <asm/proc-fns.h>
30#include <asm/smp_scu.h>
31#include <asm/suspend.h>
32#include <asm/cacheflush.h>
33#include <asm/cp15.h>
34
35extern void highbank_set_cpu_jump(int cpu, void *jump_addr);
36extern void *scu_base_addr;
37
be6a98d3
RH
38static inline unsigned int get_auxcr(void)
39{
40 unsigned int val;
41 asm("mrc p15, 0, %0, c1, c0, 1 @ get AUXCR" : "=r" (val) : : "cc");
42 return val;
43}
44
45static inline void set_auxcr(unsigned int val)
46{
47 asm volatile("mcr p15, 0, %0, c1, c0, 1 @ set AUXCR"
48 : : "r" (val) : "cc");
49 isb();
50}
51
52static noinline void calxeda_idle_restore(void)
53{
54 set_cr(get_cr() | CR_C);
55 set_auxcr(get_auxcr() | 0x40);
56 scu_power_mode(scu_base_addr, SCU_PM_NORMAL);
57}
58
59static int calxeda_idle_finish(unsigned long val)
60{
61 /* Already flushed cache, but do it again as the outer cache functions
62 * dirty the cache with spinlocks */
63 flush_cache_all();
64
65 set_auxcr(get_auxcr() & ~0x40);
66 set_cr(get_cr() & ~CR_C);
67
68 scu_power_mode(scu_base_addr, SCU_PM_DORMANT);
69
70 cpu_do_idle();
71
72 /* Restore things if we didn't enter power-gating */
73 calxeda_idle_restore();
74 return 1;
75}
76
77static int calxeda_pwrdown_idle(struct cpuidle_device *dev,
78 struct cpuidle_driver *drv,
79 int index)
80{
81 highbank_set_cpu_jump(smp_processor_id(), cpu_resume);
82 cpu_suspend(0, calxeda_idle_finish);
83 return index;
84}
85
be6a98d3
RH
86static struct cpuidle_driver calxeda_idle_driver = {
87 .name = "calxeda_idle",
be6a98d3
RH
88 .states = {
89 ARM_CPUIDLE_WFI_STATE,
90 {
91 .name = "PG",
92 .desc = "Power Gate",
93 .flags = CPUIDLE_FLAG_TIME_VALID,
94 .exit_latency = 30,
95 .power_usage = 50,
96 .target_residency = 200,
97 .enter = calxeda_pwrdown_idle,
98 },
99 },
100 .state_count = 2,
101};
102
103static int __init calxeda_cpuidle_init(void)
104{
be6a98d3
RH
105 if (!of_machine_is_compatible("calxeda,highbank"))
106 return -ENODEV;
107
0b210d96 108 return cpuidle_register(&calxeda_idle_driver, NULL);
be6a98d3
RH
109}
110module_init(calxeda_cpuidle_init);
This page took 0.060615 seconds and 5 git commands to generate.