dram.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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/arch/armada100.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. /*
  29. * ARMADA100 DRAM controller supports upto 8 banks
  30. * for chip select 0 and 1
  31. */
  32. /*
  33. * DDR Memory Control Registers
  34. * Refer Datasheet Appendix A.17
  35. */
  36. struct armd1ddr_map_registers {
  37. u32 cs; /* Memory Address Map Register -CS */
  38. u32 pad[3];
  39. };
  40. struct armd1ddr_registers {
  41. u8 pad[0x100 - 0x000];
  42. struct armd1ddr_map_registers mmap[2];
  43. };
  44. /*
  45. * armd1_sdram_base - reads SDRAM Base Address Register
  46. */
  47. u32 armd1_sdram_base(int chip_sel)
  48. {
  49. struct armd1ddr_registers *ddr_regs =
  50. (struct armd1ddr_registers *)ARMD1_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. * armd1_sdram_size - reads SDRAM size
  60. */
  61. u32 armd1_sdram_size(int chip_sel)
  62. {
  63. struct armd1ddr_registers *ddr_regs =
  64. (struct armd1ddr_registers *)ARMD1_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 = armd1_sdram_base(i);
  85. gd->bd->bi_dram[i].size = armd1_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. /* If above loop terminated prematurely, we need to set
  98. * remaining banks' start address & size as 0. Otherwise other
  99. * u-boot functions and Linux kernel gets wrong values which
  100. * could result in crash */
  101. gd->bd->bi_dram[i].start = 0;
  102. gd->bd->bi_dram[i].size = 0;
  103. }
  104. return 0;
  105. }
  106. /*
  107. * If this function is not defined here,
  108. * board.c alters dram bank zero configuration defined above.
  109. */
  110. void dram_init_banksize(void)
  111. {
  112. dram_init();
  113. }
  114. #endif /* CONFIG_SYS_BOARD_DRAM_INIT */