pm.c 2.4 KB
Newer Older
M
Magnus Damm 已提交
1
/*
2
 * arch/sh/kernel/cpu/shmobile/pm.c
M
Magnus Damm 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * Power management support code for SuperH Mobile
 *
 *  Copyright (C) 2009 Magnus Damm
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/io.h>
#include <linux/suspend.h>
#include <asm/suspend.h>
#include <asm/uaccess.h>

19 20 21 22 23 24
/*
 * Notifier lists for pre/post sleep notification
 */
ATOMIC_NOTIFIER_HEAD(sh_mobile_pre_sleep_notifier_list);
ATOMIC_NOTIFIER_HEAD(sh_mobile_post_sleep_notifier_list);

M
Magnus Damm 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
/*
 * Sleep modes available on SuperH Mobile:
 *
 * Sleep mode is just plain "sleep" instruction
 * Sleep Self-Refresh mode is above plus RAM put in Self-Refresh
 * Standby Self-Refresh mode is above plus stopped clocks
 */
#define SUSP_MODE_SLEEP		(SUSP_SH_SLEEP)
#define SUSP_MODE_SLEEP_SF	(SUSP_SH_SLEEP | SUSP_SH_SF)
#define SUSP_MODE_STANDBY_SF	(SUSP_SH_STANDBY | SUSP_SH_SF)

/*
 * The following modes are not there yet:
 *
 * R-standby mode is unsupported, but will be added in the future
 * U-standby mode is low priority since it needs bootloader hacks
 */

43 44
#define ILRAM_BASE 0xe5200000

M
Magnus Damm 已提交
45 46 47
extern const unsigned char sh_mobile_standby[];
extern const unsigned int sh_mobile_standby_size;

48
void sh_mobile_call_standby(unsigned long mode)
M
Magnus Damm 已提交
49
{
50
	void *onchip_mem = (void *)ILRAM_BASE;
51
	void (*standby_onchip_mem)(unsigned long, unsigned long) = onchip_mem;
M
Magnus Damm 已提交
52

53 54 55
	atomic_notifier_call_chain(&sh_mobile_pre_sleep_notifier_list,
				   mode, NULL);

M
Magnus Damm 已提交
56
	/* Let assembly snippet in on-chip memory handle the rest */
57
	standby_onchip_mem(mode, ILRAM_BASE);
58 59 60

	atomic_notifier_call_chain(&sh_mobile_post_sleep_notifier_list,
				   mode, NULL);
M
Magnus Damm 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
}

static int sh_pm_enter(suspend_state_t state)
{
	local_irq_disable();
	set_bl_bit();
	sh_mobile_call_standby(SUSP_MODE_STANDBY_SF);
	local_irq_disable();
	clear_bl_bit();
	return 0;
}

static struct platform_suspend_ops sh_pm_ops = {
	.enter          = sh_pm_enter,
	.valid          = suspend_valid_only_mem,
};

static int __init sh_pm_init(void)
{
80 81 82 83 84 85 86
	void *onchip_mem = (void *)ILRAM_BASE;

	/* Copy the assembly snippet to the otherwise ununsed ILRAM */
	memcpy(onchip_mem, sh_mobile_standby, sh_mobile_standby_size);
	wmb();
	ctrl_barrier();

M
Magnus Damm 已提交
87
	suspend_set_ops(&sh_pm_ops);
88
	sh_mobile_setup_cpuidle();
M
Magnus Damm 已提交
89 90 91 92
	return 0;
}

late_initcall(sh_pm_init);