17a9d109bSPaul Burton /* 27a9d109bSPaul Burton * Copyright (C) 2013 Gabor Juhos <juhosg@openwrt.org> 3baf37f06SPaul Burton * Copyright (C) 2013 Imagination Technologies 47a9d109bSPaul Burton * 57a9d109bSPaul Burton * SPDX-License-Identifier: GPL-2.0 67a9d109bSPaul Burton */ 77a9d109bSPaul Burton 87a9d109bSPaul Burton #include <common.h> 9ba21a453SPaul Burton #include <ide.h> 107a9d109bSPaul Burton #include <netdev.h> 1181f98bbdSPaul Burton #include <pci.h> 12baf37f06SPaul Burton #include <pci_gt64120.h> 13baf37f06SPaul Burton #include <pci_msc01.h> 143ced12a0SPaul Burton #include <rtc.h> 15baf37f06SPaul Burton #include <serial.h> 167a9d109bSPaul Burton 177a9d109bSPaul Burton #include <asm/addrspace.h> 187a9d109bSPaul Burton #include <asm/io.h> 197a9d109bSPaul Burton #include <asm/malta.h> 207a9d109bSPaul Burton 21a257f626SPaul Burton #include "superio.h" 22a257f626SPaul Burton 23baf37f06SPaul Burton enum core_card { 24baf37f06SPaul Burton CORE_UNKNOWN, 25baf37f06SPaul Burton CORE_LV, 26baf37f06SPaul Burton CORE_FPGA6, 27baf37f06SPaul Burton }; 28baf37f06SPaul Burton 29baf37f06SPaul Burton enum sys_con { 30baf37f06SPaul Burton SYSCON_UNKNOWN, 31baf37f06SPaul Burton SYSCON_GT64120, 32baf37f06SPaul Burton SYSCON_MSC01, 33baf37f06SPaul Burton }; 34baf37f06SPaul Burton 35e0ada631SPaul Burton static void malta_lcd_puts(const char *str) 36e0ada631SPaul Burton { 37e0ada631SPaul Burton int i; 38e0ada631SPaul Burton void *reg = (void *)CKSEG1ADDR(MALTA_ASCIIPOS0); 39e0ada631SPaul Burton 40e0ada631SPaul Burton /* print up to 8 characters of the string */ 41b4141195SMasahiro Yamada for (i = 0; i < min((int)strlen(str), 8); i++) { 42e0ada631SPaul Burton __raw_writel(str[i], reg); 43e0ada631SPaul Burton reg += MALTA_ASCIIPOS1 - MALTA_ASCIIPOS0; 44e0ada631SPaul Burton } 45e0ada631SPaul Burton 46e0ada631SPaul Burton /* fill the rest of the display with spaces */ 47e0ada631SPaul Burton for (; i < 8; i++) { 48e0ada631SPaul Burton __raw_writel(' ', reg); 49e0ada631SPaul Burton reg += MALTA_ASCIIPOS1 - MALTA_ASCIIPOS0; 50e0ada631SPaul Burton } 51e0ada631SPaul Burton } 52e0ada631SPaul Burton 53baf37f06SPaul Burton static enum core_card malta_core_card(void) 54baf37f06SPaul Burton { 55baf37f06SPaul Burton u32 corid, rev; 56baf37f06SPaul Burton 57baf37f06SPaul Burton rev = __raw_readl(CKSEG1ADDR(MALTA_REVISION)); 58baf37f06SPaul Burton corid = (rev & MALTA_REVISION_CORID_MSK) >> MALTA_REVISION_CORID_SHF; 59baf37f06SPaul Burton 60baf37f06SPaul Burton switch (corid) { 61baf37f06SPaul Burton case MALTA_REVISION_CORID_CORE_LV: 62baf37f06SPaul Burton return CORE_LV; 63baf37f06SPaul Burton 64baf37f06SPaul Burton case MALTA_REVISION_CORID_CORE_FPGA6: 65baf37f06SPaul Burton return CORE_FPGA6; 66baf37f06SPaul Burton 67baf37f06SPaul Burton default: 68baf37f06SPaul Burton return CORE_UNKNOWN; 69baf37f06SPaul Burton } 70baf37f06SPaul Burton } 71baf37f06SPaul Burton 72baf37f06SPaul Burton static enum sys_con malta_sys_con(void) 73baf37f06SPaul Burton { 74baf37f06SPaul Burton switch (malta_core_card()) { 75baf37f06SPaul Burton case CORE_LV: 76baf37f06SPaul Burton return SYSCON_GT64120; 77baf37f06SPaul Burton 78baf37f06SPaul Burton case CORE_FPGA6: 79baf37f06SPaul Burton return SYSCON_MSC01; 80baf37f06SPaul Burton 81baf37f06SPaul Burton default: 82baf37f06SPaul Burton return SYSCON_UNKNOWN; 83baf37f06SPaul Burton } 84baf37f06SPaul Burton } 85baf37f06SPaul Burton 867a9d109bSPaul Burton phys_size_t initdram(int board_type) 877a9d109bSPaul Burton { 887a9d109bSPaul Burton return CONFIG_SYS_MEM_SIZE; 897a9d109bSPaul Burton } 907a9d109bSPaul Burton 917a9d109bSPaul Burton int checkboard(void) 927a9d109bSPaul Burton { 93baf37f06SPaul Burton enum core_card core; 94baf37f06SPaul Burton 95e0ada631SPaul Burton malta_lcd_puts("U-boot"); 96baf37f06SPaul Burton puts("Board: MIPS Malta"); 97baf37f06SPaul Burton 98baf37f06SPaul Burton core = malta_core_card(); 99baf37f06SPaul Burton switch (core) { 100baf37f06SPaul Burton case CORE_LV: 101baf37f06SPaul Burton puts(" CoreLV"); 102baf37f06SPaul Burton break; 103baf37f06SPaul Burton 104baf37f06SPaul Burton case CORE_FPGA6: 105baf37f06SPaul Burton puts(" CoreFPGA6"); 106baf37f06SPaul Burton break; 107baf37f06SPaul Burton 108baf37f06SPaul Burton default: 109baf37f06SPaul Burton puts(" CoreUnknown"); 110baf37f06SPaul Burton } 111baf37f06SPaul Burton 112baf37f06SPaul Burton putc('\n'); 1137a9d109bSPaul Burton return 0; 1147a9d109bSPaul Burton } 1157a9d109bSPaul Burton 1167a9d109bSPaul Burton int board_eth_init(bd_t *bis) 1177a9d109bSPaul Burton { 1187a9d109bSPaul Burton return pci_eth_init(bis); 1197a9d109bSPaul Burton } 1207a9d109bSPaul Burton 1217a9d109bSPaul Burton void _machine_restart(void) 1227a9d109bSPaul Burton { 1237a9d109bSPaul Burton void __iomem *reset_base; 1247a9d109bSPaul Burton 1257a9d109bSPaul Burton reset_base = (void __iomem *)CKSEG1ADDR(MALTA_RESET_BASE); 1267a9d109bSPaul Burton __raw_writel(GORESET, reset_base); 127*28c8c3d4SPaul Burton mdelay(1000); 1287a9d109bSPaul Burton } 1297a9d109bSPaul Burton 130a257f626SPaul Burton int board_early_init_f(void) 131a257f626SPaul Burton { 132baf37f06SPaul Burton void *io_base; 133baf37f06SPaul Burton 134baf37f06SPaul Burton /* choose correct PCI I/O base */ 135baf37f06SPaul Burton switch (malta_sys_con()) { 136baf37f06SPaul Burton case SYSCON_GT64120: 137baf37f06SPaul Burton io_base = (void *)CKSEG1ADDR(MALTA_GT_PCIIO_BASE); 138baf37f06SPaul Burton break; 139baf37f06SPaul Burton 140baf37f06SPaul Burton case SYSCON_MSC01: 141baf37f06SPaul Burton io_base = (void *)CKSEG1ADDR(MALTA_MSC01_PCIIO_BASE); 142baf37f06SPaul Burton break; 143baf37f06SPaul Burton 144baf37f06SPaul Burton default: 145baf37f06SPaul Burton return -1; 146baf37f06SPaul Burton } 147baf37f06SPaul Burton 148a257f626SPaul Burton /* setup FDC37M817 super I/O controller */ 149baf37f06SPaul Burton malta_superio_init(io_base); 150a257f626SPaul Burton 151a257f626SPaul Burton return 0; 152a257f626SPaul Burton } 153a257f626SPaul Burton 1543ced12a0SPaul Burton int misc_init_r(void) 1553ced12a0SPaul Burton { 1563ced12a0SPaul Burton rtc_reset(); 1573ced12a0SPaul Burton 1583ced12a0SPaul Burton return 0; 1593ced12a0SPaul Burton } 1603ced12a0SPaul Burton 161baf37f06SPaul Burton struct serial_device *default_serial_console(void) 162baf37f06SPaul Burton { 163baf37f06SPaul Burton switch (malta_sys_con()) { 164baf37f06SPaul Burton case SYSCON_GT64120: 165baf37f06SPaul Burton return &eserial1_device; 166baf37f06SPaul Burton 167baf37f06SPaul Burton default: 168baf37f06SPaul Burton case SYSCON_MSC01: 169baf37f06SPaul Burton return &eserial2_device; 170baf37f06SPaul Burton } 171baf37f06SPaul Burton } 172baf37f06SPaul Burton 1737a9d109bSPaul Burton void pci_init_board(void) 1747a9d109bSPaul Burton { 17581f98bbdSPaul Burton pci_dev_t bdf; 176bea12b78SPaul Burton u32 val32; 177bea12b78SPaul Burton u8 val8; 17881f98bbdSPaul Burton 179baf37f06SPaul Burton switch (malta_sys_con()) { 180baf37f06SPaul Burton case SYSCON_GT64120: 181baf37f06SPaul Burton set_io_port_base(CKSEG1ADDR(MALTA_GT_PCIIO_BASE)); 1827a9d109bSPaul Burton 1837a9d109bSPaul Burton gt64120_pci_init((void *)CKSEG1ADDR(MALTA_GT_BASE), 1847a9d109bSPaul Burton 0x00000000, 0x00000000, CONFIG_SYS_MEM_SIZE, 1857a9d109bSPaul Burton 0x10000000, 0x10000000, 128 * 1024 * 1024, 1867a9d109bSPaul Burton 0x00000000, 0x00000000, 0x20000); 187baf37f06SPaul Burton break; 188baf37f06SPaul Burton 189baf37f06SPaul Burton default: 190baf37f06SPaul Burton case SYSCON_MSC01: 191baf37f06SPaul Burton set_io_port_base(CKSEG1ADDR(MALTA_MSC01_PCIIO_BASE)); 192baf37f06SPaul Burton 193baf37f06SPaul Burton msc01_pci_init((void *)CKSEG1ADDR(MALTA_MSC01_PCI_BASE), 194baf37f06SPaul Burton 0x00000000, 0x00000000, CONFIG_SYS_MEM_SIZE, 195baf37f06SPaul Burton MALTA_MSC01_PCIMEM_MAP, 196baf37f06SPaul Burton CKSEG1ADDR(MALTA_MSC01_PCIMEM_BASE), 197baf37f06SPaul Burton MALTA_MSC01_PCIMEM_SIZE, MALTA_MSC01_PCIIO_MAP, 198baf37f06SPaul Burton 0x00000000, MALTA_MSC01_PCIIO_SIZE); 199baf37f06SPaul Burton break; 200baf37f06SPaul Burton } 20181f98bbdSPaul Burton 20281f98bbdSPaul Burton bdf = pci_find_device(PCI_VENDOR_ID_INTEL, 20381f98bbdSPaul Burton PCI_DEVICE_ID_INTEL_82371AB_0, 0); 20481f98bbdSPaul Burton if (bdf == -1) 20581f98bbdSPaul Burton panic("Failed to find PIIX4 PCI bridge\n"); 20681f98bbdSPaul Burton 20781f98bbdSPaul Burton /* setup PCI interrupt routing */ 20881f98bbdSPaul Burton pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCA, 10); 20981f98bbdSPaul Burton pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCB, 10); 21081f98bbdSPaul Burton pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCC, 11); 21181f98bbdSPaul Burton pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCD, 11); 212bea12b78SPaul Burton 213bea12b78SPaul Burton /* mux SERIRQ onto SERIRQ pin */ 214bea12b78SPaul Burton pci_read_config_dword(bdf, PCI_CFG_PIIX4_GENCFG, &val32); 215bea12b78SPaul Burton val32 |= PCI_CFG_PIIX4_GENCFG_SERIRQ; 216bea12b78SPaul Burton pci_write_config_dword(bdf, PCI_CFG_PIIX4_GENCFG, val32); 217bea12b78SPaul Burton 218bea12b78SPaul Burton /* enable SERIRQ - Linux currently depends upon this */ 219bea12b78SPaul Burton pci_read_config_byte(bdf, PCI_CFG_PIIX4_SERIRQC, &val8); 220bea12b78SPaul Burton val8 |= PCI_CFG_PIIX4_SERIRQC_EN | PCI_CFG_PIIX4_SERIRQC_CONT; 221bea12b78SPaul Burton pci_write_config_byte(bdf, PCI_CFG_PIIX4_SERIRQC, val8); 222ba21a453SPaul Burton 223ba21a453SPaul Burton bdf = pci_find_device(PCI_VENDOR_ID_INTEL, 224ba21a453SPaul Burton PCI_DEVICE_ID_INTEL_82371AB, 0); 225ba21a453SPaul Burton if (bdf == -1) 226ba21a453SPaul Burton panic("Failed to find PIIX4 IDE controller\n"); 227ba21a453SPaul Burton 228ba21a453SPaul Burton /* enable bus master & IO access */ 229ba21a453SPaul Burton val32 |= PCI_COMMAND_MASTER | PCI_COMMAND_IO; 230ba21a453SPaul Burton pci_write_config_dword(bdf, PCI_COMMAND, val32); 231ba21a453SPaul Burton 232ba21a453SPaul Burton /* set latency */ 233ba21a453SPaul Burton pci_write_config_byte(bdf, PCI_LATENCY_TIMER, 0x40); 234ba21a453SPaul Burton 235ba21a453SPaul Burton /* enable IDE/ATA */ 236ba21a453SPaul Burton pci_write_config_dword(bdf, PCI_CFG_PIIX4_IDETIM_PRI, 237ba21a453SPaul Burton PCI_CFG_PIIX4_IDETIM_IDE); 238ba21a453SPaul Burton pci_write_config_dword(bdf, PCI_CFG_PIIX4_IDETIM_SEC, 239ba21a453SPaul Burton PCI_CFG_PIIX4_IDETIM_IDE); 2407a9d109bSPaul Burton } 241