Merge tag 'sched-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / nds32 / kernel / pm.c
blobe25700e125d8ba685fb153842775982a391863d6
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)
16 pgd_t *pgdv;
17 p4d_t *p4dv;
18 pud_t *pudv;
19 pmd_t *pmdv;
20 pte_t *ptev;
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);
33 suspend2ram();
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)
44 switch (state) {
45 case PM_SUSPEND_ON:
46 case PM_SUSPEND_STANDBY:
47 case PM_SUSPEND_MEM:
48 return 1;
49 default:
50 return 0;
54 static int nds32_pm_enter(suspend_state_t state)
56 pr_debug("%s:state:%d\n", __func__, state);
57 switch (state) {
58 case PM_SUSPEND_STANDBY:
59 nds32_suspend_cpu();
60 return 0;
61 case PM_SUSPEND_MEM:
62 nds32_suspend2ram();
63 return 0;
64 default:
65 return -EINVAL;
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);
78 return 0;
80 late_initcall(nds32_pm_init);