blob: 80005ec3cc1036302a6966f52dd1f3b0693b189a [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>
Gabor Juhos5a4dcfa2013-05-22 03:57:37 +000016
Gabor Juhosfeaa6062013-05-22 03:57:42 +000017#include <asm/addrspace.h>
Gabor Juhos01564312013-05-22 03:57:38 +000018#include <asm/io.h>
19#include <asm/malta.h>
20
Paul Burtona257f622013-11-08 11:18:49 +000021#include "superio.h"
22
Simon Glass088454c2017-03-31 08:40:25 -060023DECLARE_GLOBAL_DATA_PTR;
24
Paul Burtonbaf37f02013-11-08 11:18:50 +000025enum core_card {
26 CORE_UNKNOWN,
27 CORE_LV,
28 CORE_FPGA6,
29};
30
31enum sys_con {
32 SYSCON_UNKNOWN,
33 SYSCON_GT64120,
34 SYSCON_MSC01,
35};
36
Paul Burtone0ada632013-11-08 11:18:51 +000037static void malta_lcd_puts(const char *str)
38{
39 int i;
40 void *reg = (void *)CKSEG1ADDR(MALTA_ASCIIPOS0);
41
42 /* print up to 8 characters of the string */
Masahiro Yamadab4141192014-11-07 03:03:31 +090043 for (i = 0; i < min((int)strlen(str), 8); i++) {
Paul Burtone0ada632013-11-08 11:18:51 +000044 __raw_writel(str[i], reg);
45 reg += MALTA_ASCIIPOS1 - MALTA_ASCIIPOS0;
46 }
47
48 /* fill the rest of the display with spaces */
49 for (; i < 8; i++) {
50 __raw_writel(' ', reg);
51 reg += MALTA_ASCIIPOS1 - MALTA_ASCIIPOS0;
52 }
53}
54
Paul Burtonbaf37f02013-11-08 11:18:50 +000055static enum core_card malta_core_card(void)
56{
57 u32 corid, rev;
Daniel Schwierzeck8061cfc2016-01-09 17:32:45 +010058 const void *reg = (const void *)CKSEG1ADDR(MALTA_REVISION);
Paul Burtonbaf37f02013-11-08 11:18:50 +000059
Daniel Schwierzeck8061cfc2016-01-09 17:32:45 +010060 rev = __raw_readl(reg);
Paul Burtonbaf37f02013-11-08 11:18:50 +000061 corid = (rev & MALTA_REVISION_CORID_MSK) >> MALTA_REVISION_CORID_SHF;
62
63 switch (corid) {
64 case MALTA_REVISION_CORID_CORE_LV:
65 return CORE_LV;
66
67 case MALTA_REVISION_CORID_CORE_FPGA6:
68 return CORE_FPGA6;
69
70 default:
71 return CORE_UNKNOWN;
72 }
73}
74
75static enum sys_con malta_sys_con(void)
76{
77 switch (malta_core_card()) {
78 case CORE_LV:
79 return SYSCON_GT64120;
80
81 case CORE_FPGA6:
82 return SYSCON_MSC01;
83
84 default:
85 return SYSCON_UNKNOWN;
86 }
87}
88
Simon Glassf1683aa2017-04-06 12:47:05 -060089int dram_init(void)
Gabor Juhos5a4dcfa2013-05-22 03:57:37 +000090{
Simon Glass088454c2017-03-31 08:40:25 -060091 gd->ram_size = CONFIG_SYS_MEM_SIZE;
92
93 return 0;
Gabor Juhos5a4dcfa2013-05-22 03:57:37 +000094}
95
96int checkboard(void)
97{
Paul Burtonbaf37f02013-11-08 11:18:50 +000098 enum core_card core;
99
Bin Menga1875592016-02-05 19:30:11 -0800100 malta_lcd_puts("U-Boot");
Paul Burtonbaf37f02013-11-08 11:18:50 +0000101 puts("Board: MIPS Malta");
102
103 core = malta_core_card();
104 switch (core) {
105 case CORE_LV:
106 puts(" CoreLV");
107 break;
108
109 case CORE_FPGA6:
110 puts(" CoreFPGA6");
111 break;
112
113 default:
114 puts(" CoreUnknown");
115 }
116
117 putc('\n');
Gabor Juhos5a4dcfa2013-05-22 03:57:37 +0000118 return 0;
119}
Gabor Juhos01564312013-05-22 03:57:38 +0000120
Gabor Juhosf1957492013-05-22 03:57:44 +0000121int board_eth_init(bd_t *bis)
122{
123 return pci_eth_init(bis);
124}
125
Gabor Juhos01564312013-05-22 03:57:38 +0000126void _machine_restart(void)
127{
128 void __iomem *reset_base;
129
130 reset_base = (void __iomem *)CKSEG1ADDR(MALTA_RESET_BASE);
131 __raw_writel(GORESET, reset_base);
Paul Burton28c8c3d2015-01-29 10:38:21 +0000132 mdelay(1000);
Gabor Juhos01564312013-05-22 03:57:38 +0000133}
Gabor Juhosfeaa6062013-05-22 03:57:42 +0000134
Paul Burtona257f622013-11-08 11:18:49 +0000135int board_early_init_f(void)
136{
Paul Burton91ec6152016-01-29 13:54:54 +0000137 ulong io_base;
Paul Burtonbaf37f02013-11-08 11:18:50 +0000138
139 /* choose correct PCI I/O base */
140 switch (malta_sys_con()) {
141 case SYSCON_GT64120:
Paul Burton91ec6152016-01-29 13:54:54 +0000142 io_base = CKSEG1ADDR(MALTA_GT_PCIIO_BASE);
Paul Burtonbaf37f02013-11-08 11:18:50 +0000143 break;
144
145 case SYSCON_MSC01:
Paul Burton91ec6152016-01-29 13:54:54 +0000146 io_base = CKSEG1ADDR(MALTA_MSC01_PCIIO_BASE);
Paul Burtonbaf37f02013-11-08 11:18:50 +0000147 break;
148
149 default:
150 return -1;
151 }
152
Paul Burton91ec6152016-01-29 13:54:54 +0000153 set_io_port_base(io_base);
Paul Burton19a5ef62016-01-29 13:54:53 +0000154
Paul Burtona257f622013-11-08 11:18:49 +0000155 /* setup FDC37M817 super I/O controller */
Paul Burton91ec6152016-01-29 13:54:54 +0000156 malta_superio_init();
Paul Burtona257f622013-11-08 11:18:49 +0000157
158 return 0;
159}
160
Paul Burton3ced12a2013-11-08 11:18:55 +0000161int misc_init_r(void)
162{
163 rtc_reset();
164
165 return 0;
166}
167
Gabor Juhosfeaa6062013-05-22 03:57:42 +0000168void pci_init_board(void)
169{
Paul Burton81f98bb2013-11-08 11:18:57 +0000170 pci_dev_t bdf;
Paul Burtonbea12b72013-11-26 17:45:27 +0000171 u32 val32;
172 u8 val8;
Paul Burton81f98bb2013-11-08 11:18:57 +0000173
Paul Burtonbaf37f02013-11-08 11:18:50 +0000174 switch (malta_sys_con()) {
175 case SYSCON_GT64120:
Paul Burtonbaf37f02013-11-08 11:18:50 +0000176 gt64120_pci_init((void *)CKSEG1ADDR(MALTA_GT_BASE),
177 0x00000000, 0x00000000, CONFIG_SYS_MEM_SIZE,
178 0x10000000, 0x10000000, 128 * 1024 * 1024,
179 0x00000000, 0x00000000, 0x20000);
180 break;
181
182 default:
183 case SYSCON_MSC01:
Paul Burtonbaf37f02013-11-08 11:18:50 +0000184 msc01_pci_init((void *)CKSEG1ADDR(MALTA_MSC01_PCI_BASE),
185 0x00000000, 0x00000000, CONFIG_SYS_MEM_SIZE,
186 MALTA_MSC01_PCIMEM_MAP,
187 CKSEG1ADDR(MALTA_MSC01_PCIMEM_BASE),
188 MALTA_MSC01_PCIMEM_SIZE, MALTA_MSC01_PCIIO_MAP,
189 0x00000000, MALTA_MSC01_PCIIO_SIZE);
190 break;
191 }
Paul Burton81f98bb2013-11-08 11:18:57 +0000192
193 bdf = pci_find_device(PCI_VENDOR_ID_INTEL,
194 PCI_DEVICE_ID_INTEL_82371AB_0, 0);
195 if (bdf == -1)
196 panic("Failed to find PIIX4 PCI bridge\n");
197
198 /* setup PCI interrupt routing */
199 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCA, 10);
200 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCB, 10);
201 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCC, 11);
202 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCD, 11);
Paul Burtonbea12b72013-11-26 17:45:27 +0000203
204 /* mux SERIRQ onto SERIRQ pin */
205 pci_read_config_dword(bdf, PCI_CFG_PIIX4_GENCFG, &val32);
206 val32 |= PCI_CFG_PIIX4_GENCFG_SERIRQ;
207 pci_write_config_dword(bdf, PCI_CFG_PIIX4_GENCFG, val32);
208
209 /* enable SERIRQ - Linux currently depends upon this */
210 pci_read_config_byte(bdf, PCI_CFG_PIIX4_SERIRQC, &val8);
211 val8 |= PCI_CFG_PIIX4_SERIRQC_EN | PCI_CFG_PIIX4_SERIRQC_CONT;
212 pci_write_config_byte(bdf, PCI_CFG_PIIX4_SERIRQC, val8);
Paul Burtonba21a452015-01-29 10:38:20 +0000213
214 bdf = pci_find_device(PCI_VENDOR_ID_INTEL,
215 PCI_DEVICE_ID_INTEL_82371AB, 0);
216 if (bdf == -1)
217 panic("Failed to find PIIX4 IDE controller\n");
218
219 /* enable bus master & IO access */
220 val32 |= PCI_COMMAND_MASTER | PCI_COMMAND_IO;
221 pci_write_config_dword(bdf, PCI_COMMAND, val32);
222
223 /* set latency */
224 pci_write_config_byte(bdf, PCI_LATENCY_TIMER, 0x40);
225
226 /* enable IDE/ATA */
227 pci_write_config_dword(bdf, PCI_CFG_PIIX4_IDETIM_PRI,
228 PCI_CFG_PIIX4_IDETIM_IDE);
229 pci_write_config_dword(bdf, PCI_CFG_PIIX4_IDETIM_SEC,
230 PCI_CFG_PIIX4_IDETIM_IDE);
Gabor Juhosfeaa6062013-05-22 03:57:42 +0000231}