ddr-gen1.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 <asm/io.h>
  10. #include <asm/fsl_ddr_sdram.h>
  11. #if (CONFIG_CHIP_SELECTS_PER_CTRL > 4)
  12. #error Invalid setting for CONFIG_CHIP_SELECTS_PER_CTRL
  13. #endif
  14. void fsl_ddr_set_memctl_regs(const fsl_ddr_cfg_regs_t *regs,
  15. unsigned int ctrl_num)
  16. {
  17. unsigned int i;
  18. volatile ccsr_ddr_t *ddr = (void *)CONFIG_SYS_MPC85xx_DDR_ADDR;
  19. if (ctrl_num != 0) {
  20. printf("%s unexpected ctrl_num = %u\n", __FUNCTION__, ctrl_num);
  21. return;
  22. }
  23. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  24. if (i == 0) {
  25. out_be32(&ddr->cs0_bnds, regs->cs[i].bnds);
  26. out_be32(&ddr->cs0_config, regs->cs[i].config);
  27. } else if (i == 1) {
  28. out_be32(&ddr->cs1_bnds, regs->cs[i].bnds);
  29. out_be32(&ddr->cs1_config, regs->cs[i].config);
  30. } else if (i == 2) {
  31. out_be32(&ddr->cs2_bnds, regs->cs[i].bnds);
  32. out_be32(&ddr->cs2_config, regs->cs[i].config);
  33. } else if (i == 3) {
  34. out_be32(&ddr->cs3_bnds, regs->cs[i].bnds);
  35. out_be32(&ddr->cs3_config, regs->cs[i].config);
  36. }
  37. }
  38. out_be32(&ddr->timing_cfg_1, regs->timing_cfg_1);
  39. out_be32(&ddr->timing_cfg_2, regs->timing_cfg_2);
  40. out_be32(&ddr->sdram_mode, regs->ddr_sdram_mode);
  41. out_be32(&ddr->sdram_interval, regs->ddr_sdram_interval);
  42. #if defined(CONFIG_MPC8555) || defined(CONFIG_MPC8541)
  43. out_be32(&ddr->sdram_clk_cntl, regs->ddr_sdram_clk_cntl);
  44. #endif
  45. /*
  46. * 200 painful micro-seconds must elapse between
  47. * the DDR clock setup and the DDR config enable.
  48. */
  49. udelay(200);
  50. asm volatile("sync;isync");
  51. out_be32(&ddr->sdram_cfg, regs->ddr_sdram_cfg);
  52. asm("sync;isync;msync");
  53. udelay(500);
  54. }
  55. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  56. /*
  57. * Initialize all of memory for ECC, then enable errors.
  58. */
  59. void
  60. ddr_enable_ecc(unsigned int dram_size)
  61. {
  62. uint *p = 0;
  63. uint i = 0;
  64. volatile ccsr_ddr_t *ddr= (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
  65. for (*p = 0; p < (uint *)(8 * 1024); p++) {
  66. if (((unsigned int)p & 0x1f) == 0) {
  67. ppcDcbz((unsigned long) p);
  68. }
  69. *p = (unsigned int)CONFIG_MEM_INIT_VALUE;
  70. if (((unsigned int)p & 0x1c) == 0x1c) {
  71. ppcDcbf((unsigned long) p);
  72. }
  73. }
  74. dmacpy(0x002000, 0, 0x2000); /* 8K */
  75. dmacpy(0x004000, 0, 0x4000); /* 16K */
  76. dmacpy(0x008000, 0, 0x8000); /* 32K */
  77. dmacpy(0x010000, 0, 0x10000); /* 64K */
  78. dmacpy(0x020000, 0, 0x20000); /* 128K */
  79. dmacpy(0x040000, 0, 0x40000); /* 256K */
  80. dmacpy(0x080000, 0, 0x80000); /* 512K */
  81. dmacpy(0x100000, 0, 0x100000); /* 1M */
  82. dmacpy(0x200000, 0, 0x200000); /* 2M */
  83. dmacpy(0x400000, 0, 0x400000); /* 4M */
  84. for (i = 1; i < dram_size / 0x800000; i++)
  85. dmacpy(0x800000 *i, 0, 0x800000);
  86. /*
  87. * Enable errors for ECC.
  88. */
  89. debug("DMA DDR: err_disable = 0x%08x\n", ddr->err_disable);
  90. ddr->err_disable = 0x00000000;
  91. asm("sync;isync;msync");
  92. debug("DMA DDR: err_disable = 0x%08x\n", ddr->err_disable);
  93. }
  94. #endif /* CONFIG_DDR_ECC && ! CONFIG_ECC_INIT_VIA_DDRCONTROLLER */