blob: e4073a60a86457968a871fb8ad3096c1970f892c [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 Deacon80b5efb2011-02-28 17:01:04 +010016#include <asm/smp_scu.h>
Will Deaconbde28b82010-07-09 13:52:09 +010017#include <asm/smp_twd.h>
Russell Kingfef88f12010-02-28 17:26:25 +000018
Russell Kingfef88f12010-02-28 17:26:25 +000019#include <mach/ct-ca9x4.h>
20
Rob Herring8a9618f2010-10-06 16:18:08 +010021#include <asm/hardware/timer-sp.h>
Russell Kingfef88f12010-02-28 17:26:25 +000022
Russell Kingfef88f12010-02-28 17:26:25 +000023#include <asm/mach/map.h>
24#include <asm/mach/time.h>
25
26#include "core.h"
27
28#include <mach/motherboard.h>
29
Russell King0fb44b92011-01-18 20:13:51 +000030#include <plat/clcd.h>
31
Russell Kingfef88f12010-02-28 17:26:25 +000032static struct map_desc ct_ca9x4_io_desc[] __initdata = {
33 {
Pawel Moll98ed4ce2012-01-25 15:37:29 +000034 .virtual = V2T_PERIPH,
35 .pfn = __phys_to_pfn(CT_CA9X4_MPIC),
36 .length = SZ_8K,
37 .type = MT_DEVICE,
Russell Kingfef88f12010-02-28 17:26:25 +000038 },
39};
40
41static void __init ct_ca9x4_map_io(void)
42{
Will Deacon80b5efb2011-02-28 17:01:04 +010043 iotable_init(ct_ca9x4_io_desc, ARRAY_SIZE(ct_ca9x4_io_desc));
Russell Kingfef88f12010-02-28 17:26:25 +000044}
45
Marc Zyngier7c380f22011-08-04 11:57:04 +010046#ifdef CONFIG_HAVE_ARM_TWD
47static DEFINE_TWD_LOCAL_TIMER(twd_local_timer, A9_MPCORE_TWD, IRQ_LOCALTIMER);
48
49static void __init ca9x4_twd_init(void)
50{
51 int err = twd_local_timer_register(&twd_local_timer);
52 if (err)
53 pr_err("twd_local_timer_register failed %d\n", err);
54}
55#else
56#define ca9x4_twd_init() do {} while(0)
57#endif
58
Russell Kingfef88f12010-02-28 17:26:25 +000059static void __init ct_ca9x4_init_irq(void)
60{
Pawel Moll98ed4ce2012-01-25 15:37:29 +000061 gic_init(0, 29, ioremap(A9_MPCORE_GIC_DIST, SZ_4K),
62 ioremap(A9_MPCORE_GIC_CPU, SZ_256));
Marc Zyngier7c380f22011-08-04 11:57:04 +010063 ca9x4_twd_init();
Russell Kingfef88f12010-02-28 17:26:25 +000064}
65
Russell Kingfef88f12010-02-28 17:26:25 +000066static void ct_ca9x4_clcd_enable(struct clcd_fb *fb)
67{
Pawel Molld927daf2012-06-12 16:14:03 +010068 u32 site = v2m_get_master_site();
69
70 /*
71 * Old firmware was using the "site" component of the command
72 * to control the DVI muxer (while it should be always 0 ie. MB).
73 * Newer firmware uses the data register. Keep both for compatibility.
74 */
75 v2m_cfg_write(SYS_CFG_MUXFPGA | SYS_CFG_SITE(site), site);
76 v2m_cfg_write(SYS_CFG_DVIMODE | SYS_CFG_SITE(SYS_CFG_SITE_MB), 2);
Russell Kingfef88f12010-02-28 17:26:25 +000077}
78
79static int ct_ca9x4_clcd_setup(struct clcd_fb *fb)
80{
81 unsigned long framesize = 1024 * 768 * 2;
Russell Kingfef88f12010-02-28 17:26:25 +000082
Russell King0fb44b92011-01-18 20:13:51 +000083 fb->panel = versatile_clcd_get_panel("XVGA");
84 if (!fb->panel)
85 return -EINVAL;
Russell Kingfef88f12010-02-28 17:26:25 +000086
Russell King0fb44b92011-01-18 20:13:51 +000087 return versatile_clcd_setup_dma(fb, framesize);
Russell Kingfef88f12010-02-28 17:26:25 +000088}
89
90static struct clcd_board ct_ca9x4_clcd_data = {
91 .name = "CT-CA9X4",
Russell King0fb44b92011-01-18 20:13:51 +000092 .caps = CLCD_CAP_5551 | CLCD_CAP_565,
Russell Kingfef88f12010-02-28 17:26:25 +000093 .check = clcdfb_check,
94 .decode = clcdfb_decode,
95 .enable = ct_ca9x4_clcd_enable,
96 .setup = ct_ca9x4_clcd_setup,
Russell King0fb44b92011-01-18 20:13:51 +000097 .mmap = versatile_clcd_mmap_dma,
98 .remove = versatile_clcd_remove_dma,
Russell Kingfef88f12010-02-28 17:26:25 +000099};
100
Russell Kingcdd4e1a2011-12-18 12:07:09 +0000101static AMBA_AHB_DEVICE(clcd, "ct:clcd", 0, CT_CA9X4_CLCDC, IRQ_CT_CA9X4_CLCDC, &ct_ca9x4_clcd_data);
102static AMBA_APB_DEVICE(dmc, "ct:dmc", 0, CT_CA9X4_DMC, IRQ_CT_CA9X4_DMC, NULL);
103static AMBA_APB_DEVICE(smc, "ct:smc", 0, CT_CA9X4_SMC, IRQ_CT_CA9X4_SMC, NULL);
104static AMBA_APB_DEVICE(gpio, "ct:gpio", 0, CT_CA9X4_GPIO, IRQ_CT_CA9X4_GPIO, NULL);
Russell Kingfef88f12010-02-28 17:26:25 +0000105
106static struct amba_device *ct_ca9x4_amba_devs[] __initdata = {
107 &clcd_device,
108 &dmc_device,
109 &smc_device,
110 &gpio_device,
111};
112
113
Pawel Molld1b8a772012-07-13 11:48:16 +0100114static struct v2m_osc ct_osc1 = {
115 .osc = 1,
116 .rate_min = 10000000,
117 .rate_max = 80000000,
118 .rate_default = 23750000,
Russell Kingfef88f12010-02-28 17:26:25 +0000119};
120
Will Deaconf417cba2010-04-15 10:16:26 +0100121static struct resource pmu_resources[] = {
122 [0] = {
123 .start = IRQ_CT_CA9X4_PMU_CPU0,
124 .end = IRQ_CT_CA9X4_PMU_CPU0,
125 .flags = IORESOURCE_IRQ,
126 },
127 [1] = {
128 .start = IRQ_CT_CA9X4_PMU_CPU1,
129 .end = IRQ_CT_CA9X4_PMU_CPU1,
130 .flags = IORESOURCE_IRQ,
131 },
132 [2] = {
133 .start = IRQ_CT_CA9X4_PMU_CPU2,
134 .end = IRQ_CT_CA9X4_PMU_CPU2,
135 .flags = IORESOURCE_IRQ,
136 },
137 [3] = {
138 .start = IRQ_CT_CA9X4_PMU_CPU3,
139 .end = IRQ_CT_CA9X4_PMU_CPU3,
140 .flags = IORESOURCE_IRQ,
141 },
142};
143
144static struct platform_device pmu_device = {
145 .name = "arm-pmu",
Sudeep KarkadaNageshadf3d17e2012-07-19 09:50:21 +0100146 .id = -1,
Will Deaconf417cba2010-04-15 10:16:26 +0100147 .num_resources = ARRAY_SIZE(pmu_resources),
148 .resource = pmu_resources,
149};
150
Russell Kingcdaf9a22010-10-05 11:29:28 +0100151static void __init ct_ca9x4_init(void)
Russell Kingfef88f12010-02-28 17:26:25 +0000152{
153 int i;
Pawel Molld1b8a772012-07-13 11:48:16 +0100154 struct clk *clk;
Russell Kingfef88f12010-02-28 17:26:25 +0000155
156#ifdef CONFIG_CACHE_L2X0
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000157 void __iomem *l2x0_base = ioremap(CT_CA9X4_L2CC, SZ_4K);
Will Deacon2de59fe2010-09-27 14:55:15 +0100158
159 /* set RAM latencies to 1 cycle for this core tile. */
160 writel(0, l2x0_base + L2X0_TAG_LATENCY_CTRL);
161 writel(0, l2x0_base + L2X0_DATA_LATENCY_CTRL);
162
163 l2x0_init(l2x0_base, 0x00400000, 0xfe0fffff);
Russell Kingfef88f12010-02-28 17:26:25 +0000164#endif
165
Pawel Molld1b8a772012-07-13 11:48:16 +0100166 ct_osc1.site = v2m_get_master_site();
167 clk = v2m_osc_register("ct:osc1", &ct_osc1);
168 clk_register_clkdev(clk, NULL, "ct:clcd");
169
Russell Kingfef88f12010-02-28 17:26:25 +0000170 for (i = 0; i < ARRAY_SIZE(ct_ca9x4_amba_devs); i++)
171 amba_device_register(ct_ca9x4_amba_devs[i], &iomem_resource);
Will Deaconf417cba2010-04-15 10:16:26 +0100172
173 platform_device_register(&pmu_device);
Russell Kingfef88f12010-02-28 17:26:25 +0000174}
175
Will Deacon80b5efb2011-02-28 17:01:04 +0100176#ifdef CONFIG_SMP
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000177static void *ct_ca9x4_scu_base __initdata;
178
Russell King94ae0272012-01-18 19:40:13 +0000179static void __init ct_ca9x4_init_cpu_map(void)
Will Deacon80b5efb2011-02-28 17:01:04 +0100180{
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000181 int i, ncores;
182
183 ct_ca9x4_scu_base = ioremap(A9_MPCORE_SCU, SZ_128);
184 if (WARN_ON(!ct_ca9x4_scu_base))
185 return;
186
187 ncores = scu_get_core_count(ct_ca9x4_scu_base);
Will Deacon80b5efb2011-02-28 17:01:04 +0100188
Russell Kinga06f9162011-10-20 22:04:18 +0100189 if (ncores > nr_cpu_ids) {
190 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
191 ncores, nr_cpu_ids);
192 ncores = nr_cpu_ids;
193 }
194
Will Deacon80b5efb2011-02-28 17:01:04 +0100195 for (i = 0; i < ncores; ++i)
196 set_cpu_possible(i, true);
Russell King0f7b3322011-04-03 13:01:30 +0100197
198 set_smp_cross_call(gic_raise_softirq);
Will Deacon80b5efb2011-02-28 17:01:04 +0100199}
200
Russell King94ae0272012-01-18 19:40:13 +0000201static void __init ct_ca9x4_smp_enable(unsigned int max_cpus)
Will Deacon80b5efb2011-02-28 17:01:04 +0100202{
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000203 scu_enable(ct_ca9x4_scu_base);
Will Deacon80b5efb2011-02-28 17:01:04 +0100204}
Russell Kingfef88f12010-02-28 17:26:25 +0000205#endif
Will Deacon80b5efb2011-02-28 17:01:04 +0100206
207struct ct_desc ct_ca9x4_desc __initdata = {
208 .id = V2M_CT_ID_CA9,
209 .name = "CA9x4",
210 .map_io = ct_ca9x4_map_io,
Will Deacon80b5efb2011-02-28 17:01:04 +0100211 .init_irq = ct_ca9x4_init_irq,
212 .init_tile = ct_ca9x4_init,
213#ifdef CONFIG_SMP
214 .init_cpu_map = ct_ca9x4_init_cpu_map,
215 .smp_enable = ct_ca9x4_smp_enable,
216#endif
217};