1/* SPDX-License-Identifier: GPL-2.0
2 *
3 * MS7724SE sdram self/auto-refresh setup code
4 *
5 *  Copyright (C) 2009 Magnus Damm
6 */
7
8#include <linux/sys.h>
9#include <linux/errno.h>
10#include <linux/linkage.h>
11#include <asm/asm-offsets.h>
12#include <asm/suspend.h>
13#include <asm/romimage-macros.h>
14
15/* code to enter and leave self-refresh. must be self-contained.
16 * this code will be copied to on-chip memory and executed from there.
17 */
18	.balign 4
19ENTRY(ms7724se_sdram_enter_start)
20
21	/* DBSC: put memory in self-refresh mode */
22
23	ED 0xFD000010, 0x00000000 /* DBEN */
24	ED 0xFD000040, 0x00000000 /* DBRFPDN0 */
25	ED 0xFD000014, 0x00000002 /* DBCMDCNT (PALL) */
26	ED 0xFD000014, 0x00000004 /* DBCMDCNT (REF) */
27	ED 0xFD000040, 0x00000001 /* DBRFPDN0 */
28
29	rts
30	 nop
31
32ENTRY(ms7724se_sdram_enter_end)
33
34	.balign 4
35ENTRY(ms7724se_sdram_leave_start)
36
37	/* DBSC: put memory in auto-refresh mode */
38
39	mov.l	@(SH_SLEEP_MODE, r5), r0
40	tst	#SUSP_SH_RSTANDBY, r0
41	bf	resume_rstandby
42
43	ED 0xFD000040, 0x00000000 /* DBRFPDN0 */
44	WAIT 1
45	ED 0xFD000014, 0x00000002 /* DBCMDCNT (PALL) */
46	ED 0xFD000014, 0x00000004 /* DBCMDCNT (REF) */
47	ED 0xFD000010, 0x00000001 /* DBEN */
48	ED 0xFD000040, 0x00010000 /* DBRFPDN0 */
49
50	rts
51	 nop
52
53resume_rstandby:
54
55	/* CPG: setup clocks before restarting external memory */
56
57	ED 0xA4150024, 0x00004000 /* PLLCR */
58
59	mov.l	FRQCRA,r0
60	mov.l	@r0,r3
61	mov.l	KICK,r1
62	or	r1, r3
63	mov.l	r3, @r0
64
65	mov.l	LSTATS,r0
66	mov	#1,r1
67WAIT_LSTATS:
68	mov.l	@r0,r3
69	tst	r1,r3
70	bf	WAIT_LSTATS
71
72	/* DBSC: re-initialize and put in auto-refresh */
73
74	ED 0xFD000108, 0x00000181 /* DBPDCNT0 */
75	ED 0xFD000020, 0x015B0002 /* DBCONF */
76	ED 0xFD000030, 0x03071502 /* DBTR0 */
77	ED 0xFD000034, 0x02020102 /* DBTR1 */
78	ED 0xFD000038, 0x01090405 /* DBTR2 */
79	ED 0xFD00003C, 0x00000002 /* DBTR3 */
80	ED 0xFD000008, 0x00000005 /* DBKIND */
81	ED 0xFD000040, 0x00000001 /* DBRFPDN0 */
82	ED 0xFD000040, 0x00000000 /* DBRFPDN0 */
83	ED 0xFD000018, 0x00000001 /* DBCKECNT */
84
85	mov	#100,r0
86WAIT_400NS:
87	dt	r0
88	bf	WAIT_400NS
89
90	ED 0xFD000014, 0x00000002 /* DBCMDCNT (PALL) */
91	ED 0xFD000060, 0x00020000 /* DBMRCNT (EMR2) */
92	ED 0xFD000060, 0x00030000 /* DBMRCNT (EMR3) */
93	ED 0xFD000060, 0x00010004 /* DBMRCNT (EMR) */
94	ED 0xFD000060, 0x00000532 /* DBMRCNT (MRS) */
95	ED 0xFD000014, 0x00000002 /* DBCMDCNT (PALL) */
96	ED 0xFD000014, 0x00000004 /* DBCMDCNT (REF) */
97	ED 0xFD000014, 0x00000004 /* DBCMDCNT (REF) */
98	ED 0xFD000060, 0x00000432 /* DBMRCNT (MRS) */
99	ED 0xFD000060, 0x000103c0 /* DBMRCNT (EMR) */
100	ED 0xFD000060, 0x00010040 /* DBMRCNT (EMR) */
101
102	mov	#100,r0
103WAIT_400NS_2:
104	dt	r0
105	bf	WAIT_400NS_2
106
107	ED 0xFD000010, 0x00000001 /* DBEN */
108	ED 0xFD000044, 0x0000050f /* DBRFPDN1 */
109	ED 0xFD000048, 0x236800e6 /* DBRFPDN2 */
110
111	mov.l	DUMMY,r0
112	mov.l	@r0, r1 /* force single dummy read */
113
114	ED 0xFD000014, 0x00000002 /* DBCMDCNT (PALL) */
115	ED 0xFD000014, 0x00000004 /* DBCMDCNT (REF) */
116	ED 0xFD000108, 0x00000080 /* DBPDCNT0 */
117	ED 0xFD000040, 0x00010000 /* DBRFPDN0 */
118
119	rts
120	 nop
121
122	.balign 4
123DUMMY:	.long	0xac400000
124FRQCRA:	.long	0xa4150000
125KICK:	.long	0x80000000
126LSTATS:	.long	0xa4150060
127
128ENTRY(ms7724se_sdram_leave_end)
129