wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Rob Taylor, Flying Pig Systems. robt@flyingpig.com. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <mpc824x.h> |
| 10 | #include <asm/processor.h> |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 11 | #include <asm/io.h> |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 12 | #include <pci.h> |
wdenk | 49822e2 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 13 | #include <i2c.h> |
Ben Warren | 10efa02 | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 14 | #include <netdev.h> |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 15 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 16 | int sysControlDisplay(int digit, uchar ascii_code); |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 17 | extern void Plx9030Init(void); |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 18 | extern void SPD67290Init(void); |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 19 | |
| 20 | /* We have to clear the initial data area here. Couldn't have done it |
| 21 | * earlier because DRAM had not been initialized. |
| 22 | */ |
wdenk | c837dcb | 2004-01-20 23:12:12 +0000 | [diff] [blame] | 23 | int board_early_init_f(void) |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 24 | { |
| 25 | |
| 26 | /* enable DUAL UART Mode on CPC45 */ |
| 27 | *(uchar*)DUART_DCR |= 0x1; /* set DCM bit */ |
| 28 | |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | int checkboard(void) |
| 33 | { |
| 34 | /* |
| 35 | char revision = BOARD_REV; |
| 36 | */ |
| 37 | ulong busfreq = get_bus_freq(0); |
| 38 | char buf[32]; |
| 39 | |
wdenk | d7a0460 | 2004-06-01 21:15:28 +0000 | [diff] [blame] | 40 | puts ("CPC45 "); |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 41 | /* |
| 42 | printf("Revision %d ", revision); |
| 43 | */ |
| 44 | printf("Local Bus at %s MHz\n", strmhz(buf, busfreq)); |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 49 | phys_size_t initdram (int board_type) |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 50 | { |
wdenk | 49822e2 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 51 | 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; |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 58 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 59 | i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 60 | |
wdenk | 49822e2 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 61 | if (i2c_reg_read (0x50, 2) != 0x04) |
| 62 | return 0; /* Memory type */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 63 | |
wdenk | 49822e2 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 64 | 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-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 76 | start = CONFIG_SYS_SDRAM_BASE; |
wdenk | 49822e2 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 77 | 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; |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 153 | } |
| 154 | |
wdenk | 49822e2 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 155 | |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 156 | /* |
| 157 | * Initialize PCI Devices, report devices found. |
| 158 | */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 159 | |
wdenk | 49822e2 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 160 | static 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, |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 163 | pci_cfgfunc_config_device, { PCI_ENET0_IOADDR, |
| 164 | PCI_ENET0_MEMADDR, |
| 165 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }}, |
wdenk | 49822e2 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 166 | { 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 }}, |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 170 | { 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 }}, |
wdenk | 49822e2 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 174 | #endif /*CONFIG_PCI_PNP*/ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 175 | { } |
| 176 | }; |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 177 | |
| 178 | struct pci_controller hose = { |
| 179 | #ifndef CONFIG_PCI_PNP |
wdenk | 49822e2 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 180 | config_table: pci_cpc45_config_table, |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 181 | #endif |
| 182 | }; |
| 183 | |
| 184 | void pci_init_board(void) |
| 185 | { |
| 186 | pci_mpc824x_init(&hose); |
| 187 | |
| 188 | /* init PCI_to_LOCAL Bus BRIDGE */ |
| 189 | Plx9030Init(); |
| 190 | |
wdenk | 49822e2 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 191 | /* Clear Display */ |
| 192 | DISP_CWORD = 0x0; |
| 193 | |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 194 | 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 | |
wdenk | 49822e2 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 216 | int sysControlDisplay (int digit, /* number of digit 0..7 */ |
| 217 | uchar ascii_code /* ASCII code */ |
| 218 | ) |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 219 | { |
| 220 | if ((digit < 0) || (digit > 7)) |
| 221 | return (-1); |
| 222 | |
wdenk | 49822e2 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 223 | *((volatile uchar *) (DISP_CHR_RAM + digit)) = ascii_code; |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 224 | |
| 225 | return (0); |
| 226 | } |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 227 | |
Jon Loeliger | fcec2eb | 2007-07-09 18:19:09 -0500 | [diff] [blame] | 228 | #if defined(CONFIG_CMD_PCMCIA) |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 229 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 230 | #ifdef CONFIG_SYS_PCMCIA_MEM_ADDR |
| 231 | volatile unsigned char *pcmcia_mem = (unsigned char*)CONFIG_SYS_PCMCIA_MEM_ADDR; |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 232 | #endif |
| 233 | |
| 234 | int 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 Loeliger | 77a3185 | 2007-07-10 10:39:10 -0500 | [diff] [blame] | 245 | #endif |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 246 | |
Ben Warren | 10efa02 | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 247 | int board_eth_init(bd_t *bis) |
| 248 | { |
| 249 | return pci_eth_init(bis); |
| 250 | } |