wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 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 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 38 | /***************************************************************************** |
| 39 | * UPM table for 60ns EDO RAM at 25 MHz bus/external clock |
| 40 | *****************************************************************************/ |
wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 41 | static const uint edo_60ns_25MHz_tbl[] = { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 42 | |
| 43 | /* single read (offset 0x00 in upm ram) */ |
| 44 | 0x0ff3fc04,0x08f3fc04,0x00f3fc04,0x00f3fc00, |
| 45 | 0x33f7fc07,0xfffffc05,0xfffffc05,0xfffffc05, |
| 46 | /* burst read (offset 0x08 in upm ram) */ |
| 47 | 0x0ff3fc04,0x08f3fc04,0x00f3fc0c,0x0ff3fc40, |
| 48 | 0x0cf3fc04,0x03f3fc48,0x0cf3fc04,0x03f3fc48, |
| 49 | 0x0cf3fc04,0x03f3fc00,0x3ff7fc07,0xfffffc05, |
| 50 | 0xfffffc05,0xfffffc05,0xfffffc05,0xfffffc05, |
| 51 | /* single write (offset 0x18 in upm ram) */ |
| 52 | 0x0ffffc04,0x08fffc04,0x30fffc00,0xf1fffc07, |
| 53 | 0xfffffc05,0xfffffc05,0xfffffc05,0xfffffc05, |
| 54 | /* burst write (offset 0x20 in upm ram) */ |
| 55 | 0x0ffffc04,0x08fffc00,0x00fffc04,0x03fffc4c, |
| 56 | 0x00fffc00,0x07fffc4c,0x00fffc00,0x0ffffc4c, |
| 57 | 0x00fffc00,0x3ffffc07,0xfffffc05,0xfffffc05, |
| 58 | 0xfffffc05,0xfffffc05,0xfffffc05,0xfffffc05, |
| 59 | /* refresh (offset 0x30 in upm ram) */ |
| 60 | 0xc0fffc04,0x07fffc04,0x0ffffc04,0x0ffffc04, |
| 61 | 0xfffffc05,0xfffffc05,0xfffffc05,0xfffffc05, |
| 62 | 0xfffffc05,0xfffffc05,0xfffffc05,0xfffffc05, |
| 63 | /* exception (offset 0x3C in upm ram) */ |
| 64 | 0xfffffc07,0xfffffc03,0xfffffc05,0xfffffc05, |
wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 67 | /***************************************************************************** |
| 68 | * Print Board Identity |
| 69 | *****************************************************************************/ |
wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 70 | int checkboard (void) |
| 71 | { |
| 72 | puts ("Board:"CONFIG_IDENT_STRING"\n"); |
| 73 | return (0); |
| 74 | } |
| 75 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 76 | /***************************************************************************** |
| 77 | * Initialize DRAM controller |
| 78 | *****************************************************************************/ |
wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 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 | */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 88 | if ((ulong) initdram & 0xff000000) { |
| 89 | volatile uint *addr1, *addr2; |
| 90 | uint i, j; |
wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 91 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 92 | upmconfig (UPMA, (uint *) edo_60ns_25MHz_tbl, |
| 93 | sizeof (edo_60ns_25MHz_tbl) / sizeof (uint)); |
wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 94 | memctl->memc_mptpr = 0x0200; |
| 95 | memctl->memc_mamr = 0x0ca20330; |
| 96 | memctl->memc_or2 = -CFG_DRAM_MAX | OR_CSNT_SAM; |
| 97 | memctl->memc_br2 = CFG_DRAM_BASE | BR_MS_UPMA | BR_V; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 98 | /* |
| 99 | * Do 8 read accesses to DRAM |
| 100 | */ |
| 101 | addr1 = (volatile uint *) 0; |
| 102 | addr2 = (volatile uint *) 0x00400000; |
| 103 | for (i = 0, j = 0; i < 8; i++) |
| 104 | j = addr1[0]; |
| 105 | |
| 106 | /* |
| 107 | * Now check whether we got 4MB or 16MB populated |
| 108 | */ |
| 109 | addr1[0] = 0x12345678; |
| 110 | addr1[1] = 0x9abcdef0; |
| 111 | addr2[0] = 0xfeedc0de; |
| 112 | addr2[1] = 0x47110815; |
| 113 | if (addr1[0] == 0xfeedc0de && addr1[1] == 0x47110815) { |
| 114 | /* only 4MB populated */ |
| 115 | memctl->memc_or2 = -(CFG_DRAM_MAX / 4) | OR_CSNT_SAM; |
| 116 | } |
| 117 | } |
| 118 | |
wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 119 | return -(memctl->memc_or2 & 0xffff0000); |
| 120 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 121 | |
| 122 | /***************************************************************************** |
| 123 | * otherinits after RAM is there and we are relocated to RAM |
| 124 | * note: though this is an int function, nobody cares for the result! |
| 125 | *****************************************************************************/ |
wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 126 | int misc_init_r (void) |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 127 | { |
| 128 | /* read 'factory' part of EEPROM */ |
| 129 | uchar buf[81]; |
| 130 | uchar *p; |
| 131 | uint length; |
| 132 | uint addr; |
| 133 | uint len; |
| 134 | |
| 135 | /* get length first */ |
| 136 | addr = CFG_FACT_OFFSET; |
| 137 | if (eeprom_read (CFG_I2C_FACT_ADDR, addr, buf, 2)) { |
| 138 | bailout: |
| 139 | printf ("cannot read factory configuration\n"); |
| 140 | printf ("be sure to set ethaddr yourself!\n"); |
| 141 | return 0; |
wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 142 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 143 | length = buf[0] + (buf[1] << 8); |
| 144 | addr += 2; |
| 145 | |
| 146 | /* sanity check */ |
| 147 | if (length < 20 || length > CFG_FACT_SIZE - 2) |
| 148 | goto bailout; |
| 149 | |
| 150 | /* read lines */ |
| 151 | while (length > 0) { |
| 152 | /* read one line */ |
| 153 | len = length > 80 ? 80 : length; |
| 154 | if (eeprom_read (CFG_I2C_FACT_ADDR, addr, buf, len)) |
| 155 | goto bailout; |
| 156 | /* mark end of buffer */ |
| 157 | buf[len] = 0; |
| 158 | /* search end of line */ |
| 159 | for (p = buf; *p && *p != 0x0a; p++); |
| 160 | if (!*p) |
| 161 | goto bailout; |
| 162 | *p++ = 0; |
| 163 | /* advance to next line start */ |
| 164 | length -= p - buf; |
| 165 | addr += p - buf; |
| 166 | /*printf ("%s\n", buf); */ |
| 167 | /* search for our specific entry */ |
| 168 | if (!strncmp ((char *) buf, "[RLA/lan/Ethernet] ", 19)) { |
| 169 | setenv ("ethaddr", buf + 19); |
| 170 | } else if (!strncmp ((char *) buf, "[BOARD/SERIAL] ", 15)) { |
| 171 | setenv ("serial#", buf + 15); |
| 172 | } else if (!strncmp ((char *) buf, "[BOARD/TYPE] ", 13)) { |
| 173 | setenv ("board_id", buf + 13); |
| 174 | } |
| 175 | } |
wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 176 | return (0); |
| 177 | } |