^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // Copyright (c) 2010-2014 Samsung Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) // http://www.samsung.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // S5PV210 - Power Management support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) // Based on arch/arm/mach-s3c2410/pm.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) // Copyright (c) 2006 Simtec Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) // Ben Dooks <ben@simtec.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/syscore_ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/soc/samsung/s3c-pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "regs-clock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* helper functions to save and restore register state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct sleep_save {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) void __iomem *reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define SAVE_ITEM(x) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) { .reg = (x) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * s3c_pm_do_save() - save a set of registers for restoration on resume.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * @ptr: Pointer to an array of registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * @count: Size of the ptr array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * Run through the list of registers given, saving their contents in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * array for later restoration when we wakeup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static void s3c_pm_do_save(struct sleep_save *ptr, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) for (; count > 0; count--, ptr++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ptr->val = readl_relaxed(ptr->reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) S3C_PMDBG("saved %p value %08lx\n", ptr->reg, ptr->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * s3c_pm_do_restore() - restore register values from the save list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * @ptr: Pointer to an array of registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * @count: Size of the ptr array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * Restore the register values saved from s3c_pm_do_save().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * WARNING: Do not put any debug in here that may effect memory or use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * peripherals, as things may be changing!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static void s3c_pm_do_restore_core(const struct sleep_save *ptr, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) for (; count > 0; count--, ptr++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) writel_relaxed(ptr->val, ptr->reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static struct sleep_save s5pv210_core_save[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* Clock ETC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) SAVE_ITEM(S5P_MDNIE_SEL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * VIC wake-up support (TODO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static u32 s5pv210_irqwake_intmask = 0xffffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static u32 s5pv210_read_eint_wakeup_mask(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return __raw_readl(S5P_EINT_WAKEUP_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * Suspend helpers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static int s5pv210_cpu_suspend(unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) unsigned long tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* issue the standby signal into the pm unit. Note, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * issue a write-buffer drain just in case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) tmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) asm("b 1f\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) ".align 5\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) "1:\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) "mcr p15, 0, %0, c7, c10, 5\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) "mcr p15, 0, %0, c7, c10, 4\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) "wfi" : : "r" (tmp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) pr_info("Failed to suspend the system\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return 1; /* Aborting suspend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static void s5pv210_pm_prepare(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) unsigned int tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * Set wake-up mask registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * S5P_EINT_WAKEUP_MASK is set by pinctrl driver in late suspend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) __raw_writel(s5pv210_irqwake_intmask, S5P_WAKEUP_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* ensure at least INFORM0 has the resume address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) __raw_writel(__pa_symbol(s5pv210_cpu_resume), S5P_INFORM0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) tmp = __raw_readl(S5P_SLEEP_CFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) tmp &= ~(S5P_SLEEP_CFG_OSC_EN | S5P_SLEEP_CFG_USBOSC_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) __raw_writel(tmp, S5P_SLEEP_CFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* WFI for SLEEP mode configuration by SYSCON */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) tmp = __raw_readl(S5P_PWR_CFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) tmp &= S5P_CFG_WFI_CLEAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) tmp |= S5P_CFG_WFI_SLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) __raw_writel(tmp, S5P_PWR_CFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* SYSCON interrupt handling disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) tmp = __raw_readl(S5P_OTHERS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) tmp |= S5P_OTHER_SYSC_INTOFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) __raw_writel(tmp, S5P_OTHERS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) s3c_pm_do_save(s5pv210_core_save, ARRAY_SIZE(s5pv210_core_save));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * Suspend operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static int s5pv210_suspend_enter(suspend_state_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) u32 eint_wakeup_mask = s5pv210_read_eint_wakeup_mask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) S3C_PMDBG("%s: suspending the system...\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) S3C_PMDBG("%s: wakeup masks: %08x,%08x\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) s5pv210_irqwake_intmask, eint_wakeup_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (s5pv210_irqwake_intmask == -1U
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) && eint_wakeup_mask == -1U) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) pr_err("%s: No wake-up sources!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) pr_err("%s: Aborting sleep\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) s3c_pm_save_uarts(false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) s5pv210_pm_prepare();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) flush_cache_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) s3c_pm_check_store();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ret = cpu_suspend(0, s5pv210_cpu_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) s3c_pm_restore_uarts(false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) S3C_PMDBG("%s: wakeup stat: %08x\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) __raw_readl(S5P_WAKEUP_STAT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) s3c_pm_check_restore();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) S3C_PMDBG("%s: resuming the system...\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static int s5pv210_suspend_prepare(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) s3c_pm_check_prepare();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static void s5pv210_suspend_finish(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) s3c_pm_check_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static const struct platform_suspend_ops s5pv210_suspend_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) .enter = s5pv210_suspend_enter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) .prepare = s5pv210_suspend_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) .finish = s5pv210_suspend_finish,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) .valid = suspend_valid_only_mem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * Syscore operations used to delay restore of certain registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static void s5pv210_pm_resume(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) s3c_pm_do_restore_core(s5pv210_core_save, ARRAY_SIZE(s5pv210_core_save));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static struct syscore_ops s5pv210_pm_syscore_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) .resume = s5pv210_pm_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * Initialization entry point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) void __init s5pv210_pm_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) register_syscore_ops(&s5pv210_pm_syscore_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) suspend_set_ops(&s5pv210_suspend_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }