ast_post.c 57 KB

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