ddr.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright 2008 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * Version 2 as published by the Free Software Foundation.
  7. */
  8. #include <common.h>
  9. #include <i2c.h>
  10. #include <asm/fsl_ddr_sdram.h>
  11. #include <asm/fsl_ddr_dimm_params.h>
  12. void fsl_ddr_board_options(memctl_options_t *popts,
  13. dimm_params_t *pdimm,
  14. unsigned int ctrl_num)
  15. {
  16. /*
  17. * Factors to consider for clock adjust:
  18. * - number of chips on bus
  19. * - position of slot
  20. * - DDR1 vs. DDR2?
  21. * - ???
  22. *
  23. * This needs to be determined on a board-by-board basis.
  24. * 0110 3/4 cycle late
  25. * 0111 7/8 cycle late
  26. */
  27. popts->clk_adjust = 7;
  28. /*
  29. * Factors to consider for CPO:
  30. * - frequency
  31. * - ddr1 vs. ddr2
  32. */
  33. popts->cpo_override = 10;
  34. /*
  35. * Factors to consider for write data delay:
  36. * - number of DIMMs
  37. *
  38. * 1 = 1/4 clock delay
  39. * 2 = 1/2 clock delay
  40. * 3 = 3/4 clock delay
  41. * 4 = 1 clock delay
  42. * 5 = 5/4 clock delay
  43. * 6 = 3/2 clock delay
  44. */
  45. popts->write_data_delay = 3;
  46. /*
  47. * Factors to consider for half-strength driver enable:
  48. * - number of DIMMs installed
  49. */
  50. popts->half_strength_driver_enable = 0;
  51. }
  52. #ifdef CONFIG_SPD_EEPROM
  53. /*
  54. * Workaround for hardware errata. An i2c address conflict
  55. * existed on earlier boards; the workaround moved the DDR
  56. * SPD from 0x51 to 0x53. So we try and read 0x53 1st, and
  57. * if that fails, then fall back to reading at 0x51.
  58. */
  59. void get_spd(generic_spd_eeprom_t *spd, u8 i2c_address)
  60. {
  61. int ret;
  62. #ifdef ALT_SPD_EEPROM_ADDRESS
  63. if (i2c_address == SPD_EEPROM_ADDRESS) {
  64. ret = i2c_read(ALT_SPD_EEPROM_ADDRESS, 0, 1, (uchar *)spd,
  65. sizeof(generic_spd_eeprom_t));
  66. if (ret == 0)
  67. return; /* Good data at 0x53 */
  68. memset(spd, 0, sizeof(generic_spd_eeprom_t));
  69. }
  70. #endif
  71. ret = i2c_read(i2c_address, 0, 1, (uchar *)spd,
  72. sizeof(generic_spd_eeprom_t));
  73. if (ret) {
  74. printf("DDR: failed to read SPD from addr %u\n", i2c_address);
  75. memset(spd, 0, sizeof(generic_spd_eeprom_t));
  76. }
  77. }
  78. #else
  79. /*
  80. * fixed_sdram init -- doesn't use serial presence detect.
  81. * Assumes 256MB DDR2 SDRAM SODIMM, without ECC, running at DDR400 speed.
  82. */
  83. phys_size_t fixed_sdram(void)
  84. {
  85. volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
  86. out_be32(&ddr->cs0_bnds, 0x0000007f);
  87. out_be32(&ddr->cs1_bnds, 0x008000ff);
  88. out_be32(&ddr->cs2_bnds, 0x00000000);
  89. out_be32(&ddr->cs3_bnds, 0x00000000);
  90. out_be32(&ddr->cs0_config, 0x80010101);
  91. out_be32(&ddr->cs1_config, 0x80010101);
  92. out_be32(&ddr->cs2_config, 0x00000000);
  93. out_be32(&ddr->cs3_config, 0x00000000);
  94. out_be32(&ddr->timing_cfg_3, 0x00000000);
  95. out_be32(&ddr->timing_cfg_0, 0x00220802);
  96. out_be32(&ddr->timing_cfg_1, 0x38377322);
  97. out_be32(&ddr->timing_cfg_2, 0x0fa044C7);
  98. out_be32(&ddr->sdram_cfg, 0x4300C000);
  99. out_be32(&ddr->sdram_cfg_2, 0x24401000);
  100. out_be32(&ddr->sdram_mode, 0x23C00542);
  101. out_be32(&ddr->sdram_mode_2, 0x00000000);
  102. out_be32(&ddr->sdram_interval, 0x05080100);
  103. out_be32(&ddr->sdram_md_cntl, 0x00000000);
  104. out_be32(&ddr->sdram_data_init, 0x00000000);
  105. out_be32(&ddr->sdram_clk_cntl, 0x03800000);
  106. asm("sync;isync;msync");
  107. udelay(500);
  108. #ifdef CONFIG_DDR_ECC
  109. /* Enable ECC checking */
  110. out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_CONTROL | 0x20000000);
  111. #else
  112. out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_CONTROL);
  113. #endif
  114. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  115. }
  116. #endif