blob: ef78bd965ea0ead8a375326eaf88105df86407fe [file] [log] [blame]
Guennadi Liakhovetski9b077732008-08-31 00:39:46 +02001/*
2 * (C) Copyright 2004 Texas Insturments
3 *
4 * (C) Copyright 2002
5 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
6 * Marius Groeger <mgroeger@sysgo.de>
7 *
8 * (C) Copyright 2002
9 * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
10 *
11 * See file CREDITS for list of people who contributed to this
12 * project.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * MA 02111-1307 USA
28 */
29
30/*
31 * CPU specific code
32 */
33
34#include <common.h>
35#include <command.h>
36#include <s3c6400.h>
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +020037#include <asm/system.h>
Guennadi Liakhovetski9b077732008-08-31 00:39:46 +020038
39static void cache_flush (void);
40
Guennadi Liakhovetski9b077732008-08-31 00:39:46 +020041static void cp_delay (void)
42{
43 volatile int i;
44
45 /* Many OMAP regs need at least 2 nops */
46 for (i = 0; i < 100; i++)
47 __asm__ __volatile__("nop\n");
48}
49
Guennadi Liakhovetski9b077732008-08-31 00:39:46 +020050int cpu_init (void)
51{
52 return 0;
53}
54
55int cleanup_before_linux (void)
56{
57 /*
58 * this function is called just before we call linux
59 * it prepares the processor for linux
60 *
61 * we turn off caches etc ...
62 */
63
64 disable_interrupts ();
65
66 /* turn off I/D-cache */
67 icache_disable();
68 dcache_disable();
69 cache_flush();
70
71 return 0;
72}
73
74
75/* * reset the cpu by setting up the watchdog timer and let him time out */
76void reset_cpu (ulong ignored)
77{
78 printf("reset... \n\n\n");
79 SW_RST_REG = 0x6400;
80 /* loop forever and wait for reset to happen */
81 while (1) {
82 if (serial_tstc()) {
83 serial_getc();
84 break;
85 }
86 }
87 /*NOTREACHED*/
88}
89
90int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
91{
92 disable_interrupts ();
93 reset_cpu (0);
94 /*NOTREACHED*/
95 return 0;
96}
97
98void icache_enable (void)
99{
100 ulong reg;
101
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +0200102 reg = get_cr (); /* get control reg. */
Guennadi Liakhovetski9b077732008-08-31 00:39:46 +0200103 cp_delay ();
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +0200104 set_cr (reg | CR_I);
Guennadi Liakhovetski9b077732008-08-31 00:39:46 +0200105}
106
107void icache_disable (void)
108{
109 ulong reg;
110
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +0200111 reg = get_cr ();
Guennadi Liakhovetski9b077732008-08-31 00:39:46 +0200112 cp_delay ();
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +0200113 set_cr (reg & ~CR_I);
Guennadi Liakhovetski9b077732008-08-31 00:39:46 +0200114}
115
116int icache_status (void)
117{
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +0200118 return (get_cr () & CR_I) != 0;
Guennadi Liakhovetski9b077732008-08-31 00:39:46 +0200119}
120
121/* It makes no sense to use the dcache if the MMU is not enabled */
122void dcache_enable (void)
123{
124 ulong reg;
125
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +0200126 reg = get_cr ();
Guennadi Liakhovetski9b077732008-08-31 00:39:46 +0200127 cp_delay ();
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +0200128 set_cr (reg | CR_C);
Guennadi Liakhovetski9b077732008-08-31 00:39:46 +0200129}
130
131void dcache_disable (void)
132{
133 ulong reg;
134
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +0200135 reg = get_cr ();
Guennadi Liakhovetski9b077732008-08-31 00:39:46 +0200136 cp_delay ();
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +0200137 set_cr (reg & ~CR_C);
Guennadi Liakhovetski9b077732008-08-31 00:39:46 +0200138}
139
140int dcache_status (void)
141{
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +0200142 return (get_cr () & CR_C) != 0;
Guennadi Liakhovetski9b077732008-08-31 00:39:46 +0200143}
144
145/* flush I/D-cache */
146static void cache_flush (void)
147{
148 /* invalidate both caches and flush btb */
149 asm ("mcr p15, 0, %0, c7, c7, 0": :"r" (0));
150 /* mem barrier to sync things */
151 asm ("mcr p15, 0, %0, c7, c10, 4": :"r" (0));
152}