blob: 92ccd42e7f714516fb96153889b88c80e9806cc4 [file] [log] [blame]
wdenk3bac3512003-03-12 10:41:04 +00001/*
2 * (C) Copyright 2001
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 <asm/processor.h>
27#include <pci.h>
wdenk49822e22004-06-19 21:19:10 +000028#include <i2c.h>
wdenk3bac3512003-03-12 10:41:04 +000029
wdenk8bde7f72003-06-27 21:31:46 +000030int sysControlDisplay(int digit, uchar ascii_code);
wdenk3bac3512003-03-12 10:41:04 +000031extern void Plx9030Init(void);
32
33 /* We have to clear the initial data area here. Couldn't have done it
34 * earlier because DRAM had not been initialized.
35 */
wdenkc837dcb2004-01-20 23:12:12 +000036int board_early_init_f(void)
wdenk3bac3512003-03-12 10:41:04 +000037{
38
39 /* enable DUAL UART Mode on CPC45 */
40 *(uchar*)DUART_DCR |= 0x1; /* set DCM bit */
41
42 return 0;
43}
44
45int checkboard(void)
46{
47/*
48 char revision = BOARD_REV;
49*/
50 ulong busfreq = get_bus_freq(0);
51 char buf[32];
52
wdenkd7a04602004-06-01 21:15:28 +000053 puts ("CPC45 ");
wdenk3bac3512003-03-12 10:41:04 +000054/*
55 printf("Revision %d ", revision);
56*/
57 printf("Local Bus at %s MHz\n", strmhz(buf, busfreq));
58
59 return 0;
60}
61
wdenk49822e22004-06-19 21:19:10 +000062long int initdram (int board_type)
wdenk3bac3512003-03-12 10:41:04 +000063{
wdenk49822e22004-06-19 21:19:10 +000064 int m, row, col, bank, i, ref;
65 unsigned long start, end;
66 uint32_t mccr1, mccr2;
67 uint32_t mear1 = 0, emear1 = 0, msar1 = 0, emsar1 = 0;
68 uint32_t mear2 = 0, emear2 = 0, msar2 = 0, emsar2 = 0;
69 uint8_t mber = 0;
70 unsigned int tmp;
wdenk3bac3512003-03-12 10:41:04 +000071
wdenk49822e22004-06-19 21:19:10 +000072 i2c_init(CFG_I2C_SPEED, CFG_I2C_SLAVE);
wdenk3bac3512003-03-12 10:41:04 +000073
wdenk49822e22004-06-19 21:19:10 +000074 if (i2c_reg_read (0x50, 2) != 0x04)
75 return 0; /* Memory type */
wdenk3bac3512003-03-12 10:41:04 +000076
wdenk49822e22004-06-19 21:19:10 +000077 m = i2c_reg_read (0x50, 5); /* # of physical banks */
78 row = i2c_reg_read (0x50, 3); /* # of rows */
79 col = i2c_reg_read (0x50, 4); /* # of columns */
80 bank = i2c_reg_read (0x50, 17); /* # of logical banks */
81 ref = i2c_reg_read (0x50, 12); /* refresh rate / type */
82
83 CONFIG_READ_WORD(MCCR1, mccr1);
84 mccr1 &= 0xffff0000;
85
86 CONFIG_READ_WORD(MCCR2, mccr2);
87 mccr2 &= 0xffff0000;
88
89 start = CFG_SDRAM_BASE;
90 end = start + (1 << (col + row + 3) ) * bank - 1;
91
92 for (i = 0; i < m; i++) {
93 mccr1 |= ((row == 13)? 2 : (bank == 4)? 0 : 3) << i * 2;
94 if (i < 4) {
95 msar1 |= ((start >> 20) & 0xff) << i * 8;
96 emsar1 |= ((start >> 28) & 0xff) << i * 8;
97 mear1 |= ((end >> 20) & 0xff) << i * 8;
98 emear1 |= ((end >> 28) & 0xff) << i * 8;
99 } else {
100 msar2 |= ((start >> 20) & 0xff) << (i-4) * 8;
101 emsar2 |= ((start >> 28) & 0xff) << (i-4) * 8;
102 mear2 |= ((end >> 20) & 0xff) << (i-4) * 8;
103 emear2 |= ((end >> 28) & 0xff) << (i-4) * 8;
104 }
105 mber |= 1 << i;
106 start += (1 << (col + row + 3) ) * bank;
107 end += (1 << (col + row + 3) ) * bank;
108 }
109 for (; i < 8; i++) {
110 if (i < 4) {
111 msar1 |= 0xff << i * 8;
112 emsar1 |= 0x30 << i * 8;
113 mear1 |= 0xff << i * 8;
114 emear1 |= 0x30 << i * 8;
115 } else {
116 msar2 |= 0xff << (i-4) * 8;
117 emsar2 |= 0x30 << (i-4) * 8;
118 mear2 |= 0xff << (i-4) * 8;
119 emear2 |= 0x30 << (i-4) * 8;
120 }
121 }
122
123 switch(ref) {
124 case 0x00:
125 case 0x80:
126 tmp = get_bus_freq(0) / 1000000 * 15625 / 1000 - 22;
127 break;
128 case 0x01:
129 case 0x81:
130 tmp = get_bus_freq(0) / 1000000 * 3900 / 1000 - 22;
131 break;
132 case 0x02:
133 case 0x82:
134 tmp = get_bus_freq(0) / 1000000 * 7800 / 1000 - 22;
135 break;
136 case 0x03:
137 case 0x83:
138 tmp = get_bus_freq(0) / 1000000 * 31300 / 1000 - 22;
139 break;
140 case 0x04:
141 case 0x84:
142 tmp = get_bus_freq(0) / 1000000 * 62500 / 1000 - 22;
143 break;
144 case 0x05:
145 case 0x85:
146 tmp = get_bus_freq(0) / 1000000 * 125000 / 1000 - 22;
147 break;
148 default:
149 tmp = 0x512;
150 break;
151 }
152
153 CONFIG_WRITE_WORD(MCCR1, mccr1);
154 CONFIG_WRITE_WORD(MCCR2, tmp << MCCR2_REFINT_SHIFT);
155 CONFIG_WRITE_WORD(MSAR1, msar1);
156 CONFIG_WRITE_WORD(EMSAR1, emsar1);
157 CONFIG_WRITE_WORD(MEAR1, mear1);
158 CONFIG_WRITE_WORD(EMEAR1, emear1);
159 CONFIG_WRITE_WORD(MSAR2, msar2);
160 CONFIG_WRITE_WORD(EMSAR2, emsar2);
161 CONFIG_WRITE_WORD(MEAR2, mear2);
162 CONFIG_WRITE_WORD(EMEAR2, emear2);
163 CONFIG_WRITE_BYTE(MBER, mber);
164
165 return (1 << (col + row + 3) ) * bank * m;
wdenk3bac3512003-03-12 10:41:04 +0000166}
167
wdenk49822e22004-06-19 21:19:10 +0000168
wdenk3bac3512003-03-12 10:41:04 +0000169/*
170 * Initialize PCI Devices, report devices found.
171 */
wdenk3bac3512003-03-12 10:41:04 +0000172
wdenk49822e22004-06-19 21:19:10 +0000173static struct pci_config_table pci_cpc45_config_table[] = {
174#ifndef CONFIG_PCI_PNP
175 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0F, PCI_ANY_ID,
wdenk3bac3512003-03-12 10:41:04 +0000176 pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
177 PCI_ENET0_MEMADDR,
178 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
wdenk49822e22004-06-19 21:19:10 +0000179 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0D, PCI_ANY_ID,
180 pci_cfgfunc_config_device, { PCI_PLX9030_IOADDR,
181 PCI_PLX9030_MEMADDR,
182 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
183#endif /*CONFIG_PCI_PNP*/
wdenk3bac3512003-03-12 10:41:04 +0000184 { }
185};
wdenk3bac3512003-03-12 10:41:04 +0000186
187struct pci_controller hose = {
188#ifndef CONFIG_PCI_PNP
wdenk49822e22004-06-19 21:19:10 +0000189 config_table: pci_cpc45_config_table,
wdenk3bac3512003-03-12 10:41:04 +0000190#endif
191};
192
193void pci_init_board(void)
194{
195 pci_mpc824x_init(&hose);
196
197 /* init PCI_to_LOCAL Bus BRIDGE */
198 Plx9030Init();
199
wdenk49822e22004-06-19 21:19:10 +0000200 /* Clear Display */
201 DISP_CWORD = 0x0;
202
wdenk3bac3512003-03-12 10:41:04 +0000203 sysControlDisplay(0,' ');
204 sysControlDisplay(1,'C');
205 sysControlDisplay(2,'P');
206 sysControlDisplay(3,'C');
207 sysControlDisplay(4,' ');
208 sysControlDisplay(5,'4');
209 sysControlDisplay(6,'5');
210 sysControlDisplay(7,' ');
211
212}
213
214/**************************************************************************
215*
216* sysControlDisplay - controls one of the Alphanum. Display digits.
217*
218* This routine will write an ASCII character to the display digit requested.
219*
220* SEE ALSO:
221*
222* RETURNS: NA
223*/
224
wdenk49822e22004-06-19 21:19:10 +0000225int sysControlDisplay (int digit, /* number of digit 0..7 */
226 uchar ascii_code /* ASCII code */
227 )
wdenk3bac3512003-03-12 10:41:04 +0000228{
229 if ((digit < 0) || (digit > 7))
230 return (-1);
231
wdenk49822e22004-06-19 21:19:10 +0000232 *((volatile uchar *) (DISP_CHR_RAM + digit)) = ascii_code;
wdenk3bac3512003-03-12 10:41:04 +0000233
234 return (0);
235}