Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Carsten Langgaard, carstenl@mips.com |
| 3 | * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved. |
Dmitri Vorobiev | 52d65cf | 2008-04-01 02:03:24 +0400 | [diff] [blame] | 4 | * Copyright (C) 2008 Dmitri Vorobiev |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 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 Vorobiev | 54bf038 | 2008-01-24 19:52:49 +0300 | [diff] [blame] | 19 | #include <linux/cpu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/init.h> |
| 21 | #include <linux/sched.h> |
| 22 | #include <linux/ioport.h> |
Dmitri Vorobiev | 54bf038 | 2008-01-24 19:52:49 +0300 | [diff] [blame] | 23 | #include <linux/irq.h> |
Paul Burton | e8823d2 | 2015-05-22 16:51:02 +0100 | [diff] [blame] | 24 | #include <linux/of_fdt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/pci.h> |
Jon Smirl | 894673e | 2006-07-10 04:44:13 -0700 | [diff] [blame] | 26 | #include <linux/screen_info.h> |
Dmitri Vorobiev | 54bf038 | 2008-01-24 19:52:49 +0300 | [diff] [blame] | 27 | #include <linux/time.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 29 | #include <asm/fw/fw.h> |
Paul Burton | e81a8c7d | 2015-09-22 11:56:38 -0700 | [diff] [blame] | 30 | #include <asm/mach-malta/malta-dtshim.h> |
Paul Burton | 237036d | 2014-01-15 10:31:54 +0000 | [diff] [blame] | 31 | #include <asm/mips-cm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/mips-boards/generic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/mips-boards/malta.h> |
| 34 | #include <asm/mips-boards/maltaint.h> |
| 35 | #include <asm/dma.h> |
Paul Burton | e8823d2 | 2015-05-22 16:51:02 +0100 | [diff] [blame] | 36 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <asm/traps.h> |
| 38 | #ifdef CONFIG_VT |
| 39 | #include <linux/console.h> |
| 40 | #endif |
| 41 | |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 42 | extern void malta_be_init(void); |
| 43 | extern int malta_be_handler(struct pt_regs *regs, int is_fixup); |
| 44 | |
Dmitri Vorobiev | 52d65cf | 2008-04-01 02:03:24 +0400 | [diff] [blame] | 45 | static struct resource standard_io_resources[] = { |
Dmitri Vorobiev | 4ca7651 | 2008-01-24 19:52:41 +0300 | [diff] [blame] | 46 | { |
| 47 | .name = "dma1", |
| 48 | .start = 0x00, |
| 49 | .end = 0x1f, |
| 50 | .flags = IORESOURCE_BUSY |
| 51 | }, |
| 52 | { |
| 53 | .name = "timer", |
| 54 | .start = 0x40, |
| 55 | .end = 0x5f, |
| 56 | .flags = IORESOURCE_BUSY |
| 57 | }, |
| 58 | { |
| 59 | .name = "keyboard", |
| 60 | .start = 0x60, |
| 61 | .end = 0x6f, |
| 62 | .flags = IORESOURCE_BUSY |
| 63 | }, |
| 64 | { |
| 65 | .name = "dma page reg", |
| 66 | .start = 0x80, |
| 67 | .end = 0x8f, |
| 68 | .flags = IORESOURCE_BUSY |
| 69 | }, |
| 70 | { |
| 71 | .name = "dma2", |
| 72 | .start = 0xc0, |
| 73 | .end = 0xdf, |
| 74 | .flags = IORESOURCE_BUSY |
| 75 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | const char *get_system_type(void) |
| 79 | { |
| 80 | return "MIPS Malta"; |
| 81 | } |
| 82 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 83 | const char display_string[] = " LINUX ON MALTA "; |
Ralf Baechle | 79894c7 | 2007-05-16 17:54:08 +0200 | [diff] [blame] | 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #ifdef CONFIG_BLK_DEV_FD |
Dmitri Vorobiev | ef7645c | 2008-01-24 19:52:55 +0300 | [diff] [blame] | 86 | static void __init fd_activate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
| 88 | /* |
| 89 | * Activate Floppy Controller in the SMSC FDC37M817 Super I/O |
| 90 | * Controller. |
| 91 | * Done by YAMON 2.00 onwards |
| 92 | */ |
| 93 | /* Entering config state. */ |
| 94 | SMSC_WRITE(SMSC_CONFIG_ENTER, SMSC_CONFIG_REG); |
| 95 | |
| 96 | /* Activate floppy controller. */ |
| 97 | SMSC_WRITE(SMSC_CONFIG_DEVNUM, SMSC_CONFIG_REG); |
| 98 | SMSC_WRITE(SMSC_CONFIG_DEVNUM_FLOPPY, SMSC_DATA_REG); |
| 99 | SMSC_WRITE(SMSC_CONFIG_ACTIVATE, SMSC_CONFIG_REG); |
| 100 | SMSC_WRITE(SMSC_CONFIG_ACTIVATE_ENABLE, SMSC_DATA_REG); |
| 101 | |
| 102 | /* Exit config state. */ |
| 103 | SMSC_WRITE(SMSC_CONFIG_EXIT, SMSC_CONFIG_REG); |
| 104 | } |
| 105 | #endif |
| 106 | |
Steven J. Hill | b6d92b4 | 2013-03-25 13:47:29 -0500 | [diff] [blame] | 107 | static int __init plat_enable_iocoherency(void) |
| 108 | { |
| 109 | int supported = 0; |
| 110 | if (mips_revision_sconid == MIPS_REVISION_SCON_BONITO) { |
| 111 | if (BONITO_PCICACHECTRL & BONITO_PCICACHECTRL_CPUCOH_PRES) { |
| 112 | BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_CPUCOH_EN; |
| 113 | pr_info("Enabled Bonito CPU coherency\n"); |
| 114 | supported = 1; |
| 115 | } |
| 116 | if (strstr(fw_getcmdline(), "iobcuncached")) { |
| 117 | BONITO_PCICACHECTRL &= ~BONITO_PCICACHECTRL_IOBCCOH_EN; |
| 118 | BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG & |
| 119 | ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED | |
| 120 | BONITO_PCIMEMBASECFG_MEMBASE1_CACHED); |
| 121 | pr_info("Disabled Bonito IOBC coherency\n"); |
| 122 | } else { |
| 123 | BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_IOBCCOH_EN; |
| 124 | BONITO_PCIMEMBASECFG |= |
| 125 | (BONITO_PCIMEMBASECFG_MEMBASE0_CACHED | |
| 126 | BONITO_PCIMEMBASECFG_MEMBASE1_CACHED); |
| 127 | pr_info("Enabled Bonito IOBC coherency\n"); |
| 128 | } |
Paul Burton | 237036d | 2014-01-15 10:31:54 +0000 | [diff] [blame] | 129 | } else if (mips_cm_numiocu() != 0) { |
Steven J. Hill | b6d92b4 | 2013-03-25 13:47:29 -0500 | [diff] [blame] | 130 | /* Nothing special needs to be done to enable coherency */ |
| 131 | pr_info("CMP IOCU detected\n"); |
| 132 | if ((*(unsigned int *)0xbf403000 & 0x81) != 0x81) { |
| 133 | pr_crit("IOCU OPERATION DISABLED BY SWITCH - DEFAULTING TO SW IO COHERENCY\n"); |
| 134 | return 0; |
| 135 | } |
| 136 | supported = 1; |
| 137 | } |
| 138 | hw_coherentio = supported; |
| 139 | return supported; |
| 140 | } |
| 141 | |
| 142 | static void __init plat_setup_iocoherency(void) |
| 143 | { |
| 144 | #ifdef CONFIG_DMA_NONCOHERENT |
| 145 | /* |
| 146 | * Kernel has been configured with software coherency |
| 147 | * but we might choose to turn it off and use hardware |
| 148 | * coherency instead. |
| 149 | */ |
| 150 | if (plat_enable_iocoherency()) { |
| 151 | if (coherentio == 0) |
| 152 | pr_info("Hardware DMA cache coherency disabled\n"); |
| 153 | else |
| 154 | pr_info("Hardware DMA cache coherency enabled\n"); |
| 155 | } else { |
| 156 | if (coherentio == 1) |
| 157 | pr_info("Hardware DMA cache coherency unsupported, but enabled from command line!\n"); |
| 158 | else |
| 159 | pr_info("Software DMA cache coherency enabled\n"); |
| 160 | } |
| 161 | #else |
| 162 | if (!plat_enable_iocoherency()) |
| 163 | panic("Hardware DMA cache coherency not supported!"); |
| 164 | #endif |
| 165 | } |
| 166 | |
Dmitri Vorobiev | f3a4ce9 | 2008-01-24 19:52:43 +0300 | [diff] [blame] | 167 | static void __init pci_clock_check(void) |
| 168 | { |
| 169 | unsigned int __iomem *jmpr_p = |
| 170 | (unsigned int *) ioremap(MALTA_JMPRS_REG, sizeof(unsigned int)); |
| 171 | int jmpr = (__raw_readl(jmpr_p) >> 2) & 0x07; |
Uwe Kleine-König | 4a043d7 | 2012-07-19 09:11:16 +0200 | [diff] [blame] | 172 | static const int pciclocks[] __initconst = { |
Dmitri Vorobiev | f3a4ce9 | 2008-01-24 19:52:43 +0300 | [diff] [blame] | 173 | 33, 20, 25, 30, 12, 16, 37, 10 |
| 174 | }; |
| 175 | int pciclock = pciclocks[jmpr]; |
Ralf Baechle | a9dde28 | 2014-03-18 21:22:46 +0100 | [diff] [blame] | 176 | char *optptr, *argptr = fw_getcmdline(); |
Dmitri Vorobiev | f3a4ce9 | 2008-01-24 19:52:43 +0300 | [diff] [blame] | 177 | |
Ralf Baechle | a9dde28 | 2014-03-18 21:22:46 +0100 | [diff] [blame] | 178 | /* |
| 179 | * If user passed a pci_clock= option, don't tack on another one |
| 180 | */ |
| 181 | optptr = strstr(argptr, "pci_clock="); |
| 182 | if (optptr && (optptr == argptr || optptr[-1] == ' ')) |
| 183 | return; |
| 184 | |
| 185 | if (pciclock != 33) { |
| 186 | pr_warn("WARNING: PCI clock is %dMHz, setting pci_clock\n", |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 187 | pciclock); |
Dmitri Vorobiev | f3a4ce9 | 2008-01-24 19:52:43 +0300 | [diff] [blame] | 188 | argptr += strlen(argptr); |
Ralf Baechle | a9dde28 | 2014-03-18 21:22:46 +0100 | [diff] [blame] | 189 | sprintf(argptr, " pci_clock=%d", pciclock); |
Dmitri Vorobiev | f3a4ce9 | 2008-01-24 19:52:43 +0300 | [diff] [blame] | 190 | if (pciclock < 20 || pciclock > 66) |
Ralf Baechle | a9dde28 | 2014-03-18 21:22:46 +0100 | [diff] [blame] | 191 | pr_warn("WARNING: IDE timing calculations will be " |
| 192 | "incorrect\n"); |
Dmitri Vorobiev | f3a4ce9 | 2008-01-24 19:52:43 +0300 | [diff] [blame] | 193 | } |
| 194 | } |
Dmitri Vorobiev | f3a4ce9 | 2008-01-24 19:52:43 +0300 | [diff] [blame] | 195 | |
Dmitri Vorobiev | a382963 | 2008-01-24 19:52:44 +0300 | [diff] [blame] | 196 | #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE) |
| 197 | static void __init screen_info_setup(void) |
| 198 | { |
| 199 | screen_info = (struct screen_info) { |
| 200 | .orig_x = 0, |
| 201 | .orig_y = 25, |
| 202 | .ext_mem_k = 0, |
| 203 | .orig_video_page = 0, |
| 204 | .orig_video_mode = 0, |
| 205 | .orig_video_cols = 80, |
| 206 | .unused2 = 0, |
| 207 | .orig_video_ega_bx = 0, |
| 208 | .unused3 = 0, |
| 209 | .orig_video_lines = 25, |
| 210 | .orig_video_isVGA = VIDEO_TYPE_VGAC, |
| 211 | .orig_video_points = 16 |
| 212 | }; |
| 213 | } |
| 214 | #endif |
| 215 | |
Dmitri Vorobiev | 750dc31 | 2008-01-24 19:52:56 +0300 | [diff] [blame] | 216 | static void __init bonito_quirks_setup(void) |
| 217 | { |
| 218 | char *argptr; |
| 219 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 220 | argptr = fw_getcmdline(); |
Dmitri Vorobiev | 750dc31 | 2008-01-24 19:52:56 +0300 | [diff] [blame] | 221 | if (strstr(argptr, "debug")) { |
| 222 | BONITO_BONGENCFG |= BONITO_BONGENCFG_DEBUGMODE; |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 223 | pr_info("Enabled Bonito debug mode\n"); |
Dmitri Vorobiev | 750dc31 | 2008-01-24 19:52:56 +0300 | [diff] [blame] | 224 | } else |
| 225 | BONITO_BONGENCFG &= ~BONITO_BONGENCFG_DEBUGMODE; |
| 226 | |
| 227 | #ifdef CONFIG_DMA_COHERENT |
| 228 | if (BONITO_PCICACHECTRL & BONITO_PCICACHECTRL_CPUCOH_PRES) { |
| 229 | BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_CPUCOH_EN; |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 230 | pr_info("Enabled Bonito CPU coherency\n"); |
Dmitri Vorobiev | 750dc31 | 2008-01-24 19:52:56 +0300 | [diff] [blame] | 231 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 232 | argptr = fw_getcmdline(); |
Dmitri Vorobiev | 750dc31 | 2008-01-24 19:52:56 +0300 | [diff] [blame] | 233 | if (strstr(argptr, "iobcuncached")) { |
| 234 | BONITO_PCICACHECTRL &= ~BONITO_PCICACHECTRL_IOBCCOH_EN; |
| 235 | BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG & |
| 236 | ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED | |
| 237 | BONITO_PCIMEMBASECFG_MEMBASE1_CACHED); |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 238 | pr_info("Disabled Bonito IOBC coherency\n"); |
Dmitri Vorobiev | 750dc31 | 2008-01-24 19:52:56 +0300 | [diff] [blame] | 239 | } else { |
| 240 | BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_IOBCCOH_EN; |
| 241 | BONITO_PCIMEMBASECFG |= |
| 242 | (BONITO_PCIMEMBASECFG_MEMBASE0_CACHED | |
| 243 | BONITO_PCIMEMBASECFG_MEMBASE1_CACHED); |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 244 | pr_info("Enabled Bonito IOBC coherency\n"); |
Dmitri Vorobiev | 750dc31 | 2008-01-24 19:52:56 +0300 | [diff] [blame] | 245 | } |
| 246 | } else |
| 247 | panic("Hardware DMA cache coherency not supported"); |
| 248 | #endif |
| 249 | } |
| 250 | |
Ralf Baechle | 2925aba | 2006-06-18 01:32:22 +0100 | [diff] [blame] | 251 | void __init plat_mem_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { |
| 253 | unsigned int i; |
Paul Burton | e81a8c7d | 2015-09-22 11:56:38 -0700 | [diff] [blame] | 254 | void *fdt = __dtb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Paul Burton | e81a8c7d | 2015-09-22 11:56:38 -0700 | [diff] [blame] | 256 | fdt = malta_dt_shim(fdt); |
| 257 | __dt_setup_arch(fdt); |
Paul Burton | e8823d2 | 2015-05-22 16:51:02 +0100 | [diff] [blame] | 258 | |
Markos Chandras | f8b7faf | 2014-01-15 11:18:56 +0000 | [diff] [blame] | 259 | if (config_enabled(CONFIG_EVA)) |
| 260 | /* EVA has already been configured in mach-malta/kernel-init.h */ |
| 261 | pr_info("Enhanced Virtual Addressing (EVA) activated\n"); |
| 262 | |
Ralf Baechle | c83cfc9 | 2005-06-21 13:56:30 +0000 | [diff] [blame] | 263 | mips_pcibios_init(); |
| 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | /* Request I/O space for devices used on the Malta board. */ |
| 266 | for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++) |
| 267 | request_resource(&ioport_resource, standard_io_resources+i); |
| 268 | |
| 269 | /* |
| 270 | * Enable DMA channel 4 (cascade channel) in the PIIX4 south bridge. |
| 271 | */ |
| 272 | enable_dma(4); |
| 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | #ifdef CONFIG_DMA_COHERENT |
Dmitri Vorobiev | 750dc31 | 2008-01-24 19:52:56 +0300 | [diff] [blame] | 275 | if (mips_revision_sconid != MIPS_REVISION_SCON_BONITO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | panic("Hardware DMA cache coherency not supported"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | #endif |
| 278 | |
Dmitri Vorobiev | 750dc31 | 2008-01-24 19:52:56 +0300 | [diff] [blame] | 279 | if (mips_revision_sconid == MIPS_REVISION_SCON_BONITO) |
| 280 | bonito_quirks_setup(); |
| 281 | |
Steven J. Hill | b6d92b4 | 2013-03-25 13:47:29 -0500 | [diff] [blame] | 282 | plat_setup_iocoherency(); |
| 283 | |
Dmitri Vorobiev | f3a4ce9 | 2008-01-24 19:52:43 +0300 | [diff] [blame] | 284 | pci_clock_check(); |
Dmitri Vorobiev | 750dc31 | 2008-01-24 19:52:56 +0300 | [diff] [blame] | 285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | #ifdef CONFIG_BLK_DEV_FD |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 287 | fd_activate(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | #endif |
Dmitri Vorobiev | 750dc31 | 2008-01-24 19:52:56 +0300 | [diff] [blame] | 289 | |
Dmitri Vorobiev | a382963 | 2008-01-24 19:52:44 +0300 | [diff] [blame] | 290 | #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE) |
| 291 | screen_info_setup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | #endif |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 293 | |
| 294 | board_be_init = malta_be_init; |
| 295 | board_be_handler = malta_be_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | } |