1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <commonlib/bsd/clamp.h>
4 #include <console/console.h>
5 #include <console/usb.h>
6 #include <cpu/intel/model_206ax/model_206ax.h>
8 #include <device/device.h>
9 #include <device/pci_def.h>
10 #include <device/pci_ops.h>
11 #include <northbridge/intel/sandybridge/chip.h>
15 #include "sandybridge.h"
16 #include "raminit_common.h"
17 #include "raminit_tables.h"
19 #define SNB_MIN_DCLK_133_MULT 3
20 #define SNB_MAX_DCLK_133_MULT 8
21 #define IVB_MIN_DCLK_133_MULT 3
22 #define IVB_MAX_DCLK_133_MULT 10
23 #define IVB_MIN_DCLK_100_MULT 7
24 #define IVB_MAX_DCLK_100_MULT 12
26 /* Frequency multiplier */
27 static u32
get_FRQ(const ramctr_timing
*ctrl
)
29 const u32 FRQ
= 256000 / (ctrl
->tCK
* ctrl
->base_freq
);
31 if (IS_IVY_CPU(ctrl
->cpu
)) {
32 if (ctrl
->base_freq
== 100)
33 return clamp_u32(IVB_MIN_DCLK_100_MULT
, FRQ
, IVB_MAX_DCLK_100_MULT
);
35 if (ctrl
->base_freq
== 133)
36 return clamp_u32(IVB_MIN_DCLK_133_MULT
, FRQ
, IVB_MAX_DCLK_133_MULT
);
38 } else if (IS_SANDY_CPU(ctrl
->cpu
)) {
39 if (ctrl
->base_freq
== 133)
40 return clamp_u32(SNB_MIN_DCLK_133_MULT
, FRQ
, SNB_MAX_DCLK_133_MULT
);
43 die("Unsupported CPU or base frequency.");
46 /* CAS write latency. To be programmed in MR2. See DDR3 SPEC for MR2 documentation. */
47 static u8
get_CWL(u32 tCK
)
49 /* Get CWL based on tCK using the following rule */
81 /* Get REFI based on frequency index, tREFI = 7.8usec */
82 static u32
get_REFI(u32 FRQ
, u8 base_freq
)
85 return frq_refi_map
[1][FRQ
- 7];
88 return frq_refi_map
[0][FRQ
- 3];
91 /* Get XSOffset based on frequency index, tXS-Offset: tXS = tRFC + 10ns */
92 static u8
get_XSOffset(u32 FRQ
, u8 base_freq
)
95 return frq_xs_map
[1][FRQ
- 7];
98 return frq_xs_map
[0][FRQ
- 3];
101 /* Get MOD based on frequency index */
102 static u8
get_MOD(u32 FRQ
, u8 base_freq
)
104 if (base_freq
== 100)
105 return frq_mod_map
[1][FRQ
- 7];
108 return frq_mod_map
[0][FRQ
- 3];
111 /* Get Write Leveling Output delay based on frequency index */
112 static u8
get_WLO(u32 FRQ
, u8 base_freq
)
114 if (base_freq
== 100)
115 return frq_wlo_map
[1][FRQ
- 7];
118 return frq_wlo_map
[0][FRQ
- 3];
121 /* Get CKE based on frequency index */
122 static u8
get_CKE(u32 FRQ
, u8 base_freq
)
124 if (base_freq
== 100)
125 return frq_cke_map
[1][FRQ
- 7];
128 return frq_cke_map
[0][FRQ
- 3];
131 /* Get XPDLL based on frequency index */
132 static u8
get_XPDLL(u32 FRQ
, u8 base_freq
)
134 if (base_freq
== 100)
135 return frq_xpdll_map
[1][FRQ
- 7];
138 return frq_xpdll_map
[0][FRQ
- 3];
141 /* Get XP based on frequency index */
142 static u8
get_XP(u32 FRQ
, u8 base_freq
)
144 if (base_freq
== 100)
145 return frq_xp_map
[1][FRQ
- 7];
148 return frq_xp_map
[0][FRQ
- 3];
151 /* Get AONPD based on frequency index */
152 static u8
get_AONPD(u32 FRQ
, u8 base_freq
)
154 if (base_freq
== 100)
155 return frq_aonpd_map
[1][FRQ
- 7];
158 return frq_aonpd_map
[0][FRQ
- 3];
161 /* Get COMP2 based on CPU generation and clock speed */
162 static u32
get_COMP2(const ramctr_timing
*ctrl
)
164 const bool is_ivybridge
= IS_IVY_CPU(ctrl
->cpu
);
166 if (ctrl
->tCK
<= TCK_1066MHZ
)
167 return is_ivybridge
? 0x0C235924 : 0x0C21410C;
168 else if (ctrl
->tCK
<= TCK_933MHZ
)
169 return is_ivybridge
? 0x0C446964 : 0x0C42514C;
170 else if (ctrl
->tCK
<= TCK_800MHZ
)
171 return is_ivybridge
? 0x0C6671E4 : 0x0C6369CC;
172 else if (ctrl
->tCK
<= TCK_666MHZ
)
173 return is_ivybridge
? 0x0CA8C264 : 0x0CA57A4C;
174 else if (ctrl
->tCK
<= TCK_533MHZ
)
175 return is_ivybridge
? 0x0CEBDB64 : 0x0CE7C34C;
177 return is_ivybridge
? 0x0D6FF5E4 : 0x0D6BEDCC;
180 /* Get updated COMP1 based on CPU generation and stepping */
181 static u32
get_COMP1(ramctr_timing
*ctrl
, const int channel
)
183 const union comp_ofst_1_reg orig_comp
= {
184 .raw
= mchbar_read32(CRCOMPOFST1_ch(channel
)),
187 if (IS_SANDY_CPU(ctrl
->cpu
) && !IS_SANDY_CPU_D2(ctrl
->cpu
)) {
188 union comp_ofst_1_reg comp_ofst_1
= orig_comp
;
190 comp_ofst_1
.clk_odt_up
= 1;
191 comp_ofst_1
.clk_drv_up
= 1;
192 comp_ofst_1
.ctl_drv_up
= 1;
194 return comp_ofst_1
.raw
;
197 /* Fix PCODE COMP offset bug: revert to default values */
198 union comp_ofst_1_reg comp_ofst_1
= {
202 .clk_odt_up
= orig_comp
.clk_odt_up
,
204 .dq_drv_up
= orig_comp
.dq_drv_up
,
206 .clk_drv_up
= orig_comp
.clk_drv_up
,
208 .ctl_drv_up
= orig_comp
.ctl_drv_up
,
211 if (IS_IVY_CPU(ctrl
->cpu
))
212 comp_ofst_1
.dq_drv_up
= 2; /* 28p6 ohms */
214 return comp_ofst_1
.raw
;
217 static void normalize_tclk(ramctr_timing
*ctrl
, bool ref_100mhz_support
)
219 if (ctrl
->tCK
<= TCK_1200MHZ
) {
220 ctrl
->tCK
= TCK_1200MHZ
;
221 ctrl
->base_freq
= 133;
222 } else if (ctrl
->tCK
<= TCK_1100MHZ
) {
223 ctrl
->tCK
= TCK_1100MHZ
;
224 ctrl
->base_freq
= 100;
225 } else if (ctrl
->tCK
<= TCK_1066MHZ
) {
226 ctrl
->tCK
= TCK_1066MHZ
;
227 ctrl
->base_freq
= 133;
228 } else if (ctrl
->tCK
<= TCK_1000MHZ
) {
229 ctrl
->tCK
= TCK_1000MHZ
;
230 ctrl
->base_freq
= 100;
231 } else if (ctrl
->tCK
<= TCK_933MHZ
) {
232 ctrl
->tCK
= TCK_933MHZ
;
233 ctrl
->base_freq
= 133;
234 } else if (ctrl
->tCK
<= TCK_900MHZ
) {
235 ctrl
->tCK
= TCK_900MHZ
;
236 ctrl
->base_freq
= 100;
237 } else if (ctrl
->tCK
<= TCK_800MHZ
) {
238 ctrl
->tCK
= TCK_800MHZ
;
239 ctrl
->base_freq
= 133;
240 } else if (ctrl
->tCK
<= TCK_700MHZ
) {
241 ctrl
->tCK
= TCK_700MHZ
;
242 ctrl
->base_freq
= 100;
243 } else if (ctrl
->tCK
<= TCK_666MHZ
) {
244 ctrl
->tCK
= TCK_666MHZ
;
245 ctrl
->base_freq
= 133;
246 } else if (ctrl
->tCK
<= TCK_533MHZ
) {
247 ctrl
->tCK
= TCK_533MHZ
;
248 ctrl
->base_freq
= 133;
249 } else if (ctrl
->tCK
<= TCK_400MHZ
) {
250 ctrl
->tCK
= TCK_400MHZ
;
251 ctrl
->base_freq
= 133;
257 if (!ref_100mhz_support
&& ctrl
->base_freq
== 100) {
258 /* Skip unsupported frequency */
260 normalize_tclk(ctrl
, ref_100mhz_support
);
264 #define DEFAULT_TCK TCK_800MHZ
266 static unsigned int get_mem_min_tck(void)
270 const struct northbridge_intel_sandybridge_config
*cfg
= NULL
;
272 /* Actually, config of MCH or Host Bridge */
273 cfg
= config_of_soc();
275 /* If non-zero, it was set in the devicetree */
276 if (cfg
->max_mem_clock_mhz
) {
278 if (cfg
->max_mem_clock_mhz
>= 1066)
281 else if (cfg
->max_mem_clock_mhz
>= 933)
284 else if (cfg
->max_mem_clock_mhz
>= 800)
287 else if (cfg
->max_mem_clock_mhz
>= 666)
290 else if (cfg
->max_mem_clock_mhz
>= 533)
297 if (CONFIG(NATIVE_RAMINIT_IGNORE_MAX_MEM_FUSES
))
300 rev
= pci_read_config8(HOST_BRIDGE
, PCI_DEVICE_ID
);
302 if ((rev
& BASE_REV_MASK
) == BASE_REV_SNB
) {
303 /* Read Capabilities A Register DMFC bits */
304 reg32
= pci_read_config32(HOST_BRIDGE
, CAPID0_A
);
308 case 7: return TCK_533MHZ
;
309 case 6: return TCK_666MHZ
;
310 case 5: return TCK_800MHZ
;
316 /* Read Capabilities B Register DMFC bits */
317 reg32
= pci_read_config32(HOST_BRIDGE
, CAPID0_B
);
318 reg32
= (reg32
>> 4) & 0x7;
321 case 7: return TCK_533MHZ
;
322 case 6: return TCK_666MHZ
;
323 case 5: return TCK_800MHZ
;
324 case 4: return TCK_933MHZ
;
325 case 3: return TCK_1066MHZ
;
326 case 2: return TCK_1200MHZ
;
327 case 1: return TCK_1333MHZ
;
336 static void find_cas_tck(ramctr_timing
*ctrl
)
340 u8 ref_100mhz_support
;
342 /* 100 MHz reference clock supported */
343 reg32
= pci_read_config32(HOST_BRIDGE
, CAPID0_B
);
344 ref_100mhz_support
= (reg32
>> 21) & 0x7;
345 printk(BIOS_DEBUG
, "100MHz reference clock support: %s\n", ref_100mhz_support
? "yes"
348 printk(BIOS_DEBUG
, "PLL_REF100_CFG value: 0x%x\n", ref_100mhz_support
);
350 ctrl
->tCK
= get_mem_min_tck();
352 /* Find CAS latency */
355 * Normalising tCK before computing clock could potentially
356 * result in a lower selected CAS, which is desired.
358 normalize_tclk(ctrl
, ref_100mhz_support
);
360 die("Couldn't find compatible clock / CAS settings\n");
362 val
= DIV_ROUND_UP(ctrl
->tAA
, ctrl
->tCK
);
363 printk(BIOS_DEBUG
, "Trying CAS %u, tCK %u.\n", val
, ctrl
->tCK
);
364 for (; val
<= MAX_CAS
; val
++)
365 if ((ctrl
->cas_supported
>> (val
- MIN_CAS
)) & 1)
368 if (val
== (MAX_CAS
+ 1)) {
372 printk(BIOS_DEBUG
, "Found compatible clock, CAS pair.\n");
377 /* Frequency multiplier */
378 ctrl
->FRQ
= get_FRQ(ctrl
);
380 printk(BIOS_DEBUG
, "Selected DRAM frequency: %u MHz\n", NS2MHZ_DIV256
/ ctrl
->tCK
);
381 printk(BIOS_DEBUG
, "Selected CAS latency : %uT\n", val
);
385 static void dram_timing(ramctr_timing
*ctrl
)
388 * On Sandy Bridge, the maximum supported DDR3 frequency is 1066MHz (DDR3 2133).
389 * Cap it for faster DIMMs, and align it to the closest JEDEC standard frequency.
392 * On Ivy Bridge, the maximum supported DDR3 frequency is 1400MHz (DDR3 2800).
393 * Cap it at 1200MHz (DDR3 2400), and align it to the closest JEDEC standard frequency.
395 if (ctrl
->tCK
== TCK_1200MHZ
) {
396 ctrl
->edge_offset
[0] = 18; //XXX: guessed
397 ctrl
->edge_offset
[1] = 8;
398 ctrl
->edge_offset
[2] = 8;
399 ctrl
->tx_dq_offset
[0] = 20; //XXX: guessed
400 ctrl
->tx_dq_offset
[1] = 8;
401 ctrl
->tx_dq_offset
[2] = 8;
402 ctrl
->pi_coding_threshold
= 10;
404 } else if (ctrl
->tCK
== TCK_1100MHZ
) {
405 ctrl
->edge_offset
[0] = 17; //XXX: guessed
406 ctrl
->edge_offset
[1] = 7;
407 ctrl
->edge_offset
[2] = 7;
408 ctrl
->tx_dq_offset
[0] = 19; //XXX: guessed
409 ctrl
->tx_dq_offset
[1] = 7;
410 ctrl
->tx_dq_offset
[2] = 7;
411 ctrl
->pi_coding_threshold
= 13;
413 } else if (ctrl
->tCK
== TCK_1066MHZ
) {
414 ctrl
->edge_offset
[0] = 16;
415 ctrl
->edge_offset
[1] = 7;
416 ctrl
->edge_offset
[2] = 7;
417 ctrl
->tx_dq_offset
[0] = 18;
418 ctrl
->tx_dq_offset
[1] = 7;
419 ctrl
->tx_dq_offset
[2] = 7;
420 ctrl
->pi_coding_threshold
= 13;
422 } else if (ctrl
->tCK
== TCK_1000MHZ
) {
423 ctrl
->edge_offset
[0] = 15; //XXX: guessed
424 ctrl
->edge_offset
[1] = 6;
425 ctrl
->edge_offset
[2] = 6;
426 ctrl
->tx_dq_offset
[0] = 17; //XXX: guessed
427 ctrl
->tx_dq_offset
[1] = 6;
428 ctrl
->tx_dq_offset
[2] = 6;
429 ctrl
->pi_coding_threshold
= 13;
431 } else if (ctrl
->tCK
== TCK_933MHZ
) {
432 ctrl
->edge_offset
[0] = 14;
433 ctrl
->edge_offset
[1] = 6;
434 ctrl
->edge_offset
[2] = 6;
435 ctrl
->tx_dq_offset
[0] = 15;
436 ctrl
->tx_dq_offset
[1] = 6;
437 ctrl
->tx_dq_offset
[2] = 6;
438 ctrl
->pi_coding_threshold
= 15;
440 } else if (ctrl
->tCK
== TCK_900MHZ
) {
441 ctrl
->edge_offset
[0] = 14; //XXX: guessed
442 ctrl
->edge_offset
[1] = 6;
443 ctrl
->edge_offset
[2] = 6;
444 ctrl
->tx_dq_offset
[0] = 15; //XXX: guessed
445 ctrl
->tx_dq_offset
[1] = 6;
446 ctrl
->tx_dq_offset
[2] = 6;
447 ctrl
->pi_coding_threshold
= 12;
449 } else if (ctrl
->tCK
== TCK_800MHZ
) {
450 ctrl
->edge_offset
[0] = 13;
451 ctrl
->edge_offset
[1] = 5;
452 ctrl
->edge_offset
[2] = 5;
453 ctrl
->tx_dq_offset
[0] = 14;
454 ctrl
->tx_dq_offset
[1] = 5;
455 ctrl
->tx_dq_offset
[2] = 5;
456 ctrl
->pi_coding_threshold
= 15;
458 } else if (ctrl
->tCK
== TCK_700MHZ
) {
459 ctrl
->edge_offset
[0] = 13; //XXX: guessed
460 ctrl
->edge_offset
[1] = 5;
461 ctrl
->edge_offset
[2] = 5;
462 ctrl
->tx_dq_offset
[0] = 14; //XXX: guessed
463 ctrl
->tx_dq_offset
[1] = 5;
464 ctrl
->tx_dq_offset
[2] = 5;
465 ctrl
->pi_coding_threshold
= 16;
467 } else if (ctrl
->tCK
== TCK_666MHZ
) {
468 ctrl
->edge_offset
[0] = 10;
469 ctrl
->edge_offset
[1] = 4;
470 ctrl
->edge_offset
[2] = 4;
471 ctrl
->tx_dq_offset
[0] = 11;
472 ctrl
->tx_dq_offset
[1] = 4;
473 ctrl
->tx_dq_offset
[2] = 4;
474 ctrl
->pi_coding_threshold
= 16;
476 } else if (ctrl
->tCK
== TCK_533MHZ
) {
477 ctrl
->edge_offset
[0] = 8;
478 ctrl
->edge_offset
[1] = 3;
479 ctrl
->edge_offset
[2] = 3;
480 ctrl
->tx_dq_offset
[0] = 9;
481 ctrl
->tx_dq_offset
[1] = 3;
482 ctrl
->tx_dq_offset
[2] = 3;
483 ctrl
->pi_coding_threshold
= 17;
485 } else { /* TCK_400MHZ */
486 ctrl
->edge_offset
[0] = 6;
487 ctrl
->edge_offset
[1] = 2;
488 ctrl
->edge_offset
[2] = 2;
489 ctrl
->tx_dq_offset
[0] = 6;
490 ctrl
->tx_dq_offset
[1] = 2;
491 ctrl
->tx_dq_offset
[2] = 2;
492 ctrl
->pi_coding_threshold
= 17;
495 /* Initial phase between CLK/CMD pins */
496 ctrl
->pi_code_offset
= (256000 / ctrl
->tCK
) / 66;
498 /* DLL_CONFIG_MDLL_W_TIMER */
499 ctrl
->mdll_wake_delay
= (128000 / ctrl
->tCK
) + 3;
502 ctrl
->CWL
= DIV_ROUND_UP(ctrl
->tCWL
, ctrl
->tCK
);
504 ctrl
->CWL
= get_CWL(ctrl
->tCK
);
506 ctrl
->tRCD
= DIV_ROUND_UP(ctrl
->tRCD
, ctrl
->tCK
);
507 ctrl
->tRP
= DIV_ROUND_UP(ctrl
->tRP
, ctrl
->tCK
);
508 ctrl
->tRAS
= DIV_ROUND_UP(ctrl
->tRAS
, ctrl
->tCK
);
509 ctrl
->tWR
= DIV_ROUND_UP(ctrl
->tWR
, ctrl
->tCK
);
510 ctrl
->tFAW
= DIV_ROUND_UP(ctrl
->tFAW
, ctrl
->tCK
);
511 ctrl
->tRRD
= DIV_ROUND_UP(ctrl
->tRRD
, ctrl
->tCK
);
512 ctrl
->tRTP
= DIV_ROUND_UP(ctrl
->tRTP
, ctrl
->tCK
);
513 ctrl
->tWTR
= DIV_ROUND_UP(ctrl
->tWTR
, ctrl
->tCK
);
514 ctrl
->tRFC
= DIV_ROUND_UP(ctrl
->tRFC
, ctrl
->tCK
);
516 ctrl
->tREFI
= get_REFI(ctrl
->FRQ
, ctrl
->base_freq
);
517 ctrl
->tMOD
= get_MOD(ctrl
->FRQ
, ctrl
->base_freq
);
518 ctrl
->tXSOffset
= get_XSOffset(ctrl
->FRQ
, ctrl
->base_freq
);
519 ctrl
->tWLO
= get_WLO(ctrl
->FRQ
, ctrl
->base_freq
);
520 ctrl
->tCKE
= get_CKE(ctrl
->FRQ
, ctrl
->base_freq
);
521 ctrl
->tXPDLL
= get_XPDLL(ctrl
->FRQ
, ctrl
->base_freq
);
522 ctrl
->tXP
= get_XP(ctrl
->FRQ
, ctrl
->base_freq
);
523 ctrl
->tAONPD
= get_AONPD(ctrl
->FRQ
, ctrl
->base_freq
);
525 printk(BIOS_DEBUG
, "Selected CWL latency : %uT\n", ctrl
->CWL
);
526 printk(BIOS_DEBUG
, "Selected tRCD : %uT\n", ctrl
->tRCD
);
527 printk(BIOS_DEBUG
, "Selected tRP : %uT\n", ctrl
->tRP
);
528 printk(BIOS_DEBUG
, "Selected tRAS : %uT\n", ctrl
->tRAS
);
529 printk(BIOS_DEBUG
, "Selected tWR : %uT\n", ctrl
->tWR
);
530 printk(BIOS_DEBUG
, "Selected tFAW : %uT\n", ctrl
->tFAW
);
531 printk(BIOS_DEBUG
, "Selected tRRD : %uT\n", ctrl
->tRRD
);
532 printk(BIOS_DEBUG
, "Selected tRTP : %uT\n", ctrl
->tRTP
);
533 printk(BIOS_DEBUG
, "Selected tWTR : %uT\n", ctrl
->tWTR
);
534 printk(BIOS_DEBUG
, "Selected tRFC : %uT\n", ctrl
->tRFC
);
537 static void dram_freq(ramctr_timing
*ctrl
)
539 if (ctrl
->tCK
> TCK_400MHZ
) {
541 "DRAM frequency is under lowest supported frequency (400 MHz). "
542 "Increasing to 400 MHz as last resort.\n");
543 ctrl
->tCK
= TCK_400MHZ
;
550 /* Step 1 - Determine target MPLL frequency */
554 * The MPLL will never lock if the requested frequency is already set.
555 * Exit early to prevent a system hang.
557 reg1
= mchbar_read32(MC_BIOS_DATA
);
562 /* Step 2 - Request MPLL frequency through the PCU */
564 if (ctrl
->base_freq
== 100)
565 reg1
|= (1 << 8); /* Use 100MHz reference clock */
567 reg1
|= (1 << 31); /* Set running bit */
568 mchbar_write32(MC_BIOS_REQ
, reg1
);
570 printk(BIOS_DEBUG
, "MPLL busy... ");
571 while (reg1
& (1 << 31)) {
574 reg1
= mchbar_read32(MC_BIOS_REQ
);
576 printk(BIOS_DEBUG
, "done in %d us\n", i
* 10);
578 /* Step 3 - Verify lock frequency */
579 reg1
= mchbar_read32(MC_BIOS_DATA
);
581 if (val2
>= ctrl
->FRQ
) {
582 printk(BIOS_DEBUG
, "MPLL frequency is set at : %d MHz\n",
583 (1000 << 8) / ctrl
->tCK
);
586 printk(BIOS_DEBUG
, "MPLL didn't lock. Retrying at lower frequency\n");
591 static void dram_ioregs(ramctr_timing
*ctrl
)
597 mchbar_write32(GDCRCLKRANKSUSED_ch(channel
), ctrl
->rankmap
[channel
]);
602 mchbar_write32(GDCRCTLRANKSUSED_ch(channel
), ctrl
->rankmap
[channel
]);
606 FOR_ALL_POPULATED_CHANNELS
{
607 program_timings(ctrl
, channel
);
611 printram("RCOMP...");
612 while (!(mchbar_read32(RCOMP_TIMER
) & (1 << 16)))
618 mchbar_write32(CRCOMPOFST2
, get_COMP2(ctrl
));
619 printram("COMP2 done\n");
622 FOR_ALL_POPULATED_CHANNELS
{
623 mchbar_write32(CRCOMPOFST1_ch(channel
), get_COMP1(ctrl
, channel
));
625 printram("COMP1 done\n");
627 printram("FORCE RCOMP and wait 20us...");
628 mchbar_setbits32(M_COMP
, 1 << 8);
633 int try_init_dram_ddr3(ramctr_timing
*ctrl
, int fast_boot
, int s3resume
, int me_uma_size
)
637 printk(BIOS_DEBUG
, "Starting %s Bridge RAM training (%s).\n",
638 IS_SANDY_CPU(ctrl
->cpu
) ? "Sandy" : "Ivy",
639 fast_boot
? "fast boot" : "full initialization");
642 /* Find fastest common supported parameters */
643 dram_find_common_params(ctrl
);
645 dram_dimm_mapping(ctrl
);
648 /* Set MPLL frequency */
652 /* Calculate timings */
656 /* Set version register */
657 mchbar_write32(MRC_REVISION
, 0xc04eb002);
659 /* Enable crossover */
662 /* Set timing and refresh registers */
663 dram_timing_regs(ctrl
);
665 /* Power mode preset */
666 mchbar_write32(PM_THML_STAT
, 0x5500);
668 /* Set scheduler chicken bits */
669 mchbar_write32(SCHED_CBIT
, 0x10100005);
671 /* Set up watermarks and starvation counter */
672 set_wmm_behavior(ctrl
->cpu
);
674 /* Clear IO reset bit */
675 mchbar_clrbits32(MC_INIT_STATE_G
, 1 << 5);
677 /* Set MAD-DIMM registers */
678 dram_dimm_set_mapping(ctrl
, 1);
679 printk(BIOS_DEBUG
, "Done dimm mapping\n");
685 dram_memorymap(ctrl
, me_uma_size
);
686 printk(BIOS_DEBUG
, "Done memory map\n");
688 /* Set IO registers */
690 printk(BIOS_DEBUG
, "Done io registers\n");
695 restore_timings(ctrl
);
697 /* Do JEDEC DDR3 reset sequence */
698 dram_jedecreset(ctrl
);
699 printk(BIOS_DEBUG
, "Done jedec reset\n");
702 dram_mrscommands(ctrl
);
703 printk(BIOS_DEBUG
, "Done MRS commands\n");
705 /* Prepare for memory training */
706 prepare_training(ctrl
);
708 err
= receive_enable_calibration(ctrl
);
712 err
= read_mpr_training(ctrl
);
716 err
= write_training(ctrl
);
724 err
= command_training(ctrl
);
730 err
= aggressive_read_training(ctrl
);
734 err
= aggressive_write_training(ctrl
);
738 normalize_training(ctrl
);
741 set_read_write_timings(ctrl
);
744 err
= channel_test(ctrl
);
749 /* Set MAD-DIMM registers */
750 dram_dimm_set_mapping(ctrl
, 0);