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 void ast_enable_vga(struct drm_device *dev)
42 struct ast_device *ast = to_ast_device(dev);
44 ast_io_write8(ast, AST_IO_VGA_ENABLE_PORT, 0x01);
45 ast_io_write8(ast, AST_IO_MISC_PORT_WRITE, 0x01);
48 void ast_enable_mmio(struct drm_device *dev)
50 struct ast_device *ast = to_ast_device(dev);
52 ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x06);
56 bool ast_is_vga_enabled(struct drm_device *dev)
58 struct ast_device *ast = to_ast_device(dev);
61 ch = ast_io_read8(ast, AST_IO_VGA_ENABLE_PORT);
66 static const u8 extreginfo[] = { 0x0f, 0x04, 0x1c, 0xff };
67 static const u8 extreginfo_ast2300a0[] = { 0x0f, 0x04, 0x1c, 0xff };
68 static const u8 extreginfo_ast2300[] = { 0x0f, 0x04, 0x1f, 0xff };
71 ast_set_def_ext_reg(struct drm_device *dev)
73 struct ast_device *ast = to_ast_device(dev);
74 struct pci_dev *pdev = to_pci_dev(dev->dev);
76 const u8 *ext_reg_info;
79 for (i = 0x81; i <= 0x9f; i++)
80 ast_set_index_reg(ast, AST_IO_CRTC_PORT, i, 0x00);
82 if (ast->chip == AST2300 || ast->chip == AST2400 ||
83 ast->chip == AST2500) {
84 if (pdev->revision >= 0x20)
85 ext_reg_info = extreginfo_ast2300;
87 ext_reg_info = extreginfo_ast2300a0;
89 ext_reg_info = extreginfo;
92 while (*ext_reg_info != 0xff) {
93 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, index, 0x00, *ext_reg_info);
98 /* disable standard IO/MEM decode if secondary */
99 /* ast_set_index_reg-mask(ast, AST_IO_CRTC_PORT, 0xa1, 0xff, 0x3); */
101 /* Set Ext. Default */
102 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x8c, 0x00, 0x01);
103 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x00, 0x00);
105 /* Enable RAMDAC for A1 */
107 if (ast->chip == AST2300 || ast->chip == AST2400 ||
108 ast->chip == AST2500)
110 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb6, 0xff, reg);
113 u32 ast_mindwm(struct ast_device *ast, u32 r)
117 ast_write32(ast, 0xf004, r & 0xffff0000);
118 ast_write32(ast, 0xf000, 0x1);
121 data = ast_read32(ast, 0xf004) & 0xffff0000;
122 } while (data != (r & 0xffff0000));
123 return ast_read32(ast, 0x10000 + (r & 0x0000ffff));
126 void ast_moutdwm(struct ast_device *ast, u32 r, u32 v)
129 ast_write32(ast, 0xf004, r & 0xffff0000);
130 ast_write32(ast, 0xf000, 0x1);
132 data = ast_read32(ast, 0xf004) & 0xffff0000;
133 } while (data != (r & 0xffff0000));
134 ast_write32(ast, 0x10000 + (r & 0x0000ffff), v);
138 * AST2100/2150 DLL CBR Setting
140 #define CBR_SIZE_AST2150 ((16 << 10) - 1)
141 #define CBR_PASSNUM_AST2150 5
142 #define CBR_THRESHOLD_AST2150 10
143 #define CBR_THRESHOLD2_AST2150 10
144 #define TIMEOUT_AST2150 5000000
146 #define CBR_PATNUM_AST2150 8
148 static const u32 pattern_AST2150[14] = {
165 static u32 mmctestburst2_ast2150(struct ast_device *ast, u32 datagen)
169 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
170 ast_moutdwm(ast, 0x1e6e0070, 0x00000001 | (datagen << 3));
173 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
174 if (++timeout > TIMEOUT_AST2150) {
175 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
179 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
180 ast_moutdwm(ast, 0x1e6e0070, 0x00000003 | (datagen << 3));
183 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
184 if (++timeout > TIMEOUT_AST2150) {
185 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
189 data = (ast_mindwm(ast, 0x1e6e0070) & 0x80) >> 7;
190 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
194 #if 0 /* unused in DDX driver - here for completeness */
195 static u32 mmctestsingle2_ast2150(struct ast_device *ast, u32 datagen)
199 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
200 ast_moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3));
203 data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
204 if (++timeout > TIMEOUT_AST2150) {
205 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
209 data = (ast_mindwm(ast, 0x1e6e0070) & 0x80) >> 7;
210 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
215 static int cbrtest_ast2150(struct ast_device *ast)
219 for (i = 0; i < 8; i++)
220 if (mmctestburst2_ast2150(ast, i))
225 static int cbrscan_ast2150(struct ast_device *ast, int busw)
229 for (patcnt = 0; patcnt < CBR_PATNUM_AST2150; patcnt++) {
230 ast_moutdwm(ast, 0x1e6e007c, pattern_AST2150[patcnt]);
231 for (loop = 0; loop < CBR_PASSNUM_AST2150; loop++) {
232 if (cbrtest_ast2150(ast))
235 if (loop == CBR_PASSNUM_AST2150)
242 static void cbrdlli_ast2150(struct ast_device *ast, int busw)
244 u32 dll_min[4], dll_max[4], dlli, data, passcnt;
247 dll_min[0] = dll_min[1] = dll_min[2] = dll_min[3] = 0xff;
248 dll_max[0] = dll_max[1] = dll_max[2] = dll_max[3] = 0x0;
251 for (dlli = 0; dlli < 100; dlli++) {
252 ast_moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24));
253 data = cbrscan_ast2150(ast, busw);
256 if (dll_min[0] > dlli)
258 if (dll_max[0] < dlli)
262 } else if (passcnt >= CBR_THRESHOLD_AST2150)
265 if (dll_max[0] == 0 || (dll_max[0]-dll_min[0]) < CBR_THRESHOLD_AST2150)
268 dlli = dll_min[0] + (((dll_max[0] - dll_min[0]) * 7) >> 4);
269 ast_moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24));
274 static void ast_init_dram_reg(struct drm_device *dev)
276 struct ast_device *ast = to_ast_device(dev);
279 const struct ast_dramstruct *dram_reg_info;
281 j = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
283 if ((j & 0x80) == 0) { /* VGA only */
284 if (ast->chip == AST2000) {
285 dram_reg_info = ast2000_dram_table_data;
286 ast_write32(ast, 0xf004, 0x1e6e0000);
287 ast_write32(ast, 0xf000, 0x1);
288 ast_write32(ast, 0x10100, 0xa8);
292 } while (ast_read32(ast, 0x10100) != 0xa8);
293 } else {/* AST2100/1100 */
294 if (ast->chip == AST2100 || ast->chip == 2200)
295 dram_reg_info = ast2100_dram_table_data;
297 dram_reg_info = ast1100_dram_table_data;
299 ast_write32(ast, 0xf004, 0x1e6e0000);
300 ast_write32(ast, 0xf000, 0x1);
301 ast_write32(ast, 0x12000, 0x1688A8A8);
304 } while (ast_read32(ast, 0x12000) != 0x01);
306 ast_write32(ast, 0x10000, 0xfc600309);
309 } while (ast_read32(ast, 0x10000) != 0x01);
312 while (dram_reg_info->index != 0xffff) {
313 if (dram_reg_info->index == 0xff00) {/* delay fn */
314 for (i = 0; i < 15; i++)
315 udelay(dram_reg_info->data);
316 } else if (dram_reg_info->index == 0x4 && ast->chip != AST2000) {
317 data = dram_reg_info->data;
318 if (ast->dram_type == AST_DRAM_1Gx16)
320 else if (ast->dram_type == AST_DRAM_1Gx32)
323 temp = ast_read32(ast, 0x12070);
326 ast_write32(ast, 0x10000 + dram_reg_info->index, data | temp);
328 ast_write32(ast, 0x10000 + dram_reg_info->index, dram_reg_info->data);
332 /* AST 2100/2150 DRAM calibration */
333 data = ast_read32(ast, 0x10120);
334 if (data == 0x5061) { /* 266Mhz */
335 data = ast_read32(ast, 0x10004);
337 cbrdlli_ast2150(ast, 16); /* 16 bits */
339 cbrdlli_ast2150(ast, 32); /* 32 bits */
344 temp = ast_read32(ast, 0x10140);
345 ast_write32(ast, 0x10140, temp | 0x40);
351 temp = ast_read32(ast, 0x1200c);
352 ast_write32(ast, 0x1200c, temp & 0xfffffffd);
353 temp = ast_read32(ast, 0x12040);
354 ast_write32(ast, 0x12040, temp | 0x40);
363 j = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
364 } while ((j & 0x40) == 0);
367 void ast_post_gpu(struct drm_device *dev)
369 struct ast_device *ast = to_ast_device(dev);
370 struct pci_dev *pdev = to_pci_dev(dev->dev);
373 pci_read_config_dword(pdev, 0x04, ®);
375 pci_write_config_dword(pdev, 0x04, reg);
379 ast_enable_mmio(dev);
380 ast_set_def_ext_reg(dev);
382 if (ast->chip == AST2600) {
383 if (ast->tx_chip_types & AST_TX_ASTDP_BIT)
385 } else if (ast->config_mode == ast_use_p2a) {
386 if (ast->chip == AST2500)
387 ast_post_chip_2500(dev);
388 else if (ast->chip == AST2300 || ast->chip == AST2400)
389 ast_post_chip_2300(dev);
391 ast_init_dram_reg(dev);
395 if (ast->tx_chip_types & AST_TX_SIL164_BIT)
396 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xa3, 0xcf, 0x80); /* Enable DVO */
400 /* AST 2300 DRAM settings */
404 struct ast2300_dram_param {
426 u32 dll2_finetune_step;
430 * DQSI DLL CBR Setting
432 #define CBR_SIZE0 ((1 << 10) - 1)
433 #define CBR_SIZE1 ((4 << 10) - 1)
434 #define CBR_SIZE2 ((64 << 10) - 1)
435 #define CBR_PASSNUM 5
436 #define CBR_PASSNUM2 5
437 #define CBR_THRESHOLD 10
438 #define CBR_THRESHOLD2 10
439 #define TIMEOUT 5000000
442 static const u32 pattern[8] = {
453 static bool mmc_test(struct ast_device *ast, u32 datagen, u8 test_ctl)
457 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
458 ast_moutdwm(ast, 0x1e6e0070, (datagen << 3) | test_ctl);
461 data = ast_mindwm(ast, 0x1e6e0070) & 0x3000;
464 if (++timeout > TIMEOUT) {
465 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
469 ast_moutdwm(ast, 0x1e6e0070, 0x0);
473 static u32 mmc_test2(struct ast_device *ast, u32 datagen, u8 test_ctl)
477 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
478 ast_moutdwm(ast, 0x1e6e0070, (datagen << 3) | test_ctl);
481 data = ast_mindwm(ast, 0x1e6e0070) & 0x1000;
482 if (++timeout > TIMEOUT) {
483 ast_moutdwm(ast, 0x1e6e0070, 0x0);
487 data = ast_mindwm(ast, 0x1e6e0078);
488 data = (data | (data >> 16)) & 0xffff;
489 ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
494 static bool mmc_test_burst(struct ast_device *ast, u32 datagen)
496 return mmc_test(ast, datagen, 0xc1);
499 static u32 mmc_test_burst2(struct ast_device *ast, u32 datagen)
501 return mmc_test2(ast, datagen, 0x41);
504 static bool mmc_test_single(struct ast_device *ast, u32 datagen)
506 return mmc_test(ast, datagen, 0xc5);
509 static u32 mmc_test_single2(struct ast_device *ast, u32 datagen)
511 return mmc_test2(ast, datagen, 0x05);
514 static bool mmc_test_single_2500(struct ast_device *ast, u32 datagen)
516 return mmc_test(ast, datagen, 0x85);
519 static int cbr_test(struct ast_device *ast)
523 data = mmc_test_single2(ast, 0);
524 if ((data & 0xff) && (data & 0xff00))
526 for (i = 0; i < 8; i++) {
527 data = mmc_test_burst2(ast, i);
528 if ((data & 0xff) && (data & 0xff00))
533 else if (data & 0xff)
538 static int cbr_scan(struct ast_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_test(ast)) != 0) {
553 if (loop == CBR_PASSNUM2)
559 static u32 cbr_test2(struct ast_device *ast)
563 data = mmc_test_burst2(ast, 0);
566 data |= mmc_test_single2(ast, 0);
570 return ~data & 0xffff;
573 static u32 cbr_scan2(struct ast_device *ast)
575 u32 data, data2, patcnt, loop;
578 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
579 ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
580 for (loop = 0; loop < CBR_PASSNUM2; loop++) {
581 if ((data = cbr_test2(ast)) != 0) {
588 if (loop == CBR_PASSNUM2)
594 static bool cbr_test3(struct ast_device *ast)
596 if (!mmc_test_burst(ast, 0))
598 if (!mmc_test_single(ast, 0))
603 static bool cbr_scan3(struct ast_device *ast)
607 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
608 ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
609 for (loop = 0; loop < 2; loop++) {
619 static bool finetuneDQI_L(struct ast_device *ast, struct ast2300_dram_param *param)
621 u32 gold_sadj[2], dllmin[16], dllmax[16], dlli, data, cnt, mask, passcnt, retry = 0;
624 for (cnt = 0; cnt < 16; cnt++) {
629 for (dlli = 0; dlli < 76; dlli++) {
630 ast_moutdwm(ast, 0x1E6E0068, 0x00001400 | (dlli << 16) | (dlli << 24));
631 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE1);
632 data = cbr_scan2(ast);
635 for (cnt = 0; cnt < 16; cnt++) {
637 if (dllmin[cnt] > dlli) {
640 if (dllmax[cnt] < dlli) {
647 } else if (passcnt >= CBR_THRESHOLD2) {
653 for (cnt = 0; cnt < 16; cnt++) {
654 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
655 gold_sadj[0] += dllmin[cnt];
666 gold_sadj[0] = gold_sadj[0] >> 4;
667 gold_sadj[1] = gold_sadj[0];
670 for (cnt = 0; cnt < 8; cnt++) {
672 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
674 if (gold_sadj[0] >= dlli) {
675 dlli = ((gold_sadj[0] - dlli) * 19) >> 5;
680 dlli = ((dlli - gold_sadj[0]) * 19) >> 5;
684 dlli = (8 - dlli) & 0x7;
689 ast_moutdwm(ast, 0x1E6E0080, data);
692 for (cnt = 8; cnt < 16; cnt++) {
694 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
696 if (gold_sadj[1] >= dlli) {
697 dlli = ((gold_sadj[1] - dlli) * 19) >> 5;
701 dlli = (dlli - 1) & 0x7;
704 dlli = ((dlli - gold_sadj[1]) * 19) >> 5;
709 dlli = (8 - dlli) & 0x7;
714 ast_moutdwm(ast, 0x1E6E0084, data);
716 } /* finetuneDQI_L */
718 static void finetuneDQSI(struct ast_device *ast)
720 u32 dlli, dqsip, dqidly;
721 u32 reg_mcr18, reg_mcr0c, passcnt[2], diff;
722 u32 g_dqidly, g_dqsip, g_margin, g_side;
726 /* Disable DQI CBR */
727 reg_mcr0c = ast_mindwm(ast, 0x1E6E000C);
728 reg_mcr18 = ast_mindwm(ast, 0x1E6E0018);
729 reg_mcr18 &= 0x0000ffff;
730 ast_moutdwm(ast, 0x1E6E0018, reg_mcr18);
732 for (dlli = 0; dlli < 76; dlli++) {
736 for (dqidly = 0; dqidly < 32; dqidly++) {
737 pass[dqidly][0][0] = 0xff;
738 pass[dqidly][0][1] = 0x0;
739 pass[dqidly][1][0] = 0xff;
740 pass[dqidly][1][1] = 0x0;
742 for (dqidly = 0; dqidly < 32; dqidly++) {
743 passcnt[0] = passcnt[1] = 0;
744 for (dqsip = 0; dqsip < 2; dqsip++) {
745 ast_moutdwm(ast, 0x1E6E000C, 0);
746 ast_moutdwm(ast, 0x1E6E0018, reg_mcr18 | (dqidly << 16) | (dqsip << 23));
747 ast_moutdwm(ast, 0x1E6E000C, reg_mcr0c);
748 for (dlli = 0; dlli < 76; dlli++) {
749 ast_moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24));
750 ast_moutdwm(ast, 0x1E6E0070, 0);
751 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE0);
752 if (cbr_scan3(ast)) {
756 tag[dqsip][dlli] = 'P';
757 if (dlli < pass[dqidly][dqsip][0])
758 pass[dqidly][dqsip][0] = (u16) dlli;
759 if (dlli > pass[dqidly][dqsip][1])
760 pass[dqidly][dqsip][1] = (u16) dlli;
761 } else if (passcnt[dqsip] >= 5)
764 pass[dqidly][dqsip][0] = 0xff;
765 pass[dqidly][dqsip][1] = 0x0;
769 if (passcnt[0] == 0 && passcnt[1] == 0)
773 g_dqidly = g_dqsip = g_margin = g_side = 0;
775 for (dqidly = 0; dqidly < 32; dqidly++) {
776 for (dqsip = 0; dqsip < 2; dqsip++) {
777 if (pass[dqidly][dqsip][0] > pass[dqidly][dqsip][1])
779 diff = pass[dqidly][dqsip][1] - pass[dqidly][dqsip][0];
780 if ((diff+2) < g_margin)
782 passcnt[0] = passcnt[1] = 0;
783 for (dlli = pass[dqidly][dqsip][0]; dlli > 0 && tag[dqsip][dlli] != 0; dlli--, passcnt[0]++);
784 for (dlli = pass[dqidly][dqsip][1]; dlli < 76 && tag[dqsip][dlli] != 0; dlli++, passcnt[1]++);
785 if (passcnt[0] > passcnt[1])
786 passcnt[0] = passcnt[1];
788 if (passcnt[0] > g_side)
789 passcnt[1] = passcnt[0] - g_side;
790 if (diff > (g_margin+1) && (passcnt[1] > 0 || passcnt[0] > 8)) {
795 } else if (passcnt[1] > 1 && g_side < 8) {
804 reg_mcr18 = reg_mcr18 | (g_dqidly << 16) | (g_dqsip << 23);
805 ast_moutdwm(ast, 0x1E6E0018, reg_mcr18);
808 static bool cbr_dll2(struct ast_device *ast, struct ast2300_dram_param *param)
810 u32 dllmin[2], dllmax[2], dlli, data, passcnt, retry = 0;
814 if (finetuneDQI_L(ast, param) == false)
818 dllmin[0] = dllmin[1] = 0xff;
819 dllmax[0] = dllmax[1] = 0x0;
821 for (dlli = 0; dlli < 76; dlli++) {
822 ast_moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24));
823 ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE2);
824 data = cbr_scan(ast);
827 if (dllmin[0] > dlli) {
830 if (dllmax[0] < dlli) {
835 if (dllmin[1] > dlli) {
838 if (dllmax[1] < dlli) {
843 } else if (passcnt >= CBR_THRESHOLD) {
849 if (dllmax[0] == 0 || (dllmax[0]-dllmin[0]) < CBR_THRESHOLD) {
852 if (dllmax[1] == 0 || (dllmax[1]-dllmin[1]) < CBR_THRESHOLD) {
857 dlli = (dllmin[1] + dllmax[1]) >> 1;
859 dlli += (dllmin[0] + dllmax[0]) >> 1;
860 ast_moutdwm(ast, 0x1E6E0068, ast_mindwm(ast, 0x1E720058) | (dlli << 16));
864 static void get_ddr3_info(struct ast_device *ast, struct ast2300_dram_param *param)
866 u32 trap, trap_AC2, trap_MRS;
868 ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
871 trap = (ast_mindwm(ast, 0x1E6E2070) >> 25) & 0x3;
872 trap_AC2 = 0x00020000 + (trap << 16);
873 trap_AC2 |= 0x00300000 + ((trap & 0x2) << 19);
874 trap_MRS = 0x00000010 + (trap << 4);
875 trap_MRS |= ((trap & 0x2) << 18);
877 param->reg_MADJ = 0x00034C4C;
878 param->reg_SADJ = 0x00001800;
879 param->reg_DRV = 0x000000F0;
880 param->reg_PERIOD = param->dram_freq;
883 switch (param->dram_freq) {
885 ast_moutdwm(ast, 0x1E6E2020, 0x0190);
887 param->reg_AC1 = 0x22202725;
888 param->reg_AC2 = 0xAA007613 | trap_AC2;
889 param->reg_DQSIC = 0x000000BA;
890 param->reg_MRS = 0x04001400 | trap_MRS;
891 param->reg_EMRS = 0x00000000;
892 param->reg_IOZ = 0x00000023;
893 param->reg_DQIDLY = 0x00000074;
894 param->reg_FREQ = 0x00004DC0;
895 param->madj_max = 96;
896 param->dll2_finetune_step = 3;
897 switch (param->dram_chipid) {
899 case AST_DRAM_512Mx16:
901 param->reg_AC2 = 0xAA007613 | trap_AC2;
904 param->reg_AC2 = 0xAA00761C | trap_AC2;
907 param->reg_AC2 = 0xAA007636 | trap_AC2;
913 ast_moutdwm(ast, 0x1E6E2020, 0x03F1);
915 param->reg_AC1 = 0x33302825;
916 param->reg_AC2 = 0xCC009617 | trap_AC2;
917 param->reg_DQSIC = 0x000000E2;
918 param->reg_MRS = 0x04001600 | trap_MRS;
919 param->reg_EMRS = 0x00000000;
920 param->reg_IOZ = 0x00000034;
921 param->reg_DRV = 0x000000FA;
922 param->reg_DQIDLY = 0x00000089;
923 param->reg_FREQ = 0x00005040;
924 param->madj_max = 96;
925 param->dll2_finetune_step = 4;
927 switch (param->dram_chipid) {
929 case AST_DRAM_512Mx16:
931 param->reg_AC2 = 0xCC009617 | trap_AC2;
934 param->reg_AC2 = 0xCC009622 | trap_AC2;
937 param->reg_AC2 = 0xCC00963F | trap_AC2;
943 ast_moutdwm(ast, 0x1E6E2020, 0x01F0);
945 param->reg_AC1 = 0x33302825;
946 param->reg_AC2 = 0xCC009617 | trap_AC2;
947 param->reg_DQSIC = 0x000000E2;
948 param->reg_MRS = 0x04001600 | trap_MRS;
949 param->reg_EMRS = 0x00000000;
950 param->reg_IOZ = 0x00000023;
951 param->reg_DRV = 0x000000FA;
952 param->reg_DQIDLY = 0x00000089;
953 param->reg_FREQ = 0x000050C0;
954 param->madj_max = 96;
955 param->dll2_finetune_step = 4;
957 switch (param->dram_chipid) {
959 case AST_DRAM_512Mx16:
961 param->reg_AC2 = 0xCC009617 | trap_AC2;
964 param->reg_AC2 = 0xCC009622 | trap_AC2;
967 param->reg_AC2 = 0xCC00963F | trap_AC2;
973 ast_moutdwm(ast, 0x1E6E2020, 0x0230);
975 param->reg_AC1 = 0x33302926;
976 param->reg_AC2 = 0xCD44961A;
977 param->reg_DQSIC = 0x000000FC;
978 param->reg_MRS = 0x00081830;
979 param->reg_EMRS = 0x00000000;
980 param->reg_IOZ = 0x00000045;
981 param->reg_DQIDLY = 0x00000097;
982 param->reg_FREQ = 0x000052C0;
983 param->madj_max = 88;
984 param->dll2_finetune_step = 4;
987 ast_moutdwm(ast, 0x1E6E2020, 0x0270);
989 param->reg_AC1 = 0x33302926;
990 param->reg_AC2 = 0xDE44A61D;
991 param->reg_DQSIC = 0x00000117;
992 param->reg_MRS = 0x00081A30;
993 param->reg_EMRS = 0x00000000;
994 param->reg_IOZ = 0x070000BB;
995 param->reg_DQIDLY = 0x000000A0;
996 param->reg_FREQ = 0x000054C0;
997 param->madj_max = 79;
998 param->dll2_finetune_step = 4;
1001 ast_moutdwm(ast, 0x1E6E2020, 0x0290);
1004 param->reg_AC1 = 0x33302926;
1005 param->reg_AC2 = 0xEF44B61E;
1006 param->reg_DQSIC = 0x00000125;
1007 param->reg_MRS = 0x00081A30;
1008 param->reg_EMRS = 0x00000040;
1009 param->reg_DRV = 0x000000F5;
1010 param->reg_IOZ = 0x00000023;
1011 param->reg_DQIDLY = 0x00000088;
1012 param->reg_FREQ = 0x000055C0;
1013 param->madj_max = 76;
1014 param->dll2_finetune_step = 3;
1017 ast_moutdwm(ast, 0x1E6E2020, 0x0140);
1018 param->reg_MADJ = 0x00136868;
1019 param->reg_SADJ = 0x00004534;
1022 param->reg_AC1 = 0x33302A37;
1023 param->reg_AC2 = 0xEF56B61E;
1024 param->reg_DQSIC = 0x0000013F;
1025 param->reg_MRS = 0x00101A50;
1026 param->reg_EMRS = 0x00000040;
1027 param->reg_DRV = 0x000000FA;
1028 param->reg_IOZ = 0x00000023;
1029 param->reg_DQIDLY = 0x00000078;
1030 param->reg_FREQ = 0x000057C0;
1031 param->madj_max = 136;
1032 param->dll2_finetune_step = 3;
1035 ast_moutdwm(ast, 0x1E6E2020, 0x02E1);
1036 param->reg_MADJ = 0x00136868;
1037 param->reg_SADJ = 0x00004534;
1040 param->reg_AC1 = 0x32302A37;
1041 param->reg_AC2 = 0xDF56B61F;
1042 param->reg_DQSIC = 0x0000014D;
1043 param->reg_MRS = 0x00101A50;
1044 param->reg_EMRS = 0x00000004;
1045 param->reg_DRV = 0x000000F5;
1046 param->reg_IOZ = 0x00000023;
1047 param->reg_DQIDLY = 0x00000078;
1048 param->reg_FREQ = 0x000058C0;
1049 param->madj_max = 132;
1050 param->dll2_finetune_step = 3;
1053 ast_moutdwm(ast, 0x1E6E2020, 0x0160);
1054 param->reg_MADJ = 0x00136868;
1055 param->reg_SADJ = 0x00004534;
1058 param->reg_AC1 = 0x32302A37;
1059 param->reg_AC2 = 0xEF56B621;
1060 param->reg_DQSIC = 0x0000015A;
1061 param->reg_MRS = 0x02101A50;
1062 param->reg_EMRS = 0x00000004;
1063 param->reg_DRV = 0x000000F5;
1064 param->reg_IOZ = 0x00000034;
1065 param->reg_DQIDLY = 0x00000078;
1066 param->reg_FREQ = 0x000059C0;
1067 param->madj_max = 128;
1068 param->dll2_finetune_step = 3;
1072 switch (param->dram_chipid) {
1073 case AST_DRAM_512Mx16:
1074 param->dram_config = 0x130;
1077 case AST_DRAM_1Gx16:
1078 param->dram_config = 0x131;
1080 case AST_DRAM_2Gx16:
1081 param->dram_config = 0x132;
1083 case AST_DRAM_4Gx16:
1084 param->dram_config = 0x133;
1088 switch (param->vram_size) {
1090 case AST_VIDMEM_SIZE_8M:
1091 param->dram_config |= 0x00;
1093 case AST_VIDMEM_SIZE_16M:
1094 param->dram_config |= 0x04;
1096 case AST_VIDMEM_SIZE_32M:
1097 param->dram_config |= 0x08;
1099 case AST_VIDMEM_SIZE_64M:
1100 param->dram_config |= 0x0c;
1106 static void ddr3_init(struct ast_device *ast, struct ast2300_dram_param *param)
1108 u32 data, data2, retry = 0;
1111 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1112 ast_moutdwm(ast, 0x1E6E0018, 0x00000100);
1113 ast_moutdwm(ast, 0x1E6E0024, 0x00000000);
1114 ast_moutdwm(ast, 0x1E6E0034, 0x00000000);
1116 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ);
1117 ast_moutdwm(ast, 0x1E6E0068, param->reg_SADJ);
1119 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000);
1122 ast_moutdwm(ast, 0x1E6E0004, param->dram_config);
1123 ast_moutdwm(ast, 0x1E6E0008, 0x90040f);
1124 ast_moutdwm(ast, 0x1E6E0010, param->reg_AC1);
1125 ast_moutdwm(ast, 0x1E6E0014, param->reg_AC2);
1126 ast_moutdwm(ast, 0x1E6E0020, param->reg_DQSIC);
1127 ast_moutdwm(ast, 0x1E6E0080, 0x00000000);
1128 ast_moutdwm(ast, 0x1E6E0084, 0x00000000);
1129 ast_moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY);
1130 ast_moutdwm(ast, 0x1E6E0018, 0x4000A170);
1131 ast_moutdwm(ast, 0x1E6E0018, 0x00002370);
1132 ast_moutdwm(ast, 0x1E6E0038, 0x00000000);
1133 ast_moutdwm(ast, 0x1E6E0040, 0xFF444444);
1134 ast_moutdwm(ast, 0x1E6E0044, 0x22222222);
1135 ast_moutdwm(ast, 0x1E6E0048, 0x22222222);
1136 ast_moutdwm(ast, 0x1E6E004C, 0x00000002);
1137 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1138 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1139 ast_moutdwm(ast, 0x1E6E0054, 0);
1140 ast_moutdwm(ast, 0x1E6E0060, param->reg_DRV);
1141 ast_moutdwm(ast, 0x1E6E006C, param->reg_IOZ);
1142 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1143 ast_moutdwm(ast, 0x1E6E0074, 0x00000000);
1144 ast_moutdwm(ast, 0x1E6E0078, 0x00000000);
1145 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1146 /* Wait MCLK2X lock to MCLK */
1148 data = ast_mindwm(ast, 0x1E6E001C);
1149 } while (!(data & 0x08000000));
1150 data = ast_mindwm(ast, 0x1E6E001C);
1151 data = (data >> 8) & 0xff;
1152 while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) {
1153 data2 = (ast_mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4;
1154 if ((data2 & 0xff) > param->madj_max) {
1157 ast_moutdwm(ast, 0x1E6E0064, data2);
1158 if (data2 & 0x00100000) {
1159 data2 = ((data2 & 0xff) >> 3) + 3;
1161 data2 = ((data2 & 0xff) >> 2) + 5;
1163 data = ast_mindwm(ast, 0x1E6E0068) & 0xffff00ff;
1164 data2 += data & 0xff;
1165 data = data | (data2 << 8);
1166 ast_moutdwm(ast, 0x1E6E0068, data);
1168 ast_moutdwm(ast, 0x1E6E0064, ast_mindwm(ast, 0x1E6E0064) | 0xC0000);
1170 data = ast_mindwm(ast, 0x1E6E0018) & 0xfffff1ff;
1171 ast_moutdwm(ast, 0x1E6E0018, data);
1172 data = data | 0x200;
1173 ast_moutdwm(ast, 0x1E6E0018, data);
1175 data = ast_mindwm(ast, 0x1E6E001C);
1176 } while (!(data & 0x08000000));
1178 data = ast_mindwm(ast, 0x1E6E001C);
1179 data = (data >> 8) & 0xff;
1181 ast_moutdwm(ast, 0x1E720058, ast_mindwm(ast, 0x1E6E0068) & 0xffff);
1182 data = ast_mindwm(ast, 0x1E6E0018) | 0xC00;
1183 ast_moutdwm(ast, 0x1E6E0018, data);
1185 ast_moutdwm(ast, 0x1E6E0034, 0x00000001);
1186 ast_moutdwm(ast, 0x1E6E000C, 0x00000040);
1188 /* Mode Register Setting */
1189 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100);
1190 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1191 ast_moutdwm(ast, 0x1E6E0028, 0x00000005);
1192 ast_moutdwm(ast, 0x1E6E0028, 0x00000007);
1193 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1194 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1195 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS);
1196 ast_moutdwm(ast, 0x1E6E000C, 0x00005C08);
1197 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1199 ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
1205 data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3);
1207 ast_moutdwm(ast, 0x1E6E0034, data | 0x3);
1209 /* Calibrate the DQSI delay */
1210 if ((cbr_dll2(ast, param) == false) && (retry++ < 10))
1211 goto ddr3_init_start;
1213 ast_moutdwm(ast, 0x1E6E0120, param->reg_FREQ);
1214 /* ECC Memory Initialization */
1216 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1217 ast_moutdwm(ast, 0x1E6E0070, 0x221);
1219 data = ast_mindwm(ast, 0x1E6E0070);
1220 } while (!(data & 0x00001000));
1221 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1222 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1223 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1229 static void get_ddr2_info(struct ast_device *ast, struct ast2300_dram_param *param)
1231 u32 trap, trap_AC2, trap_MRS;
1233 ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
1236 trap = (ast_mindwm(ast, 0x1E6E2070) >> 25) & 0x3;
1237 trap_AC2 = (trap << 20) | (trap << 16);
1238 trap_AC2 += 0x00110000;
1239 trap_MRS = 0x00000040 | (trap << 4);
1242 param->reg_MADJ = 0x00034C4C;
1243 param->reg_SADJ = 0x00001800;
1244 param->reg_DRV = 0x000000F0;
1245 param->reg_PERIOD = param->dram_freq;
1248 switch (param->dram_freq) {
1250 ast_moutdwm(ast, 0x1E6E2020, 0x0130);
1252 param->reg_AC1 = 0x11101513;
1253 param->reg_AC2 = 0x78117011;
1254 param->reg_DQSIC = 0x00000092;
1255 param->reg_MRS = 0x00000842;
1256 param->reg_EMRS = 0x00000000;
1257 param->reg_DRV = 0x000000F0;
1258 param->reg_IOZ = 0x00000034;
1259 param->reg_DQIDLY = 0x0000005A;
1260 param->reg_FREQ = 0x00004AC0;
1261 param->madj_max = 138;
1262 param->dll2_finetune_step = 3;
1265 ast_moutdwm(ast, 0x1E6E2020, 0x0190);
1267 param->reg_AC1 = 0x22202613;
1268 param->reg_AC2 = 0xAA009016 | trap_AC2;
1269 param->reg_DQSIC = 0x000000BA;
1270 param->reg_MRS = 0x00000A02 | trap_MRS;
1271 param->reg_EMRS = 0x00000040;
1272 param->reg_DRV = 0x000000FA;
1273 param->reg_IOZ = 0x00000034;
1274 param->reg_DQIDLY = 0x00000074;
1275 param->reg_FREQ = 0x00004DC0;
1276 param->madj_max = 96;
1277 param->dll2_finetune_step = 3;
1278 switch (param->dram_chipid) {
1280 case AST_DRAM_512Mx16:
1281 param->reg_AC2 = 0xAA009012 | trap_AC2;
1283 case AST_DRAM_1Gx16:
1284 param->reg_AC2 = 0xAA009016 | trap_AC2;
1286 case AST_DRAM_2Gx16:
1287 param->reg_AC2 = 0xAA009023 | trap_AC2;
1289 case AST_DRAM_4Gx16:
1290 param->reg_AC2 = 0xAA00903B | trap_AC2;
1296 ast_moutdwm(ast, 0x1E6E2020, 0x03F1);
1299 param->reg_AC1 = 0x33302714;
1300 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1301 param->reg_DQSIC = 0x000000E2;
1302 param->reg_MRS = 0x00000C02 | trap_MRS;
1303 param->reg_EMRS = 0x00000040;
1304 param->reg_DRV = 0x000000FA;
1305 param->reg_IOZ = 0x00000034;
1306 param->reg_DQIDLY = 0x00000089;
1307 param->reg_FREQ = 0x00005040;
1308 param->madj_max = 96;
1309 param->dll2_finetune_step = 4;
1311 switch (param->dram_chipid) {
1312 case AST_DRAM_512Mx16:
1313 param->reg_AC2 = 0xCC00B016 | trap_AC2;
1316 case AST_DRAM_1Gx16:
1317 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1319 case AST_DRAM_2Gx16:
1320 param->reg_AC2 = 0xCC00B02B | trap_AC2;
1322 case AST_DRAM_4Gx16:
1323 param->reg_AC2 = 0xCC00B03F | trap_AC2;
1330 ast_moutdwm(ast, 0x1E6E2020, 0x01F0);
1333 param->reg_AC1 = 0x33302714;
1334 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1335 param->reg_DQSIC = 0x000000E2;
1336 param->reg_MRS = 0x00000C02 | trap_MRS;
1337 param->reg_EMRS = 0x00000040;
1338 param->reg_DRV = 0x000000FA;
1339 param->reg_IOZ = 0x00000034;
1340 param->reg_DQIDLY = 0x00000089;
1341 param->reg_FREQ = 0x000050C0;
1342 param->madj_max = 96;
1343 param->dll2_finetune_step = 4;
1345 switch (param->dram_chipid) {
1346 case AST_DRAM_512Mx16:
1347 param->reg_AC2 = 0xCC00B016 | trap_AC2;
1350 case AST_DRAM_1Gx16:
1351 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1353 case AST_DRAM_2Gx16:
1354 param->reg_AC2 = 0xCC00B02B | trap_AC2;
1356 case AST_DRAM_4Gx16:
1357 param->reg_AC2 = 0xCC00B03F | trap_AC2;
1363 ast_moutdwm(ast, 0x1E6E2020, 0x0230);
1365 param->reg_AC1 = 0x33302815;
1366 param->reg_AC2 = 0xCD44B01E;
1367 param->reg_DQSIC = 0x000000FC;
1368 param->reg_MRS = 0x00000E72;
1369 param->reg_EMRS = 0x00000000;
1370 param->reg_DRV = 0x00000000;
1371 param->reg_IOZ = 0x00000034;
1372 param->reg_DQIDLY = 0x00000097;
1373 param->reg_FREQ = 0x000052C0;
1374 param->madj_max = 88;
1375 param->dll2_finetune_step = 3;
1378 ast_moutdwm(ast, 0x1E6E2020, 0x0261);
1381 param->reg_AC1 = 0x33302815;
1382 param->reg_AC2 = 0xDE44C022;
1383 param->reg_DQSIC = 0x00000117;
1384 param->reg_MRS = 0x00000E72;
1385 param->reg_EMRS = 0x00000040;
1386 param->reg_DRV = 0x0000000A;
1387 param->reg_IOZ = 0x00000045;
1388 param->reg_DQIDLY = 0x000000A0;
1389 param->reg_FREQ = 0x000054C0;
1390 param->madj_max = 79;
1391 param->dll2_finetune_step = 3;
1394 ast_moutdwm(ast, 0x1E6E2020, 0x0120);
1397 param->reg_AC1 = 0x33302815;
1398 param->reg_AC2 = 0xEF44D024;
1399 param->reg_DQSIC = 0x00000125;
1400 param->reg_MRS = 0x00000E72;
1401 param->reg_EMRS = 0x00000004;
1402 param->reg_DRV = 0x000000F9;
1403 param->reg_IOZ = 0x00000045;
1404 param->reg_DQIDLY = 0x000000A7;
1405 param->reg_FREQ = 0x000055C0;
1406 param->madj_max = 76;
1407 param->dll2_finetune_step = 3;
1410 ast_moutdwm(ast, 0x1E6E2020, 0x02A1);
1413 param->reg_AC1 = 0x43402915;
1414 param->reg_AC2 = 0xFF44E025;
1415 param->reg_DQSIC = 0x00000132;
1416 param->reg_MRS = 0x00000E72;
1417 param->reg_EMRS = 0x00000040;
1418 param->reg_DRV = 0x0000000A;
1419 param->reg_IOZ = 0x00000045;
1420 param->reg_DQIDLY = 0x000000AD;
1421 param->reg_FREQ = 0x000056C0;
1422 param->madj_max = 76;
1423 param->dll2_finetune_step = 3;
1426 ast_moutdwm(ast, 0x1E6E2020, 0x0140);
1429 param->reg_AC1 = 0x43402915;
1430 param->reg_AC2 = 0xFF44E027;
1431 param->reg_DQSIC = 0x0000013F;
1432 param->reg_MRS = 0x00000E72;
1433 param->reg_EMRS = 0x00000004;
1434 param->reg_DRV = 0x000000F5;
1435 param->reg_IOZ = 0x00000045;
1436 param->reg_DQIDLY = 0x000000B3;
1437 param->reg_FREQ = 0x000057C0;
1438 param->madj_max = 76;
1439 param->dll2_finetune_step = 3;
1443 switch (param->dram_chipid) {
1444 case AST_DRAM_512Mx16:
1445 param->dram_config = 0x100;
1448 case AST_DRAM_1Gx16:
1449 param->dram_config = 0x121;
1451 case AST_DRAM_2Gx16:
1452 param->dram_config = 0x122;
1454 case AST_DRAM_4Gx16:
1455 param->dram_config = 0x123;
1459 switch (param->vram_size) {
1461 case AST_VIDMEM_SIZE_8M:
1462 param->dram_config |= 0x00;
1464 case AST_VIDMEM_SIZE_16M:
1465 param->dram_config |= 0x04;
1467 case AST_VIDMEM_SIZE_32M:
1468 param->dram_config |= 0x08;
1470 case AST_VIDMEM_SIZE_64M:
1471 param->dram_config |= 0x0c;
1476 static void ddr2_init(struct ast_device *ast, struct ast2300_dram_param *param)
1478 u32 data, data2, retry = 0;
1481 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1482 ast_moutdwm(ast, 0x1E6E0018, 0x00000100);
1483 ast_moutdwm(ast, 0x1E6E0024, 0x00000000);
1484 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ);
1485 ast_moutdwm(ast, 0x1E6E0068, param->reg_SADJ);
1487 ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000);
1490 ast_moutdwm(ast, 0x1E6E0004, param->dram_config);
1491 ast_moutdwm(ast, 0x1E6E0008, 0x90040f);
1492 ast_moutdwm(ast, 0x1E6E0010, param->reg_AC1);
1493 ast_moutdwm(ast, 0x1E6E0014, param->reg_AC2);
1494 ast_moutdwm(ast, 0x1E6E0020, param->reg_DQSIC);
1495 ast_moutdwm(ast, 0x1E6E0080, 0x00000000);
1496 ast_moutdwm(ast, 0x1E6E0084, 0x00000000);
1497 ast_moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY);
1498 ast_moutdwm(ast, 0x1E6E0018, 0x4000A130);
1499 ast_moutdwm(ast, 0x1E6E0018, 0x00002330);
1500 ast_moutdwm(ast, 0x1E6E0038, 0x00000000);
1501 ast_moutdwm(ast, 0x1E6E0040, 0xFF808000);
1502 ast_moutdwm(ast, 0x1E6E0044, 0x88848466);
1503 ast_moutdwm(ast, 0x1E6E0048, 0x44440008);
1504 ast_moutdwm(ast, 0x1E6E004C, 0x00000000);
1505 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1506 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1507 ast_moutdwm(ast, 0x1E6E0054, 0);
1508 ast_moutdwm(ast, 0x1E6E0060, param->reg_DRV);
1509 ast_moutdwm(ast, 0x1E6E006C, param->reg_IOZ);
1510 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1511 ast_moutdwm(ast, 0x1E6E0074, 0x00000000);
1512 ast_moutdwm(ast, 0x1E6E0078, 0x00000000);
1513 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1515 /* Wait MCLK2X lock to MCLK */
1517 data = ast_mindwm(ast, 0x1E6E001C);
1518 } while (!(data & 0x08000000));
1519 data = ast_mindwm(ast, 0x1E6E001C);
1520 data = (data >> 8) & 0xff;
1521 while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) {
1522 data2 = (ast_mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4;
1523 if ((data2 & 0xff) > param->madj_max) {
1526 ast_moutdwm(ast, 0x1E6E0064, data2);
1527 if (data2 & 0x00100000) {
1528 data2 = ((data2 & 0xff) >> 3) + 3;
1530 data2 = ((data2 & 0xff) >> 2) + 5;
1532 data = ast_mindwm(ast, 0x1E6E0068) & 0xffff00ff;
1533 data2 += data & 0xff;
1534 data = data | (data2 << 8);
1535 ast_moutdwm(ast, 0x1E6E0068, data);
1537 ast_moutdwm(ast, 0x1E6E0064, ast_mindwm(ast, 0x1E6E0064) | 0xC0000);
1539 data = ast_mindwm(ast, 0x1E6E0018) & 0xfffff1ff;
1540 ast_moutdwm(ast, 0x1E6E0018, data);
1541 data = data | 0x200;
1542 ast_moutdwm(ast, 0x1E6E0018, data);
1544 data = ast_mindwm(ast, 0x1E6E001C);
1545 } while (!(data & 0x08000000));
1547 data = ast_mindwm(ast, 0x1E6E001C);
1548 data = (data >> 8) & 0xff;
1550 ast_moutdwm(ast, 0x1E720058, ast_mindwm(ast, 0x1E6E0008) & 0xffff);
1551 data = ast_mindwm(ast, 0x1E6E0018) | 0xC00;
1552 ast_moutdwm(ast, 0x1E6E0018, data);
1554 ast_moutdwm(ast, 0x1E6E0034, 0x00000001);
1555 ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
1557 /* Mode Register Setting */
1558 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100);
1559 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1560 ast_moutdwm(ast, 0x1E6E0028, 0x00000005);
1561 ast_moutdwm(ast, 0x1E6E0028, 0x00000007);
1562 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1563 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1565 ast_moutdwm(ast, 0x1E6E000C, 0x00005C08);
1566 ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS);
1567 ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
1568 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS | 0x380);
1569 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1570 ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1571 ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
1573 ast_moutdwm(ast, 0x1E6E000C, 0x7FFF5C01);
1579 data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3);
1581 ast_moutdwm(ast, 0x1E6E0034, data | 0x3);
1582 ast_moutdwm(ast, 0x1E6E0120, param->reg_FREQ);
1584 /* Calibrate the DQSI delay */
1585 if ((cbr_dll2(ast, param) == false) && (retry++ < 10))
1586 goto ddr2_init_start;
1588 /* ECC Memory Initialization */
1590 ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
1591 ast_moutdwm(ast, 0x1E6E0070, 0x221);
1593 data = ast_mindwm(ast, 0x1E6E0070);
1594 } while (!(data & 0x00001000));
1595 ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
1596 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1597 ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
1602 static void ast_post_chip_2300(struct drm_device *dev)
1604 struct ast_device *ast = to_ast_device(dev);
1605 struct ast2300_dram_param param;
1609 reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
1610 if ((reg & 0x80) == 0) {/* vga only */
1611 ast_write32(ast, 0xf004, 0x1e6e0000);
1612 ast_write32(ast, 0xf000, 0x1);
1613 ast_write32(ast, 0x12000, 0x1688a8a8);
1616 } while (ast_read32(ast, 0x12000) != 0x1);
1618 ast_write32(ast, 0x10000, 0xfc600309);
1621 } while (ast_read32(ast, 0x10000) != 0x1);
1623 /* Slow down CPU/AHB CLK in VGA only mode */
1624 temp = ast_read32(ast, 0x12008);
1626 ast_write32(ast, 0x12008, temp);
1628 param.dram_freq = 396;
1629 param.dram_type = AST_DDR3;
1630 temp = ast_mindwm(ast, 0x1e6e2070);
1631 if (temp & 0x01000000)
1632 param.dram_type = AST_DDR2;
1633 switch (temp & 0x18000000) {
1635 param.dram_chipid = AST_DRAM_512Mx16;
1639 param.dram_chipid = AST_DRAM_1Gx16;
1642 param.dram_chipid = AST_DRAM_2Gx16;
1645 param.dram_chipid = AST_DRAM_4Gx16;
1648 switch (temp & 0x0c) {
1651 param.vram_size = AST_VIDMEM_SIZE_8M;
1655 param.vram_size = AST_VIDMEM_SIZE_16M;
1659 param.vram_size = AST_VIDMEM_SIZE_32M;
1663 param.vram_size = AST_VIDMEM_SIZE_64M;
1667 if (param.dram_type == AST_DDR3) {
1668 get_ddr3_info(ast, ¶m);
1669 ddr3_init(ast, ¶m);
1671 get_ddr2_info(ast, ¶m);
1672 ddr2_init(ast, ¶m);
1675 temp = ast_mindwm(ast, 0x1e6e2040);
1676 ast_moutdwm(ast, 0x1e6e2040, temp | 0x40);
1681 reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
1682 } while ((reg & 0x40) == 0);
1685 static bool cbr_test_2500(struct ast_device *ast)
1687 ast_moutdwm(ast, 0x1E6E0074, 0x0000FFFF);
1688 ast_moutdwm(ast, 0x1E6E007C, 0xFF00FF00);
1689 if (!mmc_test_burst(ast, 0))
1691 if (!mmc_test_single_2500(ast, 0))
1696 static bool ddr_test_2500(struct ast_device *ast)
1698 ast_moutdwm(ast, 0x1E6E0074, 0x0000FFFF);
1699 ast_moutdwm(ast, 0x1E6E007C, 0xFF00FF00);
1700 if (!mmc_test_burst(ast, 0))
1702 if (!mmc_test_burst(ast, 1))
1704 if (!mmc_test_burst(ast, 2))
1706 if (!mmc_test_burst(ast, 3))
1708 if (!mmc_test_single_2500(ast, 0))
1713 static void ddr_init_common_2500(struct ast_device *ast)
1715 ast_moutdwm(ast, 0x1E6E0034, 0x00020080);
1716 ast_moutdwm(ast, 0x1E6E0008, 0x2003000F);
1717 ast_moutdwm(ast, 0x1E6E0038, 0x00000FFF);
1718 ast_moutdwm(ast, 0x1E6E0040, 0x88448844);
1719 ast_moutdwm(ast, 0x1E6E0044, 0x24422288);
1720 ast_moutdwm(ast, 0x1E6E0048, 0x22222222);
1721 ast_moutdwm(ast, 0x1E6E004C, 0x22222222);
1722 ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
1723 ast_moutdwm(ast, 0x1E6E0208, 0x00000000);
1724 ast_moutdwm(ast, 0x1E6E0218, 0x00000000);
1725 ast_moutdwm(ast, 0x1E6E0220, 0x00000000);
1726 ast_moutdwm(ast, 0x1E6E0228, 0x00000000);
1727 ast_moutdwm(ast, 0x1E6E0230, 0x00000000);
1728 ast_moutdwm(ast, 0x1E6E02A8, 0x00000000);
1729 ast_moutdwm(ast, 0x1E6E02B0, 0x00000000);
1730 ast_moutdwm(ast, 0x1E6E0240, 0x86000000);
1731 ast_moutdwm(ast, 0x1E6E0244, 0x00008600);
1732 ast_moutdwm(ast, 0x1E6E0248, 0x80000000);
1733 ast_moutdwm(ast, 0x1E6E024C, 0x80808080);
1736 static void ddr_phy_init_2500(struct ast_device *ast)
1738 u32 data, pass, timecnt;
1741 ast_moutdwm(ast, 0x1E6E0060, 0x00000005);
1743 for (timecnt = 0; timecnt < TIMEOUT; timecnt++) {
1744 data = ast_mindwm(ast, 0x1E6E0060) & 0x1;
1748 if (timecnt != TIMEOUT) {
1749 data = ast_mindwm(ast, 0x1E6E0300) & 0x000A0000;
1754 ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
1755 udelay(10); /* delay 10 us */
1756 ast_moutdwm(ast, 0x1E6E0060, 0x00000005);
1760 ast_moutdwm(ast, 0x1E6E0060, 0x00000006);
1765 * 1Gb : 0x80000000 ~ 0x87FFFFFF
1766 * 2Gb : 0x80000000 ~ 0x8FFFFFFF
1767 * 4Gb : 0x80000000 ~ 0x9FFFFFFF
1768 * 8Gb : 0x80000000 ~ 0xBFFFFFFF
1770 static void check_dram_size_2500(struct ast_device *ast, u32 tRFC)
1774 reg_04 = ast_mindwm(ast, 0x1E6E0004) & 0xfffffffc;
1775 reg_14 = ast_mindwm(ast, 0x1E6E0014) & 0xffffff00;
1777 ast_moutdwm(ast, 0xA0100000, 0x41424344);
1778 ast_moutdwm(ast, 0x90100000, 0x35363738);
1779 ast_moutdwm(ast, 0x88100000, 0x292A2B2C);
1780 ast_moutdwm(ast, 0x80100000, 0x1D1E1F10);
1783 if (ast_mindwm(ast, 0xA0100000) == 0x41424344) {
1785 reg_14 |= (tRFC >> 24) & 0xFF;
1787 } else if (ast_mindwm(ast, 0x90100000) == 0x35363738) {
1789 reg_14 |= (tRFC >> 16) & 0xFF;
1791 } else if (ast_mindwm(ast, 0x88100000) == 0x292A2B2C) {
1793 reg_14 |= (tRFC >> 8) & 0xFF;
1795 reg_14 |= tRFC & 0xFF;
1797 ast_moutdwm(ast, 0x1E6E0004, reg_04);
1798 ast_moutdwm(ast, 0x1E6E0014, reg_14);
1801 static void enable_cache_2500(struct ast_device *ast)
1805 reg_04 = ast_mindwm(ast, 0x1E6E0004);
1806 ast_moutdwm(ast, 0x1E6E0004, reg_04 | 0x1000);
1809 data = ast_mindwm(ast, 0x1E6E0004);
1810 while (!(data & 0x80000));
1811 ast_moutdwm(ast, 0x1E6E0004, reg_04 | 0x400);
1814 static void set_mpll_2500(struct ast_device *ast)
1816 u32 addr, data, param;
1819 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1820 ast_moutdwm(ast, 0x1E6E0034, 0x00020080);
1821 for (addr = 0x1e6e0004; addr < 0x1e6e0090;) {
1822 ast_moutdwm(ast, addr, 0x0);
1825 ast_moutdwm(ast, 0x1E6E0034, 0x00020000);
1827 ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
1828 data = ast_mindwm(ast, 0x1E6E2070) & 0x00800000;
1832 ast_moutdwm(ast, 0x1E6E2160, 0x00011320);
1837 ast_moutdwm(ast, 0x1E6E2020, param);
1841 static void reset_mmc_2500(struct ast_device *ast)
1843 ast_moutdwm(ast, 0x1E78505C, 0x00000004);
1844 ast_moutdwm(ast, 0x1E785044, 0x00000001);
1845 ast_moutdwm(ast, 0x1E785048, 0x00004755);
1846 ast_moutdwm(ast, 0x1E78504C, 0x00000013);
1848 ast_moutdwm(ast, 0x1E785054, 0x00000077);
1849 ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
1852 static void ddr3_init_2500(struct ast_device *ast, const u32 *ddr_table)
1855 ast_moutdwm(ast, 0x1E6E0004, 0x00000303);
1856 ast_moutdwm(ast, 0x1E6E0010, ddr_table[REGIDX_010]);
1857 ast_moutdwm(ast, 0x1E6E0014, ddr_table[REGIDX_014]);
1858 ast_moutdwm(ast, 0x1E6E0018, ddr_table[REGIDX_018]);
1859 ast_moutdwm(ast, 0x1E6E0020, ddr_table[REGIDX_020]); /* MODEREG4/6 */
1860 ast_moutdwm(ast, 0x1E6E0024, ddr_table[REGIDX_024]); /* MODEREG5 */
1861 ast_moutdwm(ast, 0x1E6E002C, ddr_table[REGIDX_02C] | 0x100); /* MODEREG0/2 */
1862 ast_moutdwm(ast, 0x1E6E0030, ddr_table[REGIDX_030]); /* MODEREG1/3 */
1864 /* DDR PHY Setting */
1865 ast_moutdwm(ast, 0x1E6E0200, 0x02492AAE);
1866 ast_moutdwm(ast, 0x1E6E0204, 0x00001001);
1867 ast_moutdwm(ast, 0x1E6E020C, 0x55E00B0B);
1868 ast_moutdwm(ast, 0x1E6E0210, 0x20000000);
1869 ast_moutdwm(ast, 0x1E6E0214, ddr_table[REGIDX_214]);
1870 ast_moutdwm(ast, 0x1E6E02E0, ddr_table[REGIDX_2E0]);
1871 ast_moutdwm(ast, 0x1E6E02E4, ddr_table[REGIDX_2E4]);
1872 ast_moutdwm(ast, 0x1E6E02E8, ddr_table[REGIDX_2E8]);
1873 ast_moutdwm(ast, 0x1E6E02EC, ddr_table[REGIDX_2EC]);
1874 ast_moutdwm(ast, 0x1E6E02F0, ddr_table[REGIDX_2F0]);
1875 ast_moutdwm(ast, 0x1E6E02F4, ddr_table[REGIDX_2F4]);
1876 ast_moutdwm(ast, 0x1E6E02F8, ddr_table[REGIDX_2F8]);
1877 ast_moutdwm(ast, 0x1E6E0290, 0x00100008);
1878 ast_moutdwm(ast, 0x1E6E02C0, 0x00000006);
1880 /* Controller Setting */
1881 ast_moutdwm(ast, 0x1E6E0034, 0x00020091);
1883 /* Wait DDR PHY init done */
1884 ddr_phy_init_2500(ast);
1886 ast_moutdwm(ast, 0x1E6E0120, ddr_table[REGIDX_PLL]);
1887 ast_moutdwm(ast, 0x1E6E000C, 0x42AA5C81);
1888 ast_moutdwm(ast, 0x1E6E0034, 0x0001AF93);
1890 check_dram_size_2500(ast, ddr_table[REGIDX_RFC]);
1891 enable_cache_2500(ast);
1892 ast_moutdwm(ast, 0x1E6E001C, 0x00000008);
1893 ast_moutdwm(ast, 0x1E6E0038, 0xFFFFFF00);
1896 static void ddr4_init_2500(struct ast_device *ast, const u32 *ddr_table)
1898 u32 data, data2, pass, retrycnt;
1899 u32 ddr_vref, phy_vref;
1900 u32 min_ddr_vref = 0, min_phy_vref = 0;
1901 u32 max_ddr_vref = 0, max_phy_vref = 0;
1903 ast_moutdwm(ast, 0x1E6E0004, 0x00000313);
1904 ast_moutdwm(ast, 0x1E6E0010, ddr_table[REGIDX_010]);
1905 ast_moutdwm(ast, 0x1E6E0014, ddr_table[REGIDX_014]);
1906 ast_moutdwm(ast, 0x1E6E0018, ddr_table[REGIDX_018]);
1907 ast_moutdwm(ast, 0x1E6E0020, ddr_table[REGIDX_020]); /* MODEREG4/6 */
1908 ast_moutdwm(ast, 0x1E6E0024, ddr_table[REGIDX_024]); /* MODEREG5 */
1909 ast_moutdwm(ast, 0x1E6E002C, ddr_table[REGIDX_02C] | 0x100); /* MODEREG0/2 */
1910 ast_moutdwm(ast, 0x1E6E0030, ddr_table[REGIDX_030]); /* MODEREG1/3 */
1912 /* DDR PHY Setting */
1913 ast_moutdwm(ast, 0x1E6E0200, 0x42492AAE);
1914 ast_moutdwm(ast, 0x1E6E0204, 0x09002000);
1915 ast_moutdwm(ast, 0x1E6E020C, 0x55E00B0B);
1916 ast_moutdwm(ast, 0x1E6E0210, 0x20000000);
1917 ast_moutdwm(ast, 0x1E6E0214, ddr_table[REGIDX_214]);
1918 ast_moutdwm(ast, 0x1E6E02E0, ddr_table[REGIDX_2E0]);
1919 ast_moutdwm(ast, 0x1E6E02E4, ddr_table[REGIDX_2E4]);
1920 ast_moutdwm(ast, 0x1E6E02E8, ddr_table[REGIDX_2E8]);
1921 ast_moutdwm(ast, 0x1E6E02EC, ddr_table[REGIDX_2EC]);
1922 ast_moutdwm(ast, 0x1E6E02F0, ddr_table[REGIDX_2F0]);
1923 ast_moutdwm(ast, 0x1E6E02F4, ddr_table[REGIDX_2F4]);
1924 ast_moutdwm(ast, 0x1E6E02F8, ddr_table[REGIDX_2F8]);
1925 ast_moutdwm(ast, 0x1E6E0290, 0x00100008);
1926 ast_moutdwm(ast, 0x1E6E02C4, 0x3C183C3C);
1927 ast_moutdwm(ast, 0x1E6E02C8, 0x00631E0E);
1929 /* Controller Setting */
1930 ast_moutdwm(ast, 0x1E6E0034, 0x0001A991);
1932 /* Train PHY Vref first */
1935 for (retrycnt = 0; retrycnt < 4 && pass == 0; retrycnt++) {
1938 ast_moutdwm(ast, 0x1E6E02C0, 0x00001C06);
1939 for (phy_vref = 0x40; phy_vref < 0x80; phy_vref++) {
1940 ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
1941 ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
1942 ast_moutdwm(ast, 0x1E6E02CC, phy_vref | (phy_vref << 8));
1944 ddr_phy_init_2500(ast);
1945 ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
1946 if (cbr_test_2500(ast)) {
1948 data = ast_mindwm(ast, 0x1E6E03D0);
1953 if (max_phy_vref < data) {
1954 max_phy_vref = data;
1955 min_phy_vref = phy_vref;
1957 } else if (pass > 0)
1961 ast_moutdwm(ast, 0x1E6E02CC, min_phy_vref | (min_phy_vref << 8));
1963 /* Train DDR Vref next */
1966 for (retrycnt = 0; retrycnt < 4 && pass == 0; retrycnt++) {
1967 min_ddr_vref = 0xFF;
1970 for (ddr_vref = 0x00; ddr_vref < 0x40; ddr_vref++) {
1971 ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
1972 ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
1973 ast_moutdwm(ast, 0x1E6E02C0, 0x00000006 | (ddr_vref << 8));
1975 ddr_phy_init_2500(ast);
1976 ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
1977 if (cbr_test_2500(ast)) {
1979 if (min_ddr_vref > ddr_vref)
1980 min_ddr_vref = ddr_vref;
1981 if (max_ddr_vref < ddr_vref)
1982 max_ddr_vref = ddr_vref;
1983 } else if (pass != 0)
1988 ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
1989 ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
1990 ddr_vref = (min_ddr_vref + max_ddr_vref + 1) >> 1;
1991 ast_moutdwm(ast, 0x1E6E02C0, 0x00000006 | (ddr_vref << 8));
1993 /* Wait DDR PHY init done */
1994 ddr_phy_init_2500(ast);
1996 ast_moutdwm(ast, 0x1E6E0120, ddr_table[REGIDX_PLL]);
1997 ast_moutdwm(ast, 0x1E6E000C, 0x42AA5C81);
1998 ast_moutdwm(ast, 0x1E6E0034, 0x0001AF93);
2000 check_dram_size_2500(ast, ddr_table[REGIDX_RFC]);
2001 enable_cache_2500(ast);
2002 ast_moutdwm(ast, 0x1E6E001C, 0x00000008);
2003 ast_moutdwm(ast, 0x1E6E0038, 0xFFFFFF00);
2006 static bool ast_dram_init_2500(struct ast_device *ast)
2012 if (max_tries-- == 0)
2015 reset_mmc_2500(ast);
2016 ddr_init_common_2500(ast);
2018 data = ast_mindwm(ast, 0x1E6E2070);
2019 if (data & 0x01000000)
2020 ddr4_init_2500(ast, ast2500_ddr4_1600_timing_table);
2022 ddr3_init_2500(ast, ast2500_ddr3_1600_timing_table);
2023 } while (!ddr_test_2500(ast));
2025 ast_moutdwm(ast, 0x1E6E2040, ast_mindwm(ast, 0x1E6E2040) | 0x41);
2028 data = ast_mindwm(ast, 0x1E6E200C) & 0xF9FFFFFF;
2029 ast_moutdwm(ast, 0x1E6E200C, data | 0x10000000);
2034 void ast_patch_ahb_2500(struct ast_device *ast)
2038 /* Clear bus lock condition */
2039 ast_moutdwm(ast, 0x1e600000, 0xAEED1A03);
2040 ast_moutdwm(ast, 0x1e600084, 0x00010000);
2041 ast_moutdwm(ast, 0x1e600088, 0x00000000);
2042 ast_moutdwm(ast, 0x1e6e2000, 0x1688A8A8);
2043 data = ast_mindwm(ast, 0x1e6e2070);
2044 if (data & 0x08000000) { /* check fast reset */
2046 * If "Fast restet" is enabled for ARM-ICE debugger,
2047 * then WDT needs to enable, that
2048 * WDT04 is WDT#1 Reload reg.
2049 * WDT08 is WDT#1 counter restart reg to avoid system deadlock
2050 * WDT0C is WDT#1 control reg
2051 * [6:5]:= 01:Full chip
2052 * [4]:= 1:1MHz clock source
2053 * [1]:= 1:WDT will be cleeared and disabled after timeout occurs
2054 * [0]:= 1:WDT enable
2056 ast_moutdwm(ast, 0x1E785004, 0x00000010);
2057 ast_moutdwm(ast, 0x1E785008, 0x00004755);
2058 ast_moutdwm(ast, 0x1E78500c, 0x00000033);
2062 ast_moutdwm(ast, 0x1e6e2000, 0x1688A8A8);
2063 data = ast_mindwm(ast, 0x1e6e2000);
2064 } while (data != 1);
2065 ast_moutdwm(ast, 0x1e6e207c, 0x08000000); /* clear fast reset */
2068 void ast_post_chip_2500(struct drm_device *dev)
2070 struct ast_device *ast = to_ast_device(dev);
2074 reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
2075 if ((reg & AST_VRAM_INIT_STATUS_MASK) == 0) {/* vga only */
2076 /* Clear bus lock condition */
2077 ast_patch_ahb_2500(ast);
2079 /* Disable watchdog */
2080 ast_moutdwm(ast, 0x1E78502C, 0x00000000);
2081 ast_moutdwm(ast, 0x1E78504C, 0x00000000);
2084 * Reset USB port to patch USB unknown device issue
2085 * SCU90 is Multi-function Pin Control #5
2086 * [29]:= 1:Enable USB2.0 Host port#1 (that the mutually shared USB2.0 Hub
2088 * SCU94 is Multi-function Pin Control #6
2089 * [14:13]:= 1x:USB2.0 Host2 controller
2090 * SCU70 is Hardware Strap reg
2091 * [23]:= 1:CLKIN is 25MHz and USBCK1 = 24/48 MHz (determined by
2092 * [18]: 0(24)/1(48) MHz)
2093 * SCU7C is Write clear reg to SCU70
2094 * [23]:= write 1 and then SCU70[23] will be clear as 0b.
2096 ast_moutdwm(ast, 0x1E6E2090, 0x20000000);
2097 ast_moutdwm(ast, 0x1E6E2094, 0x00004000);
2098 if (ast_mindwm(ast, 0x1E6E2070) & 0x00800000) {
2099 ast_moutdwm(ast, 0x1E6E207C, 0x00800000);
2101 ast_moutdwm(ast, 0x1E6E2070, 0x00800000);
2103 /* Modify eSPI reset pin */
2104 temp = ast_mindwm(ast, 0x1E6E2070);
2105 if (temp & 0x02000000)
2106 ast_moutdwm(ast, 0x1E6E207C, 0x00004000);
2108 /* Slow down CPU/AHB CLK in VGA only mode */
2109 temp = ast_read32(ast, 0x12008);
2111 ast_write32(ast, 0x12008, temp);
2113 if (!ast_dram_init_2500(ast))
2114 drm_err(dev, "DRAM init failed !\n");
2116 temp = ast_mindwm(ast, 0x1e6e2040);
2117 ast_moutdwm(ast, 0x1e6e2040, temp | 0x40);
2122 reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
2123 } while ((reg & 0x40) == 0);