sram.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /*
  2. * linux/arch/arm/plat-omap/sram.c
  3. *
  4. * OMAP SRAM detection and management
  5. *
  6. * Copyright (C) 2005 Nokia Corporation
  7. * Written by Tony Lindgren <tony@atomide.com>
  8. *
  9. * Copyright (C) 2009 Texas Instruments
  10. * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. */
  16. #undef DEBUG
  17. #include <linux/module.h>
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/io.h>
  21. #include <asm/tlb.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/mach/map.h>
  24. #include <plat/sram.h>
  25. #include <plat/board.h>
  26. #include <plat/cpu.h>
  27. #include "sram.h"
  28. /* XXX These "sideways" includes are a sign that something is wrong */
  29. #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
  30. # include "../mach-omap2/prm2xxx_3xxx.h"
  31. # include "../mach-omap2/sdrc.h"
  32. #endif
  33. #define OMAP1_SRAM_PA 0x20000000
  34. #define OMAP2_SRAM_PUB_PA (OMAP2_SRAM_PA + 0xf800)
  35. #define OMAP3_SRAM_PUB_PA (OMAP3_SRAM_PA + 0x8000)
  36. #define OMAP4_SRAM_PUB_PA (OMAP4_SRAM_PA + 0x4000)
  37. #if defined(CONFIG_ARCH_OMAP2PLUS)
  38. #define SRAM_BOOTLOADER_SZ 0x00
  39. #else
  40. #define SRAM_BOOTLOADER_SZ 0x80
  41. #endif
  42. #define OMAP24XX_VA_REQINFOPERM0 OMAP2_L3_IO_ADDRESS(0x68005048)
  43. #define OMAP24XX_VA_READPERM0 OMAP2_L3_IO_ADDRESS(0x68005050)
  44. #define OMAP24XX_VA_WRITEPERM0 OMAP2_L3_IO_ADDRESS(0x68005058)
  45. #define OMAP34XX_VA_REQINFOPERM0 OMAP2_L3_IO_ADDRESS(0x68012848)
  46. #define OMAP34XX_VA_READPERM0 OMAP2_L3_IO_ADDRESS(0x68012850)
  47. #define OMAP34XX_VA_WRITEPERM0 OMAP2_L3_IO_ADDRESS(0x68012858)
  48. #define OMAP34XX_VA_ADDR_MATCH2 OMAP2_L3_IO_ADDRESS(0x68012880)
  49. #define OMAP34XX_VA_SMS_RG_ATT0 OMAP2_L3_IO_ADDRESS(0x6C000048)
  50. #define GP_DEVICE 0x300
  51. #define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
  52. static unsigned long omap_sram_start;
  53. static void __iomem *omap_sram_base;
  54. static unsigned long omap_sram_size;
  55. static void __iomem *omap_sram_ceil;
  56. /*
  57. * Depending on the target RAMFS firewall setup, the public usable amount of
  58. * SRAM varies. The default accessible size for all device types is 2k. A GP
  59. * device allows ARM11 but not other initiators for full size. This
  60. * functionality seems ok until some nice security API happens.
  61. */
  62. static int is_sram_locked(void)
  63. {
  64. if (OMAP2_DEVICE_TYPE_GP == omap_type()) {
  65. /* RAMFW: R/W access to all initiators for all qualifier sets */
  66. if (cpu_is_omap242x()) {
  67. __raw_writel(0xFF, OMAP24XX_VA_REQINFOPERM0); /* all q-vects */
  68. __raw_writel(0xCFDE, OMAP24XX_VA_READPERM0); /* all i-read */
  69. __raw_writel(0xCFDE, OMAP24XX_VA_WRITEPERM0); /* all i-write */
  70. }
  71. if (cpu_is_omap34xx()) {
  72. __raw_writel(0xFFFF, OMAP34XX_VA_REQINFOPERM0); /* all q-vects */
  73. __raw_writel(0xFFFF, OMAP34XX_VA_READPERM0); /* all i-read */
  74. __raw_writel(0xFFFF, OMAP34XX_VA_WRITEPERM0); /* all i-write */
  75. __raw_writel(0x0, OMAP34XX_VA_ADDR_MATCH2);
  76. __raw_writel(0xFFFFFFFF, OMAP34XX_VA_SMS_RG_ATT0);
  77. }
  78. return 0;
  79. } else
  80. return 1; /* assume locked with no PPA or security driver */
  81. }
  82. /*
  83. * The amount of SRAM depends on the core type.
  84. * Note that we cannot try to test for SRAM here because writes
  85. * to secure SRAM will hang the system. Also the SRAM is not
  86. * yet mapped at this point.
  87. */
  88. static void __init omap_detect_sram(void)
  89. {
  90. if (cpu_class_is_omap2()) {
  91. if (is_sram_locked()) {
  92. if (cpu_is_omap34xx()) {
  93. omap_sram_start = OMAP3_SRAM_PUB_PA;
  94. if ((omap_type() == OMAP2_DEVICE_TYPE_EMU) ||
  95. (omap_type() == OMAP2_DEVICE_TYPE_SEC)) {
  96. omap_sram_size = 0x7000; /* 28K */
  97. } else {
  98. omap_sram_size = 0x8000; /* 32K */
  99. }
  100. } else if (cpu_is_omap44xx()) {
  101. omap_sram_start = OMAP4_SRAM_PUB_PA;
  102. omap_sram_size = 0xa000; /* 40K */
  103. } else {
  104. omap_sram_start = OMAP2_SRAM_PUB_PA;
  105. omap_sram_size = 0x800; /* 2K */
  106. }
  107. } else {
  108. if (cpu_is_omap34xx()) {
  109. omap_sram_start = OMAP3_SRAM_PA;
  110. omap_sram_size = 0x10000; /* 64K */
  111. } else if (cpu_is_omap44xx()) {
  112. omap_sram_start = OMAP4_SRAM_PA;
  113. omap_sram_size = 0xe000; /* 56K */
  114. } else {
  115. omap_sram_start = OMAP2_SRAM_PA;
  116. if (cpu_is_omap242x())
  117. omap_sram_size = 0xa0000; /* 640K */
  118. else if (cpu_is_omap243x())
  119. omap_sram_size = 0x10000; /* 64K */
  120. }
  121. }
  122. } else {
  123. omap_sram_start = OMAP1_SRAM_PA;
  124. if (cpu_is_omap7xx())
  125. omap_sram_size = 0x32000; /* 200K */
  126. else if (cpu_is_omap15xx())
  127. omap_sram_size = 0x30000; /* 192K */
  128. else if (cpu_is_omap1610() || cpu_is_omap1621() ||
  129. cpu_is_omap1710())
  130. omap_sram_size = 0x4000; /* 16K */
  131. else if (cpu_is_omap1611())
  132. omap_sram_size = SZ_256K;
  133. else {
  134. pr_err("Could not detect SRAM size\n");
  135. omap_sram_size = 0x4000;
  136. }
  137. }
  138. }
  139. /*
  140. * Note that we cannot use ioremap for SRAM, as clock init needs SRAM early.
  141. */
  142. static void __init omap_map_sram(void)
  143. {
  144. int cached = 1;
  145. if (omap_sram_size == 0)
  146. return;
  147. if (cpu_is_omap34xx()) {
  148. /*
  149. * SRAM must be marked as non-cached on OMAP3 since the
  150. * CORE DPLL M2 divider change code (in SRAM) runs with the
  151. * SDRAM controller disabled, and if it is marked cached,
  152. * the ARM may attempt to write cache lines back to SDRAM
  153. * which will cause the system to hang.
  154. */
  155. cached = 0;
  156. }
  157. omap_sram_start = ROUND_DOWN(omap_sram_start, PAGE_SIZE);
  158. omap_sram_base = __arm_ioremap_exec(omap_sram_start, omap_sram_size,
  159. cached);
  160. if (!omap_sram_base) {
  161. pr_err("SRAM: Could not map\n");
  162. return;
  163. }
  164. omap_sram_ceil = omap_sram_base + omap_sram_size;
  165. /*
  166. * Looks like we need to preserve some bootloader code at the
  167. * beginning of SRAM for jumping to flash for reboot to work...
  168. */
  169. memset((void *)omap_sram_base + SRAM_BOOTLOADER_SZ, 0,
  170. omap_sram_size - SRAM_BOOTLOADER_SZ);
  171. }
  172. /*
  173. * Memory allocator for SRAM: calculates the new ceiling address
  174. * for pushing a function using the fncpy API.
  175. *
  176. * Note that fncpy requires the returned address to be aligned
  177. * to an 8-byte boundary.
  178. */
  179. void *omap_sram_push_address(unsigned long size)
  180. {
  181. unsigned long available, new_ceil = (unsigned long)omap_sram_ceil;
  182. available = omap_sram_ceil - (omap_sram_base + SRAM_BOOTLOADER_SZ);
  183. if (size > available) {
  184. pr_err("Not enough space in SRAM\n");
  185. return NULL;
  186. }
  187. new_ceil -= size;
  188. new_ceil = ROUND_DOWN(new_ceil, FNCPY_ALIGN);
  189. omap_sram_ceil = IOMEM(new_ceil);
  190. return (void *)omap_sram_ceil;
  191. }
  192. #ifdef CONFIG_ARCH_OMAP1
  193. static void (*_omap_sram_reprogram_clock)(u32 dpllctl, u32 ckctl);
  194. void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl)
  195. {
  196. BUG_ON(!_omap_sram_reprogram_clock);
  197. _omap_sram_reprogram_clock(dpllctl, ckctl);
  198. }
  199. static int __init omap1_sram_init(void)
  200. {
  201. _omap_sram_reprogram_clock =
  202. omap_sram_push(omap1_sram_reprogram_clock,
  203. omap1_sram_reprogram_clock_sz);
  204. return 0;
  205. }
  206. #else
  207. #define omap1_sram_init() do {} while (0)
  208. #endif
  209. #if defined(CONFIG_ARCH_OMAP2)
  210. static void (*_omap2_sram_ddr_init)(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
  211. u32 base_cs, u32 force_unlock);
  212. void omap2_sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
  213. u32 base_cs, u32 force_unlock)
  214. {
  215. BUG_ON(!_omap2_sram_ddr_init);
  216. _omap2_sram_ddr_init(slow_dll_ctrl, fast_dll_ctrl,
  217. base_cs, force_unlock);
  218. }
  219. static void (*_omap2_sram_reprogram_sdrc)(u32 perf_level, u32 dll_val,
  220. u32 mem_type);
  221. void omap2_sram_reprogram_sdrc(u32 perf_level, u32 dll_val, u32 mem_type)
  222. {
  223. BUG_ON(!_omap2_sram_reprogram_sdrc);
  224. _omap2_sram_reprogram_sdrc(perf_level, dll_val, mem_type);
  225. }
  226. static u32 (*_omap2_set_prcm)(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass);
  227. u32 omap2_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass)
  228. {
  229. BUG_ON(!_omap2_set_prcm);
  230. return _omap2_set_prcm(dpll_ctrl_val, sdrc_rfr_val, bypass);
  231. }
  232. #endif
  233. #ifdef CONFIG_SOC_OMAP2420
  234. static int __init omap242x_sram_init(void)
  235. {
  236. _omap2_sram_ddr_init = omap_sram_push(omap242x_sram_ddr_init,
  237. omap242x_sram_ddr_init_sz);
  238. _omap2_sram_reprogram_sdrc = omap_sram_push(omap242x_sram_reprogram_sdrc,
  239. omap242x_sram_reprogram_sdrc_sz);
  240. _omap2_set_prcm = omap_sram_push(omap242x_sram_set_prcm,
  241. omap242x_sram_set_prcm_sz);
  242. return 0;
  243. }
  244. #else
  245. static inline int omap242x_sram_init(void)
  246. {
  247. return 0;
  248. }
  249. #endif
  250. #ifdef CONFIG_SOC_OMAP2430
  251. static int __init omap243x_sram_init(void)
  252. {
  253. _omap2_sram_ddr_init = omap_sram_push(omap243x_sram_ddr_init,
  254. omap243x_sram_ddr_init_sz);
  255. _omap2_sram_reprogram_sdrc = omap_sram_push(omap243x_sram_reprogram_sdrc,
  256. omap243x_sram_reprogram_sdrc_sz);
  257. _omap2_set_prcm = omap_sram_push(omap243x_sram_set_prcm,
  258. omap243x_sram_set_prcm_sz);
  259. return 0;
  260. }
  261. #else
  262. static inline int omap243x_sram_init(void)
  263. {
  264. return 0;
  265. }
  266. #endif
  267. #ifdef CONFIG_ARCH_OMAP3
  268. static u32 (*_omap3_sram_configure_core_dpll)(
  269. u32 m2, u32 unlock_dll, u32 f, u32 inc,
  270. u32 sdrc_rfr_ctrl_0, u32 sdrc_actim_ctrl_a_0,
  271. u32 sdrc_actim_ctrl_b_0, u32 sdrc_mr_0,
  272. u32 sdrc_rfr_ctrl_1, u32 sdrc_actim_ctrl_a_1,
  273. u32 sdrc_actim_ctrl_b_1, u32 sdrc_mr_1);
  274. u32 omap3_configure_core_dpll(u32 m2, u32 unlock_dll, u32 f, u32 inc,
  275. u32 sdrc_rfr_ctrl_0, u32 sdrc_actim_ctrl_a_0,
  276. u32 sdrc_actim_ctrl_b_0, u32 sdrc_mr_0,
  277. u32 sdrc_rfr_ctrl_1, u32 sdrc_actim_ctrl_a_1,
  278. u32 sdrc_actim_ctrl_b_1, u32 sdrc_mr_1)
  279. {
  280. BUG_ON(!_omap3_sram_configure_core_dpll);
  281. return _omap3_sram_configure_core_dpll(
  282. m2, unlock_dll, f, inc,
  283. sdrc_rfr_ctrl_0, sdrc_actim_ctrl_a_0,
  284. sdrc_actim_ctrl_b_0, sdrc_mr_0,
  285. sdrc_rfr_ctrl_1, sdrc_actim_ctrl_a_1,
  286. sdrc_actim_ctrl_b_1, sdrc_mr_1);
  287. }
  288. #ifdef CONFIG_PM
  289. void omap3_sram_restore_context(void)
  290. {
  291. omap_sram_ceil = omap_sram_base + omap_sram_size;
  292. _omap3_sram_configure_core_dpll =
  293. omap_sram_push(omap3_sram_configure_core_dpll,
  294. omap3_sram_configure_core_dpll_sz);
  295. omap_push_sram_idle();
  296. }
  297. #endif /* CONFIG_PM */
  298. #endif /* CONFIG_ARCH_OMAP3 */
  299. static inline int omap34xx_sram_init(void)
  300. {
  301. #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
  302. omap3_sram_restore_context();
  303. #endif
  304. return 0;
  305. }
  306. int __init omap_sram_init(void)
  307. {
  308. omap_detect_sram();
  309. omap_map_sram();
  310. if (!(cpu_class_is_omap2()))
  311. omap1_sram_init();
  312. else if (cpu_is_omap242x())
  313. omap242x_sram_init();
  314. else if (cpu_is_omap2430())
  315. omap243x_sram_init();
  316. else if (cpu_is_omap34xx())
  317. omap34xx_sram_init();
  318. return 0;
  319. }