blob: 93d7a02ed4c212aaa8dc9a549b789943efaaef6b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk6f213472003-08-29 22:00:43 +00002/*
3 * (C) Copyright 2002
4 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
5 * Marius Groeger <mgroeger@sysgo.de>
6 *
7 * (C) Copyright 2002
Detlev Zundel792a09e2009-05-13 10:54:10 +02008 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
wdenk6f213472003-08-29 22:00:43 +00009 */
10
11/*
12 * CPU specific code
13 */
14
15#include <common.h>
16#include <command.h>
Simon Glass9edefc22019-11-14 12:57:37 -070017#include <cpu_func.h>
Simon Glass36bf4462019-11-14 12:57:42 -070018#include <irq_func.h>
Simon Glass90526e92020-05-10 11:39:56 -060019#include <asm/cache.h>
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +020020#include <asm/system.h>
wdenk6f213472003-08-29 22:00:43 +000021
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020022static void cache_flush(void);
wdenk6f213472003-08-29 22:00:43 +000023
wdenk6f213472003-08-29 22:00:43 +000024int cleanup_before_linux (void)
25{
26 /*
27 * this function is called just before we call linux
28 * it prepares the processor for linux
29 *
30 * we turn off caches etc ...
31 */
32
Simon Glass9d3915b2019-11-14 12:57:40 -070033 disable_interrupts();
wdenk6f213472003-08-29 22:00:43 +000034
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020035
wdenk6f213472003-08-29 22:00:43 +000036 /* turn off I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020037 icache_disable();
38 dcache_disable();
Michael Walle67953022012-02-06 22:42:10 +053039 l2_cache_disable();
40
wdenk6f213472003-08-29 22:00:43 +000041 /* flush I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020042 cache_flush();
Wolfgang Denk74f43042005-09-25 01:48:28 +020043
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020044 return 0;
wdenk6f213472003-08-29 22:00:43 +000045}
46
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020047/* flush I/D-cache */
48static void cache_flush (void)
wdenk6f213472003-08-29 22:00:43 +000049{
Trevor Woerner10015022019-05-03 09:41:00 -040050#if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020051 unsigned long i = 0;
wdenk6f213472003-08-29 22:00:43 +000052
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020053 asm ("mcr p15, 0, %0, c7, c7, 0": :"r" (i));
Heiko Schocher99197a92014-11-18 09:41:56 +010054#endif
wdenk6f213472003-08-29 22:00:43 +000055}