sram.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. *
  3. * OMAP SRAM detection and management
  4. *
  5. * Copyright (C) 2005 Nokia Corporation
  6. * Written by Tony Lindgren <tony@atomide.com>
  7. *
  8. * Copyright (C) 2009-2012 Texas Instruments
  9. * Added OMAP4/5 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/io.h>
  19. #include <asm/fncpy.h>
  20. #include <asm/tlb.h>
  21. #include <asm/cacheflush.h>
  22. #include <asm/mach/map.h>
  23. #include "soc.h"
  24. #include "iomap.h"
  25. #include "prm2xxx_3xxx.h"
  26. #include "sdrc.h"
  27. #include "sram.h"
  28. #define OMAP2_SRAM_PUB_PA (OMAP2_SRAM_PA + 0xf800)
  29. #define OMAP3_SRAM_PUB_PA (OMAP3_SRAM_PA + 0x8000)
  30. #ifdef CONFIG_OMAP4_ERRATA_I688
  31. #define OMAP4_SRAM_PUB_PA OMAP4_SRAM_PA
  32. #else
  33. #define OMAP4_SRAM_PUB_PA (OMAP4_SRAM_PA + 0x4000)
  34. #endif
  35. #define OMAP5_SRAM_PA 0x40300000
  36. #define SRAM_BOOTLOADER_SZ 0x00
  37. #define OMAP24XX_VA_REQINFOPERM0 OMAP2_L3_IO_ADDRESS(0x68005048)
  38. #define OMAP24XX_VA_READPERM0 OMAP2_L3_IO_ADDRESS(0x68005050)
  39. #define OMAP24XX_VA_WRITEPERM0 OMAP2_L3_IO_ADDRESS(0x68005058)
  40. #define OMAP34XX_VA_REQINFOPERM0 OMAP2_L3_IO_ADDRESS(0x68012848)
  41. #define OMAP34XX_VA_READPERM0 OMAP2_L3_IO_ADDRESS(0x68012850)
  42. #define OMAP34XX_VA_WRITEPERM0 OMAP2_L3_IO_ADDRESS(0x68012858)
  43. #define OMAP34XX_VA_ADDR_MATCH2 OMAP2_L3_IO_ADDRESS(0x68012880)
  44. #define OMAP34XX_VA_SMS_RG_ATT0 OMAP2_L3_IO_ADDRESS(0x6C000048)
  45. #define GP_DEVICE 0x300
  46. #define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
  47. static unsigned long omap_sram_start;
  48. static unsigned long omap_sram_skip;
  49. static unsigned long omap_sram_size;
  50. /*
  51. * Depending on the target RAMFS firewall setup, the public usable amount of
  52. * SRAM varies. The default accessible size for all device types is 2k. A GP
  53. * device allows ARM11 but not other initiators for full size. This
  54. * functionality seems ok until some nice security API happens.
  55. */
  56. static int is_sram_locked(void)
  57. {
  58. if (OMAP2_DEVICE_TYPE_GP == omap_type()) {
  59. /* RAMFW: R/W access to all initiators for all qualifier sets */
  60. if (cpu_is_omap242x()) {
  61. __raw_writel(0xFF, OMAP24XX_VA_REQINFOPERM0); /* all q-vects */
  62. __raw_writel(0xCFDE, OMAP24XX_VA_READPERM0); /* all i-read */
  63. __raw_writel(0xCFDE, OMAP24XX_VA_WRITEPERM0); /* all i-write */
  64. }
  65. if (cpu_is_omap34xx()) {
  66. __raw_writel(0xFFFF, OMAP34XX_VA_REQINFOPERM0); /* all q-vects */
  67. __raw_writel(0xFFFF, OMAP34XX_VA_READPERM0); /* all i-read */
  68. __raw_writel(0xFFFF, OMAP34XX_VA_WRITEPERM0); /* all i-write */
  69. __raw_writel(0x0, OMAP34XX_VA_ADDR_MATCH2);
  70. __raw_writel(0xFFFFFFFF, OMAP34XX_VA_SMS_RG_ATT0);
  71. }
  72. return 0;
  73. } else
  74. return 1; /* assume locked with no PPA or security driver */
  75. }
  76. /*
  77. * The amount of SRAM depends on the core type.
  78. * Note that we cannot try to test for SRAM here because writes
  79. * to secure SRAM will hang the system. Also the SRAM is not
  80. * yet mapped at this point.
  81. */
  82. static void __init omap_detect_sram(void)
  83. {
  84. omap_sram_skip = SRAM_BOOTLOADER_SZ;
  85. if (is_sram_locked()) {
  86. if (cpu_is_omap34xx()) {
  87. omap_sram_start = OMAP3_SRAM_PUB_PA;
  88. if ((omap_type() == OMAP2_DEVICE_TYPE_EMU) ||
  89. (omap_type() == OMAP2_DEVICE_TYPE_SEC)) {
  90. omap_sram_size = 0x7000; /* 28K */
  91. omap_sram_skip += SZ_16K;
  92. } else {
  93. omap_sram_size = 0x8000; /* 32K */
  94. }
  95. } else if (cpu_is_omap44xx()) {
  96. omap_sram_start = OMAP4_SRAM_PUB_PA;
  97. omap_sram_size = 0xa000; /* 40K */
  98. } else if (soc_is_omap54xx()) {
  99. omap_sram_start = OMAP5_SRAM_PA;
  100. omap_sram_size = SZ_128K; /* 128KB */
  101. } else {
  102. omap_sram_start = OMAP2_SRAM_PUB_PA;
  103. omap_sram_size = 0x800; /* 2K */
  104. }
  105. } else {
  106. if (soc_is_am33xx()) {
  107. omap_sram_start = AM33XX_SRAM_PA;
  108. omap_sram_size = 0x10000; /* 64K */
  109. } else if (cpu_is_omap34xx()) {
  110. omap_sram_start = OMAP3_SRAM_PA;
  111. omap_sram_size = 0x10000; /* 64K */
  112. } else if (cpu_is_omap44xx()) {
  113. omap_sram_start = OMAP4_SRAM_PA;
  114. omap_sram_size = 0xe000; /* 56K */
  115. } else if (soc_is_omap54xx()) {
  116. omap_sram_start = OMAP5_SRAM_PA;
  117. omap_sram_size = SZ_128K; /* 128KB */
  118. } else {
  119. omap_sram_start = OMAP2_SRAM_PA;
  120. if (cpu_is_omap242x())
  121. omap_sram_size = 0xa0000; /* 640K */
  122. else if (cpu_is_omap243x())
  123. omap_sram_size = 0x10000; /* 64K */
  124. }
  125. }
  126. }
  127. /*
  128. * Note that we cannot use ioremap for SRAM, as clock init needs SRAM early.
  129. */
  130. static void __init omap2_map_sram(void)
  131. {
  132. int cached = 1;
  133. #ifdef CONFIG_OMAP4_ERRATA_I688
  134. if (cpu_is_omap44xx()) {
  135. omap_sram_start += PAGE_SIZE;
  136. omap_sram_size -= SZ_16K;
  137. }
  138. #endif
  139. if (cpu_is_omap34xx()) {
  140. /*
  141. * SRAM must be marked as non-cached on OMAP3 since the
  142. * CORE DPLL M2 divider change code (in SRAM) runs with the
  143. * SDRAM controller disabled, and if it is marked cached,
  144. * the ARM may attempt to write cache lines back to SDRAM
  145. * which will cause the system to hang.
  146. */
  147. cached = 0;
  148. }
  149. omap_map_sram(omap_sram_start, omap_sram_size,
  150. omap_sram_skip, cached);
  151. }
  152. static void (*_omap2_sram_ddr_init)(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
  153. u32 base_cs, u32 force_unlock);
  154. void omap2_sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
  155. u32 base_cs, u32 force_unlock)
  156. {
  157. BUG_ON(!_omap2_sram_ddr_init);
  158. _omap2_sram_ddr_init(slow_dll_ctrl, fast_dll_ctrl,
  159. base_cs, force_unlock);
  160. }
  161. static void (*_omap2_sram_reprogram_sdrc)(u32 perf_level, u32 dll_val,
  162. u32 mem_type);
  163. void omap2_sram_reprogram_sdrc(u32 perf_level, u32 dll_val, u32 mem_type)
  164. {
  165. BUG_ON(!_omap2_sram_reprogram_sdrc);
  166. _omap2_sram_reprogram_sdrc(perf_level, dll_val, mem_type);
  167. }
  168. static u32 (*_omap2_set_prcm)(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass);
  169. u32 omap2_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass)
  170. {
  171. BUG_ON(!_omap2_set_prcm);
  172. return _omap2_set_prcm(dpll_ctrl_val, sdrc_rfr_val, bypass);
  173. }
  174. #ifdef CONFIG_SOC_OMAP2420
  175. static int __init omap242x_sram_init(void)
  176. {
  177. _omap2_sram_ddr_init = omap_sram_push(omap242x_sram_ddr_init,
  178. omap242x_sram_ddr_init_sz);
  179. _omap2_sram_reprogram_sdrc = omap_sram_push(omap242x_sram_reprogram_sdrc,
  180. omap242x_sram_reprogram_sdrc_sz);
  181. _omap2_set_prcm = omap_sram_push(omap242x_sram_set_prcm,
  182. omap242x_sram_set_prcm_sz);
  183. return 0;
  184. }
  185. #else
  186. static inline int omap242x_sram_init(void)
  187. {
  188. return 0;
  189. }
  190. #endif
  191. #ifdef CONFIG_SOC_OMAP2430
  192. static int __init omap243x_sram_init(void)
  193. {
  194. _omap2_sram_ddr_init = omap_sram_push(omap243x_sram_ddr_init,
  195. omap243x_sram_ddr_init_sz);
  196. _omap2_sram_reprogram_sdrc = omap_sram_push(omap243x_sram_reprogram_sdrc,
  197. omap243x_sram_reprogram_sdrc_sz);
  198. _omap2_set_prcm = omap_sram_push(omap243x_sram_set_prcm,
  199. omap243x_sram_set_prcm_sz);
  200. return 0;
  201. }
  202. #else
  203. static inline int omap243x_sram_init(void)
  204. {
  205. return 0;
  206. }
  207. #endif
  208. #ifdef CONFIG_ARCH_OMAP3
  209. static u32 (*_omap3_sram_configure_core_dpll)(
  210. u32 m2, u32 unlock_dll, u32 f, u32 inc,
  211. u32 sdrc_rfr_ctrl_0, u32 sdrc_actim_ctrl_a_0,
  212. u32 sdrc_actim_ctrl_b_0, u32 sdrc_mr_0,
  213. u32 sdrc_rfr_ctrl_1, u32 sdrc_actim_ctrl_a_1,
  214. u32 sdrc_actim_ctrl_b_1, u32 sdrc_mr_1);
  215. u32 omap3_configure_core_dpll(u32 m2, u32 unlock_dll, u32 f, u32 inc,
  216. u32 sdrc_rfr_ctrl_0, u32 sdrc_actim_ctrl_a_0,
  217. u32 sdrc_actim_ctrl_b_0, u32 sdrc_mr_0,
  218. u32 sdrc_rfr_ctrl_1, u32 sdrc_actim_ctrl_a_1,
  219. u32 sdrc_actim_ctrl_b_1, u32 sdrc_mr_1)
  220. {
  221. BUG_ON(!_omap3_sram_configure_core_dpll);
  222. return _omap3_sram_configure_core_dpll(
  223. m2, unlock_dll, f, inc,
  224. sdrc_rfr_ctrl_0, sdrc_actim_ctrl_a_0,
  225. sdrc_actim_ctrl_b_0, sdrc_mr_0,
  226. sdrc_rfr_ctrl_1, sdrc_actim_ctrl_a_1,
  227. sdrc_actim_ctrl_b_1, sdrc_mr_1);
  228. }
  229. void omap3_sram_restore_context(void)
  230. {
  231. omap_sram_reset();
  232. _omap3_sram_configure_core_dpll =
  233. omap_sram_push(omap3_sram_configure_core_dpll,
  234. omap3_sram_configure_core_dpll_sz);
  235. omap_push_sram_idle();
  236. }
  237. static inline int omap34xx_sram_init(void)
  238. {
  239. omap3_sram_restore_context();
  240. return 0;
  241. }
  242. #else
  243. static inline int omap34xx_sram_init(void)
  244. {
  245. return 0;
  246. }
  247. #endif /* CONFIG_ARCH_OMAP3 */
  248. static inline int am33xx_sram_init(void)
  249. {
  250. return 0;
  251. }
  252. int __init omap_sram_init(void)
  253. {
  254. omap_detect_sram();
  255. omap2_map_sram();
  256. if (cpu_is_omap242x())
  257. omap242x_sram_init();
  258. else if (cpu_is_omap2430())
  259. omap243x_sram_init();
  260. else if (soc_is_am33xx())
  261. am33xx_sram_init();
  262. else if (cpu_is_omap34xx())
  263. omap34xx_sram_init();
  264. return 0;
  265. }