2005-04-16 15:20:36 -07:00
/ * cmode. S : c l o c k m o d e m a n a g e m e n t
*
* Copyright ( C ) 2 0 0 4 R e d H a t , I n c . A l l R i g h t s R e s e r v e d .
2008-06-05 22:46:18 -07:00
* Written b y D a v i d W o o d h o u s e ( d w m w2 @infradead.org)
2005-04-16 15:20:36 -07:00
*
* 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
* as p u b l i s h e d 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 t h e 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 .
*
* /
# include < l i n u x / s y s . h >
# include < l i n u x / l i n k a g e . h >
# include < a s m / s e t u p . h >
# include < a s m / s e g m e n t . h >
# include < a s m / p t r a c e . h >
# include < a s m / e r r n o . h >
# include < a s m / c a c h e . h >
# include < a s m / s p r - r e g s . h >
# define _ _ a d d r _ M A S K 0 x f e f f98 2 0 / * i n t e r r u p t c o n t r o l l e r m a s k * /
# define _ _ a d d r _ S D R A M C 0 x f e 0 0 0 4 0 0 / * S D R A M c o n t r o l l e r r e g s * /
# define S D R A M C _ D S T S 0 x28 / * S D R A M s t a t u s * /
# define S D R A M C _ D S T S _ S S I 0 x00 0 0 0 0 0 1 / * i n d i c a t e s t h a t t h e S D R A M i s i n s e l f - r e f r e s h m o d e * /
# define S D R A M C _ D R C N 0 x30 / * S D R A M r e f r e s h c o n t r o l * /
# define S D R A M C _ D R C N _ S R 0 x00 0 0 0 0 0 1 / * t r a n s i t i o n S D R A M i n t o s e l f - r e f r e s h m o d e * /
# define _ _ a d d r _ C L K C 0 x f e f f9 a00
# define C L K C _ S W C M O D E 0 x00 0 0 0 0 0 8
# define _ _ a d d r _ L E D S 0 x e 1 2 0 0 0 0 4
.macro li v r
sethi. p % h i ( \ v ) ,\ r
setlo % l o ( \ v ) ,\ r
.endm
.text
.balign 4
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Change C M O D E
# - void f r v _ c h a n g e _ c m o d e ( i n t c m o d e )
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
.globl frv_change_cmode
.type frv_ c h a n g e _ c m o d e ,@function
.macro LEDS v
# ifdef D E B U G _ C M O D E
setlos #~ \ v , g r 10
sti g r10 ,@(gr11,#0)
membar
# endif
.endm
frv_change_cmode :
movsg l r ,g r9
# ifdef D E B U G _ C M O D E
li _ _ a d d r _ L E D S ,g r11
# endif
dcef @(gr0,gr0),#1
# Shift a r g u m e n t l e f t b y 2 4 b i t s t o f i t i n S W C M O D E r e g i s t e r l a t e r .
slli g r8 ,#24 ,g r8
# ( 1 ) Set ' 0 ' i n t h e P S R . E T b i t , a n d p r o h i b i t i n t e r r u p t s .
movsg p s r ,g r14
andi g r14 ,#~ P S R _ E T , g r 3
movgs g r3 ,p s r
# if 0 / / F u j i t s u r e c o m m e n d t o s k i p t h i s a n d w i l l u p d a t e d o c s .
# ( 2 ) Set ' 0 ' t o a l l b i t s o f t h e M A S K r e g i s t e r o f t h e i n t e r r u p t
# controller, a n d m a s k i n t e r r u p t s .
li _ _ a d d r _ M A S K ,g r12
ldi @(gr12,#0),gr13
li 0 x f f f f00 0 0 ,g r4
sti g r4 ,@(gr12,#0)
# endif
# ( 3 ) Stop t h e t r a n s f e r f u n c t i o n o f D M A C . S t o p a l l t h e b u s m a s t e r s
# to a c c e s s S D R A M a n d t h e i n t e r n a l r e s o u r c e s .
# ( already d o n e b y c a l l e r )
# ( 4 ) Preload a s e r i e s o f f o l l o w i n g i n s t r u c t i o n s t o t h e i n s t r u c t i o n
# cache.
li #_ _ c m o d e _ i c a c h e _ l o c k _ s t a r t , g r 3
li #_ _ c m o d e _ i c a c h e _ l o c k _ e n d , g r 4
1 : icpl g r3 ,g r0 ,#1
addi g r3 ,#L 1 _ C A C H E _ B Y T E S ,g r3
cmp g r4 ,g r3 ,i c c0
bhi i c c0 ,#0 ,1 b
# Set u p a d d r e s s e s i n r e g s f o r l a t e r s t e p s .
setlos S D R A M C _ D R C N _ S R ,g r3
li _ _ a d d r _ S D R A M C ,g r4
li _ _ a d d r _ C L K C ,g r5
ldi @(gr5,#0),gr6
li #0x80000000 ,g r7
or g r6 ,g r7 ,g r6
bra _ _ c m o d e _ i c a c h e _ l o c k _ s t a r t
.balign L1_CACHE_BYTES
__cmode_icache_lock_start :
# ( 5 ) Flush t h e c o n t e n t o f a l l c a c h e s b y t h e D C E F i n s t r u c t i o n .
dcef @(gr0,gr0),#1
# ( 6 ) Execute l o a d i n g t h e d u m m y f o r S D R A M .
ldi @(gr9,#0),gr0
# ( 7 ) Set ' 1 ' t o t h e D R C N . S R b i t , a n d c h a n g e S D R A M t o t h e
# self- r e f r e s h m o d e . E x e c u t e t h e d u m m y l o a d t o a l l m e m o r y
# devices s e t t o c a c h e a b l e o n t h e e x t e r n a l b u s s i d e i n p a r a l l e l
# with t h i s .
sti g r3 ,@(gr4,#SDRAMC_DRCN)
# ( 8 ) Execute m e m o r y b a r r i e r i n s t r u c t i o n ( M E M B A R ) .
membar
# ( 9 ) Read t h e D S T S r e g i s t e r r e p e a t e d l y u n t i l ' 1 ' s t a n d s i n t h e
# DSTS. S S I f i e l d .
1 : ldi @(gr4,#SDRAMC_DSTS),gr3
andicc g r3 ,#S D R A M C _ D S T S _ S S I , g r 3 ,i c c0
beq i c c0 ,#0 ,1 b
# ( 1 0 ) Execute m e m o r y b a r r i e r i n s t r u c t i o n ( M E M B A R ) .
membar
# if 1
# ( 1 1 ) Set t h e v a l u e o f C M O D E t h a t y o u w a n t t o c h a n g e t o
# SWCMODE. S W C M [ 3 : 0 ] .
sti g r8 ,@(gr5,#CLKC_SWCMODE)
# ( 1 2 ) Set ' 1 ' t o t h e C L K C . S W E N b i t . I n t h a t c a s e , d o n o t c h a n g e
# fields o t h e r t h a n S W E N o f t h e C L K C r e g i s t e r .
sti g r6 ,@(gr5,#0)
# endif
# ( 1 3 ) Execute t h e i n s t r u c t i o n j u s t a f t e r t h e m e m o r y b a r r i e r
# instruction t h a t e x e c u t e s t h e s e l f - l o o p 2 5 6 t i m e s . ( M e a n w h i l e ,
# the C M O D E s w i t c h i s d o n e . )
membar
setlos #256 ,g r7
2 : subicc g r7 ,#1 ,g r7 ,i c c0
bne i c c0 ,#2 ,2 b
LEDS 0 x36
# ( 1 4 ) Release t h e s e l f - r e f r e s h o f S D R A M .
sti g r0 ,@(gr4,#SDRAMC_DRCN)
# Wait f o r i t . . .
3 : ldi @(gr4,#SDRAMC_DSTS),gr3
andicc g r3 ,#S D R A M C _ D S T S _ S S I , g r 3 ,i c c0
bne i c c0 ,#2 ,3 b
# if 0
li 0 x01 0 0 0 0 0 ,g r10
4 : subicc g r10 ,#1 ,g r10 ,i c c0
bne i c c0 ,#0 ,4 b
# endif
__cmode_icache_lock_end :
li #_ _ c m o d e _ i c a c h e _ l o c k _ s t a r t , g r 3
li #_ _ c m o d e _ i c a c h e _ l o c k _ e n d , g r 4
4 : icul g r3
addi g r3 ,#L 1 _ C A C H E _ B Y T E S ,g r3
cmp g r4 ,g r3 ,i c c0
bhi i c c0 ,#0 ,4 b
# if 0 / / F u j i t s u r e c o m m e n d t o s k i p t h i s a n d w i l l u p d a t e d o c s .
# ( 1 5 ) Release t h e i n t e r r u p t m a s k s e t t i n g o f t h e M A S K r e g i s t e r o f
# the i n t e r r u p t c o n t r o l l e r i f n e c e s s a r y .
sti g r13 ,@(gr12,#0)
# endif
# ( 1 6 ) Set 1 ' i n t h e P S R . E T b i t , a n d p e r m i t i n t e r r u p t .
movgs g r14 ,p s r
bralr
.size frv_ c h a n g e _ c m o d e , . - f r v _ c h a n g e _ c m o d e