blob: 5a43107c62325fc8a3f533053777ca0385cdc436 [file] [log] [blame]
Rabin Vincent178980f2010-05-03 07:39:02 +01001/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
5 * License terms: GNU General Public License (GPL) version 2
6 */
7
8#include <linux/platform_device.h>
Rabin Vincent178980f2010-05-03 07:39:02 +01009#include <linux/io.h>
10#include <linux/clk.h>
11
Per Franssonae694802010-09-08 21:21:40 +053012#include <asm/cacheflush.h>
Rabin Vincent178980f2010-05-03 07:39:02 +010013#include <asm/hardware/cache-l2x0.h>
14#include <asm/hardware/gic.h>
15#include <asm/mach/map.h>
Rabin Vincent41ac3292010-05-03 08:28:05 +010016#include <asm/localtimer.h>
Rabin Vincent178980f2010-05-03 07:39:02 +010017
Rabin Vincent41ac3292010-05-03 08:28:05 +010018#include <plat/mtu.h>
Rabin Vincent178980f2010-05-03 07:39:02 +010019#include <mach/hardware.h>
20#include <mach/setup.h>
Rabin Vincentd48fd002010-05-03 07:46:56 +010021#include <mach/devices.h>
Mattias Wallinfcbd4582010-12-02 16:20:42 +010022#include <mach/prcmu.h>
Rabin Vincent178980f2010-05-03 07:39:02 +010023
24#include "clock.h"
25
Rabin Vincent92389ca2010-12-08 11:07:57 +053026#ifdef CONFIG_CACHE_L2X0
27static void __iomem *l2x0_base;
28#endif
Rabin Vincent178980f2010-05-03 07:39:02 +010029
Rabin Vincent178980f2010-05-03 07:39:02 +010030void __init ux500_init_irq(void)
31{
Rabin Vincent92389ca2010-12-08 11:07:57 +053032 void __iomem *dist_base;
33 void __iomem *cpu_base;
34
35 if (cpu_is_u5500()) {
36 dist_base = __io_address(U5500_GIC_DIST_BASE);
37 cpu_base = __io_address(U5500_GIC_CPU_BASE);
38 } else if (cpu_is_u8500()) {
39 dist_base = __io_address(U8500_GIC_DIST_BASE);
40 cpu_base = __io_address(U8500_GIC_CPU_BASE);
41 } else
42 ux500_unknown_soc();
43
44 gic_init(0, 29, dist_base, cpu_base);
Linus Walleijba327b12010-05-26 07:38:54 +010045
46 /*
47 * Init clocks here so that they are available for system timer
48 * initialization.
49 */
Per Forlin9b04f8b2010-12-05 12:27:05 +010050 if (cpu_is_u8500())
51 prcmu_early_init();
Linus Walleijba327b12010-05-26 07:38:54 +010052 clk_init();
Rabin Vincent178980f2010-05-03 07:39:02 +010053}
54
55#ifdef CONFIG_CACHE_L2X0
Per Franssonae694802010-09-08 21:21:40 +053056static inline void ux500_cache_wait(void __iomem *reg, unsigned long mask)
57{
58 /* wait for the operation to complete */
Per Franssonffc43ef2010-11-15 14:31:17 +010059 while (readl_relaxed(reg) & mask)
Per Franssonae694802010-09-08 21:21:40 +053060 ;
61}
62
63static inline void ux500_cache_sync(void)
64{
Rabin Vincent92389ca2010-12-08 11:07:57 +053065 void __iomem *base = l2x0_base;
66
Per Franssonffc43ef2010-11-15 14:31:17 +010067 writel_relaxed(0, base + L2X0_CACHE_SYNC);
Per Franssonae694802010-09-08 21:21:40 +053068 ux500_cache_wait(base + L2X0_CACHE_SYNC, 1);
69}
70
71/*
72 * The L2 cache cannot be turned off in the non-secure world.
73 * Dummy until a secure service is in place.
74 */
75static void ux500_l2x0_disable(void)
76{
77}
78
79/*
80 * This is only called when doing a kexec, just after turning off the L2
81 * and L1 cache, and it is surrounded by a spinlock in the generic version.
82 * However, we're not really turning off the L2 cache right now and the
83 * PL310 does not support exclusive accesses (used to implement the spinlock).
84 * So, the invalidation needs to be done without the spinlock.
85 */
86static void ux500_l2x0_inv_all(void)
87{
Rabin Vincent92389ca2010-12-08 11:07:57 +053088 void __iomem *base = l2x0_base;
Per Franssonae694802010-09-08 21:21:40 +053089 uint32_t l2x0_way_mask = (1<<16) - 1; /* Bitmask of active ways */
90
91 /* invalidate all ways */
Rabin Vincent92389ca2010-12-08 11:07:57 +053092 writel_relaxed(l2x0_way_mask, base + L2X0_INV_WAY);
93 ux500_cache_wait(base + L2X0_INV_WAY, l2x0_way_mask);
Per Franssonae694802010-09-08 21:21:40 +053094 ux500_cache_sync();
95}
96
Rabin Vincent178980f2010-05-03 07:39:02 +010097static int ux500_l2x0_init(void)
98{
Rabin Vincent92389ca2010-12-08 11:07:57 +053099 if (cpu_is_u5500())
100 l2x0_base = __io_address(U5500_L2CC_BASE);
101 else if (cpu_is_u8500())
102 l2x0_base = __io_address(U8500_L2CC_BASE);
103 else
104 ux500_unknown_soc();
Rabin Vincent178980f2010-05-03 07:39:02 +0100105
106 /* 64KB way size, 8 way associativity, force WA */
107 l2x0_init(l2x0_base, 0x3e060000, 0xc0000fff);
108
Per Franssonae694802010-09-08 21:21:40 +0530109 /* Override invalidate function */
110 outer_cache.disable = ux500_l2x0_disable;
111 outer_cache.inv_all = ux500_l2x0_inv_all;
112
Rabin Vincent178980f2010-05-03 07:39:02 +0100113 return 0;
114}
115early_initcall(ux500_l2x0_init);
116#endif
Rabin Vincent41ac3292010-05-03 08:28:05 +0100117
118static void __init ux500_timer_init(void)
119{
120#ifdef CONFIG_LOCAL_TIMERS
121 /* Setup the local timer base */
Rabin Vincent92389ca2010-12-08 11:07:57 +0530122 if (cpu_is_u5500())
123 twd_base = __io_address(U5500_TWD_BASE);
124 else if (cpu_is_u8500())
125 twd_base = __io_address(U8500_TWD_BASE);
Rabin Vincent41ac3292010-05-03 08:28:05 +0100126 else
Rabin Vincent92389ca2010-12-08 11:07:57 +0530127 ux500_unknown_soc();
128#endif
129 if (cpu_is_u5500())
130 mtu_base = __io_address(U5500_MTU0_BASE);
131 else if (cpu_is_u8500ed())
132 mtu_base = __io_address(U8500_MTU0_BASE_ED);
133 else if (cpu_is_u8500())
134 mtu_base = __io_address(U8500_MTU0_BASE);
135 else
136 ux500_unknown_soc();
Rabin Vincent41ac3292010-05-03 08:28:05 +0100137
138 nmdk_timer_init();
139}
140
141struct sys_timer ux500_timer = {
142 .init = ux500_timer_init,
143};