blob: bb775eb2d3256eb86586924347f9b44d5e4275c7 [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 Glass2dc9c342020-05-10 11:40:01 -060012#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Shengzhou Liu49912402014-11-24 17:11:56 +080014#include <netdev.h>
15#include <linux/compiler.h>
16#include <asm/mmu.h>
17#include <asm/processor.h>
18#include <asm/immap_85xx.h>
19#include <asm/fsl_law.h>
20#include <asm/fsl_serdes.h>
Shengzhou Liu49912402014-11-24 17:11:56 +080021#include <asm/fsl_liodn.h>
Shengzhou Liu49912402014-11-24 17:11:56 +080022#include <fm_eth.h>
23#include "t102xrdb.h"
York Sunf9a03632016-12-28 08:43:34 -080024#ifdef CONFIG_TARGET_T1024RDB
Shengzhou Liu49912402014-11-24 17:11:56 +080025#include "cpld.h"
York Sun940ee4a2016-12-28 08:43:33 -080026#elif defined(CONFIG_TARGET_T1023RDB)
Shengzhou Liu0a197892015-06-17 16:37:01 +080027#include <i2c.h>
28#include <mmc.h>
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080029#endif
tang yuantian8dc02f32014-12-17 15:42:54 +080030#include "../common/sleep.h"
Shengzhou Liu49912402014-11-24 17:11:56 +080031
32DECLARE_GLOBAL_DATA_PTR;
33
York Sun940ee4a2016-12-28 08:43:33 -080034#ifdef CONFIG_TARGET_T1023RDB
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080035enum {
Shengzhou Liu0a197892015-06-17 16:37:01 +080036 GPIO1_SD_SEL = 0x00020000, /* GPIO1_14, 0: eMMC, 1:SD/MMC */
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080037 GPIO1_EMMC_SEL,
Shengzhou Liu0a197892015-06-17 16:37:01 +080038 GPIO3_GET_VERSION, /* GPIO3_4/5, 00:RevB, 01: RevC */
39 GPIO3_BRD_VER_MASK = 0x0c000000,
40 GPIO3_OFFSET = 0x2000,
41 I2C_GET_BANK,
42 I2C_SET_BANK0,
43 I2C_SET_BANK4,
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080044};
45#endif
46
Shengzhou Liu49912402014-11-24 17:11:56 +080047int checkboard(void)
48{
49 struct cpu_type *cpu = gd->arch.cpu;
50 static const char *freq[3] = {"100.00MHZ", "125.00MHz", "156.25MHZ"};
Shengzhou Liuccc57ef2014-12-17 16:51:08 +080051 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
52 u32 srds_s1;
53
54 srds_s1 = in_be32(&gur->rcwsr[4]) & FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
55 srds_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
Shengzhou Liu49912402014-11-24 17:11:56 +080056
57 printf("Board: %sRDB, ", cpu->name);
York Sunf9a03632016-12-28 08:43:34 -080058#if defined(CONFIG_TARGET_T1024RDB)
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080059 printf("Board rev: 0x%02x CPLD ver: 0x%02x, ",
Shengzhou Liu49912402014-11-24 17:11:56 +080060 CPLD_READ(hw_ver), CPLD_READ(sw_ver));
York Sun940ee4a2016-12-28 08:43:33 -080061#elif defined(CONFIG_TARGET_T1023RDB)
Shengzhou Liu0a197892015-06-17 16:37:01 +080062 printf("Rev%c, ", t1023rdb_ctrl(GPIO3_GET_VERSION) + 'B');
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080063#endif
64 printf("boot from ");
Shengzhou Liu49912402014-11-24 17:11:56 +080065
66#ifdef CONFIG_SDCARD
67 puts("SD/MMC\n");
68#elif CONFIG_SPIFLASH
69 puts("SPI\n");
York Sunf9a03632016-12-28 08:43:34 -080070#elif defined(CONFIG_TARGET_T1024RDB)
Shengzhou Liu49912402014-11-24 17:11:56 +080071 u8 reg;
72
73 reg = CPLD_READ(flash_csr);
74
75 if (reg & CPLD_BOOT_SEL) {
76 puts("NAND\n");
77 } else {
78 reg = ((reg & CPLD_LBMAP_MASK) >> CPLD_LBMAP_SHIFT);
79 printf("NOR vBank%d\n", reg);
80 }
York Sun940ee4a2016-12-28 08:43:33 -080081#elif defined(CONFIG_TARGET_T1023RDB)
Miquel Raynald0935362019-10-03 19:50:03 +020082#ifdef CONFIG_MTD_RAW_NAND
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080083 puts("NAND\n");
84#else
Shengzhou Liu0a197892015-06-17 16:37:01 +080085 printf("NOR vBank%d\n", t1023rdb_ctrl(I2C_GET_BANK));
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080086#endif
Shengzhou Liu49912402014-11-24 17:11:56 +080087#endif
88
89 puts("SERDES Reference Clocks:\n");
Shengzhou Liuccc57ef2014-12-17 16:51:08 +080090 if (srds_s1 == 0x95)
91 printf("SD1_CLK1=%s, SD1_CLK2=%s\n", freq[2], freq[0]);
92 else
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080093 printf("SD1_CLK1=%s, SD1_CLK2=%s\n", freq[0], freq[1]);
Shengzhou Liu49912402014-11-24 17:11:56 +080094
95 return 0;
96}
97
York Sunf9a03632016-12-28 08:43:34 -080098#ifdef CONFIG_TARGET_T1024RDB
Shengzhou Liuccc57ef2014-12-17 16:51:08 +080099static void board_mux_lane(void)
100{
101 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
102 u32 srds_prtcl_s1;
103 u8 reg = CPLD_READ(misc_ctl_status);
104
105 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
106 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
107 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
108
109 if (srds_prtcl_s1 == 0x95) {
110 /* Route Lane B to PCIE */
111 CPLD_WRITE(misc_ctl_status, reg & ~CPLD_PCIE_SGMII_MUX);
112 } else {
113 /* Route Lane B to SGMII */
114 CPLD_WRITE(misc_ctl_status, reg | CPLD_PCIE_SGMII_MUX);
115 }
116 CPLD_WRITE(boot_override, CPLD_OVERRIDE_MUX_EN);
117}
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800118#endif
Shengzhou Liuccc57ef2014-12-17 16:51:08 +0800119
tang yuantian8dc02f32014-12-17 15:42:54 +0800120int board_early_init_f(void)
121{
122#if defined(CONFIG_DEEP_SLEEP)
123 if (is_warm_boot())
124 fsl_dp_disable_console();
125#endif
126
127 return 0;
128}
129
Shengzhou Liu49912402014-11-24 17:11:56 +0800130int board_early_init_r(void)
131{
132#ifdef CONFIG_SYS_FLASH_BASE
133 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
134 int flash_esel = find_tlb_idx((void *)flashbase, 1);
135 /*
136 * Remap Boot flash region to caching-inhibited
137 * so that flash can be erased properly.
138 */
139
140 /* Flush d-cache and invalidate i-cache of any FLASH data */
141 flush_dcache();
142 invalidate_icache();
143 if (flash_esel == -1) {
144 /* very unlikely unless something is messed up */
145 puts("Error: Could not find TLB for FLASH BASE\n");
146 flash_esel = 2; /* give our best effort to continue */
147 } else {
148 /* invalidate existing TLB entry for flash + promjet */
149 disable_tlb(flash_esel);
150 }
151
152 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
153 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
154 0, flash_esel, BOOKE_PAGESZ_256M, 1);
155#endif
156
York Sunf9a03632016-12-28 08:43:34 -0800157#ifdef CONFIG_TARGET_T1024RDB
Shengzhou Liuccc57ef2014-12-17 16:51:08 +0800158 board_mux_lane();
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800159#endif
Shengzhou Liu49912402014-11-24 17:11:56 +0800160
161 return 0;
162}
163
164unsigned long get_board_sys_clk(void)
165{
166 return CONFIG_SYS_CLK_FREQ;
167}
168
169unsigned long get_board_ddr_clk(void)
170{
171 return CONFIG_DDR_CLK_FREQ;
172}
173
Shengzhou Liu52c48532017-04-10 16:00:08 +0800174#ifdef CONFIG_TARGET_T1024RDB
175void board_reset(void)
176{
177 CPLD_WRITE(reset_ctl1, CPLD_LBMAP_RESET);
178}
179#endif
180
Shengzhou Liu49912402014-11-24 17:11:56 +0800181int misc_init_r(void)
182{
183 return 0;
184}
185
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900186int ft_board_setup(void *blob, struct bd_info *bd)
Shengzhou Liu49912402014-11-24 17:11:56 +0800187{
188 phys_addr_t base;
189 phys_size_t size;
190
191 ft_cpu_setup(blob, bd);
192
Simon Glassda1a1342017-08-03 12:22:15 -0600193 base = env_get_bootm_low();
194 size = env_get_bootm_size();
Shengzhou Liu49912402014-11-24 17:11:56 +0800195
196 fdt_fixup_memory(blob, (u64)base, (u64)size);
197
198#ifdef CONFIG_PCI
199 pci_of_setup(blob, bd);
200#endif
201
202 fdt_fixup_liodn(blob);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530203 fsl_fdt_fixup_dr_usb(blob, bd);
Shengzhou Liu49912402014-11-24 17:11:56 +0800204
205#ifdef CONFIG_SYS_DPAA_FMAN
Madalin Bucur70848512020-04-30 15:59:58 +0300206#ifndef CONFIG_DM_ETH
Shengzhou Liu49912402014-11-24 17:11:56 +0800207 fdt_fixup_fman_ethernet(blob);
Madalin Bucur70848512020-04-30 15:59:58 +0300208#endif
Shengzhou Liu49912402014-11-24 17:11:56 +0800209 fdt_fixup_board_enet(blob);
210#endif
211
York Sun940ee4a2016-12-28 08:43:33 -0800212#ifdef CONFIG_TARGET_T1023RDB
Shengzhou Liu0a197892015-06-17 16:37:01 +0800213 if (t1023rdb_ctrl(GPIO3_GET_VERSION) > 0)
214 fdt_enable_nor(blob);
215#endif
216
Shengzhou Liu49912402014-11-24 17:11:56 +0800217 return 0;
218}
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800219
York Sun940ee4a2016-12-28 08:43:33 -0800220#ifdef CONFIG_TARGET_T1023RDB
Shengzhou Liu0a197892015-06-17 16:37:01 +0800221/* Enable NOR flash for RevC */
222static void fdt_enable_nor(void *blob)
223{
224 int nodeoff = fdt_node_offset_by_compatible(blob, 0, "cfi-flash");
225
226 if (nodeoff >= 0)
227 fdt_status_okay(blob, nodeoff);
228 else
229 printf("WARNING unable to set status for NOR\n");
230}
231
232int board_mmc_getcd(struct mmc *mmc)
233{
234 ccsr_gpio_t __iomem *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
235 u32 val = in_be32(&pgpio->gpdat);
236
237 /* GPIO1_14, 0: eMMC, 1: SD/MMC */
238 val &= GPIO1_SD_SEL;
239
240 return val ? -1 : 1;
241}
242
243int board_mmc_getwp(struct mmc *mmc)
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800244{
Shengzhou Liu0a197892015-06-17 16:37:01 +0800245 ccsr_gpio_t __iomem *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
246 u32 val = in_be32(&pgpio->gpdat);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800247
Shengzhou Liu0a197892015-06-17 16:37:01 +0800248 val &= GPIO1_SD_SEL;
249
250 return val ? -1 : 0;
251}
252
253static u32 t1023rdb_ctrl(u32 ctrl_type)
254{
255 ccsr_gpio_t __iomem *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
256 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Biwen Li6b63c542020-05-01 20:04:11 +0800257 u32 val;
Shengzhou Liu0a197892015-06-17 16:37:01 +0800258 u8 tmp;
Biwen Li6b63c542020-05-01 20:04:11 +0800259 int bus_num = I2C_PCA6408_BUS_NUM;
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800260
Biwen Li6b63c542020-05-01 20:04:11 +0800261#ifdef CONFIG_DM_I2C
262 struct udevice *dev;
263 int ret;
264
265 ret = i2c_get_chip_for_busnum(bus_num, I2C_PCA6408_ADDR,
266 1, &dev);
267 if (ret) {
268 printf("%s: Cannot find udev for a bus %d\n", __func__,
269 bus_num);
270 return ret;
271 }
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800272 switch (ctrl_type) {
273 case GPIO1_SD_SEL:
Shengzhou Liu0a197892015-06-17 16:37:01 +0800274 val = in_be32(&pgpio->gpdat);
275 val |= GPIO1_SD_SEL;
276 out_be32(&pgpio->gpdat, val);
277 setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800278 break;
279 case GPIO1_EMMC_SEL:
Shengzhou Liu0a197892015-06-17 16:37:01 +0800280 val = in_be32(&pgpio->gpdat);
281 val &= ~GPIO1_SD_SEL;
282 out_be32(&pgpio->gpdat, val);
283 setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800284 break;
Shengzhou Liu0a197892015-06-17 16:37:01 +0800285 case GPIO3_GET_VERSION:
286 pgpio = (ccsr_gpio_t *)(CONFIG_SYS_MPC85xx_GPIO_ADDR
287 + GPIO3_OFFSET);
288 val = in_be32(&pgpio->gpdat);
289 val = ((val & GPIO3_BRD_VER_MASK) >> 26) & 0x3;
290 if (val == 0x3) /* GPIO3_4/5 not used on RevB */
291 val = 0;
292 return val;
293 case I2C_GET_BANK:
Biwen Li6b63c542020-05-01 20:04:11 +0800294 dm_i2c_read(dev, 0, &tmp, 1);
295 tmp &= 0x7;
296 tmp = ((tmp & 1) << 2) | (tmp & 2) | ((tmp & 4) >> 2);
297 return tmp;
298 case I2C_SET_BANK0:
299 tmp = 0x0;
300 dm_i2c_write(dev, 1, &tmp, 1);
301 tmp = 0xf8;
302 dm_i2c_write(dev, 3, &tmp, 1);
303 /* asserting HRESET_REQ */
304 out_be32(&gur->rstcr, 0x2);
305 break;
306 case I2C_SET_BANK4:
307 tmp = 0x1;
308 dm_i2c_write(dev, 1, &tmp, 1);
309 tmp = 0xf8;
310 dm_i2c_write(dev, 3, &tmp, 1);
311 out_be32(&gur->rstcr, 0x2);
312 break;
313 default:
314 break;
315 }
316#else
317 u32 orig_bus;
318
319 orig_bus = i2c_get_bus_num();
320
321 switch (ctrl_type) {
322 case GPIO1_SD_SEL:
323 val = in_be32(&pgpio->gpdat);
324 val |= GPIO1_SD_SEL;
325 out_be32(&pgpio->gpdat, val);
326 setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL);
327 break;
328 case GPIO1_EMMC_SEL:
329 val = in_be32(&pgpio->gpdat);
330 val &= ~GPIO1_SD_SEL;
331 out_be32(&pgpio->gpdat, val);
332 setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL);
333 break;
334 case GPIO3_GET_VERSION:
335 pgpio = (ccsr_gpio_t *)(CONFIG_SYS_MPC85xx_GPIO_ADDR
336 + GPIO3_OFFSET);
337 val = in_be32(&pgpio->gpdat);
338 val = ((val & GPIO3_BRD_VER_MASK) >> 26) & 0x3;
339 if (val == 0x3) /* GPIO3_4/5 not used on RevB */
340 val = 0;
341 return val;
342 case I2C_GET_BANK:
343 i2c_set_bus_num(bus_num);
Shengzhou Liu0a197892015-06-17 16:37:01 +0800344 i2c_read(I2C_PCA6408_ADDR, 0, 1, &tmp, 1);
345 tmp &= 0x7;
346 tmp = ((tmp & 1) << 2) | (tmp & 2) | ((tmp & 4) >> 2);
347 i2c_set_bus_num(orig_bus);
348 return tmp;
349 case I2C_SET_BANK0:
Biwen Li6b63c542020-05-01 20:04:11 +0800350 i2c_set_bus_num(bus_num);
Shengzhou Liu0a197892015-06-17 16:37:01 +0800351 tmp = 0x0;
352 i2c_write(I2C_PCA6408_ADDR, 1, 1, &tmp, 1);
353 tmp = 0xf8;
354 i2c_write(I2C_PCA6408_ADDR, 3, 1, &tmp, 1);
355 /* asserting HRESET_REQ */
356 out_be32(&gur->rstcr, 0x2);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800357 break;
Shengzhou Liu0a197892015-06-17 16:37:01 +0800358 case I2C_SET_BANK4:
Biwen Li6b63c542020-05-01 20:04:11 +0800359 i2c_set_bus_num(bus_num);
Shengzhou Liu0a197892015-06-17 16:37:01 +0800360 tmp = 0x1;
361 i2c_write(I2C_PCA6408_ADDR, 1, 1, &tmp, 1);
362 tmp = 0xf8;
363 i2c_write(I2C_PCA6408_ADDR, 3, 1, &tmp, 1);
364 out_be32(&gur->rstcr, 0x2);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800365 break;
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800366 default:
367 break;
368 }
Biwen Li6b63c542020-05-01 20:04:11 +0800369#endif
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800370 return 0;
371}
372
Simon Glassed38aef2020-05-10 11:40:03 -0600373static int switch_cmd(struct cmd_tbl *cmdtp, int flag, int argc,
374 char *const argv[])
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800375{
376 if (argc < 2)
377 return CMD_RET_USAGE;
Shengzhou Liu0a197892015-06-17 16:37:01 +0800378 if (!strcmp(argv[1], "bank0"))
379 t1023rdb_ctrl(I2C_SET_BANK0);
380 else if (!strcmp(argv[1], "bank4") || !strcmp(argv[1], "altbank"))
381 t1023rdb_ctrl(I2C_SET_BANK4);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800382 else if (!strcmp(argv[1], "sd"))
Shengzhou Liu0a197892015-06-17 16:37:01 +0800383 t1023rdb_ctrl(GPIO1_SD_SEL);
384 else if (!strcmp(argv[1], "emmc"))
385 t1023rdb_ctrl(GPIO1_EMMC_SEL);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800386 else
387 return CMD_RET_USAGE;
388 return 0;
389}
390
391U_BOOT_CMD(
Shengzhou Liu0a197892015-06-17 16:37:01 +0800392 switch, 2, 0, switch_cmd,
393 "for bank0/bank4/sd/emmc switch control in runtime",
394 "command (e.g. switch bank4)"
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800395);
396#endif