• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 Samsung Electronics Co., Ltd.
3  *	Tomasz Figa <t.figa@samsung.com>
4  * Copyright (C) 2008 Openmoko, Inc.
5  * Copyright (C) 2004-2008 Simtec Electronics
6  *	Ben Dooks <ben@simtec.co.uk>
7  *	http://armlinux.simtec.co.uk/
8  *
9  * Samsung common power management helper functions.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License version 2 as
13  * published by the Free Software Foundation.
14 */
15 
16 #include <linux/io.h>
17 #include <linux/kernel.h>
18 
19 #include <plat/pm-common.h>
20 
21 /* helper functions to save and restore register state */
22 
23 /**
24  * s3c_pm_do_save() - save a set of registers for restoration on resume.
25  * @ptr: Pointer to an array of registers.
26  * @count: Size of the ptr array.
27  *
28  * Run through the list of registers given, saving their contents in the
29  * array for later restoration when we wakeup.
30  */
s3c_pm_do_save(struct sleep_save * ptr,int count)31 void s3c_pm_do_save(struct sleep_save *ptr, int count)
32 {
33 	for (; count > 0; count--, ptr++) {
34 		ptr->val = __raw_readl(ptr->reg);
35 		S3C_PMDBG("saved %p value %08lx\n", ptr->reg, ptr->val);
36 	}
37 }
38 
39 /**
40  * s3c_pm_do_restore() - restore register values from the save list.
41  * @ptr: Pointer to an array of registers.
42  * @count: Size of the ptr array.
43  *
44  * Restore the register values saved from s3c_pm_do_save().
45  *
46  * Note, we do not use S3C_PMDBG() in here, as the system may not have
47  * restore the UARTs state yet
48 */
49 
s3c_pm_do_restore(const struct sleep_save * ptr,int count)50 void s3c_pm_do_restore(const struct sleep_save *ptr, int count)
51 {
52 	for (; count > 0; count--, ptr++) {
53 		pr_debug("restore %p (restore %08lx, was %08x)\n",
54 				ptr->reg, ptr->val, __raw_readl(ptr->reg));
55 
56 		__raw_writel(ptr->val, ptr->reg);
57 	}
58 }
59 
60 /**
61  * s3c_pm_do_restore_core() - early restore register values from save list.
62  *
63  * This is similar to s3c_pm_do_restore() except we try and minimise the
64  * side effects of the function in case registers that hardware might need
65  * to work has been restored.
66  *
67  * WARNING: Do not put any debug in here that may effect memory or use
68  * peripherals, as things may be changing!
69 */
70 
s3c_pm_do_restore_core(const struct sleep_save * ptr,int count)71 void s3c_pm_do_restore_core(const struct sleep_save *ptr, int count)
72 {
73 	for (; count > 0; count--, ptr++)
74 		__raw_writel(ptr->val, ptr->reg);
75 }
76