1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2013-2019 Arcturus Networks, Inc.
4 * https://www.arcturusnetworks.com/products/ucp1020/
5 * by Oleksandr G Zhadan et al.
6 * based on board/freescale/p1_p2_rdb_pc/spl.c
7 * original copyright follows:
8 * Copyright 2013 Freescale Semiconductor, Inc.
17 #include <linux/libfdt.h>
18 #include <fdt_support.h>
24 #include <spi_flash.h>
26 #include <linux/ctype.h>
27 #include <asm/fsl_serdes.h>
29 #include <asm/processor.h>
31 #include <asm/cache.h>
32 #include <asm/immap_85xx.h>
33 #include <asm/fsl_pci.h>
34 #include <fsl_ddr_sdram.h>
36 #include <asm/fsl_law.h>
37 #include <asm/fsl_lbc.h>
41 void spi_set_speed(struct spi_slave *slave, uint hz)
43 /* TO DO: It's actially have to be in spi/ */
47 * To be compatible with cmd_gpio
49 int name_to_gpio(const char *name)
51 int gpio = 31 - simple_strtoul(name, NULL, 10);
59 void board_gpio_init(void)
62 char envname[8], *val;
64 for (i = 0; i < GPIO_MAX_NUM; i++) {
65 sprintf(envname, "GPIO%d", i);
66 val = env_get(envname);
68 char direction = toupper(val[0]);
69 char level = toupper(val[1]);
71 if (direction == 'I') {
72 gpio_direction_input(i);
74 if (direction == 'O') {
76 gpio_direction_output(i, 1);
78 gpio_direction_output(i, 0);
84 val = env_get("PCIE_OFF");
86 gpio_direction_input(GPIO_PCIE1_EN);
87 gpio_direction_input(GPIO_PCIE2_EN);
89 gpio_direction_output(GPIO_PCIE1_EN, 1);
90 gpio_direction_output(GPIO_PCIE2_EN, 1);
93 val = env_get("SDHC_CDWP_OFF");
95 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
97 setbits_be32(&gur->pmuxcr,
98 (MPC85xx_PMUXCR_SDHC_CD | MPC85xx_PMUXCR_SDHC_WP));
102 int board_early_init_f(void)
104 return 0; /* Just in case. Could be disable in config file */
109 printf("Board: %s\n", CONFIG_BOARDNAME_LOCAL);
112 printf("SD/MMC: 4-bit Mode\n");
119 void pci_init_board(void)
121 fsl_pcie_init_board(0);
125 int board_early_init_r(void)
127 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
128 const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
131 * Remap Boot flash region to caching-inhibited
132 * so that flash can be erased properly.
135 /* Flush d-cache and invalidate i-cache of any FLASH data */
139 /* invalidate existing TLB entry for flash */
140 disable_tlb(flash_esel);
142 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, /* tlb, epn, rpn */
143 MAS3_SX | MAS3_SW | MAS3_SR, MAS2_I | MAS2_G, /* perms, wimge */
144 0, flash_esel, BOOKE_PAGESZ_64M, 1);/* ts, esel, tsize, iprot */
149 int board_phy_config(struct phy_device *phydev)
151 #if defined(CONFIG_PHY_MICREL_KSZ9021)
156 printf("PHYs address [");
158 if (phydev->addr == TSEC1_PHY_ADDR || phydev->addr == TSEC3_PHY_ADDR) {
160 ksz9021_phy_extended_read(phydev,
161 MII_KSZ9021_EXT_STRAP_STATUS);
165 ksz9021_phy_extended_write(phydev,
166 MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW,
169 * max rx/tx clock delay, min rx/tx control
171 ksz9021_phy_extended_write(phydev,
172 MII_KSZ9021_EXT_RGMII_CLOCK_SKEW,
174 printf("0x%x", (regval & 0x1f));
176 printf("0x%x", (TSEC2_PHY_ADDR & 0x1f));
184 #if defined(CONFIG_PHY_MICREL_KSZ9031_DEBUG)
185 regval = ksz9031_phy_extended_read(phydev, 2, 0x01, 0x4000);
187 printf(" (ADDR 0x%x) ", regval & 0x1f);
193 int last_stage_init(void)
195 static char newkernelargs[256];
203 if (i2c_read(CONFIG_SYS_I2C_IDT6V49205B, 7, 1, &id1[0], 2) < 0) {
204 printf("Error reading i2c IDT6V49205B information!\n");
206 printf("IDT6V49205B(0x%02x): ready\n", id1[1]);
207 i2c_read(CONFIG_SYS_I2C_IDT6V49205B, 4, 1, &id1[0], 2);
208 if (!(id1[1] & 0x02)) {
210 i2c_write(CONFIG_SYS_I2C_IDT6V49205B, 4, 1, &id1[0], 2);
215 if (i2c_read(CONFIG_SYS_I2C_NCT72_ADDR, 0xFE, 1, &id2, 1) < 0)
216 printf("Error reading i2c NCT72 information!\n");
218 printf("NCT72(0x%x): ready\n", id2);
220 kval = env_get("kernelargs");
223 mmc = find_mmc_device(0);
225 if (!mmc_init(mmc)) {
226 printf("MMC/SD card detected\n");
228 int n = strlen(defkargs);
229 char *tmp = strstr(kval, defkargs);
232 strcpy(newkernelargs, kval);
233 strcat(newkernelargs, " ");
234 strcat(newkernelargs, mmckargs);
235 strcat(newkernelargs, " ");
236 strcat(newkernelargs, &tmp[n]);
237 env_set("kernelargs", newkernelargs);
239 env_set("kernelargs", mmckargs);
246 sval = env_get("SERIAL");
248 strcpy(newkernelargs, "SN=");
249 strcat(newkernelargs, sval);
250 strcat(newkernelargs, " ");
251 strcat(newkernelargs, kval);
252 env_set("kernelargs", newkernelargs);
255 printf("Error reading kernelargs env variable!\n");
261 int board_eth_init(bd_t *bis)
263 struct fsl_pq_mdio_info mdio_info;
264 struct tsec_info_struct tsec_info[4];
266 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
271 SET_STD_TSEC_INFO(tsec_info[num], 1);
275 SET_STD_TSEC_INFO(tsec_info[num], 2);
276 if (is_serdes_configured(SGMII_TSEC2)) {
277 if (!(in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_SGMII2_DIS)) {
278 puts("eTSEC2 is in sgmii mode.\n");
279 tsec_info[num].flags |= TSEC_SGMII;
280 tsec_info[num].phyaddr = TSEC2_PHY_ADDR_SGMII;
286 SET_STD_TSEC_INFO(tsec_info[num], 3);
291 printf("No TSECs initialized\n");
295 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
296 mdio_info.name = DEFAULT_MII_NAME;
298 fsl_pq_mdio_init(bis, &mdio_info);
300 tsec_eth_init(bis, tsec_info, num);
302 return pci_eth_init(bis);
305 #ifdef CONFIG_OF_BOARD_SETUP
306 int ft_board_setup(void *blob, bd_t *bd)
310 const char *soc_usb_compat = "fsl-usb2-dr";
311 int err, usb1_off, usb2_off;
313 ft_cpu_setup(blob, bd);
315 base = env_get_bootm_low();
316 size = env_get_bootm_size();
318 fdt_fixup_memory(blob, (u64)base, (u64)size);
322 #if defined(CONFIG_HAS_FSL_DR_USB)
323 fsl_fdt_fixup_dr_usb(blob, bd);
326 #if defined(CONFIG_SDCARD) || defined(CONFIG_SPIFLASH)
327 /* Delete eLBC node as it is muxed with USB2 controller */
328 if (hwconfig("usb2")) {
329 const char *soc_elbc_compat = "fsl,p1020-elbc";
330 int off = fdt_node_offset_by_compatible(blob, -1,
334 ("WARNING: could not find compatible node %s: %s\n",
335 soc_elbc_compat, fdt_strerror(off));
338 err = fdt_del_node(blob, off);
340 printf("WARNING: could not remove %s: %s\n",
341 soc_elbc_compat, fdt_strerror(err));
347 /* Delete USB2 node as it is muxed with eLBC */
348 usb1_off = fdt_node_offset_by_compatible(blob, -1, soc_usb_compat);
350 printf("WARNING: could not find compatible node %s: %s.\n",
351 soc_usb_compat, fdt_strerror(usb1_off));
355 fdt_node_offset_by_compatible(blob, usb1_off, soc_usb_compat);
357 printf("WARNING: could not find compatible node %s: %s.\n",
358 soc_usb_compat, fdt_strerror(usb2_off));
361 err = fdt_del_node(blob, usb2_off);
363 printf("WARNING: could not remove %s: %s.\n",
364 soc_usb_compat, fdt_strerror(err));