v2m.c 11.9 KB
Newer Older
1 2 3 4 5 6 7
/*
 * Versatile Express V2M Motherboard Support
 */
#include <linux/device.h>
#include <linux/amba/bus.h>
#include <linux/amba/mmci.h>
#include <linux/io.h>
8
#include <linux/smp.h>
9
#include <linux/init.h>
10
#include <linux/irqchip.h>
11 12 13 14
#include <linux/of_address.h>
#include <linux/of_fdt.h>
#include <linux/of_irq.h>
#include <linux/of_platform.h>
15
#include <linux/platform_device.h>
16
#include <linux/ata_platform.h>
17 18 19
#include <linux/smsc911x.h>
#include <linux/spinlock.h>
#include <linux/usb/isp1760.h>
20
#include <linux/mtd/physmap.h>
21 22
#include <linux/regulator/fixed.h>
#include <linux/regulator/machine.h>
23
#include <linux/vexpress.h>
24 25
#include <linux/clk-provider.h>
#include <linux/clkdev.h>
26

27
#include <asm/arch_timer.h>
28
#include <asm/mach-types.h>
29
#include <asm/sizes.h>
30
#include <asm/smp_twd.h>
31
#include <asm/mach/arch.h>
32 33 34
#include <asm/mach/map.h>
#include <asm/mach/time.h>
#include <asm/hardware/arm_timer.h>
35
#include <asm/hardware/cache-l2x0.h>
R
Russell King 已提交
36
#include <asm/hardware/timer-sp.h>
37

38
#include <mach/ct-ca9x4.h>
39 40
#include <mach/motherboard.h>

41
#include <plat/sched_clock.h>
42
#include <plat/platsmp.h>
43 44 45 46 47 48 49 50 51 52 53

#include "core.h"

#define V2M_PA_CS0	0x40000000
#define V2M_PA_CS1	0x44000000
#define V2M_PA_CS2	0x48000000
#define V2M_PA_CS3	0x4c000000
#define V2M_PA_CS7	0x10000000

static struct map_desc v2m_io_desc[] __initdata = {
	{
P
Pawel Moll 已提交
54
		.virtual	= V2M_PERIPH,
55 56 57 58 59 60
		.pfn		= __phys_to_pfn(V2M_PA_CS7),
		.length		= SZ_128K,
		.type		= MT_DEVICE,
	},
};

P
Pawel Moll 已提交
61 62 63 64 65 66 67
static void __init v2m_sp804_init(void __iomem *base, unsigned int irq)
{
	if (WARN_ON(!base || irq == NO_IRQ))
		return;

	writel(0, base + TIMER_1_BASE + TIMER_CTRL);
	writel(0, base + TIMER_2_BASE + TIMER_CTRL);
68

P
Pawel Moll 已提交
69 70 71
	sp804_clocksource_init(base + TIMER_2_BASE, "v2m-timer1");
	sp804_clockevents_init(base + TIMER_1_BASE, irq, "v2m-timer0");
}
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126


static struct resource v2m_pcie_i2c_resource = {
	.start	= V2M_SERIAL_BUS_PCI,
	.end	= V2M_SERIAL_BUS_PCI + SZ_4K - 1,
	.flags	= IORESOURCE_MEM,
};

static struct platform_device v2m_pcie_i2c_device = {
	.name		= "versatile-i2c",
	.id		= 0,
	.num_resources	= 1,
	.resource	= &v2m_pcie_i2c_resource,
};

static struct resource v2m_ddc_i2c_resource = {
	.start	= V2M_SERIAL_BUS_DVI,
	.end	= V2M_SERIAL_BUS_DVI + SZ_4K - 1,
	.flags	= IORESOURCE_MEM,
};

static struct platform_device v2m_ddc_i2c_device = {
	.name		= "versatile-i2c",
	.id		= 1,
	.num_resources	= 1,
	.resource	= &v2m_ddc_i2c_resource,
};

static struct resource v2m_eth_resources[] = {
	{
		.start	= V2M_LAN9118,
		.end	= V2M_LAN9118 + SZ_64K - 1,
		.flags	= IORESOURCE_MEM,
	}, {
		.start	= IRQ_V2M_LAN9118,
		.end	= IRQ_V2M_LAN9118,
		.flags	= IORESOURCE_IRQ,
	},
};

static struct smsc911x_platform_config v2m_eth_config = {
	.flags		= SMSC911X_USE_32BIT,
	.irq_polarity	= SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
	.irq_type	= SMSC911X_IRQ_TYPE_PUSH_PULL,
	.phy_interface	= PHY_INTERFACE_MODE_MII,
};

static struct platform_device v2m_eth_device = {
	.name		= "smsc911x",
	.id		= -1,
	.resource	= v2m_eth_resources,
	.num_resources	= ARRAY_SIZE(v2m_eth_resources),
	.dev.platform_data = &v2m_eth_config,
};

