omap4-common.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 <asm/hardware/cache-l2x0.h>
  25. #include <asm/mach/map.h>
  26. #include <asm/memblock.h>
  27. #include <asm/smp_twd.h>
  28. #include "omap-wakeupgen.h"
  29. #include "soc.h"
  30. #include "iomap.h"
  31. #include "common.h"
  32. #include "mmc.h"
  33. #include "hsmmc.h"
  34. #include "prminst44xx.h"
  35. #include "prcm_mpu44xx.h"
  36. #include "omap4-sar-layout.h"
  37. #include "omap-secure.h"
  38. #include "sram.h"
  39. #ifdef CONFIG_CACHE_L2X0
  40. static void __iomem *l2cache_base;
  41. #endif
  42. static void __iomem *sar_ram_base;
  43. static void __iomem *gic_dist_base_addr;
  44. static void __iomem *twd_base;
  45. #define IRQ_LOCALTIMER 29
  46. #ifdef CONFIG_OMAP4_ERRATA_I688
  47. /* Used to implement memory barrier on DRAM path */
  48. #define OMAP4_DRAM_BARRIER_VA 0xfe600000
  49. void __iomem *dram_sync, *sram_sync;
  50. static phys_addr_t paddr;
  51. static u32 size;
  52. void omap_bus_sync(void)
  53. {
  54. if (dram_sync && sram_sync) {
  55. writel_relaxed(readl_relaxed(dram_sync), dram_sync);
  56. writel_relaxed(readl_relaxed(sram_sync), sram_sync);
  57. isb();
  58. }
  59. }
  60. EXPORT_SYMBOL(omap_bus_sync);
  61. /* Steal one page physical memory for barrier implementation */
  62. int __init omap_barrier_reserve_memblock(void)
  63. {
  64. size = ALIGN(PAGE_SIZE, SZ_1M);
  65. paddr = arm_memblock_steal(size, SZ_1M);
  66. return 0;
  67. }
  68. void __init omap_barriers_init(void)
  69. {
  70. struct map_desc dram_io_desc[1];
  71. dram_io_desc[0].virtual = OMAP4_DRAM_BARRIER_VA;
  72. dram_io_desc[0].pfn = __phys_to_pfn(paddr);
  73. dram_io_desc[0].length = size;
  74. dram_io_desc[0].type = MT_MEMORY_SO;
  75. iotable_init(dram_io_desc, ARRAY_SIZE(dram_io_desc));
  76. dram_sync = (void __iomem *) dram_io_desc[0].virtual;
  77. sram_sync = (void __iomem *) OMAP4_SRAM_VA;
  78. pr_info("OMAP4: Map 0x%08llx to 0x%08lx for dram barrier\n",
  79. (long long) paddr, dram_io_desc[0].virtual);
  80. }
  81. #else
  82. void __init omap_barriers_init(void)
  83. {}
  84. #endif
  85. void __init gic_init_irq(void)
  86. {
  87. void __iomem *omap_irq_base;
  88. /* Static mapping, never released */
  89. gic_dist_base_addr = ioremap(OMAP44XX_GIC_DIST_BASE, SZ_4K);
  90. BUG_ON(!gic_dist_base_addr);
  91. twd_base = ioremap(OMAP44XX_LOCAL_TWD_BASE, SZ_4K);
  92. BUG_ON(!twd_base);
  93. /* Static mapping, never released */
  94. omap_irq_base = ioremap(OMAP44XX_GIC_CPU_BASE, SZ_512);
  95. BUG_ON(!omap_irq_base);
  96. omap_wakeupgen_init();
  97. gic_init(0, 29, gic_dist_base_addr, omap_irq_base);
  98. }
  99. void gic_dist_disable(void)
  100. {
  101. if (gic_dist_base_addr)
  102. __raw_writel(0x0, gic_dist_base_addr + GIC_DIST_CTRL);
  103. }
  104. bool gic_dist_disabled(void)
  105. {
  106. return !(__raw_readl(gic_dist_base_addr + GIC_DIST_CTRL) & 0x1);
  107. }
  108. void gic_timer_retrigger(void)
  109. {
  110. u32 twd_int = __raw_readl(twd_base + TWD_TIMER_INTSTAT);
  111. u32 gic_int = __raw_readl(gic_dist_base_addr + GIC_DIST_PENDING_SET);
  112. u32 twd_ctrl = __raw_readl(twd_base + TWD_TIMER_CONTROL);
  113. if (twd_int && !(gic_int & BIT(IRQ_LOCALTIMER))) {
  114. /*
  115. * The local timer interrupt got lost while the distributor was
  116. * disabled. Ack the pending interrupt, and retrigger it.
  117. */
  118. pr_warn("%s: lost localtimer interrupt\n", __func__);
  119. __raw_writel(1, twd_base + TWD_TIMER_INTSTAT);
  120. if (!(twd_ctrl & TWD_TIMER_CONTROL_PERIODIC)) {
  121. __raw_writel(1, twd_base + TWD_TIMER_COUNTER);
  122. twd_ctrl |= TWD_TIMER_CONTROL_ENABLE;
  123. __raw_writel(twd_ctrl, twd_base + TWD_TIMER_CONTROL);
  124. }
  125. }
  126. }
  127. #ifdef CONFIG_CACHE_L2X0
  128. void __iomem *omap4_get_l2cache_base(void)
  129. {
  130. return l2cache_base;
  131. }
  132. static void omap4_l2x0_disable(void)
  133. {
  134. /* Disable PL310 L2 Cache controller */
  135. omap_smc1(0x102, 0x0);
  136. }
  137. static void omap4_l2x0_set_debug(unsigned long val)
  138. {
  139. /* Program PL310 L2 Cache controller debug register */
  140. omap_smc1(0x100, val);
  141. }
  142. static int __init omap_l2_cache_init(void)
  143. {
  144. u32 aux_ctrl = 0;
  145. /*
  146. * To avoid code running on other OMAPs in
  147. * multi-omap builds
  148. */
  149. if (!cpu_is_omap44xx())
  150. return -ENODEV;
  151. /* Static mapping, never released */
  152. l2cache_base = ioremap(OMAP44XX_L2CACHE_BASE, SZ_4K);
  153. if (WARN_ON(!l2cache_base))
  154. return -ENOMEM;
  155. /*
  156. * 16-way associativity, parity disabled
  157. * Way size - 32KB (es1.0)
  158. * Way size - 64KB (es2.0 +)
  159. */
  160. aux_ctrl = ((1 << L2X0_AUX_CTRL_ASSOCIATIVITY_SHIFT) |
  161. (0x1 << 25) |
  162. (0x1 << L2X0_AUX_CTRL_NS_LOCKDOWN_SHIFT) |
  163. (0x1 << L2X0_AUX_CTRL_NS_INT_CTRL_SHIFT));
  164. if (omap_rev() == OMAP4430_REV_ES1_0) {
  165. aux_ctrl |= 0x2 << L2X0_AUX_CTRL_WAY_SIZE_SHIFT;
  166. } else {
  167. aux_ctrl |= ((0x3 << L2X0_AUX_CTRL_WAY_SIZE_SHIFT) |
  168. (1 << L2X0_AUX_CTRL_SHARE_OVERRIDE_SHIFT) |
  169. (1 << L2X0_AUX_CTRL_DATA_PREFETCH_SHIFT) |
  170. (1 << L2X0_AUX_CTRL_INSTR_PREFETCH_SHIFT) |
  171. (1 << L2X0_AUX_CTRL_EARLY_BRESP_SHIFT));
  172. }
  173. if (omap_rev() != OMAP4430_REV_ES1_0)
  174. omap_smc1(0x109, aux_ctrl);
  175. /* Enable PL310 L2 Cache controller */
  176. omap_smc1(0x102, 0x1);
  177. if (of_have_populated_dt())
  178. l2x0_of_init(aux_ctrl, L2X0_AUX_CTRL_MASK);
  179. else
  180. l2x0_init(l2cache_base, aux_ctrl, L2X0_AUX_CTRL_MASK);
  181. /*
  182. * Override default outer_cache.disable with a OMAP4
  183. * specific one
  184. */
  185. outer_cache.disable = omap4_l2x0_disable;
  186. outer_cache.set_debug = omap4_l2x0_set_debug;
  187. return 0;
  188. }
  189. omap_early_initcall(omap_l2_cache_init);
  190. #endif
  191. void __iomem *omap4_get_sar_ram_base(void)
  192. {
  193. return sar_ram_base;
  194. }
  195. /*
  196. * SAR RAM used to save and restore the HW
  197. * context in low power modes
  198. */
  199. static int __init omap4_sar_ram_init(void)
  200. {
  201. /*
  202. * To avoid code running on other OMAPs in
  203. * multi-omap builds
  204. */
  205. if (!cpu_is_omap44xx())
  206. return -ENOMEM;
  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. return 0;
  212. }
  213. omap_early_initcall(omap4_sar_ram_init);
  214. void __init omap_gic_of_init(void)
  215. {
  216. omap_wakeupgen_init();
  217. irqchip_init();
  218. }
  219. #if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
  220. static int omap4_twl6030_hsmmc_late_init(struct device *dev)
  221. {
  222. int irq = 0;
  223. struct platform_device *pdev = container_of(dev,
  224. struct platform_device, dev);
  225. struct omap_mmc_platform_data *pdata = dev->platform_data;
  226. /* Setting MMC1 Card detect Irq */
  227. if (pdev->id == 0) {
  228. irq = twl6030_mmc_card_detect_config();
  229. if (irq < 0) {
  230. dev_err(dev, "%s: Error card detect config(%d)\n",
  231. __func__, irq);
  232. return irq;
  233. }
  234. pdata->slots[0].card_detect_irq = irq;
  235. pdata->slots[0].card_detect = twl6030_mmc_card_detect;
  236. }
  237. return 0;
  238. }
  239. static __init void omap4_twl6030_hsmmc_set_late_init(struct device *dev)
  240. {
  241. struct omap_mmc_platform_data *pdata;
  242. /* dev can be null if CONFIG_MMC_OMAP_HS is not set */
  243. if (!dev) {
  244. pr_err("Failed %s\n", __func__);
  245. return;
  246. }
  247. pdata = dev->platform_data;
  248. pdata->init = omap4_twl6030_hsmmc_late_init;
  249. }
  250. int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers)
  251. {
  252. struct omap2_hsmmc_info *c;
  253. omap_hsmmc_init(controllers);
  254. for (c = controllers; c->mmc; c++) {
  255. /* pdev can be null if CONFIG_MMC_OMAP_HS is not set */
  256. if (!c->pdev)
  257. continue;
  258. omap4_twl6030_hsmmc_set_late_init(&c->pdev->dev);
  259. }
  260. return 0;
  261. }
  262. #else
  263. int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers)
  264. {
  265. return 0;
  266. }
  267. #endif
  268. /**
  269. * omap44xx_restart - trigger a software restart of the SoC
  270. * @mode: the "reboot mode", see arch/arm/kernel/{setup,process}.c
  271. * @cmd: passed from the userspace program rebooting the system (if provided)
  272. *
  273. * Resets the SoC. For @cmd, see the 'reboot' syscall in
  274. * kernel/sys.c. No return value.
  275. */
  276. void omap44xx_restart(char mode, const char *cmd)
  277. {
  278. /* XXX Should save 'cmd' into scratchpad for use after reboot */
  279. omap4_prminst_global_warm_sw_reset(); /* never returns */
  280. while (1);
  281. }