Linux 5.7.6
[linux/fpc-iii.git] / arch / mips / mti-malta / malta-setup.c
blobc4ad5a9b4bc14bb95c693189505aa4a2b6f7c7bd
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Carsten Langgaard, carstenl@mips.com
4 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
5 * Copyright (C) 2008 Dmitri Vorobiev
6 */
7 #include <linux/cpu.h>
8 #include <linux/init.h>
9 #include <linux/sched.h>
10 #include <linux/ioport.h>
11 #include <linux/irq.h>
12 #include <linux/of_fdt.h>
13 #include <linux/pci.h>
14 #include <linux/screen_info.h>
15 #include <linux/time.h>
17 #include <asm/dma-coherence.h>
18 #include <asm/fw/fw.h>
19 #include <asm/mach-malta/malta-dtshim.h>
20 #include <asm/mips-cps.h>
21 #include <asm/mips-boards/generic.h>
22 #include <asm/mips-boards/malta.h>
23 #include <asm/mips-boards/maltaint.h>
24 #include <asm/dma.h>
25 #include <asm/prom.h>
26 #include <asm/traps.h>
27 #ifdef CONFIG_VT
28 #include <linux/console.h>
29 #endif
31 #define ROCIT_CONFIG_GEN0 0x1f403000
32 #define ROCIT_CONFIG_GEN0_PCI_IOCU BIT(7)
34 static struct resource standard_io_resources[] = {
36 .name = "dma1",
37 .start = 0x00,
38 .end = 0x1f,
39 .flags = IORESOURCE_IO | IORESOURCE_BUSY
42 .name = "timer",
43 .start = 0x40,
44 .end = 0x5f,
45 .flags = IORESOURCE_IO | IORESOURCE_BUSY
48 .name = "keyboard",
49 .start = 0x60,
50 .end = 0x6f,
51 .flags = IORESOURCE_IO | IORESOURCE_BUSY
54 .name = "dma page reg",
55 .start = 0x80,
56 .end = 0x8f,
57 .flags = IORESOURCE_IO | IORESOURCE_BUSY
60 .name = "dma2",
61 .start = 0xc0,
62 .end = 0xdf,
63 .flags = IORESOURCE_IO | IORESOURCE_BUSY
67 const char *get_system_type(void)
69 return "MIPS Malta";
72 #ifdef CONFIG_BLK_DEV_FD
73 static void __init fd_activate(void)
76 * Activate Floppy Controller in the SMSC FDC37M817 Super I/O
77 * Controller.
78 * Done by YAMON 2.00 onwards
80 /* Entering config state. */
81 SMSC_WRITE(SMSC_CONFIG_ENTER, SMSC_CONFIG_REG);
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);
89 /* Exit config state. */
90 SMSC_WRITE(SMSC_CONFIG_EXIT, SMSC_CONFIG_REG);
92 #endif
94 static int __init plat_enable_iocoherency(void)
96 int supported = 0;
97 u32 cfg;
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;
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");
118 } else if (mips_cps_numiocu(0) != 0) {
119 /* Nothing special needs to be done to enable coherency */
120 pr_info("CMP IOCU detected\n");
121 cfg = __raw_readl((u32 *)CKSEG1ADDR(ROCIT_CONFIG_GEN0));
122 if (!(cfg & ROCIT_CONFIG_GEN0_PCI_IOCU)) {
123 pr_crit("IOCU OPERATION DISABLED BY SWITCH - DEFAULTING TO SW IO COHERENCY\n");
124 return 0;
126 supported = 1;
128 hw_coherentio = supported;
129 return supported;
132 static void __init plat_setup_iocoherency(void)
134 if (plat_enable_iocoherency()) {
135 if (coherentio == IO_COHERENCE_DISABLED)
136 pr_info("Hardware DMA cache coherency disabled\n");
137 else
138 pr_info("Hardware DMA cache coherency enabled\n");
139 } else {
140 if (coherentio == IO_COHERENCE_ENABLED)
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");
147 static void __init pci_clock_check(void)
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;
152 static const int pciclocks[] __initconst = {
153 33, 20, 25, 30, 12, 16, 37, 10
155 int pciclock = pciclocks[jmpr];
156 char *optptr, *argptr = fw_getcmdline();
159 * If user passed a pci_clock= option, don't tack on another one
161 optptr = strstr(argptr, "pci_clock=");
162 if (optptr && (optptr == argptr || optptr[-1] == ' '))
163 return;
165 if (pciclock != 33) {
166 pr_warn("WARNING: PCI clock is %dMHz, setting pci_clock\n",
167 pciclock);
168 argptr += strlen(argptr);
169 sprintf(argptr, " pci_clock=%d", pciclock);
170 if (pciclock < 20 || pciclock > 66)
171 pr_warn("WARNING: IDE timing calculations will be "
172 "incorrect\n");
176 #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
177 static void __init screen_info_setup(void)
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
194 #endif
196 static void __init bonito_quirks_setup(void)
198 char *argptr;
200 argptr = fw_getcmdline();
201 if (strstr(argptr, "debug")) {
202 BONITO_BONGENCFG |= BONITO_BONGENCFG_DEBUGMODE;
203 pr_info("Enabled Bonito debug mode\n");
204 } else
205 BONITO_BONGENCFG &= ~BONITO_BONGENCFG_DEBUGMODE;
208 void __init *plat_get_fdt(void)
210 return (void *)__dtb_start;
213 void __init plat_mem_setup(void)
215 unsigned int i;
216 void *fdt = plat_get_fdt();
218 fdt = malta_dt_shim(fdt);
219 __dt_setup_arch(fdt);
221 if (IS_ENABLED(CONFIG_EVA))
222 /* EVA has already been configured in mach-malta/kernel-init.h */
223 pr_info("Enhanced Virtual Addressing (EVA) activated\n");
225 mips_pcibios_init();
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);
232 * Enable DMA channel 4 (cascade channel) in the PIIX4 south bridge.
234 enable_dma(4);
236 if (mips_revision_sconid == MIPS_REVISION_SCON_BONITO)
237 bonito_quirks_setup();
239 plat_setup_iocoherency();
241 pci_clock_check();
243 #ifdef CONFIG_BLK_DEV_FD
244 fd_activate();
245 #endif
247 #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
248 screen_info_setup();
249 #endif