blob: f182e79fd9d9ddb51d4596d44fff3684064bab65 [file] [log] [blame]
wdenk3bac3512003-03-12 10:41:04 +00001/*
2 * (C) Copyright 2001
3 * Rob Taylor, Flying Pig Systems. robt@flyingpig.com.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk3bac3512003-03-12 10:41:04 +00006 */
7
8#include <common.h>
9#include <mpc824x.h>
10#include <asm/processor.h>
wdenke2ffd592004-12-31 09:32:47 +000011#include <asm/io.h>
wdenk3bac3512003-03-12 10:41:04 +000012#include <pci.h>
wdenk49822e22004-06-19 21:19:10 +000013#include <i2c.h>
Ben Warren10efa022008-08-31 20:37:00 -070014#include <netdev.h>
wdenk3bac3512003-03-12 10:41:04 +000015
wdenk8bde7f72003-06-27 21:31:46 +000016int sysControlDisplay(int digit, uchar ascii_code);
wdenk3bac3512003-03-12 10:41:04 +000017extern void Plx9030Init(void);
wdenke2ffd592004-12-31 09:32:47 +000018extern void SPD67290Init(void);
wdenk3bac3512003-03-12 10:41:04 +000019
20 /* We have to clear the initial data area here. Couldn't have done it
21 * earlier because DRAM had not been initialized.
22 */
wdenkc837dcb2004-01-20 23:12:12 +000023int board_early_init_f(void)
wdenk3bac3512003-03-12 10:41:04 +000024{
25
26 /* enable DUAL UART Mode on CPC45 */
27 *(uchar*)DUART_DCR |= 0x1; /* set DCM bit */
28
29 return 0;
30}
31
32int checkboard(void)
33{
34/*
35 char revision = BOARD_REV;
36*/
37 ulong busfreq = get_bus_freq(0);
38 char buf[32];
39
wdenkd7a04602004-06-01 21:15:28 +000040 puts ("CPC45 ");
wdenk3bac3512003-03-12 10:41:04 +000041/*
42 printf("Revision %d ", revision);
43*/
44 printf("Local Bus at %s MHz\n", strmhz(buf, busfreq));
45
46 return 0;
47}
48
Becky Bruce9973e3c2008-06-09 16:03:40 -050049phys_size_t initdram (int board_type)
wdenk3bac3512003-03-12 10:41:04 +000050{
wdenk49822e22004-06-19 21:19:10 +000051 int m, row, col, bank, i, ref;
52 unsigned long start, end;
53 uint32_t mccr1, mccr2;
54 uint32_t mear1 = 0, emear1 = 0, msar1 = 0, emsar1 = 0;
55 uint32_t mear2 = 0, emear2 = 0, msar2 = 0, emsar2 = 0;
56 uint8_t mber = 0;
57 unsigned int tmp;
wdenk3bac3512003-03-12 10:41:04 +000058
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020059 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
wdenk3bac3512003-03-12 10:41:04 +000060
wdenk49822e22004-06-19 21:19:10 +000061 if (i2c_reg_read (0x50, 2) != 0x04)
62 return 0; /* Memory type */
wdenk3bac3512003-03-12 10:41:04 +000063
wdenk49822e22004-06-19 21:19:10 +000064 m = i2c_reg_read (0x50, 5); /* # of physical banks */
65 row = i2c_reg_read (0x50, 3); /* # of rows */
66 col = i2c_reg_read (0x50, 4); /* # of columns */
67 bank = i2c_reg_read (0x50, 17); /* # of logical banks */
68 ref = i2c_reg_read (0x50, 12); /* refresh rate / type */
69
70 CONFIG_READ_WORD(MCCR1, mccr1);
71 mccr1 &= 0xffff0000;
72
73 CONFIG_READ_WORD(MCCR2, mccr2);
74 mccr2 &= 0xffff0000;
75
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020076 start = CONFIG_SYS_SDRAM_BASE;
wdenk49822e22004-06-19 21:19:10 +000077 end = start + (1 << (col + row + 3) ) * bank - 1;
78
79 for (i = 0; i < m; i++) {
80 mccr1 |= ((row == 13)? 2 : (bank == 4)? 0 : 3) << i * 2;
81 if (i < 4) {
82 msar1 |= ((start >> 20) & 0xff) << i * 8;
83 emsar1 |= ((start >> 28) & 0xff) << i * 8;
84 mear1 |= ((end >> 20) & 0xff) << i * 8;
85 emear1 |= ((end >> 28) & 0xff) << i * 8;
86 } else {
87 msar2 |= ((start >> 20) & 0xff) << (i-4) * 8;
88 emsar2 |= ((start >> 28) & 0xff) << (i-4) * 8;
89 mear2 |= ((end >> 20) & 0xff) << (i-4) * 8;
90 emear2 |= ((end >> 28) & 0xff) << (i-4) * 8;
91 }
92 mber |= 1 << i;
93 start += (1 << (col + row + 3) ) * bank;
94 end += (1 << (col + row + 3) ) * bank;
95 }
96 for (; i < 8; i++) {
97 if (i < 4) {
98 msar1 |= 0xff << i * 8;
99 emsar1 |= 0x30 << i * 8;
100 mear1 |= 0xff << i * 8;
101 emear1 |= 0x30 << i * 8;
102 } else {
103 msar2 |= 0xff << (i-4) * 8;
104 emsar2 |= 0x30 << (i-4) * 8;
105 mear2 |= 0xff << (i-4) * 8;
106 emear2 |= 0x30 << (i-4) * 8;
107 }
108 }
109
110 switch(ref) {
111 case 0x00:
112 case 0x80:
113 tmp = get_bus_freq(0) / 1000000 * 15625 / 1000 - 22;
114 break;
115 case 0x01:
116 case 0x81:
117 tmp = get_bus_freq(0) / 1000000 * 3900 / 1000 - 22;
118 break;
119 case 0x02:
120 case 0x82:
121 tmp = get_bus_freq(0) / 1000000 * 7800 / 1000 - 22;
122 break;
123 case 0x03:
124 case 0x83:
125 tmp = get_bus_freq(0) / 1000000 * 31300 / 1000 - 22;
126 break;
127 case 0x04:
128 case 0x84:
129 tmp = get_bus_freq(0) / 1000000 * 62500 / 1000 - 22;
130 break;
131 case 0x05:
132 case 0x85:
133 tmp = get_bus_freq(0) / 1000000 * 125000 / 1000 - 22;
134 break;
135 default:
136 tmp = 0x512;
137 break;
138 }
139
140 CONFIG_WRITE_WORD(MCCR1, mccr1);
141 CONFIG_WRITE_WORD(MCCR2, tmp << MCCR2_REFINT_SHIFT);
142 CONFIG_WRITE_WORD(MSAR1, msar1);
143 CONFIG_WRITE_WORD(EMSAR1, emsar1);
144 CONFIG_WRITE_WORD(MEAR1, mear1);
145 CONFIG_WRITE_WORD(EMEAR1, emear1);
146 CONFIG_WRITE_WORD(MSAR2, msar2);
147 CONFIG_WRITE_WORD(EMSAR2, emsar2);
148 CONFIG_WRITE_WORD(MEAR2, mear2);
149 CONFIG_WRITE_WORD(EMEAR2, emear2);
150 CONFIG_WRITE_BYTE(MBER, mber);
151
152 return (1 << (col + row + 3) ) * bank * m;
wdenk3bac3512003-03-12 10:41:04 +0000153}
154
wdenk49822e22004-06-19 21:19:10 +0000155
wdenk3bac3512003-03-12 10:41:04 +0000156/*
157 * Initialize PCI Devices, report devices found.
158 */
wdenk3bac3512003-03-12 10:41:04 +0000159
wdenk49822e22004-06-19 21:19:10 +0000160static struct pci_config_table pci_cpc45_config_table[] = {
161#ifndef CONFIG_PCI_PNP
162 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0F, PCI_ANY_ID,
wdenk3bac3512003-03-12 10:41:04 +0000163 pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
164 PCI_ENET0_MEMADDR,
165 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
wdenk49822e22004-06-19 21:19:10 +0000166 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0D, PCI_ANY_ID,
167 pci_cfgfunc_config_device, { PCI_PLX9030_IOADDR,
168 PCI_PLX9030_MEMADDR,
169 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
wdenke2ffd592004-12-31 09:32:47 +0000170 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0E, PCI_ANY_ID,
171 pci_cfgfunc_config_device, { PCMCIA_IO_BASE,
172 PCMCIA_IO_BASE,
173 PCI_COMMAND_MEMORY | PCI_COMMAND_IO }},
wdenk49822e22004-06-19 21:19:10 +0000174#endif /*CONFIG_PCI_PNP*/
wdenk3bac3512003-03-12 10:41:04 +0000175 { }
176};
wdenk3bac3512003-03-12 10:41:04 +0000177
178struct pci_controller hose = {
179#ifndef CONFIG_PCI_PNP
wdenk49822e22004-06-19 21:19:10 +0000180 config_table: pci_cpc45_config_table,
wdenk3bac3512003-03-12 10:41:04 +0000181#endif
182};
183
184void pci_init_board(void)
185{
186 pci_mpc824x_init(&hose);
187
188 /* init PCI_to_LOCAL Bus BRIDGE */
189 Plx9030Init();
190
wdenk49822e22004-06-19 21:19:10 +0000191 /* Clear Display */
192 DISP_CWORD = 0x0;
193
wdenk3bac3512003-03-12 10:41:04 +0000194 sysControlDisplay(0,' ');
195 sysControlDisplay(1,'C');
196 sysControlDisplay(2,'P');
197 sysControlDisplay(3,'C');
198 sysControlDisplay(4,' ');
199 sysControlDisplay(5,'4');
200 sysControlDisplay(6,'5');
201 sysControlDisplay(7,' ');
202
203}
204
205/**************************************************************************
206*
207* sysControlDisplay - controls one of the Alphanum. Display digits.
208*
209* This routine will write an ASCII character to the display digit requested.
210*
211* SEE ALSO:
212*
213* RETURNS: NA
214*/
215
wdenk49822e22004-06-19 21:19:10 +0000216int sysControlDisplay (int digit, /* number of digit 0..7 */
217 uchar ascii_code /* ASCII code */
218 )
wdenk3bac3512003-03-12 10:41:04 +0000219{
220 if ((digit < 0) || (digit > 7))
221 return (-1);
222
wdenk49822e22004-06-19 21:19:10 +0000223 *((volatile uchar *) (DISP_CHR_RAM + digit)) = ascii_code;
wdenk3bac3512003-03-12 10:41:04 +0000224
225 return (0);
226}
wdenke2ffd592004-12-31 09:32:47 +0000227
Jon Loeligerfcec2eb2007-07-09 18:19:09 -0500228#if defined(CONFIG_CMD_PCMCIA)
wdenke2ffd592004-12-31 09:32:47 +0000229
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200230#ifdef CONFIG_SYS_PCMCIA_MEM_ADDR
231volatile unsigned char *pcmcia_mem = (unsigned char*)CONFIG_SYS_PCMCIA_MEM_ADDR;
wdenke2ffd592004-12-31 09:32:47 +0000232#endif
233
234int pcmcia_init(void)
235{
236 u_int rc;
237
238 debug ("Enable PCMCIA " PCMCIA_SLOT_MSG "\n");
239
240 rc = i82365_init();
241
242 return rc;
243}
244
Jon Loeliger77a31852007-07-10 10:39:10 -0500245#endif
wdenke2ffd592004-12-31 09:32:47 +0000246
Ben Warren10efa022008-08-31 20:37:00 -0700247int board_eth_init(bd_t *bis)
248{
249 return pci_eth_init(bis);
250}