blob: c04f727961decf7fb2a72b2361b5f1fa11b1cea9 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Gabor Juhos5a4dcfa2013-05-22 03:57:37 +00002/*
3 * Copyright (C) 2013 Gabor Juhos <juhosg@openwrt.org>
Paul Burtonbaf37f02013-11-08 11:18:50 +00004 * Copyright (C) 2013 Imagination Technologies
Gabor Juhos5a4dcfa2013-05-22 03:57:37 +00005 */
6
7#include <common.h>
Paul Burtonba21a452015-01-29 10:38:20 +00008#include <ide.h>
Simon Glass2cf431c2019-11-14 12:57:47 -07009#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -060010#include <net.h>
Gabor Juhosf1957492013-05-22 03:57:44 +000011#include <netdev.h>
Paul Burton81f98bb2013-11-08 11:18:57 +000012#include <pci.h>
Paul Burtonbaf37f02013-11-08 11:18:50 +000013#include <pci_gt64120.h>
14#include <pci_msc01.h>
Paul Burton3ced12a2013-11-08 11:18:55 +000015#include <rtc.h>
Simon Glass401d1c42020-10-30 21:38:53 -060016#include <asm/global_data.h>
Simon Glassc05ed002020-05-10 11:40:11 -060017#include <linux/delay.h>
Gabor Juhos5a4dcfa2013-05-22 03:57:37 +000018
Gabor Juhosfeaa6062013-05-22 03:57:42 +000019#include <asm/addrspace.h>
Gabor Juhos01564312013-05-22 03:57:38 +000020#include <asm/io.h>
21#include <asm/malta.h>
22
Paul Burtona257f622013-11-08 11:18:49 +000023#include "superio.h"
24
Simon Glass088454c2017-03-31 08:40:25 -060025DECLARE_GLOBAL_DATA_PTR;
26
Paul Burtonbaf37f02013-11-08 11:18:50 +000027enum core_card {
28 CORE_UNKNOWN,
29 CORE_LV,
30 CORE_FPGA6,
31};
32
33enum sys_con {
34 SYSCON_UNKNOWN,
35 SYSCON_GT64120,
36 SYSCON_MSC01,
37};
38
Paul Burtone0ada632013-11-08 11:18:51 +000039static void malta_lcd_puts(const char *str)
40{
41 int i;
42 void *reg = (void *)CKSEG1ADDR(MALTA_ASCIIPOS0);
43
44 /* print up to 8 characters of the string */
Masahiro Yamadab4141192014-11-07 03:03:31 +090045 for (i = 0; i < min((int)strlen(str), 8); i++) {
Paul Burtone0ada632013-11-08 11:18:51 +000046 __raw_writel(str[i], reg);
47 reg += MALTA_ASCIIPOS1 - MALTA_ASCIIPOS0;
48 }
49
50 /* fill the rest of the display with spaces */
51 for (; i < 8; i++) {
52 __raw_writel(' ', reg);
53 reg += MALTA_ASCIIPOS1 - MALTA_ASCIIPOS0;
54 }
55}
56
Paul Burtonbaf37f02013-11-08 11:18:50 +000057static enum core_card malta_core_card(void)
58{
59 u32 corid, rev;
Daniel Schwierzeck8061cfc2016-01-09 17:32:45 +010060 const void *reg = (const void *)CKSEG1ADDR(MALTA_REVISION);
Paul Burtonbaf37f02013-11-08 11:18:50 +000061
Daniel Schwierzeck8061cfc2016-01-09 17:32:45 +010062 rev = __raw_readl(reg);
Paul Burtonbaf37f02013-11-08 11:18:50 +000063 corid = (rev & MALTA_REVISION_CORID_MSK) >> MALTA_REVISION_CORID_SHF;
64
65 switch (corid) {
66 case MALTA_REVISION_CORID_CORE_LV:
67 return CORE_LV;
68
69 case MALTA_REVISION_CORID_CORE_FPGA6:
70 return CORE_FPGA6;
71
72 default:
73 return CORE_UNKNOWN;
74 }
75}
76
77static enum sys_con malta_sys_con(void)
78{
79 switch (malta_core_card()) {
80 case CORE_LV:
81 return SYSCON_GT64120;
82
83 case CORE_FPGA6:
84 return SYSCON_MSC01;
85
86 default:
87 return SYSCON_UNKNOWN;
88 }
89}
90
Simon Glassf1683aa2017-04-06 12:47:05 -060091int dram_init(void)
Gabor Juhos5a4dcfa2013-05-22 03:57:37 +000092{
Simon Glass088454c2017-03-31 08:40:25 -060093 gd->ram_size = CONFIG_SYS_MEM_SIZE;
94
95 return 0;
Gabor Juhos5a4dcfa2013-05-22 03:57:37 +000096}
97
98int checkboard(void)
99{
Paul Burtonbaf37f02013-11-08 11:18:50 +0000100 enum core_card core;
101
Bin Menga1875592016-02-05 19:30:11 -0800102 malta_lcd_puts("U-Boot");
Paul Burtonbaf37f02013-11-08 11:18:50 +0000103 puts("Board: MIPS Malta");
104
105 core = malta_core_card();
106 switch (core) {
107 case CORE_LV:
108 puts(" CoreLV");
109 break;
110
111 case CORE_FPGA6:
112 puts(" CoreFPGA6");
113 break;
114
115 default:
116 puts(" CoreUnknown");
117 }
118
119 putc('\n');
Gabor Juhos5a4dcfa2013-05-22 03:57:37 +0000120 return 0;
121}
Gabor Juhos01564312013-05-22 03:57:38 +0000122
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900123int board_eth_init(struct bd_info *bis)
Gabor Juhosf1957492013-05-22 03:57:44 +0000124{
125 return pci_eth_init(bis);
126}
127
Gabor Juhos01564312013-05-22 03:57:38 +0000128void _machine_restart(void)
129{
130 void __iomem *reset_base;
131
132 reset_base = (void __iomem *)CKSEG1ADDR(MALTA_RESET_BASE);
133 __raw_writel(GORESET, reset_base);
Paul Burton28c8c3d2015-01-29 10:38:21 +0000134 mdelay(1000);
Gabor Juhos01564312013-05-22 03:57:38 +0000135}
Gabor Juhosfeaa6062013-05-22 03:57:42 +0000136
Paul Burtona257f622013-11-08 11:18:49 +0000137int board_early_init_f(void)
138{
Paul Burton91ec6152016-01-29 13:54:54 +0000139 ulong io_base;
Paul Burtonbaf37f02013-11-08 11:18:50 +0000140
141 /* choose correct PCI I/O base */
142 switch (malta_sys_con()) {
143 case SYSCON_GT64120:
Paul Burton91ec6152016-01-29 13:54:54 +0000144 io_base = CKSEG1ADDR(MALTA_GT_PCIIO_BASE);
Paul Burtonbaf37f02013-11-08 11:18:50 +0000145 break;
146
147 case SYSCON_MSC01:
Paul Burton91ec6152016-01-29 13:54:54 +0000148 io_base = CKSEG1ADDR(MALTA_MSC01_PCIIO_BASE);
Paul Burtonbaf37f02013-11-08 11:18:50 +0000149 break;
150
151 default:
152 return -1;
153 }
154
Paul Burton91ec6152016-01-29 13:54:54 +0000155 set_io_port_base(io_base);
Paul Burton19a5ef62016-01-29 13:54:53 +0000156
Paul Burtona257f622013-11-08 11:18:49 +0000157 /* setup FDC37M817 super I/O controller */
Paul Burton91ec6152016-01-29 13:54:54 +0000158 malta_superio_init();
Paul Burtona257f622013-11-08 11:18:49 +0000159
160 return 0;
161}
162
Paul Burton3ced12a2013-11-08 11:18:55 +0000163int misc_init_r(void)
164{
165 rtc_reset();
166
167 return 0;
168}
169
Gabor Juhosfeaa6062013-05-22 03:57:42 +0000170void pci_init_board(void)
171{
Paul Burton81f98bb2013-11-08 11:18:57 +0000172 pci_dev_t bdf;
Paul Burtonbea12b72013-11-26 17:45:27 +0000173 u32 val32;
174 u8 val8;
Paul Burton81f98bb2013-11-08 11:18:57 +0000175
Paul Burtonbaf37f02013-11-08 11:18:50 +0000176 switch (malta_sys_con()) {
177 case SYSCON_GT64120:
Paul Burtonbaf37f02013-11-08 11:18:50 +0000178 gt64120_pci_init((void *)CKSEG1ADDR(MALTA_GT_BASE),
179 0x00000000, 0x00000000, CONFIG_SYS_MEM_SIZE,
180 0x10000000, 0x10000000, 128 * 1024 * 1024,
181 0x00000000, 0x00000000, 0x20000);
182 break;
183
184 default:
185 case SYSCON_MSC01:
Paul Burtonbaf37f02013-11-08 11:18:50 +0000186 msc01_pci_init((void *)CKSEG1ADDR(MALTA_MSC01_PCI_BASE),
187 0x00000000, 0x00000000, CONFIG_SYS_MEM_SIZE,
188 MALTA_MSC01_PCIMEM_MAP,
189 CKSEG1ADDR(MALTA_MSC01_PCIMEM_BASE),
190 MALTA_MSC01_PCIMEM_SIZE, MALTA_MSC01_PCIIO_MAP,
191 0x00000000, MALTA_MSC01_PCIIO_SIZE);
192 break;
193 }
Paul Burton81f98bb2013-11-08 11:18:57 +0000194
195 bdf = pci_find_device(PCI_VENDOR_ID_INTEL,
196 PCI_DEVICE_ID_INTEL_82371AB_0, 0);
197 if (bdf == -1)
198 panic("Failed to find PIIX4 PCI bridge\n");
199
200 /* setup PCI interrupt routing */
201 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCA, 10);
202 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCB, 10);
203 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCC, 11);
204 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCD, 11);
Paul Burtonbea12b72013-11-26 17:45:27 +0000205
206 /* mux SERIRQ onto SERIRQ pin */
207 pci_read_config_dword(bdf, PCI_CFG_PIIX4_GENCFG, &val32);
208 val32 |= PCI_CFG_PIIX4_GENCFG_SERIRQ;
209 pci_write_config_dword(bdf, PCI_CFG_PIIX4_GENCFG, val32);
210
211 /* enable SERIRQ - Linux currently depends upon this */
212 pci_read_config_byte(bdf, PCI_CFG_PIIX4_SERIRQC, &val8);
213 val8 |= PCI_CFG_PIIX4_SERIRQC_EN | PCI_CFG_PIIX4_SERIRQC_CONT;
214 pci_write_config_byte(bdf, PCI_CFG_PIIX4_SERIRQC, val8);
Paul Burtonba21a452015-01-29 10:38:20 +0000215
216 bdf = pci_find_device(PCI_VENDOR_ID_INTEL,
217 PCI_DEVICE_ID_INTEL_82371AB, 0);
218 if (bdf == -1)
219 panic("Failed to find PIIX4 IDE controller\n");
220
221 /* enable bus master & IO access */
222 val32 |= PCI_COMMAND_MASTER | PCI_COMMAND_IO;
223 pci_write_config_dword(bdf, PCI_COMMAND, val32);
224
225 /* set latency */
226 pci_write_config_byte(bdf, PCI_LATENCY_TIMER, 0x40);
227
228 /* enable IDE/ATA */
229 pci_write_config_dword(bdf, PCI_CFG_PIIX4_IDETIM_PRI,
230 PCI_CFG_PIIX4_IDETIM_IDE);
231 pci_write_config_dword(bdf, PCI_CFG_PIIX4_IDETIM_SEC,
232 PCI_CFG_PIIX4_IDETIM_IDE);
Gabor Juhosfeaa6062013-05-22 03:57:42 +0000233}