omap4-common.c 6.9 KB

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