]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/ppc4xx/ecc.c
ppc4xx: Enable Primordial Stack for 40x and Unify ECC Handling
[karo-tx-uboot.git] / cpu / ppc4xx / ecc.c
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
39 #include <common.h>
40 #include <ppc4xx.h>
41 #include <ppc_asm.tmpl>
42 #include <ppc_defs.h>
43 #include <asm/processor.h>
44 #include <asm/io.h>
45
46 #include "ecc.h"
47
48 #if !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX)
49 #if defined(CONFIG_DDR_ECC) || defined(CONFIG_SDRAM_ECC)
50 /*
51  *  void ecc_init()
52  *
53  *  Description:
54  *    This routine initializes a range of DRAM ECC memory with known
55  *    data and enables ECC checking.
56  *
57  *  TO DO:
58  *    - Improve performance by utilizing cache.
59  *    - Further generalize to make usable by other 4xx variants (e.g.
60  *      440EPx, et al).
61  *
62  *  Input(s):
63  *    start - A pointer to the start of memory covered by ECC requiring
64  *            initialization.
65  *    size  - The size, in bytes, of the memory covered by ECC requiring
66  *            initialization.
67  *
68  *  Output(s):
69  *    start - A pointer to the start of memory covered by ECC with
70  *            CFG_ECC_PATTERN written to all locations and ECC data
71  *            primed.
72  *
73  *  Returns:
74  *    N/A
75  */
76 void ecc_init(unsigned long * const start, unsigned long size)
77 {
78         const unsigned long pattern = CFG_ECC_PATTERN;
79         unsigned * const end = (unsigned long * const)((long)start + size);
80         unsigned long * current = start;
81         unsigned long mcopt1;
82         long increment;
83
84         if (start >= end)
85                 return;
86
87         mfsdram(SDRAM_MCOPT1, mcopt1);
88
89         /* Enable ECC generation without checking or reporting */
90
91         mtsdram(SDRAM_MCOPT1, ((mcopt1 & ~SDRAM_MCOPT1_MCHK_MASK) |
92                                SDRAM_MCOPT1_MCHK_GEN));
93
94         increment = sizeof(u32);
95
96 #if defined(CONFIG_440)
97         /*
98          * Look at the geometry of SDRAM (data width) to determine whether we
99          * can skip words when writing.
100          */
101
102         if ((mcopt1 & SDRAM_MCOPT1_DMWD_MASK) != SDRAM_MCOPT1_DMWD_32)
103                 increment = sizeof(u64);
104 #endif /* defined(CONFIG_440) */
105
106         while (current < end) {
107                 *current = pattern;
108                  current = (unsigned long *)((long)current + increment);
109         }
110
111         /* Wait until the writes are finished. */
112
113         sync();
114
115         /* Enable ECC generation with checking and no reporting */
116
117         mtsdram(SDRAM_MCOPT1, ((mcopt1 & ~SDRAM_MCOPT1_MCHK_MASK) |
118                                SDRAM_MCOPT1_MCHK_CHK));
119 }
120 #endif /* defined(CONFIG_DDR_ECC) || defined(CONFIG_SDRAM_ECC) */
121 #endif /* !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) */