xref: /rk3399_rockchip-uboot/arch/arm/cpu/armv7/cpu.c (revision f56348af5d255f6dc2a8bcd7d798ab5edf8fba25)
1*f56348afSSteve Sakoman /*
2*f56348afSSteve Sakoman  * (C) Copyright 2008 Texas Insturments
3*f56348afSSteve Sakoman  *
4*f56348afSSteve Sakoman  * (C) Copyright 2002
5*f56348afSSteve Sakoman  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
6*f56348afSSteve Sakoman  * Marius Groeger <mgroeger@sysgo.de>
7*f56348afSSteve Sakoman  *
8*f56348afSSteve Sakoman  * (C) Copyright 2002
9*f56348afSSteve Sakoman  * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
10*f56348afSSteve Sakoman  *
11*f56348afSSteve Sakoman  * See file CREDITS for list of people who contributed to this
12*f56348afSSteve Sakoman  * project.
13*f56348afSSteve Sakoman  *
14*f56348afSSteve Sakoman  * This program is free software; you can redistribute it and/or
15*f56348afSSteve Sakoman  * modify it under the terms of the GNU General Public License as
16*f56348afSSteve Sakoman  * published by the Free Software Foundation; either version 2 of
17*f56348afSSteve Sakoman  * the License, or (at your option) any later version.
18*f56348afSSteve Sakoman  *
19*f56348afSSteve Sakoman  * This program is distributed in the hope that it will be useful,
20*f56348afSSteve Sakoman  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21*f56348afSSteve Sakoman  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22*f56348afSSteve Sakoman  * GNU General Public License for more details.
23*f56348afSSteve Sakoman  *
24*f56348afSSteve Sakoman  * You should have received a copy of the GNU General Public License
25*f56348afSSteve Sakoman  * along with this program; if not, write to the Free Software
26*f56348afSSteve Sakoman  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27*f56348afSSteve Sakoman  * MA 02111-1307 USA
28*f56348afSSteve Sakoman  */
29*f56348afSSteve Sakoman 
30*f56348afSSteve Sakoman /*
31*f56348afSSteve Sakoman  * CPU specific code
32*f56348afSSteve Sakoman  */
33*f56348afSSteve Sakoman 
34*f56348afSSteve Sakoman #include <common.h>
35*f56348afSSteve Sakoman #include <command.h>
36*f56348afSSteve Sakoman #include <asm/system.h>
37*f56348afSSteve Sakoman #include <asm/cache.h>
38*f56348afSSteve Sakoman #ifndef CONFIG_L2_OFF
39*f56348afSSteve Sakoman #include <asm/arch/sys_proto.h>
40*f56348afSSteve Sakoman #endif
41*f56348afSSteve Sakoman 
42*f56348afSSteve Sakoman static void cache_flush(void);
43*f56348afSSteve Sakoman 
44*f56348afSSteve Sakoman int cleanup_before_linux(void)
45*f56348afSSteve Sakoman {
46*f56348afSSteve Sakoman 	unsigned int i;
47*f56348afSSteve Sakoman 
48*f56348afSSteve Sakoman 	/*
49*f56348afSSteve Sakoman 	 * this function is called just before we call linux
50*f56348afSSteve Sakoman 	 * it prepares the processor for linux
51*f56348afSSteve Sakoman 	 *
52*f56348afSSteve Sakoman 	 * we turn off caches etc ...
53*f56348afSSteve Sakoman 	 */
54*f56348afSSteve Sakoman 	disable_interrupts();
55*f56348afSSteve Sakoman 
56*f56348afSSteve Sakoman 	/* turn off I/D-cache */
57*f56348afSSteve Sakoman 	icache_disable();
58*f56348afSSteve Sakoman 	dcache_disable();
59*f56348afSSteve Sakoman 
60*f56348afSSteve Sakoman 	/* invalidate I-cache */
61*f56348afSSteve Sakoman 	cache_flush();
62*f56348afSSteve Sakoman 
63*f56348afSSteve Sakoman #ifndef CONFIG_L2_OFF
64*f56348afSSteve Sakoman 	/* turn off L2 cache */
65*f56348afSSteve Sakoman 	l2_cache_disable();
66*f56348afSSteve Sakoman 	/* invalidate L2 cache also */
67*f56348afSSteve Sakoman 	invalidate_dcache(get_device_type());
68*f56348afSSteve Sakoman #endif
69*f56348afSSteve Sakoman 	i = 0;
70*f56348afSSteve Sakoman 	/* mem barrier to sync up things */
71*f56348afSSteve Sakoman 	asm("mcr p15, 0, %0, c7, c10, 4": :"r"(i));
72*f56348afSSteve Sakoman 
73*f56348afSSteve Sakoman #ifndef CONFIG_L2_OFF
74*f56348afSSteve Sakoman 	l2_cache_enable();
75*f56348afSSteve Sakoman #endif
76*f56348afSSteve Sakoman 
77*f56348afSSteve Sakoman 	return 0;
78*f56348afSSteve Sakoman }
79*f56348afSSteve Sakoman 
80*f56348afSSteve Sakoman static void cache_flush(void)
81*f56348afSSteve Sakoman {
82*f56348afSSteve Sakoman 	asm ("mcr p15, 0, %0, c7, c5, 0": :"r" (0));
83*f56348afSSteve Sakoman }
84