]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/keymile/mgcoge/mgcoge.c
imported Ka-Ro specific additions to U-Boot 2009.08 for TX28
[karo-tx-uboot.git] / board / keymile / mgcoge / mgcoge.c
1 /*
2  * (C) Copyright 2007 - 2008
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 <mpc8260.h>
26 #include <ioports.h>
27 #include <malloc.h>
28 #include <net.h>
29 #include <asm/io.h>
30
31 #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
32 #include <libfdt.h>
33 #endif
34
35 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
36 #include <i2c.h>
37 #endif
38
39 #include "../common/common.h"
40
41 /*
42  * I/O Port configuration table
43  *
44  * if conf is 1, then that port pin will be configured at boot time
45  * according to the five values podr/pdir/ppar/psor/pdat for that entry
46  */
47 const iop_conf_t iop_conf_tab[4][32] = {
48
49     /* Port A */
50     {   /*            conf      ppar psor pdir podr pdat */
51         /* PA31 */ { 0,          0,   0,   0,   0,   0 }, /* PA31            */
52         /* PA30 */ { 0,          0,   0,   0,   0,   0 }, /* PA30            */
53         /* PA29 */ { 0,          0,   0,   0,   0,   0 }, /* PA29            */
54         /* PA28 */ { 0,          0,   0,   0,   0,   0 }, /* PA28            */
55         /* PA27 */ { 0,          0,   0,   0,   0,   0 }, /* PA27            */
56         /* PA26 */ { 0,          0,   0,   0,   0,   0 }, /* PA26            */
57         /* PA25 */ { 0,          0,   0,   0,   0,   0 }, /* PA25            */
58         /* PA24 */ { 0,          0,   0,   0,   0,   0 }, /* PA24            */
59         /* PA23 */ { 0,          0,   0,   0,   0,   0 }, /* PA23            */
60         /* PA22 */ { 0,          0,   0,   0,   0,   0 }, /* PA22            */
61         /* PA21 */ { 0,          0,   0,   0,   0,   0 }, /* PA21            */
62         /* PA20 */ { 0,          0,   0,   0,   0,   0 }, /* PA20            */
63         /* PA19 */ { 0,          0,   0,   0,   0,   0 }, /* PA19            */
64         /* PA18 */ { 0,          0,   0,   0,   0,   0 }, /* PA18            */
65         /* PA17 */ { 0,          0,   0,   0,   0,   0 }, /* PA17            */
66         /* PA16 */ { 0,          0,   0,   0,   0,   0 }, /* PA16            */
67         /* PA15 */ { 0,          0,   0,   0,   0,   0 }, /* PA15            */
68         /* PA14 */ { 0,          0,   0,   0,   0,   0 }, /* PA14            */
69         /* PA13 */ { 0,          0,   0,   0,   0,   0 }, /* PA13            */
70         /* PA12 */ { 0,          0,   0,   0,   0,   0 }, /* PA12            */
71         /* PA11 */ { 0,          0,   0,   0,   0,   0 }, /* PA11            */
72         /* PA10 */ { 0,          0,   0,   0,   0,   0 }, /* PA10            */
73         /* PA9  */ { 1,          1,   0,   1,   0,   0 }, /* SMC2 TxD        */
74         /* PA8  */ { 1,          1,   0,   0,   0,   0 }, /* SMC2 RxD        */
75         /* PA7  */ { 0,          0,   0,   0,   0,   0 }, /* PA7             */
76         /* PA6  */ { 0,          0,   0,   0,   0,   0 }, /* PA6             */
77         /* PA5  */ { 0,          0,   0,   0,   0,   0 }, /* PA5             */
78         /* PA4  */ { 0,          0,   0,   0,   0,   0 }, /* PA4             */
79         /* PA3  */ { 0,          0,   0,   0,   0,   0 }, /* PA3             */
80         /* PA2  */ { 0,          0,   0,   0,   0,   0 }, /* PA2             */
81         /* PA1  */ { 0,          0,   0,   0,   0,   0 }, /* PA1             */
82         /* PA0  */ { 0,          0,   0,   0,   0,   0 }  /* PA0             */
83     },
84
85     /* Port B */
86     {   /*            conf      ppar psor pdir podr pdat */
87         /* PB31 */ { 0,          0,   0,   0,   0,   0 }, /* PB31            */
88         /* PB30 */ { 0,          0,   0,   0,   0,   0 }, /* PB30            */
89         /* PB29 */ { 0,          0,   0,   0,   0,   0 }, /* PB29            */
90         /* PB28 */ { 0,          0,   0,   0,   0,   0 }, /* PB28            */
91         /* PB27 */ { 0,          0,   0,   0,   0,   0 }, /* PB27            */
92         /* PB26 */ { 0,          0,   0,   0,   0,   0 }, /* PB26            */
93         /* PB25 */ { 0,          0,   0,   0,   0,   0 }, /* PB25            */
94         /* PB24 */ { 0,          0,   0,   0,   0,   0 }, /* PB24            */
95         /* PB23 */ { 0,          0,   0,   0,   0,   0 }, /* PB23            */
96         /* PB22 */ { 0,          0,   0,   0,   0,   0 }, /* PB22            */
97         /* PB21 */ { 0,          0,   0,   0,   0,   0 }, /* PB21            */
98         /* PB20 */ { 0,          0,   0,   0,   0,   0 }, /* PB20            */
99         /* PB19 */ { 0,          0,   0,   0,   0,   0 }, /* PB19            */
100         /* PB18 */ { 0,          0,   0,   0,   0,   0 }, /* PB18            */
101         /* PB17 */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
102         /* PB16 */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
103         /* PB15 */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
104         /* PB14 */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
105         /* PB13 */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
106         /* PB12 */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
107         /* PB11 */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
108         /* PB10 */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
109         /* PB9  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
110         /* PB8  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
111         /* PB7  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
112         /* PB6  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
113         /* PB5  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
114         /* PB4  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
115         /* PB3  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
116         /* PB2  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
117         /* PB1  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
118         /* PB0  */ { 0,          0,   0,   0,   0,   0 }  /* non-existent    */
119     },
120
121     /* Port C */
122     {   /*            conf      ppar psor pdir podr pdat */
123         /* PC31 */ { 0,          0,   0,   0,   0,   0 }, /* PC31            */
124         /* PC30 */ { 0,          0,   0,   0,   0,   0 }, /* PC30            */
125         /* PC29 */ { 0,          0,   0,   0,   0,   0 }, /* PC29            */
126         /* PC28 */ { 0,          0,   0,   0,   0,   0 }, /* PC28            */
127         /* PC27 */ { 0,          0,   0,   0,   0,   0 }, /* PC27            */
128         /* PC26 */ { 0,          0,   0,   0,   0,   0 }, /* PC26            */
129         /* PC25 */ { 1,          1,   0,   0,   0,   0 }, /* SCC4 RxClk      */
130         /* PC24 */ { 1,          1,   0,   0,   0,   0 }, /* SCC4 TxClk      */
131         /* PC23 */ { 0,          0,   0,   0,   0,   0 }, /* PC23            */
132         /* PC22 */ { 0,          0,   0,   0,   0,   0 }, /* PC22            */
133         /* PC21 */ { 0,          0,   0,   0,   0,   0 }, /* PC21            */
134         /* PC20 */ { 0,          0,   0,   0,   0,   0 }, /* PC20            */
135         /* PC19 */ { 0,          0,   0,   0,   0,   0 }, /* PC19            */
136         /* PC18 */ { 0,          0,   0,   0,   0,   0 }, /* PC18            */
137         /* PC17 */ { 0,          0,   0,   0,   0,   0 }, /* PC17            */
138         /* PC16 */ { 0,          0,   0,   0,   0,   0 }, /* PC16            */
139         /* PC15 */ { 0,          0,   0,   0,   0,   0 }, /* PC15            */
140         /* PC14 */ { 0,          0,   0,   0,   0,   0 }, /* PC14            */
141         /* PC13 */ { 0,          0,   0,   0,   0,   0 }, /* PC13            */
142         /* PC12 */ { 0,          0,   0,   0,   0,   0 }, /* PC12            */
143         /* PC11 */ { 0,          0,   0,   0,   0,   0 }, /* PC11            */
144         /* PC10 */ { 0,          0,   0,   0,   0,   0 }, /* PC10            */
145         /* PC9  */ { 1,          1,   0,   0,   0,   0 }, /* SCC4: CTS       */
146         /* PC8  */ { 1,          1,   0,   0,   0,   0 }, /* SCC4: CD        */
147         /* PC7  */ { 0,          0,   0,   0,   0,   0 }, /* PC7             */
148         /* PC6  */ { 0,          0,   0,   0,   0,   0 }, /* PC6             */
149         /* PC5  */ { 0,          0,   0,   0,   0,   0 }, /* PC5             */
150         /* PC4  */ { 0,          0,   0,   0,   0,   0 }, /* PC4             */
151         /* PC3  */ { 0,          0,   0,   0,   0,   0 }, /* PC3             */
152         /* PC2  */ { 0,          0,   0,   0,   0,   0 }, /* PC2             */
153         /* PC1  */ { 0,          0,   0,   0,   0,   0 }, /* PC1             */
154         /* PC0  */ { 0,          0,   0,   0,   0,   0 }, /* PC0             */
155     },
156
157     /* Port D */
158     {   /*            conf      ppar psor pdir podr pdat */
159         /* PD31 */ { 0,          0,   0,   0,   0,   0 }, /* PD31            */
160         /* PD30 */ { 0,          0,   0,   0,   0,   0 }, /* PD30            */
161         /* PD29 */ { 0,          0,   0,   0,   0,   0 }, /* PD29            */
162         /* PD28 */ { 0,          0,   0,   0,   0,   0 }, /* PD28            */
163         /* PD27 */ { 0,          0,   0,   0,   0,   0 }, /* PD27            */
164         /* PD26 */ { 0,          0,   0,   0,   0,   0 }, /* PD26            */
165         /* PD25 */ { 0,          0,   0,   0,   0,   0 }, /* PD25            */
166         /* PD24 */ { 0,          0,   0,   0,   0,   0 }, /* PD24            */
167         /* PD23 */ { 0,          0,   0,   0,   0,   0 }, /* PD23            */
168         /* PD22 */ { 1,          1,   0,   0,   0,   0 }, /* SCC4: RXD       */
169         /* PD21 */ { 1,          1,   0,   1,   0,   0 }, /* SCC4: TXD       */
170         /* PD20 */ { 1,          1,   0,   1,   0,   0 }, /* SCC4: RTS       */
171         /* PD19 */ { 0,          0,   0,   0,   0,   0 }, /* PD19            */
172         /* PD18 */ { 0,          0,   0,   0,   0,   0 }, /* PD18            */
173         /* PD17 */ { 0,          0,   0,   0,   0,   0 }, /* PD17            */
174         /* PD16 */ { 0,          0,   0,   0,   0,   0 }, /* PD16            */
175 #if defined(CONFIG_HARD_I2C)
176         /* PD15 */ { 1,          1,   1,   0,   1,   0 }, /* I2C SDA         */
177         /* PD14 */ { 1,          1,   1,   0,   1,   0 }, /* I2C SCL         */
178 #else
179         /* PD15 */ { 1,          0,   0,   0,   1,   1 }, /* PD15            */
180         /* PD14 */ { 1,          0,   0,   1,   1,   1 }, /* PD14            */
181 #endif
182         /* PD13 */ { 0,          0,   0,   0,   0,   0 }, /* PD13            */
183         /* PD12 */ { 0,          0,   0,   0,   0,   0 }, /* PD12            */
184         /* PD11 */ { 0,          0,   0,   0,   0,   0 }, /* PD11            */
185         /* PD10 */ { 0,          0,   0,   0,   0,   0 }, /* PD10            */
186         /* PD9  */ { 0,          0,   0,   0,   0,   0 }, /* PD9             */
187         /* PD8  */ { 0,          0,   0,   0,   0,   0 }, /* PD8             */
188         /* PD7  */ { 0,          0,   0,   0,   0,   0 }, /* PD7             */
189         /* PD6  */ { 0,          0,   0,   0,   0,   0 }, /* PD6             */
190         /* PD5  */ { 0,          0,   0,   0,   0,   0 }, /* PD5             */
191         /* PD4  */ { 0,          0,   0,   0,   0,   0 }, /* PD4             */
192         /* PD3  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
193         /* PD2  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
194         /* PD1  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
195         /* PD0  */ { 0,          0,   0,   0,   0,   0 }  /* non-existent    */
196     }
197 };
198
199 /* Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx
200  *
201  * This routine performs standard 8260 initialization sequence
202  * and calculates the available memory size. It may be called
203  * several times to try different SDRAM configurations on both
204  * 60x and local buses.
205  */
206 static long int try_init (volatile memctl8260_t * memctl, ulong sdmr,
207                                                   ulong orx, volatile uchar * base)
208 {
209         volatile uchar c = 0xff;
210         volatile uint *sdmr_ptr;
211         volatile uint *orx_ptr;
212         ulong maxsize, size;
213         int i;
214
215         /* We must be able to test a location outsize the maximum legal size
216          * to find out THAT we are outside; but this address still has to be
217          * mapped by the controller. That means, that the initial mapping has
218          * to be (at least) twice as large as the maximum expected size.
219          */
220         maxsize = (1 + (~orx | 0x7fff))/* / 2*/;
221
222         sdmr_ptr = &memctl->memc_psdmr;
223         orx_ptr = &memctl->memc_or1;
224
225         *orx_ptr = orx;
226
227         /*
228          * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
229          *
230          * "At system reset, initialization software must set up the
231          *  programmable parameters in the memory controller banks registers
232          *  (ORx, BRx, P/LSDMR). After all memory parameters are configured,
233          *  system software should execute the following initialization sequence
234          *  for each SDRAM device.
235          *
236          *  1. Issue a PRECHARGE-ALL-BANKS command
237          *  2. Issue eight CBR REFRESH commands
238          *  3. Issue a MODE-SET command to initialize the mode register
239          *
240          *  The initial commands are executed by setting P/LSDMR[OP] and
241          *  accessing the SDRAM with a single-byte transaction."
242          *
243          * The appropriate BRx/ORx registers have already been set when we
244          * get here. The SDRAM can be accessed at the address CONFIG_SYS_SDRAM_BASE.
245          */
246
247         *sdmr_ptr = sdmr | PSDMR_OP_PREA;
248         *base = c;
249
250         *sdmr_ptr = sdmr | PSDMR_OP_CBRR;
251         for (i = 0; i < 8; i++)
252                 *base = c;
253
254         *sdmr_ptr = sdmr | PSDMR_OP_MRW;
255         *(base + CONFIG_SYS_MRS_OFFS) = c;      /* setting MR on address lines */
256
257         *sdmr_ptr = sdmr | PSDMR_OP_NORM | PSDMR_RFEN;
258         *base = c;
259
260         size = get_ram_size ((long *)base, maxsize);
261         *orx_ptr = orx | ~(size - 1);
262
263         return (size);
264 }
265
266 phys_size_t initdram (int board_type)
267 {
268         volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
269         volatile memctl8260_t *memctl = &immap->im_memctl;
270
271         long psize;
272
273         memctl->memc_psrt = CONFIG_SYS_PSRT;
274         memctl->memc_mptpr = CONFIG_SYS_MPTPR;
275
276 #ifndef CONFIG_SYS_RAMBOOT
277         /* 60x SDRAM setup:
278          */
279         psize = try_init (memctl, CONFIG_SYS_PSDMR, CONFIG_SYS_OR1,
280                                                   (uchar *) CONFIG_SYS_SDRAM_BASE);
281 #endif /* CONFIG_SYS_RAMBOOT */
282
283         icache_enable ();
284
285         return (psize);
286 }
287
288 int checkboard(void)
289 {
290         puts ("Board: Keymile mgcoge");
291         if (ethernet_present ())
292                 puts (" with PIGGY.");
293         puts ("\n");
294         return 0;
295 }
296
297 /*
298  * Early board initalization.
299  */
300 int board_early_init_r (void)
301 {
302         /* setup the UPIOx */
303         out_8((u8 *)(CONFIG_SYS_PIGGY_BASE + 0x02), 0xc0);
304         out_8((u8 *)(CONFIG_SYS_PIGGY_BASE + 0x03), 0x15);
305         return 0;
306 }
307
308 int hush_init_var (void)
309 {
310         ivm_read_eeprom ();
311         return 0;
312 }
313
314 #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
315 /*
316  * update "memory" property in the blob
317  */
318 void ft_blob_update (void *blob, bd_t *bd)
319 {
320         ulong memory_data[2] = {0};
321         ulong *flash_data = NULL;
322         ulong   flash_reg[6] = {0};
323         flash_info_t    *info;
324         int     len;
325         int     size;
326         int     i = 0;
327
328         memory_data[0] = cpu_to_be32 (bd->bi_memstart);
329         memory_data[1] = cpu_to_be32 (bd->bi_memsize);
330         fdt_set_node_and_value (blob, "/memory", "reg", memory_data,
331                                 sizeof (memory_data));
332
333         len = fdt_get_node_and_value (blob, "/localbus", "ranges",
334                                         (void *)&flash_data);
335
336         if (flash_data == NULL) {
337                 printf ("%s: error /localbus/ranges entry\n", __FUNCTION__);
338                 return;
339         }
340
341         /* update Flash addr, size */
342         while ( i < (len / 4)) {
343                 switch (flash_data[i]) {
344                 case 0:
345                         info = flash_get_info(CONFIG_SYS_FLASH_BASE);
346                         flash_data[i + 1] = 0;
347                         flash_data[i + 2] = cpu_to_be32 (CONFIG_SYS_FLASH_BASE);
348                         flash_data[i + 3] = cpu_to_be32 (info->size);
349                         break;
350                 case 5:
351                         info = flash_get_info(CONFIG_SYS_FLASH_BASE_1);
352                         size = info->size;
353                         info = flash_get_info(CONFIG_SYS_FLASH_BASE_2);
354                         size += info->size;
355                         flash_data[i + 1] = 0;
356                         flash_data[i + 2] = cpu_to_be32 (CONFIG_SYS_FLASH_BASE_1);
357                         flash_data[i + 3] = cpu_to_be32 (size);
358                         break;
359                 default:
360                         break;
361                 }
362                 i += 4;
363         }
364         fdt_set_node_and_value (blob, "/localbus", "ranges", flash_data,
365                                 len);
366
367         info = flash_get_info(CONFIG_SYS_FLASH_BASE_1);
368         flash_reg[0] = cpu_to_be32 (5);
369         flash_reg[2] = cpu_to_be32 (info->size);
370         flash_reg[3] = flash_reg[0];
371         flash_reg[4] = flash_reg[2];
372         info = flash_get_info(CONFIG_SYS_FLASH_BASE_2);
373         flash_reg[5] = cpu_to_be32 (info->size);
374         fdt_set_node_and_value (blob, "/localbus/flash@5,0", "reg", flash_reg,
375                                 sizeof (flash_reg));
376
377         /* MAC addr */
378         fdt_set_node_and_value (blob, "/soc/cpm/ethernet", "mac-address",
379                                 bd->bi_enetaddr, sizeof (u8) * 6);
380 }
381
382 void ft_board_setup (void *blob, bd_t *bd)
383 {
384         ft_cpu_setup (blob, bd);
385         ft_blob_update (blob, bd);
386 }
387 #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */