blob: 6e42f865e91e98e4f67748101e12298c515532e4 [file] [log] [blame]
Joel Stanleye50183f2017-02-28 12:17:46 +10301From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: "Y.C. Chen" <yc_chen@aspeedtech.com>
3Date: Fri, 17 Feb 2017 14:45:07 +1100
Joel Stanley8d5acef2017-03-15 16:24:09 +10304Subject: [PATCH 10/12] drm/ast: POST code for the new AST2500
Joel Stanleye50183f2017-02-28 12:17:46 +10305
6This is used when the BMC isn't running any code and thus has
7to be initialized by the host.
8
9The code originates from Aspeed (Y.C. Chen) and has been cleaned
10up for coding style purposes by BenH.
11
12Signed-off-by: Y.C. Chen <yc_chen@aspeedtech.com>
13Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
14--
15
16v2. - Fix bug in ddr_test_2500 reported by Emil Velikov
17 - Rebase on updated mmc_test factoring patch
18 - Fix missing else statement in 2500 POST code
19
20Signed-off-by: Joel Stanley <joel@jms.id.au>
21---
22 drivers/gpu/drm/ast/ast_dram_tables.h | 62 +++++
23 drivers/gpu/drm/ast/ast_post.c | 417 +++++++++++++++++++++++++++++++++-
24 2 files changed, 476 insertions(+), 3 deletions(-)
25
26diff --git a/drivers/gpu/drm/ast/ast_dram_tables.h b/drivers/gpu/drm/ast/ast_dram_tables.h
27index cc04539c0ff3..1d9c4e75d303 100644
28--- a/drivers/gpu/drm/ast/ast_dram_tables.h
29+++ b/drivers/gpu/drm/ast/ast_dram_tables.h
30@@ -141,4 +141,66 @@ static const struct ast_dramstruct ast2100_dram_table_data[] = {
31 { 0xffff, 0xffffffff },
32 };
33
34+/*
35+ * AST2500 DRAM settings modules
36+ */
37+#define REGTBL_NUM 17
38+#define REGIDX_010 0
39+#define REGIDX_014 1
40+#define REGIDX_018 2
41+#define REGIDX_020 3
42+#define REGIDX_024 4
43+#define REGIDX_02C 5
44+#define REGIDX_030 6
45+#define REGIDX_214 7
46+#define REGIDX_2E0 8
47+#define REGIDX_2E4 9
48+#define REGIDX_2E8 10
49+#define REGIDX_2EC 11
50+#define REGIDX_2F0 12
51+#define REGIDX_2F4 13
52+#define REGIDX_2F8 14
53+#define REGIDX_RFC 15
54+#define REGIDX_PLL 16
55+
56+static const u32 ast2500_ddr3_1600_timing_table[REGTBL_NUM] = {
57+ 0x64604D38, /* 0x010 */
58+ 0x29690599, /* 0x014 */
59+ 0x00000300, /* 0x018 */
60+ 0x00000000, /* 0x020 */
61+ 0x00000000, /* 0x024 */
62+ 0x02181E70, /* 0x02C */
63+ 0x00000040, /* 0x030 */
64+ 0x00000024, /* 0x214 */
65+ 0x02001300, /* 0x2E0 */
66+ 0x0E0000A0, /* 0x2E4 */
67+ 0x000E001B, /* 0x2E8 */
68+ 0x35B8C105, /* 0x2EC */
69+ 0x08090408, /* 0x2F0 */
70+ 0x9B000800, /* 0x2F4 */
71+ 0x0E400A00, /* 0x2F8 */
72+ 0x9971452F, /* tRFC */
73+ 0x000071C1 /* PLL */
74+};
75+
76+static const u32 ast2500_ddr4_1600_timing_table[REGTBL_NUM] = {
77+ 0x63604E37, /* 0x010 */
78+ 0xE97AFA99, /* 0x014 */
79+ 0x00019000, /* 0x018 */
80+ 0x08000000, /* 0x020 */
81+ 0x00000400, /* 0x024 */
82+ 0x00000410, /* 0x02C */
83+ 0x00000101, /* 0x030 */
84+ 0x00000024, /* 0x214 */
85+ 0x03002900, /* 0x2E0 */
86+ 0x0E0000A0, /* 0x2E4 */
87+ 0x000E001C, /* 0x2E8 */
88+ 0x35B8C106, /* 0x2EC */
89+ 0x08080607, /* 0x2F0 */
90+ 0x9B000900, /* 0x2F4 */
91+ 0x0E400A00, /* 0x2F8 */
92+ 0x99714545, /* tRFC */
93+ 0x000071C1 /* PLL */
94+};
95+
96 #endif
97diff --git a/drivers/gpu/drm/ast/ast_post.c b/drivers/gpu/drm/ast/ast_post.c
Joel Stanley8d5acef2017-03-15 16:24:09 +103098index 3716795d27c8..f7d421359d56 100644
Joel Stanleye50183f2017-02-28 12:17:46 +103099--- a/drivers/gpu/drm/ast/ast_post.c
100+++ b/drivers/gpu/drm/ast/ast_post.c
101@@ -32,6 +32,7 @@
102 #include "ast_dram_tables.h"
103
104 static void ast_post_chip_2300(struct drm_device *dev);
105+static void ast_post_chip_2500(struct drm_device *dev);
106
107 void ast_enable_vga(struct drm_device *dev)
108 {
Joel Stanley8d5acef2017-03-15 16:24:09 +1030109@@ -78,7 +79,8 @@ ast_set_def_ext_reg(struct drm_device *dev)
Joel Stanleye50183f2017-02-28 12:17:46 +1030110 for (i = 0x81; i <= 0x9f; i++)
111 ast_set_index_reg(ast, AST_IO_CRTC_PORT, i, 0x00);
112
113- if (ast->chip == AST2300 || ast->chip == AST2400) {
114+ if (ast->chip == AST2300 || ast->chip == AST2400 ||
115+ ast->chip == AST2500) {
116 if (dev->pdev->revision >= 0x20)
117 ext_reg_info = extreginfo_ast2300;
118 else
Joel Stanley8d5acef2017-03-15 16:24:09 +1030119@@ -102,7 +104,8 @@ ast_set_def_ext_reg(struct drm_device *dev)
Joel Stanleye50183f2017-02-28 12:17:46 +1030120
121 /* Enable RAMDAC for A1 */
122 reg = 0x04;
123- if (ast->chip == AST2300 || ast->chip == AST2400)
124+ if (ast->chip == AST2300 || ast->chip == AST2400 ||
125+ ast->chip == AST2500)
126 reg |= 0x20;
127 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb6, 0xff, reg);
128 }
Joel Stanley8d5acef2017-03-15 16:24:09 +1030129@@ -376,7 +379,9 @@ void ast_post_gpu(struct drm_device *dev)
Joel Stanleye50183f2017-02-28 12:17:46 +1030130 ast_set_def_ext_reg(dev);
131
132 if (ast->config_mode == ast_use_p2a) {
133- if (ast->chip == AST2300 || ast->chip == AST2400)
134+ if (ast->chip == AST2500)
135+ ast_post_chip_2500(dev);
136+ else if (ast->chip == AST2300 || ast->chip == AST2400)
137 ast_post_chip_2300(dev);
138 else
139 ast_init_dram_reg(dev);
Joel Stanley8d5acef2017-03-15 16:24:09 +1030140@@ -502,6 +507,11 @@ static u32 mmc_test_single2(struct ast_private *ast, u32 datagen)
Joel Stanleye50183f2017-02-28 12:17:46 +1030141 return mmc_test2(ast, datagen, 0x05);
142 }
143
144+static bool mmc_test_single_2500(struct ast_private *ast, u32 datagen)
145+{
146+ return mmc_test(ast, datagen, 0x85);
147+}
148+
149 static int cbr_test(struct ast_private *ast)
150 {
151 u32 data;
Joel Stanley8d5acef2017-03-15 16:24:09 +1030152@@ -1668,3 +1678,404 @@ static void ast_post_chip_2300(struct drm_device *dev)
Joel Stanleye50183f2017-02-28 12:17:46 +1030153 } while ((reg & 0x40) == 0);
154 }
155
156+static bool cbr_test_2500(struct ast_private *ast)
157+{
158+ ast_moutdwm(ast, 0x1E6E0074, 0x0000FFFF);
159+ ast_moutdwm(ast, 0x1E6E007C, 0xFF00FF00);
160+ if (!mmc_test_burst(ast, 0))
161+ return false;
162+ if (!mmc_test_single_2500(ast, 0))
163+ return false;
164+ return true;
165+}
166+
167+static bool ddr_test_2500(struct ast_private *ast)
168+{
169+ ast_moutdwm(ast, 0x1E6E0074, 0x0000FFFF);
170+ ast_moutdwm(ast, 0x1E6E007C, 0xFF00FF00);
171+ if (!mmc_test_burst(ast, 0))
172+ return false;
173+ if (!mmc_test_burst(ast, 1))
174+ return false;
175+ if (!mmc_test_burst(ast, 2))
176+ return false;
177+ if (!mmc_test_burst(ast, 3))
178+ return false;
179+ if (!mmc_test_single_2500(ast, 0))
180+ return false;
181+ return true;
182+}
183+
184+static void ddr_init_common_2500(struct ast_private *ast)
185+{
186+ ast_moutdwm(ast, 0x1E6E0034, 0x00020080);
187+ ast_moutdwm(ast, 0x1E6E0008, 0x2003000F);
188+ ast_moutdwm(ast, 0x1E6E0038, 0x00000FFF);
189+ ast_moutdwm(ast, 0x1E6E0040, 0x88448844);
190+ ast_moutdwm(ast, 0x1E6E0044, 0x24422288);
191+ ast_moutdwm(ast, 0x1E6E0048, 0x22222222);
192+ ast_moutdwm(ast, 0x1E6E004C, 0x22222222);
193+ ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
194+ ast_moutdwm(ast, 0x1E6E0208, 0x00000000);
195+ ast_moutdwm(ast, 0x1E6E0218, 0x00000000);
196+ ast_moutdwm(ast, 0x1E6E0220, 0x00000000);
197+ ast_moutdwm(ast, 0x1E6E0228, 0x00000000);
198+ ast_moutdwm(ast, 0x1E6E0230, 0x00000000);
199+ ast_moutdwm(ast, 0x1E6E02A8, 0x00000000);
200+ ast_moutdwm(ast, 0x1E6E02B0, 0x00000000);
201+ ast_moutdwm(ast, 0x1E6E0240, 0x86000000);
202+ ast_moutdwm(ast, 0x1E6E0244, 0x00008600);
203+ ast_moutdwm(ast, 0x1E6E0248, 0x80000000);
204+ ast_moutdwm(ast, 0x1E6E024C, 0x80808080);
205+}
206+
207+static void ddr_phy_init_2500(struct ast_private *ast)
208+{
209+ u32 data, pass, timecnt;
210+
211+ pass = 0;
212+ ast_moutdwm(ast, 0x1E6E0060, 0x00000005);
213+ while (!pass) {
214+ for (timecnt = 0; timecnt < TIMEOUT; timecnt++) {
215+ data = ast_mindwm(ast, 0x1E6E0060) & 0x1;
216+ if (!data)
217+ break;
218+ }
219+ if (timecnt != TIMEOUT) {
220+ data = ast_mindwm(ast, 0x1E6E0300) & 0x000A0000;
221+ if (!data)
222+ pass = 1;
223+ }
224+ if (!pass) {
225+ ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
226+ udelay(10); /* delay 10 us */
227+ ast_moutdwm(ast, 0x1E6E0060, 0x00000005);
228+ }
229+ }
230+
231+ ast_moutdwm(ast, 0x1E6E0060, 0x00000006);
232+}
233+
234+/*
235+ * Check DRAM Size
236+ * 1Gb : 0x80000000 ~ 0x87FFFFFF
237+ * 2Gb : 0x80000000 ~ 0x8FFFFFFF
238+ * 4Gb : 0x80000000 ~ 0x9FFFFFFF
239+ * 8Gb : 0x80000000 ~ 0xBFFFFFFF
240+ */
241+static void check_dram_size_2500(struct ast_private *ast, u32 tRFC)
242+{
243+ u32 reg_04, reg_14;
244+
245+ reg_04 = ast_mindwm(ast, 0x1E6E0004) & 0xfffffffc;
246+ reg_14 = ast_mindwm(ast, 0x1E6E0014) & 0xffffff00;
247+
248+ ast_moutdwm(ast, 0xA0100000, 0x41424344);
249+ ast_moutdwm(ast, 0x90100000, 0x35363738);
250+ ast_moutdwm(ast, 0x88100000, 0x292A2B2C);
251+ ast_moutdwm(ast, 0x80100000, 0x1D1E1F10);
252+
253+ /* Check 8Gbit */
254+ if (ast_mindwm(ast, 0xA0100000) == 0x41424344) {
255+ reg_04 |= 0x03;
256+ reg_14 |= (tRFC >> 24) & 0xFF;
257+ /* Check 4Gbit */
258+ } else if (ast_mindwm(ast, 0x90100000) == 0x35363738) {
259+ reg_04 |= 0x02;
260+ reg_14 |= (tRFC >> 16) & 0xFF;
261+ /* Check 2Gbit */
262+ } else if (ast_mindwm(ast, 0x88100000) == 0x292A2B2C) {
263+ reg_04 |= 0x01;
264+ reg_14 |= (tRFC >> 8) & 0xFF;
265+ } else {
266+ reg_14 |= tRFC & 0xFF;
267+ }
268+ ast_moutdwm(ast, 0x1E6E0004, reg_04);
269+ ast_moutdwm(ast, 0x1E6E0014, reg_14);
270+}
271+
272+static void enable_cache_2500(struct ast_private *ast)
273+{
274+ u32 reg_04, data;
275+
276+ reg_04 = ast_mindwm(ast, 0x1E6E0004);
277+ ast_moutdwm(ast, 0x1E6E0004, reg_04 | 0x1000);
278+
279+ do
280+ data = ast_mindwm(ast, 0x1E6E0004);
281+ while (!(data & 0x80000));
282+ ast_moutdwm(ast, 0x1E6E0004, reg_04 | 0x400);
283+}
284+
285+static void set_mpll_2500(struct ast_private *ast)
286+{
287+ u32 addr, data, param;
288+
289+ /* Reset MMC */
290+ ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
291+ ast_moutdwm(ast, 0x1E6E0034, 0x00020080);
292+ for (addr = 0x1e6e0004; addr < 0x1e6e0090;) {
293+ ast_moutdwm(ast, addr, 0x0);
294+ addr += 4;
295+ }
296+ ast_moutdwm(ast, 0x1E6E0034, 0x00020000);
297+
298+ ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
299+ data = ast_mindwm(ast, 0x1E6E2070) & 0x00800000;
300+ if (data) {
301+ /* CLKIN = 25MHz */
302+ param = 0x930023E0;
303+ ast_moutdwm(ast, 0x1E6E2160, 0x00011320);
304+ } else {
305+ /* CLKIN = 24MHz */
306+ param = 0x93002400;
307+ }
308+ ast_moutdwm(ast, 0x1E6E2020, param);
309+ udelay(100);
310+}
311+
312+static void reset_mmc_2500(struct ast_private *ast)
313+{
314+ ast_moutdwm(ast, 0x1E78505C, 0x00000004);
315+ ast_moutdwm(ast, 0x1E785044, 0x00000001);
316+ ast_moutdwm(ast, 0x1E785048, 0x00004755);
317+ ast_moutdwm(ast, 0x1E78504C, 0x00000013);
318+ mdelay(100);
319+ ast_moutdwm(ast, 0x1E785054, 0x00000077);
320+ ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
321+}
322+
323+static void ddr3_init_2500(struct ast_private *ast, const u32 *ddr_table)
324+{
325+
326+ ast_moutdwm(ast, 0x1E6E0004, 0x00000303);
327+ ast_moutdwm(ast, 0x1E6E0010, ddr_table[REGIDX_010]);
328+ ast_moutdwm(ast, 0x1E6E0014, ddr_table[REGIDX_014]);
329+ ast_moutdwm(ast, 0x1E6E0018, ddr_table[REGIDX_018]);
330+ ast_moutdwm(ast, 0x1E6E0020, ddr_table[REGIDX_020]); /* MODEREG4/6 */
331+ ast_moutdwm(ast, 0x1E6E0024, ddr_table[REGIDX_024]); /* MODEREG5 */
332+ ast_moutdwm(ast, 0x1E6E002C, ddr_table[REGIDX_02C] | 0x100); /* MODEREG0/2 */
333+ ast_moutdwm(ast, 0x1E6E0030, ddr_table[REGIDX_030]); /* MODEREG1/3 */
334+
335+ /* DDR PHY Setting */
336+ ast_moutdwm(ast, 0x1E6E0200, 0x02492AAE);
337+ ast_moutdwm(ast, 0x1E6E0204, 0x00001001);
338+ ast_moutdwm(ast, 0x1E6E020C, 0x55E00B0B);
339+ ast_moutdwm(ast, 0x1E6E0210, 0x20000000);
340+ ast_moutdwm(ast, 0x1E6E0214, ddr_table[REGIDX_214]);
341+ ast_moutdwm(ast, 0x1E6E02E0, ddr_table[REGIDX_2E0]);
342+ ast_moutdwm(ast, 0x1E6E02E4, ddr_table[REGIDX_2E4]);
343+ ast_moutdwm(ast, 0x1E6E02E8, ddr_table[REGIDX_2E8]);
344+ ast_moutdwm(ast, 0x1E6E02EC, ddr_table[REGIDX_2EC]);
345+ ast_moutdwm(ast, 0x1E6E02F0, ddr_table[REGIDX_2F0]);
346+ ast_moutdwm(ast, 0x1E6E02F4, ddr_table[REGIDX_2F4]);
347+ ast_moutdwm(ast, 0x1E6E02F8, ddr_table[REGIDX_2F8]);
348+ ast_moutdwm(ast, 0x1E6E0290, 0x00100008);
349+ ast_moutdwm(ast, 0x1E6E02C0, 0x00000006);
350+
351+ /* Controller Setting */
352+ ast_moutdwm(ast, 0x1E6E0034, 0x00020091);
353+
354+ /* Wait DDR PHY init done */
355+ ddr_phy_init_2500(ast);
356+
357+ ast_moutdwm(ast, 0x1E6E0120, ddr_table[REGIDX_PLL]);
358+ ast_moutdwm(ast, 0x1E6E000C, 0x42AA5C81);
359+ ast_moutdwm(ast, 0x1E6E0034, 0x0001AF93);
360+
361+ check_dram_size_2500(ast, ddr_table[REGIDX_RFC]);
362+ enable_cache_2500(ast);
363+ ast_moutdwm(ast, 0x1E6E001C, 0x00000008);
364+ ast_moutdwm(ast, 0x1E6E0038, 0xFFFFFF00);
365+}
366+
367+static void ddr4_init_2500(struct ast_private *ast, const u32 *ddr_table)
368+{
369+ u32 data, data2, pass, retrycnt;
370+ u32 ddr_vref, phy_vref;
371+ u32 min_ddr_vref = 0, min_phy_vref = 0;
372+ u32 max_ddr_vref = 0, max_phy_vref = 0;
373+
374+ ast_moutdwm(ast, 0x1E6E0004, 0x00000313);
375+ ast_moutdwm(ast, 0x1E6E0010, ddr_table[REGIDX_010]);
376+ ast_moutdwm(ast, 0x1E6E0014, ddr_table[REGIDX_014]);
377+ ast_moutdwm(ast, 0x1E6E0018, ddr_table[REGIDX_018]);
378+ ast_moutdwm(ast, 0x1E6E0020, ddr_table[REGIDX_020]); /* MODEREG4/6 */
379+ ast_moutdwm(ast, 0x1E6E0024, ddr_table[REGIDX_024]); /* MODEREG5 */
380+ ast_moutdwm(ast, 0x1E6E002C, ddr_table[REGIDX_02C] | 0x100); /* MODEREG0/2 */
381+ ast_moutdwm(ast, 0x1E6E0030, ddr_table[REGIDX_030]); /* MODEREG1/3 */
382+
383+ /* DDR PHY Setting */
384+ ast_moutdwm(ast, 0x1E6E0200, 0x42492AAE);
385+ ast_moutdwm(ast, 0x1E6E0204, 0x09002000);
386+ ast_moutdwm(ast, 0x1E6E020C, 0x55E00B0B);
387+ ast_moutdwm(ast, 0x1E6E0210, 0x20000000);
388+ ast_moutdwm(ast, 0x1E6E0214, ddr_table[REGIDX_214]);
389+ ast_moutdwm(ast, 0x1E6E02E0, ddr_table[REGIDX_2E0]);
390+ ast_moutdwm(ast, 0x1E6E02E4, ddr_table[REGIDX_2E4]);
391+ ast_moutdwm(ast, 0x1E6E02E8, ddr_table[REGIDX_2E8]);
392+ ast_moutdwm(ast, 0x1E6E02EC, ddr_table[REGIDX_2EC]);
393+ ast_moutdwm(ast, 0x1E6E02F0, ddr_table[REGIDX_2F0]);
394+ ast_moutdwm(ast, 0x1E6E02F4, ddr_table[REGIDX_2F4]);
395+ ast_moutdwm(ast, 0x1E6E02F8, ddr_table[REGIDX_2F8]);
396+ ast_moutdwm(ast, 0x1E6E0290, 0x00100008);
397+ ast_moutdwm(ast, 0x1E6E02C4, 0x3C183C3C);
398+ ast_moutdwm(ast, 0x1E6E02C8, 0x00631E0E);
399+
400+ /* Controller Setting */
401+ ast_moutdwm(ast, 0x1E6E0034, 0x0001A991);
402+
403+ /* Train PHY Vref first */
404+ pass = 0;
405+
406+ for (retrycnt = 0; retrycnt < 4 && pass == 0; retrycnt++) {
407+ max_phy_vref = 0x0;
408+ pass = 0;
409+ ast_moutdwm(ast, 0x1E6E02C0, 0x00001C06);
410+ for (phy_vref = 0x40; phy_vref < 0x80; phy_vref++) {
411+ ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
412+ ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
413+ ast_moutdwm(ast, 0x1E6E02CC, phy_vref | (phy_vref << 8));
414+ /* Fire DFI Init */
415+ ddr_phy_init_2500(ast);
416+ ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
417+ if (cbr_test_2500(ast)) {
418+ pass++;
419+ data = ast_mindwm(ast, 0x1E6E03D0);
420+ data2 = data >> 8;
421+ data = data & 0xff;
422+ if (data > data2)
423+ data = data2;
424+ if (max_phy_vref < data) {
425+ max_phy_vref = data;
426+ min_phy_vref = phy_vref;
427+ }
428+ } else if (pass > 0)
429+ break;
430+ }
431+ }
432+ ast_moutdwm(ast, 0x1E6E02CC, min_phy_vref | (min_phy_vref << 8));
433+
434+ /* Train DDR Vref next */
435+ pass = 0;
436+
437+ for (retrycnt = 0; retrycnt < 4 && pass == 0; retrycnt++) {
438+ min_ddr_vref = 0xFF;
439+ max_ddr_vref = 0x0;
440+ pass = 0;
441+ for (ddr_vref = 0x00; ddr_vref < 0x40; ddr_vref++) {
442+ ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
443+ ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
444+ ast_moutdwm(ast, 0x1E6E02C0, 0x00000006 | (ddr_vref << 8));
445+ /* Fire DFI Init */
446+ ddr_phy_init_2500(ast);
447+ ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
448+ if (cbr_test_2500(ast)) {
449+ pass++;
450+ if (min_ddr_vref > ddr_vref)
451+ min_ddr_vref = ddr_vref;
452+ if (max_ddr_vref < ddr_vref)
453+ max_ddr_vref = ddr_vref;
454+ } else if (pass != 0)
455+ break;
456+ }
457+ }
458+
459+ ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
460+ ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
461+ ddr_vref = (min_ddr_vref + max_ddr_vref + 1) >> 1;
462+ ast_moutdwm(ast, 0x1E6E02C0, 0x00000006 | (ddr_vref << 8));
463+
464+ /* Wait DDR PHY init done */
465+ ddr_phy_init_2500(ast);
466+
467+ ast_moutdwm(ast, 0x1E6E0120, ddr_table[REGIDX_PLL]);
468+ ast_moutdwm(ast, 0x1E6E000C, 0x42AA5C81);
469+ ast_moutdwm(ast, 0x1E6E0034, 0x0001AF93);
470+
471+ check_dram_size_2500(ast, ddr_table[REGIDX_RFC]);
472+ enable_cache_2500(ast);
473+ ast_moutdwm(ast, 0x1E6E001C, 0x00000008);
474+ ast_moutdwm(ast, 0x1E6E0038, 0xFFFFFF00);
475+}
476+
477+static bool ast_dram_init_2500(struct ast_private *ast)
478+{
479+ u32 data;
480+ u32 max_tries = 5;
481+
482+ do {
483+ if (max_tries-- == 0)
484+ return false;
485+ set_mpll_2500(ast);
486+ reset_mmc_2500(ast);
487+ ddr_init_common_2500(ast);
488+
489+ data = ast_mindwm(ast, 0x1E6E2070);
490+ if (data & 0x01000000)
491+ ddr4_init_2500(ast, ast2500_ddr4_1600_timing_table);
492+ else
493+ ddr3_init_2500(ast, ast2500_ddr3_1600_timing_table);
494+ } while (!ddr_test_2500(ast));
495+
496+ ast_moutdwm(ast, 0x1E6E2040, ast_mindwm(ast, 0x1E6E2040) | 0x41);
497+
498+ /* Patch code */
499+ data = ast_mindwm(ast, 0x1E6E200C) & 0xF9FFFFFF;
500+ ast_moutdwm(ast, 0x1E6E200C, data | 0x10000000);
501+
502+ return true;
503+}
504+
505+void ast_post_chip_2500(struct drm_device *dev)
506+{
507+ struct ast_private *ast = dev->dev_private;
508+ u32 temp;
509+ u8 reg;
510+
511+ reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
512+ if ((reg & 0x80) == 0) {/* vga only */
513+ /* Clear bus lock condition */
514+ ast_moutdwm(ast, 0x1e600000, 0xAEED1A03);
515+ ast_moutdwm(ast, 0x1e600084, 0x00010000);
516+ ast_moutdwm(ast, 0x1e600088, 0x00000000);
517+ ast_moutdwm(ast, 0x1e6e2000, 0x1688A8A8);
518+ ast_write32(ast, 0xf004, 0x1e6e0000);
519+ ast_write32(ast, 0xf000, 0x1);
520+ ast_write32(ast, 0x12000, 0x1688a8a8);
521+ while (ast_read32(ast, 0x12000) != 0x1)
522+ ;
523+
524+ ast_write32(ast, 0x10000, 0xfc600309);
525+ while (ast_read32(ast, 0x10000) != 0x1)
526+ ;
527+
528+ /* Slow down CPU/AHB CLK in VGA only mode */
529+ temp = ast_read32(ast, 0x12008);
530+ temp |= 0x73;
531+ ast_write32(ast, 0x12008, temp);
532+
533+ /* Reset USB port to patch USB unknown device issue */
534+ ast_moutdwm(ast, 0x1e6e2090, 0x20000000);
535+ temp = ast_mindwm(ast, 0x1e6e2094);
536+ temp |= 0x00004000;
537+ ast_moutdwm(ast, 0x1e6e2094, temp);
538+ temp = ast_mindwm(ast, 0x1e6e2070);
539+ if (temp & 0x00800000) {
540+ ast_moutdwm(ast, 0x1e6e207c, 0x00800000);
541+ mdelay(100);
542+ ast_moutdwm(ast, 0x1e6e2070, 0x00800000);
543+ }
544+
545+ if (!ast_dram_init_2500(ast))
546+ DRM_ERROR("DRAM init failed !\n");
547+
548+ temp = ast_mindwm(ast, 0x1e6e2040);
549+ ast_moutdwm(ast, 0x1e6e2040, temp | 0x40);
550+ }
551+
552+ /* wait ready */
553+ do {
554+ reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
555+ } while ((reg & 0x40) == 0);
556+}
557--
5582.11.0
559