wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 4 | * Marius Groeger <mgroeger@sysgo.de> |
| 5 | * |
| 6 | * (C) Copyright 2002 |
| 7 | * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch> |
| 8 | * |
| 9 | * (C) Copyright 2003 |
| 10 | * Texas Instruments, <www.ti.com> |
| 11 | * Kshitij Gupta <Kshitij@ti.com> |
| 12 | * |
| 13 | * (C) Copyright 2004 |
| 14 | * ARM Ltd. |
| 15 | * Philippe Robin, <philippe.robin@arm.com> |
| 16 | * |
| 17 | * See file CREDITS for list of people who contributed to this |
| 18 | * project. |
| 19 | * |
| 20 | * This program is free software; you can redistribute it and/or |
| 21 | * modify it under the terms of the GNU General Public License as |
| 22 | * published by the Free Software Foundation; either version 2 of |
| 23 | * the License, or (at your option) any later version. |
| 24 | * |
| 25 | * This program is distributed in the hope that it will be useful, |
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 | * GNU General Public License for more details. |
| 29 | * |
| 30 | * You should have received a copy of the GNU General Public License |
| 31 | * along with this program; if not, write to the Free Software |
| 32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 33 | * MA 02111-1307 USA |
| 34 | */ |
| 35 | |
| 36 | #include <common.h> |
| 37 | |
| 38 | #ifdef CONFIG_PCI |
| 39 | # include <pci.h> |
| 40 | #endif |
| 41 | |
| 42 | void flash__init (void); |
| 43 | void ether__init (void); |
| 44 | void peripheral_power_enable (void); |
| 45 | |
| 46 | #if defined(CONFIG_SHOW_BOOT_PROGRESS) |
| 47 | void show_boot_progress(int progress) |
| 48 | { |
| 49 | printf("Boot reached stage %d\n", progress); |
| 50 | } |
| 51 | #endif |
| 52 | |
| 53 | #define COMP_MODE_ENABLE ((unsigned int)0x0000EAEF) |
| 54 | |
| 55 | static inline void delay (unsigned long loops) |
| 56 | { |
| 57 | __asm__ volatile ("1:\n" |
| 58 | "subs %0, %1, #1\n" |
| 59 | "bne 1b":"=r" (loops):"0" (loops)); |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * Miscellaneous platform dependent initialisations |
| 64 | */ |
| 65 | |
| 66 | int board_init (void) |
| 67 | { |
| 68 | DECLARE_GLOBAL_DATA_PTR; |
| 69 | |
| 70 | /* arch number of Integrator Board */ |
| 71 | gd->bd->bi_arch_number = 21; |
| 72 | |
| 73 | /* adress of boot parameters */ |
| 74 | gd->bd->bi_boot_params = 0x00000100; |
| 75 | |
| 76 | icache_enable (); |
| 77 | |
| 78 | flash__init (); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | int misc_init_r (void) |
| 84 | { |
| 85 | #ifdef CONFIG_PCI |
| 86 | pci_init(); |
| 87 | #endif |
| 88 | setenv("verify", "n"); |
| 89 | return (0); |
| 90 | } |
| 91 | |
| 92 | /* |
| 93 | * Initialize PCI Devices, report devices found. |
| 94 | */ |
| 95 | #ifdef CONFIG_PCI |
| 96 | |
| 97 | #ifndef CONFIG_PCI_PNP |
| 98 | |
| 99 | static struct pci_config_table pci_integrator_config_table[] = { |
| 100 | { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0f, PCI_ANY_ID, |
| 101 | pci_cfgfunc_config_device, { PCI_ENET0_IOADDR, |
| 102 | PCI_ENET0_MEMADDR, |
| 103 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }}, |
| 104 | { } |
| 105 | }; |
| 106 | #endif |
| 107 | |
| 108 | // V3 access routines |
| 109 | #define _V3Write16(o,v) (*(volatile unsigned short *)(PCI_V3_BASE + (unsigned int)(o)) = (unsigned short)(v)) |
| 110 | #define _V3Read16(o) (*(volatile unsigned short *)(PCI_V3_BASE + (unsigned int)(o))) |
| 111 | |
| 112 | #define _V3Write32(o,v) (*(volatile unsigned int *)(PCI_V3_BASE + (unsigned int)(o)) = (unsigned int)(v)) |
| 113 | #define _V3Read32(o) (*(volatile unsigned int *)(PCI_V3_BASE + (unsigned int)(o))) |
| 114 | |
| 115 | // Compute address necessary to access PCI config space for the given |
| 116 | // bus and device. |
| 117 | #define PCI_CONFIG_ADDRESS( __bus, __devfn, __offset ) \ |
| 118 | ({ \ |
| 119 | unsigned int __address, __devicebit; \ |
| 120 | unsigned short __mapaddress; \ |
| 121 | unsigned int __dev = PCI_DEV(__devfn); /* FIXME to check!! (slot?) */ \ |
| 122 | \ |
| 123 | if (__bus == 0) { \ |
| 124 | /* local bus segment so need a type 0 config cycle */ \ |
| 125 | /* build the PCI configuration "address" with one-hot in A31-A11 */ \ |
| 126 | __address = PCI_CONFIG_BASE; \ |
| 127 | __address |= ((__devfn & 0x07) << 8); \ |
| 128 | __address |= __offset & 0xFF; \ |
| 129 | __mapaddress = 0x000A; /* 101=>config cycle, 0=>A1=A0=0 */ \ |
| 130 | __devicebit = (1 << (__dev + 11)); \ |
| 131 | \ |
| 132 | if ((__devicebit & 0xFF000000) != 0) { \ |
| 133 | /* high order bits are handled by the MAP register */ \ |
| 134 | __mapaddress |= (__devicebit >> 16); \ |
| 135 | } else { \ |
| 136 | /* low order bits handled directly in the address */ \ |
| 137 | __address |= __devicebit; \ |
| 138 | } \ |
| 139 | } else { /* bus !=0 */ \ |
| 140 | /* not the local bus segment so need a type 1 config cycle */ \ |
| 141 | /* A31-A24 are don't care (so clear to 0) */ \ |
| 142 | __mapaddress = 0x000B; /* 101=>config cycle, 1=>A1&A0 from PCI_CFG */ \ |
| 143 | __address = PCI_CONFIG_BASE; \ |
| 144 | __address |= ((__bus & 0xFF) << 16); /* bits 23..16 = bus number */ \ |
| 145 | __address |= ((__dev & 0x1F) << 11); /* bits 15..11 = device number */ \ |
| 146 | __address |= ((__devfn & 0x07) << 8); /* bits 10..8 = function number*/ \ |
| 147 | __address |= __offset & 0xFF; /* bits 7..0 = register number*/ \ |
| 148 | } \ |
| 149 | _V3Write16(V3_LB_MAP1, __mapaddress); \ |
| 150 | \ |
| 151 | __address; \ |
| 152 | }) |
| 153 | |
| 154 | // _V3OpenConfigWindow - open V3 configuration window |
| 155 | #define _V3OpenConfigWindow() \ |
| 156 | { \ |
| 157 | /* Set up base0 to see all 512Mbytes of memory space (not */ \ |
| 158 | /* prefetchable), this frees up base1 for re-use by configuration*/ \ |
| 159 | /* memory */ \ |
| 160 | \ |
| 161 | _V3Write32 (V3_LB_BASE0, ((INTEGRATOR_PCI_BASE & 0xFFF00000) | \ |
| 162 | 0x90 | V3_LB_BASE_M_ENABLE)); \ |
| 163 | /* Set up base1 to point into configuration space, note that MAP1 */ \ |
| 164 | /* register is set up by pciMakeConfigAddress(). */ \ |
| 165 | \ |
| 166 | _V3Write32 (V3_LB_BASE1, ((CPU_PCI_CNFG_ADRS & 0xFFF00000) | \ |
| 167 | 0x40 | V3_LB_BASE_M_ENABLE)); \ |
| 168 | } |
| 169 | |
| 170 | // _V3CloseConfigWindow - close V3 configuration window |
| 171 | #define _V3CloseConfigWindow() \ |
| 172 | { \ |
| 173 | /* Reassign base1 for use by prefetchable PCI memory */ \ |
| 174 | _V3Write32 (V3_LB_BASE1, (((INTEGRATOR_PCI_BASE + 0x10000000) & 0xFFF00000) \ |
| 175 | | 0x84 | V3_LB_BASE_M_ENABLE)); \ |
| 176 | _V3Write16 (V3_LB_MAP1, \ |
| 177 | (((INTEGRATOR_PCI_BASE + 0x10000000) & 0xFFF00000) >> 16) | 0x0006); \ |
| 178 | \ |
| 179 | /* And shrink base0 back to a 256M window (NOTE: MAP0 already correct) */ \ |
| 180 | \ |
| 181 | _V3Write32 (V3_LB_BASE0, ((INTEGRATOR_PCI_BASE & 0xFFF00000) | \ |
| 182 | 0x80 | V3_LB_BASE_M_ENABLE)); \ |
| 183 | } |
| 184 | |
| 185 | |
| 186 | static int pci_integrator_read_byte(struct pci_controller *hose, pci_dev_t dev, |
| 187 | int offset, unsigned char *val) |
| 188 | { |
| 189 | _V3OpenConfigWindow(); |
| 190 | *val = *(volatile unsigned char *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), offset); |
| 191 | _V3CloseConfigWindow(); |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | static int pci_integrator_read__word(struct pci_controller *hose, pci_dev_t dev, |
| 197 | int offset, unsigned short *val) |
| 198 | { |
| 199 | _V3OpenConfigWindow(); |
| 200 | *val = *(volatile unsigned short *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), offset); |
| 201 | _V3CloseConfigWindow(); |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | static int pci_integrator_read_dword(struct pci_controller *hose, pci_dev_t dev, |
| 207 | int offset, unsigned int *val) |
| 208 | { |
| 209 | _V3OpenConfigWindow(); |
| 210 | *val = *(volatile unsigned short *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), offset); |
| 211 | *val |= (*(volatile unsigned int *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), (offset+2))) << 16; |
| 212 | _V3CloseConfigWindow(); |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | static int pci_integrator_write_byte(struct pci_controller *hose, pci_dev_t dev, |
| 218 | int offset, unsigned char val) |
| 219 | { |
| 220 | _V3OpenConfigWindow(); |
| 221 | *(volatile unsigned char *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), offset) = val; |
| 222 | _V3CloseConfigWindow(); |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | static int pci_integrator_write_word(struct pci_controller *hose, pci_dev_t dev, |
| 228 | int offset,unsigned short val) |
| 229 | { |
| 230 | _V3OpenConfigWindow(); |
| 231 | *(volatile unsigned short *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), offset) = val; |
| 232 | _V3CloseConfigWindow(); |
| 233 | |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | static int pci_integrator_write_dword(struct pci_controller *hose, pci_dev_t dev, |
| 238 | int offset, unsigned int val) |
| 239 | { |
| 240 | _V3OpenConfigWindow(); |
| 241 | *(volatile unsigned short *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), offset) = (val & 0xFFFF); |
| 242 | *(volatile unsigned short *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), (offset + 2)) = ((val >> 16) & 0xFFFF); |
| 243 | _V3CloseConfigWindow(); |
| 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | /****************************** |
| 249 | * PCI initialisation |
| 250 | ******************************/ |
| 251 | |
| 252 | struct pci_controller integrator_hose = { |
| 253 | #ifndef CONFIG_PCI_PNP |
| 254 | config_table: pci_integrator_config_table, |
| 255 | #endif |
| 256 | }; |
| 257 | |
| 258 | void pci_init_board(void) |
| 259 | { |
| 260 | volatile int i, j; |
| 261 | struct pci_controller *hose = &integrator_hose; |
| 262 | |
| 263 | /* setting this register will take the V3 out of reset */ |
| 264 | |
| 265 | *(volatile unsigned int *)(INTEGRATOR_SC_PCIENABLE) = 1; |
| 266 | |
| 267 | /* wait a few usecs to settle the device and the PCI bus */ |
| 268 | |
| 269 | for (i = 0; i < 100 ; i++) |
| 270 | j = i + 1; |
| 271 | |
| 272 | /* Now write the Base I/O Address Word to V3_BASE + 0x6C */ |
| 273 | |
| 274 | *(volatile unsigned short *)(V3_BASE + V3_LB_IO_BASE) = (unsigned short)(V3_BASE >> 16); |
| 275 | |
| 276 | do { |
| 277 | *(volatile unsigned char *)(V3_BASE + V3_MAIL_DATA) = 0xAA; |
| 278 | *(volatile unsigned char *)(V3_BASE + V3_MAIL_DATA + 4) = 0x55; |
| 279 | } while (*(volatile unsigned char *)(V3_BASE + V3_MAIL_DATA) != 0xAA || |
| 280 | *(volatile unsigned char *)(V3_BASE + V3_MAIL_DATA + 4) != 0x55); |
| 281 | |
| 282 | /* Make sure that V3 register access is not locked, if it is, unlock it */ |
| 283 | |
| 284 | if ((*(volatile unsigned short *)(V3_BASE + V3_SYSTEM) & V3_SYSTEM_M_LOCK) |
| 285 | == V3_SYSTEM_M_LOCK) |
| 286 | *(volatile unsigned short *)(V3_BASE + V3_SYSTEM) = 0xA05F; |
| 287 | |
| 288 | /* Ensure that the slave accesses from PCI are disabled while we */ |
| 289 | /* setup windows */ |
| 290 | |
| 291 | *(volatile unsigned short *)(V3_BASE + V3_PCI_CMD) &= |
| 292 | ~(V3_COMMAND_M_MEM_EN | V3_COMMAND_M_IO_EN); |
| 293 | |
| 294 | /* Clear RST_OUT to 0; keep the PCI bus in reset until we've finished */ |
| 295 | |
| 296 | *(volatile unsigned short *)(V3_BASE + V3_SYSTEM) &= ~V3_SYSTEM_M_RST_OUT; |
| 297 | |
| 298 | /* Make all accesses from PCI space retry until we're ready for them */ |
| 299 | |
| 300 | *(volatile unsigned short *)(V3_BASE + V3_PCI_CFG) |= V3_PCI_CFG_M_RETRY_EN; |
| 301 | |
| 302 | /* Set up any V3 PCI Configuration Registers that we absolutely have to */ |
| 303 | /* LB_CFG controls Local Bus protocol. */ |
| 304 | /* Enable LocalBus byte strobes for READ accesses too. */ |
| 305 | /* set bit 7 BE_IMODE and bit 6 BE_OMODE */ |
| 306 | |
| 307 | *(volatile unsigned short *)(V3_BASE + V3_LB_CFG) |= 0x0C0; |
| 308 | |
| 309 | /* PCI_CMD controls overall PCI operation. */ |
| 310 | /* Enable PCI bus master. */ |
| 311 | |
| 312 | *(volatile unsigned short *)(V3_BASE + V3_PCI_CMD) |= 0x04; |
| 313 | |
| 314 | /* PCI_MAP0 controls where the PCI to CPU memory window is on Local Bus*/ |
| 315 | |
| 316 | *(volatile unsigned int *)(V3_BASE + V3_PCI_MAP0) = (INTEGRATOR_BOOT_ROM_BASE) | |
| 317 | (V3_PCI_MAP_M_ADR_SIZE_512M | |
| 318 | V3_PCI_MAP_M_REG_EN | |
| 319 | V3_PCI_MAP_M_ENABLE); |
| 320 | |
| 321 | /* PCI_BASE0 is the PCI address of the start of the window */ |
| 322 | |
| 323 | *(volatile unsigned int *)(V3_BASE + V3_PCI_BASE0) = INTEGRATOR_BOOT_ROM_BASE; |
| 324 | |
| 325 | /* PCI_MAP1 is LOCAL address of the start of the window */ |
| 326 | |
| 327 | *(volatile unsigned int *)(V3_BASE + V3_PCI_MAP1) = (INTEGRATOR_HDR0_SDRAM_BASE) | |
| 328 | (V3_PCI_MAP_M_ADR_SIZE_1024M | V3_PCI_MAP_M_REG_EN | |
| 329 | V3_PCI_MAP_M_ENABLE); |
| 330 | |
| 331 | /* PCI_BASE1 is the PCI address of the start of the window */ |
| 332 | |
| 333 | *(volatile unsigned int *)(V3_BASE + V3_PCI_BASE1) = INTEGRATOR_HDR0_SDRAM_BASE; |
| 334 | |
| 335 | /* Set up the windows from local bus memory into PCI configuration, */ |
| 336 | /* I/O and Memory. */ |
| 337 | /* PCI I/O, LB_BASE2 and LB_MAP2 are used exclusively for this. */ |
| 338 | |
| 339 | *(volatile unsigned short *)(V3_BASE +V3_LB_BASE2) = |
| 340 | ((CPU_PCI_IO_ADRS >> 24) << 8) | V3_LB_BASE_M_ENABLE; |
| 341 | *(volatile unsigned short *)(V3_BASE + V3_LB_MAP2) = 0; |
| 342 | |
| 343 | /* PCI Configuration, use LB_BASE1/LB_MAP1. */ |
| 344 | |
| 345 | /* PCI Memory use LB_BASE0/LB_MAP0 and LB_BASE1/LB_MAP1 */ |
| 346 | /* Map first 256Mbytes as non-prefetchable via BASE0/MAP0 */ |
| 347 | /* (INTEGRATOR_PCI_BASE == PCI_MEM_BASE) */ |
| 348 | |
| 349 | *(volatile unsigned int *)(V3_BASE + V3_LB_BASE0) = |
| 350 | INTEGRATOR_PCI_BASE | (0x80 | V3_LB_BASE_M_ENABLE); |
| 351 | |
| 352 | *(volatile unsigned short *)(V3_BASE + V3_LB_MAP0) = |
| 353 | ((INTEGRATOR_PCI_BASE >> 20) << 0x4) | 0x0006; |
| 354 | |
| 355 | /* Map second 256 Mbytes as prefetchable via BASE1/MAP1 */ |
| 356 | |
| 357 | *(volatile unsigned int *)(V3_BASE + V3_LB_BASE1) = |
| 358 | INTEGRATOR_PCI_BASE | (0x84 | V3_LB_BASE_M_ENABLE); |
| 359 | |
| 360 | *(volatile unsigned short *)(V3_BASE + V3_LB_MAP1) = |
| 361 | (((INTEGRATOR_PCI_BASE + 0x10000000) >> 20) << 4) | 0x0006; |
| 362 | |
| 363 | /* Allow accesses to PCI Configuration space */ |
| 364 | /* and set up A1, A0 for type 1 config cycles */ |
| 365 | |
| 366 | *(volatile unsigned short *)(V3_BASE + V3_PCI_CFG) = |
| 367 | ((*(volatile unsigned short *)(V3_BASE + V3_PCI_CFG)) & |
| 368 | ~(V3_PCI_CFG_M_RETRY_EN | V3_PCI_CFG_M_AD_LOW1) ) | |
| 369 | V3_PCI_CFG_M_AD_LOW0; |
| 370 | |
| 371 | /* now we can allow in PCI MEMORY accesses */ |
| 372 | |
| 373 | *(volatile unsigned short *)(V3_BASE + V3_PCI_CMD) = |
| 374 | (*(volatile unsigned short *)(V3_BASE + V3_PCI_CMD)) | V3_COMMAND_M_MEM_EN; |
| 375 | |
| 376 | /* Set RST_OUT to take the PCI bus is out of reset, PCI devices can */ |
| 377 | /* initialise and lock the V3 system register so that no one else */ |
| 378 | /* can play with it */ |
| 379 | |
| 380 | *(volatile unsigned short *)(V3_BASE + V3_SYSTEM) = |
| 381 | (*(volatile unsigned short *)(V3_BASE + V3_SYSTEM)) | V3_SYSTEM_M_RST_OUT; |
| 382 | |
| 383 | *(volatile unsigned short *)(V3_BASE + V3_SYSTEM) = |
| 384 | (*(volatile unsigned short *)(V3_BASE + V3_SYSTEM)) | V3_SYSTEM_M_LOCK; |
| 385 | |
| 386 | /* |
| 387 | * Register the hose |
| 388 | */ |
| 389 | hose->first_busno = 0; |
| 390 | hose->last_busno = 0xff; |
| 391 | |
| 392 | /* System memory space */ |
| 393 | pci_set_region(hose->regions + 0, |
| 394 | 0x00000000, 0x40000000, 0x01000000, |
| 395 | PCI_REGION_MEM | PCI_REGION_MEMORY); |
| 396 | |
| 397 | /* PCI Memory - config space */ |
| 398 | pci_set_region(hose->regions + 1, |
| 399 | 0x00000000, 0x62000000, 0x01000000, |
| 400 | PCI_REGION_MEM); |
| 401 | |
| 402 | /* PCI V3 regs */ |
| 403 | pci_set_region(hose->regions + 2, |
| 404 | 0x00000000, 0x61000000, 0x00080000, |
| 405 | PCI_REGION_MEM); |
| 406 | |
| 407 | /* PCI I/O space */ |
| 408 | pci_set_region(hose->regions + 3, |
| 409 | 0x00000000, 0x60000000, 0x00010000, |
| 410 | PCI_REGION_IO); |
| 411 | |
| 412 | pci_set_ops(hose, |
| 413 | pci_integrator_read_byte, |
| 414 | pci_integrator_read__word, |
| 415 | pci_integrator_read_dword, |
| 416 | pci_integrator_write_byte, |
| 417 | pci_integrator_write_word, |
| 418 | pci_integrator_write_dword); |
| 419 | |
| 420 | hose->region_count = 4; |
| 421 | |
| 422 | pci_register_hose(hose); |
| 423 | |
| 424 | pciauto_config_init(hose); |
| 425 | pciauto_config_device(hose, 0); |
| 426 | |
| 427 | hose->last_busno = pci_hose_scan(hose); |
| 428 | } |
| 429 | #endif |
| 430 | |
| 431 | /****************************** |
| 432 | Routine: |
| 433 | Description: |
| 434 | ******************************/ |
| 435 | void flash__init (void) |
| 436 | { |
| 437 | } |
| 438 | /************************************************************* |
| 439 | Routine:ether__init |
| 440 | Description: take the Ethernet controller out of reset and wait |
| 441 | for the EEPROM load to complete. |
| 442 | *************************************************************/ |
| 443 | void ether__init (void) |
| 444 | { |
| 445 | } |
| 446 | |
| 447 | /****************************** |
| 448 | Routine: |
| 449 | Description: |
| 450 | ******************************/ |
| 451 | int dram_init (void) |
| 452 | { |
| 453 | return 0; |
| 454 | } |
| 455 | |