savagefb_driver.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388
  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 int savagefb_blank(int blank, struct fb_info *info)
  1183. {
  1184. struct savagefb_par *par = info->par;
  1185. u8 sr8 = 0, srd = 0;
  1186. if (par->display_type == DISP_CRT) {
  1187. vga_out8(0x3c4, 0x08);
  1188. sr8 = vga_in8(0x3c5);
  1189. sr8 |= 0x06;
  1190. vga_out8(0x3c5, sr8);
  1191. vga_out8(0x3c4, 0x0d);
  1192. srd = vga_in8(0x3c5);
  1193. srd &= 0x03;
  1194. switch (blank) {
  1195. case FB_BLANK_UNBLANK:
  1196. case FB_BLANK_NORMAL:
  1197. break;
  1198. case FB_BLANK_VSYNC_SUSPEND:
  1199. srd |= 0x10;
  1200. break;
  1201. case FB_BLANK_HSYNC_SUSPEND:
  1202. srd |= 0x40;
  1203. break;
  1204. case FB_BLANK_POWERDOWN:
  1205. srd |= 0x50;
  1206. break;
  1207. }
  1208. vga_out8(0x3c4, 0x0d);
  1209. vga_out8(0x3c5, srd);
  1210. }
  1211. if (par->display_type == DISP_LCD ||
  1212. par->display_type == DISP_DFP) {
  1213. switch(blank) {
  1214. case FB_BLANK_UNBLANK:
  1215. case FB_BLANK_NORMAL:
  1216. vga_out8(0x3c4, 0x31); /* SR31 bit 4 - FP enable */
  1217. vga_out8(0x3c5, vga_in8(0x3c5) | 0x10);
  1218. break;
  1219. case FB_BLANK_VSYNC_SUSPEND:
  1220. case FB_BLANK_HSYNC_SUSPEND:
  1221. case FB_BLANK_POWERDOWN:
  1222. vga_out8(0x3c4, 0x31); /* SR31 bit 4 - FP enable */
  1223. vga_out8(0x3c5, vga_in8(0x3c5) & ~0x10);
  1224. break;
  1225. }
  1226. }
  1227. return (blank == FB_BLANK_NORMAL) ? 1 : 0;
  1228. }
  1229. static struct fb_ops savagefb_ops = {
  1230. .owner = THIS_MODULE,
  1231. .fb_check_var = savagefb_check_var,
  1232. .fb_set_par = savagefb_set_par,
  1233. .fb_setcolreg = savagefb_setcolreg,
  1234. .fb_pan_display = savagefb_pan_display,
  1235. .fb_blank = savagefb_blank,
  1236. #if defined(CONFIG_FB_SAVAGE_ACCEL)
  1237. .fb_fillrect = savagefb_fillrect,
  1238. .fb_copyarea = savagefb_copyarea,
  1239. .fb_imageblit = savagefb_imageblit,
  1240. .fb_sync = savagefb_sync,
  1241. #else
  1242. .fb_fillrect = cfb_fillrect,
  1243. .fb_copyarea = cfb_copyarea,
  1244. .fb_imageblit = cfb_imageblit,
  1245. #endif
  1246. .fb_cursor = soft_cursor,
  1247. };
  1248. /* --------------------------------------------------------------------- */
  1249. static struct fb_var_screeninfo __devinitdata savagefb_var800x600x8 = {
  1250. .accel_flags = FB_ACCELF_TEXT,
  1251. .xres = 800,
  1252. .yres = 600,
  1253. .xres_virtual = 800,
  1254. .yres_virtual = 600,
  1255. .bits_per_pixel = 8,
  1256. .pixclock = 25000,
  1257. .left_margin = 88,
  1258. .right_margin = 40,
  1259. .upper_margin = 23,
  1260. .lower_margin = 1,
  1261. .hsync_len = 128,
  1262. .vsync_len = 4,
  1263. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  1264. .vmode = FB_VMODE_NONINTERLACED
  1265. };
  1266. static void savage_enable_mmio (struct savagefb_par *par)
  1267. {
  1268. unsigned char val;
  1269. DBG ("savage_enable_mmio\n");
  1270. val = vga_in8 (0x3c3);
  1271. vga_out8 (0x3c3, val | 0x01);
  1272. val = vga_in8 (0x3cc);
  1273. vga_out8 (0x3c2, val | 0x01);
  1274. if (par->chip >= S3_SAVAGE4) {
  1275. vga_out8 (0x3d4, 0x40);
  1276. val = vga_in8 (0x3d5);
  1277. vga_out8 (0x3d5, val | 1);
  1278. }
  1279. }
  1280. static void savage_disable_mmio (struct savagefb_par *par)
  1281. {
  1282. unsigned char val;
  1283. DBG ("savage_disable_mmio\n");
  1284. if(par->chip >= S3_SAVAGE4 ) {
  1285. vga_out8 (0x3d4, 0x40);
  1286. val = vga_in8 (0x3d5);
  1287. vga_out8 (0x3d5, val | 1);
  1288. }
  1289. }
  1290. static int __devinit savage_map_mmio (struct fb_info *info)
  1291. {
  1292. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1293. DBG ("savage_map_mmio");
  1294. if (S3_SAVAGE3D_SERIES (par->chip))
  1295. par->mmio.pbase = pci_resource_start (par->pcidev, 0) +
  1296. SAVAGE_NEWMMIO_REGBASE_S3;
  1297. else
  1298. par->mmio.pbase = pci_resource_start (par->pcidev, 0) +
  1299. SAVAGE_NEWMMIO_REGBASE_S4;
  1300. par->mmio.len = SAVAGE_NEWMMIO_REGSIZE;
  1301. par->mmio.vbase = ioremap (par->mmio.pbase, par->mmio.len);
  1302. if (!par->mmio.vbase) {
  1303. printk ("savagefb: unable to map memory mapped IO\n");
  1304. return -ENOMEM;
  1305. } else
  1306. printk (KERN_INFO "savagefb: mapped io at %p\n",
  1307. par->mmio.vbase);
  1308. info->fix.mmio_start = par->mmio.pbase;
  1309. info->fix.mmio_len = par->mmio.len;
  1310. par->bci_base = (u32 __iomem *)(par->mmio.vbase + BCI_BUFFER_OFFSET);
  1311. par->bci_ptr = 0;
  1312. savage_enable_mmio (par);
  1313. return 0;
  1314. }
  1315. static void __devinit savage_unmap_mmio (struct fb_info *info)
  1316. {
  1317. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1318. DBG ("savage_unmap_mmio");
  1319. savage_disable_mmio(par);
  1320. if (par->mmio.vbase) {
  1321. iounmap(par->mmio.vbase);
  1322. par->mmio.vbase = NULL;
  1323. }
  1324. }
  1325. static int __devinit savage_map_video (struct fb_info *info,
  1326. int video_len)
  1327. {
  1328. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1329. int resource;
  1330. DBG("savage_map_video");
  1331. if (S3_SAVAGE3D_SERIES (par->chip))
  1332. resource = 0;
  1333. else
  1334. resource = 1;
  1335. par->video.pbase = pci_resource_start (par->pcidev, resource);
  1336. par->video.len = video_len;
  1337. par->video.vbase = ioremap (par->video.pbase, par->video.len);
  1338. if (!par->video.vbase) {
  1339. printk ("savagefb: unable to map screen memory\n");
  1340. return -ENOMEM;
  1341. } else
  1342. printk (KERN_INFO "savagefb: mapped framebuffer at %p, "
  1343. "pbase == %x\n", par->video.vbase, par->video.pbase);
  1344. info->fix.smem_start = par->video.pbase;
  1345. info->fix.smem_len = par->video.len - par->cob_size;
  1346. info->screen_base = par->video.vbase;
  1347. #ifdef CONFIG_MTRR
  1348. par->video.mtrr = mtrr_add (par->video.pbase, video_len,
  1349. MTRR_TYPE_WRCOMB, 1);
  1350. #endif
  1351. /* Clear framebuffer, it's all white in memory after boot */
  1352. memset_io (par->video.vbase, 0, par->video.len);
  1353. return 0;
  1354. }
  1355. static void __devinit savage_unmap_video (struct fb_info *info)
  1356. {
  1357. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1358. DBG("savage_unmap_video");
  1359. if (par->video.vbase) {
  1360. #ifdef CONFIG_MTRR
  1361. mtrr_del (par->video.mtrr, par->video.pbase, par->video.len);
  1362. #endif
  1363. iounmap (par->video.vbase);
  1364. par->video.vbase = NULL;
  1365. info->screen_base = NULL;
  1366. }
  1367. }
  1368. static int __devinit savage_init_hw (struct savagefb_par *par)
  1369. {
  1370. unsigned char config1, m, n, n1, n2, sr8, cr3f, cr66 = 0, tmp;
  1371. static unsigned char RamSavage3D[] = { 8, 4, 4, 2 };
  1372. static unsigned char RamSavage4[] = { 2, 4, 8, 12, 16, 32, 64, 32 };
  1373. static unsigned char RamSavageMX[] = { 2, 8, 4, 16, 8, 16, 4, 16 };
  1374. static unsigned char RamSavageNB[] = { 0, 2, 4, 8, 16, 32, 2, 2 };
  1375. int videoRam, videoRambytes, dvi;
  1376. DBG("savage_init_hw");
  1377. /* unprotect CRTC[0-7] */
  1378. vga_out8(0x3d4, 0x11);
  1379. tmp = vga_in8(0x3d5);
  1380. vga_out8(0x3d5, tmp & 0x7f);
  1381. /* unlock extended regs */
  1382. vga_out16(0x3d4, 0x4838);
  1383. vga_out16(0x3d4, 0xa039);
  1384. vga_out16(0x3c4, 0x0608);
  1385. vga_out8(0x3d4, 0x40);
  1386. tmp = vga_in8(0x3d5);
  1387. vga_out8(0x3d5, tmp & ~0x01);
  1388. /* unlock sys regs */
  1389. vga_out8(0x3d4, 0x38);
  1390. vga_out8(0x3d5, 0x48);
  1391. /* Unlock system registers. */
  1392. vga_out16(0x3d4, 0x4838);
  1393. /* Next go on to detect amount of installed ram */
  1394. vga_out8(0x3d4, 0x36); /* for register CR36 (CONFG_REG1), */
  1395. config1 = vga_in8(0x3d5); /* get amount of vram installed */
  1396. /* Compute the amount of video memory and offscreen memory. */
  1397. switch (par->chip) {
  1398. case S3_SAVAGE3D:
  1399. videoRam = RamSavage3D[ (config1 & 0xC0) >> 6 ] * 1024;
  1400. break;
  1401. case S3_SAVAGE4:
  1402. /*
  1403. * The Savage4 has one ugly special case to consider. On
  1404. * systems with 4 banks of 2Mx32 SDRAM, the BIOS says 4MB
  1405. * when it really means 8MB. Why do it the same when you
  1406. * can do it different...
  1407. */
  1408. vga_out8(0x3d4, 0x68); /* memory control 1 */
  1409. if( (vga_in8(0x3d5) & 0xC0) == (0x01 << 6) )
  1410. RamSavage4[1] = 8;
  1411. /*FALLTHROUGH*/
  1412. case S3_SAVAGE2000:
  1413. videoRam = RamSavage4[ (config1 & 0xE0) >> 5 ] * 1024;
  1414. break;
  1415. case S3_SAVAGE_MX:
  1416. case S3_SUPERSAVAGE:
  1417. videoRam = RamSavageMX[ (config1 & 0x0E) >> 1 ] * 1024;
  1418. break;
  1419. case S3_PROSAVAGE:
  1420. videoRam = RamSavageNB[ (config1 & 0xE0) >> 5 ] * 1024;
  1421. break;
  1422. default:
  1423. /* How did we get here? */
  1424. videoRam = 0;
  1425. break;
  1426. }
  1427. videoRambytes = videoRam * 1024;
  1428. printk (KERN_INFO "savagefb: probed videoram: %dk\n", videoRam);
  1429. /* reset graphics engine to avoid memory corruption */
  1430. vga_out8 (0x3d4, 0x66);
  1431. cr66 = vga_in8 (0x3d5);
  1432. vga_out8 (0x3d5, cr66 | 0x02);
  1433. udelay (10000);
  1434. vga_out8 (0x3d4, 0x66);
  1435. vga_out8 (0x3d5, cr66 & ~0x02); /* clear reset flag */
  1436. udelay (10000);
  1437. /*
  1438. * reset memory interface, 3D engine, AGP master, PCI master,
  1439. * master engine unit, motion compensation/LPB
  1440. */
  1441. vga_out8 (0x3d4, 0x3f);
  1442. cr3f = vga_in8 (0x3d5);
  1443. vga_out8 (0x3d5, cr3f | 0x08);
  1444. udelay (10000);
  1445. vga_out8 (0x3d4, 0x3f);
  1446. vga_out8 (0x3d5, cr3f & ~0x08); /* clear reset flags */
  1447. udelay (10000);
  1448. /* Savage ramdac speeds */
  1449. par->numClocks = 4;
  1450. par->clock[0] = 250000;
  1451. par->clock[1] = 250000;
  1452. par->clock[2] = 220000;
  1453. par->clock[3] = 220000;
  1454. /* detect current mclk */
  1455. vga_out8(0x3c4, 0x08);
  1456. sr8 = vga_in8(0x3c5);
  1457. vga_out8(0x3c5, 0x06);
  1458. vga_out8(0x3c4, 0x10);
  1459. n = vga_in8(0x3c5);
  1460. vga_out8(0x3c4, 0x11);
  1461. m = vga_in8(0x3c5);
  1462. vga_out8(0x3c4, 0x08);
  1463. vga_out8(0x3c5, sr8);
  1464. m &= 0x7f;
  1465. n1 = n & 0x1f;
  1466. n2 = (n >> 5) & 0x03;
  1467. par->MCLK = ((1431818 * (m+2)) / (n1+2) / (1 << n2) + 50) / 100;
  1468. printk (KERN_INFO "savagefb: Detected current MCLK value of %d kHz\n",
  1469. par->MCLK);
  1470. /* check for DVI/flat panel */
  1471. dvi = 0;
  1472. if (par->chip == S3_SAVAGE4) {
  1473. unsigned char sr30 = 0x00;
  1474. vga_out8(0x3c4, 0x30);
  1475. /* clear bit 1 */
  1476. vga_out8(0x3c5, vga_in8(0x3c5) & ~0x02);
  1477. sr30 = vga_in8(0x3c5);
  1478. if (sr30 & 0x02 /*0x04 */) {
  1479. dvi = 1;
  1480. printk("savagefb: Digital Flat Panel Detected\n");
  1481. }
  1482. }
  1483. if (S3_SAVAGE_MOBILE_SERIES(par->chip) ||
  1484. (S3_MOBILE_TWISTER_SERIES(par->chip) && !par->crtonly))
  1485. par->display_type = DISP_LCD;
  1486. else if (dvi || (par->chip == S3_SAVAGE4 && par->dvi))
  1487. par->display_type = DISP_DFP;
  1488. else
  1489. par->display_type = DISP_CRT;
  1490. /* Check LCD panel parrmation */
  1491. if (par->chip == S3_SAVAGE_MX) {
  1492. unsigned char cr6b = VGArCR( 0x6b );
  1493. int panelX = (VGArSEQ (0x61) +
  1494. ((VGArSEQ (0x66) & 0x02) << 7) + 1) * 8;
  1495. int panelY = (VGArSEQ (0x69) +
  1496. ((VGArSEQ (0x6e) & 0x70) << 4) + 1);
  1497. char * sTechnology = "Unknown";
  1498. /* OK, I admit it. I don't know how to limit the max dot clock
  1499. * for LCD panels of various sizes. I thought I copied the
  1500. * formula from the BIOS, but many users have parrmed me of
  1501. * my folly.
  1502. *
  1503. * Instead, I'll abandon any attempt to automatically limit the
  1504. * clock, and add an LCDClock option to XF86Config. Some day,
  1505. * I should come back to this.
  1506. */
  1507. enum ACTIVE_DISPLAYS { /* These are the bits in CR6B */
  1508. ActiveCRT = 0x01,
  1509. ActiveLCD = 0x02,
  1510. ActiveTV = 0x04,
  1511. ActiveCRT2 = 0x20,
  1512. ActiveDUO = 0x80
  1513. };
  1514. if ((VGArSEQ (0x39) & 0x03) == 0) {
  1515. sTechnology = "TFT";
  1516. } else if ((VGArSEQ (0x30) & 0x01) == 0) {
  1517. sTechnology = "DSTN";
  1518. } else {
  1519. sTechnology = "STN";
  1520. }
  1521. printk (KERN_INFO "savagefb: %dx%d %s LCD panel detected %s\n",
  1522. panelX, panelY, sTechnology,
  1523. cr6b & ActiveLCD ? "and active" : "but not active");
  1524. if( cr6b & ActiveLCD ) {
  1525. /*
  1526. * If the LCD is active and panel expansion is enabled,
  1527. * we probably want to kill the HW cursor.
  1528. */
  1529. printk (KERN_INFO "savagefb: Limiting video mode to "
  1530. "%dx%d\n", panelX, panelY );
  1531. par->SavagePanelWidth = panelX;
  1532. par->SavagePanelHeight = panelY;
  1533. } else
  1534. par->display_type = DISP_CRT;
  1535. }
  1536. savage_get_default_par (par);
  1537. if( S3_SAVAGE4_SERIES(par->chip) ) {
  1538. /*
  1539. * The Savage4 and ProSavage have COB coherency bugs which
  1540. * render the buffer useless. We disable it.
  1541. */
  1542. par->cob_index = 2;
  1543. par->cob_size = 0x8000 << par->cob_index;
  1544. par->cob_offset = videoRambytes;
  1545. } else {
  1546. /* We use 128kB for the COB on all chips. */
  1547. par->cob_index = 7;
  1548. par->cob_size = 0x400 << par->cob_index;
  1549. par->cob_offset = videoRambytes - par->cob_size;
  1550. }
  1551. return videoRambytes;
  1552. }
  1553. static int __devinit savage_init_fb_info (struct fb_info *info,
  1554. struct pci_dev *dev,
  1555. const struct pci_device_id *id)
  1556. {
  1557. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1558. int err = 0;
  1559. par->pcidev = dev;
  1560. info->fix.type = FB_TYPE_PACKED_PIXELS;
  1561. info->fix.type_aux = 0;
  1562. info->fix.xpanstep = 2;
  1563. info->fix.ypanstep = 1;
  1564. info->fix.ywrapstep = 0;
  1565. info->fix.accel = id->driver_data;
  1566. switch (info->fix.accel) {
  1567. case FB_ACCEL_SUPERSAVAGE:
  1568. par->chip = S3_SUPERSAVAGE;
  1569. snprintf (info->fix.id, 16, "SuperSavage");
  1570. break;
  1571. case FB_ACCEL_SAVAGE4:
  1572. par->chip = S3_SAVAGE4;
  1573. snprintf (info->fix.id, 16, "Savage4");
  1574. break;
  1575. case FB_ACCEL_SAVAGE3D:
  1576. par->chip = S3_SAVAGE3D;
  1577. snprintf (info->fix.id, 16, "Savage3D");
  1578. break;
  1579. case FB_ACCEL_SAVAGE3D_MV:
  1580. par->chip = S3_SAVAGE3D;
  1581. snprintf (info->fix.id, 16, "Savage3D-MV");
  1582. break;
  1583. case FB_ACCEL_SAVAGE2000:
  1584. par->chip = S3_SAVAGE2000;
  1585. snprintf (info->fix.id, 16, "Savage2000");
  1586. break;
  1587. case FB_ACCEL_SAVAGE_MX_MV:
  1588. par->chip = S3_SAVAGE_MX;
  1589. snprintf (info->fix.id, 16, "Savage/MX-MV");
  1590. break;
  1591. case FB_ACCEL_SAVAGE_MX:
  1592. par->chip = S3_SAVAGE_MX;
  1593. snprintf (info->fix.id, 16, "Savage/MX");
  1594. break;
  1595. case FB_ACCEL_SAVAGE_IX_MV:
  1596. par->chip = S3_SAVAGE_MX;
  1597. snprintf (info->fix.id, 16, "Savage/IX-MV");
  1598. break;
  1599. case FB_ACCEL_SAVAGE_IX:
  1600. par->chip = S3_SAVAGE_MX;
  1601. snprintf (info->fix.id, 16, "Savage/IX");
  1602. break;
  1603. case FB_ACCEL_PROSAVAGE_PM:
  1604. par->chip = S3_PROSAVAGE;
  1605. snprintf (info->fix.id, 16, "ProSavagePM");
  1606. break;
  1607. case FB_ACCEL_PROSAVAGE_KM:
  1608. par->chip = S3_PROSAVAGE;
  1609. snprintf (info->fix.id, 16, "ProSavageKM");
  1610. break;
  1611. case FB_ACCEL_S3TWISTER_P:
  1612. par->chip = S3_TWISTER;
  1613. snprintf (info->fix.id, 16, "TwisterP");
  1614. break;
  1615. case FB_ACCEL_S3TWISTER_K:
  1616. par->chip = S3_TWISTER;
  1617. snprintf (info->fix.id, 16, "TwisterK");
  1618. break;
  1619. case FB_ACCEL_PROSAVAGE_DDR:
  1620. par->chip = S3_PROSAVAGEDDR;
  1621. snprintf (info->fix.id, 16, "ProSavageDDR");
  1622. break;
  1623. case FB_ACCEL_PROSAVAGE_DDRK:
  1624. par->chip = S3_PROSAVAGE;
  1625. snprintf (info->fix.id, 16, "ProSavage8");
  1626. break;
  1627. }
  1628. if (S3_SAVAGE3D_SERIES(par->chip)) {
  1629. par->SavageWaitIdle = savage3D_waitidle;
  1630. par->SavageWaitFifo = savage3D_waitfifo;
  1631. } else if (S3_SAVAGE4_SERIES(par->chip) ||
  1632. S3_SUPERSAVAGE == par->chip) {
  1633. par->SavageWaitIdle = savage4_waitidle;
  1634. par->SavageWaitFifo = savage4_waitfifo;
  1635. } else {
  1636. par->SavageWaitIdle = savage2000_waitidle;
  1637. par->SavageWaitFifo = savage2000_waitfifo;
  1638. }
  1639. info->var.nonstd = 0;
  1640. info->var.activate = FB_ACTIVATE_NOW;
  1641. info->var.width = -1;
  1642. info->var.height = -1;
  1643. info->var.accel_flags = 0;
  1644. info->fbops = &savagefb_ops;
  1645. info->flags = FBINFO_DEFAULT |
  1646. FBINFO_HWACCEL_YPAN |
  1647. FBINFO_HWACCEL_XPAN;
  1648. info->pseudo_palette = par->pseudo_palette;
  1649. #if defined(CONFIG_FB_SAVAGE_ACCEL)
  1650. /* FIFO size + padding for commands */
  1651. info->pixmap.addr = kmalloc(8*1024, GFP_KERNEL);
  1652. err = -ENOMEM;
  1653. if (info->pixmap.addr) {
  1654. memset(info->pixmap.addr, 0, 8*1024);
  1655. info->pixmap.size = 8*1024;
  1656. info->pixmap.scan_align = 4;
  1657. info->pixmap.buf_align = 4;
  1658. info->pixmap.access_align = 32;
  1659. err = fb_alloc_cmap (&info->cmap, NR_PALETTE, 0);
  1660. if (!err)
  1661. info->flags |= FBINFO_HWACCEL_COPYAREA |
  1662. FBINFO_HWACCEL_FILLRECT |
  1663. FBINFO_HWACCEL_IMAGEBLIT;
  1664. }
  1665. #endif
  1666. return err;
  1667. }
  1668. /* --------------------------------------------------------------------- */
  1669. static int __devinit savagefb_probe (struct pci_dev* dev,
  1670. const struct pci_device_id* id)
  1671. {
  1672. struct fb_info *info;
  1673. struct savagefb_par *par;
  1674. u_int h_sync, v_sync;
  1675. int err, lpitch;
  1676. int video_len;
  1677. DBG("savagefb_probe");
  1678. SavagePrintRegs();
  1679. info = framebuffer_alloc(sizeof(struct savagefb_par), &dev->dev);
  1680. if (!info)
  1681. return -ENOMEM;
  1682. par = info->par;
  1683. err = pci_enable_device(dev);
  1684. if (err)
  1685. goto failed_enable;
  1686. if ((err = pci_request_regions(dev, "savagefb"))) {
  1687. printk(KERN_ERR "cannot request PCI regions\n");
  1688. goto failed_enable;
  1689. }
  1690. err = -ENOMEM;
  1691. if ((err = savage_init_fb_info(info, dev, id)))
  1692. goto failed_init;
  1693. err = savage_map_mmio(info);
  1694. if (err)
  1695. goto failed_mmio;
  1696. video_len = savage_init_hw(par);
  1697. /* FIXME: cant be negative */
  1698. if (video_len < 0) {
  1699. err = video_len;
  1700. goto failed_mmio;
  1701. }
  1702. err = savage_map_video(info, video_len);
  1703. if (err)
  1704. goto failed_video;
  1705. INIT_LIST_HEAD(&info->modelist);
  1706. #if defined(CONFIG_FB_SAVAGE_I2C)
  1707. savagefb_create_i2c_busses(info);
  1708. savagefb_probe_i2c_connector(info, &par->edid);
  1709. kfree(par->edid);
  1710. fb_edid_to_monspecs(par->edid, &info->monspecs);
  1711. fb_videomode_to_modelist(info->monspecs.modedb,
  1712. info->monspecs.modedb_len,
  1713. &info->modelist);
  1714. #endif
  1715. info->var = savagefb_var800x600x8;
  1716. if (mode_option) {
  1717. fb_find_mode(&info->var, info, mode_option,
  1718. info->monspecs.modedb, info->monspecs.modedb_len,
  1719. NULL, 8);
  1720. } else if (info->monspecs.modedb != NULL) {
  1721. struct fb_monspecs *specs = &info->monspecs;
  1722. struct fb_videomode modedb;
  1723. if (info->monspecs.misc & FB_MISC_1ST_DETAIL) {
  1724. int i;
  1725. for (i = 0; i < specs->modedb_len; i++) {
  1726. if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
  1727. modedb = specs->modedb[i];
  1728. break;
  1729. }
  1730. }
  1731. } else {
  1732. /* otherwise, get first mode in database */
  1733. modedb = specs->modedb[0];
  1734. }
  1735. savage_update_var(&info->var, &modedb);
  1736. }
  1737. /* maximize virtual vertical length */
  1738. lpitch = info->var.xres_virtual*((info->var.bits_per_pixel + 7) >> 3);
  1739. info->var.yres_virtual = info->fix.smem_len/lpitch;
  1740. if (info->var.yres_virtual < info->var.yres)
  1741. goto failed;
  1742. #if defined(CONFIG_FB_SAVAGE_ACCEL)
  1743. /*
  1744. * The clipping coordinates are masked with 0xFFF, so limit our
  1745. * virtual resolutions to these sizes.
  1746. */
  1747. if (info->var.yres_virtual > 0x1000)
  1748. info->var.yres_virtual = 0x1000;
  1749. if (info->var.xres_virtual > 0x1000)
  1750. info->var.xres_virtual = 0x1000;
  1751. #endif
  1752. savagefb_check_var(&info->var, info);
  1753. savagefb_set_fix(info);
  1754. /*
  1755. * Calculate the hsync and vsync frequencies. Note that
  1756. * we split the 1e12 constant up so that we can preserve
  1757. * the precision and fit the results into 32-bit registers.
  1758. * (1953125000 * 512 = 1e12)
  1759. */
  1760. h_sync = 1953125000 / info->var.pixclock;
  1761. h_sync = h_sync * 512 / (info->var.xres + info->var.left_margin +
  1762. info->var.right_margin +
  1763. info->var.hsync_len);
  1764. v_sync = h_sync / (info->var.yres + info->var.upper_margin +
  1765. info->var.lower_margin + info->var.vsync_len);
  1766. printk(KERN_INFO "savagefb v" SAVAGEFB_VERSION ": "
  1767. "%dkB VRAM, using %dx%d, %d.%03dkHz, %dHz\n",
  1768. info->fix.smem_len >> 10,
  1769. info->var.xres, info->var.yres,
  1770. h_sync / 1000, h_sync % 1000, v_sync);
  1771. fb_destroy_modedb(info->monspecs.modedb);
  1772. info->monspecs.modedb = NULL;
  1773. err = register_framebuffer (info);
  1774. if (err < 0)
  1775. goto failed;
  1776. printk (KERN_INFO "fb: S3 %s frame buffer device\n",
  1777. info->fix.id);
  1778. /*
  1779. * Our driver data
  1780. */
  1781. pci_set_drvdata(dev, info);
  1782. return 0;
  1783. failed:
  1784. #ifdef CONFIG_FB_SAVAGE_I2C
  1785. savagefb_delete_i2c_busses(info);
  1786. #endif
  1787. fb_alloc_cmap (&info->cmap, 0, 0);
  1788. savage_unmap_video(info);
  1789. failed_video:
  1790. savage_unmap_mmio (info);
  1791. failed_mmio:
  1792. kfree(info->pixmap.addr);
  1793. failed_init:
  1794. pci_release_regions(dev);
  1795. failed_enable:
  1796. framebuffer_release(info);
  1797. return err;
  1798. }
  1799. static void __devexit savagefb_remove (struct pci_dev *dev)
  1800. {
  1801. struct fb_info *info =
  1802. (struct fb_info *)pci_get_drvdata(dev);
  1803. DBG("savagefb_remove");
  1804. if (info) {
  1805. /*
  1806. * If unregister_framebuffer fails, then
  1807. * we will be leaving hooks that could cause
  1808. * oopsen laying around.
  1809. */
  1810. if (unregister_framebuffer (info))
  1811. printk (KERN_WARNING "savagefb: danger danger! "
  1812. "Oopsen imminent!\n");
  1813. #ifdef CONFIG_FB_SAVAGE_I2C
  1814. savagefb_delete_i2c_busses(info);
  1815. #endif
  1816. fb_alloc_cmap (&info->cmap, 0, 0);
  1817. savage_unmap_video (info);
  1818. savage_unmap_mmio (info);
  1819. kfree(info->pixmap.addr);
  1820. pci_release_regions(dev);
  1821. framebuffer_release(info);
  1822. /*
  1823. * Ensure that the driver data is no longer
  1824. * valid.
  1825. */
  1826. pci_set_drvdata(dev, NULL);
  1827. }
  1828. }
  1829. static int savagefb_suspend (struct pci_dev* dev, pm_message_t state)
  1830. {
  1831. struct fb_info *info =
  1832. (struct fb_info *)pci_get_drvdata(dev);
  1833. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1834. DBG("savagefb_suspend");
  1835. par->pm_state = state.event;
  1836. /*
  1837. * For PM_EVENT_FREEZE, do not power down so the console
  1838. * can remain active.
  1839. */
  1840. if (state.event == PM_EVENT_FREEZE) {
  1841. dev->dev.power.power_state = state;
  1842. return 0;
  1843. }
  1844. acquire_console_sem();
  1845. fb_set_suspend(info, 1);
  1846. if (info->fbops->fb_sync)
  1847. info->fbops->fb_sync(info);
  1848. savagefb_blank(FB_BLANK_POWERDOWN, info);
  1849. savage_disable_mmio(par);
  1850. pci_save_state(dev);
  1851. pci_disable_device(dev);
  1852. pci_set_power_state(dev, pci_choose_state(dev, state));
  1853. release_console_sem();
  1854. return 0;
  1855. }
  1856. static int savagefb_resume (struct pci_dev* dev)
  1857. {
  1858. struct fb_info *info =
  1859. (struct fb_info *)pci_get_drvdata(dev);
  1860. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1861. int cur_state = par->pm_state;
  1862. DBG("savage_resume");
  1863. par->pm_state = PM_EVENT_ON;
  1864. /*
  1865. * The adapter was not powered down coming back from a
  1866. * PM_EVENT_FREEZE.
  1867. */
  1868. if (cur_state == PM_EVENT_FREEZE) {
  1869. pci_set_power_state(dev, PCI_D0);
  1870. return 0;
  1871. }
  1872. acquire_console_sem();
  1873. pci_set_power_state(dev, PCI_D0);
  1874. pci_restore_state(dev);
  1875. if(pci_enable_device(dev))
  1876. DBG("err");
  1877. pci_set_master(dev);
  1878. savage_enable_mmio(par);
  1879. savage_init_hw(par);
  1880. savagefb_set_par (info);
  1881. savagefb_blank(FB_BLANK_UNBLANK, info);
  1882. fb_set_suspend (info, 0);
  1883. release_console_sem();
  1884. return 0;
  1885. }
  1886. static struct pci_device_id savagefb_devices[] __devinitdata = {
  1887. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX128,
  1888. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1889. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX64,
  1890. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1891. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX64C,
  1892. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1893. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX128SDR,
  1894. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1895. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX128DDR,
  1896. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1897. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX64SDR,
  1898. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1899. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX64DDR,
  1900. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1901. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IXCSDR,
  1902. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1903. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IXCDDR,
  1904. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1905. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE4,
  1906. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE4},
  1907. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE3D,
  1908. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE3D},
  1909. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE3D_MV,
  1910. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE3D_MV},
  1911. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE2000,
  1912. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE2000},
  1913. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_MX_MV,
  1914. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_MX_MV},
  1915. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_MX,
  1916. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_MX},
  1917. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_IX_MV,
  1918. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_IX_MV},
  1919. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_IX,
  1920. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_IX},
  1921. {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_PM,
  1922. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_PM},
  1923. {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_KM,
  1924. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_KM},
  1925. {PCI_VENDOR_ID_S3, PCI_CHIP_S3TWISTER_P,
  1926. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_S3TWISTER_P},
  1927. {PCI_VENDOR_ID_S3, PCI_CHIP_S3TWISTER_K,
  1928. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_S3TWISTER_K},
  1929. {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_DDR,
  1930. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_DDR},
  1931. {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_DDRK,
  1932. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_DDRK},
  1933. {0, 0, 0, 0, 0, 0, 0}
  1934. };
  1935. MODULE_DEVICE_TABLE(pci, savagefb_devices);
  1936. static struct pci_driver savagefb_driver = {
  1937. .name = "savagefb",
  1938. .id_table = savagefb_devices,
  1939. .probe = savagefb_probe,
  1940. .suspend = savagefb_suspend,
  1941. .resume = savagefb_resume,
  1942. .remove = __devexit_p(savagefb_remove)
  1943. };
  1944. /* **************************** exit-time only **************************** */
  1945. static void __exit savage_done (void)
  1946. {
  1947. DBG("savage_done");
  1948. pci_unregister_driver (&savagefb_driver);
  1949. }
  1950. /* ************************* init in-kernel code ************************** */
  1951. static int __init savagefb_setup(char *options)
  1952. {
  1953. #ifndef MODULE
  1954. char *this_opt;
  1955. if (!options || !*options)
  1956. return 0;
  1957. while ((this_opt = strsep(&options, ",")) != NULL) {
  1958. mode_option = this_opt;
  1959. }
  1960. #endif /* !MODULE */
  1961. return 0;
  1962. }
  1963. static int __init savagefb_init(void)
  1964. {
  1965. char *option;
  1966. DBG("savagefb_init");
  1967. if (fb_get_options("savagefb", &option))
  1968. return -ENODEV;
  1969. savagefb_setup(option);
  1970. return pci_register_driver (&savagefb_driver);
  1971. }
  1972. module_init(savagefb_init);
  1973. module_exit(savage_done);
  1974. module_param(mode_option, charp, 0);
  1975. MODULE_PARM_DESC(mode_option, "Specify initial video mode");