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