2019-05-28 10:10:04 -07:00
/* SPDX-License-Identifier: GPL-2.0-only */
2015-06-05 08:24:52 -05:00
/ *
* Copyright ( C ) 2 0 1 4 - 2 0 1 5 A l t e r a C o r p o r a t i o n . A l l r i g h t s r e s e r v e d .
* /
# 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 >
# define M A X _ L O O P _ C O U N T 1 0 0 0
/* Register offset */
# define S D R _ C T R L G R P _ L O W P W R E Q _ A D D R 0 x54
# define S D R _ C T R L G R P _ L O W P W R A C K _ A D D R 0 x58
/* Bitfield positions */
# define S E L F R S H R E Q _ P O S 3
# define S E L F R S H R E Q _ M A S K 0 x8
# define S E L F R F S H A C K _ P O S 1
# define S E L F R F S H A C K _ M A S K 0 x2
/ *
* This c o d e a s s u m e s t h a t w h e n t h e b o o t l o a d e r c o n f i g u r e d
* the s d r a m c o n t r o l l e r f o r t h e D D R o n t h e b o a r d i t
* configured t h e f o l l o w i n g f i e l d s d e p e n d i n g o n t h e D D R
* vendor/ c o n f i g u r a t i o n :
*
* sdr. c t r l c f g . l o w p w r e q . s e l f r f s h m a s k
* sdr. c t r l c f g . l o w p w r t i m i n g . c l k d i s a b l e c y c l e s
* sdr. c t r l c f g . d r a m t i m i n g 4 . s e l f r f s h e x i t
* /
.arch armv7 - a
.text
.align 3
/ *
* socfpga_ s d r a m _ s e l f _ r e f r e s h
*
* r0 : s d r _ c t l _ b a s e _ a d d r
* r1 : t e m p s t o r a g e o f r e t u r n v a l u e
* r2 : t e m p s t o r a g e o f r e g i s t e r v a l u e s
* r3 : l o o p c o u n t e r
*
* return v a l u e : l o w e r 1 6 b i t s : l o o p c o u n t g o i n g i n t o s e l f r e f r e s h
* upper 1 6 b i t s : l o o p c o u n t e x i t i n g s e l f r e f r e s h
* /
ENTRY( s o c f p g a _ s d r a m _ s e l f _ r e f r e s h )
/* Enable dynamic clock gating in the Power Control Register. */
mrc p15 , 0 , r2 , c15 , c0 , 0
orr r2 , r2 , #1
mcr p15 , 0 , r2 , c15 , c0 , 0
/* Enable self refresh: set sdr.ctrlgrp.lowpwreq.selfrshreq = 1 */
ldr r2 , [ r0 , #S D R _ C T R L G R P _ L O W P W R E Q _ A D D R ]
orr r2 , r2 , #S E L F R S H R E Q _ M A S K
str r2 , [ r0 , #S D R _ C T R L G R P _ L O W P W R E Q _ A D D R ]
/* Poll until sdr.ctrlgrp.lowpwrack.selfrfshack == 1 or hit max loops */
mov r3 , #0
while_ack_0 :
ldr r2 , [ r0 , #S D R _ C T R L G R P _ L O W P W R A C K _ A D D R ]
and r2 , r2 , #S E L F R F S H A C K _ M A S K
cmp r2 , #S E L F R F S H A C K _ M A S K
beq a c k _ 1
add r3 , #1
cmp r3 , #M A X _ L O O P _ C O U N T
bne w h i l e _ a c k _ 0
ack_1 :
mov r1 , r3
/ *
* Execute a n I S B i n s t r u c t i o n t o e n s u r e t h a t a l l o f t h e
* CP1 5 r e g i s t e r c h a n g e s h a v e b e e n c o m m i t t e d .
* /
isb
/ *
* Execute a b a r r i e r i n s t r u c t i o n t o e n s u r e t h a t a l l c a c h e ,
* TLB a n d b r a n c h p r e d i c t o r m a i n t e n a n c e o p e r a t i o n s i s s u e d
* by a n y C P U i n t h e c l u s t e r h a v e c o m p l e t e d .
* /
dsb
dmb
wfi
/* Disable self-refresh: set sdr.ctrlgrp.lowpwreq.selfrshreq = 0 */
ldr r2 , [ r0 , #S D R _ C T R L G R P _ L O W P W R E Q _ A D D R ]
bic r2 , r2 , #S E L F R S H R E Q _ M A S K
str r2 , [ r0 , #S D R _ C T R L G R P _ L O W P W R E Q _ A D D R ]
/* Poll until sdr.ctrlgrp.lowpwrack.selfrfshack == 0 or hit max loops */
mov r3 , #0
while_ack_1 :
ldr r2 , [ r0 , #S D R _ C T R L G R P _ L O W P W R A C K _ A D D R ]
and r2 , r2 , #S E L F R F S H A C K _ M A S K
cmp r2 , #S E L F R F S H A C K _ M A S K
bne a c k _ 0
add r3 , #1
cmp r3 , #M A X _ L O O P _ C O U N T
bne w h i l e _ a c k _ 1
ack_0 :
/ *
* Prepare r e t u r n v a l u e :
* Shift l o o p c o u n t f o r e x i t i n g s e l f r e f r e s h i n t o u p p e r 1 6 b i t s .
* Leave l o o p c o u n t f o r r e q u e s t i n g s e l f r e f r e s h i n l o w e r 1 6 b i t s .
* /
mov r3 , r3 , l s l #16
add r1 , r1 , r3
/* Disable dynamic clock gating in the Power Control Register. */
mrc p15 , 0 , r2 , c15 , c0 , 0
bic r2 , r2 , #1
mcr p15 , 0 , r2 , c15 , c0 , 0
mov r0 , r1 @ return value
bx l r @ return
ENDPROC( s o c f p g a _ s d r a m _ s e l f _ r e f r e s h )
ENTRY( s o c f p g a _ s d r a m _ s e l f _ r e f r e s h _ s z )
.word . - socfpga_ s d r a m _ s e l f _ r e f r e s h