2 * (C) Copyright 2004 Texas Insturments
5 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
6 * Marius Groeger <mgroeger@sysgo.de>
9 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
11 * SPDX-License-Identifier: GPL-2.0+
20 #include <asm/system.h>
22 static void cache_flush(void);
24 int cleanup_before_linux (void)
27 * this function is called just before we call linux
28 * it prepares the processor for linux
30 * we turn off caches etc ...
33 disable_interrupts ();
37 extern void lcd_disable(void);
38 extern void lcd_panel_disable(void);
40 lcd_disable(); /* proper disable of lcd & panel */
45 /* turn off I/D-cache */
54 static void cache_flush(void)
57 /* clean entire data cache */
58 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i));
59 /* invalidate both caches and flush btb */
60 asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i));
61 /* mem barrier to sync things */
62 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i));
65 #ifndef CONFIG_SYS_DCACHE_OFF
67 #ifndef CONFIG_SYS_CACHELINE_SIZE
68 #define CONFIG_SYS_CACHELINE_SIZE 32
71 void invalidate_dcache_all(void)
73 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
76 void flush_dcache_all(void)
78 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
79 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
82 static int check_cache_range(unsigned long start, unsigned long stop)
86 if (start & (CONFIG_SYS_CACHELINE_SIZE - 1))
89 if (stop & (CONFIG_SYS_CACHELINE_SIZE - 1))
93 debug("CACHE: Misaligned operation at range [%08lx, %08lx]\n",
99 void invalidate_dcache_range(unsigned long start, unsigned long stop)
101 if (!check_cache_range(start, stop))
104 while (start < stop) {
105 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
106 start += CONFIG_SYS_CACHELINE_SIZE;
110 void flush_dcache_range(unsigned long start, unsigned long stop)
112 if (!check_cache_range(start, stop))
115 while (start < stop) {
116 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
117 start += CONFIG_SYS_CACHELINE_SIZE;
120 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
123 void flush_cache(unsigned long start, unsigned long size)
125 flush_dcache_range(start, start + size);
128 #else /* #ifndef CONFIG_SYS_DCACHE_OFF */
129 void invalidate_dcache_all(void)
133 void flush_dcache_all(void)
137 void invalidate_dcache_range(unsigned long start, unsigned long stop)
141 void flush_dcache_range(unsigned long start, unsigned long stop)
145 void flush_cache(unsigned long start, unsigned long size)
148 #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
150 #if !defined(CONFIG_SYS_ICACHE_OFF) || !defined(CONFIG_SYS_DCACHE_OFF)
151 void enable_caches(void)
153 #ifndef CONFIG_SYS_ICACHE_OFF
156 #ifndef CONFIG_SYS_DCACHE_OFF