Prepare v2023.10
[platform/kernel/u-boot.git] / arch / arm / cpu / arm926ejs / cpu.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2002
4  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
5  * Marius Groeger <mgroeger@sysgo.de>
6  *
7  * (C) Copyright 2002
8  * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
9  */
10
11 /*
12  * CPU specific code
13  */
14
15 #include <common.h>
16 #include <command.h>
17 #include <cpu_func.h>
18 #include <irq_func.h>
19 #include <asm/cache.h>
20 #include <asm/system.h>
21
22 static void cache_flush(void);
23
24 /************************************************************
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  *************************************************************/
31 void sdelay(unsigned long loops)
32 {
33         __asm__ volatile ("1:\n" "subs %0, %1, #1\n"
34                           "bne 1b":"=r" (loops):"0"(loops));
35 }
36
37 int 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
46         disable_interrupts();
47
48
49         /* turn off I/D-cache */
50         icache_disable();
51         dcache_disable();
52         l2_cache_disable();
53
54         /* flush I/D-cache */
55         cache_flush();
56
57         return 0;
58 }
59
60 /* flush I/D-cache */
61 static void cache_flush (void)
62 {
63 #if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
64         unsigned long i = 0;
65
66         asm ("mcr p15, 0, %0, c7, c7, 0": :"r" (i));
67 #endif
68 }