blob: 8f3e5dc6a346bc39d4605a5d6e9cd7b87cbbdba7 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese0299c902015-10-20 15:14:47 +02002/*
3 * Copyright (C) 2015 Stefan Roese <sr@denx.de>
Stefan Roese0299c902015-10-20 15:14:47 +02004 */
5
6#include <common.h>
7#include <i2c.h>
8#include <miiphy.h>
9#include <netdev.h>
10#include <asm/io.h>
11#include <asm/arch/cpu.h>
12#include <asm/arch/soc.h>
Baruch Siacha2e41ad2020-01-20 14:20:11 +020013#include "../common/tlv_data.h"
Stefan Roese0299c902015-10-20 15:14:47 +020014
Chris Packham2b4ffbf2018-05-10 13:28:29 +120015#include "../drivers/ddr/marvell/a38x/ddr3_init.h"
Stefan Roese0299c902015-10-20 15:14:47 +020016#include <../serdes/a38x/high_speed_env_spec.h>
17
18DECLARE_GLOBAL_DATA_PTR;
19
Stefan Roese0299c902015-10-20 15:14:47 +020020/*
21 * Those values and defines are taken from the Marvell U-Boot version
22 * "u-boot-2013.01-15t1-clearfog"
23 */
24#define BOARD_GPP_OUT_ENA_LOW 0xffffffff
25#define BOARD_GPP_OUT_ENA_MID 0xffffffff
26
27#define BOARD_GPP_OUT_VAL_LOW 0x0
28#define BOARD_GPP_OUT_VAL_MID 0x0
29#define BOARD_GPP_POL_LOW 0x0
30#define BOARD_GPP_POL_MID 0x0
31
Baruch Siacha2e41ad2020-01-20 14:20:11 +020032static struct tlv_data cf_tlv_data;
33
34static void cf_read_tlv_data(void)
35{
36 static bool read_once;
37
38 if (read_once)
39 return;
40 read_once = true;
41
42 read_tlv_data(&cf_tlv_data);
43}
44
Joel Johnson9f205d62020-03-23 14:21:32 -060045/* The starting board_serdes_map reflects original Clearfog Pro usage */
Stefan Roese0299c902015-10-20 15:14:47 +020046static struct serdes_map board_serdes_map[] = {
47 {SATA0, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 0},
48 {SGMII1, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
49 {PEX1, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
50 {USB3_HOST1, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
51 {PEX2, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
52 {SGMII2, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
53};
54
Joel Johnson9f205d62020-03-23 14:21:32 -060055void config_cfbase_serdes_map(void)
56{
57 board_serdes_map[4].serdes_type = USB3_HOST0;
58 board_serdes_map[4].serdes_speed = SERDES_SPEED_5_GBPS;
59 board_serdes_map[4].serdes_mode = SERDES_DEFAULT_MODE;
60}
61
Stefan Roese0299c902015-10-20 15:14:47 +020062int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count)
63{
Baruch Siach5e983842020-01-20 14:20:14 +020064 cf_read_tlv_data();
65
Joel Johnson8a863082020-03-23 14:21:33 -060066 /* Apply build configuration options before runtime configuration */
67 if (IS_ENABLED(CONFIG_CLEARFOG_SFP_25GB))
68 board_serdes_map[5].serdes_speed = SERDES_SPEED_3_125_GBPS;
69
70 /* Apply runtime detection changes */
Baruch Siach5e983842020-01-20 14:20:14 +020071 if (sr_product_is(&cf_tlv_data, "Clearfog GTR")) {
72 board_serdes_map[0].serdes_type = PEX0;
73 board_serdes_map[0].serdes_speed = SERDES_SPEED_5_GBPS;
74 board_serdes_map[0].serdes_mode = PEX_ROOT_COMPLEX_X1;
Joel Johnson9f205d62020-03-23 14:21:32 -060075 } else if (sr_product_is(&cf_tlv_data, "Clearfog Pro")) {
76 /* handle recognized product as noop, no adjustment required */
77 } else if (sr_product_is(&cf_tlv_data, "Clearfog Base")) {
78 config_cfbase_serdes_map();
79 } else {
80 /*
81 * Fallback to static default. EEPROM TLV support is not
82 * enabled, runtime detection failed, hardware support is not
83 * present, EEPROM is corrupt, or an unrecognized product name
84 * is present.
85 */
86 if (IS_ENABLED(CONFIG_SPL_CMD_TLV_EEPROM))
87 puts("EEPROM TLV detection failed: ");
88 puts("Using static config for ");
89 if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE)) {
90 puts("Clearfog Base.\n");
91 config_cfbase_serdes_map();
92 } else {
93 puts("Clearfog Pro.\n");
94 }
Baruch Siach584a3d22020-01-20 14:20:15 +020095 }
96
Stefan Roese0299c902015-10-20 15:14:47 +020097 *serdes_map_array = board_serdes_map;
98 *count = ARRAY_SIZE(board_serdes_map);
99 return 0;
100}
101
102/*
103 * Define the DDR layout / topology here in the board file. This will
104 * be used by the DDR3 init code in the SPL U-Boot version to configure
105 * the DDR3 controller.
106 */
Chris Packham2b4ffbf2018-05-10 13:28:29 +1200107static struct mv_ddr_topology_map board_topology_map = {
108 DEBUG_LEVEL_ERROR,
Stefan Roese0299c902015-10-20 15:14:47 +0200109 0x1, /* active interfaces */
110 /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
111 { { { {0x1, 0, 0, 0},
112 {0x1, 0, 0, 0},
113 {0x1, 0, 0, 0},
114 {0x1, 0, 0, 0},
115 {0x1, 0, 0, 0} },
116 SPEED_BIN_DDR_1600K, /* speed_bin */
Chris Packham2b4ffbf2018-05-10 13:28:29 +1200117 MV_DDR_DEV_WIDTH_16BIT, /* memory_width */
118 MV_DDR_DIE_CAP_4GBIT, /* mem_size */
Chris Packhamebb1a592018-12-03 14:26:49 +1300119 MV_DDR_FREQ_800, /* frequency */
Chris Packham01c541e2017-11-29 10:38:34 +1300120 0, 0, /* cas_wl cas_l */
Chris Packhame6f61622018-05-10 13:28:30 +1200121 MV_DDR_TEMP_LOW, /* temperature */
122 MV_DDR_TIM_DEFAULT} }, /* timing */
Chris Packham2b4ffbf2018-05-10 13:28:29 +1200123 BUS_MASK_32BIT, /* Busses mask */
124 MV_DDR_CFG_DEFAULT, /* ddr configuration data source */
125 { {0} }, /* raw spd data */
Baruch Siach66646fa2020-01-20 14:20:07 +0200126 {0}, /* timing parameters */
127 { {0} }, /* electrical configuration */
128 {0,}, /* electrical parameters */
129 0x3, /* clock enable mask */
Stefan Roese0299c902015-10-20 15:14:47 +0200130};
131
Chris Packham2b4ffbf2018-05-10 13:28:29 +1200132struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
Stefan Roese0299c902015-10-20 15:14:47 +0200133{
Baruch Siacha2e41ad2020-01-20 14:20:11 +0200134 struct if_params *ifp = &board_topology_map.interface_params[0];
135
136 cf_read_tlv_data();
137
138 switch (cf_tlv_data.ram_size) {
139 case 4:
140 default:
141 ifp->memory_size = MV_DDR_DIE_CAP_4GBIT;
142 break;
143 case 8:
144 ifp->memory_size = MV_DDR_DIE_CAP_8GBIT;
145 break;
146 }
147
Stefan Roese0299c902015-10-20 15:14:47 +0200148 /* Return the board topology as defined in the board code */
149 return &board_topology_map;
150}
151
152int board_early_init_f(void)
153{
154 /* Configure MPP */
155 writel(0x11111111, MVEBU_MPP_BASE + 0x00);
156 writel(0x11111111, MVEBU_MPP_BASE + 0x04);
157 writel(0x10400011, MVEBU_MPP_BASE + 0x08);
158 writel(0x22043333, MVEBU_MPP_BASE + 0x0c);
159 writel(0x44400002, MVEBU_MPP_BASE + 0x10);
160 writel(0x41144004, MVEBU_MPP_BASE + 0x14);
161 writel(0x40333333, MVEBU_MPP_BASE + 0x18);
162 writel(0x00004444, MVEBU_MPP_BASE + 0x1c);
163
164 /* Set GPP Out value */
165 writel(BOARD_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00);
166 writel(BOARD_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00);
167
168 /* Set GPP Polarity */
169 writel(BOARD_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c);
170 writel(BOARD_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c);
171
172 /* Set GPP Out Enable */
173 writel(BOARD_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04);
174 writel(BOARD_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04);
175
176 return 0;
177}
178
179int board_init(void)
180{
Stefan Roese0299c902015-10-20 15:14:47 +0200181 /* Address of boot parameters */
182 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
183
184 /* Toggle GPIO41 to reset onboard switch and phy */
185 clrbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9));
186 clrbits_le32(MVEBU_GPIO1_BASE + 0x4, BIT(9));
Patrick Wildtfb9765d2017-05-09 13:54:44 +0200187 /* GPIO 19 on ClearFog rev 2.1 controls the uSOM onboard phy reset */
188 clrbits_le32(MVEBU_GPIO0_BASE + 0x0, BIT(19));
189 clrbits_le32(MVEBU_GPIO0_BASE + 0x4, BIT(19));
Stefan Roese0299c902015-10-20 15:14:47 +0200190 mdelay(1);
191 setbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9));
Patrick Wildtfb9765d2017-05-09 13:54:44 +0200192 setbits_le32(MVEBU_GPIO0_BASE + 0x0, BIT(19));
Stefan Roese0299c902015-10-20 15:14:47 +0200193 mdelay(10);
194
Stefan Roese0299c902015-10-20 15:14:47 +0200195 return 0;
196}
197
198int checkboard(void)
199{
Joel Johnsonee26e852020-03-23 14:21:31 -0600200 char *board = "Clearfog Pro";
Joel Johnson9f205d62020-03-23 14:21:32 -0600201 if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE))
202 board = "Clearfog Base";
Baruch Siach7211fa62020-01-20 14:20:12 +0200203
204 cf_read_tlv_data();
205 if (strlen(cf_tlv_data.tlv_product_name[0]) > 0)
206 board = cf_tlv_data.tlv_product_name[0];
207
208 printf("Board: SolidRun %s", board);
209 if (strlen(cf_tlv_data.tlv_product_name[1]) > 0)
210 printf(", %s", cf_tlv_data.tlv_product_name[1]);
211 puts("\n");
Stefan Roese0299c902015-10-20 15:14:47 +0200212
213 return 0;
214}
215
216int board_eth_init(bd_t *bis)
217{
218 cpu_eth_init(bis); /* Built in controller(s) come first */
219 return pci_eth_init(bis);
220}
Baruch Siach867572f2020-01-20 14:20:13 +0200221
222int board_late_init(void)
223{
224 cf_read_tlv_data();
225
226 if (sr_product_is(&cf_tlv_data, "Clearfog Base"))
227 env_set("fdtfile", "armada-388-clearfog-base.dtb");
228 else if (sr_product_is(&cf_tlv_data, "Clearfog GTR S4"))
229 env_set("fdtfile", "armada-385-clearfog-gtr-s4.dtb");
230 else if (sr_product_is(&cf_tlv_data, "Clearfog GTR L8"))
231 env_set("fdtfile", "armada-385-clearfog-gtr-l8.dtb");
Joel Johnson9f205d62020-03-23 14:21:32 -0600232 else if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE))
233 env_set("fdtfile", "armada-388-clearfog-base.dtb");
Baruch Siach867572f2020-01-20 14:20:13 +0200234
235 return 0;
236}