blob: a2f7d5d3ca40451dae016f4c3bf06902c6f043c4 [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>
Russell Kingfef88f12010-02-28 17:26:25 +000012
Russell Kingfef88f12010-02-28 17:26:25 +000013#include <asm/hardware/arm_timer.h>
14#include <asm/hardware/cache-l2x0.h>
15#include <asm/hardware/gic.h>
Will Deaconf417cba2010-04-15 10:16:26 +010016#include <asm/pmu.h>
Will Deacon80b5efb2011-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>
30
Russell King0fb44b92011-01-18 20:13:51 +000031#include <plat/clcd.h>
32
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 Deacon80b5efb2011-02-28 17:01:04 +010044 iotable_init(ct_ca9x4_io_desc, ARRAY_SIZE(ct_ca9x4_io_desc));
Pawel Moll98ed4ce2012-01-25 15:37:29 +000045#ifdef CONFIG_LOCAL_TIMERS
46 twd_base = ioremap(A9_MPCORE_TWD, SZ_32);
47#endif
Russell Kingfef88f12010-02-28 17:26:25 +000048}
49
Russell Kingfef88f12010-02-28 17:26:25 +000050static void __init ct_ca9x4_init_irq(void)
51{
Pawel Moll98ed4ce2012-01-25 15:37:29 +000052 gic_init(0, 29, ioremap(A9_MPCORE_GIC_DIST, SZ_4K),
53 ioremap(A9_MPCORE_GIC_CPU, SZ_256));
Russell Kingfef88f12010-02-28 17:26:25 +000054}
55
Russell Kingfef88f12010-02-28 17:26:25 +000056static void ct_ca9x4_clcd_enable(struct clcd_fb *fb)
57{
58 v2m_cfg_write(SYS_CFG_MUXFPGA | SYS_CFG_SITE_DB1, 0);
59 v2m_cfg_write(SYS_CFG_DVIMODE | SYS_CFG_SITE_DB1, 2);
60}
61
62static int ct_ca9x4_clcd_setup(struct clcd_fb *fb)
63{
64 unsigned long framesize = 1024 * 768 * 2;
Russell Kingfef88f12010-02-28 17:26:25 +000065
Russell King0fb44b92011-01-18 20:13:51 +000066 fb->panel = versatile_clcd_get_panel("XVGA");
67 if (!fb->panel)
68 return -EINVAL;
Russell Kingfef88f12010-02-28 17:26:25 +000069
Russell King0fb44b92011-01-18 20:13:51 +000070 return versatile_clcd_setup_dma(fb, framesize);
Russell Kingfef88f12010-02-28 17:26:25 +000071}
72
73static struct clcd_board ct_ca9x4_clcd_data = {
74 .name = "CT-CA9X4",
Russell King0fb44b92011-01-18 20:13:51 +000075 .caps = CLCD_CAP_5551 | CLCD_CAP_565,
Russell Kingfef88f12010-02-28 17:26:25 +000076 .check = clcdfb_check,
77 .decode = clcdfb_decode,
78 .enable = ct_ca9x4_clcd_enable,
79 .setup = ct_ca9x4_clcd_setup,
Russell King0fb44b92011-01-18 20:13:51 +000080 .mmap = versatile_clcd_mmap_dma,
81 .remove = versatile_clcd_remove_dma,
Russell Kingfef88f12010-02-28 17:26:25 +000082};
83
84static AMBA_DEVICE(clcd, "ct:clcd", CT_CA9X4_CLCDC, &ct_ca9x4_clcd_data);
85static AMBA_DEVICE(dmc, "ct:dmc", CT_CA9X4_DMC, NULL);
86static AMBA_DEVICE(smc, "ct:smc", CT_CA9X4_SMC, NULL);
87static AMBA_DEVICE(gpio, "ct:gpio", CT_CA9X4_GPIO, NULL);
88
89static struct amba_device *ct_ca9x4_amba_devs[] __initdata = {
90 &clcd_device,
91 &dmc_device,
92 &smc_device,
93 &gpio_device,
94};
95
96
97static long ct_round(struct clk *clk, unsigned long rate)
98{
99 return rate;
100}
101
102static int ct_set(struct clk *clk, unsigned long rate)
103{
104 return v2m_cfg_write(SYS_CFG_OSC | SYS_CFG_SITE_DB1 | 1, rate);
105}
106
107static const struct clk_ops osc1_clk_ops = {
108 .round = ct_round,
109 .set = ct_set,
110};
111
112static struct clk osc1_clk = {
113 .ops = &osc1_clk_ops,
114 .rate = 24000000,
115};
116
Russell King7ff550d2011-05-12 13:31:48 +0100117static struct clk ct_sp804_clk = {
118 .rate = 1000000,
119};
120
Russell Kingfef88f12010-02-28 17:26:25 +0000121static struct clk_lookup lookups[] = {
122 { /* CLCD */
123 .dev_id = "ct:clcd",
124 .clk = &osc1_clk,
Russell King7ff550d2011-05-12 13:31:48 +0100125 }, { /* SP804 timers */
126 .dev_id = "sp804",
Russell King23828a72011-05-12 15:45:16 +0100127 .con_id = "ct-timer0",
128 .clk = &ct_sp804_clk,
129 }, { /* SP804 timers */
130 .dev_id = "sp804",
Russell King7ff550d2011-05-12 13:31:48 +0100131 .con_id = "ct-timer1",
132 .clk = &ct_sp804_clk,
Russell Kingfef88f12010-02-28 17:26:25 +0000133 },
134};
135
Will Deaconf417cba2010-04-15 10:16:26 +0100136static struct resource pmu_resources[] = {
137 [0] = {
138 .start = IRQ_CT_CA9X4_PMU_CPU0,
139 .end = IRQ_CT_CA9X4_PMU_CPU0,
140 .flags = IORESOURCE_IRQ,
141 },
142 [1] = {
143 .start = IRQ_CT_CA9X4_PMU_CPU1,
144 .end = IRQ_CT_CA9X4_PMU_CPU1,
145 .flags = IORESOURCE_IRQ,
146 },
147 [2] = {
148 .start = IRQ_CT_CA9X4_PMU_CPU2,
149 .end = IRQ_CT_CA9X4_PMU_CPU2,
150 .flags = IORESOURCE_IRQ,
151 },
152 [3] = {
153 .start = IRQ_CT_CA9X4_PMU_CPU3,
154 .end = IRQ_CT_CA9X4_PMU_CPU3,
155 .flags = IORESOURCE_IRQ,
156 },
157};
158
159static struct platform_device pmu_device = {
160 .name = "arm-pmu",
161 .id = ARM_PMU_DEVICE_CPU,
162 .num_resources = ARRAY_SIZE(pmu_resources),
163 .resource = pmu_resources,
164};
165
Russell King493a4512011-01-11 13:07:52 +0000166static void __init ct_ca9x4_init_early(void)
167{
168 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
Russell King493a4512011-01-11 13:07:52 +0000169}
170
Russell Kingcdaf9a22010-10-05 11:29:28 +0100171static void __init ct_ca9x4_init(void)
Russell Kingfef88f12010-02-28 17:26:25 +0000172{
173 int i;
174
175#ifdef CONFIG_CACHE_L2X0
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000176 void __iomem *l2x0_base = ioremap(CT_CA9X4_L2CC, SZ_4K);
Will Deacon2de59fe2010-09-27 14:55:15 +0100177
178 /* set RAM latencies to 1 cycle for this core tile. */
179 writel(0, l2x0_base + L2X0_TAG_LATENCY_CTRL);
180 writel(0, l2x0_base + L2X0_DATA_LATENCY_CTRL);
181
182 l2x0_init(l2x0_base, 0x00400000, 0xfe0fffff);
Russell Kingfef88f12010-02-28 17:26:25 +0000183#endif
184
Russell Kingfef88f12010-02-28 17:26:25 +0000185 for (i = 0; i < ARRAY_SIZE(ct_ca9x4_amba_devs); i++)
186 amba_device_register(ct_ca9x4_amba_devs[i], &iomem_resource);
Will Deaconf417cba2010-04-15 10:16:26 +0100187
188 platform_device_register(&pmu_device);
Russell Kingfef88f12010-02-28 17:26:25 +0000189}
190
Will Deacon80b5efb2011-02-28 17:01:04 +0100191#ifdef CONFIG_SMP
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000192static void *ct_ca9x4_scu_base __initdata;
193
Russell King94ae0272012-01-18 19:40:13 +0000194static void __init ct_ca9x4_init_cpu_map(void)
Will Deacon80b5efb2011-02-28 17:01:04 +0100195{
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000196 int i, ncores;
197
198 ct_ca9x4_scu_base = ioremap(A9_MPCORE_SCU, SZ_128);
199 if (WARN_ON(!ct_ca9x4_scu_base))
200 return;
201
202 ncores = scu_get_core_count(ct_ca9x4_scu_base);
Will Deacon80b5efb2011-02-28 17:01:04 +0100203
Russell Kinga06f9162011-10-20 22:04:18 +0100204 if (ncores > nr_cpu_ids) {
205 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
206 ncores, nr_cpu_ids);
207 ncores = nr_cpu_ids;
208 }
209
Will Deacon80b5efb2011-02-28 17:01:04 +0100210 for (i = 0; i < ncores; ++i)
211 set_cpu_possible(i, true);
Russell King0f7b3322011-04-03 13:01:30 +0100212
213 set_smp_cross_call(gic_raise_softirq);
Will Deacon80b5efb2011-02-28 17:01:04 +0100214}
215
Russell King94ae0272012-01-18 19:40:13 +0000216static void __init ct_ca9x4_smp_enable(unsigned int max_cpus)
Will Deacon80b5efb2011-02-28 17:01:04 +0100217{
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000218 scu_enable(ct_ca9x4_scu_base);
Will Deacon80b5efb2011-02-28 17:01:04 +0100219}
Russell Kingfef88f12010-02-28 17:26:25 +0000220#endif
Will Deacon80b5efb2011-02-28 17:01:04 +0100221
222struct ct_desc ct_ca9x4_desc __initdata = {
223 .id = V2M_CT_ID_CA9,
224 .name = "CA9x4",
225 .map_io = ct_ca9x4_map_io,
226 .init_early = ct_ca9x4_init_early,
227 .init_irq = ct_ca9x4_init_irq,
228 .init_tile = ct_ca9x4_init,
229#ifdef CONFIG_SMP
230 .init_cpu_map = ct_ca9x4_init_cpu_map,
231 .smp_enable = ct_ca9x4_smp_enable,
232#endif
233};