]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/oxc/oxc.c
imported Freescale specific U-Boot additions for i.MX28,... release L2.6.31_10.08.01
[karo-tx-uboot.git] / board / oxc / oxc.c
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 #include <netdev.h>
29
30 DECLARE_GLOBAL_DATA_PTR;
31
32 int checkboard (void)
33 {
34         puts (  "Board: OXC8240\n" );
35         return 0;
36 }
37
38 phys_size_t initdram (int board_type)
39 {
40 #ifndef CONFIG_SYS_RAMBOOT
41         long size;
42         long new_bank0_end;
43         long mear1;
44         long emear1;
45
46         size = get_ram_size(CONFIG_SYS_SDRAM_BASE, CONFIG_SYS_MAX_RAM_SIZE);
47
48         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);
57
58         return (size);
59 #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
69 static 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
82 static struct pci_controller hose = {
83 #ifndef CONFIG_PCI_PNP
84         config_table: pci_oxc_config_table,
85 #endif
86 };
87
88 void pci_init_board (void)
89 {
90         pci_mpc824x_init(&hose);
91 }
92
93 int board_early_init_f (void)
94 {
95         *(volatile unsigned char *)(CONFIG_SYS_CPLD_RESET) = 0x89;
96         return 0;
97 }
98
99 #ifdef CONFIG_WATCHDOG
100 void oxc_wdt_reset(void)
101 {
102         *(volatile unsigned char *)(CONFIG_SYS_CPLD_WATCHDOG) = 0xff;
103 }
104
105 void 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
115 static int oxc_get_expander(unsigned char addr, unsigned char * val)
116 {
117         return i2c_read(addr, 0, 0, val, 1);
118 }
119
120 static int oxc_set_expander(unsigned char addr, unsigned char val)
121 {
122         return i2c_write(addr, 0, 0, &val, 1);
123 }
124
125 static int expander0alive = 0;
126
127 #ifdef CONFIG_SHOW_ACTIVITY
128 static int ledtoggle = 0;
129 static int ledstatus = 1;
130
131 void oxc_toggle_activeled(void)
132 {
133         ledtoggle++;
134 }
135
136 void board_show_activity (ulong timestamp)
137 {
138         if ((timestamp % (CONFIG_SYS_HZ / 10)) == 0)
139                 oxc_toggle_activeled ();
140 }
141
142 void 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;
151                 oxc_get_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, &val);
152                 udelay(200);
153                 oxc_set_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, (val & 0x7F) | led);
154                 ledtoggle = 0;
155         }
156 }
157 #endif
158
159 #ifdef CONFIG_SHOW_BOOT_PROGRESS
160 void show_boot_progress(int arg)
161 {
162         unsigned char val;
163
164         if (!expander0alive) return;
165
166         if (arg > 0 && ledstatus) {
167                 ledstatus = 0;
168                 oxc_get_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, &val);
169                 udelay(200);
170                 oxc_set_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, val | 0x80);
171         } else if (arg < 0) {
172                 oxc_get_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, &val);
173                 udelay(200);
174                 oxc_set_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, val & 0x7F);
175                 ledstatus = 1;
176         }
177 }
178 #endif
179
180 int misc_init_r (void)
181 {
182         /* check whether the i2c expander #0 is accessible */
183         if (!oxc_set_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, 0x7F)) {
184                 udelay(200);
185                 expander0alive = 1;
186         }
187
188 #ifdef CONFIG_SYS_OXC_GENERATE_IP
189         {
190                 char str[32];
191                 unsigned long ip = CONFIG_SYS_OXC_IPMASK;
192                 bd_t *bd = gd->bd;
193
194                 if (expander0alive) {
195                         unsigned char val;
196
197                         if (!oxc_get_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, &val)) {
198                                 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 }
219
220 int board_eth_init(bd_t *bis)
221 {
222         return pci_eth_init(bis);
223 }