Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2022 StarFive Technology Co., Ltd. |
| 4 | * Author: Yanhong Wang<yanhong.wang@starfivetech.com> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 8 | #include <cpu_func.h> |
Yanhong Wang | 2b51743 | 2023-06-15 17:36:50 +0800 | [diff] [blame] | 9 | #include <dm.h> |
Heinrich Schuchardt | 329cd57 | 2023-09-07 13:21:28 +0200 | [diff] [blame] | 10 | #include <env.h> |
| 11 | #include <asm/arch/eeprom.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <asm/sections.h> |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 14 | #include <linux/bitops.h> |
| 15 | |
| 16 | #define JH7110_L2_PREFETCHER_BASE_ADDR 0x2030000 |
| 17 | #define JH7110_L2_PREFETCHER_HART_OFFSET 0x2000 |
Heinrich Schuchardt | 329cd57 | 2023-09-07 13:21:28 +0200 | [diff] [blame] | 18 | #define FDTFILE_VISIONFIVE2_1_2A \ |
| 19 | "starfive/jh7110-starfive-visionfive-2-v1.2a.dtb" |
| 20 | #define FDTFILE_VISIONFIVE2_1_3B \ |
| 21 | "starfive/jh7110-starfive-visionfive-2-v1.3b.dtb" |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 22 | |
| 23 | /* enable U74-mc hart1~hart4 prefetcher */ |
| 24 | static void enable_prefetcher(void) |
| 25 | { |
| 26 | u8 hart; |
| 27 | u32 *reg; |
| 28 | |
| 29 | /* JH7110 use U74MC CORE IP, it include five cores(one S7 and four U7), |
| 30 | * but only U7 cores support prefetcher configuration |
| 31 | */ |
| 32 | for (hart = 1; hart < 5; hart++) { |
| 33 | reg = (void *)(u64)(JH7110_L2_PREFETCHER_BASE_ADDR |
| 34 | + hart * JH7110_L2_PREFETCHER_HART_OFFSET); |
| 35 | |
| 36 | mb(); /* memory barrier */ |
| 37 | setbits_le32(reg, 0x1); |
| 38 | mb(); /* memory barrier */ |
| 39 | } |
| 40 | } |
| 41 | |
Heinrich Schuchardt | 329cd57 | 2023-09-07 13:21:28 +0200 | [diff] [blame] | 42 | /** |
| 43 | * set_fdtfile() - set the $fdtfile variable based on the board revision |
| 44 | */ |
| 45 | static void set_fdtfile(void) |
| 46 | { |
| 47 | u8 version; |
| 48 | const char *fdtfile; |
| 49 | |
| 50 | version = get_pcb_revision_from_eeprom(); |
| 51 | switch (version) { |
| 52 | case 'a': |
| 53 | case 'A': |
| 54 | fdtfile = FDTFILE_VISIONFIVE2_1_2A; |
| 55 | break; |
| 56 | |
| 57 | case 'b': |
| 58 | case 'B': |
| 59 | default: |
| 60 | fdtfile = FDTFILE_VISIONFIVE2_1_3B; |
| 61 | break; |
| 62 | }; |
| 63 | |
| 64 | env_set("fdtfile", fdtfile); |
| 65 | } |
| 66 | |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 67 | int board_init(void) |
| 68 | { |
| 69 | enable_caches(); |
| 70 | enable_prefetcher(); |
| 71 | |
| 72 | return 0; |
| 73 | } |
Yanhong Wang | 2b51743 | 2023-06-15 17:36:50 +0800 | [diff] [blame] | 74 | |
Heinrich Schuchardt | 329cd57 | 2023-09-07 13:21:28 +0200 | [diff] [blame] | 75 | int board_late_init(void) |
| 76 | { |
| 77 | if (CONFIG_IS_ENABLED(ID_EEPROM)) |
| 78 | set_fdtfile(); |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
Yanhong Wang | 2b51743 | 2023-06-15 17:36:50 +0800 | [diff] [blame] | 83 | void *board_fdt_blob_setup(int *err) |
| 84 | { |
| 85 | *err = 0; |
| 86 | if (IS_ENABLED(CONFIG_OF_SEPARATE) || IS_ENABLED(CONFIG_OF_BOARD)) { |
| 87 | if (gd->arch.firmware_fdt_addr) |
| 88 | return (ulong *)(uintptr_t)gd->arch.firmware_fdt_addr; |
| 89 | } |
| 90 | |
Shiji Yang | eff11fa | 2023-08-03 09:47:17 +0800 | [diff] [blame] | 91 | return (ulong *)_end; |
Yanhong Wang | 2b51743 | 2023-06-15 17:36:50 +0800 | [diff] [blame] | 92 | } |