blob: acc0be07c5af530774b2cf9d5a0c5a942401a8bf [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Shengzhou Liu48c6f322014-11-24 17:11:56 +08002/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
Shengzhou Liu48c6f322014-11-24 17:11:56 +08004 */
5
6#include <common.h>
7#include <command.h>
8#include <i2c.h>
9#include <netdev.h>
10#include <linux/compiler.h>
11#include <asm/mmu.h>
12#include <asm/processor.h>
13#include <asm/immap_85xx.h>
14#include <asm/fsl_law.h>
15#include <asm/fsl_serdes.h>
Shengzhou Liu48c6f322014-11-24 17:11:56 +080016#include <asm/fsl_liodn.h>
Shengzhou Liu48c6f322014-11-24 17:11:56 +080017#include <fm_eth.h>
18#include "t102xrdb.h"
York Sun960286b2016-12-28 08:43:34 -080019#ifdef CONFIG_TARGET_T1024RDB
Shengzhou Liu48c6f322014-11-24 17:11:56 +080020#include "cpld.h"
York Sun90824052016-12-28 08:43:33 -080021#elif defined(CONFIG_TARGET_T1023RDB)
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +080022#include <i2c.h>
23#include <mmc.h>
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +080024#endif
tang yuantianf49b8c12014-12-17 15:42:54 +080025#include "../common/sleep.h"
Shengzhou Liu48c6f322014-11-24 17:11:56 +080026
27DECLARE_GLOBAL_DATA_PTR;
28
York Sun90824052016-12-28 08:43:33 -080029#ifdef CONFIG_TARGET_T1023RDB
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +080030enum {
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +080031 GPIO1_SD_SEL = 0x00020000, /* GPIO1_14, 0: eMMC, 1:SD/MMC */
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +080032 GPIO1_EMMC_SEL,
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +080033 GPIO3_GET_VERSION, /* GPIO3_4/5, 00:RevB, 01: RevC */
34 GPIO3_BRD_VER_MASK = 0x0c000000,
35 GPIO3_OFFSET = 0x2000,
36 I2C_GET_BANK,
37 I2C_SET_BANK0,
38 I2C_SET_BANK4,
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +080039};
40#endif
41
Shengzhou Liu48c6f322014-11-24 17:11:56 +080042int checkboard(void)
43{
44 struct cpu_type *cpu = gd->arch.cpu;
45 static const char *freq[3] = {"100.00MHZ", "125.00MHz", "156.25MHZ"};
Shengzhou Liue26416a2014-12-17 16:51:08 +080046 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
47 u32 srds_s1;
48
49 srds_s1 = in_be32(&gur->rcwsr[4]) & FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
50 srds_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
Shengzhou Liu48c6f322014-11-24 17:11:56 +080051
52 printf("Board: %sRDB, ", cpu->name);
York Sun960286b2016-12-28 08:43:34 -080053#if defined(CONFIG_TARGET_T1024RDB)
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +080054 printf("Board rev: 0x%02x CPLD ver: 0x%02x, ",
Shengzhou Liu48c6f322014-11-24 17:11:56 +080055 CPLD_READ(hw_ver), CPLD_READ(sw_ver));
York Sun90824052016-12-28 08:43:33 -080056#elif defined(CONFIG_TARGET_T1023RDB)
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +080057 printf("Rev%c, ", t1023rdb_ctrl(GPIO3_GET_VERSION) + 'B');
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +080058#endif
59 printf("boot from ");
Shengzhou Liu48c6f322014-11-24 17:11:56 +080060
61#ifdef CONFIG_SDCARD
62 puts("SD/MMC\n");
63#elif CONFIG_SPIFLASH
64 puts("SPI\n");
York Sun960286b2016-12-28 08:43:34 -080065#elif defined(CONFIG_TARGET_T1024RDB)
Shengzhou Liu48c6f322014-11-24 17:11:56 +080066 u8 reg;
67
68 reg = CPLD_READ(flash_csr);
69
70 if (reg & CPLD_BOOT_SEL) {
71 puts("NAND\n");
72 } else {
73 reg = ((reg & CPLD_LBMAP_MASK) >> CPLD_LBMAP_SHIFT);
74 printf("NOR vBank%d\n", reg);
75 }
York Sun90824052016-12-28 08:43:33 -080076#elif defined(CONFIG_TARGET_T1023RDB)
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +080077#ifdef CONFIG_NAND
78 puts("NAND\n");
79#else
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +080080 printf("NOR vBank%d\n", t1023rdb_ctrl(I2C_GET_BANK));
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +080081#endif
Shengzhou Liu48c6f322014-11-24 17:11:56 +080082#endif
83
84 puts("SERDES Reference Clocks:\n");
Shengzhou Liue26416a2014-12-17 16:51:08 +080085 if (srds_s1 == 0x95)
86 printf("SD1_CLK1=%s, SD1_CLK2=%s\n", freq[2], freq[0]);
87 else
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +080088 printf("SD1_CLK1=%s, SD1_CLK2=%s\n", freq[0], freq[1]);
Shengzhou Liu48c6f322014-11-24 17:11:56 +080089
90 return 0;
91}
92
York Sun960286b2016-12-28 08:43:34 -080093#ifdef CONFIG_TARGET_T1024RDB
Shengzhou Liue26416a2014-12-17 16:51:08 +080094static void board_mux_lane(void)
95{
96 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
97 u32 srds_prtcl_s1;
98 u8 reg = CPLD_READ(misc_ctl_status);
99
100 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
101 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
102 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
103
104 if (srds_prtcl_s1 == 0x95) {
105 /* Route Lane B to PCIE */
106 CPLD_WRITE(misc_ctl_status, reg & ~CPLD_PCIE_SGMII_MUX);
107 } else {
108 /* Route Lane B to SGMII */
109 CPLD_WRITE(misc_ctl_status, reg | CPLD_PCIE_SGMII_MUX);
110 }
111 CPLD_WRITE(boot_override, CPLD_OVERRIDE_MUX_EN);
112}
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800113#endif
Shengzhou Liue26416a2014-12-17 16:51:08 +0800114
tang yuantianf49b8c12014-12-17 15:42:54 +0800115int board_early_init_f(void)
116{
117#if defined(CONFIG_DEEP_SLEEP)
118 if (is_warm_boot())
119 fsl_dp_disable_console();
120#endif
121
122 return 0;
123}
124
Shengzhou Liu48c6f322014-11-24 17:11:56 +0800125int board_early_init_r(void)
126{
127#ifdef CONFIG_SYS_FLASH_BASE
128 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
129 int flash_esel = find_tlb_idx((void *)flashbase, 1);
130 /*
131 * Remap Boot flash region to caching-inhibited
132 * so that flash can be erased properly.
133 */
134
135 /* Flush d-cache and invalidate i-cache of any FLASH data */
136 flush_dcache();
137 invalidate_icache();
138 if (flash_esel == -1) {
139 /* very unlikely unless something is messed up */
140 puts("Error: Could not find TLB for FLASH BASE\n");
141 flash_esel = 2; /* give our best effort to continue */
142 } else {
143 /* invalidate existing TLB entry for flash + promjet */
144 disable_tlb(flash_esel);
145 }
146
147 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
148 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
149 0, flash_esel, BOOKE_PAGESZ_256M, 1);
150#endif
151
York Sun960286b2016-12-28 08:43:34 -0800152#ifdef CONFIG_TARGET_T1024RDB
Shengzhou Liue26416a2014-12-17 16:51:08 +0800153 board_mux_lane();
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800154#endif
Shengzhou Liu48c6f322014-11-24 17:11:56 +0800155
156 return 0;
157}
158
159unsigned long get_board_sys_clk(void)
160{
161 return CONFIG_SYS_CLK_FREQ;
162}
163
164unsigned long get_board_ddr_clk(void)
165{
166 return CONFIG_DDR_CLK_FREQ;
167}
168
Shengzhou Liue0dfec82017-04-10 16:00:08 +0800169#ifdef CONFIG_TARGET_T1024RDB
170void board_reset(void)
171{
172 CPLD_WRITE(reset_ctl1, CPLD_LBMAP_RESET);
173}
174#endif
175
Shengzhou Liu48c6f322014-11-24 17:11:56 +0800176int misc_init_r(void)
177{
178 return 0;
179}
180
181int ft_board_setup(void *blob, bd_t *bd)
182{
183 phys_addr_t base;
184 phys_size_t size;
185
186 ft_cpu_setup(blob, bd);
187
Simon Glass723806c2017-08-03 12:22:15 -0600188 base = env_get_bootm_low();
189 size = env_get_bootm_size();
Shengzhou Liu48c6f322014-11-24 17:11:56 +0800190
191 fdt_fixup_memory(blob, (u64)base, (u64)size);
192
193#ifdef CONFIG_PCI
194 pci_of_setup(blob, bd);
195#endif
196
197 fdt_fixup_liodn(blob);
Sriram Dasha5c289b2016-09-16 17:12:15 +0530198 fsl_fdt_fixup_dr_usb(blob, bd);
Shengzhou Liu48c6f322014-11-24 17:11:56 +0800199
200#ifdef CONFIG_SYS_DPAA_FMAN
201 fdt_fixup_fman_ethernet(blob);
202 fdt_fixup_board_enet(blob);
203#endif
204
York Sun90824052016-12-28 08:43:33 -0800205#ifdef CONFIG_TARGET_T1023RDB
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +0800206 if (t1023rdb_ctrl(GPIO3_GET_VERSION) > 0)
207 fdt_enable_nor(blob);
208#endif
209
Shengzhou Liu48c6f322014-11-24 17:11:56 +0800210 return 0;
211}
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800212
York Sun90824052016-12-28 08:43:33 -0800213#ifdef CONFIG_TARGET_T1023RDB
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +0800214/* Enable NOR flash for RevC */
215static void fdt_enable_nor(void *blob)
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800216{
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +0800217 int nodeoff = fdt_node_offset_by_compatible(blob, 0, "cfi-flash");
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800218
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +0800219 if (nodeoff >= 0)
220 fdt_status_okay(blob, nodeoff);
221 else
222 printf("WARNING unable to set status for NOR\n");
223}
224
225int board_mmc_getcd(struct mmc *mmc)
226{
227 ccsr_gpio_t __iomem *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
228 u32 val = in_be32(&pgpio->gpdat);
229
230 /* GPIO1_14, 0: eMMC, 1: SD/MMC */
231 val &= GPIO1_SD_SEL;
232
233 return val ? -1 : 1;
234}
235
236int board_mmc_getwp(struct mmc *mmc)
237{
238 ccsr_gpio_t __iomem *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
239 u32 val = in_be32(&pgpio->gpdat);
240
241 val &= GPIO1_SD_SEL;
242
243 return val ? -1 : 0;
244}
245
246static u32 t1023rdb_ctrl(u32 ctrl_type)
247{
248 ccsr_gpio_t __iomem *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
249 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
250 u32 val, orig_bus = i2c_get_bus_num();
251 u8 tmp;
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800252
253 switch (ctrl_type) {
254 case GPIO1_SD_SEL:
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +0800255 val = in_be32(&pgpio->gpdat);
256 val |= GPIO1_SD_SEL;
257 out_be32(&pgpio->gpdat, val);
258 setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL);
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800259 break;
260 case GPIO1_EMMC_SEL:
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +0800261 val = in_be32(&pgpio->gpdat);
262 val &= ~GPIO1_SD_SEL;
263 out_be32(&pgpio->gpdat, val);
264 setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL);
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800265 break;
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +0800266 case GPIO3_GET_VERSION:
267 pgpio = (ccsr_gpio_t *)(CONFIG_SYS_MPC85xx_GPIO_ADDR
268 + GPIO3_OFFSET);
269 val = in_be32(&pgpio->gpdat);
270 val = ((val & GPIO3_BRD_VER_MASK) >> 26) & 0x3;
271 if (val == 0x3) /* GPIO3_4/5 not used on RevB */
272 val = 0;
273 return val;
274 case I2C_GET_BANK:
275 i2c_set_bus_num(I2C_PCA6408_BUS_NUM);
276 i2c_read(I2C_PCA6408_ADDR, 0, 1, &tmp, 1);
277 tmp &= 0x7;
278 tmp = ((tmp & 1) << 2) | (tmp & 2) | ((tmp & 4) >> 2);
279 i2c_set_bus_num(orig_bus);
280 return tmp;
281 case I2C_SET_BANK0:
282 i2c_set_bus_num(I2C_PCA6408_BUS_NUM);
283 tmp = 0x0;
284 i2c_write(I2C_PCA6408_ADDR, 1, 1, &tmp, 1);
285 tmp = 0xf8;
286 i2c_write(I2C_PCA6408_ADDR, 3, 1, &tmp, 1);
287 /* asserting HRESET_REQ */
288 out_be32(&gur->rstcr, 0x2);
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800289 break;
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +0800290 case I2C_SET_BANK4:
291 i2c_set_bus_num(I2C_PCA6408_BUS_NUM);
292 tmp = 0x1;
293 i2c_write(I2C_PCA6408_ADDR, 1, 1, &tmp, 1);
294 tmp = 0xf8;
295 i2c_write(I2C_PCA6408_ADDR, 3, 1, &tmp, 1);
296 out_be32(&gur->rstcr, 0x2);
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800297 break;
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800298 default:
299 break;
300 }
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800301 return 0;
302}
303
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +0800304static int switch_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800305 char * const argv[])
306{
307 if (argc < 2)
308 return CMD_RET_USAGE;
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +0800309 if (!strcmp(argv[1], "bank0"))
310 t1023rdb_ctrl(I2C_SET_BANK0);
311 else if (!strcmp(argv[1], "bank4") || !strcmp(argv[1], "altbank"))
312 t1023rdb_ctrl(I2C_SET_BANK4);
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800313 else if (!strcmp(argv[1], "sd"))
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +0800314 t1023rdb_ctrl(GPIO1_SD_SEL);
315 else if (!strcmp(argv[1], "emmc"))
316 t1023rdb_ctrl(GPIO1_EMMC_SEL);
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800317 else
318 return CMD_RET_USAGE;
319 return 0;
320}
321
322U_BOOT_CMD(
Shengzhou Liuff7ea2d2015-06-17 16:37:01 +0800323 switch, 2, 0, switch_cmd,
324 "for bank0/bank4/sd/emmc switch control in runtime",
325 "command (e.g. switch bank4)"
Shengzhou Liue8a7f1c2015-03-27 15:48:34 +0800326);
327#endif