2005-04-17 02:20:36 +04:00
/ *
* SA1 1 x0 A s s e m b l e r S l e e p / W a k e U p M a n a g e m e n t R o u t i n e s
*
* Copyright ( c ) 2 0 0 1 C l i f f B r a k e < c b r a k e @accelent.com>
*
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or
* modify i t u n d e r t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e .
*
* History :
*
* 2 0 0 1 - 0 2 - 06 : Cliff B r a k e I n i t i a l c o d e
*
* 2 0 0 1 - 0 8 - 29 : Nicolas P i t r e S i m p l i f i e d .
*
* 2 0 0 2 - 0 5 - 27 : Nicolas P i t r e R e v i s i t e d , m o r e c l e a n u p a n d s i m p l i f i c a t i o n .
* Storage i s o n t h e s t a c k n o w .
* /
# include < l i n u x / l i n k a g e . h >
# include < a s m / a s s e m b l e r . h >
2008-08-05 19:14:15 +04:00
# include < m a c h / h a r d w a r e . h >
2005-04-17 02:20:36 +04:00
.text
/ *
* sa1 1 0 0 _ c p u _ s u s p e n d ( )
*
* Causes s a11 x0 t o e n t e r s l e e p s t a t e
*
* /
ENTRY( s a11 0 0 _ c p u _ s u s p e n d )
stmfd s p ! , { r4 - r12 , l r } @ save registers on stack
2011-02-06 20:41:40 +03:00
mov r1 , r0
ldr r3 , =sa1100_cpu_resume @ return function
bl c p u _ s u s p e n d
2005-04-17 02:20:36 +04:00
@ disable clock switching
mcr p15 , 0 , r1 , c15 , c2 , 2
@ Adjust memory timing before lowering CPU clock
@ Clock speed adjustment without changing memory timing makes
@ CPU hang in some cases
ldr r0 , =MDREFR
ldr r1 , [ r0 ]
orr r1 , r1 , #M D R E F R _ K 1 D B 2
str r1 , [ r0 ]
@ delay 90us and set CPU PLL to lowest speed
@ fixes resume problem on high speed SA1110
mov r0 , #90
bl _ _ u d e l a y
ldr r0 , =PPCR
mov r1 , #0
str r1 , [ r0 ]
mov r0 , #90
bl _ _ u d e l a y
/ *
* SA1 1 1 0 S D R A M c o n t r o l l e r w o r k a r o u n d . r e g i s t e r v a l u e s :
*
* r0 = & M S C 0
* r1 = & M S C 1
* r2 = & M S C 2
* r3 = M S C 0 v a l u e
* r4 = M S C 1 v a l u e
* r5 = M S C 2 v a l u e
* r6 = & M D R E F R
* r7 = f i r s t M D R E F R v a l u e
* r8 = s e c o n d M D R E F R v a l u e
* r9 = & M D C N F G
* r1 0 = M D C N F G v a l u e
* r1 1 = t h i r d M D R E F R v a l u e
* r1 2 = & P M C R
* r1 3 = P M C R v a l u e ( 1 )
* /
ldr r0 , =MSC0
ldr r1 , =MSC1
ldr r2 , =MSC2
2008-11-26 22:58:43 +03:00
ldr r3 , [ r0 ]
bic r3 , r3 , #F M s k ( M S C _ R T )
bic r3 , r3 , #F M s k ( M S C _ R T ) < < 16
2005-04-17 02:20:36 +04:00
2008-11-26 22:58:43 +03:00
ldr r4 , [ r1 ]
bic r4 , r4 , #F M s k ( M S C _ R T )
bic r4 , r4 , #F M s k ( M S C _ R T ) < < 16
2005-04-17 02:20:36 +04:00
2008-11-26 22:58:43 +03:00
ldr r5 , [ r2 ]
bic r5 , r5 , #F M s k ( M S C _ R T )
bic r5 , r5 , #F M s k ( M S C _ R T ) < < 16
2005-04-17 02:20:36 +04:00
2008-11-26 22:58:43 +03:00
ldr r6 , =MDREFR
2005-04-17 02:20:36 +04:00
2008-11-26 22:58:43 +03:00
ldr r7 , [ r6 ]
bic r7 , r7 , #0x0000FF00
bic r7 , r7 , #0x000000F0
orr r8 , r7 , #M D R E F R _ S L F R S H
2005-04-17 02:20:36 +04:00
2008-11-26 22:58:43 +03:00
ldr r9 , =MDCNFG
ldr r10 , [ r9 ]
bic r10 , r10 , #( M D C N F G _ D E 0 + M D C N F G _ D E 1 )
bic r10 , r10 , #( M D C N F G _ D E 2 + M D C N F G _ D E 3 )
2005-04-17 02:20:36 +04:00
2008-11-26 22:58:43 +03:00
bic r11 , r8 , #M D R E F R _ S L F R S H
bic r11 , r11 , #M D R E F R _ E 1 P I N
2005-04-17 02:20:36 +04:00
2008-11-26 22:58:43 +03:00
ldr r12 , =PMCR
2005-04-17 02:20:36 +04:00
2008-11-26 22:58:43 +03:00
mov r13 , #P M C R _ S F
2005-04-17 02:20:36 +04:00
b s a11 1 0 _ s d r a m _ c o n t r o l l e r _ f i x
.align 5
sa1110_sdram_controller_fix :
@ Step 1 clear RT field of all MSCx registers
str r3 , [ r0 ]
str r4 , [ r1 ]
str r5 , [ r2 ]
@ Step 2 clear DRI field in MDREFR
str r7 , [ r6 ]
@ Step 3 set SLFRSH bit in MDREFR
str r8 , [ r6 ]
@ Step 4 clear DE bis in MDCNFG
str r10 , [ r9 ]
@ Step 5 clear DRAM refresh control register
str r11 , [ r6 ]
@ Wow, now the hardware suspend request pins can be used, that makes them functional for
@ about 7 ns out of the entire time that the CPU is running!
@ Step 6 set force sleep bit in PMCR
str r13 , [ r12 ]
20 : b 2 0 b @ loop waiting for sleep
/ *
* cpu_ s a11 0 0 _ r e s u m e ( )
*
* entry p o i n t f r o m b o o t l o a d e r i n t o k e r n e l d u r i n g r e s u m e
* /
.align 5
2011-02-06 20:41:40 +03:00
sa1100_cpu_resume :
2008-11-26 22:58:43 +03:00
mcr p15 , 0 , r1 , c15 , c1 , 2 @ enable clock switching
2005-04-17 02:20:36 +04:00
ldmfd s p ! , { r4 - r12 , p c } @ return to caller