mgag200_mode.c 42 KB

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