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