Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * OMAP4 specific common source file. |
| 3 | * |
| 4 | * Copyright (C) 2010 Texas Instruments, Inc. |
| 5 | * Author: |
| 6 | * Santosh Shilimkar <santosh.shilimkar@ti.com> |
| 7 | * |
| 8 | * |
| 9 | * This program is free software,you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/platform_device.h> |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 18 | #include <linux/memblock.h> |
Tony Lindgren | 7d7e1eb | 2012-08-27 17:43:01 -0700 | [diff] [blame] | 19 | #include <linux/of_irq.h> |
| 20 | #include <linux/of_platform.h> |
| 21 | #include <linux/export.h> |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 22 | |
| 23 | #include <asm/hardware/gic.h> |
| 24 | #include <asm/hardware/cache-l2x0.h> |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 25 | #include <asm/mach/map.h> |
Russell King | 716a3dc | 2012-01-13 15:00:51 +0000 | [diff] [blame] | 26 | #include <asm/memblock.h> |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 27 | |
Tony Lindgren | 622297f | 2012-10-02 14:19:52 -0700 | [diff] [blame] | 28 | #include "../plat-omap/sram.h" |
Tony Lindgren | 4e65331 | 2011-11-10 22:45:17 +0100 | [diff] [blame] | 29 | |
Tony Lindgren | 622297f | 2012-10-02 14:19:52 -0700 | [diff] [blame] | 30 | #include "omap-wakeupgen.h" |
Tony Lindgren | dbc0416 | 2012-08-31 10:59:07 -0700 | [diff] [blame] | 31 | #include "soc.h" |
Tony Lindgren | 4e65331 | 2011-11-10 22:45:17 +0100 | [diff] [blame] | 32 | #include "common.h" |
Tony Lindgren | 68f39e7 | 2012-10-15 12:09:43 -0700 | [diff] [blame] | 33 | #include "mmc.h" |
Balaji T K | 1ee47b0 | 2012-04-25 17:27:46 +0530 | [diff] [blame] | 34 | #include "hsmmc.h" |
Santosh Shilimkar | 501f0c7 | 2011-01-01 19:56:04 +0530 | [diff] [blame] | 35 | #include "omap4-sar-layout.h" |
Lokesh Vutla | f7a9b8a | 2012-10-02 00:17:06 +0530 | [diff] [blame^] | 36 | #include "omap-secure.h" |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 37 | |
| 38 | #ifdef CONFIG_CACHE_L2X0 |
Santosh Shilimkar | 02afe8a | 2011-03-03 18:03:25 +0530 | [diff] [blame] | 39 | static void __iomem *l2cache_base; |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 40 | #endif |
| 41 | |
Santosh Shilimkar | 501f0c7 | 2011-01-01 19:56:04 +0530 | [diff] [blame] | 42 | static void __iomem *sar_ram_base; |
| 43 | |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 44 | #ifdef CONFIG_OMAP4_ERRATA_I688 |
| 45 | /* Used to implement memory barrier on DRAM path */ |
| 46 | #define OMAP4_DRAM_BARRIER_VA 0xfe600000 |
| 47 | |
| 48 | void __iomem *dram_sync, *sram_sync; |
| 49 | |
Santosh Shilimkar | 2ec1fc4 | 2012-02-02 19:33:55 +0530 | [diff] [blame] | 50 | static phys_addr_t paddr; |
| 51 | static u32 size; |
| 52 | |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 53 | void omap_bus_sync(void) |
| 54 | { |
| 55 | if (dram_sync && sram_sync) { |
| 56 | writel_relaxed(readl_relaxed(dram_sync), dram_sync); |
| 57 | writel_relaxed(readl_relaxed(sram_sync), sram_sync); |
| 58 | isb(); |
| 59 | } |
| 60 | } |
R Sricharan | cc4ad90 | 2012-03-02 16:31:18 +0530 | [diff] [blame] | 61 | EXPORT_SYMBOL(omap_bus_sync); |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 62 | |
Santosh Shilimkar | 2ec1fc4 | 2012-02-02 19:33:55 +0530 | [diff] [blame] | 63 | /* Steal one page physical memory for barrier implementation */ |
| 64 | int __init omap_barrier_reserve_memblock(void) |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 65 | { |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 66 | |
| 67 | size = ALIGN(PAGE_SIZE, SZ_1M); |
Russell King | 716a3dc | 2012-01-13 15:00:51 +0000 | [diff] [blame] | 68 | paddr = arm_memblock_steal(size, SZ_1M); |
| 69 | |
Santosh Shilimkar | 2ec1fc4 | 2012-02-02 19:33:55 +0530 | [diff] [blame] | 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | void __init omap_barriers_init(void) |
| 74 | { |
| 75 | struct map_desc dram_io_desc[1]; |
| 76 | |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 77 | dram_io_desc[0].virtual = OMAP4_DRAM_BARRIER_VA; |
| 78 | dram_io_desc[0].pfn = __phys_to_pfn(paddr); |
| 79 | dram_io_desc[0].length = size; |
| 80 | dram_io_desc[0].type = MT_MEMORY_SO; |
| 81 | iotable_init(dram_io_desc, ARRAY_SIZE(dram_io_desc)); |
| 82 | dram_sync = (void __iomem *) dram_io_desc[0].virtual; |
| 83 | sram_sync = (void __iomem *) OMAP4_SRAM_VA; |
| 84 | |
| 85 | pr_info("OMAP4: Map 0x%08llx to 0x%08lx for dram barrier\n", |
| 86 | (long long) paddr, dram_io_desc[0].virtual); |
| 87 | |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 88 | } |
Santosh Shilimkar | 2ec1fc4 | 2012-02-02 19:33:55 +0530 | [diff] [blame] | 89 | #else |
| 90 | void __init omap_barriers_init(void) |
| 91 | {} |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 92 | #endif |
| 93 | |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 94 | void __init gic_init_irq(void) |
| 95 | { |
Marc Zyngier | ab65be2 | 2011-11-15 17:22:45 +0000 | [diff] [blame] | 96 | void __iomem *omap_irq_base; |
| 97 | void __iomem *gic_dist_base_addr; |
| 98 | |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 99 | /* Static mapping, never released */ |
| 100 | gic_dist_base_addr = ioremap(OMAP44XX_GIC_DIST_BASE, SZ_4K); |
| 101 | BUG_ON(!gic_dist_base_addr); |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 102 | |
| 103 | /* Static mapping, never released */ |
Tony Lindgren | 741e3a8 | 2011-05-17 03:51:26 -0700 | [diff] [blame] | 104 | omap_irq_base = ioremap(OMAP44XX_GIC_CPU_BASE, SZ_512); |
| 105 | BUG_ON(!omap_irq_base); |
Russell King | b580b89 | 2010-12-04 15:55:14 +0000 | [diff] [blame] | 106 | |
Santosh Shilimkar | fcf6efa | 2010-06-16 22:19:47 +0530 | [diff] [blame] | 107 | omap_wakeupgen_init(); |
| 108 | |
Tony Lindgren | 741e3a8 | 2011-05-17 03:51:26 -0700 | [diff] [blame] | 109 | gic_init(0, 29, gic_dist_base_addr, omap_irq_base); |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | #ifdef CONFIG_CACHE_L2X0 |
Santosh Shilimkar | 4e803c4 | 2010-07-31 21:40:10 +0530 | [diff] [blame] | 113 | |
Santosh Shilimkar | 02afe8a | 2011-03-03 18:03:25 +0530 | [diff] [blame] | 114 | void __iomem *omap4_get_l2cache_base(void) |
| 115 | { |
| 116 | return l2cache_base; |
| 117 | } |
| 118 | |
Santosh Shilimkar | 4e803c4 | 2010-07-31 21:40:10 +0530 | [diff] [blame] | 119 | static void omap4_l2x0_disable(void) |
| 120 | { |
| 121 | /* Disable PL310 L2 Cache controller */ |
| 122 | omap_smc1(0x102, 0x0); |
| 123 | } |
| 124 | |
Santosh Shilimkar | 4bdb157 | 2011-02-22 10:00:44 +0100 | [diff] [blame] | 125 | static void omap4_l2x0_set_debug(unsigned long val) |
| 126 | { |
| 127 | /* Program PL310 L2 Cache controller debug register */ |
| 128 | omap_smc1(0x100, val); |
| 129 | } |
| 130 | |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 131 | static int __init omap_l2_cache_init(void) |
| 132 | { |
Santosh Shilimkar | 1773e60 | 2010-11-19 23:01:03 +0530 | [diff] [blame] | 133 | u32 aux_ctrl = 0; |
| 134 | |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 135 | /* |
| 136 | * To avoid code running on other OMAPs in |
| 137 | * multi-omap builds |
| 138 | */ |
| 139 | if (!cpu_is_omap44xx()) |
| 140 | return -ENODEV; |
| 141 | |
| 142 | /* Static mapping, never released */ |
| 143 | l2cache_base = ioremap(OMAP44XX_L2CACHE_BASE, SZ_4K); |
Santosh Shilimkar | 0db1803 | 2011-03-03 17:36:52 +0530 | [diff] [blame] | 144 | if (WARN_ON(!l2cache_base)) |
| 145 | return -ENOMEM; |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 146 | |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 147 | /* |
Santosh Shilimkar | a777b72 | 2010-09-16 18:44:47 +0530 | [diff] [blame] | 148 | * 16-way associativity, parity disabled |
| 149 | * Way size - 32KB (es1.0) |
| 150 | * Way size - 64KB (es2.0 +) |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 151 | */ |
Santosh Shilimkar | 1773e60 | 2010-11-19 23:01:03 +0530 | [diff] [blame] | 152 | aux_ctrl = ((1 << L2X0_AUX_CTRL_ASSOCIATIVITY_SHIFT) | |
| 153 | (0x1 << 25) | |
| 154 | (0x1 << L2X0_AUX_CTRL_NS_LOCKDOWN_SHIFT) | |
| 155 | (0x1 << L2X0_AUX_CTRL_NS_INT_CTRL_SHIFT)); |
| 156 | |
Mans Rullgard | 11e0264 | 2010-11-19 23:01:04 +0530 | [diff] [blame] | 157 | if (omap_rev() == OMAP4430_REV_ES1_0) { |
Santosh Shilimkar | 1773e60 | 2010-11-19 23:01:03 +0530 | [diff] [blame] | 158 | aux_ctrl |= 0x2 << L2X0_AUX_CTRL_WAY_SIZE_SHIFT; |
Mans Rullgard | 11e0264 | 2010-11-19 23:01:04 +0530 | [diff] [blame] | 159 | } else { |
| 160 | aux_ctrl |= ((0x3 << L2X0_AUX_CTRL_WAY_SIZE_SHIFT) | |
Santosh Shilimkar | b0f20ff | 2010-11-19 23:01:05 +0530 | [diff] [blame] | 161 | (1 << L2X0_AUX_CTRL_SHARE_OVERRIDE_SHIFT) | |
Mans Rullgard | 11e0264 | 2010-11-19 23:01:04 +0530 | [diff] [blame] | 162 | (1 << L2X0_AUX_CTRL_DATA_PREFETCH_SHIFT) | |
Santosh Shilimkar | b89cd71 | 2010-11-19 23:01:06 +0530 | [diff] [blame] | 163 | (1 << L2X0_AUX_CTRL_INSTR_PREFETCH_SHIFT) | |
| 164 | (1 << L2X0_AUX_CTRL_EARLY_BRESP_SHIFT)); |
Mans Rullgard | 11e0264 | 2010-11-19 23:01:04 +0530 | [diff] [blame] | 165 | } |
| 166 | if (omap_rev() != OMAP4430_REV_ES1_0) |
| 167 | omap_smc1(0x109, aux_ctrl); |
| 168 | |
| 169 | /* Enable PL310 L2 Cache controller */ |
| 170 | omap_smc1(0x102, 0x1); |
Santosh Shilimkar | 1773e60 | 2010-11-19 23:01:03 +0530 | [diff] [blame] | 171 | |
Santosh Shilimkar | 926fd45 | 2012-07-04 17:57:34 +0530 | [diff] [blame] | 172 | if (of_have_populated_dt()) |
| 173 | l2x0_of_init(aux_ctrl, L2X0_AUX_CTRL_MASK); |
| 174 | else |
| 175 | l2x0_init(l2cache_base, aux_ctrl, L2X0_AUX_CTRL_MASK); |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 176 | |
Santosh Shilimkar | 4e803c4 | 2010-07-31 21:40:10 +0530 | [diff] [blame] | 177 | /* |
| 178 | * Override default outer_cache.disable with a OMAP4 |
| 179 | * specific one |
| 180 | */ |
| 181 | outer_cache.disable = omap4_l2x0_disable; |
Santosh Shilimkar | 4bdb157 | 2011-02-22 10:00:44 +0100 | [diff] [blame] | 182 | outer_cache.set_debug = omap4_l2x0_set_debug; |
Santosh Shilimkar | 4e803c4 | 2010-07-31 21:40:10 +0530 | [diff] [blame] | 183 | |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 184 | return 0; |
| 185 | } |
| 186 | early_initcall(omap_l2_cache_init); |
| 187 | #endif |
Santosh Shilimkar | 501f0c7 | 2011-01-01 19:56:04 +0530 | [diff] [blame] | 188 | |
| 189 | void __iomem *omap4_get_sar_ram_base(void) |
| 190 | { |
| 191 | return sar_ram_base; |
| 192 | } |
| 193 | |
| 194 | /* |
| 195 | * SAR RAM used to save and restore the HW |
| 196 | * context in low power modes |
| 197 | */ |
| 198 | static int __init omap4_sar_ram_init(void) |
| 199 | { |
| 200 | /* |
| 201 | * To avoid code running on other OMAPs in |
| 202 | * multi-omap builds |
| 203 | */ |
| 204 | if (!cpu_is_omap44xx()) |
| 205 | return -ENOMEM; |
| 206 | |
| 207 | /* Static mapping, never released */ |
| 208 | sar_ram_base = ioremap(OMAP44XX_SAR_RAM_BASE, SZ_16K); |
| 209 | if (WARN_ON(!sar_ram_base)) |
| 210 | return -ENOMEM; |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | early_initcall(omap4_sar_ram_init); |
Balaji T K | 1ee47b0 | 2012-04-25 17:27:46 +0530 | [diff] [blame] | 215 | |
R Sricharan | c4082d4 | 2012-06-05 16:31:06 +0530 | [diff] [blame] | 216 | static struct of_device_id irq_match[] __initdata = { |
| 217 | { .compatible = "arm,cortex-a9-gic", .data = gic_of_init, }, |
R Sricharan | 0c1b6fa | 2012-05-09 23:34:56 +0530 | [diff] [blame] | 218 | { .compatible = "arm,cortex-a15-gic", .data = gic_of_init, }, |
R Sricharan | c4082d4 | 2012-06-05 16:31:06 +0530 | [diff] [blame] | 219 | { } |
| 220 | }; |
| 221 | |
| 222 | void __init omap_gic_of_init(void) |
| 223 | { |
| 224 | omap_wakeupgen_init(); |
| 225 | of_irq_init(irq_match); |
| 226 | } |
| 227 | |
Balaji T K | 1ee47b0 | 2012-04-25 17:27:46 +0530 | [diff] [blame] | 228 | #if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE) |
| 229 | static int omap4_twl6030_hsmmc_late_init(struct device *dev) |
| 230 | { |
| 231 | int irq = 0; |
| 232 | struct platform_device *pdev = container_of(dev, |
| 233 | struct platform_device, dev); |
| 234 | struct omap_mmc_platform_data *pdata = dev->platform_data; |
| 235 | |
| 236 | /* Setting MMC1 Card detect Irq */ |
| 237 | if (pdev->id == 0) { |
| 238 | irq = twl6030_mmc_card_detect_config(); |
| 239 | if (irq < 0) { |
| 240 | dev_err(dev, "%s: Error card detect config(%d)\n", |
| 241 | __func__, irq); |
| 242 | return irq; |
| 243 | } |
| 244 | pdata->slots[0].card_detect_irq = irq; |
| 245 | pdata->slots[0].card_detect = twl6030_mmc_card_detect; |
| 246 | } |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | static __init void omap4_twl6030_hsmmc_set_late_init(struct device *dev) |
| 251 | { |
| 252 | struct omap_mmc_platform_data *pdata; |
| 253 | |
| 254 | /* dev can be null if CONFIG_MMC_OMAP_HS is not set */ |
| 255 | if (!dev) { |
| 256 | pr_err("Failed %s\n", __func__); |
| 257 | return; |
| 258 | } |
| 259 | pdata = dev->platform_data; |
| 260 | pdata->init = omap4_twl6030_hsmmc_late_init; |
| 261 | } |
| 262 | |
| 263 | int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers) |
| 264 | { |
| 265 | struct omap2_hsmmc_info *c; |
| 266 | |
| 267 | omap_hsmmc_init(controllers); |
| 268 | for (c = controllers; c->mmc; c++) { |
| 269 | /* pdev can be null if CONFIG_MMC_OMAP_HS is not set */ |
| 270 | if (!c->pdev) |
| 271 | continue; |
| 272 | omap4_twl6030_hsmmc_set_late_init(&c->pdev->dev); |
| 273 | } |
| 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | #else |
| 278 | int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers) |
| 279 | { |
| 280 | return 0; |
| 281 | } |
| 282 | #endif |