omap4-common.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 <asm/hardware/cache-l2x0.h>
  28. #include <asm/mach/map.h>
  29. #include <asm/memblock.h>
  30. #include <asm/smp_twd.h>
  31. #include "omap-wakeupgen.h"
  32. #include "soc.h"
  33. #include "iomap.h"
  34. #include "common.h"
  35. #include "mmc.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. /* Steal one page physical memory for barrier implementation */
  64. int __init omap_barrier_reserve_memblock(void)
  65. {
  66. size = ALIGN(PAGE_SIZE, SZ_1M);
  67. paddr = arm_memblock_steal(size, SZ_1M);
  68. return 0;
  69. }
  70. void __init omap_barriers_init(void)
  71. {
  72. struct map_desc dram_io_desc[1];
  73. dram_io_desc[0].virtual = OMAP4_DRAM_BARRIER_VA;
  74. dram_io_desc[0].pfn = __phys_to_pfn(paddr);
  75. dram_io_desc[0].length = size;
  76. dram_io_desc[0].type = MT_MEMORY_RW_SO;
  77. iotable_init(dram_io_desc, ARRAY_SIZE(dram_io_desc));
  78. dram_sync = (void __iomem *) dram_io_desc[0].virtual;
  79. sram_sync = (void __iomem *) OMAP4_SRAM_VA;
  80. pr_info("OMAP4: Map 0x%08llx to 0x%08lx for dram barrier\n",
  81. (long long) paddr, dram_io_desc[0].virtual);
  82. }
  83. #else
  84. void __init omap_barriers_init(void)
  85. {}
  86. #endif
  87. void __init gic_init_irq(void)
  88. {
  89. void __iomem *omap_irq_base;
  90. /* Static mapping, never released */
  91. gic_dist_base_addr = ioremap(OMAP44XX_GIC_DIST_BASE, SZ_4K);
  92. BUG_ON(!gic_dist_base_addr);
  93. twd_base = ioremap(OMAP44XX_LOCAL_TWD_BASE, SZ_4K);
  94. BUG_ON(!twd_base);
  95. /* Static mapping, never released */
  96. omap_irq_base = ioremap(OMAP44XX_GIC_CPU_BASE, SZ_512);
  97. BUG_ON(!omap_irq_base);
  98. omap_wakeupgen_init();
  99. gic_init(0, 29, gic_dist_base_addr, omap_irq_base);
  100. }
  101. void gic_dist_disable(void)
  102. {
  103. if (gic_dist_base_addr)
  104. __raw_writel(0x0, gic_dist_base_addr + GIC_DIST_CTRL);
  105. }
  106. void gic_dist_enable(void)
  107. {
  108. if (gic_dist_base_addr)
  109. __raw_writel(0x1, gic_dist_base_addr + GIC_DIST_CTRL);
  110. }
  111. bool gic_dist_disabled(void)
  112. {
  113. return !(__raw_readl(gic_dist_base_addr + GIC_DIST_CTRL) & 0x1);
  114. }
  115. void gic_timer_retrigger(void)
  116. {
  117. u32 twd_int = __raw_readl(twd_base + TWD_TIMER_INTSTAT);
  118. u32 gic_int = __raw_readl(gic_dist_base_addr + GIC_DIST_PENDING_SET);
  119. u32 twd_ctrl = __raw_readl(twd_base + TWD_TIMER_CONTROL);
  120. if (twd_int && !(gic_int & BIT(IRQ_LOCALTIMER))) {
  121. /*
  122. * The local timer interrupt got lost while the distributor was
  123. * disabled. Ack the pending interrupt, and retrigger it.
  124. */
  125. pr_warn("%s: lost localtimer interrupt\n", __func__);
  126. __raw_writel(1, twd_base + TWD_TIMER_INTSTAT);
  127. if (!(twd_ctrl & TWD_TIMER_CONTROL_PERIODIC)) {
  128. __raw_writel(1, twd_base + TWD_TIMER_COUNTER);
  129. twd_ctrl |= TWD_TIMER_CONTROL_ENABLE;
  130. __raw_writel(twd_ctrl, twd_base + TWD_TIMER_CONTROL);
  131. }
  132. }
  133. }
  134. #ifdef CONFIG_CACHE_L2X0
  135. void __iomem *omap4_get_l2cache_base(void)
  136. {
  137. return l2cache_base;
  138. }
  139. static void omap4_l2x0_disable(void)
  140. {
  141. outer_flush_all();
  142. /* Disable PL310 L2 Cache controller */
  143. omap_smc1(0x102, 0x0);
  144. }
  145. static void omap4_l2x0_set_debug(unsigned long val)
  146. {
  147. /* Program PL310 L2 Cache controller debug register */
  148. omap_smc1(0x100, val);
  149. }
  150. static int __init omap_l2_cache_init(void)
  151. {
  152. u32 aux_ctrl;
  153. /*
  154. * To avoid code running on other OMAPs in
  155. * multi-omap builds
  156. */
  157. if (!cpu_is_omap44xx())
  158. return -ENODEV;
  159. /* Static mapping, never released */
  160. l2cache_base = ioremap(OMAP44XX_L2CACHE_BASE, SZ_4K);
  161. if (WARN_ON(!l2cache_base))
  162. return -ENOMEM;
  163. /* 16-way associativity, parity disabled, way size - 64KB (es2.0 +) */
  164. aux_ctrl = L310_AUX_CTRL_ASSOCIATIVITY_16 |
  165. L310_AUX_CTRL_CACHE_REPLACE_RR |
  166. L310_AUX_CTRL_NS_LOCKDOWN |
  167. L310_AUX_CTRL_NS_INT_CTRL |
  168. L2C_AUX_CTRL_WAY_SIZE(3) |
  169. L2C_AUX_CTRL_SHARED_OVERRIDE |
  170. L310_AUX_CTRL_DATA_PREFETCH |
  171. L310_AUX_CTRL_INSTR_PREFETCH |
  172. L310_AUX_CTRL_EARLY_BRESP;
  173. omap_smc1(0x109, aux_ctrl);
  174. /* Enable PL310 L2 Cache controller */
  175. omap_smc1(0x102, 0x1);
  176. if (of_have_populated_dt())
  177. l2x0_of_init(aux_ctrl, L2X0_AUX_CTRL_MASK);
  178. else
  179. l2x0_init(l2cache_base, aux_ctrl, L2X0_AUX_CTRL_MASK);
  180. /*
  181. * Override default outer_cache.disable with a OMAP4
  182. * specific one
  183. */
  184. outer_cache.disable = omap4_l2x0_disable;
  185. outer_cache.set_debug = omap4_l2x0_set_debug;
  186. return 0;
  187. }
  188. omap_early_initcall(omap_l2_cache_init);
  189. #endif
  190. void __iomem *omap4_get_sar_ram_base(void)
  191. {
  192. return sar_ram_base;
  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. unsigned long sar_base;
  201. /*
  202. * To avoid code running on other OMAPs in
  203. * multi-omap builds
  204. */
  205. if (cpu_is_omap44xx())
  206. sar_base = OMAP44XX_SAR_RAM_BASE;
  207. else if (soc_is_omap54xx())
  208. sar_base = OMAP54XX_SAR_RAM_BASE;
  209. else
  210. return -ENOMEM;
  211. /* Static mapping, never released */
  212. sar_ram_base = ioremap(sar_base, SZ_16K);
  213. if (WARN_ON(!sar_ram_base))
  214. return -ENOMEM;
  215. return 0;
  216. }
  217. omap_early_initcall(omap4_sar_ram_init);
  218. void __init omap_gic_of_init(void)
  219. {
  220. struct device_node *np;
  221. /* Extract GIC distributor and TWD bases for OMAP4460 ROM Errata WA */
  222. if (!cpu_is_omap446x())
  223. goto skip_errata_init;
  224. np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
  225. gic_dist_base_addr = of_iomap(np, 0);
  226. WARN_ON(!gic_dist_base_addr);
  227. np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-twd-timer");
  228. twd_base = of_iomap(np, 0);
  229. WARN_ON(!twd_base);
  230. skip_errata_init:
  231. omap_wakeupgen_init();
  232. #ifdef CONFIG_IRQ_CROSSBAR
  233. irqcrossbar_init();
  234. #endif
  235. irqchip_init();
  236. }