blob: 65ac47263ec7a77adeea4f308aaf271ec9fbecaa [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Poonam Aggrwala2ec1352011-02-09 19:17:53 +00002/*
3 * Copyright 2010-2011 Freescale Semiconductor, Inc.
Biwen Li6a2d8d12020-05-01 20:04:13 +08004 * Copyright 2020 NXP
Poonam Aggrwala2ec1352011-02-09 19:17:53 +00005 */
6
7#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -07008#include <init.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +00009#include <asm/processor.h>
10#include <asm/mmu.h>
11#include <asm/cache.h>
12#include <asm/immap_85xx.h>
13#include <asm/io.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -060014#include <env.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000015#include <miiphy.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090016#include <linux/libfdt.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000017#include <fdt_support.h>
18#include <fsl_mdio.h>
19#include <tsec.h>
20#include <mmc.h>
21#include <netdev.h>
22#include <pci.h>
23#include <asm/fsl_serdes.h>
York Sun37562f62013-10-22 12:39:02 -070024#include <fsl_ifc.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000025#include <asm/fsl_pci.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000026#include <hwconfig.h>
Shengzhou Liu36446ef2013-09-13 14:46:02 +080027#include <i2c.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000028
29DECLARE_GLOBAL_DATA_PTR;
30
31#define GPIO4_PCIE_RESET_SET 0x08000000
32#define MUX_CPLD_CAN_UART 0x00
33#define MUX_CPLD_TDM 0x01
34#define MUX_CPLD_SPICS0_FLASH 0x00
35#define MUX_CPLD_SPICS0_SLIC 0x02
Shengzhou Liu36446ef2013-09-13 14:46:02 +080036#define PMUXCR1_IFC_MASK 0x00ffff00
37#define PMUXCR1_SDHC_MASK 0x00fff000
38#define PMUXCR1_SDHC_ENABLE 0x00555000
39
40enum {
41 MUX_TYPE_IFC,
42 MUX_TYPE_SDHC,
Shengzhou Liuf0af4382013-09-13 14:46:03 +080043 MUX_TYPE_SPIFLASH,
44 MUX_TYPE_TDM,
45 MUX_TYPE_CAN,
46 MUX_TYPE_CS0_NOR,
47 MUX_TYPE_CS0_NAND,
Shengzhou Liu36446ef2013-09-13 14:46:02 +080048};
49
Shengzhou Liuf0af4382013-09-13 14:46:03 +080050enum {
51 I2C_READ_BANK,
52 I2C_READ_PCB_VER,
53};
54
Shengzhou Liu36446ef2013-09-13 14:46:02 +080055static uint sd_ifc_mux;
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000056
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000057struct cpld_data {
58 u8 cpld_ver; /* cpld revision */
York Sun7f945ca2016-11-16 13:30:06 -080059#if defined(CONFIG_TARGET_P1010RDB_PA)
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000060 u8 pcba_ver; /* pcb revision number */
61 u8 twindie_ddr3;
62 u8 res1[6];
63 u8 bank_sel; /* NOR Flash bank */
64 u8 res2[5];
65 u8 usb2_sel;
66 u8 res3[1];
67 u8 porsw_sel;
68 u8 tdm_can_sel;
69 u8 spi_cs0_sel; /* SPI CS0 SLIC/SPI Flash */
70 u8 por0; /* POR Options */
71 u8 por1; /* POR Options */
72 u8 por2; /* POR Options */
73 u8 por3; /* POR Options */
York Sun7f945ca2016-11-16 13:30:06 -080074#elif defined(CONFIG_TARGET_P1010RDB_PB)
Shengzhou Liuf0af4382013-09-13 14:46:03 +080075 u8 rom_loc;
76#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000077};
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000078
79int board_early_init_f(void)
80{
81 ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
Jaiprakash Singhdd888062015-03-20 19:28:27 -070082 struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000083 /* Clock configuration to access CPLD using IFC(GPCM) */
Jaiprakash Singhdd888062015-03-20 19:28:27 -070084 setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000085 /*
86 * Reset PCIe slots via GPIO4
87 */
88 setbits_be32(&pgpio->gpdir, GPIO4_PCIE_RESET_SET);
89 setbits_be32(&pgpio->gpdat, GPIO4_PCIE_RESET_SET);
90
91 return 0;
92}
93
94int board_early_init_r(void)
95{
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000096 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -070097 int flash_esel = find_tlb_idx((void *)flashbase, 1);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000098
99 /*
100 * Remap Boot flash region to caching-inhibited
101 * so that flash can be erased properly.
102 */
103
104 /* Flush d-cache and invalidate i-cache of any FLASH data */
105 flush_dcache();
106 invalidate_icache();
107
York Sun220c3462014-06-24 21:16:20 -0700108 if (flash_esel == -1) {
109 /* very unlikely unless something is messed up */
110 puts("Error: Could not find TLB for FLASH BASE\n");
111 flash_esel = 2; /* give our best effort to continue */
112 } else {
113 /* invalidate existing TLB entry for flash */
114 disable_tlb(flash_esel);
115 }
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000116
117 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
118 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
119 0, flash_esel, BOOKE_PAGESZ_16M, 1);
120
121 set_tlb(1, flashbase + 0x1000000,
122 CONFIG_SYS_FLASH_BASE_PHYS + 0x1000000,
123 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
124 0, flash_esel+1, BOOKE_PAGESZ_16M, 1);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000125 return 0;
126}
127
128#ifdef CONFIG_PCI
129void pci_init_board(void)
130{
131 fsl_pcie_init_board(0);
132}
133#endif /* ifdef CONFIG_PCI */
134
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800135int config_board_mux(int ctrl_type)
136{
137 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
138 u8 tmp;
139
Biwen Li6a2d8d12020-05-01 20:04:13 +0800140#ifdef CONFIG_DM_I2C
141 struct udevice *dev;
142 int ret;
York Sun7f945ca2016-11-16 13:30:06 -0800143#if defined(CONFIG_TARGET_P1010RDB_PA)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800144 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
145
Biwen Li6a2d8d12020-05-01 20:04:13 +0800146 ret = i2c_get_chip_for_busnum(I2C_PCA9557_BUS_NUM,
147 I2C_PCA9557_ADDR1, 1, &dev);
148 if (ret) {
149 printf("%s: Cannot find udev for a bus %d\n",
150 __func__, I2C_PCA9557_BUS_NUM);
151 return ret;
152 }
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800153 switch (ctrl_type) {
154 case MUX_TYPE_IFC:
Biwen Li6a2d8d12020-05-01 20:04:13 +0800155 tmp = 0xf0;
156 dm_i2c_write(dev, 3, &tmp, 1);
157 tmp = 0x01;
158 dm_i2c_write(dev, 1, &tmp, 1);
159 sd_ifc_mux = MUX_TYPE_IFC;
160 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
161 break;
162 case MUX_TYPE_SDHC:
163 tmp = 0xf0;
164 dm_i2c_write(dev, 3, &tmp, 1);
165 tmp = 0x05;
166 dm_i2c_write(dev, 1, &tmp, 1);
167 sd_ifc_mux = MUX_TYPE_SDHC;
168 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
169 PMUXCR1_SDHC_ENABLE);
170 break;
171 case MUX_TYPE_SPIFLASH:
172 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_FLASH);
173 break;
174 case MUX_TYPE_TDM:
175 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_TDM);
176 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_SLIC);
177 break;
178 case MUX_TYPE_CAN:
179 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_CAN_UART);
180 break;
181 default:
182 break;
183 }
184#elif defined(CONFIG_TARGET_P1010RDB_PB)
185 ret = i2c_get_chip_for_busnum(I2C_PCA9557_BUS_NUM,
186 I2C_PCA9557_ADDR2, 1, &dev);
187 if (ret) {
188 printf("%s: Cannot find udev for a bus %d\n",
189 __func__, I2C_PCA9557_BUS_NUM);
190 return ret;
191 }
192 switch (ctrl_type) {
193 case MUX_TYPE_IFC:
194 dm_i2c_read(dev, 0, &tmp, 1);
195 clrbits_8(&tmp, 0x04);
196 dm_i2c_write(dev, 1, &tmp, 1);
197 dm_i2c_read(dev, 3, &tmp, 1);
198 clrbits_8(&tmp, 0x04);
199 dm_i2c_write(dev, 3, &tmp, 1);
200 sd_ifc_mux = MUX_TYPE_IFC;
201 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
202 break;
203 case MUX_TYPE_SDHC:
204 dm_i2c_read(dev, 0, &tmp, 1);
205 setbits_8(&tmp, 0x04);
206 dm_i2c_write(dev, 1, &tmp, 1);
207 dm_i2c_read(dev, 3, &tmp, 1);
208 clrbits_8(&tmp, 0x04);
209 dm_i2c_write(dev, 3, &tmp, 1);
210 sd_ifc_mux = MUX_TYPE_SDHC;
211 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
212 PMUXCR1_SDHC_ENABLE);
213 break;
214 case MUX_TYPE_SPIFLASH:
215 dm_i2c_read(dev, 0, &tmp, 1);
216 clrbits_8(&tmp, 0x80);
217 dm_i2c_write(dev, 1, &tmp, 1);
218 dm_i2c_read(dev, 3, &tmp, 1);
219 clrbits_8(&tmp, 0x80);
220 dm_i2c_write(dev, 3, &tmp, 1);
221 break;
222 case MUX_TYPE_TDM:
223 dm_i2c_read(dev, 0, &tmp, 1);
224 setbits_8(&tmp, 0x82);
225 dm_i2c_write(dev, 1, &tmp, 1);
226 dm_i2c_read(dev, 3, &tmp, 1);
227 clrbits_8(&tmp, 0x82);
228 dm_i2c_write(dev, 3, &tmp, 1);
229 break;
230 case MUX_TYPE_CAN:
231 dm_i2c_read(dev, 0, &tmp, 1);
232 clrbits_8(&tmp, 0x02);
233 dm_i2c_write(dev, 1, &tmp, 1);
234 dm_i2c_read(dev, 3, &tmp, 1);
235 clrbits_8(&tmp, 0x02);
236 dm_i2c_write(dev, 3, &tmp, 1);
237 break;
238 case MUX_TYPE_CS0_NOR:
239 dm_i2c_read(dev, 0, &tmp, 1);
240 clrbits_8(&tmp, 0x08);
241 dm_i2c_write(dev, 1, &tmp, 1);
242 dm_i2c_read(dev, 3, &tmp, 1);
243 clrbits_8(&tmp, 0x08);
244 dm_i2c_write(dev, 3, &tmp, 1);
245 break;
246 case MUX_TYPE_CS0_NAND:
247 dm_i2c_read(dev, 0, &tmp, 1);
248 setbits_8(&tmp, 0x08);
249 dm_i2c_write(dev, 1, &tmp, 1);
250 dm_i2c_read(dev, 3, &tmp, 1);
251 clrbits_8(&tmp, 0x08);
252 dm_i2c_write(dev, 3, &tmp, 1);
253 break;
254 default:
255 break;
256 }
257#endif
258#else
259#if defined(CONFIG_TARGET_P1010RDB_PA)
260 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
261
262 switch (ctrl_type) {
263 case MUX_TYPE_IFC:
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800264 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
265 tmp = 0xf0;
266 i2c_write(I2C_PCA9557_ADDR1, 3, 1, &tmp, 1);
267 tmp = 0x01;
268 i2c_write(I2C_PCA9557_ADDR1, 1, 1, &tmp, 1);
269 sd_ifc_mux = MUX_TYPE_IFC;
270 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
271 break;
272 case MUX_TYPE_SDHC:
273 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
274 tmp = 0xf0;
275 i2c_write(I2C_PCA9557_ADDR1, 3, 1, &tmp, 1);
276 tmp = 0x05;
277 i2c_write(I2C_PCA9557_ADDR1, 1, 1, &tmp, 1);
278 sd_ifc_mux = MUX_TYPE_SDHC;
279 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
280 PMUXCR1_SDHC_ENABLE);
281 break;
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800282 case MUX_TYPE_SPIFLASH:
283 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_FLASH);
284 break;
285 case MUX_TYPE_TDM:
286 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_TDM);
287 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_SLIC);
288 break;
289 case MUX_TYPE_CAN:
290 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_CAN_UART);
291 break;
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800292 default:
293 break;
294 }
York Sun7f945ca2016-11-16 13:30:06 -0800295#elif defined(CONFIG_TARGET_P1010RDB_PB)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800296 uint orig_bus = i2c_get_bus_num();
297 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800298
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800299 switch (ctrl_type) {
300 case MUX_TYPE_IFC:
301 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
302 clrbits_8(&tmp, 0x04);
303 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
304 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
305 clrbits_8(&tmp, 0x04);
306 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
307 sd_ifc_mux = MUX_TYPE_IFC;
308 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
309 break;
310 case MUX_TYPE_SDHC:
311 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
312 setbits_8(&tmp, 0x04);
313 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
314 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
315 clrbits_8(&tmp, 0x04);
316 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
317 sd_ifc_mux = MUX_TYPE_SDHC;
318 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
319 PMUXCR1_SDHC_ENABLE);
320 break;
321 case MUX_TYPE_SPIFLASH:
322 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
323 clrbits_8(&tmp, 0x80);
324 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
325 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
326 clrbits_8(&tmp, 0x80);
327 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
328 break;
329 case MUX_TYPE_TDM:
330 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
331 setbits_8(&tmp, 0x82);
332 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
333 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
334 clrbits_8(&tmp, 0x82);
335 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
336 break;
337 case MUX_TYPE_CAN:
338 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
339 clrbits_8(&tmp, 0x02);
340 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
341 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
342 clrbits_8(&tmp, 0x02);
343 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
344 break;
345 case MUX_TYPE_CS0_NOR:
346 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
347 clrbits_8(&tmp, 0x08);
348 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
349 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
350 clrbits_8(&tmp, 0x08);
351 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
352 break;
353 case MUX_TYPE_CS0_NAND:
354 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
355 setbits_8(&tmp, 0x08);
356 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
357 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
358 clrbits_8(&tmp, 0x08);
359 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
360 break;
361 default:
362 break;
363 }
364 i2c_set_bus_num(orig_bus);
365#endif
Biwen Li6a2d8d12020-05-01 20:04:13 +0800366#endif
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800367 return 0;
368}
369
York Sun7f945ca2016-11-16 13:30:06 -0800370#ifdef CONFIG_TARGET_P1010RDB_PB
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800371int i2c_pca9557_read(int type)
372{
373 u8 val;
Biwen Li6a2d8d12020-05-01 20:04:13 +0800374 int bus_num = I2C_PCA9557_BUS_NUM;
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800375
Biwen Li6a2d8d12020-05-01 20:04:13 +0800376#ifdef CONFIG_DM_I2C
377 struct udevice *dev;
378 int ret;
379
380 ret = i2c_get_chip_for_busnum(bus_num, I2C_PCA9557_ADDR2, 1, &dev);
381 if (ret) {
382 printf("%s: Cannot find udev for a bus %d\n",
383 __func__, bus_num);
384 return ret;
385 }
386 dm_i2c_read(dev, 0, &val, 1);
387#else
388 i2c_set_bus_num(bus_num);
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800389 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &val, 1);
Biwen Li6a2d8d12020-05-01 20:04:13 +0800390#endif
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800391
392 switch (type) {
393 case I2C_READ_BANK:
394 val = (val & 0x10) >> 4;
395 break;
396 case I2C_READ_PCB_VER:
397 val = ((val & 0x60) >> 5) + 1;
398 break;
399 default:
400 break;
401 }
402
403 return val;
404}
405#endif
406
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000407int checkboard(void)
408{
409 struct cpu_type *cpu;
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800410 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
411 u8 val;
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000412
Simon Glassa8b57392012-12-13 20:48:48 +0000413 cpu = gd->arch.cpu;
York Sun7f945ca2016-11-16 13:30:06 -0800414#if defined(CONFIG_TARGET_P1010RDB_PA)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800415 printf("Board: %sRDB-PA, ", cpu->name);
York Sun7f945ca2016-11-16 13:30:06 -0800416#elif defined(CONFIG_TARGET_P1010RDB_PB)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800417 printf("Board: %sRDB-PB, ", cpu->name);
Biwen Li6a2d8d12020-05-01 20:04:13 +0800418#ifdef CONFIG_DM_I2C
419 struct udevice *dev;
420 int ret;
421
422 ret = i2c_get_chip_for_busnum(I2C_PCA9557_BUS_NUM, I2C_PCA9557_ADDR2,
423 1, &dev);
424 if (ret) {
425 printf("%s: Cannot find udev for a bus %d\n", __func__,
426 I2C_PCA9557_BUS_NUM);
427 return ret;
428 }
429 val = 0x0; /* no polarity inversion */
430 dm_i2c_write(dev, 2, &val, 1);
431#else
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800432 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
433 i2c_init(CONFIG_SYS_FSL_I2C_SPEED, CONFIG_SYS_FSL_I2C_SLAVE);
434 val = 0x0; /* no polarity inversion */
435 i2c_write(I2C_PCA9557_ADDR2, 2, 1, &val, 1);
436#endif
Biwen Li6a2d8d12020-05-01 20:04:13 +0800437#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000438
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800439#ifdef CONFIG_SDCARD
440 /* switch to IFC to read info from CPLD */
441 config_board_mux(MUX_TYPE_IFC);
442#endif
443
York Sun7f945ca2016-11-16 13:30:06 -0800444#if defined(CONFIG_TARGET_P1010RDB_PA)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800445 val = (in_8(&cpld_data->pcba_ver) & 0xf);
446 printf("PCB: v%x.0\n", val);
York Sun7f945ca2016-11-16 13:30:06 -0800447#elif defined(CONFIG_TARGET_P1010RDB_PB)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800448 val = in_8(&cpld_data->cpld_ver);
449 printf("CPLD: v%x.%x, ", val >> 4, val & 0xf);
450 printf("PCB: v%x.0, ", i2c_pca9557_read(I2C_READ_PCB_VER));
451 val = in_8(&cpld_data->rom_loc) & 0xf;
452 puts("Boot from: ");
453 switch (val) {
454 case 0xf:
455 config_board_mux(MUX_TYPE_CS0_NOR);
456 printf("NOR vBank%d\n", i2c_pca9557_read(I2C_READ_BANK));
457 break;
458 case 0xe:
459 puts("SDHC\n");
460 val = 0x60; /* set pca9557 pin input/output */
Biwen Li6a2d8d12020-05-01 20:04:13 +0800461#ifdef CONFIG_DM_I2C
462 dm_i2c_write(dev, 3, &val, 1);
463#else
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800464 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &val, 1);
Biwen Li6a2d8d12020-05-01 20:04:13 +0800465#endif
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800466 break;
467 case 0x5:
468 config_board_mux(MUX_TYPE_IFC);
469 config_board_mux(MUX_TYPE_CS0_NAND);
470 puts("NAND\n");
471 break;
472 case 0x6:
473 config_board_mux(MUX_TYPE_IFC);
474 puts("SPI\n");
475 break;
476 default:
477 puts("unknown\n");
478 break;
479 }
480#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000481 return 0;
482}
483
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000484int board_eth_init(bd_t *bis)
485{
Bin Menge52fb1c2016-01-11 22:41:16 -0800486#ifdef CONFIG_TSEC_ENET
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000487 struct fsl_pq_mdio_info mdio_info;
488 struct tsec_info_struct tsec_info[4];
489 struct cpu_type *cpu;
490 int num = 0;
491
Simon Glassa8b57392012-12-13 20:48:48 +0000492 cpu = gd->arch.cpu;
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000493
494#ifdef CONFIG_TSEC1
495 SET_STD_TSEC_INFO(tsec_info[num], 1);
496 num++;
497#endif
498#ifdef CONFIG_TSEC2
499 SET_STD_TSEC_INFO(tsec_info[num], 2);
500 num++;
501#endif
502#ifdef CONFIG_TSEC3
503 /* P1014 and it's derivatives do not support eTSEC3 */
York Sun8cb65482012-07-06 17:10:33 -0500504 if (cpu->soc_ver != SVR_P1014) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000505 SET_STD_TSEC_INFO(tsec_info[num], 3);
506 num++;
507 }
508#endif
509 if (!num) {
510 printf("No TSECs initialized\n");
511 return 0;
512 }
513
514 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
515 mdio_info.name = DEFAULT_MII_NAME;
516
517 fsl_pq_mdio_init(bis, &mdio_info);
518
519 tsec_eth_init(bis, tsec_info, num);
Bin Menge52fb1c2016-01-11 22:41:16 -0800520#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000521
522 return pci_eth_init(bis);
523}
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000524
525#if defined(CONFIG_OF_BOARD_SETUP)
526void fdt_del_flexcan(void *blob)
527{
528 int nodeoff = 0;
529
530 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
Shengzhou Liua5b0ded2013-03-25 07:30:09 +0000531 "fsl,p1010-flexcan")) >= 0) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000532 fdt_del_node(blob, nodeoff);
533 }
534}
535
536void fdt_del_spi_flash(void *blob)
537{
538 int nodeoff = 0;
539
540 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
541 "spansion,s25sl12801")) >= 0) {
542 fdt_del_node(blob, nodeoff);
543 }
544}
545
546void fdt_del_spi_slic(void *blob)
547{
548 int nodeoff = 0;
549
550 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
551 "zarlink,le88266")) >= 0) {
552 fdt_del_node(blob, nodeoff);
553 }
554}
555
556void fdt_del_tdm(void *blob)
557{
558 int nodeoff = 0;
559
560 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
561 "fsl,starlite-tdm")) >= 0) {
562 fdt_del_node(blob, nodeoff);
563 }
564}
565
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000566void fdt_del_sdhc(void *blob)
567{
568 int nodeoff = 0;
569
570 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
571 "fsl,esdhc")) >= 0) {
572 fdt_del_node(blob, nodeoff);
573 }
574}
575
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800576void fdt_del_ifc(void *blob)
577{
578 int nodeoff = 0;
579
580 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
581 "fsl,ifc")) >= 0) {
582 fdt_del_node(blob, nodeoff);
583 }
584}
585
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000586void fdt_disable_uart1(void *blob)
587{
588 int nodeoff;
589
590 nodeoff = fdt_node_offset_by_compat_reg(blob, "fsl,ns16550",
591 CONFIG_SYS_NS16550_COM2);
592
593 if (nodeoff > 0) {
594 fdt_status_disabled(blob, nodeoff);
595 } else {
596 printf("WARNING unable to set status for fsl,ns16550 "
597 "uart1: %s\n", fdt_strerror(nodeoff));
598 }
599}
600
Simon Glass2aec3cc2014-10-23 18:58:47 -0600601int ft_board_setup(void *blob, bd_t *bd)
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000602{
603 phys_addr_t base;
604 phys_size_t size;
605 struct cpu_type *cpu;
606
Simon Glassa8b57392012-12-13 20:48:48 +0000607 cpu = gd->arch.cpu;
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000608
609 ft_cpu_setup(blob, bd);
610
Simon Glassda1a1342017-08-03 12:22:15 -0600611 base = env_get_bootm_low();
612 size = env_get_bootm_size();
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000613
614#if defined(CONFIG_PCI)
615 FT_FSL_PCI_SETUP;
616#endif
617
618 fdt_fixup_memory(blob, (u64)base, (u64)size);
619
Ramneek Mehresh59c48b42011-11-08 10:21:28 +0530620#if defined(CONFIG_HAS_FSL_DR_USB)
Sriram Dash9fd465c2016-09-16 17:12:15 +0530621 fsl_fdt_fixup_dr_usb(blob, bd);
Ramneek Mehresh59c48b42011-11-08 10:21:28 +0530622#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000623
624 /* P1014 and it's derivatives don't support CAN and eTSEC3 */
York Sun8cb65482012-07-06 17:10:33 -0500625 if (cpu->soc_ver == SVR_P1014) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000626 fdt_del_flexcan(blob);
627 fdt_del_node_and_alias(blob, "ethernet2");
628 }
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800629
630 /* Delete IFC node as IFC pins are multiplexing with SDHC */
631 if (sd_ifc_mux != MUX_TYPE_IFC)
632 fdt_del_ifc(blob);
633 else
634 fdt_del_sdhc(blob);
635
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000636 if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "can")) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000637 fdt_del_tdm(blob);
638 fdt_del_spi_slic(blob);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000639 } else if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "tdm")) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000640 fdt_del_flexcan(blob);
641 fdt_del_spi_flash(blob);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000642 fdt_disable_uart1(blob);
643 } else {
644 /*
645 * If we don't set fsl_p1010mux:tdm_can to "can" or "tdm"
646 * explicitly, defaultly spi_cs_sel to spi-flash instead of
647 * to tdm/slic.
648 */
649 fdt_del_tdm(blob);
650 fdt_del_flexcan(blob);
651 fdt_disable_uart1(blob);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000652 }
Simon Glass2aec3cc2014-10-23 18:58:47 -0600653
654 return 0;
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800655}
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000656#endif
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800657
658#ifdef CONFIG_SDCARD
659int board_mmc_init(bd_t *bis)
660{
661 config_board_mux(MUX_TYPE_SDHC);
662 return -1;
663}
664#else
665void board_reset(void)
666{
667 /* mux to IFC to enable CPLD for reset */
668 if (sd_ifc_mux != MUX_TYPE_IFC)
669 config_board_mux(MUX_TYPE_IFC);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000670}
671#endif
672
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800673
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000674int misc_init_r(void)
675{
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000676 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
677
678 if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "can")) {
679 clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN1_TDM |
680 MPC85xx_PMUXCR_CAN1_UART |
681 MPC85xx_PMUXCR_CAN2_TDM |
682 MPC85xx_PMUXCR_CAN2_UART);
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800683 config_board_mux(MUX_TYPE_CAN);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000684 } else if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "tdm")) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000685 clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN2_UART |
686 MPC85xx_PMUXCR_CAN1_UART);
687 setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN2_TDM |
688 MPC85xx_PMUXCR_CAN1_TDM);
689 clrbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_UART_GPIO);
690 setbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_UART_TDM);
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800691 config_board_mux(MUX_TYPE_TDM);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000692 } else {
693 /* defaultly spi_cs_sel to flash */
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800694 config_board_mux(MUX_TYPE_SPIFLASH);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000695 }
696
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800697 if (hwconfig("esdhc"))
698 config_board_mux(MUX_TYPE_SDHC);
699 else if (hwconfig("ifc"))
700 config_board_mux(MUX_TYPE_IFC);
701
York Sun7f945ca2016-11-16 13:30:06 -0800702#ifdef CONFIG_TARGET_P1010RDB_PB
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800703 setbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_GPIO01_DRVVBUS);
704#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000705 return 0;
706}
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800707
Tom Rini9774e322018-01-03 09:13:04 -0500708#ifndef CONFIG_SPL_BUILD
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800709static int pin_mux_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
710 char * const argv[])
711{
712 if (argc < 2)
713 return CMD_RET_USAGE;
714 if (strcmp(argv[1], "ifc") == 0)
715 config_board_mux(MUX_TYPE_IFC);
716 else if (strcmp(argv[1], "sdhc") == 0)
717 config_board_mux(MUX_TYPE_SDHC);
718 else
719 return CMD_RET_USAGE;
720 return 0;
721}
722
723U_BOOT_CMD(
724 mux, 2, 0, pin_mux_cmd,
725 "configure multiplexing pin for IFC/SDHC bus in runtime",
726 "bus_type (e.g. mux sdhc)"
727);
Tom Rini9774e322018-01-03 09:13:04 -0500728#endif