blob: 1033d44409ef8690a516dc4e3827c825e2ecab08 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ashish Kumar227b4bc2017-08-31 16:12:54 +05302/*
Pramod Kumara0531822018-10-12 14:04:27 +00003 * Copyright 2017-2018 NXP
Ashish Kumar227b4bc2017-08-31 16:12:54 +05304 */
5#include <common.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06006#include <env.h>
Ashish Kumar227b4bc2017-08-31 16:12:54 +05307#include <i2c.h>
8#include <malloc.h>
9#include <errno.h>
10#include <netdev.h>
11#include <fsl_ifc.h>
12#include <fsl_ddr.h>
13#include <fsl_sec.h>
14#include <asm/io.h>
15#include <fdt_support.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090016#include <linux/libfdt.h>
Ashish Kumar227b4bc2017-08-31 16:12:54 +053017#include <fsl-mc/fsl_mc.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060018#include <env_internal.h>
Ashish Kumar227b4bc2017-08-31 16:12:54 +053019#include <asm/arch-fsl-layerscape/soc.h>
20#include <asm/arch/ppa.h>
Yangbo Lu1d879532017-11-27 15:40:17 +080021#include <hwconfig.h>
Rajesh Bhagata4216252018-01-17 16:13:09 +053022#include <asm/arch/fsl_serdes.h>
23#include <asm/arch/soc.h>
Ashish Kumar227b4bc2017-08-31 16:12:54 +053024
25#include "../common/qixis.h"
26#include "ls1088a_qixis.h"
Rajesh Bhagata4216252018-01-17 16:13:09 +053027#include "../common/vid.h"
28#include <fsl_immap.h>
Ashish Kumar227b4bc2017-08-31 16:12:54 +053029
30DECLARE_GLOBAL_DATA_PTR;
31
Pankit Garg112aeba2018-12-27 04:37:57 +000032#ifdef CONFIG_TARGET_LS1088AQDS
33#ifdef CONFIG_TFABOOT
34struct ifc_regs ifc_cfg_ifc_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
35 {
36 "nor0",
37 CONFIG_SYS_NOR0_CSPR_EARLY,
38 CONFIG_SYS_NOR0_CSPR_EXT,
39 CONFIG_SYS_NOR_AMASK,
40 CONFIG_SYS_NOR_CSOR,
41 {
42 CONFIG_SYS_NOR_FTIM0,
43 CONFIG_SYS_NOR_FTIM1,
44 CONFIG_SYS_NOR_FTIM2,
45 CONFIG_SYS_NOR_FTIM3
46 },
47 0,
48 CONFIG_SYS_NOR0_CSPR,
49 0,
50 },
51 {
52 "nor1",
53 CONFIG_SYS_NOR1_CSPR_EARLY,
54 CONFIG_SYS_NOR0_CSPR_EXT,
55 CONFIG_SYS_NOR_AMASK_EARLY,
56 CONFIG_SYS_NOR_CSOR,
57 {
58 CONFIG_SYS_NOR_FTIM0,
59 CONFIG_SYS_NOR_FTIM1,
60 CONFIG_SYS_NOR_FTIM2,
61 CONFIG_SYS_NOR_FTIM3
62 },
63 0,
64 CONFIG_SYS_NOR1_CSPR,
65 CONFIG_SYS_NOR_AMASK,
66 },
67 {
68 "nand",
69 CONFIG_SYS_NAND_CSPR,
70 CONFIG_SYS_NAND_CSPR_EXT,
71 CONFIG_SYS_NAND_AMASK,
72 CONFIG_SYS_NAND_CSOR,
73 {
74 CONFIG_SYS_NAND_FTIM0,
75 CONFIG_SYS_NAND_FTIM1,
76 CONFIG_SYS_NAND_FTIM2,
77 CONFIG_SYS_NAND_FTIM3
78 },
79 },
80 {
81 "fpga",
82 CONFIG_SYS_FPGA_CSPR,
83 CONFIG_SYS_FPGA_CSPR_EXT,
84 SYS_FPGA_AMASK,
85 CONFIG_SYS_FPGA_CSOR,
86 {
87 SYS_FPGA_CS_FTIM0,
88 SYS_FPGA_CS_FTIM1,
89 SYS_FPGA_CS_FTIM2,
90 SYS_FPGA_CS_FTIM3
91 },
92 0,
93 SYS_FPGA_CSPR_FINAL,
94 0,
95 }
96};
97
98struct ifc_regs ifc_cfg_qspi_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
99 {
100 "nand",
101 CONFIG_SYS_NAND_CSPR,
102 CONFIG_SYS_NAND_CSPR_EXT,
103 CONFIG_SYS_NAND_AMASK,
104 CONFIG_SYS_NAND_CSOR,
105 {
106 CONFIG_SYS_NAND_FTIM0,
107 CONFIG_SYS_NAND_FTIM1,
108 CONFIG_SYS_NAND_FTIM2,
109 CONFIG_SYS_NAND_FTIM3
110 },
111 },
112 {
113 "reserved",
114 },
115 {
116 "fpga",
117 CONFIG_SYS_FPGA_CSPR,
118 CONFIG_SYS_FPGA_CSPR_EXT,
119 SYS_FPGA_AMASK,
120 CONFIG_SYS_FPGA_CSOR,
121 {
122 SYS_FPGA_CS_FTIM0,
123 SYS_FPGA_CS_FTIM1,
124 SYS_FPGA_CS_FTIM2,
125 SYS_FPGA_CS_FTIM3
126 },
127 0,
128 SYS_FPGA_CSPR_FINAL,
129 0,
130 }
131};
132
133void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
134{
135 enum boot_src src = get_boot_src();
136
137 if (src == BOOT_SOURCE_QSPI_NOR)
138 regs_info->regs = ifc_cfg_qspi_nor_boot;
139 else
140 regs_info->regs = ifc_cfg_ifc_nor_boot;
141
142 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
143}
144#endif /* CONFIG_TFABOOT */
145#endif /* CONFIG_TARGET_LS1088AQDS */
146
Sumit Garg08da8b22018-01-06 09:04:24 +0530147int board_early_init_f(void)
148{
Ashish Kumarf719b192018-02-19 14:14:53 +0530149#if defined(CONFIG_SYS_I2C_EARLY_INIT) && defined(CONFIG_TARGET_LS1088AQDS)
150 i2c_early_init_f();
151#endif
Sumit Garg08da8b22018-01-06 09:04:24 +0530152 fsl_lsch3_early_init_f();
153 return 0;
154}
155
156#ifdef CONFIG_FSL_QIXIS
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530157unsigned long long get_qixis_addr(void)
158{
159 unsigned long long addr;
160
161 if (gd->flags & GD_FLG_RELOC)
162 addr = QIXIS_BASE_PHYS;
163 else
164 addr = QIXIS_BASE_PHYS_EARLY;
165
166 /*
167 * IFC address under 256MB is mapped to 0x30000000, any address above
168 * is mapped to 0x5_10000000 up to 4GB.
169 */
170 addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
171
172 return addr;
173}
Sumit Garg08da8b22018-01-06 09:04:24 +0530174#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530175
Rajesh Bhagata4216252018-01-17 16:13:09 +0530176#if defined(CONFIG_VID)
177int init_func_vid(void)
178{
179 if (adjust_vdd(0) < 0)
180 printf("core voltage not adjusted\n");
181
182 return 0;
183}
184#endif
185
Pramod Kumara0531822018-10-12 14:04:27 +0000186int is_pb_board(void)
187{
188 u8 board_id;
189
190 board_id = QIXIS_READ(id);
191 if (board_id == LS1088ARDB_PB_BOARD)
192 return 1;
193 else
194 return 0;
195}
196
197int fixup_ls1088ardb_pb_banner(void *fdt)
198{
199 fdt_setprop_string(fdt, 0, "model", "LS1088ARDB-PB Board");
200
201 return 0;
202}
203
Sumit Garg08da8b22018-01-06 09:04:24 +0530204#if !defined(CONFIG_SPL_BUILD)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530205int checkboard(void)
206{
Pankit Gargf5c2a832018-12-27 04:37:55 +0000207#ifdef CONFIG_TFABOOT
208 enum boot_src src = get_boot_src();
209#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530210 char buf[64];
211 u8 sw;
212 static const char *const freq[] = {"100", "125", "156.25",
213 "100 separate SSCG"};
214 int clock;
215
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530216#ifdef CONFIG_TARGET_LS1088AQDS
217 printf("Board: LS1088A-QDS, ");
218#else
Pramod Kumara0531822018-10-12 14:04:27 +0000219 if (is_pb_board())
220 printf("Board: LS1088ARDB-PB, ");
221 else
222 printf("Board: LS1088A-RDB, ");
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530223#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530224
225 sw = QIXIS_READ(arch);
226 printf("Board Arch: V%d, ", sw >> 4);
227
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530228#ifdef CONFIG_TARGET_LS1088AQDS
229 printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1);
230#else
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530231 printf("Board version: %c, boot from ", (sw & 0xf) + 'A');
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530232#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530233
234 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
235
236 sw = QIXIS_READ(brdcfg[0]);
237 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
238
Pankit Gargf5c2a832018-12-27 04:37:55 +0000239#ifdef CONFIG_TFABOOT
240 if (src == BOOT_SOURCE_SD_MMC)
241 puts("SD card\n");
242#else
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530243#ifdef CONFIG_SD_BOOT
244 puts("SD card\n");
245#endif
Pankit Gargf5c2a832018-12-27 04:37:55 +0000246#endif /* CONFIG_TFABOOT */
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530247 switch (sw) {
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530248#ifdef CONFIG_TARGET_LS1088AQDS
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530249 case 0:
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530250 case 1:
251 case 2:
252 case 3:
253 case 4:
254 case 5:
255 case 6:
256 case 7:
257 printf("vBank: %d\n", sw);
258 break;
259 case 8:
260 puts("PromJet\n");
261 break;
262 case 15:
263 puts("IFCCard\n");
264 break;
265 case 14:
266#else
267 case 0:
268#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530269 puts("QSPI:");
270 sw = QIXIS_READ(brdcfg[0]);
271 sw = (sw & QIXIS_QMAP_MASK) >> QIXIS_QMAP_SHIFT;
272 if (sw == 0 || sw == 4)
273 puts("0\n");
274 else if (sw == 1)
275 puts("1\n");
276 else
277 puts("EMU\n");
278 break;
279
280 default:
281 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
282 break;
283 }
284
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530285#ifdef CONFIG_TARGET_LS1088AQDS
286 printf("FPGA: v%d (%s), build %d",
287 (int)QIXIS_READ(scver), qixis_read_tag(buf),
288 (int)qixis_read_minor());
289 /* the timestamp string contains "\n" at the end */
290 printf(" on %s", qixis_read_time(buf));
291#else
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530292 printf("CPLD: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530293#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530294
295 /*
296 * Display the actual SERDES reference clocks as configured by the
297 * dip switches on the board. Note that the SWx registers could
298 * technically be set to force the reference clocks to match the
299 * values that the SERDES expects (or vice versa). For now, however,
300 * we just display both values and hope the user notices when they
301 * don't match.
302 */
303 puts("SERDES1 Reference : ");
304 sw = QIXIS_READ(brdcfg[2]);
305 clock = (sw >> 6) & 3;
306 printf("Clock1 = %sMHz ", freq[clock]);
307 clock = (sw >> 4) & 3;
308 printf("Clock2 = %sMHz", freq[clock]);
309
310 puts("\nSERDES2 Reference : ");
311 clock = (sw >> 2) & 3;
312 printf("Clock1 = %sMHz ", freq[clock]);
313 clock = (sw >> 0) & 3;
314 printf("Clock2 = %sMHz\n", freq[clock]);
315
316 return 0;
317}
Ashish Kumard029b272018-02-19 14:14:52 +0530318#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530319
320bool if_board_diff_clk(void)
321{
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530322#ifdef CONFIG_TARGET_LS1088AQDS
323 u8 diff_conf = QIXIS_READ(brdcfg[11]);
324 return diff_conf & 0x40;
325#else
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530326 u8 diff_conf = QIXIS_READ(dutcfg[11]);
327 return diff_conf & 0x80;
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530328#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530329}
330
331unsigned long get_board_sys_clk(void)
332{
333 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
334
335 switch (sysclk_conf & 0x0f) {
336 case QIXIS_SYSCLK_83:
337 return 83333333;
338 case QIXIS_SYSCLK_100:
339 return 100000000;
340 case QIXIS_SYSCLK_125:
341 return 125000000;
342 case QIXIS_SYSCLK_133:
343 return 133333333;
344 case QIXIS_SYSCLK_150:
345 return 150000000;
346 case QIXIS_SYSCLK_160:
347 return 160000000;
348 case QIXIS_SYSCLK_166:
349 return 166666666;
350 }
351
352 return 66666666;
353}
354
355unsigned long get_board_ddr_clk(void)
356{
357 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
358
359 if (if_board_diff_clk())
360 return get_board_sys_clk();
361 switch ((ddrclk_conf & 0x30) >> 4) {
362 case QIXIS_DDRCLK_100:
363 return 100000000;
364 case QIXIS_DDRCLK_125:
365 return 125000000;
366 case QIXIS_DDRCLK_133:
367 return 133333333;
368 }
369
370 return 66666666;
371}
372
373int select_i2c_ch_pca9547(u8 ch)
374{
375 int ret;
376
Chuanhua Han8a898462019-07-23 18:43:11 +0800377#ifndef CONFIG_DM_I2C
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530378 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800379#else
380 struct udevice *dev;
381
382 ret = i2c_get_chip_for_busnum(0, I2C_MUX_PCA_ADDR_PRI, 1, &dev);
383 if (!ret)
384 ret = dm_i2c_write(dev, 0, &ch, 1);
385#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530386 if (ret) {
387 puts("PCA: failed to select proper channel\n");
388 return ret;
389 }
390
391 return 0;
392}
393
Rajesh Bhagat6d809b82018-01-17 16:13:10 +0530394#if !defined(CONFIG_SPL_BUILD)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530395void board_retimer_init(void)
396{
397 u8 reg;
398
399 /* Retimer is connected to I2C1_CH5 */
400 select_i2c_ch_pca9547(I2C_MUX_CH5);
401
402 /* Access to Control/Shared register */
403 reg = 0x0;
Chuanhua Han8a898462019-07-23 18:43:11 +0800404#ifndef CONFIG_DM_I2C
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530405 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800406#else
407 struct udevice *dev;
408
409 i2c_get_chip_for_busnum(0, I2C_RETIMER_ADDR, 1, &dev);
410 dm_i2c_write(dev, 0xff, &reg, 1);
411#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530412
413 /* Read device revision and ID */
Chuanhua Han8a898462019-07-23 18:43:11 +0800414#ifndef CONFIG_DM_I2C
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530415 i2c_read(I2C_RETIMER_ADDR, 1, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800416#else
417 dm_i2c_read(dev, 1, &reg, 1);
418#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530419 debug("Retimer version id = 0x%x\n", reg);
420
421 /* Enable Broadcast. All writes target all channel register sets */
422 reg = 0x0c;
Chuanhua Han8a898462019-07-23 18:43:11 +0800423#ifndef CONFIG_DM_I2C
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530424 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800425#else
426 dm_i2c_write(dev, 0xff, &reg, 1);
427#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530428
429 /* Reset Channel Registers */
Chuanhua Han8a898462019-07-23 18:43:11 +0800430#ifndef CONFIG_DM_I2C
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530431 i2c_read(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800432#else
433 dm_i2c_read(dev, 0, &reg, 1);
434#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530435 reg |= 0x4;
Chuanhua Han8a898462019-07-23 18:43:11 +0800436#ifndef CONFIG_DM_I2C
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530437 i2c_write(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800438#else
439 dm_i2c_write(dev, 0, &reg, 1);
440#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530441
442 /* Set data rate as 10.3125 Gbps */
443 reg = 0x90;
Chuanhua Han8a898462019-07-23 18:43:11 +0800444#ifndef CONFIG_DM_I2C
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530445 i2c_write(I2C_RETIMER_ADDR, 0x60, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800446#else
447 dm_i2c_write(dev, 0x60, &reg, 1);
448#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530449 reg = 0xb3;
Chuanhua Han8a898462019-07-23 18:43:11 +0800450#ifndef CONFIG_DM_I2C
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530451 i2c_write(I2C_RETIMER_ADDR, 0x61, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800452#else
453 dm_i2c_write(dev, 0x61, &reg, 1);
454#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530455 reg = 0x90;
Chuanhua Han8a898462019-07-23 18:43:11 +0800456#ifndef CONFIG_DM_I2C
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530457 i2c_write(I2C_RETIMER_ADDR, 0x62, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800458#else
459 dm_i2c_write(dev, 0x62, &reg, 1);
460#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530461 reg = 0xb3;
Chuanhua Han8a898462019-07-23 18:43:11 +0800462#ifndef CONFIG_DM_I2C
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530463 i2c_write(I2C_RETIMER_ADDR, 0x63, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800464#else
465 dm_i2c_write(dev, 0x63, &reg, 1);
466#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530467 reg = 0xcd;
Chuanhua Han8a898462019-07-23 18:43:11 +0800468#ifndef CONFIG_DM_I2C
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530469 i2c_write(I2C_RETIMER_ADDR, 0x64, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800470#else
471 dm_i2c_write(dev, 0x64, &reg, 1);
472#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530473
474 /* Select VCO Divider to full rate (000) */
Chuanhua Han8a898462019-07-23 18:43:11 +0800475#ifndef CONFIG_DM_I2C
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530476 i2c_read(I2C_RETIMER_ADDR, 0x2F, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800477#else
478 dm_i2c_read(dev, 0x2F, &reg, 1);
479#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530480 reg &= 0x0f;
481 reg |= 0x70;
Chuanhua Han8a898462019-07-23 18:43:11 +0800482#ifndef CONFIG_DM_I2C
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530483 i2c_write(I2C_RETIMER_ADDR, 0x2F, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800484#else
485 dm_i2c_write(dev, 0x2F, &reg, 1);
486#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530487
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530488#ifdef CONFIG_TARGET_LS1088AQDS
489 /* Retimer is connected to I2C1_CH5 */
490 select_i2c_ch_pca9547(I2C_MUX_CH5);
491
492 /* Access to Control/Shared register */
493 reg = 0x0;
Chuanhua Han8a898462019-07-23 18:43:11 +0800494#ifndef CONFIG_DM_I2C
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530495 i2c_write(I2C_RETIMER_ADDR2, 0xff, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800496#else
497 i2c_get_chip_for_busnum(0, I2C_RETIMER_ADDR2, 1, &dev);
498 dm_i2c_write(dev, 0xff, &reg, 1);
499#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530500
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530501 /* Read device revision and ID */
Chuanhua Han8a898462019-07-23 18:43:11 +0800502#ifndef CONFIG_DM_I2C
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530503 i2c_read(I2C_RETIMER_ADDR2, 1, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800504#else
505 dm_i2c_read(dev, 1, &reg, 1);
506#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530507 debug("Retimer version id = 0x%x\n", reg);
508
509 /* Enable Broadcast. All writes target all channel register sets */
510 reg = 0x0c;
Chuanhua Han8a898462019-07-23 18:43:11 +0800511#ifndef CONFIG_DM_I2C
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530512 i2c_write(I2C_RETIMER_ADDR2, 0xff, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800513#else
514 dm_i2c_write(dev, 0xff, &reg, 1);
515#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530516
517 /* Reset Channel Registers */
Chuanhua Han8a898462019-07-23 18:43:11 +0800518#ifndef CONFIG_DM_I2C
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530519 i2c_read(I2C_RETIMER_ADDR2, 0, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800520#else
521 dm_i2c_read(dev, 0, &reg, 1);
522#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530523 reg |= 0x4;
Chuanhua Han8a898462019-07-23 18:43:11 +0800524#ifndef CONFIG_DM_I2C
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530525 i2c_write(I2C_RETIMER_ADDR2, 0, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800526#else
527 dm_i2c_write(dev, 0, &reg, 1);
528#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530529
530 /* Set data rate as 10.3125 Gbps */
531 reg = 0x90;
Chuanhua Han8a898462019-07-23 18:43:11 +0800532#ifndef CONFIG_DM_I2C
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530533 i2c_write(I2C_RETIMER_ADDR2, 0x60, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800534#else
535 dm_i2c_write(dev, 0x60, &reg, 1);
536#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530537 reg = 0xb3;
Chuanhua Han8a898462019-07-23 18:43:11 +0800538#ifndef CONFIG_DM_I2C
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530539 i2c_write(I2C_RETIMER_ADDR2, 0x61, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800540#else
541 dm_i2c_write(dev, 0x61, &reg, 1);
542#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530543 reg = 0x90;
Chuanhua Han8a898462019-07-23 18:43:11 +0800544#ifndef CONFIG_DM_I2C
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530545 i2c_write(I2C_RETIMER_ADDR2, 0x62, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800546#else
547 dm_i2c_write(dev, 0x62, &reg, 1);
548#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530549 reg = 0xb3;
Chuanhua Han8a898462019-07-23 18:43:11 +0800550#ifndef CONFIG_DM_I2C
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530551 i2c_write(I2C_RETIMER_ADDR2, 0x63, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800552#else
553 dm_i2c_write(dev, 0x63, &reg, 1);
554#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530555 reg = 0xcd;
Chuanhua Han8a898462019-07-23 18:43:11 +0800556#ifndef CONFIG_DM_I2C
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530557 i2c_write(I2C_RETIMER_ADDR2, 0x64, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800558#else
559 dm_i2c_write(dev, 0x64, &reg, 1);
560#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530561
562 /* Select VCO Divider to full rate (000) */
Chuanhua Han8a898462019-07-23 18:43:11 +0800563#ifndef CONFIG_DM_I2C
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530564 i2c_read(I2C_RETIMER_ADDR2, 0x2F, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800565#else
566 dm_i2c_read(dev, 0x2F, &reg, 1);
567#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530568 reg &= 0x0f;
569 reg |= 0x70;
Chuanhua Han8a898462019-07-23 18:43:11 +0800570#ifndef CONFIG_DM_I2C
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530571 i2c_write(I2C_RETIMER_ADDR2, 0x2F, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800572#else
573 dm_i2c_write(dev, 0x2F, &reg, 1);
574#endif
575
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530576#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530577 /*return the default channel*/
578 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
579}
580
Yangbo Lu1d879532017-11-27 15:40:17 +0800581#ifdef CONFIG_MISC_INIT_R
582int misc_init_r(void)
583{
584#ifdef CONFIG_TARGET_LS1088ARDB
585 u8 brdcfg5;
586
587 if (hwconfig("esdhc-force-sd")) {
588 brdcfg5 = QIXIS_READ(brdcfg[5]);
589 brdcfg5 &= ~BRDCFG5_SPISDHC_MASK;
590 brdcfg5 |= BRDCFG5_FORCE_SD;
591 QIXIS_WRITE(brdcfg[5], brdcfg5);
592 }
593#endif
594 return 0;
595}
596#endif
Rajesh Bhagat6d809b82018-01-17 16:13:10 +0530597#endif
Yangbo Lu1d879532017-11-27 15:40:17 +0800598
Rajesh Bhagata4216252018-01-17 16:13:09 +0530599int i2c_multiplexer_select_vid_channel(u8 channel)
600{
601 return select_i2c_ch_pca9547(channel);
602}
603
604#ifdef CONFIG_TARGET_LS1088AQDS
605/* read the current value(SVDD) of the LTM Regulator Voltage */
606int get_serdes_volt(void)
607{
608 int ret, vcode = 0;
609 u8 chan = PWM_CHANNEL0;
610
611 /* Select the PAGE 0 using PMBus commands PAGE for VDD */
Chuanhua Han8a898462019-07-23 18:43:11 +0800612#ifndef CONFIG_DM_I2C
Rajesh Bhagata4216252018-01-17 16:13:09 +0530613 ret = i2c_write(I2C_SVDD_MONITOR_ADDR,
614 PMBUS_CMD_PAGE, 1, &chan, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800615#else
616 struct udevice *dev;
617
618 ret = i2c_get_chip_for_busnum(0, I2C_SVDD_MONITOR_ADDR, 1, &dev);
619 if (!ret)
620 ret = dm_i2c_write(dev, PMBUS_CMD_PAGE,
621 &chan, 1);
622#endif
623
Rajesh Bhagata4216252018-01-17 16:13:09 +0530624 if (ret) {
625 printf("VID: failed to select VDD Page 0\n");
626 return ret;
627 }
628
629 /* Read the output voltage using PMBus command READ_VOUT */
Chuanhua Han8a898462019-07-23 18:43:11 +0800630#ifndef CONFIG_DM_I2C
Rajesh Bhagata4216252018-01-17 16:13:09 +0530631 ret = i2c_read(I2C_SVDD_MONITOR_ADDR,
632 PMBUS_CMD_READ_VOUT, 1, (void *)&vcode, 2);
Chuanhua Han8a898462019-07-23 18:43:11 +0800633#else
634 dm_i2c_read(dev, PMBUS_CMD_READ_VOUT, (void *)&vcode, 2);
635#endif
Rajesh Bhagata4216252018-01-17 16:13:09 +0530636 if (ret) {
637 printf("VID: failed to read the volatge\n");
638 return ret;
639 }
640
641 return vcode;
642}
643
644int set_serdes_volt(int svdd)
645{
646 int ret, vdd_last;
647 u8 buff[5] = {0x04, PWM_CHANNEL0, PMBUS_CMD_VOUT_COMMAND,
648 svdd & 0xFF, (svdd & 0xFF00) >> 8};
649
650 /* Write the desired voltage code to the SVDD regulator */
Chuanhua Han8a898462019-07-23 18:43:11 +0800651#ifndef CONFIG_DM_I2C
Rajesh Bhagata4216252018-01-17 16:13:09 +0530652 ret = i2c_write(I2C_SVDD_MONITOR_ADDR,
653 PMBUS_CMD_PAGE_PLUS_WRITE, 1, (void *)&buff, 5);
Chuanhua Han8a898462019-07-23 18:43:11 +0800654#else
655 struct udevice *dev;
656
657 ret = i2c_get_chip_for_busnum(0, I2C_SVDD_MONITOR_ADDR, 1, &dev);
658 if (!ret)
659 ret = dm_i2c_write(dev, PMBUS_CMD_PAGE_PLUS_WRITE,
660 (void *)&buff, 5);
661#endif
Rajesh Bhagata4216252018-01-17 16:13:09 +0530662 if (ret) {
663 printf("VID: I2C failed to write to the volatge regulator\n");
664 return -1;
665 }
666
667 /* Wait for the volatge to get to the desired value */
668 do {
669 vdd_last = get_serdes_volt();
670 if (vdd_last < 0) {
671 printf("VID: Couldn't read sensor abort VID adjust\n");
672 return -1;
673 }
674 } while (vdd_last != svdd);
675
676 return 1;
677}
678#else
679int get_serdes_volt(void)
680{
681 return 0;
682}
683
684int set_serdes_volt(int svdd)
685{
686 int ret;
687 u8 brdcfg4;
688
689 printf("SVDD changing of RDB\n");
690
691 /* Read the BRDCFG54 via CLPD */
Chuanhua Han8a898462019-07-23 18:43:11 +0800692#ifndef CONFIG_DM_I2C
Rajesh Bhagata4216252018-01-17 16:13:09 +0530693 ret = i2c_read(CONFIG_SYS_I2C_FPGA_ADDR,
694 QIXIS_BRDCFG4_OFFSET, 1, (void *)&brdcfg4, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800695#else
696 struct udevice *dev;
697
698 ret = i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_FPGA_ADDR, 1, &dev);
699 if (!ret)
700 ret = dm_i2c_read(dev, QIXIS_BRDCFG4_OFFSET,
701 (void *)&brdcfg4, 1);
702#endif
703
Rajesh Bhagata4216252018-01-17 16:13:09 +0530704 if (ret) {
705 printf("VID: I2C failed to read the CPLD BRDCFG4\n");
706 return -1;
707 }
708
709 brdcfg4 = brdcfg4 | 0x08;
710
711 /* Write to the BRDCFG4 */
Chuanhua Han8a898462019-07-23 18:43:11 +0800712#ifndef CONFIG_DM_I2C
Rajesh Bhagata4216252018-01-17 16:13:09 +0530713 ret = i2c_write(CONFIG_SYS_I2C_FPGA_ADDR,
714 QIXIS_BRDCFG4_OFFSET, 1, (void *)&brdcfg4, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800715#else
716 ret = dm_i2c_write(dev, QIXIS_BRDCFG4_OFFSET,
717 (void *)&brdcfg4, 1);
718#endif
719
Rajesh Bhagata4216252018-01-17 16:13:09 +0530720 if (ret) {
721 debug("VID: I2C failed to set the SVDD CPLD BRDCFG4\n");
722 return -1;
723 }
724
725 /* Wait for the volatge to get to the desired value */
726 udelay(10000);
727
728 return 1;
729}
730#endif
731
732/* this function disables the SERDES, changes the SVDD Voltage and enables it*/
733int board_adjust_vdd(int vdd)
734{
735 int ret = 0;
736
737 debug("%s: vdd = %d\n", __func__, vdd);
738
739 /* Special settings to be performed when voltage is 900mV */
740 if (vdd == 900) {
741 ret = setup_serdes_volt(vdd);
742 if (ret < 0) {
743 ret = -1;
744 goto exit;
745 }
746 }
747exit:
748 return ret;
749}
750
Rajesh Bhagat6d809b82018-01-17 16:13:10 +0530751#if !defined(CONFIG_SPL_BUILD)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530752int board_init(void)
753{
754 init_final_memctl_regs();
755#if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
756 u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
757#endif
758
759 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
760 board_retimer_init();
761
762#ifdef CONFIG_ENV_IS_NOWHERE
763 gd->env_addr = (ulong)&default_environment[0];
764#endif
765
766#if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
767 /* invert AQR105 IRQ pins polarity */
768 out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR105_IRQ_MASK);
769#endif
770
Udit Agarwal09fd5792017-11-22 09:01:26 +0530771#ifdef CONFIG_FSL_CAAM
772 sec_init();
773#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530774#ifdef CONFIG_FSL_LS_PPA
775 ppa_init();
776#endif
777 return 0;
778}
779
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530780void detail_board_ddr_info(void)
781{
782 puts("\nDDR ");
783 print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
784 print_ddr_info(0);
785}
786
787#if defined(CONFIG_ARCH_MISC_INIT)
788int arch_misc_init(void)
789{
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530790 return 0;
791}
792#endif
793
794#ifdef CONFIG_FSL_MC_ENET
Mian Yousaf Kaukabe1dabf02019-01-29 16:38:30 +0100795void board_quiesce_devices(void)
796{
797 fsl_mc_ldpaa_exit(gd->bd);
798}
799
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530800void fdt_fixup_board_enet(void *fdt)
801{
802 int offset;
803
804 offset = fdt_path_offset(fdt, "/fsl-mc");
805
806 if (offset < 0)
Mian Yousaf Kaukab775c0912019-01-29 16:38:31 +0100807 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530808
809 if (offset < 0) {
810 printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
811 __func__, offset);
812 return;
813 }
814
Mian Yousaf Kaukab97124652018-12-18 14:01:17 +0100815 if (get_mc_boot_status() == 0 &&
816 (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0))
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530817 fdt_status_okay(fdt, offset);
818 else
819 fdt_status_fail(fdt, offset);
820}
821#endif
822
823#ifdef CONFIG_OF_BOARD_SETUP
Ashish Kumarff12b8a2017-11-09 11:14:24 +0530824void fsl_fdt_fixup_flash(void *fdt)
825{
826 int offset;
Pankit Gargf5c2a832018-12-27 04:37:55 +0000827#ifdef CONFIG_TFABOOT
828 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
829 u32 val;
830#endif
Ashish Kumarff12b8a2017-11-09 11:14:24 +0530831
832/*
833 * IFC-NOR and QSPI are muxed on SoC.
834 * So disable IFC node in dts if QSPI is enabled or
835 * disable QSPI node in dts in case QSPI is not enabled.
836 */
837
Pankit Gargf5c2a832018-12-27 04:37:55 +0000838#ifdef CONFIG_TFABOOT
839 enum boot_src src = get_boot_src();
840 bool disable_ifc = false;
841
842 switch (src) {
843 case BOOT_SOURCE_IFC_NOR:
844 disable_ifc = false;
845 break;
846 case BOOT_SOURCE_QSPI_NOR:
847 disable_ifc = true;
848 break;
849 default:
850 val = in_le32(dcfg_ccsr + DCFG_RCWSR15 / 4);
851 if (DCFG_RCWSR15_IFCGRPABASE_QSPI == (val & (u32)0x3))
852 disable_ifc = true;
853 break;
854 }
855
856 if (disable_ifc) {
857 offset = fdt_path_offset(fdt, "/soc/ifc/nor");
858
859 if (offset < 0)
860 offset = fdt_path_offset(fdt, "/ifc/nor");
861 } else {
862 offset = fdt_path_offset(fdt, "/soc/quadspi");
863
864 if (offset < 0)
865 offset = fdt_path_offset(fdt, "/quadspi");
866 }
867
868#else
Ashish Kumarff12b8a2017-11-09 11:14:24 +0530869#ifdef CONFIG_FSL_QSPI
870 offset = fdt_path_offset(fdt, "/soc/ifc/nor");
871
872 if (offset < 0)
873 offset = fdt_path_offset(fdt, "/ifc/nor");
874#else
875 offset = fdt_path_offset(fdt, "/soc/quadspi");
876
877 if (offset < 0)
878 offset = fdt_path_offset(fdt, "/quadspi");
879#endif
Pankit Gargf5c2a832018-12-27 04:37:55 +0000880#endif
Ashish Kumarff12b8a2017-11-09 11:14:24 +0530881 if (offset < 0)
882 return;
883
884 fdt_status_disabled(fdt, offset);
885}
886
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530887int ft_board_setup(void *blob, bd_t *bd)
888{
Mian Yousaf Kaukabe1dabf02019-01-29 16:38:30 +0100889 int i;
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530890 u16 mc_memory_bank = 0;
891
892 u64 *base;
893 u64 *size;
894 u64 mc_memory_base = 0;
895 u64 mc_memory_size = 0;
896 u16 total_memory_banks;
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530897
898 ft_cpu_setup(blob, bd);
899
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530900 fdt_fixup_mc_ddr(&mc_memory_base, &mc_memory_size);
901
902 if (mc_memory_base != 0)
903 mc_memory_bank++;
904
905 total_memory_banks = CONFIG_NR_DRAM_BANKS + mc_memory_bank;
906
907 base = calloc(total_memory_banks, sizeof(u64));
908 size = calloc(total_memory_banks, sizeof(u64));
909
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530910 /* fixup DT for the two GPP DDR banks */
911 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
912 base[i] = gd->bd->bi_dram[i].start;
913 size[i] = gd->bd->bi_dram[i].size;
914 }
915
916#ifdef CONFIG_RESV_RAM
917 /* reduce size if reserved memory is within this bank */
918 if (gd->arch.resv_ram >= base[0] &&
919 gd->arch.resv_ram < base[0] + size[0])
920 size[0] = gd->arch.resv_ram - base[0];
921 else if (gd->arch.resv_ram >= base[1] &&
922 gd->arch.resv_ram < base[1] + size[1])
923 size[1] = gd->arch.resv_ram - base[1];
924#endif
925
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530926 if (mc_memory_base != 0) {
927 for (i = 0; i <= total_memory_banks; i++) {
928 if (base[i] == 0 && size[i] == 0) {
929 base[i] = mc_memory_base;
930 size[i] = mc_memory_size;
931 break;
932 }
933 }
934 }
935
936 fdt_fixup_memory_banks(blob, base, size, total_memory_banks);
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530937
Nipun Guptad6912642018-08-20 16:01:14 +0530938 fdt_fsl_mc_fixup_iommu_map_entry(blob);
939
Ashish Kumarff12b8a2017-11-09 11:14:24 +0530940 fsl_fdt_fixup_flash(blob);
941
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530942#ifdef CONFIG_FSL_MC_ENET
943 fdt_fixup_board_enet(blob);
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530944#endif
Pramod Kumara0531822018-10-12 14:04:27 +0000945 if (is_pb_board())
946 fixup_ls1088ardb_pb_banner(blob);
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530947
948 return 0;
949}
950#endif
Sumit Garg08da8b22018-01-06 09:04:24 +0530951#endif /* defined(CONFIG_SPL_BUILD) */
Pankit Gargf5c2a832018-12-27 04:37:55 +0000952
953#ifdef CONFIG_TFABOOT
954#ifdef CONFIG_MTD_NOR_FLASH
955int is_flash_available(void)
956{
957 char *env_hwconfig = env_get("hwconfig");
958 enum boot_src src = get_boot_src();
959 int is_nor_flash_available = 1;
960
961 switch (src) {
962 case BOOT_SOURCE_IFC_NOR:
963 is_nor_flash_available = 1;
964 break;
965 case BOOT_SOURCE_QSPI_NOR:
966 is_nor_flash_available = 0;
967 break;
968 /*
969 * In Case of SD boot,if qspi is defined in env_hwconfig
970 * disable nor flash probe.
971 */
972 default:
973 if (hwconfig_f("qspi", env_hwconfig))
974 is_nor_flash_available = 0;
975 break;
976 }
977 return is_nor_flash_available;
978}
979#endif
980
981void *env_sf_get_env_addr(void)
982{
983 return (void *)(CONFIG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);
984}
985#endif