omap4-common.c 8.0 KB

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