dram.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * (C) Copyright 2011
  3. * Marvell Semiconductor <www.marvell.com>
  4. * Written-by: Lei Wen <leiwen@marvell.com>,
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  22. * MA 02110-1301 USA
  23. */
  24. #include <common.h>
  25. #include <asm/io.h>
  26. #include <asm/arch/pantheon.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. /*
  29. * Pantheon DRAM controller supports upto 8 banks
  30. * for chip select 0 and 1
  31. */
  32. /*
  33. * DDR Memory Control Registers
  34. * Refer Datasheet 4.4
  35. */
  36. struct panthddr_map_registers {
  37. u32 cs; /* Memory Address Map Register -CS */
  38. u32 pad[3];
  39. };
  40. struct panthddr_registers {
  41. u8 pad[0x100 - 0x000];
  42. struct panthddr_map_registers mmap[2];
  43. };
  44. /*
  45. * panth_sdram_base - reads SDRAM Base Address Register
  46. */
  47. u32 panth_sdram_base(int chip_sel)
  48. {
  49. struct panthddr_registers *ddr_regs =
  50. (struct panthddr_registers *)PANTHEON_DRAM_BASE;
  51. u32 result = 0;
  52. u32 CS_valid = 0x01 & readl(&ddr_regs->mmap[chip_sel].cs);
  53. if (!CS_valid)
  54. return 0;
  55. result = readl(&ddr_regs->mmap[chip_sel].cs) & 0xFF800000;
  56. return result;
  57. }
  58. /*
  59. * panth_sdram_size - reads SDRAM size
  60. */
  61. u32 panth_sdram_size(int chip_sel)
  62. {
  63. struct panthddr_registers *ddr_regs =
  64. (struct panthddr_registers *)PANTHEON_DRAM_BASE;
  65. u32 result = 0;
  66. u32 CS_valid = 0x01 & readl(&ddr_regs->mmap[chip_sel].cs);
  67. if (!CS_valid)
  68. return 0;
  69. result = readl(&ddr_regs->mmap[chip_sel].cs);
  70. result = (result >> 16) & 0xF;
  71. if (result < 0x7) {
  72. printf("Unknown DRAM Size\n");
  73. return -1;
  74. } else {
  75. return ((0x8 << (result - 0x7)) * 1024 * 1024);
  76. }
  77. }
  78. #ifndef CONFIG_SYS_BOARD_DRAM_INIT
  79. int dram_init(void)
  80. {
  81. int i;
  82. gd->ram_size = 0;
  83. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  84. gd->bd->bi_dram[i].start = panth_sdram_base(i);
  85. gd->bd->bi_dram[i].size = panth_sdram_size(i);
  86. /*
  87. * It is assumed that all memory banks are consecutive
  88. * and without gaps.
  89. * If the gap is found, ram_size will be reported for
  90. * consecutive memory only
  91. */
  92. if (gd->bd->bi_dram[i].start != gd->ram_size)
  93. break;
  94. gd->ram_size += gd->bd->bi_dram[i].size;
  95. }
  96. for (; i < CONFIG_NR_DRAM_BANKS; i++) {
  97. /*
  98. * If above loop terminated prematurely, we need to set
  99. * remaining banks' start address & size as 0. Otherwise other
  100. * u-boot functions and Linux kernel gets wrong values which
  101. * could result in crash
  102. */
  103. gd->bd->bi_dram[i].start = 0;
  104. gd->bd->bi_dram[i].size = 0;
  105. }
  106. return 0;
  107. }
  108. /*
  109. * If this function is not defined here,
  110. * board.c alters dram bank zero configuration defined above.
  111. */
  112. void dram_init_banksize(void)
  113. {
  114. dram_init();
  115. }
  116. #endif /* CONFIG_SYS_BOARD_DRAM_INIT */