omap4-common.c 9.1 KB

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