malta-setup.c 7.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
/*
 * Carsten Langgaard, carstenl@mips.com
 * Copyright (C) 2000 MIPS Technologies, Inc.  All rights reserved.
4
 * Copyright (C) 2008 Dmitri Vorobiev
L
Linus Torvalds 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 *  This program is free software; you can distribute it and/or modify it
 *  under the terms of the GNU General Public License (Version 2) as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope it will be useful, but WITHOUT
 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 *  for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
 */
19
#include <linux/cpu.h>
L
Linus Torvalds 已提交
20 21 22
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/ioport.h>
23
#include <linux/irq.h>
P
Paul Burton 已提交
24
#include <linux/of_fdt.h>
L
Linus Torvalds 已提交
25
#include <linux/pci.h>
26
#include <linux/screen_info.h>
27
#include <linux/time.h>
L
Linus Torvalds 已提交
28

29
#include <asm/fw/fw.h>
30
#include <asm/mach-malta/malta-dtshim.h>
31
#include <asm/mips-cps.h>
L
Linus Torvalds 已提交
32 33 34 35
#include <asm/mips-boards/generic.h>
#include <asm/mips-boards/malta.h>
#include <asm/mips-boards/maltaint.h>
#include <asm/dma.h>
P
Paul Burton 已提交
36
#include <asm/prom.h>
L
Linus Torvalds 已提交
37 38 39 40 41
#include <asm/traps.h>
#ifdef CONFIG_VT
#include <linux/console.h>
#endif

42 43 44
#define ROCIT_CONFIG_GEN0		0x1f403000
#define  ROCIT_CONFIG_GEN0_PCI_IOCU	BIT(7)

45
static struct resource standard_io_resources[] = {
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
	{
		.name = "dma1",
		.start = 0x00,
		.end = 0x1f,
		.flags = IORESOURCE_BUSY
	},
	{
		.name = "timer",
		.start = 0x40,
		.end = 0x5f,
		.flags = IORESOURCE_BUSY
	},
	{
		.name = "keyboard",
		.start = 0x60,
		.end = 0x6f,
		.flags = IORESOURCE_BUSY
	},
	{
		.name = "dma page reg",
		.start = 0x80,
		.end = 0x8f,
		.flags = IORESOURCE_BUSY
	},
	{
		.name = "dma2",
		.start = 0xc0,
		.end = 0xdf,
		.flags = IORESOURCE_BUSY
	},
L
Linus Torvalds 已提交
76 77 78 79 80 81 82
};

const char *get_system_type(void)
{
	return "MIPS Malta";
}

R
Ralf Baechle 已提交
83
const char display_string[] = "	       LINUX ON MALTA	    ";
84

L
Linus Torvalds 已提交
85
#ifdef CONFIG_BLK_DEV_FD
86
static void __init fd_activate(void)
L
Linus Torvalds 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
{
	/*
	 * Activate Floppy Controller in the SMSC FDC37M817 Super I/O
	 * Controller.
	 * Done by YAMON 2.00 onwards
	 */
	/* Entering config state. */
	SMSC_WRITE(SMSC_CONFIG_ENTER, SMSC_CONFIG_REG);

	/* Activate floppy controller. */
	SMSC_WRITE(SMSC_CONFIG_DEVNUM, SMSC_CONFIG_REG);
	SMSC_WRITE(SMSC_CONFIG_DEVNUM_FLOPPY, SMSC_DATA_REG);
	SMSC_WRITE(SMSC_CONFIG_ACTIVATE, SMSC_CONFIG_REG);
	SMSC_WRITE(SMSC_CONFIG_ACTIVATE_ENABLE, SMSC_DATA_REG);

	/* Exit config state. */
	SMSC_WRITE(SMSC_CONFIG_EXIT, SMSC_CONFIG_REG);
}
#endif

