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