blob: 63bc24cdfc7cddfcca796a957d4b63dc97dc2e98 [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 */
Simon Glass1d91ba72019-11-14 12:57:37 -07008#include <cpu_func.h>
Simon Glass63334482019-11-14 12:57:39 -07009#include <irq_func.h>
Rick Chen842d5802018-11-07 09:34:06 +080010#include <asm/cache.h>
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080011#include <asm/csr.h>
Yu Chien Peter Lin82f0f532023-02-06 16:10:47 +080012#include <asm/arch-andes/csr.h>
Rick Chene76b8042017-12-26 13:55:48 +080013
14/*
15 * cleanup_before_linux() is called just before we call linux
16 * it prepares the processor for linux
17 *
18 * we disable interrupt and caches.
19 */
20int cleanup_before_linux(void)
21{
22 disable_interrupts();
23
Rick Chen842d5802018-11-07 09:34:06 +080024 cache_flush();
Rick Chene76b8042017-12-26 13:55:48 +080025
26 return 0;
27}
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080028
29void harts_early_init(void)
30{
Yu Chien Peter Lin82f0f532023-02-06 16:10:47 +080031 /* Enable I/D-cache in SPL */
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080032 if (CONFIG_IS_ENABLED(RISCV_MMODE)) {
Yu Chien Peter Lin82f0f532023-02-06 16:10:47 +080033 unsigned long mcache_ctl_val = csr_read(CSR_MCACHE_CTL);
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080034
Yu Chien Peter Lin82f0f532023-02-06 16:10:47 +080035 mcache_ctl_val |= (MCACHE_CTL_DC_COHEN | MCACHE_CTL_IC_EN |
36 MCACHE_CTL_DC_EN | MCACHE_CTL_CCTL_SUEN);
37
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080038 csr_write(CSR_MCACHE_CTL, mcache_ctl_val);
39
40 /*
Yu Chien Peter Lin82f0f532023-02-06 16:10:47 +080041 * Check mcache_ctl.DC_COHEN, we assume this platform does
42 * not support CM if the bit is hard-wired to 0.
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080043 */
Yu Chien Peter Lin82f0f532023-02-06 16:10:47 +080044 if (csr_read(CSR_MCACHE_CTL) & MCACHE_CTL_DC_COHEN) {
45 /* Wait for DC_COHSTA bit to be set */
46 while (!(csr_read(CSR_MCACHE_CTL) & MCACHE_CTL_DC_COHSTA));
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080047 }
48 }
49}