blob: 65bb575a9643836b613047e8375d65adf21ed214 [file] [log] [blame]
Poonam Aggrwala2ec1352011-02-09 19:17:53 +00001/*
2 * Copyright 2010-2011 Freescale Semiconductor, Inc.
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Poonam Aggrwala2ec1352011-02-09 19:17:53 +00005 */
6
7#include <common.h>
8#include <asm/processor.h>
9#include <asm/mmu.h>
10#include <asm/cache.h>
11#include <asm/immap_85xx.h>
12#include <asm/io.h>
13#include <miiphy.h>
14#include <libfdt.h>
15#include <fdt_support.h>
16#include <fsl_mdio.h>
17#include <tsec.h>
18#include <mmc.h>
19#include <netdev.h>
20#include <pci.h>
21#include <asm/fsl_serdes.h>
York Sun37562f62013-10-22 12:39:02 -070022#include <fsl_ifc.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000023#include <asm/fsl_pci.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000024#include <hwconfig.h>
Shengzhou Liu36446ef2013-09-13 14:46:02 +080025#include <i2c.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000026
27DECLARE_GLOBAL_DATA_PTR;
28
29#define GPIO4_PCIE_RESET_SET 0x08000000
30#define MUX_CPLD_CAN_UART 0x00
31#define MUX_CPLD_TDM 0x01
32#define MUX_CPLD_SPICS0_FLASH 0x00
33#define MUX_CPLD_SPICS0_SLIC 0x02
Shengzhou Liu36446ef2013-09-13 14:46:02 +080034#define PMUXCR1_IFC_MASK 0x00ffff00
35#define PMUXCR1_SDHC_MASK 0x00fff000
36#define PMUXCR1_SDHC_ENABLE 0x00555000
37
38enum {
39 MUX_TYPE_IFC,
40 MUX_TYPE_SDHC,
Shengzhou Liuf0af4382013-09-13 14:46:03 +080041 MUX_TYPE_SPIFLASH,
42 MUX_TYPE_TDM,
43 MUX_TYPE_CAN,
44 MUX_TYPE_CS0_NOR,
45 MUX_TYPE_CS0_NAND,
Shengzhou Liu36446ef2013-09-13 14:46:02 +080046};
47
Shengzhou Liuf0af4382013-09-13 14:46:03 +080048enum {
49 I2C_READ_BANK,
50 I2C_READ_PCB_VER,
51};
52
Shengzhou Liu36446ef2013-09-13 14:46:02 +080053static uint sd_ifc_mux;
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000054
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000055struct cpld_data {
56 u8 cpld_ver; /* cpld revision */
York Sun7f945ca2016-11-16 13:30:06 -080057#if defined(CONFIG_TARGET_P1010RDB_PA)
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000058 u8 pcba_ver; /* pcb revision number */
59 u8 twindie_ddr3;
60 u8 res1[6];
61 u8 bank_sel; /* NOR Flash bank */
62 u8 res2[5];
63 u8 usb2_sel;
64 u8 res3[1];
65 u8 porsw_sel;
66 u8 tdm_can_sel;
67 u8 spi_cs0_sel; /* SPI CS0 SLIC/SPI Flash */
68 u8 por0; /* POR Options */
69 u8 por1; /* POR Options */
70 u8 por2; /* POR Options */
71 u8 por3; /* POR Options */
York Sun7f945ca2016-11-16 13:30:06 -080072#elif defined(CONFIG_TARGET_P1010RDB_PB)
Shengzhou Liuf0af4382013-09-13 14:46:03 +080073 u8 rom_loc;
74#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000075};
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000076
77int board_early_init_f(void)
78{
79 ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
Jaiprakash Singhdd888062015-03-20 19:28:27 -070080 struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000081 /* Clock configuration to access CPLD using IFC(GPCM) */
Jaiprakash Singhdd888062015-03-20 19:28:27 -070082 setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000083 /*
84 * Reset PCIe slots via GPIO4
85 */
86 setbits_be32(&pgpio->gpdir, GPIO4_PCIE_RESET_SET);
87 setbits_be32(&pgpio->gpdat, GPIO4_PCIE_RESET_SET);
88
89 return 0;
90}
91
92int board_early_init_r(void)
93{
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000094 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -070095 int flash_esel = find_tlb_idx((void *)flashbase, 1);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000096
97 /*
98 * Remap Boot flash region to caching-inhibited
99 * so that flash can be erased properly.
100 */
101
102 /* Flush d-cache and invalidate i-cache of any FLASH data */
103 flush_dcache();
104 invalidate_icache();
105
York Sun220c3462014-06-24 21:16:20 -0700106 if (flash_esel == -1) {
107 /* very unlikely unless something is messed up */
108 puts("Error: Could not find TLB for FLASH BASE\n");
109 flash_esel = 2; /* give our best effort to continue */
110 } else {
111 /* invalidate existing TLB entry for flash */
112 disable_tlb(flash_esel);
113 }
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000114
115 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
116 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
117 0, flash_esel, BOOKE_PAGESZ_16M, 1);
118
119 set_tlb(1, flashbase + 0x1000000,
120 CONFIG_SYS_FLASH_BASE_PHYS + 0x1000000,
121 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
122 0, flash_esel+1, BOOKE_PAGESZ_16M, 1);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000123 return 0;
124}
125
126#ifdef CONFIG_PCI
127void pci_init_board(void)
128{
129 fsl_pcie_init_board(0);
130}
131#endif /* ifdef CONFIG_PCI */
132
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800133int config_board_mux(int ctrl_type)
134{
135 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
136 u8 tmp;
137
York Sun7f945ca2016-11-16 13:30:06 -0800138#if defined(CONFIG_TARGET_P1010RDB_PA)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800139 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
140
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800141 switch (ctrl_type) {
142 case MUX_TYPE_IFC:
143 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
144 tmp = 0xf0;
145 i2c_write(I2C_PCA9557_ADDR1, 3, 1, &tmp, 1);
146 tmp = 0x01;
147 i2c_write(I2C_PCA9557_ADDR1, 1, 1, &tmp, 1);
148 sd_ifc_mux = MUX_TYPE_IFC;
149 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
150 break;
151 case MUX_TYPE_SDHC:
152 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
153 tmp = 0xf0;
154 i2c_write(I2C_PCA9557_ADDR1, 3, 1, &tmp, 1);
155 tmp = 0x05;
156 i2c_write(I2C_PCA9557_ADDR1, 1, 1, &tmp, 1);
157 sd_ifc_mux = MUX_TYPE_SDHC;
158 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
159 PMUXCR1_SDHC_ENABLE);
160 break;
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800161 case MUX_TYPE_SPIFLASH:
162 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_FLASH);
163 break;
164 case MUX_TYPE_TDM:
165 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_TDM);
166 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_SLIC);
167 break;
168 case MUX_TYPE_CAN:
169 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_CAN_UART);
170 break;
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800171 default:
172 break;
173 }
York Sun7f945ca2016-11-16 13:30:06 -0800174#elif defined(CONFIG_TARGET_P1010RDB_PB)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800175 uint orig_bus = i2c_get_bus_num();
176 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800177
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800178 switch (ctrl_type) {
179 case MUX_TYPE_IFC:
180 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
181 clrbits_8(&tmp, 0x04);
182 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
183 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
184 clrbits_8(&tmp, 0x04);
185 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
186 sd_ifc_mux = MUX_TYPE_IFC;
187 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
188 break;
189 case MUX_TYPE_SDHC:
190 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
191 setbits_8(&tmp, 0x04);
192 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
193 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
194 clrbits_8(&tmp, 0x04);
195 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
196 sd_ifc_mux = MUX_TYPE_SDHC;
197 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
198 PMUXCR1_SDHC_ENABLE);
199 break;
200 case MUX_TYPE_SPIFLASH:
201 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
202 clrbits_8(&tmp, 0x80);
203 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
204 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
205 clrbits_8(&tmp, 0x80);
206 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
207 break;
208 case MUX_TYPE_TDM:
209 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
210 setbits_8(&tmp, 0x82);
211 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
212 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
213 clrbits_8(&tmp, 0x82);
214 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
215 break;
216 case MUX_TYPE_CAN:
217 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
218 clrbits_8(&tmp, 0x02);
219 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
220 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
221 clrbits_8(&tmp, 0x02);
222 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
223 break;
224 case MUX_TYPE_CS0_NOR:
225 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
226 clrbits_8(&tmp, 0x08);
227 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
228 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
229 clrbits_8(&tmp, 0x08);
230 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
231 break;
232 case MUX_TYPE_CS0_NAND:
233 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
234 setbits_8(&tmp, 0x08);
235 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
236 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
237 clrbits_8(&tmp, 0x08);
238 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
239 break;
240 default:
241 break;
242 }
243 i2c_set_bus_num(orig_bus);
244#endif
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800245 return 0;
246}
247
York Sun7f945ca2016-11-16 13:30:06 -0800248#ifdef CONFIG_TARGET_P1010RDB_PB
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800249int i2c_pca9557_read(int type)
250{
251 u8 val;
252
253 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
254 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &val, 1);
255
256 switch (type) {
257 case I2C_READ_BANK:
258 val = (val & 0x10) >> 4;
259 break;
260 case I2C_READ_PCB_VER:
261 val = ((val & 0x60) >> 5) + 1;
262 break;
263 default:
264 break;
265 }
266
267 return val;
268}
269#endif
270
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000271int checkboard(void)
272{
273 struct cpu_type *cpu;
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800274 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
275 u8 val;
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000276
Simon Glassa8b57392012-12-13 20:48:48 +0000277 cpu = gd->arch.cpu;
York Sun7f945ca2016-11-16 13:30:06 -0800278#if defined(CONFIG_TARGET_P1010RDB_PA)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800279 printf("Board: %sRDB-PA, ", cpu->name);
York Sun7f945ca2016-11-16 13:30:06 -0800280#elif defined(CONFIG_TARGET_P1010RDB_PB)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800281 printf("Board: %sRDB-PB, ", cpu->name);
282 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
283 i2c_init(CONFIG_SYS_FSL_I2C_SPEED, CONFIG_SYS_FSL_I2C_SLAVE);
284 val = 0x0; /* no polarity inversion */
285 i2c_write(I2C_PCA9557_ADDR2, 2, 1, &val, 1);
286#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000287
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800288#ifdef CONFIG_SDCARD
289 /* switch to IFC to read info from CPLD */
290 config_board_mux(MUX_TYPE_IFC);
291#endif
292
York Sun7f945ca2016-11-16 13:30:06 -0800293#if defined(CONFIG_TARGET_P1010RDB_PA)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800294 val = (in_8(&cpld_data->pcba_ver) & 0xf);
295 printf("PCB: v%x.0\n", val);
York Sun7f945ca2016-11-16 13:30:06 -0800296#elif defined(CONFIG_TARGET_P1010RDB_PB)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800297 val = in_8(&cpld_data->cpld_ver);
298 printf("CPLD: v%x.%x, ", val >> 4, val & 0xf);
299 printf("PCB: v%x.0, ", i2c_pca9557_read(I2C_READ_PCB_VER));
300 val = in_8(&cpld_data->rom_loc) & 0xf;
301 puts("Boot from: ");
302 switch (val) {
303 case 0xf:
304 config_board_mux(MUX_TYPE_CS0_NOR);
305 printf("NOR vBank%d\n", i2c_pca9557_read(I2C_READ_BANK));
306 break;
307 case 0xe:
308 puts("SDHC\n");
309 val = 0x60; /* set pca9557 pin input/output */
310 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &val, 1);
311 break;
312 case 0x5:
313 config_board_mux(MUX_TYPE_IFC);
314 config_board_mux(MUX_TYPE_CS0_NAND);
315 puts("NAND\n");
316 break;
317 case 0x6:
318 config_board_mux(MUX_TYPE_IFC);
319 puts("SPI\n");
320 break;
321 default:
322 puts("unknown\n");
323 break;
324 }
325#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000326 return 0;
327}
328
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000329int board_eth_init(bd_t *bis)
330{
Bin Menge52fb1c2016-01-11 22:41:16 -0800331#ifdef CONFIG_TSEC_ENET
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000332 struct fsl_pq_mdio_info mdio_info;
333 struct tsec_info_struct tsec_info[4];
334 struct cpu_type *cpu;
335 int num = 0;
336
Simon Glassa8b57392012-12-13 20:48:48 +0000337 cpu = gd->arch.cpu;
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000338
339#ifdef CONFIG_TSEC1
340 SET_STD_TSEC_INFO(tsec_info[num], 1);
341 num++;
342#endif
343#ifdef CONFIG_TSEC2
344 SET_STD_TSEC_INFO(tsec_info[num], 2);
345 num++;
346#endif
347#ifdef CONFIG_TSEC3
348 /* P1014 and it's derivatives do not support eTSEC3 */
York Sun8cb65482012-07-06 17:10:33 -0500349 if (cpu->soc_ver != SVR_P1014) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000350 SET_STD_TSEC_INFO(tsec_info[num], 3);
351 num++;
352 }
353#endif
354 if (!num) {
355 printf("No TSECs initialized\n");
356 return 0;
357 }
358
359 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
360 mdio_info.name = DEFAULT_MII_NAME;
361
362 fsl_pq_mdio_init(bis, &mdio_info);
363
364 tsec_eth_init(bis, tsec_info, num);
Bin Menge52fb1c2016-01-11 22:41:16 -0800365#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000366
367 return pci_eth_init(bis);
368}
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000369
370#if defined(CONFIG_OF_BOARD_SETUP)
371void fdt_del_flexcan(void *blob)
372{
373 int nodeoff = 0;
374
375 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
Shengzhou Liua5b0ded2013-03-25 07:30:09 +0000376 "fsl,p1010-flexcan")) >= 0) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000377 fdt_del_node(blob, nodeoff);
378 }
379}
380
381void fdt_del_spi_flash(void *blob)
382{
383 int nodeoff = 0;
384
385 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
386 "spansion,s25sl12801")) >= 0) {
387 fdt_del_node(blob, nodeoff);
388 }
389}
390
391void fdt_del_spi_slic(void *blob)
392{
393 int nodeoff = 0;
394
395 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
396 "zarlink,le88266")) >= 0) {
397 fdt_del_node(blob, nodeoff);
398 }
399}
400
401void fdt_del_tdm(void *blob)
402{
403 int nodeoff = 0;
404
405 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
406 "fsl,starlite-tdm")) >= 0) {
407 fdt_del_node(blob, nodeoff);
408 }
409}
410
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000411void fdt_del_sdhc(void *blob)
412{
413 int nodeoff = 0;
414
415 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
416 "fsl,esdhc")) >= 0) {
417 fdt_del_node(blob, nodeoff);
418 }
419}
420
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800421void fdt_del_ifc(void *blob)
422{
423 int nodeoff = 0;
424
425 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
426 "fsl,ifc")) >= 0) {
427 fdt_del_node(blob, nodeoff);
428 }
429}
430
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000431void fdt_disable_uart1(void *blob)
432{
433 int nodeoff;
434
435 nodeoff = fdt_node_offset_by_compat_reg(blob, "fsl,ns16550",
436 CONFIG_SYS_NS16550_COM2);
437
438 if (nodeoff > 0) {
439 fdt_status_disabled(blob, nodeoff);
440 } else {
441 printf("WARNING unable to set status for fsl,ns16550 "
442 "uart1: %s\n", fdt_strerror(nodeoff));
443 }
444}
445
Simon Glass2aec3cc2014-10-23 18:58:47 -0600446int ft_board_setup(void *blob, bd_t *bd)
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000447{
448 phys_addr_t base;
449 phys_size_t size;
450 struct cpu_type *cpu;
451
Simon Glassa8b57392012-12-13 20:48:48 +0000452 cpu = gd->arch.cpu;
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000453
454 ft_cpu_setup(blob, bd);
455
456 base = getenv_bootm_low();
457 size = getenv_bootm_size();
458
459#if defined(CONFIG_PCI)
460 FT_FSL_PCI_SETUP;
461#endif
462
463 fdt_fixup_memory(blob, (u64)base, (u64)size);
464
Ramneek Mehresh59c48b42011-11-08 10:21:28 +0530465#if defined(CONFIG_HAS_FSL_DR_USB)
Sriram Dash9fd465c2016-09-16 17:12:15 +0530466 fsl_fdt_fixup_dr_usb(blob, bd);
Ramneek Mehresh59c48b42011-11-08 10:21:28 +0530467#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000468
469 /* P1014 and it's derivatives don't support CAN and eTSEC3 */
York Sun8cb65482012-07-06 17:10:33 -0500470 if (cpu->soc_ver == SVR_P1014) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000471 fdt_del_flexcan(blob);
472 fdt_del_node_and_alias(blob, "ethernet2");
473 }
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800474
475 /* Delete IFC node as IFC pins are multiplexing with SDHC */
476 if (sd_ifc_mux != MUX_TYPE_IFC)
477 fdt_del_ifc(blob);
478 else
479 fdt_del_sdhc(blob);
480
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000481 if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "can")) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000482 fdt_del_tdm(blob);
483 fdt_del_spi_slic(blob);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000484 } else if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "tdm")) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000485 fdt_del_flexcan(blob);
486 fdt_del_spi_flash(blob);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000487 fdt_disable_uart1(blob);
488 } else {
489 /*
490 * If we don't set fsl_p1010mux:tdm_can to "can" or "tdm"
491 * explicitly, defaultly spi_cs_sel to spi-flash instead of
492 * to tdm/slic.
493 */
494 fdt_del_tdm(blob);
495 fdt_del_flexcan(blob);
496 fdt_disable_uart1(blob);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000497 }
Simon Glass2aec3cc2014-10-23 18:58:47 -0600498
499 return 0;
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800500}
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000501#endif
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800502
503#ifdef CONFIG_SDCARD
504int board_mmc_init(bd_t *bis)
505{
506 config_board_mux(MUX_TYPE_SDHC);
507 return -1;
508}
509#else
510void board_reset(void)
511{
512 /* mux to IFC to enable CPLD for reset */
513 if (sd_ifc_mux != MUX_TYPE_IFC)
514 config_board_mux(MUX_TYPE_IFC);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000515}
516#endif
517
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800518
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000519int misc_init_r(void)
520{
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000521 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
522
523 if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "can")) {
524 clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN1_TDM |
525 MPC85xx_PMUXCR_CAN1_UART |
526 MPC85xx_PMUXCR_CAN2_TDM |
527 MPC85xx_PMUXCR_CAN2_UART);
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800528 config_board_mux(MUX_TYPE_CAN);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000529 } else if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "tdm")) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000530 clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN2_UART |
531 MPC85xx_PMUXCR_CAN1_UART);
532 setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN2_TDM |
533 MPC85xx_PMUXCR_CAN1_TDM);
534 clrbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_UART_GPIO);
535 setbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_UART_TDM);
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800536 config_board_mux(MUX_TYPE_TDM);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000537 } else {
538 /* defaultly spi_cs_sel to flash */
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800539 config_board_mux(MUX_TYPE_SPIFLASH);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000540 }
541
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800542 if (hwconfig("esdhc"))
543 config_board_mux(MUX_TYPE_SDHC);
544 else if (hwconfig("ifc"))
545 config_board_mux(MUX_TYPE_IFC);
546
York Sun7f945ca2016-11-16 13:30:06 -0800547#ifdef CONFIG_TARGET_P1010RDB_PB
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800548 setbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_GPIO01_DRVVBUS);
549#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000550 return 0;
551}
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800552
553static int pin_mux_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
554 char * const argv[])
555{
556 if (argc < 2)
557 return CMD_RET_USAGE;
558 if (strcmp(argv[1], "ifc") == 0)
559 config_board_mux(MUX_TYPE_IFC);
560 else if (strcmp(argv[1], "sdhc") == 0)
561 config_board_mux(MUX_TYPE_SDHC);
562 else
563 return CMD_RET_USAGE;
564 return 0;
565}
566
567U_BOOT_CMD(
568 mux, 2, 0, pin_mux_cmd,
569 "configure multiplexing pin for IFC/SDHC bus in runtime",
570 "bus_type (e.g. mux sdhc)"
571);