sram.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. #define SRAM_BOOTLOADER_SZ 0x00
  31. #define OMAP24XX_VA_REQINFOPERM0 OMAP2_L3_IO_ADDRESS(0x68005048)
  32. #define OMAP24XX_VA_READPERM0 OMAP2_L3_IO_ADDRESS(0x68005050)
  33. #define OMAP24XX_VA_WRITEPERM0 OMAP2_L3_IO_ADDRESS(0x68005058)
  34. #define OMAP34XX_VA_REQINFOPERM0 OMAP2_L3_IO_ADDRESS(0x68012848)
  35. #define OMAP34XX_VA_READPERM0 OMAP2_L3_IO_ADDRESS(0x68012850)
  36. #define OMAP34XX_VA_WRITEPERM0 OMAP2_L3_IO_ADDRESS(0x68012858)
  37. #define OMAP34XX_VA_ADDR_MATCH2 OMAP2_L3_IO_ADDRESS(0x68012880)
  38. #define OMAP34XX_VA_SMS_RG_ATT0 OMAP2_L3_IO_ADDRESS(0x6C000048)
  39. #define GP_DEVICE 0x300
  40. #define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
  41. static unsigned long omap_sram_start;
  42. static unsigned long omap_sram_skip;
  43. static unsigned long omap_sram_size;
  44. /*
  45. * Depending on the target RAMFS firewall setup, the public usable amount of
  46. * SRAM varies. The default accessible size for all device types is 2k. A GP
  47. * device allows ARM11 but not other initiators for full size. This
  48. * functionality seems ok until some nice security API happens.
  49. */
  50. static int is_sram_locked(void)
  51. {
  52. if (OMAP2_DEVICE_TYPE_GP == omap_type()) {
  53. /* RAMFW: R/W access to all initiators for all qualifier sets */
  54. if (cpu_is_omap242x()) {
  55. writel_relaxed(0xFF, OMAP24XX_VA_REQINFOPERM0); /* all q-vects */
  56. writel_relaxed(0xCFDE, OMAP24XX_VA_READPERM0); /* all i-read */
  57. writel_relaxed(0xCFDE, OMAP24XX_VA_WRITEPERM0); /* all i-write */
  58. }
  59. if (cpu_is_omap34xx()) {
  60. writel_relaxed(0xFFFF, OMAP34XX_VA_REQINFOPERM0); /* all q-vects */
  61. writel_relaxed(0xFFFF, OMAP34XX_VA_READPERM0); /* all i-read */
  62. writel_relaxed(0xFFFF, OMAP34XX_VA_WRITEPERM0); /* all i-write */
  63. writel_relaxed(0x0, OMAP34XX_VA_ADDR_MATCH2);
  64. writel_relaxed(0xFFFFFFFF, OMAP34XX_VA_SMS_RG_ATT0);
  65. }
  66. return 0;
  67. } else
  68. return 1; /* assume locked with no PPA or security driver */
  69. }
  70. /*
  71. * The amount of SRAM depends on the core type.
  72. * Note that we cannot try to test for SRAM here because writes
  73. * to secure SRAM will hang the system. Also the SRAM is not
  74. * yet mapped at this point.
  75. */
  76. static void __init omap_detect_sram(void)
  77. {
  78. omap_sram_skip = SRAM_BOOTLOADER_SZ;
  79. if (is_sram_locked()) {
  80. if (cpu_is_omap34xx()) {
  81. omap_sram_start = OMAP3_SRAM_PUB_PA;
  82. if ((omap_type() == OMAP2_DEVICE_TYPE_EMU) ||
  83. (omap_type() == OMAP2_DEVICE_TYPE_SEC)) {
  84. omap_sram_size = 0x7000; /* 28K */
  85. omap_sram_skip += SZ_16K;
  86. } else {
  87. omap_sram_size = 0x8000; /* 32K */
  88. }
  89. } else {
  90. omap_sram_start = OMAP2_SRAM_PUB_PA;
  91. omap_sram_size = 0x800; /* 2K */
  92. }
  93. } else {
  94. if (cpu_is_omap34xx()) {
  95. omap_sram_start = OMAP3_SRAM_PA;
  96. omap_sram_size = 0x10000; /* 64K */
  97. } else {
  98. omap_sram_start = OMAP2_SRAM_PA;
  99. if (cpu_is_omap242x())
  100. omap_sram_size = 0xa0000; /* 640K */
  101. else if (cpu_is_omap243x())
  102. omap_sram_size = 0x10000; /* 64K */
  103. }
  104. }
  105. }
  106. /*
  107. * Note that we cannot use ioremap for SRAM, as clock init needs SRAM early.
  108. */
  109. static void __init omap2_map_sram(void)
  110. {
  111. int cached = 1;
  112. if (cpu_is_omap34xx()) {
  113. /*
  114. * SRAM must be marked as non-cached on OMAP3 since the
  115. * CORE DPLL M2 divider change code (in SRAM) runs with the
  116. * SDRAM controller disabled, and if it is marked cached,
  117. * the ARM may attempt to write cache lines back to SDRAM
  118. * which will cause the system to hang.
  119. */
  120. cached = 0;
  121. }
  122. omap_map_sram(omap_sram_start, omap_sram_size,
  123. omap_sram_skip, cached);
  124. }
  125. static void (*_omap2_sram_ddr_init)(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
  126. u32 base_cs, u32 force_unlock);
  127. void omap2_sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
  128. u32 base_cs, u32 force_unlock)
  129. {
  130. BUG_ON(!_omap2_sram_ddr_init);
  131. _omap2_sram_ddr_init(slow_dll_ctrl, fast_dll_ctrl,
  132. base_cs, force_unlock);
  133. }
  134. static void (*_omap2_sram_reprogram_sdrc)(u32 perf_level, u32 dll_val,
  135. u32 mem_type);
  136. void omap2_sram_reprogram_sdrc(u32 perf_level, u32 dll_val, u32 mem_type)
  137. {
  138. BUG_ON(!_omap2_sram_reprogram_sdrc);
  139. _omap2_sram_reprogram_sdrc(perf_level, dll_val, mem_type);
  140. }
  141. static u32 (*_omap2_set_prcm)(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass);
  142. u32 omap2_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass)
  143. {
  144. BUG_ON(!_omap2_set_prcm);
  145. return _omap2_set_prcm(dpll_ctrl_val, sdrc_rfr_val, bypass);
  146. }
  147. #ifdef CONFIG_SOC_OMAP2420
  148. static int __init omap242x_sram_init(void)
  149. {
  150. _omap2_sram_ddr_init = omap_sram_push(omap242x_sram_ddr_init,
  151. omap242x_sram_ddr_init_sz);
  152. _omap2_sram_reprogram_sdrc = omap_sram_push(omap242x_sram_reprogram_sdrc,
  153. omap242x_sram_reprogram_sdrc_sz);
  154. _omap2_set_prcm = omap_sram_push(omap242x_sram_set_prcm,
  155. omap242x_sram_set_prcm_sz);
  156. return 0;
  157. }
  158. #else
  159. static inline int omap242x_sram_init(void)
  160. {
  161. return 0;
  162. }
  163. #endif
  164. #ifdef CONFIG_SOC_OMAP2430
  165. static int __init omap243x_sram_init(void)
  166. {
  167. _omap2_sram_ddr_init = omap_sram_push(omap243x_sram_ddr_init,
  168. omap243x_sram_ddr_init_sz);
  169. _omap2_sram_reprogram_sdrc = omap_sram_push(omap243x_sram_reprogram_sdrc,
  170. omap243x_sram_reprogram_sdrc_sz);
  171. _omap2_set_prcm = omap_sram_push(omap243x_sram_set_prcm,
  172. omap243x_sram_set_prcm_sz);
  173. return 0;
  174. }
  175. #else
  176. static inline int omap243x_sram_init(void)
  177. {
  178. return 0;
  179. }
  180. #endif
  181. #ifdef CONFIG_ARCH_OMAP3
  182. void omap3_sram_restore_context(void)
  183. {
  184. omap_sram_reset();
  185. omap_push_sram_idle();
  186. }
  187. static inline int omap34xx_sram_init(void)
  188. {
  189. omap3_sram_restore_context();
  190. return 0;
  191. }
  192. #else
  193. static inline int omap34xx_sram_init(void)
  194. {
  195. return 0;
  196. }
  197. #endif /* CONFIG_ARCH_OMAP3 */
  198. int __init omap_sram_init(void)
  199. {
  200. omap_detect_sram();
  201. omap2_map_sram();
  202. if (cpu_is_omap242x())
  203. omap242x_sram_init();
  204. else if (cpu_is_omap2430())
  205. omap243x_sram_init();
  206. else if (cpu_is_omap34xx())
  207. omap34xx_sram_init();
  208. return 0;
  209. }