2008-09-22 00:35:18 +04:00
|
|
|
/*
|
|
|
|
* arch/arm/mach-at91/pm_slow_clock.S
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Savin Zlobec
|
|
|
|
*
|
|
|
|
* AT91SAM9 support:
|
|
|
|
* Copyright (C) 2007 Anti Sullin <anti.sullin@artecdesign.ee
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/linkage.h>
|
2013-10-11 11:37:45 +04:00
|
|
|
#include <linux/clk/at91_pmc.h>
|
2012-02-13 08:58:53 +04:00
|
|
|
#include <mach/at91_ramc.h>
|
2015-03-09 06:49:46 +03:00
|
|
|
#include "pm.h"
|
2008-09-22 00:35:18 +04:00
|
|
|
|
2015-03-09 06:48:26 +03:00
|
|
|
#define SRAMC_SELF_FRESH_ACTIVE 0x01
|
|
|
|
#define SRAMC_SELF_FRESH_EXIT 0x00
|
|
|
|
|
2012-02-22 20:50:54 +04:00
|
|
|
pmc .req r0
|
2012-02-22 20:50:55 +04:00
|
|
|
tmp1 .req r4
|
|
|
|
tmp2 .req r5
|
2008-09-22 00:35:18 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait until master clock is ready (after switching master clock source)
|
|
|
|
*/
|
|
|
|
.macro wait_mckrdy
|
2015-02-05 09:00:37 +03:00
|
|
|
1: ldr tmp1, [pmc, #AT91_PMC_SR]
|
2012-02-22 20:50:53 +04:00
|
|
|
tst tmp1, #AT91_PMC_MCKRDY
|
2008-09-22 00:35:18 +04:00
|
|
|
beq 1b
|
|
|
|
.endm
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait until master oscillator has stabilized.
|
|
|
|
*/
|
|
|
|
.macro wait_moscrdy
|
2015-02-05 09:00:37 +03:00
|
|
|
1: ldr tmp1, [pmc, #AT91_PMC_SR]
|
2012-02-22 20:50:53 +04:00
|
|
|
tst tmp1, #AT91_PMC_MOSCS
|
2008-09-22 00:35:18 +04:00
|
|
|
beq 1b
|
|
|
|
.endm
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait until PLLA has locked.
|
|
|
|
*/
|
|
|
|
.macro wait_pllalock
|
2015-02-05 09:00:37 +03:00
|
|
|
1: ldr tmp1, [pmc, #AT91_PMC_SR]
|
2012-02-22 20:50:53 +04:00
|
|
|
tst tmp1, #AT91_PMC_LOCKA
|
2008-09-22 00:35:18 +04:00
|
|
|
beq 1b
|
|
|
|
.endm
|
|
|
|
|
2015-03-09 06:53:46 +03:00
|
|
|
/*
|
|
|
|
* Put the processor to enter the idle state
|
|
|
|
*/
|
|
|
|
.macro at91_cpu_idle
|
|
|
|
|
|
|
|
#if defined(CONFIG_CPU_V7)
|
|
|
|
mov tmp1, #AT91_PMC_PCK
|
|
|
|
str tmp1, [pmc, #AT91_PMC_SCDR]
|
|
|
|
|
|
|
|
dsb
|
|
|
|
|
|
|
|
wfi @ Wait For Interrupt
|
|
|
|
#else
|
|
|
|
mcr p15, 0, tmp1, c7, c0, 4
|
|
|
|
#endif
|
|
|
|
|
|
|
|
.endm
|
|
|
|
|
2008-09-22 00:35:18 +04:00
|
|
|
.text
|
|
|
|
|
2015-03-11 05:08:12 +03:00
|
|
|
.arm
|
|
|
|
|
2015-03-09 06:51:09 +03:00
|
|
|
/*
|
|
|
|
* void at91_pm_suspend_in_sram(void __iomem *pmc, void __iomem *sdramc,
|
2012-02-22 20:50:55 +04:00
|
|
|
* void __iomem *ramc1, int memctrl)
|
2015-03-09 06:51:09 +03:00
|
|
|
* @input param:
|
|
|
|
* @r0: base address of AT91_PMC
|
|
|
|
* @r1: base address of SDRAM Controller (SDRAM, DDRSDR, or AT91_SYS)
|
|
|
|
* @r2: base address of second SDRAM Controller or 0 if not present
|
|
|
|
* @r3: pm information
|
2012-02-22 20:50:55 +04:00
|
|
|
*/
|
2015-03-09 06:51:09 +03:00
|
|
|
ENTRY(at91_pm_suspend_in_sram)
|
2008-09-22 00:35:18 +04:00
|
|
|
/* Save registers on stack */
|
2012-02-22 20:50:55 +04:00
|
|
|
stmfd sp!, {r4 - r12, lr}
|
2008-09-22 00:35:18 +04:00
|
|
|
|
|
|
|
/* Drain write buffer */
|
2012-02-22 20:50:53 +04:00
|
|
|
mov tmp1, #0
|
|
|
|
mcr p15, 0, tmp1, c7, c10, 4
|
2008-09-22 00:35:18 +04:00
|
|
|
|
2015-03-09 06:48:26 +03:00
|
|
|
str r0, .pmc_base
|
|
|
|
str r1, .sramc_base
|
|
|
|
str r2, .sramc1_base
|
2015-03-09 06:49:46 +03:00
|
|
|
|
|
|
|
and r0, r3, #AT91_PM_MEMTYPE_MASK
|
|
|
|
str r0, .memtype
|
|
|
|
|
|
|
|
lsr r0, r3, #AT91_PM_MODE_OFFSET
|
|
|
|
and r0, r0, #AT91_PM_MODE_MASK
|
|
|
|
str r0, .pm_mode
|
2012-02-22 20:50:55 +04:00
|
|
|
|
2015-03-09 06:48:26 +03:00
|
|
|
/* Active the self-refresh mode */
|
|
|
|
mov r0, #SRAMC_SELF_FRESH_ACTIVE
|
|
|
|
bl at91_sramc_self_refresh
|
2012-02-22 20:50:55 +04:00
|
|
|
|
2015-03-09 06:49:46 +03:00
|
|
|
ldr r0, .pm_mode
|
|
|
|
tst r0, #AT91_PM_SLOW_CLOCK
|
|
|
|
beq skip_disable_main_clock
|
|
|
|
|
2015-03-09 06:48:26 +03:00
|
|
|
ldr pmc, .pmc_base
|
2008-09-22 00:35:18 +04:00
|
|
|
|
|
|
|
/* Save Master clock setting */
|
2011-11-25 05:59:46 +04:00
|
|
|
ldr tmp1, [pmc, #AT91_PMC_MCKR]
|
2012-02-22 20:50:53 +04:00
|
|
|
str tmp1, .saved_mckr
|
2008-09-22 00:35:18 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the Master clock source to slow clock
|
|
|
|
*/
|
2012-02-22 20:50:53 +04:00
|
|
|
bic tmp1, tmp1, #AT91_PMC_CSS
|
2011-11-25 05:59:46 +04:00
|
|
|
str tmp1, [pmc, #AT91_PMC_MCKR]
|
2008-09-22 00:35:18 +04:00
|
|
|
|
|
|
|
wait_mckrdy
|
|
|
|
|
|
|
|
/* Save PLLA setting and disable it */
|
2011-11-25 05:59:46 +04:00
|
|
|
ldr tmp1, [pmc, #AT91_CKGR_PLLAR]
|
2012-02-22 20:50:53 +04:00
|
|
|
str tmp1, .saved_pllar
|
2008-09-22 00:35:18 +04:00
|
|
|
|
2012-02-22 20:50:53 +04:00
|
|
|
mov tmp1, #AT91_PMC_PLLCOUNT
|
|
|
|
orr tmp1, tmp1, #(1 << 29) /* bit 29 always set */
|
2011-11-25 05:59:46 +04:00
|
|
|
str tmp1, [pmc, #AT91_CKGR_PLLAR]
|
2008-09-22 00:35:18 +04:00
|
|
|
|
|
|
|
/* Turn off the main oscillator */
|
2011-11-25 05:59:46 +04:00
|
|
|
ldr tmp1, [pmc, #AT91_CKGR_MOR]
|
2012-02-22 20:50:53 +04:00
|
|
|
bic tmp1, tmp1, #AT91_PMC_MOSCEN
|
2015-02-12 05:52:13 +03:00
|
|
|
orr tmp1, tmp1, #AT91_PMC_KEY
|
2011-11-25 05:59:46 +04:00
|
|
|
str tmp1, [pmc, #AT91_CKGR_MOR]
|
2008-09-22 00:35:18 +04:00
|
|
|
|
2015-03-09 06:49:46 +03:00
|
|
|
skip_disable_main_clock:
|
|
|
|
ldr pmc, .pmc_base
|
|
|
|
|
2008-09-22 00:35:18 +04:00
|
|
|
/* Wait for interrupt */
|
2015-03-09 06:53:46 +03:00
|
|
|
at91_cpu_idle
|
2008-09-22 00:35:18 +04:00
|
|
|
|
2015-03-09 06:49:46 +03:00
|
|
|
ldr r0, .pm_mode
|
|
|
|
tst r0, #AT91_PM_SLOW_CLOCK
|
|
|
|
beq skip_enable_main_clock
|
|
|
|
|
|
|
|
ldr pmc, .pmc_base
|
|
|
|
|
2008-09-22 00:35:18 +04:00
|
|
|
/* Turn on the main oscillator */
|
2011-11-25 05:59:46 +04:00
|
|
|
ldr tmp1, [pmc, #AT91_CKGR_MOR]
|
2012-02-22 20:50:53 +04:00
|
|
|
orr tmp1, tmp1, #AT91_PMC_MOSCEN
|
2015-02-12 05:52:13 +03:00
|
|
|
orr tmp1, tmp1, #AT91_PMC_KEY
|
2011-11-25 05:59:46 +04:00
|
|
|
str tmp1, [pmc, #AT91_CKGR_MOR]
|
2008-09-22 00:35:18 +04:00
|
|
|
|
|
|
|
wait_moscrdy
|
|
|
|
|
|
|
|
/* Restore PLLA setting */
|
2012-02-22 20:50:53 +04:00
|
|
|
ldr tmp1, .saved_pllar
|
2011-11-25 05:59:46 +04:00
|
|
|
str tmp1, [pmc, #AT91_CKGR_PLLAR]
|
2008-09-22 00:35:18 +04:00
|
|
|
|
2012-02-22 20:50:53 +04:00
|
|
|
tst tmp1, #(AT91_PMC_MUL & 0xff0000)
|
2010-04-08 14:48:16 +04:00
|
|
|
bne 3f
|
2012-02-22 20:50:53 +04:00
|
|
|
tst tmp1, #(AT91_PMC_MUL & ~0xff0000)
|
2010-04-08 14:48:16 +04:00
|
|
|
beq 4f
|
|
|
|
3:
|
2008-09-22 00:35:18 +04:00
|
|
|
wait_pllalock
|
2010-04-08 14:48:16 +04:00
|
|
|
4:
|
2008-09-22 00:35:18 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Restore master clock setting
|
|
|
|
*/
|
2015-03-09 06:48:26 +03:00
|
|
|
ldr tmp1, .saved_mckr
|
2011-11-25 05:59:46 +04:00
|
|
|
str tmp1, [pmc, #AT91_PMC_MCKR]
|
2008-09-22 00:35:18 +04:00
|
|
|
|
|
|
|
wait_mckrdy
|
|
|
|
|
2015-03-09 06:49:46 +03:00
|
|
|
skip_enable_main_clock:
|
2015-03-09 06:48:26 +03:00
|
|
|
/* Exit the self-refresh mode */
|
|
|
|
mov r0, #SRAMC_SELF_FRESH_EXIT
|
|
|
|
bl at91_sramc_self_refresh
|
|
|
|
|
|
|
|
/* Restore registers, and return */
|
|
|
|
ldmfd sp!, {r4 - r12, pc}
|
2015-03-09 06:51:09 +03:00
|
|
|
ENDPROC(at91_pm_suspend_in_sram)
|
2015-03-09 06:48:26 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* void at91_sramc_self_refresh(unsigned int is_active)
|
|
|
|
*
|
|
|
|
* @input param:
|
|
|
|
* @r0: 1 - active self-refresh mode
|
|
|
|
* 0 - exit self-refresh mode
|
|
|
|
* register usage:
|
|
|
|
* @r1: memory type
|
|
|
|
* @r2: base address of the sram controller
|
|
|
|
*/
|
|
|
|
|
|
|
|
ENTRY(at91_sramc_self_refresh)
|
|
|
|
ldr r1, .memtype
|
|
|
|
ldr r2, .sramc_base
|
|
|
|
|
|
|
|
cmp r1, #AT91_MEMCTRL_MC
|
|
|
|
bne ddrc_sf
|
|
|
|
|
2012-02-22 20:50:55 +04:00
|
|
|
/*
|
|
|
|
* at91rm9200 Memory controller
|
|
|
|
*/
|
2015-03-09 06:48:26 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For exiting the self-refresh mode, do nothing,
|
|
|
|
* automatically exit the self-refresh mode.
|
|
|
|
*/
|
|
|
|
tst r0, #SRAMC_SELF_FRESH_ACTIVE
|
|
|
|
beq exit_sramc_sf
|
|
|
|
|
|
|
|
/* Active SDRAM self-refresh mode */
|
|
|
|
mov r3, #1
|
|
|
|
str r3, [r2, #AT91RM9200_SDRAMC_SRR]
|
|
|
|
b exit_sramc_sf
|
|
|
|
|
|
|
|
ddrc_sf:
|
|
|
|
cmp r1, #AT91_MEMCTRL_DDRSDR
|
|
|
|
bne sdramc_sf
|
2012-02-22 20:50:55 +04:00
|
|
|
|
|
|
|
/*
|
2015-03-09 06:48:26 +03:00
|
|
|
* DDR Memory controller
|
2012-02-22 20:50:55 +04:00
|
|
|
*/
|
2015-03-09 06:48:26 +03:00
|
|
|
tst r0, #SRAMC_SELF_FRESH_ACTIVE
|
|
|
|
beq ddrc_exit_sf
|
|
|
|
|
|
|
|
/* LPDDR1 --> force DDR2 mode during self-refresh */
|
|
|
|
ldr r3, [r2, #AT91_DDRSDRC_MDR]
|
|
|
|
str r3, .saved_sam9_mdr
|
|
|
|
bic r3, r3, #~AT91_DDRSDRC_MD
|
|
|
|
cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
|
|
|
|
ldreq r3, [r2, #AT91_DDRSDRC_MDR]
|
|
|
|
biceq r3, r3, #AT91_DDRSDRC_MD
|
|
|
|
orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
|
|
|
|
streq r3, [r2, #AT91_DDRSDRC_MDR]
|
|
|
|
|
|
|
|
/* Active DDRC self-refresh mode */
|
|
|
|
ldr r3, [r2, #AT91_DDRSDRC_LPR]
|
|
|
|
str r3, .saved_sam9_lpr
|
|
|
|
bic r3, r3, #AT91_DDRSDRC_LPCB
|
|
|
|
orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
|
|
|
|
str r3, [r2, #AT91_DDRSDRC_LPR]
|
|
|
|
|
|
|
|
/* If using the 2nd ddr controller */
|
|
|
|
ldr r2, .sramc1_base
|
|
|
|
cmp r2, #0
|
|
|
|
beq no_2nd_ddrc
|
|
|
|
|
|
|
|
ldr r3, [r2, #AT91_DDRSDRC_MDR]
|
|
|
|
str r3, .saved_sam9_mdr1
|
|
|
|
bic r3, r3, #~AT91_DDRSDRC_MD
|
|
|
|
cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
|
|
|
|
ldreq r3, [r2, #AT91_DDRSDRC_MDR]
|
|
|
|
biceq r3, r3, #AT91_DDRSDRC_MD
|
|
|
|
orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
|
|
|
|
streq r3, [r2, #AT91_DDRSDRC_MDR]
|
|
|
|
|
|
|
|
/* Active DDRC self-refresh mode */
|
|
|
|
ldr r3, [r2, #AT91_DDRSDRC_LPR]
|
|
|
|
str r3, .saved_sam9_lpr1
|
|
|
|
bic r3, r3, #AT91_DDRSDRC_LPCB
|
|
|
|
orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
|
|
|
|
str r3, [r2, #AT91_DDRSDRC_LPR]
|
|
|
|
|
|
|
|
no_2nd_ddrc:
|
|
|
|
b exit_sramc_sf
|
|
|
|
|
|
|
|
ddrc_exit_sf:
|
2015-02-05 09:02:09 +03:00
|
|
|
/* Restore MDR in case of LPDDR1 */
|
2015-03-09 06:48:26 +03:00
|
|
|
ldr r3, .saved_sam9_mdr
|
|
|
|
str r3, [r2, #AT91_DDRSDRC_MDR]
|
2010-06-21 17:59:27 +04:00
|
|
|
/* Restore LPR on AT91 with DDRAM */
|
2015-03-09 06:48:26 +03:00
|
|
|
ldr r3, .saved_sam9_lpr
|
|
|
|
str r3, [r2, #AT91_DDRSDRC_LPR]
|
2010-06-21 17:59:27 +04:00
|
|
|
|
2015-03-09 06:48:26 +03:00
|
|
|
/* If using the 2nd ddr controller */
|
|
|
|
ldr r2, .sramc1_base
|
|
|
|
cmp r2, #0
|
|
|
|
ldrne r3, .saved_sam9_mdr1
|
|
|
|
strne r3, [r2, #AT91_DDRSDRC_MDR]
|
|
|
|
ldrne r3, .saved_sam9_lpr1
|
|
|
|
strne r3, [r2, #AT91_DDRSDRC_LPR]
|
2010-06-21 17:59:27 +04:00
|
|
|
|
2015-03-09 06:48:26 +03:00
|
|
|
b exit_sramc_sf
|
2012-02-22 20:50:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* SDRAMC Memory controller
|
|
|
|
*/
|
2015-03-09 06:48:26 +03:00
|
|
|
sdramc_sf:
|
|
|
|
tst r0, #SRAMC_SELF_FRESH_ACTIVE
|
|
|
|
beq sdramc_exit_sf
|
|
|
|
|
|
|
|
/* Active SDRAMC self-refresh mode */
|
|
|
|
ldr r3, [r2, #AT91_SDRAMC_LPR]
|
|
|
|
str r3, .saved_sam9_lpr
|
|
|
|
bic r3, r3, #AT91_SDRAMC_LPCB
|
|
|
|
orr r3, r3, #AT91_SDRAMC_LPCB_SELF_REFRESH
|
|
|
|
str r3, [r2, #AT91_SDRAMC_LPR]
|
|
|
|
|
|
|
|
sdramc_exit_sf:
|
|
|
|
ldr r3, .saved_sam9_lpr
|
|
|
|
str r3, [r2, #AT91_SDRAMC_LPR]
|
|
|
|
|
|
|
|
exit_sramc_sf:
|
|
|
|
mov pc, lr
|
|
|
|
ENDPROC(at91_sramc_self_refresh)
|
|
|
|
|
|
|
|
.pmc_base:
|
|
|
|
.word 0
|
|
|
|
.sramc_base:
|
|
|
|
.word 0
|
|
|
|
.sramc1_base:
|
|
|
|
.word 0
|
|
|
|
.memtype:
|
|
|
|
.word 0
|
2015-03-09 06:49:46 +03:00
|
|
|
.pm_mode:
|
|
|
|
.word 0
|
2008-09-22 00:35:18 +04:00
|
|
|
.saved_mckr:
|
|
|
|
.word 0
|
|
|
|
.saved_pllar:
|
|
|
|
.word 0
|
|
|
|
.saved_sam9_lpr:
|
|
|
|
.word 0
|
2010-06-21 17:59:27 +04:00
|
|
|
.saved_sam9_lpr1:
|
|
|
|
.word 0
|
2015-02-05 09:02:09 +03:00
|
|
|
.saved_sam9_mdr:
|
|
|
|
.word 0
|
|
|
|
.saved_sam9_mdr1:
|
|
|
|
.word 0
|
|
|
|
|
2015-03-09 06:51:09 +03:00
|
|
|
ENTRY(at91_pm_suspend_in_sram_sz)
|
|
|
|
.word .-at91_pm_suspend_in_sram
|