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/usb/isp1760.h>
18 #include <linux/clkdev.h>
19 #include <linux/clk-provider.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>
35 #include <mach/ct-ca9x4.h>
36 #include <mach/motherboard.h>
38 #include <plat/sched_clock.h>
42 #define V2M_PA_CS0 0x40000000
43 #define V2M_PA_CS1 0x44000000
44 #define V2M_PA_CS2 0x48000000
45 #define V2M_PA_CS3 0x4c000000
46 #define V2M_PA_CS7 0x10000000
48 static struct map_desc v2m_io_desc
[] __initdata
= {
50 .virtual = V2M_PERIPH
,
51 .pfn
= __phys_to_pfn(V2M_PA_CS7
),
57 static void __iomem
*v2m_sysreg_base
;
59 static void __init
v2m_sysctl_init(void __iomem
*base
)
66 /* Select 1MHz TIMCLK as the reference clock for SP804 timers */
67 scctrl
= readl(base
+ SCCTRL
);
68 scctrl
|= SCCTRL_TIMEREN0SEL_TIMCLK
;
69 scctrl
|= SCCTRL_TIMEREN1SEL_TIMCLK
;
70 writel(scctrl
, base
+ SCCTRL
);
73 static void __init
v2m_sp804_init(void __iomem
*base
, unsigned int irq
)
75 if (WARN_ON(!base
|| irq
== NO_IRQ
))
78 writel(0, base
+ TIMER_1_BASE
+ TIMER_CTRL
);
79 writel(0, base
+ TIMER_2_BASE
+ TIMER_CTRL
);
81 sp804_clocksource_init(base
+ TIMER_2_BASE
, "v2m-timer1");
82 sp804_clockevents_init(base
+ TIMER_1_BASE
, irq
, "v2m-timer0");
86 static DEFINE_SPINLOCK(v2m_cfg_lock
);
88 int v2m_cfg_write(u32 devfn
, u32 data
)
90 /* Configuration interface broken? */
93 printk("%s: writing %08x to %08x\n", __func__
, data
, devfn
);
95 devfn
|= SYS_CFG_START
| SYS_CFG_WRITE
;
97 spin_lock(&v2m_cfg_lock
);
98 val
= readl(v2m_sysreg_base
+ V2M_SYS_CFGSTAT
);
99 writel(val
& ~SYS_CFG_COMPLETE
, v2m_sysreg_base
+ V2M_SYS_CFGSTAT
);
101 writel(data
, v2m_sysreg_base
+ V2M_SYS_CFGDATA
);
102 writel(devfn
, v2m_sysreg_base
+ V2M_SYS_CFGCTRL
);
105 val
= readl(v2m_sysreg_base
+ V2M_SYS_CFGSTAT
);
107 spin_unlock(&v2m_cfg_lock
);
109 return !!(val
& SYS_CFG_ERR
);
112 int v2m_cfg_read(u32 devfn
, u32
*data
)
116 devfn
|= SYS_CFG_START
;
118 spin_lock(&v2m_cfg_lock
);
119 writel(0, v2m_sysreg_base
+ V2M_SYS_CFGSTAT
);
120 writel(devfn
, v2m_sysreg_base
+ V2M_SYS_CFGCTRL
);
126 val
= readl(v2m_sysreg_base
+ V2M_SYS_CFGSTAT
);
129 *data
= readl(v2m_sysreg_base
+ V2M_SYS_CFGDATA
);
130 spin_unlock(&v2m_cfg_lock
);
132 return !!(val
& SYS_CFG_ERR
);
135 void __init
v2m_flags_set(u32 data
)
137 writel(~0, v2m_sysreg_base
+ V2M_SYS_FLAGSCLR
);
138 writel(data
, v2m_sysreg_base
+ V2M_SYS_FLAGSSET
);
141 int v2m_get_master_site(void)
143 u32 misc
= readl(v2m_sysreg_base
+ V2M_SYS_MISC
);
145 return misc
& SYS_MISC_MASTERSITE
? SYS_CFG_SITE_DB2
: SYS_CFG_SITE_DB1
;
149 static struct resource v2m_pcie_i2c_resource
= {
150 .start
= V2M_SERIAL_BUS_PCI
,
151 .end
= V2M_SERIAL_BUS_PCI
+ SZ_4K
- 1,
152 .flags
= IORESOURCE_MEM
,
155 static struct platform_device v2m_pcie_i2c_device
= {
156 .name
= "versatile-i2c",
159 .resource
= &v2m_pcie_i2c_resource
,
162 static struct resource v2m_ddc_i2c_resource
= {
163 .start
= V2M_SERIAL_BUS_DVI
,
164 .end
= V2M_SERIAL_BUS_DVI
+ SZ_4K
- 1,
165 .flags
= IORESOURCE_MEM
,
168 static struct platform_device v2m_ddc_i2c_device
= {
169 .name
= "versatile-i2c",
172 .resource
= &v2m_ddc_i2c_resource
,
175 static struct resource v2m_eth_resources
[] = {
177 .start
= V2M_LAN9118
,
178 .end
= V2M_LAN9118
+ SZ_64K
- 1,
179 .flags
= IORESOURCE_MEM
,
181 .start
= IRQ_V2M_LAN9118
,
182 .end
= IRQ_V2M_LAN9118
,
183 .flags
= IORESOURCE_IRQ
,
187 static struct smsc911x_platform_config v2m_eth_config
= {
188 .flags
= SMSC911X_USE_32BIT
,
189 .irq_polarity
= SMSC911X_IRQ_POLARITY_ACTIVE_HIGH
,
190 .irq_type
= SMSC911X_IRQ_TYPE_PUSH_PULL
,
191 .phy_interface
= PHY_INTERFACE_MODE_MII
,
194 static struct platform_device v2m_eth_device
= {
197 .resource
= v2m_eth_resources
,
198 .num_resources
= ARRAY_SIZE(v2m_eth_resources
),
199 .dev
.platform_data
= &v2m_eth_config
,
202 static struct resource v2m_usb_resources
[] = {
204 .start
= V2M_ISP1761
,
205 .end
= V2M_ISP1761
+ SZ_128K
- 1,
206 .flags
= IORESOURCE_MEM
,
208 .start
= IRQ_V2M_ISP1761
,
209 .end
= IRQ_V2M_ISP1761
,
210 .flags
= IORESOURCE_IRQ
,
214 static struct isp1760_platform_data v2m_usb_config
= {
216 .bus_width_16
= false,
219 .dack_polarity_high
= false,
220 .dreq_polarity_high
= false,
223 static struct platform_device v2m_usb_device
= {
226 .resource
= v2m_usb_resources
,
227 .num_resources
= ARRAY_SIZE(v2m_usb_resources
),
228 .dev
.platform_data
= &v2m_usb_config
,
231 static void v2m_flash_set_vpp(struct platform_device
*pdev
, int on
)
233 writel(on
!= 0, v2m_sysreg_base
+ V2M_SYS_FLASH
);
236 static struct physmap_flash_data v2m_flash_data
= {
238 .set_vpp
= v2m_flash_set_vpp
,
241 static struct resource v2m_flash_resources
[] = {
244 .end
= V2M_NOR0
+ SZ_64M
- 1,
245 .flags
= IORESOURCE_MEM
,
248 .end
= V2M_NOR1
+ SZ_64M
- 1,
249 .flags
= IORESOURCE_MEM
,
253 static struct platform_device v2m_flash_device
= {
254 .name
= "physmap-flash",
256 .resource
= v2m_flash_resources
,
257 .num_resources
= ARRAY_SIZE(v2m_flash_resources
),
258 .dev
.platform_data
= &v2m_flash_data
,
261 static struct pata_platform_info v2m_pata_data
= {
265 static struct resource v2m_pata_resources
[] = {
268 .end
= V2M_CF
+ 0xff,
269 .flags
= IORESOURCE_MEM
,
271 .start
= V2M_CF
+ 0x100,
272 .end
= V2M_CF
+ SZ_4K
- 1,
273 .flags
= IORESOURCE_MEM
,
277 static struct platform_device v2m_cf_device
= {
278 .name
= "pata_platform",
280 .resource
= v2m_pata_resources
,
281 .num_resources
= ARRAY_SIZE(v2m_pata_resources
),
282 .dev
.platform_data
= &v2m_pata_data
,
285 static unsigned int v2m_mmci_status(struct device
*dev
)
287 return readl(v2m_sysreg_base
+ V2M_SYS_MCI
) & (1 << 0);
290 static struct mmci_platform_data v2m_mmci_data
= {
291 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
292 .status
= v2m_mmci_status
,
295 static AMBA_APB_DEVICE(aaci
, "mb:aaci", 0, V2M_AACI
, IRQ_V2M_AACI
, NULL
);
296 static AMBA_APB_DEVICE(mmci
, "mb:mmci", 0, V2M_MMCI
, IRQ_V2M_MMCI
, &v2m_mmci_data
);
297 static AMBA_APB_DEVICE(kmi0
, "mb:kmi0", 0, V2M_KMI0
, IRQ_V2M_KMI0
, NULL
);
298 static AMBA_APB_DEVICE(kmi1
, "mb:kmi1", 0, V2M_KMI1
, IRQ_V2M_KMI1
, NULL
);
299 static AMBA_APB_DEVICE(uart0
, "mb:uart0", 0, V2M_UART0
, IRQ_V2M_UART0
, NULL
);
300 static AMBA_APB_DEVICE(uart1
, "mb:uart1", 0, V2M_UART1
, IRQ_V2M_UART1
, NULL
);
301 static AMBA_APB_DEVICE(uart2
, "mb:uart2", 0, V2M_UART2
, IRQ_V2M_UART2
, NULL
);
302 static AMBA_APB_DEVICE(uart3
, "mb:uart3", 0, V2M_UART3
, IRQ_V2M_UART3
, NULL
);
303 static AMBA_APB_DEVICE(wdt
, "mb:wdt", 0, V2M_WDT
, IRQ_V2M_WDT
, NULL
);
304 static AMBA_APB_DEVICE(rtc
, "mb:rtc", 0, V2M_RTC
, IRQ_V2M_RTC
, NULL
);
306 static struct amba_device
*v2m_amba_devs
[] __initdata
= {
320 static unsigned long v2m_osc_recalc_rate(struct clk_hw
*hw
,
321 unsigned long parent_rate
)
323 struct v2m_osc
*osc
= to_v2m_osc(hw
);
325 return !parent_rate
? osc
->rate_default
: parent_rate
;
328 static long v2m_osc_round_rate(struct clk_hw
*hw
, unsigned long rate
,
329 unsigned long *parent_rate
)
331 struct v2m_osc
*osc
= to_v2m_osc(hw
);
333 if (WARN_ON(rate
< osc
->rate_min
))
334 rate
= osc
->rate_min
;
336 if (WARN_ON(rate
> osc
->rate_max
))
337 rate
= osc
->rate_max
;
342 static int v2m_osc_set_rate(struct clk_hw
*hw
, unsigned long rate
,
343 unsigned long parent_rate
)
345 struct v2m_osc
*osc
= to_v2m_osc(hw
);
347 v2m_cfg_write(SYS_CFG_OSC
| SYS_CFG_SITE(osc
->site
) |
348 SYS_CFG_STACK(osc
->stack
) | osc
->osc
, rate
);
353 static struct clk_ops v2m_osc_ops
= {
354 .recalc_rate
= v2m_osc_recalc_rate
,
355 .round_rate
= v2m_osc_round_rate
,
356 .set_rate
= v2m_osc_set_rate
,
359 struct clk
* __init
v2m_osc_register(const char *name
, struct v2m_osc
*osc
)
361 struct clk_init_data init
;
363 WARN_ON(osc
->site
> 2);
364 WARN_ON(osc
->stack
> 15);
365 WARN_ON(osc
->osc
> 4095);
368 init
.ops
= &v2m_osc_ops
;
369 init
.flags
= CLK_IS_ROOT
;
370 init
.num_parents
= 0;
372 osc
->hw
.init
= &init
;
374 return clk_register(NULL
, &osc
->hw
);
377 static struct v2m_osc v2m_mb_osc1
= {
378 .site
= SYS_CFG_SITE_MB
,
380 .rate_min
= 23750000,
381 .rate_max
= 63500000,
382 .rate_default
= 23750000,
385 static const char *v2m_ref_clk_periphs
[] __initconst
= {
386 "mb:wdt", "1000f000.wdt", "1c0f0000.wdt", /* SP805 WDT */
389 static const char *v2m_osc1_periphs
[] __initconst
= {
390 "mb:clcd", "1001f000.clcd", "1c1f0000.clcd", /* PL111 CLCD */
393 static const char *v2m_osc2_periphs
[] __initconst
= {
394 "mb:mmci", "10005000.mmci", "1c050000.mmci", /* PL180 MMCI */
395 "mb:kmi0", "10006000.kmi", "1c060000.kmi", /* PL050 KMI0 */
396 "mb:kmi1", "10007000.kmi", "1c070000.kmi", /* PL050 KMI1 */
397 "mb:uart0", "10009000.uart", "1c090000.uart", /* PL011 UART0 */
398 "mb:uart1", "1000a000.uart", "1c0a0000.uart", /* PL011 UART1 */
399 "mb:uart2", "1000b000.uart", "1c0b0000.uart", /* PL011 UART2 */
400 "mb:uart3", "1000c000.uart", "1c0c0000.uart", /* PL011 UART3 */
403 static void __init
v2m_clk_init(void)
408 clk
= clk_register_fixed_rate(NULL
, "dummy_apb_pclk", NULL
,
410 WARN_ON(clk_register_clkdev(clk
, "apb_pclk", NULL
));
412 clk
= clk_register_fixed_rate(NULL
, "mb:ref_clk", NULL
,
414 for (i
= 0; i
< ARRAY_SIZE(v2m_ref_clk_periphs
); i
++)
415 WARN_ON(clk_register_clkdev(clk
, NULL
, v2m_ref_clk_periphs
[i
]));
417 clk
= clk_register_fixed_rate(NULL
, "mb:sp804_clk", NULL
,
418 CLK_IS_ROOT
, 1000000);
419 WARN_ON(clk_register_clkdev(clk
, "v2m-timer0", "sp804"));
420 WARN_ON(clk_register_clkdev(clk
, "v2m-timer1", "sp804"));
422 clk
= v2m_osc_register("mb:osc1", &v2m_mb_osc1
);
423 for (i
= 0; i
< ARRAY_SIZE(v2m_osc1_periphs
); i
++)
424 WARN_ON(clk_register_clkdev(clk
, NULL
, v2m_osc1_periphs
[i
]));
426 clk
= clk_register_fixed_rate(NULL
, "mb:osc2", NULL
,
427 CLK_IS_ROOT
, 24000000);
428 for (i
= 0; i
< ARRAY_SIZE(v2m_osc2_periphs
); i
++)
429 WARN_ON(clk_register_clkdev(clk
, NULL
, v2m_osc2_periphs
[i
]));
432 static void __init
v2m_timer_init(void)
434 v2m_sysctl_init(ioremap(V2M_SYSCTL
, SZ_4K
));
436 v2m_sp804_init(ioremap(V2M_TIMER01
, SZ_4K
), IRQ_V2M_TIMER0
);
439 static struct sys_timer v2m_timer
= {
440 .init
= v2m_timer_init
,
443 static void __init
v2m_init_early(void)
445 if (ct_desc
->init_early
)
446 ct_desc
->init_early();
447 versatile_sched_clock_init(v2m_sysreg_base
+ V2M_SYS_24MHZ
, 24000000);
450 static void v2m_power_off(void)
452 if (v2m_cfg_write(SYS_CFG_SHUTDOWN
| SYS_CFG_SITE(SYS_CFG_SITE_MB
), 0))
453 printk(KERN_EMERG
"Unable to shutdown\n");
456 static void v2m_restart(char str
, const char *cmd
)
458 if (v2m_cfg_write(SYS_CFG_REBOOT
| SYS_CFG_SITE(SYS_CFG_SITE_MB
), 0))
459 printk(KERN_EMERG
"Unable to reboot\n");
462 struct ct_desc
*ct_desc
;
464 static struct ct_desc
*ct_descs
[] __initdata
= {
465 #ifdef CONFIG_ARCH_VEXPRESS_CA9X4
470 static void __init
v2m_populate_ct_desc(void)
476 current_tile_id
= readl(v2m_sysreg_base
+ V2M_SYS_PROCID0
)
479 for (i
= 0; i
< ARRAY_SIZE(ct_descs
) && !ct_desc
; ++i
)
480 if (ct_descs
[i
]->id
== current_tile_id
)
481 ct_desc
= ct_descs
[i
];
484 panic("vexpress: this kernel does not support core tile ID 0x%08x when booting via ATAGs.\n"
485 "You may need a device tree blob or a different kernel to boot on this board.\n",
489 static void __init
v2m_map_io(void)
491 iotable_init(v2m_io_desc
, ARRAY_SIZE(v2m_io_desc
));
492 v2m_sysreg_base
= ioremap(V2M_SYSREGS
, SZ_4K
);
493 v2m_populate_ct_desc();
497 static void __init
v2m_init_irq(void)
502 static void __init
v2m_init(void)
506 platform_device_register(&v2m_pcie_i2c_device
);
507 platform_device_register(&v2m_ddc_i2c_device
);
508 platform_device_register(&v2m_flash_device
);
509 platform_device_register(&v2m_cf_device
);
510 platform_device_register(&v2m_eth_device
);
511 platform_device_register(&v2m_usb_device
);
513 for (i
= 0; i
< ARRAY_SIZE(v2m_amba_devs
); i
++)
514 amba_device_register(v2m_amba_devs
[i
], &iomem_resource
);
516 pm_power_off
= v2m_power_off
;
518 ct_desc
->init_tile();
521 MACHINE_START(VEXPRESS
, "ARM-Versatile Express")
522 .atag_offset
= 0x100,
523 .map_io
= v2m_map_io
,
524 .init_early
= v2m_init_early
,
525 .init_irq
= v2m_init_irq
,
527 .handle_irq
= gic_handle_irq
,
528 .init_machine
= v2m_init
,
529 .restart
= v2m_restart
,
532 #if defined(CONFIG_ARCH_VEXPRESS_DT)
534 static struct map_desc v2m_rs1_io_desc __initdata
= {
535 .virtual = V2M_PERIPH
,
536 .pfn
= __phys_to_pfn(0x1c000000),
541 static int __init
v2m_dt_scan_memory_map(unsigned long node
, const char *uname
,
542 int depth
, void *data
)
544 const char **map
= data
;
546 if (strcmp(uname
, "motherboard") != 0)
549 *map
= of_get_flat_dt_prop(node
, "arm,v2m-memory-map", NULL
);
554 void __init
v2m_dt_map_io(void)
556 const char *map
= NULL
;
558 of_scan_flat_dt(v2m_dt_scan_memory_map
, &map
);
560 if (map
&& strcmp(map
, "rs1") == 0)
561 iotable_init(&v2m_rs1_io_desc
, 1);
563 iotable_init(v2m_io_desc
, ARRAY_SIZE(v2m_io_desc
));
565 #if defined(CONFIG_SMP)
566 vexpress_dt_smp_map_io();
570 void __init
v2m_dt_init_early(void)
572 struct device_node
*node
;
575 node
= of_find_compatible_node(NULL
, NULL
, "arm,vexpress-sysreg");
576 v2m_sysreg_base
= of_iomap(node
, 0);
577 if (WARN_ON(!v2m_sysreg_base
))
580 /* Confirm board type against DT property, if available */
581 if (of_property_read_u32(allnodes
, "arm,hbi", &dt_hbi
) == 0) {
582 int site
= v2m_get_master_site();
583 u32 id
= readl(v2m_sysreg_base
+ (site
== SYS_CFG_SITE_DB2
?
584 V2M_SYS_PROCID1
: V2M_SYS_PROCID0
));
585 u32 hbi
= id
& SYS_PROCIDx_HBI_MASK
;
587 if (WARN_ON(dt_hbi
!= hbi
))
588 pr_warning("vexpress: DT HBI (%x) is not matching "
589 "hardware (%x)!\n", dt_hbi
, hbi
);
593 static struct of_device_id vexpress_irq_match
[] __initdata
= {
594 { .compatible
= "arm,cortex-a9-gic", .data
= gic_of_init
, },
598 static void __init
v2m_dt_init_irq(void)
600 of_irq_init(vexpress_irq_match
);
603 static void __init
v2m_dt_timer_init(void)
605 struct device_node
*node
;
609 node
= of_find_compatible_node(NULL
, NULL
, "arm,sp810");
610 v2m_sysctl_init(of_iomap(node
, 0));
614 err
= of_property_read_string(of_aliases
, "arm,v2m_timer", &path
);
617 node
= of_find_node_by_path(path
);
618 v2m_sp804_init(of_iomap(node
, 0), irq_of_parse_and_map(node
, 0));
619 if (arch_timer_of_register() != 0)
620 twd_local_timer_of_register();
622 if (arch_timer_sched_clock_init() != 0)
623 versatile_sched_clock_init(v2m_sysreg_base
+ V2M_SYS_24MHZ
, 24000000);
626 static struct sys_timer v2m_dt_timer
= {
627 .init
= v2m_dt_timer_init
,
630 static struct of_dev_auxdata v2m_dt_auxdata_lookup
[] __initdata
= {
631 OF_DEV_AUXDATA("arm,vexpress-flash", V2M_NOR0
, "physmap-flash",
633 OF_DEV_AUXDATA("arm,primecell", V2M_MMCI
, "mb:mmci", &v2m_mmci_data
),
635 OF_DEV_AUXDATA("arm,vexpress-flash", 0x08000000, "physmap-flash",
637 OF_DEV_AUXDATA("arm,primecell", 0x1c050000, "mb:mmci", &v2m_mmci_data
),
641 static void __init
v2m_dt_init(void)
643 l2x0_of_init(0x00400000, 0xfe0fffff);
644 of_platform_populate(NULL
, of_default_bus_match_table
,
645 v2m_dt_auxdata_lookup
, NULL
);
646 pm_power_off
= v2m_power_off
;
649 const static char *v2m_dt_match
[] __initconst
= {
654 DT_MACHINE_START(VEXPRESS_DT
, "ARM-Versatile Express")
655 .dt_compat
= v2m_dt_match
,
656 .map_io
= v2m_dt_map_io
,
657 .init_early
= v2m_dt_init_early
,
658 .init_irq
= v2m_dt_init_irq
,
659 .timer
= &v2m_dt_timer
,
660 .init_machine
= v2m_dt_init
,
661 .handle_irq
= gic_handle_irq
,
662 .restart
= v2m_restart
,