blob: 90436337df113569db3ee50f16e862692a07a605 [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 Glassed38aef2020-05-10 11:40:03 -06008#include <command.h>
Simon Glass2dc9c342020-05-10 11:40:01 -06009#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -070010#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060011#include <net.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000013#include <asm/processor.h>
14#include <asm/mmu.h>
15#include <asm/cache.h>
16#include <asm/immap_85xx.h>
17#include <asm/io.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -060018#include <env.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000019#include <miiphy.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090020#include <linux/libfdt.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000021#include <fdt_support.h>
22#include <fsl_mdio.h>
23#include <tsec.h>
24#include <mmc.h>
25#include <netdev.h>
26#include <pci.h>
27#include <asm/fsl_serdes.h>
York Sun37562f62013-10-22 12:39:02 -070028#include <fsl_ifc.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000029#include <asm/fsl_pci.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000030#include <hwconfig.h>
Shengzhou Liu36446ef2013-09-13 14:46:02 +080031#include <i2c.h>
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000032
33DECLARE_GLOBAL_DATA_PTR;
34
35#define GPIO4_PCIE_RESET_SET 0x08000000
36#define MUX_CPLD_CAN_UART 0x00
37#define MUX_CPLD_TDM 0x01
38#define MUX_CPLD_SPICS0_FLASH 0x00
39#define MUX_CPLD_SPICS0_SLIC 0x02
Shengzhou Liu36446ef2013-09-13 14:46:02 +080040#define PMUXCR1_IFC_MASK 0x00ffff00
41#define PMUXCR1_SDHC_MASK 0x00fff000
42#define PMUXCR1_SDHC_ENABLE 0x00555000
43
44enum {
45 MUX_TYPE_IFC,
46 MUX_TYPE_SDHC,
Shengzhou Liuf0af4382013-09-13 14:46:03 +080047 MUX_TYPE_SPIFLASH,
48 MUX_TYPE_TDM,
49 MUX_TYPE_CAN,
50 MUX_TYPE_CS0_NOR,
51 MUX_TYPE_CS0_NAND,
Shengzhou Liu36446ef2013-09-13 14:46:02 +080052};
53
Shengzhou Liuf0af4382013-09-13 14:46:03 +080054enum {
55 I2C_READ_BANK,
56 I2C_READ_PCB_VER,
57};
58
Shengzhou Liu36446ef2013-09-13 14:46:02 +080059static uint sd_ifc_mux;
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000060
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000061struct cpld_data {
62 u8 cpld_ver; /* cpld revision */
York Sun7f945ca2016-11-16 13:30:06 -080063#if defined(CONFIG_TARGET_P1010RDB_PA)
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000064 u8 pcba_ver; /* pcb revision number */
65 u8 twindie_ddr3;
66 u8 res1[6];
67 u8 bank_sel; /* NOR Flash bank */
68 u8 res2[5];
69 u8 usb2_sel;
70 u8 res3[1];
71 u8 porsw_sel;
72 u8 tdm_can_sel;
73 u8 spi_cs0_sel; /* SPI CS0 SLIC/SPI Flash */
74 u8 por0; /* POR Options */
75 u8 por1; /* POR Options */
76 u8 por2; /* POR Options */
77 u8 por3; /* POR Options */
York Sun7f945ca2016-11-16 13:30:06 -080078#elif defined(CONFIG_TARGET_P1010RDB_PB)
Shengzhou Liuf0af4382013-09-13 14:46:03 +080079 u8 rom_loc;
80#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000081};
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000082
83int board_early_init_f(void)
84{
85 ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
Jaiprakash Singhdd888062015-03-20 19:28:27 -070086 struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000087 /* Clock configuration to access CPLD using IFC(GPCM) */
Jaiprakash Singhdd888062015-03-20 19:28:27 -070088 setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +000089 /*
90 * Reset PCIe slots via GPIO4
91 */
92 setbits_be32(&pgpio->gpdir, GPIO4_PCIE_RESET_SET);
93 setbits_be32(&pgpio->gpdat, GPIO4_PCIE_RESET_SET);
94
95 return 0;
96}
97
98int board_early_init_r(void)
99{
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000100 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -0700101 int flash_esel = find_tlb_idx((void *)flashbase, 1);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000102
103 /*
104 * Remap Boot flash region to caching-inhibited
105 * so that flash can be erased properly.
106 */
107
108 /* Flush d-cache and invalidate i-cache of any FLASH data */
109 flush_dcache();
110 invalidate_icache();
111
York Sun220c3462014-06-24 21:16:20 -0700112 if (flash_esel == -1) {
113 /* very unlikely unless something is messed up */
114 puts("Error: Could not find TLB for FLASH BASE\n");
115 flash_esel = 2; /* give our best effort to continue */
116 } else {
117 /* invalidate existing TLB entry for flash */
118 disable_tlb(flash_esel);
119 }
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000120
121 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
122 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
123 0, flash_esel, BOOKE_PAGESZ_16M, 1);
124
125 set_tlb(1, flashbase + 0x1000000,
126 CONFIG_SYS_FLASH_BASE_PHYS + 0x1000000,
127 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
128 0, flash_esel+1, BOOKE_PAGESZ_16M, 1);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000129 return 0;
130}
131
Hou Zhiqiang0e49eb42020-05-01 19:06:27 +0800132#if defined(CONFIG_PCI) && !defined(CONFIG_DM_PCI)
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000133void pci_init_board(void)
134{
135 fsl_pcie_init_board(0);
136}
137#endif /* ifdef CONFIG_PCI */
138
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800139int config_board_mux(int ctrl_type)
140{
141 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
142 u8 tmp;
143
Igor Opaniukf7c91762021-02-09 13:52:45 +0200144#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Li6a2d8d12020-05-01 20:04:13 +0800145 struct udevice *dev;
146 int ret;
York Sun7f945ca2016-11-16 13:30:06 -0800147#if defined(CONFIG_TARGET_P1010RDB_PA)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800148 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
149
Biwen Li6a2d8d12020-05-01 20:04:13 +0800150 ret = i2c_get_chip_for_busnum(I2C_PCA9557_BUS_NUM,
151 I2C_PCA9557_ADDR1, 1, &dev);
152 if (ret) {
153 printf("%s: Cannot find udev for a bus %d\n",
154 __func__, I2C_PCA9557_BUS_NUM);
155 return ret;
156 }
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800157 switch (ctrl_type) {
158 case MUX_TYPE_IFC:
Biwen Li6a2d8d12020-05-01 20:04:13 +0800159 tmp = 0xf0;
160 dm_i2c_write(dev, 3, &tmp, 1);
161 tmp = 0x01;
162 dm_i2c_write(dev, 1, &tmp, 1);
163 sd_ifc_mux = MUX_TYPE_IFC;
164 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
165 break;
166 case MUX_TYPE_SDHC:
167 tmp = 0xf0;
168 dm_i2c_write(dev, 3, &tmp, 1);
169 tmp = 0x05;
170 dm_i2c_write(dev, 1, &tmp, 1);
171 sd_ifc_mux = MUX_TYPE_SDHC;
172 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
173 PMUXCR1_SDHC_ENABLE);
174 break;
175 case MUX_TYPE_SPIFLASH:
176 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_FLASH);
177 break;
178 case MUX_TYPE_TDM:
179 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_TDM);
180 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_SLIC);
181 break;
182 case MUX_TYPE_CAN:
183 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_CAN_UART);
184 break;
185 default:
186 break;
187 }
188#elif defined(CONFIG_TARGET_P1010RDB_PB)
189 ret = i2c_get_chip_for_busnum(I2C_PCA9557_BUS_NUM,
190 I2C_PCA9557_ADDR2, 1, &dev);
191 if (ret) {
192 printf("%s: Cannot find udev for a bus %d\n",
193 __func__, I2C_PCA9557_BUS_NUM);
194 return ret;
195 }
196 switch (ctrl_type) {
197 case MUX_TYPE_IFC:
198 dm_i2c_read(dev, 0, &tmp, 1);
199 clrbits_8(&tmp, 0x04);
200 dm_i2c_write(dev, 1, &tmp, 1);
201 dm_i2c_read(dev, 3, &tmp, 1);
202 clrbits_8(&tmp, 0x04);
203 dm_i2c_write(dev, 3, &tmp, 1);
204 sd_ifc_mux = MUX_TYPE_IFC;
205 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
206 break;
207 case MUX_TYPE_SDHC:
208 dm_i2c_read(dev, 0, &tmp, 1);
209 setbits_8(&tmp, 0x04);
210 dm_i2c_write(dev, 1, &tmp, 1);
211 dm_i2c_read(dev, 3, &tmp, 1);
212 clrbits_8(&tmp, 0x04);
213 dm_i2c_write(dev, 3, &tmp, 1);
214 sd_ifc_mux = MUX_TYPE_SDHC;
215 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
216 PMUXCR1_SDHC_ENABLE);
217 break;
218 case MUX_TYPE_SPIFLASH:
219 dm_i2c_read(dev, 0, &tmp, 1);
220 clrbits_8(&tmp, 0x80);
221 dm_i2c_write(dev, 1, &tmp, 1);
222 dm_i2c_read(dev, 3, &tmp, 1);
223 clrbits_8(&tmp, 0x80);
224 dm_i2c_write(dev, 3, &tmp, 1);
225 break;
226 case MUX_TYPE_TDM:
227 dm_i2c_read(dev, 0, &tmp, 1);
228 setbits_8(&tmp, 0x82);
229 dm_i2c_write(dev, 1, &tmp, 1);
230 dm_i2c_read(dev, 3, &tmp, 1);
231 clrbits_8(&tmp, 0x82);
232 dm_i2c_write(dev, 3, &tmp, 1);
233 break;
234 case MUX_TYPE_CAN:
235 dm_i2c_read(dev, 0, &tmp, 1);
236 clrbits_8(&tmp, 0x02);
237 dm_i2c_write(dev, 1, &tmp, 1);
238 dm_i2c_read(dev, 3, &tmp, 1);
239 clrbits_8(&tmp, 0x02);
240 dm_i2c_write(dev, 3, &tmp, 1);
241 break;
242 case MUX_TYPE_CS0_NOR:
243 dm_i2c_read(dev, 0, &tmp, 1);
244 clrbits_8(&tmp, 0x08);
245 dm_i2c_write(dev, 1, &tmp, 1);
246 dm_i2c_read(dev, 3, &tmp, 1);
247 clrbits_8(&tmp, 0x08);
248 dm_i2c_write(dev, 3, &tmp, 1);
249 break;
250 case MUX_TYPE_CS0_NAND:
251 dm_i2c_read(dev, 0, &tmp, 1);
252 setbits_8(&tmp, 0x08);
253 dm_i2c_write(dev, 1, &tmp, 1);
254 dm_i2c_read(dev, 3, &tmp, 1);
255 clrbits_8(&tmp, 0x08);
256 dm_i2c_write(dev, 3, &tmp, 1);
257 break;
258 default:
259 break;
260 }
261#endif
262#else
263#if defined(CONFIG_TARGET_P1010RDB_PA)
264 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
265
266 switch (ctrl_type) {
267 case MUX_TYPE_IFC:
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800268 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
269 tmp = 0xf0;
270 i2c_write(I2C_PCA9557_ADDR1, 3, 1, &tmp, 1);
271 tmp = 0x01;
272 i2c_write(I2C_PCA9557_ADDR1, 1, 1, &tmp, 1);
273 sd_ifc_mux = MUX_TYPE_IFC;
274 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
275 break;
276 case MUX_TYPE_SDHC:
277 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
278 tmp = 0xf0;
279 i2c_write(I2C_PCA9557_ADDR1, 3, 1, &tmp, 1);
280 tmp = 0x05;
281 i2c_write(I2C_PCA9557_ADDR1, 1, 1, &tmp, 1);
282 sd_ifc_mux = MUX_TYPE_SDHC;
283 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
284 PMUXCR1_SDHC_ENABLE);
285 break;
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800286 case MUX_TYPE_SPIFLASH:
287 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_FLASH);
288 break;
289 case MUX_TYPE_TDM:
290 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_TDM);
291 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_SLIC);
292 break;
293 case MUX_TYPE_CAN:
294 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_CAN_UART);
295 break;
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800296 default:
297 break;
298 }
York Sun7f945ca2016-11-16 13:30:06 -0800299#elif defined(CONFIG_TARGET_P1010RDB_PB)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800300 uint orig_bus = i2c_get_bus_num();
301 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800302
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800303 switch (ctrl_type) {
304 case MUX_TYPE_IFC:
305 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
306 clrbits_8(&tmp, 0x04);
307 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
308 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
309 clrbits_8(&tmp, 0x04);
310 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
311 sd_ifc_mux = MUX_TYPE_IFC;
312 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
313 break;
314 case MUX_TYPE_SDHC:
315 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
316 setbits_8(&tmp, 0x04);
317 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
318 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
319 clrbits_8(&tmp, 0x04);
320 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
321 sd_ifc_mux = MUX_TYPE_SDHC;
322 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
323 PMUXCR1_SDHC_ENABLE);
324 break;
325 case MUX_TYPE_SPIFLASH:
326 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
327 clrbits_8(&tmp, 0x80);
328 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
329 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
330 clrbits_8(&tmp, 0x80);
331 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
332 break;
333 case MUX_TYPE_TDM:
334 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
335 setbits_8(&tmp, 0x82);
336 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
337 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
338 clrbits_8(&tmp, 0x82);
339 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
340 break;
341 case MUX_TYPE_CAN:
342 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
343 clrbits_8(&tmp, 0x02);
344 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
345 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
346 clrbits_8(&tmp, 0x02);
347 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
348 break;
349 case MUX_TYPE_CS0_NOR:
350 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
351 clrbits_8(&tmp, 0x08);
352 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
353 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
354 clrbits_8(&tmp, 0x08);
355 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
356 break;
357 case MUX_TYPE_CS0_NAND:
358 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
359 setbits_8(&tmp, 0x08);
360 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
361 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
362 clrbits_8(&tmp, 0x08);
363 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
364 break;
365 default:
366 break;
367 }
368 i2c_set_bus_num(orig_bus);
369#endif
Biwen Li6a2d8d12020-05-01 20:04:13 +0800370#endif
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800371 return 0;
372}
373
York Sun7f945ca2016-11-16 13:30:06 -0800374#ifdef CONFIG_TARGET_P1010RDB_PB
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800375int i2c_pca9557_read(int type)
376{
377 u8 val;
Biwen Li6a2d8d12020-05-01 20:04:13 +0800378 int bus_num = I2C_PCA9557_BUS_NUM;
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800379
Igor Opaniukf7c91762021-02-09 13:52:45 +0200380#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Li6a2d8d12020-05-01 20:04:13 +0800381 struct udevice *dev;
382 int ret;
383
384 ret = i2c_get_chip_for_busnum(bus_num, I2C_PCA9557_ADDR2, 1, &dev);
385 if (ret) {
386 printf("%s: Cannot find udev for a bus %d\n",
387 __func__, bus_num);
388 return ret;
389 }
390 dm_i2c_read(dev, 0, &val, 1);
391#else
392 i2c_set_bus_num(bus_num);
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800393 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &val, 1);
Biwen Li6a2d8d12020-05-01 20:04:13 +0800394#endif
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800395
396 switch (type) {
397 case I2C_READ_BANK:
398 val = (val & 0x10) >> 4;
399 break;
400 case I2C_READ_PCB_VER:
401 val = ((val & 0x60) >> 5) + 1;
402 break;
403 default:
404 break;
405 }
406
407 return val;
408}
409#endif
410
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000411int checkboard(void)
412{
413 struct cpu_type *cpu;
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800414 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
415 u8 val;
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000416
Simon Glassa8b57392012-12-13 20:48:48 +0000417 cpu = gd->arch.cpu;
York Sun7f945ca2016-11-16 13:30:06 -0800418#if defined(CONFIG_TARGET_P1010RDB_PA)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800419 printf("Board: %sRDB-PA, ", cpu->name);
York Sun7f945ca2016-11-16 13:30:06 -0800420#elif defined(CONFIG_TARGET_P1010RDB_PB)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800421 printf("Board: %sRDB-PB, ", cpu->name);
Igor Opaniukf7c91762021-02-09 13:52:45 +0200422#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Li6a2d8d12020-05-01 20:04:13 +0800423 struct udevice *dev;
424 int ret;
425
426 ret = i2c_get_chip_for_busnum(I2C_PCA9557_BUS_NUM, I2C_PCA9557_ADDR2,
427 1, &dev);
428 if (ret) {
429 printf("%s: Cannot find udev for a bus %d\n", __func__,
430 I2C_PCA9557_BUS_NUM);
431 return ret;
432 }
433 val = 0x0; /* no polarity inversion */
434 dm_i2c_write(dev, 2, &val, 1);
435#else
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800436 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
437 i2c_init(CONFIG_SYS_FSL_I2C_SPEED, CONFIG_SYS_FSL_I2C_SLAVE);
438 val = 0x0; /* no polarity inversion */
439 i2c_write(I2C_PCA9557_ADDR2, 2, 1, &val, 1);
440#endif
Biwen Li6a2d8d12020-05-01 20:04:13 +0800441#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000442
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800443#ifdef CONFIG_SDCARD
444 /* switch to IFC to read info from CPLD */
445 config_board_mux(MUX_TYPE_IFC);
446#endif
447
York Sun7f945ca2016-11-16 13:30:06 -0800448#if defined(CONFIG_TARGET_P1010RDB_PA)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800449 val = (in_8(&cpld_data->pcba_ver) & 0xf);
450 printf("PCB: v%x.0\n", val);
York Sun7f945ca2016-11-16 13:30:06 -0800451#elif defined(CONFIG_TARGET_P1010RDB_PB)
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800452 val = in_8(&cpld_data->cpld_ver);
453 printf("CPLD: v%x.%x, ", val >> 4, val & 0xf);
454 printf("PCB: v%x.0, ", i2c_pca9557_read(I2C_READ_PCB_VER));
455 val = in_8(&cpld_data->rom_loc) & 0xf;
456 puts("Boot from: ");
457 switch (val) {
458 case 0xf:
459 config_board_mux(MUX_TYPE_CS0_NOR);
460 printf("NOR vBank%d\n", i2c_pca9557_read(I2C_READ_BANK));
461 break;
462 case 0xe:
463 puts("SDHC\n");
464 val = 0x60; /* set pca9557 pin input/output */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200465#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Li6a2d8d12020-05-01 20:04:13 +0800466 dm_i2c_write(dev, 3, &val, 1);
467#else
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800468 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &val, 1);
Biwen Li6a2d8d12020-05-01 20:04:13 +0800469#endif
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800470 break;
471 case 0x5:
472 config_board_mux(MUX_TYPE_IFC);
473 config_board_mux(MUX_TYPE_CS0_NAND);
474 puts("NAND\n");
475 break;
476 case 0x6:
477 config_board_mux(MUX_TYPE_IFC);
478 puts("SPI\n");
479 break;
480 default:
481 puts("unknown\n");
482 break;
483 }
484#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000485 return 0;
486}
487
Hou Zhiqiang7a6855f2020-09-21 15:15:04 +0530488#ifndef CONFIG_DM_ETH
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900489int board_eth_init(struct bd_info *bis)
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000490{
Bin Menge52fb1c2016-01-11 22:41:16 -0800491#ifdef CONFIG_TSEC_ENET
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000492 struct fsl_pq_mdio_info mdio_info;
493 struct tsec_info_struct tsec_info[4];
494 struct cpu_type *cpu;
495 int num = 0;
496
Simon Glassa8b57392012-12-13 20:48:48 +0000497 cpu = gd->arch.cpu;
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000498
499#ifdef CONFIG_TSEC1
500 SET_STD_TSEC_INFO(tsec_info[num], 1);
501 num++;
502#endif
503#ifdef CONFIG_TSEC2
504 SET_STD_TSEC_INFO(tsec_info[num], 2);
505 num++;
506#endif
507#ifdef CONFIG_TSEC3
508 /* P1014 and it's derivatives do not support eTSEC3 */
York Sun8cb65482012-07-06 17:10:33 -0500509 if (cpu->soc_ver != SVR_P1014) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000510 SET_STD_TSEC_INFO(tsec_info[num], 3);
511 num++;
512 }
513#endif
514 if (!num) {
515 printf("No TSECs initialized\n");
516 return 0;
517 }
518
519 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
520 mdio_info.name = DEFAULT_MII_NAME;
521
522 fsl_pq_mdio_init(bis, &mdio_info);
523
524 tsec_eth_init(bis, tsec_info, num);
Bin Menge52fb1c2016-01-11 22:41:16 -0800525#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000526
527 return pci_eth_init(bis);
528}
Hou Zhiqiang7a6855f2020-09-21 15:15:04 +0530529#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000530
531#if defined(CONFIG_OF_BOARD_SETUP)
532void fdt_del_flexcan(void *blob)
533{
534 int nodeoff = 0;
535
536 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
Shengzhou Liua5b0ded2013-03-25 07:30:09 +0000537 "fsl,p1010-flexcan")) >= 0) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000538 fdt_del_node(blob, nodeoff);
539 }
540}
541
542void fdt_del_spi_flash(void *blob)
543{
544 int nodeoff = 0;
545
546 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
547 "spansion,s25sl12801")) >= 0) {
548 fdt_del_node(blob, nodeoff);
549 }
550}
551
552void fdt_del_spi_slic(void *blob)
553{
554 int nodeoff = 0;
555
556 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
557 "zarlink,le88266")) >= 0) {
558 fdt_del_node(blob, nodeoff);
559 }
560}
561
562void fdt_del_tdm(void *blob)
563{
564 int nodeoff = 0;
565
566 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
567 "fsl,starlite-tdm")) >= 0) {
568 fdt_del_node(blob, nodeoff);
569 }
570}
571
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000572void fdt_del_sdhc(void *blob)
573{
574 int nodeoff = 0;
575
576 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
577 "fsl,esdhc")) >= 0) {
578 fdt_del_node(blob, nodeoff);
579 }
580}
581
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800582void fdt_del_ifc(void *blob)
583{
584 int nodeoff = 0;
585
586 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
587 "fsl,ifc")) >= 0) {
588 fdt_del_node(blob, nodeoff);
589 }
590}
591
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000592void fdt_disable_uart1(void *blob)
593{
594 int nodeoff;
595
596 nodeoff = fdt_node_offset_by_compat_reg(blob, "fsl,ns16550",
597 CONFIG_SYS_NS16550_COM2);
598
599 if (nodeoff > 0) {
600 fdt_status_disabled(blob, nodeoff);
601 } else {
602 printf("WARNING unable to set status for fsl,ns16550 "
603 "uart1: %s\n", fdt_strerror(nodeoff));
604 }
605}
606
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900607int ft_board_setup(void *blob, struct bd_info *bd)
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000608{
609 phys_addr_t base;
610 phys_size_t size;
611 struct cpu_type *cpu;
612
Simon Glassa8b57392012-12-13 20:48:48 +0000613 cpu = gd->arch.cpu;
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000614
615 ft_cpu_setup(blob, bd);
616
Simon Glassda1a1342017-08-03 12:22:15 -0600617 base = env_get_bootm_low();
618 size = env_get_bootm_size();
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000619
Hou Zhiqiang0e49eb42020-05-01 19:06:27 +0800620#if defined(CONFIG_PCI) && !defined(CONFIG_DM_PCI)
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000621 FT_FSL_PCI_SETUP;
622#endif
623
624 fdt_fixup_memory(blob, (u64)base, (u64)size);
625
Ramneek Mehresh59c48b42011-11-08 10:21:28 +0530626#if defined(CONFIG_HAS_FSL_DR_USB)
Sriram Dash9fd465c2016-09-16 17:12:15 +0530627 fsl_fdt_fixup_dr_usb(blob, bd);
Ramneek Mehresh59c48b42011-11-08 10:21:28 +0530628#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000629
630 /* P1014 and it's derivatives don't support CAN and eTSEC3 */
York Sun8cb65482012-07-06 17:10:33 -0500631 if (cpu->soc_ver == SVR_P1014) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000632 fdt_del_flexcan(blob);
633 fdt_del_node_and_alias(blob, "ethernet2");
634 }
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800635
636 /* Delete IFC node as IFC pins are multiplexing with SDHC */
637 if (sd_ifc_mux != MUX_TYPE_IFC)
638 fdt_del_ifc(blob);
639 else
640 fdt_del_sdhc(blob);
641
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000642 if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "can")) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000643 fdt_del_tdm(blob);
644 fdt_del_spi_slic(blob);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000645 } else if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "tdm")) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000646 fdt_del_flexcan(blob);
647 fdt_del_spi_flash(blob);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000648 fdt_disable_uart1(blob);
649 } else {
650 /*
651 * If we don't set fsl_p1010mux:tdm_can to "can" or "tdm"
652 * explicitly, defaultly spi_cs_sel to spi-flash instead of
653 * to tdm/slic.
654 */
655 fdt_del_tdm(blob);
656 fdt_del_flexcan(blob);
657 fdt_disable_uart1(blob);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000658 }
Simon Glass2aec3cc2014-10-23 18:58:47 -0600659
660 return 0;
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800661}
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000662#endif
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800663
664#ifdef CONFIG_SDCARD
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900665int board_mmc_init(struct bd_info *bis)
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800666{
667 config_board_mux(MUX_TYPE_SDHC);
668 return -1;
669}
670#else
671void board_reset(void)
672{
673 /* mux to IFC to enable CPLD for reset */
674 if (sd_ifc_mux != MUX_TYPE_IFC)
675 config_board_mux(MUX_TYPE_IFC);
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000676}
677#endif
678
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800679
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000680int misc_init_r(void)
681{
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000682 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
683
684 if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "can")) {
685 clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN1_TDM |
686 MPC85xx_PMUXCR_CAN1_UART |
687 MPC85xx_PMUXCR_CAN2_TDM |
688 MPC85xx_PMUXCR_CAN2_UART);
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800689 config_board_mux(MUX_TYPE_CAN);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000690 } else if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "tdm")) {
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000691 clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN2_UART |
692 MPC85xx_PMUXCR_CAN1_UART);
693 setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN2_TDM |
694 MPC85xx_PMUXCR_CAN1_TDM);
695 clrbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_UART_GPIO);
696 setbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_UART_TDM);
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800697 config_board_mux(MUX_TYPE_TDM);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000698 } else {
699 /* defaultly spi_cs_sel to flash */
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800700 config_board_mux(MUX_TYPE_SPIFLASH);
Shengzhou Liuceb705c2012-04-25 23:43:24 +0000701 }
702
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800703 if (hwconfig("esdhc"))
704 config_board_mux(MUX_TYPE_SDHC);
705 else if (hwconfig("ifc"))
706 config_board_mux(MUX_TYPE_IFC);
707
York Sun7f945ca2016-11-16 13:30:06 -0800708#ifdef CONFIG_TARGET_P1010RDB_PB
Shengzhou Liuf0af4382013-09-13 14:46:03 +0800709 setbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_GPIO01_DRVVBUS);
710#endif
Poonam Aggrwala2ec1352011-02-09 19:17:53 +0000711 return 0;
712}
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800713
Tom Rini9774e322018-01-03 09:13:04 -0500714#ifndef CONFIG_SPL_BUILD
Simon Glassed38aef2020-05-10 11:40:03 -0600715static int pin_mux_cmd(struct cmd_tbl *cmdtp, int flag, int argc,
716 char *const argv[])
Shengzhou Liu36446ef2013-09-13 14:46:02 +0800717{
718 if (argc < 2)
719 return CMD_RET_USAGE;
720 if (strcmp(argv[1], "ifc") == 0)
721 config_board_mux(MUX_TYPE_IFC);
722 else if (strcmp(argv[1], "sdhc") == 0)
723 config_board_mux(MUX_TYPE_SDHC);
724 else
725 return CMD_RET_USAGE;
726 return 0;
727}
728
729U_BOOT_CMD(
730 mux, 2, 0, pin_mux_cmd,
731 "configure multiplexing pin for IFC/SDHC bus in runtime",
732 "bus_type (e.g. mux sdhc)"
733);
Tom Rini9774e322018-01-03 09:13:04 -0500734#endif