wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 Wolfgang Grandegger <wg@denx.de> |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <mpc824x.h> |
Heiko Schocher | 76756e4 | 2009-03-26 07:33:59 +0100 | [diff] [blame] | 9 | #include <net.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 10 | #include <pci.h> |
Ben Warren | e309053 | 2008-08-31 10:08:43 -0700 | [diff] [blame] | 11 | #include <netdev.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 12 | |
| 13 | #include "pn62.h" |
| 14 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 15 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 16 | |
| 17 | static int get_serial_number (char *string, int size); |
Mike Frysinger | b6b4625 | 2009-02-11 18:38:38 -0500 | [diff] [blame] | 18 | static void get_mac_address(int id, u8 *mac); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 19 | |
| 20 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 21 | void show_boot_progress (int phase) |
| 22 | { |
| 23 | /* |
| 24 | * Show phases of the bootm command on the front panel |
| 25 | * LEDs and the scratchpad register #3 as well. We use |
| 26 | * blinking LEDs for logical "1". |
| 27 | */ |
| 28 | if (phase > 0) { |
| 29 | set_led (8, (phase & 0x1) ? LED_SLOW_CLOCK : LED_0); |
| 30 | set_led (9, (phase & 0x2) ? LED_SLOW_CLOCK : LED_0); |
| 31 | set_led (10, (phase & 0x4) ? LED_SLOW_CLOCK : LED_0); |
| 32 | set_led (11, (phase & 0x8) ? LED_SLOW_CLOCK : LED_0); |
| 33 | } |
| 34 | i2155x_write_scrapad (BOOT_STATUS, phase); |
| 35 | if (phase < 0) |
| 36 | i2155x_write_scrapad (BOOT_DONE, BOOT_DONE_ERROR); |
| 37 | } |
| 38 | #endif |
| 39 | |
| 40 | void show_startup_phase (int phase) |
| 41 | { |
| 42 | /* |
| 43 | * Show the phase of U-Boot startup on the front panel |
| 44 | * LEDs and the scratchpad register #3 as well. |
| 45 | */ |
| 46 | if (phase > 0) { |
| 47 | set_led (8, (phase & 0x1) ? LED_1 : LED_0); |
| 48 | set_led (9, (phase & 0x2) ? LED_1 : LED_0); |
| 49 | set_led (10, (phase & 0x4) ? LED_1 : LED_0); |
| 50 | set_led (11, (phase & 0x8) ? LED_1 : LED_0); |
| 51 | } |
| 52 | i2155x_write_scrapad (BOOT_STATUS, phase); |
| 53 | if (phase < 0) |
| 54 | i2155x_write_scrapad (BOOT_DONE, BOOT_DONE_ERROR); |
| 55 | } |
| 56 | |
| 57 | int checkboard (void) |
| 58 | { |
| 59 | show_startup_phase (1); |
| 60 | puts ("Board: PN62\n"); |
| 61 | return 0; |
| 62 | } |
| 63 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 64 | phys_size_t initdram (int board_type) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 65 | { |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 66 | long size; |
| 67 | long new_bank0_end; |
| 68 | long mear1; |
| 69 | long emear1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 70 | |
| 71 | show_startup_phase (2); |
| 72 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 73 | size = get_ram_size(CONFIG_SYS_SDRAM_BASE, CONFIG_SYS_MAX_RAM_SIZE); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 74 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 75 | new_bank0_end = size - 1; |
| 76 | mear1 = mpc824x_mpc107_getreg (MEAR1); |
| 77 | emear1 = mpc824x_mpc107_getreg (EMEAR1); |
| 78 | mear1 = (mear1 & 0xFFFFFF00) | |
| 79 | ((new_bank0_end & MICR_ADDR_MASK) >> MICR_ADDR_SHIFT); |
| 80 | emear1 = (emear1 & 0xFFFFFF00) | |
| 81 | ((new_bank0_end & MICR_ADDR_MASK) >> MICR_EADDR_SHIFT); |
| 82 | mpc824x_mpc107_setreg (MEAR1, mear1); |
| 83 | mpc824x_mpc107_setreg (EMEAR1, emear1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 84 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 85 | return (size); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Initialize PCI Devices. We rely on auto-configuration. |
| 90 | */ |
| 91 | #ifndef CONFIG_PCI_PNP |
| 92 | #error "CONFIG_PCI_PNP is not defined, please correct!" |
| 93 | #endif |
| 94 | |
| 95 | struct pci_controller hose = { |
| 96 | }; |
| 97 | |
stroese | ad10dd9 | 2003-02-14 11:21:23 +0000 | [diff] [blame] | 98 | void pci_init_board (void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 99 | { |
| 100 | show_startup_phase (4); |
| 101 | pci_mpc824x_init (&hose); |
| 102 | |
| 103 | show_startup_phase (5); |
| 104 | i2155x_init (); |
| 105 | show_startup_phase (6); |
| 106 | am79c95x_init (); |
| 107 | show_startup_phase (7); |
| 108 | } |
| 109 | |
| 110 | int misc_init_r (void) |
| 111 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 112 | char str[20]; |
| 113 | u8 mac[6]; |
| 114 | |
| 115 | show_startup_phase (8); |
| 116 | /* |
| 117 | * Get serial number and ethernet addresses if not already defined |
| 118 | * and update the board info structure and the environment. |
| 119 | */ |
| 120 | if (getenv ("serial#") == NULL && |
| 121 | get_serial_number (str, strlen (str)) > 0) { |
| 122 | setenv ("serial#", str); |
| 123 | } |
| 124 | show_startup_phase (9); |
| 125 | |
Mike Frysinger | b6b4625 | 2009-02-11 18:38:38 -0500 | [diff] [blame] | 126 | if (!eth_getenv_enetaddr("ethaddr", mac)) { |
| 127 | get_mac_address(0, mac); |
| 128 | eth_setenv_enetaddr("ethaddr", mac); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 129 | } |
| 130 | show_startup_phase (10); |
| 131 | |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 132 | #ifdef CONFIG_HAS_ETH1 |
Mike Frysinger | b6b4625 | 2009-02-11 18:38:38 -0500 | [diff] [blame] | 133 | if (!eth_getenv_enetaddr("eth1addr", mac)) { |
| 134 | get_mac_address(1, mac); |
| 135 | eth_setenv_enetaddr("eth1addr", mac); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 136 | } |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 137 | #endif /* CONFIG_HAS_ETH1 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 138 | show_startup_phase (11); |
| 139 | |
| 140 | /* Tell everybody that U-Boot is up and runnig */ |
| 141 | i2155x_write_scrapad (0, 0x12345678); |
| 142 | return (0); |
| 143 | } |
| 144 | |
| 145 | static int get_serial_number (char *string, int size) |
| 146 | { |
| 147 | int i; |
| 148 | char c; |
| 149 | |
| 150 | if (size < I2155X_VPD_SN_SIZE) |
| 151 | size = I2155X_VPD_SN_SIZE; |
| 152 | for (i = 0; i < (size - 1); i++) { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 153 | i2155x_read_vpd (I2155X_VPD_SN_START + i, 1, (uchar *)&c); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 154 | if (c == '\0') |
| 155 | break; |
| 156 | string[i] = c; |
| 157 | } |
| 158 | string[i] = '\0'; /* make sure it's terminated */ |
| 159 | |
| 160 | return i; |
| 161 | } |
| 162 | |
Mike Frysinger | b6b4625 | 2009-02-11 18:38:38 -0500 | [diff] [blame] | 163 | static void get_mac_address(int id, u8 *mac) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 164 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 165 | i2155x_read_vpd (I2155X_VPD_MAC0_START + 6 * id, 6, mac); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 166 | } |
Ben Warren | e309053 | 2008-08-31 10:08:43 -0700 | [diff] [blame] | 167 | |
| 168 | int board_eth_init(bd_t *bis) |
| 169 | { |
| 170 | return pci_eth_init(bis); |
| 171 | } |