100d75f3fSChia-Wei, Wang // SPDX-License-Identifier: GPL-2.0+ 200d75f3fSChia-Wei, Wang /* 300d75f3fSChia-Wei, Wang * Copyright (C) ASPEED Technology Inc. 400d75f3fSChia-Wei, Wang * Ryan Chen <ryan_chen@aspeedtech.com> 500d75f3fSChia-Wei, Wang */ 600d75f3fSChia-Wei, Wang 700d75f3fSChia-Wei, Wang #include <common.h> 800d75f3fSChia-Wei, Wang #include <errno.h> 900d75f3fSChia-Wei, Wang #include <asm/io.h> 1000d75f3fSChia-Wei, Wang #include <asm/arch/platform.h> 1100d75f3fSChia-Wei, Wang #include <asm/arch/aspeed_scu_info.h> 1200d75f3fSChia-Wei, Wang 1300d75f3fSChia-Wei, Wang /* SoC mapping Table */ 1400d75f3fSChia-Wei, Wang #define SOC_ID(str, rev) { .name = str, .rev_id = rev, } 1500d75f3fSChia-Wei, Wang 1600d75f3fSChia-Wei, Wang struct soc_id { 1700d75f3fSChia-Wei, Wang const char *name; 1800d75f3fSChia-Wei, Wang u32 rev_id; 1900d75f3fSChia-Wei, Wang }; 2000d75f3fSChia-Wei, Wang 2100d75f3fSChia-Wei, Wang static struct soc_id soc_map_table[] = { 2200d75f3fSChia-Wei, Wang SOC_ID("AST1100/AST2050-A0", 0x00000200), 2300d75f3fSChia-Wei, Wang SOC_ID("AST1100/AST2050-A1", 0x00000201), 2400d75f3fSChia-Wei, Wang SOC_ID("AST1100/AST2050-A2,3/AST2150-A0,1", 0x00000202), 2500d75f3fSChia-Wei, Wang SOC_ID("AST1510/AST2100-A0", 0x00000300), 2600d75f3fSChia-Wei, Wang SOC_ID("AST1510/AST2100-A1", 0x00000301), 2700d75f3fSChia-Wei, Wang SOC_ID("AST1510/AST2100-A2,3", 0x00000302), 2800d75f3fSChia-Wei, Wang SOC_ID("AST2200-A0,1", 0x00000102), 2900d75f3fSChia-Wei, Wang SOC_ID("AST2300-A0", 0x01000003), 3000d75f3fSChia-Wei, Wang SOC_ID("AST2300-A1", 0x01010303), 3100d75f3fSChia-Wei, Wang SOC_ID("AST1300-A1", 0x01010003), 3200d75f3fSChia-Wei, Wang SOC_ID("AST1050-A1", 0x01010203), 3300d75f3fSChia-Wei, Wang SOC_ID("AST2400-A0", 0x02000303), 3400d75f3fSChia-Wei, Wang SOC_ID("AST2400-A1", 0x02010303), 3500d75f3fSChia-Wei, Wang SOC_ID("AST1010-A0", 0x03000003), 3600d75f3fSChia-Wei, Wang SOC_ID("AST1010-A1", 0x03010003), 3700d75f3fSChia-Wei, Wang SOC_ID("AST3200-A0", 0x04002003), 3800d75f3fSChia-Wei, Wang SOC_ID("AST3200-A1", 0x04012003), 3900d75f3fSChia-Wei, Wang SOC_ID("AST3200-A2", 0x04032003), 4000d75f3fSChia-Wei, Wang SOC_ID("AST1520-A0", 0x03000203), 4100d75f3fSChia-Wei, Wang SOC_ID("AST1520-A1", 0x03010203), 4200d75f3fSChia-Wei, Wang SOC_ID("AST2510-A0", 0x04000103), 4300d75f3fSChia-Wei, Wang SOC_ID("AST2510-A1", 0x04010103), 4400d75f3fSChia-Wei, Wang SOC_ID("AST2510-A2", 0x04030103), 4500d75f3fSChia-Wei, Wang SOC_ID("AST2520-A0", 0x04000203), 4600d75f3fSChia-Wei, Wang SOC_ID("AST2520-A1", 0x04010203), 4700d75f3fSChia-Wei, Wang SOC_ID("AST2520-A2", 0x04030203), 4800d75f3fSChia-Wei, Wang SOC_ID("AST2500-A0", 0x04000303), 4900d75f3fSChia-Wei, Wang SOC_ID("AST2500-A1", 0x04010303), 5000d75f3fSChia-Wei, Wang SOC_ID("AST2500-A2", 0x04030303), 5100d75f3fSChia-Wei, Wang SOC_ID("AST2530-A0", 0x04000403), 5200d75f3fSChia-Wei, Wang SOC_ID("AST2530-A1", 0x04010403), 5300d75f3fSChia-Wei, Wang SOC_ID("AST2530-A2", 0x04030403), 5400d75f3fSChia-Wei, Wang SOC_ID("AST2600-A0", 0x05000303), 5500d75f3fSChia-Wei, Wang }; 5600d75f3fSChia-Wei, Wang 5700d75f3fSChia-Wei, Wang void aspeed_print_soc_id(void) 5800d75f3fSChia-Wei, Wang { 5900d75f3fSChia-Wei, Wang int i; 6000d75f3fSChia-Wei, Wang u32 rev_id = readl(ASPEED_REVISION_ID); 6100d75f3fSChia-Wei, Wang for (i = 0; i < ARRAY_SIZE(soc_map_table); i++) { 6200d75f3fSChia-Wei, Wang if (rev_id == soc_map_table[i].rev_id) 6300d75f3fSChia-Wei, Wang break; 6400d75f3fSChia-Wei, Wang } 6500d75f3fSChia-Wei, Wang if (i == ARRAY_SIZE(soc_map_table)) 6600d75f3fSChia-Wei, Wang printf("UnKnow-SOC : %x \n",rev_id); 6700d75f3fSChia-Wei, Wang else 6800d75f3fSChia-Wei, Wang printf("SOC : %4s \n",soc_map_table[i].name); 6900d75f3fSChia-Wei, Wang } 7000d75f3fSChia-Wei, Wang 7100d75f3fSChia-Wei, Wang int aspeed_get_mac_phy_interface(u8 num) 7200d75f3fSChia-Wei, Wang { 7300d75f3fSChia-Wei, Wang u32 strap1 = readl(ASPEED_HW_STRAP1); 7400d75f3fSChia-Wei, Wang #ifdef ASPEED_HW_STRAP2 7500d75f3fSChia-Wei, Wang u32 strap2 = readl(ASPEED_HW_STRAP2); 7600d75f3fSChia-Wei, Wang #endif 7700d75f3fSChia-Wei, Wang switch(num) { 7800d75f3fSChia-Wei, Wang case 0: 7900d75f3fSChia-Wei, Wang if(strap1 & BIT(6)) { 8000d75f3fSChia-Wei, Wang return 1; 8100d75f3fSChia-Wei, Wang } else { 8200d75f3fSChia-Wei, Wang return 0; 8300d75f3fSChia-Wei, Wang } 8400d75f3fSChia-Wei, Wang break; 8500d75f3fSChia-Wei, Wang case 1: 8600d75f3fSChia-Wei, Wang if(strap1 & BIT(7)) { 8700d75f3fSChia-Wei, Wang return 1; 8800d75f3fSChia-Wei, Wang } else { 8900d75f3fSChia-Wei, Wang return 0; 9000d75f3fSChia-Wei, Wang } 9100d75f3fSChia-Wei, Wang break; 9200d75f3fSChia-Wei, Wang #ifdef ASPEED_HW_STRAP2 9300d75f3fSChia-Wei, Wang case 2: 9400d75f3fSChia-Wei, Wang if(strap2 & BIT(0)) { 9500d75f3fSChia-Wei, Wang return 1; 9600d75f3fSChia-Wei, Wang } else { 9700d75f3fSChia-Wei, Wang return 0; 9800d75f3fSChia-Wei, Wang } 9900d75f3fSChia-Wei, Wang break; 10000d75f3fSChia-Wei, Wang case 3: 10100d75f3fSChia-Wei, Wang if(strap2 & BIT(1)) { 10200d75f3fSChia-Wei, Wang return 1; 10300d75f3fSChia-Wei, Wang } else { 10400d75f3fSChia-Wei, Wang return 0; 10500d75f3fSChia-Wei, Wang } 10600d75f3fSChia-Wei, Wang break; 10700d75f3fSChia-Wei, Wang #endif 10800d75f3fSChia-Wei, Wang } 10900d75f3fSChia-Wei, Wang return -1; 11000d75f3fSChia-Wei, Wang } 11100d75f3fSChia-Wei, Wang 11200d75f3fSChia-Wei, Wang void aspeed_print_security_info(void) 11300d75f3fSChia-Wei, Wang { 11400d75f3fSChia-Wei, Wang switch((readl(ASPEED_HW_STRAP2) >> 18) & 0x3) { 11500d75f3fSChia-Wei, Wang case 1: 11600d75f3fSChia-Wei, Wang printf("SEC : DSS Mode \n"); 11700d75f3fSChia-Wei, Wang break; 11800d75f3fSChia-Wei, Wang case 2: 11900d75f3fSChia-Wei, Wang printf("SEC : UnKnow \n"); 12000d75f3fSChia-Wei, Wang break; 12100d75f3fSChia-Wei, Wang case 3: 12200d75f3fSChia-Wei, Wang printf("SEC : SPI2 Mode \n"); 12300d75f3fSChia-Wei, Wang break; 12400d75f3fSChia-Wei, Wang } 12500d75f3fSChia-Wei, Wang } 12600d75f3fSChia-Wei, Wang 12700d75f3fSChia-Wei, Wang /* ASPEED_SYS_RESET_CTRL : System reset contrl/status register*/ 12800d75f3fSChia-Wei, Wang #define SYS_WDT3_RESET BIT(4) 12900d75f3fSChia-Wei, Wang #define SYS_WDT2_RESET BIT(3) 13000d75f3fSChia-Wei, Wang #define SYS_WDT1_RESET BIT(2) 13100d75f3fSChia-Wei, Wang #define SYS_EXT_RESET BIT(1) 13200d75f3fSChia-Wei, Wang #define SYS_PWR_RESET_FLAG BIT(0) 13300d75f3fSChia-Wei, Wang 13400d75f3fSChia-Wei, Wang void aspeed_print_sysrst_info(void) 13500d75f3fSChia-Wei, Wang { 13600d75f3fSChia-Wei, Wang u32 rest = readl(ASPEED_SYS_RESET_CTRL); 13700d75f3fSChia-Wei, Wang 13800d75f3fSChia-Wei, Wang if (rest & SYS_WDT1_RESET) { 13900d75f3fSChia-Wei, Wang printf("RST : WDT1 \n"); 14000d75f3fSChia-Wei, Wang writel(readl(ASPEED_SYS_RESET_CTRL) & ~SYS_WDT1_RESET, ASPEED_SYS_RESET_CTRL); 14100d75f3fSChia-Wei, Wang } 14200d75f3fSChia-Wei, Wang if (rest & SYS_WDT2_RESET) { 14300d75f3fSChia-Wei, Wang printf("RST : WDT2 - 2nd Boot \n"); 14400d75f3fSChia-Wei, Wang writel(readl(ASPEED_SYS_RESET_CTRL) & ~SYS_WDT2_RESET, ASPEED_SYS_RESET_CTRL); 14500d75f3fSChia-Wei, Wang if(readl(0x1e785030) & BIT(1)) 14600d75f3fSChia-Wei, Wang puts("second boot\n"); 14783a1e8c4SChin-Ting Kuo else 14883a1e8c4SChin-Ting Kuo puts("default boot\n"); 14900d75f3fSChia-Wei, Wang } 15000d75f3fSChia-Wei, Wang if (rest & SYS_WDT3_RESET) { 15100d75f3fSChia-Wei, Wang printf("RST : WDT3 - Boot\n"); 15200d75f3fSChia-Wei, Wang writel(readl(ASPEED_SYS_RESET_CTRL) & ~SYS_WDT3_RESET, ASPEED_SYS_RESET_CTRL); 15300d75f3fSChia-Wei, Wang } 15400d75f3fSChia-Wei, Wang if(rest & SYS_EXT_RESET) { 15500d75f3fSChia-Wei, Wang printf("RST : External \n"); 15600d75f3fSChia-Wei, Wang writel(readl(ASPEED_SYS_RESET_CTRL) & ~SYS_EXT_RESET, ASPEED_SYS_RESET_CTRL); 15700d75f3fSChia-Wei, Wang } 15800d75f3fSChia-Wei, Wang if (rest & SYS_PWR_RESET_FLAG) { 15900d75f3fSChia-Wei, Wang printf("RST : Power On \n"); 16000d75f3fSChia-Wei, Wang writel(readl(ASPEED_SYS_RESET_CTRL) & ~SYS_PWR_RESET_FLAG, ASPEED_SYS_RESET_CTRL); 16100d75f3fSChia-Wei, Wang } 16200d75f3fSChia-Wei, Wang } 16300d75f3fSChia-Wei, Wang 16400d75f3fSChia-Wei, Wang #define SOC_FW_INIT_DRAM BIT(7) 16500d75f3fSChia-Wei, Wang 16600d75f3fSChia-Wei, Wang void aspeed_print_dram_initializer(void) 16700d75f3fSChia-Wei, Wang { 16800d75f3fSChia-Wei, Wang if(readl(ASPEED_VGA_HANDSHAKE0) & SOC_FW_INIT_DRAM) 16900d75f3fSChia-Wei, Wang printf("[init by SOC]\n"); 17000d75f3fSChia-Wei, Wang else 17100d75f3fSChia-Wei, Wang printf("[init by VBIOS]\n"); 17200d75f3fSChia-Wei, Wang } 17300d75f3fSChia-Wei, Wang 17400d75f3fSChia-Wei, Wang void aspeed_print_2nd_wdt_mode(void) 17500d75f3fSChia-Wei, Wang { 17600d75f3fSChia-Wei, Wang if(readl(ASPEED_HW_STRAP1) & BIT(17)) 17700d75f3fSChia-Wei, Wang printf("2nd Boot : Enable\n"); 17800d75f3fSChia-Wei, Wang } 17900d75f3fSChia-Wei, Wang 18000d75f3fSChia-Wei, Wang void aspeed_print_spi_strap_mode(void) 18100d75f3fSChia-Wei, Wang { 18200d75f3fSChia-Wei, Wang return; 18300d75f3fSChia-Wei, Wang } 18400d75f3fSChia-Wei, Wang 18500d75f3fSChia-Wei, Wang void aspeed_print_espi_mode(void) 18600d75f3fSChia-Wei, Wang { 18700d75f3fSChia-Wei, Wang int espi_mode = 0; 18800d75f3fSChia-Wei, Wang int sio_disable = 0; 18900d75f3fSChia-Wei, Wang u32 sio_addr = 0x2e; 19000d75f3fSChia-Wei, Wang 19100d75f3fSChia-Wei, Wang if(readl(ASPEED_HW_STRAP1) & BIT(25)) 19200d75f3fSChia-Wei, Wang espi_mode = 1; 19300d75f3fSChia-Wei, Wang else 19400d75f3fSChia-Wei, Wang espi_mode = 0; 19500d75f3fSChia-Wei, Wang 19600d75f3fSChia-Wei, Wang if(readl(ASPEED_HW_STRAP1) & BIT(16)) 19700d75f3fSChia-Wei, Wang sio_addr = 0x4e; 19800d75f3fSChia-Wei, Wang 19900d75f3fSChia-Wei, Wang if(readl(ASPEED_HW_STRAP1) & BIT(20)) 20000d75f3fSChia-Wei, Wang sio_disable = 1; 20100d75f3fSChia-Wei, Wang 20200d75f3fSChia-Wei, Wang if(espi_mode) 20300d75f3fSChia-Wei, Wang printf("eSPI Mode : SIO:%s ", sio_disable ? "Disable" : "Enable"); 20400d75f3fSChia-Wei, Wang else 20500d75f3fSChia-Wei, Wang printf("LPC Mode : SIO:%s ", sio_disable ? "Disable" : "Enable"); 20600d75f3fSChia-Wei, Wang 20700d75f3fSChia-Wei, Wang if(!sio_disable) 20800d75f3fSChia-Wei, Wang printf(": SuperIO-%02x\n", sio_addr); 20900d75f3fSChia-Wei, Wang else 21000d75f3fSChia-Wei, Wang printf("\n"); 21100d75f3fSChia-Wei, Wang } 21200d75f3fSChia-Wei, Wang 21300d75f3fSChia-Wei, Wang void aspeed_print_mac_info(void) 21400d75f3fSChia-Wei, Wang { 21500d75f3fSChia-Wei, Wang int i; 216*01baafcfSryan_chen printf("Eth : "); 21700d75f3fSChia-Wei, Wang for (i = 0; i < ASPEED_MAC_COUNT; i++) 218*01baafcfSryan_chen printf("MAC%d: %s, ", i, 21900d75f3fSChia-Wei, Wang aspeed_get_mac_phy_interface(i) ? "RGMII" : "RMII/NCSI"); 220*01baafcfSryan_chen if (i != (ASPEED_MAC_COUNT -1)) 221*01baafcfSryan_chen printf(", "); 222*01baafcfSryan_chen printf("\n"); 22300d75f3fSChia-Wei, Wang } 224