blob: a86bca533b2ff43c8be89306b6e4953cb2c99636 [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 Schuchardt03a885b2023-09-07 13:21:28 +020022#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 Wang6a5a45d2023-03-29 11:42:17 +080026
27/* enable U74-mc hart1~hart4 prefetcher */
28static 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 Schuchardt03a885b2023-09-07 13:21:28 +020046/**
47 * set_fdtfile() - set the $fdtfile variable based on the board revision
48 */
49static void set_fdtfile(void)
50{
51 u8 version;
52 const char *fdtfile;
Heinrich Schuchardt328acb12024-04-02 10:49:09 +020053 const char *product_id;
Heinrich Schuchardt03a885b2023-09-07 13:21:28 +020054
Heinrich Schuchardt6bb737b2024-04-02 10:49:07 +020055 fdtfile = env_get("fdtfile");
56 if (fdtfile)
57 return;
58
Heinrich Schuchardt328acb12024-04-02 10:49:09 +020059 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 Schuchardt03a885b2023-09-07 13:21:28 +020074
Heinrich Schuchardt328acb12024-04-02 10:49:09 +020075 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 Schuchardt03a885b2023-09-07 13:21:28 +020085
86 env_set("fdtfile", fdtfile);
87}
88
Yanhong Wang6a5a45d2023-03-29 11:42:17 +080089int board_init(void)
90{
91 enable_caches();
92 enable_prefetcher();
93
94 return 0;
95}
Yanhong Wang2b517432023-06-15 17:36:50 +080096
Heinrich Schuchardt03a885b2023-09-07 13:21:28 +020097int board_late_init(void)
98{
99 if (CONFIG_IS_ENABLED(ID_EEPROM))
100 set_fdtfile();
101
102 return 0;
103}
104
Yanhong Wang2b517432023-06-15 17:36:50 +0800105void *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 Yangeff11fa2023-08-03 09:47:17 +0800113 return (ulong *)_end;
Yanhong Wang2b517432023-06-15 17:36:50 +0800114}
Shengyu Quf4af7182023-09-17 03:36:33 +0800115
116int ft_board_setup(void *blob, struct bd_info *bd)
117{
118 return fdt_fixup_memory(blob, 0x40000000, gd->ram_size);
119}