blob: 27bea049380a67fa1c16684b1c9cab354ca98407 [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>
Linus Walleij11c32d72014-05-22 23:25:14 +020011#include <linux/platform_data/video-clcd-versatile.h>
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +010012#include <linux/clkdev.h>
Pawel Moll38669e02012-10-09 12:56:36 +010013#include <linux/vexpress.h>
Rob Herring520f7bd2012-12-27 13:10:24 -060014#include <linux/irqchip/arm-gic.h>
Russell Kingfef88f12010-02-28 17:26:25 +000015
Russell Kingfef88f12010-02-28 17:26:25 +000016#include <asm/hardware/arm_timer.h>
17#include <asm/hardware/cache-l2x0.h>
Will Deacon80b5efbd2011-02-28 17:01:04 +010018#include <asm/smp_scu.h>
Will Deaconbde28b82010-07-09 13:52:09 +010019#include <asm/smp_twd.h>
Russell Kingfef88f12010-02-28 17:26:25 +000020
Russell Kingfef88f12010-02-28 17:26:25 +000021#include <mach/ct-ca9x4.h>
22
Rob Herring8a9618f2010-10-06 16:18:08 +010023#include <asm/hardware/timer-sp.h>
Russell Kingfef88f12010-02-28 17:26:25 +000024
Russell Kingfef88f12010-02-28 17:26:25 +000025#include <asm/mach/map.h>
26#include <asm/mach/time.h>
27
28#include "core.h"
29
30#include <mach/motherboard.h>
Arnd Bergmanndb6b6722012-05-07 16:54:40 +000031#include <mach/irqs.h>
Russell Kingfef88f12010-02-28 17:26:25 +000032
Russell Kingfef88f12010-02-28 17:26:25 +000033static struct map_desc ct_ca9x4_io_desc[] __initdata = {
34 {
Pawel Moll98ed4ce2012-01-25 15:37:29 +000035 .virtual = V2T_PERIPH,
36 .pfn = __phys_to_pfn(CT_CA9X4_MPIC),
37 .length = SZ_8K,
38 .type = MT_DEVICE,
Russell Kingfef88f12010-02-28 17:26:25 +000039 },
40};
41
42static void __init ct_ca9x4_map_io(void)
43{
Will Deacon80b5efbd2011-02-28 17:01:04 +010044 iotable_init(ct_ca9x4_io_desc, ARRAY_SIZE(ct_ca9x4_io_desc));
Russell Kingfef88f12010-02-28 17:26:25 +000045}
46
Russell King060bf2a2014-03-19 11:15:38 +000047static void __init ca9x4_l2_init(void)
48{
49#ifdef CONFIG_CACHE_L2X0
50 void __iomem *l2x0_base = ioremap(CT_CA9X4_L2CC, SZ_4K);
51
52 if (l2x0_base) {
53 /* set RAM latencies to 1 cycle for this core tile. */
54 writel(0, l2x0_base + L310_TAG_LATENCY_CTRL);
55 writel(0, l2x0_base + L310_DATA_LATENCY_CTRL);
56
57 l2x0_init(l2x0_base, 0x00400000, 0xfe0fffff);
58 } else {
59 pr_err("L2C: unable to map L2 cache controller\n");
60 }
61#endif
62}
63
Marc Zyngier7c380f22011-08-04 11:57:04 +010064#ifdef CONFIG_HAVE_ARM_TWD
65static DEFINE_TWD_LOCAL_TIMER(twd_local_timer, A9_MPCORE_TWD, IRQ_LOCALTIMER);
66
67static void __init ca9x4_twd_init(void)
68{
69 int err = twd_local_timer_register(&twd_local_timer);
70 if (err)
71 pr_err("twd_local_timer_register failed %d\n", err);
72}
73#else
74#define ca9x4_twd_init() do {} while(0)
75#endif
76
Russell Kingfef88f12010-02-28 17:26:25 +000077static void __init ct_ca9x4_init_irq(void)
78{
Pawel Moll98ed4ce2012-01-25 15:37:29 +000079 gic_init(0, 29, ioremap(A9_MPCORE_GIC_DIST, SZ_4K),
80 ioremap(A9_MPCORE_GIC_CPU, SZ_256));
Marc Zyngier7c380f22011-08-04 11:57:04 +010081 ca9x4_twd_init();
Russell King060bf2a2014-03-19 11:15:38 +000082 ca9x4_l2_init();
Russell Kingfef88f12010-02-28 17:26:25 +000083}
84
Russell Kingfef88f12010-02-28 17:26:25 +000085static int ct_ca9x4_clcd_setup(struct clcd_fb *fb)
86{
87 unsigned long framesize = 1024 * 768 * 2;
Russell Kingfef88f12010-02-28 17:26:25 +000088
Russell King0fb44b92011-01-18 20:13:51 +000089 fb->panel = versatile_clcd_get_panel("XVGA");
90 if (!fb->panel)
91 return -EINVAL;
Russell Kingfef88f12010-02-28 17:26:25 +000092
Russell King0fb44b92011-01-18 20:13:51 +000093 return versatile_clcd_setup_dma(fb, framesize);
Russell Kingfef88f12010-02-28 17:26:25 +000094}
95
96static struct clcd_board ct_ca9x4_clcd_data = {
97 .name = "CT-CA9X4",
Russell King0fb44b92011-01-18 20:13:51 +000098 .caps = CLCD_CAP_5551 | CLCD_CAP_565,
Russell Kingfef88f12010-02-28 17:26:25 +000099 .check = clcdfb_check,
100 .decode = clcdfb_decode,
Russell Kingfef88f12010-02-28 17:26:25 +0000101 .setup = ct_ca9x4_clcd_setup,
Russell King0fb44b92011-01-18 20:13:51 +0000102 .mmap = versatile_clcd_mmap_dma,
103 .remove = versatile_clcd_remove_dma,
Russell Kingfef88f12010-02-28 17:26:25 +0000104};
105
Russell Kingcdd4e1a2011-12-18 12:07:09 +0000106static AMBA_AHB_DEVICE(clcd, "ct:clcd", 0, CT_CA9X4_CLCDC, IRQ_CT_CA9X4_CLCDC, &ct_ca9x4_clcd_data);
107static AMBA_APB_DEVICE(dmc, "ct:dmc", 0, CT_CA9X4_DMC, IRQ_CT_CA9X4_DMC, NULL);
108static AMBA_APB_DEVICE(smc, "ct:smc", 0, CT_CA9X4_SMC, IRQ_CT_CA9X4_SMC, NULL);
109static AMBA_APB_DEVICE(gpio, "ct:gpio", 0, CT_CA9X4_GPIO, IRQ_CT_CA9X4_GPIO, NULL);
Russell Kingfef88f12010-02-28 17:26:25 +0000110
111static struct amba_device *ct_ca9x4_amba_devs[] __initdata = {
112 &clcd_device,
113 &dmc_device,
114 &smc_device,
115 &gpio_device,
116};
117
Will Deaconf417cba2010-04-15 10:16:26 +0100118static struct resource pmu_resources[] = {
119 [0] = {
120 .start = IRQ_CT_CA9X4_PMU_CPU0,
121 .end = IRQ_CT_CA9X4_PMU_CPU0,
122 .flags = IORESOURCE_IRQ,
123 },
124 [1] = {
125 .start = IRQ_CT_CA9X4_PMU_CPU1,
126 .end = IRQ_CT_CA9X4_PMU_CPU1,
127 .flags = IORESOURCE_IRQ,
128 },
129 [2] = {
130 .start = IRQ_CT_CA9X4_PMU_CPU2,
131 .end = IRQ_CT_CA9X4_PMU_CPU2,
132 .flags = IORESOURCE_IRQ,
133 },
134 [3] = {
135 .start = IRQ_CT_CA9X4_PMU_CPU3,
136 .end = IRQ_CT_CA9X4_PMU_CPU3,
137 .flags = IORESOURCE_IRQ,
138 },
139};
140
141static struct platform_device pmu_device = {
142 .name = "arm-pmu",
Sudeep KarkadaNageshadf3d17e2012-07-19 09:50:21 +0100143 .id = -1,
Will Deaconf417cba2010-04-15 10:16:26 +0100144 .num_resources = ARRAY_SIZE(pmu_resources),
145 .resource = pmu_resources,
146};
147
Pawel Moll3b9334a2014-04-30 16:46:29 +0100148static struct clk_lookup osc1_lookup = {
149 .dev_id = "ct:clcd",
150};
151
Pawel Moll38669e02012-10-09 12:56:36 +0100152static struct platform_device osc1_device = {
153 .name = "vexpress-osc",
154 .id = 1,
155 .num_resources = 1,
156 .resource = (struct resource []) {
157 VEXPRESS_RES_FUNC(0xf, 1),
158 },
Pawel Moll3b9334a2014-04-30 16:46:29 +0100159 .dev.platform_data = &osc1_lookup,
Pawel Moll38669e02012-10-09 12:56:36 +0100160};
161
Russell Kingcdaf9a22010-10-05 11:29:28 +0100162static void __init ct_ca9x4_init(void)
Russell Kingfef88f12010-02-28 17:26:25 +0000163{
164 int i;
165
Russell Kingfef88f12010-02-28 17:26:25 +0000166 for (i = 0; i < ARRAY_SIZE(ct_ca9x4_amba_devs); i++)
167 amba_device_register(ct_ca9x4_amba_devs[i], &iomem_resource);
Will Deaconf417cba2010-04-15 10:16:26 +0100168
169 platform_device_register(&pmu_device);
Pawel Moll974cc7b2014-04-23 10:49:31 +0100170 vexpress_syscfg_device_register(&osc1_device);
Russell Kingfef88f12010-02-28 17:26:25 +0000171}
172
Will Deacon80b5efbd2011-02-28 17:01:04 +0100173#ifdef CONFIG_SMP
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000174static void *ct_ca9x4_scu_base __initdata;
175
Russell King94ae0272012-01-18 19:40:13 +0000176static void __init ct_ca9x4_init_cpu_map(void)
Will Deacon80b5efbd2011-02-28 17:01:04 +0100177{
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000178 int i, ncores;
179
180 ct_ca9x4_scu_base = ioremap(A9_MPCORE_SCU, SZ_128);
181 if (WARN_ON(!ct_ca9x4_scu_base))
182 return;
183
184 ncores = scu_get_core_count(ct_ca9x4_scu_base);
Will Deacon80b5efbd2011-02-28 17:01:04 +0100185
Russell Kinga06f9162011-10-20 22:04:18 +0100186 if (ncores > nr_cpu_ids) {
187 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
188 ncores, nr_cpu_ids);
189 ncores = nr_cpu_ids;
190 }
191
Will Deacon80b5efbd2011-02-28 17:01:04 +0100192 for (i = 0; i < ncores; ++i)
193 set_cpu_possible(i, true);
194}
195
Russell King94ae0272012-01-18 19:40:13 +0000196static void __init ct_ca9x4_smp_enable(unsigned int max_cpus)
Will Deacon80b5efbd2011-02-28 17:01:04 +0100197{
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000198 scu_enable(ct_ca9x4_scu_base);
Will Deacon80b5efbd2011-02-28 17:01:04 +0100199}
Russell Kingfef88f12010-02-28 17:26:25 +0000200#endif
Will Deacon80b5efbd2011-02-28 17:01:04 +0100201
202struct ct_desc ct_ca9x4_desc __initdata = {
203 .id = V2M_CT_ID_CA9,
204 .name = "CA9x4",
205 .map_io = ct_ca9x4_map_io,
Will Deacon80b5efbd2011-02-28 17:01:04 +0100206 .init_irq = ct_ca9x4_init_irq,
207 .init_tile = ct_ca9x4_init,
208#ifdef CONFIG_SMP
209 .init_cpu_map = ct_ca9x4_init_cpu_map,
210 .smp_enable = ct_ca9x4_smp_enable,
211#endif
212};