mpc837xerdb.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (C) 2007 Freescale Semiconductor, Inc.
  3. * Kevin Lam <kevin.lam@freescale.com>
  4. * Joe D'Abbraccio <joe.d'abbraccio@freescale.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. #include <common.h>
  15. #include <i2c.h>
  16. #include <asm/io.h>
  17. #include <spd_sdram.h>
  18. #if defined(CFG_DRAM_TEST)
  19. int
  20. testdram(void)
  21. {
  22. uint *pstart = (uint *) CFG_MEMTEST_START;
  23. uint *pend = (uint *) CFG_MEMTEST_END;
  24. uint *p;
  25. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  26. CFG_MEMTEST_START,
  27. CFG_MEMTEST_END);
  28. printf("DRAM test phase 1:\n");
  29. for (p = pstart; p < pend; p++)
  30. *p = 0xaaaaaaaa;
  31. for (p = pstart; p < pend; p++) {
  32. if (*p != 0xaaaaaaaa) {
  33. printf("DRAM test fails at: %08x\n", (uint) p);
  34. return 1;
  35. }
  36. }
  37. printf("DRAM test phase 2:\n");
  38. for (p = pstart; p < pend; p++)
  39. *p = 0x55555555;
  40. for (p = pstart; p < pend; p++) {
  41. if (*p != 0x55555555) {
  42. printf("DRAM test fails at: %08x\n", (uint) p);
  43. return 1;
  44. }
  45. }
  46. printf("DRAM test passed.\n");
  47. return 0;
  48. }
  49. #endif
  50. int board_early_init_f(void)
  51. {
  52. return 0;
  53. }
  54. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  55. void ddr_enable_ecc(unsigned int dram_size);
  56. #endif
  57. int fixed_sdram(void);
  58. long int initdram(int board_type)
  59. {
  60. immap_t *im = (immap_t *) CFG_IMMR;
  61. u32 msize = 0;
  62. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
  63. return -1;
  64. #if defined(CONFIG_SPD_EEPROM)
  65. msize = spd_sdram();
  66. #else
  67. msize = fixed_sdram();
  68. #endif
  69. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  70. /* Initialize DDR ECC byte */
  71. ddr_enable_ecc(msize * 1024 * 1024);
  72. #endif
  73. /* return total bus DDR size(bytes) */
  74. return (msize * 1024 * 1024);
  75. }
  76. #if !defined(CONFIG_SPD_EEPROM)
  77. /*************************************************************************
  78. * fixed sdram init -- doesn't use serial presence detect.
  79. ************************************************************************/
  80. int fixed_sdram(void)
  81. {
  82. immap_t *im = (immap_t *) CFG_IMMR;
  83. u32 msize = CFG_DDR_SIZE * 1024 * 1024;
  84. u32 msize_log2 = __ilog2(msize);
  85. im->sysconf.ddrlaw[0].bar = CFG_DDR_SDRAM_BASE >> 12;
  86. im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
  87. im->sysconf.ddrcdr = CFG_DDRCDR_VALUE;
  88. udelay(50000);
  89. im->ddr.sdram_clk_cntl = CFG_DDR_SDRAM_CLK_CNTL;
  90. udelay(1000);
  91. im->ddr.csbnds[0].csbnds = CFG_DDR_CS0_BNDS;
  92. im->ddr.cs_config[0] = CFG_DDR_CS0_CONFIG;
  93. udelay(1000);
  94. im->ddr.timing_cfg_0 = CFG_DDR_TIMING_0;
  95. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  96. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  97. im->ddr.timing_cfg_3 = CFG_DDR_TIMING_3;
  98. im->ddr.sdram_cfg = CFG_DDR_SDRAM_CFG;
  99. im->ddr.sdram_cfg2 = CFG_DDR_SDRAM_CFG2;
  100. im->ddr.sdram_mode = CFG_DDR_MODE;
  101. im->ddr.sdram_mode2 = CFG_DDR_MODE2;
  102. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  103. sync();
  104. udelay(1000);
  105. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  106. udelay(2000);
  107. return CFG_DDR_SIZE;
  108. }
  109. #endif /*!CFG_SPD_EEPROM */
  110. int checkboard(void)
  111. {
  112. puts("Board: Freescale MPC837xERDB\n");
  113. return 0;
  114. }
  115. #if defined(CONFIG_OF_BOARD_SETUP)
  116. void ft_board_setup(void *blob, bd_t *bd)
  117. {
  118. #ifdef CONFIG_PCI
  119. ft_pci_setup(blob, bd);
  120. #endif
  121. ft_cpu_setup(blob, bd);
  122. }
  123. #endif /* CONFIG_OF_BOARD_SETUP */