ecc.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2008 Nuovation System Designs, LLC
  3. * Grant Erickson <gerickson@nuovations.com>
  4. *
  5. * (C) Copyright 2005-2007
  6. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  7. *
  8. * (C) Copyright 2002
  9. * Jun Gu, Artesyn Technology, jung@artesyncp.com
  10. *
  11. * (C) Copyright 2001
  12. * Bill Hunter, Wave 7 Optics, williamhunter@attbi.com
  13. *
  14. * See file CREDITS for list of people who contributed to this
  15. * project.
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License as
  19. * published by the Free Software Foundation; either version 2 of
  20. * the License, or (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will abe useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  30. * MA 02111-1307 USA
  31. *
  32. * Description:
  33. * This file implements generic DRAM ECC initialization for
  34. * PowerPC processors using a SDRAM DDR/DDR2 controller,
  35. * including the 405EX(r), 440GP/GX/EP/GR, 440SP(E), and
  36. * 460EX/GT.
  37. */
  38. #include <common.h>
  39. #include <ppc4xx.h>
  40. #include <ppc_asm.tmpl>
  41. #include <ppc_defs.h>
  42. #include <asm/processor.h>
  43. #include <asm/io.h>
  44. #include "ecc.h"
  45. #if defined(CONFIG_SDRAM_PPC4xx_IBM_DDR) || \
  46. defined(CONFIG_SDRAM_PPC4xx_IBM_DDR2)
  47. #if defined(CONFIG_DDR_ECC) || defined(CONFIG_SDRAM_ECC)
  48. /*
  49. * void ecc_init()
  50. *
  51. * Description:
  52. * This routine initializes a range of DRAM ECC memory with known
  53. * data and enables ECC checking.
  54. *
  55. * TO DO:
  56. * - Improve performance by utilizing cache.
  57. * - Further generalize to make usable by other 4xx variants (e.g.
  58. * 440EPx, et al).
  59. *
  60. * Input(s):
  61. * start - A pointer to the start of memory covered by ECC requiring
  62. * initialization.
  63. * size - The size, in bytes, of the memory covered by ECC requiring
  64. * initialization.
  65. *
  66. * Output(s):
  67. * start - A pointer to the start of memory covered by ECC with
  68. * CONFIG_SYS_ECC_PATTERN written to all locations and ECC data
  69. * primed.
  70. *
  71. * Returns:
  72. * N/A
  73. */
  74. void ecc_init(unsigned long * const start, unsigned long size)
  75. {
  76. const unsigned long pattern = CONFIG_SYS_ECC_PATTERN;
  77. unsigned long * const end = (unsigned long * const)((long)start + size);
  78. unsigned long * current = start;
  79. unsigned long mcopt1;
  80. long increment;
  81. if (start >= end)
  82. return;
  83. mfsdram(SDRAM_ECC_CFG, mcopt1);
  84. /* Enable ECC generation without checking or reporting */
  85. mtsdram(SDRAM_ECC_CFG, ((mcopt1 & ~SDRAM_ECC_CFG_MCHK_MASK) |
  86. SDRAM_ECC_CFG_MCHK_GEN));
  87. increment = sizeof(u32);
  88. #if defined(CONFIG_440)
  89. /*
  90. * Look at the geometry of SDRAM (data width) to determine whether we
  91. * can skip words when writing.
  92. */
  93. if ((mcopt1 & SDRAM_ECC_CFG_DMWD_MASK) != SDRAM_ECC_CFG_DMWD_32)
  94. increment = sizeof(u64);
  95. #endif /* defined(CONFIG_440) */
  96. while (current < end) {
  97. *current = pattern;
  98. current = (unsigned long *)((long)current + increment);
  99. }
  100. /* Wait until the writes are finished. */
  101. sync();
  102. /* Enable ECC generation with checking and no reporting */
  103. mtsdram(SDRAM_ECC_CFG, ((mcopt1 & ~SDRAM_ECC_CFG_MCHK_MASK) |
  104. SDRAM_ECC_CFG_MCHK_CHK));
  105. }
  106. #endif /* defined(CONFIG_DDR_ECC) || defined(CONFIG_SDRAM_ECC) */
  107. #endif /* defined(CONFIG_SDRAM_PPC4xx_IBM_DDR)... */