blob: ab15a5515312e32b2cfe1471afefc8d85ffcc169 [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));
Russell Kingfef88f12010-02-28 17:26:25 +000045}
46
Marc Zyngier7c380f22011-08-04 11:57:04 +010047#ifdef CONFIG_HAVE_ARM_TWD
48static DEFINE_TWD_LOCAL_TIMER(twd_local_timer, A9_MPCORE_TWD, IRQ_LOCALTIMER);
49
50static void __init ca9x4_twd_init(void)
51{
52 int err = twd_local_timer_register(&twd_local_timer);
53 if (err)
54 pr_err("twd_local_timer_register failed %d\n", err);
55}
56#else
57#define ca9x4_twd_init() do {} while(0)
58#endif
59
Russell Kingfef88f12010-02-28 17:26:25 +000060static void __init ct_ca9x4_init_irq(void)
61{
Pawel Moll98ed4ce2012-01-25 15:37:29 +000062 gic_init(0, 29, ioremap(A9_MPCORE_GIC_DIST, SZ_4K),
63 ioremap(A9_MPCORE_GIC_CPU, SZ_256));
Marc Zyngier7c380f22011-08-04 11:57:04 +010064 ca9x4_twd_init();
Russell Kingfef88f12010-02-28 17:26:25 +000065}
66
Russell Kingfef88f12010-02-28 17:26:25 +000067static void ct_ca9x4_clcd_enable(struct clcd_fb *fb)
68{
Pawel Molld927daf2012-06-12 16:14:03 +010069 u32 site = v2m_get_master_site();
70
71 /*
72 * Old firmware was using the "site" component of the command
73 * to control the DVI muxer (while it should be always 0 ie. MB).
74 * Newer firmware uses the data register. Keep both for compatibility.
75 */
76 v2m_cfg_write(SYS_CFG_MUXFPGA | SYS_CFG_SITE(site), site);
77 v2m_cfg_write(SYS_CFG_DVIMODE | SYS_CFG_SITE(SYS_CFG_SITE_MB), 2);
Russell Kingfef88f12010-02-28 17:26:25 +000078}
79
80static int ct_ca9x4_clcd_setup(struct clcd_fb *fb)
81{
82 unsigned long framesize = 1024 * 768 * 2;
Russell Kingfef88f12010-02-28 17:26:25 +000083
Russell King0fb44b92011-01-18 20:13:51 +000084 fb->panel = versatile_clcd_get_panel("XVGA");
85 if (!fb->panel)
86 return -EINVAL;
Russell Kingfef88f12010-02-28 17:26:25 +000087
Russell King0fb44b92011-01-18 20:13:51 +000088 return versatile_clcd_setup_dma(fb, framesize);
Russell Kingfef88f12010-02-28 17:26:25 +000089}
90
91static struct clcd_board ct_ca9x4_clcd_data = {
92 .name = "CT-CA9X4",
Russell King0fb44b92011-01-18 20:13:51 +000093 .caps = CLCD_CAP_5551 | CLCD_CAP_565,
Russell Kingfef88f12010-02-28 17:26:25 +000094 .check = clcdfb_check,
95 .decode = clcdfb_decode,
96 .enable = ct_ca9x4_clcd_enable,
97 .setup = ct_ca9x4_clcd_setup,
Russell King0fb44b92011-01-18 20:13:51 +000098 .mmap = versatile_clcd_mmap_dma,
99 .remove = versatile_clcd_remove_dma,
Russell Kingfef88f12010-02-28 17:26:25 +0000100};
101
Russell Kingcdd4e1a2011-12-18 12:07:09 +0000102static AMBA_AHB_DEVICE(clcd, "ct:clcd", 0, CT_CA9X4_CLCDC, IRQ_CT_CA9X4_CLCDC, &ct_ca9x4_clcd_data);
103static AMBA_APB_DEVICE(dmc, "ct:dmc", 0, CT_CA9X4_DMC, IRQ_CT_CA9X4_DMC, NULL);
104static AMBA_APB_DEVICE(smc, "ct:smc", 0, CT_CA9X4_SMC, IRQ_CT_CA9X4_SMC, NULL);
105static AMBA_APB_DEVICE(gpio, "ct:gpio", 0, CT_CA9X4_GPIO, IRQ_CT_CA9X4_GPIO, NULL);
Russell Kingfef88f12010-02-28 17:26:25 +0000106
107static struct amba_device *ct_ca9x4_amba_devs[] __initdata = {
108 &clcd_device,
109 &dmc_device,
110 &smc_device,
111 &gpio_device,
112};
113
114
115static long ct_round(struct clk *clk, unsigned long rate)
116{
117 return rate;
118}
119
120static int ct_set(struct clk *clk, unsigned long rate)
121{
Pawel Molld927daf2012-06-12 16:14:03 +0100122 u32 site = v2m_get_master_site();
123
124 return v2m_cfg_write(SYS_CFG_OSC | SYS_CFG_SITE(site) | 1, rate);
Russell Kingfef88f12010-02-28 17:26:25 +0000125}
126
127static const struct clk_ops osc1_clk_ops = {
128 .round = ct_round,
129 .set = ct_set,
130};
131
132static struct clk osc1_clk = {
133 .ops = &osc1_clk_ops,
134 .rate = 24000000,
135};
136
Russell King7ff550d2011-05-12 13:31:48 +0100137static struct clk ct_sp804_clk = {
138 .rate = 1000000,
139};
140
Russell Kingfef88f12010-02-28 17:26:25 +0000141static struct clk_lookup lookups[] = {
142 { /* CLCD */
143 .dev_id = "ct:clcd",
144 .clk = &osc1_clk,
Russell King7ff550d2011-05-12 13:31:48 +0100145 }, { /* SP804 timers */
146 .dev_id = "sp804",
Russell King23828a72011-05-12 15:45:16 +0100147 .con_id = "ct-timer0",
148 .clk = &ct_sp804_clk,
149 }, { /* SP804 timers */
150 .dev_id = "sp804",
Russell King7ff550d2011-05-12 13:31:48 +0100151 .con_id = "ct-timer1",
152 .clk = &ct_sp804_clk,
Russell Kingfef88f12010-02-28 17:26:25 +0000153 },
154};
155
Will Deaconf417cba2010-04-15 10:16:26 +0100156static struct resource pmu_resources[] = {
157 [0] = {
158 .start = IRQ_CT_CA9X4_PMU_CPU0,
159 .end = IRQ_CT_CA9X4_PMU_CPU0,
160 .flags = IORESOURCE_IRQ,
161 },
162 [1] = {
163 .start = IRQ_CT_CA9X4_PMU_CPU1,
164 .end = IRQ_CT_CA9X4_PMU_CPU1,
165 .flags = IORESOURCE_IRQ,
166 },
167 [2] = {
168 .start = IRQ_CT_CA9X4_PMU_CPU2,
169 .end = IRQ_CT_CA9X4_PMU_CPU2,
170 .flags = IORESOURCE_IRQ,
171 },
172 [3] = {
173 .start = IRQ_CT_CA9X4_PMU_CPU3,
174 .end = IRQ_CT_CA9X4_PMU_CPU3,
175 .flags = IORESOURCE_IRQ,
176 },
177};
178
179static struct platform_device pmu_device = {
180 .name = "arm-pmu",
181 .id = ARM_PMU_DEVICE_CPU,
182 .num_resources = ARRAY_SIZE(pmu_resources),
183 .resource = pmu_resources,
184};
185
Russell King493a4512011-01-11 13:07:52 +0000186static void __init ct_ca9x4_init_early(void)
187{
188 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
Russell King493a4512011-01-11 13:07:52 +0000189}
190
Russell Kingcdaf9a22010-10-05 11:29:28 +0100191static void __init ct_ca9x4_init(void)
Russell Kingfef88f12010-02-28 17:26:25 +0000192{
193 int i;
194
195#ifdef CONFIG_CACHE_L2X0
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000196 void __iomem *l2x0_base = ioremap(CT_CA9X4_L2CC, SZ_4K);
Will Deacon2de59fe2010-09-27 14:55:15 +0100197
198 /* set RAM latencies to 1 cycle for this core tile. */
199 writel(0, l2x0_base + L2X0_TAG_LATENCY_CTRL);
200 writel(0, l2x0_base + L2X0_DATA_LATENCY_CTRL);
201
202 l2x0_init(l2x0_base, 0x00400000, 0xfe0fffff);
Russell Kingfef88f12010-02-28 17:26:25 +0000203#endif
204
Russell Kingfef88f12010-02-28 17:26:25 +0000205 for (i = 0; i < ARRAY_SIZE(ct_ca9x4_amba_devs); i++)
206 amba_device_register(ct_ca9x4_amba_devs[i], &iomem_resource);
Will Deaconf417cba2010-04-15 10:16:26 +0100207
208 platform_device_register(&pmu_device);
Russell Kingfef88f12010-02-28 17:26:25 +0000209}
210
Will Deacon80b5efb2011-02-28 17:01:04 +0100211#ifdef CONFIG_SMP
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000212static void *ct_ca9x4_scu_base __initdata;
213
Russell King94ae0272012-01-18 19:40:13 +0000214static void __init ct_ca9x4_init_cpu_map(void)
Will Deacon80b5efb2011-02-28 17:01:04 +0100215{
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000216 int i, ncores;
217
218 ct_ca9x4_scu_base = ioremap(A9_MPCORE_SCU, SZ_128);
219 if (WARN_ON(!ct_ca9x4_scu_base))
220 return;
221
222 ncores = scu_get_core_count(ct_ca9x4_scu_base);
Will Deacon80b5efb2011-02-28 17:01:04 +0100223
Russell Kinga06f9162011-10-20 22:04:18 +0100224 if (ncores > nr_cpu_ids) {
225 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
226 ncores, nr_cpu_ids);
227 ncores = nr_cpu_ids;
228 }
229
Will Deacon80b5efb2011-02-28 17:01:04 +0100230 for (i = 0; i < ncores; ++i)
231 set_cpu_possible(i, true);
Russell King0f7b3322011-04-03 13:01:30 +0100232
233 set_smp_cross_call(gic_raise_softirq);
Will Deacon80b5efb2011-02-28 17:01:04 +0100234}
235
Russell King94ae0272012-01-18 19:40:13 +0000236static void __init ct_ca9x4_smp_enable(unsigned int max_cpus)
Will Deacon80b5efb2011-02-28 17:01:04 +0100237{
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000238 scu_enable(ct_ca9x4_scu_base);
Will Deacon80b5efb2011-02-28 17:01:04 +0100239}
Russell Kingfef88f12010-02-28 17:26:25 +0000240#endif
Will Deacon80b5efb2011-02-28 17:01:04 +0100241
242struct ct_desc ct_ca9x4_desc __initdata = {
243 .id = V2M_CT_ID_CA9,
244 .name = "CA9x4",
245 .map_io = ct_ca9x4_map_io,
246 .init_early = ct_ca9x4_init_early,
247 .init_irq = ct_ca9x4_init_irq,
248 .init_tile = ct_ca9x4_init,
249#ifdef CONFIG_SMP
250 .init_cpu_map = ct_ca9x4_init_cpu_map,
251 .smp_enable = ct_ca9x4_smp_enable,
252#endif
253};