blob: ba57a272187e2e1036c488aeed23a3bd19ce8ad5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dirk Eibachfb605942017-02-22 16:07:23 +01002/*
3 * Copyright (C) 2015 Stefan Roese <sr@denx.de>
4 * Copyright (C) 2016 Mario Six <mario.six@gdsys.cc>
Dirk Eibachfb605942017-02-22 16:07:23 +01005 */
6
7#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -06008#include <command.h>
Dirk Eibachfb605942017-02-22 16:07:23 +01009#include <dm.h>
Simon Glassa7b51302019-11-14 12:57:46 -070010#include <init.h>
Dirk Eibachfb605942017-02-22 16:07:23 +010011#include <miiphy.h>
Simon Glass274e0b02020-05-10 11:39:56 -060012#include <net.h>
Miquel Raynal4c6759e2018-05-15 11:57:06 +020013#include <tpm-v1.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Dirk Eibachfb605942017-02-22 16:07:23 +010015#include <asm/io.h>
16#include <asm/arch/cpu.h>
17#include <asm-generic/gpio.h>
Simon Glassdbd79542020-05-10 11:40:11 -060018#include <linux/delay.h>
Dirk Eibachfb605942017-02-22 16:07:23 +010019
Chris Packham1a07d212018-05-10 13:28:29 +120020#include "../drivers/ddr/marvell/a38x/ddr3_init.h"
Dirk Eibachfb605942017-02-22 16:07:23 +010021#include "../arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.h"
22
23#include "keyprogram.h"
24#include "dt_helpers.h"
25#include "hydra.h"
26#include "ihs_phys.h"
27
28DECLARE_GLOBAL_DATA_PTR;
29
Dirk Eibachfb605942017-02-22 16:07:23 +010030#define DB_GP_88F68XX_GPP_OUT_ENA_LOW 0x7fffffff
31#define DB_GP_88F68XX_GPP_OUT_ENA_MID 0xffffefff
32
33#define DB_GP_88F68XX_GPP_OUT_VAL_LOW 0x0
34#define DB_GP_88F68XX_GPP_OUT_VAL_MID 0x00001000
35#define DB_GP_88F68XX_GPP_POL_LOW 0x0
36#define DB_GP_88F68XX_GPP_POL_MID 0x0
37
Simon Glass8ceca1d2018-11-18 14:22:27 -070038static int get_tpm(struct udevice **devp)
39{
40 int rc;
41
42 rc = uclass_first_device_err(UCLASS_TPM, devp);
43 if (rc) {
44 printf("Could not find TPM (ret=%d)\n", rc);
45 return CMD_RET_FAILURE;
46 }
47
48 return 0;
49}
50
Dirk Eibachfb605942017-02-22 16:07:23 +010051/*
52 * Define the DDR layout / topology here in the board file. This will
53 * be used by the DDR3 init code in the SPL U-Boot version to configure
54 * the DDR3 controller.
55 */
Chris Packham1a07d212018-05-10 13:28:29 +120056static struct mv_ddr_topology_map ddr_topology_map = {
57 DEBUG_LEVEL_ERROR,
Dirk Eibachfb605942017-02-22 16:07:23 +010058 0x1, /* active interfaces */
59 /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
60 { { { {0x1, 0, 0, 0},
61 {0x1, 0, 0, 0},
62 {0x1, 0, 0, 0},
63 {0x1, 0, 0, 0},
64 {0x1, 0, 0, 0} },
65 SPEED_BIN_DDR_1600K, /* speed_bin */
Chris Packham1a07d212018-05-10 13:28:29 +120066 MV_DDR_DEV_WIDTH_16BIT, /* memory_width */
67 MV_DDR_DIE_CAP_4GBIT, /* mem_size */
Chris Packham4bf81db2018-12-03 14:26:49 +130068 MV_DDR_FREQ_533, /* frequency */
Chris Packhamdd092bd2017-11-29 10:38:34 +130069 0, 0, /* cas_wl cas_l */
Chris Packham3a09e132018-05-10 13:28:30 +120070 MV_DDR_TEMP_LOW, /* temperature */
71 MV_DDR_TIM_DEFAULT} }, /* timing */
Chris Packham1a07d212018-05-10 13:28:29 +120072 BUS_MASK_32BIT, /* Busses mask */
73 MV_DDR_CFG_DEFAULT, /* ddr configuration data source */
74 { {0} }, /* raw spd data */
75 {0} /* timing parameters */
76
Dirk Eibachfb605942017-02-22 16:07:23 +010077};
78
79static struct serdes_map serdes_topology_map[] = {
80 {SGMII0, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
81 {USB3_HOST0, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
82 /* SATA tx polarity is inverted */
83 {SATA1, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 1},
84 {SGMII2, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
85 {DEFAULT_SERDES, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 0},
86 {PEX2, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}
87};
88
89int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count)
90{
91 *serdes_map_array = serdes_topology_map;
92 *count = ARRAY_SIZE(serdes_topology_map);
93 return 0;
94}
95
96void board_pex_config(void)
97{
98#ifdef CONFIG_SPL_BUILD
99 uint k;
100 struct gpio_desc gpio = {};
101
102 if (!request_gpio_by_name(&gpio, "pca9698@22", 31, "fpga-program-gpio")) {
103 /* prepare FPGA reconfiguration */
104 dm_gpio_set_dir_flags(&gpio, GPIOD_IS_OUT);
105 dm_gpio_set_value(&gpio, 0);
106
107 /* give lunatic PCIe clock some time to stabilize */
108 mdelay(500);
109
110 /* start FPGA reconfiguration */
111 dm_gpio_set_dir_flags(&gpio, GPIOD_IS_IN);
112 }
113
114 /* wait for FPGA done */
115 if (!request_gpio_by_name(&gpio, "pca9698@22", 19, "fpga-done-gpio")) {
116 for (k = 0; k < 20; ++k) {
117 if (dm_gpio_get_value(&gpio)) {
118 printf("FPGA done after %u rounds\n", k);
119 break;
120 }
121 mdelay(100);
122 }
123 }
124
125 /* disable FPGA reset */
126 if (!request_gpio_by_name(&gpio, "gpio@18100", 6, "cpu-to-fpga-reset")) {
127 dm_gpio_set_dir_flags(&gpio, GPIOD_IS_OUT);
128 dm_gpio_set_value(&gpio, 1);
129 }
130
131 /* wait for FPGA ready */
132 if (!request_gpio_by_name(&gpio, "pca9698@22", 27, "fpga-ready-gpio")) {
133 for (k = 0; k < 2; ++k) {
134 if (!dm_gpio_get_value(&gpio))
135 break;
136 mdelay(100);
137 }
138 }
139#endif
140}
141
Chris Packham1a07d212018-05-10 13:28:29 +1200142struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
Dirk Eibachfb605942017-02-22 16:07:23 +0100143{
144 return &ddr_topology_map;
145}
146
147int board_early_init_f(void)
148{
149#ifdef CONFIG_SPL_BUILD
150 /* Configure MPP */
151 writel(0x00111111, MVEBU_MPP_BASE + 0x00);
152 writel(0x40040000, MVEBU_MPP_BASE + 0x04);
153 writel(0x00466444, MVEBU_MPP_BASE + 0x08);
154 writel(0x00043300, MVEBU_MPP_BASE + 0x0c);
155 writel(0x44400000, MVEBU_MPP_BASE + 0x10);
156 writel(0x20000334, MVEBU_MPP_BASE + 0x14);
157 writel(0x40000000, MVEBU_MPP_BASE + 0x18);
158 writel(0x00004444, MVEBU_MPP_BASE + 0x1c);
159
160 /* Set GPP Out value */
161 writel(DB_GP_88F68XX_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00);
162 writel(DB_GP_88F68XX_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00);
163
164 /* Set GPP Polarity */
165 writel(DB_GP_88F68XX_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c);
166 writel(DB_GP_88F68XX_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c);
167
168 /* Set GPP Out Enable */
169 writel(DB_GP_88F68XX_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04);
170 writel(DB_GP_88F68XX_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04);
171#endif
172
173 return 0;
174}
175
176int board_init(void)
177{
178 /* Address of boot parameters */
179 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
180
181 return 0;
182}
183
184#ifndef CONFIG_SPL_BUILD
185void init_host_phys(struct mii_dev *bus)
186{
187 uint k;
188
189 for (k = 0; k < 2; ++k) {
190 struct phy_device *phydev;
191
192 phydev = phy_find_by_mask(bus, 1 << k,
193 PHY_INTERFACE_MODE_SGMII);
194
195 if (phydev)
196 phy_config(phydev);
197 }
198}
199
200int ccdc_eth_init(void)
201{
202 uint k;
203 uint octo_phy_mask = 0;
204 int ret;
205 struct mii_dev *bus;
206
207 /* Init SoC's phys */
208 bus = miiphy_get_dev_by_name("ethernet@34000");
209
210 if (bus)
211 init_host_phys(bus);
212
213 bus = miiphy_get_dev_by_name("ethernet@70000");
214
215 if (bus)
216 init_host_phys(bus);
217
218 /* Init octo phys */
219 octo_phy_mask = calculate_octo_phy_mask();
220
221 printf("IHS PHYS: %08x", octo_phy_mask);
222
223 ret = init_octo_phys(octo_phy_mask);
224
225 if (ret)
226 return ret;
227
228 printf("\n");
229
230 if (!get_fpga()) {
231 puts("fpga was NULL\n");
232 return 1;
233 }
234
235 /* reset all FPGA-QSGMII instances */
236 for (k = 0; k < 80; ++k)
237 writel(1 << 31, get_fpga()->qsgmii_port_state[k]);
238
239 udelay(100);
240
241 for (k = 0; k < 80; ++k)
242 writel(0, get_fpga()->qsgmii_port_state[k]);
243 return 0;
244}
245
246#endif
247
248int board_late_init(void)
249{
250#ifndef CONFIG_SPL_BUILD
251 hydra_initialize();
252#endif
253 return 0;
254}
255
256int board_fix_fdt(void *rw_fdt_blob)
257{
258 struct udevice *bus = NULL;
259 uint k;
260 char name[64];
261 int err;
262
263 err = uclass_get_device_by_name(UCLASS_I2C, "i2c@11000", &bus);
264
265 if (err) {
266 printf("Could not get I2C bus.\n");
267 return err;
268 }
269
270 for (k = 0x21; k <= 0x26; k++) {
271 snprintf(name, 64,
272 "/soc/internal-regs/i2c@11000/pca9698@%02x", k);
273
274 if (!dm_i2c_simple_probe(bus, k))
275 fdt_disable_by_ofname(rw_fdt_blob, name);
276 }
277
278 return 0;
279}
280
281int last_stage_init(void)
282{
Simon Glass8ceca1d2018-11-18 14:22:27 -0700283 struct udevice *tpm;
284 int ret;
285
Dirk Eibachfb605942017-02-22 16:07:23 +0100286#ifndef CONFIG_SPL_BUILD
287 ccdc_eth_init();
288#endif
Simon Glass8ceca1d2018-11-18 14:22:27 -0700289 ret = get_tpm(&tpm);
290 if (ret || tpm_init(tpm) || tpm_startup(tpm, TPM_ST_CLEAR) ||
291 tpm_continue_self_test(tpm)) {
Dirk Eibachfb605942017-02-22 16:07:23 +0100292 return 1;
293 }
294
295 mdelay(37);
296
Simon Glass8ceca1d2018-11-18 14:22:27 -0700297 flush_keys(tpm);
298 load_and_run_keyprog(tpm);
Dirk Eibachfb605942017-02-22 16:07:23 +0100299
300 return 0;
301}