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
29 #include <linux/delay.h>
30 #include <linux/pci.h>
32 #include <drm/drm_print.h>
34 #include "ast_dram_tables.h"
37 static void ast_post_chip_2300(struct ast_device *ast);
38 static void ast_post_chip_2500(struct ast_device *ast);
40 static const u8 extreginfo[] = { 0x0f, 0x04, 0x1c, 0xff };
41 static const u8 extreginfo_ast2300[] = { 0x0f, 0x04, 0x1f, 0xff };
43 static void ast_set_def_ext_reg(struct ast_device *ast)
46 const u8 *ext_reg_info;
49 for (i = 0x81; i <= 0x9f; i++)
50 ast_set_index_reg(ast, AST_IO_VGACRI, i, 0x00);
52 if (IS_AST_GEN4(ast) || IS_AST_GEN5(ast) || IS_AST_GEN6(ast))
53 ext_reg_info = extreginfo_ast2300;
55 ext_reg_info = extreginfo;
58 while (*ext_reg_info != 0xff) {
59 ast_set_index_reg_mask(ast, AST_IO_VGACRI, index, 0x00, *ext_reg_info);
64 /* disable standard IO/MEM decode if secondary */
65 /* ast_set_index_reg-mask(ast, AST_IO_VGACRI, 0xa1, 0xff, 0x3); */
67 /* Set Ext. Default */
68 ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0x8c, 0x00, 0x01);
69 ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb7, 0x00, 0x00);
71 /* Enable RAMDAC for A1 */
73 if (IS_AST_GEN4(ast) || IS_AST_GEN5(ast) || IS_AST_GEN6(ast))
75 ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xff, reg);
78 static u32 __ast_mindwm(void __iomem *regs, u32 r)
82 __ast_write32(regs, 0xf004, r & 0xffff0000);
83 __ast_write32(regs, 0xf000, 0x1);
86 data = __ast_read32(regs, 0xf004) & 0xffff0000;
87 } while (data != (r & 0xffff0000));
89 return __ast_read32(regs, 0x10000 + (r & 0x0000ffff));
92 static void __ast_moutdwm(void __iomem *regs, u32 r, u32 v)
96 __ast_write32(regs, 0xf004, r & 0xffff0000);
97 __ast_write32(regs, 0xf000, 0x1);
100 data = __ast_read32(regs, 0xf004) & 0xffff0000;
101 } while (data != (r & 0xffff0000));
103 __ast_write32(regs, 0x10000 + (r & 0x0000ffff), v);
106 u32 ast_mindwm(struct ast_device *ast, u32 r)
108 return __ast_mindwm(ast->regs, r);
111 void ast_moutdwm(struct ast_device *ast, u32 r, u32 v)
113 __ast_moutdwm(ast->regs, r, v);
117 * AST2100/2150 DLL CBR Setting
119 #define CBR_SIZE_AST2150 ((16 << 10) - 1)
120 #define CBR_PASSNUM_AST2150 5
121 #define CBR_THRESHOLD_AST2150 10
122 #define CBR_THRESHOLD2_AST2150 10
123 #define TIMEOUT_AST2150 5000000
125 #define CBR_PATNUM_AST2150 8
127 static const u32 pattern_AST2150[14] = {
144 static u32 mmctestburst2_ast2150(struct ast_device *ast, u32 datagen)
148 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
149 ast_moutdwm(ast, 0x1e6e0070, 0x00000001 | (datagen << 3));
152 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
153 if (++timeout > TIMEOUT_AST2150) {
154 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
158 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
159 ast_moutdwm(ast, 0x1e6e0070, 0x00000003 | (datagen << 3));
162 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
163 if (++timeout > TIMEOUT_AST2150) {
164 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
168 data = (ast_mindwm(ast, 0x1e6e0070) & 0x80) >> 7;
169 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
173 #if 0 /* unused in DDX driver - here for completeness */
174 static u32 mmctestsingle2_ast2150(struct ast_device *ast, u32 datagen)
178 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
179 ast_moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3));
182 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
183 if (++timeout > TIMEOUT_AST2150) {
184 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
188 data = (ast_mindwm(ast, 0x1e6e0070) & 0x80) >> 7;
189 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
194 static int cbrtest_ast2150(struct ast_device *ast)
198 for (i = 0; i < 8; i++)
199 if (mmctestburst2_ast2150(ast, i))
204 static int cbrscan_ast2150(struct ast_device *ast, int busw)
208 for (patcnt = 0; patcnt < CBR_PATNUM_AST2150; patcnt++) {
209 ast_moutdwm(ast, 0x1e6e007c, pattern_AST2150[patcnt]);
210 for (loop = 0; loop < CBR_PASSNUM_AST2150; loop++) {
211 if (cbrtest_ast2150(ast))
214 if (loop == CBR_PASSNUM_AST2150)
221 static void cbrdlli_ast2150(struct ast_device *ast, int busw)
223 u32 dll_min[4], dll_max[4], dlli, data, passcnt;
226 dll_min[0] = dll_min[1] = dll_min[2] = dll_min[3] = 0xff;
227 dll_max[0] = dll_max[1] = dll_max[2] = dll_max[3] = 0x0;
230 for (dlli = 0; dlli < 100; dlli++) {
231 ast_moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24));
232 data = cbrscan_ast2150(ast, busw);
235 if (dll_min[0] > dlli)
237 if (dll_max[0] < dlli)
241 } else if (passcnt >= CBR_THRESHOLD_AST2150)
244 if (dll_max[0] == 0 || (dll_max[0]-dll_min[0]) < CBR_THRESHOLD_AST2150)
247 dlli = dll_min[0] + (((dll_max[0] - dll_min[0]) * 7) >> 4);
248 ast_moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24));
253 static void ast_init_dram_reg(struct ast_device *ast)
257 const struct ast_dramstruct *dram_reg_info;
259 j = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
261 if ((j & 0x80) == 0) { /* VGA only */
262 if (IS_AST_GEN1(ast)) {
263 dram_reg_info = ast2000_dram_table_data;
264 ast_write32(ast, 0xf004, 0x1e6e0000);
265 ast_write32(ast, 0xf000, 0x1);
266 ast_write32(ast, 0x10100, 0xa8);
270 } while (ast_read32(ast, 0x10100) != 0xa8);
271 } else { /* GEN2/GEN3 */
272 if (ast->chip == AST2100 || ast->chip == AST2200)
273 dram_reg_info = ast2100_dram_table_data;
275 dram_reg_info = ast1100_dram_table_data;
277 ast_write32(ast, 0xf004, 0x1e6e0000);
278 ast_write32(ast, 0xf000, 0x1);
279 ast_write32(ast, 0x12000, 0x1688A8A8);
282 } while (ast_read32(ast, 0x12000) != 0x01);
284 ast_write32(ast, 0x10000, 0xfc600309);
287 } while (ast_read32(ast, 0x10000) != 0x01);
290 while (dram_reg_info->index != 0xffff) {
291 if (dram_reg_info->index == 0xff00) {/* delay fn */
292 for (i = 0; i < 15; i++)
293 udelay(dram_reg_info->data);
294 } else if (dram_reg_info->index == 0x4 && !IS_AST_GEN1(ast)) {
295 data = dram_reg_info->data;
296 if (ast->dram_type == AST_DRAM_1Gx16)
298 else if (ast->dram_type == AST_DRAM_1Gx32)
301 temp = ast_read32(ast, 0x12070);
304 ast_write32(ast, 0x10000 + dram_reg_info->index, data | temp);
306 ast_write32(ast, 0x10000 + dram_reg_info->index, dram_reg_info->data);
310 /* AST 2100/2150 DRAM calibration */
311 data = ast_read32(ast, 0x10120);
312 if (data == 0x5061) { /* 266Mhz */
313 data = ast_read32(ast, 0x10004);
315 cbrdlli_ast2150(ast, 16); /* 16 bits */
317 cbrdlli_ast2150(ast, 32); /* 32 bits */
320 switch (AST_GEN(ast)) {
322 temp = ast_read32(ast, 0x10140);
323 ast_write32(ast, 0x10140, temp | 0x40);
327 temp = ast_read32(ast, 0x1200c);
328 ast_write32(ast, 0x1200c, temp & 0xfffffffd);
329 temp = ast_read32(ast, 0x12040);
330 ast_write32(ast, 0x12040, temp | 0x40);
339 j = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
340 } while ((j & 0x40) == 0);
343 void ast_post_gpu(struct ast_device *ast)
345 ast_set_def_ext_reg(ast);
347 if (IS_AST_GEN7(ast)) {
348 if (ast->tx_chip == AST_TX_ASTDP)
350 } else if (ast->config_mode == ast_use_p2a) {
351 if (IS_AST_GEN6(ast))
352 ast_post_chip_2500(ast);
353 else if (IS_AST_GEN5(ast) || IS_AST_GEN4(ast))
354 ast_post_chip_2300(ast);
356 ast_init_dram_reg(ast);
360 if (ast->tx_chip == AST_TX_SIL164)
361 ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xa3, 0xcf, 0x80); /* Enable DVO */
365 /* AST 2300 DRAM settings */
369 struct ast2300_dram_param {
391 u32 dll2_finetune_step;
395 * DQSI DLL CBR Setting
397 #define CBR_SIZE0 ((1 << 10) - 1)
398 #define CBR_SIZE1 ((4 << 10) - 1)
399 #define CBR_SIZE2 ((64 << 10) - 1)
400 #define CBR_PASSNUM 5
401 #define CBR_PASSNUM2 5
402 #define CBR_THRESHOLD 10
403 #define CBR_THRESHOLD2 10
404 #define TIMEOUT 5000000
407 static const u32 pattern[8] = {
418 static bool mmc_test(struct ast_device *ast, u32 datagen, u8 test_ctl)
422 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
423 ast_moutdwm(ast, 0x1e6e0070, (datagen << 3) | test_ctl);
426 data = ast_mindwm(ast, 0x1e6e0070) & 0x3000;
429 if (++timeout > TIMEOUT) {
430 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
434 ast_moutdwm(ast, 0x1e6e0070, 0x0);
438 static u32 mmc_test2(struct ast_device *ast, u32 datagen, u8 test_ctl)
442 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
443 ast_moutdwm(ast, 0x1e6e0070, (datagen << 3) | test_ctl);
446 data = ast_mindwm(ast, 0x1e6e0070) & 0x1000;
447 if (++timeout > TIMEOUT) {
448 ast_moutdwm(ast, 0x1e6e0070, 0x0);
452 data = ast_mindwm(ast, 0x1e6e0078);
453 data = (data | (data >> 16)) & 0xffff;
454 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
459 static bool mmc_test_burst(struct ast_device *ast, u32 datagen)
461 return mmc_test(ast, datagen, 0xc1);
464 static u32 mmc_test_burst2(struct ast_device *ast, u32 datagen)
466 return mmc_test2(ast, datagen, 0x41);
469 static bool mmc_test_single(struct ast_device *ast, u32 datagen)
471 return mmc_test(ast, datagen, 0xc5);
474 static u32 mmc_test_single2(struct ast_device *ast, u32 datagen)
476 return mmc_test2(ast, datagen, 0x05);
479 static bool mmc_test_single_2500(struct ast_device *ast, u32 datagen)
481 return mmc_test(ast, datagen, 0x85);
484 static int cbr_test(struct ast_device *ast)
488 data = mmc_test_single2(ast, 0);
489 if ((data & 0xff) && (data & 0xff00))
491 for (i = 0; i < 8; i++) {
492 data = mmc_test_burst2(ast, i);
493 if ((data & 0xff) && (data & 0xff00))
498 else if (data & 0xff)
503 static int cbr_scan(struct ast_device *ast)
505 u32 data, data2, patcnt, loop;
508 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
509 ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
510 for (loop = 0; loop < CBR_PASSNUM2; loop++) {
511 if ((data = cbr_test(ast)) != 0) {
518 if (loop == CBR_PASSNUM2)
524 static u32 cbr_test2(struct ast_device *ast)
528 data = mmc_test_burst2(ast, 0);
531 data |= mmc_test_single2(ast, 0);
535 return ~data & 0xffff;
538 static u32 cbr_scan2(struct ast_device *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_test2(ast)) != 0) {
553 if (loop == CBR_PASSNUM2)
559 static bool cbr_test3(struct ast_device *ast)
561 if (!mmc_test_burst(ast, 0))
563 if (!mmc_test_single(ast, 0))
568 static bool cbr_scan3(struct ast_device *ast)
572 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
573 ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
574 for (loop = 0; loop < 2; loop++) {
584 static bool finetuneDQI_L(struct ast_device *ast, struct ast2300_dram_param *param)
586 u32 gold_sadj[2], dllmin[16], dllmax[16], dlli, data, cnt, mask, passcnt, retry = 0;
589 for (cnt = 0; cnt < 16; cnt++) {
594 for (dlli = 0; dlli < 76; dlli++) {
595 ast_moutdwm(ast, 0x1E6E0068, 0x00001400 | (dlli << 16) | (dlli << 24));
596 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE1);
597 data = cbr_scan2(ast);
600 for (cnt = 0; cnt < 16; cnt++) {
602 if (dllmin[cnt] > dlli) {
605 if (dllmax[cnt] < dlli) {
612 } else if (passcnt >= CBR_THRESHOLD2) {
618 for (cnt = 0; cnt < 16; cnt++) {
619 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
620 gold_sadj[0] += dllmin[cnt];
631 gold_sadj[0] = gold_sadj[0] >> 4;
632 gold_sadj[1] = gold_sadj[0];
635 for (cnt = 0; cnt < 8; cnt++) {
637 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
639 if (gold_sadj[0] >= dlli) {
640 dlli = ((gold_sadj[0] - dlli) * 19) >> 5;
645 dlli = ((dlli - gold_sadj[0]) * 19) >> 5;
649 dlli = (8 - dlli) & 0x7;
654 ast_moutdwm(ast, 0x1E6E0080, data);
657 for (cnt = 8; cnt < 16; cnt++) {
659 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
661 if (gold_sadj[1] >= dlli) {
662 dlli = ((gold_sadj[1] - dlli) * 19) >> 5;
666 dlli = (dlli - 1) & 0x7;
669 dlli = ((dlli - gold_sadj[1]) * 19) >> 5;
674 dlli = (8 - dlli) & 0x7;
679 ast_moutdwm(ast, 0x1E6E0084, data);
681 } /* finetuneDQI_L */
683 static void finetuneDQSI(struct ast_device *ast)
685 u32 dlli, dqsip, dqidly;
686 u32 reg_mcr18, reg_mcr0c, passcnt[2], diff;
687 u32 g_dqidly, g_dqsip, g_margin, g_side;
691 /* Disable DQI CBR */
692 reg_mcr0c = ast_mindwm(ast, 0x1E6E000C);
693 reg_mcr18 = ast_mindwm(ast, 0x1E6E0018);
694 reg_mcr18 &= 0x0000ffff;
695 ast_moutdwm(ast, 0x1E6E0018, reg_mcr18);
697 for (dlli = 0; dlli < 76; dlli++) {
701 for (dqidly = 0; dqidly < 32; dqidly++) {
702 pass[dqidly][0][0] = 0xff;
703 pass[dqidly][0][1] = 0x0;
704 pass[dqidly][1][0] = 0xff;
705 pass[dqidly][1][1] = 0x0;
707 for (dqidly = 0; dqidly < 32; dqidly++) {
708 passcnt[0] = passcnt[1] = 0;
709 for (dqsip = 0; dqsip < 2; dqsip++) {
710 ast_moutdwm(ast, 0x1E6E000C, 0);
711 ast_moutdwm(ast, 0x1E6E0018, reg_mcr18 | (dqidly << 16) | (dqsip << 23));
712 ast_moutdwm(ast, 0x1E6E000C, reg_mcr0c);
713 for (dlli = 0; dlli < 76; dlli++) {
714 ast_moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24));
715 ast_moutdwm(ast, 0x1E6E0070, 0);
716 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE0);
717 if (cbr_scan3(ast)) {
721 tag[dqsip][dlli] = 'P';
722 if (dlli < pass[dqidly][dqsip][0])
723 pass[dqidly][dqsip][0] = (u16) dlli;
724 if (dlli > pass[dqidly][dqsip][1])
725 pass[dqidly][dqsip][1] = (u16) dlli;
726 } else if (passcnt[dqsip] >= 5)
729 pass[dqidly][dqsip][0] = 0xff;
730 pass[dqidly][dqsip][1] = 0x0;
734 if (passcnt[0] == 0 && passcnt[1] == 0)
738 g_dqidly = g_dqsip = g_margin = g_side = 0;
740 for (dqidly = 0; dqidly < 32; dqidly++) {
741 for (dqsip = 0; dqsip < 2; dqsip++) {
742 if (pass[dqidly][dqsip][0] > pass[dqidly][dqsip][1])
744 diff = pass[dqidly][dqsip][1] - pass[dqidly][dqsip][0];
745 if ((diff+2) < g_margin)
747 passcnt[0] = passcnt[1] = 0;
748 for (dlli = pass[dqidly][dqsip][0]; dlli > 0 && tag[dqsip][dlli] != 0; dlli--, passcnt[0]++);
749 for (dlli = pass[dqidly][dqsip][1]; dlli < 76 && tag[dqsip][dlli] != 0; dlli++, passcnt[1]++);
750 if (passcnt[0] > passcnt[1])
751 passcnt[0] = passcnt[1];
753 if (passcnt[0] > g_side)
754 passcnt[1] = passcnt[0] - g_side;
755 if (diff > (g_margin+1) && (passcnt[1] > 0 || passcnt[0] > 8)) {
760 } else if (passcnt[1] > 1 && g_side < 8) {
769 reg_mcr18 = reg_mcr18 | (g_dqidly << 16) | (g_dqsip << 23);
770 ast_moutdwm(ast, 0x1E6E0018, reg_mcr18);
773 static bool cbr_dll2(struct ast_device *ast, struct ast2300_dram_param *param)
775 u32 dllmin[2], dllmax[2], dlli, data, passcnt, retry = 0;
779 if (finetuneDQI_L(ast, param) == false)
783 dllmin[0] = dllmin[1] = 0xff;
784 dllmax[0] = dllmax[1] = 0x0;
786 for (dlli = 0; dlli < 76; dlli++) {
787 ast_moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24));
788 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE2);
789 data = cbr_scan(ast);
792 if (dllmin[0] > dlli) {
795 if (dllmax[0] < dlli) {
800 if (dllmin[1] > dlli) {
803 if (dllmax[1] < dlli) {
808 } else if (passcnt >= CBR_THRESHOLD) {
814 if (dllmax[0] == 0 || (dllmax[0]-dllmin[0]) < CBR_THRESHOLD) {
817 if (dllmax[1] == 0 || (dllmax[1]-dllmin[1]) < CBR_THRESHOLD) {
822 dlli = (dllmin[1] + dllmax[1]) >> 1;
824 dlli += (dllmin[0] + dllmax[0]) >> 1;
825 ast_moutdwm(ast, 0x1E6E0068, ast_mindwm(ast, 0x1E720058) | (dlli << 16));
829 static void get_ddr3_info(struct ast_device *ast, struct ast2300_dram_param *param)
831 u32 trap, trap_AC2, trap_MRS;
833 ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
836 trap = (ast_mindwm(ast, 0x1E6E2070) >> 25) & 0x3;
837 trap_AC2 = 0x00020000 + (trap << 16);
838 trap_AC2 |= 0x00300000 + ((trap & 0x2) << 19);
839 trap_MRS = 0x00000010 + (trap << 4);
840 trap_MRS |= ((trap & 0x2) << 18);
842 param->reg_MADJ = 0x00034C4C;
843 param->reg_SADJ = 0x00001800;
844 param->reg_DRV = 0x000000F0;
845 param->reg_PERIOD = param->dram_freq;
848 switch (param->dram_freq) {
850 ast_moutdwm(ast, 0x1E6E2020, 0x0190);
852 param->reg_AC1 = 0x22202725;
853 param->reg_AC2 = 0xAA007613 | trap_AC2;
854 param->reg_DQSIC = 0x000000BA;
855 param->reg_MRS = 0x04001400 | trap_MRS;
856 param->reg_EMRS = 0x00000000;
857 param->reg_IOZ = 0x00000023;
858 param->reg_DQIDLY = 0x00000074;
859 param->reg_FREQ = 0x00004DC0;
860 param->madj_max = 96;
861 param->dll2_finetune_step = 3;
862 switch (param->dram_chipid) {
864 case AST_DRAM_512Mx16:
866 param->reg_AC2 = 0xAA007613 | trap_AC2;
869 param->reg_AC2 = 0xAA00761C | trap_AC2;
872 param->reg_AC2 = 0xAA007636 | trap_AC2;
878 ast_moutdwm(ast, 0x1E6E2020, 0x03F1);
880 param->reg_AC1 = 0x33302825;
881 param->reg_AC2 = 0xCC009617 | trap_AC2;
882 param->reg_DQSIC = 0x000000E2;
883 param->reg_MRS = 0x04001600 | trap_MRS;
884 param->reg_EMRS = 0x00000000;
885 param->reg_IOZ = 0x00000034;
886 param->reg_DRV = 0x000000FA;
887 param->reg_DQIDLY = 0x00000089;
888 param->reg_FREQ = 0x00005040;
889 param->madj_max = 96;
890 param->dll2_finetune_step = 4;
892 switch (param->dram_chipid) {
894 case AST_DRAM_512Mx16:
896 param->reg_AC2 = 0xCC009617 | trap_AC2;
899 param->reg_AC2 = 0xCC009622 | trap_AC2;
902 param->reg_AC2 = 0xCC00963F | trap_AC2;
908 ast_moutdwm(ast, 0x1E6E2020, 0x01F0);
910 param->reg_AC1 = 0x33302825;
911 param->reg_AC2 = 0xCC009617 | trap_AC2;
912 param->reg_DQSIC = 0x000000E2;
913 param->reg_MRS = 0x04001600 | trap_MRS;
914 param->reg_EMRS = 0x00000000;
915 param->reg_IOZ = 0x00000023;
916 param->reg_DRV = 0x000000FA;
917 param->reg_DQIDLY = 0x00000089;
918 param->reg_FREQ = 0x000050C0;
919 param->madj_max = 96;
920 param->dll2_finetune_step = 4;
922 switch (param->dram_chipid) {
924 case AST_DRAM_512Mx16:
926 param->reg_AC2 = 0xCC009617 | trap_AC2;
929 param->reg_AC2 = 0xCC009622 | trap_AC2;
932 param->reg_AC2 = 0xCC00963F | trap_AC2;
938 ast_moutdwm(ast, 0x1E6E2020, 0x0230);
940 param->reg_AC1 = 0x33302926;
941 param->reg_AC2 = 0xCD44961A;
942 param->reg_DQSIC = 0x000000FC;
943 param->reg_MRS = 0x00081830;
944 param->reg_EMRS = 0x00000000;
945 param->reg_IOZ = 0x00000045;
946 param->reg_DQIDLY = 0x00000097;
947 param->reg_FREQ = 0x000052C0;
948 param->madj_max = 88;
949 param->dll2_finetune_step = 4;
952 ast_moutdwm(ast, 0x1E6E2020, 0x0270);
954 param->reg_AC1 = 0x33302926;
955 param->reg_AC2 = 0xDE44A61D;
956 param->reg_DQSIC = 0x00000117;
957 param->reg_MRS = 0x00081A30;
958 param->reg_EMRS = 0x00000000;
959 param->reg_IOZ = 0x070000BB;
960 param->reg_DQIDLY = 0x000000A0;
961 param->reg_FREQ = 0x000054C0;
962 param->madj_max = 79;
963 param->dll2_finetune_step = 4;
966 ast_moutdwm(ast, 0x1E6E2020, 0x0290);
969 param->reg_AC1 = 0x33302926;
970 param->reg_AC2 = 0xEF44B61E;
971 param->reg_DQSIC = 0x00000125;
972 param->reg_MRS = 0x00081A30;
973 param->reg_EMRS = 0x00000040;
974 param->reg_DRV = 0x000000F5;
975 param->reg_IOZ = 0x00000023;
976 param->reg_DQIDLY = 0x00000088;
977 param->reg_FREQ = 0x000055C0;
978 param->madj_max = 76;
979 param->dll2_finetune_step = 3;
982 ast_moutdwm(ast, 0x1E6E2020, 0x0140);
983 param->reg_MADJ = 0x00136868;
984 param->reg_SADJ = 0x00004534;
987 param->reg_AC1 = 0x33302A37;
988 param->reg_AC2 = 0xEF56B61E;
989 param->reg_DQSIC = 0x0000013F;
990 param->reg_MRS = 0x00101A50;
991 param->reg_EMRS = 0x00000040;
992 param->reg_DRV = 0x000000FA;
993 param->reg_IOZ = 0x00000023;
994 param->reg_DQIDLY = 0x00000078;
995 param->reg_FREQ = 0x000057C0;
996 param->madj_max = 136;
997 param->dll2_finetune_step = 3;
1000 ast_moutdwm(ast, 0x1E6E2020, 0x02E1);
1001 param->reg_MADJ = 0x00136868;
1002 param->reg_SADJ = 0x00004534;
1005 param->reg_AC1 = 0x32302A37;
1006 param->reg_AC2 = 0xDF56B61F;
1007 param->reg_DQSIC = 0x0000014D;
1008 param->reg_MRS = 0x00101A50;
1009 param->reg_EMRS = 0x00000004;
1010 param->reg_DRV = 0x000000F5;
1011 param->reg_IOZ = 0x00000023;
1012 param->reg_DQIDLY = 0x00000078;
1013 param->reg_FREQ = 0x000058C0;
1014 param->madj_max = 132;
1015 param->dll2_finetune_step = 3;
1018 ast_moutdwm(ast, 0x1E6E2020, 0x0160);
1019 param->reg_MADJ = 0x00136868;
1020 param->reg_SADJ = 0x00004534;
1023 param->reg_AC1 = 0x32302A37;
1024 param->reg_AC2 = 0xEF56B621;
1025 param->reg_DQSIC = 0x0000015A;
1026 param->reg_MRS = 0x02101A50;
1027 param->reg_EMRS = 0x00000004;
1028 param->reg_DRV = 0x000000F5;
1029 param->reg_IOZ = 0x00000034;
1030 param->reg_DQIDLY = 0x00000078;
1031 param->reg_FREQ = 0x000059C0;
1032 param->madj_max = 128;
1033 param->dll2_finetune_step = 3;
1037 switch (param->dram_chipid) {
1038 case AST_DRAM_512Mx16:
1039 param->dram_config = 0x130;
1042 case AST_DRAM_1Gx16:
1043 param->dram_config = 0x131;
1045 case AST_DRAM_2Gx16:
1046 param->dram_config = 0x132;
1048 case AST_DRAM_4Gx16:
1049 param->dram_config = 0x133;
1053 switch (param->vram_size) {
1055 case AST_VIDMEM_SIZE_8M:
1056 param->dram_config |= 0x00;
1058 case AST_VIDMEM_SIZE_16M:
1059 param->dram_config |= 0x04;
1061 case AST_VIDMEM_SIZE_32M:
1062 param->dram_config |= 0x08;
1064 case AST_VIDMEM_SIZE_64M:
1065 param->dram_config |= 0x0c;
1071 static void ddr3_init(struct ast_device *ast, struct ast2300_dram_param *param)
1073 u32 data, data2, retry = 0;
1076 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1077 ast_moutdwm(ast, 0x1E6E0018, 0x00000100);
1078 ast_moutdwm(ast, 0x1E6E0024, 0x00000000);
1079 ast_moutdwm(ast, 0x1E6E0034, 0x00000000);
1081 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ);
1082 ast_moutdwm(ast, 0x1E6E0068, param->reg_SADJ);
1084 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000);
1087 ast_moutdwm(ast, 0x1E6E0004, param->dram_config);
1088 ast_moutdwm(ast, 0x1E6E0008, 0x90040f);
1089 ast_moutdwm(ast, 0x1E6E0010, param->reg_AC1);
1090 ast_moutdwm(ast, 0x1E6E0014, param->reg_AC2);
1091 ast_moutdwm(ast, 0x1E6E0020, param->reg_DQSIC);
1092 ast_moutdwm(ast, 0x1E6E0080, 0x00000000);
1093 ast_moutdwm(ast, 0x1E6E0084, 0x00000000);
1094 ast_moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY);
1095 ast_moutdwm(ast, 0x1E6E0018, 0x4000A170);
1096 ast_moutdwm(ast, 0x1E6E0018, 0x00002370);
1097 ast_moutdwm(ast, 0x1E6E0038, 0x00000000);
1098 ast_moutdwm(ast, 0x1E6E0040, 0xFF444444);
1099 ast_moutdwm(ast, 0x1E6E0044, 0x22222222);
1100 ast_moutdwm(ast, 0x1E6E0048, 0x22222222);
1101 ast_moutdwm(ast, 0x1E6E004C, 0x00000002);
1102 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1103 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1104 ast_moutdwm(ast, 0x1E6E0054, 0);
1105 ast_moutdwm(ast, 0x1E6E0060, param->reg_DRV);
1106 ast_moutdwm(ast, 0x1E6E006C, param->reg_IOZ);
1107 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1108 ast_moutdwm(ast, 0x1E6E0074, 0x00000000);
1109 ast_moutdwm(ast, 0x1E6E0078, 0x00000000);
1110 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1111 /* Wait MCLK2X lock to MCLK */
1113 data = ast_mindwm(ast, 0x1E6E001C);
1114 } while (!(data & 0x08000000));
1115 data = ast_mindwm(ast, 0x1E6E001C);
1116 data = (data >> 8) & 0xff;
1117 while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) {
1118 data2 = (ast_mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4;
1119 if ((data2 & 0xff) > param->madj_max) {
1122 ast_moutdwm(ast, 0x1E6E0064, data2);
1123 if (data2 & 0x00100000) {
1124 data2 = ((data2 & 0xff) >> 3) + 3;
1126 data2 = ((data2 & 0xff) >> 2) + 5;
1128 data = ast_mindwm(ast, 0x1E6E0068) & 0xffff00ff;
1129 data2 += data & 0xff;
1130 data = data | (data2 << 8);
1131 ast_moutdwm(ast, 0x1E6E0068, data);
1133 ast_moutdwm(ast, 0x1E6E0064, ast_mindwm(ast, 0x1E6E0064) | 0xC0000);
1135 data = ast_mindwm(ast, 0x1E6E0018) & 0xfffff1ff;
1136 ast_moutdwm(ast, 0x1E6E0018, data);
1137 data = data | 0x200;
1138 ast_moutdwm(ast, 0x1E6E0018, data);
1140 data = ast_mindwm(ast, 0x1E6E001C);
1141 } while (!(data & 0x08000000));
1143 data = ast_mindwm(ast, 0x1E6E001C);
1144 data = (data >> 8) & 0xff;
1146 ast_moutdwm(ast, 0x1E720058, ast_mindwm(ast, 0x1E6E0068) & 0xffff);
1147 data = ast_mindwm(ast, 0x1E6E0018) | 0xC00;
1148 ast_moutdwm(ast, 0x1E6E0018, data);
1150 ast_moutdwm(ast, 0x1E6E0034, 0x00000001);
1151 ast_moutdwm(ast, 0x1E6E000C, 0x00000040);
1153 /* Mode Register Setting */
1154 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100);
1155 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1156 ast_moutdwm(ast, 0x1E6E0028, 0x00000005);
1157 ast_moutdwm(ast, 0x1E6E0028, 0x00000007);
1158 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1159 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1160 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS);
1161 ast_moutdwm(ast, 0x1E6E000C, 0x00005C08);
1162 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1164 ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
1170 data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3);
1172 ast_moutdwm(ast, 0x1E6E0034, data | 0x3);
1174 /* Calibrate the DQSI delay */
1175 if ((cbr_dll2(ast, param) == false) && (retry++ < 10))
1176 goto ddr3_init_start;
1178 ast_moutdwm(ast, 0x1E6E0120, param->reg_FREQ);
1179 /* ECC Memory Initialization */
1181 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1182 ast_moutdwm(ast, 0x1E6E0070, 0x221);
1184 data = ast_mindwm(ast, 0x1E6E0070);
1185 } while (!(data & 0x00001000));
1186 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1187 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1188 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1194 static void get_ddr2_info(struct ast_device *ast, struct ast2300_dram_param *param)
1196 u32 trap, trap_AC2, trap_MRS;
1198 ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
1201 trap = (ast_mindwm(ast, 0x1E6E2070) >> 25) & 0x3;
1202 trap_AC2 = (trap << 20) | (trap << 16);
1203 trap_AC2 += 0x00110000;
1204 trap_MRS = 0x00000040 | (trap << 4);
1207 param->reg_MADJ = 0x00034C4C;
1208 param->reg_SADJ = 0x00001800;
1209 param->reg_DRV = 0x000000F0;
1210 param->reg_PERIOD = param->dram_freq;
1213 switch (param->dram_freq) {
1215 ast_moutdwm(ast, 0x1E6E2020, 0x0130);
1217 param->reg_AC1 = 0x11101513;
1218 param->reg_AC2 = 0x78117011;
1219 param->reg_DQSIC = 0x00000092;
1220 param->reg_MRS = 0x00000842;
1221 param->reg_EMRS = 0x00000000;
1222 param->reg_DRV = 0x000000F0;
1223 param->reg_IOZ = 0x00000034;
1224 param->reg_DQIDLY = 0x0000005A;
1225 param->reg_FREQ = 0x00004AC0;
1226 param->madj_max = 138;
1227 param->dll2_finetune_step = 3;
1230 ast_moutdwm(ast, 0x1E6E2020, 0x0190);
1232 param->reg_AC1 = 0x22202613;
1233 param->reg_AC2 = 0xAA009016 | trap_AC2;
1234 param->reg_DQSIC = 0x000000BA;
1235 param->reg_MRS = 0x00000A02 | trap_MRS;
1236 param->reg_EMRS = 0x00000040;
1237 param->reg_DRV = 0x000000FA;
1238 param->reg_IOZ = 0x00000034;
1239 param->reg_DQIDLY = 0x00000074;
1240 param->reg_FREQ = 0x00004DC0;
1241 param->madj_max = 96;
1242 param->dll2_finetune_step = 3;
1243 switch (param->dram_chipid) {
1245 case AST_DRAM_512Mx16:
1246 param->reg_AC2 = 0xAA009012 | trap_AC2;
1248 case AST_DRAM_1Gx16:
1249 param->reg_AC2 = 0xAA009016 | trap_AC2;
1251 case AST_DRAM_2Gx16:
1252 param->reg_AC2 = 0xAA009023 | trap_AC2;
1254 case AST_DRAM_4Gx16:
1255 param->reg_AC2 = 0xAA00903B | trap_AC2;
1261 ast_moutdwm(ast, 0x1E6E2020, 0x03F1);
1264 param->reg_AC1 = 0x33302714;
1265 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1266 param->reg_DQSIC = 0x000000E2;
1267 param->reg_MRS = 0x00000C02 | trap_MRS;
1268 param->reg_EMRS = 0x00000040;
1269 param->reg_DRV = 0x000000FA;
1270 param->reg_IOZ = 0x00000034;
1271 param->reg_DQIDLY = 0x00000089;
1272 param->reg_FREQ = 0x00005040;
1273 param->madj_max = 96;
1274 param->dll2_finetune_step = 4;
1276 switch (param->dram_chipid) {
1277 case AST_DRAM_512Mx16:
1278 param->reg_AC2 = 0xCC00B016 | trap_AC2;
1281 case AST_DRAM_1Gx16:
1282 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1284 case AST_DRAM_2Gx16:
1285 param->reg_AC2 = 0xCC00B02B | trap_AC2;
1287 case AST_DRAM_4Gx16:
1288 param->reg_AC2 = 0xCC00B03F | trap_AC2;
1295 ast_moutdwm(ast, 0x1E6E2020, 0x01F0);
1298 param->reg_AC1 = 0x33302714;
1299 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1300 param->reg_DQSIC = 0x000000E2;
1301 param->reg_MRS = 0x00000C02 | trap_MRS;
1302 param->reg_EMRS = 0x00000040;
1303 param->reg_DRV = 0x000000FA;
1304 param->reg_IOZ = 0x00000034;
1305 param->reg_DQIDLY = 0x00000089;
1306 param->reg_FREQ = 0x000050C0;
1307 param->madj_max = 96;
1308 param->dll2_finetune_step = 4;
1310 switch (param->dram_chipid) {
1311 case AST_DRAM_512Mx16:
1312 param->reg_AC2 = 0xCC00B016 | trap_AC2;
1315 case AST_DRAM_1Gx16:
1316 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1318 case AST_DRAM_2Gx16:
1319 param->reg_AC2 = 0xCC00B02B | trap_AC2;
1321 case AST_DRAM_4Gx16:
1322 param->reg_AC2 = 0xCC00B03F | trap_AC2;
1328 ast_moutdwm(ast, 0x1E6E2020, 0x0230);
1330 param->reg_AC1 = 0x33302815;
1331 param->reg_AC2 = 0xCD44B01E;
1332 param->reg_DQSIC = 0x000000FC;
1333 param->reg_MRS = 0x00000E72;
1334 param->reg_EMRS = 0x00000000;
1335 param->reg_DRV = 0x00000000;
1336 param->reg_IOZ = 0x00000034;
1337 param->reg_DQIDLY = 0x00000097;
1338 param->reg_FREQ = 0x000052C0;
1339 param->madj_max = 88;
1340 param->dll2_finetune_step = 3;
1343 ast_moutdwm(ast, 0x1E6E2020, 0x0261);
1346 param->reg_AC1 = 0x33302815;
1347 param->reg_AC2 = 0xDE44C022;
1348 param->reg_DQSIC = 0x00000117;
1349 param->reg_MRS = 0x00000E72;
1350 param->reg_EMRS = 0x00000040;
1351 param->reg_DRV = 0x0000000A;
1352 param->reg_IOZ = 0x00000045;
1353 param->reg_DQIDLY = 0x000000A0;
1354 param->reg_FREQ = 0x000054C0;
1355 param->madj_max = 79;
1356 param->dll2_finetune_step = 3;
1359 ast_moutdwm(ast, 0x1E6E2020, 0x0120);
1362 param->reg_AC1 = 0x33302815;
1363 param->reg_AC2 = 0xEF44D024;
1364 param->reg_DQSIC = 0x00000125;
1365 param->reg_MRS = 0x00000E72;
1366 param->reg_EMRS = 0x00000004;
1367 param->reg_DRV = 0x000000F9;
1368 param->reg_IOZ = 0x00000045;
1369 param->reg_DQIDLY = 0x000000A7;
1370 param->reg_FREQ = 0x000055C0;
1371 param->madj_max = 76;
1372 param->dll2_finetune_step = 3;
1375 ast_moutdwm(ast, 0x1E6E2020, 0x02A1);
1378 param->reg_AC1 = 0x43402915;
1379 param->reg_AC2 = 0xFF44E025;
1380 param->reg_DQSIC = 0x00000132;
1381 param->reg_MRS = 0x00000E72;
1382 param->reg_EMRS = 0x00000040;
1383 param->reg_DRV = 0x0000000A;
1384 param->reg_IOZ = 0x00000045;
1385 param->reg_DQIDLY = 0x000000AD;
1386 param->reg_FREQ = 0x000056C0;
1387 param->madj_max = 76;
1388 param->dll2_finetune_step = 3;
1391 ast_moutdwm(ast, 0x1E6E2020, 0x0140);
1394 param->reg_AC1 = 0x43402915;
1395 param->reg_AC2 = 0xFF44E027;
1396 param->reg_DQSIC = 0x0000013F;
1397 param->reg_MRS = 0x00000E72;
1398 param->reg_EMRS = 0x00000004;
1399 param->reg_DRV = 0x000000F5;
1400 param->reg_IOZ = 0x00000045;
1401 param->reg_DQIDLY = 0x000000B3;
1402 param->reg_FREQ = 0x000057C0;
1403 param->madj_max = 76;
1404 param->dll2_finetune_step = 3;
1408 switch (param->dram_chipid) {
1409 case AST_DRAM_512Mx16:
1410 param->dram_config = 0x100;
1413 case AST_DRAM_1Gx16:
1414 param->dram_config = 0x121;
1416 case AST_DRAM_2Gx16:
1417 param->dram_config = 0x122;
1419 case AST_DRAM_4Gx16:
1420 param->dram_config = 0x123;
1424 switch (param->vram_size) {
1426 case AST_VIDMEM_SIZE_8M:
1427 param->dram_config |= 0x00;
1429 case AST_VIDMEM_SIZE_16M:
1430 param->dram_config |= 0x04;
1432 case AST_VIDMEM_SIZE_32M:
1433 param->dram_config |= 0x08;
1435 case AST_VIDMEM_SIZE_64M:
1436 param->dram_config |= 0x0c;
1441 static void ddr2_init(struct ast_device *ast, struct ast2300_dram_param *param)
1443 u32 data, data2, retry = 0;
1446 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1447 ast_moutdwm(ast, 0x1E6E0018, 0x00000100);
1448 ast_moutdwm(ast, 0x1E6E0024, 0x00000000);
1449 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ);
1450 ast_moutdwm(ast, 0x1E6E0068, param->reg_SADJ);
1452 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000);
1455 ast_moutdwm(ast, 0x1E6E0004, param->dram_config);
1456 ast_moutdwm(ast, 0x1E6E0008, 0x90040f);
1457 ast_moutdwm(ast, 0x1E6E0010, param->reg_AC1);
1458 ast_moutdwm(ast, 0x1E6E0014, param->reg_AC2);
1459 ast_moutdwm(ast, 0x1E6E0020, param->reg_DQSIC);
1460 ast_moutdwm(ast, 0x1E6E0080, 0x00000000);
1461 ast_moutdwm(ast, 0x1E6E0084, 0x00000000);
1462 ast_moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY);
1463 ast_moutdwm(ast, 0x1E6E0018, 0x4000A130);
1464 ast_moutdwm(ast, 0x1E6E0018, 0x00002330);
1465 ast_moutdwm(ast, 0x1E6E0038, 0x00000000);
1466 ast_moutdwm(ast, 0x1E6E0040, 0xFF808000);
1467 ast_moutdwm(ast, 0x1E6E0044, 0x88848466);
1468 ast_moutdwm(ast, 0x1E6E0048, 0x44440008);
1469 ast_moutdwm(ast, 0x1E6E004C, 0x00000000);
1470 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1471 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1472 ast_moutdwm(ast, 0x1E6E0054, 0);
1473 ast_moutdwm(ast, 0x1E6E0060, param->reg_DRV);
1474 ast_moutdwm(ast, 0x1E6E006C, param->reg_IOZ);
1475 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1476 ast_moutdwm(ast, 0x1E6E0074, 0x00000000);
1477 ast_moutdwm(ast, 0x1E6E0078, 0x00000000);
1478 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1480 /* Wait MCLK2X lock to MCLK */
1482 data = ast_mindwm(ast, 0x1E6E001C);
1483 } while (!(data & 0x08000000));
1484 data = ast_mindwm(ast, 0x1E6E001C);
1485 data = (data >> 8) & 0xff;
1486 while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) {
1487 data2 = (ast_mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4;
1488 if ((data2 & 0xff) > param->madj_max) {
1491 ast_moutdwm(ast, 0x1E6E0064, data2);
1492 if (data2 & 0x00100000) {
1493 data2 = ((data2 & 0xff) >> 3) + 3;
1495 data2 = ((data2 & 0xff) >> 2) + 5;
1497 data = ast_mindwm(ast, 0x1E6E0068) & 0xffff00ff;
1498 data2 += data & 0xff;
1499 data = data | (data2 << 8);
1500 ast_moutdwm(ast, 0x1E6E0068, data);
1502 ast_moutdwm(ast, 0x1E6E0064, ast_mindwm(ast, 0x1E6E0064) | 0xC0000);
1504 data = ast_mindwm(ast, 0x1E6E0018) & 0xfffff1ff;
1505 ast_moutdwm(ast, 0x1E6E0018, data);
1506 data = data | 0x200;
1507 ast_moutdwm(ast, 0x1E6E0018, data);
1509 data = ast_mindwm(ast, 0x1E6E001C);
1510 } while (!(data & 0x08000000));
1512 data = ast_mindwm(ast, 0x1E6E001C);
1513 data = (data >> 8) & 0xff;
1515 ast_moutdwm(ast, 0x1E720058, ast_mindwm(ast, 0x1E6E0008) & 0xffff);
1516 data = ast_mindwm(ast, 0x1E6E0018) | 0xC00;
1517 ast_moutdwm(ast, 0x1E6E0018, data);
1519 ast_moutdwm(ast, 0x1E6E0034, 0x00000001);
1520 ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
1522 /* Mode Register Setting */
1523 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100);
1524 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1525 ast_moutdwm(ast, 0x1E6E0028, 0x00000005);
1526 ast_moutdwm(ast, 0x1E6E0028, 0x00000007);
1527 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1528 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1530 ast_moutdwm(ast, 0x1E6E000C, 0x00005C08);
1531 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS);
1532 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1533 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS | 0x380);
1534 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1535 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1536 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1538 ast_moutdwm(ast, 0x1E6E000C, 0x7FFF5C01);
1544 data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3);
1546 ast_moutdwm(ast, 0x1E6E0034, data | 0x3);
1547 ast_moutdwm(ast, 0x1E6E0120, param->reg_FREQ);
1549 /* Calibrate the DQSI delay */
1550 if ((cbr_dll2(ast, param) == false) && (retry++ < 10))
1551 goto ddr2_init_start;
1553 /* ECC Memory Initialization */
1555 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1556 ast_moutdwm(ast, 0x1E6E0070, 0x221);
1558 data = ast_mindwm(ast, 0x1E6E0070);
1559 } while (!(data & 0x00001000));
1560 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1561 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1562 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1567 static void ast_post_chip_2300(struct ast_device *ast)
1569 struct ast2300_dram_param param;
1573 reg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
1574 if ((reg & 0x80) == 0) {/* vga only */
1575 ast_write32(ast, 0xf004, 0x1e6e0000);
1576 ast_write32(ast, 0xf000, 0x1);
1577 ast_write32(ast, 0x12000, 0x1688a8a8);
1580 } while (ast_read32(ast, 0x12000) != 0x1);
1582 ast_write32(ast, 0x10000, 0xfc600309);
1585 } while (ast_read32(ast, 0x10000) != 0x1);
1587 /* Slow down CPU/AHB CLK in VGA only mode */
1588 temp = ast_read32(ast, 0x12008);
1590 ast_write32(ast, 0x12008, temp);
1592 param.dram_freq = 396;
1593 param.dram_type = AST_DDR3;
1594 temp = ast_mindwm(ast, 0x1e6e2070);
1595 if (temp & 0x01000000)
1596 param.dram_type = AST_DDR2;
1597 switch (temp & 0x18000000) {
1599 param.dram_chipid = AST_DRAM_512Mx16;
1603 param.dram_chipid = AST_DRAM_1Gx16;
1606 param.dram_chipid = AST_DRAM_2Gx16;
1609 param.dram_chipid = AST_DRAM_4Gx16;
1612 switch (temp & 0x0c) {
1615 param.vram_size = AST_VIDMEM_SIZE_8M;
1619 param.vram_size = AST_VIDMEM_SIZE_16M;
1623 param.vram_size = AST_VIDMEM_SIZE_32M;
1627 param.vram_size = AST_VIDMEM_SIZE_64M;
1631 if (param.dram_type == AST_DDR3) {
1632 get_ddr3_info(ast, ¶m);
1633 ddr3_init(ast, ¶m);
1635 get_ddr2_info(ast, ¶m);
1636 ddr2_init(ast, ¶m);
1639 temp = ast_mindwm(ast, 0x1e6e2040);
1640 ast_moutdwm(ast, 0x1e6e2040, temp | 0x40);
1645 reg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
1646 } while ((reg & 0x40) == 0);
1649 static bool cbr_test_2500(struct ast_device *ast)
1651 ast_moutdwm(ast, 0x1E6E0074, 0x0000FFFF);
1652 ast_moutdwm(ast, 0x1E6E007C, 0xFF00FF00);
1653 if (!mmc_test_burst(ast, 0))
1655 if (!mmc_test_single_2500(ast, 0))
1660 static bool ddr_test_2500(struct ast_device *ast)
1662 ast_moutdwm(ast, 0x1E6E0074, 0x0000FFFF);
1663 ast_moutdwm(ast, 0x1E6E007C, 0xFF00FF00);
1664 if (!mmc_test_burst(ast, 0))
1666 if (!mmc_test_burst(ast, 1))
1668 if (!mmc_test_burst(ast, 2))
1670 if (!mmc_test_burst(ast, 3))
1672 if (!mmc_test_single_2500(ast, 0))
1677 static void ddr_init_common_2500(struct ast_device *ast)
1679 ast_moutdwm(ast, 0x1E6E0034, 0x00020080);
1680 ast_moutdwm(ast, 0x1E6E0008, 0x2003000F);
1681 ast_moutdwm(ast, 0x1E6E0038, 0x00000FFF);
1682 ast_moutdwm(ast, 0x1E6E0040, 0x88448844);
1683 ast_moutdwm(ast, 0x1E6E0044, 0x24422288);
1684 ast_moutdwm(ast, 0x1E6E0048, 0x22222222);
1685 ast_moutdwm(ast, 0x1E6E004C, 0x22222222);
1686 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1687 ast_moutdwm(ast, 0x1E6E0208, 0x00000000);
1688 ast_moutdwm(ast, 0x1E6E0218, 0x00000000);
1689 ast_moutdwm(ast, 0x1E6E0220, 0x00000000);
1690 ast_moutdwm(ast, 0x1E6E0228, 0x00000000);
1691 ast_moutdwm(ast, 0x1E6E0230, 0x00000000);
1692 ast_moutdwm(ast, 0x1E6E02A8, 0x00000000);
1693 ast_moutdwm(ast, 0x1E6E02B0, 0x00000000);
1694 ast_moutdwm(ast, 0x1E6E0240, 0x86000000);
1695 ast_moutdwm(ast, 0x1E6E0244, 0x00008600);
1696 ast_moutdwm(ast, 0x1E6E0248, 0x80000000);
1697 ast_moutdwm(ast, 0x1E6E024C, 0x80808080);
1700 static void ddr_phy_init_2500(struct ast_device *ast)
1702 u32 data, pass, timecnt;
1705 ast_moutdwm(ast, 0x1E6E0060, 0x00000005);
1707 for (timecnt = 0; timecnt < TIMEOUT; timecnt++) {
1708 data = ast_mindwm(ast, 0x1E6E0060) & 0x1;
1712 if (timecnt != TIMEOUT) {
1713 data = ast_mindwm(ast, 0x1E6E0300) & 0x000A0000;
1718 ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
1719 udelay(10); /* delay 10 us */
1720 ast_moutdwm(ast, 0x1E6E0060, 0x00000005);
1724 ast_moutdwm(ast, 0x1E6E0060, 0x00000006);
1729 * 1Gb : 0x80000000 ~ 0x87FFFFFF
1730 * 2Gb : 0x80000000 ~ 0x8FFFFFFF
1731 * 4Gb : 0x80000000 ~ 0x9FFFFFFF
1732 * 8Gb : 0x80000000 ~ 0xBFFFFFFF
1734 static void check_dram_size_2500(struct ast_device *ast, u32 tRFC)
1738 reg_04 = ast_mindwm(ast, 0x1E6E0004) & 0xfffffffc;
1739 reg_14 = ast_mindwm(ast, 0x1E6E0014) & 0xffffff00;
1741 ast_moutdwm(ast, 0xA0100000, 0x41424344);
1742 ast_moutdwm(ast, 0x90100000, 0x35363738);
1743 ast_moutdwm(ast, 0x88100000, 0x292A2B2C);
1744 ast_moutdwm(ast, 0x80100000, 0x1D1E1F10);
1747 if (ast_mindwm(ast, 0xA0100000) == 0x41424344) {
1749 reg_14 |= (tRFC >> 24) & 0xFF;
1751 } else if (ast_mindwm(ast, 0x90100000) == 0x35363738) {
1753 reg_14 |= (tRFC >> 16) & 0xFF;
1755 } else if (ast_mindwm(ast, 0x88100000) == 0x292A2B2C) {
1757 reg_14 |= (tRFC >> 8) & 0xFF;
1759 reg_14 |= tRFC & 0xFF;
1761 ast_moutdwm(ast, 0x1E6E0004, reg_04);
1762 ast_moutdwm(ast, 0x1E6E0014, reg_14);
1765 static void enable_cache_2500(struct ast_device *ast)
1769 reg_04 = ast_mindwm(ast, 0x1E6E0004);
1770 ast_moutdwm(ast, 0x1E6E0004, reg_04 | 0x1000);
1773 data = ast_mindwm(ast, 0x1E6E0004);
1774 while (!(data & 0x80000));
1775 ast_moutdwm(ast, 0x1E6E0004, reg_04 | 0x400);
1778 static void set_mpll_2500(struct ast_device *ast)
1780 u32 addr, data, param;
1783 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1784 ast_moutdwm(ast, 0x1E6E0034, 0x00020080);
1785 for (addr = 0x1e6e0004; addr < 0x1e6e0090;) {
1786 ast_moutdwm(ast, addr, 0x0);
1789 ast_moutdwm(ast, 0x1E6E0034, 0x00020000);
1791 ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
1792 data = ast_mindwm(ast, 0x1E6E2070) & 0x00800000;
1796 ast_moutdwm(ast, 0x1E6E2160, 0x00011320);
1801 ast_moutdwm(ast, 0x1E6E2020, param);
1805 static void reset_mmc_2500(struct ast_device *ast)
1807 ast_moutdwm(ast, 0x1E78505C, 0x00000004);
1808 ast_moutdwm(ast, 0x1E785044, 0x00000001);
1809 ast_moutdwm(ast, 0x1E785048, 0x00004755);
1810 ast_moutdwm(ast, 0x1E78504C, 0x00000013);
1812 ast_moutdwm(ast, 0x1E785054, 0x00000077);
1813 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1816 static void ddr3_init_2500(struct ast_device *ast, const u32 *ddr_table)
1819 ast_moutdwm(ast, 0x1E6E0004, 0x00000303);
1820 ast_moutdwm(ast, 0x1E6E0010, ddr_table[REGIDX_010]);
1821 ast_moutdwm(ast, 0x1E6E0014, ddr_table[REGIDX_014]);
1822 ast_moutdwm(ast, 0x1E6E0018, ddr_table[REGIDX_018]);
1823 ast_moutdwm(ast, 0x1E6E0020, ddr_table[REGIDX_020]); /* MODEREG4/6 */
1824 ast_moutdwm(ast, 0x1E6E0024, ddr_table[REGIDX_024]); /* MODEREG5 */
1825 ast_moutdwm(ast, 0x1E6E002C, ddr_table[REGIDX_02C] | 0x100); /* MODEREG0/2 */
1826 ast_moutdwm(ast, 0x1E6E0030, ddr_table[REGIDX_030]); /* MODEREG1/3 */
1828 /* DDR PHY Setting */
1829 ast_moutdwm(ast, 0x1E6E0200, 0x02492AAE);
1830 ast_moutdwm(ast, 0x1E6E0204, 0x00001001);
1831 ast_moutdwm(ast, 0x1E6E020C, 0x55E00B0B);
1832 ast_moutdwm(ast, 0x1E6E0210, 0x20000000);
1833 ast_moutdwm(ast, 0x1E6E0214, ddr_table[REGIDX_214]);
1834 ast_moutdwm(ast, 0x1E6E02E0, ddr_table[REGIDX_2E0]);
1835 ast_moutdwm(ast, 0x1E6E02E4, ddr_table[REGIDX_2E4]);
1836 ast_moutdwm(ast, 0x1E6E02E8, ddr_table[REGIDX_2E8]);
1837 ast_moutdwm(ast, 0x1E6E02EC, ddr_table[REGIDX_2EC]);
1838 ast_moutdwm(ast, 0x1E6E02F0, ddr_table[REGIDX_2F0]);
1839 ast_moutdwm(ast, 0x1E6E02F4, ddr_table[REGIDX_2F4]);
1840 ast_moutdwm(ast, 0x1E6E02F8, ddr_table[REGIDX_2F8]);
1841 ast_moutdwm(ast, 0x1E6E0290, 0x00100008);
1842 ast_moutdwm(ast, 0x1E6E02C0, 0x00000006);
1844 /* Controller Setting */
1845 ast_moutdwm(ast, 0x1E6E0034, 0x00020091);
1847 /* Wait DDR PHY init done */
1848 ddr_phy_init_2500(ast);
1850 ast_moutdwm(ast, 0x1E6E0120, ddr_table[REGIDX_PLL]);
1851 ast_moutdwm(ast, 0x1E6E000C, 0x42AA5C81);
1852 ast_moutdwm(ast, 0x1E6E0034, 0x0001AF93);
1854 check_dram_size_2500(ast, ddr_table[REGIDX_RFC]);
1855 enable_cache_2500(ast);
1856 ast_moutdwm(ast, 0x1E6E001C, 0x00000008);
1857 ast_moutdwm(ast, 0x1E6E0038, 0xFFFFFF00);
1860 static void ddr4_init_2500(struct ast_device *ast, const u32 *ddr_table)
1862 u32 data, data2, pass, retrycnt;
1863 u32 ddr_vref, phy_vref;
1864 u32 min_ddr_vref = 0, min_phy_vref = 0;
1865 u32 max_ddr_vref = 0, max_phy_vref = 0;
1867 ast_moutdwm(ast, 0x1E6E0004, 0x00000313);
1868 ast_moutdwm(ast, 0x1E6E0010, ddr_table[REGIDX_010]);
1869 ast_moutdwm(ast, 0x1E6E0014, ddr_table[REGIDX_014]);
1870 ast_moutdwm(ast, 0x1E6E0018, ddr_table[REGIDX_018]);
1871 ast_moutdwm(ast, 0x1E6E0020, ddr_table[REGIDX_020]); /* MODEREG4/6 */
1872 ast_moutdwm(ast, 0x1E6E0024, ddr_table[REGIDX_024]); /* MODEREG5 */
1873 ast_moutdwm(ast, 0x1E6E002C, ddr_table[REGIDX_02C] | 0x100); /* MODEREG0/2 */
1874 ast_moutdwm(ast, 0x1E6E0030, ddr_table[REGIDX_030]); /* MODEREG1/3 */
1876 /* DDR PHY Setting */
1877 ast_moutdwm(ast, 0x1E6E0200, 0x42492AAE);
1878 ast_moutdwm(ast, 0x1E6E0204, 0x09002000);
1879 ast_moutdwm(ast, 0x1E6E020C, 0x55E00B0B);
1880 ast_moutdwm(ast, 0x1E6E0210, 0x20000000);
1881 ast_moutdwm(ast, 0x1E6E0214, ddr_table[REGIDX_214]);
1882 ast_moutdwm(ast, 0x1E6E02E0, ddr_table[REGIDX_2E0]);
1883 ast_moutdwm(ast, 0x1E6E02E4, ddr_table[REGIDX_2E4]);
1884 ast_moutdwm(ast, 0x1E6E02E8, ddr_table[REGIDX_2E8]);
1885 ast_moutdwm(ast, 0x1E6E02EC, ddr_table[REGIDX_2EC]);
1886 ast_moutdwm(ast, 0x1E6E02F0, ddr_table[REGIDX_2F0]);
1887 ast_moutdwm(ast, 0x1E6E02F4, ddr_table[REGIDX_2F4]);
1888 ast_moutdwm(ast, 0x1E6E02F8, ddr_table[REGIDX_2F8]);
1889 ast_moutdwm(ast, 0x1E6E0290, 0x00100008);
1890 ast_moutdwm(ast, 0x1E6E02C4, 0x3C183C3C);
1891 ast_moutdwm(ast, 0x1E6E02C8, 0x00631E0E);
1893 /* Controller Setting */
1894 ast_moutdwm(ast, 0x1E6E0034, 0x0001A991);
1896 /* Train PHY Vref first */
1899 for (retrycnt = 0; retrycnt < 4 && pass == 0; retrycnt++) {
1902 ast_moutdwm(ast, 0x1E6E02C0, 0x00001C06);
1903 for (phy_vref = 0x40; phy_vref < 0x80; phy_vref++) {
1904 ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
1905 ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
1906 ast_moutdwm(ast, 0x1E6E02CC, phy_vref | (phy_vref << 8));
1908 ddr_phy_init_2500(ast);
1909 ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
1910 if (cbr_test_2500(ast)) {
1912 data = ast_mindwm(ast, 0x1E6E03D0);
1917 if (max_phy_vref < data) {
1918 max_phy_vref = data;
1919 min_phy_vref = phy_vref;
1921 } else if (pass > 0)
1925 ast_moutdwm(ast, 0x1E6E02CC, min_phy_vref | (min_phy_vref << 8));
1927 /* Train DDR Vref next */
1930 for (retrycnt = 0; retrycnt < 4 && pass == 0; retrycnt++) {
1931 min_ddr_vref = 0xFF;
1934 for (ddr_vref = 0x00; ddr_vref < 0x40; ddr_vref++) {
1935 ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
1936 ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
1937 ast_moutdwm(ast, 0x1E6E02C0, 0x00000006 | (ddr_vref << 8));
1939 ddr_phy_init_2500(ast);
1940 ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
1941 if (cbr_test_2500(ast)) {
1943 if (min_ddr_vref > ddr_vref)
1944 min_ddr_vref = ddr_vref;
1945 if (max_ddr_vref < ddr_vref)
1946 max_ddr_vref = ddr_vref;
1947 } else if (pass != 0)
1952 ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
1953 ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
1954 ddr_vref = (min_ddr_vref + max_ddr_vref + 1) >> 1;
1955 ast_moutdwm(ast, 0x1E6E02C0, 0x00000006 | (ddr_vref << 8));
1957 /* Wait DDR PHY init done */
1958 ddr_phy_init_2500(ast);
1960 ast_moutdwm(ast, 0x1E6E0120, ddr_table[REGIDX_PLL]);
1961 ast_moutdwm(ast, 0x1E6E000C, 0x42AA5C81);
1962 ast_moutdwm(ast, 0x1E6E0034, 0x0001AF93);
1964 check_dram_size_2500(ast, ddr_table[REGIDX_RFC]);
1965 enable_cache_2500(ast);
1966 ast_moutdwm(ast, 0x1E6E001C, 0x00000008);
1967 ast_moutdwm(ast, 0x1E6E0038, 0xFFFFFF00);
1970 static bool ast_dram_init_2500(struct ast_device *ast)
1976 if (max_tries-- == 0)
1979 reset_mmc_2500(ast);
1980 ddr_init_common_2500(ast);
1982 data = ast_mindwm(ast, 0x1E6E2070);
1983 if (data & 0x01000000)
1984 ddr4_init_2500(ast, ast2500_ddr4_1600_timing_table);
1986 ddr3_init_2500(ast, ast2500_ddr3_1600_timing_table);
1987 } while (!ddr_test_2500(ast));
1989 ast_moutdwm(ast, 0x1E6E2040, ast_mindwm(ast, 0x1E6E2040) | 0x41);
1992 data = ast_mindwm(ast, 0x1E6E200C) & 0xF9FFFFFF;
1993 ast_moutdwm(ast, 0x1E6E200C, data | 0x10000000);
1998 void ast_patch_ahb_2500(void __iomem *regs)
2002 /* Clear bus lock condition */
2003 __ast_moutdwm(regs, 0x1e600000, 0xAEED1A03);
2004 __ast_moutdwm(regs, 0x1e600084, 0x00010000);
2005 __ast_moutdwm(regs, 0x1e600088, 0x00000000);
2006 __ast_moutdwm(regs, 0x1e6e2000, 0x1688A8A8);
2008 data = __ast_mindwm(regs, 0x1e6e2070);
2009 if (data & 0x08000000) { /* check fast reset */
2011 * If "Fast restet" is enabled for ARM-ICE debugger,
2012 * then WDT needs to enable, that
2013 * WDT04 is WDT#1 Reload reg.
2014 * WDT08 is WDT#1 counter restart reg to avoid system deadlock
2015 * WDT0C is WDT#1 control reg
2016 * [6:5]:= 01:Full chip
2017 * [4]:= 1:1MHz clock source
2018 * [1]:= 1:WDT will be cleeared and disabled after timeout occurs
2019 * [0]:= 1:WDT enable
2021 __ast_moutdwm(regs, 0x1E785004, 0x00000010);
2022 __ast_moutdwm(regs, 0x1E785008, 0x00004755);
2023 __ast_moutdwm(regs, 0x1E78500c, 0x00000033);
2028 __ast_moutdwm(regs, 0x1e6e2000, 0x1688A8A8);
2029 data = __ast_mindwm(regs, 0x1e6e2000);
2030 } while (data != 1);
2032 __ast_moutdwm(regs, 0x1e6e207c, 0x08000000); /* clear fast reset */
2035 void ast_post_chip_2500(struct ast_device *ast)
2037 struct drm_device *dev = &ast->base;
2041 reg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
2042 if ((reg & AST_VRAM_INIT_STATUS_MASK) == 0) {/* vga only */
2043 /* Clear bus lock condition */
2044 ast_patch_ahb_2500(ast->regs);
2046 /* Disable watchdog */
2047 ast_moutdwm(ast, 0x1E78502C, 0x00000000);
2048 ast_moutdwm(ast, 0x1E78504C, 0x00000000);
2051 * Reset USB port to patch USB unknown device issue
2052 * SCU90 is Multi-function Pin Control #5
2053 * [29]:= 1:Enable USB2.0 Host port#1 (that the mutually shared USB2.0 Hub
2055 * SCU94 is Multi-function Pin Control #6
2056 * [14:13]:= 1x:USB2.0 Host2 controller
2057 * SCU70 is Hardware Strap reg
2058 * [23]:= 1:CLKIN is 25MHz and USBCK1 = 24/48 MHz (determined by
2059 * [18]: 0(24)/1(48) MHz)
2060 * SCU7C is Write clear reg to SCU70
2061 * [23]:= write 1 and then SCU70[23] will be clear as 0b.
2063 ast_moutdwm(ast, 0x1E6E2090, 0x20000000);
2064 ast_moutdwm(ast, 0x1E6E2094, 0x00004000);
2065 if (ast_mindwm(ast, 0x1E6E2070) & 0x00800000) {
2066 ast_moutdwm(ast, 0x1E6E207C, 0x00800000);
2068 ast_moutdwm(ast, 0x1E6E2070, 0x00800000);
2070 /* Modify eSPI reset pin */
2071 temp = ast_mindwm(ast, 0x1E6E2070);
2072 if (temp & 0x02000000)
2073 ast_moutdwm(ast, 0x1E6E207C, 0x00004000);
2075 /* Slow down CPU/AHB CLK in VGA only mode */
2076 temp = ast_read32(ast, 0x12008);
2078 ast_write32(ast, 0x12008, temp);
2080 if (!ast_dram_init_2500(ast))
2081 drm_err(dev, "DRAM init failed !\n");
2083 temp = ast_mindwm(ast, 0x1e6e2040);
2084 ast_moutdwm(ast, 0x1e6e2040, temp | 0x40);
2089 reg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
2090 } while ((reg & 0x40) == 0);