memory.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * linux/arch/arm/mach-omap2/memory.c
  3. *
  4. * Memory timing related functions for OMAP24XX
  5. *
  6. * Copyright (C) 2005 Texas Instruments Inc.
  7. * Richard Woodruff <r-woodruff2@ti.com>
  8. *
  9. * Copyright (C) 2005 Nokia Corporation
  10. * Tony Lindgren <tony@atomide.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. #include <linux/module.h>
  17. #include <linux/kernel.h>
  18. #include <linux/device.h>
  19. #include <linux/list.h>
  20. #include <linux/errno.h>
  21. #include <linux/delay.h>
  22. #include <linux/clk.h>
  23. #include <asm/io.h>
  24. #include <asm/arch/clock.h>
  25. #include <asm/arch/sram.h>
  26. #include "prm.h"
  27. #include "memory.h"
  28. #include "sdrc.h"
  29. unsigned long omap2_sdrc_base;
  30. unsigned long omap2_sms_base;
  31. static struct memory_timings mem_timings;
  32. static u32 curr_perf_level = CORE_CLK_SRC_DPLL_X2;
  33. u32 omap2_memory_get_slow_dll_ctrl(void)
  34. {
  35. return mem_timings.slow_dll_ctrl;
  36. }
  37. u32 omap2_memory_get_fast_dll_ctrl(void)
  38. {
  39. return mem_timings.fast_dll_ctrl;
  40. }
  41. u32 omap2_memory_get_type(void)
  42. {
  43. return mem_timings.m_type;
  44. }
  45. /*
  46. * Check the DLL lock state, and return tue if running in unlock mode.
  47. * This is needed to compensate for the shifted DLL value in unlock mode.
  48. */
  49. u32 omap2_dll_force_needed(void)
  50. {
  51. /* dlla and dllb are a set */
  52. u32 dll_state = sdrc_read_reg(SDRC_DLLA_CTRL);
  53. if ((dll_state & (1 << 2)) == (1 << 2))
  54. return 1;
  55. else
  56. return 0;
  57. }
  58. /*
  59. * 'level' is the value to store to CM_CLKSEL2_PLL.CORE_CLK_SRC.
  60. * Practical values are CORE_CLK_SRC_DPLL (for CORE_CLK = DPLL_CLK) or
  61. * CORE_CLK_SRC_DPLL_X2 (for CORE_CLK = * DPLL_CLK * 2)
  62. */
  63. u32 omap2_reprogram_sdrc(u32 level, u32 force)
  64. {
  65. u32 dll_ctrl, m_type;
  66. u32 prev = curr_perf_level;
  67. unsigned long flags;
  68. if ((curr_perf_level == level) && !force)
  69. return prev;
  70. if (level == CORE_CLK_SRC_DPLL) {
  71. dll_ctrl = omap2_memory_get_slow_dll_ctrl();
  72. } else if (level == CORE_CLK_SRC_DPLL_X2) {
  73. dll_ctrl = omap2_memory_get_fast_dll_ctrl();
  74. } else {
  75. return prev;
  76. }
  77. m_type = omap2_memory_get_type();
  78. local_irq_save(flags);
  79. __raw_writel(0xffff, OMAP24XX_PRCM_VOLTSETUP);
  80. omap2_sram_reprogram_sdrc(level, dll_ctrl, m_type);
  81. curr_perf_level = level;
  82. local_irq_restore(flags);
  83. return prev;
  84. }
  85. void omap2_init_memory_params(u32 force_lock_to_unlock_mode)
  86. {
  87. unsigned long dll_cnt;
  88. u32 fast_dll = 0;
  89. mem_timings.m_type = !((sdrc_read_reg(SDRC_MR_0) & 0x3) == 0x1); /* DDR = 1, SDR = 0 */
  90. /* 2422 es2.05 and beyond has a single SIP DDR instead of 2 like others.
  91. * In the case of 2422, its ok to use CS1 instead of CS0.
  92. */
  93. if (cpu_is_omap2422())
  94. mem_timings.base_cs = 1;
  95. else
  96. mem_timings.base_cs = 0;
  97. if (mem_timings.m_type != M_DDR)
  98. return;
  99. /* With DDR we need to determine the low frequency DLL value */
  100. if (((mem_timings.fast_dll_ctrl & (1 << 2)) == M_LOCK_CTRL))
  101. mem_timings.dll_mode = M_UNLOCK;
  102. else
  103. mem_timings.dll_mode = M_LOCK;
  104. if (mem_timings.base_cs == 0) {
  105. fast_dll = sdrc_read_reg(SDRC_DLLA_CTRL);
  106. dll_cnt = sdrc_read_reg(SDRC_DLLA_STATUS) & 0xff00;
  107. } else {
  108. fast_dll = sdrc_read_reg(SDRC_DLLB_CTRL);
  109. dll_cnt = sdrc_read_reg(SDRC_DLLB_STATUS) & 0xff00;
  110. }
  111. if (force_lock_to_unlock_mode) {
  112. fast_dll &= ~0xff00;
  113. fast_dll |= dll_cnt; /* Current lock mode */
  114. }
  115. /* set fast timings with DLL filter disabled */
  116. mem_timings.fast_dll_ctrl = (fast_dll | (3 << 8));
  117. /* No disruptions, DDR will be offline & C-ABI not followed */
  118. omap2_sram_ddr_init(&mem_timings.slow_dll_ctrl,
  119. mem_timings.fast_dll_ctrl,
  120. mem_timings.base_cs,
  121. force_lock_to_unlock_mode);
  122. mem_timings.slow_dll_ctrl &= 0xff00; /* Keep lock value */
  123. /* Turn status into unlock ctrl */
  124. mem_timings.slow_dll_ctrl |=
  125. ((mem_timings.fast_dll_ctrl & 0xF) | (1 << 2));
  126. /* 90 degree phase for anything below 133Mhz + disable DLL filter */
  127. mem_timings.slow_dll_ctrl |= ((1 << 1) | (3 << 8));
  128. }
  129. /* turn on smart idle modes for SDRAM scheduler and controller */
  130. void __init omap2_init_memory(void)
  131. {
  132. u32 l;
  133. l = sms_read_reg(SMS_SYSCONFIG);
  134. l &= ~(0x3 << 3);
  135. l |= (0x2 << 3);
  136. sms_write_reg(l, SMS_SYSCONFIG);
  137. l = sdrc_read_reg(SDRC_SYSCONFIG);
  138. l &= ~(0x3 << 3);
  139. l |= (0x2 << 3);
  140. sdrc_write_reg(l, SDRC_SYSCONFIG);
  141. }