blob: eebb2d1538c6168195998ea25ab188d14644df80 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Steven J. Hill49bffbd2013-03-25 15:05:40 -05002 * 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
4 * for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * PROM library initialisation code.
Steven J. Hill49bffbd2013-03-25 15:05:40 -05007 *
8 * Copyright (C) 1999,2000,2004,2005,2012 MIPS Technologies, Inc.
9 * All rights reserved.
10 * Authors: Carsten Langgaard <carstenl@mips.com>
11 * Maciej W. Rozycki <macro@mips.com>
12 * Steven J. Hill <sjhill@mips.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/init.h>
15#include <linux/string.h>
16#include <linux/kernel.h>
Paul Burton23a91de2013-12-02 16:48:38 +000017#include <linux/serial_8250.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Ralf Baechlee01402b2005-07-14 15:57:16 +000019#include <asm/cacheflush.h>
Ralf Baechle852fe312011-05-28 15:27:59 +010020#include <asm/smp-ops.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000021#include <asm/traps.h>
Steven J. Hillb431f092013-03-25 14:47:05 -050022#include <asm/fw/fw.h>
Paul Burton237036d2014-01-15 10:31:54 +000023#include <asm/mips-cm.h>
Paul Burton7dc28342014-01-15 10:31:55 +000024#include <asm/mips-cpc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/mips-boards/generic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/mips-boards/malta.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Dmitri Vorobievd0cdfe22009-03-23 00:12:27 +020028static int mips_revision_corid;
Chris Dearmanb72c0522007-04-27 15:58:41 +010029int mips_revision_sconid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31/* Bonito64 system controller register base. */
32unsigned long _pcictrl_bonito;
33unsigned long _pcictrl_bonito_pcicfg;
34
35/* GT64120 system controller register base */
36unsigned long _pcictrl_gt64120;
37
38/* MIPS System controller register base */
39unsigned long _pcictrl_msc;
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#ifdef CONFIG_SERIAL_8250_CONSOLE
42static void __init console_config(void)
43{
44 char console_string[40];
45 int baud = 0;
46 char parity = '\0', bits = '\0', flow = '\0';
47 char *s;
48
Paul Burton23a91de2013-12-02 16:48:38 +000049 s = fw_getenv("modetty0");
50 if (s) {
51 while (*s >= '0' && *s <= '9')
52 baud = baud*10 + *s++ - '0';
53 if (*s == ',')
54 s++;
55 if (*s)
56 parity = *s++;
57 if (*s == ',')
58 s++;
59 if (*s)
60 bits = *s++;
61 if (*s == ',')
62 s++;
63 if (*s == 'h')
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 flow = 'r';
Paul Burton23a91de2013-12-02 16:48:38 +000065 }
66 if (baud == 0)
67 baud = 38400;
68 if (parity != 'n' && parity != 'o' && parity != 'e')
69 parity = 'n';
70 if (bits != '7' && bits != '8')
71 bits = '8';
72 if (flow == '\0')
73 flow = 'r';
74
75 if ((strstr(fw_getcmdline(), "earlycon=")) == NULL) {
76 sprintf(console_string, "uart8250,io,0x3f8,%d%c%c", baud,
77 parity, bits);
78 setup_early_serial8250_console(console_string);
79 }
80
81 if ((strstr(fw_getcmdline(), "console=")) == NULL) {
Steven J. Hill49bffbd2013-03-25 15:05:40 -050082 sprintf(console_string, " console=ttyS0,%d%c%c%c", baud,
83 parity, bits, flow);
Steven J. Hillb431f092013-03-25 14:47:05 -050084 strcat(fw_getcmdline(), console_string);
Ralf Baechle36a88532007-03-01 11:56:43 +000085 pr_info("Config serial console:%s\n", console_string);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 }
87}
88#endif
89
Dmitri Vorobievcd2675f2008-04-01 02:03:20 +040090static void __init mips_nmi_setup(void)
Ralf Baechlee01402b2005-07-14 15:57:16 +000091{
92 void *base;
93 extern char except_vec_nmi;
94
95 base = cpu_has_veic ?
96 (void *)(CAC_BASE + 0xa80) :
97 (void *)(CAC_BASE + 0x380);
98 memcpy(base, &except_vec_nmi, 0x80);
99 flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
100}
101
Dmitri Vorobiev33d69d22008-04-01 02:03:21 +0400102static void __init mips_ejtag_setup(void)
Ralf Baechlee01402b2005-07-14 15:57:16 +0000103{
104 void *base;
105 extern char except_vec_ejtag_debug;
106
107 base = cpu_has_veic ?
108 (void *)(CAC_BASE + 0xa00) :
109 (void *)(CAC_BASE + 0x300);
110 memcpy(base, &except_vec_ejtag_debug, 0x80);
111 flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
112}
113
Paul Burton7dc28342014-01-15 10:31:55 +0000114phys_t mips_cpc_default_phys_base(void)
115{
116 return CPC_BASE_ADDR;
117}
118
Ralf Baechle87353d82007-11-19 12:23:51 +0000119extern struct plat_smp_ops msmtc_smp_ops;
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121void __init prom_init(void)
122{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 mips_display_message("LINUX");
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 /*
126 * early setup of _pcictrl_bonito so that we can determine
127 * the system controller on a CORE_EMUL board
128 */
129 _pcictrl_bonito = (unsigned long)ioremap(BONITO_REG_BASE, BONITO_REG_SIZE);
130
131 mips_revision_corid = MIPS_REVISION_CORID;
132
133 if (mips_revision_corid == MIPS_REVISION_CORID_CORE_EMUL) {
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700134 if (BONITO_PCIDID == 0x0001df53 ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 BONITO_PCIDID == 0x0003df53)
136 mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_BON;
137 else
138 mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_MSC;
139 }
Chris Dearmanb72c0522007-04-27 15:58:41 +0100140
141 mips_revision_sconid = MIPS_REVISION_SCONID;
142 if (mips_revision_sconid == MIPS_REVISION_SCON_OTHER) {
143 switch (mips_revision_corid) {
144 case MIPS_REVISION_CORID_QED_RM5261:
145 case MIPS_REVISION_CORID_CORE_LV:
146 case MIPS_REVISION_CORID_CORE_FPGA:
147 case MIPS_REVISION_CORID_CORE_FPGAR2:
148 mips_revision_sconid = MIPS_REVISION_SCON_GT64120;
149 break;
150 case MIPS_REVISION_CORID_CORE_EMUL_BON:
151 case MIPS_REVISION_CORID_BONITO64:
152 case MIPS_REVISION_CORID_CORE_20K:
153 mips_revision_sconid = MIPS_REVISION_SCON_BONITO;
154 break;
155 case MIPS_REVISION_CORID_CORE_MSC:
156 case MIPS_REVISION_CORID_CORE_FPGA2:
Chris Dearmanb72c0522007-04-27 15:58:41 +0100157 case MIPS_REVISION_CORID_CORE_24K:
Chris Dearman30840242007-09-21 14:50:08 +0100158 /*
159 * SOCit/ROCit support is essentially identical
160 * but make an attempt to distinguish them
161 */
Chris Dearmanb72c0522007-04-27 15:58:41 +0100162 mips_revision_sconid = MIPS_REVISION_SCON_SOCIT;
163 break;
Chris Dearman30840242007-09-21 14:50:08 +0100164 case MIPS_REVISION_CORID_CORE_FPGA3:
165 case MIPS_REVISION_CORID_CORE_FPGA4:
166 case MIPS_REVISION_CORID_CORE_FPGA5:
167 case MIPS_REVISION_CORID_CORE_EMUL_MSC:
Chris Dearmanb72c0522007-04-27 15:58:41 +0100168 default:
Chris Dearman30840242007-09-21 14:50:08 +0100169 /* See above */
170 mips_revision_sconid = MIPS_REVISION_SCON_ROCIT;
171 break;
Chris Dearmanb72c0522007-04-27 15:58:41 +0100172 }
173 }
174
175 switch (mips_revision_sconid) {
Ralf Baechlef76b7ea2007-03-04 17:26:56 +0000176 u32 start, map, mask, data;
177
Chris Dearmanb72c0522007-04-27 15:58:41 +0100178 case MIPS_REVISION_SCON_GT64120:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 /*
180 * Setup the North bridge to do Master byte-lane swapping
181 * when running in bigendian.
182 */
183 _pcictrl_gt64120 = (unsigned long)ioremap(MIPS_GT_BASE, 0x2000);
184
185#ifdef CONFIG_CPU_LITTLE_ENDIAN
186 GT_WRITE(GT_PCI0_CMD_OFS, GT_PCI0_CMD_MBYTESWAP_BIT |
187 GT_PCI0_CMD_SBYTESWAP_BIT);
188#else
189 GT_WRITE(GT_PCI0_CMD_OFS, 0);
190#endif
Maciej W. Rozyckiaa0980b2005-02-01 20:18:59 +0000191 /* Fix up PCI I/O mapping if necessary (for Atlas). */
192 start = GT_READ(GT_PCI0IOLD_OFS);
193 map = GT_READ(GT_PCI0IOREMAP_OFS);
194 if ((start & map) != 0) {
195 map &= ~start;
196 GT_WRITE(GT_PCI0IOREMAP_OFS, map);
197 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 set_io_port_base(MALTA_GT_PORT_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 break;
201
Chris Dearmanb72c0522007-04-27 15:58:41 +0100202 case MIPS_REVISION_SCON_BONITO:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 _pcictrl_bonito_pcicfg = (unsigned long)ioremap(BONITO_PCICFG_BASE, BONITO_PCICFG_SIZE);
204
205 /*
206 * Disable Bonito IOBC.
207 */
208 BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
209 ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
210 BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
211
212 /*
213 * Setup the North bridge to do Master byte-lane swapping
214 * when running in bigendian.
215 */
216#ifdef CONFIG_CPU_LITTLE_ENDIAN
217 BONITO_BONGENCFG = BONITO_BONGENCFG &
218 ~(BONITO_BONGENCFG_MSTRBYTESWAP |
219 BONITO_BONGENCFG_BYTESWAP);
220#else
221 BONITO_BONGENCFG = BONITO_BONGENCFG |
222 BONITO_BONGENCFG_MSTRBYTESWAP |
223 BONITO_BONGENCFG_BYTESWAP;
224#endif
225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 set_io_port_base(MALTA_BONITO_PORT_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 break;
228
Chris Dearmanb72c0522007-04-27 15:58:41 +0100229 case MIPS_REVISION_SCON_SOCIT:
230 case MIPS_REVISION_SCON_ROCIT:
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700231 _pcictrl_msc = (unsigned long)ioremap(MIPS_MSC01_PCI_REG_BASE, 0x2000);
Steven J. Hill49bffbd2013-03-25 15:05:40 -0500232mips_pci_controller:
Maciej W. Rozyckiaa0980b2005-02-01 20:18:59 +0000233 mb();
234 MSC_READ(MSC01_PCI_CFG, data);
235 MSC_WRITE(MSC01_PCI_CFG, data & ~MSC01_PCI_CFG_EN_BIT);
236 wmb();
237
238 /* Fix up lane swapping. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239#ifdef CONFIG_CPU_LITTLE_ENDIAN
240 MSC_WRITE(MSC01_PCI_SWAP, MSC01_PCI_SWAP_NOSWAP);
241#else
242 MSC_WRITE(MSC01_PCI_SWAP,
243 MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_IO_SHF |
244 MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_MEM_SHF |
245 MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_BAR0_SHF);
246#endif
Maciej W. Rozyckiaa0980b2005-02-01 20:18:59 +0000247 /* Fix up target memory mapping. */
248 MSC_READ(MSC01_PCI_BAR0, mask);
249 MSC_WRITE(MSC01_PCI_P2SCMSKL, mask & MSC01_PCI_BAR0_SIZE_MSK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Maciej W. Rozyckiaa0980b2005-02-01 20:18:59 +0000251 /* Don't handle target retries indefinitely. */
252 if ((data & MSC01_PCI_CFG_MAXRTRY_MSK) ==
253 MSC01_PCI_CFG_MAXRTRY_MSK)
254 data = (data & ~(MSC01_PCI_CFG_MAXRTRY_MSK <<
255 MSC01_PCI_CFG_MAXRTRY_SHF)) |
256 ((MSC01_PCI_CFG_MAXRTRY_MSK - 1) <<
257 MSC01_PCI_CFG_MAXRTRY_SHF);
258
259 wmb();
260 MSC_WRITE(MSC01_PCI_CFG, data);
261 mb();
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 set_io_port_base(MALTA_MSC_PORT_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 break;
265
Chris Dearmanb72c0522007-04-27 15:58:41 +0100266 case MIPS_REVISION_SCON_SOCITSC:
267 case MIPS_REVISION_SCON_SOCITSCP:
268 _pcictrl_msc = (unsigned long)ioremap(MIPS_SOCITSC_PCI_REG_BASE, 0x2000);
269 goto mips_pci_controller;
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 default:
Chris Dearmanb72c0522007-04-27 15:58:41 +0100272 /* Unknown system controller */
273 mips_display_message("SC Error");
Steven J. Hill49bffbd2013-03-25 15:05:40 -0500274 while (1); /* We die here... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 }
Ralf Baechlee01402b2005-07-14 15:57:16 +0000276 board_nmi_handler_setup = mips_nmi_setup;
277 board_ejtag_handler_setup = mips_ejtag_setup;
278
Steven J. Hillb431f092013-03-25 14:47:05 -0500279 fw_init_cmdline();
280 fw_meminit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281#ifdef CONFIG_SERIAL_8250_CONSOLE
282 console_config();
283#endif
Ralf Baechleaf3a1f62011-03-29 11:43:19 +0200284 /* Early detection of CMP support */
Paul Burton237036d2014-01-15 10:31:54 +0000285 mips_cm_probe();
Paul Burton7dc28342014-01-15 10:31:55 +0000286 mips_cpc_probe();
Ralf Baechle852fe312011-05-28 15:27:59 +0100287
Paul Burtone56b6aa2014-01-15 10:31:56 +0000288 if (!register_cps_smp_ops())
289 return;
Paul Burton237036d2014-01-15 10:31:54 +0000290 if (!register_cmp_smp_ops())
291 return;
Ralf Baechle852fe312011-05-28 15:27:59 +0100292 if (!register_vsmp_smp_ops())
293 return;
294
Ralf Baechle87353d82007-11-19 12:23:51 +0000295#ifdef CONFIG_MIPS_MT_SMTC
296 register_smp_ops(&msmtc_smp_ops);
297#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}