ast_post.c 43 KB

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