blob: 03adb591d82682e847932c8bd10f93fe826ad08b [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Stefan Roese73606402015-10-20 15:14:47 +020014#include <asm/io.h>
15#include <asm/arch/cpu.h>
16#include <asm/arch/soc.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060017#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060018#include <linux/delay.h>
Baruch Siach4417ff22020-01-20 14:20:11 +020019#include "../common/tlv_data.h"
Stefan Roese73606402015-10-20 15:14:47 +020020
Chris Packham1a07d212018-05-10 13:28:29 +120021#include "../drivers/ddr/marvell/a38x/ddr3_init.h"
Stefan Roese73606402015-10-20 15:14:47 +020022#include <../serdes/a38x/high_speed_env_spec.h>
23
24DECLARE_GLOBAL_DATA_PTR;
25
Stefan Roese73606402015-10-20 15:14:47 +020026/*
27 * Those values and defines are taken from the Marvell U-Boot version
28 * "u-boot-2013.01-15t1-clearfog"
29 */
30#define BOARD_GPP_OUT_ENA_LOW 0xffffffff
31#define BOARD_GPP_OUT_ENA_MID 0xffffffff
32
33#define BOARD_GPP_OUT_VAL_LOW 0x0
34#define BOARD_GPP_OUT_VAL_MID 0x0
35#define BOARD_GPP_POL_LOW 0x0
36#define BOARD_GPP_POL_MID 0x0
37
Baruch Siach4417ff22020-01-20 14:20:11 +020038static struct tlv_data cf_tlv_data;
39
40static void cf_read_tlv_data(void)
41{
42 static bool read_once;
43
44 if (read_once)
45 return;
46 read_once = true;
47
48 read_tlv_data(&cf_tlv_data);
49}
50
Joel Johnson28bf4ca2020-03-23 14:21:32 -060051/* The starting board_serdes_map reflects original Clearfog Pro usage */
Stefan Roese73606402015-10-20 15:14:47 +020052static struct serdes_map board_serdes_map[] = {
53 {SATA0, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 0},
54 {SGMII1, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
55 {PEX1, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
56 {USB3_HOST1, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
57 {PEX2, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
58 {SGMII2, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
59};
60
Joel Johnson28bf4ca2020-03-23 14:21:32 -060061void config_cfbase_serdes_map(void)
62{
63 board_serdes_map[4].serdes_type = USB3_HOST0;
64 board_serdes_map[4].serdes_speed = SERDES_SPEED_5_GBPS;
65 board_serdes_map[4].serdes_mode = SERDES_DEFAULT_MODE;
66}
67
Stefan Roese73606402015-10-20 15:14:47 +020068int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count)
69{
Baruch Siach1c6e65d2020-01-20 14:20:14 +020070 cf_read_tlv_data();
71
Joel Johnson55beee12020-03-23 14:21:33 -060072 /* Apply build configuration options before runtime configuration */
73 if (IS_ENABLED(CONFIG_CLEARFOG_SFP_25GB))
74 board_serdes_map[5].serdes_speed = SERDES_SPEED_3_125_GBPS;
75
Joel Johnson165ce6a2020-03-23 14:21:34 -060076 if (IS_ENABLED(CONFIG_CLEARFOG_CON2_SATA)) {
77 board_serdes_map[4].serdes_type = SATA2;
78 board_serdes_map[4].serdes_speed = SERDES_SPEED_3_GBPS;
79 board_serdes_map[4].serdes_mode = SERDES_DEFAULT_MODE;
80 board_serdes_map[4].swap_rx = 1;
81 }
82
83 if (IS_ENABLED(CONFIG_CLEARFOG_CON3_SATA)) {
84 board_serdes_map[2].serdes_type = SATA1;
85 board_serdes_map[2].serdes_speed = SERDES_SPEED_3_GBPS;
86 board_serdes_map[2].serdes_mode = SERDES_DEFAULT_MODE;
87 board_serdes_map[2].swap_rx = 1;
88 }
89
Joel Johnson55beee12020-03-23 14:21:33 -060090 /* Apply runtime detection changes */
Baruch Siach1c6e65d2020-01-20 14:20:14 +020091 if (sr_product_is(&cf_tlv_data, "Clearfog GTR")) {
92 board_serdes_map[0].serdes_type = PEX0;
93 board_serdes_map[0].serdes_speed = SERDES_SPEED_5_GBPS;
94 board_serdes_map[0].serdes_mode = PEX_ROOT_COMPLEX_X1;
Joel Johnson28bf4ca2020-03-23 14:21:32 -060095 } else if (sr_product_is(&cf_tlv_data, "Clearfog Pro")) {
96 /* handle recognized product as noop, no adjustment required */
97 } else if (sr_product_is(&cf_tlv_data, "Clearfog Base")) {
98 config_cfbase_serdes_map();
99 } else {
100 /*
101 * Fallback to static default. EEPROM TLV support is not
102 * enabled, runtime detection failed, hardware support is not
103 * present, EEPROM is corrupt, or an unrecognized product name
104 * is present.
105 */
106 if (IS_ENABLED(CONFIG_SPL_CMD_TLV_EEPROM))
107 puts("EEPROM TLV detection failed: ");
108 puts("Using static config for ");
109 if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE)) {
110 puts("Clearfog Base.\n");
111 config_cfbase_serdes_map();
112 } else {
113 puts("Clearfog Pro.\n");
114 }
Baruch Siach1c6e65d2020-01-20 14:20:14 +0200115 }
116
Stefan Roese73606402015-10-20 15:14:47 +0200117 *serdes_map_array = board_serdes_map;
118 *count = ARRAY_SIZE(board_serdes_map);
119 return 0;
120}
121
122/*
123 * Define the DDR layout / topology here in the board file. This will
124 * be used by the DDR3 init code in the SPL U-Boot version to configure
125 * the DDR3 controller.
126 */
Chris Packham1a07d212018-05-10 13:28:29 +1200127static struct mv_ddr_topology_map board_topology_map = {
128 DEBUG_LEVEL_ERROR,
Stefan Roese73606402015-10-20 15:14:47 +0200129 0x1, /* active interfaces */
130 /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
131 { { { {0x1, 0, 0, 0},
132 {0x1, 0, 0, 0},
133 {0x1, 0, 0, 0},
134 {0x1, 0, 0, 0},
135 {0x1, 0, 0, 0} },
136 SPEED_BIN_DDR_1600K, /* speed_bin */
Chris Packham1a07d212018-05-10 13:28:29 +1200137 MV_DDR_DEV_WIDTH_16BIT, /* memory_width */
138 MV_DDR_DIE_CAP_4GBIT, /* mem_size */
Chris Packham4bf81db2018-12-03 14:26:49 +1300139 MV_DDR_FREQ_800, /* frequency */
Chris Packhamdd092bd2017-11-29 10:38:34 +1300140 0, 0, /* cas_wl cas_l */
Chris Packham3a09e132018-05-10 13:28:30 +1200141 MV_DDR_TEMP_LOW, /* temperature */
142 MV_DDR_TIM_DEFAULT} }, /* timing */
Chris Packham1a07d212018-05-10 13:28:29 +1200143 BUS_MASK_32BIT, /* Busses mask */
144 MV_DDR_CFG_DEFAULT, /* ddr configuration data source */
Moti Buskila498475e2021-02-19 17:11:19 +0100145 NOT_COMBINED, /* ddr twin-die combined */
Chris Packham1a07d212018-05-10 13:28:29 +1200146 { {0} }, /* raw spd data */
Baruch Siach43b76ce2020-01-20 14:20:07 +0200147 {0}, /* timing parameters */
148 { {0} }, /* electrical configuration */
149 {0,}, /* electrical parameters */
Chris Packhame8462fb2022-03-01 13:53:23 +1300150 0, /* ODT configuration */
Baruch Siach43b76ce2020-01-20 14:20:07 +0200151 0x3, /* clock enable mask */
Stefan Roese73606402015-10-20 15:14:47 +0200152};
153
Chris Packham1a07d212018-05-10 13:28:29 +1200154struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
Stefan Roese73606402015-10-20 15:14:47 +0200155{
Baruch Siach4417ff22020-01-20 14:20:11 +0200156 struct if_params *ifp = &board_topology_map.interface_params[0];
157
158 cf_read_tlv_data();
159
160 switch (cf_tlv_data.ram_size) {
161 case 4:
162 default:
163 ifp->memory_size = MV_DDR_DIE_CAP_4GBIT;
164 break;
165 case 8:
166 ifp->memory_size = MV_DDR_DIE_CAP_8GBIT;
167 break;
168 }
169
Stefan Roese73606402015-10-20 15:14:47 +0200170 /* Return the board topology as defined in the board code */
171 return &board_topology_map;
172}
173
174int board_early_init_f(void)
175{
176 /* Configure MPP */
177 writel(0x11111111, MVEBU_MPP_BASE + 0x00);
178 writel(0x11111111, MVEBU_MPP_BASE + 0x04);
179 writel(0x10400011, MVEBU_MPP_BASE + 0x08);
180 writel(0x22043333, MVEBU_MPP_BASE + 0x0c);
181 writel(0x44400002, MVEBU_MPP_BASE + 0x10);
182 writel(0x41144004, MVEBU_MPP_BASE + 0x14);
183 writel(0x40333333, MVEBU_MPP_BASE + 0x18);
184 writel(0x00004444, MVEBU_MPP_BASE + 0x1c);
185
186 /* Set GPP Out value */
187 writel(BOARD_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00);
188 writel(BOARD_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00);
189
190 /* Set GPP Polarity */
191 writel(BOARD_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c);
192 writel(BOARD_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c);
193
194 /* Set GPP Out Enable */
195 writel(BOARD_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04);
196 writel(BOARD_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04);
197
198 return 0;
199}
200
201int board_init(void)
202{
Stefan Roese73606402015-10-20 15:14:47 +0200203 /* Address of boot parameters */
204 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
205
206 /* Toggle GPIO41 to reset onboard switch and phy */
207 clrbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9));
208 clrbits_le32(MVEBU_GPIO1_BASE + 0x4, BIT(9));
Patrick Wildtb6bce292017-05-09 13:54:44 +0200209 /* GPIO 19 on ClearFog rev 2.1 controls the uSOM onboard phy reset */
210 clrbits_le32(MVEBU_GPIO0_BASE + 0x0, BIT(19));
211 clrbits_le32(MVEBU_GPIO0_BASE + 0x4, BIT(19));
Stefan Roese73606402015-10-20 15:14:47 +0200212 mdelay(1);
213 setbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9));
Patrick Wildtb6bce292017-05-09 13:54:44 +0200214 setbits_le32(MVEBU_GPIO0_BASE + 0x0, BIT(19));
Stefan Roese73606402015-10-20 15:14:47 +0200215 mdelay(10);
216
Stefan Roese73606402015-10-20 15:14:47 +0200217 return 0;
218}
219
220int checkboard(void)
221{
Joel Johnsonadd85bb2020-03-23 14:21:31 -0600222 char *board = "Clearfog Pro";
Joel Johnson28bf4ca2020-03-23 14:21:32 -0600223 if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE))
224 board = "Clearfog Base";
Baruch Siach61520472020-01-20 14:20:12 +0200225
226 cf_read_tlv_data();
227 if (strlen(cf_tlv_data.tlv_product_name[0]) > 0)
228 board = cf_tlv_data.tlv_product_name[0];
229
230 printf("Board: SolidRun %s", board);
231 if (strlen(cf_tlv_data.tlv_product_name[1]) > 0)
232 printf(", %s", cf_tlv_data.tlv_product_name[1]);
233 puts("\n");
Stefan Roese73606402015-10-20 15:14:47 +0200234
235 return 0;
236}
237
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900238int board_eth_init(struct bd_info *bis)
Stefan Roese73606402015-10-20 15:14:47 +0200239{
240 cpu_eth_init(bis); /* Built in controller(s) come first */
241 return pci_eth_init(bis);
242}
Baruch Siach1c5e95d2020-01-20 14:20:13 +0200243
244int board_late_init(void)
245{
Baruch Siach9f627a52020-09-09 15:14:39 +0300246 if (env_get("fdtfile"))
247 return 0;
248
Baruch Siach1c5e95d2020-01-20 14:20:13 +0200249 cf_read_tlv_data();
250
251 if (sr_product_is(&cf_tlv_data, "Clearfog Base"))
252 env_set("fdtfile", "armada-388-clearfog-base.dtb");
253 else if (sr_product_is(&cf_tlv_data, "Clearfog GTR S4"))
254 env_set("fdtfile", "armada-385-clearfog-gtr-s4.dtb");
255 else if (sr_product_is(&cf_tlv_data, "Clearfog GTR L8"))
256 env_set("fdtfile", "armada-385-clearfog-gtr-l8.dtb");
Joel Johnson28bf4ca2020-03-23 14:21:32 -0600257 else if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE))
258 env_set("fdtfile", "armada-388-clearfog-base.dtb");
Joel Johnsonc3809442020-03-23 14:21:35 -0600259 else
Joel Johnson026d4722020-03-23 14:21:40 -0600260 env_set("fdtfile", "armada-388-clearfog-pro.dtb");
Baruch Siach1c5e95d2020-01-20 14:20:13 +0200261
262 return 0;
263}