mpc837xemds.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C) 2007 Freescale Semiconductor, Inc.
  3. * Dave Liu <daveliu@freescale.com>
  4. *
  5. * CREDITS: Kim Phillips contribute to LIBFDT code
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. */
  12. #include <common.h>
  13. #include <i2c.h>
  14. #include <spd.h>
  15. #if defined(CONFIG_SPD_EEPROM)
  16. #include <spd_sdram.h>
  17. #endif
  18. #if defined(CONFIG_OF_FLAT_TREE)
  19. #include <ft_build.h>
  20. #elif defined(CONFIG_OF_LIBFDT)
  21. #include <libfdt.h>
  22. #endif
  23. #if defined(CONFIG_PQ_MDS_PIB)
  24. #include "../common/pq-mds-pib.h"
  25. #endif
  26. int board_early_init_f(void)
  27. {
  28. u8 *bcsr = (u8 *)CFG_BCSR;
  29. /* Enable flash write */
  30. bcsr[0x9] &= ~0x04;
  31. /* Clear all of the interrupt of BCSR */
  32. bcsr[0xe] = 0xff;
  33. return 0;
  34. }
  35. int board_early_init_r(void)
  36. {
  37. #ifdef CONFIG_PQ_MDS_PIB
  38. pib_init();
  39. #endif
  40. return 0;
  41. }
  42. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  43. extern void ddr_enable_ecc(unsigned int dram_size);
  44. #endif
  45. int fixed_sdram(void);
  46. long int initdram(int board_type)
  47. {
  48. volatile immap_t *im = (immap_t *) CFG_IMMR;
  49. u32 msize = 0;
  50. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
  51. return -1;
  52. #if defined(CONFIG_SPD_EEPROM)
  53. msize = spd_sdram();
  54. #else
  55. msize = fixed_sdram();
  56. #endif
  57. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  58. /* Initialize DDR ECC byte */
  59. ddr_enable_ecc(msize * 1024 * 1024);
  60. #endif
  61. /* return total bus DDR size(bytes) */
  62. return (msize * 1024 * 1024);
  63. }
  64. #if !defined(CONFIG_SPD_EEPROM)
  65. /*************************************************************************
  66. * fixed sdram init -- doesn't use serial presence detect.
  67. ************************************************************************/
  68. int fixed_sdram(void)
  69. {
  70. volatile immap_t *im = (immap_t *) CFG_IMMR;
  71. u32 msize = CFG_DDR_SIZE * 1024 * 1024;
  72. u32 msize_log2 = __ilog2(msize);
  73. im->sysconf.ddrlaw[0].bar = CFG_DDR_SDRAM_BASE >> 12;
  74. im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
  75. #if (CFG_DDR_SIZE != 512)
  76. #warning Currenly any ddr size other than 512 is not supported
  77. #endif
  78. im->sysconf.ddrcdr = CFG_DDRCDR_VALUE;
  79. udelay(50000);
  80. im->ddr.sdram_clk_cntl = CFG_DDR_SDRAM_CLK_CNTL;
  81. udelay(1000);
  82. im->ddr.csbnds[0].csbnds = CFG_DDR_CS0_BNDS;
  83. im->ddr.cs_config[0] = CFG_DDR_CS0_CONFIG;
  84. udelay(1000);
  85. im->ddr.timing_cfg_0 = CFG_DDR_TIMING_0;
  86. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  87. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  88. im->ddr.timing_cfg_3 = CFG_DDR_TIMING_3;
  89. im->ddr.sdram_cfg = CFG_DDR_SDRAM_CFG;
  90. im->ddr.sdram_cfg2 = CFG_DDR_SDRAM_CFG2;
  91. im->ddr.sdram_mode = CFG_DDR_MODE;
  92. im->ddr.sdram_mode2 = CFG_DDR_MODE2;
  93. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  94. __asm__ __volatile__("sync");
  95. udelay(1000);
  96. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  97. udelay(2000);
  98. return CFG_DDR_SIZE;
  99. }
  100. #endif /*!CFG_SPD_EEPROM */
  101. int checkboard(void)
  102. {
  103. puts("Board: Freescale MPC837xEMDS\n");
  104. return 0;
  105. }
  106. #if defined(CONFIG_OF_BOARD_SETUP)
  107. void ft_board_setup(void *blob, bd_t *bd)
  108. {
  109. #if defined(CONFIG_OF_FLAT_TREE)
  110. u32 *p;
  111. int len;
  112. p = ft_get_prop(blob, "/memory/reg", &len);
  113. if (p != NULL) {
  114. *p++ = cpu_to_be32(bd->bi_memstart);
  115. *p = cpu_to_be32(bd->bi_memsize);
  116. }
  117. #endif
  118. ft_cpu_setup(blob, bd);
  119. #ifdef CONFIG_PCI
  120. ft_pci_setup(blob, bd);
  121. #endif
  122. }
  123. #endif /* CONFIG_OF_BOARD_SETUP */