mgag200_mode.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  1. /*
  2. * Copyright 2010 Matt Turner.
  3. * Copyright 2012 Red Hat
  4. *
  5. * This file is subject to the terms and conditions of the GNU General
  6. * Public License version 2. See the file COPYING in the main
  7. * directory of this archive for more details.
  8. *
  9. * Authors: Matthew Garrett
  10. * Matt Turner
  11. * Dave Airlie
  12. */
  13. #include <linux/delay.h>
  14. #include <drm/drmP.h>
  15. #include <drm/drm_crtc_helper.h>
  16. #include <drm/drm_plane_helper.h>
  17. #include "mgag200_drv.h"
  18. #define MGAG200_LUT_SIZE 256
  19. /*
  20. * This file contains setup code for the CRTC.
  21. */
  22. static void mga_crtc_load_lut(struct drm_crtc *crtc)
  23. {
  24. struct mga_crtc *mga_crtc = to_mga_crtc(crtc);
  25. struct drm_device *dev = crtc->dev;
  26. struct mga_device *mdev = dev->dev_private;
  27. struct drm_framebuffer *fb = crtc->primary->fb;
  28. int i;
  29. if (!crtc->enabled)
  30. return;
  31. WREG8(DAC_INDEX + MGA1064_INDEX, 0);
  32. if (fb && fb->bits_per_pixel == 16) {
  33. int inc = (fb->depth == 15) ? 8 : 4;
  34. u8 r, b;
  35. for (i = 0; i < MGAG200_LUT_SIZE; i += inc) {
  36. if (fb->depth == 16) {
  37. if (i > (MGAG200_LUT_SIZE >> 1)) {
  38. r = b = 0;
  39. } else {
  40. r = mga_crtc->lut_r[i << 1];
  41. b = mga_crtc->lut_b[i << 1];
  42. }
  43. } else {
  44. r = mga_crtc->lut_r[i];
  45. b = mga_crtc->lut_b[i];
  46. }
  47. /* VGA registers */
  48. WREG8(DAC_INDEX + MGA1064_COL_PAL, r);
  49. WREG8(DAC_INDEX + MGA1064_COL_PAL, mga_crtc->lut_g[i]);
  50. WREG8(DAC_INDEX + MGA1064_COL_PAL, b);
  51. }
  52. return;
  53. }
  54. for (i = 0; i < MGAG200_LUT_SIZE; i++) {
  55. /* VGA registers */
  56. WREG8(DAC_INDEX + MGA1064_COL_PAL, mga_crtc->lut_r[i]);
  57. WREG8(DAC_INDEX + MGA1064_COL_PAL, mga_crtc->lut_g[i]);
  58. WREG8(DAC_INDEX + MGA1064_COL_PAL, mga_crtc->lut_b[i]);
  59. }
  60. }
  61. static inline void mga_wait_vsync(struct mga_device *mdev)
  62. {
  63. unsigned long timeout = jiffies + HZ/10;
  64. unsigned int status = 0;
  65. do {
  66. status = RREG32(MGAREG_Status);
  67. } while ((status & 0x08) && time_before(jiffies, timeout));
  68. timeout = jiffies + HZ/10;
  69. status = 0;
  70. do {
  71. status = RREG32(MGAREG_Status);
  72. } while (!(status & 0x08) && time_before(jiffies, timeout));
  73. }
  74. static inline void mga_wait_busy(struct mga_device *mdev)
  75. {
  76. unsigned long timeout = jiffies + HZ;
  77. unsigned int status = 0;
  78. do {
  79. status = RREG8(MGAREG_Status + 2);
  80. } while ((status & 0x01) && time_before(jiffies, timeout));
  81. }
  82. /*
  83. * The core passes the desired mode to the CRTC code to see whether any
  84. * CRTC-specific modifications need to be made to it. We're in a position
  85. * to just pass that straight through, so this does nothing
  86. */
  87. static bool mga_crtc_mode_fixup(struct drm_crtc *crtc,
  88. const struct drm_display_mode *mode,
  89. struct drm_display_mode *adjusted_mode)
  90. {
  91. return true;
  92. }
  93. #define P_ARRAY_SIZE 9
  94. static int mga_g200se_set_plls(struct mga_device *mdev, long clock)
  95. {
  96. unsigned int vcomax, vcomin, pllreffreq;
  97. unsigned int delta, tmpdelta, permitteddelta;
  98. unsigned int testp, testm, testn;
  99. unsigned int p, m, n;
  100. unsigned int computed;
  101. unsigned int pvalues_e4[P_ARRAY_SIZE] = {16, 14, 12, 10, 8, 6, 4, 2, 1};
  102. unsigned int fvv;
  103. unsigned int i;
  104. if (mdev->unique_rev_id <= 0x03) {
  105. m = n = p = 0;
  106. vcomax = 320000;
  107. vcomin = 160000;
  108. pllreffreq = 25000;
  109. delta = 0xffffffff;
  110. permitteddelta = clock * 5 / 1000;
  111. for (testp = 8; testp > 0; testp /= 2) {
  112. if (clock * testp > vcomax)
  113. continue;
  114. if (clock * testp < vcomin)
  115. continue;
  116. for (testn = 17; testn < 256; testn++) {
  117. for (testm = 1; testm < 32; testm++) {
  118. computed = (pllreffreq * testn) /
  119. (testm * testp);
  120. if (computed > clock)
  121. tmpdelta = computed - clock;
  122. else
  123. tmpdelta = clock - computed;
  124. if (tmpdelta < delta) {
  125. delta = tmpdelta;
  126. m = testm - 1;
  127. n = testn - 1;
  128. p = testp - 1;
  129. }
  130. }
  131. }
  132. }
  133. } else {
  134. m = n = p = 0;
  135. vcomax = 1600000;
  136. vcomin = 800000;
  137. pllreffreq = 25000;
  138. if (clock < 25000)
  139. clock = 25000;
  140. clock = clock * 2;
  141. delta = 0xFFFFFFFF;
  142. /* Permited delta is 0.5% as VESA Specification */
  143. permitteddelta = clock * 5 / 1000;
  144. for (i = 0 ; i < P_ARRAY_SIZE ; i++) {
  145. testp = pvalues_e4[i];
  146. if ((clock * testp) > vcomax)
  147. continue;
  148. if ((clock * testp) < vcomin)
  149. continue;
  150. for (testn = 50; testn <= 256; testn++) {
  151. for (testm = 1; testm <= 32; testm++) {
  152. computed = (pllreffreq * testn) /
  153. (testm * testp);
  154. if (computed > clock)
  155. tmpdelta = computed - clock;
  156. else
  157. tmpdelta = clock - computed;
  158. if (tmpdelta < delta) {
  159. delta = tmpdelta;
  160. m = testm - 1;
  161. n = testn - 1;
  162. p = testp - 1;
  163. }
  164. }
  165. }
  166. }
  167. fvv = pllreffreq * testn / testm;
  168. fvv = (fvv - 800000) / 50000;
  169. if (fvv > 15)
  170. fvv = 15;
  171. p |= (fvv << 4);
  172. m |= 0x80;
  173. clock = clock / 2;
  174. }
  175. if (delta > permitteddelta) {
  176. printk(KERN_WARNING "PLL delta too large\n");
  177. return 1;
  178. }
  179. WREG_DAC(MGA1064_PIX_PLLC_M, m);
  180. WREG_DAC(MGA1064_PIX_PLLC_N, n);
  181. WREG_DAC(MGA1064_PIX_PLLC_P, p);
  182. return 0;
  183. }
  184. static int mga_g200wb_set_plls(struct mga_device *mdev, long clock)
  185. {
  186. unsigned int vcomax, vcomin, pllreffreq;
  187. unsigned int delta, tmpdelta;
  188. unsigned int testp, testm, testn, testp2;
  189. unsigned int p, m, n;
  190. unsigned int computed;
  191. int i, j, tmpcount, vcount;
  192. bool pll_locked = false;
  193. u8 tmp;
  194. m = n = p = 0;
  195. delta = 0xffffffff;
  196. if (mdev->type == G200_EW3) {
  197. vcomax = 800000;
  198. vcomin = 400000;
  199. pllreffreq = 25000;
  200. for (testp = 1; testp < 8; testp++) {
  201. for (testp2 = 1; testp2 < 8; testp2++) {
  202. if (testp < testp2)
  203. continue;
  204. if ((clock * testp * testp2) > vcomax)
  205. continue;
  206. if ((clock * testp * testp2) < vcomin)
  207. continue;
  208. for (testm = 1; testm < 26; testm++) {
  209. for (testn = 32; testn < 2048 ; testn++) {
  210. computed = (pllreffreq * testn) /
  211. (testm * testp * testp2);
  212. if (computed > clock)
  213. tmpdelta = computed - clock;
  214. else
  215. tmpdelta = clock - computed;
  216. if (tmpdelta < delta) {
  217. delta = tmpdelta;
  218. m = ((testn & 0x100) >> 1) |
  219. (testm);
  220. n = (testn & 0xFF);
  221. p = ((testn & 0x600) >> 3) |
  222. (testp2 << 3) |
  223. (testp);
  224. }
  225. }
  226. }
  227. }
  228. }
  229. } else {
  230. vcomax = 550000;
  231. vcomin = 150000;
  232. pllreffreq = 48000;
  233. for (testp = 1; testp < 9; testp++) {
  234. if (clock * testp > vcomax)
  235. continue;
  236. if (clock * testp < vcomin)
  237. continue;
  238. for (testm = 1; testm < 17; testm++) {
  239. for (testn = 1; testn < 151; testn++) {
  240. computed = (pllreffreq * testn) /
  241. (testm * testp);
  242. if (computed > clock)
  243. tmpdelta = computed - clock;
  244. else
  245. tmpdelta = clock - computed;
  246. if (tmpdelta < delta) {
  247. delta = tmpdelta;
  248. n = testn - 1;
  249. m = (testm - 1) |
  250. ((n >> 1) & 0x80);
  251. p = testp - 1;
  252. }
  253. }
  254. }
  255. }
  256. }
  257. for (i = 0; i <= 32 && pll_locked == false; i++) {
  258. if (i > 0) {
  259. WREG8(MGAREG_CRTC_INDEX, 0x1e);
  260. tmp = RREG8(MGAREG_CRTC_DATA);
  261. if (tmp < 0xff)
  262. WREG8(MGAREG_CRTC_DATA, tmp+1);
  263. }
  264. /* set pixclkdis to 1 */
  265. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  266. tmp = RREG8(DAC_DATA);
  267. tmp |= MGA1064_PIX_CLK_CTL_CLK_DIS;
  268. WREG8(DAC_DATA, tmp);
  269. WREG8(DAC_INDEX, MGA1064_REMHEADCTL);
  270. tmp = RREG8(DAC_DATA);
  271. tmp |= MGA1064_REMHEADCTL_CLKDIS;
  272. WREG8(DAC_DATA, tmp);
  273. /* select PLL Set C */
  274. tmp = RREG8(MGAREG_MEM_MISC_READ);
  275. tmp |= 0x3 << 2;
  276. WREG8(MGAREG_MEM_MISC_WRITE, tmp);
  277. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  278. tmp = RREG8(DAC_DATA);
  279. tmp |= MGA1064_PIX_CLK_CTL_CLK_POW_DOWN | 0x80;
  280. WREG8(DAC_DATA, tmp);
  281. udelay(500);
  282. /* reset the PLL */
  283. WREG8(DAC_INDEX, MGA1064_VREF_CTL);
  284. tmp = RREG8(DAC_DATA);
  285. tmp &= ~0x04;
  286. WREG8(DAC_DATA, tmp);
  287. udelay(50);
  288. /* program pixel pll register */
  289. WREG_DAC(MGA1064_WB_PIX_PLLC_N, n);
  290. WREG_DAC(MGA1064_WB_PIX_PLLC_M, m);
  291. WREG_DAC(MGA1064_WB_PIX_PLLC_P, p);
  292. udelay(50);
  293. /* turn pll on */
  294. WREG8(DAC_INDEX, MGA1064_VREF_CTL);
  295. tmp = RREG8(DAC_DATA);
  296. tmp |= 0x04;
  297. WREG_DAC(MGA1064_VREF_CTL, tmp);
  298. udelay(500);
  299. /* select the pixel pll */
  300. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  301. tmp = RREG8(DAC_DATA);
  302. tmp &= ~MGA1064_PIX_CLK_CTL_SEL_MSK;
  303. tmp |= MGA1064_PIX_CLK_CTL_SEL_PLL;
  304. WREG8(DAC_DATA, tmp);
  305. WREG8(DAC_INDEX, MGA1064_REMHEADCTL);
  306. tmp = RREG8(DAC_DATA);
  307. tmp &= ~MGA1064_REMHEADCTL_CLKSL_MSK;
  308. tmp |= MGA1064_REMHEADCTL_CLKSL_PLL;
  309. WREG8(DAC_DATA, tmp);
  310. /* reset dotclock rate bit */
  311. WREG8(MGAREG_SEQ_INDEX, 1);
  312. tmp = RREG8(MGAREG_SEQ_DATA);
  313. tmp &= ~0x8;
  314. WREG8(MGAREG_SEQ_DATA, tmp);
  315. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  316. tmp = RREG8(DAC_DATA);
  317. tmp &= ~MGA1064_PIX_CLK_CTL_CLK_DIS;
  318. WREG8(DAC_DATA, tmp);
  319. vcount = RREG8(MGAREG_VCOUNT);
  320. for (j = 0; j < 30 && pll_locked == false; j++) {
  321. tmpcount = RREG8(MGAREG_VCOUNT);
  322. if (tmpcount < vcount)
  323. vcount = 0;
  324. if ((tmpcount - vcount) > 2)
  325. pll_locked = true;
  326. else
  327. udelay(5);
  328. }
  329. }
  330. WREG8(DAC_INDEX, MGA1064_REMHEADCTL);
  331. tmp = RREG8(DAC_DATA);
  332. tmp &= ~MGA1064_REMHEADCTL_CLKDIS;
  333. WREG_DAC(MGA1064_REMHEADCTL, tmp);
  334. return 0;
  335. }
  336. static int mga_g200ev_set_plls(struct mga_device *mdev, long clock)
  337. {
  338. unsigned int vcomax, vcomin, pllreffreq;
  339. unsigned int delta, tmpdelta;
  340. unsigned int testp, testm, testn;
  341. unsigned int p, m, n;
  342. unsigned int computed;
  343. u8 tmp;
  344. m = n = p = 0;
  345. vcomax = 550000;
  346. vcomin = 150000;
  347. pllreffreq = 50000;
  348. delta = 0xffffffff;
  349. for (testp = 16; testp > 0; testp--) {
  350. if (clock * testp > vcomax)
  351. continue;
  352. if (clock * testp < vcomin)
  353. continue;
  354. for (testn = 1; testn < 257; testn++) {
  355. for (testm = 1; testm < 17; testm++) {
  356. computed = (pllreffreq * testn) /
  357. (testm * testp);
  358. if (computed > clock)
  359. tmpdelta = computed - clock;
  360. else
  361. tmpdelta = clock - computed;
  362. if (tmpdelta < delta) {
  363. delta = tmpdelta;
  364. n = testn - 1;
  365. m = testm - 1;
  366. p = testp - 1;
  367. }
  368. }
  369. }
  370. }
  371. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  372. tmp = RREG8(DAC_DATA);
  373. tmp |= MGA1064_PIX_CLK_CTL_CLK_DIS;
  374. WREG8(DAC_DATA, tmp);
  375. tmp = RREG8(MGAREG_MEM_MISC_READ);
  376. tmp |= 0x3 << 2;
  377. WREG8(MGAREG_MEM_MISC_WRITE, tmp);
  378. WREG8(DAC_INDEX, MGA1064_PIX_PLL_STAT);
  379. tmp = RREG8(DAC_DATA);
  380. WREG8(DAC_DATA, tmp & ~0x40);
  381. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  382. tmp = RREG8(DAC_DATA);
  383. tmp |= MGA1064_PIX_CLK_CTL_CLK_POW_DOWN;
  384. WREG8(DAC_DATA, tmp);
  385. WREG_DAC(MGA1064_EV_PIX_PLLC_M, m);
  386. WREG_DAC(MGA1064_EV_PIX_PLLC_N, n);
  387. WREG_DAC(MGA1064_EV_PIX_PLLC_P, p);
  388. udelay(50);
  389. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  390. tmp = RREG8(DAC_DATA);
  391. tmp &= ~MGA1064_PIX_CLK_CTL_CLK_POW_DOWN;
  392. WREG8(DAC_DATA, tmp);
  393. udelay(500);
  394. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  395. tmp = RREG8(DAC_DATA);
  396. tmp &= ~MGA1064_PIX_CLK_CTL_SEL_MSK;
  397. tmp |= MGA1064_PIX_CLK_CTL_SEL_PLL;
  398. WREG8(DAC_DATA, tmp);
  399. WREG8(DAC_INDEX, MGA1064_PIX_PLL_STAT);
  400. tmp = RREG8(DAC_DATA);
  401. WREG8(DAC_DATA, tmp | 0x40);
  402. tmp = RREG8(MGAREG_MEM_MISC_READ);
  403. tmp |= (0x3 << 2);
  404. WREG8(MGAREG_MEM_MISC_WRITE, tmp);
  405. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  406. tmp = RREG8(DAC_DATA);
  407. tmp &= ~MGA1064_PIX_CLK_CTL_CLK_DIS;
  408. WREG8(DAC_DATA, tmp);
  409. return 0;
  410. }
  411. static int mga_g200eh_set_plls(struct mga_device *mdev, long clock)
  412. {
  413. unsigned int vcomax, vcomin, pllreffreq;
  414. unsigned int delta, tmpdelta;
  415. unsigned int testp, testm, testn;
  416. unsigned int p, m, n;
  417. unsigned int computed;
  418. int i, j, tmpcount, vcount;
  419. u8 tmp;
  420. bool pll_locked = false;
  421. m = n = p = 0;
  422. vcomax = 800000;
  423. vcomin = 400000;
  424. pllreffreq = 33333;
  425. delta = 0xffffffff;
  426. for (testp = 16; testp > 0; testp >>= 1) {
  427. if (clock * testp > vcomax)
  428. continue;
  429. if (clock * testp < vcomin)
  430. continue;
  431. for (testm = 1; testm < 33; testm++) {
  432. for (testn = 17; testn < 257; testn++) {
  433. computed = (pllreffreq * testn) /
  434. (testm * testp);
  435. if (computed > clock)
  436. tmpdelta = computed - clock;
  437. else
  438. tmpdelta = clock - computed;
  439. if (tmpdelta < delta) {
  440. delta = tmpdelta;
  441. n = testn - 1;
  442. m = (testm - 1);
  443. p = testp - 1;
  444. }
  445. if ((clock * testp) >= 600000)
  446. p |= 0x80;
  447. }
  448. }
  449. }
  450. for (i = 0; i <= 32 && pll_locked == false; i++) {
  451. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  452. tmp = RREG8(DAC_DATA);
  453. tmp |= MGA1064_PIX_CLK_CTL_CLK_DIS;
  454. WREG8(DAC_DATA, tmp);
  455. tmp = RREG8(MGAREG_MEM_MISC_READ);
  456. tmp |= 0x3 << 2;
  457. WREG8(MGAREG_MEM_MISC_WRITE, tmp);
  458. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  459. tmp = RREG8(DAC_DATA);
  460. tmp |= MGA1064_PIX_CLK_CTL_CLK_POW_DOWN;
  461. WREG8(DAC_DATA, tmp);
  462. udelay(500);
  463. WREG_DAC(MGA1064_EH_PIX_PLLC_M, m);
  464. WREG_DAC(MGA1064_EH_PIX_PLLC_N, n);
  465. WREG_DAC(MGA1064_EH_PIX_PLLC_P, p);
  466. udelay(500);
  467. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  468. tmp = RREG8(DAC_DATA);
  469. tmp &= ~MGA1064_PIX_CLK_CTL_SEL_MSK;
  470. tmp |= MGA1064_PIX_CLK_CTL_SEL_PLL;
  471. WREG8(DAC_DATA, tmp);
  472. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  473. tmp = RREG8(DAC_DATA);
  474. tmp &= ~MGA1064_PIX_CLK_CTL_CLK_DIS;
  475. tmp &= ~MGA1064_PIX_CLK_CTL_CLK_POW_DOWN;
  476. WREG8(DAC_DATA, tmp);
  477. vcount = RREG8(MGAREG_VCOUNT);
  478. for (j = 0; j < 30 && pll_locked == false; j++) {
  479. tmpcount = RREG8(MGAREG_VCOUNT);
  480. if (tmpcount < vcount)
  481. vcount = 0;
  482. if ((tmpcount - vcount) > 2)
  483. pll_locked = true;
  484. else
  485. udelay(5);
  486. }
  487. }
  488. return 0;
  489. }
  490. static int mga_g200er_set_plls(struct mga_device *mdev, long clock)
  491. {
  492. unsigned int vcomax, vcomin, pllreffreq;
  493. unsigned int delta, tmpdelta;
  494. int testr, testn, testm, testo;
  495. unsigned int p, m, n;
  496. unsigned int computed, vco;
  497. int tmp;
  498. const unsigned int m_div_val[] = { 1, 2, 4, 8 };
  499. m = n = p = 0;
  500. vcomax = 1488000;
  501. vcomin = 1056000;
  502. pllreffreq = 48000;
  503. delta = 0xffffffff;
  504. for (testr = 0; testr < 4; testr++) {
  505. if (delta == 0)
  506. break;
  507. for (testn = 5; testn < 129; testn++) {
  508. if (delta == 0)
  509. break;
  510. for (testm = 3; testm >= 0; testm--) {
  511. if (delta == 0)
  512. break;
  513. for (testo = 5; testo < 33; testo++) {
  514. vco = pllreffreq * (testn + 1) /
  515. (testr + 1);
  516. if (vco < vcomin)
  517. continue;
  518. if (vco > vcomax)
  519. continue;
  520. computed = vco / (m_div_val[testm] * (testo + 1));
  521. if (computed > clock)
  522. tmpdelta = computed - clock;
  523. else
  524. tmpdelta = clock - computed;
  525. if (tmpdelta < delta) {
  526. delta = tmpdelta;
  527. m = testm | (testo << 3);
  528. n = testn;
  529. p = testr | (testr << 3);
  530. }
  531. }
  532. }
  533. }
  534. }
  535. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  536. tmp = RREG8(DAC_DATA);
  537. tmp |= MGA1064_PIX_CLK_CTL_CLK_DIS;
  538. WREG8(DAC_DATA, tmp);
  539. WREG8(DAC_INDEX, MGA1064_REMHEADCTL);
  540. tmp = RREG8(DAC_DATA);
  541. tmp |= MGA1064_REMHEADCTL_CLKDIS;
  542. WREG8(DAC_DATA, tmp);
  543. tmp = RREG8(MGAREG_MEM_MISC_READ);
  544. tmp |= (0x3<<2) | 0xc0;
  545. WREG8(MGAREG_MEM_MISC_WRITE, tmp);
  546. WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
  547. tmp = RREG8(DAC_DATA);
  548. tmp &= ~MGA1064_PIX_CLK_CTL_CLK_DIS;
  549. tmp |= MGA1064_PIX_CLK_CTL_CLK_POW_DOWN;
  550. WREG8(DAC_DATA, tmp);
  551. udelay(500);
  552. WREG_DAC(MGA1064_ER_PIX_PLLC_N, n);
  553. WREG_DAC(MGA1064_ER_PIX_PLLC_M, m);
  554. WREG_DAC(MGA1064_ER_PIX_PLLC_P, p);
  555. udelay(50);
  556. return 0;
  557. }
  558. static int mga_crtc_set_plls(struct mga_device *mdev, long clock)
  559. {
  560. switch(mdev->type) {
  561. case G200_SE_A:
  562. case G200_SE_B:
  563. return mga_g200se_set_plls(mdev, clock);
  564. break;
  565. case G200_WB:
  566. case G200_EW3:
  567. return mga_g200wb_set_plls(mdev, clock);
  568. break;
  569. case G200_EV:
  570. return mga_g200ev_set_plls(mdev, clock);
  571. break;
  572. case G200_EH:
  573. return mga_g200eh_set_plls(mdev, clock);
  574. break;
  575. case G200_ER:
  576. return mga_g200er_set_plls(mdev, clock);
  577. break;
  578. }
  579. return 0;
  580. }
  581. static void mga_g200wb_prepare(struct drm_crtc *crtc)
  582. {
  583. struct mga_device *mdev = crtc->dev->dev_private;
  584. u8 tmp;
  585. int iter_max;
  586. /* 1- The first step is to warn the BMC of an upcoming mode change.
  587. * We are putting the misc<0> to output.*/
  588. WREG8(DAC_INDEX, MGA1064_GEN_IO_CTL);
  589. tmp = RREG8(DAC_DATA);
  590. tmp |= 0x10;
  591. WREG_DAC(MGA1064_GEN_IO_CTL, tmp);
  592. /* we are putting a 1 on the misc<0> line */
  593. WREG8(DAC_INDEX, MGA1064_GEN_IO_DATA);
  594. tmp = RREG8(DAC_DATA);
  595. tmp |= 0x10;
  596. WREG_DAC(MGA1064_GEN_IO_DATA, tmp);
  597. /* 2- Second step to mask and further scan request
  598. * This will be done by asserting the remfreqmsk bit (XSPAREREG<7>)
  599. */
  600. WREG8(DAC_INDEX, MGA1064_SPAREREG);
  601. tmp = RREG8(DAC_DATA);
  602. tmp |= 0x80;
  603. WREG_DAC(MGA1064_SPAREREG, tmp);
  604. /* 3a- the third step is to verifu if there is an active scan
  605. * We are searching for a 0 on remhsyncsts <XSPAREREG<0>)
  606. */
  607. iter_max = 300;
  608. while (!(tmp & 0x1) && iter_max) {
  609. WREG8(DAC_INDEX, MGA1064_SPAREREG);
  610. tmp = RREG8(DAC_DATA);
  611. udelay(1000);
  612. iter_max--;
  613. }
  614. /* 3b- this step occurs only if the remove is actually scanning
  615. * we are waiting for the end of the frame which is a 1 on
  616. * remvsyncsts (XSPAREREG<1>)
  617. */
  618. if (iter_max) {
  619. iter_max = 300;
  620. while ((tmp & 0x2) && iter_max) {
  621. WREG8(DAC_INDEX, MGA1064_SPAREREG);
  622. tmp = RREG8(DAC_DATA);
  623. udelay(1000);
  624. iter_max--;
  625. }
  626. }
  627. }
  628. static void mga_g200wb_commit(struct drm_crtc *crtc)
  629. {
  630. u8 tmp;
  631. struct mga_device *mdev = crtc->dev->dev_private;
  632. /* 1- The first step is to ensure that the vrsten and hrsten are set */
  633. WREG8(MGAREG_CRTCEXT_INDEX, 1);
  634. tmp = RREG8(MGAREG_CRTCEXT_DATA);
  635. WREG8(MGAREG_CRTCEXT_DATA, tmp | 0x88);
  636. /* 2- second step is to assert the rstlvl2 */
  637. WREG8(DAC_INDEX, MGA1064_REMHEADCTL2);
  638. tmp = RREG8(DAC_DATA);
  639. tmp |= 0x8;
  640. WREG8(DAC_DATA, tmp);
  641. /* wait 10 us */
  642. udelay(10);
  643. /* 3- deassert rstlvl2 */
  644. tmp &= ~0x08;
  645. WREG8(DAC_INDEX, MGA1064_REMHEADCTL2);
  646. WREG8(DAC_DATA, tmp);
  647. /* 4- remove mask of scan request */
  648. WREG8(DAC_INDEX, MGA1064_SPAREREG);
  649. tmp = RREG8(DAC_DATA);
  650. tmp &= ~0x80;
  651. WREG8(DAC_DATA, tmp);
  652. /* 5- put back a 0 on the misc<0> line */
  653. WREG8(DAC_INDEX, MGA1064_GEN_IO_DATA);
  654. tmp = RREG8(DAC_DATA);
  655. tmp &= ~0x10;
  656. WREG_DAC(MGA1064_GEN_IO_DATA, tmp);
  657. }
  658. /*
  659. This is how the framebuffer base address is stored in g200 cards:
  660. * Assume @offset is the gpu_addr variable of the framebuffer object
  661. * Then addr is the number of _pixels_ (not bytes) from the start of
  662. VRAM to the first pixel we want to display. (divided by 2 for 32bit
  663. framebuffers)
  664. * addr is stored in the CRTCEXT0, CRTCC and CRTCD registers
  665. addr<20> -> CRTCEXT0<6>
  666. addr<19-16> -> CRTCEXT0<3-0>
  667. addr<15-8> -> CRTCC<7-0>
  668. addr<7-0> -> CRTCD<7-0>
  669. CRTCEXT0 has to be programmed last to trigger an update and make the
  670. new addr variable take effect.
  671. */
  672. static void mga_set_start_address(struct drm_crtc *crtc, unsigned offset)
  673. {
  674. struct mga_device *mdev = crtc->dev->dev_private;
  675. u32 addr;
  676. int count;
  677. u8 crtcext0;
  678. while (RREG8(0x1fda) & 0x08);
  679. while (!(RREG8(0x1fda) & 0x08));
  680. count = RREG8(MGAREG_VCOUNT) + 2;
  681. while (RREG8(MGAREG_VCOUNT) < count);
  682. WREG8(MGAREG_CRTCEXT_INDEX, 0);
  683. crtcext0 = RREG8(MGAREG_CRTCEXT_DATA);
  684. crtcext0 &= 0xB0;
  685. addr = offset / 8;
  686. /* Can't store addresses any higher than that...
  687. but we also don't have more than 16MB of memory, so it should be fine. */
  688. WARN_ON(addr > 0x1fffff);
  689. crtcext0 |= (!!(addr & (1<<20)))<<6;
  690. WREG_CRT(0x0d, (u8)(addr & 0xff));
  691. WREG_CRT(0x0c, (u8)(addr >> 8) & 0xff);
  692. WREG_ECRT(0x0, ((u8)(addr >> 16) & 0xf) | crtcext0);
  693. }
  694. /* ast is different - we will force move buffers out of VRAM */
  695. static int mga_crtc_do_set_base(struct drm_crtc *crtc,
  696. struct drm_framebuffer *fb,
  697. int x, int y, int atomic)
  698. {
  699. struct mga_device *mdev = crtc->dev->dev_private;
  700. struct drm_gem_object *obj;
  701. struct mga_framebuffer *mga_fb;
  702. struct mgag200_bo *bo;
  703. int ret;
  704. u64 gpu_addr;
  705. /* push the previous fb to system ram */
  706. if (!atomic && fb) {
  707. mga_fb = to_mga_framebuffer(fb);
  708. obj = mga_fb->obj;
  709. bo = gem_to_mga_bo(obj);
  710. ret = mgag200_bo_reserve(bo, false);
  711. if (ret)
  712. return ret;
  713. mgag200_bo_push_sysram(bo);
  714. mgag200_bo_unreserve(bo);
  715. }
  716. mga_fb = to_mga_framebuffer(crtc->primary->fb);
  717. obj = mga_fb->obj;
  718. bo = gem_to_mga_bo(obj);
  719. ret = mgag200_bo_reserve(bo, false);
  720. if (ret)
  721. return ret;
  722. ret = mgag200_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr);
  723. if (ret) {
  724. mgag200_bo_unreserve(bo);
  725. return ret;
  726. }
  727. if (&mdev->mfbdev->mfb == mga_fb) {
  728. /* if pushing console in kmap it */
  729. ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap);
  730. if (ret)
  731. DRM_ERROR("failed to kmap fbcon\n");
  732. }
  733. mgag200_bo_unreserve(bo);
  734. mga_set_start_address(crtc, (u32)gpu_addr);
  735. return 0;
  736. }
  737. static int mga_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
  738. struct drm_framebuffer *old_fb)
  739. {
  740. return mga_crtc_do_set_base(crtc, old_fb, x, y, 0);
  741. }
  742. static int mga_crtc_mode_set(struct drm_crtc *crtc,
  743. struct drm_display_mode *mode,
  744. struct drm_display_mode *adjusted_mode,
  745. int x, int y, struct drm_framebuffer *old_fb)
  746. {
  747. struct drm_device *dev = crtc->dev;
  748. struct mga_device *mdev = dev->dev_private;
  749. int hdisplay, hsyncstart, hsyncend, htotal;
  750. int vdisplay, vsyncstart, vsyncend, vtotal;
  751. int pitch;
  752. int option = 0, option2 = 0;
  753. int i;
  754. unsigned char misc = 0;
  755. unsigned char ext_vga[6];
  756. u8 bppshift;
  757. static unsigned char dacvalue[] = {
  758. /* 0x00: */ 0, 0, 0, 0, 0, 0, 0x00, 0,
  759. /* 0x08: */ 0, 0, 0, 0, 0, 0, 0, 0,
  760. /* 0x10: */ 0, 0, 0, 0, 0, 0, 0, 0,
  761. /* 0x18: */ 0x00, 0, 0xC9, 0xFF, 0xBF, 0x20, 0x1F, 0x20,
  762. /* 0x20: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  763. /* 0x28: */ 0x00, 0x00, 0x00, 0x00, 0, 0, 0, 0x40,
  764. /* 0x30: */ 0x00, 0xB0, 0x00, 0xC2, 0x34, 0x14, 0x02, 0x83,
  765. /* 0x38: */ 0x00, 0x93, 0x00, 0x77, 0x00, 0x00, 0x00, 0x3A,
  766. /* 0x40: */ 0, 0, 0, 0, 0, 0, 0, 0,
  767. /* 0x48: */ 0, 0, 0, 0, 0, 0, 0, 0
  768. };
  769. bppshift = mdev->bpp_shifts[(crtc->primary->fb->bits_per_pixel >> 3) - 1];
  770. switch (mdev->type) {
  771. case G200_SE_A:
  772. case G200_SE_B:
  773. dacvalue[MGA1064_VREF_CTL] = 0x03;
  774. dacvalue[MGA1064_PIX_CLK_CTL] = MGA1064_PIX_CLK_CTL_SEL_PLL;
  775. dacvalue[MGA1064_MISC_CTL] = MGA1064_MISC_CTL_DAC_EN |
  776. MGA1064_MISC_CTL_VGA8 |
  777. MGA1064_MISC_CTL_DAC_RAM_CS;
  778. if (mdev->has_sdram)
  779. option = 0x40049120;
  780. else
  781. option = 0x4004d120;
  782. option2 = 0x00008000;
  783. break;
  784. case G200_WB:
  785. case G200_EW3:
  786. dacvalue[MGA1064_VREF_CTL] = 0x07;
  787. option = 0x41049120;
  788. option2 = 0x0000b000;
  789. break;
  790. case G200_EV:
  791. dacvalue[MGA1064_PIX_CLK_CTL] = MGA1064_PIX_CLK_CTL_SEL_PLL;
  792. dacvalue[MGA1064_MISC_CTL] = MGA1064_MISC_CTL_VGA8 |
  793. MGA1064_MISC_CTL_DAC_RAM_CS;
  794. option = 0x00000120;
  795. option2 = 0x0000b000;
  796. break;
  797. case G200_EH:
  798. dacvalue[MGA1064_MISC_CTL] = MGA1064_MISC_CTL_VGA8 |
  799. MGA1064_MISC_CTL_DAC_RAM_CS;
  800. option = 0x00000120;
  801. option2 = 0x0000b000;
  802. break;
  803. case G200_ER:
  804. break;
  805. }
  806. switch (crtc->primary->fb->bits_per_pixel) {
  807. case 8:
  808. dacvalue[MGA1064_MUL_CTL] = MGA1064_MUL_CTL_8bits;
  809. break;
  810. case 16:
  811. if (crtc->primary->fb->depth == 15)
  812. dacvalue[MGA1064_MUL_CTL] = MGA1064_MUL_CTL_15bits;
  813. else
  814. dacvalue[MGA1064_MUL_CTL] = MGA1064_MUL_CTL_16bits;
  815. break;
  816. case 24:
  817. dacvalue[MGA1064_MUL_CTL] = MGA1064_MUL_CTL_24bits;
  818. break;
  819. case 32:
  820. dacvalue[MGA1064_MUL_CTL] = MGA1064_MUL_CTL_32_24bits;
  821. break;
  822. }
  823. if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  824. misc |= 0x40;
  825. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  826. misc |= 0x80;
  827. for (i = 0; i < sizeof(dacvalue); i++) {
  828. if ((i <= 0x17) ||
  829. (i == 0x1b) ||
  830. (i == 0x1c) ||
  831. ((i >= 0x1f) && (i <= 0x29)) ||
  832. ((i >= 0x30) && (i <= 0x37)))
  833. continue;
  834. if (IS_G200_SE(mdev) &&
  835. ((i == 0x2c) || (i == 0x2d) || (i == 0x2e)))
  836. continue;
  837. if ((mdev->type == G200_EV ||
  838. mdev->type == G200_WB ||
  839. mdev->type == G200_EH ||
  840. mdev->type == G200_EW3) &&
  841. (i >= 0x44) && (i <= 0x4e))
  842. continue;
  843. WREG_DAC(i, dacvalue[i]);
  844. }
  845. if (mdev->type == G200_ER)
  846. WREG_DAC(0x90, 0);
  847. if (option)
  848. pci_write_config_dword(dev->pdev, PCI_MGA_OPTION, option);
  849. if (option2)
  850. pci_write_config_dword(dev->pdev, PCI_MGA_OPTION2, option2);
  851. WREG_SEQ(2, 0xf);
  852. WREG_SEQ(3, 0);
  853. WREG_SEQ(4, 0xe);
  854. pitch = crtc->primary->fb->pitches[0] / (crtc->primary->fb->bits_per_pixel / 8);
  855. if (crtc->primary->fb->bits_per_pixel == 24)
  856. pitch = (pitch * 3) >> (4 - bppshift);
  857. else
  858. pitch = pitch >> (4 - bppshift);
  859. hdisplay = mode->hdisplay / 8 - 1;
  860. hsyncstart = mode->hsync_start / 8 - 1;
  861. hsyncend = mode->hsync_end / 8 - 1;
  862. htotal = mode->htotal / 8 - 1;
  863. /* Work around hardware quirk */
  864. if ((htotal & 0x07) == 0x06 || (htotal & 0x07) == 0x04)
  865. htotal++;
  866. vdisplay = mode->vdisplay - 1;
  867. vsyncstart = mode->vsync_start - 1;
  868. vsyncend = mode->vsync_end - 1;
  869. vtotal = mode->vtotal - 2;
  870. WREG_GFX(0, 0);
  871. WREG_GFX(1, 0);
  872. WREG_GFX(2, 0);
  873. WREG_GFX(3, 0);
  874. WREG_GFX(4, 0);
  875. WREG_GFX(5, 0x40);
  876. WREG_GFX(6, 0x5);
  877. WREG_GFX(7, 0xf);
  878. WREG_GFX(8, 0xf);
  879. WREG_CRT(0, htotal - 4);
  880. WREG_CRT(1, hdisplay);
  881. WREG_CRT(2, hdisplay);
  882. WREG_CRT(3, (htotal & 0x1F) | 0x80);
  883. WREG_CRT(4, hsyncstart);
  884. WREG_CRT(5, ((htotal & 0x20) << 2) | (hsyncend & 0x1F));
  885. WREG_CRT(6, vtotal & 0xFF);
  886. WREG_CRT(7, ((vtotal & 0x100) >> 8) |
  887. ((vdisplay & 0x100) >> 7) |
  888. ((vsyncstart & 0x100) >> 6) |
  889. ((vdisplay & 0x100) >> 5) |
  890. ((vdisplay & 0x100) >> 4) | /* linecomp */
  891. ((vtotal & 0x200) >> 4)|
  892. ((vdisplay & 0x200) >> 3) |
  893. ((vsyncstart & 0x200) >> 2));
  894. WREG_CRT(9, ((vdisplay & 0x200) >> 4) |
  895. ((vdisplay & 0x200) >> 3));
  896. WREG_CRT(10, 0);
  897. WREG_CRT(11, 0);
  898. WREG_CRT(12, 0);
  899. WREG_CRT(13, 0);
  900. WREG_CRT(14, 0);
  901. WREG_CRT(15, 0);
  902. WREG_CRT(16, vsyncstart & 0xFF);
  903. WREG_CRT(17, (vsyncend & 0x0F) | 0x20);
  904. WREG_CRT(18, vdisplay & 0xFF);
  905. WREG_CRT(19, pitch & 0xFF);
  906. WREG_CRT(20, 0);
  907. WREG_CRT(21, vdisplay & 0xFF);
  908. WREG_CRT(22, (vtotal + 1) & 0xFF);
  909. WREG_CRT(23, 0xc3);
  910. WREG_CRT(24, vdisplay & 0xFF);
  911. ext_vga[0] = 0;
  912. ext_vga[5] = 0;
  913. /* TODO interlace */
  914. ext_vga[0] |= (pitch & 0x300) >> 4;
  915. ext_vga[1] = (((htotal - 4) & 0x100) >> 8) |
  916. ((hdisplay & 0x100) >> 7) |
  917. ((hsyncstart & 0x100) >> 6) |
  918. (htotal & 0x40);
  919. ext_vga[2] = ((vtotal & 0xc00) >> 10) |
  920. ((vdisplay & 0x400) >> 8) |
  921. ((vdisplay & 0xc00) >> 7) |
  922. ((vsyncstart & 0xc00) >> 5) |
  923. ((vdisplay & 0x400) >> 3);
  924. if (crtc->primary->fb->bits_per_pixel == 24)
  925. ext_vga[3] = (((1 << bppshift) * 3) - 1) | 0x80;
  926. else
  927. ext_vga[3] = ((1 << bppshift) - 1) | 0x80;
  928. ext_vga[4] = 0;
  929. if (mdev->type == G200_WB || mdev->type == G200_EW3)
  930. ext_vga[1] |= 0x88;
  931. /* Set pixel clocks */
  932. misc = 0x2d;
  933. WREG8(MGA_MISC_OUT, misc);
  934. mga_crtc_set_plls(mdev, mode->clock);
  935. for (i = 0; i < 6; i++) {
  936. WREG_ECRT(i, ext_vga[i]);
  937. }
  938. if (mdev->type == G200_ER)
  939. WREG_ECRT(0x24, 0x5);
  940. if (mdev->type == G200_EW3)
  941. WREG_ECRT(0x34, 0x5);
  942. if (mdev->type == G200_EV) {
  943. WREG_ECRT(6, 0);
  944. }
  945. WREG_ECRT(0, ext_vga[0]);
  946. /* Enable mga pixel clock */
  947. misc = 0x2d;
  948. WREG8(MGA_MISC_OUT, misc);
  949. if (adjusted_mode)
  950. memcpy(&mdev->mode, mode, sizeof(struct drm_display_mode));
  951. mga_crtc_do_set_base(crtc, old_fb, x, y, 0);
  952. /* reset tagfifo */
  953. if (mdev->type == G200_ER) {
  954. u32 mem_ctl = RREG32(MGAREG_MEMCTL);
  955. u8 seq1;
  956. /* screen off */
  957. WREG8(MGAREG_SEQ_INDEX, 0x01);
  958. seq1 = RREG8(MGAREG_SEQ_DATA) | 0x20;
  959. WREG8(MGAREG_SEQ_DATA, seq1);
  960. WREG32(MGAREG_MEMCTL, mem_ctl | 0x00200000);
  961. udelay(1000);
  962. WREG32(MGAREG_MEMCTL, mem_ctl & ~0x00200000);
  963. WREG8(MGAREG_SEQ_DATA, seq1 & ~0x20);
  964. }
  965. if (IS_G200_SE(mdev)) {
  966. if (mdev->unique_rev_id >= 0x02) {
  967. u8 hi_pri_lvl;
  968. u32 bpp;
  969. u32 mb;
  970. if (crtc->primary->fb->bits_per_pixel > 16)
  971. bpp = 32;
  972. else if (crtc->primary->fb->bits_per_pixel > 8)
  973. bpp = 16;
  974. else
  975. bpp = 8;
  976. mb = (mode->clock * bpp) / 1000;
  977. if (mb > 3100)
  978. hi_pri_lvl = 0;
  979. else if (mb > 2600)
  980. hi_pri_lvl = 1;
  981. else if (mb > 1900)
  982. hi_pri_lvl = 2;
  983. else if (mb > 1160)
  984. hi_pri_lvl = 3;
  985. else if (mb > 440)
  986. hi_pri_lvl = 4;
  987. else
  988. hi_pri_lvl = 5;
  989. WREG8(MGAREG_CRTCEXT_INDEX, 0x06);
  990. WREG8(MGAREG_CRTCEXT_DATA, hi_pri_lvl);
  991. } else {
  992. WREG8(MGAREG_CRTCEXT_INDEX, 0x06);
  993. if (mdev->unique_rev_id >= 0x01)
  994. WREG8(MGAREG_CRTCEXT_DATA, 0x03);
  995. else
  996. WREG8(MGAREG_CRTCEXT_DATA, 0x04);
  997. }
  998. }
  999. return 0;
  1000. }
  1001. #if 0 /* code from mjg to attempt D3 on crtc dpms off - revisit later */
  1002. static int mga_suspend(struct drm_crtc *crtc)
  1003. {
  1004. struct mga_crtc *mga_crtc = to_mga_crtc(crtc);
  1005. struct drm_device *dev = crtc->dev;
  1006. struct mga_device *mdev = dev->dev_private;
  1007. struct pci_dev *pdev = dev->pdev;
  1008. int option;
  1009. if (mdev->suspended)
  1010. return 0;
  1011. WREG_SEQ(1, 0x20);
  1012. WREG_ECRT(1, 0x30);
  1013. /* Disable the pixel clock */
  1014. WREG_DAC(0x1a, 0x05);
  1015. /* Power down the DAC */
  1016. WREG_DAC(0x1e, 0x18);
  1017. /* Power down the pixel PLL */
  1018. WREG_DAC(0x1a, 0x0d);
  1019. /* Disable PLLs and clocks */
  1020. pci_read_config_dword(pdev, PCI_MGA_OPTION, &option);
  1021. option &= ~(0x1F8024);
  1022. pci_write_config_dword(pdev, PCI_MGA_OPTION, option);
  1023. pci_set_power_state(pdev, PCI_D3hot);
  1024. pci_disable_device(pdev);
  1025. mdev->suspended = true;
  1026. return 0;
  1027. }
  1028. static int mga_resume(struct drm_crtc *crtc)
  1029. {
  1030. struct mga_crtc *mga_crtc = to_mga_crtc(crtc);
  1031. struct drm_device *dev = crtc->dev;
  1032. struct mga_device *mdev = dev->dev_private;
  1033. struct pci_dev *pdev = dev->pdev;
  1034. int option;
  1035. if (!mdev->suspended)
  1036. return 0;
  1037. pci_set_power_state(pdev, PCI_D0);
  1038. pci_enable_device(pdev);
  1039. /* Disable sysclk */
  1040. pci_read_config_dword(pdev, PCI_MGA_OPTION, &option);
  1041. option &= ~(0x4);
  1042. pci_write_config_dword(pdev, PCI_MGA_OPTION, option);
  1043. mdev->suspended = false;
  1044. return 0;
  1045. }
  1046. #endif
  1047. static void mga_crtc_dpms(struct drm_crtc *crtc, int mode)
  1048. {
  1049. struct drm_device *dev = crtc->dev;
  1050. struct mga_device *mdev = dev->dev_private;
  1051. u8 seq1 = 0, crtcext1 = 0;
  1052. switch (mode) {
  1053. case DRM_MODE_DPMS_ON:
  1054. seq1 = 0;
  1055. crtcext1 = 0;
  1056. mga_crtc_load_lut(crtc);
  1057. break;
  1058. case DRM_MODE_DPMS_STANDBY:
  1059. seq1 = 0x20;
  1060. crtcext1 = 0x10;
  1061. break;
  1062. case DRM_MODE_DPMS_SUSPEND:
  1063. seq1 = 0x20;
  1064. crtcext1 = 0x20;
  1065. break;
  1066. case DRM_MODE_DPMS_OFF:
  1067. seq1 = 0x20;
  1068. crtcext1 = 0x30;
  1069. break;
  1070. }
  1071. #if 0
  1072. if (mode == DRM_MODE_DPMS_OFF) {
  1073. mga_suspend(crtc);
  1074. }
  1075. #endif
  1076. WREG8(MGAREG_SEQ_INDEX, 0x01);
  1077. seq1 |= RREG8(MGAREG_SEQ_DATA) & ~0x20;
  1078. mga_wait_vsync(mdev);
  1079. mga_wait_busy(mdev);
  1080. WREG8(MGAREG_SEQ_DATA, seq1);
  1081. msleep(20);
  1082. WREG8(MGAREG_CRTCEXT_INDEX, 0x01);
  1083. crtcext1 |= RREG8(MGAREG_CRTCEXT_DATA) & ~0x30;
  1084. WREG8(MGAREG_CRTCEXT_DATA, crtcext1);
  1085. #if 0
  1086. if (mode == DRM_MODE_DPMS_ON && mdev->suspended == true) {
  1087. mga_resume(crtc);
  1088. drm_helper_resume_force_mode(dev);
  1089. }
  1090. #endif
  1091. }
  1092. /*
  1093. * This is called before a mode is programmed. A typical use might be to
  1094. * enable DPMS during the programming to avoid seeing intermediate stages,
  1095. * but that's not relevant to us
  1096. */
  1097. static void mga_crtc_prepare(struct drm_crtc *crtc)
  1098. {
  1099. struct drm_device *dev = crtc->dev;
  1100. struct mga_device *mdev = dev->dev_private;
  1101. u8 tmp;
  1102. /* mga_resume(crtc);*/
  1103. WREG8(MGAREG_CRTC_INDEX, 0x11);
  1104. tmp = RREG8(MGAREG_CRTC_DATA);
  1105. WREG_CRT(0x11, tmp | 0x80);
  1106. if (mdev->type == G200_SE_A || mdev->type == G200_SE_B) {
  1107. WREG_SEQ(0, 1);
  1108. msleep(50);
  1109. WREG_SEQ(1, 0x20);
  1110. msleep(20);
  1111. } else {
  1112. WREG8(MGAREG_SEQ_INDEX, 0x1);
  1113. tmp = RREG8(MGAREG_SEQ_DATA);
  1114. /* start sync reset */
  1115. WREG_SEQ(0, 1);
  1116. WREG_SEQ(1, tmp | 0x20);
  1117. }
  1118. if (mdev->type == G200_WB || mdev->type == G200_EW3)
  1119. mga_g200wb_prepare(crtc);
  1120. WREG_CRT(17, 0);
  1121. }
  1122. /*
  1123. * This is called after a mode is programmed. It should reverse anything done
  1124. * by the prepare function
  1125. */
  1126. static void mga_crtc_commit(struct drm_crtc *crtc)
  1127. {
  1128. struct drm_device *dev = crtc->dev;
  1129. struct mga_device *mdev = dev->dev_private;
  1130. const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  1131. u8 tmp;
  1132. if (mdev->type == G200_WB || mdev->type == G200_EW3)
  1133. mga_g200wb_commit(crtc);
  1134. if (mdev->type == G200_SE_A || mdev->type == G200_SE_B) {
  1135. msleep(50);
  1136. WREG_SEQ(1, 0x0);
  1137. msleep(20);
  1138. WREG_SEQ(0, 0x3);
  1139. } else {
  1140. WREG8(MGAREG_SEQ_INDEX, 0x1);
  1141. tmp = RREG8(MGAREG_SEQ_DATA);
  1142. tmp &= ~0x20;
  1143. WREG_SEQ(0x1, tmp);
  1144. WREG_SEQ(0, 3);
  1145. }
  1146. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  1147. }
  1148. /*
  1149. * The core can pass us a set of gamma values to program. We actually only
  1150. * use this for 8-bit mode so can't perform smooth fades on deeper modes,
  1151. * but it's a requirement that we provide the function
  1152. */
  1153. static void mga_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  1154. u16 *blue, uint32_t start, uint32_t size)
  1155. {
  1156. struct mga_crtc *mga_crtc = to_mga_crtc(crtc);
  1157. int end = (start + size > MGAG200_LUT_SIZE) ? MGAG200_LUT_SIZE : start + size;
  1158. int i;
  1159. for (i = start; i < end; i++) {
  1160. mga_crtc->lut_r[i] = red[i] >> 8;
  1161. mga_crtc->lut_g[i] = green[i] >> 8;
  1162. mga_crtc->lut_b[i] = blue[i] >> 8;
  1163. }
  1164. mga_crtc_load_lut(crtc);
  1165. }
  1166. /* Simple cleanup function */
  1167. static void mga_crtc_destroy(struct drm_crtc *crtc)
  1168. {
  1169. struct mga_crtc *mga_crtc = to_mga_crtc(crtc);
  1170. drm_crtc_cleanup(crtc);
  1171. kfree(mga_crtc);
  1172. }
  1173. static void mga_crtc_disable(struct drm_crtc *crtc)
  1174. {
  1175. int ret;
  1176. DRM_DEBUG_KMS("\n");
  1177. mga_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  1178. if (crtc->primary->fb) {
  1179. struct mga_framebuffer *mga_fb = to_mga_framebuffer(crtc->primary->fb);
  1180. struct drm_gem_object *obj = mga_fb->obj;
  1181. struct mgag200_bo *bo = gem_to_mga_bo(obj);
  1182. ret = mgag200_bo_reserve(bo, false);
  1183. if (ret)
  1184. return;
  1185. mgag200_bo_push_sysram(bo);
  1186. mgag200_bo_unreserve(bo);
  1187. }
  1188. crtc->primary->fb = NULL;
  1189. }
  1190. /* These provide the minimum set of functions required to handle a CRTC */
  1191. static const struct drm_crtc_funcs mga_crtc_funcs = {
  1192. .cursor_set = mga_crtc_cursor_set,
  1193. .cursor_move = mga_crtc_cursor_move,
  1194. .gamma_set = mga_crtc_gamma_set,
  1195. .set_config = drm_crtc_helper_set_config,
  1196. .destroy = mga_crtc_destroy,
  1197. };
  1198. static const struct drm_crtc_helper_funcs mga_helper_funcs = {
  1199. .disable = mga_crtc_disable,
  1200. .dpms = mga_crtc_dpms,
  1201. .mode_fixup = mga_crtc_mode_fixup,
  1202. .mode_set = mga_crtc_mode_set,
  1203. .mode_set_base = mga_crtc_mode_set_base,
  1204. .prepare = mga_crtc_prepare,
  1205. .commit = mga_crtc_commit,
  1206. .load_lut = mga_crtc_load_lut,
  1207. };
  1208. /* CRTC setup */
  1209. static void mga_crtc_init(struct mga_device *mdev)
  1210. {
  1211. struct mga_crtc *mga_crtc;
  1212. int i;
  1213. mga_crtc = kzalloc(sizeof(struct mga_crtc) +
  1214. (MGAG200FB_CONN_LIMIT * sizeof(struct drm_connector *)),
  1215. GFP_KERNEL);
  1216. if (mga_crtc == NULL)
  1217. return;
  1218. drm_crtc_init(mdev->dev, &mga_crtc->base, &mga_crtc_funcs);
  1219. drm_mode_crtc_set_gamma_size(&mga_crtc->base, MGAG200_LUT_SIZE);
  1220. mdev->mode_info.crtc = mga_crtc;
  1221. for (i = 0; i < MGAG200_LUT_SIZE; i++) {
  1222. mga_crtc->lut_r[i] = i;
  1223. mga_crtc->lut_g[i] = i;
  1224. mga_crtc->lut_b[i] = i;
  1225. }
  1226. drm_crtc_helper_add(&mga_crtc->base, &mga_helper_funcs);
  1227. }
  1228. /** Sets the color ramps on behalf of fbcon */
  1229. void mga_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  1230. u16 blue, int regno)
  1231. {
  1232. struct mga_crtc *mga_crtc = to_mga_crtc(crtc);
  1233. mga_crtc->lut_r[regno] = red >> 8;
  1234. mga_crtc->lut_g[regno] = green >> 8;
  1235. mga_crtc->lut_b[regno] = blue >> 8;
  1236. }
  1237. /** Gets the color ramps on behalf of fbcon */
  1238. void mga_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  1239. u16 *blue, int regno)
  1240. {
  1241. struct mga_crtc *mga_crtc = to_mga_crtc(crtc);
  1242. *red = (u16)mga_crtc->lut_r[regno] << 8;
  1243. *green = (u16)mga_crtc->lut_g[regno] << 8;
  1244. *blue = (u16)mga_crtc->lut_b[regno] << 8;
  1245. }
  1246. /*
  1247. * The encoder comes after the CRTC in the output pipeline, but before
  1248. * the connector. It's responsible for ensuring that the digital
  1249. * stream is appropriately converted into the output format. Setup is
  1250. * very simple in this case - all we have to do is inform qemu of the
  1251. * colour depth in order to ensure that it displays appropriately
  1252. */
  1253. /*
  1254. * These functions are analagous to those in the CRTC code, but are intended
  1255. * to handle any encoder-specific limitations
  1256. */
  1257. static bool mga_encoder_mode_fixup(struct drm_encoder *encoder,
  1258. const struct drm_display_mode *mode,
  1259. struct drm_display_mode *adjusted_mode)
  1260. {
  1261. return true;
  1262. }
  1263. static void mga_encoder_mode_set(struct drm_encoder *encoder,
  1264. struct drm_display_mode *mode,
  1265. struct drm_display_mode *adjusted_mode)
  1266. {
  1267. }
  1268. static void mga_encoder_dpms(struct drm_encoder *encoder, int state)
  1269. {
  1270. return;
  1271. }
  1272. static void mga_encoder_prepare(struct drm_encoder *encoder)
  1273. {
  1274. }
  1275. static void mga_encoder_commit(struct drm_encoder *encoder)
  1276. {
  1277. }
  1278. static void mga_encoder_destroy(struct drm_encoder *encoder)
  1279. {
  1280. struct mga_encoder *mga_encoder = to_mga_encoder(encoder);
  1281. drm_encoder_cleanup(encoder);
  1282. kfree(mga_encoder);
  1283. }
  1284. static const struct drm_encoder_helper_funcs mga_encoder_helper_funcs = {
  1285. .dpms = mga_encoder_dpms,
  1286. .mode_fixup = mga_encoder_mode_fixup,
  1287. .mode_set = mga_encoder_mode_set,
  1288. .prepare = mga_encoder_prepare,
  1289. .commit = mga_encoder_commit,
  1290. };
  1291. static const struct drm_encoder_funcs mga_encoder_encoder_funcs = {
  1292. .destroy = mga_encoder_destroy,
  1293. };
  1294. static struct drm_encoder *mga_encoder_init(struct drm_device *dev)
  1295. {
  1296. struct drm_encoder *encoder;
  1297. struct mga_encoder *mga_encoder;
  1298. mga_encoder = kzalloc(sizeof(struct mga_encoder), GFP_KERNEL);
  1299. if (!mga_encoder)
  1300. return NULL;
  1301. encoder = &mga_encoder->base;
  1302. encoder->possible_crtcs = 0x1;
  1303. drm_encoder_init(dev, encoder, &mga_encoder_encoder_funcs,
  1304. DRM_MODE_ENCODER_DAC);
  1305. drm_encoder_helper_add(encoder, &mga_encoder_helper_funcs);
  1306. return encoder;
  1307. }
  1308. static int mga_vga_get_modes(struct drm_connector *connector)
  1309. {
  1310. struct mga_connector *mga_connector = to_mga_connector(connector);
  1311. struct edid *edid;
  1312. int ret = 0;
  1313. edid = drm_get_edid(connector, &mga_connector->i2c->adapter);
  1314. if (edid) {
  1315. drm_mode_connector_update_edid_property(connector, edid);
  1316. ret = drm_add_edid_modes(connector, edid);
  1317. kfree(edid);
  1318. }
  1319. return ret;
  1320. }
  1321. static uint32_t mga_vga_calculate_mode_bandwidth(struct drm_display_mode *mode,
  1322. int bits_per_pixel)
  1323. {
  1324. uint32_t total_area, divisor;
  1325. int64_t active_area, pixels_per_second, bandwidth;
  1326. uint64_t bytes_per_pixel = (bits_per_pixel + 7) / 8;
  1327. divisor = 1024;
  1328. if (!mode->htotal || !mode->vtotal || !mode->clock)
  1329. return 0;
  1330. active_area = mode->hdisplay * mode->vdisplay;
  1331. total_area = mode->htotal * mode->vtotal;
  1332. pixels_per_second = active_area * mode->clock * 1000;
  1333. do_div(pixels_per_second, total_area);
  1334. bandwidth = pixels_per_second * bytes_per_pixel * 100;
  1335. do_div(bandwidth, divisor);
  1336. return (uint32_t)(bandwidth);
  1337. }
  1338. #define MODE_BANDWIDTH MODE_BAD
  1339. static int mga_vga_mode_valid(struct drm_connector *connector,
  1340. struct drm_display_mode *mode)
  1341. {
  1342. struct drm_device *dev = connector->dev;
  1343. struct mga_device *mdev = (struct mga_device*)dev->dev_private;
  1344. int bpp = 32;
  1345. if (IS_G200_SE(mdev)) {
  1346. if (mdev->unique_rev_id == 0x01) {
  1347. if (mode->hdisplay > 1600)
  1348. return MODE_VIRTUAL_X;
  1349. if (mode->vdisplay > 1200)
  1350. return MODE_VIRTUAL_Y;
  1351. if (mga_vga_calculate_mode_bandwidth(mode, bpp)
  1352. > (24400 * 1024))
  1353. return MODE_BANDWIDTH;
  1354. } else if (mdev->unique_rev_id == 0x02) {
  1355. if (mode->hdisplay > 1920)
  1356. return MODE_VIRTUAL_X;
  1357. if (mode->vdisplay > 1200)
  1358. return MODE_VIRTUAL_Y;
  1359. if (mga_vga_calculate_mode_bandwidth(mode, bpp)
  1360. > (30100 * 1024))
  1361. return MODE_BANDWIDTH;
  1362. }
  1363. } else if (mdev->type == G200_WB) {
  1364. if (mode->hdisplay > 1280)
  1365. return MODE_VIRTUAL_X;
  1366. if (mode->vdisplay > 1024)
  1367. return MODE_VIRTUAL_Y;
  1368. if (mga_vga_calculate_mode_bandwidth(mode,
  1369. bpp > (31877 * 1024)))
  1370. return MODE_BANDWIDTH;
  1371. } else if (mdev->type == G200_EV &&
  1372. (mga_vga_calculate_mode_bandwidth(mode, bpp)
  1373. > (32700 * 1024))) {
  1374. return MODE_BANDWIDTH;
  1375. } else if (mdev->type == G200_EH &&
  1376. (mga_vga_calculate_mode_bandwidth(mode, bpp)
  1377. > (37500 * 1024))) {
  1378. return MODE_BANDWIDTH;
  1379. } else if (mdev->type == G200_ER &&
  1380. (mga_vga_calculate_mode_bandwidth(mode,
  1381. bpp) > (55000 * 1024))) {
  1382. return MODE_BANDWIDTH;
  1383. }
  1384. if ((mode->hdisplay % 8) != 0 || (mode->hsync_start % 8) != 0 ||
  1385. (mode->hsync_end % 8) != 0 || (mode->htotal % 8) != 0) {
  1386. return MODE_H_ILLEGAL;
  1387. }
  1388. if (mode->crtc_hdisplay > 2048 || mode->crtc_hsync_start > 4096 ||
  1389. mode->crtc_hsync_end > 4096 || mode->crtc_htotal > 4096 ||
  1390. mode->crtc_vdisplay > 2048 || mode->crtc_vsync_start > 4096 ||
  1391. mode->crtc_vsync_end > 4096 || mode->crtc_vtotal > 4096) {
  1392. return MODE_BAD;
  1393. }
  1394. /* Validate the mode input by the user */
  1395. if (connector->cmdline_mode.specified) {
  1396. if (connector->cmdline_mode.bpp_specified)
  1397. bpp = connector->cmdline_mode.bpp;
  1398. }
  1399. if ((mode->hdisplay * mode->vdisplay * (bpp/8)) > mdev->mc.vram_size) {
  1400. if (connector->cmdline_mode.specified)
  1401. connector->cmdline_mode.specified = false;
  1402. return MODE_BAD;
  1403. }
  1404. return MODE_OK;
  1405. }
  1406. static struct drm_encoder *mga_connector_best_encoder(struct drm_connector
  1407. *connector)
  1408. {
  1409. int enc_id = connector->encoder_ids[0];
  1410. /* pick the encoder ids */
  1411. if (enc_id)
  1412. return drm_encoder_find(connector->dev, enc_id);
  1413. return NULL;
  1414. }
  1415. static enum drm_connector_status mga_vga_detect(struct drm_connector
  1416. *connector, bool force)
  1417. {
  1418. return connector_status_connected;
  1419. }
  1420. static void mga_connector_destroy(struct drm_connector *connector)
  1421. {
  1422. struct mga_connector *mga_connector = to_mga_connector(connector);
  1423. mgag200_i2c_destroy(mga_connector->i2c);
  1424. drm_connector_cleanup(connector);
  1425. kfree(connector);
  1426. }
  1427. struct drm_connector_helper_funcs mga_vga_connector_helper_funcs = {
  1428. .get_modes = mga_vga_get_modes,
  1429. .mode_valid = mga_vga_mode_valid,
  1430. .best_encoder = mga_connector_best_encoder,
  1431. };
  1432. struct drm_connector_funcs mga_vga_connector_funcs = {
  1433. .dpms = drm_helper_connector_dpms,
  1434. .detect = mga_vga_detect,
  1435. .fill_modes = drm_helper_probe_single_connector_modes,
  1436. .destroy = mga_connector_destroy,
  1437. };
  1438. static struct drm_connector *mga_vga_init(struct drm_device *dev)
  1439. {
  1440. struct drm_connector *connector;
  1441. struct mga_connector *mga_connector;
  1442. mga_connector = kzalloc(sizeof(struct mga_connector), GFP_KERNEL);
  1443. if (!mga_connector)
  1444. return NULL;
  1445. connector = &mga_connector->base;
  1446. drm_connector_init(dev, connector,
  1447. &mga_vga_connector_funcs, DRM_MODE_CONNECTOR_VGA);
  1448. drm_connector_helper_add(connector, &mga_vga_connector_helper_funcs);
  1449. drm_connector_register(connector);
  1450. mga_connector->i2c = mgag200_i2c_create(dev);
  1451. if (!mga_connector->i2c)
  1452. DRM_ERROR("failed to add ddc bus\n");
  1453. return connector;
  1454. }
  1455. int mgag200_modeset_init(struct mga_device *mdev)
  1456. {
  1457. struct drm_encoder *encoder;
  1458. struct drm_connector *connector;
  1459. int ret;
  1460. mdev->mode_info.mode_config_initialized = true;
  1461. mdev->dev->mode_config.max_width = MGAG200_MAX_FB_WIDTH;
  1462. mdev->dev->mode_config.max_height = MGAG200_MAX_FB_HEIGHT;
  1463. mdev->dev->mode_config.fb_base = mdev->mc.vram_base;
  1464. mga_crtc_init(mdev);
  1465. encoder = mga_encoder_init(mdev->dev);
  1466. if (!encoder) {
  1467. DRM_ERROR("mga_encoder_init failed\n");
  1468. return -1;
  1469. }
  1470. connector = mga_vga_init(mdev->dev);
  1471. if (!connector) {
  1472. DRM_ERROR("mga_vga_init failed\n");
  1473. return -1;
  1474. }
  1475. drm_mode_connector_attach_encoder(connector, encoder);
  1476. ret = mgag200_fbdev_init(mdev);
  1477. if (ret) {
  1478. DRM_ERROR("mga_fbdev_init failed\n");
  1479. return ret;
  1480. }
  1481. return 0;
  1482. }
  1483. void mgag200_modeset_fini(struct mga_device *mdev)
  1484. {
  1485. }