sram.c 5.1 KB

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