blob: d25ecba0e88d47d8d4758564d2bafaf518d297d4 [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 Liang96e75a82023-12-26 14:17:34 +080034 unsigned long mmisc_ctl_val = csr_read(CSR_MMISC_CTL);
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080035
Leo Yu-Chi Liang96e75a82023-12-26 14:17:34 +080036 mcache_ctl_val |= (MCACHE_CTL_CCTL_SUEN | \
37 MCACHE_CTL_IC_PREFETCH_EN | MCACHE_CTL_DC_PREFETCH_EN | \
Leo Yu-Chi Liang7862a2a2023-12-26 14:17:35 +080038 MCACHE_CTL_DC_WAROUND_EN | MCACHE_CTL_L2C_WAROUND_EN | \
39 MCACHE_CTL_IC_ECCEN | MCACHE_CTL_DC_ECCEN | MCACHE_CTL_TLB_ECCEN);
Leo Yu-Chi Liang1eb9f912023-12-26 14:17:33 +080040
41 if (!CONFIG_IS_ENABLED(SYS_ICACHE_OFF))
42 mcache_ctl_val |= MCACHE_CTL_IC_EN;
43
44 if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
45 mcache_ctl_val |= (MCACHE_CTL_DC_EN | MCACHE_CTL_DC_COHEN);
Yu Chien Peter Lin82f0f532023-02-06 16:10:47 +080046
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080047 csr_write(CSR_MCACHE_CTL, mcache_ctl_val);
48
Leo Yu-Chi Liang1eb9f912023-12-26 14:17:33 +080049 if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) {
50 /*
51 * Check mcache_ctl.DC_COHEN, we assume this platform does
52 * not support CM if the bit is hard-wired to 0.
53 */
54 if (csr_read(CSR_MCACHE_CTL) & MCACHE_CTL_DC_COHEN) {
55 /* Wait for DC_COHSTA bit to be set */
56 while (!(csr_read(CSR_MCACHE_CTL) & MCACHE_CTL_DC_COHSTA));
57 }
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080058 }
Leo Yu-Chi Liang96e75a82023-12-26 14:17:34 +080059
60 mmisc_ctl_val |= MMISC_CTL_NON_BLOCKING_EN;
61
62 csr_write(CSR_MMISC_CTL, mmisc_ctl_val);
Leo Yu-Chi Liang2795bf22021-09-23 10:34:29 +080063 }
64}