aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/ast/ast_post.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/ast/ast_post.c')
-rw-r--r--drivers/gpu/drm/ast/ast_post.c902
1 files changed, 387 insertions, 515 deletions
diff --git a/drivers/gpu/drm/ast/ast_post.c b/drivers/gpu/drm/ast/ast_post.c
index 635f6ffc27c2..38d437f3a267 100644
--- a/drivers/gpu/drm/ast/ast_post.c
+++ b/drivers/gpu/drm/ast/ast_post.c
@@ -78,7 +78,7 @@ ast_set_def_ext_reg(struct drm_device *dev)
78 for (i = 0x81; i <= 0x8f; i++) 78 for (i = 0x81; i <= 0x8f; i++)
79 ast_set_index_reg(ast, AST_IO_CRTC_PORT, i, 0x00); 79 ast_set_index_reg(ast, AST_IO_CRTC_PORT, i, 0x00);
80 80
81 if (ast->chip == AST2300) { 81 if (ast->chip == AST2300 || ast->chip == AST2400) {
82 if (dev->pdev->revision >= 0x20) 82 if (dev->pdev->revision >= 0x20)
83 ext_reg_info = extreginfo_ast2300; 83 ext_reg_info = extreginfo_ast2300;
84 else 84 else
@@ -102,23 +102,32 @@ ast_set_def_ext_reg(struct drm_device *dev)
102 102
103 /* Enable RAMDAC for A1 */ 103 /* Enable RAMDAC for A1 */
104 reg = 0x04; 104 reg = 0x04;
105 if (ast->chip == AST2300) 105 if (ast->chip == AST2300 || ast->chip == AST2400)
106 reg |= 0x20; 106 reg |= 0x20;
107 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb6, 0xff, reg); 107 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb6, 0xff, reg);
108} 108}
109 109
110static inline u32 mindwm(struct ast_private *ast, u32 r) 110u32 ast_mindwm(struct ast_private *ast, u32 r)
111{ 111{
112 uint32_t data;
113
112 ast_write32(ast, 0xf004, r & 0xffff0000); 114 ast_write32(ast, 0xf004, r & 0xffff0000);
113 ast_write32(ast, 0xf000, 0x1); 115 ast_write32(ast, 0xf000, 0x1);
114 116
117 do {
118 data = ast_read32(ast, 0xf004) & 0xffff0000;
119 } while (data != (r & 0xffff0000));
115 return ast_read32(ast, 0x10000 + (r & 0x0000ffff)); 120 return ast_read32(ast, 0x10000 + (r & 0x0000ffff));
116} 121}
117 122
118static inline void moutdwm(struct ast_private *ast, u32 r, u32 v) 123void ast_moutdwm(struct ast_private *ast, u32 r, u32 v)
119{ 124{
125 uint32_t data;
120 ast_write32(ast, 0xf004, r & 0xffff0000); 126 ast_write32(ast, 0xf004, r & 0xffff0000);
121 ast_write32(ast, 0xf000, 0x1); 127 ast_write32(ast, 0xf000, 0x1);
128 do {
129 data = ast_read32(ast, 0xf004) & 0xffff0000;
130 } while (data != (r & 0xffff0000));
122 ast_write32(ast, 0x10000 + (r & 0x0000ffff), v); 131 ast_write32(ast, 0x10000 + (r & 0x0000ffff), v);
123} 132}
124 133
@@ -154,28 +163,28 @@ static u32 mmctestburst2_ast2150(struct ast_private *ast, u32 datagen)
154{ 163{
155 u32 data, timeout; 164 u32 data, timeout;
156 165
157 moutdwm(ast, 0x1e6e0070, 0x00000000); 166 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
158 moutdwm(ast, 0x1e6e0070, 0x00000001 | (datagen << 3)); 167 ast_moutdwm(ast, 0x1e6e0070, 0x00000001 | (datagen << 3));
159 timeout = 0; 168 timeout = 0;
160 do { 169 do {
161 data = mindwm(ast, 0x1e6e0070) & 0x40; 170 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
162 if (++timeout > TIMEOUT_AST2150) { 171 if (++timeout > TIMEOUT_AST2150) {
163 moutdwm(ast, 0x1e6e0070, 0x00000000); 172 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
164 return 0xffffffff; 173 return 0xffffffff;
165 } 174 }
166 } while (!data); 175 } while (!data);
167 moutdwm(ast, 0x1e6e0070, 0x00000000); 176 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
168 moutdwm(ast, 0x1e6e0070, 0x00000003 | (datagen << 3)); 177 ast_moutdwm(ast, 0x1e6e0070, 0x00000003 | (datagen << 3));
169 timeout = 0; 178 timeout = 0;
170 do { 179 do {
171 data = mindwm(ast, 0x1e6e0070) & 0x40; 180 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
172 if (++timeout > TIMEOUT_AST2150) { 181 if (++timeout > TIMEOUT_AST2150) {
173 moutdwm(ast, 0x1e6e0070, 0x00000000); 182 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
174 return 0xffffffff; 183 return 0xffffffff;
175 } 184 }
176 } while (!data); 185 } while (!data);
177 data = (mindwm(ast, 0x1e6e0070) & 0x80) >> 7; 186 data = (ast_mindwm(ast, 0x1e6e0070) & 0x80) >> 7;
178 moutdwm(ast, 0x1e6e0070, 0x00000000); 187 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
179 return data; 188 return data;
180} 189}
181 190
@@ -184,18 +193,18 @@ static u32 mmctestsingle2_ast2150(struct ast_private *ast, u32 datagen)
184{ 193{
185 u32 data, timeout; 194 u32 data, timeout;
186 195
187 moutdwm(ast, 0x1e6e0070, 0x00000000); 196 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
188 moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3)); 197 ast_moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3));
189 timeout = 0; 198 timeout = 0;
190 do { 199 do {
191 data = mindwm(ast, 0x1e6e0070) & 0x40; 200 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
192 if (++timeout > TIMEOUT_AST2150) { 201 if (++timeout > TIMEOUT_AST2150) {
193 moutdwm(ast, 0x1e6e0070, 0x00000000); 202 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
194 return 0xffffffff; 203 return 0xffffffff;
195 } 204 }
196 } while (!data); 205 } while (!data);
197 data = (mindwm(ast, 0x1e6e0070) & 0x80) >> 7; 206 data = (ast_mindwm(ast, 0x1e6e0070) & 0x80) >> 7;
198 moutdwm(ast, 0x1e6e0070, 0x00000000); 207 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
199 return data; 208 return data;
200} 209}
201#endif 210#endif
@@ -215,7 +224,7 @@ static int cbrscan_ast2150(struct ast_private *ast, int busw)
215 u32 patcnt, loop; 224 u32 patcnt, loop;
216 225
217 for (patcnt = 0; patcnt < CBR_PATNUM_AST2150; patcnt++) { 226 for (patcnt = 0; patcnt < CBR_PATNUM_AST2150; patcnt++) {
218 moutdwm(ast, 0x1e6e007c, pattern_AST2150[patcnt]); 227 ast_moutdwm(ast, 0x1e6e007c, pattern_AST2150[patcnt]);
219 for (loop = 0; loop < CBR_PASSNUM_AST2150; loop++) { 228 for (loop = 0; loop < CBR_PASSNUM_AST2150; loop++) {
220 if (cbrtest_ast2150(ast)) 229 if (cbrtest_ast2150(ast))
221 break; 230 break;
@@ -237,7 +246,7 @@ cbr_start:
237 passcnt = 0; 246 passcnt = 0;
238 247
239 for (dlli = 0; dlli < 100; dlli++) { 248 for (dlli = 0; dlli < 100; dlli++) {
240 moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24)); 249 ast_moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24));
241 data = cbrscan_ast2150(ast, busw); 250 data = cbrscan_ast2150(ast, busw);
242 if (data != 0) { 251 if (data != 0) {
243 if (data & 0x1) { 252 if (data & 0x1) {
@@ -254,7 +263,7 @@ cbr_start:
254 goto cbr_start; 263 goto cbr_start;
255 264
256 dlli = dll_min[0] + (((dll_max[0] - dll_min[0]) * 7) >> 4); 265 dlli = dll_min[0] + (((dll_max[0] - dll_min[0]) * 7) >> 4);
257 moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24)); 266 ast_moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24));
258} 267}
259 268
260 269
@@ -365,10 +374,12 @@ void ast_post_gpu(struct drm_device *dev)
365 ast_open_key(ast); 374 ast_open_key(ast);
366 ast_set_def_ext_reg(dev); 375 ast_set_def_ext_reg(dev);
367 376
368 if (ast->chip == AST2300) 377 if (ast->chip == AST2300 || ast->chip == AST2400)
369 ast_init_dram_2300(dev); 378 ast_init_dram_2300(dev);
370 else 379 else
371 ast_init_dram_reg(dev); 380 ast_init_dram_reg(dev);
381
382 ast_init_3rdtx(dev);
372} 383}
373 384
374/* AST 2300 DRAM settings */ 385/* AST 2300 DRAM settings */
@@ -403,6 +414,7 @@ struct ast2300_dram_param {
403/* 414/*
404 * DQSI DLL CBR Setting 415 * DQSI DLL CBR Setting
405 */ 416 */
417#define CBR_SIZE0 ((1 << 10) - 1)
406#define CBR_SIZE1 ((4 << 10) - 1) 418#define CBR_SIZE1 ((4 << 10) - 1)
407#define CBR_SIZE2 ((64 << 10) - 1) 419#define CBR_SIZE2 ((64 << 10) - 1)
408#define CBR_PASSNUM 5 420#define CBR_PASSNUM 5
@@ -423,88 +435,84 @@ static const u32 pattern[8] = {
423 0x7C61D253 435 0x7C61D253
424}; 436};
425 437
426#if 0 /* unused in DDX, included for completeness */
427static int mmc_test_burst(struct ast_private *ast, u32 datagen) 438static int mmc_test_burst(struct ast_private *ast, u32 datagen)
428{ 439{
429 u32 data, timeout; 440 u32 data, timeout;
430 441
431 moutdwm(ast, 0x1e6e0070, 0x00000000); 442 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
432 moutdwm(ast, 0x1e6e0070, 0x000000c1 | (datagen << 3)); 443 ast_moutdwm(ast, 0x1e6e0070, 0x000000c1 | (datagen << 3));
433 timeout = 0; 444 timeout = 0;
434 do { 445 do {
435 data = mindwm(ast, 0x1e6e0070) & 0x3000; 446 data = ast_mindwm(ast, 0x1e6e0070) & 0x3000;
436 if (data & 0x2000) { 447 if (data & 0x2000) {
437 return 0; 448 return 0;
438 } 449 }
439 if (++timeout > TIMEOUT) { 450 if (++timeout > TIMEOUT) {
440 moutdwm(ast, 0x1e6e0070, 0x00000000); 451 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
441 return 0; 452 return 0;
442 } 453 }
443 } while (!data); 454 } while (!data);
444 moutdwm(ast, 0x1e6e0070, 0x00000000); 455 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
445 return 1; 456 return 1;
446} 457}
447#endif
448 458
449static int mmc_test_burst2(struct ast_private *ast, u32 datagen) 459static int mmc_test_burst2(struct ast_private *ast, u32 datagen)
450{ 460{
451 u32 data, timeout; 461 u32 data, timeout;
452 462
453 moutdwm(ast, 0x1e6e0070, 0x00000000); 463 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
454 moutdwm(ast, 0x1e6e0070, 0x00000041 | (datagen << 3)); 464 ast_moutdwm(ast, 0x1e6e0070, 0x00000041 | (datagen << 3));
455 timeout = 0; 465 timeout = 0;
456 do { 466 do {
457 data = mindwm(ast, 0x1e6e0070) & 0x1000; 467 data = ast_mindwm(ast, 0x1e6e0070) & 0x1000;
458 if (++timeout > TIMEOUT) { 468 if (++timeout > TIMEOUT) {
459 moutdwm(ast, 0x1e6e0070, 0x0); 469 ast_moutdwm(ast, 0x1e6e0070, 0x0);
460 return -1; 470 return -1;
461 } 471 }
462 } while (!data); 472 } while (!data);
463 data = mindwm(ast, 0x1e6e0078); 473 data = ast_mindwm(ast, 0x1e6e0078);
464 data = (data | (data >> 16)) & 0xffff; 474 data = (data | (data >> 16)) & 0xffff;
465 moutdwm(ast, 0x1e6e0070, 0x0); 475 ast_moutdwm(ast, 0x1e6e0070, 0x0);
466 return data; 476 return data;
467} 477}
468 478
469#if 0 /* Unused in DDX here for completeness */
470static int mmc_test_single(struct ast_private *ast, u32 datagen) 479static int mmc_test_single(struct ast_private *ast, u32 datagen)
471{ 480{
472 u32 data, timeout; 481 u32 data, timeout;
473 482
474 moutdwm(ast, 0x1e6e0070, 0x00000000); 483 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
475 moutdwm(ast, 0x1e6e0070, 0x000000c5 | (datagen << 3)); 484 ast_moutdwm(ast, 0x1e6e0070, 0x000000c5 | (datagen << 3));
476 timeout = 0; 485 timeout = 0;
477 do { 486 do {
478 data = mindwm(ast, 0x1e6e0070) & 0x3000; 487 data = ast_mindwm(ast, 0x1e6e0070) & 0x3000;
479 if (data & 0x2000) 488 if (data & 0x2000)
480 return 0; 489 return 0;
481 if (++timeout > TIMEOUT) { 490 if (++timeout > TIMEOUT) {
482 moutdwm(ast, 0x1e6e0070, 0x0); 491 ast_moutdwm(ast, 0x1e6e0070, 0x0);
483 return 0; 492 return 0;
484 } 493 }
485 } while (!data); 494 } while (!data);
486 moutdwm(ast, 0x1e6e0070, 0x0); 495 ast_moutdwm(ast, 0x1e6e0070, 0x0);
487 return 1; 496 return 1;
488} 497}
489#endif
490 498
491static int mmc_test_single2(struct ast_private *ast, u32 datagen) 499static int mmc_test_single2(struct ast_private *ast, u32 datagen)
492{ 500{
493 u32 data, timeout; 501 u32 data, timeout;
494 502
495 moutdwm(ast, 0x1e6e0070, 0x00000000); 503 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
496 moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3)); 504 ast_moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3));
497 timeout = 0; 505 timeout = 0;
498 do { 506 do {
499 data = mindwm(ast, 0x1e6e0070) & 0x1000; 507 data = ast_mindwm(ast, 0x1e6e0070) & 0x1000;
500 if (++timeout > TIMEOUT) { 508 if (++timeout > TIMEOUT) {
501 moutdwm(ast, 0x1e6e0070, 0x0); 509 ast_moutdwm(ast, 0x1e6e0070, 0x0);
502 return -1; 510 return -1;
503 } 511 }
504 } while (!data); 512 } while (!data);
505 data = mindwm(ast, 0x1e6e0078); 513 data = ast_mindwm(ast, 0x1e6e0078);
506 data = (data | (data >> 16)) & 0xffff; 514 data = (data | (data >> 16)) & 0xffff;
507 moutdwm(ast, 0x1e6e0070, 0x0); 515 ast_moutdwm(ast, 0x1e6e0070, 0x0);
508 return data; 516 return data;
509} 517}
510 518
@@ -533,7 +541,7 @@ static int cbr_scan(struct ast_private *ast)
533 541
534 data2 = 3; 542 data2 = 3;
535 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) { 543 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
536 moutdwm(ast, 0x1e6e007c, pattern[patcnt]); 544 ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
537 for (loop = 0; loop < CBR_PASSNUM2; loop++) { 545 for (loop = 0; loop < CBR_PASSNUM2; loop++) {
538 if ((data = cbr_test(ast)) != 0) { 546 if ((data = cbr_test(ast)) != 0) {
539 data2 &= data; 547 data2 &= data;
@@ -568,7 +576,7 @@ static u32 cbr_scan2(struct ast_private *ast)
568 576
569 data2 = 0xffff; 577 data2 = 0xffff;
570 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) { 578 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
571 moutdwm(ast, 0x1e6e007c, pattern[patcnt]); 579 ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
572 for (loop = 0; loop < CBR_PASSNUM2; loop++) { 580 for (loop = 0; loop < CBR_PASSNUM2; loop++) {
573 if ((data = cbr_test2(ast)) != 0) { 581 if ((data = cbr_test2(ast)) != 0) {
574 data2 &= data; 582 data2 &= data;
@@ -583,106 +591,35 @@ static u32 cbr_scan2(struct ast_private *ast)
583 return data2; 591 return data2;
584} 592}
585 593
586#if 0 /* unused in DDX - added for completeness */ 594static u32 cbr_test3(struct ast_private *ast)
587static void finetuneDQI(struct ast_private *ast, struct ast2300_dram_param *param)
588{ 595{
589 u32 gold_sadj[2], dllmin[16], dllmax[16], dlli, data, cnt, mask, passcnt; 596 if (!mmc_test_burst(ast, 0))
590 597 return 0;
591 gold_sadj[0] = (mindwm(ast, 0x1E6E0024) >> 16) & 0xffff; 598 if (!mmc_test_single(ast, 0))
592 gold_sadj[1] = gold_sadj[0] >> 8; 599 return 0;
593 gold_sadj[0] = gold_sadj[0] & 0xff; 600 return 1;
594 gold_sadj[0] = (gold_sadj[0] + gold_sadj[1]) >> 1; 601}
595 gold_sadj[1] = gold_sadj[0];
596
597 for (cnt = 0; cnt < 16; cnt++) {
598 dllmin[cnt] = 0xff;
599 dllmax[cnt] = 0x0;
600 }
601 passcnt = 0;
602 for (dlli = 0; dlli < 76; dlli++) {
603 moutdwm(ast, 0x1E6E0068, 0x00001400 | (dlli << 16) | (dlli << 24));
604 /* Wait DQSI latch phase calibration */
605 moutdwm(ast, 0x1E6E0074, 0x00000010);
606 moutdwm(ast, 0x1E6E0070, 0x00000003);
607 do {
608 data = mindwm(ast, 0x1E6E0070);
609 } while (!(data & 0x00001000));
610 moutdwm(ast, 0x1E6E0070, 0x00000000);
611 602
612 moutdwm(ast, 0x1E6E0074, CBR_SIZE1); 603static u32 cbr_scan3(struct ast_private *ast)
613 data = cbr_scan2(ast); 604{
614 if (data != 0) { 605 u32 patcnt, loop;
615 mask = 0x00010001;
616 for (cnt = 0; cnt < 16; cnt++) {
617 if (data & mask) {
618 if (dllmin[cnt] > dlli) {
619 dllmin[cnt] = dlli;
620 }
621 if (dllmax[cnt] < dlli) {
622 dllmax[cnt] = dlli;
623 }
624 }
625 mask <<= 1;
626 }
627 passcnt++;
628 } else if (passcnt >= CBR_THRESHOLD) {
629 break;
630 }
631 }
632 data = 0;
633 for (cnt = 0; cnt < 8; cnt++) {
634 data >>= 3;
635 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD)) {
636 dlli = (dllmin[cnt] + dllmax[cnt]) >> 1;
637 if (gold_sadj[0] >= dlli) {
638 dlli = (gold_sadj[0] - dlli) >> 1;
639 if (dlli > 3) {
640 dlli = 3;
641 }
642 } else {
643 dlli = (dlli - gold_sadj[0]) >> 1;
644 if (dlli > 4) {
645 dlli = 4;
646 }
647 dlli = (8 - dlli) & 0x7;
648 }
649 data |= dlli << 21;
650 }
651 }
652 moutdwm(ast, 0x1E6E0080, data);
653 606
654 data = 0; 607 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
655 for (cnt = 8; cnt < 16; cnt++) { 608 ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
656 data >>= 3; 609 for (loop = 0; loop < 2; loop++) {
657 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD)) { 610 if (cbr_test3(ast))
658 dlli = (dllmin[cnt] + dllmax[cnt]) >> 1; 611 break;
659 if (gold_sadj[1] >= dlli) {
660 dlli = (gold_sadj[1] - dlli) >> 1;
661 if (dlli > 3) {
662 dlli = 3;
663 } else {
664 dlli = (dlli - 1) & 0x7;
665 }
666 } else {
667 dlli = (dlli - gold_sadj[1]) >> 1;
668 dlli += 1;
669 if (dlli > 4) {
670 dlli = 4;
671 }
672 dlli = (8 - dlli) & 0x7;
673 }
674 data |= dlli << 21;
675 } 612 }
613 if (loop == 2)
614 return 0;
676 } 615 }
677 moutdwm(ast, 0x1E6E0084, data); 616 return 1;
678 617}
679} /* finetuneDQI */
680#endif
681 618
682static void finetuneDQI_L(struct ast_private *ast, struct ast2300_dram_param *param) 619static bool finetuneDQI_L(struct ast_private *ast, struct ast2300_dram_param *param)
683{ 620{
684 u32 gold_sadj[2], dllmin[16], dllmax[16], dlli, data, cnt, mask, passcnt; 621 u32 gold_sadj[2], dllmin[16], dllmax[16], dlli, data, cnt, mask, passcnt, retry = 0;
685 622 bool status = false;
686FINETUNE_START: 623FINETUNE_START:
687 for (cnt = 0; cnt < 16; cnt++) { 624 for (cnt = 0; cnt < 16; cnt++) {
688 dllmin[cnt] = 0xff; 625 dllmin[cnt] = 0xff;
@@ -690,16 +627,8 @@ FINETUNE_START:
690 } 627 }
691 passcnt = 0; 628 passcnt = 0;
692 for (dlli = 0; dlli < 76; dlli++) { 629 for (dlli = 0; dlli < 76; dlli++) {
693 moutdwm(ast, 0x1E6E0068, 0x00001400 | (dlli << 16) | (dlli << 24)); 630 ast_moutdwm(ast, 0x1E6E0068, 0x00001400 | (dlli << 16) | (dlli << 24));
694 /* Wait DQSI latch phase calibration */ 631 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE1);
695 moutdwm(ast, 0x1E6E0074, 0x00000010);
696 moutdwm(ast, 0x1E6E0070, 0x00000003);
697 do {
698 data = mindwm(ast, 0x1E6E0070);
699 } while (!(data & 0x00001000));
700 moutdwm(ast, 0x1E6E0070, 0x00000000);
701
702 moutdwm(ast, 0x1E6E0074, CBR_SIZE1);
703 data = cbr_scan2(ast); 632 data = cbr_scan2(ast);
704 if (data != 0) { 633 if (data != 0) {
705 mask = 0x00010001; 634 mask = 0x00010001;
@@ -727,9 +656,13 @@ FINETUNE_START:
727 passcnt++; 656 passcnt++;
728 } 657 }
729 } 658 }
659 if (retry++ > 10)
660 goto FINETUNE_DONE;
730 if (passcnt != 16) { 661 if (passcnt != 16) {
731 goto FINETUNE_START; 662 goto FINETUNE_START;
732 } 663 }
664 status = true;
665FINETUNE_DONE:
733 gold_sadj[0] = gold_sadj[0] >> 4; 666 gold_sadj[0] = gold_sadj[0] >> 4;
734 gold_sadj[1] = gold_sadj[0]; 667 gold_sadj[1] = gold_sadj[0];
735 668
@@ -753,7 +686,7 @@ FINETUNE_START:
753 data |= dlli << 21; 686 data |= dlli << 21;
754 } 687 }
755 } 688 }
756 moutdwm(ast, 0x1E6E0080, data); 689 ast_moutdwm(ast, 0x1E6E0080, data);
757 690
758 data = 0; 691 data = 0;
759 for (cnt = 8; cnt < 16; cnt++) { 692 for (cnt = 8; cnt < 16; cnt++) {
@@ -778,162 +711,116 @@ FINETUNE_START:
778 data |= dlli << 21; 711 data |= dlli << 21;
779 } 712 }
780 } 713 }
781 moutdwm(ast, 0x1E6E0084, data); 714 ast_moutdwm(ast, 0x1E6E0084, data);
782 715 return status;
783} /* finetuneDQI_L */ 716} /* finetuneDQI_L */
784 717
785static void finetuneDQI_L2(struct ast_private *ast, struct ast2300_dram_param *param) 718static void finetuneDQSI(struct ast_private *ast)
786{ 719{
787 u32 gold_sadj[2], dllmin[16], dllmax[16], dlli, data, cnt, mask, passcnt, data2; 720 u32 dlli, dqsip, dqidly;
721 u32 reg_mcr18, reg_mcr0c, passcnt[2], diff;
722 u32 g_dqidly, g_dqsip, g_margin, g_side;
723 u16 pass[32][2][2];
724 char tag[2][76];
725
726 /* Disable DQI CBR */
727 reg_mcr0c = ast_mindwm(ast, 0x1E6E000C);
728 reg_mcr18 = ast_mindwm(ast, 0x1E6E0018);
729 reg_mcr18 &= 0x0000ffff;
730 ast_moutdwm(ast, 0x1E6E0018, reg_mcr18);
788 731
789 for (cnt = 0; cnt < 16; cnt++) {
790 dllmin[cnt] = 0xff;
791 dllmax[cnt] = 0x0;
792 }
793 passcnt = 0;
794 for (dlli = 0; dlli < 76; dlli++) { 732 for (dlli = 0; dlli < 76; dlli++) {
795 moutdwm(ast, 0x1E6E0068, 0x00001400 | (dlli << 16) | (dlli << 24)); 733 tag[0][dlli] = 0x0;
796 /* Wait DQSI latch phase calibration */ 734 tag[1][dlli] = 0x0;
797 moutdwm(ast, 0x1E6E0074, 0x00000010);
798 moutdwm(ast, 0x1E6E0070, 0x00000003);
799 do {
800 data = mindwm(ast, 0x1E6E0070);
801 } while (!(data & 0x00001000));
802 moutdwm(ast, 0x1E6E0070, 0x00000000);
803
804 moutdwm(ast, 0x1E6E0074, CBR_SIZE2);
805 data = cbr_scan2(ast);
806 if (data != 0) {
807 mask = 0x00010001;
808 for (cnt = 0; cnt < 16; cnt++) {
809 if (data & mask) {
810 if (dllmin[cnt] > dlli) {
811 dllmin[cnt] = dlli;
812 }
813 if (dllmax[cnt] < dlli) {
814 dllmax[cnt] = dlli;
815 }
816 }
817 mask <<= 1;
818 }
819 passcnt++;
820 } else if (passcnt >= CBR_THRESHOLD2) {
821 break;
822 }
823 } 735 }
824 gold_sadj[0] = 0x0; 736 for (dqidly = 0; dqidly < 32; dqidly++) {
825 gold_sadj[1] = 0xFF; 737 pass[dqidly][0][0] = 0xff;
826 for (cnt = 0; cnt < 8; cnt++) { 738 pass[dqidly][0][1] = 0x0;
827 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) { 739 pass[dqidly][1][0] = 0xff;
828 if (gold_sadj[0] < dllmin[cnt]) { 740 pass[dqidly][1][1] = 0x0;
829 gold_sadj[0] = dllmin[cnt];
830 }
831 if (gold_sadj[1] > dllmax[cnt]) {
832 gold_sadj[1] = dllmax[cnt];
833 }
834 }
835 } 741 }
836 gold_sadj[0] = (gold_sadj[1] + gold_sadj[0]) >> 1; 742 for (dqidly = 0; dqidly < 32; dqidly++) {
837 gold_sadj[1] = mindwm(ast, 0x1E6E0080); 743 passcnt[0] = passcnt[1] = 0;
838 744 for (dqsip = 0; dqsip < 2; dqsip++) {
839 data = 0; 745 ast_moutdwm(ast, 0x1E6E000C, 0);
840 for (cnt = 0; cnt < 8; cnt++) { 746 ast_moutdwm(ast, 0x1E6E0018, reg_mcr18 | (dqidly << 16) | (dqsip << 23));
841 data >>= 3; 747 ast_moutdwm(ast, 0x1E6E000C, reg_mcr0c);
842 data2 = gold_sadj[1] & 0x7; 748 for (dlli = 0; dlli < 76; dlli++) {
843 gold_sadj[1] >>= 3; 749 ast_moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24));
844 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) { 750 ast_moutdwm(ast, 0x1E6E0070, 0);
845 dlli = (dllmin[cnt] + dllmax[cnt]) >> 1; 751 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE0);
846 if (gold_sadj[0] >= dlli) { 752 if (cbr_scan3(ast)) {
847 dlli = (gold_sadj[0] - dlli) >> 1; 753 if (dlli == 0)
848 if (dlli > 0) { 754 break;
849 dlli = 1; 755 passcnt[dqsip]++;
850 } 756 tag[dqsip][dlli] = 'P';
851 if (data2 != 3) { 757 if (dlli < pass[dqidly][dqsip][0])
852 data2 = (data2 + dlli) & 0x7; 758 pass[dqidly][dqsip][0] = (u16) dlli;
853 } 759 if (dlli > pass[dqidly][dqsip][1])
854 } else { 760 pass[dqidly][dqsip][1] = (u16) dlli;
855 dlli = (dlli - gold_sadj[0]) >> 1; 761 } else if (passcnt[dqsip] >= 5)
856 if (dlli > 0) { 762 break;
857 dlli = 1; 763 else {
858 } 764 pass[dqidly][dqsip][0] = 0xff;
859 if (data2 != 4) { 765 pass[dqidly][dqsip][1] = 0x0;
860 data2 = (data2 - dlli) & 0x7;
861 } 766 }
862 } 767 }
863 } 768 }
864 data |= data2 << 21; 769 if (passcnt[0] == 0 && passcnt[1] == 0)
865 } 770 dqidly++;
866 moutdwm(ast, 0x1E6E0080, data);
867
868 gold_sadj[0] = 0x0;
869 gold_sadj[1] = 0xFF;
870 for (cnt = 8; cnt < 16; cnt++) {
871 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
872 if (gold_sadj[0] < dllmin[cnt]) {
873 gold_sadj[0] = dllmin[cnt];
874 }
875 if (gold_sadj[1] > dllmax[cnt]) {
876 gold_sadj[1] = dllmax[cnt];
877 }
878 }
879 } 771 }
880 gold_sadj[0] = (gold_sadj[1] + gold_sadj[0]) >> 1; 772 /* Search margin */
881 gold_sadj[1] = mindwm(ast, 0x1E6E0084); 773 g_dqidly = g_dqsip = g_margin = g_side = 0;
882 774
883 data = 0; 775 for (dqidly = 0; dqidly < 32; dqidly++) {
884 for (cnt = 8; cnt < 16; cnt++) { 776 for (dqsip = 0; dqsip < 2; dqsip++) {
885 data >>= 3; 777 if (pass[dqidly][dqsip][0] > pass[dqidly][dqsip][1])
886 data2 = gold_sadj[1] & 0x7; 778 continue;
887 gold_sadj[1] >>= 3; 779 diff = pass[dqidly][dqsip][1] - pass[dqidly][dqsip][0];
888 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) { 780 if ((diff+2) < g_margin)
889 dlli = (dllmin[cnt] + dllmax[cnt]) >> 1; 781 continue;
890 if (gold_sadj[0] >= dlli) { 782 passcnt[0] = passcnt[1] = 0;
891 dlli = (gold_sadj[0] - dlli) >> 1; 783 for (dlli = pass[dqidly][dqsip][0]; dlli > 0 && tag[dqsip][dlli] != 0; dlli--, passcnt[0]++);
892 if (dlli > 0) { 784 for (dlli = pass[dqidly][dqsip][1]; dlli < 76 && tag[dqsip][dlli] != 0; dlli++, passcnt[1]++);
893 dlli = 1; 785 if (passcnt[0] > passcnt[1])
894 } 786 passcnt[0] = passcnt[1];
895 if (data2 != 3) { 787 passcnt[1] = 0;
896 data2 = (data2 + dlli) & 0x7; 788 if (passcnt[0] > g_side)
897 } 789 passcnt[1] = passcnt[0] - g_side;
898 } else { 790 if (diff > (g_margin+1) && (passcnt[1] > 0 || passcnt[0] > 8)) {
899 dlli = (dlli - gold_sadj[0]) >> 1; 791 g_margin = diff;
900 if (dlli > 0) { 792 g_dqidly = dqidly;
901 dlli = 1; 793 g_dqsip = dqsip;
902 } 794 g_side = passcnt[0];
903 if (data2 != 4) { 795 } else if (passcnt[1] > 1 && g_side < 8) {
904 data2 = (data2 - dlli) & 0x7; 796 if (diff > g_margin)
905 } 797 g_margin = diff;
798 g_dqidly = dqidly;
799 g_dqsip = dqsip;
800 g_side = passcnt[0];
906 } 801 }
907 } 802 }
908 data |= data2 << 21;
909 } 803 }
910 moutdwm(ast, 0x1E6E0084, data); 804 reg_mcr18 = reg_mcr18 | (g_dqidly << 16) | (g_dqsip << 23);
911 805 ast_moutdwm(ast, 0x1E6E0018, reg_mcr18);
912} /* finetuneDQI_L2 */
913 806
914static void cbr_dll2(struct ast_private *ast, struct ast2300_dram_param *param) 807}
808static bool cbr_dll2(struct ast_private *ast, struct ast2300_dram_param *param)
915{ 809{
916 u32 dllmin[2], dllmax[2], dlli, data, data2, passcnt; 810 u32 dllmin[2], dllmax[2], dlli, data, passcnt, retry = 0;
811 bool status = false;
917 812
918 813 finetuneDQSI(ast);
919 finetuneDQI_L(ast, param); 814 if (finetuneDQI_L(ast, param) == false)
920 finetuneDQI_L2(ast, param); 815 return status;
921 816
922CBR_START2: 817CBR_START2:
923 dllmin[0] = dllmin[1] = 0xff; 818 dllmin[0] = dllmin[1] = 0xff;
924 dllmax[0] = dllmax[1] = 0x0; 819 dllmax[0] = dllmax[1] = 0x0;
925 passcnt = 0; 820 passcnt = 0;
926 for (dlli = 0; dlli < 76; dlli++) { 821 for (dlli = 0; dlli < 76; dlli++) {
927 moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24)); 822 ast_moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24));
928 /* Wait DQSI latch phase calibration */ 823 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE2);
929 moutdwm(ast, 0x1E6E0074, 0x00000010);
930 moutdwm(ast, 0x1E6E0070, 0x00000003);
931 do {
932 data = mindwm(ast, 0x1E6E0070);
933 } while (!(data & 0x00001000));
934 moutdwm(ast, 0x1E6E0070, 0x00000000);
935
936 moutdwm(ast, 0x1E6E0074, CBR_SIZE2);
937 data = cbr_scan(ast); 824 data = cbr_scan(ast);
938 if (data != 0) { 825 if (data != 0) {
939 if (data & 0x1) { 826 if (data & 0x1) {
@@ -957,44 +844,31 @@ CBR_START2:
957 break; 844 break;
958 } 845 }
959 } 846 }
847 if (retry++ > 10)
848 goto CBR_DONE2;
960 if (dllmax[0] == 0 || (dllmax[0]-dllmin[0]) < CBR_THRESHOLD) { 849 if (dllmax[0] == 0 || (dllmax[0]-dllmin[0]) < CBR_THRESHOLD) {
961 goto CBR_START2; 850 goto CBR_START2;
962 } 851 }
963 if (dllmax[1] == 0 || (dllmax[1]-dllmin[1]) < CBR_THRESHOLD) { 852 if (dllmax[1] == 0 || (dllmax[1]-dllmin[1]) < CBR_THRESHOLD) {
964 goto CBR_START2; 853 goto CBR_START2;
965 } 854 }
855 status = true;
856CBR_DONE2:
966 dlli = (dllmin[1] + dllmax[1]) >> 1; 857 dlli = (dllmin[1] + dllmax[1]) >> 1;
967 dlli <<= 8; 858 dlli <<= 8;
968 dlli += (dllmin[0] + dllmax[0]) >> 1; 859 dlli += (dllmin[0] + dllmax[0]) >> 1;
969 moutdwm(ast, 0x1E6E0068, (mindwm(ast, 0x1E6E0068) & 0xFFFF) | (dlli << 16)); 860 ast_moutdwm(ast, 0x1E6E0068, ast_mindwm(ast, 0x1E720058) | (dlli << 16));
970 861 return status;
971 data = (mindwm(ast, 0x1E6E0080) >> 24) & 0x1F;
972 data2 = (mindwm(ast, 0x1E6E0018) & 0xff80ffff) | (data << 16);
973 moutdwm(ast, 0x1E6E0018, data2);
974 moutdwm(ast, 0x1E6E0024, 0x8001 | (data << 1) | (param->dll2_finetune_step << 8));
975
976 /* Wait DQSI latch phase calibration */
977 moutdwm(ast, 0x1E6E0074, 0x00000010);
978 moutdwm(ast, 0x1E6E0070, 0x00000003);
979 do {
980 data = mindwm(ast, 0x1E6E0070);
981 } while (!(data & 0x00001000));
982 moutdwm(ast, 0x1E6E0070, 0x00000000);
983 moutdwm(ast, 0x1E6E0070, 0x00000003);
984 do {
985 data = mindwm(ast, 0x1E6E0070);
986 } while (!(data & 0x00001000));
987 moutdwm(ast, 0x1E6E0070, 0x00000000);
988} /* CBRDLL2 */ 862} /* CBRDLL2 */
989 863
990static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *param) 864static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *param)
991{ 865{
992 u32 trap, trap_AC2, trap_MRS; 866 u32 trap, trap_AC2, trap_MRS;
993 867
994 moutdwm(ast, 0x1E6E2000, 0x1688A8A8); 868 ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
995 869
996 /* Ger trap info */ 870 /* Ger trap info */
997 trap = (mindwm(ast, 0x1E6E2070) >> 25) & 0x3; 871 trap = (ast_mindwm(ast, 0x1E6E2070) >> 25) & 0x3;
998 trap_AC2 = 0x00020000 + (trap << 16); 872 trap_AC2 = 0x00020000 + (trap << 16);
999 trap_AC2 |= 0x00300000 + ((trap & 0x2) << 19); 873 trap_AC2 |= 0x00300000 + ((trap & 0x2) << 19);
1000 trap_MRS = 0x00000010 + (trap << 4); 874 trap_MRS = 0x00000010 + (trap << 4);
@@ -1008,22 +882,35 @@ static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *pa
1008 882
1009 switch (param->dram_freq) { 883 switch (param->dram_freq) {
1010 case 336: 884 case 336:
1011 moutdwm(ast, 0x1E6E2020, 0x0190); 885 ast_moutdwm(ast, 0x1E6E2020, 0x0190);
1012 param->wodt = 0; 886 param->wodt = 0;
1013 param->reg_AC1 = 0x22202725; 887 param->reg_AC1 = 0x22202725;
1014 param->reg_AC2 = 0xAA007613 | trap_AC2; 888 param->reg_AC2 = 0xAA007613 | trap_AC2;
1015 param->reg_DQSIC = 0x000000BA; 889 param->reg_DQSIC = 0x000000BA;
1016 param->reg_MRS = 0x04001400 | trap_MRS; 890 param->reg_MRS = 0x04001400 | trap_MRS;
1017 param->reg_EMRS = 0x00000000; 891 param->reg_EMRS = 0x00000000;
1018 param->reg_IOZ = 0x00000034; 892 param->reg_IOZ = 0x00000023;
1019 param->reg_DQIDLY = 0x00000074; 893 param->reg_DQIDLY = 0x00000074;
1020 param->reg_FREQ = 0x00004DC0; 894 param->reg_FREQ = 0x00004DC0;
1021 param->madj_max = 96; 895 param->madj_max = 96;
1022 param->dll2_finetune_step = 3; 896 param->dll2_finetune_step = 3;
897 switch (param->dram_chipid) {
898 default:
899 case AST_DRAM_512Mx16:
900 case AST_DRAM_1Gx16:
901 param->reg_AC2 = 0xAA007613 | trap_AC2;
902 break;
903 case AST_DRAM_2Gx16:
904 param->reg_AC2 = 0xAA00761C | trap_AC2;
905 break;
906 case AST_DRAM_4Gx16:
907 param->reg_AC2 = 0xAA007636 | trap_AC2;
908 break;
909 }
1023 break; 910 break;
1024 default: 911 default:
1025 case 396: 912 case 396:
1026 moutdwm(ast, 0x1E6E2020, 0x03F1); 913 ast_moutdwm(ast, 0x1E6E2020, 0x03F1);
1027 param->wodt = 1; 914 param->wodt = 1;
1028 param->reg_AC1 = 0x33302825; 915 param->reg_AC1 = 0x33302825;
1029 param->reg_AC2 = 0xCC009617 | trap_AC2; 916 param->reg_AC2 = 0xCC009617 | trap_AC2;
@@ -1033,7 +920,7 @@ static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *pa
1033 param->reg_IOZ = 0x00000034; 920 param->reg_IOZ = 0x00000034;
1034 param->reg_DRV = 0x000000FA; 921 param->reg_DRV = 0x000000FA;
1035 param->reg_DQIDLY = 0x00000089; 922 param->reg_DQIDLY = 0x00000089;
1036 param->reg_FREQ = 0x000050C0; 923 param->reg_FREQ = 0x00005040;
1037 param->madj_max = 96; 924 param->madj_max = 96;
1038 param->dll2_finetune_step = 4; 925 param->dll2_finetune_step = 4;
1039 926
@@ -1053,14 +940,14 @@ static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *pa
1053 break; 940 break;
1054 941
1055 case 408: 942 case 408:
1056 moutdwm(ast, 0x1E6E2020, 0x01F0); 943 ast_moutdwm(ast, 0x1E6E2020, 0x01F0);
1057 param->wodt = 1; 944 param->wodt = 1;
1058 param->reg_AC1 = 0x33302825; 945 param->reg_AC1 = 0x33302825;
1059 param->reg_AC2 = 0xCC009617 | trap_AC2; 946 param->reg_AC2 = 0xCC009617 | trap_AC2;
1060 param->reg_DQSIC = 0x000000E2; 947 param->reg_DQSIC = 0x000000E2;
1061 param->reg_MRS = 0x04001600 | trap_MRS; 948 param->reg_MRS = 0x04001600 | trap_MRS;
1062 param->reg_EMRS = 0x00000000; 949 param->reg_EMRS = 0x00000000;
1063 param->reg_IOZ = 0x00000034; 950 param->reg_IOZ = 0x00000023;
1064 param->reg_DRV = 0x000000FA; 951 param->reg_DRV = 0x000000FA;
1065 param->reg_DQIDLY = 0x00000089; 952 param->reg_DQIDLY = 0x00000089;
1066 param->reg_FREQ = 0x000050C0; 953 param->reg_FREQ = 0x000050C0;
@@ -1083,7 +970,7 @@ static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *pa
1083 970
1084 break; 971 break;
1085 case 456: 972 case 456:
1086 moutdwm(ast, 0x1E6E2020, 0x0230); 973 ast_moutdwm(ast, 0x1E6E2020, 0x0230);
1087 param->wodt = 0; 974 param->wodt = 0;
1088 param->reg_AC1 = 0x33302926; 975 param->reg_AC1 = 0x33302926;
1089 param->reg_AC2 = 0xCD44961A; 976 param->reg_AC2 = 0xCD44961A;
@@ -1097,7 +984,7 @@ static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *pa
1097 param->dll2_finetune_step = 4; 984 param->dll2_finetune_step = 4;
1098 break; 985 break;
1099 case 504: 986 case 504:
1100 moutdwm(ast, 0x1E6E2020, 0x0270); 987 ast_moutdwm(ast, 0x1E6E2020, 0x0270);
1101 param->wodt = 1; 988 param->wodt = 1;
1102 param->reg_AC1 = 0x33302926; 989 param->reg_AC1 = 0x33302926;
1103 param->reg_AC2 = 0xDE44A61D; 990 param->reg_AC2 = 0xDE44A61D;
@@ -1111,7 +998,7 @@ static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *pa
1111 param->dll2_finetune_step = 4; 998 param->dll2_finetune_step = 4;
1112 break; 999 break;
1113 case 528: 1000 case 528:
1114 moutdwm(ast, 0x1E6E2020, 0x0290); 1001 ast_moutdwm(ast, 0x1E6E2020, 0x0290);
1115 param->wodt = 1; 1002 param->wodt = 1;
1116 param->rodt = 1; 1003 param->rodt = 1;
1117 param->reg_AC1 = 0x33302926; 1004 param->reg_AC1 = 0x33302926;
@@ -1127,7 +1014,7 @@ static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *pa
1127 param->dll2_finetune_step = 3; 1014 param->dll2_finetune_step = 3;
1128 break; 1015 break;
1129 case 576: 1016 case 576:
1130 moutdwm(ast, 0x1E6E2020, 0x0140); 1017 ast_moutdwm(ast, 0x1E6E2020, 0x0140);
1131 param->reg_MADJ = 0x00136868; 1018 param->reg_MADJ = 0x00136868;
1132 param->reg_SADJ = 0x00004534; 1019 param->reg_SADJ = 0x00004534;
1133 param->wodt = 1; 1020 param->wodt = 1;
@@ -1145,7 +1032,7 @@ static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *pa
1145 param->dll2_finetune_step = 3; 1032 param->dll2_finetune_step = 3;
1146 break; 1033 break;
1147 case 600: 1034 case 600:
1148 moutdwm(ast, 0x1E6E2020, 0x02E1); 1035 ast_moutdwm(ast, 0x1E6E2020, 0x02E1);
1149 param->reg_MADJ = 0x00136868; 1036 param->reg_MADJ = 0x00136868;
1150 param->reg_SADJ = 0x00004534; 1037 param->reg_SADJ = 0x00004534;
1151 param->wodt = 1; 1038 param->wodt = 1;
@@ -1163,7 +1050,7 @@ static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *pa
1163 param->dll2_finetune_step = 3; 1050 param->dll2_finetune_step = 3;
1164 break; 1051 break;
1165 case 624: 1052 case 624:
1166 moutdwm(ast, 0x1E6E2020, 0x0160); 1053 ast_moutdwm(ast, 0x1E6E2020, 0x0160);
1167 param->reg_MADJ = 0x00136868; 1054 param->reg_MADJ = 0x00136868;
1168 param->reg_SADJ = 0x00004534; 1055 param->reg_SADJ = 0x00004534;
1169 param->wodt = 1; 1056 param->wodt = 1;
@@ -1196,7 +1083,7 @@ static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *pa
1196 case AST_DRAM_4Gx16: 1083 case AST_DRAM_4Gx16:
1197 param->dram_config = 0x133; 1084 param->dram_config = 0x133;
1198 break; 1085 break;
1199 }; /* switch size */ 1086 } /* switch size */
1200 1087
1201 switch (param->vram_size) { 1088 switch (param->vram_size) {
1202 default: 1089 default:
@@ -1218,106 +1105,98 @@ static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *pa
1218 1105
1219static void ddr3_init(struct ast_private *ast, struct ast2300_dram_param *param) 1106static void ddr3_init(struct ast_private *ast, struct ast2300_dram_param *param)
1220{ 1107{
1221 u32 data, data2; 1108 u32 data, data2, retry = 0;
1222 1109
1223 moutdwm(ast, 0x1E6E0000, 0xFC600309); 1110ddr3_init_start:
1224 moutdwm(ast, 0x1E6E0018, 0x00000100); 1111 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1225 moutdwm(ast, 0x1E6E0024, 0x00000000); 1112 ast_moutdwm(ast, 0x1E6E0018, 0x00000100);
1226 moutdwm(ast, 0x1E6E0034, 0x00000000); 1113 ast_moutdwm(ast, 0x1E6E0024, 0x00000000);
1114 ast_moutdwm(ast, 0x1E6E0034, 0x00000000);
1227 udelay(10); 1115 udelay(10);
1228 moutdwm(ast, 0x1E6E0064, param->reg_MADJ); 1116 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ);
1229 moutdwm(ast, 0x1E6E0068, param->reg_SADJ); 1117 ast_moutdwm(ast, 0x1E6E0068, param->reg_SADJ);
1230 udelay(10); 1118 udelay(10);
1231 moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000); 1119 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000);
1232 udelay(10); 1120 udelay(10);
1233 1121
1234 moutdwm(ast, 0x1E6E0004, param->dram_config); 1122 ast_moutdwm(ast, 0x1E6E0004, param->dram_config);
1235 moutdwm(ast, 0x1E6E0008, 0x90040f); 1123 ast_moutdwm(ast, 0x1E6E0008, 0x90040f);
1236 moutdwm(ast, 0x1E6E0010, param->reg_AC1); 1124 ast_moutdwm(ast, 0x1E6E0010, param->reg_AC1);
1237 moutdwm(ast, 0x1E6E0014, param->reg_AC2); 1125 ast_moutdwm(ast, 0x1E6E0014, param->reg_AC2);
1238 moutdwm(ast, 0x1E6E0020, param->reg_DQSIC); 1126 ast_moutdwm(ast, 0x1E6E0020, param->reg_DQSIC);
1239 moutdwm(ast, 0x1E6E0080, 0x00000000); 1127 ast_moutdwm(ast, 0x1E6E0080, 0x00000000);
1240 moutdwm(ast, 0x1E6E0084, 0x00000000); 1128 ast_moutdwm(ast, 0x1E6E0084, 0x00000000);
1241 moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY); 1129 ast_moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY);
1242 moutdwm(ast, 0x1E6E0018, 0x4040A170); 1130 ast_moutdwm(ast, 0x1E6E0018, 0x4000A170);
1243 moutdwm(ast, 0x1E6E0018, 0x20402370); 1131 ast_moutdwm(ast, 0x1E6E0018, 0x00002370);
1244 moutdwm(ast, 0x1E6E0038, 0x00000000); 1132 ast_moutdwm(ast, 0x1E6E0038, 0x00000000);
1245 moutdwm(ast, 0x1E6E0040, 0xFF444444); 1133 ast_moutdwm(ast, 0x1E6E0040, 0xFF444444);
1246 moutdwm(ast, 0x1E6E0044, 0x22222222); 1134 ast_moutdwm(ast, 0x1E6E0044, 0x22222222);
1247 moutdwm(ast, 0x1E6E0048, 0x22222222); 1135 ast_moutdwm(ast, 0x1E6E0048, 0x22222222);
1248 moutdwm(ast, 0x1E6E004C, 0x00000002); 1136 ast_moutdwm(ast, 0x1E6E004C, 0x00000002);
1249 moutdwm(ast, 0x1E6E0050, 0x80000000); 1137 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1250 moutdwm(ast, 0x1E6E0050, 0x00000000); 1138 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1251 moutdwm(ast, 0x1E6E0054, 0); 1139 ast_moutdwm(ast, 0x1E6E0054, 0);
1252 moutdwm(ast, 0x1E6E0060, param->reg_DRV); 1140 ast_moutdwm(ast, 0x1E6E0060, param->reg_DRV);
1253 moutdwm(ast, 0x1E6E006C, param->reg_IOZ); 1141 ast_moutdwm(ast, 0x1E6E006C, param->reg_IOZ);
1254 moutdwm(ast, 0x1E6E0070, 0x00000000); 1142 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1255 moutdwm(ast, 0x1E6E0074, 0x00000000); 1143 ast_moutdwm(ast, 0x1E6E0074, 0x00000000);
1256 moutdwm(ast, 0x1E6E0078, 0x00000000); 1144 ast_moutdwm(ast, 0x1E6E0078, 0x00000000);
1257 moutdwm(ast, 0x1E6E007C, 0x00000000); 1145 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1258 /* Wait MCLK2X lock to MCLK */ 1146 /* Wait MCLK2X lock to MCLK */
1259 do { 1147 do {
1260 data = mindwm(ast, 0x1E6E001C); 1148 data = ast_mindwm(ast, 0x1E6E001C);
1261 } while (!(data & 0x08000000)); 1149 } while (!(data & 0x08000000));
1262 moutdwm(ast, 0x1E6E0034, 0x00000001); 1150 data = ast_mindwm(ast, 0x1E6E001C);
1263 moutdwm(ast, 0x1E6E000C, 0x00005C04);
1264 udelay(10);
1265 moutdwm(ast, 0x1E6E000C, 0x00000000);
1266 moutdwm(ast, 0x1E6E0034, 0x00000000);
1267 data = mindwm(ast, 0x1E6E001C);
1268 data = (data >> 8) & 0xff; 1151 data = (data >> 8) & 0xff;
1269 while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) { 1152 while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) {
1270 data2 = (mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4; 1153 data2 = (ast_mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4;
1271 if ((data2 & 0xff) > param->madj_max) { 1154 if ((data2 & 0xff) > param->madj_max) {
1272 break; 1155 break;
1273 } 1156 }
1274 moutdwm(ast, 0x1E6E0064, data2); 1157 ast_moutdwm(ast, 0x1E6E0064, data2);
1275 if (data2 & 0x00100000) { 1158 if (data2 & 0x00100000) {
1276 data2 = ((data2 & 0xff) >> 3) + 3; 1159 data2 = ((data2 & 0xff) >> 3) + 3;
1277 } else { 1160 } else {
1278 data2 = ((data2 & 0xff) >> 2) + 5; 1161 data2 = ((data2 & 0xff) >> 2) + 5;
1279 } 1162 }
1280 data = mindwm(ast, 0x1E6E0068) & 0xffff00ff; 1163 data = ast_mindwm(ast, 0x1E6E0068) & 0xffff00ff;
1281 data2 += data & 0xff; 1164 data2 += data & 0xff;
1282 data = data | (data2 << 8); 1165 data = data | (data2 << 8);
1283 moutdwm(ast, 0x1E6E0068, data); 1166 ast_moutdwm(ast, 0x1E6E0068, data);
1284 udelay(10); 1167 udelay(10);
1285 moutdwm(ast, 0x1E6E0064, mindwm(ast, 0x1E6E0064) | 0xC0000); 1168 ast_moutdwm(ast, 0x1E6E0064, ast_mindwm(ast, 0x1E6E0064) | 0xC0000);
1286 udelay(10); 1169 udelay(10);
1287 data = mindwm(ast, 0x1E6E0018) & 0xfffff1ff; 1170 data = ast_mindwm(ast, 0x1E6E0018) & 0xfffff1ff;
1288 moutdwm(ast, 0x1E6E0018, data); 1171 ast_moutdwm(ast, 0x1E6E0018, data);
1289 data = data | 0x200; 1172 data = data | 0x200;
1290 moutdwm(ast, 0x1E6E0018, data); 1173 ast_moutdwm(ast, 0x1E6E0018, data);
1291 do { 1174 do {
1292 data = mindwm(ast, 0x1E6E001C); 1175 data = ast_mindwm(ast, 0x1E6E001C);
1293 } while (!(data & 0x08000000)); 1176 } while (!(data & 0x08000000));
1294 1177
1295 moutdwm(ast, 0x1E6E0034, 0x00000001); 1178 data = ast_mindwm(ast, 0x1E6E001C);
1296 moutdwm(ast, 0x1E6E000C, 0x00005C04);
1297 udelay(10);
1298 moutdwm(ast, 0x1E6E000C, 0x00000000);
1299 moutdwm(ast, 0x1E6E0034, 0x00000000);
1300 data = mindwm(ast, 0x1E6E001C);
1301 data = (data >> 8) & 0xff; 1179 data = (data >> 8) & 0xff;
1302 } 1180 }
1303 data = mindwm(ast, 0x1E6E0018) | 0xC00; 1181 ast_moutdwm(ast, 0x1E720058, ast_mindwm(ast, 0x1E6E0068) & 0xffff);
1304 moutdwm(ast, 0x1E6E0018, data); 1182 data = ast_mindwm(ast, 0x1E6E0018) | 0xC00;
1183 ast_moutdwm(ast, 0x1E6E0018, data);
1305 1184
1306 moutdwm(ast, 0x1E6E0034, 0x00000001); 1185 ast_moutdwm(ast, 0x1E6E0034, 0x00000001);
1307 moutdwm(ast, 0x1E6E000C, 0x00000040); 1186 ast_moutdwm(ast, 0x1E6E000C, 0x00000040);
1308 udelay(50); 1187 udelay(50);
1309 /* Mode Register Setting */ 1188 /* Mode Register Setting */
1310 moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100); 1189 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100);
1311 moutdwm(ast, 0x1E6E0030, param->reg_EMRS); 1190 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1312 moutdwm(ast, 0x1E6E0028, 0x00000005); 1191 ast_moutdwm(ast, 0x1E6E0028, 0x00000005);
1313 moutdwm(ast, 0x1E6E0028, 0x00000007); 1192 ast_moutdwm(ast, 0x1E6E0028, 0x00000007);
1314 moutdwm(ast, 0x1E6E0028, 0x00000003); 1193 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1315 moutdwm(ast, 0x1E6E0028, 0x00000001); 1194 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1316 moutdwm(ast, 0x1E6E002C, param->reg_MRS); 1195 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS);
1317 moutdwm(ast, 0x1E6E000C, 0x00005C08); 1196 ast_moutdwm(ast, 0x1E6E000C, 0x00005C08);
1318 moutdwm(ast, 0x1E6E0028, 0x00000001); 1197 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1319 1198
1320 moutdwm(ast, 0x1E6E000C, 0x7FFF5C01); 1199 ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
1321 data = 0; 1200 data = 0;
1322 if (param->wodt) { 1201 if (param->wodt) {
1323 data = 0x300; 1202 data = 0x300;
@@ -1325,30 +1204,23 @@ static void ddr3_init(struct ast_private *ast, struct ast2300_dram_param *param)
1325 if (param->rodt) { 1204 if (param->rodt) {
1326 data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3); 1205 data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3);
1327 } 1206 }
1328 moutdwm(ast, 0x1E6E0034, data | 0x3); 1207 ast_moutdwm(ast, 0x1E6E0034, data | 0x3);
1329 1208
1330 /* Wait DQI delay lock */
1331 do {
1332 data = mindwm(ast, 0x1E6E0080);
1333 } while (!(data & 0x40000000));
1334 /* Wait DQSI delay lock */
1335 do {
1336 data = mindwm(ast, 0x1E6E0020);
1337 } while (!(data & 0x00000800));
1338 /* Calibrate the DQSI delay */ 1209 /* Calibrate the DQSI delay */
1339 cbr_dll2(ast, param); 1210 if ((cbr_dll2(ast, param) == false) && (retry++ < 10))
1211 goto ddr3_init_start;
1340 1212
1341 moutdwm(ast, 0x1E6E0120, param->reg_FREQ); 1213 ast_moutdwm(ast, 0x1E6E0120, param->reg_FREQ);
1342 /* ECC Memory Initialization */ 1214 /* ECC Memory Initialization */
1343#ifdef ECC 1215#ifdef ECC
1344 moutdwm(ast, 0x1E6E007C, 0x00000000); 1216 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1345 moutdwm(ast, 0x1E6E0070, 0x221); 1217 ast_moutdwm(ast, 0x1E6E0070, 0x221);
1346 do { 1218 do {
1347 data = mindwm(ast, 0x1E6E0070); 1219 data = ast_mindwm(ast, 0x1E6E0070);
1348 } while (!(data & 0x00001000)); 1220 } while (!(data & 0x00001000));
1349 moutdwm(ast, 0x1E6E0070, 0x00000000); 1221 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1350 moutdwm(ast, 0x1E6E0050, 0x80000000); 1222 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1351 moutdwm(ast, 0x1E6E0050, 0x00000000); 1223 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1352#endif 1224#endif
1353 1225
1354 1226
@@ -1358,10 +1230,10 @@ static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *pa
1358{ 1230{
1359 u32 trap, trap_AC2, trap_MRS; 1231 u32 trap, trap_AC2, trap_MRS;
1360 1232
1361 moutdwm(ast, 0x1E6E2000, 0x1688A8A8); 1233 ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
1362 1234
1363 /* Ger trap info */ 1235 /* Ger trap info */
1364 trap = (mindwm(ast, 0x1E6E2070) >> 25) & 0x3; 1236 trap = (ast_mindwm(ast, 0x1E6E2070) >> 25) & 0x3;
1365 trap_AC2 = (trap << 20) | (trap << 16); 1237 trap_AC2 = (trap << 20) | (trap << 16);
1366 trap_AC2 += 0x00110000; 1238 trap_AC2 += 0x00110000;
1367 trap_MRS = 0x00000040 | (trap << 4); 1239 trap_MRS = 0x00000040 | (trap << 4);
@@ -1375,7 +1247,7 @@ static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *pa
1375 1247
1376 switch (param->dram_freq) { 1248 switch (param->dram_freq) {
1377 case 264: 1249 case 264:
1378 moutdwm(ast, 0x1E6E2020, 0x0130); 1250 ast_moutdwm(ast, 0x1E6E2020, 0x0130);
1379 param->wodt = 0; 1251 param->wodt = 0;
1380 param->reg_AC1 = 0x11101513; 1252 param->reg_AC1 = 0x11101513;
1381 param->reg_AC2 = 0x78117011; 1253 param->reg_AC2 = 0x78117011;
@@ -1390,7 +1262,7 @@ static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *pa
1390 param->dll2_finetune_step = 3; 1262 param->dll2_finetune_step = 3;
1391 break; 1263 break;
1392 case 336: 1264 case 336:
1393 moutdwm(ast, 0x1E6E2020, 0x0190); 1265 ast_moutdwm(ast, 0x1E6E2020, 0x0190);
1394 param->wodt = 1; 1266 param->wodt = 1;
1395 param->reg_AC1 = 0x22202613; 1267 param->reg_AC1 = 0x22202613;
1396 param->reg_AC2 = 0xAA009016 | trap_AC2; 1268 param->reg_AC2 = 0xAA009016 | trap_AC2;
@@ -1403,10 +1275,25 @@ static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *pa
1403 param->reg_FREQ = 0x00004DC0; 1275 param->reg_FREQ = 0x00004DC0;
1404 param->madj_max = 96; 1276 param->madj_max = 96;
1405 param->dll2_finetune_step = 3; 1277 param->dll2_finetune_step = 3;
1278 switch (param->dram_chipid) {
1279 default:
1280 case AST_DRAM_512Mx16:
1281 param->reg_AC2 = 0xAA009012 | trap_AC2;
1282 break;
1283 case AST_DRAM_1Gx16:
1284 param->reg_AC2 = 0xAA009016 | trap_AC2;
1285 break;
1286 case AST_DRAM_2Gx16:
1287 param->reg_AC2 = 0xAA009023 | trap_AC2;
1288 break;
1289 case AST_DRAM_4Gx16:
1290 param->reg_AC2 = 0xAA00903B | trap_AC2;
1291 break;
1292 }
1406 break; 1293 break;
1407 default: 1294 default:
1408 case 396: 1295 case 396:
1409 moutdwm(ast, 0x1E6E2020, 0x03F1); 1296 ast_moutdwm(ast, 0x1E6E2020, 0x03F1);
1410 param->wodt = 1; 1297 param->wodt = 1;
1411 param->rodt = 0; 1298 param->rodt = 0;
1412 param->reg_AC1 = 0x33302714; 1299 param->reg_AC1 = 0x33302714;
@@ -1417,7 +1304,7 @@ static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *pa
1417 param->reg_DRV = 0x000000FA; 1304 param->reg_DRV = 0x000000FA;
1418 param->reg_IOZ = 0x00000034; 1305 param->reg_IOZ = 0x00000034;
1419 param->reg_DQIDLY = 0x00000089; 1306 param->reg_DQIDLY = 0x00000089;
1420 param->reg_FREQ = 0x000050C0; 1307 param->reg_FREQ = 0x00005040;
1421 param->madj_max = 96; 1308 param->madj_max = 96;
1422 param->dll2_finetune_step = 4; 1309 param->dll2_finetune_step = 4;
1423 1310
@@ -1440,7 +1327,7 @@ static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *pa
1440 break; 1327 break;
1441 1328
1442 case 408: 1329 case 408:
1443 moutdwm(ast, 0x1E6E2020, 0x01F0); 1330 ast_moutdwm(ast, 0x1E6E2020, 0x01F0);
1444 param->wodt = 1; 1331 param->wodt = 1;
1445 param->rodt = 0; 1332 param->rodt = 0;
1446 param->reg_AC1 = 0x33302714; 1333 param->reg_AC1 = 0x33302714;
@@ -1473,7 +1360,7 @@ static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *pa
1473 1360
1474 break; 1361 break;
1475 case 456: 1362 case 456:
1476 moutdwm(ast, 0x1E6E2020, 0x0230); 1363 ast_moutdwm(ast, 0x1E6E2020, 0x0230);
1477 param->wodt = 0; 1364 param->wodt = 0;
1478 param->reg_AC1 = 0x33302815; 1365 param->reg_AC1 = 0x33302815;
1479 param->reg_AC2 = 0xCD44B01E; 1366 param->reg_AC2 = 0xCD44B01E;
@@ -1488,7 +1375,7 @@ static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *pa
1488 param->dll2_finetune_step = 3; 1375 param->dll2_finetune_step = 3;
1489 break; 1376 break;
1490 case 504: 1377 case 504:
1491 moutdwm(ast, 0x1E6E2020, 0x0261); 1378 ast_moutdwm(ast, 0x1E6E2020, 0x0261);
1492 param->wodt = 1; 1379 param->wodt = 1;
1493 param->rodt = 1; 1380 param->rodt = 1;
1494 param->reg_AC1 = 0x33302815; 1381 param->reg_AC1 = 0x33302815;
@@ -1504,7 +1391,7 @@ static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *pa
1504 param->dll2_finetune_step = 3; 1391 param->dll2_finetune_step = 3;
1505 break; 1392 break;
1506 case 528: 1393 case 528:
1507 moutdwm(ast, 0x1E6E2020, 0x0120); 1394 ast_moutdwm(ast, 0x1E6E2020, 0x0120);
1508 param->wodt = 1; 1395 param->wodt = 1;
1509 param->rodt = 1; 1396 param->rodt = 1;
1510 param->reg_AC1 = 0x33302815; 1397 param->reg_AC1 = 0x33302815;
@@ -1520,7 +1407,7 @@ static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *pa
1520 param->dll2_finetune_step = 3; 1407 param->dll2_finetune_step = 3;
1521 break; 1408 break;
1522 case 552: 1409 case 552:
1523 moutdwm(ast, 0x1E6E2020, 0x02A1); 1410 ast_moutdwm(ast, 0x1E6E2020, 0x02A1);
1524 param->wodt = 1; 1411 param->wodt = 1;
1525 param->rodt = 1; 1412 param->rodt = 1;
1526 param->reg_AC1 = 0x43402915; 1413 param->reg_AC1 = 0x43402915;
@@ -1536,7 +1423,7 @@ static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *pa
1536 param->dll2_finetune_step = 3; 1423 param->dll2_finetune_step = 3;
1537 break; 1424 break;
1538 case 576: 1425 case 576:
1539 moutdwm(ast, 0x1E6E2020, 0x0140); 1426 ast_moutdwm(ast, 0x1E6E2020, 0x0140);
1540 param->wodt = 1; 1427 param->wodt = 1;
1541 param->rodt = 1; 1428 param->rodt = 1;
1542 param->reg_AC1 = 0x43402915; 1429 param->reg_AC1 = 0x43402915;
@@ -1567,7 +1454,7 @@ static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *pa
1567 case AST_DRAM_4Gx16: 1454 case AST_DRAM_4Gx16:
1568 param->dram_config = 0x123; 1455 param->dram_config = 0x123;
1569 break; 1456 break;
1570 }; /* switch size */ 1457 } /* switch size */
1571 1458
1572 switch (param->vram_size) { 1459 switch (param->vram_size) {
1573 default: 1460 default:
@@ -1588,110 +1475,102 @@ static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *pa
1588 1475
1589static void ddr2_init(struct ast_private *ast, struct ast2300_dram_param *param) 1476static void ddr2_init(struct ast_private *ast, struct ast2300_dram_param *param)
1590{ 1477{
1591 u32 data, data2; 1478 u32 data, data2, retry = 0;
1592 1479
1593 moutdwm(ast, 0x1E6E0000, 0xFC600309); 1480ddr2_init_start:
1594 moutdwm(ast, 0x1E6E0018, 0x00000100); 1481 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1595 moutdwm(ast, 0x1E6E0024, 0x00000000); 1482 ast_moutdwm(ast, 0x1E6E0018, 0x00000100);
1596 moutdwm(ast, 0x1E6E0064, param->reg_MADJ); 1483 ast_moutdwm(ast, 0x1E6E0024, 0x00000000);
1597 moutdwm(ast, 0x1E6E0068, param->reg_SADJ); 1484 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ);
1485 ast_moutdwm(ast, 0x1E6E0068, param->reg_SADJ);
1598 udelay(10); 1486 udelay(10);
1599 moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000); 1487 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000);
1600 udelay(10); 1488 udelay(10);
1601 1489
1602 moutdwm(ast, 0x1E6E0004, param->dram_config); 1490 ast_moutdwm(ast, 0x1E6E0004, param->dram_config);
1603 moutdwm(ast, 0x1E6E0008, 0x90040f); 1491 ast_moutdwm(ast, 0x1E6E0008, 0x90040f);
1604 moutdwm(ast, 0x1E6E0010, param->reg_AC1); 1492 ast_moutdwm(ast, 0x1E6E0010, param->reg_AC1);
1605 moutdwm(ast, 0x1E6E0014, param->reg_AC2); 1493 ast_moutdwm(ast, 0x1E6E0014, param->reg_AC2);
1606 moutdwm(ast, 0x1E6E0020, param->reg_DQSIC); 1494 ast_moutdwm(ast, 0x1E6E0020, param->reg_DQSIC);
1607 moutdwm(ast, 0x1E6E0080, 0x00000000); 1495 ast_moutdwm(ast, 0x1E6E0080, 0x00000000);
1608 moutdwm(ast, 0x1E6E0084, 0x00000000); 1496 ast_moutdwm(ast, 0x1E6E0084, 0x00000000);
1609 moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY); 1497 ast_moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY);
1610 moutdwm(ast, 0x1E6E0018, 0x4040A130); 1498 ast_moutdwm(ast, 0x1E6E0018, 0x4000A130);
1611 moutdwm(ast, 0x1E6E0018, 0x20402330); 1499 ast_moutdwm(ast, 0x1E6E0018, 0x00002330);
1612 moutdwm(ast, 0x1E6E0038, 0x00000000); 1500 ast_moutdwm(ast, 0x1E6E0038, 0x00000000);
1613 moutdwm(ast, 0x1E6E0040, 0xFF808000); 1501 ast_moutdwm(ast, 0x1E6E0040, 0xFF808000);
1614 moutdwm(ast, 0x1E6E0044, 0x88848466); 1502 ast_moutdwm(ast, 0x1E6E0044, 0x88848466);
1615 moutdwm(ast, 0x1E6E0048, 0x44440008); 1503 ast_moutdwm(ast, 0x1E6E0048, 0x44440008);
1616 moutdwm(ast, 0x1E6E004C, 0x00000000); 1504 ast_moutdwm(ast, 0x1E6E004C, 0x00000000);
1617 moutdwm(ast, 0x1E6E0050, 0x80000000); 1505 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1618 moutdwm(ast, 0x1E6E0050, 0x00000000); 1506 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1619 moutdwm(ast, 0x1E6E0054, 0); 1507 ast_moutdwm(ast, 0x1E6E0054, 0);
1620 moutdwm(ast, 0x1E6E0060, param->reg_DRV); 1508 ast_moutdwm(ast, 0x1E6E0060, param->reg_DRV);
1621 moutdwm(ast, 0x1E6E006C, param->reg_IOZ); 1509 ast_moutdwm(ast, 0x1E6E006C, param->reg_IOZ);
1622 moutdwm(ast, 0x1E6E0070, 0x00000000); 1510 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1623 moutdwm(ast, 0x1E6E0074, 0x00000000); 1511 ast_moutdwm(ast, 0x1E6E0074, 0x00000000);
1624 moutdwm(ast, 0x1E6E0078, 0x00000000); 1512 ast_moutdwm(ast, 0x1E6E0078, 0x00000000);
1625 moutdwm(ast, 0x1E6E007C, 0x00000000); 1513 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1626 1514
1627 /* Wait MCLK2X lock to MCLK */ 1515 /* Wait MCLK2X lock to MCLK */
1628 do { 1516 do {
1629 data = mindwm(ast, 0x1E6E001C); 1517 data = ast_mindwm(ast, 0x1E6E001C);
1630 } while (!(data & 0x08000000)); 1518 } while (!(data & 0x08000000));
1631 moutdwm(ast, 0x1E6E0034, 0x00000001); 1519 data = ast_mindwm(ast, 0x1E6E001C);
1632 moutdwm(ast, 0x1E6E000C, 0x00005C04);
1633 udelay(10);
1634 moutdwm(ast, 0x1E6E000C, 0x00000000);
1635 moutdwm(ast, 0x1E6E0034, 0x00000000);
1636 data = mindwm(ast, 0x1E6E001C);
1637 data = (data >> 8) & 0xff; 1520 data = (data >> 8) & 0xff;
1638 while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) { 1521 while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) {
1639 data2 = (mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4; 1522 data2 = (ast_mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4;
1640 if ((data2 & 0xff) > param->madj_max) { 1523 if ((data2 & 0xff) > param->madj_max) {
1641 break; 1524 break;
1642 } 1525 }
1643 moutdwm(ast, 0x1E6E0064, data2); 1526 ast_moutdwm(ast, 0x1E6E0064, data2);
1644 if (data2 & 0x00100000) { 1527 if (data2 & 0x00100000) {
1645 data2 = ((data2 & 0xff) >> 3) + 3; 1528 data2 = ((data2 & 0xff) >> 3) + 3;
1646 } else { 1529 } else {
1647 data2 = ((data2 & 0xff) >> 2) + 5; 1530 data2 = ((data2 & 0xff) >> 2) + 5;
1648 } 1531 }
1649 data = mindwm(ast, 0x1E6E0068) & 0xffff00ff; 1532 data = ast_mindwm(ast, 0x1E6E0068) & 0xffff00ff;
1650 data2 += data & 0xff; 1533 data2 += data & 0xff;
1651 data = data | (data2 << 8); 1534 data = data | (data2 << 8);
1652 moutdwm(ast, 0x1E6E0068, data); 1535 ast_moutdwm(ast, 0x1E6E0068, data);
1653 udelay(10); 1536 udelay(10);
1654 moutdwm(ast, 0x1E6E0064, mindwm(ast, 0x1E6E0064) | 0xC0000); 1537 ast_moutdwm(ast, 0x1E6E0064, ast_mindwm(ast, 0x1E6E0064) | 0xC0000);
1655 udelay(10); 1538 udelay(10);
1656 data = mindwm(ast, 0x1E6E0018) & 0xfffff1ff; 1539 data = ast_mindwm(ast, 0x1E6E0018) & 0xfffff1ff;
1657 moutdwm(ast, 0x1E6E0018, data); 1540 ast_moutdwm(ast, 0x1E6E0018, data);
1658 data = data | 0x200; 1541 data = data | 0x200;
1659 moutdwm(ast, 0x1E6E0018, data); 1542 ast_moutdwm(ast, 0x1E6E0018, data);
1660 do { 1543 do {
1661 data = mindwm(ast, 0x1E6E001C); 1544 data = ast_mindwm(ast, 0x1E6E001C);
1662 } while (!(data & 0x08000000)); 1545 } while (!(data & 0x08000000));
1663 1546
1664 moutdwm(ast, 0x1E6E0034, 0x00000001); 1547 data = ast_mindwm(ast, 0x1E6E001C);
1665 moutdwm(ast, 0x1E6E000C, 0x00005C04);
1666 udelay(10);
1667 moutdwm(ast, 0x1E6E000C, 0x00000000);
1668 moutdwm(ast, 0x1E6E0034, 0x00000000);
1669 data = mindwm(ast, 0x1E6E001C);
1670 data = (data >> 8) & 0xff; 1548 data = (data >> 8) & 0xff;
1671 } 1549 }
1672 data = mindwm(ast, 0x1E6E0018) | 0xC00; 1550 ast_moutdwm(ast, 0x1E720058, ast_mindwm(ast, 0x1E6E0008) & 0xffff);
1673 moutdwm(ast, 0x1E6E0018, data); 1551 data = ast_mindwm(ast, 0x1E6E0018) | 0xC00;
1552 ast_moutdwm(ast, 0x1E6E0018, data);
1674 1553
1675 moutdwm(ast, 0x1E6E0034, 0x00000001); 1554 ast_moutdwm(ast, 0x1E6E0034, 0x00000001);
1676 moutdwm(ast, 0x1E6E000C, 0x00000000); 1555 ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
1677 udelay(50); 1556 udelay(50);
1678 /* Mode Register Setting */ 1557 /* Mode Register Setting */
1679 moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100); 1558 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100);
1680 moutdwm(ast, 0x1E6E0030, param->reg_EMRS); 1559 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1681 moutdwm(ast, 0x1E6E0028, 0x00000005); 1560 ast_moutdwm(ast, 0x1E6E0028, 0x00000005);
1682 moutdwm(ast, 0x1E6E0028, 0x00000007); 1561 ast_moutdwm(ast, 0x1E6E0028, 0x00000007);
1683 moutdwm(ast, 0x1E6E0028, 0x00000003); 1562 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1684 moutdwm(ast, 0x1E6E0028, 0x00000001); 1563 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1685 1564
1686 moutdwm(ast, 0x1E6E000C, 0x00005C08); 1565 ast_moutdwm(ast, 0x1E6E000C, 0x00005C08);
1687 moutdwm(ast, 0x1E6E002C, param->reg_MRS); 1566 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS);
1688 moutdwm(ast, 0x1E6E0028, 0x00000001); 1567 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1689 moutdwm(ast, 0x1E6E0030, param->reg_EMRS | 0x380); 1568 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS | 0x380);
1690 moutdwm(ast, 0x1E6E0028, 0x00000003); 1569 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1691 moutdwm(ast, 0x1E6E0030, param->reg_EMRS); 1570 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1692 moutdwm(ast, 0x1E6E0028, 0x00000003); 1571 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1693 1572
1694 moutdwm(ast, 0x1E6E000C, 0x7FFF5C01); 1573 ast_moutdwm(ast, 0x1E6E000C, 0x7FFF5C01);
1695 data = 0; 1574 data = 0;
1696 if (param->wodt) { 1575 if (param->wodt) {
1697 data = 0x500; 1576 data = 0x500;
@@ -1699,30 +1578,23 @@ static void ddr2_init(struct ast_private *ast, struct ast2300_dram_param *param)
1699 if (param->rodt) { 1578 if (param->rodt) {
1700 data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3); 1579 data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3);
1701 } 1580 }
1702 moutdwm(ast, 0x1E6E0034, data | 0x3); 1581 ast_moutdwm(ast, 0x1E6E0034, data | 0x3);
1703 moutdwm(ast, 0x1E6E0120, param->reg_FREQ); 1582 ast_moutdwm(ast, 0x1E6E0120, param->reg_FREQ);
1704 1583
1705 /* Wait DQI delay lock */
1706 do {
1707 data = mindwm(ast, 0x1E6E0080);
1708 } while (!(data & 0x40000000));
1709 /* Wait DQSI delay lock */
1710 do {
1711 data = mindwm(ast, 0x1E6E0020);
1712 } while (!(data & 0x00000800));
1713 /* Calibrate the DQSI delay */ 1584 /* Calibrate the DQSI delay */
1714 cbr_dll2(ast, param); 1585 if ((cbr_dll2(ast, param) == false) && (retry++ < 10))
1586 goto ddr2_init_start;
1715 1587
1716 /* ECC Memory Initialization */ 1588 /* ECC Memory Initialization */
1717#ifdef ECC 1589#ifdef ECC
1718 moutdwm(ast, 0x1E6E007C, 0x00000000); 1590 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1719 moutdwm(ast, 0x1E6E0070, 0x221); 1591 ast_moutdwm(ast, 0x1E6E0070, 0x221);
1720 do { 1592 do {
1721 data = mindwm(ast, 0x1E6E0070); 1593 data = ast_mindwm(ast, 0x1E6E0070);
1722 } while (!(data & 0x00001000)); 1594 } while (!(data & 0x00001000));
1723 moutdwm(ast, 0x1E6E0070, 0x00000000); 1595 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1724 moutdwm(ast, 0x1E6E0050, 0x80000000); 1596 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1725 moutdwm(ast, 0x1E6E0050, 0x00000000); 1597 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1726#endif 1598#endif
1727 1599
1728} 1600}
@@ -1768,8 +1640,8 @@ static void ast_init_dram_2300(struct drm_device *dev)
1768 ddr2_init(ast, &param); 1640 ddr2_init(ast, &param);
1769 } 1641 }
1770 1642
1771 temp = mindwm(ast, 0x1e6e2040); 1643 temp = ast_mindwm(ast, 0x1e6e2040);
1772 moutdwm(ast, 0x1e6e2040, temp | 0x40); 1644 ast_moutdwm(ast, 0x1e6e2040, temp | 0x40);
1773 } 1645 }
1774 1646
1775 /* wait ready */ 1647 /* wait ready */