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