xref: /openbmc/u-boot/board/imgtec/malta/malta.c (revision e8f80a5a)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0
27a9d109bSPaul Burton /*
37a9d109bSPaul Burton  * Copyright (C) 2013 Gabor Juhos <juhosg@openwrt.org>
4baf37f06SPaul Burton  * Copyright (C) 2013 Imagination Technologies
57a9d109bSPaul Burton  */
67a9d109bSPaul Burton 
77a9d109bSPaul Burton #include <common.h>
8ba21a453SPaul Burton #include <ide.h>
97a9d109bSPaul Burton #include <netdev.h>
1081f98bbdSPaul Burton #include <pci.h>
11baf37f06SPaul Burton #include <pci_gt64120.h>
12baf37f06SPaul Burton #include <pci_msc01.h>
133ced12a0SPaul Burton #include <rtc.h>
147a9d109bSPaul Burton 
157a9d109bSPaul Burton #include <asm/addrspace.h>
167a9d109bSPaul Burton #include <asm/io.h>
177a9d109bSPaul Burton #include <asm/malta.h>
187a9d109bSPaul Burton 
19a257f626SPaul Burton #include "superio.h"
20a257f626SPaul Burton 
21088454cdSSimon Glass DECLARE_GLOBAL_DATA_PTR;
22088454cdSSimon Glass 
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 
malta_lcd_puts(const char * str)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 
malta_core_card(void)53baf37f06SPaul Burton static enum core_card malta_core_card(void)
54baf37f06SPaul Burton {
55baf37f06SPaul Burton 	u32 corid, rev;
568061cfc9SDaniel Schwierzeck 	const void *reg = (const void *)CKSEG1ADDR(MALTA_REVISION);
57baf37f06SPaul Burton 
588061cfc9SDaniel Schwierzeck 	rev = __raw_readl(reg);
59baf37f06SPaul Burton 	corid = (rev & MALTA_REVISION_CORID_MSK) >> MALTA_REVISION_CORID_SHF;
60baf37f06SPaul Burton 
61baf37f06SPaul Burton 	switch (corid) {
62baf37f06SPaul Burton 	case MALTA_REVISION_CORID_CORE_LV:
63baf37f06SPaul Burton 		return CORE_LV;
64baf37f06SPaul Burton 
65baf37f06SPaul Burton 	case MALTA_REVISION_CORID_CORE_FPGA6:
66baf37f06SPaul Burton 		return CORE_FPGA6;
67baf37f06SPaul Burton 
68baf37f06SPaul Burton 	default:
69baf37f06SPaul Burton 		return CORE_UNKNOWN;
70baf37f06SPaul Burton 	}
71baf37f06SPaul Burton }
72baf37f06SPaul Burton 
malta_sys_con(void)73baf37f06SPaul Burton static enum sys_con malta_sys_con(void)
74baf37f06SPaul Burton {
75baf37f06SPaul Burton 	switch (malta_core_card()) {
76baf37f06SPaul Burton 	case CORE_LV:
77baf37f06SPaul Burton 		return SYSCON_GT64120;
78baf37f06SPaul Burton 
79baf37f06SPaul Burton 	case CORE_FPGA6:
80baf37f06SPaul Burton 		return SYSCON_MSC01;
81baf37f06SPaul Burton 
82baf37f06SPaul Burton 	default:
83baf37f06SPaul Burton 		return SYSCON_UNKNOWN;
84baf37f06SPaul Burton 	}
85baf37f06SPaul Burton }
86baf37f06SPaul Burton 
dram_init(void)87f1683aa7SSimon Glass int dram_init(void)
887a9d109bSPaul Burton {
89088454cdSSimon Glass 	gd->ram_size = CONFIG_SYS_MEM_SIZE;
90088454cdSSimon Glass 
91088454cdSSimon Glass 	return 0;
927a9d109bSPaul Burton }
937a9d109bSPaul Burton 
checkboard(void)947a9d109bSPaul Burton int checkboard(void)
957a9d109bSPaul Burton {
96baf37f06SPaul Burton 	enum core_card core;
97baf37f06SPaul Burton 
98a187559eSBin Meng 	malta_lcd_puts("U-Boot");
99baf37f06SPaul Burton 	puts("Board: MIPS Malta");
100baf37f06SPaul Burton 
101baf37f06SPaul Burton 	core = malta_core_card();
102baf37f06SPaul Burton 	switch (core) {
103baf37f06SPaul Burton 	case CORE_LV:
104baf37f06SPaul Burton 		puts(" CoreLV");
105baf37f06SPaul Burton 		break;
106baf37f06SPaul Burton 
107baf37f06SPaul Burton 	case CORE_FPGA6:
108baf37f06SPaul Burton 		puts(" CoreFPGA6");
109baf37f06SPaul Burton 		break;
110baf37f06SPaul Burton 
111baf37f06SPaul Burton 	default:
112baf37f06SPaul Burton 		puts(" CoreUnknown");
113baf37f06SPaul Burton 	}
114baf37f06SPaul Burton 
115baf37f06SPaul Burton 	putc('\n');
1167a9d109bSPaul Burton 	return 0;
1177a9d109bSPaul Burton }
1187a9d109bSPaul Burton 
board_eth_init(bd_t * bis)1197a9d109bSPaul Burton int board_eth_init(bd_t *bis)
1207a9d109bSPaul Burton {
1217a9d109bSPaul Burton 	return pci_eth_init(bis);
1227a9d109bSPaul Burton }
1237a9d109bSPaul Burton 
_machine_restart(void)1247a9d109bSPaul Burton void _machine_restart(void)
1257a9d109bSPaul Burton {
1267a9d109bSPaul Burton 	void __iomem *reset_base;
1277a9d109bSPaul Burton 
1287a9d109bSPaul Burton 	reset_base = (void __iomem *)CKSEG1ADDR(MALTA_RESET_BASE);
1297a9d109bSPaul Burton 	__raw_writel(GORESET, reset_base);
13028c8c3d4SPaul Burton 	mdelay(1000);
1317a9d109bSPaul Burton }
1327a9d109bSPaul Burton 
board_early_init_f(void)133a257f626SPaul Burton int board_early_init_f(void)
134a257f626SPaul Burton {
13591ec615eSPaul Burton 	ulong io_base;
136baf37f06SPaul Burton 
137baf37f06SPaul Burton 	/* choose correct PCI I/O base */
138baf37f06SPaul Burton 	switch (malta_sys_con()) {
139baf37f06SPaul Burton 	case SYSCON_GT64120:
14091ec615eSPaul Burton 		io_base = CKSEG1ADDR(MALTA_GT_PCIIO_BASE);
141baf37f06SPaul Burton 		break;
142baf37f06SPaul Burton 
143baf37f06SPaul Burton 	case SYSCON_MSC01:
14491ec615eSPaul Burton 		io_base = CKSEG1ADDR(MALTA_MSC01_PCIIO_BASE);
145baf37f06SPaul Burton 		break;
146baf37f06SPaul Burton 
147baf37f06SPaul Burton 	default:
148baf37f06SPaul Burton 		return -1;
149baf37f06SPaul Burton 	}
150baf37f06SPaul Burton 
15191ec615eSPaul Burton 	set_io_port_base(io_base);
15219a5ef60SPaul Burton 
153a257f626SPaul Burton 	/* setup FDC37M817 super I/O controller */
15491ec615eSPaul Burton 	malta_superio_init();
155a257f626SPaul Burton 
156a257f626SPaul Burton 	return 0;
157a257f626SPaul Burton }
158a257f626SPaul Burton 
misc_init_r(void)1593ced12a0SPaul Burton int misc_init_r(void)
1603ced12a0SPaul Burton {
1613ced12a0SPaul Burton 	rtc_reset();
1623ced12a0SPaul Burton 
1633ced12a0SPaul Burton 	return 0;
1643ced12a0SPaul Burton }
1653ced12a0SPaul Burton 
pci_init_board(void)1667a9d109bSPaul Burton void pci_init_board(void)
1677a9d109bSPaul Burton {
16881f98bbdSPaul Burton 	pci_dev_t bdf;
169bea12b78SPaul Burton 	u32 val32;
170bea12b78SPaul Burton 	u8 val8;
17181f98bbdSPaul Burton 
172baf37f06SPaul Burton 	switch (malta_sys_con()) {
173baf37f06SPaul Burton 	case SYSCON_GT64120:
1747a9d109bSPaul Burton 		gt64120_pci_init((void *)CKSEG1ADDR(MALTA_GT_BASE),
1757a9d109bSPaul Burton 				 0x00000000, 0x00000000, CONFIG_SYS_MEM_SIZE,
1767a9d109bSPaul Burton 				 0x10000000, 0x10000000, 128 * 1024 * 1024,
1777a9d109bSPaul Burton 				 0x00000000, 0x00000000, 0x20000);
178baf37f06SPaul Burton 		break;
179baf37f06SPaul Burton 
180baf37f06SPaul Burton 	default:
181baf37f06SPaul Burton 	case SYSCON_MSC01:
182baf37f06SPaul Burton 		msc01_pci_init((void *)CKSEG1ADDR(MALTA_MSC01_PCI_BASE),
183baf37f06SPaul Burton 			       0x00000000, 0x00000000, CONFIG_SYS_MEM_SIZE,
184baf37f06SPaul Burton 			       MALTA_MSC01_PCIMEM_MAP,
185baf37f06SPaul Burton 			       CKSEG1ADDR(MALTA_MSC01_PCIMEM_BASE),
186baf37f06SPaul Burton 			       MALTA_MSC01_PCIMEM_SIZE, MALTA_MSC01_PCIIO_MAP,
187baf37f06SPaul Burton 			       0x00000000, MALTA_MSC01_PCIIO_SIZE);
188baf37f06SPaul Burton 		break;
189baf37f06SPaul Burton 	}
19081f98bbdSPaul Burton 
19181f98bbdSPaul Burton 	bdf = pci_find_device(PCI_VENDOR_ID_INTEL,
19281f98bbdSPaul Burton 			      PCI_DEVICE_ID_INTEL_82371AB_0, 0);
19381f98bbdSPaul Burton 	if (bdf == -1)
19481f98bbdSPaul Burton 		panic("Failed to find PIIX4 PCI bridge\n");
19581f98bbdSPaul Burton 
19681f98bbdSPaul Burton 	/* setup PCI interrupt routing */
19781f98bbdSPaul Burton 	pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCA, 10);
19881f98bbdSPaul Burton 	pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCB, 10);
19981f98bbdSPaul Burton 	pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCC, 11);
20081f98bbdSPaul Burton 	pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCD, 11);
201bea12b78SPaul Burton 
202bea12b78SPaul Burton 	/* mux SERIRQ onto SERIRQ pin */
203bea12b78SPaul Burton 	pci_read_config_dword(bdf, PCI_CFG_PIIX4_GENCFG, &val32);
204bea12b78SPaul Burton 	val32 |= PCI_CFG_PIIX4_GENCFG_SERIRQ;
205bea12b78SPaul Burton 	pci_write_config_dword(bdf, PCI_CFG_PIIX4_GENCFG, val32);
206bea12b78SPaul Burton 
207bea12b78SPaul Burton 	/* enable SERIRQ - Linux currently depends upon this */
208bea12b78SPaul Burton 	pci_read_config_byte(bdf, PCI_CFG_PIIX4_SERIRQC, &val8);
209bea12b78SPaul Burton 	val8 |= PCI_CFG_PIIX4_SERIRQC_EN | PCI_CFG_PIIX4_SERIRQC_CONT;
210bea12b78SPaul Burton 	pci_write_config_byte(bdf, PCI_CFG_PIIX4_SERIRQC, val8);
211ba21a453SPaul Burton 
212ba21a453SPaul Burton 	bdf = pci_find_device(PCI_VENDOR_ID_INTEL,
213ba21a453SPaul Burton 			      PCI_DEVICE_ID_INTEL_82371AB, 0);
214ba21a453SPaul Burton 	if (bdf == -1)
215ba21a453SPaul Burton 		panic("Failed to find PIIX4 IDE controller\n");
216ba21a453SPaul Burton 
217ba21a453SPaul Burton 	/* enable bus master & IO access */
218ba21a453SPaul Burton 	val32 |= PCI_COMMAND_MASTER | PCI_COMMAND_IO;
219ba21a453SPaul Burton 	pci_write_config_dword(bdf, PCI_COMMAND, val32);
220ba21a453SPaul Burton 
221ba21a453SPaul Burton 	/* set latency */
222ba21a453SPaul Burton 	pci_write_config_byte(bdf, PCI_LATENCY_TIMER, 0x40);
223ba21a453SPaul Burton 
224ba21a453SPaul Burton 	/* enable IDE/ATA */
225ba21a453SPaul Burton 	pci_write_config_dword(bdf, PCI_CFG_PIIX4_IDETIM_PRI,
226ba21a453SPaul Burton 			       PCI_CFG_PIIX4_IDETIM_IDE);
227ba21a453SPaul Burton 	pci_write_config_dword(bdf, PCI_CFG_PIIX4_IDETIM_SEC,
228ba21a453SPaul Burton 			       PCI_CFG_PIIX4_IDETIM_IDE);
2297a9d109bSPaul Burton }
230