blob: 88a1a63bf48866d15a43ee35faf3bf06f7bcf014 [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 Glassc05ed002020-05-10 11:40:11 -060016#include <linux/delay.h>
Gabor Juhos5a4dcfa2013-05-22 03:57:37 +000017
Gabor Juhosfeaa6062013-05-22 03:57:42 +000018#include <asm/addrspace.h>
Gabor Juhos01564312013-05-22 03:57:38 +000019#include <asm/io.h>
20#include <asm/malta.h>
21
Paul Burtona257f622013-11-08 11:18:49 +000022#include "superio.h"
23
Simon Glass088454c2017-03-31 08:40:25 -060024DECLARE_GLOBAL_DATA_PTR;
25
Paul Burtonbaf37f02013-11-08 11:18:50 +000026enum core_card {
27 CORE_UNKNOWN,
28 CORE_LV,
29 CORE_FPGA6,
30};
31
32enum sys_con {
33 SYSCON_UNKNOWN,
34 SYSCON_GT64120,
35 SYSCON_MSC01,
36};
37
Paul Burtone0ada632013-11-08 11:18:51 +000038static void malta_lcd_puts(const char *str)
39{
40 int i;
41 void *reg = (void *)CKSEG1ADDR(MALTA_ASCIIPOS0);
42
43 /* print up to 8 characters of the string */
Masahiro Yamadab4141192014-11-07 03:03:31 +090044 for (i = 0; i < min((int)strlen(str), 8); i++) {
Paul Burtone0ada632013-11-08 11:18:51 +000045 __raw_writel(str[i], reg);
46 reg += MALTA_ASCIIPOS1 - MALTA_ASCIIPOS0;
47 }
48
49 /* fill the rest of the display with spaces */
50 for (; i < 8; i++) {
51 __raw_writel(' ', reg);
52 reg += MALTA_ASCIIPOS1 - MALTA_ASCIIPOS0;
53 }
54}
55
Paul Burtonbaf37f02013-11-08 11:18:50 +000056static enum core_card malta_core_card(void)
57{
58 u32 corid, rev;
Daniel Schwierzeck8061cfc2016-01-09 17:32:45 +010059 const void *reg = (const void *)CKSEG1ADDR(MALTA_REVISION);
Paul Burtonbaf37f02013-11-08 11:18:50 +000060
Daniel Schwierzeck8061cfc2016-01-09 17:32:45 +010061 rev = __raw_readl(reg);
Paul Burtonbaf37f02013-11-08 11:18:50 +000062 corid = (rev & MALTA_REVISION_CORID_MSK) >> MALTA_REVISION_CORID_SHF;
63
64 switch (corid) {
65 case MALTA_REVISION_CORID_CORE_LV:
66 return CORE_LV;
67
68 case MALTA_REVISION_CORID_CORE_FPGA6:
69 return CORE_FPGA6;
70
71 default:
72 return CORE_UNKNOWN;
73 }
74}
75
76static enum sys_con malta_sys_con(void)
77{
78 switch (malta_core_card()) {
79 case CORE_LV:
80 return SYSCON_GT64120;
81
82 case CORE_FPGA6:
83 return SYSCON_MSC01;
84
85 default:
86 return SYSCON_UNKNOWN;
87 }
88}
89
Simon Glassf1683aa2017-04-06 12:47:05 -060090int dram_init(void)
Gabor Juhos5a4dcfa2013-05-22 03:57:37 +000091{
Simon Glass088454c2017-03-31 08:40:25 -060092 gd->ram_size = CONFIG_SYS_MEM_SIZE;
93
94 return 0;
Gabor Juhos5a4dcfa2013-05-22 03:57:37 +000095}
96
97int checkboard(void)
98{
Paul Burtonbaf37f02013-11-08 11:18:50 +000099 enum core_card core;
100
Bin Menga1875592016-02-05 19:30:11 -0800101 malta_lcd_puts("U-Boot");
Paul Burtonbaf37f02013-11-08 11:18:50 +0000102 puts("Board: MIPS Malta");
103
104 core = malta_core_card();
105 switch (core) {
106 case CORE_LV:
107 puts(" CoreLV");
108 break;
109
110 case CORE_FPGA6:
111 puts(" CoreFPGA6");
112 break;
113
114 default:
115 puts(" CoreUnknown");
116 }
117
118 putc('\n');
Gabor Juhos5a4dcfa2013-05-22 03:57:37 +0000119 return 0;
120}
Gabor Juhos01564312013-05-22 03:57:38 +0000121
Gabor Juhosf1957492013-05-22 03:57:44 +0000122int board_eth_init(bd_t *bis)
123{
124 return pci_eth_init(bis);
125}
126
Gabor Juhos01564312013-05-22 03:57:38 +0000127void _machine_restart(void)
128{
129 void __iomem *reset_base;
130
131 reset_base = (void __iomem *)CKSEG1ADDR(MALTA_RESET_BASE);
132 __raw_writel(GORESET, reset_base);
Paul Burton28c8c3d2015-01-29 10:38:21 +0000133 mdelay(1000);
Gabor Juhos01564312013-05-22 03:57:38 +0000134}
Gabor Juhosfeaa6062013-05-22 03:57:42 +0000135
Paul Burtona257f622013-11-08 11:18:49 +0000136int board_early_init_f(void)
137{
Paul Burton91ec6152016-01-29 13:54:54 +0000138 ulong io_base;
Paul Burtonbaf37f02013-11-08 11:18:50 +0000139
140 /* choose correct PCI I/O base */
141 switch (malta_sys_con()) {
142 case SYSCON_GT64120:
Paul Burton91ec6152016-01-29 13:54:54 +0000143 io_base = CKSEG1ADDR(MALTA_GT_PCIIO_BASE);
Paul Burtonbaf37f02013-11-08 11:18:50 +0000144 break;
145
146 case SYSCON_MSC01:
Paul Burton91ec6152016-01-29 13:54:54 +0000147 io_base = CKSEG1ADDR(MALTA_MSC01_PCIIO_BASE);
Paul Burtonbaf37f02013-11-08 11:18:50 +0000148 break;
149
150 default:
151 return -1;
152 }
153
Paul Burton91ec6152016-01-29 13:54:54 +0000154 set_io_port_base(io_base);
Paul Burton19a5ef62016-01-29 13:54:53 +0000155
Paul Burtona257f622013-11-08 11:18:49 +0000156 /* setup FDC37M817 super I/O controller */
Paul Burton91ec6152016-01-29 13:54:54 +0000157 malta_superio_init();
Paul Burtona257f622013-11-08 11:18:49 +0000158
159 return 0;
160}
161
Paul Burton3ced12a2013-11-08 11:18:55 +0000162int misc_init_r(void)
163{
164 rtc_reset();
165
166 return 0;
167}
168
Gabor Juhosfeaa6062013-05-22 03:57:42 +0000169void pci_init_board(void)
170{
Paul Burton81f98bb2013-11-08 11:18:57 +0000171 pci_dev_t bdf;
Paul Burtonbea12b72013-11-26 17:45:27 +0000172 u32 val32;
173 u8 val8;
Paul Burton81f98bb2013-11-08 11:18:57 +0000174
Paul Burtonbaf37f02013-11-08 11:18:50 +0000175 switch (malta_sys_con()) {
176 case SYSCON_GT64120:
Paul Burtonbaf37f02013-11-08 11:18:50 +0000177 gt64120_pci_init((void *)CKSEG1ADDR(MALTA_GT_BASE),
178 0x00000000, 0x00000000, CONFIG_SYS_MEM_SIZE,
179 0x10000000, 0x10000000, 128 * 1024 * 1024,
180 0x00000000, 0x00000000, 0x20000);
181 break;
182
183 default:
184 case SYSCON_MSC01:
Paul Burtonbaf37f02013-11-08 11:18:50 +0000185 msc01_pci_init((void *)CKSEG1ADDR(MALTA_MSC01_PCI_BASE),
186 0x00000000, 0x00000000, CONFIG_SYS_MEM_SIZE,
187 MALTA_MSC01_PCIMEM_MAP,
188 CKSEG1ADDR(MALTA_MSC01_PCIMEM_BASE),
189 MALTA_MSC01_PCIMEM_SIZE, MALTA_MSC01_PCIIO_MAP,
190 0x00000000, MALTA_MSC01_PCIIO_SIZE);
191 break;
192 }
Paul Burton81f98bb2013-11-08 11:18:57 +0000193
194 bdf = pci_find_device(PCI_VENDOR_ID_INTEL,
195 PCI_DEVICE_ID_INTEL_82371AB_0, 0);
196 if (bdf == -1)
197 panic("Failed to find PIIX4 PCI bridge\n");
198
199 /* setup PCI interrupt routing */
200 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCA, 10);
201 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCB, 10);
202 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCC, 11);
203 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCD, 11);
Paul Burtonbea12b72013-11-26 17:45:27 +0000204
205 /* mux SERIRQ onto SERIRQ pin */
206 pci_read_config_dword(bdf, PCI_CFG_PIIX4_GENCFG, &val32);
207 val32 |= PCI_CFG_PIIX4_GENCFG_SERIRQ;
208 pci_write_config_dword(bdf, PCI_CFG_PIIX4_GENCFG, val32);
209
210 /* enable SERIRQ - Linux currently depends upon this */
211 pci_read_config_byte(bdf, PCI_CFG_PIIX4_SERIRQC, &val8);
212 val8 |= PCI_CFG_PIIX4_SERIRQC_EN | PCI_CFG_PIIX4_SERIRQC_CONT;
213 pci_write_config_byte(bdf, PCI_CFG_PIIX4_SERIRQC, val8);
Paul Burtonba21a452015-01-29 10:38:20 +0000214
215 bdf = pci_find_device(PCI_VENDOR_ID_INTEL,
216 PCI_DEVICE_ID_INTEL_82371AB, 0);
217 if (bdf == -1)
218 panic("Failed to find PIIX4 IDE controller\n");
219
220 /* enable bus master & IO access */
221 val32 |= PCI_COMMAND_MASTER | PCI_COMMAND_IO;
222 pci_write_config_dword(bdf, PCI_COMMAND, val32);
223
224 /* set latency */
225 pci_write_config_byte(bdf, PCI_LATENCY_TIMER, 0x40);
226
227 /* enable IDE/ATA */
228 pci_write_config_dword(bdf, PCI_CFG_PIIX4_IDETIM_PRI,
229 PCI_CFG_PIIX4_IDETIM_IDE);
230 pci_write_config_dword(bdf, PCI_CFG_PIIX4_IDETIM_SEC,
231 PCI_CFG_PIIX4_IDETIM_IDE);
Gabor Juhosfeaa6062013-05-22 03:57:42 +0000232}