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.
18 #include <linux/libfdt.h>
19 #include <fdt_support.h>
25 #include <spi_flash.h>
27 #include <linux/ctype.h>
28 #include <asm/fsl_serdes.h>
30 #include <asm/processor.h>
32 #include <asm/cache.h>
33 #include <asm/immap_85xx.h>
34 #include <asm/fsl_pci.h>
35 #include <fsl_ddr_sdram.h>
37 #include <asm/fsl_law.h>
38 #include <asm/fsl_lbc.h>
42 void spi_set_speed(struct spi_slave *slave, uint hz)
44 /* TO DO: It's actially have to be in spi/ */
48 * To be compatible with cmd_gpio
50 int name_to_gpio(const char *name)
52 int gpio = 31 - simple_strtoul(name, NULL, 10);
60 void board_gpio_init(void)
63 char envname[8], *val;
65 for (i = 0; i < GPIO_MAX_NUM; i++) {
66 sprintf(envname, "GPIO%d", i);
67 val = env_get(envname);
69 char direction = toupper(val[0]);
70 char level = toupper(val[1]);
72 if (direction == 'I') {
73 gpio_direction_input(i);
75 if (direction == 'O') {
77 gpio_direction_output(i, 1);
79 gpio_direction_output(i, 0);
85 val = env_get("PCIE_OFF");
87 gpio_direction_input(GPIO_PCIE1_EN);
88 gpio_direction_input(GPIO_PCIE2_EN);
90 gpio_direction_output(GPIO_PCIE1_EN, 1);
91 gpio_direction_output(GPIO_PCIE2_EN, 1);
94 val = env_get("SDHC_CDWP_OFF");
96 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
98 setbits_be32(&gur->pmuxcr,
99 (MPC85xx_PMUXCR_SDHC_CD | MPC85xx_PMUXCR_SDHC_WP));
103 int board_early_init_f(void)
105 return 0; /* Just in case. Could be disable in config file */
110 printf("Board: %s\n", CONFIG_BOARDNAME_LOCAL);
113 printf("SD/MMC: 4-bit Mode\n");
120 void pci_init_board(void)
122 fsl_pcie_init_board(0);
126 int board_early_init_r(void)
128 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
129 const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
132 * Remap Boot flash region to caching-inhibited
133 * so that flash can be erased properly.
136 /* Flush d-cache and invalidate i-cache of any FLASH data */
140 /* invalidate existing TLB entry for flash */
141 disable_tlb(flash_esel);
143 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, /* tlb, epn, rpn */
144 MAS3_SX | MAS3_SW | MAS3_SR, MAS2_I | MAS2_G, /* perms, wimge */
145 0, flash_esel, BOOKE_PAGESZ_64M, 1);/* ts, esel, tsize, iprot */
150 int board_phy_config(struct phy_device *phydev)
152 #if defined(CONFIG_PHY_MICREL_KSZ9021)
157 printf("PHYs address [");
159 if (phydev->addr == TSEC1_PHY_ADDR || phydev->addr == TSEC3_PHY_ADDR) {
161 ksz9021_phy_extended_read(phydev,
162 MII_KSZ9021_EXT_STRAP_STATUS);
166 ksz9021_phy_extended_write(phydev,
167 MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW,
170 * max rx/tx clock delay, min rx/tx control
172 ksz9021_phy_extended_write(phydev,
173 MII_KSZ9021_EXT_RGMII_CLOCK_SKEW,
175 printf("0x%x", (regval & 0x1f));
177 printf("0x%x", (TSEC2_PHY_ADDR & 0x1f));
185 #if defined(CONFIG_PHY_MICREL_KSZ9031_DEBUG)
186 regval = ksz9031_phy_extended_read(phydev, 2, 0x01, 0x4000);
188 printf(" (ADDR 0x%x) ", regval & 0x1f);
194 int last_stage_init(void)
196 static char newkernelargs[256];
204 if (i2c_read(CONFIG_SYS_I2C_IDT6V49205B, 7, 1, &id1[0], 2) < 0) {
205 printf("Error reading i2c IDT6V49205B information!\n");
207 printf("IDT6V49205B(0x%02x): ready\n", id1[1]);
208 i2c_read(CONFIG_SYS_I2C_IDT6V49205B, 4, 1, &id1[0], 2);
209 if (!(id1[1] & 0x02)) {
211 i2c_write(CONFIG_SYS_I2C_IDT6V49205B, 4, 1, &id1[0], 2);
216 if (i2c_read(CONFIG_SYS_I2C_NCT72_ADDR, 0xFE, 1, &id2, 1) < 0)
217 printf("Error reading i2c NCT72 information!\n");
219 printf("NCT72(0x%x): ready\n", id2);
221 kval = env_get("kernelargs");
224 mmc = find_mmc_device(0);
226 if (!mmc_init(mmc)) {
227 printf("MMC/SD card detected\n");
229 int n = strlen(defkargs);
230 char *tmp = strstr(kval, defkargs);
233 strcpy(newkernelargs, kval);
234 strcat(newkernelargs, " ");
235 strcat(newkernelargs, mmckargs);
236 strcat(newkernelargs, " ");
237 strcat(newkernelargs, &tmp[n]);
238 env_set("kernelargs", newkernelargs);
240 env_set("kernelargs", mmckargs);
247 sval = env_get("SERIAL");
249 strcpy(newkernelargs, "SN=");
250 strcat(newkernelargs, sval);
251 strcat(newkernelargs, " ");
252 strcat(newkernelargs, kval);
253 env_set("kernelargs", newkernelargs);
256 printf("Error reading kernelargs env variable!\n");
262 int board_eth_init(bd_t *bis)
264 struct fsl_pq_mdio_info mdio_info;
265 struct tsec_info_struct tsec_info[4];
267 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
272 SET_STD_TSEC_INFO(tsec_info[num], 1);
276 SET_STD_TSEC_INFO(tsec_info[num], 2);
277 if (is_serdes_configured(SGMII_TSEC2)) {
278 if (!(in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_SGMII2_DIS)) {
279 puts("eTSEC2 is in sgmii mode.\n");
280 tsec_info[num].flags |= TSEC_SGMII;
281 tsec_info[num].phyaddr = TSEC2_PHY_ADDR_SGMII;
287 SET_STD_TSEC_INFO(tsec_info[num], 3);
292 printf("No TSECs initialized\n");
296 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
297 mdio_info.name = DEFAULT_MII_NAME;
299 fsl_pq_mdio_init(bis, &mdio_info);
301 tsec_eth_init(bis, tsec_info, num);
303 return pci_eth_init(bis);
306 #ifdef CONFIG_OF_BOARD_SETUP
307 int ft_board_setup(void *blob, bd_t *bd)
311 const char *soc_usb_compat = "fsl-usb2-dr";
312 int err, usb1_off, usb2_off;
314 ft_cpu_setup(blob, bd);
316 base = env_get_bootm_low();
317 size = env_get_bootm_size();
319 fdt_fixup_memory(blob, (u64)base, (u64)size);
323 #if defined(CONFIG_HAS_FSL_DR_USB)
324 fsl_fdt_fixup_dr_usb(blob, bd);
327 #if defined(CONFIG_SDCARD) || defined(CONFIG_SPIFLASH)
328 /* Delete eLBC node as it is muxed with USB2 controller */
329 if (hwconfig("usb2")) {
330 const char *soc_elbc_compat = "fsl,p1020-elbc";
331 int off = fdt_node_offset_by_compatible(blob, -1,
335 ("WARNING: could not find compatible node %s: %s\n",
336 soc_elbc_compat, fdt_strerror(off));
339 err = fdt_del_node(blob, off);
341 printf("WARNING: could not remove %s: %s\n",
342 soc_elbc_compat, fdt_strerror(err));
348 /* Delete USB2 node as it is muxed with eLBC */
349 usb1_off = fdt_node_offset_by_compatible(blob, -1, soc_usb_compat);
351 printf("WARNING: could not find compatible node %s: %s.\n",
352 soc_usb_compat, fdt_strerror(usb1_off));
356 fdt_node_offset_by_compatible(blob, usb1_off, soc_usb_compat);
358 printf("WARNING: could not find compatible node %s: %s.\n",
359 soc_usb_compat, fdt_strerror(usb2_off));
362 err = fdt_del_node(blob, usb2_off);
364 printf("WARNING: could not remove %s: %s.\n",
365 soc_usb_compat, fdt_strerror(err));