blob: 05d8d2d657c03e8ae455dec76290953c91f4995e [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
7#include <common.h>
Yanhong Wang6a5a45d2023-03-29 11:42:17 +08008#include <cpu_func.h>
Yanhong Wang2b517432023-06-15 17:36:50 +08009#include <dm.h>
Heinrich Schuchardt329cd572023-09-07 13:21:28 +020010#include <env.h>
11#include <asm/arch/eeprom.h>
12#include <asm/io.h>
13#include <asm/sections.h>
Yanhong Wang6a5a45d2023-03-29 11:42:17 +080014#include <linux/bitops.h>
15
16#define JH7110_L2_PREFETCHER_BASE_ADDR 0x2030000
17#define JH7110_L2_PREFETCHER_HART_OFFSET 0x2000
Heinrich Schuchardt329cd572023-09-07 13:21:28 +020018#define FDTFILE_VISIONFIVE2_1_2A \
19 "starfive/jh7110-starfive-visionfive-2-v1.2a.dtb"
20#define FDTFILE_VISIONFIVE2_1_3B \
21 "starfive/jh7110-starfive-visionfive-2-v1.3b.dtb"
Yanhong Wang6a5a45d2023-03-29 11:42:17 +080022
23/* enable U74-mc hart1~hart4 prefetcher */
24static void enable_prefetcher(void)
25{
26 u8 hart;
27 u32 *reg;
28
29 /* JH7110 use U74MC CORE IP, it include five cores(one S7 and four U7),
30 * but only U7 cores support prefetcher configuration
31 */
32 for (hart = 1; hart < 5; hart++) {
33 reg = (void *)(u64)(JH7110_L2_PREFETCHER_BASE_ADDR
34 + hart * JH7110_L2_PREFETCHER_HART_OFFSET);
35
36 mb(); /* memory barrier */
37 setbits_le32(reg, 0x1);
38 mb(); /* memory barrier */
39 }
40}
41
Heinrich Schuchardt329cd572023-09-07 13:21:28 +020042/**
43 * set_fdtfile() - set the $fdtfile variable based on the board revision
44 */
45static void set_fdtfile(void)
46{
47 u8 version;
48 const char *fdtfile;
49
50 version = get_pcb_revision_from_eeprom();
51 switch (version) {
52 case 'a':
53 case 'A':
54 fdtfile = FDTFILE_VISIONFIVE2_1_2A;
55 break;
56
57 case 'b':
58 case 'B':
59 default:
60 fdtfile = FDTFILE_VISIONFIVE2_1_3B;
61 break;
62 };
63
64 env_set("fdtfile", fdtfile);
65}
66
Yanhong Wang6a5a45d2023-03-29 11:42:17 +080067int board_init(void)
68{
69 enable_caches();
70 enable_prefetcher();
71
72 return 0;
73}
Yanhong Wang2b517432023-06-15 17:36:50 +080074
Heinrich Schuchardt329cd572023-09-07 13:21:28 +020075int board_late_init(void)
76{
77 if (CONFIG_IS_ENABLED(ID_EEPROM))
78 set_fdtfile();
79
80 return 0;
81}
82
Yanhong Wang2b517432023-06-15 17:36:50 +080083void *board_fdt_blob_setup(int *err)
84{
85 *err = 0;
86 if (IS_ENABLED(CONFIG_OF_SEPARATE) || IS_ENABLED(CONFIG_OF_BOARD)) {
87 if (gd->arch.firmware_fdt_addr)
88 return (ulong *)(uintptr_t)gd->arch.firmware_fdt_addr;
89 }
90
Shiji Yangeff11fa2023-08-03 09:47:17 +080091 return (ulong *)_end;
Yanhong Wang2b517432023-06-15 17:36:50 +080092}