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