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