blob: 4a72ab5cecad5ffcaf6d2d98dcee4474de202e5f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Gabor Juhos02c754a2013-05-22 03:57:37 +00002/*
3 * Copyright (C) 2013 Gabor Juhos <juhosg@openwrt.org>
Paul Burton234882c2013-11-08 11:18:50 +00004 * Copyright (C) 2013 Imagination Technologies
Gabor Juhos02c754a2013-05-22 03:57:37 +00005 */
6
Daniel Schwierzeck09d32c02021-07-15 20:54:00 +02007#include <config.h>
8#include <fdt_support.h>
Paul Burtonc6c38532015-01-29 10:38:20 +00009#include <ide.h>
Simon Glass18afe102019-11-14 12:57:47 -070010#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060011#include <net.h>
Gabor Juhos439c50c2013-05-22 03:57:44 +000012#include <netdev.h>
Paul Burton12ab4ab2013-11-08 11:18:57 +000013#include <pci.h>
Paul Burton234882c2013-11-08 11:18:50 +000014#include <pci_gt64120.h>
15#include <pci_msc01.h>
Paul Burtonc028f9b2013-11-08 11:18:55 +000016#include <rtc.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Simon Glassdbd79542020-05-10 11:40:11 -060018#include <linux/delay.h>
Gabor Juhos02c754a2013-05-22 03:57:37 +000019
Gabor Juhos652ccee2013-05-22 03:57:42 +000020#include <asm/addrspace.h>
Gabor Juhosaed4fa42013-05-22 03:57:38 +000021#include <asm/io.h>
22#include <asm/malta.h>
23
Paul Burton7fb05072013-11-08 11:18:49 +000024#include "superio.h"
25
Simon Glass39f90ba2017-03-31 08:40:25 -060026DECLARE_GLOBAL_DATA_PTR;
27
Daniel Schwierzeck09d32c02021-07-15 20:54:00 +020028#define MALTA_GT_PATH "/pci0@1be00000"
29#define MALTA_MSC_PATH "/pci0@1bd00000"
30
Paul Burton234882c2013-11-08 11:18:50 +000031enum core_card {
32 CORE_UNKNOWN,
33 CORE_LV,
34 CORE_FPGA6,
35};
36
37enum sys_con {
38 SYSCON_UNKNOWN,
39 SYSCON_GT64120,
40 SYSCON_MSC01,
41};
42
Paul Burton7c8835b2013-11-08 11:18:51 +000043static void malta_lcd_puts(const char *str)
44{
45 int i;
46 void *reg = (void *)CKSEG1ADDR(MALTA_ASCIIPOS0);
47
48 /* print up to 8 characters of the string */
Masahiro Yamadadb204642014-11-07 03:03:31 +090049 for (i = 0; i < min((int)strlen(str), 8); i++) {
Paul Burton7c8835b2013-11-08 11:18:51 +000050 __raw_writel(str[i], reg);
51 reg += MALTA_ASCIIPOS1 - MALTA_ASCIIPOS0;
52 }
53
54 /* fill the rest of the display with spaces */
55 for (; i < 8; i++) {
56 __raw_writel(' ', reg);
57 reg += MALTA_ASCIIPOS1 - MALTA_ASCIIPOS0;
58 }
59}
60
Paul Burton234882c2013-11-08 11:18:50 +000061static enum core_card malta_core_card(void)
62{
63 u32 corid, rev;
Daniel Schwierzeck36eb0532016-01-09 17:32:45 +010064 const void *reg = (const void *)CKSEG1ADDR(MALTA_REVISION);
Paul Burton234882c2013-11-08 11:18:50 +000065
Daniel Schwierzeck36eb0532016-01-09 17:32:45 +010066 rev = __raw_readl(reg);
Paul Burton234882c2013-11-08 11:18:50 +000067 corid = (rev & MALTA_REVISION_CORID_MSK) >> MALTA_REVISION_CORID_SHF;
68
69 switch (corid) {
70 case MALTA_REVISION_CORID_CORE_LV:
71 return CORE_LV;
72
73 case MALTA_REVISION_CORID_CORE_FPGA6:
74 return CORE_FPGA6;
75
76 default:
77 return CORE_UNKNOWN;
78 }
79}
80
81static enum sys_con malta_sys_con(void)
82{
83 switch (malta_core_card()) {
84 case CORE_LV:
85 return SYSCON_GT64120;
86
87 case CORE_FPGA6:
88 return SYSCON_MSC01;
89
90 default:
91 return SYSCON_UNKNOWN;
92 }
93}
94
Simon Glassd35f3382017-04-06 12:47:05 -060095int dram_init(void)
Gabor Juhos02c754a2013-05-22 03:57:37 +000096{
Tom Rinibb4dd962022-11-16 13:10:37 -050097 gd->ram_size = CFG_SYS_SDRAM_SIZE;
Simon Glass39f90ba2017-03-31 08:40:25 -060098
99 return 0;
Gabor Juhos02c754a2013-05-22 03:57:37 +0000100}
101
102int checkboard(void)
103{
Paul Burton234882c2013-11-08 11:18:50 +0000104 enum core_card core;
105
Bin Meng75574052016-02-05 19:30:11 -0800106 malta_lcd_puts("U-Boot");
Paul Burton234882c2013-11-08 11:18:50 +0000107 puts("Board: MIPS Malta");
108
109 core = malta_core_card();
110 switch (core) {
111 case CORE_LV:
112 puts(" CoreLV");
113 break;
114
115 case CORE_FPGA6:
116 puts(" CoreFPGA6");
117 break;
118
119 default:
120 puts(" CoreUnknown");
121 }
122
123 putc('\n');
Gabor Juhos02c754a2013-05-22 03:57:37 +0000124 return 0;
125}
Gabor Juhosaed4fa42013-05-22 03:57:38 +0000126
Daniel Schwierzeck09d32c02021-07-15 20:54:00 +0200127#if !IS_ENABLED(CONFIG_DM_ETH)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900128int board_eth_init(struct bd_info *bis)
Gabor Juhos439c50c2013-05-22 03:57:44 +0000129{
130 return pci_eth_init(bis);
131}
Daniel Schwierzeck09d32c02021-07-15 20:54:00 +0200132#endif
Gabor Juhos439c50c2013-05-22 03:57:44 +0000133
Gabor Juhosaed4fa42013-05-22 03:57:38 +0000134void _machine_restart(void)
135{
136 void __iomem *reset_base;
137
138 reset_base = (void __iomem *)CKSEG1ADDR(MALTA_RESET_BASE);
139 __raw_writel(GORESET, reset_base);
Paul Burtonee6af872015-01-29 10:38:21 +0000140 mdelay(1000);
Gabor Juhosaed4fa42013-05-22 03:57:38 +0000141}
Gabor Juhos652ccee2013-05-22 03:57:42 +0000142
Paul Burton7fb05072013-11-08 11:18:49 +0000143int board_early_init_f(void)
144{
Paul Burtondd37a142016-01-29 13:54:54 +0000145 ulong io_base;
Paul Burton234882c2013-11-08 11:18:50 +0000146
147 /* choose correct PCI I/O base */
148 switch (malta_sys_con()) {
149 case SYSCON_GT64120:
Paul Burtondd37a142016-01-29 13:54:54 +0000150 io_base = CKSEG1ADDR(MALTA_GT_PCIIO_BASE);
Paul Burton234882c2013-11-08 11:18:50 +0000151 break;
152
153 case SYSCON_MSC01:
Paul Burtondd37a142016-01-29 13:54:54 +0000154 io_base = CKSEG1ADDR(MALTA_MSC01_PCIIO_BASE);
Paul Burton234882c2013-11-08 11:18:50 +0000155 break;
156
157 default:
158 return -1;
159 }
160
Paul Burtondd37a142016-01-29 13:54:54 +0000161 set_io_port_base(io_base);
Paul Burton2e9b2a92016-01-29 13:54:53 +0000162
Paul Burton7fb05072013-11-08 11:18:49 +0000163 /* setup FDC37M817 super I/O controller */
Paul Burtondd37a142016-01-29 13:54:54 +0000164 malta_superio_init();
Paul Burton7fb05072013-11-08 11:18:49 +0000165
166 return 0;
167}
168
Paul Burtonc028f9b2013-11-08 11:18:55 +0000169int misc_init_r(void)
170{
171 rtc_reset();
172
173 return 0;
174}
175
Daniel Schwierzeck09d32c02021-07-15 20:54:00 +0200176#if IS_ENABLED(CONFIG_OF_BOARD_FIXUP)
177/*
178 * TODO: currently doesn't work because rw_fdt_blob points to a
179 * NOR flash address. This needs some changes in board_init_f.
180 */
181int board_fix_fdt(void *rw_fdt_blob)
182{
183 int node = -1;
184
185 switch (malta_sys_con()) {
186 case SYSCON_GT64120:
187 node = fdt_path_offset(rw_fdt_blob, MALTA_GT_PATH);
188 break;
189 default:
190 case SYSCON_MSC01:
191 node = fdt_path_offset(rw_fdt_blob, MALTA_MSC_PATH);
192 break;
193 }
194
195 return fdt_status_okay(rw_fdt_blob, node);
196}
197#endif
198
Daniel Schwierzeck09d32c02021-07-15 20:54:00 +0200199int board_early_init_r(void)
200{
201 struct udevice *dev;
202 int ret;
203
204 pci_init();
205
206 ret = dm_pci_find_device(PCI_VENDOR_ID_INTEL,
207 PCI_DEVICE_ID_INTEL_82371AB_0, 0, &dev);
208 if (ret)
209 panic("Failed to find PIIX4 PCI bridge\n");
210
211 /* setup PCI interrupt routing */
212 dm_pci_write_config8(dev, PCI_CFG_PIIX4_PIRQRCA, 10);
213 dm_pci_write_config8(dev, PCI_CFG_PIIX4_PIRQRCB, 10);
214 dm_pci_write_config8(dev, PCI_CFG_PIIX4_PIRQRCC, 11);
215 dm_pci_write_config8(dev, PCI_CFG_PIIX4_PIRQRCD, 11);
216
217 /* mux SERIRQ onto SERIRQ pin */
218 dm_pci_clrset_config32(dev, PCI_CFG_PIIX4_GENCFG, 0,
219 PCI_CFG_PIIX4_GENCFG_SERIRQ);
220
221 /* enable SERIRQ - Linux currently depends upon this */
222 dm_pci_clrset_config8(dev, PCI_CFG_PIIX4_SERIRQC, 0,
223 PCI_CFG_PIIX4_SERIRQC_EN | PCI_CFG_PIIX4_SERIRQC_CONT);
224
225 ret = dm_pci_find_device(PCI_VENDOR_ID_INTEL,
226 PCI_DEVICE_ID_INTEL_82371AB, 0, &dev);
227 if (ret)
228 panic("Failed to find PIIX4 IDE controller\n");
229
230 /* enable bus master & IO access */
231 dm_pci_clrset_config32(dev, PCI_COMMAND, 0,
232 PCI_COMMAND_MASTER | PCI_COMMAND_IO);
233
234 /* set latency */
235 dm_pci_write_config8(dev, PCI_LATENCY_TIMER, 0x40);
236
237 /* enable IDE/ATA */
238 dm_pci_write_config32(dev, PCI_CFG_PIIX4_IDETIM_PRI,
239 PCI_CFG_PIIX4_IDETIM_IDE);
240 dm_pci_write_config32(dev, PCI_CFG_PIIX4_IDETIM_SEC,
241 PCI_CFG_PIIX4_IDETIM_IDE);
242
243 return 0;
244}