sram.c 11 KB

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