ast_post.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081
  1. /*
  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. #include <drm/drmP.h>
  29. #include "ast_drv.h"
  30. #include "ast_dram_tables.h"
  31. static void ast_post_chip_2300(struct drm_device *dev);
  32. static void ast_post_chip_2500(struct drm_device *dev);
  33. void ast_enable_vga(struct drm_device *dev)
  34. {
  35. struct ast_private *ast = dev->dev_private;
  36. ast_io_write8(ast, AST_IO_VGA_ENABLE_PORT, 0x01);
  37. ast_io_write8(ast, AST_IO_MISC_PORT_WRITE, 0x01);
  38. }
  39. void ast_enable_mmio(struct drm_device *dev)
  40. {
  41. struct ast_private *ast = dev->dev_private;
  42. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xa1, 0xff, 0x04);
  43. }
  44. bool ast_is_vga_enabled(struct drm_device *dev)
  45. {
  46. struct ast_private *ast = dev->dev_private;
  47. u8 ch;
  48. if (ast->chip == AST1180) {
  49. /* TODO 1180 */
  50. } else {
  51. ch = ast_io_read8(ast, AST_IO_VGA_ENABLE_PORT);
  52. return !!(ch & 0x01);
  53. }
  54. return false;
  55. }
  56. static const u8 extreginfo[] = { 0x0f, 0x04, 0x1c, 0xff };
  57. static const u8 extreginfo_ast2300a0[] = { 0x0f, 0x04, 0x1c, 0xff };
  58. static const u8 extreginfo_ast2300[] = { 0x0f, 0x04, 0x1f, 0xff };
  59. static void
  60. ast_set_def_ext_reg(struct drm_device *dev)
  61. {
  62. struct ast_private *ast = dev->dev_private;
  63. u8 i, index, reg;
  64. const u8 *ext_reg_info;
  65. /* reset scratch */
  66. for (i = 0x81; i <= 0x9f; i++)
  67. ast_set_index_reg(ast, AST_IO_CRTC_PORT, i, 0x00);
  68. if (ast->chip == AST2300 || ast->chip == AST2400 ||
  69. ast->chip == AST2500) {
  70. if (dev->pdev->revision >= 0x20)
  71. ext_reg_info = extreginfo_ast2300;
  72. else
  73. ext_reg_info = extreginfo_ast2300a0;
  74. } else
  75. ext_reg_info = extreginfo;
  76. index = 0xa0;
  77. while (*ext_reg_info != 0xff) {
  78. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, index, 0x00, *ext_reg_info);
  79. index++;
  80. ext_reg_info++;
  81. }
  82. /* disable standard IO/MEM decode if secondary */
  83. /* ast_set_index_reg-mask(ast, AST_IO_CRTC_PORT, 0xa1, 0xff, 0x3); */
  84. /* Set Ext. Default */
  85. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x8c, 0x00, 0x01);
  86. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x00, 0x00);
  87. /* Enable RAMDAC for A1 */
  88. reg = 0x04;
  89. if (ast->chip == AST2300 || ast->chip == AST2400 ||
  90. ast->chip == AST2500)
  91. reg |= 0x20;
  92. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb6, 0xff, reg);
  93. }
  94. u32 ast_mindwm(struct ast_private *ast, u32 r)
  95. {
  96. uint32_t data;
  97. ast_write32(ast, 0xf004, r & 0xffff0000);
  98. ast_write32(ast, 0xf000, 0x1);
  99. do {
  100. data = ast_read32(ast, 0xf004) & 0xffff0000;
  101. } while (data != (r & 0xffff0000));
  102. return ast_read32(ast, 0x10000 + (r & 0x0000ffff));
  103. }
  104. void ast_moutdwm(struct ast_private *ast, u32 r, u32 v)
  105. {
  106. uint32_t data;
  107. ast_write32(ast, 0xf004, r & 0xffff0000);
  108. ast_write32(ast, 0xf000, 0x1);
  109. do {
  110. data = ast_read32(ast, 0xf004) & 0xffff0000;
  111. } while (data != (r & 0xffff0000));
  112. ast_write32(ast, 0x10000 + (r & 0x0000ffff), v);
  113. }
  114. /*
  115. * AST2100/2150 DLL CBR Setting
  116. */
  117. #define CBR_SIZE_AST2150 ((16 << 10) - 1)
  118. #define CBR_PASSNUM_AST2150 5
  119. #define CBR_THRESHOLD_AST2150 10
  120. #define CBR_THRESHOLD2_AST2150 10
  121. #define TIMEOUT_AST2150 5000000
  122. #define CBR_PATNUM_AST2150 8
  123. static const u32 pattern_AST2150[14] = {
  124. 0xFF00FF00,
  125. 0xCC33CC33,
  126. 0xAA55AA55,
  127. 0xFFFE0001,
  128. 0x683501FE,
  129. 0x0F1929B0,
  130. 0x2D0B4346,
  131. 0x60767F02,
  132. 0x6FBE36A6,
  133. 0x3A253035,
  134. 0x3019686D,
  135. 0x41C6167E,
  136. 0x620152BF,
  137. 0x20F050E0
  138. };
  139. static u32 mmctestburst2_ast2150(struct ast_private *ast, u32 datagen)
  140. {
  141. u32 data, timeout;
  142. ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
  143. ast_moutdwm(ast, 0x1e6e0070, 0x00000001 | (datagen << 3));
  144. timeout = 0;
  145. do {
  146. data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
  147. if (++timeout > TIMEOUT_AST2150) {
  148. ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
  149. return 0xffffffff;
  150. }
  151. } while (!data);
  152. ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
  153. ast_moutdwm(ast, 0x1e6e0070, 0x00000003 | (datagen << 3));
  154. timeout = 0;
  155. do {
  156. data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
  157. if (++timeout > TIMEOUT_AST2150) {
  158. ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
  159. return 0xffffffff;
  160. }
  161. } while (!data);
  162. data = (ast_mindwm(ast, 0x1e6e0070) & 0x80) >> 7;
  163. ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
  164. return data;
  165. }
  166. #if 0 /* unused in DDX driver - here for completeness */
  167. static u32 mmctestsingle2_ast2150(struct ast_private *ast, u32 datagen)
  168. {
  169. u32 data, timeout;
  170. ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
  171. ast_moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3));
  172. timeout = 0;
  173. do {
  174. data = ast_mindwm(ast, 0x1e6e0070) & 0x40;
  175. if (++timeout > TIMEOUT_AST2150) {
  176. ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
  177. return 0xffffffff;
  178. }
  179. } while (!data);
  180. data = (ast_mindwm(ast, 0x1e6e0070) & 0x80) >> 7;
  181. ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
  182. return data;
  183. }
  184. #endif
  185. static int cbrtest_ast2150(struct ast_private *ast)
  186. {
  187. int i;
  188. for (i = 0; i < 8; i++)
  189. if (mmctestburst2_ast2150(ast, i))
  190. return 0;
  191. return 1;
  192. }
  193. static int cbrscan_ast2150(struct ast_private *ast, int busw)
  194. {
  195. u32 patcnt, loop;
  196. for (patcnt = 0; patcnt < CBR_PATNUM_AST2150; patcnt++) {
  197. ast_moutdwm(ast, 0x1e6e007c, pattern_AST2150[patcnt]);
  198. for (loop = 0; loop < CBR_PASSNUM_AST2150; loop++) {
  199. if (cbrtest_ast2150(ast))
  200. break;
  201. }
  202. if (loop == CBR_PASSNUM_AST2150)
  203. return 0;
  204. }
  205. return 1;
  206. }
  207. static void cbrdlli_ast2150(struct ast_private *ast, int busw)
  208. {
  209. u32 dll_min[4], dll_max[4], dlli, data, passcnt;
  210. cbr_start:
  211. dll_min[0] = dll_min[1] = dll_min[2] = dll_min[3] = 0xff;
  212. dll_max[0] = dll_max[1] = dll_max[2] = dll_max[3] = 0x0;
  213. passcnt = 0;
  214. for (dlli = 0; dlli < 100; dlli++) {
  215. ast_moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24));
  216. data = cbrscan_ast2150(ast, busw);
  217. if (data != 0) {
  218. if (data & 0x1) {
  219. if (dll_min[0] > dlli)
  220. dll_min[0] = dlli;
  221. if (dll_max[0] < dlli)
  222. dll_max[0] = dlli;
  223. }
  224. passcnt++;
  225. } else if (passcnt >= CBR_THRESHOLD_AST2150)
  226. goto cbr_start;
  227. }
  228. if (dll_max[0] == 0 || (dll_max[0]-dll_min[0]) < CBR_THRESHOLD_AST2150)
  229. goto cbr_start;
  230. dlli = dll_min[0] + (((dll_max[0] - dll_min[0]) * 7) >> 4);
  231. ast_moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24));
  232. }
  233. static void ast_init_dram_reg(struct drm_device *dev)
  234. {
  235. struct ast_private *ast = dev->dev_private;
  236. u8 j;
  237. u32 data, temp, i;
  238. const struct ast_dramstruct *dram_reg_info;
  239. j = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
  240. if ((j & 0x80) == 0) { /* VGA only */
  241. if (ast->chip == AST2000) {
  242. dram_reg_info = ast2000_dram_table_data;
  243. ast_write32(ast, 0xf004, 0x1e6e0000);
  244. ast_write32(ast, 0xf000, 0x1);
  245. ast_write32(ast, 0x10100, 0xa8);
  246. do {
  247. ;
  248. } while (ast_read32(ast, 0x10100) != 0xa8);
  249. } else {/* AST2100/1100 */
  250. if (ast->chip == AST2100 || ast->chip == 2200)
  251. dram_reg_info = ast2100_dram_table_data;
  252. else
  253. dram_reg_info = ast1100_dram_table_data;
  254. ast_write32(ast, 0xf004, 0x1e6e0000);
  255. ast_write32(ast, 0xf000, 0x1);
  256. ast_write32(ast, 0x12000, 0x1688A8A8);
  257. do {
  258. ;
  259. } while (ast_read32(ast, 0x12000) != 0x01);
  260. ast_write32(ast, 0x10000, 0xfc600309);
  261. do {
  262. ;
  263. } while (ast_read32(ast, 0x10000) != 0x01);
  264. }
  265. while (dram_reg_info->index != 0xffff) {
  266. if (dram_reg_info->index == 0xff00) {/* delay fn */
  267. for (i = 0; i < 15; i++)
  268. udelay(dram_reg_info->data);
  269. } else if (dram_reg_info->index == 0x4 && ast->chip != AST2000) {
  270. data = dram_reg_info->data;
  271. if (ast->dram_type == AST_DRAM_1Gx16)
  272. data = 0x00000d89;
  273. else if (ast->dram_type == AST_DRAM_1Gx32)
  274. data = 0x00000c8d;
  275. temp = ast_read32(ast, 0x12070);
  276. temp &= 0xc;
  277. temp <<= 2;
  278. ast_write32(ast, 0x10000 + dram_reg_info->index, data | temp);
  279. } else
  280. ast_write32(ast, 0x10000 + dram_reg_info->index, dram_reg_info->data);
  281. dram_reg_info++;
  282. }
  283. /* AST 2100/2150 DRAM calibration */
  284. data = ast_read32(ast, 0x10120);
  285. if (data == 0x5061) { /* 266Mhz */
  286. data = ast_read32(ast, 0x10004);
  287. if (data & 0x40)
  288. cbrdlli_ast2150(ast, 16); /* 16 bits */
  289. else
  290. cbrdlli_ast2150(ast, 32); /* 32 bits */
  291. }
  292. switch (ast->chip) {
  293. case AST2000:
  294. temp = ast_read32(ast, 0x10140);
  295. ast_write32(ast, 0x10140, temp | 0x40);
  296. break;
  297. case AST1100:
  298. case AST2100:
  299. case AST2200:
  300. case AST2150:
  301. temp = ast_read32(ast, 0x1200c);
  302. ast_write32(ast, 0x1200c, temp & 0xfffffffd);
  303. temp = ast_read32(ast, 0x12040);
  304. ast_write32(ast, 0x12040, temp | 0x40);
  305. break;
  306. default:
  307. break;
  308. }
  309. }
  310. /* wait ready */
  311. do {
  312. j = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
  313. } while ((j & 0x40) == 0);
  314. }
  315. void ast_post_gpu(struct drm_device *dev)
  316. {
  317. u32 reg;
  318. struct ast_private *ast = dev->dev_private;
  319. pci_read_config_dword(ast->dev->pdev, 0x04, &reg);
  320. reg |= 0x3;
  321. pci_write_config_dword(ast->dev->pdev, 0x04, reg);
  322. ast_enable_vga(dev);
  323. ast_open_key(ast);
  324. ast_enable_mmio(dev);
  325. ast_set_def_ext_reg(dev);
  326. if (ast->config_mode == ast_use_p2a) {
  327. if (ast->chip == AST2500)
  328. ast_post_chip_2500(dev);
  329. else if (ast->chip == AST2300 || ast->chip == AST2400)
  330. ast_post_chip_2300(dev);
  331. else
  332. ast_init_dram_reg(dev);
  333. ast_init_3rdtx(dev);
  334. } else {
  335. if (ast->tx_chip_type != AST_TX_NONE)
  336. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xa3, 0xcf, 0x80); /* Enable DVO */
  337. }
  338. }
  339. /* AST 2300 DRAM settings */
  340. #define AST_DDR3 0
  341. #define AST_DDR2 1
  342. struct ast2300_dram_param {
  343. u32 dram_type;
  344. u32 dram_chipid;
  345. u32 dram_freq;
  346. u32 vram_size;
  347. u32 odt;
  348. u32 wodt;
  349. u32 rodt;
  350. u32 dram_config;
  351. u32 reg_PERIOD;
  352. u32 reg_MADJ;
  353. u32 reg_SADJ;
  354. u32 reg_MRS;
  355. u32 reg_EMRS;
  356. u32 reg_AC1;
  357. u32 reg_AC2;
  358. u32 reg_DQSIC;
  359. u32 reg_DRV;
  360. u32 reg_IOZ;
  361. u32 reg_DQIDLY;
  362. u32 reg_FREQ;
  363. u32 madj_max;
  364. u32 dll2_finetune_step;
  365. };
  366. /*
  367. * DQSI DLL CBR Setting
  368. */
  369. #define CBR_SIZE0 ((1 << 10) - 1)
  370. #define CBR_SIZE1 ((4 << 10) - 1)
  371. #define CBR_SIZE2 ((64 << 10) - 1)
  372. #define CBR_PASSNUM 5
  373. #define CBR_PASSNUM2 5
  374. #define CBR_THRESHOLD 10
  375. #define CBR_THRESHOLD2 10
  376. #define TIMEOUT 5000000
  377. #define CBR_PATNUM 8
  378. static const u32 pattern[8] = {
  379. 0xFF00FF00,
  380. 0xCC33CC33,
  381. 0xAA55AA55,
  382. 0x88778877,
  383. 0x92CC4D6E,
  384. 0x543D3CDE,
  385. 0xF1E843C7,
  386. 0x7C61D253
  387. };
  388. static bool mmc_test(struct ast_private *ast, u32 datagen, u8 test_ctl)
  389. {
  390. u32 data, timeout;
  391. ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
  392. ast_moutdwm(ast, 0x1e6e0070, (datagen << 3) | test_ctl);
  393. timeout = 0;
  394. do {
  395. data = ast_mindwm(ast, 0x1e6e0070) & 0x3000;
  396. if (data & 0x2000)
  397. return false;
  398. if (++timeout > TIMEOUT) {
  399. ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
  400. return false;
  401. }
  402. } while (!data);
  403. ast_moutdwm(ast, 0x1e6e0070, 0x0);
  404. return true;
  405. }
  406. static u32 mmc_test2(struct ast_private *ast, u32 datagen, u8 test_ctl)
  407. {
  408. u32 data, timeout;
  409. ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
  410. ast_moutdwm(ast, 0x1e6e0070, (datagen << 3) | test_ctl);
  411. timeout = 0;
  412. do {
  413. data = ast_mindwm(ast, 0x1e6e0070) & 0x1000;
  414. if (++timeout > TIMEOUT) {
  415. ast_moutdwm(ast, 0x1e6e0070, 0x0);
  416. return 0xffffffff;
  417. }
  418. } while (!data);
  419. data = ast_mindwm(ast, 0x1e6e0078);
  420. data = (data | (data >> 16)) & 0xffff;
  421. ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
  422. return data;
  423. }
  424. static bool mmc_test_burst(struct ast_private *ast, u32 datagen)
  425. {
  426. return mmc_test(ast, datagen, 0xc1);
  427. }
  428. static u32 mmc_test_burst2(struct ast_private *ast, u32 datagen)
  429. {
  430. return mmc_test2(ast, datagen, 0x41);
  431. }
  432. static bool mmc_test_single(struct ast_private *ast, u32 datagen)
  433. {
  434. return mmc_test(ast, datagen, 0xc5);
  435. }
  436. static u32 mmc_test_single2(struct ast_private *ast, u32 datagen)
  437. {
  438. return mmc_test2(ast, datagen, 0x05);
  439. }
  440. static bool mmc_test_single_2500(struct ast_private *ast, u32 datagen)
  441. {
  442. return mmc_test(ast, datagen, 0x85);
  443. }
  444. static int cbr_test(struct ast_private *ast)
  445. {
  446. u32 data;
  447. int i;
  448. data = mmc_test_single2(ast, 0);
  449. if ((data & 0xff) && (data & 0xff00))
  450. return 0;
  451. for (i = 0; i < 8; i++) {
  452. data = mmc_test_burst2(ast, i);
  453. if ((data & 0xff) && (data & 0xff00))
  454. return 0;
  455. }
  456. if (!data)
  457. return 3;
  458. else if (data & 0xff)
  459. return 2;
  460. return 1;
  461. }
  462. static int cbr_scan(struct ast_private *ast)
  463. {
  464. u32 data, data2, patcnt, loop;
  465. data2 = 3;
  466. for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
  467. ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
  468. for (loop = 0; loop < CBR_PASSNUM2; loop++) {
  469. if ((data = cbr_test(ast)) != 0) {
  470. data2 &= data;
  471. if (!data2)
  472. return 0;
  473. break;
  474. }
  475. }
  476. if (loop == CBR_PASSNUM2)
  477. return 0;
  478. }
  479. return data2;
  480. }
  481. static u32 cbr_test2(struct ast_private *ast)
  482. {
  483. u32 data;
  484. data = mmc_test_burst2(ast, 0);
  485. if (data == 0xffff)
  486. return 0;
  487. data |= mmc_test_single2(ast, 0);
  488. if (data == 0xffff)
  489. return 0;
  490. return ~data & 0xffff;
  491. }
  492. static u32 cbr_scan2(struct ast_private *ast)
  493. {
  494. u32 data, data2, patcnt, loop;
  495. data2 = 0xffff;
  496. for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
  497. ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
  498. for (loop = 0; loop < CBR_PASSNUM2; loop++) {
  499. if ((data = cbr_test2(ast)) != 0) {
  500. data2 &= data;
  501. if (!data2)
  502. return 0;
  503. break;
  504. }
  505. }
  506. if (loop == CBR_PASSNUM2)
  507. return 0;
  508. }
  509. return data2;
  510. }
  511. static bool cbr_test3(struct ast_private *ast)
  512. {
  513. if (!mmc_test_burst(ast, 0))
  514. return false;
  515. if (!mmc_test_single(ast, 0))
  516. return false;
  517. return true;
  518. }
  519. static bool cbr_scan3(struct ast_private *ast)
  520. {
  521. u32 patcnt, loop;
  522. for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) {
  523. ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]);
  524. for (loop = 0; loop < 2; loop++) {
  525. if (cbr_test3(ast))
  526. break;
  527. }
  528. if (loop == 2)
  529. return false;
  530. }
  531. return true;
  532. }
  533. static bool finetuneDQI_L(struct ast_private *ast, struct ast2300_dram_param *param)
  534. {
  535. u32 gold_sadj[2], dllmin[16], dllmax[16], dlli, data, cnt, mask, passcnt, retry = 0;
  536. bool status = false;
  537. FINETUNE_START:
  538. for (cnt = 0; cnt < 16; cnt++) {
  539. dllmin[cnt] = 0xff;
  540. dllmax[cnt] = 0x0;
  541. }
  542. passcnt = 0;
  543. for (dlli = 0; dlli < 76; dlli++) {
  544. ast_moutdwm(ast, 0x1E6E0068, 0x00001400 | (dlli << 16) | (dlli << 24));
  545. ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE1);
  546. data = cbr_scan2(ast);
  547. if (data != 0) {
  548. mask = 0x00010001;
  549. for (cnt = 0; cnt < 16; cnt++) {
  550. if (data & mask) {
  551. if (dllmin[cnt] > dlli) {
  552. dllmin[cnt] = dlli;
  553. }
  554. if (dllmax[cnt] < dlli) {
  555. dllmax[cnt] = dlli;
  556. }
  557. }
  558. mask <<= 1;
  559. }
  560. passcnt++;
  561. } else if (passcnt >= CBR_THRESHOLD2) {
  562. break;
  563. }
  564. }
  565. gold_sadj[0] = 0x0;
  566. passcnt = 0;
  567. for (cnt = 0; cnt < 16; cnt++) {
  568. if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
  569. gold_sadj[0] += dllmin[cnt];
  570. passcnt++;
  571. }
  572. }
  573. if (retry++ > 10)
  574. goto FINETUNE_DONE;
  575. if (passcnt != 16) {
  576. goto FINETUNE_START;
  577. }
  578. status = true;
  579. FINETUNE_DONE:
  580. gold_sadj[0] = gold_sadj[0] >> 4;
  581. gold_sadj[1] = gold_sadj[0];
  582. data = 0;
  583. for (cnt = 0; cnt < 8; cnt++) {
  584. data >>= 3;
  585. if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
  586. dlli = dllmin[cnt];
  587. if (gold_sadj[0] >= dlli) {
  588. dlli = ((gold_sadj[0] - dlli) * 19) >> 5;
  589. if (dlli > 3) {
  590. dlli = 3;
  591. }
  592. } else {
  593. dlli = ((dlli - gold_sadj[0]) * 19) >> 5;
  594. if (dlli > 4) {
  595. dlli = 4;
  596. }
  597. dlli = (8 - dlli) & 0x7;
  598. }
  599. data |= dlli << 21;
  600. }
  601. }
  602. ast_moutdwm(ast, 0x1E6E0080, data);
  603. data = 0;
  604. for (cnt = 8; cnt < 16; cnt++) {
  605. data >>= 3;
  606. if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) {
  607. dlli = dllmin[cnt];
  608. if (gold_sadj[1] >= dlli) {
  609. dlli = ((gold_sadj[1] - dlli) * 19) >> 5;
  610. if (dlli > 3) {
  611. dlli = 3;
  612. } else {
  613. dlli = (dlli - 1) & 0x7;
  614. }
  615. } else {
  616. dlli = ((dlli - gold_sadj[1]) * 19) >> 5;
  617. dlli += 1;
  618. if (dlli > 4) {
  619. dlli = 4;
  620. }
  621. dlli = (8 - dlli) & 0x7;
  622. }
  623. data |= dlli << 21;
  624. }
  625. }
  626. ast_moutdwm(ast, 0x1E6E0084, data);
  627. return status;
  628. } /* finetuneDQI_L */
  629. static void finetuneDQSI(struct ast_private *ast)
  630. {
  631. u32 dlli, dqsip, dqidly;
  632. u32 reg_mcr18, reg_mcr0c, passcnt[2], diff;
  633. u32 g_dqidly, g_dqsip, g_margin, g_side;
  634. u16 pass[32][2][2];
  635. char tag[2][76];
  636. /* Disable DQI CBR */
  637. reg_mcr0c = ast_mindwm(ast, 0x1E6E000C);
  638. reg_mcr18 = ast_mindwm(ast, 0x1E6E0018);
  639. reg_mcr18 &= 0x0000ffff;
  640. ast_moutdwm(ast, 0x1E6E0018, reg_mcr18);
  641. for (dlli = 0; dlli < 76; dlli++) {
  642. tag[0][dlli] = 0x0;
  643. tag[1][dlli] = 0x0;
  644. }
  645. for (dqidly = 0; dqidly < 32; dqidly++) {
  646. pass[dqidly][0][0] = 0xff;
  647. pass[dqidly][0][1] = 0x0;
  648. pass[dqidly][1][0] = 0xff;
  649. pass[dqidly][1][1] = 0x0;
  650. }
  651. for (dqidly = 0; dqidly < 32; dqidly++) {
  652. passcnt[0] = passcnt[1] = 0;
  653. for (dqsip = 0; dqsip < 2; dqsip++) {
  654. ast_moutdwm(ast, 0x1E6E000C, 0);
  655. ast_moutdwm(ast, 0x1E6E0018, reg_mcr18 | (dqidly << 16) | (dqsip << 23));
  656. ast_moutdwm(ast, 0x1E6E000C, reg_mcr0c);
  657. for (dlli = 0; dlli < 76; dlli++) {
  658. ast_moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24));
  659. ast_moutdwm(ast, 0x1E6E0070, 0);
  660. ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE0);
  661. if (cbr_scan3(ast)) {
  662. if (dlli == 0)
  663. break;
  664. passcnt[dqsip]++;
  665. tag[dqsip][dlli] = 'P';
  666. if (dlli < pass[dqidly][dqsip][0])
  667. pass[dqidly][dqsip][0] = (u16) dlli;
  668. if (dlli > pass[dqidly][dqsip][1])
  669. pass[dqidly][dqsip][1] = (u16) dlli;
  670. } else if (passcnt[dqsip] >= 5)
  671. break;
  672. else {
  673. pass[dqidly][dqsip][0] = 0xff;
  674. pass[dqidly][dqsip][1] = 0x0;
  675. }
  676. }
  677. }
  678. if (passcnt[0] == 0 && passcnt[1] == 0)
  679. dqidly++;
  680. }
  681. /* Search margin */
  682. g_dqidly = g_dqsip = g_margin = g_side = 0;
  683. for (dqidly = 0; dqidly < 32; dqidly++) {
  684. for (dqsip = 0; dqsip < 2; dqsip++) {
  685. if (pass[dqidly][dqsip][0] > pass[dqidly][dqsip][1])
  686. continue;
  687. diff = pass[dqidly][dqsip][1] - pass[dqidly][dqsip][0];
  688. if ((diff+2) < g_margin)
  689. continue;
  690. passcnt[0] = passcnt[1] = 0;
  691. for (dlli = pass[dqidly][dqsip][0]; dlli > 0 && tag[dqsip][dlli] != 0; dlli--, passcnt[0]++);
  692. for (dlli = pass[dqidly][dqsip][1]; dlli < 76 && tag[dqsip][dlli] != 0; dlli++, passcnt[1]++);
  693. if (passcnt[0] > passcnt[1])
  694. passcnt[0] = passcnt[1];
  695. passcnt[1] = 0;
  696. if (passcnt[0] > g_side)
  697. passcnt[1] = passcnt[0] - g_side;
  698. if (diff > (g_margin+1) && (passcnt[1] > 0 || passcnt[0] > 8)) {
  699. g_margin = diff;
  700. g_dqidly = dqidly;
  701. g_dqsip = dqsip;
  702. g_side = passcnt[0];
  703. } else if (passcnt[1] > 1 && g_side < 8) {
  704. if (diff > g_margin)
  705. g_margin = diff;
  706. g_dqidly = dqidly;
  707. g_dqsip = dqsip;
  708. g_side = passcnt[0];
  709. }
  710. }
  711. }
  712. reg_mcr18 = reg_mcr18 | (g_dqidly << 16) | (g_dqsip << 23);
  713. ast_moutdwm(ast, 0x1E6E0018, reg_mcr18);
  714. }
  715. static bool cbr_dll2(struct ast_private *ast, struct ast2300_dram_param *param)
  716. {
  717. u32 dllmin[2], dllmax[2], dlli, data, passcnt, retry = 0;
  718. bool status = false;
  719. finetuneDQSI(ast);
  720. if (finetuneDQI_L(ast, param) == false)
  721. return status;
  722. CBR_START2:
  723. dllmin[0] = dllmin[1] = 0xff;
  724. dllmax[0] = dllmax[1] = 0x0;
  725. passcnt = 0;
  726. for (dlli = 0; dlli < 76; dlli++) {
  727. ast_moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24));
  728. ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE2);
  729. data = cbr_scan(ast);
  730. if (data != 0) {
  731. if (data & 0x1) {
  732. if (dllmin[0] > dlli) {
  733. dllmin[0] = dlli;
  734. }
  735. if (dllmax[0] < dlli) {
  736. dllmax[0] = dlli;
  737. }
  738. }
  739. if (data & 0x2) {
  740. if (dllmin[1] > dlli) {
  741. dllmin[1] = dlli;
  742. }
  743. if (dllmax[1] < dlli) {
  744. dllmax[1] = dlli;
  745. }
  746. }
  747. passcnt++;
  748. } else if (passcnt >= CBR_THRESHOLD) {
  749. break;
  750. }
  751. }
  752. if (retry++ > 10)
  753. goto CBR_DONE2;
  754. if (dllmax[0] == 0 || (dllmax[0]-dllmin[0]) < CBR_THRESHOLD) {
  755. goto CBR_START2;
  756. }
  757. if (dllmax[1] == 0 || (dllmax[1]-dllmin[1]) < CBR_THRESHOLD) {
  758. goto CBR_START2;
  759. }
  760. status = true;
  761. CBR_DONE2:
  762. dlli = (dllmin[1] + dllmax[1]) >> 1;
  763. dlli <<= 8;
  764. dlli += (dllmin[0] + dllmax[0]) >> 1;
  765. ast_moutdwm(ast, 0x1E6E0068, ast_mindwm(ast, 0x1E720058) | (dlli << 16));
  766. return status;
  767. } /* CBRDLL2 */
  768. static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *param)
  769. {
  770. u32 trap, trap_AC2, trap_MRS;
  771. ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
  772. /* Ger trap info */
  773. trap = (ast_mindwm(ast, 0x1E6E2070) >> 25) & 0x3;
  774. trap_AC2 = 0x00020000 + (trap << 16);
  775. trap_AC2 |= 0x00300000 + ((trap & 0x2) << 19);
  776. trap_MRS = 0x00000010 + (trap << 4);
  777. trap_MRS |= ((trap & 0x2) << 18);
  778. param->reg_MADJ = 0x00034C4C;
  779. param->reg_SADJ = 0x00001800;
  780. param->reg_DRV = 0x000000F0;
  781. param->reg_PERIOD = param->dram_freq;
  782. param->rodt = 0;
  783. switch (param->dram_freq) {
  784. case 336:
  785. ast_moutdwm(ast, 0x1E6E2020, 0x0190);
  786. param->wodt = 0;
  787. param->reg_AC1 = 0x22202725;
  788. param->reg_AC2 = 0xAA007613 | trap_AC2;
  789. param->reg_DQSIC = 0x000000BA;
  790. param->reg_MRS = 0x04001400 | trap_MRS;
  791. param->reg_EMRS = 0x00000000;
  792. param->reg_IOZ = 0x00000023;
  793. param->reg_DQIDLY = 0x00000074;
  794. param->reg_FREQ = 0x00004DC0;
  795. param->madj_max = 96;
  796. param->dll2_finetune_step = 3;
  797. switch (param->dram_chipid) {
  798. default:
  799. case AST_DRAM_512Mx16:
  800. case AST_DRAM_1Gx16:
  801. param->reg_AC2 = 0xAA007613 | trap_AC2;
  802. break;
  803. case AST_DRAM_2Gx16:
  804. param->reg_AC2 = 0xAA00761C | trap_AC2;
  805. break;
  806. case AST_DRAM_4Gx16:
  807. param->reg_AC2 = 0xAA007636 | trap_AC2;
  808. break;
  809. }
  810. break;
  811. default:
  812. case 396:
  813. ast_moutdwm(ast, 0x1E6E2020, 0x03F1);
  814. param->wodt = 1;
  815. param->reg_AC1 = 0x33302825;
  816. param->reg_AC2 = 0xCC009617 | trap_AC2;
  817. param->reg_DQSIC = 0x000000E2;
  818. param->reg_MRS = 0x04001600 | trap_MRS;
  819. param->reg_EMRS = 0x00000000;
  820. param->reg_IOZ = 0x00000034;
  821. param->reg_DRV = 0x000000FA;
  822. param->reg_DQIDLY = 0x00000089;
  823. param->reg_FREQ = 0x00005040;
  824. param->madj_max = 96;
  825. param->dll2_finetune_step = 4;
  826. switch (param->dram_chipid) {
  827. default:
  828. case AST_DRAM_512Mx16:
  829. case AST_DRAM_1Gx16:
  830. param->reg_AC2 = 0xCC009617 | trap_AC2;
  831. break;
  832. case AST_DRAM_2Gx16:
  833. param->reg_AC2 = 0xCC009622 | trap_AC2;
  834. break;
  835. case AST_DRAM_4Gx16:
  836. param->reg_AC2 = 0xCC00963F | trap_AC2;
  837. break;
  838. }
  839. break;
  840. case 408:
  841. ast_moutdwm(ast, 0x1E6E2020, 0x01F0);
  842. param->wodt = 1;
  843. param->reg_AC1 = 0x33302825;
  844. param->reg_AC2 = 0xCC009617 | trap_AC2;
  845. param->reg_DQSIC = 0x000000E2;
  846. param->reg_MRS = 0x04001600 | trap_MRS;
  847. param->reg_EMRS = 0x00000000;
  848. param->reg_IOZ = 0x00000023;
  849. param->reg_DRV = 0x000000FA;
  850. param->reg_DQIDLY = 0x00000089;
  851. param->reg_FREQ = 0x000050C0;
  852. param->madj_max = 96;
  853. param->dll2_finetune_step = 4;
  854. switch (param->dram_chipid) {
  855. default:
  856. case AST_DRAM_512Mx16:
  857. case AST_DRAM_1Gx16:
  858. param->reg_AC2 = 0xCC009617 | trap_AC2;
  859. break;
  860. case AST_DRAM_2Gx16:
  861. param->reg_AC2 = 0xCC009622 | trap_AC2;
  862. break;
  863. case AST_DRAM_4Gx16:
  864. param->reg_AC2 = 0xCC00963F | trap_AC2;
  865. break;
  866. }
  867. break;
  868. case 456:
  869. ast_moutdwm(ast, 0x1E6E2020, 0x0230);
  870. param->wodt = 0;
  871. param->reg_AC1 = 0x33302926;
  872. param->reg_AC2 = 0xCD44961A;
  873. param->reg_DQSIC = 0x000000FC;
  874. param->reg_MRS = 0x00081830;
  875. param->reg_EMRS = 0x00000000;
  876. param->reg_IOZ = 0x00000045;
  877. param->reg_DQIDLY = 0x00000097;
  878. param->reg_FREQ = 0x000052C0;
  879. param->madj_max = 88;
  880. param->dll2_finetune_step = 4;
  881. break;
  882. case 504:
  883. ast_moutdwm(ast, 0x1E6E2020, 0x0270);
  884. param->wodt = 1;
  885. param->reg_AC1 = 0x33302926;
  886. param->reg_AC2 = 0xDE44A61D;
  887. param->reg_DQSIC = 0x00000117;
  888. param->reg_MRS = 0x00081A30;
  889. param->reg_EMRS = 0x00000000;
  890. param->reg_IOZ = 0x070000BB;
  891. param->reg_DQIDLY = 0x000000A0;
  892. param->reg_FREQ = 0x000054C0;
  893. param->madj_max = 79;
  894. param->dll2_finetune_step = 4;
  895. break;
  896. case 528:
  897. ast_moutdwm(ast, 0x1E6E2020, 0x0290);
  898. param->wodt = 1;
  899. param->rodt = 1;
  900. param->reg_AC1 = 0x33302926;
  901. param->reg_AC2 = 0xEF44B61E;
  902. param->reg_DQSIC = 0x00000125;
  903. param->reg_MRS = 0x00081A30;
  904. param->reg_EMRS = 0x00000040;
  905. param->reg_DRV = 0x000000F5;
  906. param->reg_IOZ = 0x00000023;
  907. param->reg_DQIDLY = 0x00000088;
  908. param->reg_FREQ = 0x000055C0;
  909. param->madj_max = 76;
  910. param->dll2_finetune_step = 3;
  911. break;
  912. case 576:
  913. ast_moutdwm(ast, 0x1E6E2020, 0x0140);
  914. param->reg_MADJ = 0x00136868;
  915. param->reg_SADJ = 0x00004534;
  916. param->wodt = 1;
  917. param->rodt = 1;
  918. param->reg_AC1 = 0x33302A37;
  919. param->reg_AC2 = 0xEF56B61E;
  920. param->reg_DQSIC = 0x0000013F;
  921. param->reg_MRS = 0x00101A50;
  922. param->reg_EMRS = 0x00000040;
  923. param->reg_DRV = 0x000000FA;
  924. param->reg_IOZ = 0x00000023;
  925. param->reg_DQIDLY = 0x00000078;
  926. param->reg_FREQ = 0x000057C0;
  927. param->madj_max = 136;
  928. param->dll2_finetune_step = 3;
  929. break;
  930. case 600:
  931. ast_moutdwm(ast, 0x1E6E2020, 0x02E1);
  932. param->reg_MADJ = 0x00136868;
  933. param->reg_SADJ = 0x00004534;
  934. param->wodt = 1;
  935. param->rodt = 1;
  936. param->reg_AC1 = 0x32302A37;
  937. param->reg_AC2 = 0xDF56B61F;
  938. param->reg_DQSIC = 0x0000014D;
  939. param->reg_MRS = 0x00101A50;
  940. param->reg_EMRS = 0x00000004;
  941. param->reg_DRV = 0x000000F5;
  942. param->reg_IOZ = 0x00000023;
  943. param->reg_DQIDLY = 0x00000078;
  944. param->reg_FREQ = 0x000058C0;
  945. param->madj_max = 132;
  946. param->dll2_finetune_step = 3;
  947. break;
  948. case 624:
  949. ast_moutdwm(ast, 0x1E6E2020, 0x0160);
  950. param->reg_MADJ = 0x00136868;
  951. param->reg_SADJ = 0x00004534;
  952. param->wodt = 1;
  953. param->rodt = 1;
  954. param->reg_AC1 = 0x32302A37;
  955. param->reg_AC2 = 0xEF56B621;
  956. param->reg_DQSIC = 0x0000015A;
  957. param->reg_MRS = 0x02101A50;
  958. param->reg_EMRS = 0x00000004;
  959. param->reg_DRV = 0x000000F5;
  960. param->reg_IOZ = 0x00000034;
  961. param->reg_DQIDLY = 0x00000078;
  962. param->reg_FREQ = 0x000059C0;
  963. param->madj_max = 128;
  964. param->dll2_finetune_step = 3;
  965. break;
  966. } /* switch freq */
  967. switch (param->dram_chipid) {
  968. case AST_DRAM_512Mx16:
  969. param->dram_config = 0x130;
  970. break;
  971. default:
  972. case AST_DRAM_1Gx16:
  973. param->dram_config = 0x131;
  974. break;
  975. case AST_DRAM_2Gx16:
  976. param->dram_config = 0x132;
  977. break;
  978. case AST_DRAM_4Gx16:
  979. param->dram_config = 0x133;
  980. break;
  981. } /* switch size */
  982. switch (param->vram_size) {
  983. default:
  984. case AST_VIDMEM_SIZE_8M:
  985. param->dram_config |= 0x00;
  986. break;
  987. case AST_VIDMEM_SIZE_16M:
  988. param->dram_config |= 0x04;
  989. break;
  990. case AST_VIDMEM_SIZE_32M:
  991. param->dram_config |= 0x08;
  992. break;
  993. case AST_VIDMEM_SIZE_64M:
  994. param->dram_config |= 0x0c;
  995. break;
  996. }
  997. }
  998. static void ddr3_init(struct ast_private *ast, struct ast2300_dram_param *param)
  999. {
  1000. u32 data, data2, retry = 0;
  1001. ddr3_init_start:
  1002. ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
  1003. ast_moutdwm(ast, 0x1E6E0018, 0x00000100);
  1004. ast_moutdwm(ast, 0x1E6E0024, 0x00000000);
  1005. ast_moutdwm(ast, 0x1E6E0034, 0x00000000);
  1006. udelay(10);
  1007. ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ);
  1008. ast_moutdwm(ast, 0x1E6E0068, param->reg_SADJ);
  1009. udelay(10);
  1010. ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000);
  1011. udelay(10);
  1012. ast_moutdwm(ast, 0x1E6E0004, param->dram_config);
  1013. ast_moutdwm(ast, 0x1E6E0008, 0x90040f);
  1014. ast_moutdwm(ast, 0x1E6E0010, param->reg_AC1);
  1015. ast_moutdwm(ast, 0x1E6E0014, param->reg_AC2);
  1016. ast_moutdwm(ast, 0x1E6E0020, param->reg_DQSIC);
  1017. ast_moutdwm(ast, 0x1E6E0080, 0x00000000);
  1018. ast_moutdwm(ast, 0x1E6E0084, 0x00000000);
  1019. ast_moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY);
  1020. ast_moutdwm(ast, 0x1E6E0018, 0x4000A170);
  1021. ast_moutdwm(ast, 0x1E6E0018, 0x00002370);
  1022. ast_moutdwm(ast, 0x1E6E0038, 0x00000000);
  1023. ast_moutdwm(ast, 0x1E6E0040, 0xFF444444);
  1024. ast_moutdwm(ast, 0x1E6E0044, 0x22222222);
  1025. ast_moutdwm(ast, 0x1E6E0048, 0x22222222);
  1026. ast_moutdwm(ast, 0x1E6E004C, 0x00000002);
  1027. ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
  1028. ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
  1029. ast_moutdwm(ast, 0x1E6E0054, 0);
  1030. ast_moutdwm(ast, 0x1E6E0060, param->reg_DRV);
  1031. ast_moutdwm(ast, 0x1E6E006C, param->reg_IOZ);
  1032. ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
  1033. ast_moutdwm(ast, 0x1E6E0074, 0x00000000);
  1034. ast_moutdwm(ast, 0x1E6E0078, 0x00000000);
  1035. ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
  1036. /* Wait MCLK2X lock to MCLK */
  1037. do {
  1038. data = ast_mindwm(ast, 0x1E6E001C);
  1039. } while (!(data & 0x08000000));
  1040. data = ast_mindwm(ast, 0x1E6E001C);
  1041. data = (data >> 8) & 0xff;
  1042. while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) {
  1043. data2 = (ast_mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4;
  1044. if ((data2 & 0xff) > param->madj_max) {
  1045. break;
  1046. }
  1047. ast_moutdwm(ast, 0x1E6E0064, data2);
  1048. if (data2 & 0x00100000) {
  1049. data2 = ((data2 & 0xff) >> 3) + 3;
  1050. } else {
  1051. data2 = ((data2 & 0xff) >> 2) + 5;
  1052. }
  1053. data = ast_mindwm(ast, 0x1E6E0068) & 0xffff00ff;
  1054. data2 += data & 0xff;
  1055. data = data | (data2 << 8);
  1056. ast_moutdwm(ast, 0x1E6E0068, data);
  1057. udelay(10);
  1058. ast_moutdwm(ast, 0x1E6E0064, ast_mindwm(ast, 0x1E6E0064) | 0xC0000);
  1059. udelay(10);
  1060. data = ast_mindwm(ast, 0x1E6E0018) & 0xfffff1ff;
  1061. ast_moutdwm(ast, 0x1E6E0018, data);
  1062. data = data | 0x200;
  1063. ast_moutdwm(ast, 0x1E6E0018, data);
  1064. do {
  1065. data = ast_mindwm(ast, 0x1E6E001C);
  1066. } while (!(data & 0x08000000));
  1067. data = ast_mindwm(ast, 0x1E6E001C);
  1068. data = (data >> 8) & 0xff;
  1069. }
  1070. ast_moutdwm(ast, 0x1E720058, ast_mindwm(ast, 0x1E6E0068) & 0xffff);
  1071. data = ast_mindwm(ast, 0x1E6E0018) | 0xC00;
  1072. ast_moutdwm(ast, 0x1E6E0018, data);
  1073. ast_moutdwm(ast, 0x1E6E0034, 0x00000001);
  1074. ast_moutdwm(ast, 0x1E6E000C, 0x00000040);
  1075. udelay(50);
  1076. /* Mode Register Setting */
  1077. ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100);
  1078. ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
  1079. ast_moutdwm(ast, 0x1E6E0028, 0x00000005);
  1080. ast_moutdwm(ast, 0x1E6E0028, 0x00000007);
  1081. ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
  1082. ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
  1083. ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS);
  1084. ast_moutdwm(ast, 0x1E6E000C, 0x00005C08);
  1085. ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
  1086. ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
  1087. data = 0;
  1088. if (param->wodt) {
  1089. data = 0x300;
  1090. }
  1091. if (param->rodt) {
  1092. data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3);
  1093. }
  1094. ast_moutdwm(ast, 0x1E6E0034, data | 0x3);
  1095. /* Calibrate the DQSI delay */
  1096. if ((cbr_dll2(ast, param) == false) && (retry++ < 10))
  1097. goto ddr3_init_start;
  1098. ast_moutdwm(ast, 0x1E6E0120, param->reg_FREQ);
  1099. /* ECC Memory Initialization */
  1100. #ifdef ECC
  1101. ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
  1102. ast_moutdwm(ast, 0x1E6E0070, 0x221);
  1103. do {
  1104. data = ast_mindwm(ast, 0x1E6E0070);
  1105. } while (!(data & 0x00001000));
  1106. ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
  1107. ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
  1108. ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
  1109. #endif
  1110. }
  1111. static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *param)
  1112. {
  1113. u32 trap, trap_AC2, trap_MRS;
  1114. ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
  1115. /* Ger trap info */
  1116. trap = (ast_mindwm(ast, 0x1E6E2070) >> 25) & 0x3;
  1117. trap_AC2 = (trap << 20) | (trap << 16);
  1118. trap_AC2 += 0x00110000;
  1119. trap_MRS = 0x00000040 | (trap << 4);
  1120. param->reg_MADJ = 0x00034C4C;
  1121. param->reg_SADJ = 0x00001800;
  1122. param->reg_DRV = 0x000000F0;
  1123. param->reg_PERIOD = param->dram_freq;
  1124. param->rodt = 0;
  1125. switch (param->dram_freq) {
  1126. case 264:
  1127. ast_moutdwm(ast, 0x1E6E2020, 0x0130);
  1128. param->wodt = 0;
  1129. param->reg_AC1 = 0x11101513;
  1130. param->reg_AC2 = 0x78117011;
  1131. param->reg_DQSIC = 0x00000092;
  1132. param->reg_MRS = 0x00000842;
  1133. param->reg_EMRS = 0x00000000;
  1134. param->reg_DRV = 0x000000F0;
  1135. param->reg_IOZ = 0x00000034;
  1136. param->reg_DQIDLY = 0x0000005A;
  1137. param->reg_FREQ = 0x00004AC0;
  1138. param->madj_max = 138;
  1139. param->dll2_finetune_step = 3;
  1140. break;
  1141. case 336:
  1142. ast_moutdwm(ast, 0x1E6E2020, 0x0190);
  1143. param->wodt = 1;
  1144. param->reg_AC1 = 0x22202613;
  1145. param->reg_AC2 = 0xAA009016 | trap_AC2;
  1146. param->reg_DQSIC = 0x000000BA;
  1147. param->reg_MRS = 0x00000A02 | trap_MRS;
  1148. param->reg_EMRS = 0x00000040;
  1149. param->reg_DRV = 0x000000FA;
  1150. param->reg_IOZ = 0x00000034;
  1151. param->reg_DQIDLY = 0x00000074;
  1152. param->reg_FREQ = 0x00004DC0;
  1153. param->madj_max = 96;
  1154. param->dll2_finetune_step = 3;
  1155. switch (param->dram_chipid) {
  1156. default:
  1157. case AST_DRAM_512Mx16:
  1158. param->reg_AC2 = 0xAA009012 | trap_AC2;
  1159. break;
  1160. case AST_DRAM_1Gx16:
  1161. param->reg_AC2 = 0xAA009016 | trap_AC2;
  1162. break;
  1163. case AST_DRAM_2Gx16:
  1164. param->reg_AC2 = 0xAA009023 | trap_AC2;
  1165. break;
  1166. case AST_DRAM_4Gx16:
  1167. param->reg_AC2 = 0xAA00903B | trap_AC2;
  1168. break;
  1169. }
  1170. break;
  1171. default:
  1172. case 396:
  1173. ast_moutdwm(ast, 0x1E6E2020, 0x03F1);
  1174. param->wodt = 1;
  1175. param->rodt = 0;
  1176. param->reg_AC1 = 0x33302714;
  1177. param->reg_AC2 = 0xCC00B01B | trap_AC2;
  1178. param->reg_DQSIC = 0x000000E2;
  1179. param->reg_MRS = 0x00000C02 | trap_MRS;
  1180. param->reg_EMRS = 0x00000040;
  1181. param->reg_DRV = 0x000000FA;
  1182. param->reg_IOZ = 0x00000034;
  1183. param->reg_DQIDLY = 0x00000089;
  1184. param->reg_FREQ = 0x00005040;
  1185. param->madj_max = 96;
  1186. param->dll2_finetune_step = 4;
  1187. switch (param->dram_chipid) {
  1188. case AST_DRAM_512Mx16:
  1189. param->reg_AC2 = 0xCC00B016 | trap_AC2;
  1190. break;
  1191. default:
  1192. case AST_DRAM_1Gx16:
  1193. param->reg_AC2 = 0xCC00B01B | trap_AC2;
  1194. break;
  1195. case AST_DRAM_2Gx16:
  1196. param->reg_AC2 = 0xCC00B02B | trap_AC2;
  1197. break;
  1198. case AST_DRAM_4Gx16:
  1199. param->reg_AC2 = 0xCC00B03F | trap_AC2;
  1200. break;
  1201. }
  1202. break;
  1203. case 408:
  1204. ast_moutdwm(ast, 0x1E6E2020, 0x01F0);
  1205. param->wodt = 1;
  1206. param->rodt = 0;
  1207. param->reg_AC1 = 0x33302714;
  1208. param->reg_AC2 = 0xCC00B01B | trap_AC2;
  1209. param->reg_DQSIC = 0x000000E2;
  1210. param->reg_MRS = 0x00000C02 | trap_MRS;
  1211. param->reg_EMRS = 0x00000040;
  1212. param->reg_DRV = 0x000000FA;
  1213. param->reg_IOZ = 0x00000034;
  1214. param->reg_DQIDLY = 0x00000089;
  1215. param->reg_FREQ = 0x000050C0;
  1216. param->madj_max = 96;
  1217. param->dll2_finetune_step = 4;
  1218. switch (param->dram_chipid) {
  1219. case AST_DRAM_512Mx16:
  1220. param->reg_AC2 = 0xCC00B016 | trap_AC2;
  1221. break;
  1222. default:
  1223. case AST_DRAM_1Gx16:
  1224. param->reg_AC2 = 0xCC00B01B | trap_AC2;
  1225. break;
  1226. case AST_DRAM_2Gx16:
  1227. param->reg_AC2 = 0xCC00B02B | trap_AC2;
  1228. break;
  1229. case AST_DRAM_4Gx16:
  1230. param->reg_AC2 = 0xCC00B03F | trap_AC2;
  1231. break;
  1232. }
  1233. break;
  1234. case 456:
  1235. ast_moutdwm(ast, 0x1E6E2020, 0x0230);
  1236. param->wodt = 0;
  1237. param->reg_AC1 = 0x33302815;
  1238. param->reg_AC2 = 0xCD44B01E;
  1239. param->reg_DQSIC = 0x000000FC;
  1240. param->reg_MRS = 0x00000E72;
  1241. param->reg_EMRS = 0x00000000;
  1242. param->reg_DRV = 0x00000000;
  1243. param->reg_IOZ = 0x00000034;
  1244. param->reg_DQIDLY = 0x00000097;
  1245. param->reg_FREQ = 0x000052C0;
  1246. param->madj_max = 88;
  1247. param->dll2_finetune_step = 3;
  1248. break;
  1249. case 504:
  1250. ast_moutdwm(ast, 0x1E6E2020, 0x0261);
  1251. param->wodt = 1;
  1252. param->rodt = 1;
  1253. param->reg_AC1 = 0x33302815;
  1254. param->reg_AC2 = 0xDE44C022;
  1255. param->reg_DQSIC = 0x00000117;
  1256. param->reg_MRS = 0x00000E72;
  1257. param->reg_EMRS = 0x00000040;
  1258. param->reg_DRV = 0x0000000A;
  1259. param->reg_IOZ = 0x00000045;
  1260. param->reg_DQIDLY = 0x000000A0;
  1261. param->reg_FREQ = 0x000054C0;
  1262. param->madj_max = 79;
  1263. param->dll2_finetune_step = 3;
  1264. break;
  1265. case 528:
  1266. ast_moutdwm(ast, 0x1E6E2020, 0x0120);
  1267. param->wodt = 1;
  1268. param->rodt = 1;
  1269. param->reg_AC1 = 0x33302815;
  1270. param->reg_AC2 = 0xEF44D024;
  1271. param->reg_DQSIC = 0x00000125;
  1272. param->reg_MRS = 0x00000E72;
  1273. param->reg_EMRS = 0x00000004;
  1274. param->reg_DRV = 0x000000F9;
  1275. param->reg_IOZ = 0x00000045;
  1276. param->reg_DQIDLY = 0x000000A7;
  1277. param->reg_FREQ = 0x000055C0;
  1278. param->madj_max = 76;
  1279. param->dll2_finetune_step = 3;
  1280. break;
  1281. case 552:
  1282. ast_moutdwm(ast, 0x1E6E2020, 0x02A1);
  1283. param->wodt = 1;
  1284. param->rodt = 1;
  1285. param->reg_AC1 = 0x43402915;
  1286. param->reg_AC2 = 0xFF44E025;
  1287. param->reg_DQSIC = 0x00000132;
  1288. param->reg_MRS = 0x00000E72;
  1289. param->reg_EMRS = 0x00000040;
  1290. param->reg_DRV = 0x0000000A;
  1291. param->reg_IOZ = 0x00000045;
  1292. param->reg_DQIDLY = 0x000000AD;
  1293. param->reg_FREQ = 0x000056C0;
  1294. param->madj_max = 76;
  1295. param->dll2_finetune_step = 3;
  1296. break;
  1297. case 576:
  1298. ast_moutdwm(ast, 0x1E6E2020, 0x0140);
  1299. param->wodt = 1;
  1300. param->rodt = 1;
  1301. param->reg_AC1 = 0x43402915;
  1302. param->reg_AC2 = 0xFF44E027;
  1303. param->reg_DQSIC = 0x0000013F;
  1304. param->reg_MRS = 0x00000E72;
  1305. param->reg_EMRS = 0x00000004;
  1306. param->reg_DRV = 0x000000F5;
  1307. param->reg_IOZ = 0x00000045;
  1308. param->reg_DQIDLY = 0x000000B3;
  1309. param->reg_FREQ = 0x000057C0;
  1310. param->madj_max = 76;
  1311. param->dll2_finetune_step = 3;
  1312. break;
  1313. }
  1314. switch (param->dram_chipid) {
  1315. case AST_DRAM_512Mx16:
  1316. param->dram_config = 0x100;
  1317. break;
  1318. default:
  1319. case AST_DRAM_1Gx16:
  1320. param->dram_config = 0x121;
  1321. break;
  1322. case AST_DRAM_2Gx16:
  1323. param->dram_config = 0x122;
  1324. break;
  1325. case AST_DRAM_4Gx16:
  1326. param->dram_config = 0x123;
  1327. break;
  1328. } /* switch size */
  1329. switch (param->vram_size) {
  1330. default:
  1331. case AST_VIDMEM_SIZE_8M:
  1332. param->dram_config |= 0x00;
  1333. break;
  1334. case AST_VIDMEM_SIZE_16M:
  1335. param->dram_config |= 0x04;
  1336. break;
  1337. case AST_VIDMEM_SIZE_32M:
  1338. param->dram_config |= 0x08;
  1339. break;
  1340. case AST_VIDMEM_SIZE_64M:
  1341. param->dram_config |= 0x0c;
  1342. break;
  1343. }
  1344. }
  1345. static void ddr2_init(struct ast_private *ast, struct ast2300_dram_param *param)
  1346. {
  1347. u32 data, data2, retry = 0;
  1348. ddr2_init_start:
  1349. ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
  1350. ast_moutdwm(ast, 0x1E6E0018, 0x00000100);
  1351. ast_moutdwm(ast, 0x1E6E0024, 0x00000000);
  1352. ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ);
  1353. ast_moutdwm(ast, 0x1E6E0068, param->reg_SADJ);
  1354. udelay(10);
  1355. ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000);
  1356. udelay(10);
  1357. ast_moutdwm(ast, 0x1E6E0004, param->dram_config);
  1358. ast_moutdwm(ast, 0x1E6E0008, 0x90040f);
  1359. ast_moutdwm(ast, 0x1E6E0010, param->reg_AC1);
  1360. ast_moutdwm(ast, 0x1E6E0014, param->reg_AC2);
  1361. ast_moutdwm(ast, 0x1E6E0020, param->reg_DQSIC);
  1362. ast_moutdwm(ast, 0x1E6E0080, 0x00000000);
  1363. ast_moutdwm(ast, 0x1E6E0084, 0x00000000);
  1364. ast_moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY);
  1365. ast_moutdwm(ast, 0x1E6E0018, 0x4000A130);
  1366. ast_moutdwm(ast, 0x1E6E0018, 0x00002330);
  1367. ast_moutdwm(ast, 0x1E6E0038, 0x00000000);
  1368. ast_moutdwm(ast, 0x1E6E0040, 0xFF808000);
  1369. ast_moutdwm(ast, 0x1E6E0044, 0x88848466);
  1370. ast_moutdwm(ast, 0x1E6E0048, 0x44440008);
  1371. ast_moutdwm(ast, 0x1E6E004C, 0x00000000);
  1372. ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
  1373. ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
  1374. ast_moutdwm(ast, 0x1E6E0054, 0);
  1375. ast_moutdwm(ast, 0x1E6E0060, param->reg_DRV);
  1376. ast_moutdwm(ast, 0x1E6E006C, param->reg_IOZ);
  1377. ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
  1378. ast_moutdwm(ast, 0x1E6E0074, 0x00000000);
  1379. ast_moutdwm(ast, 0x1E6E0078, 0x00000000);
  1380. ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
  1381. /* Wait MCLK2X lock to MCLK */
  1382. do {
  1383. data = ast_mindwm(ast, 0x1E6E001C);
  1384. } while (!(data & 0x08000000));
  1385. data = ast_mindwm(ast, 0x1E6E001C);
  1386. data = (data >> 8) & 0xff;
  1387. while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) {
  1388. data2 = (ast_mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4;
  1389. if ((data2 & 0xff) > param->madj_max) {
  1390. break;
  1391. }
  1392. ast_moutdwm(ast, 0x1E6E0064, data2);
  1393. if (data2 & 0x00100000) {
  1394. data2 = ((data2 & 0xff) >> 3) + 3;
  1395. } else {
  1396. data2 = ((data2 & 0xff) >> 2) + 5;
  1397. }
  1398. data = ast_mindwm(ast, 0x1E6E0068) & 0xffff00ff;
  1399. data2 += data & 0xff;
  1400. data = data | (data2 << 8);
  1401. ast_moutdwm(ast, 0x1E6E0068, data);
  1402. udelay(10);
  1403. ast_moutdwm(ast, 0x1E6E0064, ast_mindwm(ast, 0x1E6E0064) | 0xC0000);
  1404. udelay(10);
  1405. data = ast_mindwm(ast, 0x1E6E0018) & 0xfffff1ff;
  1406. ast_moutdwm(ast, 0x1E6E0018, data);
  1407. data = data | 0x200;
  1408. ast_moutdwm(ast, 0x1E6E0018, data);
  1409. do {
  1410. data = ast_mindwm(ast, 0x1E6E001C);
  1411. } while (!(data & 0x08000000));
  1412. data = ast_mindwm(ast, 0x1E6E001C);
  1413. data = (data >> 8) & 0xff;
  1414. }
  1415. ast_moutdwm(ast, 0x1E720058, ast_mindwm(ast, 0x1E6E0008) & 0xffff);
  1416. data = ast_mindwm(ast, 0x1E6E0018) | 0xC00;
  1417. ast_moutdwm(ast, 0x1E6E0018, data);
  1418. ast_moutdwm(ast, 0x1E6E0034, 0x00000001);
  1419. ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
  1420. udelay(50);
  1421. /* Mode Register Setting */
  1422. ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100);
  1423. ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
  1424. ast_moutdwm(ast, 0x1E6E0028, 0x00000005);
  1425. ast_moutdwm(ast, 0x1E6E0028, 0x00000007);
  1426. ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
  1427. ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
  1428. ast_moutdwm(ast, 0x1E6E000C, 0x00005C08);
  1429. ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS);
  1430. ast_moutdwm(ast, 0x1E6E0028, 0x00000001);
  1431. ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS | 0x380);
  1432. ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
  1433. ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS);
  1434. ast_moutdwm(ast, 0x1E6E0028, 0x00000003);
  1435. ast_moutdwm(ast, 0x1E6E000C, 0x7FFF5C01);
  1436. data = 0;
  1437. if (param->wodt) {
  1438. data = 0x500;
  1439. }
  1440. if (param->rodt) {
  1441. data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3);
  1442. }
  1443. ast_moutdwm(ast, 0x1E6E0034, data | 0x3);
  1444. ast_moutdwm(ast, 0x1E6E0120, param->reg_FREQ);
  1445. /* Calibrate the DQSI delay */
  1446. if ((cbr_dll2(ast, param) == false) && (retry++ < 10))
  1447. goto ddr2_init_start;
  1448. /* ECC Memory Initialization */
  1449. #ifdef ECC
  1450. ast_moutdwm(ast, 0x1E6E007C, 0x00000000);
  1451. ast_moutdwm(ast, 0x1E6E0070, 0x221);
  1452. do {
  1453. data = ast_mindwm(ast, 0x1E6E0070);
  1454. } while (!(data & 0x00001000));
  1455. ast_moutdwm(ast, 0x1E6E0070, 0x00000000);
  1456. ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
  1457. ast_moutdwm(ast, 0x1E6E0050, 0x00000000);
  1458. #endif
  1459. }
  1460. static void ast_post_chip_2300(struct drm_device *dev)
  1461. {
  1462. struct ast_private *ast = dev->dev_private;
  1463. struct ast2300_dram_param param;
  1464. u32 temp;
  1465. u8 reg;
  1466. reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
  1467. if ((reg & 0x80) == 0) {/* vga only */
  1468. ast_write32(ast, 0xf004, 0x1e6e0000);
  1469. ast_write32(ast, 0xf000, 0x1);
  1470. ast_write32(ast, 0x12000, 0x1688a8a8);
  1471. do {
  1472. ;
  1473. } while (ast_read32(ast, 0x12000) != 0x1);
  1474. ast_write32(ast, 0x10000, 0xfc600309);
  1475. do {
  1476. ;
  1477. } while (ast_read32(ast, 0x10000) != 0x1);
  1478. /* Slow down CPU/AHB CLK in VGA only mode */
  1479. temp = ast_read32(ast, 0x12008);
  1480. temp |= 0x73;
  1481. ast_write32(ast, 0x12008, temp);
  1482. param.dram_freq = 396;
  1483. param.dram_type = AST_DDR3;
  1484. temp = ast_mindwm(ast, 0x1e6e2070);
  1485. if (temp & 0x01000000)
  1486. param.dram_type = AST_DDR2;
  1487. switch (temp & 0x18000000) {
  1488. case 0:
  1489. param.dram_chipid = AST_DRAM_512Mx16;
  1490. break;
  1491. default:
  1492. case 0x08000000:
  1493. param.dram_chipid = AST_DRAM_1Gx16;
  1494. break;
  1495. case 0x10000000:
  1496. param.dram_chipid = AST_DRAM_2Gx16;
  1497. break;
  1498. case 0x18000000:
  1499. param.dram_chipid = AST_DRAM_4Gx16;
  1500. break;
  1501. }
  1502. switch (temp & 0x0c) {
  1503. default:
  1504. case 0x00:
  1505. param.vram_size = AST_VIDMEM_SIZE_8M;
  1506. break;
  1507. case 0x04:
  1508. param.vram_size = AST_VIDMEM_SIZE_16M;
  1509. break;
  1510. case 0x08:
  1511. param.vram_size = AST_VIDMEM_SIZE_32M;
  1512. break;
  1513. case 0x0c:
  1514. param.vram_size = AST_VIDMEM_SIZE_64M;
  1515. break;
  1516. }
  1517. if (param.dram_type == AST_DDR3) {
  1518. get_ddr3_info(ast, &param);
  1519. ddr3_init(ast, &param);
  1520. } else {
  1521. get_ddr2_info(ast, &param);
  1522. ddr2_init(ast, &param);
  1523. }
  1524. temp = ast_mindwm(ast, 0x1e6e2040);
  1525. ast_moutdwm(ast, 0x1e6e2040, temp | 0x40);
  1526. }
  1527. /* wait ready */
  1528. do {
  1529. reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
  1530. } while ((reg & 0x40) == 0);
  1531. }
  1532. static bool cbr_test_2500(struct ast_private *ast)
  1533. {
  1534. ast_moutdwm(ast, 0x1E6E0074, 0x0000FFFF);
  1535. ast_moutdwm(ast, 0x1E6E007C, 0xFF00FF00);
  1536. if (!mmc_test_burst(ast, 0))
  1537. return false;
  1538. if (!mmc_test_single_2500(ast, 0))
  1539. return false;
  1540. return true;
  1541. }
  1542. static bool ddr_test_2500(struct ast_private *ast)
  1543. {
  1544. ast_moutdwm(ast, 0x1E6E0074, 0x0000FFFF);
  1545. ast_moutdwm(ast, 0x1E6E007C, 0xFF00FF00);
  1546. if (!mmc_test_burst(ast, 0))
  1547. return false;
  1548. if (!mmc_test_burst(ast, 1))
  1549. return false;
  1550. if (!mmc_test_burst(ast, 2))
  1551. return false;
  1552. if (!mmc_test_burst(ast, 3))
  1553. return false;
  1554. if (!mmc_test_single_2500(ast, 0))
  1555. return false;
  1556. return true;
  1557. }
  1558. static void ddr_init_common_2500(struct ast_private *ast)
  1559. {
  1560. ast_moutdwm(ast, 0x1E6E0034, 0x00020080);
  1561. ast_moutdwm(ast, 0x1E6E0008, 0x2003000F);
  1562. ast_moutdwm(ast, 0x1E6E0038, 0x00000FFF);
  1563. ast_moutdwm(ast, 0x1E6E0040, 0x88448844);
  1564. ast_moutdwm(ast, 0x1E6E0044, 0x24422288);
  1565. ast_moutdwm(ast, 0x1E6E0048, 0x22222222);
  1566. ast_moutdwm(ast, 0x1E6E004C, 0x22222222);
  1567. ast_moutdwm(ast, 0x1E6E0050, 0x80000000);
  1568. ast_moutdwm(ast, 0x1E6E0208, 0x00000000);
  1569. ast_moutdwm(ast, 0x1E6E0218, 0x00000000);
  1570. ast_moutdwm(ast, 0x1E6E0220, 0x00000000);
  1571. ast_moutdwm(ast, 0x1E6E0228, 0x00000000);
  1572. ast_moutdwm(ast, 0x1E6E0230, 0x00000000);
  1573. ast_moutdwm(ast, 0x1E6E02A8, 0x00000000);
  1574. ast_moutdwm(ast, 0x1E6E02B0, 0x00000000);
  1575. ast_moutdwm(ast, 0x1E6E0240, 0x86000000);
  1576. ast_moutdwm(ast, 0x1E6E0244, 0x00008600);
  1577. ast_moutdwm(ast, 0x1E6E0248, 0x80000000);
  1578. ast_moutdwm(ast, 0x1E6E024C, 0x80808080);
  1579. }
  1580. static void ddr_phy_init_2500(struct ast_private *ast)
  1581. {
  1582. u32 data, pass, timecnt;
  1583. pass = 0;
  1584. ast_moutdwm(ast, 0x1E6E0060, 0x00000005);
  1585. while (!pass) {
  1586. for (timecnt = 0; timecnt < TIMEOUT; timecnt++) {
  1587. data = ast_mindwm(ast, 0x1E6E0060) & 0x1;
  1588. if (!data)
  1589. break;
  1590. }
  1591. if (timecnt != TIMEOUT) {
  1592. data = ast_mindwm(ast, 0x1E6E0300) & 0x000A0000;
  1593. if (!data)
  1594. pass = 1;
  1595. }
  1596. if (!pass) {
  1597. ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
  1598. udelay(10); /* delay 10 us */
  1599. ast_moutdwm(ast, 0x1E6E0060, 0x00000005);
  1600. }
  1601. }
  1602. ast_moutdwm(ast, 0x1E6E0060, 0x00000006);
  1603. }
  1604. /*
  1605. * Check DRAM Size
  1606. * 1Gb : 0x80000000 ~ 0x87FFFFFF
  1607. * 2Gb : 0x80000000 ~ 0x8FFFFFFF
  1608. * 4Gb : 0x80000000 ~ 0x9FFFFFFF
  1609. * 8Gb : 0x80000000 ~ 0xBFFFFFFF
  1610. */
  1611. static void check_dram_size_2500(struct ast_private *ast, u32 tRFC)
  1612. {
  1613. u32 reg_04, reg_14;
  1614. reg_04 = ast_mindwm(ast, 0x1E6E0004) & 0xfffffffc;
  1615. reg_14 = ast_mindwm(ast, 0x1E6E0014) & 0xffffff00;
  1616. ast_moutdwm(ast, 0xA0100000, 0x41424344);
  1617. ast_moutdwm(ast, 0x90100000, 0x35363738);
  1618. ast_moutdwm(ast, 0x88100000, 0x292A2B2C);
  1619. ast_moutdwm(ast, 0x80100000, 0x1D1E1F10);
  1620. /* Check 8Gbit */
  1621. if (ast_mindwm(ast, 0xA0100000) == 0x41424344) {
  1622. reg_04 |= 0x03;
  1623. reg_14 |= (tRFC >> 24) & 0xFF;
  1624. /* Check 4Gbit */
  1625. } else if (ast_mindwm(ast, 0x90100000) == 0x35363738) {
  1626. reg_04 |= 0x02;
  1627. reg_14 |= (tRFC >> 16) & 0xFF;
  1628. /* Check 2Gbit */
  1629. } else if (ast_mindwm(ast, 0x88100000) == 0x292A2B2C) {
  1630. reg_04 |= 0x01;
  1631. reg_14 |= (tRFC >> 8) & 0xFF;
  1632. } else {
  1633. reg_14 |= tRFC & 0xFF;
  1634. }
  1635. ast_moutdwm(ast, 0x1E6E0004, reg_04);
  1636. ast_moutdwm(ast, 0x1E6E0014, reg_14);
  1637. }
  1638. static void enable_cache_2500(struct ast_private *ast)
  1639. {
  1640. u32 reg_04, data;
  1641. reg_04 = ast_mindwm(ast, 0x1E6E0004);
  1642. ast_moutdwm(ast, 0x1E6E0004, reg_04 | 0x1000);
  1643. do
  1644. data = ast_mindwm(ast, 0x1E6E0004);
  1645. while (!(data & 0x80000));
  1646. ast_moutdwm(ast, 0x1E6E0004, reg_04 | 0x400);
  1647. }
  1648. static void set_mpll_2500(struct ast_private *ast)
  1649. {
  1650. u32 addr, data, param;
  1651. /* Reset MMC */
  1652. ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
  1653. ast_moutdwm(ast, 0x1E6E0034, 0x00020080);
  1654. for (addr = 0x1e6e0004; addr < 0x1e6e0090;) {
  1655. ast_moutdwm(ast, addr, 0x0);
  1656. addr += 4;
  1657. }
  1658. ast_moutdwm(ast, 0x1E6E0034, 0x00020000);
  1659. ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8);
  1660. data = ast_mindwm(ast, 0x1E6E2070) & 0x00800000;
  1661. if (data) {
  1662. /* CLKIN = 25MHz */
  1663. param = 0x930023E0;
  1664. ast_moutdwm(ast, 0x1E6E2160, 0x00011320);
  1665. } else {
  1666. /* CLKIN = 24MHz */
  1667. param = 0x93002400;
  1668. }
  1669. ast_moutdwm(ast, 0x1E6E2020, param);
  1670. udelay(100);
  1671. }
  1672. static void reset_mmc_2500(struct ast_private *ast)
  1673. {
  1674. ast_moutdwm(ast, 0x1E78505C, 0x00000004);
  1675. ast_moutdwm(ast, 0x1E785044, 0x00000001);
  1676. ast_moutdwm(ast, 0x1E785048, 0x00004755);
  1677. ast_moutdwm(ast, 0x1E78504C, 0x00000013);
  1678. mdelay(100);
  1679. ast_moutdwm(ast, 0x1E785054, 0x00000077);
  1680. ast_moutdwm(ast, 0x1E6E0000, 0xFC600309);
  1681. }
  1682. static void ddr3_init_2500(struct ast_private *ast, const u32 *ddr_table)
  1683. {
  1684. ast_moutdwm(ast, 0x1E6E0004, 0x00000303);
  1685. ast_moutdwm(ast, 0x1E6E0010, ddr_table[REGIDX_010]);
  1686. ast_moutdwm(ast, 0x1E6E0014, ddr_table[REGIDX_014]);
  1687. ast_moutdwm(ast, 0x1E6E0018, ddr_table[REGIDX_018]);
  1688. ast_moutdwm(ast, 0x1E6E0020, ddr_table[REGIDX_020]); /* MODEREG4/6 */
  1689. ast_moutdwm(ast, 0x1E6E0024, ddr_table[REGIDX_024]); /* MODEREG5 */
  1690. ast_moutdwm(ast, 0x1E6E002C, ddr_table[REGIDX_02C] | 0x100); /* MODEREG0/2 */
  1691. ast_moutdwm(ast, 0x1E6E0030, ddr_table[REGIDX_030]); /* MODEREG1/3 */
  1692. /* DDR PHY Setting */
  1693. ast_moutdwm(ast, 0x1E6E0200, 0x02492AAE);
  1694. ast_moutdwm(ast, 0x1E6E0204, 0x00001001);
  1695. ast_moutdwm(ast, 0x1E6E020C, 0x55E00B0B);
  1696. ast_moutdwm(ast, 0x1E6E0210, 0x20000000);
  1697. ast_moutdwm(ast, 0x1E6E0214, ddr_table[REGIDX_214]);
  1698. ast_moutdwm(ast, 0x1E6E02E0, ddr_table[REGIDX_2E0]);
  1699. ast_moutdwm(ast, 0x1E6E02E4, ddr_table[REGIDX_2E4]);
  1700. ast_moutdwm(ast, 0x1E6E02E8, ddr_table[REGIDX_2E8]);
  1701. ast_moutdwm(ast, 0x1E6E02EC, ddr_table[REGIDX_2EC]);
  1702. ast_moutdwm(ast, 0x1E6E02F0, ddr_table[REGIDX_2F0]);
  1703. ast_moutdwm(ast, 0x1E6E02F4, ddr_table[REGIDX_2F4]);
  1704. ast_moutdwm(ast, 0x1E6E02F8, ddr_table[REGIDX_2F8]);
  1705. ast_moutdwm(ast, 0x1E6E0290, 0x00100008);
  1706. ast_moutdwm(ast, 0x1E6E02C0, 0x00000006);
  1707. /* Controller Setting */
  1708. ast_moutdwm(ast, 0x1E6E0034, 0x00020091);
  1709. /* Wait DDR PHY init done */
  1710. ddr_phy_init_2500(ast);
  1711. ast_moutdwm(ast, 0x1E6E0120, ddr_table[REGIDX_PLL]);
  1712. ast_moutdwm(ast, 0x1E6E000C, 0x42AA5C81);
  1713. ast_moutdwm(ast, 0x1E6E0034, 0x0001AF93);
  1714. check_dram_size_2500(ast, ddr_table[REGIDX_RFC]);
  1715. enable_cache_2500(ast);
  1716. ast_moutdwm(ast, 0x1E6E001C, 0x00000008);
  1717. ast_moutdwm(ast, 0x1E6E0038, 0xFFFFFF00);
  1718. }
  1719. static void ddr4_init_2500(struct ast_private *ast, const u32 *ddr_table)
  1720. {
  1721. u32 data, data2, pass, retrycnt;
  1722. u32 ddr_vref, phy_vref;
  1723. u32 min_ddr_vref = 0, min_phy_vref = 0;
  1724. u32 max_ddr_vref = 0, max_phy_vref = 0;
  1725. ast_moutdwm(ast, 0x1E6E0004, 0x00000313);
  1726. ast_moutdwm(ast, 0x1E6E0010, ddr_table[REGIDX_010]);
  1727. ast_moutdwm(ast, 0x1E6E0014, ddr_table[REGIDX_014]);
  1728. ast_moutdwm(ast, 0x1E6E0018, ddr_table[REGIDX_018]);
  1729. ast_moutdwm(ast, 0x1E6E0020, ddr_table[REGIDX_020]); /* MODEREG4/6 */
  1730. ast_moutdwm(ast, 0x1E6E0024, ddr_table[REGIDX_024]); /* MODEREG5 */
  1731. ast_moutdwm(ast, 0x1E6E002C, ddr_table[REGIDX_02C] | 0x100); /* MODEREG0/2 */
  1732. ast_moutdwm(ast, 0x1E6E0030, ddr_table[REGIDX_030]); /* MODEREG1/3 */
  1733. /* DDR PHY Setting */
  1734. ast_moutdwm(ast, 0x1E6E0200, 0x42492AAE);
  1735. ast_moutdwm(ast, 0x1E6E0204, 0x09002000);
  1736. ast_moutdwm(ast, 0x1E6E020C, 0x55E00B0B);
  1737. ast_moutdwm(ast, 0x1E6E0210, 0x20000000);
  1738. ast_moutdwm(ast, 0x1E6E0214, ddr_table[REGIDX_214]);
  1739. ast_moutdwm(ast, 0x1E6E02E0, ddr_table[REGIDX_2E0]);
  1740. ast_moutdwm(ast, 0x1E6E02E4, ddr_table[REGIDX_2E4]);
  1741. ast_moutdwm(ast, 0x1E6E02E8, ddr_table[REGIDX_2E8]);
  1742. ast_moutdwm(ast, 0x1E6E02EC, ddr_table[REGIDX_2EC]);
  1743. ast_moutdwm(ast, 0x1E6E02F0, ddr_table[REGIDX_2F0]);
  1744. ast_moutdwm(ast, 0x1E6E02F4, ddr_table[REGIDX_2F4]);
  1745. ast_moutdwm(ast, 0x1E6E02F8, ddr_table[REGIDX_2F8]);
  1746. ast_moutdwm(ast, 0x1E6E0290, 0x00100008);
  1747. ast_moutdwm(ast, 0x1E6E02C4, 0x3C183C3C);
  1748. ast_moutdwm(ast, 0x1E6E02C8, 0x00631E0E);
  1749. /* Controller Setting */
  1750. ast_moutdwm(ast, 0x1E6E0034, 0x0001A991);
  1751. /* Train PHY Vref first */
  1752. pass = 0;
  1753. for (retrycnt = 0; retrycnt < 4 && pass == 0; retrycnt++) {
  1754. max_phy_vref = 0x0;
  1755. pass = 0;
  1756. ast_moutdwm(ast, 0x1E6E02C0, 0x00001C06);
  1757. for (phy_vref = 0x40; phy_vref < 0x80; phy_vref++) {
  1758. ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
  1759. ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
  1760. ast_moutdwm(ast, 0x1E6E02CC, phy_vref | (phy_vref << 8));
  1761. /* Fire DFI Init */
  1762. ddr_phy_init_2500(ast);
  1763. ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
  1764. if (cbr_test_2500(ast)) {
  1765. pass++;
  1766. data = ast_mindwm(ast, 0x1E6E03D0);
  1767. data2 = data >> 8;
  1768. data = data & 0xff;
  1769. if (data > data2)
  1770. data = data2;
  1771. if (max_phy_vref < data) {
  1772. max_phy_vref = data;
  1773. min_phy_vref = phy_vref;
  1774. }
  1775. } else if (pass > 0)
  1776. break;
  1777. }
  1778. }
  1779. ast_moutdwm(ast, 0x1E6E02CC, min_phy_vref | (min_phy_vref << 8));
  1780. /* Train DDR Vref next */
  1781. pass = 0;
  1782. for (retrycnt = 0; retrycnt < 4 && pass == 0; retrycnt++) {
  1783. min_ddr_vref = 0xFF;
  1784. max_ddr_vref = 0x0;
  1785. pass = 0;
  1786. for (ddr_vref = 0x00; ddr_vref < 0x40; ddr_vref++) {
  1787. ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
  1788. ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
  1789. ast_moutdwm(ast, 0x1E6E02C0, 0x00000006 | (ddr_vref << 8));
  1790. /* Fire DFI Init */
  1791. ddr_phy_init_2500(ast);
  1792. ast_moutdwm(ast, 0x1E6E000C, 0x00005C01);
  1793. if (cbr_test_2500(ast)) {
  1794. pass++;
  1795. if (min_ddr_vref > ddr_vref)
  1796. min_ddr_vref = ddr_vref;
  1797. if (max_ddr_vref < ddr_vref)
  1798. max_ddr_vref = ddr_vref;
  1799. } else if (pass != 0)
  1800. break;
  1801. }
  1802. }
  1803. ast_moutdwm(ast, 0x1E6E000C, 0x00000000);
  1804. ast_moutdwm(ast, 0x1E6E0060, 0x00000000);
  1805. ddr_vref = (min_ddr_vref + max_ddr_vref + 1) >> 1;
  1806. ast_moutdwm(ast, 0x1E6E02C0, 0x00000006 | (ddr_vref << 8));
  1807. /* Wait DDR PHY init done */
  1808. ddr_phy_init_2500(ast);
  1809. ast_moutdwm(ast, 0x1E6E0120, ddr_table[REGIDX_PLL]);
  1810. ast_moutdwm(ast, 0x1E6E000C, 0x42AA5C81);
  1811. ast_moutdwm(ast, 0x1E6E0034, 0x0001AF93);
  1812. check_dram_size_2500(ast, ddr_table[REGIDX_RFC]);
  1813. enable_cache_2500(ast);
  1814. ast_moutdwm(ast, 0x1E6E001C, 0x00000008);
  1815. ast_moutdwm(ast, 0x1E6E0038, 0xFFFFFF00);
  1816. }
  1817. static bool ast_dram_init_2500(struct ast_private *ast)
  1818. {
  1819. u32 data;
  1820. u32 max_tries = 5;
  1821. do {
  1822. if (max_tries-- == 0)
  1823. return false;
  1824. set_mpll_2500(ast);
  1825. reset_mmc_2500(ast);
  1826. ddr_init_common_2500(ast);
  1827. data = ast_mindwm(ast, 0x1E6E2070);
  1828. if (data & 0x01000000)
  1829. ddr4_init_2500(ast, ast2500_ddr4_1600_timing_table);
  1830. else
  1831. ddr3_init_2500(ast, ast2500_ddr3_1600_timing_table);
  1832. } while (!ddr_test_2500(ast));
  1833. ast_moutdwm(ast, 0x1E6E2040, ast_mindwm(ast, 0x1E6E2040) | 0x41);
  1834. /* Patch code */
  1835. data = ast_mindwm(ast, 0x1E6E200C) & 0xF9FFFFFF;
  1836. ast_moutdwm(ast, 0x1E6E200C, data | 0x10000000);
  1837. return true;
  1838. }
  1839. void ast_post_chip_2500(struct drm_device *dev)
  1840. {
  1841. struct ast_private *ast = dev->dev_private;
  1842. u32 temp;
  1843. u8 reg;
  1844. reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
  1845. if ((reg & 0x80) == 0) {/* vga only */
  1846. /* Clear bus lock condition */
  1847. ast_moutdwm(ast, 0x1e600000, 0xAEED1A03);
  1848. ast_moutdwm(ast, 0x1e600084, 0x00010000);
  1849. ast_moutdwm(ast, 0x1e600088, 0x00000000);
  1850. ast_moutdwm(ast, 0x1e6e2000, 0x1688A8A8);
  1851. ast_write32(ast, 0xf004, 0x1e6e0000);
  1852. ast_write32(ast, 0xf000, 0x1);
  1853. ast_write32(ast, 0x12000, 0x1688a8a8);
  1854. while (ast_read32(ast, 0x12000) != 0x1)
  1855. ;
  1856. ast_write32(ast, 0x10000, 0xfc600309);
  1857. while (ast_read32(ast, 0x10000) != 0x1)
  1858. ;
  1859. /* Slow down CPU/AHB CLK in VGA only mode */
  1860. temp = ast_read32(ast, 0x12008);
  1861. temp |= 0x73;
  1862. ast_write32(ast, 0x12008, temp);
  1863. /* Reset USB port to patch USB unknown device issue */
  1864. ast_moutdwm(ast, 0x1e6e2090, 0x20000000);
  1865. temp = ast_mindwm(ast, 0x1e6e2094);
  1866. temp |= 0x00004000;
  1867. ast_moutdwm(ast, 0x1e6e2094, temp);
  1868. temp = ast_mindwm(ast, 0x1e6e2070);
  1869. if (temp & 0x00800000) {
  1870. ast_moutdwm(ast, 0x1e6e207c, 0x00800000);
  1871. mdelay(100);
  1872. ast_moutdwm(ast, 0x1e6e2070, 0x00800000);
  1873. }
  1874. if (!ast_dram_init_2500(ast))
  1875. DRM_ERROR("DRAM init failed !\n");
  1876. temp = ast_mindwm(ast, 0x1e6e2040);
  1877. ast_moutdwm(ast, 0x1e6e2040, temp | 0x40);
  1878. }
  1879. /* wait ready */
  1880. do {
  1881. reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
  1882. } while ((reg & 0x40) == 0);
  1883. }