blob: a971af3aa93ee68da5fe19b046504bfd8570c77d [file] [log] [blame]
wdenk9f837932003-10-09 19:00:25 +00001/*
2 * (C) Copyright 2000
3 * Sangmoon Kim, Etin Systems. dogoil@etinsys.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>
wdenk78924a72004-04-18 21:45:42 +000027#include <i2c.h>
Ben Warren052a5ea2008-08-31 20:37:00 -070028#include <netdev.h>
wdenk9f837932003-10-09 19:00:25 +000029
Wolfgang Denk6405a152006-03-31 18:32:53 +020030DECLARE_GLOBAL_DATA_PTR;
31
wdenk9f837932003-10-09 19:00:25 +000032int checkboard (void)
33{
34 /*TODO: Check processor type */
35
36 puts ( "Board: Debris "
37#ifdef CONFIG_MPC8240
38 "8240"
39#endif
40#ifdef CONFIG_MPC8245
41 "8245"
42#endif
43 " ##Test not implemented yet##\n");
44 return 0;
45}
46
Wolfgang Denka1be4762008-05-20 16:00:29 +020047#if 0 /* NOT USED */
wdenk9f837932003-10-09 19:00:25 +000048int checkflash (void)
49{
50 /* TODO: XXX XXX XXX */
51 printf ("## Test not implemented yet ##\n");
52
53 return (0);
54}
55#endif
56
Becky Brucebd99ae72008-06-09 16:03:40 -050057phys_size_t initdram (int board_type)
wdenk9f837932003-10-09 19:00:25 +000058{
wdenk78924a72004-04-18 21:45:42 +000059 int m, row, col, bank, i;
60 unsigned long start, end;
61 uint32_t mccr1;
62 uint32_t mear1 = 0, emear1 = 0, msar1 = 0, emsar1 = 0;
63 uint32_t mear2 = 0, emear2 = 0, msar2 = 0, emsar2 = 0;
64 uint8_t mber = 0;
wdenk9f837932003-10-09 19:00:25 +000065
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020066 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
wdenk9f837932003-10-09 19:00:25 +000067
wdenk78924a72004-04-18 21:45:42 +000068 if (i2c_reg_read (0x50, 2) != 0x04) return 0; /* Memory type */
69 m = i2c_reg_read (0x50, 5); /* # of physical banks */
70 row = i2c_reg_read (0x50, 3); /* # of rows */
71 col = i2c_reg_read (0x50, 4); /* # of columns */
72 bank = i2c_reg_read (0x50, 17); /* # of logical banks */
73
74 CONFIG_READ_WORD(MCCR1, mccr1);
75 mccr1 &= 0xffff0000;
76
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020077 start = CONFIG_SYS_SDRAM_BASE;
wdenk78924a72004-04-18 21:45:42 +000078 end = start + (1 << (col + row + 3) ) * bank - 1;
79
80 for (i = 0; i < m; i++) {
81 mccr1 |= ((row == 13)? 2 : (bank == 4)? 0 : 3) << i * 2;
82 if (i < 4) {
83 msar1 |= ((start >> 20) & 0xff) << i * 8;
84 emsar1 |= ((start >> 28) & 0xff) << i * 8;
85 mear1 |= ((end >> 20) & 0xff) << i * 8;
86 emear1 |= ((end >> 28) & 0xff) << i * 8;
87 } else {
88 msar2 |= ((start >> 20) & 0xff) << (i-4) * 8;
89 emsar2 |= ((start >> 28) & 0xff) << (i-4) * 8;
90 mear2 |= ((end >> 20) & 0xff) << (i-4) * 8;
91 emear2 |= ((end >> 28) & 0xff) << (i-4) * 8;
92 }
93 mber |= 1 << i;
94 start += (1 << (col + row + 3) ) * bank;
95 end += (1 << (col + row + 3) ) * bank;
96 }
97 for (; i < 8; i++) {
98 if (i < 4) {
99 msar1 |= 0xff << i * 8;
100 emsar1 |= 0x30 << i * 8;
101 mear1 |= 0xff << i * 8;
102 emear1 |= 0x30 << i * 8;
103 } else {
104 msar2 |= 0xff << (i-4) * 8;
105 emsar2 |= 0x30 << (i-4) * 8;
106 mear2 |= 0xff << (i-4) * 8;
107 emear2 |= 0x30 << (i-4) * 8;
108 }
109 }
110
111 CONFIG_WRITE_WORD(MCCR1, mccr1);
112 CONFIG_WRITE_WORD(MSAR1, msar1);
113 CONFIG_WRITE_WORD(EMSAR1, emsar1);
114 CONFIG_WRITE_WORD(MEAR1, mear1);
115 CONFIG_WRITE_WORD(EMEAR1, emear1);
116 CONFIG_WRITE_WORD(MSAR2, msar2);
117 CONFIG_WRITE_WORD(EMSAR2, emsar2);
118 CONFIG_WRITE_WORD(MEAR2, mear2);
119 CONFIG_WRITE_WORD(EMEAR2, emear2);
120 CONFIG_WRITE_BYTE(MBER, mber);
wdenk9f837932003-10-09 19:00:25 +0000121
wdenk78924a72004-04-18 21:45:42 +0000122 return (1 << (col + row + 3) ) * bank * m;
wdenk9f837932003-10-09 19:00:25 +0000123}
124
125/*
126 * Initialize PCI Devices, report devices found.
127 */
128#ifndef CONFIG_PCI_PNP
129static struct pci_config_table pci_debris_config_table[] = {
130 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0f, PCI_ANY_ID,
131 pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
132 PCI_ENET0_MEMADDR,
133 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
134 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x10, PCI_ANY_ID,
135 pci_cfgfunc_config_device, { PCI_ENET1_IOADDR,
136 PCI_ENET1_MEMADDR,
137 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
138 { }
139};
140#endif
141
142struct pci_controller hose = {
143#ifndef CONFIG_PCI_PNP
144 config_table: pci_debris_config_table,
145#endif
146};
147
148void pci_init_board(void)
149{
150 pci_mpc824x_init(&hose);
151}
152
153void *nvram_read(void *dest, const long src, size_t count)
154{
155 volatile uchar *d = (volatile uchar*) dest;
156 volatile uchar *s = (volatile uchar*) src;
157 while(count--) {
158 *d++ = *s++;
159 asm volatile("sync");
160 }
161 return dest;
162}
163
164void nvram_write(long dest, const void *src, size_t count)
165{
166 volatile uchar *d = (volatile uchar*)dest;
167 volatile uchar *s = (volatile uchar*)src;
168 while(count--) {
169 *d++ = *s++;
170 asm volatile("sync");
171 }
172}
173
174int misc_init_r(void)
175{
Mike Frysinger69798322009-02-11 18:38:38 -0500176 uchar ethaddr[6];
177
178 if (eth_getenv_enetaddr("ethaddr", ethaddr))
179 /* Write ethernet addr in NVRAM for VxWorks */
180 nvram_write(CONFIG_ENV_ADDR + CONFIG_SYS_NVRAM_VXWORKS_OFFS,
181 ethaddr, 6);
182
wdenk9f837932003-10-09 19:00:25 +0000183 return 0;
184}
Ben Warren052a5ea2008-08-31 20:37:00 -0700185
186int board_eth_init(bd_t *bis)
187{
188 return pci_eth_init(bis);
189}