blob: 6534c3ff9fe29b99cb7c50b3eb76ba63b483c8cd [file] [log] [blame]
Tomasz Figab2789912014-03-18 07:28:10 +09001/*
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 */
31void s3c_pm_do_save(struct sleep_save *ptr, int count)
32{
33 for (; count > 0; count--, ptr++) {
Ben Dooks85586432016-06-21 11:20:27 +010034 ptr->val = readl_relaxed(ptr->reg);
Tomasz Figab2789912014-03-18 07:28:10 +090035 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
50void 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",
Ben Dooks85586432016-06-21 11:20:27 +010054 ptr->reg, ptr->val, readl_relaxed(ptr->reg));
Tomasz Figab2789912014-03-18 07:28:10 +090055
Ben Dooks85586432016-06-21 11:20:27 +010056 writel_relaxed(ptr->val, ptr->reg);
Tomasz Figab2789912014-03-18 07:28:10 +090057 }
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
71void s3c_pm_do_restore_core(const struct sleep_save *ptr, int count)
72{
73 for (; count > 0; count--, ptr++)
Ben Dooks85586432016-06-21 11:20:27 +010074 writel_relaxed(ptr->val, ptr->reg);
Tomasz Figab2789912014-03-18 07:28:10 +090075}