2022-06-07 17:11:13 +03:00
/* SPDX-License-Identifier: GPL-2.0-only */
memory: ti-emif-sram: introduce relocatable suspend/resume handlers
Certain SoCs like Texas Instruments AM335x and AM437x require parts
of the EMIF PM code to run late in the suspend sequence from SRAM,
such as saving and restoring the EMIF context and placing the memory
into self-refresh.
One requirement for these SoCs to suspend and enter its lowest power
mode, called DeepSleep0, is that the PER power domain must be shut off.
Because the EMIF (DDR Controller) resides within this power domain, it
will lose context during a suspend operation, so we must save it so we
can restore once we resume. However, we cannot execute this code from
external memory, as it is not available at this point, so the code must
be executed late in the suspend path from SRAM.
This patch introduces a ti-emif-sram driver that includes several
functions written in ARM ASM that are relocatable so the PM SRAM
code can use them. It also allocates a region of writable SRAM to
be used by the code running in the executable region of SRAM to save
and restore the EMIF context. It can export a table containing the
absolute addresses of the available PM functions so that other SRAM
code can branch to them. This code is required for suspend/resume on
AM335x and AM437x to work.
In addition to this, to be able to share data structures between C and
the ti-emif-sram-pm assembly code, we can automatically generate all of
the C struct member offsets and sizes as macros by processing
emif-asm-offsets.c into assembly code and then extracting the relevant
data as is done for the generated platform asm-offsets.h files.
Acked-by: Tony Lindgren <tony@atomide.com>
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
2015-06-17 22:52:10 +03:00
/ *
* Low l e v e l P M c o d e f o r T I E M I F
*
* Copyright ( C ) 2 0 1 6 - 2 0 1 7 T e x a s I n s t r u m e n t s I n c o r p o r a t e d - h t t p : / / w w w . t i . c o m /
* Dave G e r l a c h
* /
# 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 >
ARM: mm: Make virt_to_pfn() a static inline
Making virt_to_pfn() a static inline taking a strongly typed
(const void *) makes the contract of a passing a pointer of that
type to the function explicit and exposes any misuse of the
macro virt_to_pfn() acting polymorphic and accepting many types
such as (void *), (unitptr_t) or (unsigned long) as arguments
without warnings.
Doing this is a bit intrusive: virt_to_pfn() requires
PHYS_PFN_OFFSET and PAGE_SHIFT to be defined, and this is defined in
<asm/page.h>, so this must be included *before* <asm/memory.h>.
The use of macros were obscuring the unclear inclusion order here,
as the macros would eventually be resolved, but a static inline
like this cannot be compiled with unresolved macros.
The naive solution to include <asm/page.h> at the top of
<asm/memory.h> does not work, because <asm/memory.h> sometimes
includes <asm/page.h> at the end of itself, which would create a
confusing inclusion loop. So instead, take the approach to always
unconditionally include <asm/page.h> at the end of <asm/memory.h>
arch/arm uses <asm/memory.h> explicitly in a lot of places,
however it turns out that if we just unconditionally include
<asm/memory.h> into <asm/page.h> and switch all inclusions of
<asm/memory.h> to <asm/page.h> instead, we enforce the right
order and <asm/memory.h> will always have access to the
definitions.
Put an inclusion guard in place making it impossible to include
<asm/memory.h> explicitly.
Link: https://lore.kernel.org/linux-mm/20220701160004.2ffff4e5ab59a55499f4c736@linux-foundation.org/
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2022-06-02 11:18:32 +03:00
# include < a s m / p a g e . h >
memory: ti-emif-sram: introduce relocatable suspend/resume handlers
Certain SoCs like Texas Instruments AM335x and AM437x require parts
of the EMIF PM code to run late in the suspend sequence from SRAM,
such as saving and restoring the EMIF context and placing the memory
into self-refresh.
One requirement for these SoCs to suspend and enter its lowest power
mode, called DeepSleep0, is that the PER power domain must be shut off.
Because the EMIF (DDR Controller) resides within this power domain, it
will lose context during a suspend operation, so we must save it so we
can restore once we resume. However, we cannot execute this code from
external memory, as it is not available at this point, so the code must
be executed late in the suspend path from SRAM.
This patch introduces a ti-emif-sram driver that includes several
functions written in ARM ASM that are relocatable so the PM SRAM
code can use them. It also allocates a region of writable SRAM to
be used by the code running in the executable region of SRAM to save
and restore the EMIF context. It can export a table containing the
absolute addresses of the available PM functions so that other SRAM
code can branch to them. This code is required for suspend/resume on
AM335x and AM437x to work.
In addition to this, to be able to share data structures between C and
the ti-emif-sram-pm assembly code, we can automatically generate all of
the C struct member offsets and sizes as macros by processing
emif-asm-offsets.c into assembly code and then extracting the relevant
data as is done for the generated platform asm-offsets.h files.
Acked-by: Tony Lindgren <tony@atomide.com>
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
2015-06-17 22:52:10 +03:00
# include " e m i f . h "
2019-04-12 06:09:41 +03:00
# include " t i - e m i f - a s m - o f f s e t s . h "
memory: ti-emif-sram: introduce relocatable suspend/resume handlers
Certain SoCs like Texas Instruments AM335x and AM437x require parts
of the EMIF PM code to run late in the suspend sequence from SRAM,
such as saving and restoring the EMIF context and placing the memory
into self-refresh.
One requirement for these SoCs to suspend and enter its lowest power
mode, called DeepSleep0, is that the PER power domain must be shut off.
Because the EMIF (DDR Controller) resides within this power domain, it
will lose context during a suspend operation, so we must save it so we
can restore once we resume. However, we cannot execute this code from
external memory, as it is not available at this point, so the code must
be executed late in the suspend path from SRAM.
This patch introduces a ti-emif-sram driver that includes several
functions written in ARM ASM that are relocatable so the PM SRAM
code can use them. It also allocates a region of writable SRAM to
be used by the code running in the executable region of SRAM to save
and restore the EMIF context. It can export a table containing the
absolute addresses of the available PM functions so that other SRAM
code can branch to them. This code is required for suspend/resume on
AM335x and AM437x to work.
In addition to this, to be able to share data structures between C and
the ti-emif-sram-pm assembly code, we can automatically generate all of
the C struct member offsets and sizes as macros by processing
emif-asm-offsets.c into assembly code and then extracting the relevant
data as is done for the generated platform asm-offsets.h files.
Acked-by: Tony Lindgren <tony@atomide.com>
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
2015-06-17 22:52:10 +03:00
# define E M I F _ P O W E R _ M G M T _ W A I T _ S E L F _ R E F R E S H _ 8 1 9 2 _ C Y C L E S 0 x00 a0
# define E M I F _ P O W E R _ M G M T _ S R _ T I M E R _ M A S K 0 x00 f0
# define E M I F _ P O W E R _ M G M T _ S E L F _ R E F R E S H _ M O D E 0 x02 0 0
# define E M I F _ P O W E R _ M G M T _ S E L F _ R E F R E S H _ M O D E _ M A S K 0 x07 0 0
# define E M I F _ S D C F G _ T Y P E _ D D R 2 0 x2 < < S D R A M _ T Y P E _ S H I F T
2019-04-02 19:57:42 +03:00
# define E M I F _ S D C F G _ T Y P E _ D D R 3 0 x3 < < S D R A M _ T Y P E _ S H I F T
memory: ti-emif-sram: introduce relocatable suspend/resume handlers
Certain SoCs like Texas Instruments AM335x and AM437x require parts
of the EMIF PM code to run late in the suspend sequence from SRAM,
such as saving and restoring the EMIF context and placing the memory
into self-refresh.
One requirement for these SoCs to suspend and enter its lowest power
mode, called DeepSleep0, is that the PER power domain must be shut off.
Because the EMIF (DDR Controller) resides within this power domain, it
will lose context during a suspend operation, so we must save it so we
can restore once we resume. However, we cannot execute this code from
external memory, as it is not available at this point, so the code must
be executed late in the suspend path from SRAM.
This patch introduces a ti-emif-sram driver that includes several
functions written in ARM ASM that are relocatable so the PM SRAM
code can use them. It also allocates a region of writable SRAM to
be used by the code running in the executable region of SRAM to save
and restore the EMIF context. It can export a table containing the
absolute addresses of the available PM functions so that other SRAM
code can branch to them. This code is required for suspend/resume on
AM335x and AM437x to work.
In addition to this, to be able to share data structures between C and
the ti-emif-sram-pm assembly code, we can automatically generate all of
the C struct member offsets and sizes as macros by processing
emif-asm-offsets.c into assembly code and then extracting the relevant
data as is done for the generated platform asm-offsets.h files.
Acked-by: Tony Lindgren <tony@atomide.com>
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
2015-06-17 22:52:10 +03:00
# define E M I F _ S T A T U S _ R E A D Y 0 x4
# define A M 4 3 X X _ E M I F _ P H Y _ C T R L _ R E G _ C O U N T 0 x12 0
# define E M I F _ A M 4 3 7 X _ R E G I S T E R S 0 x1
.arm
.align 3
ARM: 9263/1: use .arch directives instead of assembler command line flags
Similar to commit a6c30873ee4a ("ARM: 8989/1: use .fpu assembler
directives instead of assembler arguments").
GCC and GNU binutils support setting the "sub arch" via -march=,
-Wa,-march, target function attribute, and .arch assembler directive.
Clang was missing support for -Wa,-march=, but this was implemented in
clang-13.
The behavior of both GCC and Clang is to
prefer -Wa,-march= over -march= for assembler and assembler-with-cpp
sources, but Clang will warn about the -march= being unused.
clang: warning: argument unused during compilation: '-march=armv6k'
[-Wunused-command-line-argument]
Since most assembler is non-conditionally assembled with one sub arch
(modulo arch/arm/delay-loop.S which conditionally is assembled as armv4
based on CONFIG_ARCH_RPC, and arch/arm/mach-at91/pm-suspend.S which is
conditionally assembled as armv7-a based on CONFIG_CPU_V7), prefer the
.arch assembler directive.
Add a few more instances found in compile testing as found by Arnd and
Nathan.
Link: https://github.com/llvm/llvm-project/commit/1d51c699b9e2ebc5bcfdbe85c74cc871426333d4
Link: https://bugs.llvm.org/show_bug.cgi?id=48894
Link: https://github.com/ClangBuiltLinux/linux/issues/1195
Link: https://github.com/ClangBuiltLinux/linux/issues/1315
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
2022-10-24 22:44:41 +03:00
.arch armv7 - a
memory: ti-emif-sram: introduce relocatable suspend/resume handlers
Certain SoCs like Texas Instruments AM335x and AM437x require parts
of the EMIF PM code to run late in the suspend sequence from SRAM,
such as saving and restoring the EMIF context and placing the memory
into self-refresh.
One requirement for these SoCs to suspend and enter its lowest power
mode, called DeepSleep0, is that the PER power domain must be shut off.
Because the EMIF (DDR Controller) resides within this power domain, it
will lose context during a suspend operation, so we must save it so we
can restore once we resume. However, we cannot execute this code from
external memory, as it is not available at this point, so the code must
be executed late in the suspend path from SRAM.
This patch introduces a ti-emif-sram driver that includes several
functions written in ARM ASM that are relocatable so the PM SRAM
code can use them. It also allocates a region of writable SRAM to
be used by the code running in the executable region of SRAM to save
and restore the EMIF context. It can export a table containing the
absolute addresses of the available PM functions so that other SRAM
code can branch to them. This code is required for suspend/resume on
AM335x and AM437x to work.
In addition to this, to be able to share data structures between C and
the ti-emif-sram-pm assembly code, we can automatically generate all of
the C struct member offsets and sizes as macros by processing
emif-asm-offsets.c into assembly code and then extracting the relevant
data as is done for the generated platform asm-offsets.h files.
Acked-by: Tony Lindgren <tony@atomide.com>
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
2015-06-17 22:52:10 +03:00
ENTRY( t i _ e m i f _ s r a m )
/ *
* void t i _ e m i f _ s a v e _ c o n t e x t ( v o i d )
*
* Used d u r i n g s u s p e n d t o s a v e t h e c o n t e x t o f a l l r e q u i r e d E M I F r e g i s t e r s
* to l o c a l m e m o r y i f t h e E M I F i s g o i n g t o l o s e c o n t e x t d u r i n g t h e s l e e p
* transition. O p e r a t e s o n t h e V I R T U A L a d d r e s s o f t h e E M I F .
* /
ENTRY( t i _ e m i f _ s a v e _ c o n t e x t )
stmfd s p ! , { r4 - r11 , l r } @ save registers on stack
adr r4 , t i _ e m i f _ p m _ s r a m _ d a t a
ldr r0 , [ r4 , #E M I F _ P M _ B A S E _ A D D R _ V I R T _ O F F S E T ]
ldr r2 , [ r4 , #E M I F _ P M _ R E G S _ V I R T _ O F F S E T ]
/* Save EMIF configuration */
ldr r1 , [ r0 , #E M I F _ S D R A M _ C O N F I G ]
str r1 , [ r2 , #E M I F _ S D C F G _ V A L _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ S D R A M _ R E F R E S H _ C O N T R O L ]
str r1 , [ r2 , #E M I F _ R E F _ C T R L _ V A L _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ S D R A M _ T I M I N G _ 1 ]
str r1 , [ r2 , #E M I F _ T I M I N G 1 _ V A L _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ S D R A M _ T I M I N G _ 2 ]
str r1 , [ r2 , #E M I F _ T I M I N G 2 _ V A L _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ S D R A M _ T I M I N G _ 3 ]
str r1 , [ r2 , #E M I F _ T I M I N G 3 _ V A L _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ P O W E R _ M A N A G E M E N T _ C O N T R O L ]
str r1 , [ r2 , #E M I F _ P M C R _ V A L _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ P O W E R _ M A N A G E M E N T _ C T R L _ S H D W ]
str r1 , [ r2 , #E M I F _ P M C R _ S H D W _ V A L _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ S D R A M _ O U T P U T _ I M P E D A N C E _ C A L I B R A T I O N _ C O N F I G ]
str r1 , [ r2 , #E M I F _ Z Q C F G _ V A L _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ D D R _ P H Y _ C T R L _ 1 ]
str r1 , [ r2 , #E M I F _ D D R _ P H Y _ C T L R _ 1 _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ C O S _ C O N F I G ]
str r1 , [ r2 , #E M I F _ C O S _ C O N F I G _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ P R I O R I T Y _ T O _ C L A S S _ O F _ S E R V I C E _ M A P P I N G ]
str r1 , [ r2 , #E M I F _ P R I O R I T Y _ T O _ C O S _ M A P P I N G _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ C O N N E C T I O N _ I D _ T O _ C L A S S _ O F _ S E R V I C E _ 1 _ M A P P I N G ]
str r1 , [ r2 , #E M I F _ C O N N E C T _ I D _ S E R V _ 1 _ M A P _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ C O N N E C T I O N _ I D _ T O _ C L A S S _ O F _ S E R V I C E _ 2 _ M A P P I N G ]
str r1 , [ r2 , #E M I F _ C O N N E C T _ I D _ S E R V _ 2 _ M A P _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ O C P _ C O N F I G ]
str r1 , [ r2 , #E M I F _ O C P _ C O N F I G _ V A L _ O F F S E T ]
ldr r5 , [ r4 , #E M I F _ P M _ C O N F I G _ O F F S E T ]
cmp r5 , #E M I F _ S R A M _ A M 43 _ R E G _ L A Y O U T
bne e m i f _ s k i p _ s a v e _ e x t r a _ r e g s
ldr r1 , [ r0 , #E M I F _ R E A D _ W R I T E _ L E V E L I N G _ R A M P _ C O N T R O L ]
str r1 , [ r2 , #E M I F _ R D _ W R _ L E V E L _ R A M P _ C T R L _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ R E A D _ W R I T E _ E X E C U T I O N _ T H R E S H O L D ]
str r1 , [ r2 , #E M I F _ R D _ W R _ E X E C _ T H R E S H _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ L P D D R 2 _ N V M _ T I M I N G ]
str r1 , [ r2 , #E M I F _ L P D D R 2 _ N V M _ T I M _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ L P D D R 2 _ N V M _ T I M I N G _ S H D W ]
str r1 , [ r2 , #E M I F _ L P D D R 2 _ N V M _ T I M _ S H D W _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ D L L _ C A L I B _ C T R L ]
str r1 , [ r2 , #E M I F _ D L L _ C A L I B _ C T R L _ V A L _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ D L L _ C A L I B _ C T R L _ S H D W ]
str r1 , [ r2 , #E M I F _ D L L _ C A L I B _ C T R L _ V A L _ S H D W _ O F F S E T ]
/* Loop and save entire block of emif phy regs */
mov r5 , #0x0
add r4 , r2 , #E M I F _ E X T _ P H Y _ C T R L _ V A L S _ O F F S E T
add r3 , r0 , #E M I F _ E X T _ P H Y _ C T R L _ 1
ddr_phy_ctrl_save :
ldr r1 , [ r3 , r5 ]
str r1 , [ r4 , r5 ]
add r5 , r5 , #0x4
cmp r5 , #A M 43 X X _ E M I F _ P H Y _ C T R L _ R E G _ C O U N T
bne d d r _ p h y _ c t r l _ s a v e
emif_skip_save_extra_regs :
ldmfd s p ! , { r4 - r11 , p c } @ restore regs and return
ENDPROC( t i _ e m i f _ s a v e _ c o n t e x t )
/ *
* void t i _ e m i f _ r e s t o r e _ c o n t e x t ( v o i d )
*
* Used d u r i n g r e s u m e t o r e s t o r e t h e c o n t e x t o f a l l r e q u i r e d E M I F r e g i s t e r s
* from l o c a l m e m o r y a f t e r t h e E M I F h a s l o s t c o n t e x t d u r i n g a s l e e p t r a n s i t i o n .
* Operates o n t h e P H Y S I C A L a d d r e s s o f t h e E M I F .
* /
ENTRY( t i _ e m i f _ r e s t o r e _ c o n t e x t )
adr r4 , t i _ e m i f _ p m _ s r a m _ d a t a
ldr r0 , [ r4 , #E M I F _ P M _ B A S E _ A D D R _ P H Y S _ O F F S E T ]
ldr r2 , [ r4 , #E M I F _ P M _ R E G S _ P H Y S _ O F F S E T ]
/* Config EMIF Timings */
ldr r1 , [ r2 , #E M I F _ D D R _ P H Y _ C T L R _ 1 _ O F F S E T ]
str r1 , [ r0 , #E M I F _ D D R _ P H Y _ C T R L _ 1 ]
str r1 , [ r0 , #E M I F _ D D R _ P H Y _ C T R L _ 1 _ S H D W ]
ldr r1 , [ r2 , #E M I F _ T I M I N G 1 _ V A L _ O F F S E T ]
str r1 , [ r0 , #E M I F _ S D R A M _ T I M I N G _ 1 ]
str r1 , [ r0 , #E M I F _ S D R A M _ T I M I N G _ 1 _ S H D W ]
ldr r1 , [ r2 , #E M I F _ T I M I N G 2 _ V A L _ O F F S E T ]
str r1 , [ r0 , #E M I F _ S D R A M _ T I M I N G _ 2 ]
str r1 , [ r0 , #E M I F _ S D R A M _ T I M I N G _ 2 _ S H D W ]
ldr r1 , [ r2 , #E M I F _ T I M I N G 3 _ V A L _ O F F S E T ]
str r1 , [ r0 , #E M I F _ S D R A M _ T I M I N G _ 3 ]
str r1 , [ r0 , #E M I F _ S D R A M _ T I M I N G _ 3 _ S H D W ]
ldr r1 , [ r2 , #E M I F _ R E F _ C T R L _ V A L _ O F F S E T ]
str r1 , [ r0 , #E M I F _ S D R A M _ R E F R E S H _ C O N T R O L ]
str r1 , [ r0 , #E M I F _ S D R A M _ R E F R E S H _ C T R L _ S H D W ]
ldr r1 , [ r2 , #E M I F _ P M C R _ V A L _ O F F S E T ]
str r1 , [ r0 , #E M I F _ P O W E R _ M A N A G E M E N T _ C O N T R O L ]
ldr r1 , [ r2 , #E M I F _ P M C R _ S H D W _ V A L _ O F F S E T ]
str r1 , [ r0 , #E M I F _ P O W E R _ M A N A G E M E N T _ C T R L _ S H D W ]
ldr r1 , [ r2 , #E M I F _ C O S _ C O N F I G _ O F F S E T ]
str r1 , [ r0 , #E M I F _ C O S _ C O N F I G ]
ldr r1 , [ r2 , #E M I F _ P R I O R I T Y _ T O _ C O S _ M A P P I N G _ O F F S E T ]
str r1 , [ r0 , #E M I F _ P R I O R I T Y _ T O _ C L A S S _ O F _ S E R V I C E _ M A P P I N G ]
ldr r1 , [ r2 , #E M I F _ C O N N E C T _ I D _ S E R V _ 1 _ M A P _ O F F S E T ]
str r1 , [ r0 , #E M I F _ C O N N E C T I O N _ I D _ T O _ C L A S S _ O F _ S E R V I C E _ 1 _ M A P P I N G ]
ldr r1 , [ r2 , #E M I F _ C O N N E C T _ I D _ S E R V _ 2 _ M A P _ O F F S E T ]
str r1 , [ r0 , #E M I F _ C O N N E C T I O N _ I D _ T O _ C L A S S _ O F _ S E R V I C E _ 2 _ M A P P I N G ]
ldr r1 , [ r2 , #E M I F _ O C P _ C O N F I G _ V A L _ O F F S E T ]
str r1 , [ r0 , #E M I F _ O C P _ C O N F I G ]
ldr r5 , [ r4 , #E M I F _ P M _ C O N F I G _ O F F S E T ]
cmp r5 , #E M I F _ S R A M _ A M 43 _ R E G _ L A Y O U T
bne e m i f _ s k i p _ r e s t o r e _ e x t r a _ r e g s
ldr r1 , [ r2 , #E M I F _ R D _ W R _ L E V E L _ R A M P _ C T R L _ O F F S E T ]
str r1 , [ r0 , #E M I F _ R E A D _ W R I T E _ L E V E L I N G _ R A M P _ C O N T R O L ]
ldr r1 , [ r2 , #E M I F _ R D _ W R _ E X E C _ T H R E S H _ O F F S E T ]
str r1 , [ r0 , #E M I F _ R E A D _ W R I T E _ E X E C U T I O N _ T H R E S H O L D ]
ldr r1 , [ r2 , #E M I F _ L P D D R 2 _ N V M _ T I M _ O F F S E T ]
str r1 , [ r0 , #E M I F _ L P D D R 2 _ N V M _ T I M I N G ]
ldr r1 , [ r2 , #E M I F _ L P D D R 2 _ N V M _ T I M _ S H D W _ O F F S E T ]
str r1 , [ r0 , #E M I F _ L P D D R 2 _ N V M _ T I M I N G _ S H D W ]
ldr r1 , [ r2 , #E M I F _ D L L _ C A L I B _ C T R L _ V A L _ O F F S E T ]
str r1 , [ r0 , #E M I F _ D L L _ C A L I B _ C T R L ]
ldr r1 , [ r2 , #E M I F _ D L L _ C A L I B _ C T R L _ V A L _ S H D W _ O F F S E T ]
str r1 , [ r0 , #E M I F _ D L L _ C A L I B _ C T R L _ S H D W ]
ldr r1 , [ r2 , #E M I F _ Z Q C F G _ V A L _ O F F S E T ]
str r1 , [ r0 , #E M I F _ S D R A M _ O U T P U T _ I M P E D A N C E _ C A L I B R A T I O N _ C O N F I G ]
/* Loop and restore entire block of emif phy regs */
mov r5 , #0x0
/ * Load t i _ e m i f _ r e g s _ a m x3 + E M I F _ E X T _ P H Y _ C T R L _ V A L S _ O F F S E T f o r a d d r e s s
* to p h y r e g i s t e r s a v e s p a c e
* /
add r3 , r2 , #E M I F _ E X T _ P H Y _ C T R L _ V A L S _ O F F S E T
add r4 , r0 , #E M I F _ E X T _ P H Y _ C T R L _ 1
ddr_phy_ctrl_restore :
ldr r1 , [ r3 , r5 ]
str r1 , [ r4 , r5 ]
add r5 , r5 , #0x4
cmp r5 , #A M 43 X X _ E M I F _ P H Y _ C T R L _ R E G _ C O U N T
bne d d r _ p h y _ c t r l _ r e s t o r e
emif_skip_restore_extra_regs :
/ *
* Output i m p e d e n c e c a l i b n e e d e d o n l y f o r D D R 3
* but s i n c e t h e i n i t i a l s t a t e o f t h i s w i l l b e
* disabled f o r D D R 2 n o h a r m i n r e s t o r i n g t h e
* old c o n f i g u r a t i o n
* /
ldr r1 , [ r2 , #E M I F _ Z Q C F G _ V A L _ O F F S E T ]
str r1 , [ r0 , #E M I F _ S D R A M _ O U T P U T _ I M P E D A N C E _ C A L I B R A T I O N _ C O N F I G ]
/* Write to sdcfg last for DDR2 only */
ldr r1 , [ r2 , #E M I F _ S D C F G _ V A L _ O F F S E T ]
and r2 , r1 , #S D R A M _ T Y P E _ M A S K
cmp r2 , #E M I F _ S D C F G _ T Y P E _ D D R 2
streq r1 , [ r0 , #E M I F _ S D R A M _ C O N F I G ]
mov p c , l r
ENDPROC( t i _ e m i f _ r e s t o r e _ c o n t e x t )
2019-04-02 19:57:42 +03:00
/ *
* void t i _ e m i f _ r u n _ h w _ l e v e l i n g ( v o i d )
*
* Used d u r i n g r e s u m e t o r u n h a r d w a r e l e v e l i n g a g a i n a n d r e s t o r e t h e
* configuration o f t h e E M I F P H Y , o n l y f o r D D R 3 .
* /
ENTRY( t i _ e m i f _ r u n _ h w _ l e v e l i n g )
adr r4 , t i _ e m i f _ p m _ s r a m _ d a t a
ldr r0 , [ r4 , #E M I F _ P M _ B A S E _ A D D R _ P H Y S _ O F F S E T ]
ldr r3 , [ r0 , #E M I F _ R E A D _ W R I T E _ L E V E L I N G _ C O N T R O L ]
orr r3 , r3 , #R D W R L V L F U L L _ S T A R T
ldr r2 , [ r0 , #E M I F _ S D R A M _ C O N F I G ]
and r2 , r2 , #S D R A M _ T Y P E _ M A S K
cmp r2 , #E M I F _ S D C F G _ T Y P E _ D D R 3
bne s k i p _ h w l v l
str r3 , [ r0 , #E M I F _ R E A D _ W R I T E _ L E V E L I N G _ C O N T R O L ]
/ *
* If E M I F r e g i s t e r s a r e t o u c h e d d u r i n g i n i t i a l s t a g e o f H W
* leveling s e q u e n c e t h e r e w i l l b e a n L 3 N O C t i m e o u t e r r o r i s s u e d
* as t h e E M I F w i l l n o t r e s p o n d , w h i c h i s n o t f a t a l , b u t i t i s
* avoidable. T h i s s m a l l w a i t l o o p i s e n o u g h t i m e f o r t h i s c o n d i t i o n
* to c l e a r , e v e n a t w o r s t c a s e o f C P U r u n n i n g a t m a x s p e e d o f 1 G h z .
* /
mov r2 , #0x2000
1 :
subs r2 , r2 , #0x1
bne 1 b
/* Bit clears when operation is complete */
2 : ldr r1 , [ r0 , #E M I F _ R E A D _ W R I T E _ L E V E L I N G _ C O N T R O L ]
tst r1 , #R D W R L V L F U L L _ S T A R T
bne 2 b
skip_hwlvl :
mov p c , l r
ENDPROC( t i _ e m i f _ r u n _ h w _ l e v e l i n g )
memory: ti-emif-sram: introduce relocatable suspend/resume handlers
Certain SoCs like Texas Instruments AM335x and AM437x require parts
of the EMIF PM code to run late in the suspend sequence from SRAM,
such as saving and restoring the EMIF context and placing the memory
into self-refresh.
One requirement for these SoCs to suspend and enter its lowest power
mode, called DeepSleep0, is that the PER power domain must be shut off.
Because the EMIF (DDR Controller) resides within this power domain, it
will lose context during a suspend operation, so we must save it so we
can restore once we resume. However, we cannot execute this code from
external memory, as it is not available at this point, so the code must
be executed late in the suspend path from SRAM.
This patch introduces a ti-emif-sram driver that includes several
functions written in ARM ASM that are relocatable so the PM SRAM
code can use them. It also allocates a region of writable SRAM to
be used by the code running in the executable region of SRAM to save
and restore the EMIF context. It can export a table containing the
absolute addresses of the available PM functions so that other SRAM
code can branch to them. This code is required for suspend/resume on
AM335x and AM437x to work.
In addition to this, to be able to share data structures between C and
the ti-emif-sram-pm assembly code, we can automatically generate all of
the C struct member offsets and sizes as macros by processing
emif-asm-offsets.c into assembly code and then extracting the relevant
data as is done for the generated platform asm-offsets.h files.
Acked-by: Tony Lindgren <tony@atomide.com>
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
2015-06-17 22:52:10 +03:00
/ *
* void t i _ e m i f _ e n t e r _ s r ( v o i d )
*
* Programs t h e E M I F t o t e l l t h e S D R A M t o e n t e r i n t o s e l f - r e f r e s h
* mode d u r i n g a s l e e p t r a n s i t i o n . O p e r a t e s o n t h e V I R T U A L a d d r e s s
* of t h e E M I F .
* /
ENTRY( t i _ e m i f _ e n t e r _ s r )
stmfd s p ! , { r4 - r11 , l r } @ save registers on stack
adr r4 , t i _ e m i f _ p m _ s r a m _ d a t a
ldr r0 , [ r4 , #E M I F _ P M _ B A S E _ A D D R _ V I R T _ O F F S E T ]
ldr r2 , [ r4 , #E M I F _ P M _ R E G S _ V I R T _ O F F S E T ]
ldr r1 , [ r0 , #E M I F _ P O W E R _ M A N A G E M E N T _ C O N T R O L ]
bic r1 , r1 , #E M I F _ P O W E R _ M G M T _ S E L F _ R E F R E S H _ M O D E _ M A S K
orr r1 , r1 , #E M I F _ P O W E R _ M G M T _ S E L F _ R E F R E S H _ M O D E
str r1 , [ r0 , #E M I F _ P O W E R _ M A N A G E M E N T _ C O N T R O L ]
ldmfd s p ! , { r4 - r11 , p c } @ restore regs and return
ENDPROC( t i _ e m i f _ e n t e r _ s r )
/ *
* void t i _ e m i f _ e x i t _ s r ( v o i d )
*
* Programs t h e E M I F t o t e l l t h e S D R A M t o e x i t s e l f - r e f r e s h m o d e
* after a s l e e p t r a n s i t i o n . O p e r a t e s o n t h e P H Y S I C A L a d d r e s s o f
* the E M I F .
* /
ENTRY( t i _ e m i f _ e x i t _ s r )
adr r4 , t i _ e m i f _ p m _ s r a m _ d a t a
ldr r0 , [ r4 , #E M I F _ P M _ B A S E _ A D D R _ P H Y S _ O F F S E T ]
ldr r2 , [ r4 , #E M I F _ P M _ R E G S _ P H Y S _ O F F S E T ]
/ *
* Toggle E M I F t o e x i t r e f r e s h m o d e :
* if E M I F l o s t c o n t e x t , P W R _ M G T _ C T R L i s c u r r e n t l y 0 , w r i t i n g d i s a b l e
* ( 0 x0 ) , w o n t d o d i d d l y s q u a t ! s o d o a t o g g l e f r o m S R ( 0 x2 ) t o d i s a b l e
* ( 0 x0 ) h e r e .
* * If* E M I F d i d n o t l o s e c o n t e x t , n o t h i n g b r o k e n a s w e w r i t e t h e s a m e
* value( 0 x2 ) t o r e g b e f o r e w e w r i t e a d i s a b l e ( 0 x0 ) .
* /
ldr r1 , [ r2 , #E M I F _ P M C R _ V A L _ O F F S E T ]
bic r1 , r1 , #E M I F _ P O W E R _ M G M T _ S E L F _ R E F R E S H _ M O D E _ M A S K
orr r1 , r1 , #E M I F _ P O W E R _ M G M T _ S E L F _ R E F R E S H _ M O D E
str r1 , [ r0 , #E M I F _ P O W E R _ M A N A G E M E N T _ C O N T R O L ]
bic r1 , r1 , #E M I F _ P O W E R _ M G M T _ S E L F _ R E F R E S H _ M O D E _ M A S K
str r1 , [ r0 , #E M I F _ P O W E R _ M A N A G E M E N T _ C O N T R O L ]
/* Wait for EMIF to become ready */
1 : ldr r1 , [ r0 , #E M I F _ S T A T U S ]
tst r1 , #E M I F _ S T A T U S _ R E A D Y
beq 1 b
mov p c , l r
ENDPROC( t i _ e m i f _ e x i t _ s r )
/ *
* void t i _ e m i f _ a b o r t _ s r ( v o i d )
*
* Disables s e l f - r e f r e s h a f t e r a f a i l e d t r a n s i t i o n t o a l o w - p o w e r
* state s o t h e k e r n e l c a n j u m p b a c k t o D D R a n d f o l l o w a b o r t p a t h .
* Operates o n t h e V I R T U A L a d d r e s s o f t h e E M I F .
* /
ENTRY( t i _ e m i f _ a b o r t _ s r )
stmfd s p ! , { r4 - r11 , l r } @ save registers on stack
adr r4 , t i _ e m i f _ p m _ s r a m _ d a t a
ldr r0 , [ r4 , #E M I F _ P M _ B A S E _ A D D R _ V I R T _ O F F S E T ]
ldr r2 , [ r4 , #E M I F _ P M _ R E G S _ V I R T _ O F F S E T ]
ldr r1 , [ r2 , #E M I F _ P M C R _ V A L _ O F F S E T ]
bic r1 , r1 , #E M I F _ P O W E R _ M G M T _ S E L F _ R E F R E S H _ M O D E _ M A S K
str r1 , [ r0 , #E M I F _ P O W E R _ M A N A G E M E N T _ C O N T R O L ]
/* Wait for EMIF to become ready */
1 : ldr r1 , [ r0 , #E M I F _ S T A T U S ]
tst r1 , #E M I F _ S T A T U S _ R E A D Y
beq 1 b
ldmfd s p ! , { r4 - r11 , p c } @ restore regs and return
ENDPROC( t i _ e m i f _ a b o r t _ s r )
.align 3
ENTRY( t i _ e m i f _ p m _ s r a m _ d a t a )
.space EMIF_PM_DATA_SIZE
ENTRY( t i _ e m i f _ s r a m _ s z )
.word . - ti_ e m i f _ s a v e _ c o n t e x t