127 128 129 130 131
static struct regulator_consumer_supply v2m_eth_supplies[] = {
	REGULATOR_SUPPLY("vddvario", "smsc911x"),
	REGULATOR_SUPPLY("vdd33a", "smsc911x"),
};

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
static struct resource v2m_usb_resources[] = {
	{
		.start	= V2M_ISP1761,
		.end	= V2M_ISP1761 + SZ_128K - 1,
		.flags	= IORESOURCE_MEM,
	}, {
		.start	= IRQ_V2M_ISP1761,
		.end	= IRQ_V2M_ISP1761,
		.flags	= IORESOURCE_IRQ,
	},
};

static struct isp1760_platform_data v2m_usb_config = {
	.is_isp1761		= true,
	.bus_width_16		= false,
	.port1_otg		= true,
	.analog_oc		= false,
	.dack_polarity_high	= false,
	.dreq_polarity_high	= false,
};

static struct platform_device v2m_usb_device = {
	.name		= "isp1760",
	.id		= -1,
	.resource	= v2m_usb_resources,
	.num_resources	= ARRAY_SIZE(v2m_usb_resources),
	.dev.platform_data = &v2m_usb_config,
};

161
static struct physmap_flash_data v2m_flash_data = {
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
	.width		= 4,
};

static struct resource v2m_flash_resources[] = {
	{
		.start	= V2M_NOR0,
		.end	= V2M_NOR0 + SZ_64M - 1,
		.flags	= IORESOURCE_MEM,
	}, {
		.start	= V2M_NOR1,
		.end	= V2M_NOR1 + SZ_64M - 1,
		.flags	= IORESOURCE_MEM,
	},
};

static struct platform_device v2m_flash_device = {
178
	.name		= "physmap-flash",
179 180 181 182 183 184
	.id		= -1,
	.resource	= v2m_flash_resources,
	.num_resources	= ARRAY_SIZE(v2m_flash_resources),
	.dev.platform_data = &v2m_flash_data,
};

185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
static struct pata_platform_info v2m_pata_data = {
	.ioport_shift	= 2,
};

static struct resource v2m_pata_resources[] = {
	{
		.start	= V2M_CF,
		.end	= V2M_CF + 0xff,
		.flags	= IORESOURCE_MEM,
	}, {
		.start	= V2M_CF + 0x100,
		.end	= V2M_CF + SZ_4K - 1,
		.flags	= IORESOURCE_MEM,
	},
};

static struct platform_device v2m_cf_device = {
	.name		= "pata_platform",
	.id		= -1,
	.resource	= v2m_pata_resources,
	.num_resources	= ARRAY_SIZE(v2m_pata_resources),
	.dev.platform_data = &v2m_pata_data,
};
208 209 210

static struct mmci_platform_data v2m_mmci_data = {
	.ocr_mask	= MMC_VDD_32_33|MMC_VDD_33_34,
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
	.gpio_wp	= VEXPRESS_GPIO_MMC_WPROT,
	.gpio_cd	= VEXPRESS_GPIO_MMC_CARDIN,
};

static struct resource v2m_sysreg_resources[] = {
	{
		.start	= V2M_SYSREGS,
		.end	= V2M_SYSREGS + 0xfff,
		.flags	= IORESOURCE_MEM,
	},
};

static struct platform_device v2m_sysreg_device = {
	.name		= "vexpress-sysreg",
	.id		= -1,
	.resource	= v2m_sysreg_resources,
	.num_resources	= ARRAY_SIZE(v2m_sysreg_resources),
};

static struct platform_device v2m_muxfpga_device = {
	.name		= "vexpress-muxfpga",
	.id		= 0,
	.num_resources	= 1,
	.resource	= (struct resource []) {
		VEXPRESS_RES_FUNC(0, 7),
	}
};

static struct platform_device v2m_shutdown_device = {
	.name		= "vexpress-shutdown",
	.id		= 0,
	.num_resources	= 1,
	.resource	= (struct resource []) {
		VEXPRESS_RES_FUNC(0, 8),
	}
};

static struct platform_device v2m_reboot_device = {
	.name		= "vexpress-reboot",
	.id		= 0,
	.num_resources	= 1,
	.resource	= (struct resource []) {
		VEXPRESS_RES_FUNC(0, 9),
	}
};

static struct platform_device v2m_dvimode_device = {
	.name		= "vexpress-dvimode",
	.id		= 0,
	.num_resources	= 1,
	.resource	= (struct resource []) {
		VEXPRESS_RES_FUNC(0, 11),
	}
264 265
};

