1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/unicore32/kernel/pm.c
5 * Code specific to PKUnity SoC and UniCore ISA
7 * Maintained by GUAN Xue-tao <gxt@mprc.pku.edu.cn>
8 * Copyright (C) 2001-2010 Guan Xuetao
10 #include <linux/init.h>
11 #include <linux/module.h>
12 #include <linux/suspend.h>
13 #include <linux/errno.h>
14 #include <linux/slab.h>
17 #include <mach/hardware.h>
22 struct puv3_cpu_pm_fns *puv3_cpu_pm_fns;
23 static unsigned long *sleep_save;
25 int puv3_pm_enter(suspend_state_t state)
27 unsigned long sleep_save_checksum = 0, checksum = 0;
30 /* skip registers saving for standby */
31 if (state != PM_SUSPEND_STANDBY) {
32 puv3_cpu_pm_fns->save(sleep_save);
33 /* before sleeping, calculate and save a checksum */
34 for (i = 0; i < puv3_cpu_pm_fns->save_count - 1; i++)
35 sleep_save_checksum += sleep_save[i];
39 puv3_cpu_pm_fns->enter(state);
41 #ifdef CONFIG_INPUT_KEYBOARD
47 if (state != PM_SUSPEND_STANDBY) {
48 /* after sleeping, validate the checksum */
49 for (i = 0; i < puv3_cpu_pm_fns->save_count - 1; i++)
50 checksum += sleep_save[i];
52 /* if invalid, display message and wait for a hardware reset */
53 if (checksum != sleep_save_checksum) {
55 puv3_cpu_pm_fns->enter(state);
57 puv3_cpu_pm_fns->restore(sleep_save);
60 pr_debug("*** made it back from resume\n");
64 EXPORT_SYMBOL_GPL(puv3_pm_enter);
66 unsigned long sleep_phys_sp(void *sp)
68 return virt_to_phys(sp);
71 static int puv3_pm_valid(suspend_state_t state)
74 return puv3_cpu_pm_fns->valid(state);
79 static int puv3_pm_prepare(void)
83 if (puv3_cpu_pm_fns && puv3_cpu_pm_fns->prepare)
84 ret = puv3_cpu_pm_fns->prepare();
89 static void puv3_pm_finish(void)
91 if (puv3_cpu_pm_fns && puv3_cpu_pm_fns->finish)
92 puv3_cpu_pm_fns->finish();
95 static struct platform_suspend_ops puv3_pm_ops = {
96 .valid = puv3_pm_valid,
97 .enter = puv3_pm_enter,
98 .prepare = puv3_pm_prepare,
99 .finish = puv3_pm_finish,
102 static int __init puv3_pm_init(void)
104 if (!puv3_cpu_pm_fns) {
105 printk(KERN_ERR "no valid puv3_cpu_pm_fns defined\n");
109 sleep_save = kmalloc_array(puv3_cpu_pm_fns->save_count,
110 sizeof(unsigned long),
113 printk(KERN_ERR "failed to alloc memory for pm save\n");
117 suspend_set_ops(&puv3_pm_ops);
121 device_initcall(puv3_pm_init);