2 * Versatile Express V2M Motherboard Support
4 #include <linux/device.h>
5 #include <linux/amba/bus.h>
6 #include <linux/amba/mmci.h>
8 #include <linux/init.h>
9 #include <linux/of_address.h>
10 #include <linux/of_fdt.h>
11 #include <linux/of_irq.h>
12 #include <linux/of_platform.h>
13 #include <linux/platform_device.h>
14 #include <linux/ata_platform.h>
15 #include <linux/smsc911x.h>
16 #include <linux/spinlock.h>
17 #include <linux/device.h>
18 #include <linux/usb/isp1760.h>
19 #include <linux/clkdev.h>
20 #include <linux/mtd/physmap.h>
22 #include <asm/arch_timer.h>
23 #include <asm/mach-types.h>
24 #include <asm/sizes.h>
25 #include <asm/smp_twd.h>
26 #include <asm/mach/arch.h>
27 #include <asm/mach/map.h>
28 #include <asm/mach/time.h>
29 #include <asm/hardware/arm_timer.h>
30 #include <asm/hardware/cache-l2x0.h>
31 #include <asm/hardware/gic.h>
32 #include <asm/hardware/timer-sp.h>
33 #include <asm/hardware/sp810.h>
34 #include <asm/hardware/gic.h>
36 #include <mach/ct-ca9x4.h>
37 #include <mach/motherboard.h>
39 #include <plat/sched_clock.h>
43 #define V2M_PA_CS0 0x40000000
44 #define V2M_PA_CS1 0x44000000
45 #define V2M_PA_CS2 0x48000000
46 #define V2M_PA_CS3 0x4c000000
47 #define V2M_PA_CS7 0x10000000
49 static struct map_desc v2m_io_desc[] __initdata = {
51 .virtual = V2M_PERIPH,
52 .pfn = __phys_to_pfn(V2M_PA_CS7),
58 static void __iomem *v2m_sysreg_base;
60 static void __init v2m_sysctl_init(void __iomem *base)
67 /* Select 1MHz TIMCLK as the reference clock for SP804 timers */
68 scctrl = readl(base + SCCTRL);
69 scctrl |= SCCTRL_TIMEREN0SEL_TIMCLK;
70 scctrl |= SCCTRL_TIMEREN1SEL_TIMCLK;
71 writel(scctrl, base + SCCTRL);
74 static void __init v2m_sp804_init(void __iomem *base, unsigned int irq)
76 if (WARN_ON(!base || irq == NO_IRQ))
79 writel(0, base + TIMER_1_BASE + TIMER_CTRL);
80 writel(0, base + TIMER_2_BASE + TIMER_CTRL);
82 sp804_clocksource_init(base + TIMER_2_BASE, "v2m-timer1");
83 sp804_clockevents_init(base + TIMER_1_BASE, irq, "v2m-timer0");
86 static void __init v2m_timer_init(void)
88 v2m_sysctl_init(ioremap(V2M_SYSCTL, SZ_4K));
89 v2m_sp804_init(ioremap(V2M_TIMER01, SZ_4K), IRQ_V2M_TIMER0);
92 static struct sys_timer v2m_timer = {
93 .init = v2m_timer_init,
97 static DEFINE_SPINLOCK(v2m_cfg_lock);
99 int v2m_cfg_write(u32 devfn, u32 data)
101 /* Configuration interface broken? */
104 printk("%s: writing %08x to %08x\n", __func__, data, devfn);
106 devfn |= SYS_CFG_START | SYS_CFG_WRITE;
108 spin_lock(&v2m_cfg_lock);
109 val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT);
110 writel(val & ~SYS_CFG_COMPLETE, v2m_sysreg_base + V2M_SYS_CFGSTAT);
112 writel(data, v2m_sysreg_base + V2M_SYS_CFGDATA);
113 writel(devfn, v2m_sysreg_base + V2M_SYS_CFGCTRL);
116 val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT);
118 spin_unlock(&v2m_cfg_lock);
120 return !!(val & SYS_CFG_ERR);
123 int v2m_cfg_read(u32 devfn, u32 *data)
127 devfn |= SYS_CFG_START;
129 spin_lock(&v2m_cfg_lock);
130 writel(0, v2m_sysreg_base + V2M_SYS_CFGSTAT);
131 writel(devfn, v2m_sysreg_base + V2M_SYS_CFGCTRL);
137 val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT);
140 *data = readl(v2m_sysreg_base + V2M_SYS_CFGDATA);
141 spin_unlock(&v2m_cfg_lock);
143 return !!(val & SYS_CFG_ERR);
146 void __init v2m_flags_set(u32 data)
148 writel(~0, v2m_sysreg_base + V2M_SYS_FLAGSCLR);
149 writel(data, v2m_sysreg_base + V2M_SYS_FLAGSSET);
153 static struct resource v2m_pcie_i2c_resource = {
154 .start = V2M_SERIAL_BUS_PCI,
155 .end = V2M_SERIAL_BUS_PCI + SZ_4K - 1,
156 .flags = IORESOURCE_MEM,
159 static struct platform_device v2m_pcie_i2c_device = {
160 .name = "versatile-i2c",
163 .resource = &v2m_pcie_i2c_resource,
166 static struct resource v2m_ddc_i2c_resource = {
167 .start = V2M_SERIAL_BUS_DVI,
168 .end = V2M_SERIAL_BUS_DVI + SZ_4K - 1,
169 .flags = IORESOURCE_MEM,
172 static struct platform_device v2m_ddc_i2c_device = {
173 .name = "versatile-i2c",
176 .resource = &v2m_ddc_i2c_resource,
179 static struct resource v2m_eth_resources[] = {
181 .start = V2M_LAN9118,
182 .end = V2M_LAN9118 + SZ_64K - 1,
183 .flags = IORESOURCE_MEM,
185 .start = IRQ_V2M_LAN9118,
186 .end = IRQ_V2M_LAN9118,
187 .flags = IORESOURCE_IRQ,
191 static struct smsc911x_platform_config v2m_eth_config = {
192 .flags = SMSC911X_USE_32BIT,
193 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
194 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
195 .phy_interface = PHY_INTERFACE_MODE_MII,
198 static struct platform_device v2m_eth_device = {
201 .resource = v2m_eth_resources,
202 .num_resources = ARRAY_SIZE(v2m_eth_resources),
203 .dev.platform_data = &v2m_eth_config,
206 static struct resource v2m_usb_resources[] = {
208 .start = V2M_ISP1761,
209 .end = V2M_ISP1761 + SZ_128K - 1,
210 .flags = IORESOURCE_MEM,
212 .start = IRQ_V2M_ISP1761,
213 .end = IRQ_V2M_ISP1761,
214 .flags = IORESOURCE_IRQ,
218 static struct isp1760_platform_data v2m_usb_config = {
220 .bus_width_16 = false,
223 .dack_polarity_high = false,
224 .dreq_polarity_high = false,
227 static struct platform_device v2m_usb_device = {
230 .resource = v2m_usb_resources,
231 .num_resources = ARRAY_SIZE(v2m_usb_resources),
232 .dev.platform_data = &v2m_usb_config,
235 static void v2m_flash_set_vpp(struct platform_device *pdev, int on)
237 writel(on != 0, v2m_sysreg_base + V2M_SYS_FLASH);
240 static struct physmap_flash_data v2m_flash_data = {
242 .set_vpp = v2m_flash_set_vpp,
245 static struct resource v2m_flash_resources[] = {
248 .end = V2M_NOR0 + SZ_64M - 1,
249 .flags = IORESOURCE_MEM,
252 .end = V2M_NOR1 + SZ_64M - 1,
253 .flags = IORESOURCE_MEM,
257 static struct platform_device v2m_flash_device = {
258 .name = "physmap-flash",
260 .resource = v2m_flash_resources,
261 .num_resources = ARRAY_SIZE(v2m_flash_resources),
262 .dev.platform_data = &v2m_flash_data,
265 static struct pata_platform_info v2m_pata_data = {
269 static struct resource v2m_pata_resources[] = {
272 .end = V2M_CF + 0xff,
273 .flags = IORESOURCE_MEM,
275 .start = V2M_CF + 0x100,
276 .end = V2M_CF + SZ_4K - 1,
277 .flags = IORESOURCE_MEM,
281 static struct platform_device v2m_cf_device = {
282 .name = "pata_platform",
284 .resource = v2m_pata_resources,
285 .num_resources = ARRAY_SIZE(v2m_pata_resources),
286 .dev.platform_data = &v2m_pata_data,
289 static unsigned int v2m_mmci_status(struct device *dev)
291 return readl(v2m_sysreg_base + V2M_SYS_MCI) & (1 << 0);
294 static struct mmci_platform_data v2m_mmci_data = {
295 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
296 .status = v2m_mmci_status,
299 static AMBA_APB_DEVICE(aaci, "mb:aaci", 0, V2M_AACI, IRQ_V2M_AACI, NULL);
300 static AMBA_APB_DEVICE(mmci, "mb:mmci", 0, V2M_MMCI, IRQ_V2M_MMCI, &v2m_mmci_data);
301 static AMBA_APB_DEVICE(kmi0, "mb:kmi0", 0, V2M_KMI0, IRQ_V2M_KMI0, NULL);
302 static AMBA_APB_DEVICE(kmi1, "mb:kmi1", 0, V2M_KMI1, IRQ_V2M_KMI1, NULL);
303 static AMBA_APB_DEVICE(uart0, "mb:uart0", 0, V2M_UART0, IRQ_V2M_UART0, NULL);
304 static AMBA_APB_DEVICE(uart1, "mb:uart1", 0, V2M_UART1, IRQ_V2M_UART1, NULL);
305 static AMBA_APB_DEVICE(uart2, "mb:uart2", 0, V2M_UART2, IRQ_V2M_UART2, NULL);
306 static AMBA_APB_DEVICE(uart3, "mb:uart3", 0, V2M_UART3, IRQ_V2M_UART3, NULL);
307 static AMBA_APB_DEVICE(wdt, "mb:wdt", 0, V2M_WDT, IRQ_V2M_WDT, NULL);
308 static AMBA_APB_DEVICE(rtc, "mb:rtc", 0, V2M_RTC, IRQ_V2M_RTC, NULL);
310 static struct amba_device *v2m_amba_devs[] __initdata = {
324 static long v2m_osc_round(struct clk *clk, unsigned long rate)
329 static int v2m_osc1_set(struct clk *clk, unsigned long rate)
331 return v2m_cfg_write(SYS_CFG_OSC | SYS_CFG_SITE_MB | 1, rate);
334 static const struct clk_ops osc1_clk_ops = {
335 .round = v2m_osc_round,
339 static struct clk osc1_clk = {
340 .ops = &osc1_clk_ops,
344 static struct clk osc2_clk = {
348 static struct clk v2m_sp804_clk = {
352 static struct clk v2m_ref_clk = {
356 static struct clk dummy_apb_pclk;
358 static struct clk_lookup v2m_lookups[] = {
359 { /* AMBA bus clock */
360 .con_id = "apb_pclk",
361 .clk = &dummy_apb_pclk,
363 .dev_id = "mb:uart0",
366 .dev_id = "mb:uart1",
369 .dev_id = "mb:uart2",
372 .dev_id = "mb:uart3",
389 }, { /* SP804 timers */
391 .con_id = "v2m-timer0",
392 .clk = &v2m_sp804_clk,
393 }, { /* SP804 timers */
395 .con_id = "v2m-timer1",
396 .clk = &v2m_sp804_clk,
400 static void __init v2m_init_early(void)
402 ct_desc->init_early();
403 clkdev_add_table(v2m_lookups, ARRAY_SIZE(v2m_lookups));
404 versatile_sched_clock_init(v2m_sysreg_base + V2M_SYS_24MHZ, 24000000);
407 static void v2m_power_off(void)
409 if (v2m_cfg_write(SYS_CFG_SHUTDOWN | SYS_CFG_SITE_MB, 0))
410 printk(KERN_EMERG "Unable to shutdown\n");
413 static void v2m_restart(char str, const char *cmd)
415 if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE_MB, 0))
416 printk(KERN_EMERG "Unable to reboot\n");
419 struct ct_desc *ct_desc;
421 static struct ct_desc *ct_descs[] __initdata = {
422 #ifdef CONFIG_ARCH_VEXPRESS_CA9X4
427 static void __init v2m_populate_ct_desc(void)
433 current_tile_id = readl(v2m_sysreg_base + V2M_SYS_PROCID0)
436 for (i = 0; i < ARRAY_SIZE(ct_descs) && !ct_desc; ++i)
437 if (ct_descs[i]->id == current_tile_id)
438 ct_desc = ct_descs[i];
441 panic("vexpress: this kernel does not support core tile ID 0x%08x when booting via ATAGs.\n"
442 "You may need a device tree blob or a different kernel to boot on this board.\n",
446 static void __init v2m_map_io(void)
448 iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
449 v2m_sysreg_base = ioremap(V2M_SYSREGS, SZ_4K);
450 v2m_populate_ct_desc();
454 static void __init v2m_init_irq(void)
459 static void __init v2m_init(void)
463 platform_device_register(&v2m_pcie_i2c_device);
464 platform_device_register(&v2m_ddc_i2c_device);
465 platform_device_register(&v2m_flash_device);
466 platform_device_register(&v2m_cf_device);
467 platform_device_register(&v2m_eth_device);
468 platform_device_register(&v2m_usb_device);
470 for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++)
471 amba_device_register(v2m_amba_devs[i], &iomem_resource);
473 pm_power_off = v2m_power_off;
475 ct_desc->init_tile();
478 MACHINE_START(VEXPRESS, "ARM-Versatile Express")
479 .atag_offset = 0x100,
480 .map_io = v2m_map_io,
481 .init_early = v2m_init_early,
482 .init_irq = v2m_init_irq,
484 .handle_irq = gic_handle_irq,
485 .init_machine = v2m_init,
486 .restart = v2m_restart,
489 #if defined(CONFIG_ARCH_VEXPRESS_DT)
491 static struct map_desc v2m_rs1_io_desc __initdata = {
492 .virtual = V2M_PERIPH,
493 .pfn = __phys_to_pfn(0x1c000000),
498 static int __init v2m_dt_scan_memory_map(unsigned long node, const char *uname,
499 int depth, void *data)
501 const char **map = data;
503 if (strcmp(uname, "motherboard") != 0)
506 *map = of_get_flat_dt_prop(node, "arm,v2m-memory-map", NULL);
511 void __init v2m_dt_map_io(void)
513 const char *map = NULL;
515 of_scan_flat_dt(v2m_dt_scan_memory_map, &map);
517 if (map && strcmp(map, "rs1") == 0)
518 iotable_init(&v2m_rs1_io_desc, 1);
520 iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
522 #if defined(CONFIG_SMP)
523 vexpress_dt_smp_map_io();
527 static struct clk_lookup v2m_dt_lookups[] = {
528 { /* AMBA bus clock */
529 .con_id = "apb_pclk",
530 .clk = &dummy_apb_pclk,
531 }, { /* SP804 timers */
533 .con_id = "v2m-timer0",
534 .clk = &v2m_sp804_clk,
535 }, { /* SP804 timers */
537 .con_id = "v2m-timer1",
538 .clk = &v2m_sp804_clk,
539 }, { /* PL180 MMCI */
540 .dev_id = "mb:mmci", /* 10005000.mmci */
542 }, { /* PL050 KMI0 */
543 .dev_id = "10006000.kmi",
545 }, { /* PL050 KMI1 */
546 .dev_id = "10007000.kmi",
548 }, { /* PL011 UART0 */
549 .dev_id = "10009000.uart",
551 }, { /* PL011 UART1 */
552 .dev_id = "1000a000.uart",
554 }, { /* PL011 UART2 */
555 .dev_id = "1000b000.uart",
557 }, { /* PL011 UART3 */
558 .dev_id = "1000c000.uart",
561 .dev_id = "1000f000.wdt",
563 }, { /* PL111 CLCD */
564 .dev_id = "1001f000.clcd",
569 .dev_id = "mb:mmci", /* 1c050000.mmci */
571 }, { /* PL050 KMI0 */
572 .dev_id = "1c060000.kmi",
574 }, { /* PL050 KMI1 */
575 .dev_id = "1c070000.kmi",
577 }, { /* PL011 UART0 */
578 .dev_id = "1c090000.uart",
580 }, { /* PL011 UART1 */
581 .dev_id = "1c0a0000.uart",
583 }, { /* PL011 UART2 */
584 .dev_id = "1c0b0000.uart",
586 }, { /* PL011 UART3 */
587 .dev_id = "1c0c0000.uart",
590 .dev_id = "1c0f0000.wdt",
592 }, { /* PL111 CLCD */
593 .dev_id = "1c1f0000.clcd",
598 void __init v2m_dt_init_early(void)
600 struct device_node *node;
603 node = of_find_compatible_node(NULL, NULL, "arm,vexpress-sysreg");
604 v2m_sysreg_base = of_iomap(node, 0);
605 if (WARN_ON(!v2m_sysreg_base))
608 /* Confirm board type against DT property, if available */
609 if (of_property_read_u32(allnodes, "arm,hbi", &dt_hbi) == 0) {
610 u32 misc = readl(v2m_sysreg_base + V2M_SYS_MISC);
611 u32 id = readl(v2m_sysreg_base + (misc & SYS_MISC_MASTERSITE ?
612 V2M_SYS_PROCID1 : V2M_SYS_PROCID0));
613 u32 hbi = id & SYS_PROCIDx_HBI_MASK;
615 if (WARN_ON(dt_hbi != hbi))
616 pr_warning("vexpress: DT HBI (%x) is not matching "
617 "hardware (%x)!\n", dt_hbi, hbi);
620 clkdev_add_table(v2m_dt_lookups, ARRAY_SIZE(v2m_dt_lookups));
623 static struct of_device_id vexpress_irq_match[] __initdata = {
624 { .compatible = "arm,cortex-a9-gic", .data = gic_of_init, },
628 static void __init v2m_dt_init_irq(void)
630 of_irq_init(vexpress_irq_match);
633 static void __init v2m_dt_timer_init(void)
635 struct device_node *node;
639 node = of_find_compatible_node(NULL, NULL, "arm,sp810");
640 v2m_sysctl_init(of_iomap(node, 0));
642 err = of_property_read_string(of_aliases, "arm,v2m_timer", &path);
645 node = of_find_node_by_path(path);
646 v2m_sp804_init(of_iomap(node, 0), irq_of_parse_and_map(node, 0));
647 if (arch_timer_of_register() != 0)
648 twd_local_timer_of_register();
650 if (arch_timer_sched_clock_init() != 0)
651 versatile_sched_clock_init(v2m_sysreg_base + V2M_SYS_24MHZ, 24000000);
654 static struct sys_timer v2m_dt_timer = {
655 .init = v2m_dt_timer_init,
658 static struct of_dev_auxdata v2m_dt_auxdata_lookup[] __initdata = {
659 OF_DEV_AUXDATA("arm,vexpress-flash", V2M_NOR0, "physmap-flash",
661 OF_DEV_AUXDATA("arm,primecell", V2M_MMCI, "mb:mmci", &v2m_mmci_data),
663 OF_DEV_AUXDATA("arm,vexpress-flash", 0x08000000, "physmap-flash",
665 OF_DEV_AUXDATA("arm,primecell", 0x1c050000, "mb:mmci", &v2m_mmci_data),
669 static void __init v2m_dt_init(void)
671 l2x0_of_init(0x00400000, 0xfe0fffff);
672 of_platform_populate(NULL, of_default_bus_match_table,
673 v2m_dt_auxdata_lookup, NULL);
674 pm_power_off = v2m_power_off;
677 const static char *v2m_dt_match[] __initconst = {
682 DT_MACHINE_START(VEXPRESS_DT, "ARM-Versatile Express")
683 .dt_compat = v2m_dt_match,
684 .map_io = v2m_dt_map_io,
685 .init_early = v2m_dt_init_early,
686 .init_irq = v2m_dt_init_irq,
687 .timer = &v2m_dt_timer,
688 .init_machine = v2m_dt_init,
689 .handle_irq = gic_handle_irq,
690 .restart = v2m_restart,