Changeset 5073
- Timestamp:
- Feb 1, 2010 11:51:18 PM (3 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
-
mainboard/rca/rm4100/auto.c (modified) (3 diffs)
-
mainboard/thomson/ip1000/auto.c (modified) (3 diffs)
-
northbridge/intel/i82830/raminit.c (modified) (18 diffs)
-
northbridge/intel/i82830/raminit.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/mainboard/rca/rm4100/auto.c
r5069 r5073 70 70 71 71 #include "northbridge/intel/i82830/raminit.c" 72 #include "lib/generic_sdram.c"73 72 74 73 /** … … 104 103 static void main(unsigned long bist) 105 104 { 106 static const struct mem_controller memctrl[] = {107 {108 .d0 = PCI_DEV(0, 0, 0),109 .channel0 = {0x50, 0x51},110 }111 };112 113 105 if (bist == 0) 114 106 early_mtrr_init(); … … 130 122 mb_early_setup(); 131 123 132 /* SDRAM init */ 133 sdram_set_registers(memctrl); 134 sdram_set_spd_registers(memctrl); 135 sdram_enable(0, memctrl); 124 /* Initialize memory */ 125 sdram_initialize(); 136 126 137 127 /* Check RAM. */ -
trunk/src/mainboard/thomson/ip1000/auto.c
r5069 r5073 70 70 71 71 #include "northbridge/intel/i82830/raminit.c" 72 #include "lib/generic_sdram.c"73 72 74 73 /** … … 104 103 static void main(unsigned long bist) 105 104 { 106 static const struct mem_controller memctrl[] = {107 {108 .d0 = PCI_DEV(0, 0, 0),109 .channel0 = {0x50, 0x51},110 }111 };112 113 105 if (bist == 0) 114 106 early_mtrr_init(); … … 130 122 mb_early_setup(); 131 123 132 /* SDRAM init */ 133 sdram_set_registers(memctrl); 134 sdram_set_spd_registers(memctrl); 135 sdram_enable(0, memctrl); 124 /* Initialize memory */ 125 sdram_initialize(); 136 126 137 127 /* Check RAM. */ -
trunk/src/northbridge/intel/i82830/raminit.c
r3653 r5073 2 2 * This file is part of the coreboot project. 3 3 * 4 * Copyright (C) 2008 Joseph Smith <joe@smittys.pointclark.net>4 * Copyright (C) 2008-2010 Joseph Smith <joe@settoplinux.org> 5 5 * 6 6 * This program is free software; you can redistribute it and/or modify … … 68 68 69 69 /*----------------------------------------------------------------------------- 70 SDRAM configuration functions.70 DIMM-initialization functions. 71 71 -----------------------------------------------------------------------------*/ 72 72 73 /* Send the specified RAM command to all DIMMs. */ 74 75 static void do_ram_command(const struct mem_controller *ctrl, uint32_t command, 76 uint32_t addr_offset) 77 { 78 int i; 79 uint8_t dimm_start, dimm_end; 73 static void do_ram_command(uint32_t command) 74 { 80 75 uint32_t reg32; 81 76 82 77 /* Configure the RAM command. */ 83 reg32 = pci_read_config32( ctrl->d0, DRC);78 reg32 = pci_read_config32(NORTHBRIDGE, DRC); 84 79 /* Clear bits 29, 10-8, 6-4. */ 85 80 reg32 &= 0xdffff88f; 86 81 reg32 |= command << 4; 87 pci_write_config32(ctrl->d0, DRC, reg32); 88 89 /* Send the ram command to each row of memory. 90 * (DIMM_SOCKETS * 2) is the maximum number of rows possible. 91 * Note: Each DRB defines the upper boundary address of 92 * each SDRAM row in 32-MB granularity. 93 */ 82 pci_write_config32(NORTHBRIDGE, DRC, reg32); 83 PRINT_DEBUG("RAM command 0x"); 84 PRINT_DEBUG_HEX32(reg32); 85 PRINT_DEBUG("\r\n"); 86 } 87 88 static void ram_read32(uint8_t dimm_start, uint32_t offset) 89 { 90 if (offset == 0x55aa55aa) { 91 PRINT_DEBUG(" Reading RAM at 0x"); 92 PRINT_DEBUG_HEX32(dimm_start * 32 * 1024 * 1024); 93 PRINT_DEBUG(" => 0x"); 94 PRINT_DEBUG_HEX32(read32(dimm_start * 32 * 1024 * 1024)); 95 PRINT_DEBUG("\r\n"); 96 97 PRINT_DEBUG(" Writing RAM at 0x"); 98 PRINT_DEBUG_HEX32(dimm_start * 32 * 1024 * 1024); 99 PRINT_DEBUG(" <= 0x"); 100 PRINT_DEBUG_HEX32(offset); 101 PRINT_DEBUG("\r\n"); 102 write32(dimm_start * 32 * 1024 * 1024, offset); 103 104 PRINT_DEBUG(" Reading RAM at 0x"); 105 PRINT_DEBUG_HEX32(dimm_start * 32 * 1024 * 1024); 106 PRINT_DEBUG(" => 0x"); 107 PRINT_DEBUG_HEX32(read32(dimm_start * 32 * 1024 * 1024)); 108 PRINT_DEBUG("\r\n"); 109 } else { 110 PRINT_DEBUG(" Sending RAM command to 0x"); 111 PRINT_DEBUG_HEX32((dimm_start * 32 * 1024 * 1024) + offset); 112 PRINT_DEBUG("\r\n"); 113 read32((dimm_start * 32 * 1024 * 1024) + offset); 114 } 115 } 116 117 static void initialize_dimm_rows(void) 118 { 119 int i, row; 120 uint8_t dimm_start, dimm_end; 121 unsigned device; 122 94 123 dimm_start = 0; 95 124 96 for (i = 0; i < (DIMM_SOCKETS * 2); i++) { 97 dimm_end = pci_read_config8(ctrl->d0, DRB + i); 125 for (row = 0; row < (DIMM_SOCKETS * 2); row++) { 126 127 switch (row) { 128 case 0: 129 device = DIMM_SPD_BASE; 130 break; 131 case 1: 132 device = DIMM_SPD_BASE; 133 break; 134 case 2: 135 device = DIMM_SPD_BASE + 1; 136 break; 137 case 3: 138 device = DIMM_SPD_BASE + 1; 139 break; 140 } 141 142 dimm_end = pci_read_config8(NORTHBRIDGE, DRB + row); 143 98 144 if (dimm_end > dimm_start) { 99 PRINT_DEBUG(" Sending RAM command 0x"); 100 PRINT_DEBUG_HEX32(reg32); 101 PRINT_DEBUG(" to 0x"); 102 PRINT_DEBUG_HEX32((dimm_start * 32 * 1024 * 1024) + addr_offset); 103 PRINT_DEBUG("\r\n"); 104 read32((dimm_start * 32 * 1024 * 1024) + addr_offset); 145 print_debug("Initializing SDRAM Row "); 146 print_debug_hex8(row); 147 print_debug("\r\n"); 148 149 /* NOP command */ 150 PRINT_DEBUG(" NOP "); 151 do_ram_command(RAM_COMMAND_NOP); 152 ram_read32(dimm_start, 0); 153 udelay(200); 154 155 /* Pre-charge all banks (at least 200 us after NOP) */ 156 PRINT_DEBUG(" Pre-charging all banks "); 157 do_ram_command(RAM_COMMAND_PRECHARGE); 158 ram_read32(dimm_start, 0); 159 udelay(1); 160 161 /* 8 CBR refreshes (Auto Refresh) */ 162 PRINT_DEBUG(" 8 CBR refreshes "); 163 for (i = 0; i < 8; i++) { 164 do_ram_command(RAM_COMMAND_CBR); 165 ram_read32(dimm_start, 0); 166 udelay(1); 167 } 168 169 /* MRS command */ 170 /* TODO: Set offset 0x1d0 according to DRT values */ 171 PRINT_DEBUG(" MRS "); 172 do_ram_command(RAM_COMMAND_MRS); 173 ram_read32(dimm_start, 0x1d0); 174 udelay(2); 175 176 /* Set GMCH-M Mode Select bits back to NORMAL operation mode */ 177 PRINT_DEBUG(" Normal operation mode "); 178 do_ram_command(RAM_COMMAND_NORMAL); 179 ram_read32(dimm_start, 0); 180 udelay(1); 181 182 /* Perform a dummy memory read/write cycle */ 183 PRINT_DEBUG(" Performing dummy read/write\r\n"); 184 ram_read32(dimm_start, 0x55aa55aa); 185 udelay(1); 105 186 } 106 187 /* Set the start of the next DIMM. */ … … 123 204 int i, module_density, dimm_banks; 124 205 sz.side1 = 0; 125 module_density = spd_read_byte(device, 31);126 dimm_banks = spd_read_byte(device, 5);206 module_density = spd_read_byte(device, SPD_DENSITY_OF_EACH_ROW_ON_MODULE); 207 dimm_banks = spd_read_byte(device, SPD_NUM_DIMM_BANKS); 127 208 128 209 /* Find the size of side1. */ … … 164 245 } 165 246 166 static void s pd_set_dram_size(const struct mem_controller *ctrl)247 static void set_dram_row_boundaries(void) 167 248 { 168 249 int i, value, drb1, drb2; … … 171 252 struct dimm_size sz; 172 253 unsigned device; 173 device = ctrl->channel0[i];254 device = DIMM_SPD_BASE + i; 174 255 drb1 = 0; 175 256 drb2 = 0; 176 257 177 258 /* First check if a DIMM is actually present. */ 178 if (spd_read_byte(device, 2) == 0x4) {259 if (spd_read_byte(device, SPD_MEMORY_TYPE) == 0x4) { 179 260 print_debug("Found DIMM in slot "); 180 261 print_debug_hex8(i); … … 191 272 print_debug(" on side 2\r\n"); 192 273 274 /* - Memory compatibility checks - */ 193 275 /* Test for PC133 (i82830 only supports PC133) */ 194 276 /* PC133 SPD9 - cycle time is always 75 */ 195 if (spd_read_byte(device, 9) != 0x75) {277 if (spd_read_byte(device, SPD_MIN_CYCLE_TIME_AT_CAS_MAX) != 0x75) { 196 278 print_err("SPD9 DIMM Is Not PC133 Compatable\r\n"); 197 279 die("HALT\r\n"); 198 280 } 199 281 /* PC133 SPD10 - access time is always 54 */ 200 if (spd_read_byte(device, 10) != 0x54) {282 if (spd_read_byte(device, SPD_ACCESS_TIME_FROM_CLOCK) != 0x54) { 201 283 print_err("SPD10 DIMM Is Not PC133 Compatable\r\n"); 202 284 die("HALT\r\n"); … … 226 308 die("HALT\r\n"); 227 309 } 310 /* - End Memory compatibility checks - */ 228 311 229 312 /* We need to divide size by 32 to set up the … … 245 328 /* Set the value for DRAM Row Boundary Registers */ 246 329 if (i == 0) { 247 pci_write_config8( ctrl->d0, DRB, drb1);248 pci_write_config8( ctrl->d0, DRB + 1, drb1 + drb2);330 pci_write_config8(NORTHBRIDGE, DRB, drb1); 331 pci_write_config8(NORTHBRIDGE, DRB + 1, drb1 + drb2); 249 332 PRINT_DEBUG("DRB 0x"); 250 333 PRINT_DEBUG_HEX8(DRB); … … 258 341 PRINT_DEBUG("\r\n"); 259 342 } else if (i == 1) { 260 value = pci_read_config8(ctrl->d0, DRB + 1); 261 pci_write_config8(ctrl->d0, DRB + 2, value + drb1); 262 pci_write_config8(ctrl->d0, DRB + 3, 263 value + drb1 + drb2); 343 value = pci_read_config8(NORTHBRIDGE, DRB + 1); 344 pci_write_config8(NORTHBRIDGE, DRB + 2, value + drb1); 345 pci_write_config8(NORTHBRIDGE, DRB + 3, value + drb1 + drb2); 264 346 PRINT_DEBUG("DRB2 0x"); 265 347 PRINT_DEBUG_HEX8(DRB + 2); … … 277 359 * not initialize properly if we don't. 278 360 */ 279 value = pci_read_config8( ctrl->d0, DRB + 3);280 pci_write_config8( ctrl->d0, DRB + 4, value);281 pci_write_config8( ctrl->d0, DRB + 5, value);282 } 283 } 284 } 285 286 static void set_dram_row_attributes( const struct mem_controller *ctrl)361 value = pci_read_config8(NORTHBRIDGE, DRB + 3); 362 pci_write_config8(NORTHBRIDGE, DRB + 4, value); 363 pci_write_config8(NORTHBRIDGE, DRB + 5, value); 364 } 365 } 366 } 367 368 static void set_dram_row_attributes(void) 287 369 { 288 370 int i, dra, col, width, value; … … 290 372 for (i = 0; i < DIMM_SOCKETS; i++) { 291 373 unsigned device; 292 device = ctrl->channel0[i];374 device = DIMM_SPD_BASE + i; 293 375 294 376 /* First check if a DIMM is actually present. */ 295 if (spd_read_byte(device, 2) == 0x4) {377 if (spd_read_byte(device, SPD_MEMORY_TYPE) == 0x4) { 296 378 print_debug("Found DIMM in slot "); 297 379 print_debug_hex8(i); … … 301 383 302 384 /* columns */ 303 col = spd_read_byte(device, 4);385 col = spd_read_byte(device, SPD_NUM_COLUMNS); 304 386 305 387 /* data width */ 306 width = spd_read_byte(device, 6);388 width = spd_read_byte(device, SPD_MODULE_DATA_WIDTH_LSB); 307 389 308 390 /* calculate page size in bits */ … … 313 395 314 396 /* # of banks of DIMM (single or double sided) */ 315 value = spd_read_byte(device, 5);397 value = spd_read_byte(device, SPD_NUM_DIMM_BANKS); 316 398 317 399 if (value == 1) { … … 356 438 357 439 /* Set the value for DRAM Row Attribute Registers */ 358 pci_write_config8( ctrl->d0, DRA + i, dra);440 pci_write_config8(NORTHBRIDGE, DRA + i, dra); 359 441 PRINT_DEBUG("DRA 0x"); 360 442 PRINT_DEBUG_HEX8(DRA + i); … … 365 447 } 366 448 367 static void set_dram_timing( const struct mem_controller *ctrl)449 static void set_dram_timing(void) 368 450 { 369 451 /* Set the value for DRAM Timing Register */ 370 452 /* TODO: Configure the value according to SPD values. */ 371 pci_write_config32( ctrl->d0, DRT, 0x00000010);372 } 373 374 static void set_dram_buffer_strength( const struct mem_controller *ctrl)453 pci_write_config32(NORTHBRIDGE, DRT, 0x00000010); 454 } 455 456 static void set_dram_buffer_strength(void) 375 457 { 376 458 /* TODO: This needs to be set according to the DRAM tech … … 381 463 382 464 /* Set the value for System Memory Buffer Strength Control Registers */ 383 pci_write_config32( ctrl->d0, BUFF_SC, 0xFC9B491B);465 pci_write_config32(NORTHBRIDGE, BUFF_SC, 0xFC9B491B); 384 466 } 385 467 … … 388 470 -----------------------------------------------------------------------------*/ 389 471 390 static void sdram_set_registers(const struct mem_controller *ctrl) 472 static void sdram_set_registers(void) 473 { 474 PRINT_DEBUG("Setting initial sdram registers....\r\n"); 475 476 /* Calculate the value for DRT DRAM Timing Register */ 477 set_dram_timing(); 478 479 /* Setup System Memory Buffer Strength Control Registers */ 480 set_dram_buffer_strength(); 481 482 /* Setup DRAM Row Boundary Registers */ 483 set_dram_row_boundaries(); 484 485 /* Setup DRAM Row Attribute Registers */ 486 set_dram_row_attributes(); 487 488 PRINT_DEBUG("Initial sdram registers have been set.\r\n"); 489 } 490 491 static void northbridge_set_registers(void) 391 492 { 392 493 uint16_t value; 393 494 int igd_memory = 0; 394 495 395 PRINT_DEBUG("Setting initial registers....\r\n"); 496 PRINT_DEBUG("Setting initial nothbridge registers....\r\n"); 497 498 /* Set the value for Fixed DRAM Hole Control Register */ 499 pci_write_config8(NORTHBRIDGE, FDHC, 0x00); 500 501 /* Set the value for Programable Attribute Map Registers 502 * Ideally, this should be R/W for as many ranges as possible. 503 */ 504 pci_write_config8(NORTHBRIDGE, PAM0, 0x30); 505 pci_write_config8(NORTHBRIDGE, PAM1, 0x33); 506 pci_write_config8(NORTHBRIDGE, PAM2, 0x33); 507 pci_write_config8(NORTHBRIDGE, PAM3, 0x33); 508 pci_write_config8(NORTHBRIDGE, PAM4, 0x33); 509 pci_write_config8(NORTHBRIDGE, PAM5, 0x33); 510 pci_write_config8(NORTHBRIDGE, PAM6, 0x33); 511 512 /* Set the value for System Management RAM Control Register */ 513 pci_write_config8(NORTHBRIDGE, SMRAM, 0x02); 396 514 397 515 /* Set the value for GMCH Control Register #0 */ 398 pci_write_config16(ctrl->d0, GCC0, 0xA072); 516 pci_write_config16(NORTHBRIDGE, GCC0, 0xA072); 517 518 /* Set the value for Aperture Base Configuration Register */ 519 pci_write_config32(NORTHBRIDGE, APBASE, 0x00000008); 399 520 400 521 /* Set the value for GMCH Control Register #1 */ … … 410 531 break; 411 532 default: /* No memory */ 412 pci_write_config16( ctrl->d0, GCC1, 0x0002);533 pci_write_config16(NORTHBRIDGE, GCC1, 0x0002); 413 534 igd_memory = 0x0; 414 535 } 415 536 416 value = pci_read_config16( ctrl->d0, GCC1);537 value = pci_read_config16(NORTHBRIDGE, GCC1); 417 538 value |= igd_memory << 4; 418 pci_write_config16(ctrl->d0, GCC1, value); 419 420 /* Set the value for Aperture Base Configuration Register */ 421 pci_write_config32(ctrl->d0, APBASE, 0x00000008); 422 423 /* Set the value for Register Range Base Address Register */ 424 pci_write_config32(ctrl->d0, RRBAR, 0x00000000); 425 426 /* Set the value for Fixed DRAM Hole Control Register */ 427 pci_write_config8(ctrl->d0, FDHC, 0x00); 428 429 /* Set the value for Programable Attribute Map Registers 430 * Ideally, this should be R/W for as many ranges as possible. 431 */ 432 pci_write_config8(ctrl->d0, PAM0, 0x30); 433 pci_write_config8(ctrl->d0, PAM1, 0x33); 434 pci_write_config8(ctrl->d0, PAM2, 0x33); 435 pci_write_config8(ctrl->d0, PAM3, 0x33); 436 pci_write_config8(ctrl->d0, PAM4, 0x33); 437 pci_write_config8(ctrl->d0, PAM5, 0x33); 438 pci_write_config8(ctrl->d0, PAM6, 0x33); 439 440 /* Set the value for DRAM Throttling Control Register */ 441 pci_write_config32(ctrl->d0, DTC, 0x00000000); 442 443 /* Set the value for System Management RAM Control Register */ 444 pci_write_config8(ctrl->d0, SMRAM, 0x02); 445 446 /* Set the value for Extended System Management RAM Control Register */ 447 pci_write_config8(ctrl->d0, ESMRAMC, 0x38); 448 449 PRINT_DEBUG("Initial registers have been set.\r\n"); 450 } 451 452 static void sdram_set_spd_registers(const struct mem_controller *ctrl) 453 { 454 spd_set_dram_size(ctrl); 455 set_dram_row_attributes(ctrl); 456 set_dram_timing(ctrl); 457 set_dram_buffer_strength(ctrl); 458 } 459 460 static void sdram_enable(int controllers, const struct mem_controller *ctrl) 539 pci_write_config16(NORTHBRIDGE, GCC1, value); 540 541 PRINT_DEBUG("Initial northbridge registers have been set.\r\n"); 542 } 543 544 static void sdram_initialize(void) 461 545 { 462 546 int i; 463 547 uint32_t reg32; 464 548 549 /* Setup Initial SDRAM Registers */ 550 sdram_set_registers(); 551 465 552 /* 0. Wait until power/voltages and clocks are stable (200us). */ 466 553 udelay(200); 467 554 468 /* 1. Apply NOP. */ 469 PRINT_DEBUG("RAM Enable 1: Apply NOP\r\n"); 470 do_ram_command(ctrl, RAM_COMMAND_NOP, 0); 471 udelay(200); 472 473 /* 2. Precharge all. Wait tRP. */ 474 PRINT_DEBUG("RAM Enable 2: Precharge all\r\n"); 475 do_ram_command(ctrl, RAM_COMMAND_PRECHARGE, 0); 476 udelay(1); 477 478 /* 3. Perform 8 refresh cycles. Wait tRC each time. */ 479 PRINT_DEBUG("RAM Enable 3: CBR\r\n"); 480 for (i = 0; i < 8; i++) { 481 do_ram_command(ctrl, RAM_COMMAND_CBR, 0); 482 udelay(1); 483 } 484 485 /* 4. Mode register set. Wait two memory cycles. */ 486 /* TODO: Set offset according to DRT values */ 487 PRINT_DEBUG("RAM Enable 4: Mode register set\r\n"); 488 do_ram_command(ctrl, RAM_COMMAND_MRS, 0x1d0); 489 udelay(2); 490 491 /* 5. Normal operation (enables refresh) */ 492 PRINT_DEBUG("RAM Enable 5: Normal operation\r\n"); 493 do_ram_command(ctrl, RAM_COMMAND_NORMAL, 0); 494 udelay(1); 495 496 /* 6. Enable refresh and Set initialization complete. */ 497 PRINT_DEBUG("RAM Enable 6: Enable Refresh and IC\r\n"); 498 reg32 = pci_read_config32(ctrl->d0, DRC); 499 reg32 |= ((RAM_COMMAND_REFRESH << 8) | (RAM_COMMAND_IC << 29)); 500 pci_write_config32(ctrl->d0, DRC, reg32); 555 /* Initialize each row of memory one at a time */ 556 initialize_dimm_rows(); 557 558 /* Enable Refresh */ 559 PRINT_DEBUG("Enabling Refresh\r\n"); 560 reg32 = pci_read_config32(NORTHBRIDGE, DRC); 561 reg32 |= (RAM_COMMAND_REFRESH << 8); 562 pci_write_config32(NORTHBRIDGE, DRC, reg32); 563 564 /* Set initialization complete */ 565 PRINT_DEBUG("Setting initialization complete\r\n"); 566 reg32 = pci_read_config32(NORTHBRIDGE, DRC); 567 reg32 |= (RAM_COMMAND_IC << 29); 568 pci_write_config32(NORTHBRIDGE, DRC, reg32); 569 570 /* Setup Initial Northbridge Registers */ 571 northbridge_set_registers(); 501 572 502 573 PRINT_DEBUG("Northbridge following SDRAM init:\r\n"); -
trunk/src/northbridge/intel/i82830/raminit.h
r3129 r5073 2 2 * This file is part of the coreboot project. 3 3 * 4 * Copyright (C) 2008 Joseph Smith <joe@smittys.pointclark.net>4 * Copyright (C) 2008-2010 Joseph Smith <joe@settoplinux.org> 5 5 * 6 6 * This program is free software; you can redistribute it and/or modify … … 22 22 #define NORTHBRIDGE_INTEL_I82830_RAMINIT_H 23 23 24 /* 82830 Northbridge PCI device */ 25 #define NORTHBRIDGE PCI_DEV(0, 0, 0) 26 24 27 /* The 82830 supports max. 2 dual-sided SO-DIMMs. */ 25 28 #define DIMM_SOCKETS 2 26 29 27 struct mem_controller { 28 device_t d0; 29 uint16_t channel0[DIMM_SOCKETS]; 30 }; 30 /* DIMM0 is at 0x50, DIMM1 is at 0x51. */ 31 #define DIMM_SPD_BASE 0x50 31 32 32 33 #endif /* NORTHBRIDGE_INTEL_I82830_RAMINIT_H */
Note: See TracChangeset
for help on using the changeset viewer.
