1 // SPDX-License-Identifier: GPL-2.0-only
3 * DaVinci Power Management Routines
5 * Copyright (C) 2009 Texas Instruments, Inc. https://www.ti.com/
9 #include <linux/suspend.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/clk.h>
13 #include <linux/spinlock.h>
15 #include <asm/cacheflush.h>
16 #include <asm/delay.h>
27 #define DA850_PLL1_BASE 0x01e1a000
28 #define DEEPSLEEP_SLEEPCOUNT_MASK 0xFFFF
29 #define DEEPSLEEP_SLEEPCOUNT 128
31 static void (*davinci_sram_suspend
) (struct davinci_pm_config
*);
32 static struct davinci_pm_config pm_config
= {
33 .sleepcount
= DEEPSLEEP_SLEEPCOUNT
,
34 .ddrpsc_num
= DA8XX_LPSC1_EMIF3C
,
37 static void davinci_sram_push(void *dest
, void *src
, unsigned int size
)
39 memcpy(dest
, src
, size
);
40 flush_icache_range((unsigned long)dest
, (unsigned long)(dest
+ size
));
43 static void davinci_pm_suspend(void)
47 if (pm_config
.cpupll_reg_base
!= pm_config
.ddrpll_reg_base
) {
49 /* Switch CPU PLL to bypass mode */
50 val
= __raw_readl(pm_config
.cpupll_reg_base
+ PLLCTL
);
51 val
&= ~(PLLCTL_PLLENSRC
| PLLCTL_PLLEN
);
52 __raw_writel(val
, pm_config
.cpupll_reg_base
+ PLLCTL
);
54 udelay(PLL_BYPASS_TIME
);
56 /* Powerdown CPU PLL */
57 val
= __raw_readl(pm_config
.cpupll_reg_base
+ PLLCTL
);
58 val
|= PLLCTL_PLLPWRDN
;
59 __raw_writel(val
, pm_config
.cpupll_reg_base
+ PLLCTL
);
62 /* Configure sleep count in deep sleep register */
63 val
= __raw_readl(pm_config
.deepsleep_reg
);
64 val
&= ~DEEPSLEEP_SLEEPCOUNT_MASK
;
65 val
|= pm_config
.sleepcount
;
66 __raw_writel(val
, pm_config
.deepsleep_reg
);
68 /* System goes to sleep in this call */
69 davinci_sram_suspend(&pm_config
);
71 if (pm_config
.cpupll_reg_base
!= pm_config
.ddrpll_reg_base
) {
73 /* put CPU PLL in reset */
74 val
= __raw_readl(pm_config
.cpupll_reg_base
+ PLLCTL
);
75 val
&= ~PLLCTL_PLLRST
;
76 __raw_writel(val
, pm_config
.cpupll_reg_base
+ PLLCTL
);
78 /* put CPU PLL in power down */
79 val
= __raw_readl(pm_config
.cpupll_reg_base
+ PLLCTL
);
80 val
&= ~PLLCTL_PLLPWRDN
;
81 __raw_writel(val
, pm_config
.cpupll_reg_base
+ PLLCTL
);
83 /* wait for CPU PLL reset */
84 udelay(PLL_RESET_TIME
);
86 /* bring CPU PLL out of reset */
87 val
= __raw_readl(pm_config
.cpupll_reg_base
+ PLLCTL
);
89 __raw_writel(val
, pm_config
.cpupll_reg_base
+ PLLCTL
);
91 /* Wait for CPU PLL to lock */
92 udelay(PLL_LOCK_TIME
);
94 /* Remove CPU PLL from bypass mode */
95 val
= __raw_readl(pm_config
.cpupll_reg_base
+ PLLCTL
);
96 val
&= ~PLLCTL_PLLENSRC
;
98 __raw_writel(val
, pm_config
.cpupll_reg_base
+ PLLCTL
);
102 static int davinci_pm_enter(suspend_state_t state
)
108 davinci_pm_suspend();
117 static const struct platform_suspend_ops davinci_pm_ops
= {
118 .enter
= davinci_pm_enter
,
119 .valid
= suspend_valid_only_mem
,
122 int __init
davinci_pm_init(void)
126 ret
= davinci_cfg_reg(DA850_RTC_ALARM
);
130 pm_config
.ddr2_ctlr_base
= da8xx_get_mem_ctlr();
131 pm_config
.deepsleep_reg
= DA8XX_SYSCFG1_VIRT(DA8XX_DEEPSLEEP_REG
);
133 pm_config
.cpupll_reg_base
= ioremap(DA8XX_PLL0_BASE
, SZ_4K
);
134 if (!pm_config
.cpupll_reg_base
)
137 pm_config
.ddrpll_reg_base
= ioremap(DA850_PLL1_BASE
, SZ_4K
);
138 if (!pm_config
.ddrpll_reg_base
) {
143 pm_config
.ddrpsc_reg_base
= ioremap(DA8XX_PSC1_BASE
, SZ_4K
);
144 if (!pm_config
.ddrpsc_reg_base
) {
149 davinci_sram_suspend
= sram_alloc(davinci_cpu_suspend_sz
, NULL
);
150 if (!davinci_sram_suspend
) {
151 pr_err("PM: cannot allocate SRAM memory\n");
156 davinci_sram_push(davinci_sram_suspend
, davinci_cpu_suspend
,
157 davinci_cpu_suspend_sz
);
159 suspend_set_ops(&davinci_pm_ops
);
164 iounmap(pm_config
.ddrpsc_reg_base
);
166 iounmap(pm_config
.ddrpll_reg_base
);
168 iounmap(pm_config
.cpupll_reg_base
);