blob: 6be534896260d318219648b12e64b01fda0cb474 [file] [log] [blame]
Yanhong Wang6a5a45d2023-03-29 11:42:17 +08001// 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 Wang6a5a45d2023-03-29 11:42:17 +08007#include <cpu_func.h>
Yanhong Wang2b517432023-06-15 17:36:50 +08008#include <dm.h>
Shengyu Quf4af7182023-09-17 03:36:33 +08009#include <fdt_support.h>
Heinrich Schuchardt03a885b2023-09-07 13:21:28 +020010#include <env.h>
Heinrich Schuchardt328acb12024-04-02 10:49:09 +020011#include <log.h>
Heinrich Schuchardt03a885b2023-09-07 13:21:28 +020012#include <asm/arch/eeprom.h>
13#include <asm/io.h>
14#include <asm/sections.h>
Yanhong Wang6a5a45d2023-03-29 11:42:17 +080015#include <linux/bitops.h>
16
Shengyu Quf4af7182023-09-17 03:36:33 +080017DECLARE_GLOBAL_DATA_PTR;
Yanhong Wang6a5a45d2023-03-29 11:42:17 +080018#define JH7110_L2_PREFETCHER_BASE_ADDR 0x2030000
19#define JH7110_L2_PREFETCHER_HART_OFFSET 0x2000
Heinrich Schuchardt328acb12024-04-02 10:49:09 +020020#define FDTFILE_MILK_V_MARS \
21 "starfive/jh7110-milkv-mars.dtb"
Heinrich Schuchardtadaa12d2024-05-12 06:25:23 +020022#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 Schuchardt03a885b2023-09-07 13:21:28 +020026#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 Wang6a5a45d2023-03-29 11:42:17 +080030
31/* enable U74-mc hart1~hart4 prefetcher */
32static 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 Schuchardt03a885b2023-09-07 13:21:28 +020050/**
51 * set_fdtfile() - set the $fdtfile variable based on the board revision
52 */
53static void set_fdtfile(void)
54{
55 u8 version;
56 const char *fdtfile;
Heinrich Schuchardt328acb12024-04-02 10:49:09 +020057 const char *product_id;
Heinrich Schuchardt03a885b2023-09-07 13:21:28 +020058
Heinrich Schuchardt6bb737b2024-04-02 10:49:07 +020059 fdtfile = env_get("fdtfile");
60 if (fdtfile)
61 return;
62
Heinrich Schuchardt328acb12024-04-02 10:49:09 +020063 product_id = get_product_id_from_eeprom();
64 if (!product_id) {
65 log_err("Can't read EEPROM\n");
66 return;
67 }
Heinrich Schuchardtadaa12d2024-05-12 06:25:23 +020068 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 Schuchardt328acb12024-04-02 10:49:09 +020074 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 Schuchardt03a885b2023-09-07 13:21:28 +020083
Heinrich Schuchardt328acb12024-04-02 10:49:09 +020084 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 Schuchardt03a885b2023-09-07 13:21:28 +020094
95 env_set("fdtfile", fdtfile);
96}
97
Yanhong Wang6a5a45d2023-03-29 11:42:17 +080098int board_init(void)
99{
100 enable_caches();
101 enable_prefetcher();
102
103 return 0;
104}
Yanhong Wang2b517432023-06-15 17:36:50 +0800105
Heinrich Schuchardt03a885b2023-09-07 13:21:28 +0200106int board_late_init(void)
107{
108 if (CONFIG_IS_ENABLED(ID_EEPROM))
109 set_fdtfile();
110
111 return 0;
112}
113
Yanhong Wang2b517432023-06-15 17:36:50 +0800114void *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 Yangeff11fa2023-08-03 09:47:17 +0800122 return (ulong *)_end;
Yanhong Wang2b517432023-06-15 17:36:50 +0800123}
Shengyu Quf4af7182023-09-17 03:36:33 +0800124
125int ft_board_setup(void *blob, struct bd_info *bd)
126{
127 return fdt_fixup_memory(blob, 0x40000000, gd->ram_size);
128}