sram.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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 <linux/omapfb.h>
  22. #include <asm/tlb.h>
  23. #include <asm/cacheflush.h>
  24. #include <asm/mach/map.h>
  25. #include <plat/sram.h>
  26. #include <plat/board.h>
  27. #include <plat/cpu.h>
  28. #include <plat/vram.h>
  29. #include "sram.h"
  30. #include "fb.h"
  31. #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
  32. # include "../mach-omap2/prm.h"
  33. # include "../mach-omap2/cm.h"
  34. # include "../mach-omap2/sdrc.h"
  35. #endif
  36. #define OMAP1_SRAM_PA 0x20000000
  37. #define OMAP1_SRAM_VA VMALLOC_END
  38. #define OMAP2_SRAM_PA 0x40200000
  39. #define OMAP2_SRAM_PUB_PA 0x4020f800
  40. #define OMAP2_SRAM_VA 0xfe400000
  41. #define OMAP2_SRAM_PUB_VA (OMAP2_SRAM_VA + 0x800)
  42. #define OMAP3_SRAM_PA 0x40200000
  43. #define OMAP3_SRAM_VA 0xfe400000
  44. #define OMAP3_SRAM_PUB_PA 0x40208000
  45. #define OMAP3_SRAM_PUB_VA (OMAP3_SRAM_VA + 0x8000)
  46. #define OMAP4_SRAM_PA 0x40300000
  47. #define OMAP4_SRAM_VA 0xfe400000
  48. #define OMAP4_SRAM_PUB_PA (OMAP4_SRAM_PA + 0x4000)
  49. #define OMAP4_SRAM_PUB_VA (OMAP4_SRAM_VA + 0x4000)
  50. #if defined(CONFIG_ARCH_OMAP2PLUS)
  51. #define SRAM_BOOTLOADER_SZ 0x00
  52. #else
  53. #define SRAM_BOOTLOADER_SZ 0x80
  54. #endif
  55. #define OMAP24XX_VA_REQINFOPERM0 OMAP2_L3_IO_ADDRESS(0x68005048)
  56. #define OMAP24XX_VA_READPERM0 OMAP2_L3_IO_ADDRESS(0x68005050)
  57. #define OMAP24XX_VA_WRITEPERM0 OMAP2_L3_IO_ADDRESS(0x68005058)
  58. #define OMAP34XX_VA_REQINFOPERM0 OMAP2_L3_IO_ADDRESS(0x68012848)
  59. #define OMAP34XX_VA_READPERM0 OMAP2_L3_IO_ADDRESS(0x68012850)
  60. #define OMAP34XX_VA_WRITEPERM0 OMAP2_L3_IO_ADDRESS(0x68012858)
  61. #define OMAP34XX_VA_ADDR_MATCH2 OMAP2_L3_IO_ADDRESS(0x68012880)
  62. #define OMAP34XX_VA_SMS_RG_ATT0 OMAP2_L3_IO_ADDRESS(0x6C000048)
  63. #define GP_DEVICE 0x300
  64. #define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
  65. static unsigned long omap_sram_start;
  66. static unsigned long omap_sram_base;
  67. static unsigned long omap_sram_size;
  68. static unsigned long omap_sram_ceil;
  69. /*
  70. * Depending on the target RAMFS firewall setup, the public usable amount of
  71. * SRAM varies. The default accessible size for all device types is 2k. A GP
  72. * device allows ARM11 but not other initiators for full size. This
  73. * functionality seems ok until some nice security API happens.
  74. */
  75. static int is_sram_locked(void)
  76. {
  77. if (OMAP2_DEVICE_TYPE_GP == omap_type()) {
  78. /* RAMFW: R/W access to all initiators for all qualifier sets */
  79. if (cpu_is_omap242x()) {
  80. __raw_writel(0xFF, OMAP24XX_VA_REQINFOPERM0); /* all q-vects */
  81. __raw_writel(0xCFDE, OMAP24XX_VA_READPERM0); /* all i-read */
  82. __raw_writel(0xCFDE, OMAP24XX_VA_WRITEPERM0); /* all i-write */
  83. }
  84. if (cpu_is_omap34xx()) {
  85. __raw_writel(0xFFFF, OMAP34XX_VA_REQINFOPERM0); /* all q-vects */
  86. __raw_writel(0xFFFF, OMAP34XX_VA_READPERM0); /* all i-read */
  87. __raw_writel(0xFFFF, OMAP34XX_VA_WRITEPERM0); /* all i-write */
  88. __raw_writel(0x0, OMAP34XX_VA_ADDR_MATCH2);
  89. __raw_writel(0xFFFFFFFF, OMAP34XX_VA_SMS_RG_ATT0);
  90. }
  91. return 0;
  92. } else
  93. return 1; /* assume locked with no PPA or security driver */
  94. }
  95. /*
  96. * The amount of SRAM depends on the core type.
  97. * Note that we cannot try to test for SRAM here because writes
  98. * to secure SRAM will hang the system. Also the SRAM is not
  99. * yet mapped at this point.
  100. */
  101. static void __init omap_detect_sram(void)
  102. {
  103. unsigned long reserved;
  104. if (cpu_class_is_omap2()) {
  105. if (is_sram_locked()) {
  106. if (cpu_is_omap34xx()) {
  107. omap_sram_base = OMAP3_SRAM_PUB_VA;
  108. omap_sram_start = OMAP3_SRAM_PUB_PA;
  109. if ((omap_type() == OMAP2_DEVICE_TYPE_EMU) ||
  110. (omap_type() == OMAP2_DEVICE_TYPE_SEC)) {
  111. omap_sram_size = 0x7000; /* 28K */
  112. } else {
  113. omap_sram_size = 0x8000; /* 32K */
  114. }
  115. } else if (cpu_is_omap44xx()) {
  116. omap_sram_base = OMAP4_SRAM_PUB_VA;
  117. omap_sram_start = OMAP4_SRAM_PUB_PA;
  118. omap_sram_size = 0xa000; /* 40K */
  119. } else {
  120. omap_sram_base = OMAP2_SRAM_PUB_VA;
  121. omap_sram_start = OMAP2_SRAM_PUB_PA;
  122. omap_sram_size = 0x800; /* 2K */
  123. }
  124. } else {
  125. if (cpu_is_omap34xx()) {
  126. omap_sram_base = OMAP3_SRAM_VA;
  127. omap_sram_start = OMAP3_SRAM_PA;
  128. omap_sram_size = 0x10000; /* 64K */
  129. } else if (cpu_is_omap44xx()) {
  130. omap_sram_base = OMAP4_SRAM_VA;
  131. omap_sram_start = OMAP4_SRAM_PA;
  132. omap_sram_size = 0xe000; /* 56K */
  133. } else {
  134. omap_sram_base = OMAP2_SRAM_VA;
  135. omap_sram_start = OMAP2_SRAM_PA;
  136. if (cpu_is_omap242x())
  137. omap_sram_size = 0xa0000; /* 640K */
  138. else if (cpu_is_omap243x())
  139. omap_sram_size = 0x10000; /* 64K */
  140. }
  141. }
  142. } else {
  143. omap_sram_base = OMAP1_SRAM_VA;
  144. omap_sram_start = OMAP1_SRAM_PA;
  145. if (cpu_is_omap7xx())
  146. omap_sram_size = 0x32000; /* 200K */
  147. else if (cpu_is_omap15xx())
  148. omap_sram_size = 0x30000; /* 192K */
  149. else if (cpu_is_omap1610() || cpu_is_omap1621() ||
  150. cpu_is_omap1710())
  151. omap_sram_size = 0x4000; /* 16K */
  152. else if (cpu_is_omap1611())
  153. omap_sram_size = 0x3e800; /* 250K */
  154. else {
  155. printk(KERN_ERR "Could not detect SRAM size\n");
  156. omap_sram_size = 0x4000;
  157. }
  158. }
  159. reserved = omapfb_reserve_sram(omap_sram_start, omap_sram_base,
  160. omap_sram_size,
  161. omap_sram_start + SRAM_BOOTLOADER_SZ,
  162. omap_sram_size - SRAM_BOOTLOADER_SZ);
  163. omap_sram_size -= reserved;
  164. reserved = omap_vram_reserve_sram(omap_sram_start, omap_sram_base,
  165. omap_sram_size,
  166. omap_sram_start + SRAM_BOOTLOADER_SZ,
  167. omap_sram_size - SRAM_BOOTLOADER_SZ);
  168. omap_sram_size -= reserved;
  169. omap_sram_ceil = omap_sram_base + omap_sram_size;
  170. }
  171. static struct map_desc omap_sram_io_desc[] __initdata = {
  172. { /* .length gets filled in at runtime */
  173. .virtual = OMAP1_SRAM_VA,
  174. .pfn = __phys_to_pfn(OMAP1_SRAM_PA),
  175. .type = MT_MEMORY
  176. }
  177. };
  178. /*
  179. * Note that we cannot use ioremap for SRAM, as clock init needs SRAM early.
  180. */
  181. static void __init omap_map_sram(void)
  182. {
  183. unsigned long base;
  184. if (omap_sram_size == 0)
  185. return;
  186. if (cpu_is_omap24xx()) {
  187. omap_sram_io_desc[0].virtual = OMAP2_SRAM_VA;
  188. base = OMAP2_SRAM_PA;
  189. base = ROUND_DOWN(base, PAGE_SIZE);
  190. omap_sram_io_desc[0].pfn = __phys_to_pfn(base);
  191. }
  192. if (cpu_is_omap34xx()) {
  193. omap_sram_io_desc[0].virtual = OMAP3_SRAM_VA;
  194. base = OMAP3_SRAM_PA;
  195. base = ROUND_DOWN(base, PAGE_SIZE);
  196. omap_sram_io_desc[0].pfn = __phys_to_pfn(base);
  197. /*
  198. * SRAM must be marked as non-cached on OMAP3 since the
  199. * CORE DPLL M2 divider change code (in SRAM) runs with the
  200. * SDRAM controller disabled, and if it is marked cached,
  201. * the ARM may attempt to write cache lines back to SDRAM
  202. * which will cause the system to hang.
  203. */
  204. omap_sram_io_desc[0].type = MT_MEMORY_NONCACHED;
  205. }
  206. if (cpu_is_omap44xx()) {
  207. omap_sram_io_desc[0].virtual = OMAP4_SRAM_VA;
  208. base = OMAP4_SRAM_PA;
  209. base = ROUND_DOWN(base, PAGE_SIZE);
  210. omap_sram_io_desc[0].pfn = __phys_to_pfn(base);
  211. }
  212. omap_sram_io_desc[0].length = 1024 * 1024; /* Use section desc */
  213. iotable_init(omap_sram_io_desc, ARRAY_SIZE(omap_sram_io_desc));
  214. printk(KERN_INFO "SRAM: Mapped pa 0x%08lx to va 0x%08lx size: 0x%lx\n",
  215. __pfn_to_phys(omap_sram_io_desc[0].pfn),
  216. omap_sram_io_desc[0].virtual,
  217. omap_sram_io_desc[0].length);
  218. /*
  219. * Normally devicemaps_init() would flush caches and tlb after
  220. * mdesc->map_io(), but since we're called from map_io(), we
  221. * must do it here.
  222. */
  223. local_flush_tlb_all();
  224. flush_cache_all();
  225. /*
  226. * Looks like we need to preserve some bootloader code at the
  227. * beginning of SRAM for jumping to flash for reboot to work...
  228. */
  229. memset((void *)omap_sram_base + SRAM_BOOTLOADER_SZ, 0,
  230. omap_sram_size - SRAM_BOOTLOADER_SZ);
  231. }
  232. void * omap_sram_push(void * start, unsigned long size)
  233. {
  234. if (size > (omap_sram_ceil - (omap_sram_base + SRAM_BOOTLOADER_SZ))) {
  235. printk(KERN_ERR "Not enough space in SRAM\n");
  236. return NULL;
  237. }
  238. omap_sram_ceil -= size;
  239. omap_sram_ceil = ROUND_DOWN(omap_sram_ceil, sizeof(void *));
  240. memcpy((void *)omap_sram_ceil, start, size);
  241. flush_icache_range((unsigned long)omap_sram_ceil,
  242. (unsigned long)(omap_sram_ceil + size));
  243. return (void *)omap_sram_ceil;
  244. }
  245. #ifdef CONFIG_ARCH_OMAP1
  246. static void (*_omap_sram_reprogram_clock)(u32 dpllctl, u32 ckctl);
  247. void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl)
  248. {
  249. BUG_ON(!_omap_sram_reprogram_clock);
  250. _omap_sram_reprogram_clock(dpllctl, ckctl);
  251. }
  252. int __init omap1_sram_init(void)
  253. {
  254. _omap_sram_reprogram_clock =
  255. omap_sram_push(omap1_sram_reprogram_clock,
  256. omap1_sram_reprogram_clock_sz);
  257. return 0;
  258. }
  259. #else
  260. #define omap1_sram_init() do {} while (0)
  261. #endif
  262. #if defined(CONFIG_ARCH_OMAP2)
  263. static void (*_omap2_sram_ddr_init)(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
  264. u32 base_cs, u32 force_unlock);
  265. void omap2_sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
  266. u32 base_cs, u32 force_unlock)
  267. {
  268. BUG_ON(!_omap2_sram_ddr_init);
  269. _omap2_sram_ddr_init(slow_dll_ctrl, fast_dll_ctrl,
  270. base_cs, force_unlock);
  271. }
  272. static void (*_omap2_sram_reprogram_sdrc)(u32 perf_level, u32 dll_val,
  273. u32 mem_type);
  274. void omap2_sram_reprogram_sdrc(u32 perf_level, u32 dll_val, u32 mem_type)
  275. {
  276. BUG_ON(!_omap2_sram_reprogram_sdrc);
  277. _omap2_sram_reprogram_sdrc(perf_level, dll_val, mem_type);
  278. }
  279. static u32 (*_omap2_set_prcm)(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass);
  280. u32 omap2_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass)
  281. {
  282. BUG_ON(!_omap2_set_prcm);
  283. return _omap2_set_prcm(dpll_ctrl_val, sdrc_rfr_val, bypass);
  284. }
  285. #endif
  286. #ifdef CONFIG_ARCH_OMAP2420
  287. static int __init omap242x_sram_init(void)
  288. {
  289. _omap2_sram_ddr_init = omap_sram_push(omap242x_sram_ddr_init,
  290. omap242x_sram_ddr_init_sz);
  291. _omap2_sram_reprogram_sdrc = omap_sram_push(omap242x_sram_reprogram_sdrc,
  292. omap242x_sram_reprogram_sdrc_sz);
  293. _omap2_set_prcm = omap_sram_push(omap242x_sram_set_prcm,
  294. omap242x_sram_set_prcm_sz);
  295. return 0;
  296. }
  297. #else
  298. static inline int omap242x_sram_init(void)
  299. {
  300. return 0;
  301. }
  302. #endif
  303. #ifdef CONFIG_ARCH_OMAP2430
  304. static int __init omap243x_sram_init(void)
  305. {
  306. _omap2_sram_ddr_init = omap_sram_push(omap243x_sram_ddr_init,
  307. omap243x_sram_ddr_init_sz);
  308. _omap2_sram_reprogram_sdrc = omap_sram_push(omap243x_sram_reprogram_sdrc,
  309. omap243x_sram_reprogram_sdrc_sz);
  310. _omap2_set_prcm = omap_sram_push(omap243x_sram_set_prcm,
  311. omap243x_sram_set_prcm_sz);
  312. return 0;
  313. }
  314. #else
  315. static inline int omap243x_sram_init(void)
  316. {
  317. return 0;
  318. }
  319. #endif
  320. #ifdef CONFIG_ARCH_OMAP3
  321. static u32 (*_omap3_sram_configure_core_dpll)(
  322. u32 m2, u32 unlock_dll, u32 f, u32 inc,
  323. u32 sdrc_rfr_ctrl_0, u32 sdrc_actim_ctrl_a_0,
  324. u32 sdrc_actim_ctrl_b_0, u32 sdrc_mr_0,
  325. u32 sdrc_rfr_ctrl_1, u32 sdrc_actim_ctrl_a_1,
  326. u32 sdrc_actim_ctrl_b_1, u32 sdrc_mr_1);
  327. u32 omap3_configure_core_dpll(u32 m2, u32 unlock_dll, u32 f, u32 inc,
  328. u32 sdrc_rfr_ctrl_0, u32 sdrc_actim_ctrl_a_0,
  329. u32 sdrc_actim_ctrl_b_0, u32 sdrc_mr_0,
  330. u32 sdrc_rfr_ctrl_1, u32 sdrc_actim_ctrl_a_1,
  331. u32 sdrc_actim_ctrl_b_1, u32 sdrc_mr_1)
  332. {
  333. BUG_ON(!_omap3_sram_configure_core_dpll);
  334. return _omap3_sram_configure_core_dpll(
  335. m2, unlock_dll, f, inc,
  336. sdrc_rfr_ctrl_0, sdrc_actim_ctrl_a_0,
  337. sdrc_actim_ctrl_b_0, sdrc_mr_0,
  338. sdrc_rfr_ctrl_1, sdrc_actim_ctrl_a_1,
  339. sdrc_actim_ctrl_b_1, sdrc_mr_1);
  340. }
  341. #ifdef CONFIG_PM
  342. void omap3_sram_restore_context(void)
  343. {
  344. omap_sram_ceil = omap_sram_base + omap_sram_size;
  345. _omap3_sram_configure_core_dpll =
  346. omap_sram_push(omap3_sram_configure_core_dpll,
  347. omap3_sram_configure_core_dpll_sz);
  348. omap_push_sram_idle();
  349. }
  350. #endif /* CONFIG_PM */
  351. static int __init omap34xx_sram_init(void)
  352. {
  353. _omap3_sram_configure_core_dpll =
  354. omap_sram_push(omap3_sram_configure_core_dpll,
  355. omap3_sram_configure_core_dpll_sz);
  356. omap_push_sram_idle();
  357. return 0;
  358. }
  359. #else
  360. static inline int omap34xx_sram_init(void)
  361. {
  362. return 0;
  363. }
  364. #endif
  365. #ifdef CONFIG_ARCH_OMAP4
  366. static int __init omap44xx_sram_init(void)
  367. {
  368. printk(KERN_ERR "FIXME: %s not implemented\n", __func__);
  369. return -ENODEV;
  370. }
  371. #else
  372. static inline int omap44xx_sram_init(void)
  373. {
  374. return 0;
  375. }
  376. #endif
  377. int __init omap_sram_init(void)
  378. {
  379. omap_detect_sram();
  380. omap_map_sram();
  381. if (!(cpu_class_is_omap2()))
  382. omap1_sram_init();
  383. else if (cpu_is_omap242x())
  384. omap242x_sram_init();
  385. else if (cpu_is_omap2430())
  386. omap243x_sram_init();
  387. else if (cpu_is_omap34xx())
  388. omap34xx_sram_init();
  389. else if (cpu_is_omap44xx())
  390. omap44xx_sram_init();
  391. return 0;
  392. }