/* SPDX-License-Identifier: GPL-2.0-only */1/*2* (C) Copyright 2009, Texas Instruments, Inc. https://www.ti.com/3*/45/* replicated define because linux/bitops.h cannot be included in assembly */6#define BIT(nr) (1 << (nr))78#include <linux/linkage.h>9#include <asm/assembler.h>10#include "psc.h"11#include "ddr2.h"1213#include "clock.h"1415/* Arbitrary, hardware currently does not update PHYRDY correctly */16#define PHYRDY_CYCLES 0x10001718/* Assume 25 MHz speed for the cycle conversions since PLLs are bypassed */19#define PLL_BYPASS_CYCLES (PLL_BYPASS_TIME * 25)20#define PLL_RESET_CYCLES (PLL_RESET_TIME * 25)21#define PLL_LOCK_CYCLES (PLL_LOCK_TIME * 25)2223#define DEEPSLEEP_SLEEPENABLE_BIT BIT(31)2425.text26.arch armv5te27/*28* Move DaVinci into deep sleep state29*30* Note: This code is copied to internal SRAM by PM code. When the DaVinci31* wakes up it continues execution at the point it went to sleep.32* Register Usage:33* r0: contains virtual base for DDR2 controller34* r1: contains virtual base for DDR2 Power and Sleep controller (PSC)35* r2: contains PSC number for DDR236* r3: contains virtual base DDR2 PLL controller37* r4: contains virtual address of the DEEPSLEEP register38*/39ENTRY(davinci_cpu_suspend)40stmfd sp!, {r0-r12, lr} @ save registers on stack4142ldr ip, CACHE_FLUSH43blx ip4445ldmia r0, {r0-r4}4647/*48* Switch DDR to self-refresh mode.49*/5051/* calculate SDRCR address */52ldr ip, [r0, #DDR2_SDRCR_OFFSET]53bic ip, ip, #DDR2_SRPD_BIT54orr ip, ip, #DDR2_LPMODEN_BIT55str ip, [r0, #DDR2_SDRCR_OFFSET]5657ldr ip, [r0, #DDR2_SDRCR_OFFSET]58orr ip, ip, #DDR2_MCLKSTOPEN_BIT59str ip, [r0, #DDR2_SDRCR_OFFSET]6061mov ip, #PHYRDY_CYCLES621: subs ip, ip, #0x163bne 1b6465/* Disable DDR2 LPSC */66mov r7, r067mov r0, #0x268bl davinci_ddr_psc_config69mov r0, r77071/* Disable clock to DDR PHY */72ldr ip, [r3, #PLLDIV1]73bic ip, ip, #PLLDIV_EN74str ip, [r3, #PLLDIV1]7576/* Put the DDR PLL in bypass and power down */77ldr ip, [r3, #PLLCTL]78bic ip, ip, #PLLCTL_PLLENSRC79bic ip, ip, #PLLCTL_PLLEN80str ip, [r3, #PLLCTL]8182/* Wait for PLL to switch to bypass */83mov ip, #PLL_BYPASS_CYCLES842: subs ip, ip, #0x185bne 2b8687/* Power down the PLL */88ldr ip, [r3, #PLLCTL]89orr ip, ip, #PLLCTL_PLLPWRDN90str ip, [r3, #PLLCTL]9192/* Go to deep sleep */93ldr ip, [r4]94orr ip, ip, #DEEPSLEEP_SLEEPENABLE_BIT95/* System goes to sleep beyond after this instruction */96str ip, [r4]9798/* Wake up from sleep */99100/* Clear sleep enable */101ldr ip, [r4]102bic ip, ip, #DEEPSLEEP_SLEEPENABLE_BIT103str ip, [r4]104105/* initialize the DDR PLL controller */106107/* Put PLL in reset */108ldr ip, [r3, #PLLCTL]109bic ip, ip, #PLLCTL_PLLRST110str ip, [r3, #PLLCTL]111112/* Clear PLL power down */113ldr ip, [r3, #PLLCTL]114bic ip, ip, #PLLCTL_PLLPWRDN115str ip, [r3, #PLLCTL]116117mov ip, #PLL_RESET_CYCLES1183: subs ip, ip, #0x1119bne 3b120121/* Bring PLL out of reset */122ldr ip, [r3, #PLLCTL]123orr ip, ip, #PLLCTL_PLLRST124str ip, [r3, #PLLCTL]125126/* Wait for PLL to lock (assume prediv = 1, 25MHz OSCIN) */127mov ip, #PLL_LOCK_CYCLES1284: subs ip, ip, #0x1129bne 4b130131/* Remove PLL from bypass mode */132ldr ip, [r3, #PLLCTL]133bic ip, ip, #PLLCTL_PLLENSRC134orr ip, ip, #PLLCTL_PLLEN135str ip, [r3, #PLLCTL]136137/* Start 2x clock to DDR2 */138139ldr ip, [r3, #PLLDIV1]140orr ip, ip, #PLLDIV_EN141str ip, [r3, #PLLDIV1]142143/* Enable VCLK */144145/* Enable DDR2 LPSC */146mov r7, r0147mov r0, #0x3148bl davinci_ddr_psc_config149mov r0, r7150151/* clear MCLKSTOPEN */152153ldr ip, [r0, #DDR2_SDRCR_OFFSET]154bic ip, ip, #DDR2_MCLKSTOPEN_BIT155str ip, [r0, #DDR2_SDRCR_OFFSET]156157ldr ip, [r0, #DDR2_SDRCR_OFFSET]158bic ip, ip, #DDR2_LPMODEN_BIT159str ip, [r0, #DDR2_SDRCR_OFFSET]160161/* Restore registers and return */162ldmfd sp!, {r0-r12, pc}163164ENDPROC(davinci_cpu_suspend)165166/*167* Disables or Enables DDR2 LPSC168* Register Usage:169* r0: Enable or Disable LPSC r0 = 0x3 => Enable, r0 = 0x2 => Disable LPSC170* r1: contains virtual base for DDR2 Power and Sleep controller (PSC)171* r2: contains PSC number for DDR2172*/173ENTRY(davinci_ddr_psc_config)174/* Set next state in mdctl for DDR2 */175mov r6, #MDCTL176add r6, r6, r2, lsl #2177ldr ip, [r1, r6]178bic ip, ip, #MDSTAT_STATE_MASK179orr ip, ip, r0180str ip, [r1, r6]181182/* Enable the Power Domain Transition Command */183ldr ip, [r1, #PTCMD]184orr ip, ip, #0x1185str ip, [r1, #PTCMD]186187/* Check for Transition Complete (PTSTAT) */188ptstat_done:189ldr ip, [r1, #PTSTAT]190and ip, ip, #0x1191cmp ip, #0x0192bne ptstat_done193194/* Check for DDR2 clock disable completion; */195mov r6, #MDSTAT196add r6, r6, r2, lsl #2197ddr2clk_stop_done:198ldr ip, [r1, r6]199and ip, ip, #MDSTAT_STATE_MASK200cmp ip, r0201bne ddr2clk_stop_done202203ret lr204ENDPROC(davinci_ddr_psc_config)205206CACHE_FLUSH:207#ifdef CONFIG_CPU_V6208.word v6_flush_kern_cache_all209#else210.word arm926_flush_kern_cache_all211#endif212213ENTRY(davinci_cpu_suspend_sz)214.word . - davinci_cpu_suspend215ENDPROC(davinci_cpu_suspend_sz)216217218