ast_post.c 43 KB

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