blob: a34490c8bdcf46c3046ccec0c9c27ec6695ff33a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Shengzhou Liu49912402014-11-24 17:11:56 +08002/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
Biwen Li6b63c542020-05-01 20:04:11 +08004 * Copyright 2020 NXP
Shengzhou Liu49912402014-11-24 17:11:56 +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 Liu49912402014-11-24 17:11:56 +080011#include <i2c.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Shengzhou Liu49912402014-11-24 17:11:56 +080013#include <netdev.h>
14#include <linux/compiler.h>
15#include <asm/mmu.h>
16#include <asm/processor.h>
17#include <asm/immap_85xx.h>
18#include <asm/fsl_law.h>
19#include <asm/fsl_serdes.h>
Shengzhou Liu49912402014-11-24 17:11:56 +080020#include <asm/fsl_liodn.h>
Shengzhou Liu49912402014-11-24 17:11:56 +080021#include <fm_eth.h>
22#include "t102xrdb.h"
York Sunf9a03632016-12-28 08:43:34 -080023#ifdef CONFIG_TARGET_T1024RDB
Shengzhou Liu49912402014-11-24 17:11:56 +080024#include "cpld.h"
York Sun940ee4a2016-12-28 08:43:33 -080025#elif defined(CONFIG_TARGET_T1023RDB)
Shengzhou Liu0a197892015-06-17 16:37:01 +080026#include <i2c.h>
27#include <mmc.h>
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080028#endif
tang yuantian8dc02f32014-12-17 15:42:54 +080029#include "../common/sleep.h"
Shengzhou Liu49912402014-11-24 17:11:56 +080030
31DECLARE_GLOBAL_DATA_PTR;
32
York Sun940ee4a2016-12-28 08:43:33 -080033#ifdef CONFIG_TARGET_T1023RDB
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080034enum {
Shengzhou Liu0a197892015-06-17 16:37:01 +080035 GPIO1_SD_SEL = 0x00020000, /* GPIO1_14, 0: eMMC, 1:SD/MMC */
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080036 GPIO1_EMMC_SEL,
Shengzhou Liu0a197892015-06-17 16:37:01 +080037 GPIO3_GET_VERSION, /* GPIO3_4/5, 00:RevB, 01: RevC */
38 GPIO3_BRD_VER_MASK = 0x0c000000,
39 GPIO3_OFFSET = 0x2000,
40 I2C_GET_BANK,
41 I2C_SET_BANK0,
42 I2C_SET_BANK4,
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080043};
44#endif
45
Shengzhou Liu49912402014-11-24 17:11:56 +080046int checkboard(void)
47{
48 struct cpu_type *cpu = gd->arch.cpu;
49 static const char *freq[3] = {"100.00MHZ", "125.00MHz", "156.25MHZ"};
Shengzhou Liuccc57ef2014-12-17 16:51:08 +080050 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
51 u32 srds_s1;
52
53 srds_s1 = in_be32(&gur->rcwsr[4]) & FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
54 srds_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
Shengzhou Liu49912402014-11-24 17:11:56 +080055
56 printf("Board: %sRDB, ", cpu->name);
York Sunf9a03632016-12-28 08:43:34 -080057#if defined(CONFIG_TARGET_T1024RDB)
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080058 printf("Board rev: 0x%02x CPLD ver: 0x%02x, ",
Shengzhou Liu49912402014-11-24 17:11:56 +080059 CPLD_READ(hw_ver), CPLD_READ(sw_ver));
York Sun940ee4a2016-12-28 08:43:33 -080060#elif defined(CONFIG_TARGET_T1023RDB)
Shengzhou Liu0a197892015-06-17 16:37:01 +080061 printf("Rev%c, ", t1023rdb_ctrl(GPIO3_GET_VERSION) + 'B');
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080062#endif
63 printf("boot from ");
Shengzhou Liu49912402014-11-24 17:11:56 +080064
65#ifdef CONFIG_SDCARD
66 puts("SD/MMC\n");
67#elif CONFIG_SPIFLASH
68 puts("SPI\n");
York Sunf9a03632016-12-28 08:43:34 -080069#elif defined(CONFIG_TARGET_T1024RDB)
Shengzhou Liu49912402014-11-24 17:11:56 +080070 u8 reg;
71
72 reg = CPLD_READ(flash_csr);
73
74 if (reg & CPLD_BOOT_SEL) {
75 puts("NAND\n");
76 } else {
77 reg = ((reg & CPLD_LBMAP_MASK) >> CPLD_LBMAP_SHIFT);
78 printf("NOR vBank%d\n", reg);
79 }
York Sun940ee4a2016-12-28 08:43:33 -080080#elif defined(CONFIG_TARGET_T1023RDB)
Miquel Raynald0935362019-10-03 19:50:03 +020081#ifdef CONFIG_MTD_RAW_NAND
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080082 puts("NAND\n");
83#else
Shengzhou Liu0a197892015-06-17 16:37:01 +080084 printf("NOR vBank%d\n", t1023rdb_ctrl(I2C_GET_BANK));
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080085#endif
Shengzhou Liu49912402014-11-24 17:11:56 +080086#endif
87
88 puts("SERDES Reference Clocks:\n");
Shengzhou Liuccc57ef2014-12-17 16:51:08 +080089 if (srds_s1 == 0x95)
90 printf("SD1_CLK1=%s, SD1_CLK2=%s\n", freq[2], freq[0]);
91 else
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080092 printf("SD1_CLK1=%s, SD1_CLK2=%s\n", freq[0], freq[1]);
Shengzhou Liu49912402014-11-24 17:11:56 +080093
94 return 0;
95}
96
York Sunf9a03632016-12-28 08:43:34 -080097#ifdef CONFIG_TARGET_T1024RDB
Shengzhou Liuccc57ef2014-12-17 16:51:08 +080098static void board_mux_lane(void)
99{
100 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
101 u32 srds_prtcl_s1;
102 u8 reg = CPLD_READ(misc_ctl_status);
103
104 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
105 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
106 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
107
108 if (srds_prtcl_s1 == 0x95) {
109 /* Route Lane B to PCIE */
110 CPLD_WRITE(misc_ctl_status, reg & ~CPLD_PCIE_SGMII_MUX);
111 } else {
112 /* Route Lane B to SGMII */
113 CPLD_WRITE(misc_ctl_status, reg | CPLD_PCIE_SGMII_MUX);
114 }
115 CPLD_WRITE(boot_override, CPLD_OVERRIDE_MUX_EN);
116}
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800117#endif
Shengzhou Liuccc57ef2014-12-17 16:51:08 +0800118
tang yuantian8dc02f32014-12-17 15:42:54 +0800119int board_early_init_f(void)
120{
121#if defined(CONFIG_DEEP_SLEEP)
122 if (is_warm_boot())
123 fsl_dp_disable_console();
124#endif
125
126 return 0;
127}
128
Shengzhou Liu49912402014-11-24 17:11:56 +0800129int board_early_init_r(void)
130{
131#ifdef CONFIG_SYS_FLASH_BASE
132 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
133 int flash_esel = find_tlb_idx((void *)flashbase, 1);
134 /*
135 * Remap Boot flash region to caching-inhibited
136 * so that flash can be erased properly.
137 */
138
139 /* Flush d-cache and invalidate i-cache of any FLASH data */
140 flush_dcache();
141 invalidate_icache();
142 if (flash_esel == -1) {
143 /* very unlikely unless something is messed up */
144 puts("Error: Could not find TLB for FLASH BASE\n");
145 flash_esel = 2; /* give our best effort to continue */
146 } else {
147 /* invalidate existing TLB entry for flash + promjet */
148 disable_tlb(flash_esel);
149 }
150
151 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
152 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
153 0, flash_esel, BOOKE_PAGESZ_256M, 1);
154#endif
155
York Sunf9a03632016-12-28 08:43:34 -0800156#ifdef CONFIG_TARGET_T1024RDB
Shengzhou Liuccc57ef2014-12-17 16:51:08 +0800157 board_mux_lane();
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800158#endif
Shengzhou Liu49912402014-11-24 17:11:56 +0800159
160 return 0;
161}
162
163unsigned long get_board_sys_clk(void)
164{
165 return CONFIG_SYS_CLK_FREQ;
166}
167
168unsigned long get_board_ddr_clk(void)
169{
170 return CONFIG_DDR_CLK_FREQ;
171}
172
Shengzhou Liu52c48532017-04-10 16:00:08 +0800173#ifdef CONFIG_TARGET_T1024RDB
174void board_reset(void)
175{
176 CPLD_WRITE(reset_ctl1, CPLD_LBMAP_RESET);
177}
178#endif
179
Shengzhou Liu49912402014-11-24 17:11:56 +0800180int misc_init_r(void)
181{
182 return 0;
183}
184
185int ft_board_setup(void *blob, bd_t *bd)
186{
187 phys_addr_t base;
188 phys_size_t size;
189
190 ft_cpu_setup(blob, bd);
191
Simon Glassda1a1342017-08-03 12:22:15 -0600192 base = env_get_bootm_low();
193 size = env_get_bootm_size();
Shengzhou Liu49912402014-11-24 17:11:56 +0800194
195 fdt_fixup_memory(blob, (u64)base, (u64)size);
196
197#ifdef CONFIG_PCI
198 pci_of_setup(blob, bd);
199#endif
200
201 fdt_fixup_liodn(blob);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530202 fsl_fdt_fixup_dr_usb(blob, bd);
Shengzhou Liu49912402014-11-24 17:11:56 +0800203
204#ifdef CONFIG_SYS_DPAA_FMAN
205 fdt_fixup_fman_ethernet(blob);
206 fdt_fixup_board_enet(blob);
207#endif
208
York Sun940ee4a2016-12-28 08:43:33 -0800209#ifdef CONFIG_TARGET_T1023RDB
Shengzhou Liu0a197892015-06-17 16:37:01 +0800210 if (t1023rdb_ctrl(GPIO3_GET_VERSION) > 0)
211 fdt_enable_nor(blob);
212#endif
213
Shengzhou Liu49912402014-11-24 17:11:56 +0800214 return 0;
215}
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800216
York Sun940ee4a2016-12-28 08:43:33 -0800217#ifdef CONFIG_TARGET_T1023RDB
Shengzhou Liu0a197892015-06-17 16:37:01 +0800218/* Enable NOR flash for RevC */
219static void fdt_enable_nor(void *blob)
220{
221 int nodeoff = fdt_node_offset_by_compatible(blob, 0, "cfi-flash");
222
223 if (nodeoff >= 0)
224 fdt_status_okay(blob, nodeoff);
225 else
226 printf("WARNING unable to set status for NOR\n");
227}
228
229int board_mmc_getcd(struct mmc *mmc)
230{
231 ccsr_gpio_t __iomem *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
232 u32 val = in_be32(&pgpio->gpdat);
233
234 /* GPIO1_14, 0: eMMC, 1: SD/MMC */
235 val &= GPIO1_SD_SEL;
236
237 return val ? -1 : 1;
238}
239
240int board_mmc_getwp(struct mmc *mmc)
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800241{
Shengzhou Liu0a197892015-06-17 16:37:01 +0800242 ccsr_gpio_t __iomem *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
243 u32 val = in_be32(&pgpio->gpdat);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800244
Shengzhou Liu0a197892015-06-17 16:37:01 +0800245 val &= GPIO1_SD_SEL;
246
247 return val ? -1 : 0;
248}
249
250static u32 t1023rdb_ctrl(u32 ctrl_type)
251{
252 ccsr_gpio_t __iomem *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
253 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Biwen Li6b63c542020-05-01 20:04:11 +0800254 u32 val;
Shengzhou Liu0a197892015-06-17 16:37:01 +0800255 u8 tmp;
Biwen Li6b63c542020-05-01 20:04:11 +0800256 int bus_num = I2C_PCA6408_BUS_NUM;
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800257
Biwen Li6b63c542020-05-01 20:04:11 +0800258#ifdef CONFIG_DM_I2C
259 struct udevice *dev;
260 int ret;
261
262 ret = i2c_get_chip_for_busnum(bus_num, I2C_PCA6408_ADDR,
263 1, &dev);
264 if (ret) {
265 printf("%s: Cannot find udev for a bus %d\n", __func__,
266 bus_num);
267 return ret;
268 }
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800269 switch (ctrl_type) {
270 case GPIO1_SD_SEL:
Shengzhou Liu0a197892015-06-17 16:37:01 +0800271 val = in_be32(&pgpio->gpdat);
272 val |= GPIO1_SD_SEL;
273 out_be32(&pgpio->gpdat, val);
274 setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800275 break;
276 case GPIO1_EMMC_SEL:
Shengzhou Liu0a197892015-06-17 16:37:01 +0800277 val = in_be32(&pgpio->gpdat);
278 val &= ~GPIO1_SD_SEL;
279 out_be32(&pgpio->gpdat, val);
280 setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800281 break;
Shengzhou Liu0a197892015-06-17 16:37:01 +0800282 case GPIO3_GET_VERSION:
283 pgpio = (ccsr_gpio_t *)(CONFIG_SYS_MPC85xx_GPIO_ADDR
284 + GPIO3_OFFSET);
285 val = in_be32(&pgpio->gpdat);
286 val = ((val & GPIO3_BRD_VER_MASK) >> 26) & 0x3;
287 if (val == 0x3) /* GPIO3_4/5 not used on RevB */
288 val = 0;
289 return val;
290 case I2C_GET_BANK:
Biwen Li6b63c542020-05-01 20:04:11 +0800291 dm_i2c_read(dev, 0, &tmp, 1);
292 tmp &= 0x7;
293 tmp = ((tmp & 1) << 2) | (tmp & 2) | ((tmp & 4) >> 2);
294 return tmp;
295 case I2C_SET_BANK0:
296 tmp = 0x0;
297 dm_i2c_write(dev, 1, &tmp, 1);
298 tmp = 0xf8;
299 dm_i2c_write(dev, 3, &tmp, 1);
300 /* asserting HRESET_REQ */
301 out_be32(&gur->rstcr, 0x2);
302 break;
303 case I2C_SET_BANK4:
304 tmp = 0x1;
305 dm_i2c_write(dev, 1, &tmp, 1);
306 tmp = 0xf8;
307 dm_i2c_write(dev, 3, &tmp, 1);
308 out_be32(&gur->rstcr, 0x2);
309 break;
310 default:
311 break;
312 }
313#else
314 u32 orig_bus;
315
316 orig_bus = i2c_get_bus_num();
317
318 switch (ctrl_type) {
319 case GPIO1_SD_SEL:
320 val = in_be32(&pgpio->gpdat);
321 val |= GPIO1_SD_SEL;
322 out_be32(&pgpio->gpdat, val);
323 setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL);
324 break;
325 case GPIO1_EMMC_SEL:
326 val = in_be32(&pgpio->gpdat);
327 val &= ~GPIO1_SD_SEL;
328 out_be32(&pgpio->gpdat, val);
329 setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL);
330 break;
331 case GPIO3_GET_VERSION:
332 pgpio = (ccsr_gpio_t *)(CONFIG_SYS_MPC85xx_GPIO_ADDR
333 + GPIO3_OFFSET);
334 val = in_be32(&pgpio->gpdat);
335 val = ((val & GPIO3_BRD_VER_MASK) >> 26) & 0x3;
336 if (val == 0x3) /* GPIO3_4/5 not used on RevB */
337 val = 0;
338 return val;
339 case I2C_GET_BANK:
340 i2c_set_bus_num(bus_num);
Shengzhou Liu0a197892015-06-17 16:37:01 +0800341 i2c_read(I2C_PCA6408_ADDR, 0, 1, &tmp, 1);
342 tmp &= 0x7;
343 tmp = ((tmp & 1) << 2) | (tmp & 2) | ((tmp & 4) >> 2);
344 i2c_set_bus_num(orig_bus);
345 return tmp;
346 case I2C_SET_BANK0:
Biwen Li6b63c542020-05-01 20:04:11 +0800347 i2c_set_bus_num(bus_num);
Shengzhou Liu0a197892015-06-17 16:37:01 +0800348 tmp = 0x0;
349 i2c_write(I2C_PCA6408_ADDR, 1, 1, &tmp, 1);
350 tmp = 0xf8;
351 i2c_write(I2C_PCA6408_ADDR, 3, 1, &tmp, 1);
352 /* asserting HRESET_REQ */
353 out_be32(&gur->rstcr, 0x2);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800354 break;
Shengzhou Liu0a197892015-06-17 16:37:01 +0800355 case I2C_SET_BANK4:
Biwen Li6b63c542020-05-01 20:04:11 +0800356 i2c_set_bus_num(bus_num);
Shengzhou Liu0a197892015-06-17 16:37:01 +0800357 tmp = 0x1;
358 i2c_write(I2C_PCA6408_ADDR, 1, 1, &tmp, 1);
359 tmp = 0xf8;
360 i2c_write(I2C_PCA6408_ADDR, 3, 1, &tmp, 1);
361 out_be32(&gur->rstcr, 0x2);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800362 break;
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800363 default:
364 break;
365 }
Biwen Li6b63c542020-05-01 20:04:11 +0800366#endif
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800367 return 0;
368}
369
Shengzhou Liu0a197892015-06-17 16:37:01 +0800370static int switch_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800371 char * const argv[])
372{
373 if (argc < 2)
374 return CMD_RET_USAGE;
Shengzhou Liu0a197892015-06-17 16:37:01 +0800375 if (!strcmp(argv[1], "bank0"))
376 t1023rdb_ctrl(I2C_SET_BANK0);
377 else if (!strcmp(argv[1], "bank4") || !strcmp(argv[1], "altbank"))
378 t1023rdb_ctrl(I2C_SET_BANK4);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800379 else if (!strcmp(argv[1], "sd"))
Shengzhou Liu0a197892015-06-17 16:37:01 +0800380 t1023rdb_ctrl(GPIO1_SD_SEL);
381 else if (!strcmp(argv[1], "emmc"))
382 t1023rdb_ctrl(GPIO1_EMMC_SEL);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800383 else
384 return CMD_RET_USAGE;
385 return 0;
386}
387
388U_BOOT_CMD(
Shengzhou Liu0a197892015-06-17 16:37:01 +0800389 switch, 2, 0, switch_cmd,
390 "for bank0/bank4/sd/emmc switch control in runtime",
391 "command (e.g. switch bank4)"
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800392);
393#endif