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/platform_device.h>
10 #include <linux/ata_platform.h>
11 #include <linux/smsc911x.h>
12 #include <linux/spinlock.h>
13 #include <linux/device.h>
14 #include <linux/usb/isp1760.h>
15 #include <linux/clkdev.h>
16 #include <linux/mtd/physmap.h>
18 #include <asm/mach-types.h>
19 #include <asm/sizes.h>
20 #include <asm/mach/arch.h>
21 #include <asm/mach/map.h>
22 #include <asm/mach/time.h>
23 #include <asm/hardware/arm_timer.h>
24 #include <asm/hardware/timer-sp.h>
25 #include <asm/hardware/sp810.h>
26 #include <asm/hardware/gic.h>
28 #include <mach/ct-ca9x4.h>
29 #include <mach/motherboard.h>
31 #include <plat/sched_clock.h>
35 #define V2M_PA_CS0 0x40000000
36 #define V2M_PA_CS1 0x44000000
37 #define V2M_PA_CS2 0x48000000
38 #define V2M_PA_CS3 0x4c000000
39 #define V2M_PA_CS7 0x10000000
41 static struct map_desc v2m_io_desc[] __initdata = {
43 .virtual = V2M_PERIPH,
44 .pfn = __phys_to_pfn(V2M_PA_CS7),
50 static void __iomem *v2m_sysreg_base;
52 static void __init v2m_sysctl_init(void __iomem *base)
59 /* Select 1MHz TIMCLK as the reference clock for SP804 timers */
60 scctrl = readl(base + SCCTRL);
61 scctrl |= SCCTRL_TIMEREN0SEL_TIMCLK;
62 scctrl |= SCCTRL_TIMEREN1SEL_TIMCLK;
63 writel(scctrl, base + SCCTRL);
66 static void __init v2m_sp804_init(void __iomem *base, unsigned int irq)
68 if (WARN_ON(!base || irq == NO_IRQ))
71 writel(0, base + TIMER_1_BASE + TIMER_CTRL);
72 writel(0, base + TIMER_2_BASE + TIMER_CTRL);
74 sp804_clocksource_init(base + TIMER_2_BASE, "v2m-timer1");
75 sp804_clockevents_init(base + TIMER_1_BASE, irq, "v2m-timer0");
78 static void __init v2m_timer_init(void)
80 v2m_sysctl_init(ioremap(V2M_SYSCTL, SZ_4K));
81 v2m_sp804_init(ioremap(V2M_TIMER01, SZ_4K), IRQ_V2M_TIMER0);
84 static struct sys_timer v2m_timer = {
85 .init = v2m_timer_init,
89 static DEFINE_SPINLOCK(v2m_cfg_lock);
91 int v2m_cfg_write(u32 devfn, u32 data)
93 /* Configuration interface broken? */
96 printk("%s: writing %08x to %08x\n", __func__, data, devfn);
98 devfn |= SYS_CFG_START | SYS_CFG_WRITE;
100 spin_lock(&v2m_cfg_lock);
101 val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT);
102 writel(val & ~SYS_CFG_COMPLETE, v2m_sysreg_base + V2M_SYS_CFGSTAT);
104 writel(data, v2m_sysreg_base + V2M_SYS_CFGDATA);
105 writel(devfn, v2m_sysreg_base + V2M_SYS_CFGCTRL);
108 val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT);
110 spin_unlock(&v2m_cfg_lock);
112 return !!(val & SYS_CFG_ERR);
115 int v2m_cfg_read(u32 devfn, u32 *data)
119 devfn |= SYS_CFG_START;
121 spin_lock(&v2m_cfg_lock);
122 writel(0, v2m_sysreg_base + V2M_SYS_CFGSTAT);
123 writel(devfn, v2m_sysreg_base + V2M_SYS_CFGCTRL);
129 val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT);
132 *data = readl(v2m_sysreg_base + V2M_SYS_CFGDATA);
133 spin_unlock(&v2m_cfg_lock);
135 return !!(val & SYS_CFG_ERR);
138 void __init v2m_flags_set(u32 data)
140 writel(~0, v2m_sysreg_base + V2M_SYS_FLAGSCLR);
141 writel(data, v2m_sysreg_base + V2M_SYS_FLAGSSET);
145 static struct resource v2m_pcie_i2c_resource = {
146 .start = V2M_SERIAL_BUS_PCI,
147 .end = V2M_SERIAL_BUS_PCI + SZ_4K - 1,
148 .flags = IORESOURCE_MEM,
151 static struct platform_device v2m_pcie_i2c_device = {
152 .name = "versatile-i2c",
155 .resource = &v2m_pcie_i2c_resource,
158 static struct resource v2m_ddc_i2c_resource = {
159 .start = V2M_SERIAL_BUS_DVI,
160 .end = V2M_SERIAL_BUS_DVI + SZ_4K - 1,
161 .flags = IORESOURCE_MEM,
164 static struct platform_device v2m_ddc_i2c_device = {
165 .name = "versatile-i2c",
168 .resource = &v2m_ddc_i2c_resource,
171 static struct resource v2m_eth_resources[] = {
173 .start = V2M_LAN9118,
174 .end = V2M_LAN9118 + SZ_64K - 1,
175 .flags = IORESOURCE_MEM,
177 .start = IRQ_V2M_LAN9118,
178 .end = IRQ_V2M_LAN9118,
179 .flags = IORESOURCE_IRQ,
183 static struct smsc911x_platform_config v2m_eth_config = {
184 .flags = SMSC911X_USE_32BIT,
185 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
186 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
187 .phy_interface = PHY_INTERFACE_MODE_MII,
190 static struct platform_device v2m_eth_device = {
193 .resource = v2m_eth_resources,
194 .num_resources = ARRAY_SIZE(v2m_eth_resources),
195 .dev.platform_data = &v2m_eth_config,
198 static struct resource v2m_usb_resources[] = {
200 .start = V2M_ISP1761,
201 .end = V2M_ISP1761 + SZ_128K - 1,
202 .flags = IORESOURCE_MEM,
204 .start = IRQ_V2M_ISP1761,
205 .end = IRQ_V2M_ISP1761,
206 .flags = IORESOURCE_IRQ,
210 static struct isp1760_platform_data v2m_usb_config = {
212 .bus_width_16 = false,
215 .dack_polarity_high = false,
216 .dreq_polarity_high = false,
219 static struct platform_device v2m_usb_device = {
222 .resource = v2m_usb_resources,
223 .num_resources = ARRAY_SIZE(v2m_usb_resources),
224 .dev.platform_data = &v2m_usb_config,
227 static void v2m_flash_set_vpp(struct platform_device *pdev, int on)
229 writel(on != 0, v2m_sysreg_base + V2M_SYS_FLASH);
232 static struct physmap_flash_data v2m_flash_data = {
234 .set_vpp = v2m_flash_set_vpp,
237 static struct resource v2m_flash_resources[] = {
240 .end = V2M_NOR0 + SZ_64M - 1,
241 .flags = IORESOURCE_MEM,
244 .end = V2M_NOR1 + SZ_64M - 1,
245 .flags = IORESOURCE_MEM,
249 static struct platform_device v2m_flash_device = {
250 .name = "physmap-flash",
252 .resource = v2m_flash_resources,
253 .num_resources = ARRAY_SIZE(v2m_flash_resources),
254 .dev.platform_data = &v2m_flash_data,
257 static struct pata_platform_info v2m_pata_data = {
261 static struct resource v2m_pata_resources[] = {
264 .end = V2M_CF + 0xff,
265 .flags = IORESOURCE_MEM,
267 .start = V2M_CF + 0x100,
268 .end = V2M_CF + SZ_4K - 1,
269 .flags = IORESOURCE_MEM,
273 static struct platform_device v2m_cf_device = {
274 .name = "pata_platform",
276 .resource = v2m_pata_resources,
277 .num_resources = ARRAY_SIZE(v2m_pata_resources),
278 .dev.platform_data = &v2m_pata_data,
281 static unsigned int v2m_mmci_status(struct device *dev)
283 return readl(v2m_sysreg_base + V2M_SYS_MCI) & (1 << 0);
286 static struct mmci_platform_data v2m_mmci_data = {
287 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
288 .status = v2m_mmci_status,
291 static AMBA_APB_DEVICE(aaci, "mb:aaci", 0, V2M_AACI, IRQ_V2M_AACI, NULL);
292 static AMBA_APB_DEVICE(mmci, "mb:mmci", 0, V2M_MMCI, IRQ_V2M_MMCI, &v2m_mmci_data);
293 static AMBA_APB_DEVICE(kmi0, "mb:kmi0", 0, V2M_KMI0, IRQ_V2M_KMI0, NULL);
294 static AMBA_APB_DEVICE(kmi1, "mb:kmi1", 0, V2M_KMI1, IRQ_V2M_KMI1, NULL);
295 static AMBA_APB_DEVICE(uart0, "mb:uart0", 0, V2M_UART0, IRQ_V2M_UART0, NULL);
296 static AMBA_APB_DEVICE(uart1, "mb:uart1", 0, V2M_UART1, IRQ_V2M_UART1, NULL);
297 static AMBA_APB_DEVICE(uart2, "mb:uart2", 0, V2M_UART2, IRQ_V2M_UART2, NULL);
298 static AMBA_APB_DEVICE(uart3, "mb:uart3", 0, V2M_UART3, IRQ_V2M_UART3, NULL);
299 static AMBA_APB_DEVICE(wdt, "mb:wdt", 0, V2M_WDT, IRQ_V2M_WDT, NULL);
300 static AMBA_APB_DEVICE(rtc, "mb:rtc", 0, V2M_RTC, IRQ_V2M_RTC, NULL);
302 static struct amba_device *v2m_amba_devs[] __initdata = {
316 static long v2m_osc_round(struct clk *clk, unsigned long rate)
321 static int v2m_osc1_set(struct clk *clk, unsigned long rate)
323 return v2m_cfg_write(SYS_CFG_OSC | SYS_CFG_SITE_MB | 1, rate);
326 static const struct clk_ops osc1_clk_ops = {
327 .round = v2m_osc_round,
331 static struct clk osc1_clk = {
332 .ops = &osc1_clk_ops,
336 static struct clk osc2_clk = {
340 static struct clk v2m_sp804_clk = {
344 static struct clk v2m_ref_clk = {
348 static struct clk dummy_apb_pclk;
350 static struct clk_lookup v2m_lookups[] = {
351 { /* AMBA bus clock */
352 .con_id = "apb_pclk",
353 .clk = &dummy_apb_pclk,
355 .dev_id = "mb:uart0",
358 .dev_id = "mb:uart1",
361 .dev_id = "mb:uart2",
364 .dev_id = "mb:uart3",
381 }, { /* SP804 timers */
383 .con_id = "v2m-timer0",
384 .clk = &v2m_sp804_clk,
385 }, { /* SP804 timers */
387 .con_id = "v2m-timer1",
388 .clk = &v2m_sp804_clk,
392 static void __init v2m_init_early(void)
394 ct_desc->init_early();
395 clkdev_add_table(v2m_lookups, ARRAY_SIZE(v2m_lookups));
396 versatile_sched_clock_init(v2m_sysreg_base + V2M_SYS_24MHZ, 24000000);
399 static void v2m_power_off(void)
401 if (v2m_cfg_write(SYS_CFG_SHUTDOWN | SYS_CFG_SITE_MB, 0))
402 printk(KERN_EMERG "Unable to shutdown\n");
405 static void v2m_restart(char str, const char *cmd)
407 if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE_MB, 0))
408 printk(KERN_EMERG "Unable to reboot\n");
411 struct ct_desc *ct_desc;
413 static struct ct_desc *ct_descs[] __initdata = {
414 #ifdef CONFIG_ARCH_VEXPRESS_CA9X4
419 static void __init v2m_populate_ct_desc(void)
425 current_tile_id = readl(v2m_sysreg_base + V2M_SYS_PROCID0)
428 for (i = 0; i < ARRAY_SIZE(ct_descs) && !ct_desc; ++i)
429 if (ct_descs[i]->id == current_tile_id)
430 ct_desc = ct_descs[i];
433 panic("vexpress: failed to populate core tile description "
434 "for tile ID 0x%8x\n", current_tile_id);
437 static void __init v2m_map_io(void)
439 iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
440 v2m_sysreg_base = ioremap(V2M_SYSREGS, SZ_4K);
441 v2m_populate_ct_desc();
445 static void __init v2m_init_irq(void)
450 static void __init v2m_init(void)
454 platform_device_register(&v2m_pcie_i2c_device);
455 platform_device_register(&v2m_ddc_i2c_device);
456 platform_device_register(&v2m_flash_device);
457 platform_device_register(&v2m_cf_device);
458 platform_device_register(&v2m_eth_device);
459 platform_device_register(&v2m_usb_device);
461 for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++)
462 amba_device_register(v2m_amba_devs[i], &iomem_resource);
464 pm_power_off = v2m_power_off;
466 ct_desc->init_tile();
469 MACHINE_START(VEXPRESS, "ARM-Versatile Express")
470 .atag_offset = 0x100,
471 .map_io = v2m_map_io,
472 .init_early = v2m_init_early,
473 .init_irq = v2m_init_irq,
475 .handle_irq = gic_handle_irq,
476 .init_machine = v2m_init,
477 .restart = v2m_restart,