107 108 109
static int __init plat_enable_iocoherency(void)
{
	int supported = 0;
110 111
	u32 cfg;

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
	if (mips_revision_sconid == MIPS_REVISION_SCON_BONITO) {
		if (BONITO_PCICACHECTRL & BONITO_PCICACHECTRL_CPUCOH_PRES) {
			BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_CPUCOH_EN;
			pr_info("Enabled Bonito CPU coherency\n");
			supported = 1;
		}
		if (strstr(fw_getcmdline(), "iobcuncached")) {
			BONITO_PCICACHECTRL &= ~BONITO_PCICACHECTRL_IOBCCOH_EN;
			BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
				~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
				  BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
			pr_info("Disabled Bonito IOBC coherency\n");
		} else {
			BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_IOBCCOH_EN;
			BONITO_PCIMEMBASECFG |=
				(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
				 BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
			pr_info("Enabled Bonito IOBC coherency\n");
		}
131
	} else if (mips_cps_numiocu(0) != 0) {
132 133
		/* Nothing special needs to be done to enable coherency */
		pr_info("CMP IOCU detected\n");
134 135
		cfg = __raw_readl((u32 *)CKSEG1ADDR(ROCIT_CONFIG_GEN0));
		if (!(cfg & ROCIT_CONFIG_GEN0_PCI_IOCU)) {
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
			pr_crit("IOCU OPERATION DISABLED BY SWITCH - DEFAULTING TO SW IO COHERENCY\n");
			return 0;
		}
		supported = 1;
	}
	hw_coherentio = supported;
	return supported;
}

static void __init plat_setup_iocoherency(void)
{
#ifdef CONFIG_DMA_NONCOHERENT
	/*
	 * Kernel has been configured with software coherency
	 * but we might choose to turn it off and use hardware
	 * coherency instead.
	 */
	if (plat_enable_iocoherency()) {
P
Paul Burton 已提交
154
		if (coherentio == IO_COHERENCE_DISABLED)
155 156 157 158
			pr_info("Hardware DMA cache coherency disabled\n");
		else
			pr_info("Hardware DMA cache coherency enabled\n");
	} else {
P
Paul Burton 已提交
159
		if (coherentio == IO_COHERENCE_ENABLED)
160 161 162 163 164 165 166 167 168 169
			pr_info("Hardware DMA cache coherency unsupported, but enabled from command line!\n");
		else
			pr_info("Software DMA cache coherency enabled\n");
	}
#else
	if (!plat_enable_iocoherency())
		panic("Hardware DMA cache coherency not supported!");
#endif
}

170 171 172 173 174
static void __init pci_clock_check(void)
{
	unsigned int __iomem *jmpr_p =
		(unsigned int *) ioremap(MALTA_JMPRS_REG, sizeof(unsigned int));
	int jmpr = (__raw_readl(jmpr_p) >> 2) & 0x07;
175
	static const int pciclocks[] __initconst = {
176 177 178
		33, 20, 25, 30, 12, 16, 37, 10
	};
	int pciclock = pciclocks[jmpr];
179
	char *optptr, *argptr = fw_getcmdline();
180

181 182 183 184 185 186 187 188 189
	/*
	 * If user passed a pci_clock= option, don't tack on another one
	 */
	optptr = strstr(argptr, "pci_clock=");
	if (optptr && (optptr == argptr || optptr[-1] == ' '))
		return;

	if (pciclock != 33) {
		pr_warn("WARNING: PCI clock is %dMHz, setting pci_clock\n",
190
			pciclock);
191
		argptr += strlen(argptr);
192
		sprintf(argptr, " pci_clock=%d", pciclock);
193
		if (pciclock < 20 || pciclock > 66)
194 195
			pr_warn("WARNING: IDE timing calculations will be "
			        "incorrect\n");
196 197 198
	}
}

199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
static void __init screen_info_setup(void)
{
	screen_info = (struct screen_info) {
		.orig_x = 0,
		.orig_y = 25,
		.ext_mem_k = 0,
		.orig_video_page = 0,
		.orig_video_mode = 0,
		.orig_video_cols = 80,
		.unused2 = 0,
		.orig_video_ega_bx = 0,
		.unused3 = 0,
		.orig_video_lines = 25,
		.orig_video_isVGA = VIDEO_TYPE_VGAC,
		.orig_video_points = 16
	};
}
#endif

219 220 221 222
static void __init bonito_quirks_setup(void)
{
	char *argptr;

223
	argptr = fw_getcmdline();
224 225
	if (strstr(argptr, "debug")) {
		BONITO_BONGENCFG |= BONITO_BONGENCFG_DEBUGMODE;
226
		pr_info("Enabled Bonito debug mode\n");
227 228 229 230 231 232
	} else
		BONITO_BONGENCFG &= ~BONITO_BONGENCFG_DEBUGMODE;

#ifdef CONFIG_DMA_COHERENT
	if (BONITO_PCICACHECTRL & BONITO_PCICACHECTRL_CPUCOH_PRES) {
		BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_CPUCOH_EN;
233
		pr_info("Enabled Bonito CPU coherency\n");
234

235
		argptr = fw_getcmdline();
236 237 238 239 240
		if (strstr(argptr, "iobcuncached")) {
			BONITO_PCICACHECTRL &= ~BONITO_PCICACHECTRL_IOBCCOH_EN;
			BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
				~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
					BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
241
			pr_info("Disabled Bonito IOBC coherency\n");
242 243 244 245 246
		} else {
			BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_IOBCCOH_EN;
			BONITO_PCIMEMBASECFG |=
				(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
					BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
247
			pr_info("Enabled Bonito IOBC coherency\n");
248 249 250 251 252 253
		}
	} else
		panic("Hardware DMA cache coherency not supported");
#endif
}

254 255 256 257 258
void __init *plat_get_fdt(void)
{
	return (void *)__dtb_start;
}

259
void __init plat_mem_setup(void)
L
Linus Torvalds 已提交
260 261
{
	unsigned int i;
262
	void *fdt = plat_get_fdt();
L
Linus Torvalds 已提交
263

264 265
	fdt = malta_dt_shim(fdt);
	__dt_setup_arch(fdt);
P
Paul Burton 已提交
266

267
	if (IS_ENABLED(CONFIG_EVA))
268 269 270
		/* EVA has already been configured in mach-malta/kernel-init.h */
		pr_info("Enhanced Virtual Addressing (EVA) activated\n");

271 272
	mips_pcibios_init();

L
Linus Torvalds 已提交
273 274 275 276 277 278 279 280 281 282
	/* Request I/O space for devices used on the Malta board. */
	for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
		request_resource(&ioport_resource, standard_io_resources+i);

	/*
	 * Enable DMA channel 4 (cascade channel) in the PIIX4 south bridge.
	 */
	enable_dma(4);

#ifdef CONFIG_DMA_COHERENT
283
	if (mips_revision_sconid != MIPS_REVISION_SCON_BONITO)
L
Linus Torvalds 已提交
284 285 286
		panic("Hardware DMA cache coherency not supported");
#endif

287 288 289
	if (mips_revision_sconid == MIPS_REVISION_SCON_BONITO)
		bonito_quirks_setup();

290 291
	plat_setup_iocoherency();

292
	pci_clock_check();
293

L
Linus Torvalds 已提交
294
#ifdef CONFIG_BLK_DEV_FD
295
	fd_activate();
L
Linus Torvalds 已提交
296
#endif
297

298 299
#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
	screen_info_setup();
L
Linus Torvalds 已提交
300 301
#endif
}