ast_post.c 44 KB

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