blob: 9e39376025711f73dd74c0cf1e33367973144dac [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
Dmitri Vorobiev52d65cf2008-04-01 02:03:24 +04004 * Copyright (C) 2008 Dmitri Vorobiev
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * This program is free software; you can distribute it and/or modify it
7 * under the terms of the GNU General Public License (Version 2) as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
18 */
Dmitri Vorobiev54bf0382008-01-24 19:52:49 +030019#include <linux/cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/init.h>
21#include <linux/sched.h>
22#include <linux/ioport.h>
Dmitri Vorobiev54bf0382008-01-24 19:52:49 +030023#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/pci.h>
Jon Smirl894673e2006-07-10 04:44:13 -070025#include <linux/screen_info.h>
Dmitri Vorobiev54bf0382008-01-24 19:52:49 +030026#include <linux/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Steven J. Hillb431f092013-03-25 14:47:05 -050028#include <asm/fw/fw.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/mips-boards/generic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/mips-boards/malta.h>
31#include <asm/mips-boards/maltaint.h>
32#include <asm/dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/traps.h>
Steven J. Hillb6d92b42013-03-25 13:47:29 -050034#include <asm/gcmpregs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#ifdef CONFIG_VT
36#include <linux/console.h>
37#endif
38
Ralf Baechle39b8d522008-04-28 17:14:26 +010039extern void malta_be_init(void);
40extern int malta_be_handler(struct pt_regs *regs, int is_fixup);
41
Dmitri Vorobiev52d65cf2008-04-01 02:03:24 +040042static struct resource standard_io_resources[] = {
Dmitri Vorobiev4ca76512008-01-24 19:52:41 +030043 {
44 .name = "dma1",
45 .start = 0x00,
46 .end = 0x1f,
47 .flags = IORESOURCE_BUSY
48 },
49 {
50 .name = "timer",
51 .start = 0x40,
52 .end = 0x5f,
53 .flags = IORESOURCE_BUSY
54 },
55 {
56 .name = "keyboard",
57 .start = 0x60,
58 .end = 0x6f,
59 .flags = IORESOURCE_BUSY
60 },
61 {
62 .name = "dma page reg",
63 .start = 0x80,
64 .end = 0x8f,
65 .flags = IORESOURCE_BUSY
66 },
67 {
68 .name = "dma2",
69 .start = 0xc0,
70 .end = 0xdf,
71 .flags = IORESOURCE_BUSY
72 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070073};
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075const char *get_system_type(void)
76{
77 return "MIPS Malta";
78}
79
Ralf Baechle79894c72007-05-16 17:54:08 +020080#if defined(CONFIG_MIPS_MT_SMTC)
Ralf Baechle70342282013-01-22 12:59:30 +010081const char display_string[] = " SMTC LINUX ON MALTA ";
Ralf Baechle79894c72007-05-16 17:54:08 +020082#else
Ralf Baechle70342282013-01-22 12:59:30 +010083const char display_string[] = " LINUX ON MALTA ";
Ralf Baechle79894c72007-05-16 17:54:08 +020084#endif /* CONFIG_MIPS_MT_SMTC */
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#ifdef CONFIG_BLK_DEV_FD
Dmitri Vorobievef7645c2008-01-24 19:52:55 +030087static void __init fd_activate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
89 /*
90 * Activate Floppy Controller in the SMSC FDC37M817 Super I/O
91 * Controller.
92 * Done by YAMON 2.00 onwards
93 */
94 /* Entering config state. */
95 SMSC_WRITE(SMSC_CONFIG_ENTER, SMSC_CONFIG_REG);
96
97 /* Activate floppy controller. */
98 SMSC_WRITE(SMSC_CONFIG_DEVNUM, SMSC_CONFIG_REG);
99 SMSC_WRITE(SMSC_CONFIG_DEVNUM_FLOPPY, SMSC_DATA_REG);
100 SMSC_WRITE(SMSC_CONFIG_ACTIVATE, SMSC_CONFIG_REG);
101 SMSC_WRITE(SMSC_CONFIG_ACTIVATE_ENABLE, SMSC_DATA_REG);
102
103 /* Exit config state. */
104 SMSC_WRITE(SMSC_CONFIG_EXIT, SMSC_CONFIG_REG);
105}
106#endif
107
Steven J. Hillb6d92b42013-03-25 13:47:29 -0500108static int __init plat_enable_iocoherency(void)
109{
110 int supported = 0;
111 if (mips_revision_sconid == MIPS_REVISION_SCON_BONITO) {
112 if (BONITO_PCICACHECTRL & BONITO_PCICACHECTRL_CPUCOH_PRES) {
113 BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_CPUCOH_EN;
114 pr_info("Enabled Bonito CPU coherency\n");
115 supported = 1;
116 }
117 if (strstr(fw_getcmdline(), "iobcuncached")) {
118 BONITO_PCICACHECTRL &= ~BONITO_PCICACHECTRL_IOBCCOH_EN;
119 BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
120 ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
121 BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
122 pr_info("Disabled Bonito IOBC coherency\n");
123 } else {
124 BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_IOBCCOH_EN;
125 BONITO_PCIMEMBASECFG |=
126 (BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
127 BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
128 pr_info("Enabled Bonito IOBC coherency\n");
129 }
130 } else if (gcmp_niocu() != 0) {
131 /* Nothing special needs to be done to enable coherency */
132 pr_info("CMP IOCU detected\n");
133 if ((*(unsigned int *)0xbf403000 & 0x81) != 0x81) {
134 pr_crit("IOCU OPERATION DISABLED BY SWITCH - DEFAULTING TO SW IO COHERENCY\n");
135 return 0;
136 }
137 supported = 1;
138 }
139 hw_coherentio = supported;
140 return supported;
141}
142
143static void __init plat_setup_iocoherency(void)
144{
145#ifdef CONFIG_DMA_NONCOHERENT
146 /*
147 * Kernel has been configured with software coherency
148 * but we might choose to turn it off and use hardware
149 * coherency instead.
150 */
151 if (plat_enable_iocoherency()) {
152 if (coherentio == 0)
153 pr_info("Hardware DMA cache coherency disabled\n");
154 else
155 pr_info("Hardware DMA cache coherency enabled\n");
156 } else {
157 if (coherentio == 1)
158 pr_info("Hardware DMA cache coherency unsupported, but enabled from command line!\n");
159 else
160 pr_info("Software DMA cache coherency enabled\n");
161 }
162#else
163 if (!plat_enable_iocoherency())
164 panic("Hardware DMA cache coherency not supported!");
165#endif
166}
167
Dmitri Vorobievf3a4ce92008-01-24 19:52:43 +0300168#ifdef CONFIG_BLK_DEV_IDE
169static void __init pci_clock_check(void)
170{
171 unsigned int __iomem *jmpr_p =
172 (unsigned int *) ioremap(MALTA_JMPRS_REG, sizeof(unsigned int));
173 int jmpr = (__raw_readl(jmpr_p) >> 2) & 0x07;
Uwe Kleine-König4a043d72012-07-19 09:11:16 +0200174 static const int pciclocks[] __initconst = {
Dmitri Vorobievf3a4ce92008-01-24 19:52:43 +0300175 33, 20, 25, 30, 12, 16, 37, 10
176 };
177 int pciclock = pciclocks[jmpr];
Steven J. Hillb431f092013-03-25 14:47:05 -0500178 char *argptr = fw_getcmdline();
Dmitri Vorobievf3a4ce92008-01-24 19:52:43 +0300179
180 if (pciclock != 33 && !strstr(argptr, "idebus=")) {
181 printk(KERN_WARNING "WARNING: PCI clock is %dMHz, "
182 "setting idebus\n", pciclock);
183 argptr += strlen(argptr);
184 sprintf(argptr, " idebus=%d", pciclock);
185 if (pciclock < 20 || pciclock > 66)
186 printk(KERN_WARNING "WARNING: IDE timing "
187 "calculations will be incorrect\n");
188 }
189}
190#endif
191
Dmitri Vorobieva3829632008-01-24 19:52:44 +0300192#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
193static void __init screen_info_setup(void)
194{
195 screen_info = (struct screen_info) {
196 .orig_x = 0,
197 .orig_y = 25,
198 .ext_mem_k = 0,
199 .orig_video_page = 0,
200 .orig_video_mode = 0,
201 .orig_video_cols = 80,
202 .unused2 = 0,
203 .orig_video_ega_bx = 0,
204 .unused3 = 0,
205 .orig_video_lines = 25,
206 .orig_video_isVGA = VIDEO_TYPE_VGAC,
207 .orig_video_points = 16
208 };
209}
210#endif
211
Dmitri Vorobiev750dc312008-01-24 19:52:56 +0300212static void __init bonito_quirks_setup(void)
213{
214 char *argptr;
215
Steven J. Hillb431f092013-03-25 14:47:05 -0500216 argptr = fw_getcmdline();
Dmitri Vorobiev750dc312008-01-24 19:52:56 +0300217 if (strstr(argptr, "debug")) {
218 BONITO_BONGENCFG |= BONITO_BONGENCFG_DEBUGMODE;
219 printk(KERN_INFO "Enabled Bonito debug mode\n");
220 } else
221 BONITO_BONGENCFG &= ~BONITO_BONGENCFG_DEBUGMODE;
222
223#ifdef CONFIG_DMA_COHERENT
224 if (BONITO_PCICACHECTRL & BONITO_PCICACHECTRL_CPUCOH_PRES) {
225 BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_CPUCOH_EN;
226 printk(KERN_INFO "Enabled Bonito CPU coherency\n");
227
Steven J. Hillb431f092013-03-25 14:47:05 -0500228 argptr = fw_getcmdline();
Dmitri Vorobiev750dc312008-01-24 19:52:56 +0300229 if (strstr(argptr, "iobcuncached")) {
230 BONITO_PCICACHECTRL &= ~BONITO_PCICACHECTRL_IOBCCOH_EN;
231 BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
232 ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
233 BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
234 printk(KERN_INFO "Disabled Bonito IOBC coherency\n");
235 } else {
236 BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_IOBCCOH_EN;
237 BONITO_PCIMEMBASECFG |=
238 (BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
239 BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
240 printk(KERN_INFO "Enabled Bonito IOBC coherency\n");
241 }
242 } else
243 panic("Hardware DMA cache coherency not supported");
244#endif
245}
246
Ralf Baechle2925aba2006-06-18 01:32:22 +0100247void __init plat_mem_setup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
249 unsigned int i;
250
Ralf Baechlec83cfc92005-06-21 13:56:30 +0000251 mips_pcibios_init();
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 /* Request I/O space for devices used on the Malta board. */
254 for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
255 request_resource(&ioport_resource, standard_io_resources+i);
256
257 /*
258 * Enable DMA channel 4 (cascade channel) in the PIIX4 south bridge.
259 */
260 enable_dma(4);
261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262#ifdef CONFIG_DMA_COHERENT
Dmitri Vorobiev750dc312008-01-24 19:52:56 +0300263 if (mips_revision_sconid != MIPS_REVISION_SCON_BONITO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 panic("Hardware DMA cache coherency not supported");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#endif
266
Dmitri Vorobiev750dc312008-01-24 19:52:56 +0300267 if (mips_revision_sconid == MIPS_REVISION_SCON_BONITO)
268 bonito_quirks_setup();
269
Steven J. Hillb6d92b42013-03-25 13:47:29 -0500270 plat_setup_iocoherency();
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272#ifdef CONFIG_BLK_DEV_IDE
Dmitri Vorobievf3a4ce92008-01-24 19:52:43 +0300273 pci_clock_check();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274#endif
Dmitri Vorobiev750dc312008-01-24 19:52:56 +0300275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276#ifdef CONFIG_BLK_DEV_FD
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100277 fd_activate();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278#endif
Dmitri Vorobiev750dc312008-01-24 19:52:56 +0300279
Dmitri Vorobieva3829632008-01-24 19:52:44 +0300280#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
281 screen_info_setup();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282#endif
Ralf Baechle39b8d522008-04-28 17:14:26 +0100283
284 board_be_init = malta_be_init;
285 board_be_handler = malta_be_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}