]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/tqc/tqm8272/tqm8272.c
Merge branch 'master' of git://git.denx.de/u-boot-mips
[karo-tx-uboot.git] / board / tqc / tqm8272 / tqm8272.c
1 /*
2  * (C) Copyright 2006
3  * Heiko Schocher, DENX Software Engineering, hs@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 #include <common.h>
25 #include <ioports.h>
26 #include <mpc8260.h>
27
28 #include <command.h>
29 #include <netdev.h>
30 #ifdef CONFIG_PCI
31 #include <pci.h>
32 #include <asm/m8260_pci.h>
33 #endif
34
35 #if 0
36 #define deb_printf(fmt,arg...) \
37         printf ("TQM8272 %s %s: " fmt,__FILE__, __FUNCTION__, ##arg)
38 #else
39 #define deb_printf(fmt,arg...) \
40         do { } while (0)
41 #endif
42
43 #if defined(CONFIG_BOARD_GET_CPU_CLK_F)
44 unsigned long board_get_cpu_clk_f (void);
45 #endif
46
47 /*
48  * I/O Port configuration table
49  *
50  * if conf is 1, then that port pin will be configured at boot time
51  * according to the five values podr/pdir/ppar/psor/pdat for that entry
52  */
53
54 const iop_conf_t iop_conf_tab[4][32] = {
55
56     /* Port A configuration */
57     {   /*            conf ppar psor pdir podr pdat */
58         /* PA31 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 *ATMTXEN */
59         /* PA30 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMTCA   */
60         /* PA29 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMTSOC  */
61         /* PA28 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 *ATMRXEN */
62         /* PA27 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMRSOC */
63         /* PA26 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMRCA */
64         /* PA25 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMTXD[0] */
65         /* PA24 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMTXD[1] */
66         /* PA23 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMTXD[2] */
67         /* PA22 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMTXD[3] */
68         /* PA21 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMTXD[4] */
69         /* PA20 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMTXD[5] */
70         /* PA19 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMTXD[6] */
71         /* PA18 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMTXD[7] */
72         /* PA17 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMRXD[7] */
73         /* PA16 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMRXD[6] */
74         /* PA15 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMRXD[5] */
75         /* PA14 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMRXD[4] */
76         /* PA13 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMRXD[3] */
77         /* PA12 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMRXD[2] */
78         /* PA11 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMRXD[1] */
79         /* PA10 */ {   0,   0,   0,   1,   0,   0   }, /* FCC1 ATMRXD[0] */
80         /* PA9  */ {   1,   1,   0,   1,   0,   0   }, /* SMC2 TXD */
81         /* PA8  */ {   1,   1,   0,   0,   0,   0   }, /* SMC2 RXD */
82         /* PA7  */ {   0,   0,   0,   1,   0,   0   }, /* PA7 */
83         /* PA6  */ {   0,   0,   0,   1,   0,   0   }, /* PA6 */
84         /* PA5  */ {   0,   0,   0,   1,   0,   0   }, /* PA5 */
85         /* PA4  */ {   0,   0,   0,   1,   0,   0   }, /* PA4 */
86         /* PA3  */ {   0,   0,   0,   1,   0,   0   }, /* PA3 */
87         /* PA2  */ {   0,   0,   0,   1,   0,   0   }, /* PA2 */
88         /* PA1  */ {   0,   0,   0,   1,   0,   0   }, /* PA1 */
89         /* PA0  */ {   0,   0,   0,   1,   0,   0   }  /* PA0 */
90     },
91
92     /* Port B configuration */
93     {   /*            conf ppar psor pdir podr pdat */
94         /* PB31 */ {   1,   1,   0,   1,   0,   0   }, /* FCC2 MII TX_ER */
95         /* PB30 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII RX_DV */
96         /* PB29 */ {   1,   1,   1,   1,   0,   0   }, /* FCC2 MII TX_EN */
97         /* PB28 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII RX_ER */
98         /* PB27 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII COL */
99         /* PB26 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII CRS */
100         /* PB25 */ {   1,   1,   0,   1,   0,   0   }, /* FCC2 MII TxD[3] */
101         /* PB24 */ {   1,   1,   0,   1,   0,   0   }, /* FCC2 MII TxD[2] */
102         /* PB23 */ {   1,   1,   0,   1,   0,   0   }, /* FCC2 MII TxD[1] */
103         /* PB22 */ {   1,   1,   0,   1,   0,   0   }, /* FCC2 MII TxD[0] */
104         /* PB21 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII RxD[0] */
105         /* PB20 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII RxD[1] */
106         /* PB19 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII RxD[2] */
107         /* PB18 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII RxD[3] */
108         /* PB17 */ {   0,   0,   0,   0,   0,   0   }, /* PB17 */
109         /* PB16 */ {   0,   0,   0,   0,   0,   0   }, /* PB16 */
110         /* PB15 */ {   0,   0,   0,   0,   0,   0   }, /* PB15 */
111         /* PB14 */ {   0,   0,   0,   0,   0,   0   }, /* PB14 */
112         /* PB13 */ {   0,   0,   0,   0,   0,   0   }, /* PB13 */
113         /* PB12 */ {   0,   0,   0,   0,   0,   0   }, /* PB12 */
114         /* PB11 */ {   0,   0,   0,   0,   0,   0   }, /* PB11 */
115         /* PB10 */ {   0,   0,   0,   0,   0,   0   }, /* PB10 */
116         /* PB9  */ {   0,   0,   0,   0,   0,   0   }, /* PB9 */
117         /* PB8  */ {   0,   0,   0,   0,   0,   0   }, /* PB8 */
118         /* PB7  */ {   0,   0,   0,   0,   0,   0   }, /* PB7 */
119         /* PB6  */ {   0,   0,   0,   0,   0,   0   }, /* PB6 */
120         /* PB5  */ {   0,   0,   0,   0,   0,   0   }, /* PB5 */
121         /* PB4  */ {   0,   0,   0,   0,   0,   0   }, /* PB4 */
122         /* PB3  */ {   0,   0,   0,   0,   0,   0   }, /* pin doesn't exist */
123         /* PB2  */ {   0,   0,   0,   0,   0,   0   }, /* pin doesn't exist */
124         /* PB1  */ {   0,   0,   0,   0,   0,   0   }, /* pin doesn't exist */
125         /* PB0  */ {   0,   0,   0,   0,   0,   0   }  /* pin doesn't exist */
126     },
127
128     /* Port C */
129     {   /*            conf ppar psor pdir podr pdat */
130         /* PC31 */ {   0,   0,   0,   1,   0,   0   }, /* PC31 */
131         /* PC30 */ {   0,   0,   0,   0,   0,   0   }, /* PC30 */
132         /* PC29 */ {   1,   1,   1,   0,   0,   0   }, /* SCC1 EN *CLSN */
133         /* PC28 */ {   0,   0,   0,   1,   0,   0   }, /* PC28 */
134         /* PC27 */ {   0,   0,   0,   1,   0,   0   }, /* PC27 */
135         /* PC26 */ {   0,   0,   0,   1,   0,   0   }, /* PC26 */
136         /* PC25 */ {   0,   0,   0,   1,   0,   0   }, /* PC25 */
137         /* PC24 */ {   0,   0,   0,   1,   0,   0   }, /* PC24 */
138         /* PC23 */ {   0,   1,   0,   1,   0,   0   }, /* ATMTFCLK */
139         /* PC22 */ {   0,   1,   0,   0,   0,   0   }, /* ATMRFCLK */
140         /* PC21 */ {   1,   1,   0,   0,   0,   0   }, /* SCC1 EN RXCLK */
141         /* PC20 */ {   1,   1,   0,   0,   0,   0   }, /* SCC1 EN TXCLK */
142         /* PC19 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII RX_CLK */
143         /* PC18 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII TX_CLK */
144         /* PC17 */ {   1,   0,   0,   1,   0,   0   }, /* PC17 MDC */
145         /* PC16 */ {   1,   0,   0,   0,   0,   0   }, /* PC16 MDIO*/
146         /* PC15 */ {   0,   0,   0,   1,   0,   0   }, /* PC15 */
147         /* PC14 */ {   1,   1,   0,   0,   0,   0   }, /* SCC1 EN *CD */
148         /* PC13 */ {   0,   0,   0,   1,   0,   0   }, /* PC13 */
149         /* PC12 */ {   0,   0,   0,   1,   0,   0   }, /* PC12 */
150         /* PC11 */ {   0,   0,   0,   1,   0,   0   }, /* PC11 */
151         /* PC10 */ {   0,   0,   0,   1,   0,   0   }, /* PC10 */
152         /* PC9  */ {   0,   0,   0,   1,   0,   0   }, /* PC9 */
153         /* PC8  */ {   0,   0,   0,   1,   0,   0   }, /* PC8 */
154         /* PC7  */ {   0,   0,   0,   1,   0,   0   }, /* PC7 */
155         /* PC6  */ {   0,   0,   0,   1,   0,   0   }, /* PC6 */
156         /* PC5  */ {   1,   1,   0,   1,   0,   0   }, /* PC5 SMC1 TXD */
157         /* PC4  */ {   1,   1,   0,   0,   0,   0   }, /* PC4 SMC1 RXD */
158         /* PC3  */ {   0,   0,   0,   1,   0,   0   }, /* PC3 */
159         /* PC2  */ {   0,   0,   0,   1,   0,   1   }, /* ENET FDE */
160         /* PC1  */ {   0,   0,   0,   1,   0,   0   }, /* ENET DSQE */
161         /* PC0  */ {   0,   0,   0,   1,   0,   0   }, /* ENET LBK */
162     },
163
164     /* Port D */
165     {   /*            conf ppar psor pdir podr pdat */
166         /* PD31 */ {   1,   1,   0,   0,   0,   0   }, /* SCC1 EN RxD */
167         /* PD30 */ {   1,   1,   1,   1,   0,   0   }, /* SCC1 EN TxD */
168         /* PD29 */ {   1,   1,   0,   1,   0,   0   }, /* SCC1 EN TENA */
169         /* PD28 */ {   0,   0,   0,   1,   0,   0   }, /* PD28 */
170         /* PD27 */ {   0,   0,   0,   1,   0,   0   }, /* PD27 */
171         /* PD26 */ {   0,   0,   0,   1,   0,   0   }, /* PD26 */
172         /* PD25 */ {   0,   0,   0,   1,   0,   0   }, /* PD25 */
173         /* PD24 */ {   0,   0,   0,   1,   0,   0   }, /* PD24 */
174         /* PD23 */ {   0,   0,   0,   1,   0,   0   }, /* PD23 */
175         /* PD22 */ {   0,   0,   0,   1,   0,   0   }, /* PD22 */
176         /* PD21 */ {   0,   0,   0,   1,   0,   0   }, /* PD21 */
177         /* PD20 */ {   0,   0,   0,   1,   0,   0   }, /* PD20 */
178         /* PD19 */ {   0,   0,   0,   1,   0,   0   }, /* PD19 */
179         /* PD18 */ {   0,   0,   0,   1,   0,   0   }, /* PD19 */
180         /* PD17 */ {   0,   1,   0,   0,   0,   0   }, /* FCC1 ATMRXPRTY */
181         /* PD16 */ {   0,   1,   0,   1,   0,   0   }, /* FCC1 ATMTXPRTY */
182 #if defined(CONFIG_SOFT_I2C)
183         /* PD15 */ {   1,   0,   0,   1,   1,   1   }, /* I2C SDA */
184         /* PD14 */ {   1,   0,   0,   1,   1,   1   }, /* I2C SCL */
185 #else
186 #if defined(CONFIG_HARD_I2C)
187         /* PD15 */ {   1,   1,   1,   0,   1,   0   }, /* I2C SDA */
188         /* PD14 */ {   1,   1,   1,   0,   1,   0   }, /* I2C SCL */
189 #else /* normal I/O port pins */
190         /* PD15 */ {   0,   1,   1,   0,   1,   0   }, /* I2C SDA */
191         /* PD14 */ {   0,   1,   1,   0,   1,   0   }, /* I2C SCL */
192 #endif
193 #endif
194         /* PD13 */ {   0,   0,   0,   0,   0,   0   }, /* PD13 */
195         /* PD12 */ {   0,   0,   0,   0,   0,   0   }, /* PD12 */
196         /* PD11 */ {   0,   0,   0,   0,   0,   0   }, /* PD11 */
197         /* PD10 */ {   0,   0,   0,   0,   0,   0   }, /* PD10 */
198         /* PD9  */ {   1,   1,   0,   1,   0,   0   }, /* SMC1 TXD */
199         /* PD8  */ {   1,   1,   0,   0,   0,   0   }, /* SMC1 RXD */
200         /* PD7  */ {   0,   0,   0,   1,   0,   1   }, /* PD7 */
201         /* PD6  */ {   0,   0,   0,   1,   0,   1   }, /* PD6 */
202         /* PD5  */ {   0,   0,   0,   1,   0,   0   }, /* PD5 */
203         /* PD4  */ {   0,   0,   0,   1,   0,   1   }, /* PD4 */
204         /* PD3  */ {   0,   0,   0,   0,   0,   0   }, /* pin doesn't exist */
205         /* PD2  */ {   0,   0,   0,   0,   0,   0   }, /* pin doesn't exist */
206         /* PD1  */ {   0,   0,   0,   0,   0,   0   }, /* pin doesn't exist */
207         /* PD0  */ {   0,   0,   0,   0,   0,   0   }  /* pin doesn't exist */
208     }
209 };
210
211 #define _NOT_USED_      0xFFFFFFFF
212
213 /* UPM pattern for bus clock = 66.7 MHz */
214 static const uint upmTable67[] =
215 {
216     /* Offset   UPM Read Single RAM array entry -> NAND Read Data */
217     /* 0x00 */  0x0fa3f100, 0x0fa3b000, 0x0fa33100, 0x0fa33000,
218     /* 0x04 */  0x0fa33000, 0x0fa33004, 0xfffffc01, 0xfffffc00,
219
220                 /* UPM Read Burst RAM array entry -> unused */
221     /* 0x08 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
222     /* 0x0C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
223
224                 /* UPM Read Burst RAM array entry -> unused */
225     /* 0x10 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
226     /* 0x14 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
227
228                 /* UPM Write Single RAM array entry -> NAND Write Data, ADDR and CMD */
229     /* 0x18 */  0x00a3fc00, 0x00a3fc00, 0x00a3fc00, 0x00a3fc00,
230     /* 0x1C */  0x0fa3fc00, 0x0fa3fc04, 0xfffffc01, 0xfffffc00,
231
232                 /* UPM Write Burst RAM array entry -> unused */
233     /* 0x20 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
234     /* 0x24 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
235     /* 0x28 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
236     /* 0x2C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
237
238                 /* UPM Refresh Timer RAM array entry -> unused */
239     /* 0x30 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
240     /* 0x34 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
241     /* 0x38 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
242
243                 /* UPM Exception RAM array entry -> unsused */
244     /* 0x3C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
245 };
246
247 /* UPM pattern for bus clock = 100 MHz */
248 static const uint upmTable100[] =
249 {
250     /* Offset   UPM Read Single RAM array entry -> NAND Read Data */
251     /* 0x00 */  0x0fa3f200, 0x0fa3b000, 0x0fa33300, 0x0fa33000,
252     /* 0x04 */  0x0fa33000, 0x0fa33004, 0xfffffc01, 0xfffffc00,
253
254                 /* UPM Read Burst RAM array entry -> unused */
255     /* 0x08 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
256     /* 0x0C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
257
258                 /* UPM Read Burst RAM array entry -> unused */
259     /* 0x10 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
260     /* 0x14 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
261
262                 /* UPM Write Single RAM array entry -> NAND Write Data, ADDR and CMD */
263     /* 0x18 */  0x00a3ff00, 0x00a3fc00, 0x00a3fc00, 0x0fa3fc00,
264     /* 0x1C */  0x0fa3fc00, 0x0fa3fc04, 0xfffffc01, 0xfffffc00,
265
266                 /* UPM Write Burst RAM array entry -> unused */
267     /* 0x20 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
268     /* 0x24 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
269     /* 0x28 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
270     /* 0x2C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
271
272                 /* UPM Refresh Timer RAM array entry -> unused */
273     /* 0x30 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
274     /* 0x34 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
275     /* 0x38 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
276
277                 /* UPM Exception RAM array entry -> unsused */
278     /* 0x3C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
279 };
280
281 /* UPM pattern for bus clock = 133.3 MHz */
282 static const uint upmTable133[] =
283 {
284     /* Offset   UPM Read Single RAM array entry -> NAND Read Data */
285     /* 0x00 */  0x0fa3f300, 0x0fa3b000, 0x0fa33300, 0x0fa33000,
286     /* 0x04 */  0x0fa33200, 0x0fa33004, 0xfffffc01, 0xfffffc00,
287
288                 /* UPM Read Burst RAM array entry -> unused */
289     /* 0x08 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
290     /* 0x0C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
291
292                 /* UPM Read Burst RAM array entry -> unused */
293     /* 0x10 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
294     /* 0x14 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
295
296                 /* UPM Write Single RAM array entry -> NAND Write Data, ADDR and CMD */
297     /* 0x18 */  0x00a3ff00, 0x00a3fc00, 0x00a3fd00, 0x0fa3fc00,
298     /* 0x1C */  0x0fa3fd00, 0x0fa3fc04, 0xfffffc01, 0xfffffc00,
299
300                 /* UPM Write Burst RAM array entry -> unused */
301     /* 0x20 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
302     /* 0x24 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
303     /* 0x28 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
304     /* 0x2C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
305
306                 /* UPM Refresh Timer RAM array entry -> unused */
307     /* 0x30 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
308     /* 0x34 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
309     /* 0x38 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
310
311                 /* UPM Exception RAM array entry -> unsused */
312     /* 0x3C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
313 };
314
315 static int      chipsel = 0;
316
317 /* UPM pattern for slow init */
318 static const uint upmTableSlow[] =
319 {
320     /* Offset   UPM Read Single RAM array entry */
321     /* 0x00 */  0xffffee00, 0x00ffcc80, 0x00ffcf00, 0x00ffdc00,
322     /* 0x04 */  0x00ffce80, 0x00ffcc00, 0x00ffee00, 0x3fffcc07,
323
324                 /* UPM Read Burst RAM array entry -> unused */
325     /* 0x08 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
326     /* 0x0C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
327
328                 /* UPM Read Burst RAM array entry -> unused */
329     /* 0x10 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
330     /* 0x14 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
331
332                 /* UPM Write Single RAM array entry */
333     /* 0x18 */  0xffffee00, 0x00ffec80, 0x00ffef00, 0x00fffc80,
334     /* 0x1C */  0x00fffe00, 0x00ffec00, 0x0fffef00, 0x3fffec05,
335
336                 /* UPM Write Burst RAM array entry -> unused */
337     /* 0x20 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
338     /* 0x24 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
339     /* 0x28 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
340     /* 0x2C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
341
342                 /* UPM Refresh Timer RAM array entry -> unused */
343     /* 0x30 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
344     /* 0x34 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
345     /* 0x38 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
346
347                 /* UPM Exception RAM array entry -> unused */
348     /* 0x3C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
349 };
350
351 /* UPM pattern for fast init */
352 static const uint upmTableFast[] =
353 {
354     /* Offset   UPM Read Single RAM array entry */
355     /* 0x00 */  0xffffee00, 0x00ffcc80, 0x00ffcd80, 0x00ffdc00,
356     /* 0x04 */  0x00ffdc00, 0x00ffcf00, 0x00ffec00, 0x3fffcc07,
357
358                 /* UPM Read Burst RAM array entry -> unused */
359     /* 0x08 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
360     /* 0x0C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
361
362                 /* UPM Read Burst RAM array entry -> unused */
363     /* 0x10 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
364     /* 0x14 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
365
366                 /* UPM Write Single RAM array entry */
367     /* 0x18 */  0xffffee00, 0x00ffec80, 0x00ffee80, 0x00fffc00,
368     /* 0x1C */  0x00fffc00, 0x00ffec00, 0x0fffef00, 0x3fffec05,
369
370                 /* UPM Write Burst RAM array entry -> unused */
371     /* 0x20 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
372     /* 0x24 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
373     /* 0x28 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
374     /* 0x2C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
375
376                 /* UPM Refresh Timer RAM array entry -> unused */
377     /* 0x30 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
378     /* 0x34 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
379     /* 0x38 */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
380
381                 /* UPM Exception RAM array entry -> unused */
382     /* 0x3C */  0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
383 };
384
385
386 /* ------------------------------------------------------------------------- */
387
388 /* Check Board Identity:
389  */
390 int checkboard (void)
391 {
392         char *p = (char *) HWIB_INFO_START_ADDR;
393
394         puts ("Board: ");
395         if (*((unsigned long *)p) == (unsigned long)CFG_HWINFO_MAGIC) {
396                 puts (p);
397         } else {
398                 puts ("No HWIB assuming TQM8272");
399         }
400         putc ('\n');
401
402         return 0;
403 }
404
405 /* ------------------------------------------------------------------------- */
406 #if defined(CONFIG_BOARD_GET_CPU_CLK_F)
407 static int get_cas_latency (void)
408 {
409         /* get it from the option -ts in CIB */
410         /* default is 3 */
411         int     ret = 3;
412         int     pos = 0;
413         char    *p = (char *) CIB_INFO_START_ADDR;
414
415         while ((*p != '\0') && (pos < CIB_INFO_LEN)) {
416                 if (*p < ' ' || *p > '~') { /* ASCII strings! */
417                         return ret;
418                 }
419                 if (*p == '-') {
420                         if ((p[1] == 't') && (p[2] == 's')) {
421                                 return (p[4] - '0');
422                         }
423                 }
424                 p++;
425                 pos++;
426         }
427         return ret;
428 }
429 #endif
430
431 static ulong set_sdram_timing (volatile uint *sdmr_ptr, ulong sdmr, int col)
432 {
433 #if defined(CONFIG_BOARD_GET_CPU_CLK_F)
434         int     clk = board_get_cpu_clk_f ();
435         volatile immap_t *immr = (immap_t *)CFG_IMMR;
436         int     busmode = (immr->im_siu_conf.sc_bcr & BCR_EBM ? 1 : 0);
437         int     cas;
438
439         sdmr = sdmr & ~(PSDMR_RFRC_MSK | PSDMR_PRETOACT_MSK | PSDMR_WRC_MSK | \
440                          PSDMR_BUFCMD);
441         if (busmode) {
442                 switch (clk) {
443                         case 66666666:
444                                 sdmr |= (PSDMR_RFRC_66MHZ_60X | \
445                                         PSDMR_PRETOACT_66MHZ_60X | \
446                                         PSDMR_WRC_66MHZ_60X | \
447                                         PSDMR_BUFCMD_66MHZ_60X);
448                                 break;
449                         case 100000000:
450                                 sdmr |= (PSDMR_RFRC_100MHZ_60X | \
451                                         PSDMR_PRETOACT_100MHZ_60X | \
452                                         PSDMR_WRC_100MHZ_60X | \
453                                         PSDMR_BUFCMD_100MHZ_60X);
454                                 break;
455
456                 }
457         } else {
458                 switch (clk) {
459                         case 66666666:
460                                 sdmr |= (PSDMR_RFRC_66MHZ_SINGLE | \
461                                         PSDMR_PRETOACT_66MHZ_SINGLE | \
462                                         PSDMR_WRC_66MHZ_SINGLE | \
463                                         PSDMR_BUFCMD_66MHZ_SINGLE);
464                                 break;
465                         case 100000000:
466                                 sdmr |= (PSDMR_RFRC_100MHZ_SINGLE | \
467                                         PSDMR_PRETOACT_100MHZ_SINGLE | \
468                                         PSDMR_WRC_100MHZ_SINGLE | \
469                                         PSDMR_BUFCMD_100MHZ_SINGLE);
470                                 break;
471                         case 133333333:
472                                 sdmr |= (PSDMR_RFRC_133MHZ_SINGLE | \
473                                         PSDMR_PRETOACT_133MHZ_SINGLE | \
474                                         PSDMR_WRC_133MHZ_SINGLE | \
475                                         PSDMR_BUFCMD_133MHZ_SINGLE);
476                                 break;
477                 }
478         }
479         cas = get_cas_latency();
480         sdmr &=~ (PSDMR_CL_MSK | PSDMR_LDOTOPRE_MSK);
481         sdmr |= cas;
482         sdmr |= ((cas - 1) << 6);
483         return sdmr;
484 #else
485         return sdmr;
486 #endif
487 }
488
489 /* Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx
490  *
491  * This routine performs standard 8260 initialization sequence
492  * and calculates the available memory size. It may be called
493  * several times to try different SDRAM configurations on both
494  * 60x and local buses.
495  */
496 static long int try_init (volatile memctl8260_t * memctl, ulong sdmr,
497                                                   ulong orx, volatile uchar * base, int col)
498 {
499         volatile uchar c = 0xff;
500         volatile uint *sdmr_ptr;
501         volatile uint *orx_ptr;
502         ulong maxsize, size;
503         int i;
504
505         /* We must be able to test a location outsize the maximum legal size
506          * to find out THAT we are outside; but this address still has to be
507          * mapped by the controller. That means, that the initial mapping has
508          * to be (at least) twice as large as the maximum expected size.
509          */
510         maxsize = (1 + (~orx | 0x7fff)) / 2;
511
512         /* Since CFG_SDRAM_BASE is always 0 (??), we assume that
513          * we are configuring CS1 if base != 0
514          */
515         sdmr_ptr = base ? &memctl->memc_lsdmr : &memctl->memc_psdmr;
516         orx_ptr = base ? &memctl->memc_or2 : &memctl->memc_or1;
517
518         *orx_ptr = orx;
519         sdmr = set_sdram_timing (sdmr_ptr, sdmr, col);
520         /*
521          * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
522          *
523          * "At system reset, initialization software must set up the
524          *  programmable parameters in the memory controller banks registers
525          *  (ORx, BRx, P/LSDMR). After all memory parameters are configured,
526          *  system software should execute the following initialization sequence
527          *  for each SDRAM device.
528          *
529          *  1. Issue a PRECHARGE-ALL-BANKS command
530          *  2. Issue eight CBR REFRESH commands
531          *  3. Issue a MODE-SET command to initialize the mode register
532          *
533          *  The initial commands are executed by setting P/LSDMR[OP] and
534          *  accessing the SDRAM with a single-byte transaction."
535          *
536          * The appropriate BRx/ORx registers have already been set when we
537          * get here. The SDRAM can be accessed at the address CFG_SDRAM_BASE.
538          */
539
540         *sdmr_ptr = sdmr | PSDMR_OP_PREA;
541         *base = c;
542
543         *sdmr_ptr = sdmr | PSDMR_OP_CBRR;
544         for (i = 0; i < 8; i++)
545                 *base = c;
546
547         *sdmr_ptr = sdmr | PSDMR_OP_MRW;
548         *(base + CFG_MRS_OFFS) = c;     /* setting MR on address lines */
549
550         *sdmr_ptr = sdmr | PSDMR_OP_NORM | PSDMR_RFEN;
551         *base = c;
552
553         size = get_ram_size((long *)base, maxsize);
554         *orx_ptr = orx | ~(size - 1);
555
556         return (size);
557 }
558
559 phys_size_t initdram (int board_type)
560 {
561         volatile immap_t *immap = (immap_t *) CFG_IMMR;
562         volatile memctl8260_t *memctl = &immap->im_memctl;
563
564 #ifndef CFG_RAMBOOT
565         long size8, size9;
566 #endif
567         long psize, lsize;
568
569         psize = 16 * 1024 * 1024;
570         lsize = 0;
571
572         memctl->memc_psrt = CFG_PSRT;
573         memctl->memc_mptpr = CFG_MPTPR;
574
575 #ifndef CFG_RAMBOOT
576         /* 60x SDRAM setup:
577          */
578         size8 = try_init (memctl, CFG_PSDMR_8COL, CFG_OR1_8COL,
579                                           (uchar *) CFG_SDRAM_BASE, 8);
580         size9 = try_init (memctl, CFG_PSDMR_9COL, CFG_OR1_9COL,
581                                           (uchar *) CFG_SDRAM_BASE, 9);
582
583         if (size8 < size9) {
584                 psize = size9;
585                 printf ("(60x:9COL - %ld MB, ", psize >> 20);
586         } else {
587                 psize = try_init (memctl, CFG_PSDMR_8COL, CFG_OR1_8COL,
588                                                   (uchar *) CFG_SDRAM_BASE, 8);
589                 printf ("(60x:8COL - %ld MB, ", psize >> 20);
590         }
591
592 #endif /* CFG_RAMBOOT */
593
594         icache_enable ();
595
596         return (psize);
597 }
598
599
600 static inline int scanChar (char *p, int len, unsigned long *number)
601 {
602         int     akt = 0;
603
604         *number = 0;
605         while (akt < len) {
606                 if ((*p >= '0') && (*p <= '9')) {
607                         *number *= 10;
608                         *number += *p - '0';
609                         p += 1;
610                 } else {
611                         if (*p == '-')  return akt;
612                         return -1;
613                 }
614                 akt ++;
615         }
616         return akt;
617 }
618
619 typedef struct{
620         int     Bus;
621         int     flash;
622         int     flash_nr;
623         int     ram;
624         int     ram_cs;
625         int     nand;
626         int     nand_cs;
627         int     eeprom;
628         int     can;
629         unsigned long   cpunr;
630         unsigned long   option;
631         int     SecEng;
632         int     cpucl;
633         int     cpmcl;
634         int     buscl;
635         int     busclk_real_ok;
636         int     busclk_real;
637         unsigned char   OK;
638         unsigned char  ethaddr[20];
639 } HWIB_INFO;
640
641 HWIB_INFO       hwinf = {0, 0, 1, 0, 1, 0, 0, 0, 0, 8272, 0 ,0,
642                          0, 0, 0, 0, 0, 0};
643
644 static int dump_hwib(void)
645 {
646         HWIB_INFO       *hw = &hwinf;
647         volatile immap_t *immr = (immap_t *)CFG_IMMR;
648         char *s = getenv("serial#");
649
650         if (hw->OK) {
651                 printf ("HWIB on %x\n", HWIB_INFO_START_ADDR);
652                 printf ("serial : %s\n", s);
653                 printf ("ethaddr: %s\n", hw->ethaddr);
654                 printf ("FLASH  : %x nr:%d\n", hw->flash, hw->flash_nr);
655                 printf ("RAM    : %x cs:%d\n", hw->ram, hw->ram_cs);
656                 printf ("CPU    : %lu\n", hw->cpunr);
657                 printf ("CAN    : %d\n", hw->can);
658                 if (hw->eeprom) printf ("EEprom : %x\n", hw->eeprom);
659                 else printf ("No EEprom\n");
660                 if (hw->nand) {
661                         printf ("NAND   : %x\n", hw->nand);
662                         printf ("NAND CS: %d\n", hw->nand_cs);
663                 } else { printf ("No NAND\n");}
664                 printf ("Bus %s mode.\n", (hw->Bus ? "60x" : "Single PQII"));
665                 printf ("  real : %s\n", (immr->im_siu_conf.sc_bcr & BCR_EBM ? \
666                                  "60x" : "Single PQII"));
667                 printf ("Option : %lx\n", hw->option);
668                 printf ("%s Security Engine\n", (hw->SecEng ? "with" : "no"));
669                 printf ("CPM Clk: %d\n", hw->cpmcl);
670                 printf ("CPU Clk: %d\n", hw->cpucl);
671                 printf ("Bus Clk: %d\n", hw->buscl);
672                 if (hw->busclk_real_ok) {
673                         printf ("  real Clk: %d\n", hw->busclk_real);
674                 }
675                 printf ("CAS    : %d\n", get_cas_latency());
676         } else {
677                 printf("HWIB @%x not OK\n", HWIB_INFO_START_ADDR);
678         }
679         return 0;
680 }
681
682 static inline int search_real_busclk (int *clk)
683 {
684         int     part = 0, pos = 0;
685         char *p = (char *) CIB_INFO_START_ADDR;
686         int     ok = 0;
687
688         while ((*p != '\0') && (pos < CIB_INFO_LEN)) {
689                 if (*p < ' ' || *p > '~') { /* ASCII strings! */
690                         return 0;
691                 }
692                 switch (part) {
693                 default:
694                         if (*p == '-') {
695                                 ++part;
696                         }
697                         break;
698                 case 3:
699                         if (*p == '-') {
700                                 ++part;
701                                 break;
702                         }
703                         if (*p == 'b') {
704                                 ok = 1;
705                                 p++;
706                                 break;
707                         }
708                         if (ok) {
709                                 switch (*p) {
710                                 case '6':
711                                         *clk = 66666666;
712                                         return 1;
713                                         break;
714                                 case '1':
715                                         if (p[1] == '3') {
716                                                 *clk = 133333333;
717                                         } else {
718                                                 *clk = 100000000;
719                                         }
720                                         return 1;
721                                         break;
722                                 }
723                         }
724                         break;
725                 }
726                 p++;
727         }
728         return 0;
729 }
730
731 int analyse_hwib (void)
732 {
733         char    *p = (char *) HWIB_INFO_START_ADDR;
734         int     anz;
735         int     part = 1, i = 0, pos = 0;
736         HWIB_INFO       *hw = &hwinf;
737
738         deb_printf(" %s pointer: %p\n", __FUNCTION__, p);
739         /* Head = TQM */
740         if (*((unsigned long *)p) != (unsigned long)CFG_HWINFO_MAGIC) {
741                 deb_printf("No HWIB\n");
742                 return -1;
743         }
744         p += 3;
745         if (scanChar (p, 4, &hw->cpunr) < 0) {
746                 deb_printf("No CPU\n");
747                 return -2;
748         }
749         p +=4;
750
751         hw->flash = 0x200000 << (*p - 'A');
752         p++;
753         hw->flash_nr = *p - '0';
754         p++;
755
756         hw->ram = 0x2000000 << (*p - 'A');
757         p++;
758         if (*p == '2') {
759                 hw->ram_cs = 2;
760                 p++;
761         }
762
763         if (*p == 'A') hw->can = 1;
764         if (*p == 'B') hw->can = 2;
765         p +=1;
766         p +=1;  /* connector */
767         if (*p != '0') {
768                 hw->eeprom = 0x1000 << (*p - 'A');
769         }
770         p++;
771
772         if ((*p < '0') || (*p > '9')) {
773                 /* NAND before z-option */
774                 hw->nand = 0x8000000 << (*p - 'A');
775                 p++;
776                 hw->nand_cs = *p - '0';
777                 p += 2;
778         }
779         /* z-option */
780         anz = scanChar (p, 4, &hw->option);
781         if (anz < 0) {
782                 deb_printf("No option\n");
783                 return -3;
784         }
785         if (hw->option & 0x8) hw->Bus = 1;
786         p += anz;
787         if (*p != '-') {
788                 deb_printf("No -\n");
789                 return -4;
790         }
791         p++;
792         /* C option */
793         if (*p == 'E') {
794                 hw->SecEng = 1;
795                 p++;
796         }
797         switch (*p) {
798                 case 'M': hw->cpucl = 266666666;
799                         break;
800                 case 'P': hw->cpucl = 300000000;
801                         break;
802                 case 'T': hw->cpucl = 400000000;
803                         break;
804                 default:
805                         deb_printf("No CPU Clk: %c\n", *p);
806                         return -5;
807                         break;
808         }
809         p++;
810         switch (*p) {
811                 case 'I': hw->cpmcl = 200000000;
812                         break;
813                 case 'M': hw->cpmcl = 300000000;
814                         break;
815                 default:
816                         deb_printf("No CPM Clk\n");
817                         return -6;
818                         break;
819         }
820         p++;
821         switch (*p) {
822                 case 'B': hw->buscl = 66666666;
823                         break;
824                 case 'E': hw->buscl = 100000000;
825                         break;
826                 case 'F': hw->buscl = 133333333;
827                         break;
828                 default:
829                         deb_printf("No BUS Clk\n");
830                         return -7;
831                         break;
832         }
833         p++;
834
835         hw->OK = 1;
836         /* search MAC Address */
837         while ((*p != '\0') && (pos < CFG_HWINFO_SIZE)) {
838                 if (*p < ' ' || *p > '~') { /* ASCII strings! */
839                         return 0;
840                 }
841                 switch (part) {
842                 default:
843                         if (*p == ' ') {
844                                 ++part;
845                                 i = 0;
846                         }
847                         break;
848                 case 3:                 /* Copy MAC address */
849                         if (*p == ' ') {
850                                 ++part;
851                                 i = 0;
852                                 break;
853                         }
854                         hw->ethaddr[i++] = *p;
855                         if ((i % 3) == 2)
856                                 hw->ethaddr[i++] = ':';
857                         break;
858
859                 }
860                 p++;
861         }
862
863         hw->busclk_real_ok = search_real_busclk (&hw->busclk_real);
864         return 0;
865 }
866
867 #if defined(CONFIG_GET_CPU_STR_F)
868 /* !! This routine runs from Flash */
869 char get_cpu_str_f (char *buf)
870 {
871         char *p = (char *) HWIB_INFO_START_ADDR;
872         int     i = 0;
873
874         buf[i++] = 'M';
875         buf[i++] = 'P';
876         buf[i++] = 'C';
877         if (*((unsigned long *)p) == (unsigned long)CFG_HWINFO_MAGIC) {
878                 buf[i++] = *&p[3];
879                 buf[i++] = *&p[4];
880                 buf[i++] = *&p[5];
881                 buf[i++] = *&p[6];
882         } else {
883                 buf[i++] = '8';
884                 buf[i++] = '2';
885                 buf[i++] = '7';
886                 buf[i++] = 'x';
887         }
888         buf[i++] = 0;
889         return 0;
890 }
891 #endif
892
893 #if defined(CONFIG_BOARD_GET_CPU_CLK_F)
894 /* !! This routine runs from Flash */
895 unsigned long board_get_cpu_clk_f (void)
896 {
897         char *p = (char *) HWIB_INFO_START_ADDR;
898         int i = 0;
899
900         if (*((unsigned long *)p) == (unsigned long)CFG_HWINFO_MAGIC) {
901                 if (search_real_busclk (&i))
902                         return i;
903         }
904         return CONFIG_8260_CLKIN;
905 }
906 #endif
907
908 #if CONFIG_BOARD_EARLY_INIT_R
909
910 static int can_test (unsigned long off)
911 {
912         volatile unsigned char  *base   = (unsigned char *) (CFG_CAN_BASE + off);
913
914         *(base + 0x17) = 'T';
915         *(base + 0x18) = 'Q';
916         *(base + 0x19) = 'M';
917         if ((*(base + 0x17) != 'T') ||
918             (*(base + 0x18) != 'Q') ||
919             (*(base + 0x19) != 'M')) {
920                 return 0;
921         }
922         return 1;
923 }
924
925 static int can_config_one (unsigned long off)
926 {
927         volatile unsigned char  *ctrl   = (unsigned char *) (CFG_CAN_BASE + off);
928         volatile unsigned char  *cpu_if = (unsigned char *) (CFG_CAN_BASE + off + 0x02);
929         volatile unsigned char  *clkout = (unsigned char *) (CFG_CAN_BASE + off + 0x1f);
930         unsigned char temp;
931
932         *cpu_if = 0x45;
933         temp = *ctrl;
934         temp |= 0x40;
935         *ctrl   = temp;
936         *clkout = 0x20;
937         temp = *ctrl;
938         temp &= ~0x40;
939         *ctrl   = temp;
940         return 0;
941 }
942
943 static int can_config (void)
944 {
945         int     ret = 0;
946         can_config_one (0);
947         if (hwinf.can == 2) {
948                 can_config_one (0x100);
949         }
950         /* make Test if they really there */
951         ret += can_test (0);
952         ret += can_test (0x100);
953         return ret;
954 }
955
956 static int init_can (void)
957 {
958         volatile immap_t * immr = (immap_t *)CFG_IMMR;
959         volatile memctl8260_t *memctl = &immr->im_memctl;
960         int     count = 0;
961
962         if ((hwinf.OK) && (hwinf.can)) {
963                 memctl->memc_or4 = CFG_CAN_OR;
964                 memctl->memc_br4 = CFG_CAN_BR;
965                 /* upm Init */
966                 upmconfig (UPMC, (uint *) upmTableFast,
967                            sizeof (upmTableFast) / sizeof (uint));
968                 memctl->memc_mcmr =     (MxMR_DSx_3_CYCL |
969                                         MxMR_GPL_x4DIS |
970                                         MxMR_RLFx_2X |
971                                         MxMR_WLFx_2X |
972                                         MxMR_OP_NORM);
973                 /* can configure */
974                 count = can_config ();
975                 printf ("CAN:   %d @ %x\n", count, CFG_CAN_BASE);
976                 if (hwinf.can != count) printf("!!! difference to HWIB\n");
977         } else {
978                 printf ("CAN:   No\n");
979         }
980         return 0;
981 }
982
983 int board_early_init_r(void)
984 {
985         analyse_hwib ();
986         init_can ();
987         return 0;
988 }
989 #endif
990
991 int do_hwib_dump (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
992 {
993         dump_hwib ();
994         return 0;
995 }
996
997 U_BOOT_CMD(
998           hwib, 1,      1,      do_hwib_dump,
999           "hwib    - dump HWIB'\n",
1000           "\n"
1001 );
1002
1003 #ifdef CFG_UPDATE_FLASH_SIZE
1004 static int get_flash_timing (void)
1005 {
1006         /* get it from the option -tf in CIB */
1007         /* default is 0x00000c84 */
1008         int     ret = 0x00000c84;
1009         int     pos = 0;
1010         int     nr = 0;
1011         char    *p = (char *) CIB_INFO_START_ADDR;
1012
1013         while ((*p != '\0') && (pos < CIB_INFO_LEN)) {
1014                 if (*p < ' ' || *p > '~') { /* ASCII strings! */
1015                         return ret;
1016                 }
1017                 if (*p == '-') {
1018                         if ((p[1] == 't') && (p[2] == 'f')) {
1019                                 p += 6;
1020                                 ret = 0;
1021                                 while (nr < 8) {
1022                                 if ((*p >= '0') && (*p <= '9')) {
1023                                         ret *= 0x10;
1024                                         ret += *p - '0';
1025                                         p += 1;
1026                                         nr ++;
1027                                 } else if ((*p >= 'A') && (*p <= 'F')) {
1028                                         ret *= 10;
1029                                         ret += *p - '7';
1030                                         p += 1;
1031                                         nr ++;
1032                                 } else {
1033                                         if (nr < 8) return 0x00000c84;
1034                                         return ret;
1035                                 }
1036                                 }
1037                         }
1038                 }
1039                 p++;
1040                 pos++;
1041         }
1042         return ret;
1043 }
1044
1045 /* Update the Flash_Size and the Flash Timing */
1046 int update_flash_size (int flash_size)
1047 {
1048         volatile immap_t * immr = (immap_t *)CFG_IMMR;
1049         volatile memctl8260_t *memctl = &immr->im_memctl;
1050         unsigned long reg;
1051         unsigned long tim;
1052
1053         /* I must use reg, otherwise the board hang */
1054         reg = memctl->memc_or0;
1055         reg &= ~ORxU_AM_MSK;
1056         reg |= MEG_TO_AM(flash_size >> 20);
1057         tim = get_flash_timing ();
1058         reg &= ~0xfff;
1059         reg |= (tim & 0xfff);
1060         memctl->memc_or0 = reg;
1061         return 0;
1062 }
1063 #endif
1064
1065 #if defined(CONFIG_CMD_NAND)
1066
1067 #include <nand.h>
1068 #include <linux/mtd/mtd.h>
1069
1070 static u8 hwctl = 0;
1071
1072 static void upmnand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
1073 {
1074         struct nand_chip *this = mtd->priv;
1075
1076         if (ctrl & NAND_CTRL_CHANGE) {
1077                 if ( ctrl & NAND_CLE )
1078                         hwctl |= 0x1;
1079                 else
1080                         hwctl &= ~0x1;
1081                 if ( ctrl & NAND_ALE )
1082                         hwctl |= 0x2;
1083                 else
1084                         hwctl &= ~0x2;
1085         }
1086         if (cmd != NAND_CMD_NONE)
1087                 writeb(cmd, this->IO_ADDR_W);
1088 }
1089
1090 static void upmnand_write_byte(struct mtd_info *mtdinfo, u_char byte)
1091 {
1092         struct nand_chip *this = mtdinfo->priv;
1093         ulong base = (ulong) (this->IO_ADDR_W + chipsel * CFG_NAND_CS_DIST);
1094
1095         if (hwctl & 0x1) {
1096                 WRITE_NAND_UPM(byte, base, CFG_NAND_UPM_WRITE_CMD_OFS);
1097         } else if (hwctl & 0x2) {
1098                 WRITE_NAND_UPM(byte, base, CFG_NAND_UPM_WRITE_ADDR_OFS);
1099         } else {
1100                 WRITE_NAND(byte, base);
1101         }
1102 }
1103
1104 static u_char upmnand_read_byte(struct mtd_info *mtdinfo)
1105 {
1106         struct nand_chip *this = mtdinfo->priv;
1107         ulong base = (ulong) (this->IO_ADDR_W + chipsel * CFG_NAND_CS_DIST);
1108
1109         return READ_NAND(base);
1110 }
1111
1112 static int tqm8272_dev_ready(struct mtd_info *mtdinfo)
1113 {
1114         /* constant delay (see also tR in the datasheet) */
1115         udelay(12); \
1116         return 1;
1117 }
1118
1119 #ifndef CONFIG_NAND_SPL
1120 static void tqm8272_read_buf(struct mtd_info *mtdinfo, uint8_t *buf, int len)
1121 {
1122         struct nand_chip *this = mtdinfo->priv;
1123         unsigned char *base = (unsigned char *) (this->IO_ADDR_W + chipsel * CFG_NAND_CS_DIST);
1124         int     i;
1125
1126         for (i = 0; i< len; i++)
1127                 buf[i] = *base;
1128 }
1129
1130 static void tqm8272_write_buf(struct mtd_info *mtdinfo, const uint8_t *buf, int len)
1131 {
1132         struct nand_chip *this = mtdinfo->priv;
1133         unsigned char *base = (unsigned char *) (this->IO_ADDR_W + chipsel * CFG_NAND_CS_DIST);
1134         int     i;
1135
1136         for (i = 0; i< len; i++)
1137                 *base = buf[i];
1138 }
1139
1140 static int tqm8272_verify_buf(struct mtd_info *mtdinfo, const uint8_t *buf, int len)
1141 {
1142         struct nand_chip *this = mtdinfo->priv;
1143         unsigned char *base = (unsigned char *) (this->IO_ADDR_W + chipsel * CFG_NAND_CS_DIST);
1144         int     i;
1145
1146         for (i = 0; i < len; i++)
1147                 if (buf[i] != *base)
1148                         return -1;
1149         return 0;
1150 }
1151 #endif /* #ifndef CONFIG_NAND_SPL */
1152
1153 void board_nand_select_device(struct nand_chip *nand, int chip)
1154 {
1155         chipsel = chip;
1156 }
1157
1158 int board_nand_init(struct nand_chip *nand)
1159 {
1160         static  int     UpmInit = 0;
1161         volatile immap_t * immr = (immap_t *)CFG_IMMR;
1162         volatile memctl8260_t *memctl = &immr->im_memctl;
1163
1164         if (hwinf.nand == 0) return -1;
1165
1166         /* Setup the UPM */
1167         if (UpmInit == 0) {
1168                 switch (hwinf.busclk_real) {
1169                 case 100000000:
1170                         upmconfig (UPMB, (uint *) upmTable100,
1171                            sizeof (upmTable100) / sizeof (uint));
1172                         break;
1173                 case 133333333:
1174                         upmconfig (UPMB, (uint *) upmTable133,
1175                            sizeof (upmTable133) / sizeof (uint));
1176                         break;
1177                 default:
1178                         upmconfig (UPMB, (uint *) upmTable67,
1179                            sizeof (upmTable67) / sizeof (uint));
1180                         break;
1181                 }
1182                 UpmInit = 1;
1183         }
1184
1185         /* Setup the memctrl */
1186         memctl->memc_or3 = CFG_NAND_OR;
1187         memctl->memc_br3 = CFG_NAND_BR;
1188         memctl->memc_mbmr = (MxMR_OP_NORM);
1189
1190         nand->ecc.mode = NAND_ECC_SOFT;
1191
1192         nand->cmd_ctrl   = upmnand_hwcontrol;
1193         nand->read_byte  = upmnand_read_byte;
1194         nand->write_byte = upmnand_write_byte;
1195         nand->dev_ready  = tqm8272_dev_ready;
1196
1197 #ifndef CONFIG_NAND_SPL
1198         nand->write_buf  = tqm8272_write_buf;
1199         nand->read_buf   = tqm8272_read_buf;
1200         nand->verify_buf = tqm8272_verify_buf;
1201 #endif
1202
1203         /*
1204          * Select required NAND chip
1205          */
1206         board_nand_select_device(nand, 0);
1207         return 0;
1208 }
1209
1210 #endif
1211
1212 #ifdef CONFIG_PCI
1213 struct pci_controller hose;
1214
1215 int board_early_init_f (void)
1216 {
1217         volatile immap_t *immap = (immap_t *) CFG_IMMR;
1218
1219         immap->im_clkrst.car_sccr |= M826X_SCCR_PCI_MODE_EN;
1220         return 0;
1221 }
1222
1223 extern void pci_mpc8250_init(struct pci_controller *);
1224
1225 void pci_init_board(void)
1226 {
1227         pci_mpc8250_init(&hose);
1228 }
1229 #endif
1230
1231 int board_eth_init(bd_t *bis)
1232 {
1233         return pci_eth_init(bis);
1234 }