b99bf0e9284f5c38c81a173488c0d88e008e1881
[kernel/u-boot.git] / board / emk / top860 / top860.c
1 /*
2  * (C) Copyright 2003
3  * EMK Elektronik GmbH <www.emk-elektronik.de>
4  * Reinhard Meyer <r.meyer@emk-elektronik.de>
5  *
6  * Board specific routines for the TOP860
7  *
8  * - initialisation
9  * - interface to VPD data (mac address, clock speeds)
10  * - memory controller
11  * - serial io initialisation
12  * - ethernet io initialisation
13  *
14  * -----------------------------------------------------------------
15  * See file CREDITS for list of people who contributed to this
16  * project.
17  *
18  * This program is free software; you can redistribute it and/or
19  * modify it under the terms of the GNU General Public License as
20  * published by the Free Software Foundation; either version 2 of
21  * the License, or (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31  * MA 02111-1307 USA
32  */
33
34 #include <common.h>
35 #include <commproc.h>
36 #include <mpc8xx.h>
37
38 /*****************************************************************************\r
39  * UPM table for 60ns EDO RAM at 25 MHz bus/external clock\r
40  *****************************************************************************/\r
41 static const uint edo_60ns_25MHz_tbl[] = {
42 \r
43 /* single read   (offset 0x00 in upm ram) */\r
44     0x0ff3fc04,0x08f3fc04,0x00f3fc04,0x00f3fc00,\r
45     0x33f7fc07,0xfffffc05,0xfffffc05,0xfffffc05,\r
46 /* burst read    (offset 0x08 in upm ram) */\r
47     0x0ff3fc04,0x08f3fc04,0x00f3fc0c,0x0ff3fc40,\r
48     0x0cf3fc04,0x03f3fc48,0x0cf3fc04,0x03f3fc48,\r
49     0x0cf3fc04,0x03f3fc00,0x3ff7fc07,0xfffffc05,\r
50     0xfffffc05,0xfffffc05,0xfffffc05,0xfffffc05,\r
51 /* single write  (offset 0x18 in upm ram) */\r
52     0x0ffffc04,0x08fffc04,0x30fffc00,0xf1fffc07,\r
53     0xfffffc05,0xfffffc05,0xfffffc05,0xfffffc05,\r
54 /* burst write   (offset 0x20 in upm ram) */\r
55     0x0ffffc04,0x08fffc00,0x00fffc04,0x03fffc4c,\r
56     0x00fffc00,0x07fffc4c,0x00fffc00,0x0ffffc4c,\r
57     0x00fffc00,0x3ffffc07,0xfffffc05,0xfffffc05,\r
58     0xfffffc05,0xfffffc05,0xfffffc05,0xfffffc05,\r
59 /* refresh       (offset 0x30 in upm ram) */\r
60     0xc0fffc04,0x07fffc04,0x0ffffc04,0x0ffffc04,\r
61     0xfffffc05,0xfffffc05,0xfffffc05,0xfffffc05,\r
62     0xfffffc05,0xfffffc05,0xfffffc05,0xfffffc05,\r
63 /* exception     (offset 0x3C in upm ram) */\r
64     0xfffffc07,0xfffffc03,0xfffffc05,0xfffffc05,\r
65 };
66
67 /*****************************************************************************\r
68  * Print Board Identity\r
69  *****************************************************************************/\r
70 int checkboard (void)
71 {
72         puts ("Board:"CONFIG_IDENT_STRING"\n");
73         return (0);
74 }
75
76 /*****************************************************************************\r
77  * Initialize DRAM controller\r
78  *****************************************************************************/\r
79 long int initdram (int board_type)
80 {
81         volatile immap_t *immap = (immap_t *) CFG_IMMR;
82         volatile memctl8xx_t *memctl = &immap->im_memctl;
83
84         /*
85          * Only initialize memory controller when running from FLASH.
86          * When running from RAM, don't touch it.
87          */
88         if ((ulong) initdram & 0xff000000)\r
89         {\r
90                 volatile uint   *addr1, *addr2;\r
91                 uint                    i, j;\r
92
93                 upmconfig (UPMA, (uint *) edo_60ns_25MHz_tbl,\r
94                         sizeof (edo_60ns_25MHz_tbl) / sizeof (uint));
95                 memctl->memc_mptpr = 0x0200;
96                 memctl->memc_mamr = 0x0ca20330;
97                 memctl->memc_or2 = -CFG_DRAM_MAX | OR_CSNT_SAM;
98                 memctl->memc_br2 = CFG_DRAM_BASE | BR_MS_UPMA | BR_V;
99                 /*\r
100                  * Do 8 read accesses to DRAM\r
101                  */\r
102                 addr1 = (volatile uint*) 0;\r
103                 addr2 = (volatile uint*) 0x00400000;\r
104                 for (i=0, j=0; i<8; i++)\r
105                         j = addr1[0];\r
106                 \r
107                 /*\r
108                  * Now check whether we got 4MB or 16MB populated\r
109                  */\r
110                 addr1[0] = 0x12345678;\r
111                 addr1[1] = 0x9abcdef0;\r
112                 addr2[0] = 0xfeedc0de;\r
113                 addr2[1] = 0x47110815;\r
114                 if (addr1[0] == 0xfeedc0de && addr1[1] == 0x47110815)\r
115                 {\r
116                         /* only 4MB populated */\r
117                         memctl->memc_or2 = -(CFG_DRAM_MAX/4) | OR_CSNT_SAM;\r
118                 }\r
119         }\r
120 \r
121         return -(memctl->memc_or2 & 0xffff0000);
122 }
123 \r
124 /*****************************************************************************\r
125  * otherinits after RAM is there and we are relocated to RAM\r
126  * note: though this is an int function, nobody cares for the result!\r
127  *****************************************************************************/\r
128 int misc_init_r (void)
129 {\r
130         /* read 'factory' part of EEPROM */\r
131         uchar                           buf[81];\r
132         uchar                           *p;\r
133         uint                            length;\r
134         uint                            addr;\r
135         uint                            len;\r
136 \r
137         /* get length first */\r
138         addr = CFG_FACT_OFFSET;\r
139         if (eeprom_read (CFG_I2C_FACT_ADDR, addr, buf, 2))\r
140         {\r
141 bailout:\r
142                 printf ("cannot read factory configuration\n");\r
143                 printf ("be sure to set ethaddr yourself!\n");\r
144                 return 0;\r
145         }
146         length = buf[0] + (buf[1]<<8);\r
147         addr += 2;\r
148 \r
149         /* sanity check */\r
150         if (length < 20 || length > CFG_FACT_SIZE-2)\r
151                 goto bailout;\r
152 \r
153         /* read lines */\r
154         while (length > 0)\r
155         {\r
156                 /* read one line */\r
157                 len = length > 80 ? 80 : length;\r
158                 if (eeprom_read (CFG_I2C_FACT_ADDR, addr, buf, len))\r
159                         goto bailout;\r
160                 /* mark end of buffer */\r
161                 buf[len] = 0;\r
162                 /* search end of line */\r
163                 for (p=buf; *p && *p != 0x0a; p++) ;\r
164                 if (!*p)\r
165                         goto bailout;\r
166                 *p++ = 0;\r
167                 /* advance to next line start */\r
168                 length -= p-buf;\r
169                 addr += p-buf;\r
170                 /*printf ("%s\n", buf);*/\r
171                 /* search for our specific entry */\r
172                 if (!strncmp ((char *)buf, "[RLA/lan/Ethernet] ", 19))\r
173                 {\r
174                         setenv ("ethaddr", buf+19);
175                 } \r
176                 else if (!strncmp ((char *)buf, "[BOARD/SERIAL] ", 15))\r
177                 {\r
178                         setenv ("serial#", buf+15);
179                 } \r
180                 else if (!strncmp ((char *)buf, "[BOARD/TYPE] ", 13))\r
181                 {\r
182                         setenv ("board_id", buf+13);
183                 } \r
184         }\r
185         return (0);
186 }
187