blob: 495504372a021831be75d4c8a6a7f55d74a0216a [file] [log] [blame]
Gabor Juhos02c754a2013-05-22 03:57:37 +00001/*
2 * Copyright (C) 2013 Gabor Juhos <juhosg@openwrt.org>
Paul Burton234882c2013-11-08 11:18:50 +00003 * Copyright (C) 2013 Imagination Technologies
Gabor Juhos02c754a2013-05-22 03:57:37 +00004 *
Tom Rinifba23012013-07-24 09:34:30 -04005 * SPDX-License-Identifier: GPL-2.0
Gabor Juhos02c754a2013-05-22 03:57:37 +00006 */
7
8#include <common.h>
Paul Burtonc6c38532015-01-29 10:38:20 +00009#include <ide.h>
Gabor Juhos439c50c2013-05-22 03:57:44 +000010#include <netdev.h>
Paul Burton12ab4ab2013-11-08 11:18:57 +000011#include <pci.h>
Paul Burton234882c2013-11-08 11:18:50 +000012#include <pci_gt64120.h>
13#include <pci_msc01.h>
Paul Burtonc028f9b2013-11-08 11:18:55 +000014#include <rtc.h>
Gabor Juhos02c754a2013-05-22 03:57:37 +000015
Gabor Juhos652ccee2013-05-22 03:57:42 +000016#include <asm/addrspace.h>
Gabor Juhosaed4fa42013-05-22 03:57:38 +000017#include <asm/io.h>
18#include <asm/malta.h>
19
Paul Burton7fb05072013-11-08 11:18:49 +000020#include "superio.h"
21
Paul Burton234882c2013-11-08 11:18:50 +000022enum core_card {
23 CORE_UNKNOWN,
24 CORE_LV,
25 CORE_FPGA6,
26};
27
28enum sys_con {
29 SYSCON_UNKNOWN,
30 SYSCON_GT64120,
31 SYSCON_MSC01,
32};
33
Paul Burton7c8835b2013-11-08 11:18:51 +000034static void malta_lcd_puts(const char *str)
35{
36 int i;
37 void *reg = (void *)CKSEG1ADDR(MALTA_ASCIIPOS0);
38
39 /* print up to 8 characters of the string */
Masahiro Yamadadb204642014-11-07 03:03:31 +090040 for (i = 0; i < min((int)strlen(str), 8); i++) {
Paul Burton7c8835b2013-11-08 11:18:51 +000041 __raw_writel(str[i], reg);
42 reg += MALTA_ASCIIPOS1 - MALTA_ASCIIPOS0;
43 }
44
45 /* fill the rest of the display with spaces */
46 for (; i < 8; i++) {
47 __raw_writel(' ', reg);
48 reg += MALTA_ASCIIPOS1 - MALTA_ASCIIPOS0;
49 }
50}
51
Paul Burton234882c2013-11-08 11:18:50 +000052static enum core_card malta_core_card(void)
53{
54 u32 corid, rev;
Daniel Schwierzeck36eb0532016-01-09 17:32:45 +010055 const void *reg = (const void *)CKSEG1ADDR(MALTA_REVISION);
Paul Burton234882c2013-11-08 11:18:50 +000056
Daniel Schwierzeck36eb0532016-01-09 17:32:45 +010057 rev = __raw_readl(reg);
Paul Burton234882c2013-11-08 11:18:50 +000058 corid = (rev & MALTA_REVISION_CORID_MSK) >> MALTA_REVISION_CORID_SHF;
59
60 switch (corid) {
61 case MALTA_REVISION_CORID_CORE_LV:
62 return CORE_LV;
63
64 case MALTA_REVISION_CORID_CORE_FPGA6:
65 return CORE_FPGA6;
66
67 default:
68 return CORE_UNKNOWN;
69 }
70}
71
72static enum sys_con malta_sys_con(void)
73{
74 switch (malta_core_card()) {
75 case CORE_LV:
76 return SYSCON_GT64120;
77
78 case CORE_FPGA6:
79 return SYSCON_MSC01;
80
81 default:
82 return SYSCON_UNKNOWN;
83 }
84}
85
Gabor Juhos02c754a2013-05-22 03:57:37 +000086phys_size_t initdram(int board_type)
87{
88 return CONFIG_SYS_MEM_SIZE;
89}
90
91int checkboard(void)
92{
Paul Burton234882c2013-11-08 11:18:50 +000093 enum core_card core;
94
Bin Meng75574052016-02-05 19:30:11 -080095 malta_lcd_puts("U-Boot");
Paul Burton234882c2013-11-08 11:18:50 +000096 puts("Board: MIPS Malta");
97
98 core = malta_core_card();
99 switch (core) {
100 case CORE_LV:
101 puts(" CoreLV");
102 break;
103
104 case CORE_FPGA6:
105 puts(" CoreFPGA6");
106 break;
107
108 default:
109 puts(" CoreUnknown");
110 }
111
112 putc('\n');
Gabor Juhos02c754a2013-05-22 03:57:37 +0000113 return 0;
114}
Gabor Juhosaed4fa42013-05-22 03:57:38 +0000115
Gabor Juhos439c50c2013-05-22 03:57:44 +0000116int board_eth_init(bd_t *bis)
117{
118 return pci_eth_init(bis);
119}
120
Gabor Juhosaed4fa42013-05-22 03:57:38 +0000121void _machine_restart(void)
122{
123 void __iomem *reset_base;
124
125 reset_base = (void __iomem *)CKSEG1ADDR(MALTA_RESET_BASE);
126 __raw_writel(GORESET, reset_base);
Paul Burtonee6af872015-01-29 10:38:21 +0000127 mdelay(1000);
Gabor Juhosaed4fa42013-05-22 03:57:38 +0000128}
Gabor Juhos652ccee2013-05-22 03:57:42 +0000129
Paul Burton7fb05072013-11-08 11:18:49 +0000130int board_early_init_f(void)
131{
Paul Burtondd37a142016-01-29 13:54:54 +0000132 ulong io_base;
Paul Burton234882c2013-11-08 11:18:50 +0000133
134 /* choose correct PCI I/O base */
135 switch (malta_sys_con()) {
136 case SYSCON_GT64120:
Paul Burtondd37a142016-01-29 13:54:54 +0000137 io_base = CKSEG1ADDR(MALTA_GT_PCIIO_BASE);
Paul Burton234882c2013-11-08 11:18:50 +0000138 break;
139
140 case SYSCON_MSC01:
Paul Burtondd37a142016-01-29 13:54:54 +0000141 io_base = CKSEG1ADDR(MALTA_MSC01_PCIIO_BASE);
Paul Burton234882c2013-11-08 11:18:50 +0000142 break;
143
144 default:
145 return -1;
146 }
147
Paul Burtondd37a142016-01-29 13:54:54 +0000148 set_io_port_base(io_base);
Paul Burton2e9b2a92016-01-29 13:54:53 +0000149
Paul Burton7fb05072013-11-08 11:18:49 +0000150 /* setup FDC37M817 super I/O controller */
Paul Burtondd37a142016-01-29 13:54:54 +0000151 malta_superio_init();
Paul Burton7fb05072013-11-08 11:18:49 +0000152
153 return 0;
154}
155
Paul Burtonc028f9b2013-11-08 11:18:55 +0000156int misc_init_r(void)
157{
158 rtc_reset();
159
160 return 0;
161}
162
Gabor Juhos652ccee2013-05-22 03:57:42 +0000163void pci_init_board(void)
164{
Paul Burton12ab4ab2013-11-08 11:18:57 +0000165 pci_dev_t bdf;
Paul Burtondc7c2872013-11-26 17:45:27 +0000166 u32 val32;
167 u8 val8;
Paul Burton12ab4ab2013-11-08 11:18:57 +0000168
Paul Burton234882c2013-11-08 11:18:50 +0000169 switch (malta_sys_con()) {
170 case SYSCON_GT64120:
Paul Burton234882c2013-11-08 11:18:50 +0000171 gt64120_pci_init((void *)CKSEG1ADDR(MALTA_GT_BASE),
172 0x00000000, 0x00000000, CONFIG_SYS_MEM_SIZE,
173 0x10000000, 0x10000000, 128 * 1024 * 1024,
174 0x00000000, 0x00000000, 0x20000);
175 break;
176
177 default:
178 case SYSCON_MSC01:
Paul Burton234882c2013-11-08 11:18:50 +0000179 msc01_pci_init((void *)CKSEG1ADDR(MALTA_MSC01_PCI_BASE),
180 0x00000000, 0x00000000, CONFIG_SYS_MEM_SIZE,
181 MALTA_MSC01_PCIMEM_MAP,
182 CKSEG1ADDR(MALTA_MSC01_PCIMEM_BASE),
183 MALTA_MSC01_PCIMEM_SIZE, MALTA_MSC01_PCIIO_MAP,
184 0x00000000, MALTA_MSC01_PCIIO_SIZE);
185 break;
186 }
Paul Burton12ab4ab2013-11-08 11:18:57 +0000187
188 bdf = pci_find_device(PCI_VENDOR_ID_INTEL,
189 PCI_DEVICE_ID_INTEL_82371AB_0, 0);
190 if (bdf == -1)
191 panic("Failed to find PIIX4 PCI bridge\n");
192
193 /* setup PCI interrupt routing */
194 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCA, 10);
195 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCB, 10);
196 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCC, 11);
197 pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCD, 11);
Paul Burtondc7c2872013-11-26 17:45:27 +0000198
199 /* mux SERIRQ onto SERIRQ pin */
200 pci_read_config_dword(bdf, PCI_CFG_PIIX4_GENCFG, &val32);
201 val32 |= PCI_CFG_PIIX4_GENCFG_SERIRQ;
202 pci_write_config_dword(bdf, PCI_CFG_PIIX4_GENCFG, val32);
203
204 /* enable SERIRQ - Linux currently depends upon this */
205 pci_read_config_byte(bdf, PCI_CFG_PIIX4_SERIRQC, &val8);
206 val8 |= PCI_CFG_PIIX4_SERIRQC_EN | PCI_CFG_PIIX4_SERIRQC_CONT;
207 pci_write_config_byte(bdf, PCI_CFG_PIIX4_SERIRQC, val8);
Paul Burtonc6c38532015-01-29 10:38:20 +0000208
209 bdf = pci_find_device(PCI_VENDOR_ID_INTEL,
210 PCI_DEVICE_ID_INTEL_82371AB, 0);
211 if (bdf == -1)
212 panic("Failed to find PIIX4 IDE controller\n");
213
214 /* enable bus master & IO access */
215 val32 |= PCI_COMMAND_MASTER | PCI_COMMAND_IO;
216 pci_write_config_dword(bdf, PCI_COMMAND, val32);
217
218 /* set latency */
219 pci_write_config_byte(bdf, PCI_LATENCY_TIMER, 0x40);
220
221 /* enable IDE/ATA */
222 pci_write_config_dword(bdf, PCI_CFG_PIIX4_IDETIM_PRI,
223 PCI_CFG_PIIX4_IDETIM_IDE);
224 pci_write_config_dword(bdf, PCI_CFG_PIIX4_IDETIM_SEC,
225 PCI_CFG_PIIX4_IDETIM_IDE);
Gabor Juhos652ccee2013-05-22 03:57:42 +0000226}