omap4-common.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * OMAP4 specific common source file.
  4. *
  5. * Copyright (C) 2010 Texas Instruments, Inc.
  6. * Author:
  7. * Santosh Shilimkar <[email protected]>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/io.h>
  12. #include <linux/irq.h>
  13. #include <linux/irqchip.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/memblock.h>
  16. #include <linux/of_irq.h>
  17. #include <linux/of_platform.h>
  18. #include <linux/export.h>
  19. #include <linux/irqchip/arm-gic.h>
  20. #include <linux/of_address.h>
  21. #include <linux/reboot.h>
  22. #include <linux/genalloc.h>
  23. #include <asm/hardware/cache-l2x0.h>
  24. #include <asm/mach/map.h>
  25. #include <asm/memblock.h>
  26. #include <asm/smp_twd.h>
  27. #include "omap-wakeupgen.h"
  28. #include "soc.h"
  29. #include "iomap.h"
  30. #include "common.h"
  31. #include "prminst44xx.h"
  32. #include "prcm_mpu44xx.h"
  33. #include "omap4-sar-layout.h"
  34. #include "omap-secure.h"
  35. #include "sram.h"
  36. #ifdef CONFIG_CACHE_L2X0
  37. static void __iomem *l2cache_base;
  38. #endif
  39. static void __iomem *sar_ram_base;
  40. static void __iomem *gic_dist_base_addr;
  41. static void __iomem *twd_base;
  42. #define IRQ_LOCALTIMER 29
  43. #ifdef CONFIG_OMAP_INTERCONNECT_BARRIER
  44. /* Used to implement memory barrier on DRAM path */
  45. #define OMAP4_DRAM_BARRIER_VA 0xfe600000
  46. static void __iomem *dram_sync, *sram_sync;
  47. static phys_addr_t dram_sync_paddr;
  48. static u32 dram_sync_size;
  49. /*
  50. * The OMAP4 bus structure contains asynchronous bridges which can buffer
  51. * data writes from the MPU. These asynchronous bridges can be found on
  52. * paths between the MPU to EMIF, and the MPU to L3 interconnects.
  53. *
  54. * We need to be careful about re-ordering which can happen as a result
  55. * of different accesses being performed via different paths, and
  56. * therefore different asynchronous bridges.
  57. */
  58. /*
  59. * OMAP4 interconnect barrier which is called for each mb() and wmb().
  60. * This is to ensure that normal paths to DRAM (normal memory, cacheable
  61. * accesses) are properly synchronised with writes to DMA coherent memory
  62. * (normal memory, uncacheable) and device writes.
  63. *
  64. * The mb() and wmb() barriers only operate only on the MPU->MA->EMIF
  65. * path, as we need to ensure that data is visible to other system
  66. * masters prior to writes to those system masters being seen.
  67. *
  68. * Note: the SRAM path is not synchronised via mb() and wmb().
  69. */
  70. static void omap4_mb(void)
  71. {
  72. if (dram_sync)
  73. writel_relaxed(0, dram_sync);
  74. }
  75. /*
  76. * OMAP4 Errata i688 - asynchronous bridge corruption when entering WFI.
  77. *
  78. * If a data is stalled inside asynchronous bridge because of back
  79. * pressure, it may be accepted multiple times, creating pointer
  80. * misalignment that will corrupt next transfers on that data path until
  81. * next reset of the system. No recovery procedure once the issue is hit,
  82. * the path remains consistently broken.
  83. *
  84. * Async bridges can be found on paths between MPU to EMIF and MPU to L3
  85. * interconnects.
  86. *
  87. * This situation can happen only when the idle is initiated by a Master
  88. * Request Disconnection (which is trigged by software when executing WFI
  89. * on the CPU).
  90. *
  91. * The work-around for this errata needs all the initiators connected
  92. * through an async bridge to ensure that data path is properly drained
  93. * before issuing WFI. This condition will be met if one Strongly ordered
  94. * access is performed to the target right before executing the WFI.
  95. *
  96. * In MPU case, L3 T2ASYNC FIFO and DDR T2ASYNC FIFO needs to be drained.
  97. * IO barrier ensure that there is no synchronisation loss on initiators
  98. * operating on both interconnect port simultaneously.
  99. *
  100. * This is a stronger version of the OMAP4 memory barrier below, and
  101. * operates on both the MPU->MA->EMIF path but also the MPU->OCP path
  102. * as well, and is necessary prior to executing a WFI.
  103. */
  104. void omap_interconnect_sync(void)
  105. {
  106. if (dram_sync && sram_sync) {
  107. writel_relaxed(readl_relaxed(dram_sync), dram_sync);
  108. writel_relaxed(readl_relaxed(sram_sync), sram_sync);
  109. isb();
  110. }
  111. }
  112. static int __init omap4_sram_init(void)
  113. {
  114. struct device_node *np;
  115. struct gen_pool *sram_pool;
  116. if (!soc_is_omap44xx() && !soc_is_omap54xx())
  117. return 0;
  118. np = of_find_compatible_node(NULL, NULL, "ti,omap4-mpu");
  119. if (!np)
  120. pr_warn("%s:Unable to allocate sram needed to handle errata I688\n",
  121. __func__);
  122. sram_pool = of_gen_pool_get(np, "sram", 0);
  123. if (!sram_pool)
  124. pr_warn("%s:Unable to get sram pool needed to handle errata I688\n",
  125. __func__);
  126. else
  127. sram_sync = (void __iomem *)gen_pool_alloc(sram_pool, PAGE_SIZE);
  128. of_node_put(np);
  129. return 0;
  130. }
  131. omap_arch_initcall(omap4_sram_init);
  132. /* Steal one page physical memory for barrier implementation */
  133. void __init omap_barrier_reserve_memblock(void)
  134. {
  135. dram_sync_size = ALIGN(PAGE_SIZE, SZ_1M);
  136. dram_sync_paddr = arm_memblock_steal(dram_sync_size, SZ_1M);
  137. }
  138. void __init omap_barriers_init(void)
  139. {
  140. struct map_desc dram_io_desc[1];
  141. dram_io_desc[0].virtual = OMAP4_DRAM_BARRIER_VA;
  142. dram_io_desc[0].pfn = __phys_to_pfn(dram_sync_paddr);
  143. dram_io_desc[0].length = dram_sync_size;
  144. dram_io_desc[0].type = MT_MEMORY_RW_SO;
  145. iotable_init(dram_io_desc, ARRAY_SIZE(dram_io_desc));
  146. dram_sync = (void __iomem *) dram_io_desc[0].virtual;
  147. pr_info("OMAP4: Map %pa to %p for dram barrier\n",
  148. &dram_sync_paddr, dram_sync);
  149. soc_mb = omap4_mb;
  150. }
  151. #endif
  152. void gic_dist_disable(void)
  153. {
  154. if (gic_dist_base_addr)
  155. writel_relaxed(0x0, gic_dist_base_addr + GIC_DIST_CTRL);
  156. }
  157. void gic_dist_enable(void)
  158. {
  159. if (gic_dist_base_addr)
  160. writel_relaxed(0x1, gic_dist_base_addr + GIC_DIST_CTRL);
  161. }
  162. bool gic_dist_disabled(void)
  163. {
  164. return !(readl_relaxed(gic_dist_base_addr + GIC_DIST_CTRL) & 0x1);
  165. }
  166. void gic_timer_retrigger(void)
  167. {
  168. u32 twd_int = readl_relaxed(twd_base + TWD_TIMER_INTSTAT);
  169. u32 gic_int = readl_relaxed(gic_dist_base_addr + GIC_DIST_PENDING_SET);
  170. u32 twd_ctrl = readl_relaxed(twd_base + TWD_TIMER_CONTROL);
  171. if (twd_int && !(gic_int & BIT(IRQ_LOCALTIMER))) {
  172. /*
  173. * The local timer interrupt got lost while the distributor was
  174. * disabled. Ack the pending interrupt, and retrigger it.
  175. */
  176. pr_warn("%s: lost localtimer interrupt\n", __func__);
  177. writel_relaxed(1, twd_base + TWD_TIMER_INTSTAT);
  178. if (!(twd_ctrl & TWD_TIMER_CONTROL_PERIODIC)) {
  179. writel_relaxed(1, twd_base + TWD_TIMER_COUNTER);
  180. twd_ctrl |= TWD_TIMER_CONTROL_ENABLE;
  181. writel_relaxed(twd_ctrl, twd_base + TWD_TIMER_CONTROL);
  182. }
  183. }
  184. }
  185. #ifdef CONFIG_CACHE_L2X0
  186. void __iomem *omap4_get_l2cache_base(void)
  187. {
  188. return l2cache_base;
  189. }
  190. void omap4_l2c310_write_sec(unsigned long val, unsigned reg)
  191. {
  192. unsigned smc_op;
  193. switch (reg) {
  194. case L2X0_CTRL:
  195. smc_op = OMAP4_MON_L2X0_CTRL_INDEX;
  196. break;
  197. case L2X0_AUX_CTRL:
  198. smc_op = OMAP4_MON_L2X0_AUXCTRL_INDEX;
  199. break;
  200. case L2X0_DEBUG_CTRL:
  201. smc_op = OMAP4_MON_L2X0_DBG_CTRL_INDEX;
  202. break;
  203. case L310_PREFETCH_CTRL:
  204. smc_op = OMAP4_MON_L2X0_PREFETCH_INDEX;
  205. break;
  206. case L310_POWER_CTRL:
  207. pr_info_once("OMAP L2C310: ROM does not support power control setting\n");
  208. return;
  209. default:
  210. WARN_ONCE(1, "OMAP L2C310: ignoring write to reg 0x%x\n", reg);
  211. return;
  212. }
  213. omap_smc1(smc_op, val);
  214. }
  215. int __init omap_l2_cache_init(void)
  216. {
  217. /* Static mapping, never released */
  218. l2cache_base = ioremap(OMAP44XX_L2CACHE_BASE, SZ_4K);
  219. if (WARN_ON(!l2cache_base))
  220. return -ENOMEM;
  221. return 0;
  222. }
  223. #endif
  224. void __iomem *omap4_get_sar_ram_base(void)
  225. {
  226. return sar_ram_base;
  227. }
  228. /*
  229. * SAR RAM used to save and restore the HW context in low power modes.
  230. * Note that we need to initialize this very early for kexec. See
  231. * omap4_mpuss_early_init().
  232. */
  233. void __init omap4_sar_ram_init(void)
  234. {
  235. unsigned long sar_base;
  236. /*
  237. * To avoid code running on other OMAPs in
  238. * multi-omap builds
  239. */
  240. if (cpu_is_omap44xx())
  241. sar_base = OMAP44XX_SAR_RAM_BASE;
  242. else if (soc_is_omap54xx())
  243. sar_base = OMAP54XX_SAR_RAM_BASE;
  244. else
  245. return;
  246. /* Static mapping, never released */
  247. sar_ram_base = ioremap(sar_base, SZ_16K);
  248. if (WARN_ON(!sar_ram_base))
  249. return;
  250. }
  251. static const struct of_device_id intc_match[] = {
  252. { .compatible = "ti,omap4-wugen-mpu", },
  253. { .compatible = "ti,omap5-wugen-mpu", },
  254. { },
  255. };
  256. static struct device_node *intc_node;
  257. void __init omap_gic_of_init(void)
  258. {
  259. struct device_node *np;
  260. intc_node = of_find_matching_node(NULL, intc_match);
  261. if (WARN_ON(!intc_node)) {
  262. pr_err("No WUGEN found in DT, system will misbehave.\n");
  263. pr_err("UPDATE YOUR DEVICE TREE!\n");
  264. }
  265. /* Extract GIC distributor and TWD bases for OMAP4460 ROM Errata WA */
  266. if (!cpu_is_omap446x())
  267. goto skip_errata_init;
  268. np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
  269. gic_dist_base_addr = of_iomap(np, 0);
  270. of_node_put(np);
  271. WARN_ON(!gic_dist_base_addr);
  272. np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-twd-timer");
  273. twd_base = of_iomap(np, 0);
  274. of_node_put(np);
  275. WARN_ON(!twd_base);
  276. skip_errata_init:
  277. irqchip_init();
  278. }