blob: 93d7a02ed4c212aaa8dc9a549b789943efaaef6b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk7eaacc52003-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 Zundelf1b3f2b2009-05-13 10:54:10 +02008 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
wdenk7eaacc52003-08-29 22:00:43 +00009 */
10
11/*
12 * CPU specific code
13 */
14
15#include <common.h>
16#include <command.h>
Simon Glass1d91ba72019-11-14 12:57:37 -070017#include <cpu_func.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070018#include <irq_func.h>
Simon Glass274e0b02020-05-10 11:39:56 -060019#include <asm/cache.h>
Jean-Christophe PLAGNIOL-VILLARD9053b5a2009-04-05 13:02:43 +020020#include <asm/system.h>
wdenk7eaacc52003-08-29 22:00:43 +000021
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020022static void cache_flush(void);
wdenk7eaacc52003-08-29 22:00:43 +000023
wdenk7eaacc52003-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 Glassf87959b2019-11-14 12:57:40 -070033 disable_interrupts();
wdenk7eaacc52003-08-29 22:00:43 +000034
wdenk7eaacc52003-08-29 22:00:43 +000035
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020036 /* turn off I/D-cache */
37 icache_disable();
38 dcache_disable();
Michael Walle5ae3eec2012-02-06 22:42:10 +053039 l2_cache_disable();
40
wdenk7eaacc52003-08-29 22:00:43 +000041 /* flush I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020042 cache_flush();
Wolfgang Denkadf20a12005-09-25 01:48:28 +020043
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020044 return 0;
wdenk7eaacc52003-08-29 22:00:43 +000045}
46
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020047/* flush I/D-cache */
48static void cache_flush (void)
Hugo Villeneuve82a84372008-07-10 10:46:33 -040049{
Trevor Woerner43ec7e02019-05-03 09:41:00 -040050#if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020051 unsigned long i = 0;
Hugo Villeneuve82a84372008-07-10 10:46:33 -040052
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020053 asm ("mcr p15, 0, %0, c7, c7, 0": :"r" (i));
Heiko Schocherb642d832014-11-18 09:41:56 +010054#endif
wdenk7eaacc52003-08-29 22:00:43 +000055}