2009-05-28 21:56:16 +04:00
/ *
* ( C) C o p y r i g h t 2 0 0 7
* Texas I n s t r u m e n t s
* Karthik D a s u < k a r t h i k - d p @ti.com>
*
* ( C) C o p y r i g h t 2 0 0 4
* Texas I n s t r u m e n t s , < w w w . t i . c o m >
* Richard W o o d r u f f < r - w o o d r u f f2 @ti.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 a s
* published b y t h e F r e e S o f t w a r e F o u n d a t i o n ; either version 2 of
* the L i c e n s e , o r ( a t y o u r o p t i o n ) a n y l a t e r v e r s i o n .
*
* This p r o g r a m i s d i s t r i b u t e d i n t h e h o p e t h a t i t w i l l b e u s e f u l ,
* but W I T H O U T A N Y W A R R A N T Y ; without even the implied warranty of
* MERCHANTABILITY o r F I T N E S S F O R A P A R T I C U L A R / P U R P O S E . S e e t h e
* GNU G e n e r a l P u b l i c L i c e n s e f o r m o r e d e t a i l s .
*
* You s h o u l d h a v e r e c e i v e d a c o p y 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
* along w i t h t h i s p r o g r a m ; if not, write to the Free Software
* Foundation, I n c . , 5 9 T e m p l e P l a c e , S u i t e 3 3 0 , B o s t o n ,
* MA 0 2 1 1 1 - 1 3 0 7 U S A
* /
# include < l i n u x / l i n k a g e . h >
2012-02-24 22:34:35 +04:00
2009-05-28 21:56:16 +04:00
# include < a s m / a s s e m b l e r . h >
2012-02-24 22:34:35 +04:00
2012-08-31 21:59:07 +04:00
# include < p l a t / o m a p34 x x . h >
2010-12-18 18:44:42 +03:00
# include < p l a t / s r a m . h >
2009-05-28 21:56:16 +04:00
2012-02-24 22:34:35 +04:00
# include " i o m a p . h "
2010-12-22 01:30:55 +03:00
# include " c m 2 x x x _ 3 x x x . h "
# include " p r m 2 x x x _ 3 x x x . h "
2009-05-28 21:56:16 +04:00
# include " s d r c . h "
2010-10-08 21:40:20 +04:00
# include " c o n t r o l . h "
2009-05-28 21:56:16 +04:00
2010-12-18 18:44:43 +03:00
/ *
* Registers a c c e s s d e f i n i t i o n s
* /
# define S D R C _ S C R A T C H P A D _ S E M _ O F F S 0 x c
# define S D R C _ S C R A T C H P A D _ S E M _ V O M A P 3 4 3 X _ S C R A T C H P A D _ R E G A D D R \
( SDRC_ S C R A T C H P A D _ S E M _ O F F S )
# define P M _ P R E P W S T S T _ C O R E _ P O M A P 3 4 3 0 _ P R M _ B A S E + C O R E _ M O D + \
OMAP3 4 3 0 _ P M _ P R E P W S T S T
2010-01-27 06:12:51 +03:00
# define P M _ P W S T C T R L _ M P U _ P O M A P 3 4 3 0 _ P R M _ B A S E + M P U _ M O D + O M A P 2 _ P M _ P W S T C T R L
2009-01-16 19:53:48 +03:00
# define C M _ I D L E S T 1 _ C O R E _ V O M A P 3 4 X X _ C M _ R E G A D D R ( C O R E _ M O D , C M _ I D L E S T 1 )
2010-12-20 23:05:04 +03:00
# define C M _ I D L E S T _ C K G E N _ V O M A P 3 4 X X _ C M _ R E G A D D R ( P L L _ M O D , C M _ I D L E S T )
2010-12-18 18:44:43 +03:00
# define S R A M _ B A S E _ P O M A P 3 _ S R A M _ P A
# define C O N T R O L _ S T A T O M A P 3 4 3 X _ C T R L _ B A S E + O M A P 3 4 3 X _ C O N T R O L _ S T A T U S
# define C O N T R O L _ M E M _ R T A _ C T R L ( O M A P 3 4 3 X _ C T R L _ B A S E + \
OMAP3 6 X X _ C O N T R O L _ M E M _ R T A _ C T R L )
/* Move this as correct place is available */
# define S C R A T C H P A D _ M E M _ O F F S 0 x31 0
# define S C R A T C H P A D _ B A S E _ P ( O M A P 3 4 3 X _ C T R L _ B A S E + \
OMAP3 4 3 X _ C O N T R O L _ M E M _ W K U P + \
SCRATCHPAD_ M E M _ O F F S )
2009-05-28 21:56:16 +04:00
# define S D R C _ P O W E R _ V O M A P 3 4 X X _ S D R C _ R E G A D D R ( S D R C _ P O W E R )
2008-10-13 18:58:50 +04:00
# define S D R C _ S Y S C O N F I G _ P ( O M A P 3 4 3 X _ S D R C _ B A S E + S D R C _ S Y S C O N F I G )
# define S D R C _ M R _ 0 _ P ( O M A P 3 4 3 X _ S D R C _ B A S E + S D R C _ M R _ 0 )
# define S D R C _ E M R 2 _ 0 _ P ( O M A P 3 4 3 X _ S D R C _ B A S E + S D R C _ E M R 2 _ 0 )
# define S D R C _ M A N U A L _ 0 _ P ( O M A P 3 4 3 X _ S D R C _ B A S E + S D R C _ M A N U A L _ 0 )
# define S D R C _ M R _ 1 _ P ( O M A P 3 4 3 X _ S D R C _ B A S E + S D R C _ M R _ 1 )
# define S D R C _ E M R 2 _ 1 _ P ( O M A P 3 4 3 X _ S D R C _ B A S E + S D R C _ E M R 2 _ 1 )
# define S D R C _ M A N U A L _ 1 _ P ( O M A P 3 4 3 X _ S D R C _ B A S E + S D R C _ M A N U A L _ 1 )
2009-01-16 19:53:48 +03:00
# define S D R C _ D L L A _ S T A T U S _ V O M A P 3 4 X X _ S D R C _ R E G A D D R ( S D R C _ D L L A _ S T A T U S )
# define S D R C _ D L L A _ C T R L _ V O M A P 3 4 X X _ S D R C _ R E G A D D R ( S D R C _ D L L A _ C T R L )
2009-05-28 21:56:16 +04:00
2011-03-04 18:33:57 +03:00
/ *
* This f i l e n e e d s b e b u i l t u n c o n d i t i o n a l l y a s A R M t o i n t e r o p e r a t e c o r r e c t l y
* with n o n - T h u m b - 2 - c a p a b l e f i r m w a r e .
* /
.arm
2010-12-18 18:44:41 +03:00
/ *
* API f u n c t i o n s
2010-12-18 18:44:45 +03:00
* /
2010-12-20 23:05:07 +03:00
.text
/ *
* L2 c a c h e n e e d s t o b e t o g g l e d f o r s t a b l e O F F m o d e f u n c t i o n a l i t y o n 3 6 3 0 .
2010-12-18 18:44:44 +03:00
* This f u n c t i o n s e t s u p a f l a g t h a t w i l l a l l o w f o r t h i s t o g g l i n g t o t a k e
2010-12-18 18:44:45 +03:00
* place o n 3 6 3 0 . H o p e f u l l y s o m e v e r s i o n i n t h e f u t u r e m a y n o t n e e d t h i s .
2010-12-20 23:05:07 +03:00
* /
ENTRY( e n a b l e _ o m a p36 3 0 _ t o g g l e _ l 2 _ o n _ r e s t o r e )
2010-12-18 18:49:57 +03:00
stmfd s p ! , { l r } @ save registers on stack
2010-12-20 23:05:07 +03:00
/* Setup so that we will disable and enable l2 */
mov r1 , #0x1
2011-03-04 18:33:57 +03:00
adrl r2 , l 2 d i s _ 3 6 3 0 @ may be too distant for plain adr
str r1 , [ r2 ]
2010-12-18 18:49:57 +03:00
ldmfd s p ! , { p c } @ restore regs and return
2011-03-04 18:33:57 +03:00
ENDPROC( e n a b l e _ o m a p36 3 0 _ t o g g l e _ l 2 _ o n _ r e s t o r e )
2010-12-20 23:05:07 +03:00
2010-12-18 18:49:57 +03:00
.text
2008-10-13 14:15:00 +04:00
/* Function to call rom code to save secure ram context */
2011-02-02 18:38:06 +03:00
.align 3
2008-10-13 14:15:00 +04:00
ENTRY( s a v e _ s e c u r e _ r a m _ c o n t e x t )
2011-06-22 15:44:32 +04:00
stmfd s p ! , { r4 - r11 , l r } @ save registers on stack
2008-10-13 14:15:00 +04:00
adr r3 , a p i _ p a r a m s @ r3 points to parameters
str r0 , [ r3 ,#0x4 ] @ r0 has sdram address
ldr r12 , h i g h _ m a s k
and r3 , r3 , r12
ldr r12 , s r a m _ p h y _ a d d r _ m a s k
orr r3 , r3 , r12
mov r0 , #25 @ set service ID for PPA
mov r12 , r0 @ copy secure service ID in r12
mov r1 , #0 @ set task id for ROM code in r1
2009-03-26 16:59:00 +03:00
mov r2 , #4 @ set some flags in r2, r6
2008-10-13 14:15:00 +04:00
mov r6 , #0xff
2011-01-23 16:30:34 +03:00
dsb @ data write barrier
dmb @ data memory barrier
2011-03-04 18:33:55 +03:00
smc #1 @ call SMI monitor (smi #1)
2008-10-13 14:15:00 +04:00
nop
nop
nop
nop
2011-06-22 15:44:32 +04:00
ldmfd s p ! , { r4 - r11 , p c }
2011-03-04 18:33:57 +03:00
.align
2008-10-13 14:15:00 +04:00
sram_phy_addr_mask :
.word SRAM_BASE_P
high_mask :
.word 0xffff
api_params :
.word 0 x4 , 0 x0 , 0 x0 , 0 x1 , 0 x1
2011-03-04 18:33:57 +03:00
ENDPROC( s a v e _ s e c u r e _ r a m _ c o n t e x t )
2008-10-13 14:15:00 +04:00
ENTRY( s a v e _ s e c u r e _ r a m _ c o n t e x t _ s z )
.word . - save_ s e c u r e _ r a m _ c o n t e x t
2010-12-18 18:44:45 +03:00
/ *
* = = = = = = = = = = = = = = = = = = = = = =
* = = Idle e n t r y p o i n t = =
* = = = = = = = = = = = = = = = = = = = = = =
* /
2009-05-28 21:56:16 +04:00
/ *
* Forces O M A P i n t o i d l e s t a t e
*
2010-12-18 18:44:45 +03:00
* omap3 4 x x _ c p u _ s u s p e n d ( ) - T h i s b i t o f c o d e s a v e s t h e C P U c o n t e x t i f n e e d e d
* and e x e c u t e s t h e W F I i n s t r u c t i o n . C a l l i n g W F I e f f e c t i v e l y c h a n g e s t h e
* power d o m a i n s s t a t e s t o t h e d e s i r e d t a r g e t p o w e r s t a t e s .
*
2009-05-28 21:56:16 +04:00
*
2010-12-18 18:44:45 +03:00
* Notes :
2011-06-29 20:40:23 +04:00
* - only t h e m i n i m u m s e t o f f u n c t i o n s g e t s c o p i e d t o i n t e r n a l S R A M a t b o o t
* and a f t e r w a k e - u p f r o m O F F m o d e , c f . o m a p _ p u s h _ s r a m _ i d l e . T h e f u n c t i o n
* pointers i n S D R A M o r S R A M a r e c a l l e d d e p e n d i n g o n t h e d e s i r e d l o w p o w e r
* target s t a t e .
2010-12-18 18:44:45 +03:00
* - when t h e O M A P w a k e s u p i t c o n t i n u e s a t d i f f e r e n t e x e c u t i o n p o i n t s
* depending o n t h e l o w p o w e r m o d e ( n o n - O F F v s O F F m o d e s ) ,
* cf. ' R e s u m e p a t h f o r x x x m o d e ' c o m m e n t s .
2009-05-28 21:56:16 +04:00
* /
2011-02-02 18:38:06 +03:00
.align 3
2009-05-28 21:56:16 +04:00
ENTRY( o m a p34 x x _ c p u _ s u s p e n d )
2011-06-22 15:44:32 +04:00
stmfd s p ! , { r4 - r11 , l r } @ save registers on stack
2010-12-18 18:44:41 +03:00
2010-12-18 18:44:45 +03:00
/ *
2011-06-30 11:45:49 +04:00
* r0 c o n t a i n s i n f o r m a t i o n a b o u t s a v i n g c o n t e x t :
2010-12-18 18:44:45 +03:00
* 0 - No c o n t e x t l o s t
* 1 - Only L 1 a n d l o g i c l o s t
2011-01-23 17:03:53 +03:00
* 2 - Only L 2 l o s t ( E v e n L 1 i s r e t a i n e d w e c l e a n i t a l o n g w i t h L 2 )
* 3 - Both L 1 a n d L 2 l o s t a n d l o g i c l o s t
2010-12-18 18:44:45 +03:00
* /
2009-05-28 21:56:16 +04:00
2011-06-29 20:40:23 +04:00
/ *
* For O F F m o d e : s a v e c o n t e x t a n d j u m p t o W F I i n S D R A M ( o m a p3 _ d o _ w f i )
* For n o n - O F F m o d e s : j u m p t o t h e W F I c o d e i n S R A M ( o m a p3 _ d o _ w f i _ s r a m )
* /
ldr r4 , o m a p3 _ d o _ w f i _ s r a m _ a d d r
ldr r5 , [ r4 ]
2011-06-30 11:45:49 +04:00
cmp r0 , #0x0 @ If no context save required,
2011-06-29 20:40:23 +04:00
bxeq r5 @ jump to the WFI code in SRAM
2010-12-18 18:44:45 +03:00
/* Otherwise fall through to the save context code */
save_context_wfi :
/ *
* jump o u t t o k e r n e l f l u s h r o u t i n e
* - reuse t h a t c o d e i s b e t t e r
* - it e x e c u t e s i n a c a c h e d s p a c e s o i s f a s t e r t h a n r e f e t c h p e r - b l o c k
* - should b e f a s t e r a n d w i l l c h a n g e w i t h k e r n e l
* - ' might' h a v e t o c o p y a d d r e s s , l o a d a n d j u m p t o i t
2011-01-23 20:21:09 +03:00
* Flush a l l d a t a f r o m t h e L 1 d a t a c a c h e b e f o r e d i s a b l i n g
* SCTLR. C b i t .
2010-12-18 18:44:45 +03:00
* /
2010-12-18 18:49:57 +03:00
ldr r1 , k e r n e l _ f l u s h
mov l r , p c
bx r1
2010-12-18 18:44:45 +03:00
2011-01-23 20:21:09 +03:00
/ *
* Clear t h e S C T L R . C b i t t o p r e v e n t f u r t h e r d a t a c a c h e
* allocation. C l e a r i n g S C T L R . C w o u l d m a k e a l l t h e d a t a a c c e s s e s
* strongly o r d e r e d a n d w o u l d n o t h i t t h e c a c h e .
* /
mrc p15 , 0 , r0 , c1 , c0 , 0
bic r0 , r0 , #( 1 < < 2 ) @ Disable the C bit
mcr p15 , 0 , r0 , c1 , c0 , 0
isb
/ *
* Invalidate L 1 d a t a c a c h e . E v e n t h o u g h o n l y i n v a l i d a t e i s
* necessary e x p o r t e d f l u s h A P I i s u s e d h e r e . D o i n g c l e a n
* on a l r e a d y c l e a n c a c h e w o u l d b e a l m o s t N O P .
2010-12-18 18:44:45 +03:00
* /
2010-12-18 18:49:57 +03:00
ldr r1 , k e r n e l _ f l u s h
2011-03-04 18:33:57 +03:00
blx r1
/ *
* The k e r n e l d o e s n ' t i n t e r w o r k : v7 _ f l u s h _ d c a c h e _ a l l i n p a r t i c l u a r w i l l
* always r e t u r n i n T h u m b s t a t e w h e n C O N F I G _ T H U M B 2 _ K E R N E L i s e n a b l e d .
* This s e q u e n c e s w i t c h e s b a c k t o A R M . N o t e t h a t . a l i g n m a y i n s e r t a
* nop : bx p c n e e d s t o b e w o r d - a l i g n e d i n o r d e r t o w o r k .
* /
THUMB( . t h u m b )
THUMB( . a l i g n )
THUMB( b x p c )
THUMB( n o p )
.arm
2010-12-18 18:44:45 +03:00
2011-06-29 20:40:23 +04:00
b o m a p3 _ d o _ w f i
/ *
* Local v a r i a b l e s
* /
omap3_do_wfi_sram_addr :
.word omap3_do_wfi_sram
kernel_flush :
.word v7_flush_dcache_all
/ * = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* = = WFI i n s t r u c t i o n = > E n t e r i d l e = =
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* /
/ *
* Do W F I i n s t r u c t i o n
* Includes t h e r e s u m e p a t h f o r n o n - O F F m o d e s
*
* This c o d e g e t s c o p i e d t o i n t e r n a l S R A M a n d i s a c c e s s i b l e
* from b o t h S D R A M a n d S R A M :
* - executed f r o m S R A M f o r n o n - o f f m o d e s ( o m a p3 _ d o _ w f i _ s r a m ) ,
* - executed f r o m S D R A M f o r O F F m o d e ( o m a p3 _ d o _ w f i ) .
* /
.align 3
ENTRY( o m a p3 _ d o _ w f i )
2010-12-18 18:44:45 +03:00
ldr r4 , s d r c _ p o w e r @ read the SDRC_POWER register
ldr r5 , [ r4 ] @ read the contents of SDRC_POWER
orr r5 , r5 , #0x40 @ enable self refresh on idle req
str r5 , [ r4 ] @ write back to SDRC_POWER register
2009-05-28 21:56:16 +04:00
/* Data memory barrier and Data sync barrier */
2011-01-23 16:30:34 +03:00
dsb
dmb
2009-05-28 21:56:16 +04:00
2010-12-18 18:44:45 +03:00
/ *
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* = = WFI i n s t r u c t i o n = > E n t e r i d l e = =
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* /
2009-05-28 21:56:16 +04:00
wfi @ wait for interrupt
2010-12-18 18:44:45 +03:00
/ *
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* = = Resume p a t h f o r n o n - O F F m o d e s = =
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* /
2009-05-28 21:56:16 +04:00
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
2011-06-29 20:40:23 +04:00
/ *
* This f u n c t i o n i m p l e m e n t s t h e e r r a t u m I D i 5 8 1 W A :
* SDRC s t a t e r e s t o r e b e f o r e a c c e s s i n g t h e S D R A M
*
* Only u s e d a t r e t u r n f r o m n o n - O F F m o d e . F o r O F F
* mode t h e R O M c o d e c o n f i g u r e s t h e S D R C a n d
* the D P L L b e f o r e c a l l i n g t h e r e s t o r e c o d e d i r e c t l y
* from D D R .
* /
/* Make sure SDRC accesses are ok */
wait_sdrc_ok :
/* DPLL3 must be locked before accessing the SDRC. Maybe the HW ensures this */
ldr r4 , c m _ i d l e s t _ c k g e n
wait_dpll3_lock :
ldr r5 , [ r4 ]
tst r5 , #1
beq w a i t _ d p l l 3 _ l o c k
ldr r4 , c m _ i d l e s t 1 _ c o r e
wait_sdrc_ready :
ldr r5 , [ r4 ]
tst r5 , #0x2
bne w a i t _ s d r c _ r e a d y
/* allow DLL powerdown upon hw idle req */
ldr r4 , s d r c _ p o w e r
ldr r5 , [ r4 ]
bic r5 , r5 , #0x40
str r5 , [ r4 ]
/ *
* PC- r e l a t i v e s t o r e s l e a d t o u n d e f i n e d b e h a v i o u r i n T h u m b - 2 : u s e a r7 a s a
* base i n s t e a d .
* Be c a r e f u l n o t t o c l o b b e r r7 w h e n m a i n t a i n g t h i s c o d e .
* /
is_dll_in_lock_mode :
/* Is dll in lock mode? */
ldr r4 , s d r c _ d l l a _ c t r l
ldr r5 , [ r4 ]
tst r5 , #0x4
bne e x i t _ n o n o f f _ m o d e s @ Return if locked
/* wait till dll locks */
adr r7 , k i c k _ c o u n t e r
wait_dll_lock_timed :
ldr r4 , w a i t _ d l l _ l o c k _ c o u n t e r
add r4 , r4 , #1
str r4 , [ r7 , #w a i t _ d l l _ l o c k _ c o u n t e r - k i c k _ c o u n t e r ]
ldr r4 , s d r c _ d l l a _ s t a t u s
/* Wait 20uS for lock */
mov r6 , #8
wait_dll_lock :
subs r6 , r6 , #0x1
beq k i c k _ d l l
ldr r5 , [ r4 ]
and r5 , r5 , #0x4
cmp r5 , #0x4
bne w a i t _ d l l _ l o c k
b e x i t _ n o n o f f _ m o d e s @ Return when locked
/* disable/reenable DLL if not locked */
kick_dll :
ldr r4 , s d r c _ d l l a _ c t r l
ldr r5 , [ r4 ]
mov r6 , r5
bic r6 , #( 1 < < 3 ) @ disable dll
str r6 , [ r4 ]
dsb
orr r6 , r6 , #( 1 < < 3 ) @ enable dll
str r6 , [ r4 ]
dsb
ldr r4 , k i c k _ c o u n t e r
add r4 , r4 , #1
str r4 , [ r7 ] @ kick_counter
b w a i t _ d l l _ l o c k _ t i m e d
exit_nonoff_modes :
/* Re-enable C-bit if needed */
2011-01-23 20:21:09 +03:00
mrc p15 , 0 , r0 , c1 , c0 , 0
tst r0 , #( 1 < < 2 ) @ Check C bit enabled?
orreq r0 , r0 , #( 1 < < 2 ) @ Enable the C bit if cleared
mcreq p15 , 0 , r0 , c1 , c0 , 0
isb
2010-12-18 18:44:45 +03:00
/ *
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* = = Exit p o i n t f r o m n o n - O F F m o d e s = =
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* /
2011-06-22 15:44:32 +04:00
ldmfd s p ! , { r4 - r11 , p c } @ restore regs and return
2010-12-18 18:44:45 +03:00
2011-06-29 20:40:23 +04:00
/ *
* Local v a r i a b l e s
* /
sdrc_power :
.word SDRC_POWER_V
cm_idlest1_core :
.word CM_IDLEST1_CORE_V
cm_idlest_ckgen :
.word CM_IDLEST_CKGEN_V
sdrc_dlla_status :
.word SDRC_DLLA_STATUS_V
sdrc_dlla_ctrl :
.word SDRC_DLLA_CTRL_V
/ *
* When e x p o r t i n g t o u s e r s p a c e w h i l e t h e c o u n t e r s a r e i n S R A M ,
* these 2 w o r d s n e e d t o b e a t t h e e n d t o f a c i l i t a t e r e t r i v a l !
* /
kick_counter :
.word 0
wait_dll_lock_counter :
.word 0
ENTRY( o m a p3 _ d o _ w f i _ s z )
.word . - omap3 _ d o _ w f i
2010-12-18 18:44:45 +03:00
/ *
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* = = Resume p a t h f o r O F F m o d e = =
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* /
/ *
* The r e s t o r e _ * f u n c t i o n s a r e c a l l e d b y t h e R O M c o d e
* when b a c k f r o m W F I i n O F F m o d e .
* Cf. t h e g e t _ * r e s t o r e _ p o i n t e r f u n c t i o n s .
*
* restore_es3 : applies t o 3 4 x x > = E S 3 . 0
* restore_3630 : applies t o 3 6 x x
* restore : common c o d e f o r 3 x x x
2011-06-29 20:40:23 +04:00
*
* Note : when b a c k f r o m C O R E a n d M P U O F F m o d e w e a r e r u n n i n g
* from S D R A M , w i t h o u t M M U , w i t h o u t t h e c a c h e s a n d p r e d i c t i o n .
* Also t h e S R A M c o n t e n t h a s b e e n c l e a r e d .
2010-12-18 18:44:45 +03:00
* /
2011-06-24 04:16:14 +04:00
ENTRY( o m a p3 _ r e s t o r e _ e s3 )
2008-10-13 18:58:50 +04:00
ldr r5 , p m _ p r e p w s t s t _ c o r e _ p
ldr r4 , [ r5 ]
and r4 , r4 , #0x3
cmp r4 , #0x0 @ Check if previous power state of CORE is OFF
2011-06-29 20:40:23 +04:00
bne o m a p3 _ r e s t o r e @ Fall through to OMAP3 common code
2008-10-13 18:58:50 +04:00
adr r0 , e s3 _ s d r c _ f i x
ldr r1 , s r a m _ b a s e
ldr r2 , e s3 _ s d r c _ f i x _ s z
mov r2 , r2 , r o r #2
copy_to_sram :
ldmia r0 ! , { r3 } @ val = *src
stmia r1 ! , { r3 } @ *dst = val
subs r2 , r2 , #0x1 @ num_words--
bne c o p y _ t o _ s r a m
ldr r1 , s r a m _ b a s e
blx r1
2011-06-29 20:40:23 +04:00
b o m a p3 _ r e s t o r e @ Fall through to OMAP3 common code
2011-06-24 04:16:14 +04:00
ENDPROC( o m a p3 _ r e s t o r e _ e s3 )
2010-12-20 23:05:06 +03:00
2011-06-24 04:16:14 +04:00
ENTRY( o m a p3 _ r e s t o r e _ 3 6 3 0 )
2010-12-20 23:05:06 +03:00
ldr r1 , p m _ p r e p w s t s t _ c o r e _ p
ldr r2 , [ r1 ]
and r2 , r2 , #0x3
cmp r2 , #0x0 @ Check if previous power state of CORE is OFF
2011-06-29 20:40:23 +04:00
bne o m a p3 _ r e s t o r e @ Fall through to OMAP3 common code
2010-12-20 23:05:06 +03:00
/* Disable RTA before giving control */
ldr r1 , c o n t r o l _ m e m _ r t a
mov r2 , #O M A P 36 X X _ R T A _ D I S A B L E
str r2 , [ r1 ]
2011-06-24 04:16:14 +04:00
ENDPROC( o m a p3 _ r e s t o r e _ 3 6 3 0 )
2010-12-18 18:44:45 +03:00
/* Fall through to common code for the remaining logic */
2011-06-24 04:16:14 +04:00
ENTRY( o m a p3 _ r e s t o r e )
2010-12-18 18:49:57 +03:00
/ *
2011-06-22 15:54:41 +04:00
* Read t h e p w s t c t r l r e g i s t e r t o c h e c k t h e r e a s o n f o r m p u r e s e t .
* This t e l l s u s w h a t w a s l o s t .
2010-12-18 18:44:45 +03:00
* /
2010-12-18 18:49:57 +03:00
ldr r1 , p m _ p w s t c t r l _ m p u
2009-05-28 21:56:16 +04:00
ldr r2 , [ r1 ]
2010-12-18 18:49:57 +03:00
and r2 , r2 , #0x3
cmp r2 , #0x0 @ Check if target power state was OFF or RET
2009-05-28 21:56:16 +04:00
bne l o g i c _ l 1 _ r e s t o r e
2010-12-20 23:05:07 +03:00
ldr r0 , l 2 d i s _ 3 6 3 0
cmp r0 , #0x1 @ should we disable L2 on 3630?
bne s k i p l 2 d i s
mrc p15 , 0 , r0 , c1 , c0 , 1
bic r0 , r0 , #2 @ disable L2 cache
mcr p15 , 0 , r0 , c1 , c0 , 1
skipl2dis :
2008-10-13 14:15:00 +04:00
ldr r0 , c o n t r o l _ s t a t
ldr r1 , [ r0 ]
and r1 , #0x700
cmp r1 , #0x300
beq l 2 _ i n v _ g p
2010-12-18 18:49:57 +03:00
mov r0 , #40 @ set service ID for PPA
mov r12 , r0 @ copy secure Service ID in r12
mov r1 , #0 @ set task id for ROM code in r1
mov r2 , #4 @ set some flags in r2, r6
2008-10-13 14:15:00 +04:00
mov r6 , #0xff
adr r3 , l 2 _ i n v _ a p i _ p a r a m s @ r3 points to dummy parameters
2011-01-23 16:30:34 +03:00
dsb @ data write barrier
dmb @ data memory barrier
2011-03-04 18:33:55 +03:00
smc #1 @ call SMI monitor (smi #1)
2008-10-13 14:15:00 +04:00
/* Write to Aux control register to set some bits */
2010-12-18 18:49:57 +03:00
mov r0 , #42 @ set service ID for PPA
mov r12 , r0 @ copy secure Service ID in r12
mov r1 , #0 @ set task id for ROM code in r1
mov r2 , #4 @ set some flags in r2, r6
2008-10-13 14:15:00 +04:00
mov r6 , #0xff
2009-11-12 13:07:20 +03:00
ldr r4 , s c r a t c h p a d _ b a s e
2010-12-18 18:49:57 +03:00
ldr r3 , [ r4 , #0xBC ] @ r3 points to parameters
2011-01-23 16:30:34 +03:00
dsb @ data write barrier
dmb @ data memory barrier
2011-03-04 18:33:55 +03:00
smc #1 @ call SMI monitor (smi #1)
2008-10-13 14:15:00 +04:00
2009-11-12 13:07:22 +03:00
# ifdef C O N F I G _ O M A P 3 _ L 2 _ A U X _ S E C U R E _ S A V E _ R E S T O R E
/* Restore L2 aux control register */
2010-12-18 18:49:57 +03:00
@ set service ID for PPA
2009-11-12 13:07:22 +03:00
mov r0 , #C O N F I G _ O M A P 3 _ L 2 _ A U X _ S E C U R E _ S E R V I C E _ S E T _ I D
2010-12-18 18:49:57 +03:00
mov r12 , r0 @ copy service ID in r12
mov r1 , #0 @ set task ID for ROM code in r1
mov r2 , #4 @ set some flags in r2, r6
2009-11-12 13:07:22 +03:00
mov r6 , #0xff
ldr r4 , s c r a t c h p a d _ b a s e
ldr r3 , [ r4 , #0xBC ]
2010-12-18 18:49:57 +03:00
adds r3 , r3 , #8 @ r3 points to parameters
2011-01-23 16:30:34 +03:00
dsb @ data write barrier
dmb @ data memory barrier
2011-03-04 18:33:55 +03:00
smc #1 @ call SMI monitor (smi #1)
2009-11-12 13:07:22 +03:00
# endif
2008-10-13 14:15:00 +04:00
b l o g i c _ l 1 _ r e s t o r e
2010-12-18 18:49:57 +03:00
2011-03-04 18:33:57 +03:00
.align
2008-10-13 14:15:00 +04:00
l2_inv_api_params :
2010-12-18 18:49:57 +03:00
.word 0 x1 , 0 x00
2008-10-13 14:15:00 +04:00
l2_inv_gp :
2009-05-28 21:56:16 +04:00
/* Execute smi to invalidate L2 cache */
2010-12-18 18:49:57 +03:00
mov r12 , #0x1 @ set up to invalidate L2
2011-03-04 18:33:55 +03:00
smc #0 @ Call SMI monitor (smieq)
2008-10-13 14:15:00 +04:00
/* Write to Aux control register to set some bits */
2009-11-12 13:07:20 +03:00
ldr r4 , s c r a t c h p a d _ b a s e
ldr r3 , [ r4 ,#0xBC ]
ldr r0 , [ r3 ,#4 ]
2008-10-13 14:15:00 +04:00
mov r12 , #0x3
2011-03-04 18:33:55 +03:00
smc #0 @ Call SMI monitor (smieq)
2009-11-12 13:07:22 +03:00
ldr r4 , s c r a t c h p a d _ b a s e
ldr r3 , [ r4 ,#0xBC ]
ldr r0 , [ r3 ,#12 ]
mov r12 , #0x2
2011-03-04 18:33:55 +03:00
smc #0 @ Call SMI monitor (smieq)
2009-05-28 21:56:16 +04:00
logic_l1_restore :
2010-12-20 23:05:07 +03:00
ldr r1 , l 2 d i s _ 3 6 3 0
2010-12-18 18:49:57 +03:00
cmp r1 , #0x1 @ Test if L2 re-enable needed on 3630
2010-12-20 23:05:07 +03:00
bne s k i p l 2 r e e n
mrc p15 , 0 , r1 , c1 , c0 , 1
2010-12-18 18:49:57 +03:00
orr r1 , r1 , #2 @ re-enable L2 cache
2010-12-20 23:05:07 +03:00
mcr p15 , 0 , r1 , c1 , c0 , 1
skipl2reen :
2009-05-28 21:56:16 +04:00
2011-06-22 18:42:54 +04:00
/* Now branch to the common CPU resume function */
b c p u _ r e s u m e
2011-06-24 04:16:14 +04:00
ENDPROC( o m a p3 _ r e s t o r e )
2009-05-28 21:56:16 +04:00
2011-06-22 18:42:54 +04:00
.ltorg
2010-12-18 18:44:44 +03:00
2011-06-29 20:40:23 +04:00
/ *
* Local v a r i a b l e s
* /
pm_prepwstst_core_p :
.word PM_PREPWSTST_CORE_P
pm_pwstctrl_mpu :
.word PM_PWSTCTRL_MPU_P
scratchpad_base :
.word SCRATCHPAD_BASE_P
sram_base :
.word SRAM_BASE_P + 0 x8 0 0 0
control_stat :
.word CONTROL_STAT
control_mem_rta :
.word CONTROL_MEM_RTA_CTRL
l2dis_3630 :
.word 0
2010-12-18 18:44:44 +03:00
/ *
* Internal f u n c t i o n s
* /
2011-06-29 20:40:23 +04:00
/ *
* This f u n c t i o n i m p l e m e n t s t h e e r r a t u m I D i 4 4 3 W A , a p p l i e s t o 3 4 x x > = E S 3 . 0
* Copied t o a n d r u n f r o m S R A M i n o r d e r t o r e c o n f i g u r e t h e S D R C p a r a m e t e r s .
* /
2010-12-18 18:44:44 +03:00
.text
2011-03-04 18:33:57 +03:00
.align 3
2010-12-18 18:44:44 +03:00
ENTRY( e s3 _ s d r c _ f i x )
ldr r4 , s d r c _ s y s c f g @ get config addr
ldr r5 , [ r4 ] @ get value
tst r5 , #0x100 @ is part access blocked
it e q
biceq r5 , r5 , #0x100 @ clear bit if set
str r5 , [ r4 ] @ write back change
ldr r4 , s d r c _ m r _ 0 @ get config addr
ldr r5 , [ r4 ] @ get value
str r5 , [ r4 ] @ write back change
ldr r4 , s d r c _ e m r2 _ 0 @ get config addr
ldr r5 , [ r4 ] @ get value
str r5 , [ r4 ] @ write back change
ldr r4 , s d r c _ m a n u a l _ 0 @ get config addr
mov r5 , #0x2 @ autorefresh command
str r5 , [ r4 ] @ kick off refreshes
ldr r4 , s d r c _ m r _ 1 @ get config addr
ldr r5 , [ r4 ] @ get value
str r5 , [ r4 ] @ write back change
ldr r4 , s d r c _ e m r2 _ 1 @ get config addr
ldr r5 , [ r4 ] @ get value
str r5 , [ r4 ] @ write back change
ldr r4 , s d r c _ m a n u a l _ 1 @ get config addr
mov r5 , #0x2 @ autorefresh command
str r5 , [ r4 ] @ kick off refreshes
bx l r
2011-06-29 20:40:23 +04:00
/ *
* Local v a r i a b l e s
* /
2011-03-04 18:33:57 +03:00
.align
2010-12-18 18:44:44 +03:00
sdrc_syscfg :
.word SDRC_SYSCONFIG_P
sdrc_mr_0 :
.word SDRC_MR_0_P
sdrc_emr2_0 :
.word SDRC_EMR2_0_P
sdrc_manual_0 :
.word SDRC_MANUAL_0_P
sdrc_mr_1 :
.word SDRC_MR_1_P
sdrc_emr2_1 :
.word SDRC_EMR2_1_P
sdrc_manual_1 :
.word SDRC_MANUAL_1_P
2011-03-04 18:33:57 +03:00
ENDPROC( e s3 _ s d r c _ f i x )
2010-12-18 18:44:44 +03:00
ENTRY( e s3 _ s d r c _ f i x _ s z )
.word . - es3 _ s d r c _ f i x