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