savagefb_driver.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279
  1. /*
  2. * linux/drivers/video/savagefb.c -- S3 Savage Framebuffer Driver
  3. *
  4. * Copyright (c) 2001-2002 Denis Oliver Kropp <dok@directfb.org>
  5. * Sven Neumann <neo@directfb.org>
  6. *
  7. *
  8. * Card specific code is based on XFree86's savage driver.
  9. * Framebuffer framework code is based on code of cyber2000fb and tdfxfb.
  10. *
  11. * This file is subject to the terms and conditions of the GNU General
  12. * Public License. See the file COPYING in the main directory of this
  13. * archive for more details.
  14. *
  15. * 0.4.0 (neo)
  16. * - hardware accelerated clear and move
  17. *
  18. * 0.3.2 (dok)
  19. * - wait for vertical retrace before writing to cr67
  20. * at the beginning of savagefb_set_par
  21. * - use synchronization registers cr23 and cr26
  22. *
  23. * 0.3.1 (dok)
  24. * - reset 3D engine
  25. * - don't return alpha bits for 32bit format
  26. *
  27. * 0.3.0 (dok)
  28. * - added WaitIdle functions for all Savage types
  29. * - do WaitIdle before mode switching
  30. * - code cleanup
  31. *
  32. * 0.2.0 (dok)
  33. * - first working version
  34. *
  35. *
  36. * TODO
  37. * - clock validations in decode_var
  38. *
  39. * BUGS
  40. * - white margin on bootup
  41. *
  42. */
  43. #include <linux/config.h>
  44. #include <linux/module.h>
  45. #include <linux/kernel.h>
  46. #include <linux/errno.h>
  47. #include <linux/string.h>
  48. #include <linux/mm.h>
  49. #include <linux/tty.h>
  50. #include <linux/slab.h>
  51. #include <linux/delay.h>
  52. #include <linux/fb.h>
  53. #include <linux/pci.h>
  54. #include <linux/init.h>
  55. #include <linux/console.h>
  56. #include <asm/io.h>
  57. #include <asm/irq.h>
  58. #include <asm/pgtable.h>
  59. #include <asm/system.h>
  60. #include <asm/uaccess.h>
  61. #ifdef CONFIG_MTRR
  62. #include <asm/mtrr.h>
  63. #endif
  64. #include "savagefb.h"
  65. #define SAVAGEFB_VERSION "0.4.0_2.6"
  66. /* --------------------------------------------------------------------- */
  67. static char *mode_option __initdata = NULL;
  68. static int paletteEnabled = 0;
  69. #ifdef MODULE
  70. MODULE_AUTHOR("(c) 2001-2002 Denis Oliver Kropp <dok@directfb.org>");
  71. MODULE_LICENSE("GPL");
  72. MODULE_DESCRIPTION("FBDev driver for S3 Savage PCI/AGP Chips");
  73. #endif
  74. /* --------------------------------------------------------------------- */
  75. static void vgaHWSeqReset (struct savagefb_par *par, int start)
  76. {
  77. if (start)
  78. VGAwSEQ (0x00, 0x01); /* Synchronous Reset */
  79. else
  80. VGAwSEQ (0x00, 0x03); /* End Reset */
  81. }
  82. static void vgaHWProtect (struct savagefb_par *par, int on)
  83. {
  84. unsigned char tmp;
  85. if (on) {
  86. /*
  87. * Turn off screen and disable sequencer.
  88. */
  89. tmp = VGArSEQ (0x01);
  90. vgaHWSeqReset (par, 1); /* start synchronous reset */
  91. VGAwSEQ (0x01, tmp | 0x20); /* disable the display */
  92. VGAenablePalette();
  93. } else {
  94. /*
  95. * Reenable sequencer, then turn on screen.
  96. */
  97. tmp = VGArSEQ (0x01);
  98. VGAwSEQ (0x01, tmp & ~0x20); /* reenable display */
  99. vgaHWSeqReset (par, 0); /* clear synchronous reset */
  100. VGAdisablePalette();
  101. }
  102. }
  103. static void vgaHWRestore (struct savagefb_par *par)
  104. {
  105. int i;
  106. VGAwMISC (par->MiscOutReg);
  107. for (i = 1; i < 5; i++)
  108. VGAwSEQ (i, par->Sequencer[i]);
  109. /* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 or
  110. CRTC[17] */
  111. VGAwCR (17, par->CRTC[17] & ~0x80);
  112. for (i = 0; i < 25; i++)
  113. VGAwCR (i, par->CRTC[i]);
  114. for (i = 0; i < 9; i++)
  115. VGAwGR (i, par->Graphics[i]);
  116. VGAenablePalette();
  117. for (i = 0; i < 21; i++)
  118. VGAwATTR (i, par->Attribute[i]);
  119. VGAdisablePalette();
  120. }
  121. static void vgaHWInit (struct fb_var_screeninfo *var,
  122. struct savagefb_par *par,
  123. struct xtimings *timings)
  124. {
  125. par->MiscOutReg = 0x23;
  126. if (!(timings->sync & FB_SYNC_HOR_HIGH_ACT))
  127. par->MiscOutReg |= 0x40;
  128. if (!(timings->sync & FB_SYNC_VERT_HIGH_ACT))
  129. par->MiscOutReg |= 0x80;
  130. /*
  131. * Time Sequencer
  132. */
  133. par->Sequencer[0x00] = 0x00;
  134. par->Sequencer[0x01] = 0x01;
  135. par->Sequencer[0x02] = 0x0F;
  136. par->Sequencer[0x03] = 0x00; /* Font select */
  137. par->Sequencer[0x04] = 0x0E; /* Misc */
  138. /*
  139. * CRTC Controller
  140. */
  141. par->CRTC[0x00] = (timings->HTotal >> 3) - 5;
  142. par->CRTC[0x01] = (timings->HDisplay >> 3) - 1;
  143. par->CRTC[0x02] = (timings->HSyncStart >> 3) - 1;
  144. par->CRTC[0x03] = (((timings->HSyncEnd >> 3) - 1) & 0x1f) | 0x80;
  145. par->CRTC[0x04] = (timings->HSyncStart >> 3);
  146. par->CRTC[0x05] = ((((timings->HSyncEnd >> 3) - 1) & 0x20) << 2) |
  147. (((timings->HSyncEnd >> 3)) & 0x1f);
  148. par->CRTC[0x06] = (timings->VTotal - 2) & 0xFF;
  149. par->CRTC[0x07] = (((timings->VTotal - 2) & 0x100) >> 8) |
  150. (((timings->VDisplay - 1) & 0x100) >> 7) |
  151. ((timings->VSyncStart & 0x100) >> 6) |
  152. (((timings->VSyncStart - 1) & 0x100) >> 5) |
  153. 0x10 |
  154. (((timings->VTotal - 2) & 0x200) >> 4) |
  155. (((timings->VDisplay - 1) & 0x200) >> 3) |
  156. ((timings->VSyncStart & 0x200) >> 2);
  157. par->CRTC[0x08] = 0x00;
  158. par->CRTC[0x09] = (((timings->VSyncStart - 1) & 0x200) >> 4) | 0x40;
  159. if (timings->dblscan)
  160. par->CRTC[0x09] |= 0x80;
  161. par->CRTC[0x0a] = 0x00;
  162. par->CRTC[0x0b] = 0x00;
  163. par->CRTC[0x0c] = 0x00;
  164. par->CRTC[0x0d] = 0x00;
  165. par->CRTC[0x0e] = 0x00;
  166. par->CRTC[0x0f] = 0x00;
  167. par->CRTC[0x10] = timings->VSyncStart & 0xff;
  168. par->CRTC[0x11] = (timings->VSyncEnd & 0x0f) | 0x20;
  169. par->CRTC[0x12] = (timings->VDisplay - 1) & 0xff;
  170. par->CRTC[0x13] = var->xres_virtual >> 4;
  171. par->CRTC[0x14] = 0x00;
  172. par->CRTC[0x15] = (timings->VSyncStart - 1) & 0xff;
  173. par->CRTC[0x16] = (timings->VSyncEnd - 1) & 0xff;
  174. par->CRTC[0x17] = 0xc3;
  175. par->CRTC[0x18] = 0xff;
  176. /*
  177. * are these unnecessary?
  178. * vgaHWHBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN|KGA_ENABLE_ON_ZERO);
  179. * vgaHWVBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN|KGA_ENABLE_ON_ZERO);
  180. */
  181. /*
  182. * Graphics Display Controller
  183. */
  184. par->Graphics[0x00] = 0x00;
  185. par->Graphics[0x01] = 0x00;
  186. par->Graphics[0x02] = 0x00;
  187. par->Graphics[0x03] = 0x00;
  188. par->Graphics[0x04] = 0x00;
  189. par->Graphics[0x05] = 0x40;
  190. par->Graphics[0x06] = 0x05; /* only map 64k VGA memory !!!! */
  191. par->Graphics[0x07] = 0x0F;
  192. par->Graphics[0x08] = 0xFF;
  193. par->Attribute[0x00] = 0x00; /* standard colormap translation */
  194. par->Attribute[0x01] = 0x01;
  195. par->Attribute[0x02] = 0x02;
  196. par->Attribute[0x03] = 0x03;
  197. par->Attribute[0x04] = 0x04;
  198. par->Attribute[0x05] = 0x05;
  199. par->Attribute[0x06] = 0x06;
  200. par->Attribute[0x07] = 0x07;
  201. par->Attribute[0x08] = 0x08;
  202. par->Attribute[0x09] = 0x09;
  203. par->Attribute[0x0a] = 0x0A;
  204. par->Attribute[0x0b] = 0x0B;
  205. par->Attribute[0x0c] = 0x0C;
  206. par->Attribute[0x0d] = 0x0D;
  207. par->Attribute[0x0e] = 0x0E;
  208. par->Attribute[0x0f] = 0x0F;
  209. par->Attribute[0x10] = 0x41;
  210. par->Attribute[0x11] = 0xFF;
  211. par->Attribute[0x12] = 0x0F;
  212. par->Attribute[0x13] = 0x00;
  213. par->Attribute[0x14] = 0x00;
  214. }
  215. /* -------------------- Hardware specific routines ------------------------- */
  216. /*
  217. * Hardware Acceleration for SavageFB
  218. */
  219. /* Wait for fifo space */
  220. static void
  221. savage3D_waitfifo(struct savagefb_par *par, int space)
  222. {
  223. int slots = MAXFIFO - space;
  224. while ((savage_in32(0x48C00) & 0x0000ffff) > slots);
  225. }
  226. static void
  227. savage4_waitfifo(struct savagefb_par *par, int space)
  228. {
  229. int slots = MAXFIFO - space;
  230. while ((savage_in32(0x48C60) & 0x001fffff) > slots);
  231. }
  232. static void
  233. savage2000_waitfifo(struct savagefb_par *par, int space)
  234. {
  235. int slots = MAXFIFO - space;
  236. while ((savage_in32(0x48C60) & 0x0000ffff) > slots);
  237. }
  238. /* Wait for idle accelerator */
  239. static void
  240. savage3D_waitidle(struct savagefb_par *par)
  241. {
  242. while ((savage_in32(0x48C00) & 0x0008ffff) != 0x80000);
  243. }
  244. static void
  245. savage4_waitidle(struct savagefb_par *par)
  246. {
  247. while ((savage_in32(0x48C60) & 0x00a00000) != 0x00a00000);
  248. }
  249. static void
  250. savage2000_waitidle(struct savagefb_par *par)
  251. {
  252. while ((savage_in32(0x48C60) & 0x009fffff));
  253. }
  254. static void
  255. SavageSetup2DEngine (struct savagefb_par *par)
  256. {
  257. unsigned long GlobalBitmapDescriptor;
  258. GlobalBitmapDescriptor = 1 | 8 | BCI_BD_BW_DISABLE;
  259. BCI_BD_SET_BPP (GlobalBitmapDescriptor, par->depth);
  260. BCI_BD_SET_STRIDE (GlobalBitmapDescriptor, par->vwidth);
  261. switch(par->chip) {
  262. case S3_SAVAGE3D:
  263. case S3_SAVAGE_MX:
  264. /* Disable BCI */
  265. savage_out32(0x48C18, savage_in32(0x48C18) & 0x3FF0);
  266. /* Setup BCI command overflow buffer */
  267. savage_out32(0x48C14, (par->cob_offset >> 11) | (par->cob_index << 29));
  268. /* Program shadow status update. */
  269. savage_out32(0x48C10, 0x78207220);
  270. savage_out32(0x48C0C, 0);
  271. /* Enable BCI and command overflow buffer */
  272. savage_out32(0x48C18, savage_in32(0x48C18) | 0x0C);
  273. break;
  274. case S3_SAVAGE4:
  275. case S3_PROSAVAGE:
  276. case S3_SUPERSAVAGE:
  277. /* Disable BCI */
  278. savage_out32(0x48C18, savage_in32(0x48C18) & 0x3FF0);
  279. /* Program shadow status update */
  280. savage_out32(0x48C10, 0x00700040);
  281. savage_out32(0x48C0C, 0);
  282. /* Enable BCI without the COB */
  283. savage_out32(0x48C18, savage_in32(0x48C18) | 0x08);
  284. break;
  285. case S3_SAVAGE2000:
  286. /* Disable BCI */
  287. savage_out32(0x48C18, 0);
  288. /* Setup BCI command overflow buffer */
  289. savage_out32(0x48C18, (par->cob_offset >> 7) | (par->cob_index));
  290. /* Disable shadow status update */
  291. savage_out32(0x48A30, 0);
  292. /* Enable BCI and command overflow buffer */
  293. savage_out32(0x48C18, savage_in32(0x48C18) | 0x00280000 );
  294. break;
  295. default:
  296. break;
  297. }
  298. /* Turn on 16-bit register access. */
  299. vga_out8(0x3d4, 0x31);
  300. vga_out8(0x3d5, 0x0c);
  301. /* Set stride to use GBD. */
  302. vga_out8 (0x3d4, 0x50);
  303. vga_out8 (0x3d5, vga_in8 (0x3d5 ) | 0xC1);
  304. /* Enable 2D engine. */
  305. vga_out8 (0x3d4, 0x40 );
  306. vga_out8 (0x3d5, 0x01 );
  307. savage_out32 (MONO_PAT_0, ~0);
  308. savage_out32 (MONO_PAT_1, ~0);
  309. /* Setup plane masks */
  310. savage_out32 (0x8128, ~0 ); /* enable all write planes */
  311. savage_out32 (0x812C, ~0 ); /* enable all read planes */
  312. savage_out16 (0x8134, 0x27 );
  313. savage_out16 (0x8136, 0x07 );
  314. /* Now set the GBD */
  315. par->bci_ptr = 0;
  316. par->SavageWaitFifo (par, 4);
  317. BCI_SEND( BCI_CMD_SETREG | (1 << 16) | BCI_GBD1 );
  318. BCI_SEND( 0 );
  319. BCI_SEND( BCI_CMD_SETREG | (1 << 16) | BCI_GBD2 );
  320. BCI_SEND( GlobalBitmapDescriptor );
  321. }
  322. static void SavageCalcClock(long freq, int min_m, int min_n1, int max_n1,
  323. int min_n2, int max_n2, long freq_min,
  324. long freq_max, unsigned int *mdiv,
  325. unsigned int *ndiv, unsigned int *r)
  326. {
  327. long diff, best_diff;
  328. unsigned int m;
  329. unsigned char n1, n2, best_n1=16+2, best_n2=2, best_m=125+2;
  330. if (freq < freq_min / (1 << max_n2)) {
  331. printk (KERN_ERR "invalid frequency %ld Khz\n", freq);
  332. freq = freq_min / (1 << max_n2);
  333. }
  334. if (freq > freq_max / (1 << min_n2)) {
  335. printk (KERN_ERR "invalid frequency %ld Khz\n", freq);
  336. freq = freq_max / (1 << min_n2);
  337. }
  338. /* work out suitable timings */
  339. best_diff = freq;
  340. for (n2=min_n2; n2<=max_n2; n2++) {
  341. for (n1=min_n1+2; n1<=max_n1+2; n1++) {
  342. m = (freq * n1 * (1 << n2) + HALF_BASE_FREQ) /
  343. BASE_FREQ;
  344. if (m < min_m+2 || m > 127+2)
  345. continue;
  346. if ((m * BASE_FREQ >= freq_min * n1) &&
  347. (m * BASE_FREQ <= freq_max * n1)) {
  348. diff = freq * (1 << n2) * n1 - BASE_FREQ * m;
  349. if (diff < 0)
  350. diff = -diff;
  351. if (diff < best_diff) {
  352. best_diff = diff;
  353. best_m = m;
  354. best_n1 = n1;
  355. best_n2 = n2;
  356. }
  357. }
  358. }
  359. }
  360. *ndiv = best_n1 - 2;
  361. *r = best_n2;
  362. *mdiv = best_m - 2;
  363. }
  364. static int common_calc_clock(long freq, int min_m, int min_n1, int max_n1,
  365. int min_n2, int max_n2, long freq_min,
  366. long freq_max, unsigned char *mdiv,
  367. unsigned char *ndiv)
  368. {
  369. long diff, best_diff;
  370. unsigned int m;
  371. unsigned char n1, n2;
  372. unsigned char best_n1 = 16+2, best_n2 = 2, best_m = 125+2;
  373. best_diff = freq;
  374. for (n2 = min_n2; n2 <= max_n2; n2++) {
  375. for (n1 = min_n1+2; n1 <= max_n1+2; n1++) {
  376. m = (freq * n1 * (1 << n2) + HALF_BASE_FREQ) /
  377. BASE_FREQ;
  378. if (m < min_m + 2 || m > 127+2)
  379. continue;
  380. if((m * BASE_FREQ >= freq_min * n1) &&
  381. (m * BASE_FREQ <= freq_max * n1)) {
  382. diff = freq * (1 << n2) * n1 - BASE_FREQ * m;
  383. if(diff < 0)
  384. diff = -diff;
  385. if(diff < best_diff) {
  386. best_diff = diff;
  387. best_m = m;
  388. best_n1 = n1;
  389. best_n2 = n2;
  390. }
  391. }
  392. }
  393. }
  394. if(max_n1 == 63)
  395. *ndiv = (best_n1 - 2) | (best_n2 << 6);
  396. else
  397. *ndiv = (best_n1 - 2) | (best_n2 << 5);
  398. *mdiv = best_m - 2;
  399. return 0;
  400. }
  401. #ifdef SAVAGEFB_DEBUG
  402. /* This function is used to debug, it prints out the contents of s3 regs */
  403. static void SavagePrintRegs(void)
  404. {
  405. unsigned char i;
  406. int vgaCRIndex = 0x3d4;
  407. int vgaCRReg = 0x3d5;
  408. printk(KERN_DEBUG "SR x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE "
  409. "xF" );
  410. for( i = 0; i < 0x70; i++ ) {
  411. if( !(i % 16) )
  412. printk(KERN_DEBUG "\nSR%xx ", i >> 4 );
  413. vga_out8( 0x3c4, i );
  414. printk(KERN_DEBUG " %02x", vga_in8(0x3c5) );
  415. }
  416. printk(KERN_DEBUG "\n\nCR x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC "
  417. "xD xE xF" );
  418. for( i = 0; i < 0xB7; i++ ) {
  419. if( !(i % 16) )
  420. printk(KERN_DEBUG "\nCR%xx ", i >> 4 );
  421. vga_out8( vgaCRIndex, i );
  422. printk(KERN_DEBUG " %02x", vga_in8(vgaCRReg) );
  423. }
  424. printk(KERN_DEBUG "\n\n");
  425. }
  426. #endif
  427. /* --------------------------------------------------------------------- */
  428. static void savage_get_default_par(struct savagefb_par *par)
  429. {
  430. unsigned char cr3a, cr53, cr66;
  431. vga_out16 (0x3d4, 0x4838);
  432. vga_out16 (0x3d4, 0xa039);
  433. vga_out16 (0x3c4, 0x0608);
  434. vga_out8 (0x3d4, 0x66);
  435. cr66 = vga_in8 (0x3d5);
  436. vga_out8 (0x3d5, cr66 | 0x80);
  437. vga_out8 (0x3d4, 0x3a);
  438. cr3a = vga_in8 (0x3d5);
  439. vga_out8 (0x3d5, cr3a | 0x80);
  440. vga_out8 (0x3d4, 0x53);
  441. cr53 = vga_in8 (0x3d5);
  442. vga_out8 (0x3d5, cr53 & 0x7f);
  443. vga_out8 (0x3d4, 0x66);
  444. vga_out8 (0x3d5, cr66);
  445. vga_out8 (0x3d4, 0x3a);
  446. vga_out8 (0x3d5, cr3a);
  447. vga_out8 (0x3d4, 0x66);
  448. vga_out8 (0x3d5, cr66);
  449. vga_out8 (0x3d4, 0x3a);
  450. vga_out8 (0x3d5, cr3a);
  451. /* unlock extended seq regs */
  452. vga_out8 (0x3c4, 0x08);
  453. par->SR08 = vga_in8 (0x3c5);
  454. vga_out8 (0x3c5, 0x06);
  455. /* now save all the extended regs we need */
  456. vga_out8 (0x3d4, 0x31);
  457. par->CR31 = vga_in8 (0x3d5);
  458. vga_out8 (0x3d4, 0x32);
  459. par->CR32 = vga_in8 (0x3d5);
  460. vga_out8 (0x3d4, 0x34);
  461. par->CR34 = vga_in8 (0x3d5);
  462. vga_out8 (0x3d4, 0x36);
  463. par->CR36 = vga_in8 (0x3d5);
  464. vga_out8 (0x3d4, 0x3a);
  465. par->CR3A = vga_in8 (0x3d5);
  466. vga_out8 (0x3d4, 0x40);
  467. par->CR40 = vga_in8 (0x3d5);
  468. vga_out8 (0x3d4, 0x42);
  469. par->CR42 = vga_in8 (0x3d5);
  470. vga_out8 (0x3d4, 0x45);
  471. par->CR45 = vga_in8 (0x3d5);
  472. vga_out8 (0x3d4, 0x50);
  473. par->CR50 = vga_in8 (0x3d5);
  474. vga_out8 (0x3d4, 0x51);
  475. par->CR51 = vga_in8 (0x3d5);
  476. vga_out8 (0x3d4, 0x53);
  477. par->CR53 = vga_in8 (0x3d5);
  478. vga_out8 (0x3d4, 0x58);
  479. par->CR58 = vga_in8 (0x3d5);
  480. vga_out8 (0x3d4, 0x60);
  481. par->CR60 = vga_in8 (0x3d5);
  482. vga_out8 (0x3d4, 0x66);
  483. par->CR66 = vga_in8 (0x3d5);
  484. vga_out8 (0x3d4, 0x67);
  485. par->CR67 = vga_in8 (0x3d5);
  486. vga_out8 (0x3d4, 0x68);
  487. par->CR68 = vga_in8 (0x3d5);
  488. vga_out8 (0x3d4, 0x69);
  489. par->CR69 = vga_in8 (0x3d5);
  490. vga_out8 (0x3d4, 0x6f);
  491. par->CR6F = vga_in8 (0x3d5);
  492. vga_out8 (0x3d4, 0x33);
  493. par->CR33 = vga_in8 (0x3d5);
  494. vga_out8 (0x3d4, 0x86);
  495. par->CR86 = vga_in8 (0x3d5);
  496. vga_out8 (0x3d4, 0x88);
  497. par->CR88 = vga_in8 (0x3d5);
  498. vga_out8 (0x3d4, 0x90);
  499. par->CR90 = vga_in8 (0x3d5);
  500. vga_out8 (0x3d4, 0x91);
  501. par->CR91 = vga_in8 (0x3d5);
  502. vga_out8 (0x3d4, 0xb0);
  503. par->CRB0 = vga_in8 (0x3d5) | 0x80;
  504. /* extended mode timing regs */
  505. vga_out8 (0x3d4, 0x3b);
  506. par->CR3B = vga_in8 (0x3d5);
  507. vga_out8 (0x3d4, 0x3c);
  508. par->CR3C = vga_in8 (0x3d5);
  509. vga_out8 (0x3d4, 0x43);
  510. par->CR43 = vga_in8 (0x3d5);
  511. vga_out8 (0x3d4, 0x5d);
  512. par->CR5D = vga_in8 (0x3d5);
  513. vga_out8 (0x3d4, 0x5e);
  514. par->CR5E = vga_in8 (0x3d5);
  515. vga_out8 (0x3d4, 0x65);
  516. par->CR65 = vga_in8 (0x3d5);
  517. /* save seq extended regs for DCLK PLL programming */
  518. vga_out8 (0x3c4, 0x0e);
  519. par->SR0E = vga_in8 (0x3c5);
  520. vga_out8 (0x3c4, 0x0f);
  521. par->SR0F = vga_in8 (0x3c5);
  522. vga_out8 (0x3c4, 0x10);
  523. par->SR10 = vga_in8 (0x3c5);
  524. vga_out8 (0x3c4, 0x11);
  525. par->SR11 = vga_in8 (0x3c5);
  526. vga_out8 (0x3c4, 0x12);
  527. par->SR12 = vga_in8 (0x3c5);
  528. vga_out8 (0x3c4, 0x13);
  529. par->SR13 = vga_in8 (0x3c5);
  530. vga_out8 (0x3c4, 0x29);
  531. par->SR29 = vga_in8 (0x3c5);
  532. vga_out8 (0x3c4, 0x15);
  533. par->SR15 = vga_in8 (0x3c5);
  534. vga_out8 (0x3c4, 0x30);
  535. par->SR30 = vga_in8 (0x3c5);
  536. vga_out8 (0x3c4, 0x18);
  537. par->SR18 = vga_in8 (0x3c5);
  538. /* Save flat panel expansion regsters. */
  539. if (par->chip == S3_SAVAGE_MX) {
  540. int i;
  541. for (i = 0; i < 8; i++) {
  542. vga_out8 (0x3c4, 0x54+i);
  543. par->SR54[i] = vga_in8 (0x3c5);
  544. }
  545. }
  546. vga_out8 (0x3d4, 0x66);
  547. cr66 = vga_in8 (0x3d5);
  548. vga_out8 (0x3d5, cr66 | 0x80);
  549. vga_out8 (0x3d4, 0x3a);
  550. cr3a = vga_in8 (0x3d5);
  551. vga_out8 (0x3d5, cr3a | 0x80);
  552. /* now save MIU regs */
  553. if (par->chip != S3_SAVAGE_MX) {
  554. par->MMPR0 = savage_in32(FIFO_CONTROL_REG);
  555. par->MMPR1 = savage_in32(MIU_CONTROL_REG);
  556. par->MMPR2 = savage_in32(STREAMS_TIMEOUT_REG);
  557. par->MMPR3 = savage_in32(MISC_TIMEOUT_REG);
  558. }
  559. vga_out8 (0x3d4, 0x3a);
  560. vga_out8 (0x3d5, cr3a);
  561. vga_out8 (0x3d4, 0x66);
  562. vga_out8 (0x3d5, cr66);
  563. }
  564. static void savage_update_var(struct fb_var_screeninfo *var, struct fb_videomode *modedb)
  565. {
  566. var->xres = var->xres_virtual = modedb->xres;
  567. var->yres = modedb->yres;
  568. if (var->yres_virtual < var->yres)
  569. var->yres_virtual = var->yres;
  570. var->xoffset = var->yoffset = 0;
  571. var->pixclock = modedb->pixclock;
  572. var->left_margin = modedb->left_margin;
  573. var->right_margin = modedb->right_margin;
  574. var->upper_margin = modedb->upper_margin;
  575. var->lower_margin = modedb->lower_margin;
  576. var->hsync_len = modedb->hsync_len;
  577. var->vsync_len = modedb->vsync_len;
  578. var->sync = modedb->sync;
  579. var->vmode = modedb->vmode;
  580. }
  581. static int savagefb_check_var (struct fb_var_screeninfo *var,
  582. struct fb_info *info)
  583. {
  584. struct savagefb_par *par = (struct savagefb_par *)info->par;
  585. int memlen, vramlen, mode_valid = 0;
  586. DBG("savagefb_check_var");
  587. var->transp.offset = 0;
  588. var->transp.length = 0;
  589. switch (var->bits_per_pixel) {
  590. case 8:
  591. var->red.offset = var->green.offset =
  592. var->blue.offset = 0;
  593. var->red.length = var->green.length =
  594. var->blue.length = var->bits_per_pixel;
  595. break;
  596. case 16:
  597. var->red.offset = 11;
  598. var->red.length = 5;
  599. var->green.offset = 5;
  600. var->green.length = 6;
  601. var->blue.offset = 0;
  602. var->blue.length = 5;
  603. break;
  604. case 32:
  605. var->transp.offset = 24;
  606. var->transp.length = 8;
  607. var->red.offset = 16;
  608. var->red.length = 8;
  609. var->green.offset = 8;
  610. var->green.length = 8;
  611. var->blue.offset = 0;
  612. var->blue.length = 8;
  613. break;
  614. default:
  615. return -EINVAL;
  616. }
  617. if (!info->monspecs.hfmax || !info->monspecs.vfmax ||
  618. !info->monspecs.dclkmax || !fb_validate_mode(var, info))
  619. mode_valid = 1;
  620. /* calculate modeline if supported by monitor */
  621. if (!mode_valid && info->monspecs.gtf) {
  622. if (!fb_get_mode(FB_MAXTIMINGS, 0, var, info))
  623. mode_valid = 1;
  624. }
  625. if (!mode_valid) {
  626. struct fb_videomode *mode;
  627. mode = fb_find_best_mode(var, &info->modelist);
  628. if (mode) {
  629. savage_update_var(var, mode);
  630. mode_valid = 1;
  631. }
  632. }
  633. if (!mode_valid && info->monspecs.modedb_len)
  634. return -EINVAL;
  635. /* Is the mode larger than the LCD panel? */
  636. if (par->SavagePanelWidth &&
  637. (var->xres > par->SavagePanelWidth ||
  638. var->yres > par->SavagePanelHeight)) {
  639. printk (KERN_INFO "Mode (%dx%d) larger than the LCD panel "
  640. "(%dx%d)\n", var->xres, var->yres,
  641. par->SavagePanelWidth,
  642. par->SavagePanelHeight);
  643. return -1;
  644. }
  645. if (var->yres_virtual < var->yres)
  646. var->yres_virtual = var->yres;
  647. if (var->xres_virtual < var->xres)
  648. var->xres_virtual = var->xres;
  649. vramlen = info->fix.smem_len;
  650. memlen = var->xres_virtual * var->bits_per_pixel *
  651. var->yres_virtual / 8;
  652. if (memlen > vramlen) {
  653. var->yres_virtual = vramlen * 8 /
  654. (var->xres_virtual * var->bits_per_pixel);
  655. memlen = var->xres_virtual * var->bits_per_pixel *
  656. var->yres_virtual / 8;
  657. }
  658. /* we must round yres/xres down, we already rounded y/xres_virtual up
  659. if it was possible. We should return -EINVAL, but I disagree */
  660. if (var->yres_virtual < var->yres)
  661. var->yres = var->yres_virtual;
  662. if (var->xres_virtual < var->xres)
  663. var->xres = var->xres_virtual;
  664. if (var->xoffset + var->xres > var->xres_virtual)
  665. var->xoffset = var->xres_virtual - var->xres;
  666. if (var->yoffset + var->yres > var->yres_virtual)
  667. var->yoffset = var->yres_virtual - var->yres;
  668. return 0;
  669. }
  670. static int savagefb_decode_var (struct fb_var_screeninfo *var,
  671. struct savagefb_par *par)
  672. {
  673. struct xtimings timings;
  674. int width, dclk, i, j; /*, refresh; */
  675. unsigned int m, n, r;
  676. unsigned char tmp = 0;
  677. unsigned int pixclock = var->pixclock;
  678. DBG("savagefb_decode_var");
  679. memset (&timings, 0, sizeof(timings));
  680. if (!pixclock) pixclock = 10000; /* 10ns = 100MHz */
  681. timings.Clock = 1000000000 / pixclock;
  682. if (timings.Clock < 1) timings.Clock = 1;
  683. timings.dblscan = var->vmode & FB_VMODE_DOUBLE;
  684. timings.interlaced = var->vmode & FB_VMODE_INTERLACED;
  685. timings.HDisplay = var->xres;
  686. timings.HSyncStart = timings.HDisplay + var->right_margin;
  687. timings.HSyncEnd = timings.HSyncStart + var->hsync_len;
  688. timings.HTotal = timings.HSyncEnd + var->left_margin;
  689. timings.VDisplay = var->yres;
  690. timings.VSyncStart = timings.VDisplay + var->lower_margin;
  691. timings.VSyncEnd = timings.VSyncStart + var->vsync_len;
  692. timings.VTotal = timings.VSyncEnd + var->upper_margin;
  693. timings.sync = var->sync;
  694. par->depth = var->bits_per_pixel;
  695. par->vwidth = var->xres_virtual;
  696. if (var->bits_per_pixel == 16 && par->chip == S3_SAVAGE3D) {
  697. timings.HDisplay *= 2;
  698. timings.HSyncStart *= 2;
  699. timings.HSyncEnd *= 2;
  700. timings.HTotal *= 2;
  701. }
  702. /*
  703. * This will allocate the datastructure and initialize all of the
  704. * generic VGA registers.
  705. */
  706. vgaHWInit (var, par, &timings);
  707. /* We need to set CR67 whether or not we use the BIOS. */
  708. dclk = timings.Clock;
  709. par->CR67 = 0x00;
  710. switch( var->bits_per_pixel ) {
  711. case 8:
  712. if( (par->chip == S3_SAVAGE2000) && (dclk >= 230000) )
  713. par->CR67 = 0x10; /* 8bpp, 2 pixels/clock */
  714. else
  715. par->CR67 = 0x00; /* 8bpp, 1 pixel/clock */
  716. break;
  717. case 15:
  718. if ( S3_SAVAGE_MOBILE_SERIES(par->chip) ||
  719. ((par->chip == S3_SAVAGE2000) && (dclk >= 230000)) )
  720. par->CR67 = 0x30; /* 15bpp, 2 pixel/clock */
  721. else
  722. par->CR67 = 0x20; /* 15bpp, 1 pixels/clock */
  723. break;
  724. case 16:
  725. if( S3_SAVAGE_MOBILE_SERIES(par->chip) ||
  726. ((par->chip == S3_SAVAGE2000) && (dclk >= 230000)) )
  727. par->CR67 = 0x50; /* 16bpp, 2 pixel/clock */
  728. else
  729. par->CR67 = 0x40; /* 16bpp, 1 pixels/clock */
  730. break;
  731. case 24:
  732. par->CR67 = 0x70;
  733. break;
  734. case 32:
  735. par->CR67 = 0xd0;
  736. break;
  737. }
  738. /*
  739. * Either BIOS use is disabled, or we failed to find a suitable
  740. * match. Fall back to traditional register-crunching.
  741. */
  742. vga_out8 (0x3d4, 0x3a);
  743. tmp = vga_in8 (0x3d5);
  744. if (1 /*FIXME:psav->pci_burst*/)
  745. par->CR3A = (tmp & 0x7f) | 0x15;
  746. else
  747. par->CR3A = tmp | 0x95;
  748. par->CR53 = 0x00;
  749. par->CR31 = 0x8c;
  750. par->CR66 = 0x89;
  751. vga_out8 (0x3d4, 0x58);
  752. par->CR58 = vga_in8 (0x3d5) & 0x80;
  753. par->CR58 |= 0x13;
  754. par->SR15 = 0x03 | 0x80;
  755. par->SR18 = 0x00;
  756. par->CR43 = par->CR45 = par->CR65 = 0x00;
  757. vga_out8 (0x3d4, 0x40);
  758. par->CR40 = vga_in8 (0x3d5) & ~0x01;
  759. par->MMPR0 = 0x010400;
  760. par->MMPR1 = 0x00;
  761. par->MMPR2 = 0x0808;
  762. par->MMPR3 = 0x08080810;
  763. SavageCalcClock (dclk, 1, 1, 127, 0, 4, 180000, 360000, &m, &n, &r);
  764. /* m = 107; n = 4; r = 2; */
  765. if (par->MCLK <= 0) {
  766. par->SR10 = 255;
  767. par->SR11 = 255;
  768. } else {
  769. common_calc_clock (par->MCLK, 1, 1, 31, 0, 3, 135000, 270000,
  770. &par->SR11, &par->SR10);
  771. /* par->SR10 = 80; // MCLK == 286000 */
  772. /* par->SR11 = 125; */
  773. }
  774. par->SR12 = (r << 6) | (n & 0x3f);
  775. par->SR13 = m & 0xff;
  776. par->SR29 = (r & 4) | (m & 0x100) >> 5 | (n & 0x40) >> 2;
  777. if (var->bits_per_pixel < 24)
  778. par->MMPR0 -= 0x8000;
  779. else
  780. par->MMPR0 -= 0x4000;
  781. if (timings.interlaced)
  782. par->CR42 = 0x20;
  783. else
  784. par->CR42 = 0x00;
  785. par->CR34 = 0x10; /* display fifo */
  786. i = ((((timings.HTotal >> 3) - 5) & 0x100) >> 8) |
  787. ((((timings.HDisplay >> 3) - 1) & 0x100) >> 7) |
  788. ((((timings.HSyncStart >> 3) - 1) & 0x100) >> 6) |
  789. ((timings.HSyncStart & 0x800) >> 7);
  790. if ((timings.HSyncEnd >> 3) - (timings.HSyncStart >> 3) > 64)
  791. i |= 0x08;
  792. if ((timings.HSyncEnd >> 3) - (timings.HSyncStart >> 3) > 32)
  793. i |= 0x20;
  794. j = (par->CRTC[0] + ((i & 0x01) << 8) +
  795. par->CRTC[4] + ((i & 0x10) << 4) + 1) / 2;
  796. if (j - (par->CRTC[4] + ((i & 0x10) << 4)) < 4) {
  797. if (par->CRTC[4] + ((i & 0x10) << 4) + 4 <=
  798. par->CRTC[0] + ((i & 0x01) << 8))
  799. j = par->CRTC[4] + ((i & 0x10) << 4) + 4;
  800. else
  801. j = par->CRTC[0] + ((i & 0x01) << 8) + 1;
  802. }
  803. par->CR3B = j & 0xff;
  804. i |= (j & 0x100) >> 2;
  805. par->CR3C = (par->CRTC[0] + ((i & 0x01) << 8)) / 2;
  806. par->CR5D = i;
  807. par->CR5E = (((timings.VTotal - 2) & 0x400) >> 10) |
  808. (((timings.VDisplay - 1) & 0x400) >> 9) |
  809. (((timings.VSyncStart) & 0x400) >> 8) |
  810. (((timings.VSyncStart) & 0x400) >> 6) | 0x40;
  811. width = (var->xres_virtual * ((var->bits_per_pixel+7) / 8)) >> 3;
  812. par->CR91 = par->CRTC[19] = 0xff & width;
  813. par->CR51 = (0x300 & width) >> 4;
  814. par->CR90 = 0x80 | (width >> 8);
  815. par->MiscOutReg |= 0x0c;
  816. /* Set frame buffer description. */
  817. if (var->bits_per_pixel <= 8)
  818. par->CR50 = 0;
  819. else if (var->bits_per_pixel <= 16)
  820. par->CR50 = 0x10;
  821. else
  822. par->CR50 = 0x30;
  823. if (var->xres_virtual <= 640)
  824. par->CR50 |= 0x40;
  825. else if (var->xres_virtual == 800)
  826. par->CR50 |= 0x80;
  827. else if (var->xres_virtual == 1024)
  828. par->CR50 |= 0x00;
  829. else if (var->xres_virtual == 1152)
  830. par->CR50 |= 0x01;
  831. else if (var->xres_virtual == 1280)
  832. par->CR50 |= 0xc0;
  833. else if (var->xres_virtual == 1600)
  834. par->CR50 |= 0x81;
  835. else
  836. par->CR50 |= 0xc1; /* Use GBD */
  837. if( par->chip == S3_SAVAGE2000 )
  838. par->CR33 = 0x08;
  839. else
  840. par->CR33 = 0x20;
  841. par->CRTC[0x17] = 0xeb;
  842. par->CR67 |= 1;
  843. vga_out8(0x3d4, 0x36);
  844. par->CR36 = vga_in8 (0x3d5);
  845. vga_out8 (0x3d4, 0x68);
  846. par->CR68 = vga_in8 (0x3d5);
  847. par->CR69 = 0;
  848. vga_out8 (0x3d4, 0x6f);
  849. par->CR6F = vga_in8 (0x3d5);
  850. vga_out8 (0x3d4, 0x86);
  851. par->CR86 = vga_in8 (0x3d5);
  852. vga_out8 (0x3d4, 0x88);
  853. par->CR88 = vga_in8 (0x3d5) | 0x08;
  854. vga_out8 (0x3d4, 0xb0);
  855. par->CRB0 = vga_in8 (0x3d5) | 0x80;
  856. return 0;
  857. }
  858. /* --------------------------------------------------------------------- */
  859. /*
  860. * Set a single color register. Return != 0 for invalid regno.
  861. */
  862. static int savagefb_setcolreg(unsigned regno,
  863. unsigned red,
  864. unsigned green,
  865. unsigned blue,
  866. unsigned transp,
  867. struct fb_info *info)
  868. {
  869. struct savagefb_par *par = (struct savagefb_par *)info->par;
  870. if (regno >= NR_PALETTE)
  871. return -EINVAL;
  872. par->palette[regno].red = red;
  873. par->palette[regno].green = green;
  874. par->palette[regno].blue = blue;
  875. par->palette[regno].transp = transp;
  876. switch (info->var.bits_per_pixel) {
  877. case 8:
  878. vga_out8 (0x3c8, regno);
  879. vga_out8 (0x3c9, red >> 10);
  880. vga_out8 (0x3c9, green >> 10);
  881. vga_out8 (0x3c9, blue >> 10);
  882. break;
  883. case 16:
  884. if (regno < 16)
  885. ((u32 *)info->pseudo_palette)[regno] =
  886. ((red & 0xf800) ) |
  887. ((green & 0xfc00) >> 5) |
  888. ((blue & 0xf800) >> 11);
  889. break;
  890. case 24:
  891. if (regno < 16)
  892. ((u32 *)info->pseudo_palette)[regno] =
  893. ((red & 0xff00) << 8) |
  894. ((green & 0xff00) ) |
  895. ((blue & 0xff00) >> 8);
  896. break;
  897. case 32:
  898. if (regno < 16)
  899. ((u32 *)info->pseudo_palette)[regno] =
  900. ((transp & 0xff00) << 16) |
  901. ((red & 0xff00) << 8) |
  902. ((green & 0xff00) ) |
  903. ((blue & 0xff00) >> 8);
  904. break;
  905. default:
  906. return 1;
  907. }
  908. return 0;
  909. }
  910. static void savagefb_set_par_int (struct savagefb_par *par)
  911. {
  912. unsigned char tmp, cr3a, cr66, cr67;
  913. DBG ("savagefb_set_par_int");
  914. par->SavageWaitIdle (par);
  915. vga_out8 (0x3c2, 0x23);
  916. vga_out16 (0x3d4, 0x4838);
  917. vga_out16 (0x3d4, 0xa539);
  918. vga_out16 (0x3c4, 0x0608);
  919. vgaHWProtect (par, 1);
  920. /*
  921. * Some Savage/MX and /IX systems go nuts when trying to exit the
  922. * server after WindowMaker has displayed a gradient background. I
  923. * haven't been able to find what causes it, but a non-destructive
  924. * switch to mode 3 here seems to eliminate the issue.
  925. */
  926. VerticalRetraceWait();
  927. vga_out8 (0x3d4, 0x67);
  928. cr67 = vga_in8 (0x3d5);
  929. vga_out8 (0x3d5, cr67/*par->CR67*/ & ~0x0c); /* no STREAMS yet */
  930. vga_out8 (0x3d4, 0x23);
  931. vga_out8 (0x3d5, 0x00);
  932. vga_out8 (0x3d4, 0x26);
  933. vga_out8 (0x3d5, 0x00);
  934. /* restore extended regs */
  935. vga_out8 (0x3d4, 0x66);
  936. vga_out8 (0x3d5, par->CR66);
  937. vga_out8 (0x3d4, 0x3a);
  938. vga_out8 (0x3d5, par->CR3A);
  939. vga_out8 (0x3d4, 0x31);
  940. vga_out8 (0x3d5, par->CR31);
  941. vga_out8 (0x3d4, 0x32);
  942. vga_out8 (0x3d5, par->CR32);
  943. vga_out8 (0x3d4, 0x58);
  944. vga_out8 (0x3d5, par->CR58);
  945. vga_out8 (0x3d4, 0x53);
  946. vga_out8 (0x3d5, par->CR53 & 0x7f);
  947. vga_out16 (0x3c4, 0x0608);
  948. /* Restore DCLK registers. */
  949. vga_out8 (0x3c4, 0x0e);
  950. vga_out8 (0x3c5, par->SR0E);
  951. vga_out8 (0x3c4, 0x0f);
  952. vga_out8 (0x3c5, par->SR0F);
  953. vga_out8 (0x3c4, 0x29);
  954. vga_out8 (0x3c5, par->SR29);
  955. vga_out8 (0x3c4, 0x15);
  956. vga_out8 (0x3c5, par->SR15);
  957. /* Restore flat panel expansion regsters. */
  958. if( par->chip == S3_SAVAGE_MX ) {
  959. int i;
  960. for( i = 0; i < 8; i++ ) {
  961. vga_out8 (0x3c4, 0x54+i);
  962. vga_out8 (0x3c5, par->SR54[i]);
  963. }
  964. }
  965. vgaHWRestore (par);
  966. /* extended mode timing registers */
  967. vga_out8 (0x3d4, 0x53);
  968. vga_out8 (0x3d5, par->CR53);
  969. vga_out8 (0x3d4, 0x5d);
  970. vga_out8 (0x3d5, par->CR5D);
  971. vga_out8 (0x3d4, 0x5e);
  972. vga_out8 (0x3d5, par->CR5E);
  973. vga_out8 (0x3d4, 0x3b);
  974. vga_out8 (0x3d5, par->CR3B);
  975. vga_out8 (0x3d4, 0x3c);
  976. vga_out8 (0x3d5, par->CR3C);
  977. vga_out8 (0x3d4, 0x43);
  978. vga_out8 (0x3d5, par->CR43);
  979. vga_out8 (0x3d4, 0x65);
  980. vga_out8 (0x3d5, par->CR65);
  981. /* restore the desired video mode with cr67 */
  982. vga_out8 (0x3d4, 0x67);
  983. /* following part not present in X11 driver */
  984. cr67 = vga_in8 (0x3d5) & 0xf;
  985. vga_out8 (0x3d5, 0x50 | cr67);
  986. udelay (10000);
  987. vga_out8 (0x3d4, 0x67);
  988. /* end of part */
  989. vga_out8 (0x3d5, par->CR67 & ~0x0c);
  990. /* other mode timing and extended regs */
  991. vga_out8 (0x3d4, 0x34);
  992. vga_out8 (0x3d5, par->CR34);
  993. vga_out8 (0x3d4, 0x40);
  994. vga_out8 (0x3d5, par->CR40);
  995. vga_out8 (0x3d4, 0x42);
  996. vga_out8 (0x3d5, par->CR42);
  997. vga_out8 (0x3d4, 0x45);
  998. vga_out8 (0x3d5, par->CR45);
  999. vga_out8 (0x3d4, 0x50);
  1000. vga_out8 (0x3d5, par->CR50);
  1001. vga_out8 (0x3d4, 0x51);
  1002. vga_out8 (0x3d5, par->CR51);
  1003. /* memory timings */
  1004. vga_out8 (0x3d4, 0x36);
  1005. vga_out8 (0x3d5, par->CR36);
  1006. vga_out8 (0x3d4, 0x60);
  1007. vga_out8 (0x3d5, par->CR60);
  1008. vga_out8 (0x3d4, 0x68);
  1009. vga_out8 (0x3d5, par->CR68);
  1010. vga_out8 (0x3d4, 0x69);
  1011. vga_out8 (0x3d5, par->CR69);
  1012. vga_out8 (0x3d4, 0x6f);
  1013. vga_out8 (0x3d5, par->CR6F);
  1014. vga_out8 (0x3d4, 0x33);
  1015. vga_out8 (0x3d5, par->CR33);
  1016. vga_out8 (0x3d4, 0x86);
  1017. vga_out8 (0x3d5, par->CR86);
  1018. vga_out8 (0x3d4, 0x88);
  1019. vga_out8 (0x3d5, par->CR88);
  1020. vga_out8 (0x3d4, 0x90);
  1021. vga_out8 (0x3d5, par->CR90);
  1022. vga_out8 (0x3d4, 0x91);
  1023. vga_out8 (0x3d5, par->CR91);
  1024. if (par->chip == S3_SAVAGE4) {
  1025. vga_out8 (0x3d4, 0xb0);
  1026. vga_out8 (0x3d5, par->CRB0);
  1027. }
  1028. vga_out8 (0x3d4, 0x32);
  1029. vga_out8 (0x3d5, par->CR32);
  1030. /* unlock extended seq regs */
  1031. vga_out8 (0x3c4, 0x08);
  1032. vga_out8 (0x3c5, 0x06);
  1033. /* Restore extended sequencer regs for MCLK. SR10 == 255 indicates
  1034. * that we should leave the default SR10 and SR11 values there.
  1035. */
  1036. if (par->SR10 != 255) {
  1037. vga_out8 (0x3c4, 0x10);
  1038. vga_out8 (0x3c5, par->SR10);
  1039. vga_out8 (0x3c4, 0x11);
  1040. vga_out8 (0x3c5, par->SR11);
  1041. }
  1042. /* restore extended seq regs for dclk */
  1043. vga_out8 (0x3c4, 0x0e);
  1044. vga_out8 (0x3c5, par->SR0E);
  1045. vga_out8 (0x3c4, 0x0f);
  1046. vga_out8 (0x3c5, par->SR0F);
  1047. vga_out8 (0x3c4, 0x12);
  1048. vga_out8 (0x3c5, par->SR12);
  1049. vga_out8 (0x3c4, 0x13);
  1050. vga_out8 (0x3c5, par->SR13);
  1051. vga_out8 (0x3c4, 0x29);
  1052. vga_out8 (0x3c5, par->SR29);
  1053. vga_out8 (0x3c4, 0x18);
  1054. vga_out8 (0x3c5, par->SR18);
  1055. /* load new m, n pll values for dclk & mclk */
  1056. vga_out8 (0x3c4, 0x15);
  1057. tmp = vga_in8 (0x3c5) & ~0x21;
  1058. vga_out8 (0x3c5, tmp | 0x03);
  1059. vga_out8 (0x3c5, tmp | 0x23);
  1060. vga_out8 (0x3c5, tmp | 0x03);
  1061. vga_out8 (0x3c5, par->SR15);
  1062. udelay (100);
  1063. vga_out8 (0x3c4, 0x30);
  1064. vga_out8 (0x3c5, par->SR30);
  1065. vga_out8 (0x3c4, 0x08);
  1066. vga_out8 (0x3c5, par->SR08);
  1067. /* now write out cr67 in full, possibly starting STREAMS */
  1068. VerticalRetraceWait();
  1069. vga_out8 (0x3d4, 0x67);
  1070. vga_out8 (0x3d5, par->CR67);
  1071. vga_out8 (0x3d4, 0x66);
  1072. cr66 = vga_in8 (0x3d5);
  1073. vga_out8 (0x3d5, cr66 | 0x80);
  1074. vga_out8 (0x3d4, 0x3a);
  1075. cr3a = vga_in8 (0x3d5);
  1076. vga_out8 (0x3d5, cr3a | 0x80);
  1077. if (par->chip != S3_SAVAGE_MX) {
  1078. VerticalRetraceWait();
  1079. savage_out32 (FIFO_CONTROL_REG, par->MMPR0);
  1080. par->SavageWaitIdle (par);
  1081. savage_out32 (MIU_CONTROL_REG, par->MMPR1);
  1082. par->SavageWaitIdle (par);
  1083. savage_out32 (STREAMS_TIMEOUT_REG, par->MMPR2);
  1084. par->SavageWaitIdle (par);
  1085. savage_out32 (MISC_TIMEOUT_REG, par->MMPR3);
  1086. }
  1087. vga_out8 (0x3d4, 0x66);
  1088. vga_out8 (0x3d5, cr66);
  1089. vga_out8 (0x3d4, 0x3a);
  1090. vga_out8 (0x3d5, cr3a);
  1091. SavageSetup2DEngine (par);
  1092. vgaHWProtect (par, 0);
  1093. }
  1094. static void savagefb_update_start (struct savagefb_par *par,
  1095. struct fb_var_screeninfo *var)
  1096. {
  1097. int base;
  1098. base = ((var->yoffset * var->xres_virtual + (var->xoffset & ~1))
  1099. * ((var->bits_per_pixel+7) / 8)) >> 2;
  1100. /* now program the start address registers */
  1101. vga_out16(0x3d4, (base & 0x00ff00) | 0x0c);
  1102. vga_out16(0x3d4, ((base & 0x00ff) << 8) | 0x0d);
  1103. vga_out8 (0x3d4, 0x69);
  1104. vga_out8 (0x3d5, (base & 0x7f0000) >> 16);
  1105. }
  1106. static void savagefb_set_fix(struct fb_info *info)
  1107. {
  1108. info->fix.line_length = info->var.xres_virtual *
  1109. info->var.bits_per_pixel / 8;
  1110. if (info->var.bits_per_pixel == 8)
  1111. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  1112. else
  1113. info->fix.visual = FB_VISUAL_TRUECOLOR;
  1114. }
  1115. #if defined(CONFIG_FB_SAVAGE_ACCEL)
  1116. static void savagefb_set_clip(struct fb_info *info)
  1117. {
  1118. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1119. int cmd;
  1120. cmd = BCI_CMD_NOP | BCI_CMD_CLIP_NEW;
  1121. par->bci_ptr = 0;
  1122. par->SavageWaitFifo(par,3);
  1123. BCI_SEND(cmd);
  1124. BCI_SEND(BCI_CLIP_TL(0, 0));
  1125. BCI_SEND(BCI_CLIP_BR(0xfff, 0xfff));
  1126. }
  1127. #endif
  1128. static int savagefb_set_par (struct fb_info *info)
  1129. {
  1130. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1131. struct fb_var_screeninfo *var = &info->var;
  1132. int err;
  1133. DBG("savagefb_set_par");
  1134. err = savagefb_decode_var (var, par);
  1135. if (err)
  1136. return err;
  1137. if (par->dacSpeedBpp <= 0) {
  1138. if (var->bits_per_pixel > 24)
  1139. par->dacSpeedBpp = par->clock[3];
  1140. else if (var->bits_per_pixel >= 24)
  1141. par->dacSpeedBpp = par->clock[2];
  1142. else if ((var->bits_per_pixel > 8) && (var->bits_per_pixel < 24))
  1143. par->dacSpeedBpp = par->clock[1];
  1144. else if (var->bits_per_pixel <= 8)
  1145. par->dacSpeedBpp = par->clock[0];
  1146. }
  1147. /* Set ramdac limits */
  1148. par->maxClock = par->dacSpeedBpp;
  1149. par->minClock = 10000;
  1150. savagefb_set_par_int (par);
  1151. savagefb_update_start (par, var);
  1152. fb_set_cmap (&info->cmap, info);
  1153. savagefb_set_fix(info);
  1154. savagefb_set_clip(info);
  1155. SavagePrintRegs();
  1156. return 0;
  1157. }
  1158. /*
  1159. * Pan or Wrap the Display
  1160. */
  1161. static int savagefb_pan_display (struct fb_var_screeninfo *var,
  1162. struct fb_info *info)
  1163. {
  1164. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1165. u_int y_bottom;
  1166. y_bottom = var->yoffset;
  1167. if (!(var->vmode & FB_VMODE_YWRAP))
  1168. y_bottom += var->yres;
  1169. if (var->xoffset > (var->xres_virtual - var->xres))
  1170. return -EINVAL;
  1171. if (y_bottom > info->var.yres_virtual)
  1172. return -EINVAL;
  1173. savagefb_update_start (par, var);
  1174. info->var.xoffset = var->xoffset;
  1175. info->var.yoffset = var->yoffset;
  1176. if (var->vmode & FB_VMODE_YWRAP)
  1177. info->var.vmode |= FB_VMODE_YWRAP;
  1178. else
  1179. info->var.vmode &= ~FB_VMODE_YWRAP;
  1180. return 0;
  1181. }
  1182. static struct fb_ops savagefb_ops = {
  1183. .owner = THIS_MODULE,
  1184. .fb_check_var = savagefb_check_var,
  1185. .fb_set_par = savagefb_set_par,
  1186. .fb_setcolreg = savagefb_setcolreg,
  1187. .fb_pan_display = savagefb_pan_display,
  1188. #if defined(CONFIG_FB_SAVAGE_ACCEL)
  1189. .fb_fillrect = savagefb_fillrect,
  1190. .fb_copyarea = savagefb_copyarea,
  1191. .fb_imageblit = savagefb_imageblit,
  1192. .fb_sync = savagefb_sync,
  1193. #else
  1194. .fb_fillrect = cfb_fillrect,
  1195. .fb_copyarea = cfb_copyarea,
  1196. .fb_imageblit = cfb_imageblit,
  1197. #endif
  1198. .fb_cursor = soft_cursor,
  1199. };
  1200. /* --------------------------------------------------------------------- */
  1201. static struct fb_var_screeninfo __devinitdata savagefb_var800x600x8 = {
  1202. .accel_flags = FB_ACCELF_TEXT,
  1203. .xres = 800,
  1204. .yres = 600,
  1205. .xres_virtual = 800,
  1206. .yres_virtual = 600,
  1207. .bits_per_pixel = 8,
  1208. .pixclock = 25000,
  1209. .left_margin = 88,
  1210. .right_margin = 40,
  1211. .upper_margin = 23,
  1212. .lower_margin = 1,
  1213. .hsync_len = 128,
  1214. .vsync_len = 4,
  1215. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  1216. .vmode = FB_VMODE_NONINTERLACED
  1217. };
  1218. static void savage_enable_mmio (struct savagefb_par *par)
  1219. {
  1220. unsigned char val;
  1221. DBG ("savage_enable_mmio\n");
  1222. val = vga_in8 (0x3c3);
  1223. vga_out8 (0x3c3, val | 0x01);
  1224. val = vga_in8 (0x3cc);
  1225. vga_out8 (0x3c2, val | 0x01);
  1226. if (par->chip >= S3_SAVAGE4) {
  1227. vga_out8 (0x3d4, 0x40);
  1228. val = vga_in8 (0x3d5);
  1229. vga_out8 (0x3d5, val | 1);
  1230. }
  1231. }
  1232. static void savage_disable_mmio (struct savagefb_par *par)
  1233. {
  1234. unsigned char val;
  1235. DBG ("savage_disable_mmio\n");
  1236. if(par->chip >= S3_SAVAGE4 ) {
  1237. vga_out8 (0x3d4, 0x40);
  1238. val = vga_in8 (0x3d5);
  1239. vga_out8 (0x3d5, val | 1);
  1240. }
  1241. }
  1242. static int __devinit savage_map_mmio (struct fb_info *info)
  1243. {
  1244. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1245. DBG ("savage_map_mmio");
  1246. if (S3_SAVAGE3D_SERIES (par->chip))
  1247. par->mmio.pbase = pci_resource_start (par->pcidev, 0) +
  1248. SAVAGE_NEWMMIO_REGBASE_S3;
  1249. else
  1250. par->mmio.pbase = pci_resource_start (par->pcidev, 0) +
  1251. SAVAGE_NEWMMIO_REGBASE_S4;
  1252. par->mmio.len = SAVAGE_NEWMMIO_REGSIZE;
  1253. par->mmio.vbase = ioremap (par->mmio.pbase, par->mmio.len);
  1254. if (!par->mmio.vbase) {
  1255. printk ("savagefb: unable to map memory mapped IO\n");
  1256. return -ENOMEM;
  1257. } else
  1258. printk (KERN_INFO "savagefb: mapped io at %p\n",
  1259. par->mmio.vbase);
  1260. info->fix.mmio_start = par->mmio.pbase;
  1261. info->fix.mmio_len = par->mmio.len;
  1262. par->bci_base = (u32 __iomem *)(par->mmio.vbase + BCI_BUFFER_OFFSET);
  1263. par->bci_ptr = 0;
  1264. savage_enable_mmio (par);
  1265. return 0;
  1266. }
  1267. static void __devinit savage_unmap_mmio (struct fb_info *info)
  1268. {
  1269. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1270. DBG ("savage_unmap_mmio");
  1271. savage_disable_mmio(par);
  1272. if (par->mmio.vbase) {
  1273. iounmap(par->mmio.vbase);
  1274. par->mmio.vbase = NULL;
  1275. }
  1276. }
  1277. static int __devinit savage_map_video (struct fb_info *info,
  1278. int video_len)
  1279. {
  1280. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1281. int resource;
  1282. DBG("savage_map_video");
  1283. if (S3_SAVAGE3D_SERIES (par->chip))
  1284. resource = 0;
  1285. else
  1286. resource = 1;
  1287. par->video.pbase = pci_resource_start (par->pcidev, resource);
  1288. par->video.len = video_len;
  1289. par->video.vbase = ioremap (par->video.pbase, par->video.len);
  1290. if (!par->video.vbase) {
  1291. printk ("savagefb: unable to map screen memory\n");
  1292. return -ENOMEM;
  1293. } else
  1294. printk (KERN_INFO "savagefb: mapped framebuffer at %p, "
  1295. "pbase == %x\n", par->video.vbase, par->video.pbase);
  1296. info->fix.smem_start = par->video.pbase;
  1297. info->fix.smem_len = par->video.len - par->cob_size;
  1298. info->screen_base = par->video.vbase;
  1299. #ifdef CONFIG_MTRR
  1300. par->video.mtrr = mtrr_add (par->video.pbase, video_len,
  1301. MTRR_TYPE_WRCOMB, 1);
  1302. #endif
  1303. /* Clear framebuffer, it's all white in memory after boot */
  1304. memset_io (par->video.vbase, 0, par->video.len);
  1305. return 0;
  1306. }
  1307. static void __devinit savage_unmap_video (struct fb_info *info)
  1308. {
  1309. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1310. DBG("savage_unmap_video");
  1311. if (par->video.vbase) {
  1312. #ifdef CONFIG_MTRR
  1313. mtrr_del (par->video.mtrr, par->video.pbase, par->video.len);
  1314. #endif
  1315. iounmap (par->video.vbase);
  1316. par->video.vbase = NULL;
  1317. info->screen_base = NULL;
  1318. }
  1319. }
  1320. static int __devinit savage_init_hw (struct savagefb_par *par)
  1321. {
  1322. unsigned char config1, m, n, n1, n2, sr8, cr3f, cr66 = 0, tmp;
  1323. static unsigned char RamSavage3D[] = { 8, 4, 4, 2 };
  1324. static unsigned char RamSavage4[] = { 2, 4, 8, 12, 16, 32, 64, 32 };
  1325. static unsigned char RamSavageMX[] = { 2, 8, 4, 16, 8, 16, 4, 16 };
  1326. static unsigned char RamSavageNB[] = { 0, 2, 4, 8, 16, 32, 2, 2 };
  1327. int videoRam, videoRambytes;
  1328. DBG("savage_init_hw");
  1329. /* unprotect CRTC[0-7] */
  1330. vga_out8(0x3d4, 0x11);
  1331. tmp = vga_in8(0x3d5);
  1332. vga_out8(0x3d5, tmp & 0x7f);
  1333. /* unlock extended regs */
  1334. vga_out16(0x3d4, 0x4838);
  1335. vga_out16(0x3d4, 0xa039);
  1336. vga_out16(0x3c4, 0x0608);
  1337. vga_out8(0x3d4, 0x40);
  1338. tmp = vga_in8(0x3d5);
  1339. vga_out8(0x3d5, tmp & ~0x01);
  1340. /* unlock sys regs */
  1341. vga_out8(0x3d4, 0x38);
  1342. vga_out8(0x3d5, 0x48);
  1343. /* Unlock system registers. */
  1344. vga_out16(0x3d4, 0x4838);
  1345. /* Next go on to detect amount of installed ram */
  1346. vga_out8(0x3d4, 0x36); /* for register CR36 (CONFG_REG1), */
  1347. config1 = vga_in8(0x3d5); /* get amount of vram installed */
  1348. /* Compute the amount of video memory and offscreen memory. */
  1349. switch (par->chip) {
  1350. case S3_SAVAGE3D:
  1351. videoRam = RamSavage3D[ (config1 & 0xC0) >> 6 ] * 1024;
  1352. break;
  1353. case S3_SAVAGE4:
  1354. /*
  1355. * The Savage4 has one ugly special case to consider. On
  1356. * systems with 4 banks of 2Mx32 SDRAM, the BIOS says 4MB
  1357. * when it really means 8MB. Why do it the same when you
  1358. * can do it different...
  1359. */
  1360. vga_out8(0x3d4, 0x68); /* memory control 1 */
  1361. if( (vga_in8(0x3d5) & 0xC0) == (0x01 << 6) )
  1362. RamSavage4[1] = 8;
  1363. /*FALLTHROUGH*/
  1364. case S3_SAVAGE2000:
  1365. videoRam = RamSavage4[ (config1 & 0xE0) >> 5 ] * 1024;
  1366. break;
  1367. case S3_SAVAGE_MX:
  1368. case S3_SUPERSAVAGE:
  1369. videoRam = RamSavageMX[ (config1 & 0x0E) >> 1 ] * 1024;
  1370. break;
  1371. case S3_PROSAVAGE:
  1372. videoRam = RamSavageNB[ (config1 & 0xE0) >> 5 ] * 1024;
  1373. break;
  1374. default:
  1375. /* How did we get here? */
  1376. videoRam = 0;
  1377. break;
  1378. }
  1379. videoRambytes = videoRam * 1024;
  1380. printk (KERN_INFO "savagefb: probed videoram: %dk\n", videoRam);
  1381. /* reset graphics engine to avoid memory corruption */
  1382. vga_out8 (0x3d4, 0x66);
  1383. cr66 = vga_in8 (0x3d5);
  1384. vga_out8 (0x3d5, cr66 | 0x02);
  1385. udelay (10000);
  1386. vga_out8 (0x3d4, 0x66);
  1387. vga_out8 (0x3d5, cr66 & ~0x02); /* clear reset flag */
  1388. udelay (10000);
  1389. /*
  1390. * reset memory interface, 3D engine, AGP master, PCI master,
  1391. * master engine unit, motion compensation/LPB
  1392. */
  1393. vga_out8 (0x3d4, 0x3f);
  1394. cr3f = vga_in8 (0x3d5);
  1395. vga_out8 (0x3d5, cr3f | 0x08);
  1396. udelay (10000);
  1397. vga_out8 (0x3d4, 0x3f);
  1398. vga_out8 (0x3d5, cr3f & ~0x08); /* clear reset flags */
  1399. udelay (10000);
  1400. /* Savage ramdac speeds */
  1401. par->numClocks = 4;
  1402. par->clock[0] = 250000;
  1403. par->clock[1] = 250000;
  1404. par->clock[2] = 220000;
  1405. par->clock[3] = 220000;
  1406. /* detect current mclk */
  1407. vga_out8(0x3c4, 0x08);
  1408. sr8 = vga_in8(0x3c5);
  1409. vga_out8(0x3c5, 0x06);
  1410. vga_out8(0x3c4, 0x10);
  1411. n = vga_in8(0x3c5);
  1412. vga_out8(0x3c4, 0x11);
  1413. m = vga_in8(0x3c5);
  1414. vga_out8(0x3c4, 0x08);
  1415. vga_out8(0x3c5, sr8);
  1416. m &= 0x7f;
  1417. n1 = n & 0x1f;
  1418. n2 = (n >> 5) & 0x03;
  1419. par->MCLK = ((1431818 * (m+2)) / (n1+2) / (1 << n2) + 50) / 100;
  1420. printk (KERN_INFO "savagefb: Detected current MCLK value of %d kHz\n",
  1421. par->MCLK);
  1422. /* Check LCD panel parrmation */
  1423. if (par->chip == S3_SAVAGE_MX) {
  1424. unsigned char cr6b = VGArCR( 0x6b );
  1425. int panelX = (VGArSEQ (0x61) +
  1426. ((VGArSEQ (0x66) & 0x02) << 7) + 1) * 8;
  1427. int panelY = (VGArSEQ (0x69) +
  1428. ((VGArSEQ (0x6e) & 0x70) << 4) + 1);
  1429. char * sTechnology = "Unknown";
  1430. /* OK, I admit it. I don't know how to limit the max dot clock
  1431. * for LCD panels of various sizes. I thought I copied the
  1432. * formula from the BIOS, but many users have parrmed me of
  1433. * my folly.
  1434. *
  1435. * Instead, I'll abandon any attempt to automatically limit the
  1436. * clock, and add an LCDClock option to XF86Config. Some day,
  1437. * I should come back to this.
  1438. */
  1439. enum ACTIVE_DISPLAYS { /* These are the bits in CR6B */
  1440. ActiveCRT = 0x01,
  1441. ActiveLCD = 0x02,
  1442. ActiveTV = 0x04,
  1443. ActiveCRT2 = 0x20,
  1444. ActiveDUO = 0x80
  1445. };
  1446. if ((VGArSEQ (0x39) & 0x03) == 0) {
  1447. sTechnology = "TFT";
  1448. } else if ((VGArSEQ (0x30) & 0x01) == 0) {
  1449. sTechnology = "DSTN";
  1450. } else {
  1451. sTechnology = "STN";
  1452. }
  1453. printk (KERN_INFO "savagefb: %dx%d %s LCD panel detected %s\n",
  1454. panelX, panelY, sTechnology,
  1455. cr6b & ActiveLCD ? "and active" : "but not active");
  1456. if( cr6b & ActiveLCD ) {
  1457. /*
  1458. * If the LCD is active and panel expansion is enabled,
  1459. * we probably want to kill the HW cursor.
  1460. */
  1461. printk (KERN_INFO "savagefb: Limiting video mode to "
  1462. "%dx%d\n", panelX, panelY );
  1463. par->SavagePanelWidth = panelX;
  1464. par->SavagePanelHeight = panelY;
  1465. }
  1466. }
  1467. savage_get_default_par (par);
  1468. if( S3_SAVAGE4_SERIES(par->chip) ) {
  1469. /*
  1470. * The Savage4 and ProSavage have COB coherency bugs which
  1471. * render the buffer useless. We disable it.
  1472. */
  1473. par->cob_index = 2;
  1474. par->cob_size = 0x8000 << par->cob_index;
  1475. par->cob_offset = videoRambytes;
  1476. } else {
  1477. /* We use 128kB for the COB on all chips. */
  1478. par->cob_index = 7;
  1479. par->cob_size = 0x400 << par->cob_index;
  1480. par->cob_offset = videoRambytes - par->cob_size;
  1481. }
  1482. return videoRambytes;
  1483. }
  1484. static int __devinit savage_init_fb_info (struct fb_info *info,
  1485. struct pci_dev *dev,
  1486. const struct pci_device_id *id)
  1487. {
  1488. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1489. int err = 0;
  1490. par->pcidev = dev;
  1491. info->fix.type = FB_TYPE_PACKED_PIXELS;
  1492. info->fix.type_aux = 0;
  1493. info->fix.xpanstep = 2;
  1494. info->fix.ypanstep = 1;
  1495. info->fix.ywrapstep = 0;
  1496. info->fix.accel = id->driver_data;
  1497. switch (info->fix.accel) {
  1498. case FB_ACCEL_SUPERSAVAGE:
  1499. par->chip = S3_SUPERSAVAGE;
  1500. snprintf (info->fix.id, 16, "SuperSavage");
  1501. break;
  1502. case FB_ACCEL_SAVAGE4:
  1503. par->chip = S3_SAVAGE4;
  1504. snprintf (info->fix.id, 16, "Savage4");
  1505. break;
  1506. case FB_ACCEL_SAVAGE3D:
  1507. par->chip = S3_SAVAGE3D;
  1508. snprintf (info->fix.id, 16, "Savage3D");
  1509. break;
  1510. case FB_ACCEL_SAVAGE3D_MV:
  1511. par->chip = S3_SAVAGE3D;
  1512. snprintf (info->fix.id, 16, "Savage3D-MV");
  1513. break;
  1514. case FB_ACCEL_SAVAGE2000:
  1515. par->chip = S3_SAVAGE2000;
  1516. snprintf (info->fix.id, 16, "Savage2000");
  1517. break;
  1518. case FB_ACCEL_SAVAGE_MX_MV:
  1519. par->chip = S3_SAVAGE_MX;
  1520. snprintf (info->fix.id, 16, "Savage/MX-MV");
  1521. break;
  1522. case FB_ACCEL_SAVAGE_MX:
  1523. par->chip = S3_SAVAGE_MX;
  1524. snprintf (info->fix.id, 16, "Savage/MX");
  1525. break;
  1526. case FB_ACCEL_SAVAGE_IX_MV:
  1527. par->chip = S3_SAVAGE_MX;
  1528. snprintf (info->fix.id, 16, "Savage/IX-MV");
  1529. break;
  1530. case FB_ACCEL_SAVAGE_IX:
  1531. par->chip = S3_SAVAGE_MX;
  1532. snprintf (info->fix.id, 16, "Savage/IX");
  1533. break;
  1534. case FB_ACCEL_PROSAVAGE_PM:
  1535. par->chip = S3_PROSAVAGE;
  1536. snprintf (info->fix.id, 16, "ProSavagePM");
  1537. break;
  1538. case FB_ACCEL_PROSAVAGE_KM:
  1539. par->chip = S3_PROSAVAGE;
  1540. snprintf (info->fix.id, 16, "ProSavageKM");
  1541. break;
  1542. case FB_ACCEL_S3TWISTER_P:
  1543. par->chip = S3_PROSAVAGE;
  1544. snprintf (info->fix.id, 16, "TwisterP");
  1545. break;
  1546. case FB_ACCEL_S3TWISTER_K:
  1547. par->chip = S3_PROSAVAGE;
  1548. snprintf (info->fix.id, 16, "TwisterK");
  1549. break;
  1550. case FB_ACCEL_PROSAVAGE_DDR:
  1551. par->chip = S3_PROSAVAGE;
  1552. snprintf (info->fix.id, 16, "ProSavageDDR");
  1553. break;
  1554. case FB_ACCEL_PROSAVAGE_DDRK:
  1555. par->chip = S3_PROSAVAGE;
  1556. snprintf (info->fix.id, 16, "ProSavage8");
  1557. break;
  1558. }
  1559. if (S3_SAVAGE3D_SERIES(par->chip)) {
  1560. par->SavageWaitIdle = savage3D_waitidle;
  1561. par->SavageWaitFifo = savage3D_waitfifo;
  1562. } else if (S3_SAVAGE4_SERIES(par->chip) ||
  1563. S3_SUPERSAVAGE == par->chip) {
  1564. par->SavageWaitIdle = savage4_waitidle;
  1565. par->SavageWaitFifo = savage4_waitfifo;
  1566. } else {
  1567. par->SavageWaitIdle = savage2000_waitidle;
  1568. par->SavageWaitFifo = savage2000_waitfifo;
  1569. }
  1570. info->var.nonstd = 0;
  1571. info->var.activate = FB_ACTIVATE_NOW;
  1572. info->var.width = -1;
  1573. info->var.height = -1;
  1574. info->var.accel_flags = 0;
  1575. info->fbops = &savagefb_ops;
  1576. info->flags = FBINFO_DEFAULT |
  1577. FBINFO_HWACCEL_YPAN |
  1578. FBINFO_HWACCEL_XPAN;
  1579. info->pseudo_palette = par->pseudo_palette;
  1580. #if defined(CONFIG_FB_SAVAGE_ACCEL)
  1581. /* FIFO size + padding for commands */
  1582. info->pixmap.addr = kmalloc(8*1024, GFP_KERNEL);
  1583. err = -ENOMEM;
  1584. if (info->pixmap.addr) {
  1585. memset(info->pixmap.addr, 0, 8*1024);
  1586. info->pixmap.size = 8*1024;
  1587. info->pixmap.scan_align = 4;
  1588. info->pixmap.buf_align = 4;
  1589. info->pixmap.access_align = 32;
  1590. fb_alloc_cmap (&info->cmap, NR_PALETTE, 0);
  1591. info->flags |= FBINFO_HWACCEL_COPYAREA |
  1592. FBINFO_HWACCEL_FILLRECT |
  1593. FBINFO_HWACCEL_IMAGEBLIT;
  1594. err = 0;
  1595. }
  1596. #endif
  1597. return err;
  1598. }
  1599. /* --------------------------------------------------------------------- */
  1600. static int __devinit savagefb_probe (struct pci_dev* dev,
  1601. const struct pci_device_id* id)
  1602. {
  1603. struct fb_info *info;
  1604. struct savagefb_par *par;
  1605. u_int h_sync, v_sync;
  1606. int err, lpitch;
  1607. int video_len;
  1608. DBG("savagefb_probe");
  1609. SavagePrintRegs();
  1610. info = framebuffer_alloc(sizeof(struct savagefb_par), &dev->dev);
  1611. if (!info)
  1612. return -ENOMEM;
  1613. par = info->par;
  1614. err = pci_enable_device(dev);
  1615. if (err)
  1616. goto failed_enable;
  1617. if (pci_request_regions(dev, "savagefb")) {
  1618. printk(KERN_ERR "cannot request PCI regions\n");
  1619. goto failed_enable;
  1620. }
  1621. err = -ENOMEM;
  1622. if (savage_init_fb_info(info, dev, id))
  1623. goto failed_init;
  1624. err = savage_map_mmio(info);
  1625. if (err)
  1626. goto failed_mmio;
  1627. video_len = savage_init_hw(par);
  1628. if (video_len < 0) {
  1629. err = video_len;
  1630. goto failed_mmio;
  1631. }
  1632. err = savage_map_video(info, video_len);
  1633. if (err)
  1634. goto failed_video;
  1635. INIT_LIST_HEAD(&info->modelist);
  1636. #if defined(CONFIG_FB_SAVAGE_I2C)
  1637. savagefb_create_i2c_busses(info);
  1638. savagefb_probe_i2c_connector(par, &par->edid);
  1639. fb_edid_to_monspecs(par->edid, &info->monspecs);
  1640. fb_videomode_to_modelist(info->monspecs.modedb,
  1641. info->monspecs.modedb_len,
  1642. &info->modelist);
  1643. #endif
  1644. info->var = savagefb_var800x600x8;
  1645. if (mode_option) {
  1646. fb_find_mode(&info->var, info, mode_option,
  1647. info->monspecs.modedb, info->monspecs.modedb_len,
  1648. NULL, 8);
  1649. } else if (info->monspecs.modedb != NULL) {
  1650. struct fb_monspecs *specs = &info->monspecs;
  1651. struct fb_videomode modedb;
  1652. if (info->monspecs.misc & FB_MISC_1ST_DETAIL) {
  1653. int i;
  1654. for (i = 0; i < specs->modedb_len; i++) {
  1655. if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
  1656. modedb = specs->modedb[i];
  1657. break;
  1658. }
  1659. }
  1660. } else {
  1661. /* otherwise, get first mode in database */
  1662. modedb = specs->modedb[0];
  1663. }
  1664. savage_update_var(&info->var, &modedb);
  1665. }
  1666. /* maximize virtual vertical length */
  1667. lpitch = info->var.xres_virtual*((info->var.bits_per_pixel + 7) >> 3);
  1668. info->var.yres_virtual = info->fix.smem_len/lpitch;
  1669. if (info->var.yres_virtual < info->var.yres)
  1670. goto failed;
  1671. #if defined(CONFIG_FB_SAVAGE_ACCEL)
  1672. /*
  1673. * The clipping coordinates are masked with 0xFFF, so limit our
  1674. * virtual resolutions to these sizes.
  1675. */
  1676. if (info->var.yres_virtual > 0x1000)
  1677. info->var.yres_virtual = 0x1000;
  1678. if (info->var.xres_virtual > 0x1000)
  1679. info->var.xres_virtual = 0x1000;
  1680. #endif
  1681. savagefb_check_var(&info->var, info);
  1682. savagefb_set_fix(info);
  1683. /*
  1684. * Calculate the hsync and vsync frequencies. Note that
  1685. * we split the 1e12 constant up so that we can preserve
  1686. * the precision and fit the results into 32-bit registers.
  1687. * (1953125000 * 512 = 1e12)
  1688. */
  1689. h_sync = 1953125000 / info->var.pixclock;
  1690. h_sync = h_sync * 512 / (info->var.xres + info->var.left_margin +
  1691. info->var.right_margin +
  1692. info->var.hsync_len);
  1693. v_sync = h_sync / (info->var.yres + info->var.upper_margin +
  1694. info->var.lower_margin + info->var.vsync_len);
  1695. printk(KERN_INFO "savagefb v" SAVAGEFB_VERSION ": "
  1696. "%dkB VRAM, using %dx%d, %d.%03dkHz, %dHz\n",
  1697. info->fix.smem_len >> 10,
  1698. info->var.xres, info->var.yres,
  1699. h_sync / 1000, h_sync % 1000, v_sync);
  1700. fb_destroy_modedb(info->monspecs.modedb);
  1701. info->monspecs.modedb = NULL;
  1702. err = register_framebuffer (info);
  1703. if (err < 0)
  1704. goto failed;
  1705. printk (KERN_INFO "fb: S3 %s frame buffer device\n",
  1706. info->fix.id);
  1707. /*
  1708. * Our driver data
  1709. */
  1710. pci_set_drvdata(dev, info);
  1711. return 0;
  1712. failed:
  1713. #ifdef CONFIG_FB_SAVAGE_I2C
  1714. savagefb_delete_i2c_busses(info);
  1715. #endif
  1716. fb_alloc_cmap (&info->cmap, 0, 0);
  1717. savage_unmap_video(info);
  1718. failed_video:
  1719. savage_unmap_mmio (info);
  1720. failed_mmio:
  1721. kfree(info->pixmap.addr);
  1722. failed_init:
  1723. pci_release_regions(dev);
  1724. failed_enable:
  1725. framebuffer_release(info);
  1726. return err;
  1727. }
  1728. static void __devexit savagefb_remove (struct pci_dev *dev)
  1729. {
  1730. struct fb_info *info =
  1731. (struct fb_info *)pci_get_drvdata(dev);
  1732. DBG("savagefb_remove");
  1733. if (info) {
  1734. /*
  1735. * If unregister_framebuffer fails, then
  1736. * we will be leaving hooks that could cause
  1737. * oopsen laying around.
  1738. */
  1739. if (unregister_framebuffer (info))
  1740. printk (KERN_WARNING "savagefb: danger danger! "
  1741. "Oopsen imminent!\n");
  1742. #ifdef CONFIG_FB_SAVAGE_I2C
  1743. savagefb_delete_i2c_busses(info);
  1744. #endif
  1745. fb_alloc_cmap (&info->cmap, 0, 0);
  1746. savage_unmap_video (info);
  1747. savage_unmap_mmio (info);
  1748. kfree(info->pixmap.addr);
  1749. pci_release_regions(dev);
  1750. framebuffer_release(info);
  1751. /*
  1752. * Ensure that the driver data is no longer
  1753. * valid.
  1754. */
  1755. pci_set_drvdata(dev, NULL);
  1756. }
  1757. }
  1758. static int savagefb_suspend (struct pci_dev* dev, pm_message_t state)
  1759. {
  1760. struct fb_info *info =
  1761. (struct fb_info *)pci_get_drvdata(dev);
  1762. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1763. DBG("savagefb_suspend");
  1764. printk(KERN_DEBUG "state: %u\n", state);
  1765. acquire_console_sem();
  1766. fb_set_suspend(info, state);
  1767. savage_disable_mmio(par);
  1768. release_console_sem();
  1769. pci_disable_device(dev);
  1770. pci_set_power_state(dev, pci_choose_state(dev, state));
  1771. return 0;
  1772. }
  1773. static int savagefb_resume (struct pci_dev* dev)
  1774. {
  1775. struct fb_info *info =
  1776. (struct fb_info *)pci_get_drvdata(dev);
  1777. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1778. DBG("savage_resume");
  1779. pci_set_power_state(dev, 0);
  1780. pci_restore_state(dev);
  1781. if(pci_enable_device(dev))
  1782. DBG("err");
  1783. SavagePrintRegs();
  1784. acquire_console_sem();
  1785. savage_enable_mmio(par);
  1786. savage_init_hw(par);
  1787. savagefb_set_par (info);
  1788. fb_set_suspend (info, 0);
  1789. release_console_sem();
  1790. return 0;
  1791. }
  1792. static struct pci_device_id savagefb_devices[] __devinitdata = {
  1793. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX128,
  1794. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1795. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX64,
  1796. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1797. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX64C,
  1798. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1799. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX128SDR,
  1800. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1801. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX128DDR,
  1802. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1803. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX64SDR,
  1804. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1805. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX64DDR,
  1806. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1807. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IXCSDR,
  1808. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1809. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IXCDDR,
  1810. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1811. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE4,
  1812. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE4},
  1813. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE3D,
  1814. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE3D},
  1815. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE3D_MV,
  1816. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE3D_MV},
  1817. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE2000,
  1818. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE2000},
  1819. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_MX_MV,
  1820. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_MX_MV},
  1821. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_MX,
  1822. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_MX},
  1823. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_IX_MV,
  1824. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_IX_MV},
  1825. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_IX,
  1826. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_IX},
  1827. {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_PM,
  1828. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_PM},
  1829. {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_KM,
  1830. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_KM},
  1831. {PCI_VENDOR_ID_S3, PCI_CHIP_S3TWISTER_P,
  1832. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_S3TWISTER_P},
  1833. {PCI_VENDOR_ID_S3, PCI_CHIP_S3TWISTER_K,
  1834. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_S3TWISTER_K},
  1835. {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_DDR,
  1836. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_DDR},
  1837. {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_DDRK,
  1838. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_DDRK},
  1839. {0, 0, 0, 0, 0, 0, 0}
  1840. };
  1841. MODULE_DEVICE_TABLE(pci, savagefb_devices);
  1842. static struct pci_driver savagefb_driver = {
  1843. .name = "savagefb",
  1844. .id_table = savagefb_devices,
  1845. .probe = savagefb_probe,
  1846. .suspend = savagefb_suspend,
  1847. .resume = savagefb_resume,
  1848. .remove = __devexit_p(savagefb_remove)
  1849. };
  1850. /* **************************** exit-time only **************************** */
  1851. static void __exit savage_done (void)
  1852. {
  1853. DBG("savage_done");
  1854. pci_unregister_driver (&savagefb_driver);
  1855. }
  1856. /* ************************* init in-kernel code ************************** */
  1857. static int __init savagefb_setup(char *options)
  1858. {
  1859. #ifndef MODULE
  1860. char *this_opt;
  1861. if (!options || !*options)
  1862. return 0;
  1863. while ((this_opt = strsep(&options, ",")) != NULL) {
  1864. mode_option = this_opt;
  1865. }
  1866. #endif /* !MODULE */
  1867. return 0;
  1868. }
  1869. static int __init savagefb_init(void)
  1870. {
  1871. char *option;
  1872. DBG("savagefb_init");
  1873. if (fb_get_options("savagefb", &option))
  1874. return -ENODEV;
  1875. savagefb_setup(option);
  1876. return pci_register_driver (&savagefb_driver);
  1877. }
  1878. module_init(savagefb_init);
  1879. module_exit(savage_done);