1 // SPDX-License-Identifier: GPL-2.0+
15 #include <asm/arch/cpu.h>
16 #include <asm-generic/gpio.h>
18 #include "../drivers/ddr/marvell/a38x/ddr3_init.h"
19 #include "../arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.h"
21 #include "keyprogram.h"
22 #include "dt_helpers.h"
26 DECLARE_GLOBAL_DATA_PTR;
28 #define DB_GP_88F68XX_GPP_OUT_ENA_LOW 0x7fffffff
29 #define DB_GP_88F68XX_GPP_OUT_ENA_MID 0xffffefff
31 #define DB_GP_88F68XX_GPP_OUT_VAL_LOW 0x0
32 #define DB_GP_88F68XX_GPP_OUT_VAL_MID 0x00001000
33 #define DB_GP_88F68XX_GPP_POL_LOW 0x0
34 #define DB_GP_88F68XX_GPP_POL_MID 0x0
36 static int get_tpm(struct udevice **devp)
40 rc = uclass_first_device_err(UCLASS_TPM, devp);
42 printf("Could not find TPM (ret=%d)\n", rc);
43 return CMD_RET_FAILURE;
50 * Define the DDR layout / topology here in the board file. This will
51 * be used by the DDR3 init code in the SPL U-Boot version to configure
52 * the DDR3 controller.
54 static struct mv_ddr_topology_map ddr_topology_map = {
56 0x1, /* active interfaces */
57 /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
63 SPEED_BIN_DDR_1600K, /* speed_bin */
64 MV_DDR_DEV_WIDTH_16BIT, /* memory_width */
65 MV_DDR_DIE_CAP_4GBIT, /* mem_size */
66 MV_DDR_FREQ_533, /* frequency */
67 0, 0, /* cas_wl cas_l */
68 MV_DDR_TEMP_LOW, /* temperature */
69 MV_DDR_TIM_DEFAULT} }, /* timing */
70 BUS_MASK_32BIT, /* Busses mask */
71 MV_DDR_CFG_DEFAULT, /* ddr configuration data source */
72 { {0} }, /* raw spd data */
73 {0} /* timing parameters */
77 static struct serdes_map serdes_topology_map[] = {
78 {SGMII0, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
79 {USB3_HOST0, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
80 /* SATA tx polarity is inverted */
81 {SATA1, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 1},
82 {SGMII2, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
83 {DEFAULT_SERDES, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 0},
84 {PEX2, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}
87 int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count)
89 *serdes_map_array = serdes_topology_map;
90 *count = ARRAY_SIZE(serdes_topology_map);
94 void board_pex_config(void)
96 #ifdef CONFIG_SPL_BUILD
98 struct gpio_desc gpio = {};
100 if (!request_gpio_by_name(&gpio, "pca9698@22", 31, "fpga-program-gpio")) {
101 /* prepare FPGA reconfiguration */
102 dm_gpio_set_dir_flags(&gpio, GPIOD_IS_OUT);
103 dm_gpio_set_value(&gpio, 0);
105 /* give lunatic PCIe clock some time to stabilize */
108 /* start FPGA reconfiguration */
109 dm_gpio_set_dir_flags(&gpio, GPIOD_IS_IN);
112 /* wait for FPGA done */
113 if (!request_gpio_by_name(&gpio, "pca9698@22", 19, "fpga-done-gpio")) {
114 for (k = 0; k < 20; ++k) {
115 if (dm_gpio_get_value(&gpio)) {
116 printf("FPGA done after %u rounds\n", k);
123 /* disable FPGA reset */
124 if (!request_gpio_by_name(&gpio, "gpio@18100", 6, "cpu-to-fpga-reset")) {
125 dm_gpio_set_dir_flags(&gpio, GPIOD_IS_OUT);
126 dm_gpio_set_value(&gpio, 1);
129 /* wait for FPGA ready */
130 if (!request_gpio_by_name(&gpio, "pca9698@22", 27, "fpga-ready-gpio")) {
131 for (k = 0; k < 2; ++k) {
132 if (!dm_gpio_get_value(&gpio))
140 struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
142 return &ddr_topology_map;
145 int board_early_init_f(void)
147 #ifdef CONFIG_SPL_BUILD
149 writel(0x00111111, MVEBU_MPP_BASE + 0x00);
150 writel(0x40040000, MVEBU_MPP_BASE + 0x04);
151 writel(0x00466444, MVEBU_MPP_BASE + 0x08);
152 writel(0x00043300, MVEBU_MPP_BASE + 0x0c);
153 writel(0x44400000, MVEBU_MPP_BASE + 0x10);
154 writel(0x20000334, MVEBU_MPP_BASE + 0x14);
155 writel(0x40000000, MVEBU_MPP_BASE + 0x18);
156 writel(0x00004444, MVEBU_MPP_BASE + 0x1c);
158 /* Set GPP Out value */
159 writel(DB_GP_88F68XX_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00);
160 writel(DB_GP_88F68XX_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00);
162 /* Set GPP Polarity */
163 writel(DB_GP_88F68XX_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c);
164 writel(DB_GP_88F68XX_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c);
166 /* Set GPP Out Enable */
167 writel(DB_GP_88F68XX_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04);
168 writel(DB_GP_88F68XX_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04);
176 /* Address of boot parameters */
177 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
182 #ifndef CONFIG_SPL_BUILD
183 void init_host_phys(struct mii_dev *bus)
187 for (k = 0; k < 2; ++k) {
188 struct phy_device *phydev;
190 phydev = phy_find_by_mask(bus, 1 << k,
191 PHY_INTERFACE_MODE_SGMII);
198 int ccdc_eth_init(void)
201 uint octo_phy_mask = 0;
205 /* Init SoC's phys */
206 bus = miiphy_get_dev_by_name("ethernet@34000");
211 bus = miiphy_get_dev_by_name("ethernet@70000");
217 octo_phy_mask = calculate_octo_phy_mask();
219 printf("IHS PHYS: %08x", octo_phy_mask);
221 ret = init_octo_phys(octo_phy_mask);
229 puts("fpga was NULL\n");
233 /* reset all FPGA-QSGMII instances */
234 for (k = 0; k < 80; ++k)
235 writel(1 << 31, get_fpga()->qsgmii_port_state[k]);
239 for (k = 0; k < 80; ++k)
240 writel(0, get_fpga()->qsgmii_port_state[k]);
246 int board_late_init(void)
248 #ifndef CONFIG_SPL_BUILD
254 int board_fix_fdt(void *rw_fdt_blob)
256 struct udevice *bus = NULL;
261 err = uclass_get_device_by_name(UCLASS_I2C, "i2c@11000", &bus);
264 printf("Could not get I2C bus.\n");
268 for (k = 0x21; k <= 0x26; k++) {
270 "/soc/internal-regs/i2c@11000/pca9698@%02x", k);
272 if (!dm_i2c_simple_probe(bus, k))
273 fdt_disable_by_ofname(rw_fdt_blob, name);
279 int last_stage_init(void)
284 #ifndef CONFIG_SPL_BUILD
288 if (ret || tpm_init(tpm) || tpm_startup(tpm, TPM_ST_CLEAR) ||
289 tpm_continue_self_test(tpm)) {
296 load_and_run_keyprog(tpm);