blob: 86150d7a2e7d977c1767795cfd3da082efae0013 [file] [log] [blame]
Russell Kingfef88f12010-02-28 17:26:25 +00001/*
2 * Versatile Express Core Tile Cortex A9x4 Support
3 */
4#include <linux/init.h>
Tejun Heo68aaae92010-03-30 02:52:45 +09005#include <linux/gfp.h>
Russell Kingfef88f12010-02-28 17:26:25 +00006#include <linux/device.h>
7#include <linux/dma-mapping.h>
Will Deaconf417cba2010-04-15 10:16:26 +01008#include <linux/platform_device.h>
Russell Kingfef88f12010-02-28 17:26:25 +00009#include <linux/amba/bus.h>
10#include <linux/amba/clcd.h>
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +010011#include <linux/clkdev.h>
Pawel Moll38669e02012-10-09 12:56:36 +010012#include <linux/vexpress.h>
Rob Herring520f7bd2012-12-27 13:10:24 -060013#include <linux/irqchip/arm-gic.h>
Russell Kingfef88f12010-02-28 17:26:25 +000014
Russell Kingfef88f12010-02-28 17:26:25 +000015#include <asm/hardware/arm_timer.h>
16#include <asm/hardware/cache-l2x0.h>
Will Deacon80b5efbd2011-02-28 17:01:04 +010017#include <asm/smp_scu.h>
Will Deaconbde28b82010-07-09 13:52:09 +010018#include <asm/smp_twd.h>
Russell Kingfef88f12010-02-28 17:26:25 +000019
Russell Kingfef88f12010-02-28 17:26:25 +000020#include <mach/ct-ca9x4.h>
21
Rob Herring8a9618f2010-10-06 16:18:08 +010022#include <asm/hardware/timer-sp.h>
Russell Kingfef88f12010-02-28 17:26:25 +000023
Russell Kingfef88f12010-02-28 17:26:25 +000024#include <asm/mach/map.h>
25#include <asm/mach/time.h>
26
27#include "core.h"
28
29#include <mach/motherboard.h>
Arnd Bergmanndb6b6722012-05-07 16:54:40 +000030#include <mach/irqs.h>
Russell Kingfef88f12010-02-28 17:26:25 +000031
Russell King0fb44b92011-01-18 20:13:51 +000032#include <plat/clcd.h>
33
Russell Kingfef88f12010-02-28 17:26:25 +000034static struct map_desc ct_ca9x4_io_desc[] __initdata = {
35 {
Pawel Moll98ed4ce2012-01-25 15:37:29 +000036 .virtual = V2T_PERIPH,
37 .pfn = __phys_to_pfn(CT_CA9X4_MPIC),
38 .length = SZ_8K,
39 .type = MT_DEVICE,
Russell Kingfef88f12010-02-28 17:26:25 +000040 },
41};
42
43static void __init ct_ca9x4_map_io(void)
44{
Will Deacon80b5efbd2011-02-28 17:01:04 +010045 iotable_init(ct_ca9x4_io_desc, ARRAY_SIZE(ct_ca9x4_io_desc));
Russell Kingfef88f12010-02-28 17:26:25 +000046}
47
Russell King060bf2a2014-03-19 11:15:38 +000048static void __init ca9x4_l2_init(void)
49{
50#ifdef CONFIG_CACHE_L2X0
51 void __iomem *l2x0_base = ioremap(CT_CA9X4_L2CC, SZ_4K);
52
53 if (l2x0_base) {
54 /* set RAM latencies to 1 cycle for this core tile. */
55 writel(0, l2x0_base + L310_TAG_LATENCY_CTRL);
56 writel(0, l2x0_base + L310_DATA_LATENCY_CTRL);
57
58 l2x0_init(l2x0_base, 0x00400000, 0xfe0fffff);
59 } else {
60 pr_err("L2C: unable to map L2 cache controller\n");
61 }
62#endif
63}
64
Marc Zyngier7c380f22011-08-04 11:57:04 +010065#ifdef CONFIG_HAVE_ARM_TWD
66static DEFINE_TWD_LOCAL_TIMER(twd_local_timer, A9_MPCORE_TWD, IRQ_LOCALTIMER);
67
68static void __init ca9x4_twd_init(void)
69{
70 int err = twd_local_timer_register(&twd_local_timer);
71 if (err)
72 pr_err("twd_local_timer_register failed %d\n", err);
73}
74#else
75#define ca9x4_twd_init() do {} while(0)
76#endif
77
Russell Kingfef88f12010-02-28 17:26:25 +000078static void __init ct_ca9x4_init_irq(void)
79{
Pawel Moll98ed4ce2012-01-25 15:37:29 +000080 gic_init(0, 29, ioremap(A9_MPCORE_GIC_DIST, SZ_4K),
81 ioremap(A9_MPCORE_GIC_CPU, SZ_256));
Marc Zyngier7c380f22011-08-04 11:57:04 +010082 ca9x4_twd_init();
Russell King060bf2a2014-03-19 11:15:38 +000083 ca9x4_l2_init();
Russell Kingfef88f12010-02-28 17:26:25 +000084}
85
Russell Kingfef88f12010-02-28 17:26:25 +000086static int ct_ca9x4_clcd_setup(struct clcd_fb *fb)
87{
88 unsigned long framesize = 1024 * 768 * 2;
Russell Kingfef88f12010-02-28 17:26:25 +000089
Russell King0fb44b92011-01-18 20:13:51 +000090 fb->panel = versatile_clcd_get_panel("XVGA");
91 if (!fb->panel)
92 return -EINVAL;
Russell Kingfef88f12010-02-28 17:26:25 +000093
Russell King0fb44b92011-01-18 20:13:51 +000094 return versatile_clcd_setup_dma(fb, framesize);
Russell Kingfef88f12010-02-28 17:26:25 +000095}
96
97static struct clcd_board ct_ca9x4_clcd_data = {
98 .name = "CT-CA9X4",
Russell King0fb44b92011-01-18 20:13:51 +000099 .caps = CLCD_CAP_5551 | CLCD_CAP_565,
Russell Kingfef88f12010-02-28 17:26:25 +0000100 .check = clcdfb_check,
101 .decode = clcdfb_decode,
Russell Kingfef88f12010-02-28 17:26:25 +0000102 .setup = ct_ca9x4_clcd_setup,
Russell King0fb44b92011-01-18 20:13:51 +0000103 .mmap = versatile_clcd_mmap_dma,
104 .remove = versatile_clcd_remove_dma,
Russell Kingfef88f12010-02-28 17:26:25 +0000105};
106
Russell Kingcdd4e1a2011-12-18 12:07:09 +0000107static AMBA_AHB_DEVICE(clcd, "ct:clcd", 0, CT_CA9X4_CLCDC, IRQ_CT_CA9X4_CLCDC, &ct_ca9x4_clcd_data);
108static AMBA_APB_DEVICE(dmc, "ct:dmc", 0, CT_CA9X4_DMC, IRQ_CT_CA9X4_DMC, NULL);
109static AMBA_APB_DEVICE(smc, "ct:smc", 0, CT_CA9X4_SMC, IRQ_CT_CA9X4_SMC, NULL);
110static AMBA_APB_DEVICE(gpio, "ct:gpio", 0, CT_CA9X4_GPIO, IRQ_CT_CA9X4_GPIO, NULL);
Russell Kingfef88f12010-02-28 17:26:25 +0000111
112static struct amba_device *ct_ca9x4_amba_devs[] __initdata = {
113 &clcd_device,
114 &dmc_device,
115 &smc_device,
116 &gpio_device,
117};
118
Will Deaconf417cba2010-04-15 10:16:26 +0100119static struct resource pmu_resources[] = {
120 [0] = {
121 .start = IRQ_CT_CA9X4_PMU_CPU0,
122 .end = IRQ_CT_CA9X4_PMU_CPU0,
123 .flags = IORESOURCE_IRQ,
124 },
125 [1] = {
126 .start = IRQ_CT_CA9X4_PMU_CPU1,
127 .end = IRQ_CT_CA9X4_PMU_CPU1,
128 .flags = IORESOURCE_IRQ,
129 },
130 [2] = {
131 .start = IRQ_CT_CA9X4_PMU_CPU2,
132 .end = IRQ_CT_CA9X4_PMU_CPU2,
133 .flags = IORESOURCE_IRQ,
134 },
135 [3] = {
136 .start = IRQ_CT_CA9X4_PMU_CPU3,
137 .end = IRQ_CT_CA9X4_PMU_CPU3,
138 .flags = IORESOURCE_IRQ,
139 },
140};
141
142static struct platform_device pmu_device = {
143 .name = "arm-pmu",
Sudeep KarkadaNageshadf3d17e2012-07-19 09:50:21 +0100144 .id = -1,
Will Deaconf417cba2010-04-15 10:16:26 +0100145 .num_resources = ARRAY_SIZE(pmu_resources),
146 .resource = pmu_resources,
147};
148
Pawel Moll3b9334a2014-04-30 16:46:29 +0100149static struct clk_lookup osc1_lookup = {
150 .dev_id = "ct:clcd",
151};
152
Pawel Moll38669e02012-10-09 12:56:36 +0100153static struct platform_device osc1_device = {
154 .name = "vexpress-osc",
155 .id = 1,
156 .num_resources = 1,
157 .resource = (struct resource []) {
158 VEXPRESS_RES_FUNC(0xf, 1),
159 },
Pawel Moll3b9334a2014-04-30 16:46:29 +0100160 .dev.platform_data = &osc1_lookup,
Pawel Moll38669e02012-10-09 12:56:36 +0100161};
162
Russell Kingcdaf9a22010-10-05 11:29:28 +0100163static void __init ct_ca9x4_init(void)
Russell Kingfef88f12010-02-28 17:26:25 +0000164{
165 int i;
166
Russell Kingfef88f12010-02-28 17:26:25 +0000167 for (i = 0; i < ARRAY_SIZE(ct_ca9x4_amba_devs); i++)
168 amba_device_register(ct_ca9x4_amba_devs[i], &iomem_resource);
Will Deaconf417cba2010-04-15 10:16:26 +0100169
170 platform_device_register(&pmu_device);
Pawel Moll974cc7b2014-04-23 10:49:31 +0100171 vexpress_syscfg_device_register(&osc1_device);
Russell Kingfef88f12010-02-28 17:26:25 +0000172}
173
Will Deacon80b5efbd2011-02-28 17:01:04 +0100174#ifdef CONFIG_SMP
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000175static void *ct_ca9x4_scu_base __initdata;
176
Russell King94ae0272012-01-18 19:40:13 +0000177static void __init ct_ca9x4_init_cpu_map(void)
Will Deacon80b5efbd2011-02-28 17:01:04 +0100178{
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000179 int i, ncores;
180
181 ct_ca9x4_scu_base = ioremap(A9_MPCORE_SCU, SZ_128);
182 if (WARN_ON(!ct_ca9x4_scu_base))
183 return;
184
185 ncores = scu_get_core_count(ct_ca9x4_scu_base);
Will Deacon80b5efbd2011-02-28 17:01:04 +0100186
Russell Kinga06f9162011-10-20 22:04:18 +0100187 if (ncores > nr_cpu_ids) {
188 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
189 ncores, nr_cpu_ids);
190 ncores = nr_cpu_ids;
191 }
192
Will Deacon80b5efbd2011-02-28 17:01:04 +0100193 for (i = 0; i < ncores; ++i)
194 set_cpu_possible(i, true);
195}
196
Russell King94ae0272012-01-18 19:40:13 +0000197static void __init ct_ca9x4_smp_enable(unsigned int max_cpus)
Will Deacon80b5efbd2011-02-28 17:01:04 +0100198{
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000199 scu_enable(ct_ca9x4_scu_base);
Will Deacon80b5efbd2011-02-28 17:01:04 +0100200}
Russell Kingfef88f12010-02-28 17:26:25 +0000201#endif
Will Deacon80b5efbd2011-02-28 17:01:04 +0100202
203struct ct_desc ct_ca9x4_desc __initdata = {
204 .id = V2M_CT_ID_CA9,
205 .name = "CA9x4",
206 .map_io = ct_ca9x4_map_io,
Will Deacon80b5efbd2011-02-28 17:01:04 +0100207 .init_irq = ct_ca9x4_init_irq,
208 .init_tile = ct_ca9x4_init,
209#ifdef CONFIG_SMP
210 .init_cpu_map = ct_ca9x4_init_cpu_map,
211 .smp_enable = ct_ca9x4_smp_enable,
212#endif
213};