Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Versatile Express Core Tile Cortex A9x4 Support |
| 3 | */ |
| 4 | #include <linux/init.h> |
Tejun Heo | 68aaae9 | 2010-03-30 02:52:45 +0900 | [diff] [blame] | 5 | #include <linux/gfp.h> |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 6 | #include <linux/device.h> |
| 7 | #include <linux/dma-mapping.h> |
Will Deacon | f417cba | 2010-04-15 10:16:26 +0100 | [diff] [blame] | 8 | #include <linux/platform_device.h> |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 9 | #include <linux/amba/bus.h> |
| 10 | #include <linux/amba/clcd.h> |
Jean-Christop PLAGNIOL-VILLARD | 6d803ba | 2010-11-17 10:04:33 +0100 | [diff] [blame] | 11 | #include <linux/clkdev.h> |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 12 | |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 13 | #include <asm/hardware/arm_timer.h> |
| 14 | #include <asm/hardware/cache-l2x0.h> |
| 15 | #include <asm/hardware/gic.h> |
Will Deacon | f417cba | 2010-04-15 10:16:26 +0100 | [diff] [blame] | 16 | #include <asm/pmu.h> |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 17 | #include <asm/smp_scu.h> |
Will Deacon | bde28b8 | 2010-07-09 13:52:09 +0100 | [diff] [blame] | 18 | #include <asm/smp_twd.h> |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 19 | |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 20 | #include <mach/ct-ca9x4.h> |
| 21 | |
Rob Herring | 8a9618f | 2010-10-06 16:18:08 +0100 | [diff] [blame] | 22 | #include <asm/hardware/timer-sp.h> |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 23 | |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 24 | #include <asm/mach/map.h> |
| 25 | #include <asm/mach/time.h> |
| 26 | |
| 27 | #include "core.h" |
| 28 | |
| 29 | #include <mach/motherboard.h> |
| 30 | |
Russell King | 0fb44b9 | 2011-01-18 20:13:51 +0000 | [diff] [blame] | 31 | #include <plat/clcd.h> |
| 32 | |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 33 | static struct map_desc ct_ca9x4_io_desc[] __initdata = { |
| 34 | { |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 35 | .virtual = V2T_PERIPH, |
| 36 | .pfn = __phys_to_pfn(CT_CA9X4_MPIC), |
| 37 | .length = SZ_8K, |
| 38 | .type = MT_DEVICE, |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 39 | }, |
| 40 | }; |
| 41 | |
| 42 | static void __init ct_ca9x4_map_io(void) |
| 43 | { |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 44 | iotable_init(ct_ca9x4_io_desc, ARRAY_SIZE(ct_ca9x4_io_desc)); |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Marc Zyngier | 7c380f2 | 2011-08-04 11:57:04 +0100 | [diff] [blame] | 47 | #ifdef CONFIG_HAVE_ARM_TWD |
| 48 | static DEFINE_TWD_LOCAL_TIMER(twd_local_timer, A9_MPCORE_TWD, IRQ_LOCALTIMER); |
| 49 | |
| 50 | static 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 King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 60 | static void __init ct_ca9x4_init_irq(void) |
| 61 | { |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 62 | gic_init(0, 29, ioremap(A9_MPCORE_GIC_DIST, SZ_4K), |
| 63 | ioremap(A9_MPCORE_GIC_CPU, SZ_256)); |
Marc Zyngier | 7c380f2 | 2011-08-04 11:57:04 +0100 | [diff] [blame] | 64 | ca9x4_twd_init(); |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 67 | static void ct_ca9x4_clcd_enable(struct clcd_fb *fb) |
| 68 | { |
| 69 | v2m_cfg_write(SYS_CFG_MUXFPGA | SYS_CFG_SITE_DB1, 0); |
| 70 | v2m_cfg_write(SYS_CFG_DVIMODE | SYS_CFG_SITE_DB1, 2); |
| 71 | } |
| 72 | |
| 73 | static int ct_ca9x4_clcd_setup(struct clcd_fb *fb) |
| 74 | { |
| 75 | unsigned long framesize = 1024 * 768 * 2; |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 76 | |
Russell King | 0fb44b9 | 2011-01-18 20:13:51 +0000 | [diff] [blame] | 77 | fb->panel = versatile_clcd_get_panel("XVGA"); |
| 78 | if (!fb->panel) |
| 79 | return -EINVAL; |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 80 | |
Russell King | 0fb44b9 | 2011-01-18 20:13:51 +0000 | [diff] [blame] | 81 | return versatile_clcd_setup_dma(fb, framesize); |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static struct clcd_board ct_ca9x4_clcd_data = { |
| 85 | .name = "CT-CA9X4", |
Russell King | 0fb44b9 | 2011-01-18 20:13:51 +0000 | [diff] [blame] | 86 | .caps = CLCD_CAP_5551 | CLCD_CAP_565, |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 87 | .check = clcdfb_check, |
| 88 | .decode = clcdfb_decode, |
| 89 | .enable = ct_ca9x4_clcd_enable, |
| 90 | .setup = ct_ca9x4_clcd_setup, |
Russell King | 0fb44b9 | 2011-01-18 20:13:51 +0000 | [diff] [blame] | 91 | .mmap = versatile_clcd_mmap_dma, |
| 92 | .remove = versatile_clcd_remove_dma, |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
Russell King | cdd4e1a | 2011-12-18 12:07:09 +0000 | [diff] [blame] | 95 | static AMBA_AHB_DEVICE(clcd, "ct:clcd", 0, CT_CA9X4_CLCDC, IRQ_CT_CA9X4_CLCDC, &ct_ca9x4_clcd_data); |
| 96 | static AMBA_APB_DEVICE(dmc, "ct:dmc", 0, CT_CA9X4_DMC, IRQ_CT_CA9X4_DMC, NULL); |
| 97 | static AMBA_APB_DEVICE(smc, "ct:smc", 0, CT_CA9X4_SMC, IRQ_CT_CA9X4_SMC, NULL); |
| 98 | static AMBA_APB_DEVICE(gpio, "ct:gpio", 0, CT_CA9X4_GPIO, IRQ_CT_CA9X4_GPIO, NULL); |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 99 | |
| 100 | static struct amba_device *ct_ca9x4_amba_devs[] __initdata = { |
| 101 | &clcd_device, |
| 102 | &dmc_device, |
| 103 | &smc_device, |
| 104 | &gpio_device, |
| 105 | }; |
| 106 | |
| 107 | |
| 108 | static long ct_round(struct clk *clk, unsigned long rate) |
| 109 | { |
| 110 | return rate; |
| 111 | } |
| 112 | |
| 113 | static int ct_set(struct clk *clk, unsigned long rate) |
| 114 | { |
| 115 | return v2m_cfg_write(SYS_CFG_OSC | SYS_CFG_SITE_DB1 | 1, rate); |
| 116 | } |
| 117 | |
| 118 | static const struct clk_ops osc1_clk_ops = { |
| 119 | .round = ct_round, |
| 120 | .set = ct_set, |
| 121 | }; |
| 122 | |
| 123 | static struct clk osc1_clk = { |
| 124 | .ops = &osc1_clk_ops, |
| 125 | .rate = 24000000, |
| 126 | }; |
| 127 | |
Russell King | 7ff550d | 2011-05-12 13:31:48 +0100 | [diff] [blame] | 128 | static struct clk ct_sp804_clk = { |
| 129 | .rate = 1000000, |
| 130 | }; |
| 131 | |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 132 | static struct clk_lookup lookups[] = { |
| 133 | { /* CLCD */ |
| 134 | .dev_id = "ct:clcd", |
| 135 | .clk = &osc1_clk, |
Russell King | 7ff550d | 2011-05-12 13:31:48 +0100 | [diff] [blame] | 136 | }, { /* SP804 timers */ |
| 137 | .dev_id = "sp804", |
Russell King | 23828a7 | 2011-05-12 15:45:16 +0100 | [diff] [blame] | 138 | .con_id = "ct-timer0", |
| 139 | .clk = &ct_sp804_clk, |
| 140 | }, { /* SP804 timers */ |
| 141 | .dev_id = "sp804", |
Russell King | 7ff550d | 2011-05-12 13:31:48 +0100 | [diff] [blame] | 142 | .con_id = "ct-timer1", |
| 143 | .clk = &ct_sp804_clk, |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 144 | }, |
| 145 | }; |
| 146 | |
Will Deacon | f417cba | 2010-04-15 10:16:26 +0100 | [diff] [blame] | 147 | static struct resource pmu_resources[] = { |
| 148 | [0] = { |
| 149 | .start = IRQ_CT_CA9X4_PMU_CPU0, |
| 150 | .end = IRQ_CT_CA9X4_PMU_CPU0, |
| 151 | .flags = IORESOURCE_IRQ, |
| 152 | }, |
| 153 | [1] = { |
| 154 | .start = IRQ_CT_CA9X4_PMU_CPU1, |
| 155 | .end = IRQ_CT_CA9X4_PMU_CPU1, |
| 156 | .flags = IORESOURCE_IRQ, |
| 157 | }, |
| 158 | [2] = { |
| 159 | .start = IRQ_CT_CA9X4_PMU_CPU2, |
| 160 | .end = IRQ_CT_CA9X4_PMU_CPU2, |
| 161 | .flags = IORESOURCE_IRQ, |
| 162 | }, |
| 163 | [3] = { |
| 164 | .start = IRQ_CT_CA9X4_PMU_CPU3, |
| 165 | .end = IRQ_CT_CA9X4_PMU_CPU3, |
| 166 | .flags = IORESOURCE_IRQ, |
| 167 | }, |
| 168 | }; |
| 169 | |
| 170 | static struct platform_device pmu_device = { |
| 171 | .name = "arm-pmu", |
| 172 | .id = ARM_PMU_DEVICE_CPU, |
| 173 | .num_resources = ARRAY_SIZE(pmu_resources), |
| 174 | .resource = pmu_resources, |
| 175 | }; |
| 176 | |
Russell King | 493a451 | 2011-01-11 13:07:52 +0000 | [diff] [blame] | 177 | static void __init ct_ca9x4_init_early(void) |
| 178 | { |
| 179 | clkdev_add_table(lookups, ARRAY_SIZE(lookups)); |
Russell King | 493a451 | 2011-01-11 13:07:52 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Russell King | cdaf9a2 | 2010-10-05 11:29:28 +0100 | [diff] [blame] | 182 | static void __init ct_ca9x4_init(void) |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 183 | { |
| 184 | int i; |
| 185 | |
| 186 | #ifdef CONFIG_CACHE_L2X0 |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 187 | void __iomem *l2x0_base = ioremap(CT_CA9X4_L2CC, SZ_4K); |
Will Deacon | 2de59fe | 2010-09-27 14:55:15 +0100 | [diff] [blame] | 188 | |
| 189 | /* set RAM latencies to 1 cycle for this core tile. */ |
| 190 | writel(0, l2x0_base + L2X0_TAG_LATENCY_CTRL); |
| 191 | writel(0, l2x0_base + L2X0_DATA_LATENCY_CTRL); |
| 192 | |
| 193 | l2x0_init(l2x0_base, 0x00400000, 0xfe0fffff); |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 194 | #endif |
| 195 | |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 196 | for (i = 0; i < ARRAY_SIZE(ct_ca9x4_amba_devs); i++) |
| 197 | amba_device_register(ct_ca9x4_amba_devs[i], &iomem_resource); |
Will Deacon | f417cba | 2010-04-15 10:16:26 +0100 | [diff] [blame] | 198 | |
| 199 | platform_device_register(&pmu_device); |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 202 | #ifdef CONFIG_SMP |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 203 | static void *ct_ca9x4_scu_base __initdata; |
| 204 | |
Russell King | 94ae027 | 2012-01-18 19:40:13 +0000 | [diff] [blame] | 205 | static void __init ct_ca9x4_init_cpu_map(void) |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 206 | { |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 207 | int i, ncores; |
| 208 | |
| 209 | ct_ca9x4_scu_base = ioremap(A9_MPCORE_SCU, SZ_128); |
| 210 | if (WARN_ON(!ct_ca9x4_scu_base)) |
| 211 | return; |
| 212 | |
| 213 | ncores = scu_get_core_count(ct_ca9x4_scu_base); |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 214 | |
Russell King | a06f916 | 2011-10-20 22:04:18 +0100 | [diff] [blame] | 215 | if (ncores > nr_cpu_ids) { |
| 216 | pr_warn("SMP: %u cores greater than maximum (%u), clipping\n", |
| 217 | ncores, nr_cpu_ids); |
| 218 | ncores = nr_cpu_ids; |
| 219 | } |
| 220 | |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 221 | for (i = 0; i < ncores; ++i) |
| 222 | set_cpu_possible(i, true); |
Russell King | 0f7b332 | 2011-04-03 13:01:30 +0100 | [diff] [blame] | 223 | |
| 224 | set_smp_cross_call(gic_raise_softirq); |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 225 | } |
| 226 | |
Russell King | 94ae027 | 2012-01-18 19:40:13 +0000 | [diff] [blame] | 227 | static void __init ct_ca9x4_smp_enable(unsigned int max_cpus) |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 228 | { |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 229 | scu_enable(ct_ca9x4_scu_base); |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 230 | } |
Russell King | fef88f1 | 2010-02-28 17:26:25 +0000 | [diff] [blame] | 231 | #endif |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 232 | |
| 233 | struct ct_desc ct_ca9x4_desc __initdata = { |
| 234 | .id = V2M_CT_ID_CA9, |
| 235 | .name = "CA9x4", |
| 236 | .map_io = ct_ca9x4_map_io, |
| 237 | .init_early = ct_ca9x4_init_early, |
| 238 | .init_irq = ct_ca9x4_init_irq, |
| 239 | .init_tile = ct_ca9x4_init, |
| 240 | #ifdef CONFIG_SMP |
| 241 | .init_cpu_map = ct_ca9x4_init_cpu_map, |
| 242 | .smp_enable = ct_ca9x4_smp_enable, |
| 243 | #endif |
| 244 | }; |