266 267 268 269 270 271 272 273 274 275
static AMBA_APB_DEVICE(aaci,  "mb:aaci",  0, V2M_AACI, IRQ_V2M_AACI, NULL);
static AMBA_APB_DEVICE(mmci,  "mb:mmci",  0, V2M_MMCI, IRQ_V2M_MMCI, &v2m_mmci_data);
static AMBA_APB_DEVICE(kmi0,  "mb:kmi0",  0, V2M_KMI0, IRQ_V2M_KMI0, NULL);
static AMBA_APB_DEVICE(kmi1,  "mb:kmi1",  0, V2M_KMI1, IRQ_V2M_KMI1, NULL);
static AMBA_APB_DEVICE(uart0, "mb:uart0", 0, V2M_UART0, IRQ_V2M_UART0, NULL);
static AMBA_APB_DEVICE(uart1, "mb:uart1", 0, V2M_UART1, IRQ_V2M_UART1, NULL);
static AMBA_APB_DEVICE(uart2, "mb:uart2", 0, V2M_UART2, IRQ_V2M_UART2, NULL);
static AMBA_APB_DEVICE(uart3, "mb:uart3", 0, V2M_UART3, IRQ_V2M_UART3, NULL);
static AMBA_APB_DEVICE(wdt,   "mb:wdt",   0, V2M_WDT, IRQ_V2M_WDT, NULL);
static AMBA_APB_DEVICE(rtc,   "mb:rtc",   0, V2M_RTC, IRQ_V2M_RTC, NULL);
276 277 278 279 280 281 282 283 284 285 286 287 288 289

static struct amba_device *v2m_amba_devs[] __initdata = {
	&aaci_device,
	&mmci_device,
	&kmi0_device,
	&kmi1_device,
	&uart0_device,
	&uart1_device,
	&uart2_device,
	&uart3_device,
	&wdt_device,
	&rtc_device,
};

290 291
static void __init v2m_timer_init(void)
{
292
	vexpress_clk_init(ioremap(V2M_SYSCTL, SZ_4K));
293 294 295
	v2m_sp804_init(ioremap(V2M_TIMER01, SZ_4K), IRQ_V2M_TIMER0);
}

296 297
static void __init v2m_init_early(void)
{
298 299
	if (ct_desc->init_early)
		ct_desc->init_early();
300
	versatile_sched_clock_init(vexpress_get_24mhz_clock_base(), 24000000);
301 302
}

303 304 305 306 307 308 309 310 311 312 313 314 315 316
struct ct_desc *ct_desc;

static struct ct_desc *ct_descs[] __initdata = {
#ifdef CONFIG_ARCH_VEXPRESS_CA9X4
	&ct_ca9x4_desc,
#endif
};

static void __init v2m_populate_ct_desc(void)
{
	int i;
	u32 current_tile_id;

	ct_desc = NULL;
317
	current_tile_id = vexpress_get_procid(VEXPRESS_SITE_MASTER)
P
Pawel Moll 已提交
318
				& V2M_CT_ID_MASK;
319 320 321 322 323 324

	for (i = 0; i < ARRAY_SIZE(ct_descs) && !ct_desc; ++i)
		if (ct_descs[i]->id == current_tile_id)
			ct_desc = ct_descs[i];

	if (!ct_desc)
325 326 327
		panic("vexpress: this kernel does not support core tile ID 0x%08x when booting via ATAGs.\n"
		      "You may need a device tree blob or a different kernel to boot on this board.\n",
		      current_tile_id);
328 329 330 331 332
}

static void __init v2m_map_io(void)
{
	iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
333
	vexpress_sysreg_early_init(ioremap(V2M_SYSREGS, SZ_4K));
334 335 336 337 338 339 340 341 342 343
	v2m_populate_ct_desc();
	ct_desc->map_io();
}

static void __init v2m_init_irq(void)
{
	ct_desc->init_irq();
}

static void __init v2m_init(void)
344 345 346
{
	int i;

347 348 349
	regulator_register_fixed(0, v2m_eth_supplies,
			ARRAY_SIZE(v2m_eth_supplies));

350 351 352 353 354 355
	platform_device_register(&v2m_muxfpga_device);
	platform_device_register(&v2m_shutdown_device);
	platform_device_register(&v2m_reboot_device);
	platform_device_register(&v2m_dvimode_device);

	platform_device_register(&v2m_sysreg_device);
356 357 358
	platform_device_register(&v2m_pcie_i2c_device);
	platform_device_register(&v2m_ddc_i2c_device);
	platform_device_register(&v2m_flash_device);
359
	platform_device_register(&v2m_cf_device);
360 361 362 363 364 365
	platform_device_register(&v2m_eth_device);
	platform_device_register(&v2m_usb_device);

	for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++)
		amba_device_register(v2m_amba_devs[i], &iomem_resource);

