summaryrefslogtreecommitdiffstats
path: root/target/linux/realtek/files/arch/rlx/mm/imem-dmem.S
blob: 7551d89bcbb9d8ced2f323c0467a76afd24e42d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include <asm/asmmacro.h>

#if defined(CONFIG_RTK_VOIP)
		.macro refill_dmem	sel, addr
		.set noreorder
		la		t0, 0xB800B808		# CTRL 
		sw		zero, 0(t0)
		la		t1, ( 1 << 21 )
		sw		t1, 0(t0)
		la		t0, 0xB800B800		# SA 
		sw		zero, 0(t0)
		la		t0, \addr			# EXT SA
		la		t1, 0x1ffffffc
		and		t1, t0, t1
		la		t0, 0xB800B804
		sw		t1, 0(t0)
		la		t0, 0xB800B808		# CTRL 
		la		t1, ( \sel << 23 ) | ( 1 << 22 ) | ( 1 << 19 ) | ( ( ( 0x1000 ) >> 2 ) & 0x3FFFF )
		sw		t1, 0(t0)
		la		t4, ( 1 << 20 )
		or		t1, t1, t4
		sw		t1, 0(t0)
1:
		lw		t1, 0(t0)
		and		t1, t1, t4
		bne		t1, zero, 1b
		nop		
		.endm

#endif
	.text
        LEAF(_imem_dmem_init)
        .set noreorder

	#--- initialize and start COP3
        mfc0    $8,$12
        nop
        nop
        or              $8,0x80000000
        mtc0    $8,$12
        nop
        nop

        #--- invalidate the IRAM with a 0->1 transition
        mtc0    $0, $20 # CCTL
        nop
        nop
        li              $8,0x00000020 # IRAM Off
        mtc0    $8, $20
        nop
        nop

        #--- invalidate the icache and dcache with a 0->1 transition
        mtc0    $0, $20 # CCTL
        nop
        nop
        li              $8,0x00000202 # Invalid ICACHE and DCACHE
        mtc0    $8, $20
        nop
        nop

        #--- load iram base and top
#ifdef CONFIG_RTL_819XD
#define IMEM0_SIZE	4096*4
#else
#define IMEM0_SIZE	4096
#endif
#define IMEM1_SIZE	4096
        la              $8,__iram
        la              $9,0x0fffc000
        and             $8,$8,$9
        mtc3    $8,$0                                                           # IW bas
        nop
        nop
#ifdef CONFIG_ARCH_CPU_RLX5281
#if defined(CONFIG_RTL8198_REVISION_B)
        //jasonwang0413
        li	t6,0xb8000000
	lw	t7,0(t6)
	nop
	nop
	and     t7,t7,0x03
	bgtz	t7,rev_b
	nop
rev_a:	// 00
        li     t6,0xfff
        li     t4,0xfff
        j     rev_end
	nop
rev_b:	// 01
rev_c:	// 02
        li     t6,0x7fff
        li     t4,0x1fff
rev_end:
             nop
             nop

        add   $8,$8,t6
#else
        addiu   $8,$8,IMEM0_SIZE-1
#endif
        mtc3    $8,$1                                                           # IW top
        nop
        nop

        #--- Refill the IRAM with a 0->1 transition
        mtc0    $0, $20 # CCTL
        nop
        nop
        li              $8,0x00000010 # IRAM Fill
        mtc0    $8, $20
        nop
        nop
#if !defined(CONFIG_RTL_819XD)
	#--- load iram base1 and top1
        la              $8,__iram
#ifdef CONFIG_RTL8198_REVISION_B
	add             $8,$8,t6
	add             $8,$8,0x01
#else
	add             $8,$8,IMEM0_SIZE
#endif
        la              $9,0x0fffc000
        and             $8,$8,$9
        mtc3    $8,$2                                                           # IW bas 1
        nop
        nop
#ifdef CONFIG_RTL8198_REVISION_B
        add   $8,$8,t4
#else
        addiu   $8,$8,IMEM1_SIZE-1
#endif
        mtc3    $8,$3                                                           # IW top 1
        nop
        nop

        #--- Refill the IRAM with a 0->1 transition
        mtc0    $0, $20,1 # CCTL
        nop
        nop
        li              $8,0x00000010 # IRAM Fill
        mtc0    $8, $20,1
#endif
        nop
        nop

        #--- load dram base and top
        la              $8,__dram_start
        la              $9,__dram_end
        beq             $8,$9,skip_dramInit
	nop
        la              $9,0x0fffe000
        and             $8,$8,$9
        mtc3    $8,$4                                                           # DW bas
        nop
        nop
#if defined(CONFIG_RTL_819XD)
        #define DMEM0_SIZE	4096*2

	addiu   $8,$8,(DMEM0_SIZE-1)
#else
        addiu   $8,$8,0xfff
#endif
        mtc3    $8,$5                                                           # DW top
        nop
        nop
	#la              $8,__dram_start
        #la              $9,__dram_end
        #beq             $8,$9,skip_dramInit
	#nop
        #la              $9,0x0fffe000
        add		$8,$8,1
	#and             $8,$8,$9
#if !defined(CONFIG_RTL_819XD)
        mtc3    $8,$6                                                           # DW bas 1
        nop
        nop
        addiu   $8,$8,0xfff
        mtc3    $8,$7                                                           # DW top 1
#endif
        nop
        nop
#if defined(CONFIG_RTK_VOIP) && !defined(CONFIG_RTL_89xxD)
	#--- Refill the DRAM -----
	refill_dmem 2, __dram_start				# DMEM 0 (4k)
	refill_dmem 3, __dram_start + 0x1000	# DMEM 1 (4k)
#endif
#if !defined(CONFIG_RTL_89xxD)
		mfc0	t0, $20
		or		t0, 0x00000400	# DMEM On	// pkshih: add to enable DMEM0 and DMEM1
        mtc0    t0, $20			# DMEM0 ON
#endif
#if !defined(CONFIG_RTL_819XD)
        mfc0	t0, $20,1
		or		t0, 0x00000400	# DMEM On	// pkshih: add to enable DMEM0 and DMEM1
        mtc0    t0, $20,1		# DMEM1 ON
#endif
		nop
		nop

#else
        addiu   $8,$8,0x3fff
        mtc3    $8,$1                                                           # IW top
        nop
        nop

        #--- Refill the IRAM with a 0->1 transition
        mtc0    $0, $20 # CCTL
        nop
        nop
        li              $8,0x00000010 # IRAM Fill
        mtc0    $8, $20
        nop
        nop

        #--- load dram base and top
        la              $8,__dram_start
        la              $9,__dram_end
        beq             $8,$9,skip_dramInit
	nop
        la              $9,0x0fffe000
        and             $8,$8,$9
        mtc3    $8,$4                                                           # DW bas
        nop
        nop
        addiu   $8,$8,0x1fff
        mtc3    $8,$5                                                           # DW top
        nop
        nop
#endif
skip_dramInit:
        #--- enable icache and dcache
        mtc0    $0, $20 # CCTL
        nop
        nop

        .set    reorder
        j               $31
	END(_imem_dmem_init)