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