blob: 38132ecccd31f67b1e96ca7ec7b265f32c749ddc [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 Wang4e321fa2023-06-15 17:36:52 +08007#include <asm/arch/eeprom.h>
Chanho Park9ca68c92023-10-31 17:56:00 +09008#include <asm/arch/gpio.h>
Yanhong Wang6a5a45d2023-03-29 11:42:17 +08009#include <asm/arch/regs.h>
10#include <asm/arch/spl.h>
11#include <asm/io.h>
Yanhong Wang4e321fa2023-06-15 17:36:52 +080012#include <dt-bindings/clock/starfive,jh7110-crg.h>
13#include <fdt_support.h>
14#include <linux/libfdt.h>
Yanhong Wang6a5a45d2023-03-29 11:42:17 +080015#include <log.h>
16#include <spl.h>
17
Yanhong Wang4e321fa2023-06-15 17:36:52 +080018DECLARE_GLOBAL_DATA_PTR;
Yanhong Wang6a5a45d2023-03-29 11:42:17 +080019#define JH7110_CLK_CPU_ROOT_OFFSET 0x0U
20#define JH7110_CLK_CPU_ROOT_SHIFT 24
21#define JH7110_CLK_CPU_ROOT_MASK GENMASK(29, 24)
22
Yanhong Wang4e321fa2023-06-15 17:36:52 +080023void spl_perform_fixups(struct spl_image_info *spl_image)
24{
Heinrich Schuchardtf8841732024-04-02 10:49:10 +020025 /* Update the memory size which read from eeprom or DT */
Yanhong Wang4e321fa2023-06-15 17:36:52 +080026 fdt_fixup_memory(spl_image->fdt_addr, 0x40000000, gd->ram_size);
27}
Chanho Park9ca68c92023-10-31 17:56:00 +090028
29static void jh7110_jtag_init(void)
30{
31 /* nTRST: GPIO36 */
32 SYS_IOMUX_DOEN(36, HIGH);
33 SYS_IOMUX_DIN(36, 4);
34 /* TDI: GPIO61 */
35 SYS_IOMUX_DOEN(61, HIGH);
36 SYS_IOMUX_DIN(61, 19);
37 /* TMS: GPIO63 */
38 SYS_IOMUX_DOEN(63, HIGH);
39 SYS_IOMUX_DIN(63, 20);
40 /* TCK: GPIO60 */
41 SYS_IOMUX_DOEN(60, HIGH);
42 SYS_IOMUX_DIN(60, 29);
43 /* TDO: GPIO44 */
44 SYS_IOMUX_DOEN(44, 8);
45 SYS_IOMUX_DOUT(44, 22);
46}
47
Yanhong Wang6a5a45d2023-03-29 11:42:17 +080048int spl_board_init_f(void)
49{
50 int ret;
51
Chanho Park9ca68c92023-10-31 17:56:00 +090052 jh7110_jtag_init();
53
Lukas Funke2b62dd62024-04-24 09:43:39 +020054 ret = spl_dram_init();
Yanhong Wang6a5a45d2023-03-29 11:42:17 +080055 if (ret) {
Lukas Funke2b62dd62024-04-24 09:43:39 +020056 debug("JH7110 DRAM init failed: %d\n", ret);
Yanhong Wang6a5a45d2023-03-29 11:42:17 +080057 return ret;
58 }
59
60 return 0;
61}
62
63u32 spl_boot_device(void)
64{
65 u32 mode;
66
67 mode = in_le32(JH7110_BOOT_MODE_SELECT_REG)
68 & JH7110_BOOT_MODE_SELECT_MASK;
69 switch (mode) {
70 case 0:
71 return BOOT_DEVICE_SPI;
72
73 case 1:
74 return BOOT_DEVICE_MMC2;
75
76 case 2:
77 return BOOT_DEVICE_MMC1;
78
79 case 3:
80 return BOOT_DEVICE_UART;
81
82 default:
83 debug("Unsupported boot device 0x%x.\n", mode);
84 return BOOT_DEVICE_NONE;
85 }
86}
87
88void board_init_f(ulong dummy)
89{
90 int ret;
91
92 ret = spl_early_init();
93 if (ret)
94 panic("spl_early_init() failed: %d\n", ret);
95
Simon Glassb8357c12023-08-21 21:16:56 -060096 riscv_cpu_setup();
Yanhong Wang6a5a45d2023-03-29 11:42:17 +080097 preloader_console_init();
98
99 /* Set the parent clock of cpu_root clock to pll0,
100 * it must be initialized here
101 */
102 clrsetbits_le32(JH7110_SYS_CRG + JH7110_CLK_CPU_ROOT_OFFSET,
103 JH7110_CLK_CPU_ROOT_MASK,
104 BIT(JH7110_CLK_CPU_ROOT_SHIFT));
105
106 ret = spl_board_init_f();
107 if (ret) {
108 debug("spl_board_init_f init failed: %d\n", ret);
109 return;
110 }
111}
112
113#if CONFIG_IS_ENABLED(SPL_LOAD_FIT)
114int board_fit_config_name_match(const char *name)
115{
116 /* boot using first FIT config */
117 return 0;
118}
119#endif