blob: df23c0d8b3334fdbe4098e8f6b0afe90877f08d7 [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
6#include <common.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>
13#include <asm/io.h>
14#include <asm/arch/cpu.h>
15#include <asm/arch/soc.h>
Simon Glassdbd79542020-05-10 11:40:11 -060016#include <linux/delay.h>
Baruch Siach4417ff22020-01-20 14:20:11 +020017#include "../common/tlv_data.h"
Stefan Roese73606402015-10-20 15:14:47 +020018
Chris Packham1a07d212018-05-10 13:28:29 +120019#include "../drivers/ddr/marvell/a38x/ddr3_init.h"
Stefan Roese73606402015-10-20 15:14:47 +020020#include <../serdes/a38x/high_speed_env_spec.h>
21
22DECLARE_GLOBAL_DATA_PTR;
23
Stefan Roese73606402015-10-20 15:14:47 +020024/*
25 * Those values and defines are taken from the Marvell U-Boot version
26 * "u-boot-2013.01-15t1-clearfog"
27 */
28#define BOARD_GPP_OUT_ENA_LOW 0xffffffff
29#define BOARD_GPP_OUT_ENA_MID 0xffffffff
30
31#define BOARD_GPP_OUT_VAL_LOW 0x0
32#define BOARD_GPP_OUT_VAL_MID 0x0
33#define BOARD_GPP_POL_LOW 0x0
34#define BOARD_GPP_POL_MID 0x0
35
Baruch Siach4417ff22020-01-20 14:20:11 +020036static struct tlv_data cf_tlv_data;
37
38static void cf_read_tlv_data(void)
39{
40 static bool read_once;
41
42 if (read_once)
43 return;
44 read_once = true;
45
46 read_tlv_data(&cf_tlv_data);
47}
48
Joel Johnson28bf4ca2020-03-23 14:21:32 -060049/* The starting board_serdes_map reflects original Clearfog Pro usage */
Stefan Roese73606402015-10-20 15:14:47 +020050static struct serdes_map board_serdes_map[] = {
51 {SATA0, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 0},
52 {SGMII1, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
53 {PEX1, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
54 {USB3_HOST1, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
55 {PEX2, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
56 {SGMII2, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
57};
58
Joel Johnson28bf4ca2020-03-23 14:21:32 -060059void config_cfbase_serdes_map(void)
60{
61 board_serdes_map[4].serdes_type = USB3_HOST0;
62 board_serdes_map[4].serdes_speed = SERDES_SPEED_5_GBPS;
63 board_serdes_map[4].serdes_mode = SERDES_DEFAULT_MODE;
64}
65
Stefan Roese73606402015-10-20 15:14:47 +020066int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count)
67{
Baruch Siach1c6e65d2020-01-20 14:20:14 +020068 cf_read_tlv_data();
69
Joel Johnson55beee12020-03-23 14:21:33 -060070 /* Apply build configuration options before runtime configuration */
71 if (IS_ENABLED(CONFIG_CLEARFOG_SFP_25GB))
72 board_serdes_map[5].serdes_speed = SERDES_SPEED_3_125_GBPS;
73
Joel Johnson165ce6a2020-03-23 14:21:34 -060074 if (IS_ENABLED(CONFIG_CLEARFOG_CON2_SATA)) {
75 board_serdes_map[4].serdes_type = SATA2;
76 board_serdes_map[4].serdes_speed = SERDES_SPEED_3_GBPS;
77 board_serdes_map[4].serdes_mode = SERDES_DEFAULT_MODE;
78 board_serdes_map[4].swap_rx = 1;
79 }
80
81 if (IS_ENABLED(CONFIG_CLEARFOG_CON3_SATA)) {
82 board_serdes_map[2].serdes_type = SATA1;
83 board_serdes_map[2].serdes_speed = SERDES_SPEED_3_GBPS;
84 board_serdes_map[2].serdes_mode = SERDES_DEFAULT_MODE;
85 board_serdes_map[2].swap_rx = 1;
86 }
87
Joel Johnson55beee12020-03-23 14:21:33 -060088 /* Apply runtime detection changes */
Baruch Siach1c6e65d2020-01-20 14:20:14 +020089 if (sr_product_is(&cf_tlv_data, "Clearfog GTR")) {
90 board_serdes_map[0].serdes_type = PEX0;
91 board_serdes_map[0].serdes_speed = SERDES_SPEED_5_GBPS;
92 board_serdes_map[0].serdes_mode = PEX_ROOT_COMPLEX_X1;
Joel Johnson28bf4ca2020-03-23 14:21:32 -060093 } else if (sr_product_is(&cf_tlv_data, "Clearfog Pro")) {
94 /* handle recognized product as noop, no adjustment required */
95 } else if (sr_product_is(&cf_tlv_data, "Clearfog Base")) {
96 config_cfbase_serdes_map();
97 } else {
98 /*
99 * Fallback to static default. EEPROM TLV support is not
100 * enabled, runtime detection failed, hardware support is not
101 * present, EEPROM is corrupt, or an unrecognized product name
102 * is present.
103 */
104 if (IS_ENABLED(CONFIG_SPL_CMD_TLV_EEPROM))
105 puts("EEPROM TLV detection failed: ");
106 puts("Using static config for ");
107 if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE)) {
108 puts("Clearfog Base.\n");
109 config_cfbase_serdes_map();
110 } else {
111 puts("Clearfog Pro.\n");
112 }
Baruch Siach1c6e65d2020-01-20 14:20:14 +0200113 }
114
Stefan Roese73606402015-10-20 15:14:47 +0200115 *serdes_map_array = board_serdes_map;
116 *count = ARRAY_SIZE(board_serdes_map);
117 return 0;
118}
119
120/*
121 * Define the DDR layout / topology here in the board file. This will
122 * be used by the DDR3 init code in the SPL U-Boot version to configure
123 * the DDR3 controller.
124 */
Chris Packham1a07d212018-05-10 13:28:29 +1200125static struct mv_ddr_topology_map board_topology_map = {
126 DEBUG_LEVEL_ERROR,
Stefan Roese73606402015-10-20 15:14:47 +0200127 0x1, /* active interfaces */
128 /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
129 { { { {0x1, 0, 0, 0},
130 {0x1, 0, 0, 0},
131 {0x1, 0, 0, 0},
132 {0x1, 0, 0, 0},
133 {0x1, 0, 0, 0} },
134 SPEED_BIN_DDR_1600K, /* speed_bin */
Chris Packham1a07d212018-05-10 13:28:29 +1200135 MV_DDR_DEV_WIDTH_16BIT, /* memory_width */
136 MV_DDR_DIE_CAP_4GBIT, /* mem_size */
Chris Packham4bf81db2018-12-03 14:26:49 +1300137 MV_DDR_FREQ_800, /* frequency */
Chris Packhamdd092bd2017-11-29 10:38:34 +1300138 0, 0, /* cas_wl cas_l */
Chris Packham3a09e132018-05-10 13:28:30 +1200139 MV_DDR_TEMP_LOW, /* temperature */
140 MV_DDR_TIM_DEFAULT} }, /* timing */
Chris Packham1a07d212018-05-10 13:28:29 +1200141 BUS_MASK_32BIT, /* Busses mask */
142 MV_DDR_CFG_DEFAULT, /* ddr configuration data source */
143 { {0} }, /* raw spd data */
Baruch Siach43b76ce2020-01-20 14:20:07 +0200144 {0}, /* timing parameters */
145 { {0} }, /* electrical configuration */
146 {0,}, /* electrical parameters */
147 0x3, /* clock enable mask */
Stefan Roese73606402015-10-20 15:14:47 +0200148};
149
Chris Packham1a07d212018-05-10 13:28:29 +1200150struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
Stefan Roese73606402015-10-20 15:14:47 +0200151{
Baruch Siach4417ff22020-01-20 14:20:11 +0200152 struct if_params *ifp = &board_topology_map.interface_params[0];
153
154 cf_read_tlv_data();
155
156 switch (cf_tlv_data.ram_size) {
157 case 4:
158 default:
159 ifp->memory_size = MV_DDR_DIE_CAP_4GBIT;
160 break;
161 case 8:
162 ifp->memory_size = MV_DDR_DIE_CAP_8GBIT;
163 break;
164 }
165
Stefan Roese73606402015-10-20 15:14:47 +0200166 /* Return the board topology as defined in the board code */
167 return &board_topology_map;
168}
169
170int board_early_init_f(void)
171{
172 /* Configure MPP */
173 writel(0x11111111, MVEBU_MPP_BASE + 0x00);
174 writel(0x11111111, MVEBU_MPP_BASE + 0x04);
175 writel(0x10400011, MVEBU_MPP_BASE + 0x08);
176 writel(0x22043333, MVEBU_MPP_BASE + 0x0c);
177 writel(0x44400002, MVEBU_MPP_BASE + 0x10);
178 writel(0x41144004, MVEBU_MPP_BASE + 0x14);
179 writel(0x40333333, MVEBU_MPP_BASE + 0x18);
180 writel(0x00004444, MVEBU_MPP_BASE + 0x1c);
181
182 /* Set GPP Out value */
183 writel(BOARD_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00);
184 writel(BOARD_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00);
185
186 /* Set GPP Polarity */
187 writel(BOARD_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c);
188 writel(BOARD_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c);
189
190 /* Set GPP Out Enable */
191 writel(BOARD_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04);
192 writel(BOARD_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04);
193
194 return 0;
195}
196
197int board_init(void)
198{
Stefan Roese73606402015-10-20 15:14:47 +0200199 /* Address of boot parameters */
200 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
201
202 /* Toggle GPIO41 to reset onboard switch and phy */
203 clrbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9));
204 clrbits_le32(MVEBU_GPIO1_BASE + 0x4, BIT(9));
Patrick Wildtb6bce292017-05-09 13:54:44 +0200205 /* GPIO 19 on ClearFog rev 2.1 controls the uSOM onboard phy reset */
206 clrbits_le32(MVEBU_GPIO0_BASE + 0x0, BIT(19));
207 clrbits_le32(MVEBU_GPIO0_BASE + 0x4, BIT(19));
Stefan Roese73606402015-10-20 15:14:47 +0200208 mdelay(1);
209 setbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9));
Patrick Wildtb6bce292017-05-09 13:54:44 +0200210 setbits_le32(MVEBU_GPIO0_BASE + 0x0, BIT(19));
Stefan Roese73606402015-10-20 15:14:47 +0200211 mdelay(10);
212
Stefan Roese73606402015-10-20 15:14:47 +0200213 return 0;
214}
215
216int checkboard(void)
217{
Joel Johnsonadd85bb2020-03-23 14:21:31 -0600218 char *board = "Clearfog Pro";
Joel Johnson28bf4ca2020-03-23 14:21:32 -0600219 if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE))
220 board = "Clearfog Base";
Baruch Siach61520472020-01-20 14:20:12 +0200221
222 cf_read_tlv_data();
223 if (strlen(cf_tlv_data.tlv_product_name[0]) > 0)
224 board = cf_tlv_data.tlv_product_name[0];
225
226 printf("Board: SolidRun %s", board);
227 if (strlen(cf_tlv_data.tlv_product_name[1]) > 0)
228 printf(", %s", cf_tlv_data.tlv_product_name[1]);
229 puts("\n");
Stefan Roese73606402015-10-20 15:14:47 +0200230
231 return 0;
232}
233
234int board_eth_init(bd_t *bis)
235{
236 cpu_eth_init(bis); /* Built in controller(s) come first */
237 return pci_eth_init(bis);
238}
Baruch Siach1c5e95d2020-01-20 14:20:13 +0200239
240int board_late_init(void)
241{
242 cf_read_tlv_data();
243
244 if (sr_product_is(&cf_tlv_data, "Clearfog Base"))
245 env_set("fdtfile", "armada-388-clearfog-base.dtb");
246 else if (sr_product_is(&cf_tlv_data, "Clearfog GTR S4"))
247 env_set("fdtfile", "armada-385-clearfog-gtr-s4.dtb");
248 else if (sr_product_is(&cf_tlv_data, "Clearfog GTR L8"))
249 env_set("fdtfile", "armada-385-clearfog-gtr-l8.dtb");
Joel Johnson28bf4ca2020-03-23 14:21:32 -0600250 else if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE))
251 env_set("fdtfile", "armada-388-clearfog-base.dtb");
Joel Johnsonc3809442020-03-23 14:21:35 -0600252 else
Joel Johnson026d4722020-03-23 14:21:40 -0600253 env_set("fdtfile", "armada-388-clearfog-pro.dtb");
Baruch Siach1c5e95d2020-01-20 14:20:13 +0200254
255 return 0;
256}