2 * (C) Copyright 2009, Texas Instruments, Inc. http://www.ti.com/
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19 /* replicated define because linux/bitops.h cannot be included in assembly */
20 #define BIT(nr) (1 << (nr))
22 #include <linux/linkage.h>
23 #include <asm/assembler.h>
29 /* Arbitrary, hardware currently does not update PHYRDY correctly */
30 #define PHYRDY_CYCLES 0x1000
32 /* Assume 25 MHz speed for the cycle conversions since PLLs are bypassed */
33 #define PLL_BYPASS_CYCLES (PLL_BYPASS_TIME * 25)
34 #define PLL_RESET_CYCLES (PLL_RESET_TIME * 25)
35 #define PLL_LOCK_CYCLES (PLL_LOCK_TIME * 25)
37 #define DEEPSLEEP_SLEEPENABLE_BIT BIT(31)
41 * Move DaVinci into deep sleep state
43 * Note: This code is copied to internal SRAM by PM code. When the DaVinci
44 * wakes up it continues execution at the point it went to sleep.
46 * r0: contains virtual base for DDR2 controller
47 * r1: contains virtual base for DDR2 Power and Sleep controller (PSC)
48 * r2: contains PSC number for DDR2
49 * r3: contains virtual base DDR2 PLL controller
50 * r4: contains virtual address of the DEEPSLEEP register
52 ENTRY(davinci_cpu_suspend)
53 stmfd sp!, {r0-r12, lr} @ save registers on stack
61 * Switch DDR to self-refresh mode.
64 /* calculate SDRCR address */
65 ldr ip, [r0, #DDR2_SDRCR_OFFSET]
66 bic ip, ip, #DDR2_SRPD_BIT
67 orr ip, ip, #DDR2_LPMODEN_BIT
68 str ip, [r0, #DDR2_SDRCR_OFFSET]
70 ldr ip, [r0, #DDR2_SDRCR_OFFSET]
71 orr ip, ip, #DDR2_MCLKSTOPEN_BIT
72 str ip, [r0, #DDR2_SDRCR_OFFSET]
74 mov ip, #PHYRDY_CYCLES
78 /* Disable DDR2 LPSC */
81 bl davinci_ddr_psc_config
84 /* Disable clock to DDR PHY */
85 ldr ip, [r3, #PLLDIV1]
86 bic ip, ip, #PLLDIV_EN
87 str ip, [r3, #PLLDIV1]
89 /* Put the DDR PLL in bypass and power down */
91 bic ip, ip, #PLLCTL_PLLENSRC
92 bic ip, ip, #PLLCTL_PLLEN
95 /* Wait for PLL to switch to bypass */
96 mov ip, #PLL_BYPASS_CYCLES
100 /* Power down the PLL */
101 ldr ip, [r3, #PLLCTL]
102 orr ip, ip, #PLLCTL_PLLPWRDN
103 str ip, [r3, #PLLCTL]
105 /* Go to deep sleep */
107 orr ip, ip, #DEEPSLEEP_SLEEPENABLE_BIT
108 /* System goes to sleep beyond after this instruction */
111 /* Wake up from sleep */
113 /* Clear sleep enable */
115 bic ip, ip, #DEEPSLEEP_SLEEPENABLE_BIT
118 /* initialize the DDR PLL controller */
120 /* Put PLL in reset */
121 ldr ip, [r3, #PLLCTL]
122 bic ip, ip, #PLLCTL_PLLRST
123 str ip, [r3, #PLLCTL]
125 /* Clear PLL power down */
126 ldr ip, [r3, #PLLCTL]
127 bic ip, ip, #PLLCTL_PLLPWRDN
128 str ip, [r3, #PLLCTL]
130 mov ip, #PLL_RESET_CYCLES
134 /* Bring PLL out of reset */
135 ldr ip, [r3, #PLLCTL]
136 orr ip, ip, #PLLCTL_PLLRST
137 str ip, [r3, #PLLCTL]
139 /* Wait for PLL to lock (assume prediv = 1, 25MHz OSCIN) */
140 mov ip, #PLL_LOCK_CYCLES
144 /* Remove PLL from bypass mode */
145 ldr ip, [r3, #PLLCTL]
146 bic ip, ip, #PLLCTL_PLLENSRC
147 orr ip, ip, #PLLCTL_PLLEN
148 str ip, [r3, #PLLCTL]
150 /* Start 2x clock to DDR2 */
152 ldr ip, [r3, #PLLDIV1]
153 orr ip, ip, #PLLDIV_EN
154 str ip, [r3, #PLLDIV1]
158 /* Enable DDR2 LPSC */
161 bl davinci_ddr_psc_config
164 /* clear MCLKSTOPEN */
166 ldr ip, [r0, #DDR2_SDRCR_OFFSET]
167 bic ip, ip, #DDR2_MCLKSTOPEN_BIT
168 str ip, [r0, #DDR2_SDRCR_OFFSET]
170 ldr ip, [r0, #DDR2_SDRCR_OFFSET]
171 bic ip, ip, #DDR2_LPMODEN_BIT
172 str ip, [r0, #DDR2_SDRCR_OFFSET]
174 /* Restore registers and return */
175 ldmfd sp!, {r0-r12, pc}
177 ENDPROC(davinci_cpu_suspend)
180 * Disables or Enables DDR2 LPSC
182 * r0: Enable or Disable LPSC r0 = 0x3 => Enable, r0 = 0x2 => Disable LPSC
183 * r1: contains virtual base for DDR2 Power and Sleep controller (PSC)
184 * r2: contains PSC number for DDR2
186 ENTRY(davinci_ddr_psc_config)
187 /* Set next state in mdctl for DDR2 */
189 add r6, r6, r2, lsl #2
191 bic ip, ip, #MDSTAT_STATE_MASK
195 /* Enable the Power Domain Transition Command */
200 /* Check for Transition Complete (PTSTAT) */
202 ldr ip, [r1, #PTSTAT]
207 /* Check for DDR2 clock disable completion; */
209 add r6, r6, r2, lsl #2
212 and ip, ip, #MDSTAT_STATE_MASK
214 bne ddr2clk_stop_done
217 ENDPROC(davinci_ddr_psc_config)
221 .word v6_flush_kern_cache_all
223 .word arm926_flush_kern_cache_all
226 ENTRY(davinci_cpu_suspend_sz)
227 .word . - davinci_cpu_suspend
228 ENDPROC(davinci_cpu_suspend_sz)