omap4-common.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/io.h>
  16. #include <linux/irq.h>
  17. #include <linux/irqchip.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/memblock.h>
  20. #include <linux/of_irq.h>
  21. #include <linux/of_platform.h>
  22. #include <linux/export.h>
  23. #include <linux/irqchip/arm-gic.h>
  24. #include <linux/irqchip/irq-crossbar.h>
  25. #include <linux/of_address.h>
  26. #include <linux/reboot.h>
  27. #include <linux/genalloc.h>
  28. #include <asm/hardware/cache-l2x0.h>
  29. #include <asm/mach/map.h>
  30. #include <asm/memblock.h>
  31. #include <asm/smp_twd.h>
  32. #include "omap-wakeupgen.h"
  33. #include "soc.h"
  34. #include "iomap.h"
  35. #include "common.h"
  36. #include "prminst44xx.h"
  37. #include "prcm_mpu44xx.h"
  38. #include "omap4-sar-layout.h"
  39. #include "omap-secure.h"
  40. #include "sram.h"
  41. #ifdef CONFIG_CACHE_L2X0
  42. static void __iomem *l2cache_base;
  43. #endif
  44. static void __iomem *sar_ram_base;
  45. static void __iomem *gic_dist_base_addr;
  46. static void __iomem *twd_base;
  47. #define IRQ_LOCALTIMER 29
  48. #ifdef CONFIG_OMAP4_ERRATA_I688
  49. /* Used to implement memory barrier on DRAM path */
  50. #define OMAP4_DRAM_BARRIER_VA 0xfe600000
  51. void __iomem *dram_sync, *sram_sync;
  52. static phys_addr_t paddr;
  53. static u32 size;
  54. void omap_bus_sync(void)
  55. {
  56. if (dram_sync && sram_sync) {
  57. writel_relaxed(readl_relaxed(dram_sync), dram_sync);
  58. writel_relaxed(readl_relaxed(sram_sync), sram_sync);
  59. isb();
  60. }
  61. }
  62. EXPORT_SYMBOL(omap_bus_sync);
  63. static int __init omap4_sram_init(void)
  64. {
  65. struct device_node *np;
  66. struct gen_pool *sram_pool;
  67. np = of_find_compatible_node(NULL, NULL, "ti,omap4-mpu");
  68. if (!np)
  69. pr_warn("%s:Unable to allocate sram needed to handle errata I688\n",
  70. __func__);
  71. sram_pool = of_get_named_gen_pool(np, "sram", 0);
  72. if (!sram_pool)
  73. pr_warn("%s:Unable to get sram pool needed to handle errata I688\n",
  74. __func__);
  75. else
  76. sram_sync = (void *)gen_pool_alloc(sram_pool, PAGE_SIZE);
  77. return 0;
  78. }
  79. omap_arch_initcall(omap4_sram_init);
  80. /* Steal one page physical memory for barrier implementation */
  81. int __init omap_barrier_reserve_memblock(void)
  82. {
  83. size = ALIGN(PAGE_SIZE, SZ_1M);
  84. paddr = arm_memblock_steal(size, SZ_1M);
  85. return 0;
  86. }
  87. void __init omap_barriers_init(void)
  88. {
  89. struct map_desc dram_io_desc[1];
  90. dram_io_desc[0].virtual = OMAP4_DRAM_BARRIER_VA;
  91. dram_io_desc[0].pfn = __phys_to_pfn(paddr);
  92. dram_io_desc[0].length = size;
  93. dram_io_desc[0].type = MT_MEMORY_RW_SO;
  94. iotable_init(dram_io_desc, ARRAY_SIZE(dram_io_desc));
  95. dram_sync = (void __iomem *) dram_io_desc[0].virtual;
  96. pr_info("OMAP4: Map 0x%08llx to 0x%08lx for dram barrier\n",
  97. (long long) paddr, dram_io_desc[0].virtual);
  98. }
  99. #else
  100. void __init omap_barriers_init(void)
  101. {}
  102. #endif
  103. void gic_dist_disable(void)
  104. {
  105. if (gic_dist_base_addr)
  106. writel_relaxed(0x0, gic_dist_base_addr + GIC_DIST_CTRL);
  107. }
  108. void gic_dist_enable(void)
  109. {
  110. if (gic_dist_base_addr)
  111. writel_relaxed(0x1, gic_dist_base_addr + GIC_DIST_CTRL);
  112. }
  113. bool gic_dist_disabled(void)
  114. {
  115. return !(readl_relaxed(gic_dist_base_addr + GIC_DIST_CTRL) & 0x1);
  116. }
  117. void gic_timer_retrigger(void)
  118. {
  119. u32 twd_int = readl_relaxed(twd_base + TWD_TIMER_INTSTAT);
  120. u32 gic_int = readl_relaxed(gic_dist_base_addr + GIC_DIST_PENDING_SET);
  121. u32 twd_ctrl = readl_relaxed(twd_base + TWD_TIMER_CONTROL);
  122. if (twd_int && !(gic_int & BIT(IRQ_LOCALTIMER))) {
  123. /*
  124. * The local timer interrupt got lost while the distributor was
  125. * disabled. Ack the pending interrupt, and retrigger it.
  126. */
  127. pr_warn("%s: lost localtimer interrupt\n", __func__);
  128. writel_relaxed(1, twd_base + TWD_TIMER_INTSTAT);
  129. if (!(twd_ctrl & TWD_TIMER_CONTROL_PERIODIC)) {
  130. writel_relaxed(1, twd_base + TWD_TIMER_COUNTER);
  131. twd_ctrl |= TWD_TIMER_CONTROL_ENABLE;
  132. writel_relaxed(twd_ctrl, twd_base + TWD_TIMER_CONTROL);
  133. }
  134. }
  135. }
  136. #ifdef CONFIG_CACHE_L2X0
  137. void __iomem *omap4_get_l2cache_base(void)
  138. {
  139. return l2cache_base;
  140. }
  141. static void omap4_l2c310_write_sec(unsigned long val, unsigned reg)
  142. {
  143. unsigned smc_op;
  144. switch (reg) {
  145. case L2X0_CTRL:
  146. smc_op = OMAP4_MON_L2X0_CTRL_INDEX;
  147. break;
  148. case L2X0_AUX_CTRL:
  149. smc_op = OMAP4_MON_L2X0_AUXCTRL_INDEX;
  150. break;
  151. case L2X0_DEBUG_CTRL:
  152. smc_op = OMAP4_MON_L2X0_DBG_CTRL_INDEX;
  153. break;
  154. case L310_PREFETCH_CTRL:
  155. smc_op = OMAP4_MON_L2X0_PREFETCH_INDEX;
  156. break;
  157. case L310_POWER_CTRL:
  158. pr_info_once("OMAP L2C310: ROM does not support power control setting\n");
  159. return;
  160. default:
  161. WARN_ONCE(1, "OMAP L2C310: ignoring write to reg 0x%x\n", reg);
  162. return;
  163. }
  164. omap_smc1(smc_op, val);
  165. }
  166. int __init omap_l2_cache_init(void)
  167. {
  168. u32 aux_ctrl;
  169. /* Static mapping, never released */
  170. l2cache_base = ioremap(OMAP44XX_L2CACHE_BASE, SZ_4K);
  171. if (WARN_ON(!l2cache_base))
  172. return -ENOMEM;
  173. /* 16-way associativity, parity disabled, way size - 64KB (es2.0 +) */
  174. aux_ctrl = L2C_AUX_CTRL_SHARED_OVERRIDE |
  175. L310_AUX_CTRL_DATA_PREFETCH |
  176. L310_AUX_CTRL_INSTR_PREFETCH;
  177. outer_cache.write_sec = omap4_l2c310_write_sec;
  178. if (of_have_populated_dt())
  179. l2x0_of_init(aux_ctrl, 0xcf9fffff);
  180. else
  181. l2x0_init(l2cache_base, aux_ctrl, 0xcf9fffff);
  182. return 0;
  183. }
  184. #endif
  185. void __iomem *omap4_get_sar_ram_base(void)
  186. {
  187. return sar_ram_base;
  188. }
  189. /*
  190. * SAR RAM used to save and restore the HW
  191. * context in low power modes
  192. */
  193. static int __init omap4_sar_ram_init(void)
  194. {
  195. unsigned long sar_base;
  196. /*
  197. * To avoid code running on other OMAPs in
  198. * multi-omap builds
  199. */
  200. if (cpu_is_omap44xx())
  201. sar_base = OMAP44XX_SAR_RAM_BASE;
  202. else if (soc_is_omap54xx())
  203. sar_base = OMAP54XX_SAR_RAM_BASE;
  204. else
  205. return -ENOMEM;
  206. /* Static mapping, never released */
  207. sar_ram_base = ioremap(sar_base, SZ_16K);
  208. if (WARN_ON(!sar_ram_base))
  209. return -ENOMEM;
  210. return 0;
  211. }
  212. omap_early_initcall(omap4_sar_ram_init);
  213. static struct of_device_id gic_match[] = {
  214. { .compatible = "arm,cortex-a9-gic", },
  215. { .compatible = "arm,cortex-a15-gic", },
  216. { },
  217. };
  218. static struct device_node *gic_node;
  219. unsigned int omap4_xlate_irq(unsigned int hwirq)
  220. {
  221. struct of_phandle_args irq_data;
  222. unsigned int irq;
  223. if (!gic_node)
  224. gic_node = of_find_matching_node(NULL, gic_match);
  225. if (WARN_ON(!gic_node))
  226. return hwirq;
  227. irq_data.np = gic_node;
  228. irq_data.args_count = 3;
  229. irq_data.args[0] = 0;
  230. irq_data.args[1] = hwirq - OMAP44XX_IRQ_GIC_START;
  231. irq_data.args[2] = IRQ_TYPE_LEVEL_HIGH;
  232. irq = irq_create_of_mapping(&irq_data);
  233. if (WARN_ON(!irq))
  234. irq = hwirq;
  235. return irq;
  236. }
  237. void __init omap_gic_of_init(void)
  238. {
  239. struct device_node *np;
  240. /* Extract GIC distributor and TWD bases for OMAP4460 ROM Errata WA */
  241. if (!cpu_is_omap446x())
  242. goto skip_errata_init;
  243. np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
  244. gic_dist_base_addr = of_iomap(np, 0);
  245. WARN_ON(!gic_dist_base_addr);
  246. np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-twd-timer");
  247. twd_base = of_iomap(np, 0);
  248. WARN_ON(!twd_base);
  249. skip_errata_init:
  250. omap_wakeupgen_init();
  251. #ifdef CONFIG_IRQ_CROSSBAR
  252. irqcrossbar_init();
  253. #endif
  254. irqchip_init();
  255. }