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
26 * Authors: Dave Airlie <airlied@redhat.com>
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_private
*ast
= to_ast_private(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_private
*ast
= to_ast_private(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_private
*ast
= to_ast_private(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_private
*ast
= to_ast_private(dev
);
75 const u8
*ext_reg_info
;
78 for (i
= 0x81; i
<= 0x9f; i
++)
79 ast_set_index_reg(ast
, AST_IO_CRTC_PORT
, i
, 0x00);
81 if (ast
->chip
== AST2300
|| ast
->chip
== AST2400
||
82 ast
->chip
== AST2500
) {
83 if (dev
->pdev
->revision
>= 0x20)
84 ext_reg_info
= extreginfo_ast2300
;
86 ext_reg_info
= extreginfo_ast2300a0
;
88 ext_reg_info
= extreginfo
;
91 while (*ext_reg_info
!= 0xff) {
92 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, index
, 0x00, *ext_reg_info
);
97 /* disable standard IO/MEM decode if secondary */
98 /* ast_set_index_reg-mask(ast, AST_IO_CRTC_PORT, 0xa1, 0xff, 0x3); */
100 /* Set Ext. Default */
101 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0x8c, 0x00, 0x01);
102 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xb7, 0x00, 0x00);
104 /* Enable RAMDAC for A1 */
106 if (ast
->chip
== AST2300
|| ast
->chip
== AST2400
||
107 ast
->chip
== AST2500
)
109 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xb6, 0xff, reg
);
112 u32
ast_mindwm(struct ast_private
*ast
, u32 r
)
116 ast_write32(ast
, 0xf004, r
& 0xffff0000);
117 ast_write32(ast
, 0xf000, 0x1);
120 data
= ast_read32(ast
, 0xf004) & 0xffff0000;
121 } while (data
!= (r
& 0xffff0000));
122 return ast_read32(ast
, 0x10000 + (r
& 0x0000ffff));
125 void ast_moutdwm(struct ast_private
*ast
, u32 r
, u32 v
)
128 ast_write32(ast
, 0xf004, r
& 0xffff0000);
129 ast_write32(ast
, 0xf000, 0x1);
131 data
= ast_read32(ast
, 0xf004) & 0xffff0000;
132 } while (data
!= (r
& 0xffff0000));
133 ast_write32(ast
, 0x10000 + (r
& 0x0000ffff), v
);
137 * AST2100/2150 DLL CBR Setting
139 #define CBR_SIZE_AST2150 ((16 << 10) - 1)
140 #define CBR_PASSNUM_AST2150 5
141 #define CBR_THRESHOLD_AST2150 10
142 #define CBR_THRESHOLD2_AST2150 10
143 #define TIMEOUT_AST2150 5000000
145 #define CBR_PATNUM_AST2150 8
147 static const u32 pattern_AST2150
[14] = {
164 static u32
mmctestburst2_ast2150(struct ast_private
*ast
, u32 datagen
)
168 ast_moutdwm(ast
, 0x1e6e0070, 0x00000000);
169 ast_moutdwm(ast
, 0x1e6e0070, 0x00000001 | (datagen
<< 3));
172 data
= ast_mindwm(ast
, 0x1e6e0070) & 0x40;
173 if (++timeout
> TIMEOUT_AST2150
) {
174 ast_moutdwm(ast
, 0x1e6e0070, 0x00000000);
178 ast_moutdwm(ast
, 0x1e6e0070, 0x00000000);
179 ast_moutdwm(ast
, 0x1e6e0070, 0x00000003 | (datagen
<< 3));
182 data
= ast_mindwm(ast
, 0x1e6e0070) & 0x40;
183 if (++timeout
> TIMEOUT_AST2150
) {
184 ast_moutdwm(ast
, 0x1e6e0070, 0x00000000);
188 data
= (ast_mindwm(ast
, 0x1e6e0070) & 0x80) >> 7;
189 ast_moutdwm(ast
, 0x1e6e0070, 0x00000000);
193 #if 0 /* unused in DDX driver - here for completeness */
194 static u32
mmctestsingle2_ast2150(struct ast_private
*ast
, u32 datagen
)
198 ast_moutdwm(ast
, 0x1e6e0070, 0x00000000);
199 ast_moutdwm(ast
, 0x1e6e0070, 0x00000005 | (datagen
<< 3));
202 data
= ast_mindwm(ast
, 0x1e6e0070) & 0x40;
203 if (++timeout
> TIMEOUT_AST2150
) {
204 ast_moutdwm(ast
, 0x1e6e0070, 0x00000000);
208 data
= (ast_mindwm(ast
, 0x1e6e0070) & 0x80) >> 7;
209 ast_moutdwm(ast
, 0x1e6e0070, 0x00000000);
214 static int cbrtest_ast2150(struct ast_private
*ast
)
218 for (i
= 0; i
< 8; i
++)
219 if (mmctestburst2_ast2150(ast
, i
))
224 static int cbrscan_ast2150(struct ast_private
*ast
, int busw
)
228 for (patcnt
= 0; patcnt
< CBR_PATNUM_AST2150
; patcnt
++) {
229 ast_moutdwm(ast
, 0x1e6e007c, pattern_AST2150
[patcnt
]);
230 for (loop
= 0; loop
< CBR_PASSNUM_AST2150
; loop
++) {
231 if (cbrtest_ast2150(ast
))
234 if (loop
== CBR_PASSNUM_AST2150
)
241 static void cbrdlli_ast2150(struct ast_private
*ast
, int busw
)
243 u32 dll_min
[4], dll_max
[4], dlli
, data
, passcnt
;
246 dll_min
[0] = dll_min
[1] = dll_min
[2] = dll_min
[3] = 0xff;
247 dll_max
[0] = dll_max
[1] = dll_max
[2] = dll_max
[3] = 0x0;
250 for (dlli
= 0; dlli
< 100; dlli
++) {
251 ast_moutdwm(ast
, 0x1e6e0068, dlli
| (dlli
<< 8) | (dlli
<< 16) | (dlli
<< 24));
252 data
= cbrscan_ast2150(ast
, busw
);
255 if (dll_min
[0] > dlli
)
257 if (dll_max
[0] < dlli
)
261 } else if (passcnt
>= CBR_THRESHOLD_AST2150
)
264 if (dll_max
[0] == 0 || (dll_max
[0]-dll_min
[0]) < CBR_THRESHOLD_AST2150
)
267 dlli
= dll_min
[0] + (((dll_max
[0] - dll_min
[0]) * 7) >> 4);
268 ast_moutdwm(ast
, 0x1e6e0068, dlli
| (dlli
<< 8) | (dlli
<< 16) | (dlli
<< 24));
273 static void ast_init_dram_reg(struct drm_device
*dev
)
275 struct ast_private
*ast
= to_ast_private(dev
);
278 const struct ast_dramstruct
*dram_reg_info
;
280 j
= ast_get_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xd0, 0xff);
282 if ((j
& 0x80) == 0) { /* VGA only */
283 if (ast
->chip
== AST2000
) {
284 dram_reg_info
= ast2000_dram_table_data
;
285 ast_write32(ast
, 0xf004, 0x1e6e0000);
286 ast_write32(ast
, 0xf000, 0x1);
287 ast_write32(ast
, 0x10100, 0xa8);
291 } while (ast_read32(ast
, 0x10100) != 0xa8);
292 } else {/* AST2100/1100 */
293 if (ast
->chip
== AST2100
|| ast
->chip
== 2200)
294 dram_reg_info
= ast2100_dram_table_data
;
296 dram_reg_info
= ast1100_dram_table_data
;
298 ast_write32(ast
, 0xf004, 0x1e6e0000);
299 ast_write32(ast
, 0xf000, 0x1);
300 ast_write32(ast
, 0x12000, 0x1688A8A8);
303 } while (ast_read32(ast
, 0x12000) != 0x01);
305 ast_write32(ast
, 0x10000, 0xfc600309);
308 } while (ast_read32(ast
, 0x10000) != 0x01);
311 while (dram_reg_info
->index
!= 0xffff) {
312 if (dram_reg_info
->index
== 0xff00) {/* delay fn */
313 for (i
= 0; i
< 15; i
++)
314 udelay(dram_reg_info
->data
);
315 } else if (dram_reg_info
->index
== 0x4 && ast
->chip
!= AST2000
) {
316 data
= dram_reg_info
->data
;
317 if (ast
->dram_type
== AST_DRAM_1Gx16
)
319 else if (ast
->dram_type
== AST_DRAM_1Gx32
)
322 temp
= ast_read32(ast
, 0x12070);
325 ast_write32(ast
, 0x10000 + dram_reg_info
->index
, data
| temp
);
327 ast_write32(ast
, 0x10000 + dram_reg_info
->index
, dram_reg_info
->data
);
331 /* AST 2100/2150 DRAM calibration */
332 data
= ast_read32(ast
, 0x10120);
333 if (data
== 0x5061) { /* 266Mhz */
334 data
= ast_read32(ast
, 0x10004);
336 cbrdlli_ast2150(ast
, 16); /* 16 bits */
338 cbrdlli_ast2150(ast
, 32); /* 32 bits */
343 temp
= ast_read32(ast
, 0x10140);
344 ast_write32(ast
, 0x10140, temp
| 0x40);
350 temp
= ast_read32(ast
, 0x1200c);
351 ast_write32(ast
, 0x1200c, temp
& 0xfffffffd);
352 temp
= ast_read32(ast
, 0x12040);
353 ast_write32(ast
, 0x12040, temp
| 0x40);
362 j
= ast_get_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xd0, 0xff);
363 } while ((j
& 0x40) == 0);
366 void ast_post_gpu(struct drm_device
*dev
)
368 struct ast_private
*ast
= to_ast_private(dev
);
371 pci_read_config_dword(dev
->pdev
, 0x04, ®
);
373 pci_write_config_dword(dev
->pdev
, 0x04, reg
);
377 ast_enable_mmio(dev
);
378 ast_set_def_ext_reg(dev
);
380 if (ast
->config_mode
== ast_use_p2a
) {
381 if (ast
->chip
== AST2500
)
382 ast_post_chip_2500(dev
);
383 else if (ast
->chip
== AST2300
|| ast
->chip
== AST2400
)
384 ast_post_chip_2300(dev
);
386 ast_init_dram_reg(dev
);
390 if (ast
->tx_chip_type
!= AST_TX_NONE
)
391 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xa3, 0xcf, 0x80); /* Enable DVO */
395 /* AST 2300 DRAM settings */
399 struct ast2300_dram_param
{
421 u32 dll2_finetune_step
;
425 * DQSI DLL CBR Setting
427 #define CBR_SIZE0 ((1 << 10) - 1)
428 #define CBR_SIZE1 ((4 << 10) - 1)
429 #define CBR_SIZE2 ((64 << 10) - 1)
430 #define CBR_PASSNUM 5
431 #define CBR_PASSNUM2 5
432 #define CBR_THRESHOLD 10
433 #define CBR_THRESHOLD2 10
434 #define TIMEOUT 5000000
437 static const u32 pattern
[8] = {
448 static bool mmc_test(struct ast_private
*ast
, u32 datagen
, u8 test_ctl
)
452 ast_moutdwm(ast
, 0x1e6e0070, 0x00000000);
453 ast_moutdwm(ast
, 0x1e6e0070, (datagen
<< 3) | test_ctl
);
456 data
= ast_mindwm(ast
, 0x1e6e0070) & 0x3000;
459 if (++timeout
> TIMEOUT
) {
460 ast_moutdwm(ast
, 0x1e6e0070, 0x00000000);
464 ast_moutdwm(ast
, 0x1e6e0070, 0x0);
468 static u32
mmc_test2(struct ast_private
*ast
, u32 datagen
, u8 test_ctl
)
472 ast_moutdwm(ast
, 0x1e6e0070, 0x00000000);
473 ast_moutdwm(ast
, 0x1e6e0070, (datagen
<< 3) | test_ctl
);
476 data
= ast_mindwm(ast
, 0x1e6e0070) & 0x1000;
477 if (++timeout
> TIMEOUT
) {
478 ast_moutdwm(ast
, 0x1e6e0070, 0x0);
482 data
= ast_mindwm(ast
, 0x1e6e0078);
483 data
= (data
| (data
>> 16)) & 0xffff;
484 ast_moutdwm(ast
, 0x1e6e0070, 0x00000000);
489 static bool mmc_test_burst(struct ast_private
*ast
, u32 datagen
)
491 return mmc_test(ast
, datagen
, 0xc1);
494 static u32
mmc_test_burst2(struct ast_private
*ast
, u32 datagen
)
496 return mmc_test2(ast
, datagen
, 0x41);
499 static bool mmc_test_single(struct ast_private
*ast
, u32 datagen
)
501 return mmc_test(ast
, datagen
, 0xc5);
504 static u32
mmc_test_single2(struct ast_private
*ast
, u32 datagen
)
506 return mmc_test2(ast
, datagen
, 0x05);
509 static bool mmc_test_single_2500(struct ast_private
*ast
, u32 datagen
)
511 return mmc_test(ast
, datagen
, 0x85);
514 static int cbr_test(struct ast_private
*ast
)
518 data
= mmc_test_single2(ast
, 0);
519 if ((data
& 0xff) && (data
& 0xff00))
521 for (i
= 0; i
< 8; i
++) {
522 data
= mmc_test_burst2(ast
, i
);
523 if ((data
& 0xff) && (data
& 0xff00))
528 else if (data
& 0xff)
533 static int cbr_scan(struct ast_private
*ast
)
535 u32 data
, data2
, patcnt
, loop
;
538 for (patcnt
= 0; patcnt
< CBR_PATNUM
; patcnt
++) {
539 ast_moutdwm(ast
, 0x1e6e007c, pattern
[patcnt
]);
540 for (loop
= 0; loop
< CBR_PASSNUM2
; loop
++) {
541 if ((data
= cbr_test(ast
)) != 0) {
548 if (loop
== CBR_PASSNUM2
)
554 static u32
cbr_test2(struct ast_private
*ast
)
558 data
= mmc_test_burst2(ast
, 0);
561 data
|= mmc_test_single2(ast
, 0);
565 return ~data
& 0xffff;
568 static u32
cbr_scan2(struct ast_private
*ast
)
570 u32 data
, data2
, patcnt
, loop
;
573 for (patcnt
= 0; patcnt
< CBR_PATNUM
; patcnt
++) {
574 ast_moutdwm(ast
, 0x1e6e007c, pattern
[patcnt
]);
575 for (loop
= 0; loop
< CBR_PASSNUM2
; loop
++) {
576 if ((data
= cbr_test2(ast
)) != 0) {
583 if (loop
== CBR_PASSNUM2
)
589 static bool cbr_test3(struct ast_private
*ast
)
591 if (!mmc_test_burst(ast
, 0))
593 if (!mmc_test_single(ast
, 0))
598 static bool cbr_scan3(struct ast_private
*ast
)
602 for (patcnt
= 0; patcnt
< CBR_PATNUM
; patcnt
++) {
603 ast_moutdwm(ast
, 0x1e6e007c, pattern
[patcnt
]);
604 for (loop
= 0; loop
< 2; loop
++) {
614 static bool finetuneDQI_L(struct ast_private
*ast
, struct ast2300_dram_param
*param
)
616 u32 gold_sadj
[2], dllmin
[16], dllmax
[16], dlli
, data
, cnt
, mask
, passcnt
, retry
= 0;
619 for (cnt
= 0; cnt
< 16; cnt
++) {
624 for (dlli
= 0; dlli
< 76; dlli
++) {
625 ast_moutdwm(ast
, 0x1E6E0068, 0x00001400 | (dlli
<< 16) | (dlli
<< 24));
626 ast_moutdwm(ast
, 0x1E6E0074, CBR_SIZE1
);
627 data
= cbr_scan2(ast
);
630 for (cnt
= 0; cnt
< 16; cnt
++) {
632 if (dllmin
[cnt
] > dlli
) {
635 if (dllmax
[cnt
] < dlli
) {
642 } else if (passcnt
>= CBR_THRESHOLD2
) {
648 for (cnt
= 0; cnt
< 16; cnt
++) {
649 if ((dllmax
[cnt
] > dllmin
[cnt
]) && ((dllmax
[cnt
] - dllmin
[cnt
]) >= CBR_THRESHOLD2
)) {
650 gold_sadj
[0] += dllmin
[cnt
];
661 gold_sadj
[0] = gold_sadj
[0] >> 4;
662 gold_sadj
[1] = gold_sadj
[0];
665 for (cnt
= 0; cnt
< 8; cnt
++) {
667 if ((dllmax
[cnt
] > dllmin
[cnt
]) && ((dllmax
[cnt
] - dllmin
[cnt
]) >= CBR_THRESHOLD2
)) {
669 if (gold_sadj
[0] >= dlli
) {
670 dlli
= ((gold_sadj
[0] - dlli
) * 19) >> 5;
675 dlli
= ((dlli
- gold_sadj
[0]) * 19) >> 5;
679 dlli
= (8 - dlli
) & 0x7;
684 ast_moutdwm(ast
, 0x1E6E0080, data
);
687 for (cnt
= 8; cnt
< 16; cnt
++) {
689 if ((dllmax
[cnt
] > dllmin
[cnt
]) && ((dllmax
[cnt
] - dllmin
[cnt
]) >= CBR_THRESHOLD2
)) {
691 if (gold_sadj
[1] >= dlli
) {
692 dlli
= ((gold_sadj
[1] - dlli
) * 19) >> 5;
696 dlli
= (dlli
- 1) & 0x7;
699 dlli
= ((dlli
- gold_sadj
[1]) * 19) >> 5;
704 dlli
= (8 - dlli
) & 0x7;
709 ast_moutdwm(ast
, 0x1E6E0084, data
);
711 } /* finetuneDQI_L */
713 static void finetuneDQSI(struct ast_private
*ast
)
715 u32 dlli
, dqsip
, dqidly
;
716 u32 reg_mcr18
, reg_mcr0c
, passcnt
[2], diff
;
717 u32 g_dqidly
, g_dqsip
, g_margin
, g_side
;
721 /* Disable DQI CBR */
722 reg_mcr0c
= ast_mindwm(ast
, 0x1E6E000C);
723 reg_mcr18
= ast_mindwm(ast
, 0x1E6E0018);
724 reg_mcr18
&= 0x0000ffff;
725 ast_moutdwm(ast
, 0x1E6E0018, reg_mcr18
);
727 for (dlli
= 0; dlli
< 76; dlli
++) {
731 for (dqidly
= 0; dqidly
< 32; dqidly
++) {
732 pass
[dqidly
][0][0] = 0xff;
733 pass
[dqidly
][0][1] = 0x0;
734 pass
[dqidly
][1][0] = 0xff;
735 pass
[dqidly
][1][1] = 0x0;
737 for (dqidly
= 0; dqidly
< 32; dqidly
++) {
738 passcnt
[0] = passcnt
[1] = 0;
739 for (dqsip
= 0; dqsip
< 2; dqsip
++) {
740 ast_moutdwm(ast
, 0x1E6E000C, 0);
741 ast_moutdwm(ast
, 0x1E6E0018, reg_mcr18
| (dqidly
<< 16) | (dqsip
<< 23));
742 ast_moutdwm(ast
, 0x1E6E000C, reg_mcr0c
);
743 for (dlli
= 0; dlli
< 76; dlli
++) {
744 ast_moutdwm(ast
, 0x1E6E0068, 0x00001300 | (dlli
<< 16) | (dlli
<< 24));
745 ast_moutdwm(ast
, 0x1E6E0070, 0);
746 ast_moutdwm(ast
, 0x1E6E0074, CBR_SIZE0
);
747 if (cbr_scan3(ast
)) {
751 tag
[dqsip
][dlli
] = 'P';
752 if (dlli
< pass
[dqidly
][dqsip
][0])
753 pass
[dqidly
][dqsip
][0] = (u16
) dlli
;
754 if (dlli
> pass
[dqidly
][dqsip
][1])
755 pass
[dqidly
][dqsip
][1] = (u16
) dlli
;
756 } else if (passcnt
[dqsip
] >= 5)
759 pass
[dqidly
][dqsip
][0] = 0xff;
760 pass
[dqidly
][dqsip
][1] = 0x0;
764 if (passcnt
[0] == 0 && passcnt
[1] == 0)
768 g_dqidly
= g_dqsip
= g_margin
= g_side
= 0;
770 for (dqidly
= 0; dqidly
< 32; dqidly
++) {
771 for (dqsip
= 0; dqsip
< 2; dqsip
++) {
772 if (pass
[dqidly
][dqsip
][0] > pass
[dqidly
][dqsip
][1])
774 diff
= pass
[dqidly
][dqsip
][1] - pass
[dqidly
][dqsip
][0];
775 if ((diff
+2) < g_margin
)
777 passcnt
[0] = passcnt
[1] = 0;
778 for (dlli
= pass
[dqidly
][dqsip
][0]; dlli
> 0 && tag
[dqsip
][dlli
] != 0; dlli
--, passcnt
[0]++);
779 for (dlli
= pass
[dqidly
][dqsip
][1]; dlli
< 76 && tag
[dqsip
][dlli
] != 0; dlli
++, passcnt
[1]++);
780 if (passcnt
[0] > passcnt
[1])
781 passcnt
[0] = passcnt
[1];
783 if (passcnt
[0] > g_side
)
784 passcnt
[1] = passcnt
[0] - g_side
;
785 if (diff
> (g_margin
+1) && (passcnt
[1] > 0 || passcnt
[0] > 8)) {
790 } else if (passcnt
[1] > 1 && g_side
< 8) {
799 reg_mcr18
= reg_mcr18
| (g_dqidly
<< 16) | (g_dqsip
<< 23);
800 ast_moutdwm(ast
, 0x1E6E0018, reg_mcr18
);
803 static bool cbr_dll2(struct ast_private
*ast
, struct ast2300_dram_param
*param
)
805 u32 dllmin
[2], dllmax
[2], dlli
, data
, passcnt
, retry
= 0;
809 if (finetuneDQI_L(ast
, param
) == false)
813 dllmin
[0] = dllmin
[1] = 0xff;
814 dllmax
[0] = dllmax
[1] = 0x0;
816 for (dlli
= 0; dlli
< 76; dlli
++) {
817 ast_moutdwm(ast
, 0x1E6E0068, 0x00001300 | (dlli
<< 16) | (dlli
<< 24));
818 ast_moutdwm(ast
, 0x1E6E0074, CBR_SIZE2
);
819 data
= cbr_scan(ast
);
822 if (dllmin
[0] > dlli
) {
825 if (dllmax
[0] < dlli
) {
830 if (dllmin
[1] > dlli
) {
833 if (dllmax
[1] < dlli
) {
838 } else if (passcnt
>= CBR_THRESHOLD
) {
844 if (dllmax
[0] == 0 || (dllmax
[0]-dllmin
[0]) < CBR_THRESHOLD
) {
847 if (dllmax
[1] == 0 || (dllmax
[1]-dllmin
[1]) < CBR_THRESHOLD
) {
852 dlli
= (dllmin
[1] + dllmax
[1]) >> 1;
854 dlli
+= (dllmin
[0] + dllmax
[0]) >> 1;
855 ast_moutdwm(ast
, 0x1E6E0068, ast_mindwm(ast
, 0x1E720058) | (dlli
<< 16));
859 static void get_ddr3_info(struct ast_private
*ast
, struct ast2300_dram_param
*param
)
861 u32 trap
, trap_AC2
, trap_MRS
;
863 ast_moutdwm(ast
, 0x1E6E2000, 0x1688A8A8);
866 trap
= (ast_mindwm(ast
, 0x1E6E2070) >> 25) & 0x3;
867 trap_AC2
= 0x00020000 + (trap
<< 16);
868 trap_AC2
|= 0x00300000 + ((trap
& 0x2) << 19);
869 trap_MRS
= 0x00000010 + (trap
<< 4);
870 trap_MRS
|= ((trap
& 0x2) << 18);
872 param
->reg_MADJ
= 0x00034C4C;
873 param
->reg_SADJ
= 0x00001800;
874 param
->reg_DRV
= 0x000000F0;
875 param
->reg_PERIOD
= param
->dram_freq
;
878 switch (param
->dram_freq
) {
880 ast_moutdwm(ast
, 0x1E6E2020, 0x0190);
882 param
->reg_AC1
= 0x22202725;
883 param
->reg_AC2
= 0xAA007613 | trap_AC2
;
884 param
->reg_DQSIC
= 0x000000BA;
885 param
->reg_MRS
= 0x04001400 | trap_MRS
;
886 param
->reg_EMRS
= 0x00000000;
887 param
->reg_IOZ
= 0x00000023;
888 param
->reg_DQIDLY
= 0x00000074;
889 param
->reg_FREQ
= 0x00004DC0;
890 param
->madj_max
= 96;
891 param
->dll2_finetune_step
= 3;
892 switch (param
->dram_chipid
) {
894 case AST_DRAM_512Mx16
:
896 param
->reg_AC2
= 0xAA007613 | trap_AC2
;
899 param
->reg_AC2
= 0xAA00761C | trap_AC2
;
902 param
->reg_AC2
= 0xAA007636 | trap_AC2
;
908 ast_moutdwm(ast
, 0x1E6E2020, 0x03F1);
910 param
->reg_AC1
= 0x33302825;
911 param
->reg_AC2
= 0xCC009617 | trap_AC2
;
912 param
->reg_DQSIC
= 0x000000E2;
913 param
->reg_MRS
= 0x04001600 | trap_MRS
;
914 param
->reg_EMRS
= 0x00000000;
915 param
->reg_IOZ
= 0x00000034;
916 param
->reg_DRV
= 0x000000FA;
917 param
->reg_DQIDLY
= 0x00000089;
918 param
->reg_FREQ
= 0x00005040;
919 param
->madj_max
= 96;
920 param
->dll2_finetune_step
= 4;
922 switch (param
->dram_chipid
) {
924 case AST_DRAM_512Mx16
:
926 param
->reg_AC2
= 0xCC009617 | trap_AC2
;
929 param
->reg_AC2
= 0xCC009622 | trap_AC2
;
932 param
->reg_AC2
= 0xCC00963F | trap_AC2
;
938 ast_moutdwm(ast
, 0x1E6E2020, 0x01F0);
940 param
->reg_AC1
= 0x33302825;
941 param
->reg_AC2
= 0xCC009617 | trap_AC2
;
942 param
->reg_DQSIC
= 0x000000E2;
943 param
->reg_MRS
= 0x04001600 | trap_MRS
;
944 param
->reg_EMRS
= 0x00000000;
945 param
->reg_IOZ
= 0x00000023;
946 param
->reg_DRV
= 0x000000FA;
947 param
->reg_DQIDLY
= 0x00000089;
948 param
->reg_FREQ
= 0x000050C0;
949 param
->madj_max
= 96;
950 param
->dll2_finetune_step
= 4;
952 switch (param
->dram_chipid
) {
954 case AST_DRAM_512Mx16
:
956 param
->reg_AC2
= 0xCC009617 | trap_AC2
;
959 param
->reg_AC2
= 0xCC009622 | trap_AC2
;
962 param
->reg_AC2
= 0xCC00963F | trap_AC2
;
968 ast_moutdwm(ast
, 0x1E6E2020, 0x0230);
970 param
->reg_AC1
= 0x33302926;
971 param
->reg_AC2
= 0xCD44961A;
972 param
->reg_DQSIC
= 0x000000FC;
973 param
->reg_MRS
= 0x00081830;
974 param
->reg_EMRS
= 0x00000000;
975 param
->reg_IOZ
= 0x00000045;
976 param
->reg_DQIDLY
= 0x00000097;
977 param
->reg_FREQ
= 0x000052C0;
978 param
->madj_max
= 88;
979 param
->dll2_finetune_step
= 4;
982 ast_moutdwm(ast
, 0x1E6E2020, 0x0270);
984 param
->reg_AC1
= 0x33302926;
985 param
->reg_AC2
= 0xDE44A61D;
986 param
->reg_DQSIC
= 0x00000117;
987 param
->reg_MRS
= 0x00081A30;
988 param
->reg_EMRS
= 0x00000000;
989 param
->reg_IOZ
= 0x070000BB;
990 param
->reg_DQIDLY
= 0x000000A0;
991 param
->reg_FREQ
= 0x000054C0;
992 param
->madj_max
= 79;
993 param
->dll2_finetune_step
= 4;
996 ast_moutdwm(ast
, 0x1E6E2020, 0x0290);
999 param
->reg_AC1
= 0x33302926;
1000 param
->reg_AC2
= 0xEF44B61E;
1001 param
->reg_DQSIC
= 0x00000125;
1002 param
->reg_MRS
= 0x00081A30;
1003 param
->reg_EMRS
= 0x00000040;
1004 param
->reg_DRV
= 0x000000F5;
1005 param
->reg_IOZ
= 0x00000023;
1006 param
->reg_DQIDLY
= 0x00000088;
1007 param
->reg_FREQ
= 0x000055C0;
1008 param
->madj_max
= 76;
1009 param
->dll2_finetune_step
= 3;
1012 ast_moutdwm(ast
, 0x1E6E2020, 0x0140);
1013 param
->reg_MADJ
= 0x00136868;
1014 param
->reg_SADJ
= 0x00004534;
1017 param
->reg_AC1
= 0x33302A37;
1018 param
->reg_AC2
= 0xEF56B61E;
1019 param
->reg_DQSIC
= 0x0000013F;
1020 param
->reg_MRS
= 0x00101A50;
1021 param
->reg_EMRS
= 0x00000040;
1022 param
->reg_DRV
= 0x000000FA;
1023 param
->reg_IOZ
= 0x00000023;
1024 param
->reg_DQIDLY
= 0x00000078;
1025 param
->reg_FREQ
= 0x000057C0;
1026 param
->madj_max
= 136;
1027 param
->dll2_finetune_step
= 3;
1030 ast_moutdwm(ast
, 0x1E6E2020, 0x02E1);
1031 param
->reg_MADJ
= 0x00136868;
1032 param
->reg_SADJ
= 0x00004534;
1035 param
->reg_AC1
= 0x32302A37;
1036 param
->reg_AC2
= 0xDF56B61F;
1037 param
->reg_DQSIC
= 0x0000014D;
1038 param
->reg_MRS
= 0x00101A50;
1039 param
->reg_EMRS
= 0x00000004;
1040 param
->reg_DRV
= 0x000000F5;
1041 param
->reg_IOZ
= 0x00000023;
1042 param
->reg_DQIDLY
= 0x00000078;
1043 param
->reg_FREQ
= 0x000058C0;
1044 param
->madj_max
= 132;
1045 param
->dll2_finetune_step
= 3;
1048 ast_moutdwm(ast
, 0x1E6E2020, 0x0160);
1049 param
->reg_MADJ
= 0x00136868;
1050 param
->reg_SADJ
= 0x00004534;
1053 param
->reg_AC1
= 0x32302A37;
1054 param
->reg_AC2
= 0xEF56B621;
1055 param
->reg_DQSIC
= 0x0000015A;
1056 param
->reg_MRS
= 0x02101A50;
1057 param
->reg_EMRS
= 0x00000004;
1058 param
->reg_DRV
= 0x000000F5;
1059 param
->reg_IOZ
= 0x00000034;
1060 param
->reg_DQIDLY
= 0x00000078;
1061 param
->reg_FREQ
= 0x000059C0;
1062 param
->madj_max
= 128;
1063 param
->dll2_finetune_step
= 3;
1067 switch (param
->dram_chipid
) {
1068 case AST_DRAM_512Mx16
:
1069 param
->dram_config
= 0x130;
1072 case AST_DRAM_1Gx16
:
1073 param
->dram_config
= 0x131;
1075 case AST_DRAM_2Gx16
:
1076 param
->dram_config
= 0x132;
1078 case AST_DRAM_4Gx16
:
1079 param
->dram_config
= 0x133;
1083 switch (param
->vram_size
) {
1085 case AST_VIDMEM_SIZE_8M
:
1086 param
->dram_config
|= 0x00;
1088 case AST_VIDMEM_SIZE_16M
:
1089 param
->dram_config
|= 0x04;
1091 case AST_VIDMEM_SIZE_32M
:
1092 param
->dram_config
|= 0x08;
1094 case AST_VIDMEM_SIZE_64M
:
1095 param
->dram_config
|= 0x0c;
1101 static void ddr3_init(struct ast_private
*ast
, struct ast2300_dram_param
*param
)
1103 u32 data
, data2
, retry
= 0;
1106 ast_moutdwm(ast
, 0x1E6E0000, 0xFC600309);
1107 ast_moutdwm(ast
, 0x1E6E0018, 0x00000100);
1108 ast_moutdwm(ast
, 0x1E6E0024, 0x00000000);
1109 ast_moutdwm(ast
, 0x1E6E0034, 0x00000000);
1111 ast_moutdwm(ast
, 0x1E6E0064, param
->reg_MADJ
);
1112 ast_moutdwm(ast
, 0x1E6E0068, param
->reg_SADJ
);
1114 ast_moutdwm(ast
, 0x1E6E0064, param
->reg_MADJ
| 0xC0000);
1117 ast_moutdwm(ast
, 0x1E6E0004, param
->dram_config
);
1118 ast_moutdwm(ast
, 0x1E6E0008, 0x90040f);
1119 ast_moutdwm(ast
, 0x1E6E0010, param
->reg_AC1
);
1120 ast_moutdwm(ast
, 0x1E6E0014, param
->reg_AC2
);
1121 ast_moutdwm(ast
, 0x1E6E0020, param
->reg_DQSIC
);
1122 ast_moutdwm(ast
, 0x1E6E0080, 0x00000000);
1123 ast_moutdwm(ast
, 0x1E6E0084, 0x00000000);
1124 ast_moutdwm(ast
, 0x1E6E0088, param
->reg_DQIDLY
);
1125 ast_moutdwm(ast
, 0x1E6E0018, 0x4000A170);
1126 ast_moutdwm(ast
, 0x1E6E0018, 0x00002370);
1127 ast_moutdwm(ast
, 0x1E6E0038, 0x00000000);
1128 ast_moutdwm(ast
, 0x1E6E0040, 0xFF444444);
1129 ast_moutdwm(ast
, 0x1E6E0044, 0x22222222);
1130 ast_moutdwm(ast
, 0x1E6E0048, 0x22222222);
1131 ast_moutdwm(ast
, 0x1E6E004C, 0x00000002);
1132 ast_moutdwm(ast
, 0x1E6E0050, 0x80000000);
1133 ast_moutdwm(ast
, 0x1E6E0050, 0x00000000);
1134 ast_moutdwm(ast
, 0x1E6E0054, 0);
1135 ast_moutdwm(ast
, 0x1E6E0060, param
->reg_DRV
);
1136 ast_moutdwm(ast
, 0x1E6E006C, param
->reg_IOZ
);
1137 ast_moutdwm(ast
, 0x1E6E0070, 0x00000000);
1138 ast_moutdwm(ast
, 0x1E6E0074, 0x00000000);
1139 ast_moutdwm(ast
, 0x1E6E0078, 0x00000000);
1140 ast_moutdwm(ast
, 0x1E6E007C, 0x00000000);
1141 /* Wait MCLK2X lock to MCLK */
1143 data
= ast_mindwm(ast
, 0x1E6E001C);
1144 } while (!(data
& 0x08000000));
1145 data
= ast_mindwm(ast
, 0x1E6E001C);
1146 data
= (data
>> 8) & 0xff;
1147 while ((data
& 0x08) || ((data
& 0x7) < 2) || (data
< 4)) {
1148 data2
= (ast_mindwm(ast
, 0x1E6E0064) & 0xfff3ffff) + 4;
1149 if ((data2
& 0xff) > param
->madj_max
) {
1152 ast_moutdwm(ast
, 0x1E6E0064, data2
);
1153 if (data2
& 0x00100000) {
1154 data2
= ((data2
& 0xff) >> 3) + 3;
1156 data2
= ((data2
& 0xff) >> 2) + 5;
1158 data
= ast_mindwm(ast
, 0x1E6E0068) & 0xffff00ff;
1159 data2
+= data
& 0xff;
1160 data
= data
| (data2
<< 8);
1161 ast_moutdwm(ast
, 0x1E6E0068, data
);
1163 ast_moutdwm(ast
, 0x1E6E0064, ast_mindwm(ast
, 0x1E6E0064) | 0xC0000);
1165 data
= ast_mindwm(ast
, 0x1E6E0018) & 0xfffff1ff;
1166 ast_moutdwm(ast
, 0x1E6E0018, data
);
1167 data
= data
| 0x200;
1168 ast_moutdwm(ast
, 0x1E6E0018, data
);
1170 data
= ast_mindwm(ast
, 0x1E6E001C);
1171 } while (!(data
& 0x08000000));
1173 data
= ast_mindwm(ast
, 0x1E6E001C);
1174 data
= (data
>> 8) & 0xff;
1176 ast_moutdwm(ast
, 0x1E720058, ast_mindwm(ast
, 0x1E6E0068) & 0xffff);
1177 data
= ast_mindwm(ast
, 0x1E6E0018) | 0xC00;
1178 ast_moutdwm(ast
, 0x1E6E0018, data
);
1180 ast_moutdwm(ast
, 0x1E6E0034, 0x00000001);
1181 ast_moutdwm(ast
, 0x1E6E000C, 0x00000040);
1183 /* Mode Register Setting */
1184 ast_moutdwm(ast
, 0x1E6E002C, param
->reg_MRS
| 0x100);
1185 ast_moutdwm(ast
, 0x1E6E0030, param
->reg_EMRS
);
1186 ast_moutdwm(ast
, 0x1E6E0028, 0x00000005);
1187 ast_moutdwm(ast
, 0x1E6E0028, 0x00000007);
1188 ast_moutdwm(ast
, 0x1E6E0028, 0x00000003);
1189 ast_moutdwm(ast
, 0x1E6E0028, 0x00000001);
1190 ast_moutdwm(ast
, 0x1E6E002C, param
->reg_MRS
);
1191 ast_moutdwm(ast
, 0x1E6E000C, 0x00005C08);
1192 ast_moutdwm(ast
, 0x1E6E0028, 0x00000001);
1194 ast_moutdwm(ast
, 0x1E6E000C, 0x00005C01);
1200 data
= data
| 0x3000 | ((param
->reg_AC2
& 0x60000) >> 3);
1202 ast_moutdwm(ast
, 0x1E6E0034, data
| 0x3);
1204 /* Calibrate the DQSI delay */
1205 if ((cbr_dll2(ast
, param
) == false) && (retry
++ < 10))
1206 goto ddr3_init_start
;
1208 ast_moutdwm(ast
, 0x1E6E0120, param
->reg_FREQ
);
1209 /* ECC Memory Initialization */
1211 ast_moutdwm(ast
, 0x1E6E007C, 0x00000000);
1212 ast_moutdwm(ast
, 0x1E6E0070, 0x221);
1214 data
= ast_mindwm(ast
, 0x1E6E0070);
1215 } while (!(data
& 0x00001000));
1216 ast_moutdwm(ast
, 0x1E6E0070, 0x00000000);
1217 ast_moutdwm(ast
, 0x1E6E0050, 0x80000000);
1218 ast_moutdwm(ast
, 0x1E6E0050, 0x00000000);
1224 static void get_ddr2_info(struct ast_private
*ast
, struct ast2300_dram_param
*param
)
1226 u32 trap
, trap_AC2
, trap_MRS
;
1228 ast_moutdwm(ast
, 0x1E6E2000, 0x1688A8A8);
1231 trap
= (ast_mindwm(ast
, 0x1E6E2070) >> 25) & 0x3;
1232 trap_AC2
= (trap
<< 20) | (trap
<< 16);
1233 trap_AC2
+= 0x00110000;
1234 trap_MRS
= 0x00000040 | (trap
<< 4);
1237 param
->reg_MADJ
= 0x00034C4C;
1238 param
->reg_SADJ
= 0x00001800;
1239 param
->reg_DRV
= 0x000000F0;
1240 param
->reg_PERIOD
= param
->dram_freq
;
1243 switch (param
->dram_freq
) {
1245 ast_moutdwm(ast
, 0x1E6E2020, 0x0130);
1247 param
->reg_AC1
= 0x11101513;
1248 param
->reg_AC2
= 0x78117011;
1249 param
->reg_DQSIC
= 0x00000092;
1250 param
->reg_MRS
= 0x00000842;
1251 param
->reg_EMRS
= 0x00000000;
1252 param
->reg_DRV
= 0x000000F0;
1253 param
->reg_IOZ
= 0x00000034;
1254 param
->reg_DQIDLY
= 0x0000005A;
1255 param
->reg_FREQ
= 0x00004AC0;
1256 param
->madj_max
= 138;
1257 param
->dll2_finetune_step
= 3;
1260 ast_moutdwm(ast
, 0x1E6E2020, 0x0190);
1262 param
->reg_AC1
= 0x22202613;
1263 param
->reg_AC2
= 0xAA009016 | trap_AC2
;
1264 param
->reg_DQSIC
= 0x000000BA;
1265 param
->reg_MRS
= 0x00000A02 | trap_MRS
;
1266 param
->reg_EMRS
= 0x00000040;
1267 param
->reg_DRV
= 0x000000FA;
1268 param
->reg_IOZ
= 0x00000034;
1269 param
->reg_DQIDLY
= 0x00000074;
1270 param
->reg_FREQ
= 0x00004DC0;
1271 param
->madj_max
= 96;
1272 param
->dll2_finetune_step
= 3;
1273 switch (param
->dram_chipid
) {
1275 case AST_DRAM_512Mx16
:
1276 param
->reg_AC2
= 0xAA009012 | trap_AC2
;
1278 case AST_DRAM_1Gx16
:
1279 param
->reg_AC2
= 0xAA009016 | trap_AC2
;
1281 case AST_DRAM_2Gx16
:
1282 param
->reg_AC2
= 0xAA009023 | trap_AC2
;
1284 case AST_DRAM_4Gx16
:
1285 param
->reg_AC2
= 0xAA00903B | trap_AC2
;
1291 ast_moutdwm(ast
, 0x1E6E2020, 0x03F1);
1294 param
->reg_AC1
= 0x33302714;
1295 param
->reg_AC2
= 0xCC00B01B | trap_AC2
;
1296 param
->reg_DQSIC
= 0x000000E2;
1297 param
->reg_MRS
= 0x00000C02 | trap_MRS
;
1298 param
->reg_EMRS
= 0x00000040;
1299 param
->reg_DRV
= 0x000000FA;
1300 param
->reg_IOZ
= 0x00000034;
1301 param
->reg_DQIDLY
= 0x00000089;
1302 param
->reg_FREQ
= 0x00005040;
1303 param
->madj_max
= 96;
1304 param
->dll2_finetune_step
= 4;
1306 switch (param
->dram_chipid
) {
1307 case AST_DRAM_512Mx16
:
1308 param
->reg_AC2
= 0xCC00B016 | trap_AC2
;
1311 case AST_DRAM_1Gx16
:
1312 param
->reg_AC2
= 0xCC00B01B | trap_AC2
;
1314 case AST_DRAM_2Gx16
:
1315 param
->reg_AC2
= 0xCC00B02B | trap_AC2
;
1317 case AST_DRAM_4Gx16
:
1318 param
->reg_AC2
= 0xCC00B03F | trap_AC2
;
1325 ast_moutdwm(ast
, 0x1E6E2020, 0x01F0);
1328 param
->reg_AC1
= 0x33302714;
1329 param
->reg_AC2
= 0xCC00B01B | trap_AC2
;
1330 param
->reg_DQSIC
= 0x000000E2;
1331 param
->reg_MRS
= 0x00000C02 | trap_MRS
;
1332 param
->reg_EMRS
= 0x00000040;
1333 param
->reg_DRV
= 0x000000FA;
1334 param
->reg_IOZ
= 0x00000034;
1335 param
->reg_DQIDLY
= 0x00000089;
1336 param
->reg_FREQ
= 0x000050C0;
1337 param
->madj_max
= 96;
1338 param
->dll2_finetune_step
= 4;
1340 switch (param
->dram_chipid
) {
1341 case AST_DRAM_512Mx16
:
1342 param
->reg_AC2
= 0xCC00B016 | trap_AC2
;
1345 case AST_DRAM_1Gx16
:
1346 param
->reg_AC2
= 0xCC00B01B | trap_AC2
;
1348 case AST_DRAM_2Gx16
:
1349 param
->reg_AC2
= 0xCC00B02B | trap_AC2
;
1351 case AST_DRAM_4Gx16
:
1352 param
->reg_AC2
= 0xCC00B03F | trap_AC2
;
1358 ast_moutdwm(ast
, 0x1E6E2020, 0x0230);
1360 param
->reg_AC1
= 0x33302815;
1361 param
->reg_AC2
= 0xCD44B01E;
1362 param
->reg_DQSIC
= 0x000000FC;
1363 param
->reg_MRS
= 0x00000E72;
1364 param
->reg_EMRS
= 0x00000000;
1365 param
->reg_DRV
= 0x00000000;
1366 param
->reg_IOZ
= 0x00000034;
1367 param
->reg_DQIDLY
= 0x00000097;
1368 param
->reg_FREQ
= 0x000052C0;
1369 param
->madj_max
= 88;
1370 param
->dll2_finetune_step
= 3;
1373 ast_moutdwm(ast
, 0x1E6E2020, 0x0261);
1376 param
->reg_AC1
= 0x33302815;
1377 param
->reg_AC2
= 0xDE44C022;
1378 param
->reg_DQSIC
= 0x00000117;
1379 param
->reg_MRS
= 0x00000E72;
1380 param
->reg_EMRS
= 0x00000040;
1381 param
->reg_DRV
= 0x0000000A;
1382 param
->reg_IOZ
= 0x00000045;
1383 param
->reg_DQIDLY
= 0x000000A0;
1384 param
->reg_FREQ
= 0x000054C0;
1385 param
->madj_max
= 79;
1386 param
->dll2_finetune_step
= 3;
1389 ast_moutdwm(ast
, 0x1E6E2020, 0x0120);
1392 param
->reg_AC1
= 0x33302815;
1393 param
->reg_AC2
= 0xEF44D024;
1394 param
->reg_DQSIC
= 0x00000125;
1395 param
->reg_MRS
= 0x00000E72;
1396 param
->reg_EMRS
= 0x00000004;
1397 param
->reg_DRV
= 0x000000F9;
1398 param
->reg_IOZ
= 0x00000045;
1399 param
->reg_DQIDLY
= 0x000000A7;
1400 param
->reg_FREQ
= 0x000055C0;
1401 param
->madj_max
= 76;
1402 param
->dll2_finetune_step
= 3;
1405 ast_moutdwm(ast
, 0x1E6E2020, 0x02A1);
1408 param
->reg_AC1
= 0x43402915;
1409 param
->reg_AC2
= 0xFF44E025;
1410 param
->reg_DQSIC
= 0x00000132;
1411 param
->reg_MRS
= 0x00000E72;
1412 param
->reg_EMRS
= 0x00000040;
1413 param
->reg_DRV
= 0x0000000A;
1414 param
->reg_IOZ
= 0x00000045;
1415 param
->reg_DQIDLY
= 0x000000AD;
1416 param
->reg_FREQ
= 0x000056C0;
1417 param
->madj_max
= 76;
1418 param
->dll2_finetune_step
= 3;
1421 ast_moutdwm(ast
, 0x1E6E2020, 0x0140);
1424 param
->reg_AC1
= 0x43402915;
1425 param
->reg_AC2
= 0xFF44E027;
1426 param
->reg_DQSIC
= 0x0000013F;
1427 param
->reg_MRS
= 0x00000E72;
1428 param
->reg_EMRS
= 0x00000004;
1429 param
->reg_DRV
= 0x000000F5;
1430 param
->reg_IOZ
= 0x00000045;
1431 param
->reg_DQIDLY
= 0x000000B3;
1432 param
->reg_FREQ
= 0x000057C0;
1433 param
->madj_max
= 76;
1434 param
->dll2_finetune_step
= 3;
1438 switch (param
->dram_chipid
) {
1439 case AST_DRAM_512Mx16
:
1440 param
->dram_config
= 0x100;
1443 case AST_DRAM_1Gx16
:
1444 param
->dram_config
= 0x121;
1446 case AST_DRAM_2Gx16
:
1447 param
->dram_config
= 0x122;
1449 case AST_DRAM_4Gx16
:
1450 param
->dram_config
= 0x123;
1454 switch (param
->vram_size
) {
1456 case AST_VIDMEM_SIZE_8M
:
1457 param
->dram_config
|= 0x00;
1459 case AST_VIDMEM_SIZE_16M
:
1460 param
->dram_config
|= 0x04;
1462 case AST_VIDMEM_SIZE_32M
:
1463 param
->dram_config
|= 0x08;
1465 case AST_VIDMEM_SIZE_64M
:
1466 param
->dram_config
|= 0x0c;
1471 static void ddr2_init(struct ast_private
*ast
, struct ast2300_dram_param
*param
)
1473 u32 data
, data2
, retry
= 0;
1476 ast_moutdwm(ast
, 0x1E6E0000, 0xFC600309);
1477 ast_moutdwm(ast
, 0x1E6E0018, 0x00000100);
1478 ast_moutdwm(ast
, 0x1E6E0024, 0x00000000);
1479 ast_moutdwm(ast
, 0x1E6E0064, param
->reg_MADJ
);
1480 ast_moutdwm(ast
, 0x1E6E0068, param
->reg_SADJ
);
1482 ast_moutdwm(ast
, 0x1E6E0064, param
->reg_MADJ
| 0xC0000);
1485 ast_moutdwm(ast
, 0x1E6E0004, param
->dram_config
);
1486 ast_moutdwm(ast
, 0x1E6E0008, 0x90040f);
1487 ast_moutdwm(ast
, 0x1E6E0010, param
->reg_AC1
);
1488 ast_moutdwm(ast
, 0x1E6E0014, param
->reg_AC2
);
1489 ast_moutdwm(ast
, 0x1E6E0020, param
->reg_DQSIC
);
1490 ast_moutdwm(ast
, 0x1E6E0080, 0x00000000);
1491 ast_moutdwm(ast
, 0x1E6E0084, 0x00000000);
1492 ast_moutdwm(ast
, 0x1E6E0088, param
->reg_DQIDLY
);
1493 ast_moutdwm(ast
, 0x1E6E0018, 0x4000A130);
1494 ast_moutdwm(ast
, 0x1E6E0018, 0x00002330);
1495 ast_moutdwm(ast
, 0x1E6E0038, 0x00000000);
1496 ast_moutdwm(ast
, 0x1E6E0040, 0xFF808000);
1497 ast_moutdwm(ast
, 0x1E6E0044, 0x88848466);
1498 ast_moutdwm(ast
, 0x1E6E0048, 0x44440008);
1499 ast_moutdwm(ast
, 0x1E6E004C, 0x00000000);
1500 ast_moutdwm(ast
, 0x1E6E0050, 0x80000000);
1501 ast_moutdwm(ast
, 0x1E6E0050, 0x00000000);
1502 ast_moutdwm(ast
, 0x1E6E0054, 0);
1503 ast_moutdwm(ast
, 0x1E6E0060, param
->reg_DRV
);
1504 ast_moutdwm(ast
, 0x1E6E006C, param
->reg_IOZ
);
1505 ast_moutdwm(ast
, 0x1E6E0070, 0x00000000);
1506 ast_moutdwm(ast
, 0x1E6E0074, 0x00000000);
1507 ast_moutdwm(ast
, 0x1E6E0078, 0x00000000);
1508 ast_moutdwm(ast
, 0x1E6E007C, 0x00000000);
1510 /* Wait MCLK2X lock to MCLK */
1512 data
= ast_mindwm(ast
, 0x1E6E001C);
1513 } while (!(data
& 0x08000000));
1514 data
= ast_mindwm(ast
, 0x1E6E001C);
1515 data
= (data
>> 8) & 0xff;
1516 while ((data
& 0x08) || ((data
& 0x7) < 2) || (data
< 4)) {
1517 data2
= (ast_mindwm(ast
, 0x1E6E0064) & 0xfff3ffff) + 4;
1518 if ((data2
& 0xff) > param
->madj_max
) {
1521 ast_moutdwm(ast
, 0x1E6E0064, data2
);
1522 if (data2
& 0x00100000) {
1523 data2
= ((data2
& 0xff) >> 3) + 3;
1525 data2
= ((data2
& 0xff) >> 2) + 5;
1527 data
= ast_mindwm(ast
, 0x1E6E0068) & 0xffff00ff;
1528 data2
+= data
& 0xff;
1529 data
= data
| (data2
<< 8);
1530 ast_moutdwm(ast
, 0x1E6E0068, data
);
1532 ast_moutdwm(ast
, 0x1E6E0064, ast_mindwm(ast
, 0x1E6E0064) | 0xC0000);
1534 data
= ast_mindwm(ast
, 0x1E6E0018) & 0xfffff1ff;
1535 ast_moutdwm(ast
, 0x1E6E0018, data
);
1536 data
= data
| 0x200;
1537 ast_moutdwm(ast
, 0x1E6E0018, data
);
1539 data
= ast_mindwm(ast
, 0x1E6E001C);
1540 } while (!(data
& 0x08000000));
1542 data
= ast_mindwm(ast
, 0x1E6E001C);
1543 data
= (data
>> 8) & 0xff;
1545 ast_moutdwm(ast
, 0x1E720058, ast_mindwm(ast
, 0x1E6E0008) & 0xffff);
1546 data
= ast_mindwm(ast
, 0x1E6E0018) | 0xC00;
1547 ast_moutdwm(ast
, 0x1E6E0018, data
);
1549 ast_moutdwm(ast
, 0x1E6E0034, 0x00000001);
1550 ast_moutdwm(ast
, 0x1E6E000C, 0x00000000);
1552 /* Mode Register Setting */
1553 ast_moutdwm(ast
, 0x1E6E002C, param
->reg_MRS
| 0x100);
1554 ast_moutdwm(ast
, 0x1E6E0030, param
->reg_EMRS
);
1555 ast_moutdwm(ast
, 0x1E6E0028, 0x00000005);
1556 ast_moutdwm(ast
, 0x1E6E0028, 0x00000007);
1557 ast_moutdwm(ast
, 0x1E6E0028, 0x00000003);
1558 ast_moutdwm(ast
, 0x1E6E0028, 0x00000001);
1560 ast_moutdwm(ast
, 0x1E6E000C, 0x00005C08);
1561 ast_moutdwm(ast
, 0x1E6E002C, param
->reg_MRS
);
1562 ast_moutdwm(ast
, 0x1E6E0028, 0x00000001);
1563 ast_moutdwm(ast
, 0x1E6E0030, param
->reg_EMRS
| 0x380);
1564 ast_moutdwm(ast
, 0x1E6E0028, 0x00000003);
1565 ast_moutdwm(ast
, 0x1E6E0030, param
->reg_EMRS
);
1566 ast_moutdwm(ast
, 0x1E6E0028, 0x00000003);
1568 ast_moutdwm(ast
, 0x1E6E000C, 0x7FFF5C01);
1574 data
= data
| 0x3000 | ((param
->reg_AC2
& 0x60000) >> 3);
1576 ast_moutdwm(ast
, 0x1E6E0034, data
| 0x3);
1577 ast_moutdwm(ast
, 0x1E6E0120, param
->reg_FREQ
);
1579 /* Calibrate the DQSI delay */
1580 if ((cbr_dll2(ast
, param
) == false) && (retry
++ < 10))
1581 goto ddr2_init_start
;
1583 /* ECC Memory Initialization */
1585 ast_moutdwm(ast
, 0x1E6E007C, 0x00000000);
1586 ast_moutdwm(ast
, 0x1E6E0070, 0x221);
1588 data
= ast_mindwm(ast
, 0x1E6E0070);
1589 } while (!(data
& 0x00001000));
1590 ast_moutdwm(ast
, 0x1E6E0070, 0x00000000);
1591 ast_moutdwm(ast
, 0x1E6E0050, 0x80000000);
1592 ast_moutdwm(ast
, 0x1E6E0050, 0x00000000);
1597 static void ast_post_chip_2300(struct drm_device
*dev
)
1599 struct ast_private
*ast
= to_ast_private(dev
);
1600 struct ast2300_dram_param param
;
1604 reg
= ast_get_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xd0, 0xff);
1605 if ((reg
& 0x80) == 0) {/* vga only */
1606 ast_write32(ast
, 0xf004, 0x1e6e0000);
1607 ast_write32(ast
, 0xf000, 0x1);
1608 ast_write32(ast
, 0x12000, 0x1688a8a8);
1611 } while (ast_read32(ast
, 0x12000) != 0x1);
1613 ast_write32(ast
, 0x10000, 0xfc600309);
1616 } while (ast_read32(ast
, 0x10000) != 0x1);
1618 /* Slow down CPU/AHB CLK in VGA only mode */
1619 temp
= ast_read32(ast
, 0x12008);
1621 ast_write32(ast
, 0x12008, temp
);
1623 param
.dram_freq
= 396;
1624 param
.dram_type
= AST_DDR3
;
1625 temp
= ast_mindwm(ast
, 0x1e6e2070);
1626 if (temp
& 0x01000000)
1627 param
.dram_type
= AST_DDR2
;
1628 switch (temp
& 0x18000000) {
1630 param
.dram_chipid
= AST_DRAM_512Mx16
;
1634 param
.dram_chipid
= AST_DRAM_1Gx16
;
1637 param
.dram_chipid
= AST_DRAM_2Gx16
;
1640 param
.dram_chipid
= AST_DRAM_4Gx16
;
1643 switch (temp
& 0x0c) {
1646 param
.vram_size
= AST_VIDMEM_SIZE_8M
;
1650 param
.vram_size
= AST_VIDMEM_SIZE_16M
;
1654 param
.vram_size
= AST_VIDMEM_SIZE_32M
;
1658 param
.vram_size
= AST_VIDMEM_SIZE_64M
;
1662 if (param
.dram_type
== AST_DDR3
) {
1663 get_ddr3_info(ast
, ¶m
);
1664 ddr3_init(ast
, ¶m
);
1666 get_ddr2_info(ast
, ¶m
);
1667 ddr2_init(ast
, ¶m
);
1670 temp
= ast_mindwm(ast
, 0x1e6e2040);
1671 ast_moutdwm(ast
, 0x1e6e2040, temp
| 0x40);
1676 reg
= ast_get_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xd0, 0xff);
1677 } while ((reg
& 0x40) == 0);
1680 static bool cbr_test_2500(struct ast_private
*ast
)
1682 ast_moutdwm(ast
, 0x1E6E0074, 0x0000FFFF);
1683 ast_moutdwm(ast
, 0x1E6E007C, 0xFF00FF00);
1684 if (!mmc_test_burst(ast
, 0))
1686 if (!mmc_test_single_2500(ast
, 0))
1691 static bool ddr_test_2500(struct ast_private
*ast
)
1693 ast_moutdwm(ast
, 0x1E6E0074, 0x0000FFFF);
1694 ast_moutdwm(ast
, 0x1E6E007C, 0xFF00FF00);
1695 if (!mmc_test_burst(ast
, 0))
1697 if (!mmc_test_burst(ast
, 1))
1699 if (!mmc_test_burst(ast
, 2))
1701 if (!mmc_test_burst(ast
, 3))
1703 if (!mmc_test_single_2500(ast
, 0))
1708 static void ddr_init_common_2500(struct ast_private
*ast
)
1710 ast_moutdwm(ast
, 0x1E6E0034, 0x00020080);
1711 ast_moutdwm(ast
, 0x1E6E0008, 0x2003000F);
1712 ast_moutdwm(ast
, 0x1E6E0038, 0x00000FFF);
1713 ast_moutdwm(ast
, 0x1E6E0040, 0x88448844);
1714 ast_moutdwm(ast
, 0x1E6E0044, 0x24422288);
1715 ast_moutdwm(ast
, 0x1E6E0048, 0x22222222);
1716 ast_moutdwm(ast
, 0x1E6E004C, 0x22222222);
1717 ast_moutdwm(ast
, 0x1E6E0050, 0x80000000);
1718 ast_moutdwm(ast
, 0x1E6E0208, 0x00000000);
1719 ast_moutdwm(ast
, 0x1E6E0218, 0x00000000);
1720 ast_moutdwm(ast
, 0x1E6E0220, 0x00000000);
1721 ast_moutdwm(ast
, 0x1E6E0228, 0x00000000);
1722 ast_moutdwm(ast
, 0x1E6E0230, 0x00000000);
1723 ast_moutdwm(ast
, 0x1E6E02A8, 0x00000000);
1724 ast_moutdwm(ast
, 0x1E6E02B0, 0x00000000);
1725 ast_moutdwm(ast
, 0x1E6E0240, 0x86000000);
1726 ast_moutdwm(ast
, 0x1E6E0244, 0x00008600);
1727 ast_moutdwm(ast
, 0x1E6E0248, 0x80000000);
1728 ast_moutdwm(ast
, 0x1E6E024C, 0x80808080);
1731 static void ddr_phy_init_2500(struct ast_private
*ast
)
1733 u32 data
, pass
, timecnt
;
1736 ast_moutdwm(ast
, 0x1E6E0060, 0x00000005);
1738 for (timecnt
= 0; timecnt
< TIMEOUT
; timecnt
++) {
1739 data
= ast_mindwm(ast
, 0x1E6E0060) & 0x1;
1743 if (timecnt
!= TIMEOUT
) {
1744 data
= ast_mindwm(ast
, 0x1E6E0300) & 0x000A0000;
1749 ast_moutdwm(ast
, 0x1E6E0060, 0x00000000);
1750 udelay(10); /* delay 10 us */
1751 ast_moutdwm(ast
, 0x1E6E0060, 0x00000005);
1755 ast_moutdwm(ast
, 0x1E6E0060, 0x00000006);
1760 * 1Gb : 0x80000000 ~ 0x87FFFFFF
1761 * 2Gb : 0x80000000 ~ 0x8FFFFFFF
1762 * 4Gb : 0x80000000 ~ 0x9FFFFFFF
1763 * 8Gb : 0x80000000 ~ 0xBFFFFFFF
1765 static void check_dram_size_2500(struct ast_private
*ast
, u32 tRFC
)
1769 reg_04
= ast_mindwm(ast
, 0x1E6E0004) & 0xfffffffc;
1770 reg_14
= ast_mindwm(ast
, 0x1E6E0014) & 0xffffff00;
1772 ast_moutdwm(ast
, 0xA0100000, 0x41424344);
1773 ast_moutdwm(ast
, 0x90100000, 0x35363738);
1774 ast_moutdwm(ast
, 0x88100000, 0x292A2B2C);
1775 ast_moutdwm(ast
, 0x80100000, 0x1D1E1F10);
1778 if (ast_mindwm(ast
, 0xA0100000) == 0x41424344) {
1780 reg_14
|= (tRFC
>> 24) & 0xFF;
1782 } else if (ast_mindwm(ast
, 0x90100000) == 0x35363738) {
1784 reg_14
|= (tRFC
>> 16) & 0xFF;
1786 } else if (ast_mindwm(ast
, 0x88100000) == 0x292A2B2C) {
1788 reg_14
|= (tRFC
>> 8) & 0xFF;
1790 reg_14
|= tRFC
& 0xFF;
1792 ast_moutdwm(ast
, 0x1E6E0004, reg_04
);
1793 ast_moutdwm(ast
, 0x1E6E0014, reg_14
);
1796 static void enable_cache_2500(struct ast_private
*ast
)
1800 reg_04
= ast_mindwm(ast
, 0x1E6E0004);
1801 ast_moutdwm(ast
, 0x1E6E0004, reg_04
| 0x1000);
1804 data
= ast_mindwm(ast
, 0x1E6E0004);
1805 while (!(data
& 0x80000));
1806 ast_moutdwm(ast
, 0x1E6E0004, reg_04
| 0x400);
1809 static void set_mpll_2500(struct ast_private
*ast
)
1811 u32 addr
, data
, param
;
1814 ast_moutdwm(ast
, 0x1E6E0000, 0xFC600309);
1815 ast_moutdwm(ast
, 0x1E6E0034, 0x00020080);
1816 for (addr
= 0x1e6e0004; addr
< 0x1e6e0090;) {
1817 ast_moutdwm(ast
, addr
, 0x0);
1820 ast_moutdwm(ast
, 0x1E6E0034, 0x00020000);
1822 ast_moutdwm(ast
, 0x1E6E2000, 0x1688A8A8);
1823 data
= ast_mindwm(ast
, 0x1E6E2070) & 0x00800000;
1827 ast_moutdwm(ast
, 0x1E6E2160, 0x00011320);
1832 ast_moutdwm(ast
, 0x1E6E2020, param
);
1836 static void reset_mmc_2500(struct ast_private
*ast
)
1838 ast_moutdwm(ast
, 0x1E78505C, 0x00000004);
1839 ast_moutdwm(ast
, 0x1E785044, 0x00000001);
1840 ast_moutdwm(ast
, 0x1E785048, 0x00004755);
1841 ast_moutdwm(ast
, 0x1E78504C, 0x00000013);
1843 ast_moutdwm(ast
, 0x1E785054, 0x00000077);
1844 ast_moutdwm(ast
, 0x1E6E0000, 0xFC600309);
1847 static void ddr3_init_2500(struct ast_private
*ast
, const u32
*ddr_table
)
1850 ast_moutdwm(ast
, 0x1E6E0004, 0x00000303);
1851 ast_moutdwm(ast
, 0x1E6E0010, ddr_table
[REGIDX_010
]);
1852 ast_moutdwm(ast
, 0x1E6E0014, ddr_table
[REGIDX_014
]);
1853 ast_moutdwm(ast
, 0x1E6E0018, ddr_table
[REGIDX_018
]);
1854 ast_moutdwm(ast
, 0x1E6E0020, ddr_table
[REGIDX_020
]); /* MODEREG4/6 */
1855 ast_moutdwm(ast
, 0x1E6E0024, ddr_table
[REGIDX_024
]); /* MODEREG5 */
1856 ast_moutdwm(ast
, 0x1E6E002C, ddr_table
[REGIDX_02C
] | 0x100); /* MODEREG0/2 */
1857 ast_moutdwm(ast
, 0x1E6E0030, ddr_table
[REGIDX_030
]); /* MODEREG1/3 */
1859 /* DDR PHY Setting */
1860 ast_moutdwm(ast
, 0x1E6E0200, 0x02492AAE);
1861 ast_moutdwm(ast
, 0x1E6E0204, 0x00001001);
1862 ast_moutdwm(ast
, 0x1E6E020C, 0x55E00B0B);
1863 ast_moutdwm(ast
, 0x1E6E0210, 0x20000000);
1864 ast_moutdwm(ast
, 0x1E6E0214, ddr_table
[REGIDX_214
]);
1865 ast_moutdwm(ast
, 0x1E6E02E0, ddr_table
[REGIDX_2E0
]);
1866 ast_moutdwm(ast
, 0x1E6E02E4, ddr_table
[REGIDX_2E4
]);
1867 ast_moutdwm(ast
, 0x1E6E02E8, ddr_table
[REGIDX_2E8
]);
1868 ast_moutdwm(ast
, 0x1E6E02EC, ddr_table
[REGIDX_2EC
]);
1869 ast_moutdwm(ast
, 0x1E6E02F0, ddr_table
[REGIDX_2F0
]);
1870 ast_moutdwm(ast
, 0x1E6E02F4, ddr_table
[REGIDX_2F4
]);
1871 ast_moutdwm(ast
, 0x1E6E02F8, ddr_table
[REGIDX_2F8
]);
1872 ast_moutdwm(ast
, 0x1E6E0290, 0x00100008);
1873 ast_moutdwm(ast
, 0x1E6E02C0, 0x00000006);
1875 /* Controller Setting */
1876 ast_moutdwm(ast
, 0x1E6E0034, 0x00020091);
1878 /* Wait DDR PHY init done */
1879 ddr_phy_init_2500(ast
);
1881 ast_moutdwm(ast
, 0x1E6E0120, ddr_table
[REGIDX_PLL
]);
1882 ast_moutdwm(ast
, 0x1E6E000C, 0x42AA5C81);
1883 ast_moutdwm(ast
, 0x1E6E0034, 0x0001AF93);
1885 check_dram_size_2500(ast
, ddr_table
[REGIDX_RFC
]);
1886 enable_cache_2500(ast
);
1887 ast_moutdwm(ast
, 0x1E6E001C, 0x00000008);
1888 ast_moutdwm(ast
, 0x1E6E0038, 0xFFFFFF00);
1891 static void ddr4_init_2500(struct ast_private
*ast
, const u32
*ddr_table
)
1893 u32 data
, data2
, pass
, retrycnt
;
1894 u32 ddr_vref
, phy_vref
;
1895 u32 min_ddr_vref
= 0, min_phy_vref
= 0;
1896 u32 max_ddr_vref
= 0, max_phy_vref
= 0;
1898 ast_moutdwm(ast
, 0x1E6E0004, 0x00000313);
1899 ast_moutdwm(ast
, 0x1E6E0010, ddr_table
[REGIDX_010
]);
1900 ast_moutdwm(ast
, 0x1E6E0014, ddr_table
[REGIDX_014
]);
1901 ast_moutdwm(ast
, 0x1E6E0018, ddr_table
[REGIDX_018
]);
1902 ast_moutdwm(ast
, 0x1E6E0020, ddr_table
[REGIDX_020
]); /* MODEREG4/6 */
1903 ast_moutdwm(ast
, 0x1E6E0024, ddr_table
[REGIDX_024
]); /* MODEREG5 */
1904 ast_moutdwm(ast
, 0x1E6E002C, ddr_table
[REGIDX_02C
] | 0x100); /* MODEREG0/2 */
1905 ast_moutdwm(ast
, 0x1E6E0030, ddr_table
[REGIDX_030
]); /* MODEREG1/3 */
1907 /* DDR PHY Setting */
1908 ast_moutdwm(ast
, 0x1E6E0200, 0x42492AAE);
1909 ast_moutdwm(ast
, 0x1E6E0204, 0x09002000);
1910 ast_moutdwm(ast
, 0x1E6E020C, 0x55E00B0B);
1911 ast_moutdwm(ast
, 0x1E6E0210, 0x20000000);
1912 ast_moutdwm(ast
, 0x1E6E0214, ddr_table
[REGIDX_214
]);
1913 ast_moutdwm(ast
, 0x1E6E02E0, ddr_table
[REGIDX_2E0
]);
1914 ast_moutdwm(ast
, 0x1E6E02E4, ddr_table
[REGIDX_2E4
]);
1915 ast_moutdwm(ast
, 0x1E6E02E8, ddr_table
[REGIDX_2E8
]);
1916 ast_moutdwm(ast
, 0x1E6E02EC, ddr_table
[REGIDX_2EC
]);
1917 ast_moutdwm(ast
, 0x1E6E02F0, ddr_table
[REGIDX_2F0
]);
1918 ast_moutdwm(ast
, 0x1E6E02F4, ddr_table
[REGIDX_2F4
]);
1919 ast_moutdwm(ast
, 0x1E6E02F8, ddr_table
[REGIDX_2F8
]);
1920 ast_moutdwm(ast
, 0x1E6E0290, 0x00100008);
1921 ast_moutdwm(ast
, 0x1E6E02C4, 0x3C183C3C);
1922 ast_moutdwm(ast
, 0x1E6E02C8, 0x00631E0E);
1924 /* Controller Setting */
1925 ast_moutdwm(ast
, 0x1E6E0034, 0x0001A991);
1927 /* Train PHY Vref first */
1930 for (retrycnt
= 0; retrycnt
< 4 && pass
== 0; retrycnt
++) {
1933 ast_moutdwm(ast
, 0x1E6E02C0, 0x00001C06);
1934 for (phy_vref
= 0x40; phy_vref
< 0x80; phy_vref
++) {
1935 ast_moutdwm(ast
, 0x1E6E000C, 0x00000000);
1936 ast_moutdwm(ast
, 0x1E6E0060, 0x00000000);
1937 ast_moutdwm(ast
, 0x1E6E02CC, phy_vref
| (phy_vref
<< 8));
1939 ddr_phy_init_2500(ast
);
1940 ast_moutdwm(ast
, 0x1E6E000C, 0x00005C01);
1941 if (cbr_test_2500(ast
)) {
1943 data
= ast_mindwm(ast
, 0x1E6E03D0);
1948 if (max_phy_vref
< data
) {
1949 max_phy_vref
= data
;
1950 min_phy_vref
= phy_vref
;
1952 } else if (pass
> 0)
1956 ast_moutdwm(ast
, 0x1E6E02CC, min_phy_vref
| (min_phy_vref
<< 8));
1958 /* Train DDR Vref next */
1961 for (retrycnt
= 0; retrycnt
< 4 && pass
== 0; retrycnt
++) {
1962 min_ddr_vref
= 0xFF;
1965 for (ddr_vref
= 0x00; ddr_vref
< 0x40; ddr_vref
++) {
1966 ast_moutdwm(ast
, 0x1E6E000C, 0x00000000);
1967 ast_moutdwm(ast
, 0x1E6E0060, 0x00000000);
1968 ast_moutdwm(ast
, 0x1E6E02C0, 0x00000006 | (ddr_vref
<< 8));
1970 ddr_phy_init_2500(ast
);
1971 ast_moutdwm(ast
, 0x1E6E000C, 0x00005C01);
1972 if (cbr_test_2500(ast
)) {
1974 if (min_ddr_vref
> ddr_vref
)
1975 min_ddr_vref
= ddr_vref
;
1976 if (max_ddr_vref
< ddr_vref
)
1977 max_ddr_vref
= ddr_vref
;
1978 } else if (pass
!= 0)
1983 ast_moutdwm(ast
, 0x1E6E000C, 0x00000000);
1984 ast_moutdwm(ast
, 0x1E6E0060, 0x00000000);
1985 ddr_vref
= (min_ddr_vref
+ max_ddr_vref
+ 1) >> 1;
1986 ast_moutdwm(ast
, 0x1E6E02C0, 0x00000006 | (ddr_vref
<< 8));
1988 /* Wait DDR PHY init done */
1989 ddr_phy_init_2500(ast
);
1991 ast_moutdwm(ast
, 0x1E6E0120, ddr_table
[REGIDX_PLL
]);
1992 ast_moutdwm(ast
, 0x1E6E000C, 0x42AA5C81);
1993 ast_moutdwm(ast
, 0x1E6E0034, 0x0001AF93);
1995 check_dram_size_2500(ast
, ddr_table
[REGIDX_RFC
]);
1996 enable_cache_2500(ast
);
1997 ast_moutdwm(ast
, 0x1E6E001C, 0x00000008);
1998 ast_moutdwm(ast
, 0x1E6E0038, 0xFFFFFF00);
2001 static bool ast_dram_init_2500(struct ast_private
*ast
)
2007 if (max_tries
-- == 0)
2010 reset_mmc_2500(ast
);
2011 ddr_init_common_2500(ast
);
2013 data
= ast_mindwm(ast
, 0x1E6E2070);
2014 if (data
& 0x01000000)
2015 ddr4_init_2500(ast
, ast2500_ddr4_1600_timing_table
);
2017 ddr3_init_2500(ast
, ast2500_ddr3_1600_timing_table
);
2018 } while (!ddr_test_2500(ast
));
2020 ast_moutdwm(ast
, 0x1E6E2040, ast_mindwm(ast
, 0x1E6E2040) | 0x41);
2023 data
= ast_mindwm(ast
, 0x1E6E200C) & 0xF9FFFFFF;
2024 ast_moutdwm(ast
, 0x1E6E200C, data
| 0x10000000);
2029 void ast_post_chip_2500(struct drm_device
*dev
)
2031 struct ast_private
*ast
= to_ast_private(dev
);
2035 reg
= ast_get_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xd0, 0xff);
2036 if ((reg
& 0x80) == 0) {/* vga only */
2037 /* Clear bus lock condition */
2038 ast_moutdwm(ast
, 0x1e600000, 0xAEED1A03);
2039 ast_moutdwm(ast
, 0x1e600084, 0x00010000);
2040 ast_moutdwm(ast
, 0x1e600088, 0x00000000);
2041 ast_moutdwm(ast
, 0x1e6e2000, 0x1688A8A8);
2042 ast_write32(ast
, 0xf004, 0x1e6e0000);
2043 ast_write32(ast
, 0xf000, 0x1);
2044 ast_write32(ast
, 0x12000, 0x1688a8a8);
2045 while (ast_read32(ast
, 0x12000) != 0x1)
2048 ast_write32(ast
, 0x10000, 0xfc600309);
2049 while (ast_read32(ast
, 0x10000) != 0x1)
2052 /* Slow down CPU/AHB CLK in VGA only mode */
2053 temp
= ast_read32(ast
, 0x12008);
2055 ast_write32(ast
, 0x12008, temp
);
2057 /* Reset USB port to patch USB unknown device issue */
2058 ast_moutdwm(ast
, 0x1e6e2090, 0x20000000);
2059 temp
= ast_mindwm(ast
, 0x1e6e2094);
2061 ast_moutdwm(ast
, 0x1e6e2094, temp
);
2062 temp
= ast_mindwm(ast
, 0x1e6e2070);
2063 if (temp
& 0x00800000) {
2064 ast_moutdwm(ast
, 0x1e6e207c, 0x00800000);
2066 ast_moutdwm(ast
, 0x1e6e2070, 0x00800000);
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_CRTC_PORT
, 0xd0, 0xff);
2079 } while ((reg
& 0x40) == 0);