blob: 7b541e911ab4aebe99262ef74c8ec0fb6084c01c [file] [log] [blame]
Magnus Damm0af48172011-04-29 02:36:07 +09001/*
2 * CPUIdle support code for SH-Mobile ARM
3 *
4 * Copyright (C) 2011 Magnus Damm
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/pm.h>
12#include <linux/cpuidle.h>
13#include <linux/suspend.h>
14#include <linux/module.h>
15#include <linux/err.h>
Robert Leeee807dd2012-03-20 15:22:48 -050016#include <asm/cpuidle.h>
Magnus Damm0af48172011-04-29 02:36:07 +090017#include <asm/io.h>
18
19static void shmobile_enter_wfi(void)
20{
21 cpu_do_idle();
22}
23
24void (*shmobile_cpuidle_modes[CPUIDLE_STATE_MAX])(void) = {
25 shmobile_enter_wfi, /* regular sleep mode */
26};
27
28static int shmobile_cpuidle_enter(struct cpuidle_device *dev,
Magnus Dammb73b5c42011-11-11 14:01:30 +090029 struct cpuidle_driver *drv,
30 int index)
Magnus Damm0af48172011-04-29 02:36:07 +090031{
Magnus Dammb73b5c42011-11-11 14:01:30 +090032 shmobile_cpuidle_modes[index]();
Magnus Damm0af48172011-04-29 02:36:07 +090033
Magnus Dammb73b5c42011-11-11 14:01:30 +090034 return index;
Magnus Damm0af48172011-04-29 02:36:07 +090035}
36
37static struct cpuidle_device shmobile_cpuidle_dev;
38static struct cpuidle_driver shmobile_cpuidle_driver = {
Robert Leeee807dd2012-03-20 15:22:48 -050039 .name = "shmobile_cpuidle",
40 .owner = THIS_MODULE,
41 .en_core_tk_irqen = 1,
42 .states[0] = ARM_CPUIDLE_WFI_STATE,
43 .safe_state_index = 0, /* C1 */
44 .state_count = 1,
Magnus Damm0af48172011-04-29 02:36:07 +090045};
46
Magnus Dammb73b5c42011-11-11 14:01:30 +090047void (*shmobile_cpuidle_setup)(struct cpuidle_driver *drv);
Magnus Damm0af48172011-04-29 02:36:07 +090048
Shawn Guo21cc1b72012-04-26 21:58:41 +080049int shmobile_cpuidle_init(void)
Magnus Damm0af48172011-04-29 02:36:07 +090050{
51 struct cpuidle_device *dev = &shmobile_cpuidle_dev;
Magnus Dammb73b5c42011-11-11 14:01:30 +090052 struct cpuidle_driver *drv = &shmobile_cpuidle_driver;
Magnus Damm0af48172011-04-29 02:36:07 +090053 int i;
54
Magnus Dammb73b5c42011-11-11 14:01:30 +090055 for (i = 0; i < CPUIDLE_STATE_MAX; i++)
56 drv->states[i].enter = shmobile_cpuidle_enter;
Magnus Damm0af48172011-04-29 02:36:07 +090057
58 if (shmobile_cpuidle_setup)
Magnus Dammb73b5c42011-11-11 14:01:30 +090059 shmobile_cpuidle_setup(drv);
Magnus Damm0af48172011-04-29 02:36:07 +090060
Magnus Dammb73b5c42011-11-11 14:01:30 +090061 cpuidle_register_driver(drv);
62
63 dev->state_count = drv->state_count;
Magnus Damm0af48172011-04-29 02:36:07 +090064 cpuidle_register_device(dev);
65
66 return 0;
67}