dram.c 3.3 KB

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