2 * Copyright 2012 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
15 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18 * USE OR OTHER DEALINGS IN THE SOFTWARE.
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
32 #include "ast_dram_tables.h"
34 static void ast_init_dram_2300(struct drm_device *dev);
37 ast_enable_vga(struct drm_device *dev)
39 struct ast_private *ast = dev->dev_private;
41 ast_io_write8(ast, 0x43, 0x01);
42 ast_io_write8(ast, 0x42, 0x01);
45 #if 0 /* will use later */
47 ast_is_vga_enabled(struct drm_device *dev)
49 struct ast_private *ast = dev->dev_private;
52 if (ast->chip == AST1180) {
55 ch = ast_io_read8(ast, 0x43);
58 ch = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb6, 0xff);
66 static const u8 extreginfo[] = { 0x0f, 0x04, 0x1c, 0xff };
67 static const u8 extreginfo_ast2300a0[] = { 0x0f, 0x04, 0x1c, 0xff };
68 static const u8 extreginfo_ast2300[] = { 0x0f, 0x04, 0x1f, 0xff };
71 ast_set_def_ext_reg(struct drm_device *dev)
73 struct ast_private *ast = dev->dev_private;
75 const u8 *ext_reg_info;
78 for (i = 0x81; i <= 0x8f; i++)
79 ast_set_index_reg(ast, AST_IO_CRTC_PORT, i, 0x00);
81 if (ast->chip == AST2300 || ast->chip == AST2400) {
82 if (dev->pdev->revision >= 0x20)
83 ext_reg_info = extreginfo_ast2300;
85 ext_reg_info = extreginfo_ast2300a0;
87 ext_reg_info = extreginfo;
90 while (*ext_reg_info != 0xff) {
91 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, index, 0x00, *ext_reg_info);
96 /* disable standard IO/MEM decode if secondary */
97 /* ast_set_index_reg-mask(ast, AST_IO_CRTC_PORT, 0xa1, 0xff, 0x3); */
99 /* Set Ext. Default */
100 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x8c, 0x00, 0x01);
101 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x00, 0x00);
103 /* Enable RAMDAC for A1 */
105 if (ast->chip == AST2300 || ast->chip == AST2400)
107 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb6, 0xff, reg);
110 u32 ast_mindwm(struct ast_private *ast, u32 r)
114 ast_write32(ast, 0xf004, r & 0xffff0000);
115 ast_write32(ast, 0xf000, 0x1);
118 data = ast_read32(ast, 0xf004) & 0xffff0000;
119 } while (data != (r & 0xffff0000));
120 return ast_read32(ast, 0x10000 + (r & 0x0000ffff));
123 void ast_moutdwm(struct ast_private *ast, u32 r, u32 v)
126 ast_write32(ast, 0xf004, r & 0xffff0000);
127 ast_write32(ast, 0xf000, 0x1);
129 data = ast_read32(ast, 0xf004) & 0xffff0000;
130 } while (data != (r & 0xffff0000));
131 ast_write32(ast, 0x10000 + (r & 0x0000ffff), v);
135 * AST2100/2150 DLL CBR Setting
137 #define CBR_SIZE_AST2150 ((16 << 10) - 1)
138 #define CBR_PASSNUM_AST2150 5
139 #define CBR_THRESHOLD_AST2150 10
140 #define CBR_THRESHOLD2_AST2150 10
141 #define TIMEOUT_AST2150 5000000
143 #define CBR_PATNUM_AST2150 8
145 static const u32 pattern_AST2150[14] = {
162 static u32 mmctestburst2_ast2150(struct ast_private *ast, u32 datagen)
166 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
167 ast_moutdwm(ast, 0x1e6e0070, 0x00000001 | (datagen << 3));
170 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
171 if (++timeout > TIMEOUT_AST2150) {
172 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
176 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
177 ast_moutdwm(ast, 0x1e6e0070, 0x00000003 | (datagen << 3));
180 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
181 if (++timeout > TIMEOUT_AST2150) {
182 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
186 data = (ast_mindwm(ast, 0x1e6e0070) & 0x80) >> 7;
187 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
191 #if 0 /* unused in DDX driver - here for completeness */
192 static u32 mmctestsingle2_ast2150(struct ast_private *ast, u32 datagen)
196 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
197 ast_moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3));
200 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
201 if (++timeout > TIMEOUT_AST2150) {
202 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
206 data = (ast_mindwm(ast, 0x1e6e0070) & 0x80) >> 7;
207 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
212 static int cbrtest_ast2150(struct ast_private *ast)
216 for (i = 0; i < 8; i++)
217 if (mmctestburst2_ast2150(ast, i))
222 static int cbrscan_ast2150(struct ast_private *ast, int busw)
226 for (patcnt = 0; patcnt < CBR_PATNUM_AST2150; patcnt++) {
227 ast_moutdwm(ast, 0x1e6e007c, pattern_AST2150[patcnt]);
228 for (loop = 0; loop < CBR_PASSNUM_AST2150; loop++) {
229 if (cbrtest_ast2150(ast))
232 if (loop == CBR_PASSNUM_AST2150)
239 static void cbrdlli_ast2150(struct ast_private *ast, int busw)
241 u32 dll_min[4], dll_max[4], dlli, data, passcnt;
244 dll_min[0] = dll_min[1] = dll_min[2] = dll_min[3] = 0xff;
245 dll_max[0] = dll_max[1] = dll_max[2] = dll_max[3] = 0x0;
248 for (dlli = 0; dlli < 100; dlli++) {
249 ast_moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24));
250 data = cbrscan_ast2150(ast, busw);
253 if (dll_min[0] > dlli)
255 if (dll_max[0] < dlli)
259 } else if (passcnt >= CBR_THRESHOLD_AST2150)
262 if (dll_max[0] == 0 || (dll_max[0]-dll_min[0]) < CBR_THRESHOLD_AST2150)
265 dlli = dll_min[0] + (((dll_max[0] - dll_min[0]) * 7) >> 4);
266 ast_moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24));
271 static void ast_init_dram_reg(struct drm_device *dev)
273 struct ast_private *ast = dev->dev_private;
276 const struct ast_dramstruct *dram_reg_info;
278 j = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
280 if ((j & 0x80) == 0) { /* VGA only */
281 if (ast->chip == AST2000) {
282 dram_reg_info = ast2000_dram_table_data;
283 ast_write32(ast, 0xf004, 0x1e6e0000);
284 ast_write32(ast, 0xf000, 0x1);
285 ast_write32(ast, 0x10100, 0xa8);
289 } while (ast_read32(ast, 0x10100) != 0xa8);
290 } else {/* AST2100/1100 */
291 if (ast->chip == AST2100 || ast->chip == 2200)
292 dram_reg_info = ast2100_dram_table_data;
294 dram_reg_info = ast1100_dram_table_data;
296 ast_write32(ast, 0xf004, 0x1e6e0000);
297 ast_write32(ast, 0xf000, 0x1);
298 ast_write32(ast, 0x12000, 0x1688A8A8);
301 } while (ast_read32(ast, 0x12000) != 0x01);
303 ast_write32(ast, 0x10000, 0xfc600309);
306 } while (ast_read32(ast, 0x10000) != 0x01);
309 while (dram_reg_info->index != 0xffff) {
310 if (dram_reg_info->index == 0xff00) {/* delay fn */
311 for (i = 0; i < 15; i++)
312 udelay(dram_reg_info->data);
313 } else if (dram_reg_info->index == 0x4 && ast->chip != AST2000) {
314 data = dram_reg_info->data;
315 if (ast->dram_type == AST_DRAM_1Gx16)
317 else if (ast->dram_type == AST_DRAM_1Gx32)
320 temp = ast_read32(ast, 0x12070);
323 ast_write32(ast, 0x10000 + dram_reg_info->index, data | temp);
325 ast_write32(ast, 0x10000 + dram_reg_info->index, dram_reg_info->data);
329 /* AST 2100/2150 DRAM calibration */
330 data = ast_read32(ast, 0x10120);
331 if (data == 0x5061) { /* 266Mhz */
332 data = ast_read32(ast, 0x10004);
334 cbrdlli_ast2150(ast, 16); /* 16 bits */
336 cbrdlli_ast2150(ast, 32); /* 32 bits */
341 temp = ast_read32(ast, 0x10140);
342 ast_write32(ast, 0x10140, temp | 0x40);
348 temp = ast_read32(ast, 0x1200c);
349 ast_write32(ast, 0x1200c, temp & 0xfffffffd);
350 temp = ast_read32(ast, 0x12040);
351 ast_write32(ast, 0x12040, temp | 0x40);
360 j = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
361 } while ((j & 0x40) == 0);
364 void ast_post_gpu(struct drm_device *dev)
367 struct ast_private *ast = dev->dev_private;
369 pci_read_config_dword(ast->dev->pdev, 0x04, ®);
371 pci_write_config_dword(ast->dev->pdev, 0x04, reg);
375 ast_set_def_ext_reg(dev);
377 if (ast->chip == AST2300 || ast->chip == AST2400)
378 ast_init_dram_2300(dev);
380 ast_init_dram_reg(dev);
385 /* AST 2300 DRAM settings */
389 struct ast2300_dram_param {
411 u32 dll2_finetune_step;
415 * DQSI DLL CBR Setting
417 #define CBR_SIZE0 ((1 << 10) - 1)
418 #define CBR_SIZE1 ((4 << 10) - 1)
419 #define CBR_SIZE2 ((64 << 10) - 1)
420 #define CBR_PASSNUM 5
421 #define CBR_PASSNUM2 5
422 #define CBR_THRESHOLD 10
423 #define CBR_THRESHOLD2 10
424 #define TIMEOUT 5000000
427 static const u32 pattern[8] = {
438 static int mmc_test_burst(struct ast_private *ast, u32 datagen)
442 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
443 ast_moutdwm(ast, 0x1e6e0070, 0x000000c1 | (datagen << 3));
446 data = ast_mindwm(ast, 0x1e6e0070) & 0x3000;
450 if (++timeout > TIMEOUT) {
451 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
455 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
459 static int mmc_test_burst2(struct ast_private *ast, u32 datagen)
463 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
464 ast_moutdwm(ast, 0x1e6e0070, 0x00000041 | (datagen << 3));
467 data = ast_mindwm(ast, 0x1e6e0070) & 0x1000;
468 if (++timeout > TIMEOUT) {
469 ast_moutdwm(ast, 0x1e6e0070, 0x0);
473 data = ast_mindwm(ast, 0x1e6e0078);
474 data = (data | (data >> 16)) & 0xffff;
475 ast_moutdwm(ast, 0x1e6e0070, 0x0);
479 static int mmc_test_single(struct ast_private *ast, u32 datagen)
483 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
484 ast_moutdwm(ast, 0x1e6e0070, 0x000000c5 | (datagen << 3));
487 data = ast_mindwm(ast, 0x1e6e0070) & 0x3000;
490 if (++timeout > TIMEOUT) {
491 ast_moutdwm(ast, 0x1e6e0070, 0x0);
495 ast_moutdwm(ast, 0x1e6e0070, 0x0);
499 static int mmc_test_single2(struct ast_private *ast, u32 datagen)
503 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
504 ast_moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3));
507 data = ast_mindwm(ast, 0x1e6e0070) & 0x1000;
508 if (++timeout > TIMEOUT) {
509 ast_moutdwm(ast, 0x1e6e0070, 0x0);
513 data = ast_mindwm(ast, 0x1e6e0078);
514 data = (data | (data >> 16)) & 0xffff;
515 ast_moutdwm(ast, 0x1e6e0070, 0x0);
519 static int cbr_test(struct ast_private *ast)
523 data = mmc_test_single2(ast, 0);
524 if ((data & 0xff) && (data & 0xff00))
526 for (i = 0; i < 8; i++) {
527 data = mmc_test_burst2(ast, i);
528 if ((data & 0xff) && (data & 0xff00))
533 else if (data & 0xff)
538 static int cbr_scan(struct ast_private *ast)
540 u32 data, data2, patcnt, loop;
543 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
544 ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
545 for (loop = 0; loop < CBR_PASSNUM2; loop++) {
546 if ((data = cbr_test(ast)) != 0) {
553 if (loop == CBR_PASSNUM2)
559 static u32 cbr_test2(struct ast_private *ast)
563 data = mmc_test_burst2(ast, 0);
566 data |= mmc_test_single2(ast, 0);
570 return ~data & 0xffff;
573 static u32 cbr_scan2(struct ast_private *ast)
575 u32 data, data2, patcnt, loop;
578 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
579 ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
580 for (loop = 0; loop < CBR_PASSNUM2; loop++) {
581 if ((data = cbr_test2(ast)) != 0) {
588 if (loop == CBR_PASSNUM2)
594 static u32 cbr_test3(struct ast_private *ast)
596 if (!mmc_test_burst(ast, 0))
598 if (!mmc_test_single(ast, 0))
603 static u32 cbr_scan3(struct ast_private *ast)
607 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
608 ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
609 for (loop = 0; loop < 2; loop++) {
619 static bool finetuneDQI_L(struct ast_private *ast, struct ast2300_dram_param *param)
621 u32 gold_sadj[2], dllmin[16], dllmax[16], dlli, data, cnt, mask, passcnt, retry = 0;
624 for (cnt = 0; cnt < 16; cnt++) {
629 for (dlli = 0; dlli < 76; dlli++) {
630 ast_moutdwm(ast, 0x1E6E0068, 0x00001400 | (dlli << 16) | (dlli << 24));
631 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE1);
632 data = cbr_scan2(ast);
635 for (cnt = 0; cnt < 16; cnt++) {
637 if (dllmin[cnt] > dlli) {
640 if (dllmax[cnt] < dlli) {
647 } else if (passcnt >= CBR_THRESHOLD2) {
653 for (cnt = 0; cnt < 16; cnt++) {
654 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
655 gold_sadj[0] += dllmin[cnt];
666 gold_sadj[0] = gold_sadj[0] >> 4;
667 gold_sadj[1] = gold_sadj[0];
670 for (cnt = 0; cnt < 8; cnt++) {
672 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
674 if (gold_sadj[0] >= dlli) {
675 dlli = ((gold_sadj[0] - dlli) * 19) >> 5;
680 dlli = ((dlli - gold_sadj[0]) * 19) >> 5;
684 dlli = (8 - dlli) & 0x7;
689 ast_moutdwm(ast, 0x1E6E0080, data);
692 for (cnt = 8; cnt < 16; cnt++) {
694 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
696 if (gold_sadj[1] >= dlli) {
697 dlli = ((gold_sadj[1] - dlli) * 19) >> 5;
701 dlli = (dlli - 1) & 0x7;
704 dlli = ((dlli - gold_sadj[1]) * 19) >> 5;
709 dlli = (8 - dlli) & 0x7;
714 ast_moutdwm(ast, 0x1E6E0084, data);
716 } /* finetuneDQI_L */
718 static void finetuneDQSI(struct ast_private *ast)
720 u32 dlli, dqsip, dqidly;
721 u32 reg_mcr18, reg_mcr0c, passcnt[2], diff;
722 u32 g_dqidly, g_dqsip, g_margin, g_side;
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);
732 for (dlli = 0; dlli < 76; dlli++) {
736 for (dqidly = 0; dqidly < 32; dqidly++) {
737 pass[dqidly][0][0] = 0xff;
738 pass[dqidly][0][1] = 0x0;
739 pass[dqidly][1][0] = 0xff;
740 pass[dqidly][1][1] = 0x0;
742 for (dqidly = 0; dqidly < 32; dqidly++) {
743 passcnt[0] = passcnt[1] = 0;
744 for (dqsip = 0; dqsip < 2; dqsip++) {
745 ast_moutdwm(ast, 0x1E6E000C, 0);
746 ast_moutdwm(ast, 0x1E6E0018, reg_mcr18 | (dqidly << 16) | (dqsip << 23));
747 ast_moutdwm(ast, 0x1E6E000C, reg_mcr0c);
748 for (dlli = 0; dlli < 76; dlli++) {
749 ast_moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24));
750 ast_moutdwm(ast, 0x1E6E0070, 0);
751 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE0);
752 if (cbr_scan3(ast)) {
756 tag[dqsip][dlli] = 'P';
757 if (dlli < pass[dqidly][dqsip][0])
758 pass[dqidly][dqsip][0] = (u16) dlli;
759 if (dlli > pass[dqidly][dqsip][1])
760 pass[dqidly][dqsip][1] = (u16) dlli;
761 } else if (passcnt[dqsip] >= 5)
764 pass[dqidly][dqsip][0] = 0xff;
765 pass[dqidly][dqsip][1] = 0x0;
769 if (passcnt[0] == 0 && passcnt[1] == 0)
773 g_dqidly = g_dqsip = g_margin = g_side = 0;
775 for (dqidly = 0; dqidly < 32; dqidly++) {
776 for (dqsip = 0; dqsip < 2; dqsip++) {
777 if (pass[dqidly][dqsip][0] > pass[dqidly][dqsip][1])
779 diff = pass[dqidly][dqsip][1] - pass[dqidly][dqsip][0];
780 if ((diff+2) < g_margin)
782 passcnt[0] = passcnt[1] = 0;
783 for (dlli = pass[dqidly][dqsip][0]; dlli > 0 && tag[dqsip][dlli] != 0; dlli--, passcnt[0]++);
784 for (dlli = pass[dqidly][dqsip][1]; dlli < 76 && tag[dqsip][dlli] != 0; dlli++, passcnt[1]++);
785 if (passcnt[0] > passcnt[1])
786 passcnt[0] = passcnt[1];
788 if (passcnt[0] > g_side)
789 passcnt[1] = passcnt[0] - g_side;
790 if (diff > (g_margin+1) && (passcnt[1] > 0 || passcnt[0] > 8)) {
795 } else if (passcnt[1] > 1 && g_side < 8) {
804 reg_mcr18 = reg_mcr18 | (g_dqidly << 16) | (g_dqsip << 23);
805 ast_moutdwm(ast, 0x1E6E0018, reg_mcr18);
808 static bool cbr_dll2(struct ast_private *ast, struct ast2300_dram_param *param)
810 u32 dllmin[2], dllmax[2], dlli, data, passcnt, retry = 0;
814 if (finetuneDQI_L(ast, param) == false)
818 dllmin[0] = dllmin[1] = 0xff;
819 dllmax[0] = dllmax[1] = 0x0;
821 for (dlli = 0; dlli < 76; dlli++) {
822 ast_moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24));
823 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE2);
824 data = cbr_scan(ast);
827 if (dllmin[0] > dlli) {
830 if (dllmax[0] < dlli) {
835 if (dllmin[1] > dlli) {
838 if (dllmax[1] < dlli) {
843 } else if (passcnt >= CBR_THRESHOLD) {
849 if (dllmax[0] == 0 || (dllmax[0]-dllmin[0]) < CBR_THRESHOLD) {
852 if (dllmax[1] == 0 || (dllmax[1]-dllmin[1]) < CBR_THRESHOLD) {
857 dlli = (dllmin[1] + dllmax[1]) >> 1;
859 dlli += (dllmin[0] + dllmax[0]) >> 1;
860 ast_moutdwm(ast, 0x1E6E0068, ast_mindwm(ast, 0x1E720058) | (dlli << 16));
864 static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *param)
866 u32 trap, trap_AC2, trap_MRS;
868 ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
871 trap = (ast_mindwm(ast, 0x1E6E2070) >> 25) & 0x3;
872 trap_AC2 = 0x00020000 + (trap << 16);
873 trap_AC2 |= 0x00300000 + ((trap & 0x2) << 19);
874 trap_MRS = 0x00000010 + (trap << 4);
875 trap_MRS |= ((trap & 0x2) << 18);
877 param->reg_MADJ = 0x00034C4C;
878 param->reg_SADJ = 0x00001800;
879 param->reg_DRV = 0x000000F0;
880 param->reg_PERIOD = param->dram_freq;
883 switch (param->dram_freq) {
885 ast_moutdwm(ast, 0x1E6E2020, 0x0190);
887 param->reg_AC1 = 0x22202725;
888 param->reg_AC2 = 0xAA007613 | trap_AC2;
889 param->reg_DQSIC = 0x000000BA;
890 param->reg_MRS = 0x04001400 | trap_MRS;
891 param->reg_EMRS = 0x00000000;
892 param->reg_IOZ = 0x00000023;
893 param->reg_DQIDLY = 0x00000074;
894 param->reg_FREQ = 0x00004DC0;
895 param->madj_max = 96;
896 param->dll2_finetune_step = 3;
897 switch (param->dram_chipid) {
899 case AST_DRAM_512Mx16:
901 param->reg_AC2 = 0xAA007613 | trap_AC2;
904 param->reg_AC2 = 0xAA00761C | trap_AC2;
907 param->reg_AC2 = 0xAA007636 | trap_AC2;
913 ast_moutdwm(ast, 0x1E6E2020, 0x03F1);
915 param->reg_AC1 = 0x33302825;
916 param->reg_AC2 = 0xCC009617 | trap_AC2;
917 param->reg_DQSIC = 0x000000E2;
918 param->reg_MRS = 0x04001600 | trap_MRS;
919 param->reg_EMRS = 0x00000000;
920 param->reg_IOZ = 0x00000034;
921 param->reg_DRV = 0x000000FA;
922 param->reg_DQIDLY = 0x00000089;
923 param->reg_FREQ = 0x00005040;
924 param->madj_max = 96;
925 param->dll2_finetune_step = 4;
927 switch (param->dram_chipid) {
929 case AST_DRAM_512Mx16:
931 param->reg_AC2 = 0xCC009617 | trap_AC2;
934 param->reg_AC2 = 0xCC009622 | trap_AC2;
937 param->reg_AC2 = 0xCC00963F | trap_AC2;
943 ast_moutdwm(ast, 0x1E6E2020, 0x01F0);
945 param->reg_AC1 = 0x33302825;
946 param->reg_AC2 = 0xCC009617 | trap_AC2;
947 param->reg_DQSIC = 0x000000E2;
948 param->reg_MRS = 0x04001600 | trap_MRS;
949 param->reg_EMRS = 0x00000000;
950 param->reg_IOZ = 0x00000023;
951 param->reg_DRV = 0x000000FA;
952 param->reg_DQIDLY = 0x00000089;
953 param->reg_FREQ = 0x000050C0;
954 param->madj_max = 96;
955 param->dll2_finetune_step = 4;
957 switch (param->dram_chipid) {
959 case AST_DRAM_512Mx16:
961 param->reg_AC2 = 0xCC009617 | trap_AC2;
964 param->reg_AC2 = 0xCC009622 | trap_AC2;
967 param->reg_AC2 = 0xCC00963F | trap_AC2;
973 ast_moutdwm(ast, 0x1E6E2020, 0x0230);
975 param->reg_AC1 = 0x33302926;
976 param->reg_AC2 = 0xCD44961A;
977 param->reg_DQSIC = 0x000000FC;
978 param->reg_MRS = 0x00081830;
979 param->reg_EMRS = 0x00000000;
980 param->reg_IOZ = 0x00000045;
981 param->reg_DQIDLY = 0x00000097;
982 param->reg_FREQ = 0x000052C0;
983 param->madj_max = 88;
984 param->dll2_finetune_step = 4;
987 ast_moutdwm(ast, 0x1E6E2020, 0x0270);
989 param->reg_AC1 = 0x33302926;
990 param->reg_AC2 = 0xDE44A61D;
991 param->reg_DQSIC = 0x00000117;
992 param->reg_MRS = 0x00081A30;
993 param->reg_EMRS = 0x00000000;
994 param->reg_IOZ = 0x070000BB;
995 param->reg_DQIDLY = 0x000000A0;
996 param->reg_FREQ = 0x000054C0;
997 param->madj_max = 79;
998 param->dll2_finetune_step = 4;
1001 ast_moutdwm(ast, 0x1E6E2020, 0x0290);
1004 param->reg_AC1 = 0x33302926;
1005 param->reg_AC2 = 0xEF44B61E;
1006 param->reg_DQSIC = 0x00000125;
1007 param->reg_MRS = 0x00081A30;
1008 param->reg_EMRS = 0x00000040;
1009 param->reg_DRV = 0x000000F5;
1010 param->reg_IOZ = 0x00000023;
1011 param->reg_DQIDLY = 0x00000088;
1012 param->reg_FREQ = 0x000055C0;
1013 param->madj_max = 76;
1014 param->dll2_finetune_step = 3;
1017 ast_moutdwm(ast, 0x1E6E2020, 0x0140);
1018 param->reg_MADJ = 0x00136868;
1019 param->reg_SADJ = 0x00004534;
1022 param->reg_AC1 = 0x33302A37;
1023 param->reg_AC2 = 0xEF56B61E;
1024 param->reg_DQSIC = 0x0000013F;
1025 param->reg_MRS = 0x00101A50;
1026 param->reg_EMRS = 0x00000040;
1027 param->reg_DRV = 0x000000FA;
1028 param->reg_IOZ = 0x00000023;
1029 param->reg_DQIDLY = 0x00000078;
1030 param->reg_FREQ = 0x000057C0;
1031 param->madj_max = 136;
1032 param->dll2_finetune_step = 3;
1035 ast_moutdwm(ast, 0x1E6E2020, 0x02E1);
1036 param->reg_MADJ = 0x00136868;
1037 param->reg_SADJ = 0x00004534;
1040 param->reg_AC1 = 0x32302A37;
1041 param->reg_AC2 = 0xDF56B61F;
1042 param->reg_DQSIC = 0x0000014D;
1043 param->reg_MRS = 0x00101A50;
1044 param->reg_EMRS = 0x00000004;
1045 param->reg_DRV = 0x000000F5;
1046 param->reg_IOZ = 0x00000023;
1047 param->reg_DQIDLY = 0x00000078;
1048 param->reg_FREQ = 0x000058C0;
1049 param->madj_max = 132;
1050 param->dll2_finetune_step = 3;
1053 ast_moutdwm(ast, 0x1E6E2020, 0x0160);
1054 param->reg_MADJ = 0x00136868;
1055 param->reg_SADJ = 0x00004534;
1058 param->reg_AC1 = 0x32302A37;
1059 param->reg_AC2 = 0xEF56B621;
1060 param->reg_DQSIC = 0x0000015A;
1061 param->reg_MRS = 0x02101A50;
1062 param->reg_EMRS = 0x00000004;
1063 param->reg_DRV = 0x000000F5;
1064 param->reg_IOZ = 0x00000034;
1065 param->reg_DQIDLY = 0x00000078;
1066 param->reg_FREQ = 0x000059C0;
1067 param->madj_max = 128;
1068 param->dll2_finetune_step = 3;
1072 switch (param->dram_chipid) {
1073 case AST_DRAM_512Mx16:
1074 param->dram_config = 0x130;
1077 case AST_DRAM_1Gx16:
1078 param->dram_config = 0x131;
1080 case AST_DRAM_2Gx16:
1081 param->dram_config = 0x132;
1083 case AST_DRAM_4Gx16:
1084 param->dram_config = 0x133;
1088 switch (param->vram_size) {
1090 case AST_VIDMEM_SIZE_8M:
1091 param->dram_config |= 0x00;
1093 case AST_VIDMEM_SIZE_16M:
1094 param->dram_config |= 0x04;
1096 case AST_VIDMEM_SIZE_32M:
1097 param->dram_config |= 0x08;
1099 case AST_VIDMEM_SIZE_64M:
1100 param->dram_config |= 0x0c;
1106 static void ddr3_init(struct ast_private *ast, struct ast2300_dram_param *param)
1108 u32 data, data2, retry = 0;
1111 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1112 ast_moutdwm(ast, 0x1E6E0018, 0x00000100);
1113 ast_moutdwm(ast, 0x1E6E0024, 0x00000000);
1114 ast_moutdwm(ast, 0x1E6E0034, 0x00000000);
1116 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ);
1117 ast_moutdwm(ast, 0x1E6E0068, param->reg_SADJ);
1119 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000);
1122 ast_moutdwm(ast, 0x1E6E0004, param->dram_config);
1123 ast_moutdwm(ast, 0x1E6E0008, 0x90040f);
1124 ast_moutdwm(ast, 0x1E6E0010, param->reg_AC1);
1125 ast_moutdwm(ast, 0x1E6E0014, param->reg_AC2);
1126 ast_moutdwm(ast, 0x1E6E0020, param->reg_DQSIC);
1127 ast_moutdwm(ast, 0x1E6E0080, 0x00000000);
1128 ast_moutdwm(ast, 0x1E6E0084, 0x00000000);
1129 ast_moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY);
1130 ast_moutdwm(ast, 0x1E6E0018, 0x4000A170);
1131 ast_moutdwm(ast, 0x1E6E0018, 0x00002370);
1132 ast_moutdwm(ast, 0x1E6E0038, 0x00000000);
1133 ast_moutdwm(ast, 0x1E6E0040, 0xFF444444);
1134 ast_moutdwm(ast, 0x1E6E0044, 0x22222222);
1135 ast_moutdwm(ast, 0x1E6E0048, 0x22222222);
1136 ast_moutdwm(ast, 0x1E6E004C, 0x00000002);
1137 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1138 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1139 ast_moutdwm(ast, 0x1E6E0054, 0);
1140 ast_moutdwm(ast, 0x1E6E0060, param->reg_DRV);
1141 ast_moutdwm(ast, 0x1E6E006C, param->reg_IOZ);
1142 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1143 ast_moutdwm(ast, 0x1E6E0074, 0x00000000);
1144 ast_moutdwm(ast, 0x1E6E0078, 0x00000000);
1145 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1146 /* Wait MCLK2X lock to MCLK */
1148 data = ast_mindwm(ast, 0x1E6E001C);
1149 } while (!(data & 0x08000000));
1150 data = ast_mindwm(ast, 0x1E6E001C);
1151 data = (data >> 8) & 0xff;
1152 while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) {
1153 data2 = (ast_mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4;
1154 if ((data2 & 0xff) > param->madj_max) {
1157 ast_moutdwm(ast, 0x1E6E0064, data2);
1158 if (data2 & 0x00100000) {
1159 data2 = ((data2 & 0xff) >> 3) + 3;
1161 data2 = ((data2 & 0xff) >> 2) + 5;
1163 data = ast_mindwm(ast, 0x1E6E0068) & 0xffff00ff;
1164 data2 += data & 0xff;
1165 data = data | (data2 << 8);
1166 ast_moutdwm(ast, 0x1E6E0068, data);
1168 ast_moutdwm(ast, 0x1E6E0064, ast_mindwm(ast, 0x1E6E0064) | 0xC0000);
1170 data = ast_mindwm(ast, 0x1E6E0018) & 0xfffff1ff;
1171 ast_moutdwm(ast, 0x1E6E0018, data);
1172 data = data | 0x200;
1173 ast_moutdwm(ast, 0x1E6E0018, data);
1175 data = ast_mindwm(ast, 0x1E6E001C);
1176 } while (!(data & 0x08000000));
1178 data = ast_mindwm(ast, 0x1E6E001C);
1179 data = (data >> 8) & 0xff;
1181 ast_moutdwm(ast, 0x1E720058, ast_mindwm(ast, 0x1E6E0068) & 0xffff);
1182 data = ast_mindwm(ast, 0x1E6E0018) | 0xC00;
1183 ast_moutdwm(ast, 0x1E6E0018, data);
1185 ast_moutdwm(ast, 0x1E6E0034, 0x00000001);
1186 ast_moutdwm(ast, 0x1E6E000C, 0x00000040);
1188 /* Mode Register Setting */
1189 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100);
1190 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1191 ast_moutdwm(ast, 0x1E6E0028, 0x00000005);
1192 ast_moutdwm(ast, 0x1E6E0028, 0x00000007);
1193 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1194 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1195 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS);
1196 ast_moutdwm(ast, 0x1E6E000C, 0x00005C08);
1197 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1199 ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
1205 data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3);
1207 ast_moutdwm(ast, 0x1E6E0034, data | 0x3);
1209 /* Calibrate the DQSI delay */
1210 if ((cbr_dll2(ast, param) == false) && (retry++ < 10))
1211 goto ddr3_init_start;
1213 ast_moutdwm(ast, 0x1E6E0120, param->reg_FREQ);
1214 /* ECC Memory Initialization */
1216 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1217 ast_moutdwm(ast, 0x1E6E0070, 0x221);
1219 data = ast_mindwm(ast, 0x1E6E0070);
1220 } while (!(data & 0x00001000));
1221 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1222 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1223 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1229 static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *param)
1231 u32 trap, trap_AC2, trap_MRS;
1233 ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
1236 trap = (ast_mindwm(ast, 0x1E6E2070) >> 25) & 0x3;
1237 trap_AC2 = (trap << 20) | (trap << 16);
1238 trap_AC2 += 0x00110000;
1239 trap_MRS = 0x00000040 | (trap << 4);
1242 param->reg_MADJ = 0x00034C4C;
1243 param->reg_SADJ = 0x00001800;
1244 param->reg_DRV = 0x000000F0;
1245 param->reg_PERIOD = param->dram_freq;
1248 switch (param->dram_freq) {
1250 ast_moutdwm(ast, 0x1E6E2020, 0x0130);
1252 param->reg_AC1 = 0x11101513;
1253 param->reg_AC2 = 0x78117011;
1254 param->reg_DQSIC = 0x00000092;
1255 param->reg_MRS = 0x00000842;
1256 param->reg_EMRS = 0x00000000;
1257 param->reg_DRV = 0x000000F0;
1258 param->reg_IOZ = 0x00000034;
1259 param->reg_DQIDLY = 0x0000005A;
1260 param->reg_FREQ = 0x00004AC0;
1261 param->madj_max = 138;
1262 param->dll2_finetune_step = 3;
1265 ast_moutdwm(ast, 0x1E6E2020, 0x0190);
1267 param->reg_AC1 = 0x22202613;
1268 param->reg_AC2 = 0xAA009016 | trap_AC2;
1269 param->reg_DQSIC = 0x000000BA;
1270 param->reg_MRS = 0x00000A02 | trap_MRS;
1271 param->reg_EMRS = 0x00000040;
1272 param->reg_DRV = 0x000000FA;
1273 param->reg_IOZ = 0x00000034;
1274 param->reg_DQIDLY = 0x00000074;
1275 param->reg_FREQ = 0x00004DC0;
1276 param->madj_max = 96;
1277 param->dll2_finetune_step = 3;
1278 switch (param->dram_chipid) {
1280 case AST_DRAM_512Mx16:
1281 param->reg_AC2 = 0xAA009012 | trap_AC2;
1283 case AST_DRAM_1Gx16:
1284 param->reg_AC2 = 0xAA009016 | trap_AC2;
1286 case AST_DRAM_2Gx16:
1287 param->reg_AC2 = 0xAA009023 | trap_AC2;
1289 case AST_DRAM_4Gx16:
1290 param->reg_AC2 = 0xAA00903B | trap_AC2;
1296 ast_moutdwm(ast, 0x1E6E2020, 0x03F1);
1299 param->reg_AC1 = 0x33302714;
1300 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1301 param->reg_DQSIC = 0x000000E2;
1302 param->reg_MRS = 0x00000C02 | trap_MRS;
1303 param->reg_EMRS = 0x00000040;
1304 param->reg_DRV = 0x000000FA;
1305 param->reg_IOZ = 0x00000034;
1306 param->reg_DQIDLY = 0x00000089;
1307 param->reg_FREQ = 0x00005040;
1308 param->madj_max = 96;
1309 param->dll2_finetune_step = 4;
1311 switch (param->dram_chipid) {
1312 case AST_DRAM_512Mx16:
1313 param->reg_AC2 = 0xCC00B016 | trap_AC2;
1316 case AST_DRAM_1Gx16:
1317 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1319 case AST_DRAM_2Gx16:
1320 param->reg_AC2 = 0xCC00B02B | trap_AC2;
1322 case AST_DRAM_4Gx16:
1323 param->reg_AC2 = 0xCC00B03F | trap_AC2;
1330 ast_moutdwm(ast, 0x1E6E2020, 0x01F0);
1333 param->reg_AC1 = 0x33302714;
1334 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1335 param->reg_DQSIC = 0x000000E2;
1336 param->reg_MRS = 0x00000C02 | trap_MRS;
1337 param->reg_EMRS = 0x00000040;
1338 param->reg_DRV = 0x000000FA;
1339 param->reg_IOZ = 0x00000034;
1340 param->reg_DQIDLY = 0x00000089;
1341 param->reg_FREQ = 0x000050C0;
1342 param->madj_max = 96;
1343 param->dll2_finetune_step = 4;
1345 switch (param->dram_chipid) {
1346 case AST_DRAM_512Mx16:
1347 param->reg_AC2 = 0xCC00B016 | trap_AC2;
1350 case AST_DRAM_1Gx16:
1351 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1353 case AST_DRAM_2Gx16:
1354 param->reg_AC2 = 0xCC00B02B | trap_AC2;
1356 case AST_DRAM_4Gx16:
1357 param->reg_AC2 = 0xCC00B03F | trap_AC2;
1363 ast_moutdwm(ast, 0x1E6E2020, 0x0230);
1365 param->reg_AC1 = 0x33302815;
1366 param->reg_AC2 = 0xCD44B01E;
1367 param->reg_DQSIC = 0x000000FC;
1368 param->reg_MRS = 0x00000E72;
1369 param->reg_EMRS = 0x00000000;
1370 param->reg_DRV = 0x00000000;
1371 param->reg_IOZ = 0x00000034;
1372 param->reg_DQIDLY = 0x00000097;
1373 param->reg_FREQ = 0x000052C0;
1374 param->madj_max = 88;
1375 param->dll2_finetune_step = 3;
1378 ast_moutdwm(ast, 0x1E6E2020, 0x0261);
1381 param->reg_AC1 = 0x33302815;
1382 param->reg_AC2 = 0xDE44C022;
1383 param->reg_DQSIC = 0x00000117;
1384 param->reg_MRS = 0x00000E72;
1385 param->reg_EMRS = 0x00000040;
1386 param->reg_DRV = 0x0000000A;
1387 param->reg_IOZ = 0x00000045;
1388 param->reg_DQIDLY = 0x000000A0;
1389 param->reg_FREQ = 0x000054C0;
1390 param->madj_max = 79;
1391 param->dll2_finetune_step = 3;
1394 ast_moutdwm(ast, 0x1E6E2020, 0x0120);
1397 param->reg_AC1 = 0x33302815;
1398 param->reg_AC2 = 0xEF44D024;
1399 param->reg_DQSIC = 0x00000125;
1400 param->reg_MRS = 0x00000E72;
1401 param->reg_EMRS = 0x00000004;
1402 param->reg_DRV = 0x000000F9;
1403 param->reg_IOZ = 0x00000045;
1404 param->reg_DQIDLY = 0x000000A7;
1405 param->reg_FREQ = 0x000055C0;
1406 param->madj_max = 76;
1407 param->dll2_finetune_step = 3;
1410 ast_moutdwm(ast, 0x1E6E2020, 0x02A1);
1413 param->reg_AC1 = 0x43402915;
1414 param->reg_AC2 = 0xFF44E025;
1415 param->reg_DQSIC = 0x00000132;
1416 param->reg_MRS = 0x00000E72;
1417 param->reg_EMRS = 0x00000040;
1418 param->reg_DRV = 0x0000000A;
1419 param->reg_IOZ = 0x00000045;
1420 param->reg_DQIDLY = 0x000000AD;
1421 param->reg_FREQ = 0x000056C0;
1422 param->madj_max = 76;
1423 param->dll2_finetune_step = 3;
1426 ast_moutdwm(ast, 0x1E6E2020, 0x0140);
1429 param->reg_AC1 = 0x43402915;
1430 param->reg_AC2 = 0xFF44E027;
1431 param->reg_DQSIC = 0x0000013F;
1432 param->reg_MRS = 0x00000E72;
1433 param->reg_EMRS = 0x00000004;
1434 param->reg_DRV = 0x000000F5;
1435 param->reg_IOZ = 0x00000045;
1436 param->reg_DQIDLY = 0x000000B3;
1437 param->reg_FREQ = 0x000057C0;
1438 param->madj_max = 76;
1439 param->dll2_finetune_step = 3;
1443 switch (param->dram_chipid) {
1444 case AST_DRAM_512Mx16:
1445 param->dram_config = 0x100;
1448 case AST_DRAM_1Gx16:
1449 param->dram_config = 0x121;
1451 case AST_DRAM_2Gx16:
1452 param->dram_config = 0x122;
1454 case AST_DRAM_4Gx16:
1455 param->dram_config = 0x123;
1459 switch (param->vram_size) {
1461 case AST_VIDMEM_SIZE_8M:
1462 param->dram_config |= 0x00;
1464 case AST_VIDMEM_SIZE_16M:
1465 param->dram_config |= 0x04;
1467 case AST_VIDMEM_SIZE_32M:
1468 param->dram_config |= 0x08;
1470 case AST_VIDMEM_SIZE_64M:
1471 param->dram_config |= 0x0c;
1476 static void ddr2_init(struct ast_private *ast, struct ast2300_dram_param *param)
1478 u32 data, data2, retry = 0;
1481 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1482 ast_moutdwm(ast, 0x1E6E0018, 0x00000100);
1483 ast_moutdwm(ast, 0x1E6E0024, 0x00000000);
1484 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ);
1485 ast_moutdwm(ast, 0x1E6E0068, param->reg_SADJ);
1487 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000);
1490 ast_moutdwm(ast, 0x1E6E0004, param->dram_config);
1491 ast_moutdwm(ast, 0x1E6E0008, 0x90040f);
1492 ast_moutdwm(ast, 0x1E6E0010, param->reg_AC1);
1493 ast_moutdwm(ast, 0x1E6E0014, param->reg_AC2);
1494 ast_moutdwm(ast, 0x1E6E0020, param->reg_DQSIC);
1495 ast_moutdwm(ast, 0x1E6E0080, 0x00000000);
1496 ast_moutdwm(ast, 0x1E6E0084, 0x00000000);
1497 ast_moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY);
1498 ast_moutdwm(ast, 0x1E6E0018, 0x4000A130);
1499 ast_moutdwm(ast, 0x1E6E0018, 0x00002330);
1500 ast_moutdwm(ast, 0x1E6E0038, 0x00000000);
1501 ast_moutdwm(ast, 0x1E6E0040, 0xFF808000);
1502 ast_moutdwm(ast, 0x1E6E0044, 0x88848466);
1503 ast_moutdwm(ast, 0x1E6E0048, 0x44440008);
1504 ast_moutdwm(ast, 0x1E6E004C, 0x00000000);
1505 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1506 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1507 ast_moutdwm(ast, 0x1E6E0054, 0);
1508 ast_moutdwm(ast, 0x1E6E0060, param->reg_DRV);
1509 ast_moutdwm(ast, 0x1E6E006C, param->reg_IOZ);
1510 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1511 ast_moutdwm(ast, 0x1E6E0074, 0x00000000);
1512 ast_moutdwm(ast, 0x1E6E0078, 0x00000000);
1513 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1515 /* Wait MCLK2X lock to MCLK */
1517 data = ast_mindwm(ast, 0x1E6E001C);
1518 } while (!(data & 0x08000000));
1519 data = ast_mindwm(ast, 0x1E6E001C);
1520 data = (data >> 8) & 0xff;
1521 while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) {
1522 data2 = (ast_mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4;
1523 if ((data2 & 0xff) > param->madj_max) {
1526 ast_moutdwm(ast, 0x1E6E0064, data2);
1527 if (data2 & 0x00100000) {
1528 data2 = ((data2 & 0xff) >> 3) + 3;
1530 data2 = ((data2 & 0xff) >> 2) + 5;
1532 data = ast_mindwm(ast, 0x1E6E0068) & 0xffff00ff;
1533 data2 += data & 0xff;
1534 data = data | (data2 << 8);
1535 ast_moutdwm(ast, 0x1E6E0068, data);
1537 ast_moutdwm(ast, 0x1E6E0064, ast_mindwm(ast, 0x1E6E0064) | 0xC0000);
1539 data = ast_mindwm(ast, 0x1E6E0018) & 0xfffff1ff;
1540 ast_moutdwm(ast, 0x1E6E0018, data);
1541 data = data | 0x200;
1542 ast_moutdwm(ast, 0x1E6E0018, data);
1544 data = ast_mindwm(ast, 0x1E6E001C);
1545 } while (!(data & 0x08000000));
1547 data = ast_mindwm(ast, 0x1E6E001C);
1548 data = (data >> 8) & 0xff;
1550 ast_moutdwm(ast, 0x1E720058, ast_mindwm(ast, 0x1E6E0008) & 0xffff);
1551 data = ast_mindwm(ast, 0x1E6E0018) | 0xC00;
1552 ast_moutdwm(ast, 0x1E6E0018, data);
1554 ast_moutdwm(ast, 0x1E6E0034, 0x00000001);
1555 ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
1557 /* Mode Register Setting */
1558 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100);
1559 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1560 ast_moutdwm(ast, 0x1E6E0028, 0x00000005);
1561 ast_moutdwm(ast, 0x1E6E0028, 0x00000007);
1562 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1563 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1565 ast_moutdwm(ast, 0x1E6E000C, 0x00005C08);
1566 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS);
1567 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1568 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS | 0x380);
1569 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1570 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1571 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1573 ast_moutdwm(ast, 0x1E6E000C, 0x7FFF5C01);
1579 data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3);
1581 ast_moutdwm(ast, 0x1E6E0034, data | 0x3);
1582 ast_moutdwm(ast, 0x1E6E0120, param->reg_FREQ);
1584 /* Calibrate the DQSI delay */
1585 if ((cbr_dll2(ast, param) == false) && (retry++ < 10))
1586 goto ddr2_init_start;
1588 /* ECC Memory Initialization */
1590 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1591 ast_moutdwm(ast, 0x1E6E0070, 0x221);
1593 data = ast_mindwm(ast, 0x1E6E0070);
1594 } while (!(data & 0x00001000));
1595 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1596 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1597 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1602 static void ast_init_dram_2300(struct drm_device *dev)
1604 struct ast_private *ast = dev->dev_private;
1605 struct ast2300_dram_param param;
1609 reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
1610 if ((reg & 0x80) == 0) {/* vga only */
1611 ast_write32(ast, 0xf004, 0x1e6e0000);
1612 ast_write32(ast, 0xf000, 0x1);
1613 ast_write32(ast, 0x12000, 0x1688a8a8);
1616 } while (ast_read32(ast, 0x12000) != 0x1);
1618 ast_write32(ast, 0x10000, 0xfc600309);
1621 } while (ast_read32(ast, 0x10000) != 0x1);
1623 /* Slow down CPU/AHB CLK in VGA only mode */
1624 temp = ast_read32(ast, 0x12008);
1626 ast_write32(ast, 0x12008, temp);
1628 param.dram_type = AST_DDR3;
1629 if (temp & 0x01000000)
1630 param.dram_type = AST_DDR2;
1631 param.dram_chipid = ast->dram_type;
1632 param.dram_freq = ast->mclk;
1633 param.vram_size = ast->vram_size;
1635 if (param.dram_type == AST_DDR3) {
1636 get_ddr3_info(ast, ¶m);
1637 ddr3_init(ast, ¶m);
1639 get_ddr2_info(ast, ¶m);
1640 ddr2_init(ast, ¶m);
1643 temp = ast_mindwm(ast, 0x1e6e2040);
1644 ast_moutdwm(ast, 0x1e6e2040, temp | 0x40);
1649 reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
1650 } while ((reg & 0x40) == 0);