blob: 667fabfee91de80299d4db97e800cbb730428ba4 [file] [log] [blame]
Dave Airlie312fec12012-02-29 13:40:04 +00001/*
2 * Copyright 2012 Red Hat Inc.
3 *
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:
11 *
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.
19 *
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
22 * of the Software.
23 *
24 */
25/*
26 * Authors: Dave Airlie <airlied@redhat.com>
27 */
28
David Howells760285e2012-10-02 18:01:07 +010029#include <drm/drmP.h>
Dave Airlie312fec12012-02-29 13:40:04 +000030#include "ast_drv.h"
31
32#include "ast_dram_tables.h"
33
34static void ast_init_dram_2300(struct drm_device *dev);
35
36static void
37ast_enable_vga(struct drm_device *dev)
38{
39 struct ast_private *ast = dev->dev_private;
40
41 ast_io_write8(ast, 0x43, 0x01);
42 ast_io_write8(ast, 0x42, 0x01);
43}
44
45#if 0 /* will use later */
46static bool
47ast_is_vga_enabled(struct drm_device *dev)
48{
49 struct ast_private *ast = dev->dev_private;
50 u8 ch;
51
52 if (ast->chip == AST1180) {
53 /* TODO 1180 */
54 } else {
55 ch = ast_io_read8(ast, 0x43);
56 if (ch) {
57 ast_open_key(ast);
58 ch = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb6, 0xff);
59 return ch & 0x04;
60 }
61 }
62 return 0;
63}
64#endif
65
66static const u8 extreginfo[] = { 0x0f, 0x04, 0x1c, 0xff };
67static const u8 extreginfo_ast2300a0[] = { 0x0f, 0x04, 0x1c, 0xff };
68static const u8 extreginfo_ast2300[] = { 0x0f, 0x04, 0x1f, 0xff };
69
70static void
71ast_set_def_ext_reg(struct drm_device *dev)
72{
73 struct ast_private *ast = dev->dev_private;
74 u8 i, index, reg;
75 const u8 *ext_reg_info;
76
77 /* reset scratch */
78 for (i = 0x81; i <= 0x8f; i++)
79 ast_set_index_reg(ast, AST_IO_CRTC_PORT, i, 0x00);
80
Dave Airlie1453bf42014-03-28 09:18:45 +100081 if (ast->chip == AST2300 || ast->chip == AST2400) {
Dave Airlie312fec12012-02-29 13:40:04 +000082 if (dev->pdev->revision >= 0x20)
83 ext_reg_info = extreginfo_ast2300;
84 else
85 ext_reg_info = extreginfo_ast2300a0;
86 } else
87 ext_reg_info = extreginfo;
88
89 index = 0xa0;
90 while (*ext_reg_info != 0xff) {
91 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, index, 0x00, *ext_reg_info);
92 index++;
93 ext_reg_info++;
94 }
95
96 /* disable standard IO/MEM decode if secondary */
97 /* ast_set_index_reg-mask(ast, AST_IO_CRTC_PORT, 0xa1, 0xff, 0x3); */
98
99 /* Set Ext. Default */
100 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x8c, 0x00, 0x01);
101 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x00, 0x00);
102
103 /* Enable RAMDAC for A1 */
104 reg = 0x04;
Dave Airlie1453bf42014-03-28 09:18:45 +1000105 if (ast->chip == AST2300 || ast->chip == AST2400)
Dave Airlie312fec12012-02-29 13:40:04 +0000106 reg |= 0x20;
107 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb6, 0xff, reg);
108}
109
110static inline u32 mindwm(struct ast_private *ast, u32 r)
111{
Dave Airlie318cfa22014-01-17 11:36:14 +1000112 uint32_t data;
113
Dave Airlie312fec12012-02-29 13:40:04 +0000114 ast_write32(ast, 0xf004, r & 0xffff0000);
115 ast_write32(ast, 0xf000, 0x1);
116
Dave Airlie318cfa22014-01-17 11:36:14 +1000117 do {
118 data = ast_read32(ast, 0xf004) & 0xffff0000;
119 } while (data != (r & 0xffff0000));
Dave Airlie312fec12012-02-29 13:40:04 +0000120 return ast_read32(ast, 0x10000 + (r & 0x0000ffff));
121}
122
123static inline void moutdwm(struct ast_private *ast, u32 r, u32 v)
124{
Dave Airlie318cfa22014-01-17 11:36:14 +1000125 uint32_t data;
Dave Airlie312fec12012-02-29 13:40:04 +0000126 ast_write32(ast, 0xf004, r & 0xffff0000);
127 ast_write32(ast, 0xf000, 0x1);
Dave Airlie318cfa22014-01-17 11:36:14 +1000128 do {
129 data = ast_read32(ast, 0xf004) & 0xffff0000;
130 } while (data != (r & 0xffff0000));
Dave Airlie312fec12012-02-29 13:40:04 +0000131 ast_write32(ast, 0x10000 + (r & 0x0000ffff), v);
132}
133
134/*
135 * AST2100/2150 DLL CBR Setting
136 */
137#define CBR_SIZE_AST2150 ((16 << 10) - 1)
138#define CBR_PASSNUM_AST2150 5
139#define CBR_THRESHOLD_AST2150 10
140#define CBR_THRESHOLD2_AST2150 10
141#define TIMEOUT_AST2150 5000000
142
143#define CBR_PATNUM_AST2150 8
144
145static const u32 pattern_AST2150[14] = {
146 0xFF00FF00,
147 0xCC33CC33,
148 0xAA55AA55,
149 0xFFFE0001,
150 0x683501FE,
151 0x0F1929B0,
152 0x2D0B4346,
153 0x60767F02,
154 0x6FBE36A6,
155 0x3A253035,
156 0x3019686D,
157 0x41C6167E,
158 0x620152BF,
159 0x20F050E0
160};
161
162static u32 mmctestburst2_ast2150(struct ast_private *ast, u32 datagen)
163{
164 u32 data, timeout;
165
166 moutdwm(ast, 0x1e6e0070, 0x00000000);
167 moutdwm(ast, 0x1e6e0070, 0x00000001 | (datagen << 3));
168 timeout = 0;
169 do {
170 data = mindwm(ast, 0x1e6e0070) & 0x40;
171 if (++timeout > TIMEOUT_AST2150) {
172 moutdwm(ast, 0x1e6e0070, 0x00000000);
173 return 0xffffffff;
174 }
175 } while (!data);
176 moutdwm(ast, 0x1e6e0070, 0x00000000);
177 moutdwm(ast, 0x1e6e0070, 0x00000003 | (datagen << 3));
178 timeout = 0;
179 do {
180 data = mindwm(ast, 0x1e6e0070) & 0x40;
181 if (++timeout > TIMEOUT_AST2150) {
182 moutdwm(ast, 0x1e6e0070, 0x00000000);
183 return 0xffffffff;
184 }
185 } while (!data);
186 data = (mindwm(ast, 0x1e6e0070) & 0x80) >> 7;
187 moutdwm(ast, 0x1e6e0070, 0x00000000);
188 return data;
189}
190
191#if 0 /* unused in DDX driver - here for completeness */
192static u32 mmctestsingle2_ast2150(struct ast_private *ast, u32 datagen)
193{
194 u32 data, timeout;
195
196 moutdwm(ast, 0x1e6e0070, 0x00000000);
197 moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3));
198 timeout = 0;
199 do {
200 data = mindwm(ast, 0x1e6e0070) & 0x40;
201 if (++timeout > TIMEOUT_AST2150) {
202 moutdwm(ast, 0x1e6e0070, 0x00000000);
203 return 0xffffffff;
204 }
205 } while (!data);
206 data = (mindwm(ast, 0x1e6e0070) & 0x80) >> 7;
207 moutdwm(ast, 0x1e6e0070, 0x00000000);
208 return data;
209}
210#endif
211
212static int cbrtest_ast2150(struct ast_private *ast)
213{
214 int i;
215
216 for (i = 0; i < 8; i++)
217 if (mmctestburst2_ast2150(ast, i))
218 return 0;
219 return 1;
220}
221
222static int cbrscan_ast2150(struct ast_private *ast, int busw)
223{
224 u32 patcnt, loop;
225
226 for (patcnt = 0; patcnt < CBR_PATNUM_AST2150; patcnt++) {
227 moutdwm(ast, 0x1e6e007c, pattern_AST2150[patcnt]);
228 for (loop = 0; loop < CBR_PASSNUM_AST2150; loop++) {
229 if (cbrtest_ast2150(ast))
230 break;
231 }
232 if (loop == CBR_PASSNUM_AST2150)
233 return 0;
234 }
235 return 1;
236}
237
238
239static void cbrdlli_ast2150(struct ast_private *ast, int busw)
240{
241 u32 dll_min[4], dll_max[4], dlli, data, passcnt;
242
243cbr_start:
244 dll_min[0] = dll_min[1] = dll_min[2] = dll_min[3] = 0xff;
245 dll_max[0] = dll_max[1] = dll_max[2] = dll_max[3] = 0x0;
246 passcnt = 0;
247
248 for (dlli = 0; dlli < 100; dlli++) {
249 moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24));
250 data = cbrscan_ast2150(ast, busw);
251 if (data != 0) {
252 if (data & 0x1) {
253 if (dll_min[0] > dlli)
254 dll_min[0] = dlli;
255 if (dll_max[0] < dlli)
256 dll_max[0] = dlli;
257 }
258 passcnt++;
259 } else if (passcnt >= CBR_THRESHOLD_AST2150)
260 goto cbr_start;
261 }
262 if (dll_max[0] == 0 || (dll_max[0]-dll_min[0]) < CBR_THRESHOLD_AST2150)
263 goto cbr_start;
264
265 dlli = dll_min[0] + (((dll_max[0] - dll_min[0]) * 7) >> 4);
266 moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24));
267}
268
269
270
271static void ast_init_dram_reg(struct drm_device *dev)
272{
273 struct ast_private *ast = dev->dev_private;
274 u8 j;
275 u32 data, temp, i;
276 const struct ast_dramstruct *dram_reg_info;
277
278 j = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
279
280 if ((j & 0x80) == 0) { /* VGA only */
281 if (ast->chip == AST2000) {
282 dram_reg_info = ast2000_dram_table_data;
283 ast_write32(ast, 0xf004, 0x1e6e0000);
284 ast_write32(ast, 0xf000, 0x1);
285 ast_write32(ast, 0x10100, 0xa8);
286
287 do {
288 ;
289 } while (ast_read32(ast, 0x10100) != 0xa8);
290 } else {/* AST2100/1100 */
291 if (ast->chip == AST2100 || ast->chip == 2200)
292 dram_reg_info = ast2100_dram_table_data;
293 else
294 dram_reg_info = ast1100_dram_table_data;
295
296 ast_write32(ast, 0xf004, 0x1e6e0000);
297 ast_write32(ast, 0xf000, 0x1);
298 ast_write32(ast, 0x12000, 0x1688A8A8);
299 do {
300 ;
301 } while (ast_read32(ast, 0x12000) != 0x01);
302
303 ast_write32(ast, 0x10000, 0xfc600309);
304 do {
305 ;
306 } while (ast_read32(ast, 0x10000) != 0x01);
307 }
308
309 while (dram_reg_info->index != 0xffff) {
310 if (dram_reg_info->index == 0xff00) {/* delay fn */
311 for (i = 0; i < 15; i++)
312 udelay(dram_reg_info->data);
313 } else if (dram_reg_info->index == 0x4 && ast->chip != AST2000) {
314 data = dram_reg_info->data;
315 if (ast->dram_type == AST_DRAM_1Gx16)
316 data = 0x00000d89;
317 else if (ast->dram_type == AST_DRAM_1Gx32)
318 data = 0x00000c8d;
319
320 temp = ast_read32(ast, 0x12070);
321 temp &= 0xc;
322 temp <<= 2;
323 ast_write32(ast, 0x10000 + dram_reg_info->index, data | temp);
324 } else
325 ast_write32(ast, 0x10000 + dram_reg_info->index, dram_reg_info->data);
326 dram_reg_info++;
327 }
328
329 /* AST 2100/2150 DRAM calibration */
330 data = ast_read32(ast, 0x10120);
331 if (data == 0x5061) { /* 266Mhz */
332 data = ast_read32(ast, 0x10004);
333 if (data & 0x40)
334 cbrdlli_ast2150(ast, 16); /* 16 bits */
335 else
336 cbrdlli_ast2150(ast, 32); /* 32 bits */
337 }
338
339 switch (ast->chip) {
340 case AST2000:
341 temp = ast_read32(ast, 0x10140);
342 ast_write32(ast, 0x10140, temp | 0x40);
343 break;
344 case AST1100:
345 case AST2100:
346 case AST2200:
347 case AST2150:
348 temp = ast_read32(ast, 0x1200c);
349 ast_write32(ast, 0x1200c, temp & 0xfffffffd);
350 temp = ast_read32(ast, 0x12040);
351 ast_write32(ast, 0x12040, temp | 0x40);
352 break;
353 default:
354 break;
355 }
356 }
357
358 /* wait ready */
359 do {
360 j = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
361 } while ((j & 0x40) == 0);
362}
363
364void ast_post_gpu(struct drm_device *dev)
365{
366 u32 reg;
367 struct ast_private *ast = dev->dev_private;
368
369 pci_read_config_dword(ast->dev->pdev, 0x04, &reg);
370 reg |= 0x3;
371 pci_write_config_dword(ast->dev->pdev, 0x04, reg);
372
373 ast_enable_vga(dev);
374 ast_open_key(ast);
375 ast_set_def_ext_reg(dev);
376
Dave Airlie1453bf42014-03-28 09:18:45 +1000377 if (ast->chip == AST2300 || ast->chip == AST2400)
Dave Airlie312fec12012-02-29 13:40:04 +0000378 ast_init_dram_2300(dev);
379 else
380 ast_init_dram_reg(dev);
381}
382
383/* AST 2300 DRAM settings */
384#define AST_DDR3 0
385#define AST_DDR2 1
386
387struct ast2300_dram_param {
388 u32 dram_type;
389 u32 dram_chipid;
390 u32 dram_freq;
391 u32 vram_size;
392 u32 odt;
393 u32 wodt;
394 u32 rodt;
395 u32 dram_config;
396 u32 reg_PERIOD;
397 u32 reg_MADJ;
398 u32 reg_SADJ;
399 u32 reg_MRS;
400 u32 reg_EMRS;
401 u32 reg_AC1;
402 u32 reg_AC2;
403 u32 reg_DQSIC;
404 u32 reg_DRV;
405 u32 reg_IOZ;
406 u32 reg_DQIDLY;
407 u32 reg_FREQ;
408 u32 madj_max;
409 u32 dll2_finetune_step;
410};
411
412/*
413 * DQSI DLL CBR Setting
414 */
Dave Airlie318cfa22014-01-17 11:36:14 +1000415#define CBR_SIZE0 ((1 << 10) - 1)
Dave Airlie312fec12012-02-29 13:40:04 +0000416#define CBR_SIZE1 ((4 << 10) - 1)
417#define CBR_SIZE2 ((64 << 10) - 1)
418#define CBR_PASSNUM 5
419#define CBR_PASSNUM2 5
420#define CBR_THRESHOLD 10
421#define CBR_THRESHOLD2 10
422#define TIMEOUT 5000000
423#define CBR_PATNUM 8
424
425static const u32 pattern[8] = {
426 0xFF00FF00,
427 0xCC33CC33,
428 0xAA55AA55,
429 0x88778877,
430 0x92CC4D6E,
431 0x543D3CDE,
432 0xF1E843C7,
433 0x7C61D253
434};
435
Dave Airlie312fec12012-02-29 13:40:04 +0000436static int mmc_test_burst(struct ast_private *ast, u32 datagen)
437{
438 u32 data, timeout;
439
440 moutdwm(ast, 0x1e6e0070, 0x00000000);
441 moutdwm(ast, 0x1e6e0070, 0x000000c1 | (datagen << 3));
442 timeout = 0;
443 do {
444 data = mindwm(ast, 0x1e6e0070) & 0x3000;
445 if (data & 0x2000) {
446 return 0;
447 }
448 if (++timeout > TIMEOUT) {
449 moutdwm(ast, 0x1e6e0070, 0x00000000);
450 return 0;
451 }
452 } while (!data);
453 moutdwm(ast, 0x1e6e0070, 0x00000000);
454 return 1;
455}
Dave Airlie312fec12012-02-29 13:40:04 +0000456
457static int mmc_test_burst2(struct ast_private *ast, u32 datagen)
458{
459 u32 data, timeout;
460
461 moutdwm(ast, 0x1e6e0070, 0x00000000);
462 moutdwm(ast, 0x1e6e0070, 0x00000041 | (datagen << 3));
463 timeout = 0;
464 do {
465 data = mindwm(ast, 0x1e6e0070) & 0x1000;
466 if (++timeout > TIMEOUT) {
467 moutdwm(ast, 0x1e6e0070, 0x0);
468 return -1;
469 }
470 } while (!data);
471 data = mindwm(ast, 0x1e6e0078);
472 data = (data | (data >> 16)) & 0xffff;
473 moutdwm(ast, 0x1e6e0070, 0x0);
474 return data;
475}
476
Dave Airlie312fec12012-02-29 13:40:04 +0000477static int mmc_test_single(struct ast_private *ast, u32 datagen)
478{
479 u32 data, timeout;
480
481 moutdwm(ast, 0x1e6e0070, 0x00000000);
482 moutdwm(ast, 0x1e6e0070, 0x000000c5 | (datagen << 3));
483 timeout = 0;
484 do {
485 data = mindwm(ast, 0x1e6e0070) & 0x3000;
486 if (data & 0x2000)
487 return 0;
488 if (++timeout > TIMEOUT) {
489 moutdwm(ast, 0x1e6e0070, 0x0);
490 return 0;
491 }
492 } while (!data);
493 moutdwm(ast, 0x1e6e0070, 0x0);
494 return 1;
495}
Dave Airlie312fec12012-02-29 13:40:04 +0000496
497static int mmc_test_single2(struct ast_private *ast, u32 datagen)
498{
499 u32 data, timeout;
500
501 moutdwm(ast, 0x1e6e0070, 0x00000000);
502 moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3));
503 timeout = 0;
504 do {
505 data = mindwm(ast, 0x1e6e0070) & 0x1000;
506 if (++timeout > TIMEOUT) {
507 moutdwm(ast, 0x1e6e0070, 0x0);
508 return -1;
509 }
510 } while (!data);
511 data = mindwm(ast, 0x1e6e0078);
512 data = (data | (data >> 16)) & 0xffff;
513 moutdwm(ast, 0x1e6e0070, 0x0);
514 return data;
515}
516
517static int cbr_test(struct ast_private *ast)
518{
519 u32 data;
520 int i;
521 data = mmc_test_single2(ast, 0);
522 if ((data & 0xff) && (data & 0xff00))
523 return 0;
524 for (i = 0; i < 8; i++) {
525 data = mmc_test_burst2(ast, i);
526 if ((data & 0xff) && (data & 0xff00))
527 return 0;
528 }
529 if (!data)
530 return 3;
531 else if (data & 0xff)
532 return 2;
533 return 1;
534}
535
536static int cbr_scan(struct ast_private *ast)
537{
538 u32 data, data2, patcnt, loop;
539
540 data2 = 3;
541 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
542 moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
543 for (loop = 0; loop < CBR_PASSNUM2; loop++) {
544 if ((data = cbr_test(ast)) != 0) {
545 data2 &= data;
546 if (!data2)
547 return 0;
548 break;
549 }
550 }
551 if (loop == CBR_PASSNUM2)
552 return 0;
553 }
554 return data2;
555}
556
557static u32 cbr_test2(struct ast_private *ast)
558{
559 u32 data;
560
561 data = mmc_test_burst2(ast, 0);
562 if (data == 0xffff)
563 return 0;
564 data |= mmc_test_single2(ast, 0);
565 if (data == 0xffff)
566 return 0;
567
568 return ~data & 0xffff;
569}
570
571static u32 cbr_scan2(struct ast_private *ast)
572{
573 u32 data, data2, patcnt, loop;
574
575 data2 = 0xffff;
576 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
577 moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
578 for (loop = 0; loop < CBR_PASSNUM2; loop++) {
579 if ((data = cbr_test2(ast)) != 0) {
580 data2 &= data;
581 if (!data)
582 return 0;
583 break;
584 }
585 }
586 if (loop == CBR_PASSNUM2)
587 return 0;
588 }
589 return data2;
590}
591
Dave Airlie318cfa22014-01-17 11:36:14 +1000592static u32 cbr_test3(struct ast_private *ast)
Dave Airlie312fec12012-02-29 13:40:04 +0000593{
Dave Airlie318cfa22014-01-17 11:36:14 +1000594 if (!mmc_test_burst(ast, 0))
595 return 0;
596 if (!mmc_test_single(ast, 0))
597 return 0;
598 return 1;
599}
Dave Airlie312fec12012-02-29 13:40:04 +0000600
Dave Airlie318cfa22014-01-17 11:36:14 +1000601static u32 cbr_scan3(struct ast_private *ast)
Dave Airlie312fec12012-02-29 13:40:04 +0000602{
Dave Airlie318cfa22014-01-17 11:36:14 +1000603 u32 patcnt, loop;
Dave Airlie312fec12012-02-29 13:40:04 +0000604
Dave Airlie318cfa22014-01-17 11:36:14 +1000605 for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
606 moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
607 for (loop = 0; loop < 2; loop++) {
608 if (cbr_test3(ast))
609 break;
610 }
611 if (loop == 2)
612 return 0;
613 }
614 return 1;
615}
616
617static bool finetuneDQI_L(struct ast_private *ast, struct ast2300_dram_param *param)
618{
619 u32 gold_sadj[2], dllmin[16], dllmax[16], dlli, data, cnt, mask, passcnt, retry = 0;
620 bool status = false;
Dave Airlie312fec12012-02-29 13:40:04 +0000621FINETUNE_START:
622 for (cnt = 0; cnt < 16; cnt++) {
623 dllmin[cnt] = 0xff;
624 dllmax[cnt] = 0x0;
625 }
626 passcnt = 0;
627 for (dlli = 0; dlli < 76; dlli++) {
628 moutdwm(ast, 0x1E6E0068, 0x00001400 | (dlli << 16) | (dlli << 24));
Dave Airlie312fec12012-02-29 13:40:04 +0000629 moutdwm(ast, 0x1E6E0074, CBR_SIZE1);
630 data = cbr_scan2(ast);
631 if (data != 0) {
632 mask = 0x00010001;
633 for (cnt = 0; cnt < 16; cnt++) {
634 if (data & mask) {
635 if (dllmin[cnt] > dlli) {
636 dllmin[cnt] = dlli;
637 }
638 if (dllmax[cnt] < dlli) {
639 dllmax[cnt] = dlli;
640 }
641 }
642 mask <<= 1;
643 }
644 passcnt++;
645 } else if (passcnt >= CBR_THRESHOLD2) {
646 break;
647 }
648 }
649 gold_sadj[0] = 0x0;
650 passcnt = 0;
651 for (cnt = 0; cnt < 16; cnt++) {
652 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
653 gold_sadj[0] += dllmin[cnt];
654 passcnt++;
655 }
656 }
Dave Airlie318cfa22014-01-17 11:36:14 +1000657 if (retry++ > 10)
658 goto FINETUNE_DONE;
Dave Airlie312fec12012-02-29 13:40:04 +0000659 if (passcnt != 16) {
660 goto FINETUNE_START;
661 }
Dave Airlie318cfa22014-01-17 11:36:14 +1000662 status = true;
663FINETUNE_DONE:
Dave Airlie312fec12012-02-29 13:40:04 +0000664 gold_sadj[0] = gold_sadj[0] >> 4;
665 gold_sadj[1] = gold_sadj[0];
666
667 data = 0;
668 for (cnt = 0; cnt < 8; cnt++) {
669 data >>= 3;
670 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
671 dlli = dllmin[cnt];
672 if (gold_sadj[0] >= dlli) {
673 dlli = ((gold_sadj[0] - dlli) * 19) >> 5;
674 if (dlli > 3) {
675 dlli = 3;
676 }
677 } else {
678 dlli = ((dlli - gold_sadj[0]) * 19) >> 5;
679 if (dlli > 4) {
680 dlli = 4;
681 }
682 dlli = (8 - dlli) & 0x7;
683 }
684 data |= dlli << 21;
685 }
686 }
687 moutdwm(ast, 0x1E6E0080, data);
688
689 data = 0;
690 for (cnt = 8; cnt < 16; cnt++) {
691 data >>= 3;
692 if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
693 dlli = dllmin[cnt];
694 if (gold_sadj[1] >= dlli) {
695 dlli = ((gold_sadj[1] - dlli) * 19) >> 5;
696 if (dlli > 3) {
697 dlli = 3;
698 } else {
699 dlli = (dlli - 1) & 0x7;
700 }
701 } else {
702 dlli = ((dlli - gold_sadj[1]) * 19) >> 5;
703 dlli += 1;
704 if (dlli > 4) {
705 dlli = 4;
706 }
707 dlli = (8 - dlli) & 0x7;
708 }
709 data |= dlli << 21;
710 }
711 }
712 moutdwm(ast, 0x1E6E0084, data);
Dave Airlie318cfa22014-01-17 11:36:14 +1000713 return status;
Dave Airlie312fec12012-02-29 13:40:04 +0000714} /* finetuneDQI_L */
715
Dave Airlie318cfa22014-01-17 11:36:14 +1000716static void finetuneDQSI(struct ast_private *ast)
Dave Airlie312fec12012-02-29 13:40:04 +0000717{
Dave Airlie318cfa22014-01-17 11:36:14 +1000718 u32 dlli, dqsip, dqidly;
719 u32 reg_mcr18, reg_mcr0c, passcnt[2], diff;
720 u32 g_dqidly, g_dqsip, g_margin, g_side;
721 u16 pass[32][2][2];
722 char tag[2][76];
Dave Airlie312fec12012-02-29 13:40:04 +0000723
Dave Airlie318cfa22014-01-17 11:36:14 +1000724 /* Disable DQI CBR */
725 reg_mcr0c = mindwm(ast, 0x1E6E000C);
726 reg_mcr18 = mindwm(ast, 0x1E6E0018);
727 reg_mcr18 &= 0x0000ffff;
728 moutdwm(ast, 0x1E6E0018, reg_mcr18);
729
Dave Airlie312fec12012-02-29 13:40:04 +0000730 for (dlli = 0; dlli < 76; dlli++) {
Dave Airlie318cfa22014-01-17 11:36:14 +1000731 tag[0][dlli] = 0x0;
732 tag[1][dlli] = 0x0;
Dave Airlie312fec12012-02-29 13:40:04 +0000733 }
Dave Airlie318cfa22014-01-17 11:36:14 +1000734 for (dqidly = 0; dqidly < 32; dqidly++) {
735 pass[dqidly][0][0] = 0xff;
736 pass[dqidly][0][1] = 0x0;
737 pass[dqidly][1][0] = 0xff;
738 pass[dqidly][1][1] = 0x0;
Dave Airlie312fec12012-02-29 13:40:04 +0000739 }
Dave Airlie318cfa22014-01-17 11:36:14 +1000740 for (dqidly = 0; dqidly < 32; dqidly++) {
741 passcnt[0] = passcnt[1] = 0;
742 for (dqsip = 0; dqsip < 2; dqsip++) {
743 moutdwm(ast, 0x1E6E000C, 0);
744 moutdwm(ast, 0x1E6E0018, reg_mcr18 | (dqidly << 16) | (dqsip << 23));
745 moutdwm(ast, 0x1E6E000C, reg_mcr0c);
746 for (dlli = 0; dlli < 76; dlli++) {
747 moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24));
748 moutdwm(ast, 0x1E6E0070, 0);
749 moutdwm(ast, 0x1E6E0074, CBR_SIZE0);
750 if (cbr_scan3(ast)) {
751 if (dlli == 0)
752 break;
753 passcnt[dqsip]++;
754 tag[dqsip][dlli] = 'P';
755 if (dlli < pass[dqidly][dqsip][0])
756 pass[dqidly][dqsip][0] = (u16) dlli;
757 if (dlli > pass[dqidly][dqsip][1])
758 pass[dqidly][dqsip][1] = (u16) dlli;
759 } else if (passcnt[dqsip] >= 5)
760 break;
761 else {
762 pass[dqidly][dqsip][0] = 0xff;
763 pass[dqidly][dqsip][1] = 0x0;
Dave Airlie312fec12012-02-29 13:40:04 +0000764 }
765 }
766 }
Dave Airlie318cfa22014-01-17 11:36:14 +1000767 if (passcnt[0] == 0 && passcnt[1] == 0)
768 dqidly++;
Dave Airlie312fec12012-02-29 13:40:04 +0000769 }
Dave Airlie318cfa22014-01-17 11:36:14 +1000770 /* Search margin */
771 g_dqidly = g_dqsip = g_margin = g_side = 0;
Dave Airlie312fec12012-02-29 13:40:04 +0000772
Dave Airlie318cfa22014-01-17 11:36:14 +1000773 for (dqidly = 0; dqidly < 32; dqidly++) {
774 for (dqsip = 0; dqsip < 2; dqsip++) {
775 if (pass[dqidly][dqsip][0] > pass[dqidly][dqsip][1])
776 continue;
777 diff = pass[dqidly][dqsip][1] - pass[dqidly][dqsip][0];
778 if ((diff+2) < g_margin)
779 continue;
780 passcnt[0] = passcnt[1] = 0;
781 for (dlli = pass[dqidly][dqsip][0]; dlli > 0 && tag[dqsip][dlli] != 0; dlli--, passcnt[0]++);
782 for (dlli = pass[dqidly][dqsip][1]; dlli < 76 && tag[dqsip][dlli] != 0; dlli++, passcnt[1]++);
783 if (passcnt[0] > passcnt[1])
784 passcnt[0] = passcnt[1];
785 passcnt[1] = 0;
786 if (passcnt[0] > g_side)
787 passcnt[1] = passcnt[0] - g_side;
788 if (diff > (g_margin+1) && (passcnt[1] > 0 || passcnt[0] > 8)) {
789 g_margin = diff;
790 g_dqidly = dqidly;
791 g_dqsip = dqsip;
792 g_side = passcnt[0];
793 } else if (passcnt[1] > 1 && g_side < 8) {
794 if (diff > g_margin)
795 g_margin = diff;
796 g_dqidly = dqidly;
797 g_dqsip = dqsip;
798 g_side = passcnt[0];
Dave Airlie312fec12012-02-29 13:40:04 +0000799 }
800 }
801 }
Dave Airlie318cfa22014-01-17 11:36:14 +1000802 reg_mcr18 = reg_mcr18 | (g_dqidly << 16) | (g_dqsip << 23);
803 moutdwm(ast, 0x1E6E0018, reg_mcr18);
Dave Airlie312fec12012-02-29 13:40:04 +0000804
Dave Airlie318cfa22014-01-17 11:36:14 +1000805}
806static bool cbr_dll2(struct ast_private *ast, struct ast2300_dram_param *param)
Dave Airlie312fec12012-02-29 13:40:04 +0000807{
Dave Airlie318cfa22014-01-17 11:36:14 +1000808 u32 dllmin[2], dllmax[2], dlli, data, passcnt, retry = 0;
809 bool status = false;
Dave Airlie312fec12012-02-29 13:40:04 +0000810
Dave Airlie318cfa22014-01-17 11:36:14 +1000811 finetuneDQSI(ast);
812 if (finetuneDQI_L(ast, param) == false)
813 return status;
Dave Airlie312fec12012-02-29 13:40:04 +0000814
815CBR_START2:
816 dllmin[0] = dllmin[1] = 0xff;
817 dllmax[0] = dllmax[1] = 0x0;
818 passcnt = 0;
819 for (dlli = 0; dlli < 76; dlli++) {
820 moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24));
Dave Airlie312fec12012-02-29 13:40:04 +0000821 moutdwm(ast, 0x1E6E0074, CBR_SIZE2);
822 data = cbr_scan(ast);
823 if (data != 0) {
824 if (data & 0x1) {
825 if (dllmin[0] > dlli) {
826 dllmin[0] = dlli;
827 }
828 if (dllmax[0] < dlli) {
829 dllmax[0] = dlli;
830 }
831 }
832 if (data & 0x2) {
833 if (dllmin[1] > dlli) {
834 dllmin[1] = dlli;
835 }
836 if (dllmax[1] < dlli) {
837 dllmax[1] = dlli;
838 }
839 }
840 passcnt++;
841 } else if (passcnt >= CBR_THRESHOLD) {
842 break;
843 }
844 }
Dave Airlie318cfa22014-01-17 11:36:14 +1000845 if (retry++ > 10)
846 goto CBR_DONE2;
Dave Airlie312fec12012-02-29 13:40:04 +0000847 if (dllmax[0] == 0 || (dllmax[0]-dllmin[0]) < CBR_THRESHOLD) {
848 goto CBR_START2;
849 }
850 if (dllmax[1] == 0 || (dllmax[1]-dllmin[1]) < CBR_THRESHOLD) {
851 goto CBR_START2;
852 }
Dave Airlie318cfa22014-01-17 11:36:14 +1000853 status = true;
854CBR_DONE2:
Dave Airlie312fec12012-02-29 13:40:04 +0000855 dlli = (dllmin[1] + dllmax[1]) >> 1;
856 dlli <<= 8;
857 dlli += (dllmin[0] + dllmax[0]) >> 1;
Dave Airlie318cfa22014-01-17 11:36:14 +1000858 moutdwm(ast, 0x1E6E0068, mindwm(ast, 0x1E720058) | (dlli << 16));
859 return status;
Dave Airlie312fec12012-02-29 13:40:04 +0000860} /* CBRDLL2 */
861
862static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *param)
863{
864 u32 trap, trap_AC2, trap_MRS;
865
866 moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
867
868 /* Ger trap info */
869 trap = (mindwm(ast, 0x1E6E2070) >> 25) & 0x3;
870 trap_AC2 = 0x00020000 + (trap << 16);
871 trap_AC2 |= 0x00300000 + ((trap & 0x2) << 19);
872 trap_MRS = 0x00000010 + (trap << 4);
873 trap_MRS |= ((trap & 0x2) << 18);
874
875 param->reg_MADJ = 0x00034C4C;
876 param->reg_SADJ = 0x00001800;
877 param->reg_DRV = 0x000000F0;
878 param->reg_PERIOD = param->dram_freq;
879 param->rodt = 0;
880
881 switch (param->dram_freq) {
882 case 336:
883 moutdwm(ast, 0x1E6E2020, 0x0190);
884 param->wodt = 0;
885 param->reg_AC1 = 0x22202725;
886 param->reg_AC2 = 0xAA007613 | trap_AC2;
887 param->reg_DQSIC = 0x000000BA;
888 param->reg_MRS = 0x04001400 | trap_MRS;
889 param->reg_EMRS = 0x00000000;
Dave Airlie318cfa22014-01-17 11:36:14 +1000890 param->reg_IOZ = 0x00000023;
Dave Airlie312fec12012-02-29 13:40:04 +0000891 param->reg_DQIDLY = 0x00000074;
892 param->reg_FREQ = 0x00004DC0;
893 param->madj_max = 96;
894 param->dll2_finetune_step = 3;
Dave Airlie318cfa22014-01-17 11:36:14 +1000895 switch (param->dram_chipid) {
896 default:
897 case AST_DRAM_512Mx16:
898 case AST_DRAM_1Gx16:
899 param->reg_AC2 = 0xAA007613 | trap_AC2;
900 break;
901 case AST_DRAM_2Gx16:
902 param->reg_AC2 = 0xAA00761C | trap_AC2;
903 break;
904 case AST_DRAM_4Gx16:
905 param->reg_AC2 = 0xAA007636 | trap_AC2;
906 break;
907 }
Dave Airlie312fec12012-02-29 13:40:04 +0000908 break;
909 default:
910 case 396:
911 moutdwm(ast, 0x1E6E2020, 0x03F1);
912 param->wodt = 1;
913 param->reg_AC1 = 0x33302825;
914 param->reg_AC2 = 0xCC009617 | trap_AC2;
915 param->reg_DQSIC = 0x000000E2;
916 param->reg_MRS = 0x04001600 | trap_MRS;
917 param->reg_EMRS = 0x00000000;
918 param->reg_IOZ = 0x00000034;
919 param->reg_DRV = 0x000000FA;
920 param->reg_DQIDLY = 0x00000089;
Dave Airlie318cfa22014-01-17 11:36:14 +1000921 param->reg_FREQ = 0x00005040;
Dave Airlie312fec12012-02-29 13:40:04 +0000922 param->madj_max = 96;
923 param->dll2_finetune_step = 4;
924
925 switch (param->dram_chipid) {
926 default:
927 case AST_DRAM_512Mx16:
928 case AST_DRAM_1Gx16:
929 param->reg_AC2 = 0xCC009617 | trap_AC2;
930 break;
931 case AST_DRAM_2Gx16:
932 param->reg_AC2 = 0xCC009622 | trap_AC2;
933 break;
934 case AST_DRAM_4Gx16:
935 param->reg_AC2 = 0xCC00963F | trap_AC2;
936 break;
937 }
938 break;
939
940 case 408:
941 moutdwm(ast, 0x1E6E2020, 0x01F0);
942 param->wodt = 1;
943 param->reg_AC1 = 0x33302825;
944 param->reg_AC2 = 0xCC009617 | trap_AC2;
945 param->reg_DQSIC = 0x000000E2;
946 param->reg_MRS = 0x04001600 | trap_MRS;
947 param->reg_EMRS = 0x00000000;
Dave Airlie318cfa22014-01-17 11:36:14 +1000948 param->reg_IOZ = 0x00000023;
Dave Airlie312fec12012-02-29 13:40:04 +0000949 param->reg_DRV = 0x000000FA;
950 param->reg_DQIDLY = 0x00000089;
951 param->reg_FREQ = 0x000050C0;
952 param->madj_max = 96;
953 param->dll2_finetune_step = 4;
954
955 switch (param->dram_chipid) {
956 default:
957 case AST_DRAM_512Mx16:
958 case AST_DRAM_1Gx16:
959 param->reg_AC2 = 0xCC009617 | trap_AC2;
960 break;
961 case AST_DRAM_2Gx16:
962 param->reg_AC2 = 0xCC009622 | trap_AC2;
963 break;
964 case AST_DRAM_4Gx16:
965 param->reg_AC2 = 0xCC00963F | trap_AC2;
966 break;
967 }
968
969 break;
970 case 456:
971 moutdwm(ast, 0x1E6E2020, 0x0230);
972 param->wodt = 0;
973 param->reg_AC1 = 0x33302926;
974 param->reg_AC2 = 0xCD44961A;
975 param->reg_DQSIC = 0x000000FC;
976 param->reg_MRS = 0x00081830;
977 param->reg_EMRS = 0x00000000;
978 param->reg_IOZ = 0x00000045;
979 param->reg_DQIDLY = 0x00000097;
980 param->reg_FREQ = 0x000052C0;
981 param->madj_max = 88;
982 param->dll2_finetune_step = 4;
983 break;
984 case 504:
985 moutdwm(ast, 0x1E6E2020, 0x0270);
986 param->wodt = 1;
987 param->reg_AC1 = 0x33302926;
988 param->reg_AC2 = 0xDE44A61D;
989 param->reg_DQSIC = 0x00000117;
990 param->reg_MRS = 0x00081A30;
991 param->reg_EMRS = 0x00000000;
992 param->reg_IOZ = 0x070000BB;
993 param->reg_DQIDLY = 0x000000A0;
994 param->reg_FREQ = 0x000054C0;
995 param->madj_max = 79;
996 param->dll2_finetune_step = 4;
997 break;
998 case 528:
999 moutdwm(ast, 0x1E6E2020, 0x0290);
1000 param->wodt = 1;
1001 param->rodt = 1;
1002 param->reg_AC1 = 0x33302926;
1003 param->reg_AC2 = 0xEF44B61E;
1004 param->reg_DQSIC = 0x00000125;
1005 param->reg_MRS = 0x00081A30;
1006 param->reg_EMRS = 0x00000040;
1007 param->reg_DRV = 0x000000F5;
1008 param->reg_IOZ = 0x00000023;
1009 param->reg_DQIDLY = 0x00000088;
1010 param->reg_FREQ = 0x000055C0;
1011 param->madj_max = 76;
1012 param->dll2_finetune_step = 3;
1013 break;
1014 case 576:
1015 moutdwm(ast, 0x1E6E2020, 0x0140);
1016 param->reg_MADJ = 0x00136868;
1017 param->reg_SADJ = 0x00004534;
1018 param->wodt = 1;
1019 param->rodt = 1;
1020 param->reg_AC1 = 0x33302A37;
1021 param->reg_AC2 = 0xEF56B61E;
1022 param->reg_DQSIC = 0x0000013F;
1023 param->reg_MRS = 0x00101A50;
1024 param->reg_EMRS = 0x00000040;
1025 param->reg_DRV = 0x000000FA;
1026 param->reg_IOZ = 0x00000023;
1027 param->reg_DQIDLY = 0x00000078;
1028 param->reg_FREQ = 0x000057C0;
1029 param->madj_max = 136;
1030 param->dll2_finetune_step = 3;
1031 break;
1032 case 600:
1033 moutdwm(ast, 0x1E6E2020, 0x02E1);
1034 param->reg_MADJ = 0x00136868;
1035 param->reg_SADJ = 0x00004534;
1036 param->wodt = 1;
1037 param->rodt = 1;
1038 param->reg_AC1 = 0x32302A37;
1039 param->reg_AC2 = 0xDF56B61F;
1040 param->reg_DQSIC = 0x0000014D;
1041 param->reg_MRS = 0x00101A50;
1042 param->reg_EMRS = 0x00000004;
1043 param->reg_DRV = 0x000000F5;
1044 param->reg_IOZ = 0x00000023;
1045 param->reg_DQIDLY = 0x00000078;
1046 param->reg_FREQ = 0x000058C0;
1047 param->madj_max = 132;
1048 param->dll2_finetune_step = 3;
1049 break;
1050 case 624:
1051 moutdwm(ast, 0x1E6E2020, 0x0160);
1052 param->reg_MADJ = 0x00136868;
1053 param->reg_SADJ = 0x00004534;
1054 param->wodt = 1;
1055 param->rodt = 1;
1056 param->reg_AC1 = 0x32302A37;
1057 param->reg_AC2 = 0xEF56B621;
1058 param->reg_DQSIC = 0x0000015A;
1059 param->reg_MRS = 0x02101A50;
1060 param->reg_EMRS = 0x00000004;
1061 param->reg_DRV = 0x000000F5;
1062 param->reg_IOZ = 0x00000034;
1063 param->reg_DQIDLY = 0x00000078;
1064 param->reg_FREQ = 0x000059C0;
1065 param->madj_max = 128;
1066 param->dll2_finetune_step = 3;
1067 break;
1068 } /* switch freq */
1069
1070 switch (param->dram_chipid) {
1071 case AST_DRAM_512Mx16:
1072 param->dram_config = 0x130;
1073 break;
1074 default:
1075 case AST_DRAM_1Gx16:
1076 param->dram_config = 0x131;
1077 break;
1078 case AST_DRAM_2Gx16:
1079 param->dram_config = 0x132;
1080 break;
1081 case AST_DRAM_4Gx16:
1082 param->dram_config = 0x133;
1083 break;
1084 }; /* switch size */
1085
1086 switch (param->vram_size) {
1087 default:
1088 case AST_VIDMEM_SIZE_8M:
1089 param->dram_config |= 0x00;
1090 break;
1091 case AST_VIDMEM_SIZE_16M:
1092 param->dram_config |= 0x04;
1093 break;
1094 case AST_VIDMEM_SIZE_32M:
1095 param->dram_config |= 0x08;
1096 break;
1097 case AST_VIDMEM_SIZE_64M:
1098 param->dram_config |= 0x0c;
1099 break;
1100 }
1101
1102}
1103
1104static void ddr3_init(struct ast_private *ast, struct ast2300_dram_param *param)
1105{
Dave Airlie318cfa22014-01-17 11:36:14 +10001106 u32 data, data2, retry = 0;
Dave Airlie312fec12012-02-29 13:40:04 +00001107
Dave Airlie318cfa22014-01-17 11:36:14 +10001108ddr3_init_start:
Dave Airlie312fec12012-02-29 13:40:04 +00001109 moutdwm(ast, 0x1E6E0000, 0xFC600309);
1110 moutdwm(ast, 0x1E6E0018, 0x00000100);
1111 moutdwm(ast, 0x1E6E0024, 0x00000000);
1112 moutdwm(ast, 0x1E6E0034, 0x00000000);
1113 udelay(10);
1114 moutdwm(ast, 0x1E6E0064, param->reg_MADJ);
1115 moutdwm(ast, 0x1E6E0068, param->reg_SADJ);
1116 udelay(10);
1117 moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000);
1118 udelay(10);
1119
1120 moutdwm(ast, 0x1E6E0004, param->dram_config);
1121 moutdwm(ast, 0x1E6E0008, 0x90040f);
1122 moutdwm(ast, 0x1E6E0010, param->reg_AC1);
1123 moutdwm(ast, 0x1E6E0014, param->reg_AC2);
1124 moutdwm(ast, 0x1E6E0020, param->reg_DQSIC);
1125 moutdwm(ast, 0x1E6E0080, 0x00000000);
1126 moutdwm(ast, 0x1E6E0084, 0x00000000);
1127 moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY);
Dave Airlie318cfa22014-01-17 11:36:14 +10001128 moutdwm(ast, 0x1E6E0018, 0x4000A170);
1129 moutdwm(ast, 0x1E6E0018, 0x00002370);
Dave Airlie312fec12012-02-29 13:40:04 +00001130 moutdwm(ast, 0x1E6E0038, 0x00000000);
1131 moutdwm(ast, 0x1E6E0040, 0xFF444444);
1132 moutdwm(ast, 0x1E6E0044, 0x22222222);
1133 moutdwm(ast, 0x1E6E0048, 0x22222222);
1134 moutdwm(ast, 0x1E6E004C, 0x00000002);
1135 moutdwm(ast, 0x1E6E0050, 0x80000000);
1136 moutdwm(ast, 0x1E6E0050, 0x00000000);
1137 moutdwm(ast, 0x1E6E0054, 0);
1138 moutdwm(ast, 0x1E6E0060, param->reg_DRV);
1139 moutdwm(ast, 0x1E6E006C, param->reg_IOZ);
1140 moutdwm(ast, 0x1E6E0070, 0x00000000);
1141 moutdwm(ast, 0x1E6E0074, 0x00000000);
1142 moutdwm(ast, 0x1E6E0078, 0x00000000);
1143 moutdwm(ast, 0x1E6E007C, 0x00000000);
1144 /* Wait MCLK2X lock to MCLK */
1145 do {
1146 data = mindwm(ast, 0x1E6E001C);
1147 } while (!(data & 0x08000000));
Dave Airlie312fec12012-02-29 13:40:04 +00001148 data = mindwm(ast, 0x1E6E001C);
1149 data = (data >> 8) & 0xff;
1150 while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) {
1151 data2 = (mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4;
1152 if ((data2 & 0xff) > param->madj_max) {
1153 break;
1154 }
1155 moutdwm(ast, 0x1E6E0064, data2);
1156 if (data2 & 0x00100000) {
1157 data2 = ((data2 & 0xff) >> 3) + 3;
1158 } else {
1159 data2 = ((data2 & 0xff) >> 2) + 5;
1160 }
1161 data = mindwm(ast, 0x1E6E0068) & 0xffff00ff;
1162 data2 += data & 0xff;
1163 data = data | (data2 << 8);
1164 moutdwm(ast, 0x1E6E0068, data);
1165 udelay(10);
1166 moutdwm(ast, 0x1E6E0064, mindwm(ast, 0x1E6E0064) | 0xC0000);
1167 udelay(10);
1168 data = mindwm(ast, 0x1E6E0018) & 0xfffff1ff;
1169 moutdwm(ast, 0x1E6E0018, data);
1170 data = data | 0x200;
1171 moutdwm(ast, 0x1E6E0018, data);
1172 do {
1173 data = mindwm(ast, 0x1E6E001C);
1174 } while (!(data & 0x08000000));
1175
Dave Airlie312fec12012-02-29 13:40:04 +00001176 data = mindwm(ast, 0x1E6E001C);
1177 data = (data >> 8) & 0xff;
1178 }
Dave Airlie318cfa22014-01-17 11:36:14 +10001179 moutdwm(ast, 0x1E720058, mindwm(ast, 0x1E6E0068) & 0xffff);
Dave Airlie312fec12012-02-29 13:40:04 +00001180 data = mindwm(ast, 0x1E6E0018) | 0xC00;
1181 moutdwm(ast, 0x1E6E0018, data);
1182
1183 moutdwm(ast, 0x1E6E0034, 0x00000001);
1184 moutdwm(ast, 0x1E6E000C, 0x00000040);
1185 udelay(50);
1186 /* Mode Register Setting */
1187 moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100);
1188 moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1189 moutdwm(ast, 0x1E6E0028, 0x00000005);
1190 moutdwm(ast, 0x1E6E0028, 0x00000007);
1191 moutdwm(ast, 0x1E6E0028, 0x00000003);
1192 moutdwm(ast, 0x1E6E0028, 0x00000001);
1193 moutdwm(ast, 0x1E6E002C, param->reg_MRS);
1194 moutdwm(ast, 0x1E6E000C, 0x00005C08);
1195 moutdwm(ast, 0x1E6E0028, 0x00000001);
1196
Dave Airlie318cfa22014-01-17 11:36:14 +10001197 moutdwm(ast, 0x1E6E000C, 0x00005C01);
Dave Airlie312fec12012-02-29 13:40:04 +00001198 data = 0;
1199 if (param->wodt) {
1200 data = 0x300;
1201 }
1202 if (param->rodt) {
1203 data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3);
1204 }
1205 moutdwm(ast, 0x1E6E0034, data | 0x3);
1206
Dave Airlie312fec12012-02-29 13:40:04 +00001207 /* Calibrate the DQSI delay */
Dave Airlie318cfa22014-01-17 11:36:14 +10001208 if ((cbr_dll2(ast, param) == false) && (retry++ < 10))
1209 goto ddr3_init_start;
Dave Airlie312fec12012-02-29 13:40:04 +00001210
1211 moutdwm(ast, 0x1E6E0120, param->reg_FREQ);
1212 /* ECC Memory Initialization */
1213#ifdef ECC
1214 moutdwm(ast, 0x1E6E007C, 0x00000000);
1215 moutdwm(ast, 0x1E6E0070, 0x221);
1216 do {
1217 data = mindwm(ast, 0x1E6E0070);
1218 } while (!(data & 0x00001000));
1219 moutdwm(ast, 0x1E6E0070, 0x00000000);
1220 moutdwm(ast, 0x1E6E0050, 0x80000000);
1221 moutdwm(ast, 0x1E6E0050, 0x00000000);
1222#endif
1223
1224
1225}
1226
1227static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *param)
1228{
1229 u32 trap, trap_AC2, trap_MRS;
1230
1231 moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
1232
1233 /* Ger trap info */
1234 trap = (mindwm(ast, 0x1E6E2070) >> 25) & 0x3;
1235 trap_AC2 = (trap << 20) | (trap << 16);
1236 trap_AC2 += 0x00110000;
1237 trap_MRS = 0x00000040 | (trap << 4);
1238
1239
1240 param->reg_MADJ = 0x00034C4C;
1241 param->reg_SADJ = 0x00001800;
1242 param->reg_DRV = 0x000000F0;
1243 param->reg_PERIOD = param->dram_freq;
1244 param->rodt = 0;
1245
1246 switch (param->dram_freq) {
1247 case 264:
1248 moutdwm(ast, 0x1E6E2020, 0x0130);
1249 param->wodt = 0;
1250 param->reg_AC1 = 0x11101513;
1251 param->reg_AC2 = 0x78117011;
1252 param->reg_DQSIC = 0x00000092;
1253 param->reg_MRS = 0x00000842;
1254 param->reg_EMRS = 0x00000000;
1255 param->reg_DRV = 0x000000F0;
1256 param->reg_IOZ = 0x00000034;
1257 param->reg_DQIDLY = 0x0000005A;
1258 param->reg_FREQ = 0x00004AC0;
1259 param->madj_max = 138;
1260 param->dll2_finetune_step = 3;
1261 break;
1262 case 336:
1263 moutdwm(ast, 0x1E6E2020, 0x0190);
1264 param->wodt = 1;
1265 param->reg_AC1 = 0x22202613;
1266 param->reg_AC2 = 0xAA009016 | trap_AC2;
1267 param->reg_DQSIC = 0x000000BA;
1268 param->reg_MRS = 0x00000A02 | trap_MRS;
1269 param->reg_EMRS = 0x00000040;
1270 param->reg_DRV = 0x000000FA;
1271 param->reg_IOZ = 0x00000034;
1272 param->reg_DQIDLY = 0x00000074;
1273 param->reg_FREQ = 0x00004DC0;
1274 param->madj_max = 96;
1275 param->dll2_finetune_step = 3;
Dave Airlie318cfa22014-01-17 11:36:14 +10001276 switch (param->dram_chipid) {
1277 default:
1278 case AST_DRAM_512Mx16:
1279 param->reg_AC2 = 0xAA009012 | trap_AC2;
1280 break;
1281 case AST_DRAM_1Gx16:
1282 param->reg_AC2 = 0xAA009016 | trap_AC2;
1283 break;
1284 case AST_DRAM_2Gx16:
1285 param->reg_AC2 = 0xAA009023 | trap_AC2;
1286 break;
1287 case AST_DRAM_4Gx16:
1288 param->reg_AC2 = 0xAA00903B | trap_AC2;
1289 break;
1290 }
Dave Airlie312fec12012-02-29 13:40:04 +00001291 break;
1292 default:
1293 case 396:
1294 moutdwm(ast, 0x1E6E2020, 0x03F1);
1295 param->wodt = 1;
1296 param->rodt = 0;
1297 param->reg_AC1 = 0x33302714;
1298 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1299 param->reg_DQSIC = 0x000000E2;
1300 param->reg_MRS = 0x00000C02 | trap_MRS;
1301 param->reg_EMRS = 0x00000040;
1302 param->reg_DRV = 0x000000FA;
1303 param->reg_IOZ = 0x00000034;
1304 param->reg_DQIDLY = 0x00000089;
Dave Airlie318cfa22014-01-17 11:36:14 +10001305 param->reg_FREQ = 0x00005040;
Dave Airlie312fec12012-02-29 13:40:04 +00001306 param->madj_max = 96;
1307 param->dll2_finetune_step = 4;
1308
1309 switch (param->dram_chipid) {
1310 case AST_DRAM_512Mx16:
1311 param->reg_AC2 = 0xCC00B016 | trap_AC2;
1312 break;
1313 default:
1314 case AST_DRAM_1Gx16:
1315 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1316 break;
1317 case AST_DRAM_2Gx16:
1318 param->reg_AC2 = 0xCC00B02B | trap_AC2;
1319 break;
1320 case AST_DRAM_4Gx16:
1321 param->reg_AC2 = 0xCC00B03F | trap_AC2;
1322 break;
1323 }
1324
1325 break;
1326
1327 case 408:
1328 moutdwm(ast, 0x1E6E2020, 0x01F0);
1329 param->wodt = 1;
1330 param->rodt = 0;
1331 param->reg_AC1 = 0x33302714;
1332 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1333 param->reg_DQSIC = 0x000000E2;
1334 param->reg_MRS = 0x00000C02 | trap_MRS;
1335 param->reg_EMRS = 0x00000040;
1336 param->reg_DRV = 0x000000FA;
1337 param->reg_IOZ = 0x00000034;
1338 param->reg_DQIDLY = 0x00000089;
1339 param->reg_FREQ = 0x000050C0;
1340 param->madj_max = 96;
1341 param->dll2_finetune_step = 4;
1342
1343 switch (param->dram_chipid) {
1344 case AST_DRAM_512Mx16:
1345 param->reg_AC2 = 0xCC00B016 | trap_AC2;
1346 break;
1347 default:
1348 case AST_DRAM_1Gx16:
1349 param->reg_AC2 = 0xCC00B01B | trap_AC2;
1350 break;
1351 case AST_DRAM_2Gx16:
1352 param->reg_AC2 = 0xCC00B02B | trap_AC2;
1353 break;
1354 case AST_DRAM_4Gx16:
1355 param->reg_AC2 = 0xCC00B03F | trap_AC2;
1356 break;
1357 }
1358
1359 break;
1360 case 456:
1361 moutdwm(ast, 0x1E6E2020, 0x0230);
1362 param->wodt = 0;
1363 param->reg_AC1 = 0x33302815;
1364 param->reg_AC2 = 0xCD44B01E;
1365 param->reg_DQSIC = 0x000000FC;
1366 param->reg_MRS = 0x00000E72;
1367 param->reg_EMRS = 0x00000000;
1368 param->reg_DRV = 0x00000000;
1369 param->reg_IOZ = 0x00000034;
1370 param->reg_DQIDLY = 0x00000097;
1371 param->reg_FREQ = 0x000052C0;
1372 param->madj_max = 88;
1373 param->dll2_finetune_step = 3;
1374 break;
1375 case 504:
1376 moutdwm(ast, 0x1E6E2020, 0x0261);
1377 param->wodt = 1;
1378 param->rodt = 1;
1379 param->reg_AC1 = 0x33302815;
1380 param->reg_AC2 = 0xDE44C022;
1381 param->reg_DQSIC = 0x00000117;
1382 param->reg_MRS = 0x00000E72;
1383 param->reg_EMRS = 0x00000040;
1384 param->reg_DRV = 0x0000000A;
1385 param->reg_IOZ = 0x00000045;
1386 param->reg_DQIDLY = 0x000000A0;
1387 param->reg_FREQ = 0x000054C0;
1388 param->madj_max = 79;
1389 param->dll2_finetune_step = 3;
1390 break;
1391 case 528:
1392 moutdwm(ast, 0x1E6E2020, 0x0120);
1393 param->wodt = 1;
1394 param->rodt = 1;
1395 param->reg_AC1 = 0x33302815;
1396 param->reg_AC2 = 0xEF44D024;
1397 param->reg_DQSIC = 0x00000125;
1398 param->reg_MRS = 0x00000E72;
1399 param->reg_EMRS = 0x00000004;
1400 param->reg_DRV = 0x000000F9;
1401 param->reg_IOZ = 0x00000045;
1402 param->reg_DQIDLY = 0x000000A7;
1403 param->reg_FREQ = 0x000055C0;
1404 param->madj_max = 76;
1405 param->dll2_finetune_step = 3;
1406 break;
1407 case 552:
1408 moutdwm(ast, 0x1E6E2020, 0x02A1);
1409 param->wodt = 1;
1410 param->rodt = 1;
1411 param->reg_AC1 = 0x43402915;
1412 param->reg_AC2 = 0xFF44E025;
1413 param->reg_DQSIC = 0x00000132;
1414 param->reg_MRS = 0x00000E72;
1415 param->reg_EMRS = 0x00000040;
1416 param->reg_DRV = 0x0000000A;
1417 param->reg_IOZ = 0x00000045;
1418 param->reg_DQIDLY = 0x000000AD;
1419 param->reg_FREQ = 0x000056C0;
1420 param->madj_max = 76;
1421 param->dll2_finetune_step = 3;
1422 break;
1423 case 576:
1424 moutdwm(ast, 0x1E6E2020, 0x0140);
1425 param->wodt = 1;
1426 param->rodt = 1;
1427 param->reg_AC1 = 0x43402915;
1428 param->reg_AC2 = 0xFF44E027;
1429 param->reg_DQSIC = 0x0000013F;
1430 param->reg_MRS = 0x00000E72;
1431 param->reg_EMRS = 0x00000004;
1432 param->reg_DRV = 0x000000F5;
1433 param->reg_IOZ = 0x00000045;
1434 param->reg_DQIDLY = 0x000000B3;
1435 param->reg_FREQ = 0x000057C0;
1436 param->madj_max = 76;
1437 param->dll2_finetune_step = 3;
1438 break;
1439 }
1440
1441 switch (param->dram_chipid) {
1442 case AST_DRAM_512Mx16:
1443 param->dram_config = 0x100;
1444 break;
1445 default:
1446 case AST_DRAM_1Gx16:
1447 param->dram_config = 0x121;
1448 break;
1449 case AST_DRAM_2Gx16:
1450 param->dram_config = 0x122;
1451 break;
1452 case AST_DRAM_4Gx16:
1453 param->dram_config = 0x123;
1454 break;
1455 }; /* switch size */
1456
1457 switch (param->vram_size) {
1458 default:
1459 case AST_VIDMEM_SIZE_8M:
1460 param->dram_config |= 0x00;
1461 break;
1462 case AST_VIDMEM_SIZE_16M:
1463 param->dram_config |= 0x04;
1464 break;
1465 case AST_VIDMEM_SIZE_32M:
1466 param->dram_config |= 0x08;
1467 break;
1468 case AST_VIDMEM_SIZE_64M:
1469 param->dram_config |= 0x0c;
1470 break;
1471 }
1472}
1473
1474static void ddr2_init(struct ast_private *ast, struct ast2300_dram_param *param)
1475{
Dave Airlie318cfa22014-01-17 11:36:14 +10001476 u32 data, data2, retry = 0;
Dave Airlie312fec12012-02-29 13:40:04 +00001477
Dave Airlie318cfa22014-01-17 11:36:14 +10001478ddr2_init_start:
Dave Airlie312fec12012-02-29 13:40:04 +00001479 moutdwm(ast, 0x1E6E0000, 0xFC600309);
1480 moutdwm(ast, 0x1E6E0018, 0x00000100);
1481 moutdwm(ast, 0x1E6E0024, 0x00000000);
1482 moutdwm(ast, 0x1E6E0064, param->reg_MADJ);
1483 moutdwm(ast, 0x1E6E0068, param->reg_SADJ);
1484 udelay(10);
1485 moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000);
1486 udelay(10);
1487
1488 moutdwm(ast, 0x1E6E0004, param->dram_config);
1489 moutdwm(ast, 0x1E6E0008, 0x90040f);
1490 moutdwm(ast, 0x1E6E0010, param->reg_AC1);
1491 moutdwm(ast, 0x1E6E0014, param->reg_AC2);
1492 moutdwm(ast, 0x1E6E0020, param->reg_DQSIC);
1493 moutdwm(ast, 0x1E6E0080, 0x00000000);
1494 moutdwm(ast, 0x1E6E0084, 0x00000000);
1495 moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY);
Dave Airlie318cfa22014-01-17 11:36:14 +10001496 moutdwm(ast, 0x1E6E0018, 0x4000A130);
1497 moutdwm(ast, 0x1E6E0018, 0x00002330);
Dave Airlie312fec12012-02-29 13:40:04 +00001498 moutdwm(ast, 0x1E6E0038, 0x00000000);
1499 moutdwm(ast, 0x1E6E0040, 0xFF808000);
1500 moutdwm(ast, 0x1E6E0044, 0x88848466);
1501 moutdwm(ast, 0x1E6E0048, 0x44440008);
1502 moutdwm(ast, 0x1E6E004C, 0x00000000);
1503 moutdwm(ast, 0x1E6E0050, 0x80000000);
1504 moutdwm(ast, 0x1E6E0050, 0x00000000);
1505 moutdwm(ast, 0x1E6E0054, 0);
1506 moutdwm(ast, 0x1E6E0060, param->reg_DRV);
1507 moutdwm(ast, 0x1E6E006C, param->reg_IOZ);
1508 moutdwm(ast, 0x1E6E0070, 0x00000000);
1509 moutdwm(ast, 0x1E6E0074, 0x00000000);
1510 moutdwm(ast, 0x1E6E0078, 0x00000000);
1511 moutdwm(ast, 0x1E6E007C, 0x00000000);
1512
1513 /* Wait MCLK2X lock to MCLK */
1514 do {
1515 data = mindwm(ast, 0x1E6E001C);
1516 } while (!(data & 0x08000000));
Dave Airlie312fec12012-02-29 13:40:04 +00001517 data = mindwm(ast, 0x1E6E001C);
1518 data = (data >> 8) & 0xff;
1519 while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) {
1520 data2 = (mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4;
1521 if ((data2 & 0xff) > param->madj_max) {
1522 break;
1523 }
1524 moutdwm(ast, 0x1E6E0064, data2);
1525 if (data2 & 0x00100000) {
1526 data2 = ((data2 & 0xff) >> 3) + 3;
1527 } else {
1528 data2 = ((data2 & 0xff) >> 2) + 5;
1529 }
1530 data = mindwm(ast, 0x1E6E0068) & 0xffff00ff;
1531 data2 += data & 0xff;
1532 data = data | (data2 << 8);
1533 moutdwm(ast, 0x1E6E0068, data);
1534 udelay(10);
1535 moutdwm(ast, 0x1E6E0064, mindwm(ast, 0x1E6E0064) | 0xC0000);
1536 udelay(10);
1537 data = mindwm(ast, 0x1E6E0018) & 0xfffff1ff;
1538 moutdwm(ast, 0x1E6E0018, data);
1539 data = data | 0x200;
1540 moutdwm(ast, 0x1E6E0018, data);
1541 do {
1542 data = mindwm(ast, 0x1E6E001C);
1543 } while (!(data & 0x08000000));
1544
Dave Airlie312fec12012-02-29 13:40:04 +00001545 data = mindwm(ast, 0x1E6E001C);
1546 data = (data >> 8) & 0xff;
1547 }
Dave Airlie318cfa22014-01-17 11:36:14 +10001548 moutdwm(ast, 0x1E720058, mindwm(ast, 0x1E6E0008) & 0xffff);
Dave Airlie312fec12012-02-29 13:40:04 +00001549 data = mindwm(ast, 0x1E6E0018) | 0xC00;
1550 moutdwm(ast, 0x1E6E0018, data);
1551
1552 moutdwm(ast, 0x1E6E0034, 0x00000001);
1553 moutdwm(ast, 0x1E6E000C, 0x00000000);
1554 udelay(50);
1555 /* Mode Register Setting */
1556 moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100);
1557 moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1558 moutdwm(ast, 0x1E6E0028, 0x00000005);
1559 moutdwm(ast, 0x1E6E0028, 0x00000007);
1560 moutdwm(ast, 0x1E6E0028, 0x00000003);
1561 moutdwm(ast, 0x1E6E0028, 0x00000001);
1562
1563 moutdwm(ast, 0x1E6E000C, 0x00005C08);
1564 moutdwm(ast, 0x1E6E002C, param->reg_MRS);
1565 moutdwm(ast, 0x1E6E0028, 0x00000001);
1566 moutdwm(ast, 0x1E6E0030, param->reg_EMRS | 0x380);
1567 moutdwm(ast, 0x1E6E0028, 0x00000003);
1568 moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
1569 moutdwm(ast, 0x1E6E0028, 0x00000003);
1570
1571 moutdwm(ast, 0x1E6E000C, 0x7FFF5C01);
1572 data = 0;
1573 if (param->wodt) {
1574 data = 0x500;
1575 }
1576 if (param->rodt) {
1577 data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3);
1578 }
1579 moutdwm(ast, 0x1E6E0034, data | 0x3);
1580 moutdwm(ast, 0x1E6E0120, param->reg_FREQ);
1581
Dave Airlie312fec12012-02-29 13:40:04 +00001582 /* Calibrate the DQSI delay */
Dave Airlie318cfa22014-01-17 11:36:14 +10001583 if ((cbr_dll2(ast, param) == false) && (retry++ < 10))
1584 goto ddr2_init_start;
Dave Airlie312fec12012-02-29 13:40:04 +00001585
1586 /* ECC Memory Initialization */
1587#ifdef ECC
1588 moutdwm(ast, 0x1E6E007C, 0x00000000);
1589 moutdwm(ast, 0x1E6E0070, 0x221);
1590 do {
1591 data = mindwm(ast, 0x1E6E0070);
1592 } while (!(data & 0x00001000));
1593 moutdwm(ast, 0x1E6E0070, 0x00000000);
1594 moutdwm(ast, 0x1E6E0050, 0x80000000);
1595 moutdwm(ast, 0x1E6E0050, 0x00000000);
1596#endif
1597
1598}
1599
1600static void ast_init_dram_2300(struct drm_device *dev)
1601{
1602 struct ast_private *ast = dev->dev_private;
1603 struct ast2300_dram_param param;
1604 u32 temp;
1605 u8 reg;
1606
1607 reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
1608 if ((reg & 0x80) == 0) {/* vga only */
1609 ast_write32(ast, 0xf004, 0x1e6e0000);
1610 ast_write32(ast, 0xf000, 0x1);
1611 ast_write32(ast, 0x12000, 0x1688a8a8);
1612 do {
1613 ;
1614 } while (ast_read32(ast, 0x12000) != 0x1);
1615
1616 ast_write32(ast, 0x10000, 0xfc600309);
1617 do {
1618 ;
1619 } while (ast_read32(ast, 0x10000) != 0x1);
1620
1621 /* Slow down CPU/AHB CLK in VGA only mode */
1622 temp = ast_read32(ast, 0x12008);
1623 temp |= 0x73;
1624 ast_write32(ast, 0x12008, temp);
1625
1626 param.dram_type = AST_DDR3;
1627 if (temp & 0x01000000)
1628 param.dram_type = AST_DDR2;
1629 param.dram_chipid = ast->dram_type;
1630 param.dram_freq = ast->mclk;
1631 param.vram_size = ast->vram_size;
1632
1633 if (param.dram_type == AST_DDR3) {
1634 get_ddr3_info(ast, &param);
1635 ddr3_init(ast, &param);
1636 } else {
1637 get_ddr2_info(ast, &param);
1638 ddr2_init(ast, &param);
1639 }
1640
1641 temp = mindwm(ast, 0x1e6e2040);
1642 moutdwm(ast, 0x1e6e2040, temp | 0x40);
1643 }
1644
1645 /* wait ready */
1646 do {
1647 reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
1648 } while ((reg & 0x40) == 0);
1649}
1650