blob: 2dbd071abd9f29cee97fb813a67d0190a620bd32 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese73606402015-10-20 15:14:47 +02002/*
3 * Copyright (C) 2015 Stefan Roese <sr@denx.de>
Stefan Roese73606402015-10-20 15:14:47 +02004 */
5
Tom Rinidec7ea02024-05-20 13:35:03 -06006#include <config.h>
Simon Glassed38aef2020-05-10 11:40:03 -06007#include <env.h>
Stefan Roese73606402015-10-20 15:14:47 +02008#include <i2c.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Stefan Roese73606402015-10-20 15:14:47 +020010#include <miiphy.h>
Simon Glass274e0b02020-05-10 11:39:56 -060011#include <net.h>
Stefan Roese73606402015-10-20 15:14:47 +020012#include <netdev.h>
Martin Rowe7eceb672023-03-27 21:24:09 +100013#include <mmc.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Stefan Roese73606402015-10-20 15:14:47 +020015#include <asm/io.h>
16#include <asm/arch/cpu.h>
17#include <asm/arch/soc.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060018#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060019#include <linux/delay.h>
Baruch Siach4417ff22020-01-20 14:20:11 +020020#include "../common/tlv_data.h"
Stefan Roese73606402015-10-20 15:14:47 +020021
Chris Packham1a07d212018-05-10 13:28:29 +120022#include "../drivers/ddr/marvell/a38x/ddr3_init.h"
Stefan Roese73606402015-10-20 15:14:47 +020023#include <../serdes/a38x/high_speed_env_spec.h>
24
25DECLARE_GLOBAL_DATA_PTR;
26
Stefan Roese73606402015-10-20 15:14:47 +020027/*
28 * Those values and defines are taken from the Marvell U-Boot version
29 * "u-boot-2013.01-15t1-clearfog"
30 */
31#define BOARD_GPP_OUT_ENA_LOW 0xffffffff
32#define BOARD_GPP_OUT_ENA_MID 0xffffffff
33
34#define BOARD_GPP_OUT_VAL_LOW 0x0
35#define BOARD_GPP_OUT_VAL_MID 0x0
36#define BOARD_GPP_POL_LOW 0x0
37#define BOARD_GPP_POL_MID 0x0
38
Josua Mayere5283662023-10-08 16:58:03 +020039static struct tlv_data cf_tlv_data = { 0 };
Baruch Siach4417ff22020-01-20 14:20:11 +020040
41static void cf_read_tlv_data(void)
42{
43 static bool read_once;
44
45 if (read_once)
46 return;
47 read_once = true;
48
49 read_tlv_data(&cf_tlv_data);
50}
51
Joel Johnson28bf4ca2020-03-23 14:21:32 -060052/* The starting board_serdes_map reflects original Clearfog Pro usage */
Stefan Roese73606402015-10-20 15:14:47 +020053static struct serdes_map board_serdes_map[] = {
54 {SATA0, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 0},
55 {SGMII1, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
56 {PEX1, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
57 {USB3_HOST1, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
58 {PEX2, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
59 {SGMII2, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
60};
61
Joel Johnson28bf4ca2020-03-23 14:21:32 -060062void config_cfbase_serdes_map(void)
63{
64 board_serdes_map[4].serdes_type = USB3_HOST0;
65 board_serdes_map[4].serdes_speed = SERDES_SPEED_5_GBPS;
66 board_serdes_map[4].serdes_mode = SERDES_DEFAULT_MODE;
67}
68
Stefan Roese73606402015-10-20 15:14:47 +020069int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count)
70{
Baruch Siach1c6e65d2020-01-20 14:20:14 +020071 cf_read_tlv_data();
72
Joel Johnson55beee12020-03-23 14:21:33 -060073 /* Apply build configuration options before runtime configuration */
74 if (IS_ENABLED(CONFIG_CLEARFOG_SFP_25GB))
75 board_serdes_map[5].serdes_speed = SERDES_SPEED_3_125_GBPS;
76
Joel Johnson165ce6a2020-03-23 14:21:34 -060077 if (IS_ENABLED(CONFIG_CLEARFOG_CON2_SATA)) {
78 board_serdes_map[4].serdes_type = SATA2;
79 board_serdes_map[4].serdes_speed = SERDES_SPEED_3_GBPS;
80 board_serdes_map[4].serdes_mode = SERDES_DEFAULT_MODE;
81 board_serdes_map[4].swap_rx = 1;
82 }
83
84 if (IS_ENABLED(CONFIG_CLEARFOG_CON3_SATA)) {
85 board_serdes_map[2].serdes_type = SATA1;
86 board_serdes_map[2].serdes_speed = SERDES_SPEED_3_GBPS;
87 board_serdes_map[2].serdes_mode = SERDES_DEFAULT_MODE;
88 board_serdes_map[2].swap_rx = 1;
89 }
90
Joel Johnson55beee12020-03-23 14:21:33 -060091 /* Apply runtime detection changes */
Baruch Siach1c6e65d2020-01-20 14:20:14 +020092 if (sr_product_is(&cf_tlv_data, "Clearfog GTR")) {
Josua Mayer85076d72024-01-12 14:35:10 +010093 if (IS_ENABLED(CONFIG_CLEARFOG_GTR_SERDES0_SATA)) {
94 /* serdes 0 is sata (like clearfog pro) */
95 } else if (IS_ENABLED(CONFIG_CLEARFOG_GTR_SERDES0_PCIE)) {
96 /* serdes 0 is pci */
97 board_serdes_map[0].serdes_type = PEX0;
98 board_serdes_map[0].serdes_speed = SERDES_SPEED_5_GBPS;
99 board_serdes_map[0].serdes_mode = PEX_ROOT_COMPLEX_X1;
100 }
Josua Mayerdf04a142024-01-12 14:35:11 +0100101 /* serdes 1 is 2.5Gbps fixed link to ethernet switch */
102 board_serdes_map[1].serdes_type = SGMII1;
103 board_serdes_map[1].serdes_speed = SERDES_SPEED_3_125_GBPS;
104 board_serdes_map[1].serdes_mode = SERDES_DEFAULT_MODE;
105 /* serdes 2 is pci (like clearfog pro) */
106 /* serdes 3 is usb-3 (like clearfog pro) */
107 /* serdes 4 is pci (like clearfog pro) */
108 /* serdes 5 is sfp connector (like clearfog pro) */
Joel Johnson28bf4ca2020-03-23 14:21:32 -0600109 } else if (sr_product_is(&cf_tlv_data, "Clearfog Pro")) {
110 /* handle recognized product as noop, no adjustment required */
111 } else if (sr_product_is(&cf_tlv_data, "Clearfog Base")) {
112 config_cfbase_serdes_map();
113 } else {
114 /*
115 * Fallback to static default. EEPROM TLV support is not
116 * enabled, runtime detection failed, hardware support is not
117 * present, EEPROM is corrupt, or an unrecognized product name
118 * is present.
119 */
120 if (IS_ENABLED(CONFIG_SPL_CMD_TLV_EEPROM))
121 puts("EEPROM TLV detection failed: ");
122 puts("Using static config for ");
123 if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE)) {
124 puts("Clearfog Base.\n");
125 config_cfbase_serdes_map();
126 } else {
127 puts("Clearfog Pro.\n");
128 }
Baruch Siach1c6e65d2020-01-20 14:20:14 +0200129 }
130
Stefan Roese73606402015-10-20 15:14:47 +0200131 *serdes_map_array = board_serdes_map;
132 *count = ARRAY_SIZE(board_serdes_map);
133 return 0;
134}
135
136/*
137 * Define the DDR layout / topology here in the board file. This will
138 * be used by the DDR3 init code in the SPL U-Boot version to configure
139 * the DDR3 controller.
140 */
Chris Packham1a07d212018-05-10 13:28:29 +1200141static struct mv_ddr_topology_map board_topology_map = {
142 DEBUG_LEVEL_ERROR,
Stefan Roese73606402015-10-20 15:14:47 +0200143 0x1, /* active interfaces */
144 /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
145 { { { {0x1, 0, 0, 0},
146 {0x1, 0, 0, 0},
147 {0x1, 0, 0, 0},
148 {0x1, 0, 0, 0},
149 {0x1, 0, 0, 0} },
150 SPEED_BIN_DDR_1600K, /* speed_bin */
Chris Packham1a07d212018-05-10 13:28:29 +1200151 MV_DDR_DEV_WIDTH_16BIT, /* memory_width */
152 MV_DDR_DIE_CAP_4GBIT, /* mem_size */
Chris Packham4bf81db2018-12-03 14:26:49 +1300153 MV_DDR_FREQ_800, /* frequency */
Chris Packhamdd092bd2017-11-29 10:38:34 +1300154 0, 0, /* cas_wl cas_l */
Chris Packham3a09e132018-05-10 13:28:30 +1200155 MV_DDR_TEMP_LOW, /* temperature */
156 MV_DDR_TIM_DEFAULT} }, /* timing */
Chris Packham1a07d212018-05-10 13:28:29 +1200157 BUS_MASK_32BIT, /* Busses mask */
158 MV_DDR_CFG_DEFAULT, /* ddr configuration data source */
Moti Buskila498475e2021-02-19 17:11:19 +0100159 NOT_COMBINED, /* ddr twin-die combined */
Chris Packham1a07d212018-05-10 13:28:29 +1200160 { {0} }, /* raw spd data */
Baruch Siach43b76ce2020-01-20 14:20:07 +0200161 {0}, /* timing parameters */
162 { {0} }, /* electrical configuration */
163 {0,}, /* electrical parameters */
Chris Packhame8462fb2022-03-01 13:53:23 +1300164 0, /* ODT configuration */
Baruch Siach43b76ce2020-01-20 14:20:07 +0200165 0x3, /* clock enable mask */
Stefan Roese73606402015-10-20 15:14:47 +0200166};
167
Chris Packham1a07d212018-05-10 13:28:29 +1200168struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
Stefan Roese73606402015-10-20 15:14:47 +0200169{
Baruch Siach4417ff22020-01-20 14:20:11 +0200170 struct if_params *ifp = &board_topology_map.interface_params[0];
171
172 cf_read_tlv_data();
173
174 switch (cf_tlv_data.ram_size) {
Josua Mayer50922212023-10-08 16:58:04 +0200175 case 2:
176 ifp->memory_size = MV_DDR_DIE_CAP_2GBIT;
177 break;
Baruch Siach4417ff22020-01-20 14:20:11 +0200178 case 4:
179 default:
180 ifp->memory_size = MV_DDR_DIE_CAP_4GBIT;
181 break;
182 case 8:
183 ifp->memory_size = MV_DDR_DIE_CAP_8GBIT;
184 break;
185 }
186
Josua Mayere5283662023-10-08 16:58:03 +0200187 switch (cf_tlv_data.ram_channels) {
188 default:
189 case 1:
190 for (uint8_t i = 0; i < 5; i++)
191 ifp->as_bus_params[i].cs_bitmask = 0x1;
192 break;
193 case 2:
194 for (uint8_t i = 0; i < 5; i++)
195 ifp->as_bus_params[i].cs_bitmask = 0x3;
196 break;
197 }
198
Stefan Roese73606402015-10-20 15:14:47 +0200199 /* Return the board topology as defined in the board code */
200 return &board_topology_map;
201}
202
203int board_early_init_f(void)
204{
205 /* Configure MPP */
206 writel(0x11111111, MVEBU_MPP_BASE + 0x00);
207 writel(0x11111111, MVEBU_MPP_BASE + 0x04);
208 writel(0x10400011, MVEBU_MPP_BASE + 0x08);
209 writel(0x22043333, MVEBU_MPP_BASE + 0x0c);
210 writel(0x44400002, MVEBU_MPP_BASE + 0x10);
211 writel(0x41144004, MVEBU_MPP_BASE + 0x14);
212 writel(0x40333333, MVEBU_MPP_BASE + 0x18);
213 writel(0x00004444, MVEBU_MPP_BASE + 0x1c);
214
215 /* Set GPP Out value */
216 writel(BOARD_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00);
217 writel(BOARD_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00);
218
219 /* Set GPP Polarity */
220 writel(BOARD_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c);
221 writel(BOARD_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c);
222
223 /* Set GPP Out Enable */
224 writel(BOARD_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04);
225 writel(BOARD_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04);
226
227 return 0;
228}
229
230int board_init(void)
231{
Stefan Roese73606402015-10-20 15:14:47 +0200232 /* Address of boot parameters */
233 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
234
235 /* Toggle GPIO41 to reset onboard switch and phy */
236 clrbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9));
237 clrbits_le32(MVEBU_GPIO1_BASE + 0x4, BIT(9));
Patrick Wildtb6bce292017-05-09 13:54:44 +0200238 /* GPIO 19 on ClearFog rev 2.1 controls the uSOM onboard phy reset */
239 clrbits_le32(MVEBU_GPIO0_BASE + 0x0, BIT(19));
240 clrbits_le32(MVEBU_GPIO0_BASE + 0x4, BIT(19));
Stefan Roese73606402015-10-20 15:14:47 +0200241 mdelay(1);
242 setbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9));
Patrick Wildtb6bce292017-05-09 13:54:44 +0200243 setbits_le32(MVEBU_GPIO0_BASE + 0x0, BIT(19));
Stefan Roese73606402015-10-20 15:14:47 +0200244 mdelay(10);
245
Stefan Roese73606402015-10-20 15:14:47 +0200246 return 0;
247}
248
249int checkboard(void)
250{
Joel Johnsonadd85bb2020-03-23 14:21:31 -0600251 char *board = "Clearfog Pro";
Joel Johnson28bf4ca2020-03-23 14:21:32 -0600252 if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE))
253 board = "Clearfog Base";
Baruch Siach61520472020-01-20 14:20:12 +0200254
255 cf_read_tlv_data();
256 if (strlen(cf_tlv_data.tlv_product_name[0]) > 0)
257 board = cf_tlv_data.tlv_product_name[0];
258
259 printf("Board: SolidRun %s", board);
260 if (strlen(cf_tlv_data.tlv_product_name[1]) > 0)
261 printf(", %s", cf_tlv_data.tlv_product_name[1]);
262 puts("\n");
Stefan Roese73606402015-10-20 15:14:47 +0200263
264 return 0;
265}
266
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900267int board_eth_init(struct bd_info *bis)
Stefan Roese73606402015-10-20 15:14:47 +0200268{
269 cpu_eth_init(bis); /* Built in controller(s) come first */
270 return pci_eth_init(bis);
271}
Baruch Siach1c5e95d2020-01-20 14:20:13 +0200272
273int board_late_init(void)
274{
Baruch Siach9f627a52020-09-09 15:14:39 +0300275 if (env_get("fdtfile"))
276 return 0;
277
Baruch Siach1c5e95d2020-01-20 14:20:13 +0200278 cf_read_tlv_data();
279
280 if (sr_product_is(&cf_tlv_data, "Clearfog Base"))
281 env_set("fdtfile", "armada-388-clearfog-base.dtb");
282 else if (sr_product_is(&cf_tlv_data, "Clearfog GTR S4"))
283 env_set("fdtfile", "armada-385-clearfog-gtr-s4.dtb");
284 else if (sr_product_is(&cf_tlv_data, "Clearfog GTR L8"))
285 env_set("fdtfile", "armada-385-clearfog-gtr-l8.dtb");
Joel Johnson28bf4ca2020-03-23 14:21:32 -0600286 else if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE))
287 env_set("fdtfile", "armada-388-clearfog-base.dtb");
Joel Johnsonc3809442020-03-23 14:21:35 -0600288 else
Joel Johnson026d4722020-03-23 14:21:40 -0600289 env_set("fdtfile", "armada-388-clearfog-pro.dtb");
Baruch Siach1c5e95d2020-01-20 14:20:13 +0200290
291 return 0;
292}
Martin Rowe7eceb672023-03-27 21:24:09 +1000293
294static bool has_emmc(void)
295{
296 struct mmc *mmc;
297
298 mmc = find_mmc_device(0);
299 if (!mmc)
300 return 0;
301 return (!mmc_init(mmc) && IS_MMC(mmc)) ? true : false;
302}
303
304/*
305 * The Clearfog devices have only one SDHC device. This is either eMMC
306 * if it is populated on the SOM or SDHC if not. The Linux device tree
307 * assumes the SDHC case. Detect if the device is an eMMC and fixup the
308 * device-tree, so that it will be detected by Linux.
309 */
310int ft_board_setup(void *blob, struct bd_info *bd)
311{
312 int node;
313
314 if (has_emmc()) {
315 node = fdt_node_offset_by_compatible(blob, -1, "marvell,armada-380-sdhci");
316 if (node < 0)
317 return 0; /* Unexpected eMMC device; patching not supported */
318
319 puts("Patching FDT so that eMMC is detected by OS\n");
320 return fdt_setprop_empty(blob, node, "non-removable");
321 }
322
323 return 0;
324}