blob: fa7ff0215c01bb7a2fdaa14ecb8a6e8e019cb3ce [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
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
29int checkboard (void)
30{
31 puts ( "Board: OXC8240\n" );
32 return 0;
33}
34
35long int initdram (int board_type)
36{
37#ifndef CFG_RAMBOOT
wdenk87249ba2004-01-06 22:38:14 +000038 long size;
39 long new_bank0_end;
40 long mear1;
41 long emear1;
wdenkc6097192002-11-03 00:24:07 +000042
wdenk87249ba2004-01-06 22:38:14 +000043 size = get_ram_size(CFG_SDRAM_BASE, CFG_MAX_RAM_SIZE);
wdenkc6097192002-11-03 00:24:07 +000044
wdenk87249ba2004-01-06 22:38:14 +000045 new_bank0_end = size - 1;
46 mear1 = mpc824x_mpc107_getreg(MEAR1);
47 emear1 = mpc824x_mpc107_getreg(EMEAR1);
48 mear1 = (mear1 & 0xFFFFFF00) |
49 ((new_bank0_end & MICR_ADDR_MASK) >> MICR_ADDR_SHIFT);
50 emear1 = (emear1 & 0xFFFFFF00) |
51 ((new_bank0_end & MICR_ADDR_MASK) >> MICR_EADDR_SHIFT);
52 mpc824x_mpc107_setreg(MEAR1, mear1);
53 mpc824x_mpc107_setreg(EMEAR1, emear1);
wdenkc6097192002-11-03 00:24:07 +000054
wdenk87249ba2004-01-06 22:38:14 +000055 return (size);
wdenkc6097192002-11-03 00:24:07 +000056#else
57 /* if U-Boot starts from RAM, then suppose we have 16Mb of RAM */
58 return (16 << 20);
59#endif
60}
61
62/*
63 * Initialize PCI Devices, report devices found.
64 */
65#ifndef CONFIG_PCI_PNP
66static struct pci_config_table pci_oxc_config_table[] = {
67 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x14, PCI_ANY_ID,
68 pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
69 PCI_ENET0_MEMADDR,
70 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
71 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x15, PCI_ANY_ID,
72 pci_cfgfunc_config_device, { PCI_ENET1_IOADDR,
73 PCI_ENET1_MEMADDR,
74 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
75 { }
76};
77#endif
78
79static struct pci_controller hose = {
80#ifndef CONFIG_PCI_PNP
81 config_table: pci_oxc_config_table,
82#endif
83};
84
stroesef5dd4102003-02-14 11:21:23 +000085void pci_init_board (void)
wdenkc6097192002-11-03 00:24:07 +000086{
87 pci_mpc824x_init(&hose);
88}
89
wdenkda55c6e2004-01-20 23:12:12 +000090int board_early_init_f (void)
wdenkc6097192002-11-03 00:24:07 +000091{
92 *(volatile unsigned char *)(CFG_CPLD_RESET) = 0x89;
93 return 0;
94}
95
96#ifdef CONFIG_WATCHDOG
97void oxc_wdt_reset(void)
98{
99 *(volatile unsigned char *)(CFG_CPLD_WATCHDOG) = 0xff;
100}
101
102void watchdog_reset(void)
103{
104 int re_enable = disable_interrupts();
105
106 oxc_wdt_reset();
107 if (re_enable)
108 enable_interrupts();
109}
110#endif
111
112static int oxc_get_expander(unsigned char addr, unsigned char * val)
113{
114 return i2c_read(addr, 0, 0, val, 1);
115}
116
117static int oxc_set_expander(unsigned char addr, unsigned char val)
118{
119 return i2c_write(addr, 0, 0, &val, 1);
120}
121
122static int expander0alive = 0;
123
124#ifdef CONFIG_SHOW_ACTIVITY
125static int ledtoggle = 0;
126static int ledstatus = 1;
127
128void oxc_toggle_activeled(void)
129{
130 ledtoggle++;
131}
132
wdenkc0aa5c52003-12-06 19:49:23 +0000133void board_show_activity (ulong timestamp)
134{
135 if ((timestamp % (CFG_HZ / 10)) == 0)
136 oxc_toggle_activeled ();
137}
138
wdenkc6097192002-11-03 00:24:07 +0000139void show_activity(int arg)
140{
141 static unsigned char led = 0;
142 unsigned char val;
143
144 if (!expander0alive) return;
145
146 if ((ledtoggle > (2 * arg)) && ledstatus) {
147 led ^= 0x80;
148 oxc_get_expander(CFG_I2C_EXPANDER0_ADDR, &val);
149 udelay(200);
150 oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, (val & 0x7F) | led);
151 ledtoggle = 0;
152 }
153}
154#endif
155
156#ifdef CONFIG_SHOW_BOOT_PROGRESS
157void show_boot_progress(int arg)
158{
159 unsigned char val;
160
161 if (!expander0alive) return;
162
163 if (arg > 0 && ledstatus) {
164 ledstatus = 0;
165 oxc_get_expander(CFG_I2C_EXPANDER0_ADDR, &val);
166 udelay(200);
167 oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, val | 0x80);
168 } else if (arg < 0) {
169 oxc_get_expander(CFG_I2C_EXPANDER0_ADDR, &val);
170 udelay(200);
171 oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, val & 0x7F);
172 ledstatus = 1;
173 }
174}
175#endif
176
177int misc_init_r (void)
178{
179 /* check whether the i2c expander #0 is accessible */
180 if (!oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, 0x7F)) {
181 udelay(200);
182 expander0alive = 1;
183 }
184
185#ifdef CFG_OXC_GENERATE_IP
186 {
187 DECLARE_GLOBAL_DATA_PTR;
188
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}