blob: 1a2bdf430dcae95d3651cdc1a6a3638931c2932f [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>
Ben Warren052a5ea2008-08-31 20:37:00 -070028#include <netdev.h>
wdenkc6097192002-11-03 00:24:07 +000029
Wolfgang Denk6405a152006-03-31 18:32:53 +020030DECLARE_GLOBAL_DATA_PTR;
31
wdenkc6097192002-11-03 00:24:07 +000032int checkboard (void)
33{
34 puts ( "Board: OXC8240\n" );
35 return 0;
36}
37
Becky Brucebd99ae72008-06-09 16:03:40 -050038phys_size_t initdram (int board_type)
wdenkc6097192002-11-03 00:24:07 +000039{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020040#ifndef CONFIG_SYS_RAMBOOT
wdenk87249ba2004-01-06 22:38:14 +000041 long size;
42 long new_bank0_end;
43 long mear1;
44 long emear1;
wdenkc6097192002-11-03 00:24:07 +000045
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020046 size = get_ram_size(CONFIG_SYS_SDRAM_BASE, CONFIG_SYS_MAX_RAM_SIZE);
wdenkc6097192002-11-03 00:24:07 +000047
wdenk87249ba2004-01-06 22:38:14 +000048 new_bank0_end = size - 1;
49 mear1 = mpc824x_mpc107_getreg(MEAR1);
50 emear1 = mpc824x_mpc107_getreg(EMEAR1);
51 mear1 = (mear1 & 0xFFFFFF00) |
52 ((new_bank0_end & MICR_ADDR_MASK) >> MICR_ADDR_SHIFT);
53 emear1 = (emear1 & 0xFFFFFF00) |
54 ((new_bank0_end & MICR_ADDR_MASK) >> MICR_EADDR_SHIFT);
55 mpc824x_mpc107_setreg(MEAR1, mear1);
56 mpc824x_mpc107_setreg(EMEAR1, emear1);
wdenkc6097192002-11-03 00:24:07 +000057
wdenk87249ba2004-01-06 22:38:14 +000058 return (size);
wdenkc6097192002-11-03 00:24:07 +000059#else
60 /* if U-Boot starts from RAM, then suppose we have 16Mb of RAM */
61 return (16 << 20);
62#endif
63}
64
65/*
66 * Initialize PCI Devices, report devices found.
67 */
68#ifndef CONFIG_PCI_PNP
69static struct pci_config_table pci_oxc_config_table[] = {
70 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x14, PCI_ANY_ID,
71 pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
72 PCI_ENET0_MEMADDR,
73 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
74 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x15, PCI_ANY_ID,
75 pci_cfgfunc_config_device, { PCI_ENET1_IOADDR,
76 PCI_ENET1_MEMADDR,
77 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
78 { }
79};
80#endif
81
82static struct pci_controller hose = {
83#ifndef CONFIG_PCI_PNP
84 config_table: pci_oxc_config_table,
85#endif
86};
87
stroesef5dd4102003-02-14 11:21:23 +000088void pci_init_board (void)
wdenkc6097192002-11-03 00:24:07 +000089{
90 pci_mpc824x_init(&hose);
91}
92
wdenkda55c6e2004-01-20 23:12:12 +000093int board_early_init_f (void)
wdenkc6097192002-11-03 00:24:07 +000094{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020095 *(volatile unsigned char *)(CONFIG_SYS_CPLD_RESET) = 0x89;
wdenkc6097192002-11-03 00:24:07 +000096 return 0;
97}
98
99#ifdef CONFIG_WATCHDOG
100void oxc_wdt_reset(void)
101{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200102 *(volatile unsigned char *)(CONFIG_SYS_CPLD_WATCHDOG) = 0xff;
wdenkc6097192002-11-03 00:24:07 +0000103}
104
105void watchdog_reset(void)
106{
107 int re_enable = disable_interrupts();
108
109 oxc_wdt_reset();
110 if (re_enable)
111 enable_interrupts();
112}
113#endif
114
115static int oxc_get_expander(unsigned char addr, unsigned char * val)
116{
117 return i2c_read(addr, 0, 0, val, 1);
118}
119
120static int oxc_set_expander(unsigned char addr, unsigned char val)
121{
122 return i2c_write(addr, 0, 0, &val, 1);
123}
124
125static int expander0alive = 0;
126
127#ifdef CONFIG_SHOW_ACTIVITY
128static int ledtoggle = 0;
129static int ledstatus = 1;
130
131void oxc_toggle_activeled(void)
132{
133 ledtoggle++;
134}
135
wdenkc0aa5c52003-12-06 19:49:23 +0000136void board_show_activity (ulong timestamp)
137{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200138 if ((timestamp % (CONFIG_SYS_HZ / 10)) == 0)
wdenkc0aa5c52003-12-06 19:49:23 +0000139 oxc_toggle_activeled ();
140}
141
wdenkc6097192002-11-03 00:24:07 +0000142void show_activity(int arg)
143{
144 static unsigned char led = 0;
145 unsigned char val;
146
147 if (!expander0alive) return;
148
149 if ((ledtoggle > (2 * arg)) && ledstatus) {
150 led ^= 0x80;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200151 oxc_get_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, &val);
wdenkc6097192002-11-03 00:24:07 +0000152 udelay(200);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200153 oxc_set_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, (val & 0x7F) | led);
wdenkc6097192002-11-03 00:24:07 +0000154 ledtoggle = 0;
155 }
156}
157#endif
158
159#ifdef CONFIG_SHOW_BOOT_PROGRESS
160void show_boot_progress(int arg)
161{
162 unsigned char val;
163
164 if (!expander0alive) return;
165
166 if (arg > 0 && ledstatus) {
167 ledstatus = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200168 oxc_get_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, &val);
wdenkc6097192002-11-03 00:24:07 +0000169 udelay(200);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200170 oxc_set_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, val | 0x80);
wdenkc6097192002-11-03 00:24:07 +0000171 } else if (arg < 0) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200172 oxc_get_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, &val);
wdenkc6097192002-11-03 00:24:07 +0000173 udelay(200);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200174 oxc_set_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, val & 0x7F);
wdenkc6097192002-11-03 00:24:07 +0000175 ledstatus = 1;
176 }
177}
178#endif
179
180int misc_init_r (void)
181{
182 /* check whether the i2c expander #0 is accessible */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200183 if (!oxc_set_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, 0x7F)) {
wdenkc6097192002-11-03 00:24:07 +0000184 udelay(200);
185 expander0alive = 1;
186 }
187
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200188#ifdef CONFIG_SYS_OXC_GENERATE_IP
wdenkc6097192002-11-03 00:24:07 +0000189 {
wdenkc6097192002-11-03 00:24:07 +0000190 char str[32];
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200191 unsigned long ip = CONFIG_SYS_OXC_IPMASK;
wdenkc6097192002-11-03 00:24:07 +0000192 bd_t *bd = gd->bd;
193
194 if (expander0alive) {
195 unsigned char val;
196
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200197 if (!oxc_get_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, &val)) {
wdenkc6097192002-11-03 00:24:07 +0000198 ip = (ip & 0xffffff00) | ((val & 0x7c) >> 2);
199 }
200 }
201
202 if ((ip & 0xff) < 3) {
203 /* if fail, set x.x.x.254 */
204 ip = (ip & 0xffffff00) | 0xfe;
205 }
206
207 bd->bi_ip_addr = ip;
208 sprintf(str, "%ld.%ld.%ld.%ld",
209 (bd->bi_ip_addr & 0xff000000) >> 24,
210 (bd->bi_ip_addr & 0x00ff0000) >> 16,
211 (bd->bi_ip_addr & 0x0000ff00) >> 8,
212 (bd->bi_ip_addr & 0x000000ff));
213 setenv("ipaddr", str);
214 printf("ip: %s\n", str);
215 }
216#endif
217 return (0);
218}
Ben Warren052a5ea2008-08-31 20:37:00 -0700219
220int board_eth_init(bd_t *bis)
221{
222 return pci_eth_init(bis);
223}