2
* linux/arch/unicore32/kernel/pm.c
4
* Code specific to PKUnity SoC and UniCore ISA
6
* Maintained by GUAN Xue-tao <gxt@mprc.pku.edu.cn>
7
* Copyright (C) 2001-2010 Guan Xuetao
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License version 2 as
11
* published by the Free Software Foundation.
13
#include <linux/init.h>
14
#include <linux/module.h>
15
#include <linux/suspend.h>
16
#include <linux/errno.h>
17
#include <linux/slab.h>
20
#include <mach/hardware.h>
25
struct puv3_cpu_pm_fns *puv3_cpu_pm_fns;
26
static unsigned long *sleep_save;
28
int puv3_pm_enter(suspend_state_t state)
30
unsigned long sleep_save_checksum = 0, checksum = 0;
33
/* skip registers saving for standby */
34
if (state != PM_SUSPEND_STANDBY) {
35
puv3_cpu_pm_fns->save(sleep_save);
36
/* before sleeping, calculate and save a checksum */
37
for (i = 0; i < puv3_cpu_pm_fns->save_count - 1; i++)
38
sleep_save_checksum += sleep_save[i];
42
puv3_cpu_pm_fns->enter(state);
44
#ifdef CONFIG_INPUT_KEYBOARD
50
if (state != PM_SUSPEND_STANDBY) {
51
/* after sleeping, validate the checksum */
52
for (i = 0; i < puv3_cpu_pm_fns->save_count - 1; i++)
53
checksum += sleep_save[i];
55
/* if invalid, display message and wait for a hardware reset */
56
if (checksum != sleep_save_checksum) {
58
puv3_cpu_pm_fns->enter(state);
60
puv3_cpu_pm_fns->restore(sleep_save);
63
pr_debug("*** made it back from resume\n");
67
EXPORT_SYMBOL_GPL(puv3_pm_enter);
69
unsigned long sleep_phys_sp(void *sp)
71
return virt_to_phys(sp);
74
static int puv3_pm_valid(suspend_state_t state)
77
return puv3_cpu_pm_fns->valid(state);
82
static int puv3_pm_prepare(void)
86
if (puv3_cpu_pm_fns && puv3_cpu_pm_fns->prepare)
87
ret = puv3_cpu_pm_fns->prepare();
92
static void puv3_pm_finish(void)
94
if (puv3_cpu_pm_fns && puv3_cpu_pm_fns->finish)
95
puv3_cpu_pm_fns->finish();
98
static struct platform_suspend_ops puv3_pm_ops = {
99
.valid = puv3_pm_valid,
100
.enter = puv3_pm_enter,
101
.prepare = puv3_pm_prepare,
102
.finish = puv3_pm_finish,
105
static int __init puv3_pm_init(void)
107
if (!puv3_cpu_pm_fns) {
108
printk(KERN_ERR "no valid puv3_cpu_pm_fns defined\n");
112
sleep_save = kmalloc(puv3_cpu_pm_fns->save_count
113
* sizeof(unsigned long), GFP_KERNEL);
115
printk(KERN_ERR "failed to alloc memory for pm save\n");
119
suspend_set_ops(&puv3_pm_ops);
123
device_initcall(puv3_pm_init);