blob: 0190e0e68b4d11d68a91ef3ca3fcf31783cac9cf [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
Linus Walleij11871892011-03-29 16:53:29 +020026void __iomem *_PRCMU_BASE;
27
Rabin Vincent92389ca2010-12-08 11:07:57 +053028#ifdef CONFIG_CACHE_L2X0
29static void __iomem *l2x0_base;
30#endif
Rabin Vincent178980f2010-05-03 07:39:02 +010031
Rabin Vincent178980f2010-05-03 07:39:02 +010032void __init ux500_init_irq(void)
33{
Rabin Vincent92389ca2010-12-08 11:07:57 +053034 void __iomem *dist_base;
35 void __iomem *cpu_base;
36
37 if (cpu_is_u5500()) {
38 dist_base = __io_address(U5500_GIC_DIST_BASE);
39 cpu_base = __io_address(U5500_GIC_CPU_BASE);
40 } else if (cpu_is_u8500()) {
41 dist_base = __io_address(U8500_GIC_DIST_BASE);
42 cpu_base = __io_address(U8500_GIC_CPU_BASE);
43 } else
44 ux500_unknown_soc();
45
46 gic_init(0, 29, dist_base, cpu_base);
Linus Walleijba327b12010-05-26 07:38:54 +010047
48 /*
49 * Init clocks here so that they are available for system timer
50 * initialization.
51 */
Per Forlin9b04f8b2010-12-05 12:27:05 +010052 if (cpu_is_u8500())
53 prcmu_early_init();
Linus Walleijba327b12010-05-26 07:38:54 +010054 clk_init();
Rabin Vincent178980f2010-05-03 07:39:02 +010055}
56
57#ifdef CONFIG_CACHE_L2X0
Per Franssonae694802010-09-08 21:21:40 +053058static inline void ux500_cache_wait(void __iomem *reg, unsigned long mask)
59{
60 /* wait for the operation to complete */
Per Franssonffc43ef2010-11-15 14:31:17 +010061 while (readl_relaxed(reg) & mask)
Per Franssonae694802010-09-08 21:21:40 +053062 ;
63}
64
65static inline void ux500_cache_sync(void)
66{
Rabin Vincent92389ca2010-12-08 11:07:57 +053067 void __iomem *base = l2x0_base;
68
Per Franssonffc43ef2010-11-15 14:31:17 +010069 writel_relaxed(0, base + L2X0_CACHE_SYNC);
Per Franssonae694802010-09-08 21:21:40 +053070 ux500_cache_wait(base + L2X0_CACHE_SYNC, 1);
71}
72
73/*
74 * The L2 cache cannot be turned off in the non-secure world.
75 * Dummy until a secure service is in place.
76 */
77static void ux500_l2x0_disable(void)
78{
79}
80
81/*
82 * This is only called when doing a kexec, just after turning off the L2
83 * and L1 cache, and it is surrounded by a spinlock in the generic version.
84 * However, we're not really turning off the L2 cache right now and the
85 * PL310 does not support exclusive accesses (used to implement the spinlock).
86 * So, the invalidation needs to be done without the spinlock.
87 */
88static void ux500_l2x0_inv_all(void)
89{
Rabin Vincent92389ca2010-12-08 11:07:57 +053090 void __iomem *base = l2x0_base;
Per Franssonae694802010-09-08 21:21:40 +053091 uint32_t l2x0_way_mask = (1<<16) - 1; /* Bitmask of active ways */
92
93 /* invalidate all ways */
Rabin Vincent92389ca2010-12-08 11:07:57 +053094 writel_relaxed(l2x0_way_mask, base + L2X0_INV_WAY);
95 ux500_cache_wait(base + L2X0_INV_WAY, l2x0_way_mask);
Per Franssonae694802010-09-08 21:21:40 +053096 ux500_cache_sync();
97}
98
Rabin Vincent178980f2010-05-03 07:39:02 +010099static int ux500_l2x0_init(void)
100{
Rabin Vincent92389ca2010-12-08 11:07:57 +0530101 if (cpu_is_u5500())
102 l2x0_base = __io_address(U5500_L2CC_BASE);
103 else if (cpu_is_u8500())
104 l2x0_base = __io_address(U8500_L2CC_BASE);
105 else
106 ux500_unknown_soc();
Rabin Vincent178980f2010-05-03 07:39:02 +0100107
108 /* 64KB way size, 8 way associativity, force WA */
109 l2x0_init(l2x0_base, 0x3e060000, 0xc0000fff);
110
Per Franssonae694802010-09-08 21:21:40 +0530111 /* Override invalidate function */
112 outer_cache.disable = ux500_l2x0_disable;
113 outer_cache.inv_all = ux500_l2x0_inv_all;
114
Rabin Vincent178980f2010-05-03 07:39:02 +0100115 return 0;
116}
117early_initcall(ux500_l2x0_init);
118#endif
Rabin Vincent41ac3292010-05-03 08:28:05 +0100119
120static void __init ux500_timer_init(void)
121{
122#ifdef CONFIG_LOCAL_TIMERS
123 /* Setup the local timer base */
Rabin Vincent92389ca2010-12-08 11:07:57 +0530124 if (cpu_is_u5500())
125 twd_base = __io_address(U5500_TWD_BASE);
126 else if (cpu_is_u8500())
127 twd_base = __io_address(U8500_TWD_BASE);
Rabin Vincent41ac3292010-05-03 08:28:05 +0100128 else
Rabin Vincent92389ca2010-12-08 11:07:57 +0530129 ux500_unknown_soc();
130#endif
131 if (cpu_is_u5500())
132 mtu_base = __io_address(U5500_MTU0_BASE);
133 else if (cpu_is_u8500ed())
134 mtu_base = __io_address(U8500_MTU0_BASE_ED);
135 else if (cpu_is_u8500())
136 mtu_base = __io_address(U8500_MTU0_BASE);
137 else
138 ux500_unknown_soc();
Rabin Vincent41ac3292010-05-03 08:28:05 +0100139
140 nmdk_timer_init();
141}
142
143struct sys_timer ux500_timer = {
144 .init = ux500_timer_init,
145};