summaryrefslogtreecommitdiff
path: root/board/starfive/devkits/spl.c
blob: d5f43b4747b00ca5c93aeea8efa30044d77a2187 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2022-2023 StarFive Technology Co., Ltd.
 * Author:	yanhong <yanhong.wang@starfivetech.com>
 *
 */

#include <common.h>
#include <init.h>
#include <asm/arch/spl.h>
#include <asm/io.h>
#include <asm/arch/gpio.h>
#include <asm/arch/jh7110-regs.h>
#include <asm/arch/clk.h>
#include <image.h>
#include <log.h>
#include <spl.h>

#define MODE_SELECT_REG		0x1702002c

int spl_board_init_f(void)
{
	int ret;

	ret = spl_soc_init();
	if (ret) {
		debug("JH7110 SPL init failed: %d\n", ret);
		return ret;
	}

	return 0;
}

u32 spl_boot_device(void)
{
	int boot_mode = 0;

	boot_mode = readl((const volatile void *)MODE_SELECT_REG) & 0x3;
	switch (boot_mode) {
	case 0:
		return BOOT_DEVICE_SPI;
	case 1:
		return BOOT_DEVICE_MMC2;
	case 2:
		return BOOT_DEVICE_MMC1;
	case 3:
		return BOOT_DEVICE_UART;
	default:
		debug("Unsupported boot device 0x%x.\n",
		      boot_mode);
		return BOOT_DEVICE_NONE;
	}
}

struct image_header *spl_get_load_buffer(ssize_t offset, size_t size)
{
	return (struct image_header *)(STARFIVE_SPL_BOOT_LOAD_ADDR);
}

void board_init_f(ulong dummy)
{
	int ret;

	/* Adjust cpu frequency, the default is 1.0GHz */
	starfive_jh7110_pll_set_rate(PLL0, 1000000000);

	/*change pll2 to 1188MHz*/
	starfive_jh7110_pll_set_rate(PLL2, 1188000000);

	/*DDR control depend clk init*/
	clrsetbits_le32(SYS_CRG_BASE, CLK_CPU_ROOT_SW_MASK,
		BIT(CLK_CPU_ROOT_SW_SHIFT) & CLK_CPU_ROOT_SW_MASK);

	clrsetbits_le32(SYS_CRG_BASE + CLK_BUS_ROOT_OFFSET,
		CLK_BUS_ROOT_SW_MASK,
		BIT(CLK_BUS_ROOT_SW_SHIFT) & CLK_BUS_ROOT_SW_MASK);

	/*Set clk_perh_root clk default mux sel to pll2*/
	clrsetbits_le32(SYS_CRG_BASE + CLK_PERH_ROOT_OFFSET,
		CLK_PERH_ROOT_MASK,
		BIT(CLK_PERH_ROOT_SHIFT) & CLK_PERH_ROOT_MASK);

	clrsetbits_le32(SYS_CRG_BASE + CLK_NOC_BUS_STG_AXI_OFFSET,
		CLK_NOC_BUS_STG_AXI_EN_MASK,
		BIT(CLK_NOC_BUS_STG_AXI_EN_SHIFT)
		& CLK_NOC_BUS_STG_AXI_EN_MASK);

	clrsetbits_le32(AON_CRG_BASE + CLK_AON_APB_FUNC_OFFSET,
		CLK_AON_APB_FUNC_SW_MASK,
		BIT(CLK_AON_APB_FUNC_SW_SHIFT) & CLK_AON_APB_FUNC_SW_MASK);

	/* switch qspi clk to pll0 */
	clrsetbits_le32(SYS_CRG_BASE + CLK_QSPI_REF_OFFSET,
			CLK_QSPI_REF_SW_MASK,
			BIT(CLK_QSPI_REF_SW_SHIFT) & CLK_QSPI_REF_SW_MASK);

	/*set GPIO to 3.3v*/
	setbits_le32(SYS_SYSCON_BASE + 0xC, 0x0);

	/* Improved GMAC0 TX I/O PAD capability */
	clrsetbits_le32(AON_IOMUX_BASE + 0x78, 0x3, BIT(0) & 0x3);
	clrsetbits_le32(AON_IOMUX_BASE + 0x7c, 0x3, BIT(0) & 0x3);
	clrsetbits_le32(AON_IOMUX_BASE + 0x80, 0x3, BIT(0) & 0x3);
	clrsetbits_le32(AON_IOMUX_BASE + 0x84, 0x3, BIT(0) & 0x3);
	clrsetbits_le32(AON_IOMUX_BASE + 0x88, 0x3, BIT(0) & 0x3);

	/* Improved GMAC1 TX I/O PAD capability */
	clrsetbits_le32(SYS_IOMUX_BASE + 0x26c, 0x3, BIT(0) & 0x3);
	clrsetbits_le32(SYS_IOMUX_BASE + 0x270, 0x3, BIT(0) & 0x3);
	clrsetbits_le32(SYS_IOMUX_BASE + 0x274, 0x3, BIT(0) & 0x3);
	clrsetbits_le32(SYS_IOMUX_BASE + 0x278, 0x3, BIT(0) & 0x3);
	clrsetbits_le32(SYS_IOMUX_BASE + 0x27c, 0x3, BIT(0) & 0x3);

	SYS_IOMUX_DOEN(62, LOW);
	SYS_IOMUX_DOUT(62, 19);
	SYS_IOMUX_SET_DS(64, 2);
	SYS_IOMUX_SET_SLEW(64, 1);
	SYS_IOMUX_SET_DS(65, 1);
	SYS_IOMUX_SET_DS(66, 1);
	SYS_IOMUX_SET_DS(67, 1);
	SYS_IOMUX_SET_DS(68, 1);
	SYS_IOMUX_SET_DS(69, 1);
	SYS_IOMUX_SET_DS(70, 1);
	SYS_IOMUX_SET_DS(71, 1);
	SYS_IOMUX_SET_DS(72, 1);
	SYS_IOMUX_SET_DS(73, 1);

	SYS_IOMUX_DOEN(10, LOW);
	SYS_IOMUX_DOUT(10, 55);
	SYS_IOMUX_SET_SLEW(10, 1);
	SYS_IOMUX_SET_DS(10, 2);
	SYS_IOMUX_COMPLEX(9, 44, 57, 19);
	SYS_IOMUX_SET_DS(9, 1);
	SYS_IOMUX_COMPLEX(11, 45, 58, 20);
	SYS_IOMUX_SET_DS(11, 1);
	SYS_IOMUX_COMPLEX(12, 46, 59, 21);
	SYS_IOMUX_SET_DS(12, 1);
	SYS_IOMUX_COMPLEX(7, 47, 60, 22);
	SYS_IOMUX_SET_DS(7, 1);
	SYS_IOMUX_COMPLEX(8, 48, 61, 23);
	SYS_IOMUX_SET_DS(8, 1);

	ret = spl_early_init();
	if (ret)
		panic("spl_early_init() failed: %d\n", ret);

	arch_cpu_init_dm();

	preloader_console_init();

	ret = spl_board_init_f();
	if (ret) {
		debug("spl_board_init_f init failed: %d\n", ret);
		return;
	}
}

#ifdef CONFIG_SPL_LOAD_FIT
int board_fit_config_name_match(const char *name)
{
	/* boot using first FIT config */
	return 0;
}
#endif