1 // SPDX-License-Identifier: (GPL-2.0+ OR MIT) 2 /* 3 * Copyright (c) 2018 Microsemi Corporation 4 */ 5 6 #include <common.h> 7 #include <asm/io.h> 8 #include <led.h> 9 10 enum { 11 BOARD_TYPE_PCB110 = 0xAABBCE00, 12 BOARD_TYPE_PCB111, 13 BOARD_TYPE_PCB112, 14 }; 15 16 int board_early_init_r(void) 17 { 18 /* Prepare SPI controller to be used in master mode */ 19 writel(0, BASE_CFG + ICPU_SW_MODE); 20 clrsetbits_le32(BASE_CFG + ICPU_GENERAL_CTRL, 21 ICPU_GENERAL_CTRL_IF_SI_OWNER_M, 22 ICPU_GENERAL_CTRL_IF_SI_OWNER(2)); 23 24 /* Address of boot parameters */ 25 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE; 26 27 /* LED setup */ 28 if (IS_ENABLED(CONFIG_LED)) 29 led_default_state(); 30 31 return 0; 32 } 33 34 static void vcoreiii_gpio_set_alternate(int gpio, int mode) 35 { 36 u32 mask; 37 u32 val0, val1; 38 void __iomem *reg0, *reg1; 39 40 if (gpio < 32) { 41 mask = BIT(gpio); 42 reg0 = BASE_DEVCPU_GCB + GPIO_GPIO_ALT(0); 43 reg1 = BASE_DEVCPU_GCB + GPIO_GPIO_ALT(1); 44 } else { 45 gpio -= 32; 46 mask = BIT(gpio); 47 reg0 = BASE_DEVCPU_GCB + GPIO_GPIO_ALT1(0); 48 reg1 = BASE_DEVCPU_GCB + GPIO_GPIO_ALT1(1); 49 } 50 val0 = readl(reg0); 51 val1 = readl(reg1); 52 if (mode == 1) { 53 writel(val0 | mask, reg0); 54 writel(val1 & ~mask, reg1); 55 } else if (mode == 2) { 56 writel(val0 & ~mask, reg0); 57 writel(val1 | mask, reg1); 58 } else if (mode == 3) { 59 writel(val0 | mask, reg0); 60 writel(val1 | mask, reg1); 61 } else { 62 writel(val0 & ~mask, reg0); 63 writel(val1 & ~mask, reg1); 64 } 65 } 66 67 static void do_board_detect(void) 68 { 69 int i; 70 u16 pval; 71 72 /* MIIM 1 + 2 MDC/MDIO */ 73 for (i = 56; i < 60; i++) 74 vcoreiii_gpio_set_alternate(i, 1); 75 76 if (mscc_phy_rd(0, 0x10, 0x3, &pval) == 0 && 77 ((pval >> 4) & 0x3F) == 0x3c) { 78 gd->board_type = BOARD_TYPE_PCB112; /* Serval2-NID */ 79 } else if (mscc_phy_rd(1, 0x0, 0x3, &pval) == 0 && 80 ((pval >> 4) & 0x3F) == 0x3c) { 81 gd->board_type = BOARD_TYPE_PCB110; /* Jr2-24 */ 82 } else { 83 /* Fall-back */ 84 gd->board_type = BOARD_TYPE_PCB111; /* Jr2-48 */ 85 } 86 } 87 88 #if defined(CONFIG_MULTI_DTB_FIT) 89 int board_fit_config_name_match(const char *name) 90 { 91 if (gd->board_type == BOARD_TYPE_PCB110 && 92 strcmp(name, "jr2_pcb110") == 0) 93 return 0; 94 95 if (gd->board_type == BOARD_TYPE_PCB111 && 96 strcmp(name, "jr2_pcb111") == 0) 97 return 0; 98 99 if (gd->board_type == BOARD_TYPE_PCB112 && 100 strcmp(name, "serval2_pcb112") == 0) 101 return 0; 102 103 return -1; 104 } 105 #endif 106 107 #if defined(CONFIG_DTB_RESELECT) 108 int embedded_dtb_select(void) 109 { 110 do_board_detect(); 111 fdtdec_setup(); 112 113 return 0; 114 } 115 #endif 116