Add initial support for MPC8349E MDS board.
[platform/kernel/u-boot.git] / board / mpc8349emds / mpc8349emds.c
1 /*
2  * (C) Copyright 2006
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  *
23  */
24
25 #include <common.h>
26 #include <ioports.h>
27 #include <mpc83xx.h>
28 #include <asm/mpc8349_pci.h>
29 #include <i2c.h>
30 #include <spd.h>
31 #include <miiphy.h>
32 #if defined(CONFIG_PCI)
33 #include <pci.h>
34 #endif
35 #if defined(CONFIG_SPD_EEPROM)
36 #include <spd_sdram.h>
37 #endif
38 int fixed_sdram(void);
39 void sdram_init(void);
40
41 #if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83XX)
42 void ddr_enable_ecc(unsigned int dram_size);
43 #endif
44
45 int board_early_init_f (void)
46 {
47         volatile u8* bcsr = (volatile u8*)CFG_BCSR;
48
49         /* Enable flash write */
50         bcsr[1] &= ~0x01;
51
52         return 0;
53 }
54
55 #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
56
57 long int initdram (int board_type)
58 {
59         volatile immap_t *im = (immap_t *)CFG_IMMRBAR;
60         u32 msize = 0;
61
62         if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
63                 return -1;
64
65         /* DDR SDRAM - Main SODIMM */
66         im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
67 #if defined(CONFIG_SPD_EEPROM)
68
69         msize = spd_sdram(0);
70 #else
71         msize = fixed_sdram();
72 #endif
73         /*
74          * Initialize SDRAM if it is on local bus.
75          */
76         sdram_init();
77
78 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
79         /*
80          * Initialize and enable DDR ECC.
81          */
82         ddr_enable_ecc(msize * 1024 * 1024);
83 #endif
84         puts("   DDR RAM: ");
85         /* return total bus SDRAM size(bytes)  -- DDR */
86         return (msize * 1024 * 1024);
87 }
88
89 #if !defined(CONFIG_SPD_EEPROM)
90 /*************************************************************************
91  *  fixed sdram init -- doesn't use serial presence detect.
92  ************************************************************************/
93 int fixed_sdram(void)
94 {
95         volatile immap_t *im = (immap_t *)CFG_IMMRBAR;
96         u32 msize = 0;
97         u32 ddr_size;
98         u32 ddr_size_log2;
99
100         msize = CFG_DDR_SIZE;
101         for (ddr_size = msize << 20, ddr_size_log2 = 0;
102              (ddr_size > 1);
103              ddr_size = ddr_size>>1, ddr_size_log2++) {
104                 if (ddr_size & 1) {
105                         return -1;
106                 }
107         }
108         im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
109 #if (CFG_DDR_SIZE != 256)
110 #warning Currenly any ddr size other than 256 is not supported
111 #endif
112
113         im->ddr.csbnds[0].csbnds = 0x00100017;
114         im->ddr.csbnds[1].csbnds = 0x0018001f;
115         im->ddr.csbnds[2].csbnds = 0x00000007;
116         im->ddr.csbnds[3].csbnds = 0x0008000f;
117         im->ddr.cs_config[0] = CFG_DDR_CONFIG;
118         im->ddr.cs_config[1] = CFG_DDR_CONFIG;
119         im->ddr.cs_config[2] = CFG_DDR_CONFIG;
120         im->ddr.cs_config[3] = CFG_DDR_CONFIG;
121         im->ddr.timing_cfg_1 =
122                 3 << TIMING_CFG1_PRETOACT_SHIFT |
123                 7 << TIMING_CFG1_ACTTOPRE_SHIFT |
124                 3 << TIMING_CFG1_ACTTORW_SHIFT  |
125                 4 << TIMING_CFG1_CASLAT_SHIFT   |
126                 3 << TIMING_CFG1_REFREC_SHIFT   |
127                 3 << TIMING_CFG1_WRREC_SHIFT    |
128                 2 << TIMING_CFG1_ACTTOACT_SHIFT |
129                 1 << TIMING_CFG1_WRTORD_SHIFT;
130         im->ddr.timing_cfg_2 = 2 << TIMING_CFG2_WR_DATA_DELAY_SHIFT;
131         im->ddr.sdram_cfg =
132                 SDRAM_CFG_SREN
133 #if defined(CONFIG_DDR_2T_TIMING)
134                 | SDRAM_CFG_2T_EN
135 #endif
136                 | 2 << SDRAM_CFG_SDRAM_TYPE_SHIFT;
137         im->ddr.sdram_mode =
138                 0x2000 << SDRAM_MODE_ESD_SHIFT |
139                 0x0162 << SDRAM_MODE_SD_SHIFT;
140
141         im->ddr.sdram_interval = 0x045B << SDRAM_INTERVAL_REFINT_SHIFT |
142                 0x0100 << SDRAM_INTERVAL_BSTOPRE_SHIFT;
143         udelay(200);
144
145         im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
146
147         return msize;
148 }
149 #endif/*!CFG_SPD_EEPROM*/
150
151
152 int checkboard (void)
153 {
154         puts("Board: Freescale MPC8349EMDS\n");
155         return 0;
156 }
157
158 #if defined(CONFIG_PCI)
159 /*
160  * Initialize PCI Devices, report devices found
161  */
162 #ifndef CONFIG_PCI_PNP
163 static struct pci_config_table pci_mpc8349emds_config_table[] = {
164         {PCI_ANY_ID,PCI_ANY_ID,PCI_ANY_ID,PCI_ANY_ID,
165         pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
166                                     PCI_ENET0_MEMADDR,
167                                     PCI_COMMON_MEMORY | PCI_COMMAND_MASTER
168         } },
169         {}
170 }
171 #endif
172
173 volatile static struct pci_controller hose[] = {
174         {
175 #ifndef CONFIG_PCI_PNP
176         config_table:pci_mpc8349emds_config_table,
177 #endif
178         },
179         {
180 #ifndef CONFIG_PCI_PNP
181         config_table:pci_mpc8349emds_config_table,
182 #endif
183         }
184 };
185 #endif /* CONFIG_PCI */
186
187 void pci_init_board(void)
188 {
189 #ifdef CONFIG_PCI
190         extern void pci_mpc83xx_init(volatile struct pci_controller *hose);
191
192         pci_mpc83xx_init(hose);
193 #endif /* CONFIG_PCI */
194 }
195
196 /*
197  * if MPC8349EMDS is soldered with SDRAM
198  */
199 #if defined(CFG_BR2_PRELIM)  \
200         && defined(CFG_OR2_PRELIM) \
201         && defined(CFG_LBLAWBAR2_PRELIM) \
202         && defined(CFG_LBLAWAR2_PRELIM)
203 /*
204  * Initialize SDRAM memory on the Local Bus.
205  */
206
207 void sdram_init(void)
208 {
209         volatile immap_t *immap = (immap_t *)CFG_IMMRBAR;
210         volatile lbus8349_t *lbc= &immap->lbus;
211         uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
212
213         puts("\n   SDRAM on Local Bus: ");
214         print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
215
216         /*
217          * Setup SDRAM Base and Option Registers, already done in cpu_init.c
218          */
219
220         /* setup mtrpt, lsrt and lbcr for LB bus */
221         lbc->lbcr = CFG_LBC_LBCR;
222         lbc->mrtpr = CFG_LBC_MRTPR;
223         lbc->lsrt = CFG_LBC_LSRT;
224         asm("sync");
225
226         /*
227          * Configure the SDRAM controller Machine Mode Register.
228          */
229         lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
230
231         lbc->lsdmr = CFG_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */
232         asm("sync");
233         *sdram_addr = 0xff;
234         udelay(100);
235
236         lbc->lsdmr = CFG_LBC_LSDMR_2; /* 0x48636733; auto refresh */
237         asm("sync");
238         /*1 times*/
239         *sdram_addr = 0xff;
240         udelay(100);
241         /*2 times*/
242         *sdram_addr = 0xff;
243         udelay(100);
244         /*3 times*/
245         *sdram_addr = 0xff;
246         udelay(100);
247         /*4 times*/
248         *sdram_addr = 0xff;
249         udelay(100);
250         /*5 times*/
251         *sdram_addr = 0xff;
252         udelay(100);
253         /*6 times*/
254         *sdram_addr = 0xff;
255         udelay(100);
256         /*7 times*/
257         *sdram_addr = 0xff;
258         udelay(100);
259         /*8 times*/
260         *sdram_addr = 0xff;
261         udelay(100);
262
263         /* 0x58636733; mode register write operation */
264         lbc->lsdmr = CFG_LBC_LSDMR_4;
265         asm("sync");
266         *sdram_addr = 0xff;
267         udelay(100);
268
269         lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
270         asm("sync");
271         *sdram_addr = 0xff;
272         udelay(100);
273 }
274 #else
275 void sdram_init(void)
276 {
277         put("SDRAM on Local Bus is NOT available!\n");
278 }
279 #endif