2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * PROM library initialisation code.
8 * Copyright (C) 1999,2000,2004,2005,2012 MIPS Technologies, Inc.
10 * Authors: Carsten Langgaard <carstenl@mips.com>
11 * Maciej W. Rozycki <macro@mips.com>
12 * Steven J. Hill <sjhill@mips.com>
14 #include <linux/init.h>
15 #include <linux/string.h>
16 #include <linux/kernel.h>
17 #include <linux/serial_8250.h>
19 #include <asm/cacheflush.h>
20 #include <asm/smp-ops.h>
21 #include <asm/traps.h>
22 #include <asm/fw/fw.h>
23 #include <asm/gcmpregs.h>
24 #include <asm/mips-boards/generic.h>
25 #include <asm/mips-boards/malta.h>
27 static int mips_revision_corid;
28 int mips_revision_sconid;
30 /* Bonito64 system controller register base. */
31 unsigned long _pcictrl_bonito;
32 unsigned long _pcictrl_bonito_pcicfg;
34 /* GT64120 system controller register base */
35 unsigned long _pcictrl_gt64120;
37 /* MIPS System controller register base */
38 unsigned long _pcictrl_msc;
40 #ifdef CONFIG_SERIAL_8250_CONSOLE
41 static void __init console_config(void)
43 char console_string[40];
45 char parity = '\0', bits = '\0', flow = '\0';
48 s = fw_getenv("modetty0");
50 while (*s >= '0' && *s <= '9')
51 baud = baud*10 + *s++ - '0';
67 if (parity != 'n' && parity != 'o' && parity != 'e')
69 if (bits != '7' && bits != '8')
74 if ((strstr(fw_getcmdline(), "earlycon=")) == NULL) {
75 sprintf(console_string, "uart8250,io,0x3f8,%d%c%c", baud,
77 setup_early_serial8250_console(console_string);
80 if ((strstr(fw_getcmdline(), "console=")) == NULL) {
81 sprintf(console_string, " console=ttyS0,%d%c%c%c", baud,
83 strcat(fw_getcmdline(), console_string);
84 pr_info("Config serial console:%s\n", console_string);
89 static void __init mips_nmi_setup(void)
92 extern char except_vec_nmi;
95 (void *)(CAC_BASE + 0xa80) :
96 (void *)(CAC_BASE + 0x380);
97 memcpy(base, &except_vec_nmi, 0x80);
98 flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
101 static void __init mips_ejtag_setup(void)
104 extern char except_vec_ejtag_debug;
106 base = cpu_has_veic ?
107 (void *)(CAC_BASE + 0xa00) :
108 (void *)(CAC_BASE + 0x300);
109 memcpy(base, &except_vec_ejtag_debug, 0x80);
110 flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
113 extern struct plat_smp_ops msmtc_smp_ops;
115 void __init prom_init(void)
117 mips_display_message("LINUX");
120 * early setup of _pcictrl_bonito so that we can determine
121 * the system controller on a CORE_EMUL board
123 _pcictrl_bonito = (unsigned long)ioremap(BONITO_REG_BASE, BONITO_REG_SIZE);
125 mips_revision_corid = MIPS_REVISION_CORID;
127 if (mips_revision_corid == MIPS_REVISION_CORID_CORE_EMUL) {
128 if (BONITO_PCIDID == 0x0001df53 ||
129 BONITO_PCIDID == 0x0003df53)
130 mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_BON;
132 mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_MSC;
135 mips_revision_sconid = MIPS_REVISION_SCONID;
136 if (mips_revision_sconid == MIPS_REVISION_SCON_OTHER) {
137 switch (mips_revision_corid) {
138 case MIPS_REVISION_CORID_QED_RM5261:
139 case MIPS_REVISION_CORID_CORE_LV:
140 case MIPS_REVISION_CORID_CORE_FPGA:
141 case MIPS_REVISION_CORID_CORE_FPGAR2:
142 mips_revision_sconid = MIPS_REVISION_SCON_GT64120;
144 case MIPS_REVISION_CORID_CORE_EMUL_BON:
145 case MIPS_REVISION_CORID_BONITO64:
146 case MIPS_REVISION_CORID_CORE_20K:
147 mips_revision_sconid = MIPS_REVISION_SCON_BONITO;
149 case MIPS_REVISION_CORID_CORE_MSC:
150 case MIPS_REVISION_CORID_CORE_FPGA2:
151 case MIPS_REVISION_CORID_CORE_24K:
153 * SOCit/ROCit support is essentially identical
154 * but make an attempt to distinguish them
156 mips_revision_sconid = MIPS_REVISION_SCON_SOCIT;
158 case MIPS_REVISION_CORID_CORE_FPGA3:
159 case MIPS_REVISION_CORID_CORE_FPGA4:
160 case MIPS_REVISION_CORID_CORE_FPGA5:
161 case MIPS_REVISION_CORID_CORE_EMUL_MSC:
164 mips_revision_sconid = MIPS_REVISION_SCON_ROCIT;
169 switch (mips_revision_sconid) {
170 u32 start, map, mask, data;
172 case MIPS_REVISION_SCON_GT64120:
174 * Setup the North bridge to do Master byte-lane swapping
175 * when running in bigendian.
177 _pcictrl_gt64120 = (unsigned long)ioremap(MIPS_GT_BASE, 0x2000);
179 #ifdef CONFIG_CPU_LITTLE_ENDIAN
180 GT_WRITE(GT_PCI0_CMD_OFS, GT_PCI0_CMD_MBYTESWAP_BIT |
181 GT_PCI0_CMD_SBYTESWAP_BIT);
183 GT_WRITE(GT_PCI0_CMD_OFS, 0);
185 /* Fix up PCI I/O mapping if necessary (for Atlas). */
186 start = GT_READ(GT_PCI0IOLD_OFS);
187 map = GT_READ(GT_PCI0IOREMAP_OFS);
188 if ((start & map) != 0) {
190 GT_WRITE(GT_PCI0IOREMAP_OFS, map);
193 set_io_port_base(MALTA_GT_PORT_BASE);
196 case MIPS_REVISION_SCON_BONITO:
197 _pcictrl_bonito_pcicfg = (unsigned long)ioremap(BONITO_PCICFG_BASE, BONITO_PCICFG_SIZE);
200 * Disable Bonito IOBC.
202 BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
203 ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
204 BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
207 * Setup the North bridge to do Master byte-lane swapping
208 * when running in bigendian.
210 #ifdef CONFIG_CPU_LITTLE_ENDIAN
211 BONITO_BONGENCFG = BONITO_BONGENCFG &
212 ~(BONITO_BONGENCFG_MSTRBYTESWAP |
213 BONITO_BONGENCFG_BYTESWAP);
215 BONITO_BONGENCFG = BONITO_BONGENCFG |
216 BONITO_BONGENCFG_MSTRBYTESWAP |
217 BONITO_BONGENCFG_BYTESWAP;
220 set_io_port_base(MALTA_BONITO_PORT_BASE);
223 case MIPS_REVISION_SCON_SOCIT:
224 case MIPS_REVISION_SCON_ROCIT:
225 _pcictrl_msc = (unsigned long)ioremap(MIPS_MSC01_PCI_REG_BASE, 0x2000);
228 MSC_READ(MSC01_PCI_CFG, data);
229 MSC_WRITE(MSC01_PCI_CFG, data & ~MSC01_PCI_CFG_EN_BIT);
232 /* Fix up lane swapping. */
233 #ifdef CONFIG_CPU_LITTLE_ENDIAN
234 MSC_WRITE(MSC01_PCI_SWAP, MSC01_PCI_SWAP_NOSWAP);
236 MSC_WRITE(MSC01_PCI_SWAP,
237 MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_IO_SHF |
238 MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_MEM_SHF |
239 MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_BAR0_SHF);
241 /* Fix up target memory mapping. */
242 MSC_READ(MSC01_PCI_BAR0, mask);
243 MSC_WRITE(MSC01_PCI_P2SCMSKL, mask & MSC01_PCI_BAR0_SIZE_MSK);
245 /* Don't handle target retries indefinitely. */
246 if ((data & MSC01_PCI_CFG_MAXRTRY_MSK) ==
247 MSC01_PCI_CFG_MAXRTRY_MSK)
248 data = (data & ~(MSC01_PCI_CFG_MAXRTRY_MSK <<
249 MSC01_PCI_CFG_MAXRTRY_SHF)) |
250 ((MSC01_PCI_CFG_MAXRTRY_MSK - 1) <<
251 MSC01_PCI_CFG_MAXRTRY_SHF);
254 MSC_WRITE(MSC01_PCI_CFG, data);
257 set_io_port_base(MALTA_MSC_PORT_BASE);
260 case MIPS_REVISION_SCON_SOCITSC:
261 case MIPS_REVISION_SCON_SOCITSCP:
262 _pcictrl_msc = (unsigned long)ioremap(MIPS_SOCITSC_PCI_REG_BASE, 0x2000);
263 goto mips_pci_controller;
266 /* Unknown system controller */
267 mips_display_message("SC Error");
268 while (1); /* We die here... */
270 board_nmi_handler_setup = mips_nmi_setup;
271 board_ejtag_handler_setup = mips_ejtag_setup;
275 #ifdef CONFIG_SERIAL_8250_CONSOLE
278 /* Early detection of CMP support */
279 if (gcmp_probe(GCMP_BASE_ADDR, GCMP_ADDRSPACE_SZ))
280 if (!register_cmp_smp_ops())
283 if (!register_vsmp_smp_ops())
286 #ifdef CONFIG_MIPS_MT_SMTC
287 register_smp_ops(&msmtc_smp_ops);