sram.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/config.h>
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <asm/mach/map.h>
  18. #include <asm/tlb.h>
  19. #include <asm/io.h>
  20. #include <asm/cacheflush.h>
  21. #include <asm/arch/sram.h>
  22. #define OMAP1_SRAM_PA 0x20000000
  23. #define OMAP1_SRAM_VA 0xd0000000
  24. #define OMAP2_SRAM_PA 0x40200000
  25. #define OMAP2_SRAM_VA 0xd0000000
  26. #define SRAM_BOOTLOADER_SZ 0x80
  27. static unsigned long omap_sram_base;
  28. static unsigned long omap_sram_size;
  29. static unsigned long omap_sram_ceil;
  30. /*
  31. * The amount of SRAM depends on the core type.
  32. * Note that we cannot try to test for SRAM here because writes
  33. * to secure SRAM will hang the system. Also the SRAM is not
  34. * yet mapped at this point.
  35. */
  36. void __init omap_detect_sram(void)
  37. {
  38. if (!cpu_is_omap24xx())
  39. omap_sram_base = OMAP1_SRAM_VA;
  40. else
  41. omap_sram_base = OMAP2_SRAM_VA;
  42. if (cpu_is_omap730())
  43. omap_sram_size = 0x32000; /* 200K */
  44. else if (cpu_is_omap15xx())
  45. omap_sram_size = 0x30000; /* 192K */
  46. else if (cpu_is_omap1610() || cpu_is_omap1621() || cpu_is_omap1710())
  47. omap_sram_size = 0x4000; /* 16K */
  48. else if (cpu_is_omap1611())
  49. omap_sram_size = 0x3e800; /* 250K */
  50. else if (cpu_is_omap2420())
  51. omap_sram_size = 0xa0014; /* 640K */
  52. else {
  53. printk(KERN_ERR "Could not detect SRAM size\n");
  54. omap_sram_size = 0x4000;
  55. }
  56. omap_sram_ceil = omap_sram_base + omap_sram_size;
  57. }
  58. static struct map_desc omap_sram_io_desc[] __initdata = {
  59. { /* .length gets filled in at runtime */
  60. .virtual = OMAP1_SRAM_VA,
  61. .pfn = __phys_to_pfn(OMAP1_SRAM_PA),
  62. .type = MT_DEVICE
  63. }
  64. };
  65. /*
  66. * In order to use last 2kB of SRAM on 1611b, we must round the size
  67. * up to multiple of PAGE_SIZE. We cannot use ioremap for SRAM, as
  68. * clock init needs SRAM early.
  69. */
  70. void __init omap_map_sram(void)
  71. {
  72. if (omap_sram_size == 0)
  73. return;
  74. if (cpu_is_omap24xx()) {
  75. omap_sram_io_desc[0].virtual = OMAP2_SRAM_VA;
  76. omap_sram_io_desc[0].pfn = __phys_to_pfn(OMAP2_SRAM_PA);
  77. }
  78. omap_sram_io_desc[0].length = (omap_sram_size + PAGE_SIZE-1)/PAGE_SIZE;
  79. omap_sram_io_desc[0].length *= PAGE_SIZE;
  80. iotable_init(omap_sram_io_desc, ARRAY_SIZE(omap_sram_io_desc));
  81. printk(KERN_INFO "SRAM: Mapped pa 0x%08lx to va 0x%08lx size: 0x%lx\n",
  82. omap_sram_io_desc[0].pfn, omap_sram_io_desc[0].virtual,
  83. omap_sram_io_desc[0].length);
  84. /*
  85. * Normally devicemaps_init() would flush caches and tlb after
  86. * mdesc->map_io(), but since we're called from map_io(), we
  87. * must do it here.
  88. */
  89. local_flush_tlb_all();
  90. flush_cache_all();
  91. /*
  92. * Looks like we need to preserve some bootloader code at the
  93. * beginning of SRAM for jumping to flash for reboot to work...
  94. */
  95. memset((void *)omap_sram_base + SRAM_BOOTLOADER_SZ, 0,
  96. omap_sram_size - SRAM_BOOTLOADER_SZ);
  97. }
  98. void * omap_sram_push(void * start, unsigned long size)
  99. {
  100. if (size > (omap_sram_ceil - (omap_sram_base + SRAM_BOOTLOADER_SZ))) {
  101. printk(KERN_ERR "Not enough space in SRAM\n");
  102. return NULL;
  103. }
  104. omap_sram_ceil -= size;
  105. omap_sram_ceil &= ~0x3;
  106. memcpy((void *)omap_sram_ceil, start, size);
  107. return (void *)omap_sram_ceil;
  108. }
  109. static void omap_sram_error(void)
  110. {
  111. panic("Uninitialized SRAM function\n");
  112. }
  113. #ifdef CONFIG_ARCH_OMAP1
  114. static void (*_omap_sram_reprogram_clock)(u32 dpllctl, u32 ckctl);
  115. void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl)
  116. {
  117. if (!_omap_sram_reprogram_clock)
  118. omap_sram_error();
  119. return _omap_sram_reprogram_clock(dpllctl, ckctl);
  120. }
  121. int __init omap1_sram_init(void)
  122. {
  123. _omap_sram_reprogram_clock = omap_sram_push(sram_reprogram_clock,
  124. sram_reprogram_clock_sz);
  125. return 0;
  126. }
  127. #else
  128. #define omap1_sram_init() do {} while (0)
  129. #endif
  130. #ifdef CONFIG_ARCH_OMAP2
  131. static void (*_omap2_sram_ddr_init)(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
  132. u32 base_cs, u32 force_unlock);
  133. void omap2_sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
  134. u32 base_cs, u32 force_unlock)
  135. {
  136. if (!_omap2_sram_ddr_init)
  137. omap_sram_error();
  138. return _omap2_sram_ddr_init(slow_dll_ctrl, fast_dll_ctrl,
  139. base_cs, force_unlock);
  140. }
  141. static void (*_omap2_sram_reprogram_sdrc)(u32 perf_level, u32 dll_val,
  142. u32 mem_type);
  143. void omap2_sram_reprogram_sdrc(u32 perf_level, u32 dll_val, u32 mem_type)
  144. {
  145. if (!_omap2_sram_reprogram_sdrc)
  146. omap_sram_error();
  147. return _omap2_sram_reprogram_sdrc(perf_level, dll_val, mem_type);
  148. }
  149. static u32 (*_omap2_set_prcm)(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass);
  150. u32 omap2_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass)
  151. {
  152. if (!_omap2_set_prcm)
  153. omap_sram_error();
  154. return _omap2_set_prcm(dpll_ctrl_val, sdrc_rfr_val, bypass);
  155. }
  156. int __init omap2_sram_init(void)
  157. {
  158. _omap2_sram_ddr_init = omap_sram_push(sram_ddr_init, sram_ddr_init_sz);
  159. _omap2_sram_reprogram_sdrc = omap_sram_push(sram_reprogram_sdrc,
  160. sram_reprogram_sdrc_sz);
  161. _omap2_set_prcm = omap_sram_push(sram_set_prcm, sram_set_prcm_sz);
  162. return 0;
  163. }
  164. #else
  165. #define omap2_sram_init() do {} while (0)
  166. #endif
  167. int __init omap_sram_init(void)
  168. {
  169. omap_detect_sram();
  170. omap_map_sram();
  171. if (!cpu_is_omap24xx())
  172. omap1_sram_init();
  173. else
  174. omap2_sram_init();
  175. return 0;
  176. }