blob: b424747e425226f1a7428fdb294a7094497eac94 [file] [log] [blame]
Magnus Damm77594912009-03-13 15:23:04 +00001/*
Magnus Damm74263942009-07-03 10:28:00 +00002 * arch/sh/kernel/cpu/shmobile/pm.c
Magnus Damm77594912009-03-13 15:23:04 +00003 *
4 * Power management support code for SuperH Mobile
5 *
6 * Copyright (C) 2009 Magnus Damm
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/io.h>
15#include <linux/suspend.h>
16#include <asm/suspend.h>
17#include <asm/uaccess.h>
18
19/*
Magnus Damm49f42642009-10-29 10:51:48 +000020 * Notifier lists for pre/post sleep notification
21 */
22ATOMIC_NOTIFIER_HEAD(sh_mobile_pre_sleep_notifier_list);
23ATOMIC_NOTIFIER_HEAD(sh_mobile_post_sleep_notifier_list);
24
25/*
Magnus Damm77594912009-03-13 15:23:04 +000026 * Sleep modes available on SuperH Mobile:
27 *
28 * Sleep mode is just plain "sleep" instruction
29 * Sleep Self-Refresh mode is above plus RAM put in Self-Refresh
30 * Standby Self-Refresh mode is above plus stopped clocks
31 */
32#define SUSP_MODE_SLEEP (SUSP_SH_SLEEP)
33#define SUSP_MODE_SLEEP_SF (SUSP_SH_SLEEP | SUSP_SH_SF)
34#define SUSP_MODE_STANDBY_SF (SUSP_SH_STANDBY | SUSP_SH_SF)
35
36/*
37 * The following modes are not there yet:
38 *
39 * R-standby mode is unsupported, but will be added in the future
40 * U-standby mode is low priority since it needs bootloader hacks
Magnus Damm77594912009-03-13 15:23:04 +000041 */
42
Magnus Damm74263942009-07-03 10:28:00 +000043#define ILRAM_BASE 0xe5200000
44
Magnus Damm77594912009-03-13 15:23:04 +000045extern const unsigned char sh_mobile_standby[];
46extern const unsigned int sh_mobile_standby_size;
47
Magnus Damm74263942009-07-03 10:28:00 +000048void sh_mobile_call_standby(unsigned long mode)
Magnus Damm77594912009-03-13 15:23:04 +000049{
Magnus Damm74263942009-07-03 10:28:00 +000050 void *onchip_mem = (void *)ILRAM_BASE;
Magnus Damm309214a2009-08-17 09:27:29 +000051 void (*standby_onchip_mem)(unsigned long, unsigned long) = onchip_mem;
Magnus Damm77594912009-03-13 15:23:04 +000052
Magnus Damm49f42642009-10-29 10:51:48 +000053 atomic_notifier_call_chain(&sh_mobile_pre_sleep_notifier_list,
54 mode, NULL);
55
Magnus Damm77594912009-03-13 15:23:04 +000056 /* Let assembly snippet in on-chip memory handle the rest */
Magnus Damm309214a2009-08-17 09:27:29 +000057 standby_onchip_mem(mode, ILRAM_BASE);
Magnus Damm49f42642009-10-29 10:51:48 +000058
59 atomic_notifier_call_chain(&sh_mobile_post_sleep_notifier_list,
60 mode, NULL);
Magnus Damm77594912009-03-13 15:23:04 +000061}
62
Magnus Damm159f8cd2009-10-29 10:52:06 +000063void sh_mobile_register_self_refresh(unsigned long flags,
64 void *pre_start, void *pre_end,
65 void *post_start, void *post_end)
66{
67}
68
Magnus Damm77594912009-03-13 15:23:04 +000069static int sh_pm_enter(suspend_state_t state)
70{
71 local_irq_disable();
72 set_bl_bit();
73 sh_mobile_call_standby(SUSP_MODE_STANDBY_SF);
74 local_irq_disable();
75 clear_bl_bit();
76 return 0;
77}
78
79static struct platform_suspend_ops sh_pm_ops = {
80 .enter = sh_pm_enter,
81 .valid = suspend_valid_only_mem,
82};
83
84static int __init sh_pm_init(void)
85{
Magnus Damm74263942009-07-03 10:28:00 +000086 void *onchip_mem = (void *)ILRAM_BASE;
87
88 /* Copy the assembly snippet to the otherwise ununsed ILRAM */
89 memcpy(onchip_mem, sh_mobile_standby, sh_mobile_standby_size);
90 wmb();
91 ctrl_barrier();
92
Magnus Damm77594912009-03-13 15:23:04 +000093 suspend_set_ops(&sh_pm_ops);
Magnus Damm74263942009-07-03 10:28:00 +000094 sh_mobile_setup_cpuidle();
Magnus Damm77594912009-03-13 15:23:04 +000095 return 0;
96}
97
98late_initcall(sh_pm_init);