blob: 2ce413a7f8661a2be32a412c9af39fac843ca519 [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
Icenowy Zhengb198c2e2022-01-29 10:23:02 -050024/************************************************************
25 * sdelay() - simple spin loop. Will be constant time as
26 * its generally used in bypass conditions only. This
27 * is necessary until timers are accessible.
28 *
29 * not inline to increase chances its in cache when called
30 *************************************************************/
31void sdelay(unsigned long loops)
32{
33 __asm__ volatile ("1:\n" "subs %0, %1, #1\n"
34 "bne 1b":"=r" (loops):"0"(loops));
35}
36
wdenk7eaacc52003-08-29 22:00:43 +000037int cleanup_before_linux (void)
38{
39 /*
40 * this function is called just before we call linux
41 * it prepares the processor for linux
42 *
43 * we turn off caches etc ...
44 */
45
Simon Glassf87959b2019-11-14 12:57:40 -070046 disable_interrupts();
wdenk7eaacc52003-08-29 22:00:43 +000047
wdenk7eaacc52003-08-29 22:00:43 +000048
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020049 /* turn off I/D-cache */
50 icache_disable();
51 dcache_disable();
Michael Walle5ae3eec2012-02-06 22:42:10 +053052 l2_cache_disable();
53
wdenk7eaacc52003-08-29 22:00:43 +000054 /* flush I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020055 cache_flush();
Wolfgang Denkadf20a12005-09-25 01:48:28 +020056
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020057 return 0;
wdenk7eaacc52003-08-29 22:00:43 +000058}
59
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020060/* flush I/D-cache */
61static void cache_flush (void)
Hugo Villeneuve82a84372008-07-10 10:46:33 -040062{
Trevor Woerner43ec7e02019-05-03 09:41:00 -040063#if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020064 unsigned long i = 0;
Hugo Villeneuve82a84372008-07-10 10:46:33 -040065
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020066 asm ("mcr p15, 0, %0, c7, c7, 0": :"r" (i));
Heiko Schocherb642d832014-11-18 09:41:56 +010067#endif
wdenk7eaacc52003-08-29 22:00:43 +000068}