1 // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
3 * Copyright (c) 2018 Microsemi Corporation
12 #include <linux/bitops.h>
13 #include <linux/delay.h>
16 BOARD_TYPE_PCB110 = 0xAABBCE00,
21 int board_early_init_r(void)
23 /* Prepare SPI controller to be used in master mode */
24 writel(0, BASE_CFG + ICPU_SW_MODE);
25 clrsetbits_le32(BASE_CFG + ICPU_GENERAL_CTRL,
26 ICPU_GENERAL_CTRL_IF_SI_OWNER_M,
27 ICPU_GENERAL_CTRL_IF_SI_OWNER(2));
29 /* Address of boot parameters */
30 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE;
33 if (IS_ENABLED(CONFIG_LED))
39 static void vcoreiii_gpio_set_alternate(int gpio, int mode)
43 void __iomem *reg0, *reg1;
47 reg0 = BASE_DEVCPU_GCB + GPIO_GPIO_ALT(0);
48 reg1 = BASE_DEVCPU_GCB + GPIO_GPIO_ALT(1);
52 reg0 = BASE_DEVCPU_GCB + GPIO_GPIO_ALT1(0);
53 reg1 = BASE_DEVCPU_GCB + GPIO_GPIO_ALT1(1);
58 writel(val0 | mask, reg0);
59 writel(val1 & ~mask, reg1);
60 } else if (mode == 2) {
61 writel(val0 & ~mask, reg0);
62 writel(val1 | mask, reg1);
63 } else if (mode == 3) {
64 writel(val0 | mask, reg0);
65 writel(val1 | mask, reg1);
67 writel(val0 & ~mask, reg0);
68 writel(val1 & ~mask, reg1);
72 int board_phy_config(struct phy_device *phydev)
74 if (gd->board_type == BOARD_TYPE_PCB110 ||
75 gd->board_type == BOARD_TYPE_PCB112) {
76 phy_write(phydev, 0, 31, 0x10);
77 phy_write(phydev, 0, 18, 0x80F0);
78 while (phy_read(phydev, 0, 18) & 0x8000)
80 phy_write(phydev, 0, 31, 0);
82 if (gd->board_type == BOARD_TYPE_PCB111) {
83 phy_write(phydev, 0, 31, 0x10);
84 phy_write(phydev, 0, 18, 0x80A0);
85 while (phy_read(phydev, 0, 18) & 0x8000)
87 phy_write(phydev, 0, 14, 0x800);
88 phy_write(phydev, 0, 31, 0);
94 void board_debug_uart_init(void)
96 /* too early for the pinctrl driver, so configure the UART pins here */
97 vcoreiii_gpio_set_alternate(10, 1);
98 vcoreiii_gpio_set_alternate(11, 1);
101 static void do_board_detect(void)
106 /* MIIM 1 + 2 MDC/MDIO */
107 for (i = 56; i < 60; i++)
108 vcoreiii_gpio_set_alternate(i, 1);
110 /* small delay for settling the pins */
113 if (mscc_phy_rd(0, 0x10, 0x3, &pval) == 0 &&
114 ((pval >> 4) & 0x3F) == 0x3c) {
115 gd->board_type = BOARD_TYPE_PCB112; /* Serval2-NID */
116 } else if (mscc_phy_rd(1, 0x0, 0x3, &pval) == 0 &&
117 ((pval >> 4) & 0x3F) == 0x3c) {
118 gd->board_type = BOARD_TYPE_PCB110; /* Jr2-24 */
121 gd->board_type = BOARD_TYPE_PCB111; /* Jr2-48 */
125 #if defined(CONFIG_MULTI_DTB_FIT)
126 int board_fit_config_name_match(const char *name)
128 if (gd->board_type == BOARD_TYPE_PCB110 &&
129 strcmp(name, "jr2_pcb110") == 0)
132 if (gd->board_type == BOARD_TYPE_PCB111 &&
133 strcmp(name, "jr2_pcb111") == 0)
136 if (gd->board_type == BOARD_TYPE_PCB112 &&
137 strcmp(name, "serval2_pcb112") == 0)
144 #if defined(CONFIG_DTB_RESELECT)
145 int embedded_dtb_select(void)