blob: 32b4780376a63d1dd21dfcf4c1c5e01e89fc8319 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Shengzhou Liu9eca55f2014-11-24 17:11:55 +08002/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
Biwen Li6b63c542020-05-01 20:04:11 +08004 * Copyright 2020 NXP
Shengzhou Liu9eca55f2014-11-24 17:11:55 +08005 */
6
7#include <common.h>
8#include <command.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06009#include <env.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -070010#include <fdt_support.h>
Shengzhou Liu9eca55f2014-11-24 17:11:55 +080011#include <i2c.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Shengzhou Liu9eca55f2014-11-24 17:11:55 +080013#include <netdev.h>
14#include <linux/compiler.h>
15#include <asm/mmu.h>
16#include <asm/processor.h>
17#include <asm/cache.h>
18#include <asm/immap_85xx.h>
19#include <asm/fsl_law.h>
20#include <asm/fsl_serdes.h>
Shengzhou Liu9eca55f2014-11-24 17:11:55 +080021#include <asm/fsl_liodn.h>
22#include <fm_eth.h>
23#include <hwconfig.h>
Shengzhou Liu9eca55f2014-11-24 17:11:55 +080024#include "../common/qixis.h"
25#include "t102xqds.h"
26#include "t102xqds_qixis.h"
tang yuantianbcf04652014-12-18 09:55:07 +080027#include "../common/sleep.h"
Shengzhou Liu9eca55f2014-11-24 17:11:55 +080028
29DECLARE_GLOBAL_DATA_PTR;
30
31int checkboard(void)
32{
33 char buf[64];
34 struct cpu_type *cpu = gd->arch.cpu;
35 static const char *const freq[] = {"100", "125", "156.25", "100.0"};
36 int clock;
37 u8 sw = QIXIS_READ(arch);
38
39 printf("Board: %sQDS, ", cpu->name);
40 printf("Sys ID: 0x%02x, Board Arch: V%d, ", QIXIS_READ(id), sw >> 4);
41 printf("Board Version: %c, boot from ", (sw & 0xf) + 'A' - 1);
42
43#ifdef CONFIG_SDCARD
44 puts("SD/MMC\n");
45#elif CONFIG_SPIFLASH
46 puts("SPI\n");
47#else
48 sw = QIXIS_READ(brdcfg[0]);
49 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
50
51 if (sw < 0x8)
52 printf("vBank: %d\n", sw);
53 else if (sw == 0x8)
54 puts("PromJet\n");
55 else if (sw == 0x9)
56 puts("NAND\n");
57 else if (sw == 0x15)
58 printf("IFC Card\n");
59 else
60 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
61#endif
62
63 printf("FPGA: v%d (%s), build %d",
64 (int)QIXIS_READ(scver), qixis_read_tag(buf),
65 (int)qixis_read_minor());
66 /* the timestamp string contains "\n" at the end */
67 printf(" on %s", qixis_read_time(buf));
68
69 puts("SERDES Reference: ");
70 sw = QIXIS_READ(brdcfg[2]);
71 clock = (sw >> 6) & 3;
72 printf("Clock1=%sMHz ", freq[clock]);
73 clock = (sw >> 4) & 3;
74 printf("Clock2=%sMHz\n", freq[clock]);
75
76 return 0;
77}
78
Biwen Li6b63c542020-05-01 20:04:11 +080079int select_i2c_ch_pca9547(u8 ch, int bus_num)
Shengzhou Liu9eca55f2014-11-24 17:11:55 +080080{
81 int ret;
Biwen Li6b63c542020-05-01 20:04:11 +080082#ifdef CONFIG_DM_I2C
83 struct udevice *dev;
Shengzhou Liu9eca55f2014-11-24 17:11:55 +080084
Biwen Li6b63c542020-05-01 20:04:11 +080085 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI,
86 1, &dev);
87 if (ret) {
88 printf("%s: Cannot find udev for a bus %d\n", __func__,
89 bus_num);
90 return ret;
91 }
92
93 ret = dm_i2c_write(dev, 0, &ch, 1);
94#else
Shengzhou Liu9eca55f2014-11-24 17:11:55 +080095 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
Biwen Li6b63c542020-05-01 20:04:11 +080096#endif
Shengzhou Liu9eca55f2014-11-24 17:11:55 +080097 if (ret) {
98 puts("PCA: failed to select proper channel\n");
99 return ret;
100 }
101
102 return 0;
103}
104
105static int board_mux_lane_to_slot(void)
106{
107 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
108 u32 srds_prtcl_s1;
109 u8 brdcfg9;
110
111 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
112 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
113 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
114
115
116 brdcfg9 = QIXIS_READ(brdcfg[9]);
117 QIXIS_WRITE(brdcfg[9], brdcfg9 | BRDCFG9_XFI_TX_DISABLE);
118
119 switch (srds_prtcl_s1) {
120 case 0:
121 /* SerDes1 is not enabled */
122 break;
123 case 0xd5:
124 case 0x5b:
125 case 0x6b:
126 case 0x77:
127 case 0x6f:
128 case 0x7f:
129 QIXIS_WRITE(brdcfg[12], 0x8c);
130 break;
131 case 0x40:
132 QIXIS_WRITE(brdcfg[12], 0xfc);
133 break;
134 case 0xd6:
135 case 0x5a:
136 case 0x6a:
137 case 0x56:
138 QIXIS_WRITE(brdcfg[12], 0x88);
139 break;
140 case 0x47:
141 QIXIS_WRITE(brdcfg[12], 0xcc);
142 break;
143 case 0x46:
144 QIXIS_WRITE(brdcfg[12], 0xc8);
145 break;
146 case 0x95:
147 case 0x99:
148 brdcfg9 &= ~BRDCFG9_XFI_TX_DISABLE;
149 QIXIS_WRITE(brdcfg[9], brdcfg9);
150 QIXIS_WRITE(brdcfg[12], 0x8c);
151 break;
152 case 0x116:
153 QIXIS_WRITE(brdcfg[12], 0x00);
154 break;
155 case 0x115:
156 case 0x119:
157 case 0x129:
158 case 0x12b:
159 /* Aurora, PCIe, SGMII, SATA */
160 QIXIS_WRITE(brdcfg[12], 0x04);
161 break;
162 default:
163 printf("WARNING: unsupported for SerDes Protocol %d\n",
164 srds_prtcl_s1);
165 return -1;
166 }
167
168 return 0;
169}
170
York Sun7d29dd62016-11-18 13:01:34 -0800171#ifdef CONFIG_ARCH_T1024
Shengzhou Liu9eca55f2014-11-24 17:11:55 +0800172static void board_mux_setup(void)
173{
174 u8 brdcfg15;
175
176 brdcfg15 = QIXIS_READ(brdcfg[15]);
177 brdcfg15 &= ~BRDCFG15_DIUSEL_MASK;
178
179 if (hwconfig_arg_cmp("pin_mux", "tdm")) {
180 /* Route QE_TDM multiplexed signals to TDM Riser slot */
181 QIXIS_WRITE(brdcfg[15], brdcfg15 | BRDCFG15_DIUSEL_TDM);
182 QIXIS_WRITE(brdcfg[13], BRDCFG13_TDM_INTERFACE << 2);
Shengzhou Liu57430ee2014-11-24 17:11:58 +0800183 QIXIS_WRITE(brdcfg[5], (QIXIS_READ(brdcfg[5]) &
184 ~BRDCFG5_SPIRTE_MASK) | BRDCFG5_SPIRTE_TDM);
Shengzhou Liu9eca55f2014-11-24 17:11:55 +0800185 } else if (hwconfig_arg_cmp("pin_mux", "ucc")) {
186 /* to UCC (ProfiBus) interface */
187 QIXIS_WRITE(brdcfg[15], brdcfg15 | BRDCFG15_DIUSEL_UCC);
188 } else if (hwconfig_arg_cmp("pin_mux", "hdmi")) {
189 /* to DVI (HDMI) encoder */
190 QIXIS_WRITE(brdcfg[15], brdcfg15 | BRDCFG15_DIUSEL_HDMI);
191 } else if (hwconfig_arg_cmp("pin_mux", "lcd")) {
192 /* to DFP (LCD) encoder */
193 QIXIS_WRITE(brdcfg[15], brdcfg15 | BRDCFG15_LCDFM |
194 BRDCFG15_LCDPD | BRDCFG15_DIUSEL_LCD);
195 }
Shengzhou Liu57430ee2014-11-24 17:11:58 +0800196
197 if (hwconfig_arg_cmp("adaptor", "sdxc"))
198 /* Route SPI_CS multiplexed signals to SD slot */
199 QIXIS_WRITE(brdcfg[5], (QIXIS_READ(brdcfg[5]) &
200 ~BRDCFG5_SPIRTE_MASK) | BRDCFG5_SPIRTE_SDHC);
Shengzhou Liu9eca55f2014-11-24 17:11:55 +0800201}
202#endif
203
Shengzhou Liuf847bcc2014-11-24 17:18:28 +0800204void board_retimer_ds125df111_init(void)
205{
206 u8 reg;
207
Biwen Li6b63c542020-05-01 20:04:11 +0800208#ifdef CONFIG_DM_I2C
209 struct udevice *dev;
210 int ret, bus_num = 0;
211
212 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI,
213 1, &dev);
214 if (ret)
215 goto failed;
216
Shengzhou Liuf847bcc2014-11-24 17:18:28 +0800217 /* Retimer DS125DF111 is connected to I2C1_CH7_CH5 */
218 reg = I2C_MUX_CH7;
Biwen Li6b63c542020-05-01 20:04:11 +0800219 dm_i2c_write(dev, 0, &reg, 1);
220
221 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_SEC,
222 1, &dev);
223 if (ret)
224 goto failed;
225
226 reg = I2C_MUX_CH5;
227 dm_i2c_write(dev, 0, &reg, 1);
228
229 /* Access to Control/Shared register */
230 ret = i2c_get_chip_for_busnum(bus_num, I2C_RETIMER_ADDR,
231 1, &dev);
232 if (ret)
233 goto failed;
234 reg = 0x0;
235 dm_i2c_write(dev, 0xff, &reg, 1);
236
237 /* Read device revision and ID */
238 dm_i2c_read(dev, 1, &reg, 1);
239 debug("Retimer version id = 0x%x\n", reg);
240
241 /* Enable Broadcast */
242 reg = 0x0c;
243 dm_i2c_write(dev, 0xff, &reg, 1);
244
245 /* Reset Channel Registers */
246 dm_i2c_read(dev, 0, &reg, 1);
247 reg |= 0x4;
248 dm_i2c_write(dev, 0, &reg, 1);
249
250 /* Enable override divider select and Enable Override Output Mux */
251 dm_i2c_read(dev, 9, &reg, 1);
252 reg |= 0x24;
253 dm_i2c_write(dev, 9, &reg, 1);
254
255 /* Select VCO Divider to full rate (000) */
256 dm_i2c_read(dev, 0x18, &reg, 1);
257 reg &= 0x8f;
258 dm_i2c_write(dev, 0x18, &reg, 1);
259
260 /* Select active PFD MUX input as re-timed data (001) */
261 dm_i2c_read(dev, 0x1e, &reg, 1);
262 reg &= 0x3f;
263 reg |= 0x20;
264 dm_i2c_write(dev, 0x1e, &reg, 1);
265
266 /* Set data rate as 10.3125 Gbps */
267 reg = 0x0;
268 dm_i2c_write(dev, 0x60, &reg, 1);
269 reg = 0xb2;
270 dm_i2c_write(dev, 0x61, &reg, 1);
271 reg = 0x90;
272 dm_i2c_write(dev, 0x62, &reg, 1);
273 reg = 0xb3;
274 dm_i2c_write(dev, 0x63, &reg, 1);
275 reg = 0xcd;
276 dm_i2c_write(dev, 0x64, &reg, 1);
277 return;
278
279failed:
280 printf("%s: Cannot find udev for a bus %d\n", __func__,
281 bus_num);
282 return;
283#else
284 /* Retimer DS125DF111 is connected to I2C1_CH7_CH5 */
285 reg = I2C_MUX_CH7;
Shengzhou Liuf847bcc2014-11-24 17:18:28 +0800286 i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &reg, 1);
287 reg = I2C_MUX_CH5;
288 i2c_write(I2C_MUX_PCA_ADDR_SEC, 0, 1, &reg, 1);
289
290 /* Access to Control/Shared register */
291 reg = 0x0;
292 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
293
294 /* Read device revision and ID */
295 i2c_read(I2C_RETIMER_ADDR, 1, 1, &reg, 1);
296 debug("Retimer version id = 0x%x\n", reg);
297
298 /* Enable Broadcast */
299 reg = 0x0c;
300 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
301
302 /* Reset Channel Registers */
303 i2c_read(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
304 reg |= 0x4;
305 i2c_write(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
306
307 /* Enable override divider select and Enable Override Output Mux */
308 i2c_read(I2C_RETIMER_ADDR, 9, 1, &reg, 1);
309 reg |= 0x24;
310 i2c_write(I2C_RETIMER_ADDR, 9, 1, &reg, 1);
311
312 /* Select VCO Divider to full rate (000) */
313 i2c_read(I2C_RETIMER_ADDR, 0x18, 1, &reg, 1);
314 reg &= 0x8f;
315 i2c_write(I2C_RETIMER_ADDR, 0x18, 1, &reg, 1);
316
317 /* Select active PFD MUX input as re-timed data (001) */
318 i2c_read(I2C_RETIMER_ADDR, 0x1e, 1, &reg, 1);
319 reg &= 0x3f;
320 reg |= 0x20;
321 i2c_write(I2C_RETIMER_ADDR, 0x1e, 1, &reg, 1);
322
323 /* Set data rate as 10.3125 Gbps */
324 reg = 0x0;
325 i2c_write(I2C_RETIMER_ADDR, 0x60, 1, &reg, 1);
326 reg = 0xb2;
327 i2c_write(I2C_RETIMER_ADDR, 0x61, 1, &reg, 1);
328 reg = 0x90;
329 i2c_write(I2C_RETIMER_ADDR, 0x62, 1, &reg, 1);
330 reg = 0xb3;
331 i2c_write(I2C_RETIMER_ADDR, 0x63, 1, &reg, 1);
332 reg = 0xcd;
333 i2c_write(I2C_RETIMER_ADDR, 0x64, 1, &reg, 1);
Biwen Li6b63c542020-05-01 20:04:11 +0800334#endif
Shengzhou Liuf847bcc2014-11-24 17:18:28 +0800335}
336
tang yuantianbcf04652014-12-18 09:55:07 +0800337int board_early_init_f(void)
338{
339#if defined(CONFIG_DEEP_SLEEP)
340 if (is_warm_boot())
341 fsl_dp_disable_console();
342#endif
343
344 return 0;
345}
346
Shengzhou Liu9eca55f2014-11-24 17:11:55 +0800347int board_early_init_r(void)
348{
349#ifdef CONFIG_SYS_FLASH_BASE
350 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
351 int flash_esel = find_tlb_idx((void *)flashbase, 1);
352
353 /*
354 * Remap Boot flash + PROMJET region to caching-inhibited
355 * so that flash can be erased properly.
356 */
357
358 /* Flush d-cache and invalidate i-cache of any FLASH data */
359 flush_dcache();
360 invalidate_icache();
361
362 if (flash_esel == -1) {
363 /* very unlikely unless something is messed up */
364 puts("Error: Could not find TLB for FLASH BASE\n");
365 flash_esel = 2; /* give our best effort to continue */
366 } else {
367 /* invalidate existing TLB entry for flash + promjet */
368 disable_tlb(flash_esel);
369 }
370
371 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
372 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
373 0, flash_esel, BOOKE_PAGESZ_256M, 1);
374#endif
Biwen Li6b63c542020-05-01 20:04:11 +0800375 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Shengzhou Liu9eca55f2014-11-24 17:11:55 +0800376 board_mux_lane_to_slot();
Shengzhou Liuf847bcc2014-11-24 17:18:28 +0800377 board_retimer_ds125df111_init();
Shengzhou Liube51cbd2014-11-24 17:12:00 +0800378
379 /* Increase IO drive strength to address FCS error on RGMII */
380 out_be32((unsigned *)CONFIG_SYS_FSL_SCFG_IODSECR1_ADDR, 0xbfdb7800);
381
Shengzhou Liu9eca55f2014-11-24 17:11:55 +0800382 return 0;
383}
384
385unsigned long get_board_sys_clk(void)
386{
387 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
388
389 switch (sysclk_conf & 0x0F) {
390 case QIXIS_SYSCLK_64:
391 return 64000000;
392 case QIXIS_SYSCLK_83:
393 return 83333333;
394 case QIXIS_SYSCLK_100:
395 return 100000000;
396 case QIXIS_SYSCLK_125:
397 return 125000000;
398 case QIXIS_SYSCLK_133:
399 return 133333333;
400 case QIXIS_SYSCLK_150:
401 return 150000000;
402 case QIXIS_SYSCLK_160:
403 return 160000000;
404 case QIXIS_SYSCLK_166:
405 return 166666666;
406 }
407 return 66666666;
408}
409
410unsigned long get_board_ddr_clk(void)
411{
412 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
413
414 switch ((ddrclk_conf & 0x30) >> 4) {
415 case QIXIS_DDRCLK_100:
416 return 100000000;
417 case QIXIS_DDRCLK_125:
418 return 125000000;
419 case QIXIS_DDRCLK_133:
420 return 133333333;
421 }
422 return 66666666;
423}
424
425#define NUM_SRDS_PLL 2
426int misc_init_r(void)
427{
York Sun7d29dd62016-11-18 13:01:34 -0800428#ifdef CONFIG_ARCH_T1024
Shengzhou Liu9eca55f2014-11-24 17:11:55 +0800429 board_mux_setup();
430#endif
431 return 0;
432}
433
Shengzhou Liu57430ee2014-11-24 17:11:58 +0800434void fdt_fixup_spi_mux(void *blob)
435{
436 int nodeoff = 0;
437
438 if (hwconfig_arg_cmp("pin_mux", "tdm")) {
439 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
440 "eon,en25s64")) >= 0) {
441 fdt_del_node(blob, nodeoff);
442 }
443 } else {
444 /* remove tdm node */
445 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
446 "maxim,ds26522")) >= 0) {
447 fdt_del_node(blob, nodeoff);
448 }
449 }
450}
451
Shengzhou Liu9eca55f2014-11-24 17:11:55 +0800452int ft_board_setup(void *blob, bd_t *bd)
453{
454 phys_addr_t base;
455 phys_size_t size;
456
457 ft_cpu_setup(blob, bd);
458
Simon Glassda1a1342017-08-03 12:22:15 -0600459 base = env_get_bootm_low();
460 size = env_get_bootm_size();
Shengzhou Liu9eca55f2014-11-24 17:11:55 +0800461
462 fdt_fixup_memory(blob, (u64)base, (u64)size);
463
464#ifdef CONFIG_PCI
465 pci_of_setup(blob, bd);
466#endif
467
468 fdt_fixup_liodn(blob);
469
470#ifdef CONFIG_HAS_FSL_DR_USB
Sriram Dash9fd465c2016-09-16 17:12:15 +0530471 fsl_fdt_fixup_dr_usb(blob, bd);
Shengzhou Liu9eca55f2014-11-24 17:11:55 +0800472#endif
473
474#ifdef CONFIG_SYS_DPAA_FMAN
475 fdt_fixup_fman_ethernet(blob);
476 fdt_fixup_board_enet(blob);
477#endif
Shengzhou Liu57430ee2014-11-24 17:11:58 +0800478 fdt_fixup_spi_mux(blob);
Shengzhou Liu9eca55f2014-11-24 17:11:55 +0800479
480 return 0;
481}
482
483void qixis_dump_switch(void)
484{
485 int i, nr_of_cfgsw;
486
487 QIXIS_WRITE(cms[0], 0x00);
488 nr_of_cfgsw = QIXIS_READ(cms[1]);
489
490 puts("DIP switch settings dump:\n");
491 for (i = 1; i <= nr_of_cfgsw; i++) {
492 QIXIS_WRITE(cms[0], i);
493 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));
494 }
495}