1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2008-2017 Andes Technology Corporation
4 #include <linux/init.h>
5 #include <linux/suspend.h>
6 #include <linux/device.h>
7 #include <linux/printk.h>
8 #include <asm/suspend.h>
9 #include <nds32_intrinsic.h>
11 unsigned int resume_addr;
12 unsigned int *phy_addr_sp_tmp;
14 static void nds32_suspend2ram(void)
22 pgdv = (pgd_t *)__va((__nds32__mfsr(NDS32_SR_L1_PPTB) &
23 L1_PPTB_mskBASE)) + pgd_index((unsigned int)cpu_resume);
25 p4dv = p4d_offset(pgdv, (unsigned int)cpu_resume);
26 pudv = pud_offset(p4dv, (unsigned int)cpu_resume);
27 pmdv = pmd_offset(pudv, (unsigned int)cpu_resume);
28 ptev = pte_offset_map(pmdv, (unsigned int)cpu_resume);
30 resume_addr = ((*ptev) & TLB_DATA_mskPPN)
31 | ((unsigned int)cpu_resume & 0x00000fff);
36 static void nds32_suspend_cpu(void)
38 while (!(__nds32__mfsr(NDS32_SR_INT_PEND) & wake_mask))
39 __asm__ volatile ("standby no_wake_grant\n\t");
42 static int nds32_pm_valid(suspend_state_t state)
46 case PM_SUSPEND_STANDBY:
54 static int nds32_pm_enter(suspend_state_t state)
56 pr_debug("%s:state:%d\n", __func__, state);
58 case PM_SUSPEND_STANDBY:
69 static const struct platform_suspend_ops nds32_pm_ops = {
70 .valid = nds32_pm_valid,
71 .enter = nds32_pm_enter,
74 static int __init nds32_pm_init(void)
76 pr_debug("Enter %s\n", __func__);
77 suspend_set_ops(&nds32_pm_ops);
80 late_initcall(nds32_pm_init);