blob: f6114602f88008ba9519d9413ee7f04a831df88f [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"
H Bell25ce7c92024-05-22 19:12:48 +000030#define FDTFILE_PINE64_STAR64 \
31 "starfive/jh7110-pine64-star64.dtb"
Yanhong Wang6a5a45d2023-03-29 11:42:17 +080032
33/* enable U74-mc hart1~hart4 prefetcher */
34static 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 Schuchardt03a885b2023-09-07 13:21:28 +020052/**
53 * set_fdtfile() - set the $fdtfile variable based on the board revision
54 */
55static void set_fdtfile(void)
56{
57 u8 version;
58 const char *fdtfile;
Heinrich Schuchardt328acb12024-04-02 10:49:09 +020059 const char *product_id;
Heinrich Schuchardt03a885b2023-09-07 13:21:28 +020060
Heinrich Schuchardt6bb737b2024-04-02 10:49:07 +020061 fdtfile = env_get("fdtfile");
62 if (fdtfile)
63 return;
64
Heinrich Schuchardt328acb12024-04-02 10:49:09 +020065 product_id = get_product_id_from_eeprom();
66 if (!product_id) {
67 log_err("Can't read EEPROM\n");
68 return;
69 }
Heinrich Schuchardtadaa12d2024-05-12 06:25:23 +020070 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 Schuchardt328acb12024-04-02 10:49:09 +020076 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 Schuchardt03a885b2023-09-07 13:21:28 +020085
Heinrich Schuchardt328acb12024-04-02 10:49:09 +020086 case 'b':
87 case 'B':
88 default:
89 fdtfile = FDTFILE_VISIONFIVE2_1_3B;
90 break;
91 }
H Bell25ce7c92024-05-22 19:12:48 +000092 } else if (!strncmp(product_id, "STAR64", 6)) {
93 fdtfile = FDTFILE_PINE64_STAR64;
Heinrich Schuchardt328acb12024-04-02 10:49:09 +020094 } else {
95 log_err("Unknown product\n");
96 return;
97 }
Heinrich Schuchardt03a885b2023-09-07 13:21:28 +020098
99 env_set("fdtfile", fdtfile);
100}
101
Yanhong Wang6a5a45d2023-03-29 11:42:17 +0800102int board_init(void)
103{
104 enable_caches();
105 enable_prefetcher();
106
107 return 0;
108}
Yanhong Wang2b517432023-06-15 17:36:50 +0800109
Heinrich Schuchardt03a885b2023-09-07 13:21:28 +0200110int board_late_init(void)
111{
112 if (CONFIG_IS_ENABLED(ID_EEPROM))
113 set_fdtfile();
114
115 return 0;
116}
117
Yanhong Wang2b517432023-06-15 17:36:50 +0800118void *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 Yangeff11fa2023-08-03 09:47:17 +0800126 return (ulong *)_end;
Yanhong Wang2b517432023-06-15 17:36:50 +0800127}
Shengyu Quf4af7182023-09-17 03:36:33 +0800128
129int ft_board_setup(void *blob, struct bd_info *bd)
130{
131 return fdt_fixup_memory(blob, 0x40000000, gd->ram_size);
132}