blob: ce0ccd26efbd4dfa992e507fda3385a35ea6503c [file] [log] [blame]
Tony Lindgren670c1042006-04-02 17:46:25 +01001/*
2 * linux/arch/arm/mach-omap2/sleep.S
3 *
4 * (C) Copyright 2004
5 * Texas Instruments, <www.ti.com>
6 * Richard Woodruff <r-woodruff2@ti.com>
7 *
Tony Lindgren1835f1d2008-10-06 15:49:15 +03008 * (C) Copyright 2006 Nokia Corporation
9 * Fixed idle loop sleep
10 * Igor Stoppa <igor.stoppa@nokia.com>
11 *
Tony Lindgren670c1042006-04-02 17:46:25 +010012 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
Tony Lindgren670c1042006-04-02 17:46:25 +010028#include <linux/linkage.h>
29#include <asm/assembler.h>
Tony Lindgren670c1042006-04-02 17:46:25 +010030
Tony Lindgrenc49f34b2012-08-31 16:08:07 -070031#include "omap24xx.h"
Paul Walmsley44595982008-03-18 10:04:51 +020032#include "sdrc.h"
Tony Lindgren670c1042006-04-02 17:46:25 +010033
Paul Walmsley44595982008-03-18 10:04:51 +020034/* First address of reserved address space? apparently valid for OMAP2 & 3 */
Tony Lindgren670c1042006-04-02 17:46:25 +010035#define A_SDRC0_V (0xC0000000)
Tony Lindgren670c1042006-04-02 17:46:25 +010036
37 .text
38
39/*
40 * Forces OMAP into idle state
41 *
42 * omap24xx_idle_loop_suspend() - This bit of code just executes the WFI
43 * for normal idles.
44 *
45 * Note: This code get's copied to internal SRAM at boot. When the OMAP
46 * wakes up it continues execution at the point it went to sleep.
47 */
Jean Pihetb6338bd2011-02-02 16:38:06 +010048 .align 3
Tony Lindgren670c1042006-04-02 17:46:25 +010049ENTRY(omap24xx_idle_loop_suspend)
50 stmfd sp!, {r0, lr} @ save registers on stack
51 mov r0, #0 @ clear for mcr setup
52 mcr p15, 0, r0, c7, c0, 4 @ wait for interrupt
53 ldmfd sp!, {r0, pc} @ restore regs and return
54
55ENTRY(omap24xx_idle_loop_suspend_sz)
56 .word . - omap24xx_idle_loop_suspend
57
58/*
Tony Lindgren1835f1d2008-10-06 15:49:15 +030059 * omap24xx_cpu_suspend() - Forces OMAP into deep sleep state by completing
Tony Lindgren670c1042006-04-02 17:46:25 +010060 * SDRC shutdown then ARM shutdown. Upon wake MPU is back on so just restore
61 * SDRC.
62 *
63 * Input:
64 * R0 : DLL ctrl value pre-Sleep
Tony Lindgren1835f1d2008-10-06 15:49:15 +030065 * R1 : SDRC_DLLA_CTRL
66 * R2 : SDRC_POWER
Tony Lindgren670c1042006-04-02 17:46:25 +010067 *
68 * The if the DPLL is going to AutoIdle. It seems like the DPLL may be back on
69 * when we get called, but the DLL probably isn't. We will wait a bit more in
70 * case the DPLL isn't quite there yet. The code will wait on DLL for DDR even
71 * if in unlocked mode.
72 *
73 * For less than 242x-ES2.2 upon wake from a sleep mode where the external
74 * oscillator was stopped, a timing bug exists where a non-stabilized 12MHz
75 * clock can pass into the PRCM can cause problems at DSP and IVA.
76 * To work around this the code will switch to the 32kHz source prior to sleep.
77 * Post sleep we will shift back to using the DPLL. Apparently,
78 * CM_IDLEST_CLKGEN does not reflect the full clock change so you need to wait
79 * 3x12MHz + 3x32kHz clocks for a full switch.
80 *
81 * The DLL load value is not kept in RETENTION or OFF. It needs to be restored
82 * at wake
83 */
Jean Pihetb6338bd2011-02-02 16:38:06 +010084 .align 3
Tony Lindgren670c1042006-04-02 17:46:25 +010085ENTRY(omap24xx_cpu_suspend)
86 stmfd sp!, {r0 - r12, lr} @ save registers on stack
Tony Lindgren1835f1d2008-10-06 15:49:15 +030087 mov r3, #0x0 @ clear for mcr call
Tony Lindgren670c1042006-04-02 17:46:25 +010088 mcr p15, 0, r3, c7, c10, 4 @ memory barrier, hope SDR/DDR finished
89 nop
90 nop
Tony Lindgren1835f1d2008-10-06 15:49:15 +030091 ldr r4, [r2] @ read SDRC_POWER
Tony Lindgren670c1042006-04-02 17:46:25 +010092 orr r4, r4, #0x40 @ enable self refresh on idle req
93 mov r5, #0x2000 @ set delay (DPLL relock + DLL relock)
Tony Lindgren1835f1d2008-10-06 15:49:15 +030094 str r4, [r2] @ make it so
Tony Lindgren670c1042006-04-02 17:46:25 +010095 nop
Kevin Hilman0dc23d72009-01-29 08:57:18 -080096 mcr p15, 0, r3, c7, c0, 4 @ wait for interrupt
Tony Lindgren670c1042006-04-02 17:46:25 +010097 nop
98loop:
99 subs r5, r5, #0x1 @ awake, wait just a bit
100 bne loop
101
Tony Lindgren1835f1d2008-10-06 15:49:15 +0300102 /* The DPLL has to be on before we take the DDR out of self refresh */
Tony Lindgren670c1042006-04-02 17:46:25 +0100103 bic r4, r4, #0x40 @ now clear self refresh bit.
Tony Lindgren1835f1d2008-10-06 15:49:15 +0300104 str r4, [r2] @ write to SDRC_POWER
Tony Lindgren670c1042006-04-02 17:46:25 +0100105 ldr r4, A_SDRC0 @ make a clock happen
Tony Lindgren1835f1d2008-10-06 15:49:15 +0300106 ldr r4, [r4] @ read A_SDRC0
Tony Lindgren670c1042006-04-02 17:46:25 +0100107 nop @ start auto refresh only after clk ok
108 movs r0, r0 @ see if DDR or SDR
Tony Lindgren670c1042006-04-02 17:46:25 +0100109 strne r0, [r1] @ rewrite DLLA to force DLL reload
110 addne r1, r1, #0x8 @ move to DLLB
111 strne r0, [r1] @ rewrite DLLB to force DLL reload
112
113 mov r5, #0x1000
114loop2:
115 subs r5, r5, #0x1
116 bne loop2
117 /* resume*/
118 ldmfd sp!, {r0 - r12, pc} @ restore regs and return
119
Tony Lindgren670c1042006-04-02 17:46:25 +0100120A_SDRC0:
121 .word A_SDRC0_V
Tony Lindgren670c1042006-04-02 17:46:25 +0100122
123ENTRY(omap24xx_cpu_suspend_sz)
124 .word . - omap24xx_cpu_suspend