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 | |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 7 | #include <cpu_func.h> |
Yanhong Wang | 2b51743 | 2023-06-15 17:36:50 +0800 | [diff] [blame] | 8 | #include <dm.h> |
Shengyu Qu | f4af718 | 2023-09-17 03:36:33 +0800 | [diff] [blame] | 9 | #include <fdt_support.h> |
Heinrich Schuchardt | 03a885b | 2023-09-07 13:21:28 +0200 | [diff] [blame] | 10 | #include <env.h> |
Heinrich Schuchardt | 328acb1 | 2024-04-02 10:49:09 +0200 | [diff] [blame] | 11 | #include <log.h> |
Heinrich Schuchardt | 03a885b | 2023-09-07 13:21:28 +0200 | [diff] [blame] | 12 | #include <asm/arch/eeprom.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <asm/sections.h> |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 15 | #include <linux/bitops.h> |
| 16 | |
Shengyu Qu | f4af718 | 2023-09-17 03:36:33 +0800 | [diff] [blame] | 17 | DECLARE_GLOBAL_DATA_PTR; |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 18 | #define JH7110_L2_PREFETCHER_BASE_ADDR 0x2030000 |
| 19 | #define JH7110_L2_PREFETCHER_HART_OFFSET 0x2000 |
Heinrich Schuchardt | 328acb1 | 2024-04-02 10:49:09 +0200 | [diff] [blame] | 20 | #define FDTFILE_MILK_V_MARS \ |
| 21 | "starfive/jh7110-milkv-mars.dtb" |
Heinrich Schuchardt | 03a885b | 2023-09-07 13:21:28 +0200 | [diff] [blame] | 22 | #define FDTFILE_VISIONFIVE2_1_2A \ |
| 23 | "starfive/jh7110-starfive-visionfive-2-v1.2a.dtb" |
| 24 | #define FDTFILE_VISIONFIVE2_1_3B \ |
| 25 | "starfive/jh7110-starfive-visionfive-2-v1.3b.dtb" |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 26 | |
| 27 | /* enable U74-mc hart1~hart4 prefetcher */ |
| 28 | static void enable_prefetcher(void) |
| 29 | { |
| 30 | u8 hart; |
| 31 | u32 *reg; |
| 32 | |
| 33 | /* JH7110 use U74MC CORE IP, it include five cores(one S7 and four U7), |
| 34 | * but only U7 cores support prefetcher configuration |
| 35 | */ |
| 36 | for (hart = 1; hart < 5; hart++) { |
| 37 | reg = (void *)(u64)(JH7110_L2_PREFETCHER_BASE_ADDR |
| 38 | + hart * JH7110_L2_PREFETCHER_HART_OFFSET); |
| 39 | |
| 40 | mb(); /* memory barrier */ |
| 41 | setbits_le32(reg, 0x1); |
| 42 | mb(); /* memory barrier */ |
| 43 | } |
| 44 | } |
| 45 | |
Heinrich Schuchardt | 03a885b | 2023-09-07 13:21:28 +0200 | [diff] [blame] | 46 | /** |
| 47 | * set_fdtfile() - set the $fdtfile variable based on the board revision |
| 48 | */ |
| 49 | static void set_fdtfile(void) |
| 50 | { |
| 51 | u8 version; |
| 52 | const char *fdtfile; |
Heinrich Schuchardt | 328acb1 | 2024-04-02 10:49:09 +0200 | [diff] [blame] | 53 | const char *product_id; |
Heinrich Schuchardt | 03a885b | 2023-09-07 13:21:28 +0200 | [diff] [blame] | 54 | |
Heinrich Schuchardt | 6bb737b | 2024-04-02 10:49:07 +0200 | [diff] [blame] | 55 | fdtfile = env_get("fdtfile"); |
| 56 | if (fdtfile) |
| 57 | return; |
| 58 | |
Heinrich Schuchardt | 328acb1 | 2024-04-02 10:49:09 +0200 | [diff] [blame] | 59 | product_id = get_product_id_from_eeprom(); |
| 60 | if (!product_id) { |
| 61 | log_err("Can't read EEPROM\n"); |
| 62 | return; |
| 63 | } |
| 64 | if (!strncmp(product_id, "MARS", 4)) { |
| 65 | fdtfile = FDTFILE_MILK_V_MARS; |
| 66 | } else if (!strncmp(product_id, "VF7110", 6)) { |
| 67 | version = get_pcb_revision_from_eeprom(); |
| 68 | |
| 69 | switch (version) { |
| 70 | case 'a': |
| 71 | case 'A': |
| 72 | fdtfile = FDTFILE_VISIONFIVE2_1_2A; |
| 73 | break; |
Heinrich Schuchardt | 03a885b | 2023-09-07 13:21:28 +0200 | [diff] [blame] | 74 | |
Heinrich Schuchardt | 328acb1 | 2024-04-02 10:49:09 +0200 | [diff] [blame] | 75 | case 'b': |
| 76 | case 'B': |
| 77 | default: |
| 78 | fdtfile = FDTFILE_VISIONFIVE2_1_3B; |
| 79 | break; |
| 80 | } |
| 81 | } else { |
| 82 | log_err("Unknown product\n"); |
| 83 | return; |
| 84 | } |
Heinrich Schuchardt | 03a885b | 2023-09-07 13:21:28 +0200 | [diff] [blame] | 85 | |
| 86 | env_set("fdtfile", fdtfile); |
| 87 | } |
| 88 | |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 89 | int board_init(void) |
| 90 | { |
| 91 | enable_caches(); |
| 92 | enable_prefetcher(); |
| 93 | |
| 94 | return 0; |
| 95 | } |
Yanhong Wang | 2b51743 | 2023-06-15 17:36:50 +0800 | [diff] [blame] | 96 | |
Heinrich Schuchardt | 03a885b | 2023-09-07 13:21:28 +0200 | [diff] [blame] | 97 | int board_late_init(void) |
| 98 | { |
| 99 | if (CONFIG_IS_ENABLED(ID_EEPROM)) |
| 100 | set_fdtfile(); |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
Yanhong Wang | 2b51743 | 2023-06-15 17:36:50 +0800 | [diff] [blame] | 105 | void *board_fdt_blob_setup(int *err) |
| 106 | { |
| 107 | *err = 0; |
| 108 | if (IS_ENABLED(CONFIG_OF_SEPARATE) || IS_ENABLED(CONFIG_OF_BOARD)) { |
| 109 | if (gd->arch.firmware_fdt_addr) |
| 110 | return (ulong *)(uintptr_t)gd->arch.firmware_fdt_addr; |
| 111 | } |
| 112 | |
Shiji Yang | eff11fa | 2023-08-03 09:47:17 +0800 | [diff] [blame] | 113 | return (ulong *)_end; |
Yanhong Wang | 2b51743 | 2023-06-15 17:36:50 +0800 | [diff] [blame] | 114 | } |
Shengyu Qu | f4af718 | 2023-09-17 03:36:33 +0800 | [diff] [blame] | 115 | |
| 116 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 117 | { |
| 118 | return fdt_fixup_memory(blob, 0x40000000, gd->ram_size); |
| 119 | } |