blob: 06e379bcb1fe11b73d55881f7fb9d393a5c49411 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rick Chene76b8042017-12-26 13:55:48 +08002/*
Yu Chien Peter Lin82f0f532023-02-06 16:10:47 +08003 * Copyright (C) 2023 Andes Technology Corporation
Rick Chene76b8042017-12-26 13:55:48 +08004 * Rick Chen, Andes Technology Corporation <rick@andestech.com>
Rick Chene76b8042017-12-26 13:55:48 +08005 */
6
7/* CPU specific code */
8#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07009#include <cpu_func.h>
Simon Glass63334482019-11-14 12:57:39 -070010#include <irq_func.h>
Rick Chen842d5802018-11-07 09:34:06 +080011#include <asm/cache.h>
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080012#include <asm/csr.h>
Yu Chien Peter Lin82f0f532023-02-06 16:10:47 +080013#include <asm/arch-andes/csr.h>
Rick Chene76b8042017-12-26 13:55:48 +080014
15/*
16 * cleanup_before_linux() is called just before we call linux
17 * it prepares the processor for linux
18 *
19 * we disable interrupt and caches.
20 */
21int cleanup_before_linux(void)
22{
23 disable_interrupts();
24
Rick Chen842d5802018-11-07 09:34:06 +080025 cache_flush();
Rick Chene76b8042017-12-26 13:55:48 +080026
27 return 0;
28}
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080029
30void harts_early_init(void)
31{
Yu Chien Peter Lin82f0f532023-02-06 16:10:47 +080032 /* Enable I/D-cache in SPL */
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080033 if (CONFIG_IS_ENABLED(RISCV_MMODE)) {
Yu Chien Peter Lin82f0f532023-02-06 16:10:47 +080034 unsigned long mcache_ctl_val = csr_read(CSR_MCACHE_CTL);
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080035
Yu Chien Peter Lin82f0f532023-02-06 16:10:47 +080036 mcache_ctl_val |= (MCACHE_CTL_DC_COHEN | MCACHE_CTL_IC_EN |
37 MCACHE_CTL_DC_EN | MCACHE_CTL_CCTL_SUEN);
38
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080039 csr_write(CSR_MCACHE_CTL, mcache_ctl_val);
40
41 /*
Yu Chien Peter Lin82f0f532023-02-06 16:10:47 +080042 * Check mcache_ctl.DC_COHEN, we assume this platform does
43 * not support CM if the bit is hard-wired to 0.
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080044 */
Yu Chien Peter Lin82f0f532023-02-06 16:10:47 +080045 if (csr_read(CSR_MCACHE_CTL) & MCACHE_CTL_DC_COHEN) {
46 /* Wait for DC_COHSTA bit to be set */
47 while (!(csr_read(CSR_MCACHE_CTL) & MCACHE_CTL_DC_COHSTA));
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080048 }
49 }
50}