Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rick Chen | e76b804 | 2017-12-26 13:55:48 +0800 | [diff] [blame] | 2 | /* |
Yu Chien Peter Lin | 82f0f53 | 2023-02-06 16:10:47 +0800 | [diff] [blame] | 3 | * Copyright (C) 2023 Andes Technology Corporation |
Rick Chen | e76b804 | 2017-12-26 13:55:48 +0800 | [diff] [blame] | 4 | * Rick Chen, Andes Technology Corporation <rick@andestech.com> |
Rick Chen | e76b804 | 2017-12-26 13:55:48 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* CPU specific code */ |
| 8 | #include <common.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 10 | #include <irq_func.h> |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 11 | #include <asm/cache.h> |
Leo Yu-Chi Liang | 2795bf2 | 2021-09-23 10:34:29 +0800 | [diff] [blame] | 12 | #include <asm/csr.h> |
Yu Chien Peter Lin | 82f0f53 | 2023-02-06 16:10:47 +0800 | [diff] [blame] | 13 | #include <asm/arch-andes/csr.h> |
Rick Chen | e76b804 | 2017-12-26 13:55:48 +0800 | [diff] [blame] | 14 | |
| 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 | */ |
| 21 | int cleanup_before_linux(void) |
| 22 | { |
| 23 | disable_interrupts(); |
| 24 | |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 25 | cache_flush(); |
Rick Chen | e76b804 | 2017-12-26 13:55:48 +0800 | [diff] [blame] | 26 | |
| 27 | return 0; |
| 28 | } |
Leo Yu-Chi Liang | 2795bf2 | 2021-09-23 10:34:29 +0800 | [diff] [blame] | 29 | |
| 30 | void harts_early_init(void) |
| 31 | { |
Yu Chien Peter Lin | 82f0f53 | 2023-02-06 16:10:47 +0800 | [diff] [blame] | 32 | /* Enable I/D-cache in SPL */ |
Leo Yu-Chi Liang | 2795bf2 | 2021-09-23 10:34:29 +0800 | [diff] [blame] | 33 | if (CONFIG_IS_ENABLED(RISCV_MMODE)) { |
Yu Chien Peter Lin | 82f0f53 | 2023-02-06 16:10:47 +0800 | [diff] [blame] | 34 | unsigned long mcache_ctl_val = csr_read(CSR_MCACHE_CTL); |
Leo Yu-Chi Liang | 2795bf2 | 2021-09-23 10:34:29 +0800 | [diff] [blame] | 35 | |
Yu Chien Peter Lin | 82f0f53 | 2023-02-06 16:10:47 +0800 | [diff] [blame] | 36 | mcache_ctl_val |= (MCACHE_CTL_DC_COHEN | MCACHE_CTL_IC_EN | |
| 37 | MCACHE_CTL_DC_EN | MCACHE_CTL_CCTL_SUEN); |
| 38 | |
Leo Yu-Chi Liang | 2795bf2 | 2021-09-23 10:34:29 +0800 | [diff] [blame] | 39 | csr_write(CSR_MCACHE_CTL, mcache_ctl_val); |
| 40 | |
| 41 | /* |
Yu Chien Peter Lin | 82f0f53 | 2023-02-06 16:10:47 +0800 | [diff] [blame] | 42 | * 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 Liang | 2795bf2 | 2021-09-23 10:34:29 +0800 | [diff] [blame] | 44 | */ |
Yu Chien Peter Lin | 82f0f53 | 2023-02-06 16:10:47 +0800 | [diff] [blame] | 45 | 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 Liang | 2795bf2 | 2021-09-23 10:34:29 +0800 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | } |