Atmel LCD driver GUARDTIME fix
[platform/kernel/u-boot.git] / cpu / arm_cortexa8 / cpu.c
1 /*
2  * (C) Copyright 2008 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, <garyj@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 <asm/arch/sys_proto.h>
37 #include <asm/system.h>
38
39 #ifndef CONFIG_L2_OFF
40 void l2cache_disable(void);
41 #endif
42
43 static void cache_flush(void);
44
45 int cleanup_before_linux(void)
46 {
47         unsigned int i;
48
49         /*
50          * this function is called just before we call linux
51          * it prepares the processor for linux
52          *
53          * we turn off caches etc ...
54          */
55         disable_interrupts();
56
57         /* turn off I/D-cache */
58         icache_disable();
59         dcache_disable();
60
61         /* invalidate I-cache */
62         cache_flush();
63
64 #ifndef CONFIG_L2_OFF
65         /* turn off L2 cache */
66         l2cache_disable();
67         /* invalidate L2 cache also */
68         v7_flush_dcache_all(get_device_type());
69 #endif
70         i = 0;
71         /* mem barrier to sync up things */
72         asm("mcr p15, 0, %0, c7, c10, 4": :"r"(i));
73
74 #ifndef CONFIG_L2_OFF
75         l2cache_enable();
76 #endif
77
78         return 0;
79 }
80
81 void l2cache_enable()
82 {
83         unsigned long i;
84         volatile unsigned int j;
85
86         /* ES2 onwards we can disable/enable L2 ourselves */
87         if (get_cpu_rev() >= CPU_3XX_ES20) {
88                 __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
89                 __asm__ __volatile__("orr %0, %0, #0x2":"=r"(i));
90                 __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
91         } else {
92                 /* Save r0, r12 and restore them after usage */
93                 __asm__ __volatile__("mov %0, r12":"=r"(j));
94                 __asm__ __volatile__("mov %0, r0":"=r"(i));
95
96                 /*
97                  * GP Device ROM code API usage here
98                  * r12 = AUXCR Write function and r0 value
99                  */
100                 __asm__ __volatile__("mov r12, #0x3");
101                 __asm__ __volatile__("mrc p15, 0, r0, c1, c0, 1");
102                 __asm__ __volatile__("orr r0, r0, #0x2");
103                 /* SMI instruction to call ROM Code API */
104                 __asm__ __volatile__(".word 0xE1600070");
105                 __asm__ __volatile__("mov r0, %0":"=r"(i));
106                 __asm__ __volatile__("mov r12, %0":"=r"(j));
107         }
108
109 }
110
111 void l2cache_disable()
112 {
113         unsigned long i;
114         volatile unsigned int j;
115
116         /* ES2 onwards we can disable/enable L2 ourselves */
117         if (get_cpu_rev() >= CPU_3XX_ES20) {
118                 __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
119                 __asm__ __volatile__("bic %0, %0, #0x2":"=r"(i));
120                 __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
121         } else {
122                 /* Save r0, r12 and restore them after usage */
123                 __asm__ __volatile__("mov %0, r12":"=r"(j));
124                 __asm__ __volatile__("mov %0, r0":"=r"(i));
125
126                 /*
127                  * GP Device ROM code API usage here
128                  * r12 = AUXCR Write function and r0 value
129                  */
130                 __asm__ __volatile__("mov r12, #0x3");
131                 __asm__ __volatile__("mrc p15, 0, r0, c1, c0, 1");
132                 __asm__ __volatile__("bic r0, r0, #0x2");
133                 /* SMI instruction to call ROM Code API */
134                 __asm__ __volatile__(".word 0xE1600070");
135                 __asm__ __volatile__("mov r0, %0":"=r"(i));
136                 __asm__ __volatile__("mov r12, %0":"=r"(j));
137         }
138 }
139
140 static void cache_flush(void)
141 {
142         asm ("mcr p15, 0, %0, c7, c5, 0": :"r" (0));
143 }