]> Git Repo - J-u-boot.git/blame - board/gdsys/a38x/controlcenterdc.c
command: Remove the cmd_tbl_t typedef
[J-u-boot.git] / board / gdsys / a38x / controlcenterdc.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
60083261
DE
2/*
3 * Copyright (C) 2015 Stefan Roese <[email protected]>
4 * Copyright (C) 2016 Mario Six <[email protected]>
60083261
DE
5 */
6
7#include <common.h>
09140113 8#include <command.h>
60083261 9#include <dm.h>
5255932f 10#include <init.h>
60083261 11#include <miiphy.h>
90526e9f 12#include <net.h>
d677bfe2 13#include <tpm-v1.h>
60083261
DE
14#include <asm/io.h>
15#include <asm/arch/cpu.h>
16#include <asm-generic/gpio.h>
17
2b4ffbf6 18#include "../drivers/ddr/marvell/a38x/ddr3_init.h"
60083261
DE
19#include "../arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.h"
20
21#include "keyprogram.h"
22#include "dt_helpers.h"
23#include "hydra.h"
24#include "ihs_phys.h"
25
26DECLARE_GLOBAL_DATA_PTR;
27
60083261
DE
28#define DB_GP_88F68XX_GPP_OUT_ENA_LOW 0x7fffffff
29#define DB_GP_88F68XX_GPP_OUT_ENA_MID 0xffffefff
30
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
35
abdc7b8a
SG
36static int get_tpm(struct udevice **devp)
37{
38 int rc;
39
40 rc = uclass_first_device_err(UCLASS_TPM, devp);
41 if (rc) {
42 printf("Could not find TPM (ret=%d)\n", rc);
43 return CMD_RET_FAILURE;
44 }
45
46 return 0;
47}
48
60083261
DE
49/*
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.
53 */
2b4ffbf6
CP
54static struct mv_ddr_topology_map ddr_topology_map = {
55 DEBUG_LEVEL_ERROR,
60083261
DE
56 0x1, /* active interfaces */
57 /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
58 { { { {0x1, 0, 0, 0},
59 {0x1, 0, 0, 0},
60 {0x1, 0, 0, 0},
61 {0x1, 0, 0, 0},
62 {0x1, 0, 0, 0} },
63 SPEED_BIN_DDR_1600K, /* speed_bin */
2b4ffbf6
CP
64 MV_DDR_DEV_WIDTH_16BIT, /* memory_width */
65 MV_DDR_DIE_CAP_4GBIT, /* mem_size */
ebb1a593 66 MV_DDR_FREQ_533, /* frequency */
01c541e0 67 0, 0, /* cas_wl cas_l */
e6f61622
CP
68 MV_DDR_TEMP_LOW, /* temperature */
69 MV_DDR_TIM_DEFAULT} }, /* timing */
2b4ffbf6
CP
70 BUS_MASK_32BIT, /* Busses mask */
71 MV_DDR_CFG_DEFAULT, /* ddr configuration data source */
72 { {0} }, /* raw spd data */
73 {0} /* timing parameters */
74
60083261
DE
75};
76
77static 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}
85};
86
87int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count)
88{
89 *serdes_map_array = serdes_topology_map;
90 *count = ARRAY_SIZE(serdes_topology_map);
91 return 0;
92}
93
94void board_pex_config(void)
95{
96#ifdef CONFIG_SPL_BUILD
97 uint k;
98 struct gpio_desc gpio = {};
99
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);
104
105 /* give lunatic PCIe clock some time to stabilize */
106 mdelay(500);
107
108 /* start FPGA reconfiguration */
109 dm_gpio_set_dir_flags(&gpio, GPIOD_IS_IN);
110 }
111
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);
117 break;
118 }
119 mdelay(100);
120 }
121 }
122
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);
127 }
128
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))
133 break;
134 mdelay(100);
135 }
136 }
137#endif
138}
139
2b4ffbf6 140struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
60083261
DE
141{
142 return &ddr_topology_map;
143}
144
145int board_early_init_f(void)
146{
147#ifdef CONFIG_SPL_BUILD
148 /* Configure MPP */
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);
157
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);
161
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);
165
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);
169#endif
170
171 return 0;
172}
173
174int board_init(void)
175{
176 /* Address of boot parameters */
177 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
178
179 return 0;
180}
181
182#ifndef CONFIG_SPL_BUILD
183void init_host_phys(struct mii_dev *bus)
184{
185 uint k;
186
187 for (k = 0; k < 2; ++k) {
188 struct phy_device *phydev;
189
190 phydev = phy_find_by_mask(bus, 1 << k,
191 PHY_INTERFACE_MODE_SGMII);
192
193 if (phydev)
194 phy_config(phydev);
195 }
196}
197
198int ccdc_eth_init(void)
199{
200 uint k;
201 uint octo_phy_mask = 0;
202 int ret;
203 struct mii_dev *bus;
204
205 /* Init SoC's phys */
206 bus = miiphy_get_dev_by_name("ethernet@34000");
207
208 if (bus)
209 init_host_phys(bus);
210
211 bus = miiphy_get_dev_by_name("ethernet@70000");
212
213 if (bus)
214 init_host_phys(bus);
215
216 /* Init octo phys */
217 octo_phy_mask = calculate_octo_phy_mask();
218
219 printf("IHS PHYS: %08x", octo_phy_mask);
220
221 ret = init_octo_phys(octo_phy_mask);
222
223 if (ret)
224 return ret;
225
226 printf("\n");
227
228 if (!get_fpga()) {
229 puts("fpga was NULL\n");
230 return 1;
231 }
232
233 /* reset all FPGA-QSGMII instances */
234 for (k = 0; k < 80; ++k)
235 writel(1 << 31, get_fpga()->qsgmii_port_state[k]);
236
237 udelay(100);
238
239 for (k = 0; k < 80; ++k)
240 writel(0, get_fpga()->qsgmii_port_state[k]);
241 return 0;
242}
243
244#endif
245
246int board_late_init(void)
247{
248#ifndef CONFIG_SPL_BUILD
249 hydra_initialize();
250#endif
251 return 0;
252}
253
254int board_fix_fdt(void *rw_fdt_blob)
255{
256 struct udevice *bus = NULL;
257 uint k;
258 char name[64];
259 int err;
260
261 err = uclass_get_device_by_name(UCLASS_I2C, "i2c@11000", &bus);
262
263 if (err) {
264 printf("Could not get I2C bus.\n");
265 return err;
266 }
267
268 for (k = 0x21; k <= 0x26; k++) {
269 snprintf(name, 64,
270 "/soc/internal-regs/i2c@11000/pca9698@%02x", k);
271
272 if (!dm_i2c_simple_probe(bus, k))
273 fdt_disable_by_ofname(rw_fdt_blob, name);
274 }
275
276 return 0;
277}
278
279int last_stage_init(void)
280{
abdc7b8a
SG
281 struct udevice *tpm;
282 int ret;
283
60083261
DE
284#ifndef CONFIG_SPL_BUILD
285 ccdc_eth_init();
286#endif
abdc7b8a
SG
287 ret = get_tpm(&tpm);
288 if (ret || tpm_init(tpm) || tpm_startup(tpm, TPM_ST_CLEAR) ||
289 tpm_continue_self_test(tpm)) {
60083261
DE
290 return 1;
291 }
292
293 mdelay(37);
294
abdc7b8a
SG
295 flush_keys(tpm);
296 load_and_run_keyprog(tpm);
60083261
DE
297
298 return 0;
299}
This page took 0.220199 seconds and 4 git commands to generate.