2 * Copyright (c) 2008 Nuovation System Designs, LLC
3 * Grant Erickson <gerickson@nuovations.com>
5 * (C) Copyright 2007-2008
6 * Stefan Roese, DENX Software Engineering, sr@denx.de.
8 * Originally based on code provided from UDTech and AMCC
10 * See file CREDITS for list of people who contributed to this
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 #include <ppc_asm.tmpl>
35 #define mtsdram_as(reg, value) \
38 addis r4,0,value@h ; \
42 #if defined(CONFIG_DDR_ECC)
44 #endif /* defined(CONFIG_DDR_ECC) */
46 .globl ext_bus_cntlr_init
48 #if !defined(CFG_INIT_DCACHE_CS)
49 #if !defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
52 * DDR2 SDRAM Controller Setup
55 /* Set Memory Bank Configuration Registers */
56 mtsdram_as(SDRAM_MB0CF, CFG_SDRAM0_MB0CF);
57 mtsdram_as(SDRAM_MB1CF, CFG_SDRAM0_MB1CF);
58 mtsdram_as(SDRAM_MB2CF, CFG_SDRAM0_MB2CF);
59 mtsdram_as(SDRAM_MB3CF, CFG_SDRAM0_MB3CF);
61 /* Set Memory Clock Timing Register */
62 mtsdram_as(SDRAM_CLKTR, CFG_SDRAM0_CLKTR);
64 /* Set Refresh Time Register */
65 mtsdram_as(SDRAM_RTR, CFG_SDRAM0_RTR);
67 /* Set SDRAM Timing Registers */
68 mtsdram_as(SDRAM_SDTR1, CFG_SDRAM0_SDTR1);
69 mtsdram_as(SDRAM_SDTR2, CFG_SDRAM0_SDTR2);
70 mtsdram_as(SDRAM_SDTR3, CFG_SDRAM0_SDTR3);
72 /* Set Mode and Extended Mode Registers */
73 mtsdram_as(SDRAM_MMODE, CFG_SDRAM0_MMODE);
74 mtsdram_as(SDRAM_MEMODE, CFG_SDRAM0_MEMODE);
76 /* Set Memory Controller Options 1 Register */
77 mtsdram_as(SDRAM_MCOPT1, CFG_SDRAM0_MCOPT1);
79 /* Set Manual Initialization Control Registers */
80 mtsdram_as(SDRAM_INITPLR0, CFG_SDRAM0_INITPLR0);
81 mtsdram_as(SDRAM_INITPLR1, CFG_SDRAM0_INITPLR1);
82 mtsdram_as(SDRAM_INITPLR2, CFG_SDRAM0_INITPLR2);
83 mtsdram_as(SDRAM_INITPLR3, CFG_SDRAM0_INITPLR3);
84 mtsdram_as(SDRAM_INITPLR4, CFG_SDRAM0_INITPLR4);
85 mtsdram_as(SDRAM_INITPLR5, CFG_SDRAM0_INITPLR5);
86 mtsdram_as(SDRAM_INITPLR6, CFG_SDRAM0_INITPLR6);
87 mtsdram_as(SDRAM_INITPLR7, CFG_SDRAM0_INITPLR7);
88 mtsdram_as(SDRAM_INITPLR8, CFG_SDRAM0_INITPLR8);
89 mtsdram_as(SDRAM_INITPLR9, CFG_SDRAM0_INITPLR9);
90 mtsdram_as(SDRAM_INITPLR10, CFG_SDRAM0_INITPLR10);
91 mtsdram_as(SDRAM_INITPLR11, CFG_SDRAM0_INITPLR11);
92 mtsdram_as(SDRAM_INITPLR12, CFG_SDRAM0_INITPLR12);
93 mtsdram_as(SDRAM_INITPLR13, CFG_SDRAM0_INITPLR13);
94 mtsdram_as(SDRAM_INITPLR14, CFG_SDRAM0_INITPLR14);
95 mtsdram_as(SDRAM_INITPLR15, CFG_SDRAM0_INITPLR15);
97 /* Set On-Die Termination Registers */
98 mtsdram_as(SDRAM_CODT, CFG_SDRAM0_CODT);
99 mtsdram_as(SDRAM_MODT0, CFG_SDRAM0_MODT0);
100 mtsdram_as(SDRAM_MODT1, CFG_SDRAM0_MODT1);
102 /* Set Write Timing Register */
103 mtsdram_as(SDRAM_WRDTR, CFG_SDRAM0_WRDTR);
106 * Start Initialization by SDRAM0_MCOPT2[SREN] = 0 and
107 * SDRAM0_MCOPT2[IPTR] = 1
109 mtsdram_as(SDRAM_MCOPT2, SDRAM_MCOPT2_SREN_EXIT | \
110 SDRAM_MCOPT2_IPTR_EXECUTE);
113 * Poll SDRAM0_MCSTAT[MIC] for assertion to indicate the
114 * completion of initialization.
117 * mfsdram(SDRAM_MCSTAT, val);
118 * } while ((val & SDRAM_MCSTAT_MIC_MASK) != SDRAM_MCSTAT_MIC_COMP);
121 lis r2,SDRAM_MCSTAT_MIC_COMP@h
122 ori r2,r2,SDRAM_MCSTAT_MIC_COMP@l
129 /* Set Delay Control Registers */
130 mtsdram_as(SDRAM_DLCR, CFG_SDRAM0_DLCR);
131 mtsdram_as(SDRAM_RDCC, CFG_SDRAM0_RDCC);
132 mtsdram_as(SDRAM_RQDC, CFG_SDRAM0_RQDC);
133 mtsdram_as(SDRAM_RFDC, CFG_SDRAM0_RFDC);
136 * Enable Controller by SDRAM0_MCOPT2[DCEN] = 1:
138 * mcopt2 = mfsdram(SDRAM_MCOPT2);
145 * mtsdram(SDRAM_MCOPT2, mcopt2 | SDRAM_MCOPT2_DCEN_ENABLE);
148 oris r3,r3,SDRAM_MCOPT2_DCEN_ENABLE@h
149 ori r3,r3,SDRAM_MCOPT2_DCEN_ENABLE@l
152 #if defined(CONFIG_DDR_ECC)
154 * ecc_init(CFG_SDRAM_BASE, CFG_MBYTES_SDRAM << 20);
157 lis r3,CFG_SDRAM_BASE@h
158 ori r3,r3,CFG_SDRAM_BASE@l
159 lis r4,(CFG_MBYTES_SDRAM << 20)@h
160 ori r4,r4,(CFG_MBYTES_SDRAM << 20)@l
163 #endif /* defined(CONFIG_DDR_ECC) */
164 #endif /* !defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL) */
165 #endif /* !defined(CFG_INIT_DCACHE_CS) */