blob: 4d875271522e0eefb2c4387dfce6ba73a2cae5e7 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002 Wolfgang Grandegger <wg@denx.de>
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
24#include <mpc824x.h>
25#include <pci.h>
26
27#include "pn62.h"
28
29
30static int get_serial_number (char *string, int size);
31static int get_mac_address (int id, u8 * mac, char *string, int size);
32
33#ifdef CONFIG_SHOW_BOOT_PROGRESS
34void show_boot_progress (int phase)
35{
36 /*
37 * Show phases of the bootm command on the front panel
38 * LEDs and the scratchpad register #3 as well. We use
39 * blinking LEDs for logical "1".
40 */
41 if (phase > 0) {
42 set_led (8, (phase & 0x1) ? LED_SLOW_CLOCK : LED_0);
43 set_led (9, (phase & 0x2) ? LED_SLOW_CLOCK : LED_0);
44 set_led (10, (phase & 0x4) ? LED_SLOW_CLOCK : LED_0);
45 set_led (11, (phase & 0x8) ? LED_SLOW_CLOCK : LED_0);
46 }
47 i2155x_write_scrapad (BOOT_STATUS, phase);
48 if (phase < 0)
49 i2155x_write_scrapad (BOOT_DONE, BOOT_DONE_ERROR);
50}
51#endif
52
53void show_startup_phase (int phase)
54{
55 /*
56 * Show the phase of U-Boot startup on the front panel
57 * LEDs and the scratchpad register #3 as well.
58 */
59 if (phase > 0) {
60 set_led (8, (phase & 0x1) ? LED_1 : LED_0);
61 set_led (9, (phase & 0x2) ? LED_1 : LED_0);
62 set_led (10, (phase & 0x4) ? LED_1 : LED_0);
63 set_led (11, (phase & 0x8) ? LED_1 : LED_0);
64 }
65 i2155x_write_scrapad (BOOT_STATUS, phase);
66 if (phase < 0)
67 i2155x_write_scrapad (BOOT_DONE, BOOT_DONE_ERROR);
68}
69
70int checkboard (void)
71{
72 show_startup_phase (1);
73 puts ("Board: PN62\n");
74 return 0;
75}
76
77long int initdram (int board_type)
78{
79 int i, cnt;
80 volatile uchar *base = CFG_SDRAM_BASE;
81 volatile ulong *addr;
82 ulong save[32];
83 ulong val, ret = 0;
84
85 show_startup_phase (2);
86
87 for (i = 0, cnt = (CFG_MAX_RAM_SIZE / sizeof (long)) >> 1; cnt > 0;
88 cnt >>= 1) {
89 addr = (volatile ulong *) base + cnt;
90 save[i++] = *addr;
91 *addr = ~cnt;
92 }
93
94 addr = (volatile ulong *) base;
95 save[i] = *addr;
96 *addr = 0;
97
98 if (*addr != 0) {
99 *addr = save[i];
100 goto Done;
101 }
102
103 for (cnt = 1; cnt <= CFG_MAX_RAM_SIZE / sizeof (long); cnt <<= 1) {
104 addr = (volatile ulong *) base + cnt;
105 val = *addr;
106 *addr = save[--i];
107 if (val != ~cnt) {
108 ulong new_bank0_end = cnt * sizeof (long) - 1;
109 ulong mear1 = mpc824x_mpc107_getreg (MEAR1);
110 ulong emear1 = mpc824x_mpc107_getreg (EMEAR1);
111
112 mear1 = (mear1 & 0xFFFFFF00) |
113 ((new_bank0_end & MICR_ADDR_MASK) >> MICR_ADDR_SHIFT);
114 emear1 = (emear1 & 0xFFFFFF00) |
115 ((new_bank0_end & MICR_ADDR_MASK) >> MICR_EADDR_SHIFT);
116 mpc824x_mpc107_setreg (MEAR1, mear1);
117 mpc824x_mpc107_setreg (EMEAR1, emear1);
118
119 ret = cnt * sizeof (long);
120 goto Done;
121 }
122 }
123
124 ret = CFG_MAX_RAM_SIZE;
125 Done:
126 show_startup_phase (3);
127 return ret;
128}
129
130/*
131 * Initialize PCI Devices. We rely on auto-configuration.
132 */
133#ifndef CONFIG_PCI_PNP
134#error "CONFIG_PCI_PNP is not defined, please correct!"
135#endif
136
137struct pci_controller hose = {
138};
139
140void pci_init (void)
141{
142 show_startup_phase (4);
143 pci_mpc824x_init (&hose);
144
145 show_startup_phase (5);
146 i2155x_init ();
147 show_startup_phase (6);
148 am79c95x_init ();
149 show_startup_phase (7);
150}
151
152int misc_init_r (void)
153{
154 DECLARE_GLOBAL_DATA_PTR;
155
156 char str[20];
157 u8 mac[6];
158
159 show_startup_phase (8);
160 /*
161 * Get serial number and ethernet addresses if not already defined
162 * and update the board info structure and the environment.
163 */
164 if (getenv ("serial#") == NULL &&
165 get_serial_number (str, strlen (str)) > 0) {
166 setenv ("serial#", str);
167 }
168 show_startup_phase (9);
169
170 if (getenv ("ethaddr") == NULL &&
171 get_mac_address (0, mac, str, sizeof (str)) > 0) {
172 setenv ("ethaddr", str);
173 memcpy (gd->bd->bi_enetaddr, mac, 6);
174 }
175 show_startup_phase (10);
176
177 if (getenv ("eth1addr") == NULL &&
178 get_mac_address (1, mac, str, sizeof (str)) > 0) {
179 setenv ("eth1addr", str);
180 memcpy (gd->bd->bi_enet1addr, mac, 6);
181 }
182 show_startup_phase (11);
183
184 /* Tell everybody that U-Boot is up and runnig */
185 i2155x_write_scrapad (0, 0x12345678);
186 return (0);
187}
188
189static int get_serial_number (char *string, int size)
190{
191 int i;
192 char c;
193
194 if (size < I2155X_VPD_SN_SIZE)
195 size = I2155X_VPD_SN_SIZE;
196 for (i = 0; i < (size - 1); i++) {
197 i2155x_read_vpd (I2155X_VPD_SN_START + i, 1, &c);
198 if (c == '\0')
199 break;
200 string[i] = c;
201 }
202 string[i] = '\0'; /* make sure it's terminated */
203
204 return i;
205}
206
207static int get_mac_address (int id, u8 * mac, char *string, int size)
208{
209 if (size < 6 * 3)
210 return -1;
211
212 i2155x_read_vpd (I2155X_VPD_MAC0_START + 6 * id, 6, mac);
213 return sprintf (string, "%02x:%02x:%02x:%02x:%02x:%02x",
214 mac[0], mac[1], mac[2],
215 mac[3], mac[4], mac[5]);
216}