blob: 58eab4e550e85a8d073097919eb124e5e52eb0d9 [file] [log] [blame]
wdenka8f88912002-09-08 20:20:45 +00001/*
2 * (C) Copyright 2002
3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
5 *
6 * (C) Copyright 2002
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Alex Zuepke <azu@sysgo.de>
9 *
10 * See file CREDITS for list of people who contributed to this
11 * project.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 * MA 02111-1307 USA
27 */
28
29/*
30 * CPU specific code
31 */
32
33#include <common.h>
34#include <command.h>
35#include <clps7111.h>
wdenk39539882004-07-01 16:30:44 +000036#include <asm/hardware.h>
wdenka8f88912002-09-08 20:20:45 +000037
wdenk39539882004-07-01 16:30:44 +000038int cpu_init (void)
39{
40 /*
41 * setup up stacks if necessary
42 */
43#ifdef CONFIG_USE_IRQ
44 DECLARE_GLOBAL_DATA_PTR;
45
46 IRQ_STACK_START = _armboot_start - CFG_MALLOC_LEN - CFG_GBL_DATA_SIZE - 4;
47 FIQ_STACK_START = IRQ_STACK_START - CONFIG_STACKSIZE_IRQ;
48#endif
49 return 0;
50}
51
52int cleanup_before_linux (void)
53{
54 /*
55 * this function is called just before we call linux
56 * it prepares the processor for linux
57 *
58 * we turn off caches etc ...
59 * and we set the CPU-speed to 73 MHz - see start.S for details
60 */
61
62#if defined(CONFIG_IMPA7) || defined(CONFIG_EP7312)
63 unsigned long i;
64
65 disable_interrupts ();
66
67 /* turn off I-cache */
68 asm ("mrc p15, 0, %0, c1, c0, 0":"=r" (i));
69 i &= ~0x1000;
70 asm ("mcr p15, 0, %0, c1, c0, 0": :"r" (i));
71
72 /* flush I-cache */
73 asm ("mcr p15, 0, %0, c7, c5, 0": :"r" (i));
74#ifdef CONFIG_ARM7_REVD
75 /* go to high speed */
76 IO_SYSCON3 = (IO_SYSCON3 & ~CLKCTL) | CLKCTL_73;
77#endif
78#elif defined(CONFIG_NETARM) || defined(CONFIG_S3C4510B)
79 disable_interrupts ();
80 /* Nothing more needed */
81#else
82#error No cleanup_before_linux() defined for this CPU type
83#endif
84 return 0;
85}
86
87int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
88{
89 extern void reset_cpu (ulong addr);
90
91 disable_interrupts ();
92 reset_cpu (0);
93 /*NOTREACHED*/
94 return (0);
95}
96
97/*
98 * Instruction and Data cache enable and disable functions
99 *
100 */
101
102#if defined(CONFIG_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_NETARM)
wdenka8f88912002-09-08 20:20:45 +0000103/* read co-processor 15, register #1 (control register) */
104static unsigned long read_p15_c1(void)
105{
106 unsigned long value;
107
108 __asm__ __volatile__(
109 "mrc p15, 0, %0, c1, c0, 0 @ read control reg\n"
110 : "=r" (value)
111 :
112 : "memory");
113 /* printf("p15/c1 is = %08lx\n", value); */
114 return value;
115}
116
117/* write to co-processor 15, register #1 (control register) */
118static void write_p15_c1(unsigned long value)
119{
120 /* printf("write %08lx to p15/c1\n", value); */
121 __asm__ __volatile__(
122 "mcr p15, 0, %0, c1, c0, 0 @ write it back\n"
123 :
124 : "r" (value)
125 : "memory");
126
127 read_p15_c1();
128}
129
130static void cp_delay (void)
131{
132 volatile int i;
133
134 /* copro seems to need some delay between reading and writing */
135 for (i = 0; i < 100; i++);
136}
137
138/* See also ARM Ref. Man. */
139#define C1_MMU (1<<0) /* mmu off/on */
140#define C1_ALIGN (1<<1) /* alignment faults off/on */
141#define C1_IDC (1<<2) /* icache and/or dcache off/on */
142#define C1_WRITE_BUFFER (1<<3) /* write buffer off/on */
143#define C1_BIG_ENDIAN (1<<7) /* big endian off/on */
144#define C1_SYS_PROT (1<<8) /* system protection */
145#define C1_ROM_PROT (1<<9) /* ROM protection */
146#define C1_HIGH_VECTORS (1<<13) /* location of vectors: low/high addresses */
147
wdenka8f88912002-09-08 20:20:45 +0000148void icache_enable (void)
149{
150 ulong reg;
151
152 reg = read_p15_c1 ();
153 cp_delay ();
154 write_p15_c1 (reg | C1_IDC);
155}
156
157void icache_disable (void)
158{
159 ulong reg;
160
161 reg = read_p15_c1 ();
162 cp_delay ();
163 write_p15_c1 (reg & ~C1_IDC);
164}
165
166int icache_status (void)
167{
168 return (read_p15_c1 () & C1_IDC) != 0;
169}
170
171void dcache_enable (void)
172{
173 ulong reg;
174
175 reg = read_p15_c1 ();
176 cp_delay ();
177 write_p15_c1 (reg | C1_IDC);
178}
179
180void dcache_disable (void)
181{
182 ulong reg;
183
184 reg = read_p15_c1 ();
185 cp_delay ();
186 write_p15_c1 (reg & ~C1_IDC);
187}
188
189int dcache_status (void)
190{
191 return (read_p15_c1 () & C1_IDC) != 0;
192}
wdenk39539882004-07-01 16:30:44 +0000193
194#elif defined(CONFIG_S3C4510B)
195
196void icache_enable (void)
197{
198 s32 i;
199
200 /* disable all cache bits */
201 CLR_REG( REG_SYSCFG, 0x3F);
202
203 /* 8KB cache, write enable */
204 SET_REG( REG_SYSCFG, CACHE_WRITE_BUFF | CACHE_MODE_01);
205
206 /* clear TAG RAM bits */
207 for ( i = 0; i < 256; i++)
208 PUT_REG( CACHE_TAG_RAM + 4*i, 0x00000000);
209
210 /* clear SET0 RAM */
211 for(i=0; i < 1024; i++)
212 PUT_REG( CACHE_SET0_RAM + 4*i, 0x00000000);
213
214 /* clear SET1 RAM */
215 for(i=0; i < 1024; i++)
216 PUT_REG( CACHE_SET1_RAM + 4*i, 0x00000000);
217
218 /* enable cache */
219 SET_REG( REG_SYSCFG, CACHE_ENABLE);
220
221}
222
223void icache_disable (void)
224{
225 /* disable all cache bits */
226 CLR_REG( REG_SYSCFG, 0x3F);
227}
228
229int icache_status (void)
230{
231 return GET_REG( REG_SYSCFG) & CACHE_ENABLE;
232}
233
234void dcache_enable (void)
235{
236 /* we don't have seperate instruction/data caches */
237 icache_enable();
238}
239
240void dcache_disable (void)
241{
242 /* we don't have seperate instruction/data caches */
243 icache_disable();
244}
245
246int dcache_status (void)
247{
248 /* we don't have seperate instruction/data caches */
249 return icache_status();
250}
251
252#else
253#error No icache/dcache enable/disable functions defined for this CPU type
254#endif