366
	pm_power_off = vexpress_power_off;
367

368
	ct_desc->init_tile();
369
}
370 371

MACHINE_START(VEXPRESS, "ARM-Versatile Express")
372
	.atag_offset	= 0x100,
373
	.smp		= smp_ops(vexpress_smp_ops),
374 375 376
	.map_io		= v2m_map_io,
	.init_early	= v2m_init_early,
	.init_irq	= v2m_init_irq,
S
Stephen Warren 已提交
377
	.init_time	= v2m_timer_init,
378
	.init_machine	= v2m_init,
379
	.restart	= vexpress_restart,
380
MACHINE_END
381

382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
static struct map_desc v2m_rs1_io_desc __initdata = {
	.virtual	= V2M_PERIPH,
	.pfn		= __phys_to_pfn(0x1c000000),
	.length		= SZ_2M,
	.type		= MT_DEVICE,
};

static int __init v2m_dt_scan_memory_map(unsigned long node, const char *uname,
		int depth, void *data)
{
	const char **map = data;

	if (strcmp(uname, "motherboard") != 0)
		return 0;

	*map = of_get_flat_dt_prop(node, "arm,v2m-memory-map", NULL);

	return 1;
}

402 403
void __init v2m_dt_map_io(void)
{
404 405 406 407 408 409 410 411
	const char *map = NULL;

	of_scan_flat_dt(v2m_dt_scan_memory_map, &map);

	if (map && strcmp(map, "rs1") == 0)
		iotable_init(&v2m_rs1_io_desc, 1);
	else
		iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
412 413 414 415 416 417 418 419 420 421

#if defined(CONFIG_SMP)
	vexpress_dt_smp_map_io();
#endif
}

void __init v2m_dt_init_early(void)
{
	u32 dt_hbi;

422
	vexpress_sysreg_of_early_init();
423 424

	/* Confirm board type against DT property, if available */
425
	if (of_property_read_u32(of_allnodes, "arm,hbi", &dt_hbi) == 0) {
426
		u32 hbi = vexpress_get_hbi(VEXPRESS_SITE_MASTER);
427 428 429 430 431 432 433 434 435

		if (WARN_ON(dt_hbi != hbi))
			pr_warning("vexpress: DT HBI (%x) is not matching "
					"hardware (%x)!\n", dt_hbi, hbi);
	}
}

static void __init v2m_dt_timer_init(void)
{
436
	struct device_node *node = NULL;
437

438
	of_clk_init(NULL);
439

440 441 442 443 444 445
	do {
		node = of_find_compatible_node(node, NULL, "arm,sp804");
	} while (node && vexpress_get_site_by_node(node) != VEXPRESS_SITE_MB);
	if (node) {
		pr_info("Using SP804 '%s' as a clock & events source\n",
				node->full_name);
446 447 448 449
		WARN_ON(clk_register_clkdev(of_clk_get_by_name(node,
				"timclken1"), "v2m-timer0", "sp804"));
		WARN_ON(clk_register_clkdev(of_clk_get_by_name(node,
				"timclken2"), "v2m-timer1", "sp804"));
450 451 452
		v2m_sp804_init(of_iomap(node, 0),
				irq_of_parse_and_map(node, 0));
	}
453

454 455 456 457
	if (arch_timer_of_register() != 0)
		twd_local_timer_of_register();

	if (arch_timer_sched_clock_init() != 0)
458 459
		versatile_sched_clock_init(vexpress_get_24mhz_clock_base(),
				24000000);
460 461
}

462 463 464 465
static const struct of_device_id v2m_dt_bus_match[] __initconst = {
	{ .compatible = "simple-bus", },
	{ .compatible = "arm,amba-bus", },
	{ .compatible = "arm,vexpress,config-bus", },
466 467 468 469 470 471
	{}
};

static void __init v2m_dt_init(void)
{
	l2x0_of_init(0x00400000, 0xfe0fffff);
472 473
	of_platform_populate(NULL, v2m_dt_bus_match, NULL, NULL);
	pm_power_off = vexpress_power_off;
474 475
}

476
static const char * const v2m_dt_match[] __initconst = {
477
	"arm,vexpress",
478
	"xen,xenvm",
479 480 481 482 483
	NULL,
};

DT_MACHINE_START(VEXPRESS_DT, "ARM-Versatile Express")
	.dt_compat	= v2m_dt_match,
484
	.smp		= smp_ops(vexpress_smp_ops),
485 486
	.map_io		= v2m_dt_map_io,
	.init_early	= v2m_dt_init_early,
487
	.init_irq	= irqchip_init,
S
Stephen Warren 已提交
488
	.init_time	= v2m_dt_timer_init,
489
	.init_machine	= v2m_dt_init,
490
	.restart	= vexpress_restart,
491
MACHINE_END