wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Rob Taylor, Flying Pig Systems. robt@flyingpig.com. |
| 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 <mpc824x.h> |
| 26 | #include <pci.h> |
| 27 | #include <i2c.h> |
| 28 | |
| 29 | int checkboard (void) |
| 30 | { |
| 31 | puts ( "Board: OXC8240\n" ); |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | long int initdram (int board_type) |
| 36 | { |
| 37 | #ifndef CFG_RAMBOOT |
| 38 | int i, cnt; |
| 39 | volatile uchar * base= CFG_SDRAM_BASE; |
| 40 | volatile ulong * addr; |
| 41 | ulong save[32]; |
| 42 | ulong val, ret = 0; |
| 43 | |
| 44 | for (i=0, cnt=(CFG_MAX_RAM_SIZE / sizeof(long)) >> 1; cnt > 0; cnt >>= 1) { |
| 45 | addr = (volatile ulong *)base + cnt; |
| 46 | save[i++] = *addr; |
| 47 | *addr = ~cnt; |
| 48 | } |
| 49 | |
| 50 | addr = (volatile ulong *)base; |
| 51 | save[i] = *addr; |
| 52 | *addr = 0; |
| 53 | |
| 54 | if (*addr != 0) { |
| 55 | *addr = save[i]; |
| 56 | goto Done; |
| 57 | } |
| 58 | |
| 59 | for (cnt = 1; cnt <= CFG_MAX_RAM_SIZE / sizeof(long); cnt <<= 1) { |
| 60 | addr = (volatile ulong *)base + cnt; |
| 61 | val = *addr; |
| 62 | *addr = save[--i]; |
| 63 | if (val != ~cnt) { |
| 64 | ulong new_bank0_end = cnt * sizeof(long) - 1; |
| 65 | ulong mear1 = mpc824x_mpc107_getreg(MEAR1); |
| 66 | ulong emear1 = mpc824x_mpc107_getreg(EMEAR1); |
| 67 | mear1 = (mear1 & 0xFFFFFF00) | |
| 68 | ((new_bank0_end & MICR_ADDR_MASK) >> MICR_ADDR_SHIFT); |
| 69 | emear1 = (emear1 & 0xFFFFFF00) | |
| 70 | ((new_bank0_end & MICR_ADDR_MASK) >> MICR_EADDR_SHIFT); |
| 71 | mpc824x_mpc107_setreg(MEAR1, mear1); |
| 72 | mpc824x_mpc107_setreg(EMEAR1, emear1); |
| 73 | |
| 74 | ret = cnt * sizeof(long); |
| 75 | goto Done; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | ret = CFG_MAX_RAM_SIZE; |
| 80 | Done: |
| 81 | return ret; |
| 82 | #else |
| 83 | /* if U-Boot starts from RAM, then suppose we have 16Mb of RAM */ |
| 84 | return (16 << 20); |
| 85 | #endif |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Initialize PCI Devices, report devices found. |
| 90 | */ |
| 91 | #ifndef CONFIG_PCI_PNP |
| 92 | static struct pci_config_table pci_oxc_config_table[] = { |
| 93 | { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x14, PCI_ANY_ID, |
| 94 | pci_cfgfunc_config_device, { PCI_ENET0_IOADDR, |
| 95 | PCI_ENET0_MEMADDR, |
| 96 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }}, |
| 97 | { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x15, PCI_ANY_ID, |
| 98 | pci_cfgfunc_config_device, { PCI_ENET1_IOADDR, |
| 99 | PCI_ENET1_MEMADDR, |
| 100 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }}, |
| 101 | { } |
| 102 | }; |
| 103 | #endif |
| 104 | |
| 105 | static struct pci_controller hose = { |
| 106 | #ifndef CONFIG_PCI_PNP |
| 107 | config_table: pci_oxc_config_table, |
| 108 | #endif |
| 109 | }; |
| 110 | |
stroese | f5dd410 | 2003-02-14 11:21:23 +0000 | [diff] [blame] | 111 | void pci_init_board (void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 112 | { |
| 113 | pci_mpc824x_init(&hose); |
| 114 | } |
| 115 | |
| 116 | int board_pre_init (void) |
| 117 | { |
| 118 | *(volatile unsigned char *)(CFG_CPLD_RESET) = 0x89; |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | #ifdef CONFIG_WATCHDOG |
| 123 | void oxc_wdt_reset(void) |
| 124 | { |
| 125 | *(volatile unsigned char *)(CFG_CPLD_WATCHDOG) = 0xff; |
| 126 | } |
| 127 | |
| 128 | void watchdog_reset(void) |
| 129 | { |
| 130 | int re_enable = disable_interrupts(); |
| 131 | |
| 132 | oxc_wdt_reset(); |
| 133 | if (re_enable) |
| 134 | enable_interrupts(); |
| 135 | } |
| 136 | #endif |
| 137 | |
| 138 | static int oxc_get_expander(unsigned char addr, unsigned char * val) |
| 139 | { |
| 140 | return i2c_read(addr, 0, 0, val, 1); |
| 141 | } |
| 142 | |
| 143 | static int oxc_set_expander(unsigned char addr, unsigned char val) |
| 144 | { |
| 145 | return i2c_write(addr, 0, 0, &val, 1); |
| 146 | } |
| 147 | |
| 148 | static int expander0alive = 0; |
| 149 | |
| 150 | #ifdef CONFIG_SHOW_ACTIVITY |
| 151 | static int ledtoggle = 0; |
| 152 | static int ledstatus = 1; |
| 153 | |
| 154 | void oxc_toggle_activeled(void) |
| 155 | { |
| 156 | ledtoggle++; |
| 157 | } |
| 158 | |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame^] | 159 | void board_show_activity (ulong timestamp) |
| 160 | { |
| 161 | if ((timestamp % (CFG_HZ / 10)) == 0) |
| 162 | oxc_toggle_activeled (); |
| 163 | } |
| 164 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 165 | void show_activity(int arg) |
| 166 | { |
| 167 | static unsigned char led = 0; |
| 168 | unsigned char val; |
| 169 | |
| 170 | if (!expander0alive) return; |
| 171 | |
| 172 | if ((ledtoggle > (2 * arg)) && ledstatus) { |
| 173 | led ^= 0x80; |
| 174 | oxc_get_expander(CFG_I2C_EXPANDER0_ADDR, &val); |
| 175 | udelay(200); |
| 176 | oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, (val & 0x7F) | led); |
| 177 | ledtoggle = 0; |
| 178 | } |
| 179 | } |
| 180 | #endif |
| 181 | |
| 182 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 183 | void show_boot_progress(int arg) |
| 184 | { |
| 185 | unsigned char val; |
| 186 | |
| 187 | if (!expander0alive) return; |
| 188 | |
| 189 | if (arg > 0 && ledstatus) { |
| 190 | ledstatus = 0; |
| 191 | oxc_get_expander(CFG_I2C_EXPANDER0_ADDR, &val); |
| 192 | udelay(200); |
| 193 | oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, val | 0x80); |
| 194 | } else if (arg < 0) { |
| 195 | oxc_get_expander(CFG_I2C_EXPANDER0_ADDR, &val); |
| 196 | udelay(200); |
| 197 | oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, val & 0x7F); |
| 198 | ledstatus = 1; |
| 199 | } |
| 200 | } |
| 201 | #endif |
| 202 | |
| 203 | int misc_init_r (void) |
| 204 | { |
| 205 | /* check whether the i2c expander #0 is accessible */ |
| 206 | if (!oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, 0x7F)) { |
| 207 | udelay(200); |
| 208 | expander0alive = 1; |
| 209 | } |
| 210 | |
| 211 | #ifdef CFG_OXC_GENERATE_IP |
| 212 | { |
| 213 | DECLARE_GLOBAL_DATA_PTR; |
| 214 | |
| 215 | char str[32]; |
| 216 | unsigned long ip = CFG_OXC_IPMASK; |
| 217 | bd_t *bd = gd->bd; |
| 218 | |
| 219 | if (expander0alive) { |
| 220 | unsigned char val; |
| 221 | |
| 222 | if (!oxc_get_expander(CFG_I2C_EXPANDER0_ADDR, &val)) { |
| 223 | ip = (ip & 0xffffff00) | ((val & 0x7c) >> 2); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | if ((ip & 0xff) < 3) { |
| 228 | /* if fail, set x.x.x.254 */ |
| 229 | ip = (ip & 0xffffff00) | 0xfe; |
| 230 | } |
| 231 | |
| 232 | bd->bi_ip_addr = ip; |
| 233 | sprintf(str, "%ld.%ld.%ld.%ld", |
| 234 | (bd->bi_ip_addr & 0xff000000) >> 24, |
| 235 | (bd->bi_ip_addr & 0x00ff0000) >> 16, |
| 236 | (bd->bi_ip_addr & 0x0000ff00) >> 8, |
| 237 | (bd->bi_ip_addr & 0x000000ff)); |
| 238 | setenv("ipaddr", str); |
| 239 | printf("ip: %s\n", str); |
| 240 | } |
| 241 | #endif |
| 242 | return (0); |
| 243 | } |