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 drm_device *dev);
38 static void ast_post_chip_2500(struct drm_device *dev);
40 static const u8 extreginfo[] = { 0x0f, 0x04, 0x1c, 0xff };
41 static const u8 extreginfo_ast2300[] = { 0x0f, 0x04, 0x1f, 0xff };
44 ast_set_def_ext_reg(struct drm_device *dev)
46 struct ast_device *ast = to_ast_device(dev);
48 const u8 *ext_reg_info;
51 for (i = 0x81; i <= 0x9f; i++)
52 ast_set_index_reg(ast, AST_IO_VGACRI, i, 0x00);
54 if (IS_AST_GEN4(ast) || IS_AST_GEN5(ast) || IS_AST_GEN6(ast))
55 ext_reg_info = extreginfo_ast2300;
57 ext_reg_info = extreginfo;
60 while (*ext_reg_info != 0xff) {
61 ast_set_index_reg_mask(ast, AST_IO_VGACRI, index, 0x00, *ext_reg_info);
66 /* disable standard IO/MEM decode if secondary */
67 /* ast_set_index_reg-mask(ast, AST_IO_VGACRI, 0xa1, 0xff, 0x3); */
69 /* Set Ext. Default */
70 ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0x8c, 0x00, 0x01);
71 ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb7, 0x00, 0x00);
73 /* Enable RAMDAC for A1 */
75 if (IS_AST_GEN4(ast) || IS_AST_GEN5(ast) || IS_AST_GEN6(ast))
77 ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xff, reg);
80 u32 ast_mindwm(struct ast_device *ast, u32 r)
84 ast_write32(ast, 0xf004, r & 0xffff0000);
85 ast_write32(ast, 0xf000, 0x1);
88 data = ast_read32(ast, 0xf004) & 0xffff0000;
89 } while (data != (r & 0xffff0000));
90 return ast_read32(ast, 0x10000 + (r & 0x0000ffff));
93 void ast_moutdwm(struct ast_device *ast, u32 r, u32 v)
96 ast_write32(ast, 0xf004, r & 0xffff0000);
97 ast_write32(ast, 0xf000, 0x1);
99 data = ast_read32(ast, 0xf004) & 0xffff0000;
100 } while (data != (r & 0xffff0000));
101 ast_write32(ast, 0x10000 + (r & 0x0000ffff), v);
105 * AST2100/2150 DLL CBR Setting
107 #define CBR_SIZE_AST2150 ((16 << 10) - 1)
108 #define CBR_PASSNUM_AST2150 5
109 #define CBR_THRESHOLD_AST2150 10
110 #define CBR_THRESHOLD2_AST2150 10
111 #define TIMEOUT_AST2150 5000000
113 #define CBR_PATNUM_AST2150 8
115 static const u32 pattern_AST2150[14] = {
132 static u32 mmctestburst2_ast2150(struct ast_device *ast, u32 datagen)
136 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
137 ast_moutdwm(ast, 0x1e6e0070, 0x00000001 | (datagen << 3));
140 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
141 if (++timeout > TIMEOUT_AST2150) {
142 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
146 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
147 ast_moutdwm(ast, 0x1e6e0070, 0x00000003 | (datagen << 3));
150 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
151 if (++timeout > TIMEOUT_AST2150) {
152 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
156 data = (ast_mindwm(ast, 0x1e6e0070) & 0x80) >> 7;
157 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
161 #if 0 /* unused in DDX driver - here for completeness */
162 static u32 mmctestsingle2_ast2150(struct ast_device *ast, u32 datagen)
166 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
167 ast_moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3));
170 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
171 if (++timeout > TIMEOUT_AST2150) {
172 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
176 data = (ast_mindwm(ast, 0x1e6e0070) & 0x80) >> 7;
177 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
182 static int cbrtest_ast2150(struct ast_device *ast)
186 for (i = 0; i < 8; i++)
187 if (mmctestburst2_ast2150(ast, i))
192 static int cbrscan_ast2150(struct ast_device *ast, int busw)
196 for (patcnt = 0; patcnt < CBR_PATNUM_AST2150; patcnt++) {
197 ast_moutdwm(ast, 0x1e6e007c, pattern_AST2150[patcnt]);
198 for (loop = 0; loop < CBR_PASSNUM_AST2150; loop++) {
199 if (cbrtest_ast2150(ast))
202 if (loop == CBR_PASSNUM_AST2150)
209 static void cbrdlli_ast2150(struct ast_device *ast, int busw)
211 u32 dll_min[4], dll_max[4], dlli, data, passcnt;
214 dll_min[0] = dll_min[1] = dll_min[2] = dll_min[3] = 0xff;
215 dll_max[0] = dll_max[1] = dll_max[2] = dll_max[3] = 0x0;
218 for (dlli = 0; dlli < 100; dlli++) {
219 ast_moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24));
220 data = cbrscan_ast2150(ast, busw);
223 if (dll_min[0] > dlli)
225 if (dll_max[0] < dlli)
229 } else if (passcnt >= CBR_THRESHOLD_AST2150)
232 if (dll_max[0] == 0 || (dll_max[0]-dll_min[0]) < CBR_THRESHOLD_AST2150)
235 dlli = dll_min[0] + (((dll_max[0] - dll_min[0]) * 7) >> 4);
236 ast_moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24));
241 static void ast_init_dram_reg(struct drm_device *dev)
243 struct ast_device *ast = to_ast_device(dev);
246 const struct ast_dramstruct *dram_reg_info;
248 j = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
250 if ((j & 0x80) == 0) { /* VGA only */
251 if (IS_AST_GEN1(ast)) {
252 dram_reg_info = ast2000_dram_table_data;
253 ast_write32(ast, 0xf004, 0x1e6e0000);
254 ast_write32(ast, 0xf000, 0x1);
255 ast_write32(ast, 0x10100, 0xa8);
259 } while (ast_read32(ast, 0x10100) != 0xa8);
260 } else { /* GEN2/GEN3 */
261 if (ast->chip == AST2100 || ast->chip == AST2200)
262 dram_reg_info = ast2100_dram_table_data;
264 dram_reg_info = ast1100_dram_table_data;
266 ast_write32(ast, 0xf004, 0x1e6e0000);
267 ast_write32(ast, 0xf000, 0x1);
268 ast_write32(ast, 0x12000, 0x1688A8A8);
271 } while (ast_read32(ast, 0x12000) != 0x01);
273 ast_write32(ast, 0x10000, 0xfc600309);
276 } while (ast_read32(ast, 0x10000) != 0x01);
279 while (dram_reg_info->index != 0xffff) {
280 if (dram_reg_info->index == 0xff00) {/* delay fn */
281 for (i = 0; i < 15; i++)
282 udelay(dram_reg_info->data);
283 } else if (dram_reg_info->index == 0x4 && !IS_AST_GEN1(ast)) {
284 data = dram_reg_info->data;
285 if (ast->dram_type == AST_DRAM_1Gx16)
287 else if (ast->dram_type == AST_DRAM_1Gx32)
290 temp = ast_read32(ast, 0x12070);
293 ast_write32(ast, 0x10000 + dram_reg_info->index, data | temp);
295 ast_write32(ast, 0x10000 + dram_reg_info->index, dram_reg_info->data);
299 /* AST 2100/2150 DRAM calibration */
300 data = ast_read32(ast, 0x10120);
301 if (data == 0x5061) { /* 266Mhz */
302 data = ast_read32(ast, 0x10004);
304 cbrdlli_ast2150(ast, 16); /* 16 bits */
306 cbrdlli_ast2150(ast, 32); /* 32 bits */
309 switch (AST_GEN(ast)) {
311 temp = ast_read32(ast, 0x10140);
312 ast_write32(ast, 0x10140, temp | 0x40);
316 temp = ast_read32(ast, 0x1200c);
317 ast_write32(ast, 0x1200c, temp & 0xfffffffd);
318 temp = ast_read32(ast, 0x12040);
319 ast_write32(ast, 0x12040, temp | 0x40);
328 j = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
329 } while ((j & 0x40) == 0);
332 void ast_post_gpu(struct drm_device *dev)
334 struct ast_device *ast = to_ast_device(dev);
336 ast_set_def_ext_reg(dev);
338 if (IS_AST_GEN7(ast)) {
339 if (ast->tx_chip_types & AST_TX_ASTDP_BIT)
341 } else if (ast->config_mode == ast_use_p2a) {
342 if (IS_AST_GEN6(ast))
343 ast_post_chip_2500(dev);
344 else if (IS_AST_GEN5(ast) || IS_AST_GEN4(ast))
345 ast_post_chip_2300(dev);
347 ast_init_dram_reg(dev);
351 if (ast->tx_chip_types & AST_TX_SIL164_BIT)
352 ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xa3, 0xcf, 0x80); /* Enable DVO */
356 /* AST 2300 DRAM settings */
360 struct ast2300_dram_param {
382 u32 dll2_finetune_step;
386 * DQSI DLL CBR Setting
388 #define CBR_SIZE0 ((1 << 10) - 1)
389 #define CBR_SIZE1 ((4 << 10) - 1)
390 #define CBR_SIZE2 ((64 << 10) - 1)
391 #define CBR_PASSNUM 5
392 #define CBR_PASSNUM2 5
393 #define CBR_THRESHOLD 10
394 #define CBR_THRESHOLD2 10
395 #define TIMEOUT 5000000
398 static const u32 pattern[8] = {
409 static bool mmc_test(struct ast_device *ast, u32 datagen, u8 test_ctl)
413 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
414 ast_moutdwm(ast, 0x1e6e0070, (datagen << 3) | test_ctl);
417 data = ast_mindwm(ast, 0x1e6e0070) & 0x3000;
420 if (++timeout > TIMEOUT) {
421 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
425 ast_moutdwm(ast, 0x1e6e0070, 0x0);
429 static u32 mmc_test2(struct ast_device *ast, u32 datagen, u8 test_ctl)
433 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
434 ast_moutdwm(ast, 0x1e6e0070, (datagen << 3) | test_ctl);
437 data = ast_mindwm(ast, 0x1e6e0070) & 0x1000;
438 if (++timeout > TIMEOUT) {
439 ast_moutdwm(ast, 0x1e6e0070, 0x0);
443 data = ast_mindwm(ast, 0x1e6e0078);
444 data = (data | (data >> 16)) & 0xffff;
445 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
450 static bool mmc_test_burst(struct ast_device *ast, u32 datagen)
452 return mmc_test(ast, datagen, 0xc1);
455 static u32 mmc_test_burst2(struct ast_device *ast, u32 datagen)
457 return mmc_test2(ast, datagen, 0x41);
460 static bool mmc_test_single(struct ast_device *ast, u32 datagen)
462 return mmc_test(ast, datagen, 0xc5);
465 static u32 mmc_test_single2(struct ast_device *ast, u32 datagen)
467 return mmc_test2(ast, datagen, 0x05);
470 static bool mmc_test_single_2500(struct ast_device *ast, u32 datagen)
472 return mmc_test(ast, datagen, 0x85);
475 static int cbr_test(struct ast_device *ast)
479 data = mmc_test_single2(ast, 0);
480 if ((data & 0xff) && (data & 0xff00))
482 for (i = 0; i < 8; i++) {
483 data = mmc_test_burst2(ast, i);
484 if ((data & 0xff) && (data & 0xff00))
489 else if (data & 0xff)
494 static int cbr_scan(struct ast_device *ast)
496 u32 data, data2, patcnt, loop;
499 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
500 ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
501 for (loop = 0; loop < CBR_PASSNUM2; loop++) {
502 if ((data = cbr_test(ast)) != 0) {
509 if (loop == CBR_PASSNUM2)
515 static u32 cbr_test2(struct ast_device *ast)
519 data = mmc_test_burst2(ast, 0);
522 data |= mmc_test_single2(ast, 0);
526 return ~data & 0xffff;
529 static u32 cbr_scan2(struct ast_device *ast)
531 u32 data, data2, patcnt, loop;
534 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
535 ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
536 for (loop = 0; loop < CBR_PASSNUM2; loop++) {
537 if ((data = cbr_test2(ast)) != 0) {
544 if (loop == CBR_PASSNUM2)
550 static bool cbr_test3(struct ast_device *ast)
552 if (!mmc_test_burst(ast, 0))
554 if (!mmc_test_single(ast, 0))
559 static bool cbr_scan3(struct ast_device *ast)
563 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
564 ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
565 for (loop = 0; loop < 2; loop++) {
575 static bool finetuneDQI_L(struct ast_device *ast, struct ast2300_dram_param *param)
577 u32 gold_sadj[2], dllmin[16], dllmax[16], dlli, data, cnt, mask, passcnt, retry = 0;
580 for (cnt = 0; cnt < 16; cnt++) {
585 for (dlli = 0; dlli < 76; dlli++) {
586 ast_moutdwm(ast, 0x1E6E0068, 0x00001400 | (dlli << 16) | (dlli << 24));
587 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE1);
588 data = cbr_scan2(ast);
591 for (cnt = 0; cnt < 16; cnt++) {
593 if (dllmin[cnt] > dlli) {
596 if (dllmax[cnt] < dlli) {
603 } else if (passcnt >= CBR_THRESHOLD2) {
609 for (cnt = 0; cnt < 16; cnt++) {
610 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
611 gold_sadj[0] += dllmin[cnt];
622 gold_sadj[0] = gold_sadj[0] >> 4;
623 gold_sadj[1] = gold_sadj[0];
626 for (cnt = 0; cnt < 8; cnt++) {
628 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
630 if (gold_sadj[0] >= dlli) {
631 dlli = ((gold_sadj[0] - dlli) * 19) >> 5;
636 dlli = ((dlli - gold_sadj[0]) * 19) >> 5;
640 dlli = (8 - dlli) & 0x7;
645 ast_moutdwm(ast, 0x1E6E0080, data);
648 for (cnt = 8; cnt < 16; cnt++) {
650 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
652 if (gold_sadj[1] >= dlli) {
653 dlli = ((gold_sadj[1] - dlli) * 19) >> 5;
657 dlli = (dlli - 1) & 0x7;
660 dlli = ((dlli - gold_sadj[1]) * 19) >> 5;
665 dlli = (8 - dlli) & 0x7;
670 ast_moutdwm(ast, 0x1E6E0084, data);
672 } /* finetuneDQI_L */
674 static void finetuneDQSI(struct ast_device *ast)
676 u32 dlli, dqsip, dqidly;
677 u32 reg_mcr18, reg_mcr0c, passcnt[2], diff;
678 u32 g_dqidly, g_dqsip, g_margin, g_side;
682 /* Disable DQI CBR */
683 reg_mcr0c = ast_mindwm(ast, 0x1E6E000C);
684 reg_mcr18 = ast_mindwm(ast, 0x1E6E0018);
685 reg_mcr18 &= 0x0000ffff;
686 ast_moutdwm(ast, 0x1E6E0018, reg_mcr18);
688 for (dlli = 0; dlli < 76; dlli++) {
692 for (dqidly = 0; dqidly < 32; dqidly++) {
693 pass[dqidly][0][0] = 0xff;
694 pass[dqidly][0][1] = 0x0;
695 pass[dqidly][1][0] = 0xff;
696 pass[dqidly][1][1] = 0x0;
698 for (dqidly = 0; dqidly < 32; dqidly++) {
699 passcnt[0] = passcnt[1] = 0;
700 for (dqsip = 0; dqsip < 2; dqsip++) {
701 ast_moutdwm(ast, 0x1E6E000C, 0);
702 ast_moutdwm(ast, 0x1E6E0018, reg_mcr18 | (dqidly << 16) | (dqsip << 23));
703 ast_moutdwm(ast, 0x1E6E000C, reg_mcr0c);
704 for (dlli = 0; dlli < 76; dlli++) {
705 ast_moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24));
706 ast_moutdwm(ast, 0x1E6E0070, 0);
707 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE0);
708 if (cbr_scan3(ast)) {
712 tag[dqsip][dlli] = 'P';
713 if (dlli < pass[dqidly][dqsip][0])
714 pass[dqidly][dqsip][0] = (u16) dlli;
715 if (dlli > pass[dqidly][dqsip][1])
716 pass[dqidly][dqsip][1] = (u16) dlli;
717 } else if (passcnt[dqsip] >= 5)
720 pass[dqidly][dqsip][0] = 0xff;
721 pass[dqidly][dqsip][1] = 0x0;
725 if (passcnt[0] == 0 && passcnt[1] == 0)
729 g_dqidly = g_dqsip = g_margin = g_side = 0;
731 for (dqidly = 0; dqidly < 32; dqidly++) {
732 for (dqsip = 0; dqsip < 2; dqsip++) {
733 if (pass[dqidly][dqsip][0] > pass[dqidly][dqsip][1])
735 diff = pass[dqidly][dqsip][1] - pass[dqidly][dqsip][0];
736 if ((diff+2) < g_margin)
738 passcnt[0] = passcnt[1] = 0;
739 for (dlli = pass[dqidly][dqsip][0]; dlli > 0 && tag[dqsip][dlli] != 0; dlli--, passcnt[0]++);
740 for (dlli = pass[dqidly][dqsip][1]; dlli < 76 && tag[dqsip][dlli] != 0; dlli++, passcnt[1]++);
741 if (passcnt[0] > passcnt[1])
742 passcnt[0] = passcnt[1];
744 if (passcnt[0] > g_side)
745 passcnt[1] = passcnt[0] - g_side;
746 if (diff > (g_margin+1) && (passcnt[1] > 0 || passcnt[0] > 8)) {
751 } else if (passcnt[1] > 1 && g_side < 8) {
760 reg_mcr18 = reg_mcr18 | (g_dqidly << 16) | (g_dqsip << 23);
761 ast_moutdwm(ast, 0x1E6E0018, reg_mcr18);
764 static bool cbr_dll2(struct ast_device *ast, struct ast2300_dram_param *param)
766 u32 dllmin[2], dllmax[2], dlli, data, passcnt, retry = 0;
770 if (finetuneDQI_L(ast, param) == false)
774 dllmin[0] = dllmin[1] = 0xff;
775 dllmax[0] = dllmax[1] = 0x0;
777 for (dlli = 0; dlli < 76; dlli++) {
778 ast_moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24));
779 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE2);
780 data = cbr_scan(ast);
783 if (dllmin[0] > dlli) {
786 if (dllmax[0] < dlli) {
791 if (dllmin[1] > dlli) {
794 if (dllmax[1] < dlli) {
799 } else if (passcnt >= CBR_THRESHOLD) {
805 if (dllmax[0] == 0 || (dllmax[0]-dllmin[0]) < CBR_THRESHOLD) {
808 if (dllmax[1] == 0 || (dllmax[1]-dllmin[1]) < CBR_THRESHOLD) {
813 dlli = (dllmin[1] + dllmax[1]) >> 1;
815 dlli += (dllmin[0] + dllmax[0]) >> 1;
816 ast_moutdwm(ast, 0x1E6E0068, ast_mindwm(ast, 0x1E720058) | (dlli << 16));
820 static void get_ddr3_info(struct ast_device *ast, struct ast2300_dram_param *param)
822 u32 trap, trap_AC2, trap_MRS;
824 ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
827 trap = (ast_mindwm(ast, 0x1E6E2070) >> 25) & 0x3;
828 trap_AC2 = 0x00020000 + (trap << 16);
829 trap_AC2 |= 0x00300000 + ((trap & 0x2) << 19);
830 trap_MRS = 0x00000010 + (trap << 4);
831 trap_MRS |= ((trap & 0x2) << 18);
833 param->reg_MADJ = 0x00034C4C;
834 param->reg_SADJ = 0x00001800;
835 param->reg_DRV = 0x000000F0;
836 param->reg_PERIOD = param->dram_freq;
839 switch (param->dram_freq) {
841 ast_moutdwm(ast, 0x1E6E2020, 0x0190);
843 param->reg_AC1 = 0x22202725;
844 param->reg_AC2 = 0xAA007613 | trap_AC2;
845 param->reg_DQSIC = 0x000000BA;
846 param->reg_MRS = 0x04001400 | trap_MRS;
847 param->reg_EMRS = 0x00000000;
848 param->reg_IOZ = 0x00000023;
849 param->reg_DQIDLY = 0x00000074;
850 param->reg_FREQ = 0x00004DC0;
851 param->madj_max = 96;
852 param->dll2_finetune_step = 3;
853 switch (param->dram_chipid) {
855 case AST_DRAM_512Mx16:
857 param->reg_AC2 = 0xAA007613 | trap_AC2;
860 param->reg_AC2 = 0xAA00761C | trap_AC2;
863 param->reg_AC2 = 0xAA007636 | trap_AC2;
869 ast_moutdwm(ast, 0x1E6E2020, 0x03F1);
871 param->reg_AC1 = 0x33302825;
872 param->reg_AC2 = 0xCC009617 | trap_AC2;
873 param->reg_DQSIC = 0x000000E2;
874 param->reg_MRS = 0x04001600 | trap_MRS;
875 param->reg_EMRS = 0x00000000;
876 param->reg_IOZ = 0x00000034;
877 param->reg_DRV = 0x000000FA;
878 param->reg_DQIDLY = 0x00000089;
879 param->reg_FREQ = 0x00005040;
880 param->madj_max = 96;
881 param->dll2_finetune_step = 4;
883 switch (param->dram_chipid) {
885 case AST_DRAM_512Mx16:
887 param->reg_AC2 = 0xCC009617 | trap_AC2;
890 param->reg_AC2 = 0xCC009622 | trap_AC2;
893 param->reg_AC2 = 0xCC00963F | trap_AC2;
899 ast_moutdwm(ast, 0x1E6E2020, 0x01F0);
901 param->reg_AC1 = 0x33302825;
902 param->reg_AC2 = 0xCC009617 | trap_AC2;
903 param->reg_DQSIC = 0x000000E2;
904 param->reg_MRS = 0x04001600 | trap_MRS;
905 param->reg_EMRS = 0x00000000;
906 param->reg_IOZ = 0x00000023;
907 param->reg_DRV = 0x000000FA;
908 param->reg_DQIDLY = 0x00000089;
909 param->reg_FREQ = 0x000050C0;
910 param->madj_max = 96;
911 param->dll2_finetune_step = 4;
913 switch (param->dram_chipid) {
915 case AST_DRAM_512Mx16:
917 param->reg_AC2 = 0xCC009617 | trap_AC2;
920 param->reg_AC2 = 0xCC009622 | trap_AC2;
923 param->reg_AC2 = 0xCC00963F | trap_AC2;
929 ast_moutdwm(ast, 0x1E6E2020, 0x0230);
931 param->reg_AC1 = 0x33302926;
932 param->reg_AC2 = 0xCD44961A;
933 param->reg_DQSIC = 0x000000FC;
934 param->reg_MRS = 0x00081830;
935 param->reg_EMRS = 0x00000000;
936 param->reg_IOZ = 0x00000045;
937 param->reg_DQIDLY = 0x00000097;
938 param->reg_FREQ = 0x000052C0;
939 param->madj_max = 88;
940 param->dll2_finetune_step = 4;
943 ast_moutdwm(ast, 0x1E6E2020, 0x0270);
945 param->reg_AC1 = 0x33302926;
946 param->reg_AC2 = 0xDE44A61D;
947 param->reg_DQSIC = 0x00000117;
948 param->reg_MRS = 0x00081A30;
949 param->reg_EMRS = 0x00000000;
950 param->reg_IOZ = 0x070000BB;
951 param->reg_DQIDLY = 0x000000A0;
952 param->reg_FREQ = 0x000054C0;
953 param->madj_max = 79;
954 param->dll2_finetune_step = 4;
957 ast_moutdwm(ast, 0x1E6E2020, 0x0290);
960 param->reg_AC1 = 0x33302926;
961 param->reg_AC2 = 0xEF44B61E;
962 param->reg_DQSIC = 0x00000125;
963 param->reg_MRS = 0x00081A30;
964 param->reg_EMRS = 0x00000040;
965 param->reg_DRV = 0x000000F5;
966 param->reg_IOZ = 0x00000023;
967 param->reg_DQIDLY = 0x00000088;
968 param->reg_FREQ = 0x000055C0;
969 param->madj_max = 76;
970 param->dll2_finetune_step = 3;
973 ast_moutdwm(ast, 0x1E6E2020, 0x0140);
974 param->reg_MADJ = 0x00136868;
975 param->reg_SADJ = 0x00004534;
978 param->reg_AC1 = 0x33302A37;
979 param->reg_AC2 = 0xEF56B61E;
980 param->reg_DQSIC = 0x0000013F;
981 param->reg_MRS = 0x00101A50;
982 param->reg_EMRS = 0x00000040;
983 param->reg_DRV = 0x000000FA;
984 param->reg_IOZ = 0x00000023;
985 param->reg_DQIDLY = 0x00000078;
986 param->reg_FREQ = 0x000057C0;
987 param->madj_max = 136;
988 param->dll2_finetune_step = 3;
991 ast_moutdwm(ast, 0x1E6E2020, 0x02E1);
992 param->reg_MADJ = 0x00136868;
993 param->reg_SADJ = 0x00004534;
996 param->reg_AC1 = 0x32302A37;
997 param->reg_AC2 = 0xDF56B61F;
998 param->reg_DQSIC = 0x0000014D;
999 param->reg_MRS = 0x00101A50;
1000 param->reg_EMRS = 0x00000004;
1001 param->reg_DRV = 0x000000F5;
1002 param->reg_IOZ = 0x00000023;
1003 param->reg_DQIDLY = 0x00000078;
1004 param->reg_FREQ = 0x000058C0;
1005 param->madj_max = 132;
1006 param->dll2_finetune_step = 3;
1009 ast_moutdwm(ast, 0x1E6E2020, 0x0160);
1010 param->reg_MADJ = 0x00136868;
1011 param->reg_SADJ = 0x00004534;
1014 param->reg_AC1 = 0x32302A37;
1015 param->reg_AC2 = 0xEF56B621;
1016 param->reg_DQSIC = 0x0000015A;
1017 param->reg_MRS = 0x02101A50;
1018 param->reg_EMRS = 0x00000004;
1019 param->reg_DRV = 0x000000F5;
1020 param->reg_IOZ = 0x00000034;
1021 param->reg_DQIDLY = 0x00000078;
1022 param->reg_FREQ = 0x000059C0;
1023 param->madj_max = 128;
1024 param->dll2_finetune_step = 3;
1028 switch (param->dram_chipid) {
1029 case AST_DRAM_512Mx16:
1030 param->dram_config = 0x130;
1033 case AST_DRAM_1Gx16:
1034 param->dram_config = 0x131;
1036 case AST_DRAM_2Gx16:
1037 param->dram_config = 0x132;
1039 case AST_DRAM_4Gx16:
1040 param->dram_config = 0x133;
1044 switch (param->vram_size) {
1046 case AST_VIDMEM_SIZE_8M:
1047 param->dram_config |= 0x00;
1049 case AST_VIDMEM_SIZE_16M:
1050 param->dram_config |= 0x04;
1052 case AST_VIDMEM_SIZE_32M:
1053 param->dram_config |= 0x08;
1055 case AST_VIDMEM_SIZE_64M:
1056 param->dram_config |= 0x0c;
1062 static void ddr3_init(struct ast_device *ast, struct ast2300_dram_param *param)
1064 u32 data, data2, retry = 0;
1067 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1068 ast_moutdwm(ast, 0x1E6E0018, 0x00000100);
1069 ast_moutdwm(ast, 0x1E6E0024, 0x00000000);
1070 ast_moutdwm(ast, 0x1E6E0034, 0x00000000);
1072 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ);
1073 ast_moutdwm(ast, 0x1E6E0068, param->reg_SADJ);
1075 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000);
1078 ast_moutdwm(ast, 0x1E6E0004, param->dram_config);
1079 ast_moutdwm(ast, 0x1E6E0008, 0x90040f);
1080 ast_moutdwm(ast, 0x1E6E0010, param->reg_AC1);
1081 ast_moutdwm(ast, 0x1E6E0014, param->reg_AC2);
1082 ast_moutdwm(ast, 0x1E6E0020, param->reg_DQSIC);
1083 ast_moutdwm(ast, 0x1E6E0080, 0x00000000);
1084 ast_moutdwm(ast, 0x1E6E0084, 0x00000000);
1085 ast_moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY);
1086 ast_moutdwm(ast, 0x1E6E0018, 0x4000A170);
1087 ast_moutdwm(ast, 0x1E6E0018, 0x00002370);
1088 ast_moutdwm(ast, 0x1E6E0038, 0x00000000);
1089 ast_moutdwm(ast, 0x1E6E0040, 0xFF444444);
1090 ast_moutdwm(ast, 0x1E6E0044, 0x22222222);
1091 ast_moutdwm(ast, 0x1E6E0048, 0x22222222);
1092 ast_moutdwm(ast, 0x1E6E004C, 0x00000002);
1093 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1094 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1095 ast_moutdwm(ast, 0x1E6E0054, 0);
1096 ast_moutdwm(ast, 0x1E6E0060, param->reg_DRV);
1097 ast_moutdwm(ast, 0x1E6E006C, param->reg_IOZ);
1098 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1099 ast_moutdwm(ast, 0x1E6E0074, 0x00000000);
1100 ast_moutdwm(ast, 0x1E6E0078, 0x00000000);
1101 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1102 /* Wait MCLK2X lock to MCLK */
1104 data = ast_mindwm(ast, 0x1E6E001C);
1105 } while (!(data & 0x08000000));
1106 data = ast_mindwm(ast, 0x1E6E001C);
1107 data = (data >> 8) & 0xff;
1108 while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) {
1109 data2 = (ast_mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4;
1110 if ((data2 & 0xff) > param->madj_max) {
1113 ast_moutdwm(ast, 0x1E6E0064, data2);
1114 if (data2 & 0x00100000) {
1115 data2 = ((data2 & 0xff) >> 3) + 3;
1117 data2 = ((data2 & 0xff) >> 2) + 5;
1119 data = ast_mindwm(ast, 0x1E6E0068) & 0xffff00ff;
1120 data2 += data & 0xff;
1121 data = data | (data2 << 8);
1122 ast_moutdwm(ast, 0x1E6E0068, data);
1124 ast_moutdwm(ast, 0x1E6E0064, ast_mindwm(ast, 0x1E6E0064) | 0xC0000);
1126 data = ast_mindwm(ast, 0x1E6E0018) & 0xfffff1ff;
1127 ast_moutdwm(ast, 0x1E6E0018, data);
1128 data = data | 0x200;
1129 ast_moutdwm(ast, 0x1E6E0018, data);
1131 data = ast_mindwm(ast, 0x1E6E001C);
1132 } while (!(data & 0x08000000));
1134 data = ast_mindwm(ast, 0x1E6E001C);
1135 data = (data >> 8) & 0xff;
1137 ast_moutdwm(ast, 0x1E720058, ast_mindwm(ast, 0x1E6E0068) & 0xffff);
1138 data = ast_mindwm(ast, 0x1E6E0018) | 0xC00;
1139 ast_moutdwm(ast, 0x1E6E0018, data);
1141 ast_moutdwm(ast, 0x1E6E0034, 0x00000001);
1142 ast_moutdwm(ast, 0x1E6E000C, 0x00000040);
1144 /* Mode Register Setting */
1145 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100);
1146 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1147 ast_moutdwm(ast, 0x1E6E0028, 0x00000005);
1148 ast_moutdwm(ast, 0x1E6E0028, 0x00000007);
1149 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1150 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1151 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS);
1152 ast_moutdwm(ast, 0x1E6E000C, 0x00005C08);
1153 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1155 ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
1161 data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3);
1163 ast_moutdwm(ast, 0x1E6E0034, data | 0x3);
1165 /* Calibrate the DQSI delay */
1166 if ((cbr_dll2(ast, param) == false) && (retry++ < 10))
1167 goto ddr3_init_start;
1169 ast_moutdwm(ast, 0x1E6E0120, param->reg_FREQ);
1170 /* ECC Memory Initialization */
1172 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1173 ast_moutdwm(ast, 0x1E6E0070, 0x221);
1175 data = ast_mindwm(ast, 0x1E6E0070);
1176 } while (!(data & 0x00001000));
1177 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1178 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1179 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1185 static void get_ddr2_info(struct ast_device *ast, struct ast2300_dram_param *param)
1187 u32 trap, trap_AC2, trap_MRS;
1189 ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
1192 trap = (ast_mindwm(ast, 0x1E6E2070) >> 25) & 0x3;
1193 trap_AC2 = (trap << 20) | (trap << 16);
1194 trap_AC2 += 0x00110000;
1195 trap_MRS = 0x00000040 | (trap << 4);
1198 param->reg_MADJ = 0x00034C4C;
1199 param->reg_SADJ = 0x00001800;
1200 param->reg_DRV = 0x000000F0;
1201 param->reg_PERIOD = param->dram_freq;
1204 switch (param->dram_freq) {
1206 ast_moutdwm(ast, 0x1E6E2020, 0x0130);
1208 param->reg_AC1 = 0x11101513;
1209 param->reg_AC2 = 0x78117011;
1210 param->reg_DQSIC = 0x00000092;
1211 param->reg_MRS = 0x00000842;
1212 param->reg_EMRS = 0x00000000;
1213 param->reg_DRV = 0x000000F0;
1214 param->reg_IOZ = 0x00000034;
1215 param->reg_DQIDLY = 0x0000005A;
1216 param->reg_FREQ = 0x00004AC0;
1217 param->madj_max = 138;
1218 param->dll2_finetune_step = 3;
1221 ast_moutdwm(ast, 0x1E6E2020, 0x0190);
1223 param->reg_AC1 = 0x22202613;
1224 param->reg_AC2 = 0xAA009016 | trap_AC2;
1225 param->reg_DQSIC = 0x000000BA;
1226 param->reg_MRS = 0x00000A02 | trap_MRS;
1227 param->reg_EMRS = 0x00000040;
1228 param->reg_DRV = 0x000000FA;
1229 param->reg_IOZ = 0x00000034;
1230 param->reg_DQIDLY = 0x00000074;
1231 param->reg_FREQ = 0x00004DC0;
1232 param->madj_max = 96;
1233 param->dll2_finetune_step = 3;
1234 switch (param->dram_chipid) {
1236 case AST_DRAM_512Mx16:
1237 param->reg_AC2 = 0xAA009012 | trap_AC2;
1239 case AST_DRAM_1Gx16:
1240 param->reg_AC2 = 0xAA009016 | trap_AC2;
1242 case AST_DRAM_2Gx16:
1243 param->reg_AC2 = 0xAA009023 | trap_AC2;
1245 case AST_DRAM_4Gx16:
1246 param->reg_AC2 = 0xAA00903B | trap_AC2;
1252 ast_moutdwm(ast, 0x1E6E2020, 0x03F1);
1255 param->reg_AC1 = 0x33302714;
1256 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1257 param->reg_DQSIC = 0x000000E2;
1258 param->reg_MRS = 0x00000C02 | trap_MRS;
1259 param->reg_EMRS = 0x00000040;
1260 param->reg_DRV = 0x000000FA;
1261 param->reg_IOZ = 0x00000034;
1262 param->reg_DQIDLY = 0x00000089;
1263 param->reg_FREQ = 0x00005040;
1264 param->madj_max = 96;
1265 param->dll2_finetune_step = 4;
1267 switch (param->dram_chipid) {
1268 case AST_DRAM_512Mx16:
1269 param->reg_AC2 = 0xCC00B016 | trap_AC2;
1272 case AST_DRAM_1Gx16:
1273 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1275 case AST_DRAM_2Gx16:
1276 param->reg_AC2 = 0xCC00B02B | trap_AC2;
1278 case AST_DRAM_4Gx16:
1279 param->reg_AC2 = 0xCC00B03F | trap_AC2;
1286 ast_moutdwm(ast, 0x1E6E2020, 0x01F0);
1289 param->reg_AC1 = 0x33302714;
1290 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1291 param->reg_DQSIC = 0x000000E2;
1292 param->reg_MRS = 0x00000C02 | trap_MRS;
1293 param->reg_EMRS = 0x00000040;
1294 param->reg_DRV = 0x000000FA;
1295 param->reg_IOZ = 0x00000034;
1296 param->reg_DQIDLY = 0x00000089;
1297 param->reg_FREQ = 0x000050C0;
1298 param->madj_max = 96;
1299 param->dll2_finetune_step = 4;
1301 switch (param->dram_chipid) {
1302 case AST_DRAM_512Mx16:
1303 param->reg_AC2 = 0xCC00B016 | trap_AC2;
1306 case AST_DRAM_1Gx16:
1307 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1309 case AST_DRAM_2Gx16:
1310 param->reg_AC2 = 0xCC00B02B | trap_AC2;
1312 case AST_DRAM_4Gx16:
1313 param->reg_AC2 = 0xCC00B03F | trap_AC2;
1319 ast_moutdwm(ast, 0x1E6E2020, 0x0230);
1321 param->reg_AC1 = 0x33302815;
1322 param->reg_AC2 = 0xCD44B01E;
1323 param->reg_DQSIC = 0x000000FC;
1324 param->reg_MRS = 0x00000E72;
1325 param->reg_EMRS = 0x00000000;
1326 param->reg_DRV = 0x00000000;
1327 param->reg_IOZ = 0x00000034;
1328 param->reg_DQIDLY = 0x00000097;
1329 param->reg_FREQ = 0x000052C0;
1330 param->madj_max = 88;
1331 param->dll2_finetune_step = 3;
1334 ast_moutdwm(ast, 0x1E6E2020, 0x0261);
1337 param->reg_AC1 = 0x33302815;
1338 param->reg_AC2 = 0xDE44C022;
1339 param->reg_DQSIC = 0x00000117;
1340 param->reg_MRS = 0x00000E72;
1341 param->reg_EMRS = 0x00000040;
1342 param->reg_DRV = 0x0000000A;
1343 param->reg_IOZ = 0x00000045;
1344 param->reg_DQIDLY = 0x000000A0;
1345 param->reg_FREQ = 0x000054C0;
1346 param->madj_max = 79;
1347 param->dll2_finetune_step = 3;
1350 ast_moutdwm(ast, 0x1E6E2020, 0x0120);
1353 param->reg_AC1 = 0x33302815;
1354 param->reg_AC2 = 0xEF44D024;
1355 param->reg_DQSIC = 0x00000125;
1356 param->reg_MRS = 0x00000E72;
1357 param->reg_EMRS = 0x00000004;
1358 param->reg_DRV = 0x000000F9;
1359 param->reg_IOZ = 0x00000045;
1360 param->reg_DQIDLY = 0x000000A7;
1361 param->reg_FREQ = 0x000055C0;
1362 param->madj_max = 76;
1363 param->dll2_finetune_step = 3;
1366 ast_moutdwm(ast, 0x1E6E2020, 0x02A1);
1369 param->reg_AC1 = 0x43402915;
1370 param->reg_AC2 = 0xFF44E025;
1371 param->reg_DQSIC = 0x00000132;
1372 param->reg_MRS = 0x00000E72;
1373 param->reg_EMRS = 0x00000040;
1374 param->reg_DRV = 0x0000000A;
1375 param->reg_IOZ = 0x00000045;
1376 param->reg_DQIDLY = 0x000000AD;
1377 param->reg_FREQ = 0x000056C0;
1378 param->madj_max = 76;
1379 param->dll2_finetune_step = 3;
1382 ast_moutdwm(ast, 0x1E6E2020, 0x0140);
1385 param->reg_AC1 = 0x43402915;
1386 param->reg_AC2 = 0xFF44E027;
1387 param->reg_DQSIC = 0x0000013F;
1388 param->reg_MRS = 0x00000E72;
1389 param->reg_EMRS = 0x00000004;
1390 param->reg_DRV = 0x000000F5;
1391 param->reg_IOZ = 0x00000045;
1392 param->reg_DQIDLY = 0x000000B3;
1393 param->reg_FREQ = 0x000057C0;
1394 param->madj_max = 76;
1395 param->dll2_finetune_step = 3;
1399 switch (param->dram_chipid) {
1400 case AST_DRAM_512Mx16:
1401 param->dram_config = 0x100;
1404 case AST_DRAM_1Gx16:
1405 param->dram_config = 0x121;
1407 case AST_DRAM_2Gx16:
1408 param->dram_config = 0x122;
1410 case AST_DRAM_4Gx16:
1411 param->dram_config = 0x123;
1415 switch (param->vram_size) {
1417 case AST_VIDMEM_SIZE_8M:
1418 param->dram_config |= 0x00;
1420 case AST_VIDMEM_SIZE_16M:
1421 param->dram_config |= 0x04;
1423 case AST_VIDMEM_SIZE_32M:
1424 param->dram_config |= 0x08;
1426 case AST_VIDMEM_SIZE_64M:
1427 param->dram_config |= 0x0c;
1432 static void ddr2_init(struct ast_device *ast, struct ast2300_dram_param *param)
1434 u32 data, data2, retry = 0;
1437 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1438 ast_moutdwm(ast, 0x1E6E0018, 0x00000100);
1439 ast_moutdwm(ast, 0x1E6E0024, 0x00000000);
1440 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ);
1441 ast_moutdwm(ast, 0x1E6E0068, param->reg_SADJ);
1443 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000);
1446 ast_moutdwm(ast, 0x1E6E0004, param->dram_config);
1447 ast_moutdwm(ast, 0x1E6E0008, 0x90040f);
1448 ast_moutdwm(ast, 0x1E6E0010, param->reg_AC1);
1449 ast_moutdwm(ast, 0x1E6E0014, param->reg_AC2);
1450 ast_moutdwm(ast, 0x1E6E0020, param->reg_DQSIC);
1451 ast_moutdwm(ast, 0x1E6E0080, 0x00000000);
1452 ast_moutdwm(ast, 0x1E6E0084, 0x00000000);
1453 ast_moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY);
1454 ast_moutdwm(ast, 0x1E6E0018, 0x4000A130);
1455 ast_moutdwm(ast, 0x1E6E0018, 0x00002330);
1456 ast_moutdwm(ast, 0x1E6E0038, 0x00000000);
1457 ast_moutdwm(ast, 0x1E6E0040, 0xFF808000);
1458 ast_moutdwm(ast, 0x1E6E0044, 0x88848466);
1459 ast_moutdwm(ast, 0x1E6E0048, 0x44440008);
1460 ast_moutdwm(ast, 0x1E6E004C, 0x00000000);
1461 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1462 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1463 ast_moutdwm(ast, 0x1E6E0054, 0);
1464 ast_moutdwm(ast, 0x1E6E0060, param->reg_DRV);
1465 ast_moutdwm(ast, 0x1E6E006C, param->reg_IOZ);
1466 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1467 ast_moutdwm(ast, 0x1E6E0074, 0x00000000);
1468 ast_moutdwm(ast, 0x1E6E0078, 0x00000000);
1469 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1471 /* Wait MCLK2X lock to MCLK */
1473 data = ast_mindwm(ast, 0x1E6E001C);
1474 } while (!(data & 0x08000000));
1475 data = ast_mindwm(ast, 0x1E6E001C);
1476 data = (data >> 8) & 0xff;
1477 while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) {
1478 data2 = (ast_mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4;
1479 if ((data2 & 0xff) > param->madj_max) {
1482 ast_moutdwm(ast, 0x1E6E0064, data2);
1483 if (data2 & 0x00100000) {
1484 data2 = ((data2 & 0xff) >> 3) + 3;
1486 data2 = ((data2 & 0xff) >> 2) + 5;
1488 data = ast_mindwm(ast, 0x1E6E0068) & 0xffff00ff;
1489 data2 += data & 0xff;
1490 data = data | (data2 << 8);
1491 ast_moutdwm(ast, 0x1E6E0068, data);
1493 ast_moutdwm(ast, 0x1E6E0064, ast_mindwm(ast, 0x1E6E0064) | 0xC0000);
1495 data = ast_mindwm(ast, 0x1E6E0018) & 0xfffff1ff;
1496 ast_moutdwm(ast, 0x1E6E0018, data);
1497 data = data | 0x200;
1498 ast_moutdwm(ast, 0x1E6E0018, data);
1500 data = ast_mindwm(ast, 0x1E6E001C);
1501 } while (!(data & 0x08000000));
1503 data = ast_mindwm(ast, 0x1E6E001C);
1504 data = (data >> 8) & 0xff;
1506 ast_moutdwm(ast, 0x1E720058, ast_mindwm(ast, 0x1E6E0008) & 0xffff);
1507 data = ast_mindwm(ast, 0x1E6E0018) | 0xC00;
1508 ast_moutdwm(ast, 0x1E6E0018, data);
1510 ast_moutdwm(ast, 0x1E6E0034, 0x00000001);
1511 ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
1513 /* Mode Register Setting */
1514 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100);
1515 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1516 ast_moutdwm(ast, 0x1E6E0028, 0x00000005);
1517 ast_moutdwm(ast, 0x1E6E0028, 0x00000007);
1518 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1519 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1521 ast_moutdwm(ast, 0x1E6E000C, 0x00005C08);
1522 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS);
1523 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1524 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS | 0x380);
1525 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1526 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1527 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1529 ast_moutdwm(ast, 0x1E6E000C, 0x7FFF5C01);
1535 data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3);
1537 ast_moutdwm(ast, 0x1E6E0034, data | 0x3);
1538 ast_moutdwm(ast, 0x1E6E0120, param->reg_FREQ);
1540 /* Calibrate the DQSI delay */
1541 if ((cbr_dll2(ast, param) == false) && (retry++ < 10))
1542 goto ddr2_init_start;
1544 /* ECC Memory Initialization */
1546 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1547 ast_moutdwm(ast, 0x1E6E0070, 0x221);
1549 data = ast_mindwm(ast, 0x1E6E0070);
1550 } while (!(data & 0x00001000));
1551 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1552 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1553 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1558 static void ast_post_chip_2300(struct drm_device *dev)
1560 struct ast_device *ast = to_ast_device(dev);
1561 struct ast2300_dram_param param;
1565 reg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
1566 if ((reg & 0x80) == 0) {/* vga only */
1567 ast_write32(ast, 0xf004, 0x1e6e0000);
1568 ast_write32(ast, 0xf000, 0x1);
1569 ast_write32(ast, 0x12000, 0x1688a8a8);
1572 } while (ast_read32(ast, 0x12000) != 0x1);
1574 ast_write32(ast, 0x10000, 0xfc600309);
1577 } while (ast_read32(ast, 0x10000) != 0x1);
1579 /* Slow down CPU/AHB CLK in VGA only mode */
1580 temp = ast_read32(ast, 0x12008);
1582 ast_write32(ast, 0x12008, temp);
1584 param.dram_freq = 396;
1585 param.dram_type = AST_DDR3;
1586 temp = ast_mindwm(ast, 0x1e6e2070);
1587 if (temp & 0x01000000)
1588 param.dram_type = AST_DDR2;
1589 switch (temp & 0x18000000) {
1591 param.dram_chipid = AST_DRAM_512Mx16;
1595 param.dram_chipid = AST_DRAM_1Gx16;
1598 param.dram_chipid = AST_DRAM_2Gx16;
1601 param.dram_chipid = AST_DRAM_4Gx16;
1604 switch (temp & 0x0c) {
1607 param.vram_size = AST_VIDMEM_SIZE_8M;
1611 param.vram_size = AST_VIDMEM_SIZE_16M;
1615 param.vram_size = AST_VIDMEM_SIZE_32M;
1619 param.vram_size = AST_VIDMEM_SIZE_64M;
1623 if (param.dram_type == AST_DDR3) {
1624 get_ddr3_info(ast, ¶m);
1625 ddr3_init(ast, ¶m);
1627 get_ddr2_info(ast, ¶m);
1628 ddr2_init(ast, ¶m);
1631 temp = ast_mindwm(ast, 0x1e6e2040);
1632 ast_moutdwm(ast, 0x1e6e2040, temp | 0x40);
1637 reg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
1638 } while ((reg & 0x40) == 0);
1641 static bool cbr_test_2500(struct ast_device *ast)
1643 ast_moutdwm(ast, 0x1E6E0074, 0x0000FFFF);
1644 ast_moutdwm(ast, 0x1E6E007C, 0xFF00FF00);
1645 if (!mmc_test_burst(ast, 0))
1647 if (!mmc_test_single_2500(ast, 0))
1652 static bool ddr_test_2500(struct ast_device *ast)
1654 ast_moutdwm(ast, 0x1E6E0074, 0x0000FFFF);
1655 ast_moutdwm(ast, 0x1E6E007C, 0xFF00FF00);
1656 if (!mmc_test_burst(ast, 0))
1658 if (!mmc_test_burst(ast, 1))
1660 if (!mmc_test_burst(ast, 2))
1662 if (!mmc_test_burst(ast, 3))
1664 if (!mmc_test_single_2500(ast, 0))
1669 static void ddr_init_common_2500(struct ast_device *ast)
1671 ast_moutdwm(ast, 0x1E6E0034, 0x00020080);
1672 ast_moutdwm(ast, 0x1E6E0008, 0x2003000F);
1673 ast_moutdwm(ast, 0x1E6E0038, 0x00000FFF);
1674 ast_moutdwm(ast, 0x1E6E0040, 0x88448844);
1675 ast_moutdwm(ast, 0x1E6E0044, 0x24422288);
1676 ast_moutdwm(ast, 0x1E6E0048, 0x22222222);
1677 ast_moutdwm(ast, 0x1E6E004C, 0x22222222);
1678 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1679 ast_moutdwm(ast, 0x1E6E0208, 0x00000000);
1680 ast_moutdwm(ast, 0x1E6E0218, 0x00000000);
1681 ast_moutdwm(ast, 0x1E6E0220, 0x00000000);
1682 ast_moutdwm(ast, 0x1E6E0228, 0x00000000);
1683 ast_moutdwm(ast, 0x1E6E0230, 0x00000000);
1684 ast_moutdwm(ast, 0x1E6E02A8, 0x00000000);
1685 ast_moutdwm(ast, 0x1E6E02B0, 0x00000000);
1686 ast_moutdwm(ast, 0x1E6E0240, 0x86000000);
1687 ast_moutdwm(ast, 0x1E6E0244, 0x00008600);
1688 ast_moutdwm(ast, 0x1E6E0248, 0x80000000);
1689 ast_moutdwm(ast, 0x1E6E024C, 0x80808080);
1692 static void ddr_phy_init_2500(struct ast_device *ast)
1694 u32 data, pass, timecnt;
1697 ast_moutdwm(ast, 0x1E6E0060, 0x00000005);
1699 for (timecnt = 0; timecnt < TIMEOUT; timecnt++) {
1700 data = ast_mindwm(ast, 0x1E6E0060) & 0x1;
1704 if (timecnt != TIMEOUT) {
1705 data = ast_mindwm(ast, 0x1E6E0300) & 0x000A0000;
1710 ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
1711 udelay(10); /* delay 10 us */
1712 ast_moutdwm(ast, 0x1E6E0060, 0x00000005);
1716 ast_moutdwm(ast, 0x1E6E0060, 0x00000006);
1721 * 1Gb : 0x80000000 ~ 0x87FFFFFF
1722 * 2Gb : 0x80000000 ~ 0x8FFFFFFF
1723 * 4Gb : 0x80000000 ~ 0x9FFFFFFF
1724 * 8Gb : 0x80000000 ~ 0xBFFFFFFF
1726 static void check_dram_size_2500(struct ast_device *ast, u32 tRFC)
1730 reg_04 = ast_mindwm(ast, 0x1E6E0004) & 0xfffffffc;
1731 reg_14 = ast_mindwm(ast, 0x1E6E0014) & 0xffffff00;
1733 ast_moutdwm(ast, 0xA0100000, 0x41424344);
1734 ast_moutdwm(ast, 0x90100000, 0x35363738);
1735 ast_moutdwm(ast, 0x88100000, 0x292A2B2C);
1736 ast_moutdwm(ast, 0x80100000, 0x1D1E1F10);
1739 if (ast_mindwm(ast, 0xA0100000) == 0x41424344) {
1741 reg_14 |= (tRFC >> 24) & 0xFF;
1743 } else if (ast_mindwm(ast, 0x90100000) == 0x35363738) {
1745 reg_14 |= (tRFC >> 16) & 0xFF;
1747 } else if (ast_mindwm(ast, 0x88100000) == 0x292A2B2C) {
1749 reg_14 |= (tRFC >> 8) & 0xFF;
1751 reg_14 |= tRFC & 0xFF;
1753 ast_moutdwm(ast, 0x1E6E0004, reg_04);
1754 ast_moutdwm(ast, 0x1E6E0014, reg_14);
1757 static void enable_cache_2500(struct ast_device *ast)
1761 reg_04 = ast_mindwm(ast, 0x1E6E0004);
1762 ast_moutdwm(ast, 0x1E6E0004, reg_04 | 0x1000);
1765 data = ast_mindwm(ast, 0x1E6E0004);
1766 while (!(data & 0x80000));
1767 ast_moutdwm(ast, 0x1E6E0004, reg_04 | 0x400);
1770 static void set_mpll_2500(struct ast_device *ast)
1772 u32 addr, data, param;
1775 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1776 ast_moutdwm(ast, 0x1E6E0034, 0x00020080);
1777 for (addr = 0x1e6e0004; addr < 0x1e6e0090;) {
1778 ast_moutdwm(ast, addr, 0x0);
1781 ast_moutdwm(ast, 0x1E6E0034, 0x00020000);
1783 ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
1784 data = ast_mindwm(ast, 0x1E6E2070) & 0x00800000;
1788 ast_moutdwm(ast, 0x1E6E2160, 0x00011320);
1793 ast_moutdwm(ast, 0x1E6E2020, param);
1797 static void reset_mmc_2500(struct ast_device *ast)
1799 ast_moutdwm(ast, 0x1E78505C, 0x00000004);
1800 ast_moutdwm(ast, 0x1E785044, 0x00000001);
1801 ast_moutdwm(ast, 0x1E785048, 0x00004755);
1802 ast_moutdwm(ast, 0x1E78504C, 0x00000013);
1804 ast_moutdwm(ast, 0x1E785054, 0x00000077);
1805 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1808 static void ddr3_init_2500(struct ast_device *ast, const u32 *ddr_table)
1811 ast_moutdwm(ast, 0x1E6E0004, 0x00000303);
1812 ast_moutdwm(ast, 0x1E6E0010, ddr_table[REGIDX_010]);
1813 ast_moutdwm(ast, 0x1E6E0014, ddr_table[REGIDX_014]);
1814 ast_moutdwm(ast, 0x1E6E0018, ddr_table[REGIDX_018]);
1815 ast_moutdwm(ast, 0x1E6E0020, ddr_table[REGIDX_020]); /* MODEREG4/6 */
1816 ast_moutdwm(ast, 0x1E6E0024, ddr_table[REGIDX_024]); /* MODEREG5 */
1817 ast_moutdwm(ast, 0x1E6E002C, ddr_table[REGIDX_02C] | 0x100); /* MODEREG0/2 */
1818 ast_moutdwm(ast, 0x1E6E0030, ddr_table[REGIDX_030]); /* MODEREG1/3 */
1820 /* DDR PHY Setting */
1821 ast_moutdwm(ast, 0x1E6E0200, 0x02492AAE);
1822 ast_moutdwm(ast, 0x1E6E0204, 0x00001001);
1823 ast_moutdwm(ast, 0x1E6E020C, 0x55E00B0B);
1824 ast_moutdwm(ast, 0x1E6E0210, 0x20000000);
1825 ast_moutdwm(ast, 0x1E6E0214, ddr_table[REGIDX_214]);
1826 ast_moutdwm(ast, 0x1E6E02E0, ddr_table[REGIDX_2E0]);
1827 ast_moutdwm(ast, 0x1E6E02E4, ddr_table[REGIDX_2E4]);
1828 ast_moutdwm(ast, 0x1E6E02E8, ddr_table[REGIDX_2E8]);
1829 ast_moutdwm(ast, 0x1E6E02EC, ddr_table[REGIDX_2EC]);
1830 ast_moutdwm(ast, 0x1E6E02F0, ddr_table[REGIDX_2F0]);
1831 ast_moutdwm(ast, 0x1E6E02F4, ddr_table[REGIDX_2F4]);
1832 ast_moutdwm(ast, 0x1E6E02F8, ddr_table[REGIDX_2F8]);
1833 ast_moutdwm(ast, 0x1E6E0290, 0x00100008);
1834 ast_moutdwm(ast, 0x1E6E02C0, 0x00000006);
1836 /* Controller Setting */
1837 ast_moutdwm(ast, 0x1E6E0034, 0x00020091);
1839 /* Wait DDR PHY init done */
1840 ddr_phy_init_2500(ast);
1842 ast_moutdwm(ast, 0x1E6E0120, ddr_table[REGIDX_PLL]);
1843 ast_moutdwm(ast, 0x1E6E000C, 0x42AA5C81);
1844 ast_moutdwm(ast, 0x1E6E0034, 0x0001AF93);
1846 check_dram_size_2500(ast, ddr_table[REGIDX_RFC]);
1847 enable_cache_2500(ast);
1848 ast_moutdwm(ast, 0x1E6E001C, 0x00000008);
1849 ast_moutdwm(ast, 0x1E6E0038, 0xFFFFFF00);
1852 static void ddr4_init_2500(struct ast_device *ast, const u32 *ddr_table)
1854 u32 data, data2, pass, retrycnt;
1855 u32 ddr_vref, phy_vref;
1856 u32 min_ddr_vref = 0, min_phy_vref = 0;
1857 u32 max_ddr_vref = 0, max_phy_vref = 0;
1859 ast_moutdwm(ast, 0x1E6E0004, 0x00000313);
1860 ast_moutdwm(ast, 0x1E6E0010, ddr_table[REGIDX_010]);
1861 ast_moutdwm(ast, 0x1E6E0014, ddr_table[REGIDX_014]);
1862 ast_moutdwm(ast, 0x1E6E0018, ddr_table[REGIDX_018]);
1863 ast_moutdwm(ast, 0x1E6E0020, ddr_table[REGIDX_020]); /* MODEREG4/6 */
1864 ast_moutdwm(ast, 0x1E6E0024, ddr_table[REGIDX_024]); /* MODEREG5 */
1865 ast_moutdwm(ast, 0x1E6E002C, ddr_table[REGIDX_02C] | 0x100); /* MODEREG0/2 */
1866 ast_moutdwm(ast, 0x1E6E0030, ddr_table[REGIDX_030]); /* MODEREG1/3 */
1868 /* DDR PHY Setting */
1869 ast_moutdwm(ast, 0x1E6E0200, 0x42492AAE);
1870 ast_moutdwm(ast, 0x1E6E0204, 0x09002000);
1871 ast_moutdwm(ast, 0x1E6E020C, 0x55E00B0B);
1872 ast_moutdwm(ast, 0x1E6E0210, 0x20000000);
1873 ast_moutdwm(ast, 0x1E6E0214, ddr_table[REGIDX_214]);
1874 ast_moutdwm(ast, 0x1E6E02E0, ddr_table[REGIDX_2E0]);
1875 ast_moutdwm(ast, 0x1E6E02E4, ddr_table[REGIDX_2E4]);
1876 ast_moutdwm(ast, 0x1E6E02E8, ddr_table[REGIDX_2E8]);
1877 ast_moutdwm(ast, 0x1E6E02EC, ddr_table[REGIDX_2EC]);
1878 ast_moutdwm(ast, 0x1E6E02F0, ddr_table[REGIDX_2F0]);
1879 ast_moutdwm(ast, 0x1E6E02F4, ddr_table[REGIDX_2F4]);
1880 ast_moutdwm(ast, 0x1E6E02F8, ddr_table[REGIDX_2F8]);
1881 ast_moutdwm(ast, 0x1E6E0290, 0x00100008);
1882 ast_moutdwm(ast, 0x1E6E02C4, 0x3C183C3C);
1883 ast_moutdwm(ast, 0x1E6E02C8, 0x00631E0E);
1885 /* Controller Setting */
1886 ast_moutdwm(ast, 0x1E6E0034, 0x0001A991);
1888 /* Train PHY Vref first */
1891 for (retrycnt = 0; retrycnt < 4 && pass == 0; retrycnt++) {
1894 ast_moutdwm(ast, 0x1E6E02C0, 0x00001C06);
1895 for (phy_vref = 0x40; phy_vref < 0x80; phy_vref++) {
1896 ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
1897 ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
1898 ast_moutdwm(ast, 0x1E6E02CC, phy_vref | (phy_vref << 8));
1900 ddr_phy_init_2500(ast);
1901 ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
1902 if (cbr_test_2500(ast)) {
1904 data = ast_mindwm(ast, 0x1E6E03D0);
1909 if (max_phy_vref < data) {
1910 max_phy_vref = data;
1911 min_phy_vref = phy_vref;
1913 } else if (pass > 0)
1917 ast_moutdwm(ast, 0x1E6E02CC, min_phy_vref | (min_phy_vref << 8));
1919 /* Train DDR Vref next */
1922 for (retrycnt = 0; retrycnt < 4 && pass == 0; retrycnt++) {
1923 min_ddr_vref = 0xFF;
1926 for (ddr_vref = 0x00; ddr_vref < 0x40; ddr_vref++) {
1927 ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
1928 ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
1929 ast_moutdwm(ast, 0x1E6E02C0, 0x00000006 | (ddr_vref << 8));
1931 ddr_phy_init_2500(ast);
1932 ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
1933 if (cbr_test_2500(ast)) {
1935 if (min_ddr_vref > ddr_vref)
1936 min_ddr_vref = ddr_vref;
1937 if (max_ddr_vref < ddr_vref)
1938 max_ddr_vref = ddr_vref;
1939 } else if (pass != 0)
1944 ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
1945 ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
1946 ddr_vref = (min_ddr_vref + max_ddr_vref + 1) >> 1;
1947 ast_moutdwm(ast, 0x1E6E02C0, 0x00000006 | (ddr_vref << 8));
1949 /* Wait DDR PHY init done */
1950 ddr_phy_init_2500(ast);
1952 ast_moutdwm(ast, 0x1E6E0120, ddr_table[REGIDX_PLL]);
1953 ast_moutdwm(ast, 0x1E6E000C, 0x42AA5C81);
1954 ast_moutdwm(ast, 0x1E6E0034, 0x0001AF93);
1956 check_dram_size_2500(ast, ddr_table[REGIDX_RFC]);
1957 enable_cache_2500(ast);
1958 ast_moutdwm(ast, 0x1E6E001C, 0x00000008);
1959 ast_moutdwm(ast, 0x1E6E0038, 0xFFFFFF00);
1962 static bool ast_dram_init_2500(struct ast_device *ast)
1968 if (max_tries-- == 0)
1971 reset_mmc_2500(ast);
1972 ddr_init_common_2500(ast);
1974 data = ast_mindwm(ast, 0x1E6E2070);
1975 if (data & 0x01000000)
1976 ddr4_init_2500(ast, ast2500_ddr4_1600_timing_table);
1978 ddr3_init_2500(ast, ast2500_ddr3_1600_timing_table);
1979 } while (!ddr_test_2500(ast));
1981 ast_moutdwm(ast, 0x1E6E2040, ast_mindwm(ast, 0x1E6E2040) | 0x41);
1984 data = ast_mindwm(ast, 0x1E6E200C) & 0xF9FFFFFF;
1985 ast_moutdwm(ast, 0x1E6E200C, data | 0x10000000);
1990 void ast_patch_ahb_2500(struct ast_device *ast)
1994 /* Clear bus lock condition */
1995 ast_moutdwm(ast, 0x1e600000, 0xAEED1A03);
1996 ast_moutdwm(ast, 0x1e600084, 0x00010000);
1997 ast_moutdwm(ast, 0x1e600088, 0x00000000);
1998 ast_moutdwm(ast, 0x1e6e2000, 0x1688A8A8);
1999 data = ast_mindwm(ast, 0x1e6e2070);
2000 if (data & 0x08000000) { /* check fast reset */
2002 * If "Fast restet" is enabled for ARM-ICE debugger,
2003 * then WDT needs to enable, that
2004 * WDT04 is WDT#1 Reload reg.
2005 * WDT08 is WDT#1 counter restart reg to avoid system deadlock
2006 * WDT0C is WDT#1 control reg
2007 * [6:5]:= 01:Full chip
2008 * [4]:= 1:1MHz clock source
2009 * [1]:= 1:WDT will be cleeared and disabled after timeout occurs
2010 * [0]:= 1:WDT enable
2012 ast_moutdwm(ast, 0x1E785004, 0x00000010);
2013 ast_moutdwm(ast, 0x1E785008, 0x00004755);
2014 ast_moutdwm(ast, 0x1E78500c, 0x00000033);
2018 ast_moutdwm(ast, 0x1e6e2000, 0x1688A8A8);
2019 data = ast_mindwm(ast, 0x1e6e2000);
2020 } while (data != 1);
2021 ast_moutdwm(ast, 0x1e6e207c, 0x08000000); /* clear fast reset */
2024 void ast_post_chip_2500(struct drm_device *dev)
2026 struct ast_device *ast = to_ast_device(dev);
2030 reg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
2031 if ((reg & AST_VRAM_INIT_STATUS_MASK) == 0) {/* vga only */
2032 /* Clear bus lock condition */
2033 ast_patch_ahb_2500(ast);
2035 /* Disable watchdog */
2036 ast_moutdwm(ast, 0x1E78502C, 0x00000000);
2037 ast_moutdwm(ast, 0x1E78504C, 0x00000000);
2040 * Reset USB port to patch USB unknown device issue
2041 * SCU90 is Multi-function Pin Control #5
2042 * [29]:= 1:Enable USB2.0 Host port#1 (that the mutually shared USB2.0 Hub
2044 * SCU94 is Multi-function Pin Control #6
2045 * [14:13]:= 1x:USB2.0 Host2 controller
2046 * SCU70 is Hardware Strap reg
2047 * [23]:= 1:CLKIN is 25MHz and USBCK1 = 24/48 MHz (determined by
2048 * [18]: 0(24)/1(48) MHz)
2049 * SCU7C is Write clear reg to SCU70
2050 * [23]:= write 1 and then SCU70[23] will be clear as 0b.
2052 ast_moutdwm(ast, 0x1E6E2090, 0x20000000);
2053 ast_moutdwm(ast, 0x1E6E2094, 0x00004000);
2054 if (ast_mindwm(ast, 0x1E6E2070) & 0x00800000) {
2055 ast_moutdwm(ast, 0x1E6E207C, 0x00800000);
2057 ast_moutdwm(ast, 0x1E6E2070, 0x00800000);
2059 /* Modify eSPI reset pin */
2060 temp = ast_mindwm(ast, 0x1E6E2070);
2061 if (temp & 0x02000000)
2062 ast_moutdwm(ast, 0x1E6E207C, 0x00004000);
2064 /* Slow down CPU/AHB CLK in VGA only mode */
2065 temp = ast_read32(ast, 0x12008);
2067 ast_write32(ast, 0x12008, temp);
2069 if (!ast_dram_init_2500(ast))
2070 drm_err(dev, "DRAM init failed !\n");
2072 temp = ast_mindwm(ast, 0x1e6e2040);
2073 ast_moutdwm(ast, 0x1e6e2040, temp | 0x40);
2078 reg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
2079 } while ((reg & 0x40) == 0);