/*1* (C) Copyright 2009, Texas Instruments, Inc. http://www.ti.com/2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* version 2 as published by the Free Software Foundation.6*7* This program is distributed in the hope that it will be useful,8* but WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the10* GNU General Public License for more details.11*12* You should have received a copy of the GNU General Public License13* along with this program; if not, write to the Free Software14* Foundation, Inc., 59 Temple Place, Suite 330, Boston,15* MA 02111-1307 USA16*/1718/* replicated define because linux/bitops.h cannot be included in assembly */19#define BIT(nr) (1 << (nr))2021#include <linux/linkage.h>22#include <asm/assembler.h>23#include <mach/psc.h>24#include <mach/memory.h>2526#include "clock.h"2728/* Arbitrary, hardware currently does not update PHYRDY correctly */29#define PHYRDY_CYCLES 0x10003031/* Assume 25 MHz speed for the cycle conversions since PLLs are bypassed */32#define PLL_BYPASS_CYCLES (PLL_BYPASS_TIME * 25)33#define PLL_RESET_CYCLES (PLL_RESET_TIME * 25)34#define PLL_LOCK_CYCLES (PLL_LOCK_TIME * 25)3536#define DEEPSLEEP_SLEEPENABLE_BIT BIT(31)3738.text39/*40* Move DaVinci into deep sleep state41*42* Note: This code is copied to internal SRAM by PM code. When the DaVinci43* wakes up it continues execution at the point it went to sleep.44* Register Usage:45* r0: contains virtual base for DDR2 controller46* r1: contains virtual base for DDR2 Power and Sleep controller (PSC)47* r2: contains PSC number for DDR248* r3: contains virtual base DDR2 PLL controller49* r4: contains virtual address of the DEEPSLEEP register50*/51ENTRY(davinci_cpu_suspend)52stmfd sp!, {r0-r12, lr} @ save registers on stack5354ldr ip, CACHE_FLUSH55blx ip5657ldmia r0, {r0-r4}5859/*60* Switch DDR to self-refresh mode.61*/6263/* calculate SDRCR address */64ldr ip, [r0, #DDR2_SDRCR_OFFSET]65bic ip, ip, #DDR2_SRPD_BIT66orr ip, ip, #DDR2_LPMODEN_BIT67str ip, [r0, #DDR2_SDRCR_OFFSET]6869ldr ip, [r0, #DDR2_SDRCR_OFFSET]70orr ip, ip, #DDR2_MCLKSTOPEN_BIT71str ip, [r0, #DDR2_SDRCR_OFFSET]7273mov ip, #PHYRDY_CYCLES741: subs ip, ip, #0x175bne 1b7677/* Disable DDR2 LPSC */78mov r7, r079mov r0, #0x280bl davinci_ddr_psc_config81mov r0, r78283/* Disable clock to DDR PHY */84ldr ip, [r3, #PLLDIV1]85bic ip, ip, #PLLDIV_EN86str ip, [r3, #PLLDIV1]8788/* Put the DDR PLL in bypass and power down */89ldr ip, [r3, #PLLCTL]90bic ip, ip, #PLLCTL_PLLENSRC91bic ip, ip, #PLLCTL_PLLEN92str ip, [r3, #PLLCTL]9394/* Wait for PLL to switch to bypass */95mov ip, #PLL_BYPASS_CYCLES962: subs ip, ip, #0x197bne 2b9899/* Power down the PLL */100ldr ip, [r3, #PLLCTL]101orr ip, ip, #PLLCTL_PLLPWRDN102str ip, [r3, #PLLCTL]103104/* Go to deep sleep */105ldr ip, [r4]106orr ip, ip, #DEEPSLEEP_SLEEPENABLE_BIT107/* System goes to sleep beyond after this instruction */108str ip, [r4]109110/* Wake up from sleep */111112/* Clear sleep enable */113ldr ip, [r4]114bic ip, ip, #DEEPSLEEP_SLEEPENABLE_BIT115str ip, [r4]116117/* initialize the DDR PLL controller */118119/* Put PLL in reset */120ldr ip, [r3, #PLLCTL]121bic ip, ip, #PLLCTL_PLLRST122str ip, [r3, #PLLCTL]123124/* Clear PLL power down */125ldr ip, [r3, #PLLCTL]126bic ip, ip, #PLLCTL_PLLPWRDN127str ip, [r3, #PLLCTL]128129mov ip, #PLL_RESET_CYCLES1303: subs ip, ip, #0x1131bne 3b132133/* Bring PLL out of reset */134ldr ip, [r3, #PLLCTL]135orr ip, ip, #PLLCTL_PLLRST136str ip, [r3, #PLLCTL]137138/* Wait for PLL to lock (assume prediv = 1, 25MHz OSCIN) */139mov ip, #PLL_LOCK_CYCLES1404: subs ip, ip, #0x1141bne 4b142143/* Remove PLL from bypass mode */144ldr ip, [r3, #PLLCTL]145bic ip, ip, #PLLCTL_PLLENSRC146orr ip, ip, #PLLCTL_PLLEN147str ip, [r3, #PLLCTL]148149/* Start 2x clock to DDR2 */150151ldr ip, [r3, #PLLDIV1]152orr ip, ip, #PLLDIV_EN153str ip, [r3, #PLLDIV1]154155/* Enable VCLK */156157/* Enable DDR2 LPSC */158mov r7, r0159mov r0, #0x3160bl davinci_ddr_psc_config161mov r0, r7162163/* clear MCLKSTOPEN */164165ldr ip, [r0, #DDR2_SDRCR_OFFSET]166bic ip, ip, #DDR2_MCLKSTOPEN_BIT167str ip, [r0, #DDR2_SDRCR_OFFSET]168169ldr ip, [r0, #DDR2_SDRCR_OFFSET]170bic ip, ip, #DDR2_LPMODEN_BIT171str ip, [r0, #DDR2_SDRCR_OFFSET]172173/* Restore registers and return */174ldmfd sp!, {r0-r12, pc}175176ENDPROC(davinci_cpu_suspend)177178/*179* Disables or Enables DDR2 LPSC180* Register Usage:181* r0: Enable or Disable LPSC r0 = 0x3 => Enable, r0 = 0x2 => Disable LPSC182* r1: contains virtual base for DDR2 Power and Sleep controller (PSC)183* r2: contains PSC number for DDR2184*/185ENTRY(davinci_ddr_psc_config)186/* Set next state in mdctl for DDR2 */187mov r6, #MDCTL188add r6, r6, r2, lsl #2189ldr ip, [r1, r6]190bic ip, ip, #MDSTAT_STATE_MASK191orr ip, ip, r0192str ip, [r1, r6]193194/* Enable the Power Domain Transition Command */195ldr ip, [r1, #PTCMD]196orr ip, ip, #0x1197str ip, [r1, #PTCMD]198199/* Check for Transition Complete (PTSTAT) */200ptstat_done:201ldr ip, [r1, #PTSTAT]202and ip, ip, #0x1203cmp ip, #0x0204bne ptstat_done205206/* Check for DDR2 clock disable completion; */207mov r6, #MDSTAT208add r6, r6, r2, lsl #2209ddr2clk_stop_done:210ldr ip, [r1, r6]211and ip, ip, #MDSTAT_STATE_MASK212cmp ip, r0213bne ddr2clk_stop_done214215mov pc, lr216ENDPROC(davinci_ddr_psc_config)217218CACHE_FLUSH:219.word arm926_flush_kern_cache_all220221ENTRY(davinci_cpu_suspend_sz)222.word . - davinci_cpu_suspend223ENDPROC(davinci_cpu_suspend_sz)224225226