blob: f777f5a2fe7f12398c8f6220d61831a21f4157db [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Shengzhou Liu49912402014-11-24 17:11:56 +080016#include <linux/compiler.h>
17#include <asm/mmu.h>
18#include <asm/processor.h>
19#include <asm/immap_85xx.h>
20#include <asm/fsl_law.h>
21#include <asm/fsl_serdes.h>
Shengzhou Liu49912402014-11-24 17:11:56 +080022#include <asm/fsl_liodn.h>
Shengzhou Liu49912402014-11-24 17:11:56 +080023#include <fm_eth.h>
24#include "t102xrdb.h"
York Sunf9a03632016-12-28 08:43:34 -080025#ifdef CONFIG_TARGET_T1024RDB
Shengzhou Liu49912402014-11-24 17:11:56 +080026#include "cpld.h"
York Sun940ee4a2016-12-28 08:43:33 -080027#elif defined(CONFIG_TARGET_T1023RDB)
Shengzhou Liu0a197892015-06-17 16:37:01 +080028#include <i2c.h>
29#include <mmc.h>
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080030#endif
tang yuantian8dc02f32014-12-17 15:42:54 +080031#include "../common/sleep.h"
Shengzhou Liu49912402014-11-24 17:11:56 +080032
33DECLARE_GLOBAL_DATA_PTR;
34
York Sun940ee4a2016-12-28 08:43:33 -080035#ifdef CONFIG_TARGET_T1023RDB
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080036enum {
Shengzhou Liu0a197892015-06-17 16:37:01 +080037 GPIO1_SD_SEL = 0x00020000, /* GPIO1_14, 0: eMMC, 1:SD/MMC */
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080038 GPIO1_EMMC_SEL,
Shengzhou Liu0a197892015-06-17 16:37:01 +080039 GPIO3_GET_VERSION, /* GPIO3_4/5, 00:RevB, 01: RevC */
40 GPIO3_BRD_VER_MASK = 0x0c000000,
41 GPIO3_OFFSET = 0x2000,
42 I2C_GET_BANK,
43 I2C_SET_BANK0,
44 I2C_SET_BANK4,
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080045};
46#endif
47
Shengzhou Liu49912402014-11-24 17:11:56 +080048int checkboard(void)
49{
50 struct cpu_type *cpu = gd->arch.cpu;
51 static const char *freq[3] = {"100.00MHZ", "125.00MHz", "156.25MHZ"};
Tom Rinid5c3bf22022-10-28 20:27:12 -040052 ccsr_gur_t __iomem *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Shengzhou Liuccc57ef2014-12-17 16:51:08 +080053 u32 srds_s1;
54
55 srds_s1 = in_be32(&gur->rcwsr[4]) & FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
56 srds_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
Shengzhou Liu49912402014-11-24 17:11:56 +080057
58 printf("Board: %sRDB, ", cpu->name);
York Sunf9a03632016-12-28 08:43:34 -080059#if defined(CONFIG_TARGET_T1024RDB)
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080060 printf("Board rev: 0x%02x CPLD ver: 0x%02x, ",
Shengzhou Liu49912402014-11-24 17:11:56 +080061 CPLD_READ(hw_ver), CPLD_READ(sw_ver));
York Sun940ee4a2016-12-28 08:43:33 -080062#elif defined(CONFIG_TARGET_T1023RDB)
Shengzhou Liu0a197892015-06-17 16:37:01 +080063 printf("Rev%c, ", t1023rdb_ctrl(GPIO3_GET_VERSION) + 'B');
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080064#endif
65 printf("boot from ");
Shengzhou Liu49912402014-11-24 17:11:56 +080066
67#ifdef CONFIG_SDCARD
68 puts("SD/MMC\n");
69#elif CONFIG_SPIFLASH
70 puts("SPI\n");
York Sunf9a03632016-12-28 08:43:34 -080071#elif defined(CONFIG_TARGET_T1024RDB)
Shengzhou Liu49912402014-11-24 17:11:56 +080072 u8 reg;
73
74 reg = CPLD_READ(flash_csr);
75
76 if (reg & CPLD_BOOT_SEL) {
77 puts("NAND\n");
78 } else {
79 reg = ((reg & CPLD_LBMAP_MASK) >> CPLD_LBMAP_SHIFT);
80 printf("NOR vBank%d\n", reg);
81 }
York Sun940ee4a2016-12-28 08:43:33 -080082#elif defined(CONFIG_TARGET_T1023RDB)
Miquel Raynald0935362019-10-03 19:50:03 +020083#ifdef CONFIG_MTD_RAW_NAND
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080084 puts("NAND\n");
85#else
Shengzhou Liu0a197892015-06-17 16:37:01 +080086 printf("NOR vBank%d\n", t1023rdb_ctrl(I2C_GET_BANK));
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080087#endif
Shengzhou Liu49912402014-11-24 17:11:56 +080088#endif
89
90 puts("SERDES Reference Clocks:\n");
Shengzhou Liuccc57ef2014-12-17 16:51:08 +080091 if (srds_s1 == 0x95)
92 printf("SD1_CLK1=%s, SD1_CLK2=%s\n", freq[2], freq[0]);
93 else
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +080094 printf("SD1_CLK1=%s, SD1_CLK2=%s\n", freq[0], freq[1]);
Shengzhou Liu49912402014-11-24 17:11:56 +080095
96 return 0;
97}
98
York Sunf9a03632016-12-28 08:43:34 -080099#ifdef CONFIG_TARGET_T1024RDB
Shengzhou Liuccc57ef2014-12-17 16:51:08 +0800100static void board_mux_lane(void)
101{
Tom Rinid5c3bf22022-10-28 20:27:12 -0400102 ccsr_gur_t __iomem *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Shengzhou Liuccc57ef2014-12-17 16:51:08 +0800103 u32 srds_prtcl_s1;
104 u8 reg = CPLD_READ(misc_ctl_status);
105
106 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
107 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
108 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
109
110 if (srds_prtcl_s1 == 0x95) {
111 /* Route Lane B to PCIE */
112 CPLD_WRITE(misc_ctl_status, reg & ~CPLD_PCIE_SGMII_MUX);
113 } else {
114 /* Route Lane B to SGMII */
115 CPLD_WRITE(misc_ctl_status, reg | CPLD_PCIE_SGMII_MUX);
116 }
117 CPLD_WRITE(boot_override, CPLD_OVERRIDE_MUX_EN);
118}
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800119#endif
Shengzhou Liuccc57ef2014-12-17 16:51:08 +0800120
tang yuantian8dc02f32014-12-17 15:42:54 +0800121int board_early_init_f(void)
122{
123#if defined(CONFIG_DEEP_SLEEP)
124 if (is_warm_boot())
125 fsl_dp_disable_console();
126#endif
127
128 return 0;
129}
130
Shengzhou Liu49912402014-11-24 17:11:56 +0800131int board_early_init_r(void)
132{
133#ifdef CONFIG_SYS_FLASH_BASE
134 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
135 int flash_esel = find_tlb_idx((void *)flashbase, 1);
136 /*
137 * Remap Boot flash region to caching-inhibited
138 * so that flash can be erased properly.
139 */
140
141 /* Flush d-cache and invalidate i-cache of any FLASH data */
142 flush_dcache();
143 invalidate_icache();
144 if (flash_esel == -1) {
145 /* very unlikely unless something is messed up */
146 puts("Error: Could not find TLB for FLASH BASE\n");
147 flash_esel = 2; /* give our best effort to continue */
148 } else {
149 /* invalidate existing TLB entry for flash + promjet */
150 disable_tlb(flash_esel);
151 }
152
153 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
154 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
155 0, flash_esel, BOOKE_PAGESZ_256M, 1);
156#endif
157
York Sunf9a03632016-12-28 08:43:34 -0800158#ifdef CONFIG_TARGET_T1024RDB
Shengzhou Liuccc57ef2014-12-17 16:51:08 +0800159 board_mux_lane();
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800160#endif
Shengzhou Liu49912402014-11-24 17:11:56 +0800161
162 return 0;
163}
164
Shengzhou Liu52c48532017-04-10 16:00:08 +0800165#ifdef CONFIG_TARGET_T1024RDB
166void board_reset(void)
167{
168 CPLD_WRITE(reset_ctl1, CPLD_LBMAP_RESET);
169}
170#endif
171
Shengzhou Liu49912402014-11-24 17:11:56 +0800172int misc_init_r(void)
173{
174 return 0;
175}
176
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900177int ft_board_setup(void *blob, struct bd_info *bd)
Shengzhou Liu49912402014-11-24 17:11:56 +0800178{
179 phys_addr_t base;
180 phys_size_t size;
181
182 ft_cpu_setup(blob, bd);
183
Simon Glassda1a1342017-08-03 12:22:15 -0600184 base = env_get_bootm_low();
185 size = env_get_bootm_size();
Shengzhou Liu49912402014-11-24 17:11:56 +0800186
187 fdt_fixup_memory(blob, (u64)base, (u64)size);
188
189#ifdef CONFIG_PCI
190 pci_of_setup(blob, bd);
191#endif
192
193 fdt_fixup_liodn(blob);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530194 fsl_fdt_fixup_dr_usb(blob, bd);
Shengzhou Liu49912402014-11-24 17:11:56 +0800195
196#ifdef CONFIG_SYS_DPAA_FMAN
Madalin Bucur70848512020-04-30 15:59:58 +0300197#ifndef CONFIG_DM_ETH
Shengzhou Liu49912402014-11-24 17:11:56 +0800198 fdt_fixup_fman_ethernet(blob);
Madalin Bucur70848512020-04-30 15:59:58 +0300199#endif
Shengzhou Liu49912402014-11-24 17:11:56 +0800200 fdt_fixup_board_enet(blob);
201#endif
202
York Sun940ee4a2016-12-28 08:43:33 -0800203#ifdef CONFIG_TARGET_T1023RDB
Shengzhou Liu0a197892015-06-17 16:37:01 +0800204 if (t1023rdb_ctrl(GPIO3_GET_VERSION) > 0)
205 fdt_enable_nor(blob);
206#endif
207
Shengzhou Liu49912402014-11-24 17:11:56 +0800208 return 0;
209}
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800210
York Sun940ee4a2016-12-28 08:43:33 -0800211#ifdef CONFIG_TARGET_T1023RDB
Shengzhou Liu0a197892015-06-17 16:37:01 +0800212/* Enable NOR flash for RevC */
213static void fdt_enable_nor(void *blob)
214{
215 int nodeoff = fdt_node_offset_by_compatible(blob, 0, "cfi-flash");
216
217 if (nodeoff >= 0)
218 fdt_status_okay(blob, nodeoff);
219 else
220 printf("WARNING unable to set status for NOR\n");
221}
222
223int board_mmc_getcd(struct mmc *mmc)
224{
Tom Rinid5c3bf22022-10-28 20:27:12 -0400225 ccsr_gpio_t __iomem *pgpio = (void *)(CFG_SYS_MPC85xx_GPIO_ADDR);
Shengzhou Liu0a197892015-06-17 16:37:01 +0800226 u32 val = in_be32(&pgpio->gpdat);
227
228 /* GPIO1_14, 0: eMMC, 1: SD/MMC */
229 val &= GPIO1_SD_SEL;
230
231 return val ? -1 : 1;
232}
233
234int board_mmc_getwp(struct mmc *mmc)
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800235{
Tom Rinid5c3bf22022-10-28 20:27:12 -0400236 ccsr_gpio_t __iomem *pgpio = (void *)(CFG_SYS_MPC85xx_GPIO_ADDR);
Shengzhou Liu0a197892015-06-17 16:37:01 +0800237 u32 val = in_be32(&pgpio->gpdat);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800238
Shengzhou Liu0a197892015-06-17 16:37:01 +0800239 val &= GPIO1_SD_SEL;
240
241 return val ? -1 : 0;
242}
243
244static u32 t1023rdb_ctrl(u32 ctrl_type)
245{
Tom Rinid5c3bf22022-10-28 20:27:12 -0400246 ccsr_gpio_t __iomem *pgpio = (void *)(CFG_SYS_MPC85xx_GPIO_ADDR);
247 ccsr_gur_t __iomem *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Biwen Li6b63c542020-05-01 20:04:11 +0800248 u32 val;
Shengzhou Liu0a197892015-06-17 16:37:01 +0800249 u8 tmp;
Biwen Li6b63c542020-05-01 20:04:11 +0800250 int bus_num = I2C_PCA6408_BUS_NUM;
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800251
Igor Opaniukf7c91762021-02-09 13:52:45 +0200252#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Li6b63c542020-05-01 20:04:11 +0800253 struct udevice *dev;
254 int ret;
255
256 ret = i2c_get_chip_for_busnum(bus_num, I2C_PCA6408_ADDR,
257 1, &dev);
258 if (ret) {
259 printf("%s: Cannot find udev for a bus %d\n", __func__,
260 bus_num);
261 return ret;
262 }
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800263 switch (ctrl_type) {
264 case GPIO1_SD_SEL:
Shengzhou Liu0a197892015-06-17 16:37:01 +0800265 val = in_be32(&pgpio->gpdat);
266 val |= GPIO1_SD_SEL;
267 out_be32(&pgpio->gpdat, val);
268 setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800269 break;
270 case GPIO1_EMMC_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;
Shengzhou Liu0a197892015-06-17 16:37:01 +0800276 case GPIO3_GET_VERSION:
Tom Rinid5c3bf22022-10-28 20:27:12 -0400277 pgpio = (ccsr_gpio_t *)(CFG_SYS_MPC85xx_GPIO_ADDR
Shengzhou Liu0a197892015-06-17 16:37:01 +0800278 + GPIO3_OFFSET);
279 val = in_be32(&pgpio->gpdat);
280 val = ((val & GPIO3_BRD_VER_MASK) >> 26) & 0x3;
281 if (val == 0x3) /* GPIO3_4/5 not used on RevB */
282 val = 0;
283 return val;
284 case I2C_GET_BANK:
Biwen Li6b63c542020-05-01 20:04:11 +0800285 dm_i2c_read(dev, 0, &tmp, 1);
286 tmp &= 0x7;
287 tmp = ((tmp & 1) << 2) | (tmp & 2) | ((tmp & 4) >> 2);
288 return tmp;
289 case I2C_SET_BANK0:
290 tmp = 0x0;
291 dm_i2c_write(dev, 1, &tmp, 1);
292 tmp = 0xf8;
293 dm_i2c_write(dev, 3, &tmp, 1);
294 /* asserting HRESET_REQ */
295 out_be32(&gur->rstcr, 0x2);
296 break;
297 case I2C_SET_BANK4:
298 tmp = 0x1;
299 dm_i2c_write(dev, 1, &tmp, 1);
300 tmp = 0xf8;
301 dm_i2c_write(dev, 3, &tmp, 1);
302 out_be32(&gur->rstcr, 0x2);
303 break;
304 default:
305 break;
306 }
307#else
308 u32 orig_bus;
309
310 orig_bus = i2c_get_bus_num();
311
312 switch (ctrl_type) {
313 case GPIO1_SD_SEL:
314 val = in_be32(&pgpio->gpdat);
315 val |= GPIO1_SD_SEL;
316 out_be32(&pgpio->gpdat, val);
317 setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL);
318 break;
319 case GPIO1_EMMC_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 GPIO3_GET_VERSION:
Tom Rinid5c3bf22022-10-28 20:27:12 -0400326 pgpio = (ccsr_gpio_t *)(CFG_SYS_MPC85xx_GPIO_ADDR
Biwen Li6b63c542020-05-01 20:04:11 +0800327 + GPIO3_OFFSET);
328 val = in_be32(&pgpio->gpdat);
329 val = ((val & GPIO3_BRD_VER_MASK) >> 26) & 0x3;
330 if (val == 0x3) /* GPIO3_4/5 not used on RevB */
331 val = 0;
332 return val;
333 case I2C_GET_BANK:
334 i2c_set_bus_num(bus_num);
Shengzhou Liu0a197892015-06-17 16:37:01 +0800335 i2c_read(I2C_PCA6408_ADDR, 0, 1, &tmp, 1);
336 tmp &= 0x7;
337 tmp = ((tmp & 1) << 2) | (tmp & 2) | ((tmp & 4) >> 2);
338 i2c_set_bus_num(orig_bus);
339 return tmp;
340 case I2C_SET_BANK0:
Biwen Li6b63c542020-05-01 20:04:11 +0800341 i2c_set_bus_num(bus_num);
Shengzhou Liu0a197892015-06-17 16:37:01 +0800342 tmp = 0x0;
343 i2c_write(I2C_PCA6408_ADDR, 1, 1, &tmp, 1);
344 tmp = 0xf8;
345 i2c_write(I2C_PCA6408_ADDR, 3, 1, &tmp, 1);
346 /* asserting HRESET_REQ */
347 out_be32(&gur->rstcr, 0x2);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800348 break;
Shengzhou Liu0a197892015-06-17 16:37:01 +0800349 case I2C_SET_BANK4:
Biwen Li6b63c542020-05-01 20:04:11 +0800350 i2c_set_bus_num(bus_num);
Shengzhou Liu0a197892015-06-17 16:37:01 +0800351 tmp = 0x1;
352 i2c_write(I2C_PCA6408_ADDR, 1, 1, &tmp, 1);
353 tmp = 0xf8;
354 i2c_write(I2C_PCA6408_ADDR, 3, 1, &tmp, 1);
355 out_be32(&gur->rstcr, 0x2);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800356 break;
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800357 default:
358 break;
359 }
Biwen Li6b63c542020-05-01 20:04:11 +0800360#endif
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800361 return 0;
362}
363
Simon Glassed38aef2020-05-10 11:40:03 -0600364static int switch_cmd(struct cmd_tbl *cmdtp, int flag, int argc,
365 char *const argv[])
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800366{
367 if (argc < 2)
368 return CMD_RET_USAGE;
Shengzhou Liu0a197892015-06-17 16:37:01 +0800369 if (!strcmp(argv[1], "bank0"))
370 t1023rdb_ctrl(I2C_SET_BANK0);
371 else if (!strcmp(argv[1], "bank4") || !strcmp(argv[1], "altbank"))
372 t1023rdb_ctrl(I2C_SET_BANK4);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800373 else if (!strcmp(argv[1], "sd"))
Shengzhou Liu0a197892015-06-17 16:37:01 +0800374 t1023rdb_ctrl(GPIO1_SD_SEL);
375 else if (!strcmp(argv[1], "emmc"))
376 t1023rdb_ctrl(GPIO1_EMMC_SEL);
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800377 else
378 return CMD_RET_USAGE;
379 return 0;
380}
381
382U_BOOT_CMD(
Shengzhou Liu0a197892015-06-17 16:37:01 +0800383 switch, 2, 0, switch_cmd,
384 "for bank0/bank4/sd/emmc switch control in runtime",
385 "command (e.g. switch bank4)"
Shengzhou Liu00d7e5b2015-03-27 15:48:34 +0800386);
387#endif