Rabin Vincent | 178980f | 2010-05-03 07:39:02 +0100 | [diff] [blame] | 1 | /* |
| 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 Vincent | 178980f | 2010-05-03 07:39:02 +0100 | [diff] [blame] | 9 | #include <linux/io.h> |
| 10 | #include <linux/clk.h> |
Linus Walleij | 650c2a2 | 2011-05-15 22:53:56 +0200 | [diff] [blame] | 11 | #include <linux/mfd/db8500-prcmu.h> |
Linus Walleij | 8317797 | 2011-05-03 18:14:48 +0200 | [diff] [blame] | 12 | #include <linux/mfd/db5500-prcmu.h> |
Rabin Vincent | 178980f | 2010-05-03 07:39:02 +0100 | [diff] [blame] | 13 | |
Per Fransson | ae69480 | 2010-09-08 21:21:40 +0530 | [diff] [blame] | 14 | #include <asm/cacheflush.h> |
Rabin Vincent | 178980f | 2010-05-03 07:39:02 +0100 | [diff] [blame] | 15 | #include <asm/hardware/cache-l2x0.h> |
| 16 | #include <asm/hardware/gic.h> |
| 17 | #include <asm/mach/map.h> |
Rabin Vincent | 41ac329 | 2010-05-03 08:28:05 +0100 | [diff] [blame] | 18 | #include <asm/localtimer.h> |
Rabin Vincent | 178980f | 2010-05-03 07:39:02 +0100 | [diff] [blame] | 19 | |
Rabin Vincent | 41ac329 | 2010-05-03 08:28:05 +0100 | [diff] [blame] | 20 | #include <plat/mtu.h> |
Rabin Vincent | 178980f | 2010-05-03 07:39:02 +0100 | [diff] [blame] | 21 | #include <mach/hardware.h> |
| 22 | #include <mach/setup.h> |
Rabin Vincent | d48fd00 | 2010-05-03 07:46:56 +0100 | [diff] [blame] | 23 | #include <mach/devices.h> |
Rabin Vincent | 178980f | 2010-05-03 07:39:02 +0100 | [diff] [blame] | 24 | |
| 25 | #include "clock.h" |
| 26 | |
Linus Walleij | 1187189 | 2011-03-29 16:53:29 +0200 | [diff] [blame] | 27 | void __iomem *_PRCMU_BASE; |
| 28 | |
Rabin Vincent | 92389ca | 2010-12-08 11:07:57 +0530 | [diff] [blame] | 29 | #ifdef CONFIG_CACHE_L2X0 |
| 30 | static void __iomem *l2x0_base; |
| 31 | #endif |
Rabin Vincent | 178980f | 2010-05-03 07:39:02 +0100 | [diff] [blame] | 32 | |
Rabin Vincent | 178980f | 2010-05-03 07:39:02 +0100 | [diff] [blame] | 33 | void __init ux500_init_irq(void) |
| 34 | { |
Rabin Vincent | 92389ca | 2010-12-08 11:07:57 +0530 | [diff] [blame] | 35 | void __iomem *dist_base; |
| 36 | void __iomem *cpu_base; |
| 37 | |
| 38 | if (cpu_is_u5500()) { |
| 39 | dist_base = __io_address(U5500_GIC_DIST_BASE); |
| 40 | cpu_base = __io_address(U5500_GIC_CPU_BASE); |
| 41 | } else if (cpu_is_u8500()) { |
| 42 | dist_base = __io_address(U8500_GIC_DIST_BASE); |
| 43 | cpu_base = __io_address(U8500_GIC_CPU_BASE); |
| 44 | } else |
| 45 | ux500_unknown_soc(); |
| 46 | |
| 47 | gic_init(0, 29, dist_base, cpu_base); |
Linus Walleij | ba327b1 | 2010-05-26 07:38:54 +0100 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * Init clocks here so that they are available for system timer |
| 51 | * initialization. |
| 52 | */ |
Linus Walleij | 8317797 | 2011-05-03 18:14:48 +0200 | [diff] [blame] | 53 | if (cpu_is_u5500()) |
| 54 | db5500_prcmu_early_init(); |
Per Forlin | 9b04f8b | 2010-12-05 12:27:05 +0100 | [diff] [blame] | 55 | if (cpu_is_u8500()) |
| 56 | prcmu_early_init(); |
Linus Walleij | ba327b1 | 2010-05-26 07:38:54 +0100 | [diff] [blame] | 57 | clk_init(); |
Rabin Vincent | 178980f | 2010-05-03 07:39:02 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | #ifdef CONFIG_CACHE_L2X0 |
Per Fransson | ae69480 | 2010-09-08 21:21:40 +0530 | [diff] [blame] | 61 | static inline void ux500_cache_wait(void __iomem *reg, unsigned long mask) |
| 62 | { |
| 63 | /* wait for the operation to complete */ |
Per Fransson | ffc43ef | 2010-11-15 14:31:17 +0100 | [diff] [blame] | 64 | while (readl_relaxed(reg) & mask) |
Per Fransson | ae69480 | 2010-09-08 21:21:40 +0530 | [diff] [blame] | 65 | ; |
| 66 | } |
| 67 | |
| 68 | static inline void ux500_cache_sync(void) |
| 69 | { |
Rabin Vincent | 92389ca | 2010-12-08 11:07:57 +0530 | [diff] [blame] | 70 | void __iomem *base = l2x0_base; |
| 71 | |
Per Fransson | ffc43ef | 2010-11-15 14:31:17 +0100 | [diff] [blame] | 72 | writel_relaxed(0, base + L2X0_CACHE_SYNC); |
Per Fransson | ae69480 | 2010-09-08 21:21:40 +0530 | [diff] [blame] | 73 | ux500_cache_wait(base + L2X0_CACHE_SYNC, 1); |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * The L2 cache cannot be turned off in the non-secure world. |
| 78 | * Dummy until a secure service is in place. |
| 79 | */ |
| 80 | static void ux500_l2x0_disable(void) |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | * This is only called when doing a kexec, just after turning off the L2 |
| 86 | * and L1 cache, and it is surrounded by a spinlock in the generic version. |
| 87 | * However, we're not really turning off the L2 cache right now and the |
| 88 | * PL310 does not support exclusive accesses (used to implement the spinlock). |
| 89 | * So, the invalidation needs to be done without the spinlock. |
| 90 | */ |
| 91 | static void ux500_l2x0_inv_all(void) |
| 92 | { |
Rabin Vincent | 92389ca | 2010-12-08 11:07:57 +0530 | [diff] [blame] | 93 | void __iomem *base = l2x0_base; |
Per Fransson | ae69480 | 2010-09-08 21:21:40 +0530 | [diff] [blame] | 94 | uint32_t l2x0_way_mask = (1<<16) - 1; /* Bitmask of active ways */ |
| 95 | |
| 96 | /* invalidate all ways */ |
Rabin Vincent | 92389ca | 2010-12-08 11:07:57 +0530 | [diff] [blame] | 97 | writel_relaxed(l2x0_way_mask, base + L2X0_INV_WAY); |
| 98 | ux500_cache_wait(base + L2X0_INV_WAY, l2x0_way_mask); |
Per Fransson | ae69480 | 2010-09-08 21:21:40 +0530 | [diff] [blame] | 99 | ux500_cache_sync(); |
| 100 | } |
| 101 | |
Linus Walleij | ad41704 | 2011-08-12 13:54:42 +0200 | [diff] [blame] | 102 | static int __init ux500_l2x0_unlock(void) |
| 103 | { |
| 104 | int i; |
| 105 | |
| 106 | /* |
| 107 | * Unlock Data and Instruction Lock if locked. Ux500 U-Boot versions |
| 108 | * apparently locks both caches before jumping to the kernel. The |
| 109 | * l2x0 core will not touch the unlock registers if the l2x0 is |
| 110 | * already enabled, so we do it right here instead. The PL310 has |
| 111 | * 8 sets of registers, one per possible CPU. |
| 112 | */ |
| 113 | for (i = 0; i < 8; i++) { |
| 114 | writel_relaxed(0x0, l2x0_base + L2X0_LOCKDOWN_WAY_D_BASE + |
| 115 | i * L2X0_LOCKDOWN_STRIDE); |
| 116 | writel_relaxed(0x0, l2x0_base + L2X0_LOCKDOWN_WAY_I_BASE + |
| 117 | i * L2X0_LOCKDOWN_STRIDE); |
| 118 | } |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | static int __init ux500_l2x0_init(void) |
Rabin Vincent | 178980f | 2010-05-03 07:39:02 +0100 | [diff] [blame] | 123 | { |
Rabin Vincent | 92389ca | 2010-12-08 11:07:57 +0530 | [diff] [blame] | 124 | if (cpu_is_u5500()) |
| 125 | l2x0_base = __io_address(U5500_L2CC_BASE); |
| 126 | else if (cpu_is_u8500()) |
| 127 | l2x0_base = __io_address(U8500_L2CC_BASE); |
| 128 | else |
| 129 | ux500_unknown_soc(); |
Rabin Vincent | 178980f | 2010-05-03 07:39:02 +0100 | [diff] [blame] | 130 | |
Linus Walleij | ad41704 | 2011-08-12 13:54:42 +0200 | [diff] [blame] | 131 | /* Unlock before init */ |
| 132 | ux500_l2x0_unlock(); |
| 133 | |
Rabin Vincent | 178980f | 2010-05-03 07:39:02 +0100 | [diff] [blame] | 134 | /* 64KB way size, 8 way associativity, force WA */ |
| 135 | l2x0_init(l2x0_base, 0x3e060000, 0xc0000fff); |
| 136 | |
Per Fransson | ae69480 | 2010-09-08 21:21:40 +0530 | [diff] [blame] | 137 | /* Override invalidate function */ |
| 138 | outer_cache.disable = ux500_l2x0_disable; |
| 139 | outer_cache.inv_all = ux500_l2x0_inv_all; |
| 140 | |
Rabin Vincent | 178980f | 2010-05-03 07:39:02 +0100 | [diff] [blame] | 141 | return 0; |
| 142 | } |
| 143 | early_initcall(ux500_l2x0_init); |
| 144 | #endif |
Rabin Vincent | 41ac329 | 2010-05-03 08:28:05 +0100 | [diff] [blame] | 145 | |
| 146 | static void __init ux500_timer_init(void) |
| 147 | { |
| 148 | #ifdef CONFIG_LOCAL_TIMERS |
| 149 | /* Setup the local timer base */ |
Rabin Vincent | 92389ca | 2010-12-08 11:07:57 +0530 | [diff] [blame] | 150 | if (cpu_is_u5500()) |
| 151 | twd_base = __io_address(U5500_TWD_BASE); |
| 152 | else if (cpu_is_u8500()) |
| 153 | twd_base = __io_address(U8500_TWD_BASE); |
Rabin Vincent | 41ac329 | 2010-05-03 08:28:05 +0100 | [diff] [blame] | 154 | else |
Rabin Vincent | 92389ca | 2010-12-08 11:07:57 +0530 | [diff] [blame] | 155 | ux500_unknown_soc(); |
| 156 | #endif |
| 157 | if (cpu_is_u5500()) |
| 158 | mtu_base = __io_address(U5500_MTU0_BASE); |
| 159 | else if (cpu_is_u8500ed()) |
| 160 | mtu_base = __io_address(U8500_MTU0_BASE_ED); |
| 161 | else if (cpu_is_u8500()) |
| 162 | mtu_base = __io_address(U8500_MTU0_BASE); |
| 163 | else |
| 164 | ux500_unknown_soc(); |
Rabin Vincent | 41ac329 | 2010-05-03 08:28:05 +0100 | [diff] [blame] | 165 | |
| 166 | nmdk_timer_init(); |
| 167 | } |
| 168 | |
| 169 | struct sys_timer ux500_timer = { |
| 170 | .init = ux500_timer_init, |
| 171 | }; |