ddr-gen1.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 *)CFG_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. extern void dma_init(void);
  57. extern uint dma_check(void);
  58. extern int dma_xfer(void *dest, uint count, void *src);
  59. /*
  60. * Initialize all of memory for ECC, then enable errors.
  61. */
  62. void
  63. ddr_enable_ecc(unsigned int dram_size)
  64. {
  65. uint *p = 0;
  66. uint i = 0;
  67. volatile ccsr_ddr_t *ddr= (void *)(CFG_MPC85xx_DDR_ADDR);
  68. dma_init();
  69. for (*p = 0; p < (uint *)(8 * 1024); p++) {
  70. if (((unsigned int)p & 0x1f) == 0) {
  71. ppcDcbz((unsigned long) p);
  72. }
  73. *p = (unsigned int)CONFIG_MEM_INIT_VALUE;
  74. if (((unsigned int)p & 0x1c) == 0x1c) {
  75. ppcDcbf((unsigned long) p);
  76. }
  77. }
  78. dma_xfer((uint *)0x002000, 0x002000, (uint *)0); /* 8K */
  79. dma_xfer((uint *)0x004000, 0x004000, (uint *)0); /* 16K */
  80. dma_xfer((uint *)0x008000, 0x008000, (uint *)0); /* 32K */
  81. dma_xfer((uint *)0x010000, 0x010000, (uint *)0); /* 64K */
  82. dma_xfer((uint *)0x020000, 0x020000, (uint *)0); /* 128k */
  83. dma_xfer((uint *)0x040000, 0x040000, (uint *)0); /* 256k */
  84. dma_xfer((uint *)0x080000, 0x080000, (uint *)0); /* 512k */
  85. dma_xfer((uint *)0x100000, 0x100000, (uint *)0); /* 1M */
  86. dma_xfer((uint *)0x200000, 0x200000, (uint *)0); /* 2M */
  87. dma_xfer((uint *)0x400000, 0x400000, (uint *)0); /* 4M */
  88. for (i = 1; i < dram_size / 0x800000; i++) {
  89. dma_xfer((uint *)(0x800000*i), 0x800000, (uint *)0);
  90. }
  91. /*
  92. * Enable errors for ECC.
  93. */
  94. debug("DMA DDR: err_disable = 0x%08x\n", ddr->err_disable);
  95. ddr->err_disable = 0x00000000;
  96. asm("sync;isync;msync");
  97. debug("DMA DDR: err_disable = 0x%08x\n", ddr->err_disable);
  98. }
  99. #endif /* CONFIG_DDR_ECC && ! CONFIG_ECC_INIT_VIA_DDRCONTROLLER */