savagefb_driver.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278
  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. acquire_console_sem();
  1765. fb_set_suspend(info, pci_choose_state(dev, state));
  1766. savage_disable_mmio(par);
  1767. release_console_sem();
  1768. pci_disable_device(dev);
  1769. pci_set_power_state(dev, pci_choose_state(dev, state));
  1770. return 0;
  1771. }
  1772. static int savagefb_resume (struct pci_dev* dev)
  1773. {
  1774. struct fb_info *info =
  1775. (struct fb_info *)pci_get_drvdata(dev);
  1776. struct savagefb_par *par = (struct savagefb_par *)info->par;
  1777. DBG("savage_resume");
  1778. pci_set_power_state(dev, 0);
  1779. pci_restore_state(dev);
  1780. if(pci_enable_device(dev))
  1781. DBG("err");
  1782. SavagePrintRegs();
  1783. acquire_console_sem();
  1784. savage_enable_mmio(par);
  1785. savage_init_hw(par);
  1786. savagefb_set_par (info);
  1787. fb_set_suspend (info, 0);
  1788. release_console_sem();
  1789. return 0;
  1790. }
  1791. static struct pci_device_id savagefb_devices[] __devinitdata = {
  1792. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX128,
  1793. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1794. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX64,
  1795. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1796. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX64C,
  1797. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1798. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX128SDR,
  1799. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1800. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX128DDR,
  1801. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1802. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX64SDR,
  1803. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1804. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX64DDR,
  1805. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1806. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IXCSDR,
  1807. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1808. {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IXCDDR,
  1809. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE},
  1810. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE4,
  1811. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE4},
  1812. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE3D,
  1813. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE3D},
  1814. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE3D_MV,
  1815. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE3D_MV},
  1816. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE2000,
  1817. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE2000},
  1818. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_MX_MV,
  1819. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_MX_MV},
  1820. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_MX,
  1821. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_MX},
  1822. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_IX_MV,
  1823. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_IX_MV},
  1824. {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_IX,
  1825. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_IX},
  1826. {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_PM,
  1827. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_PM},
  1828. {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_KM,
  1829. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_KM},
  1830. {PCI_VENDOR_ID_S3, PCI_CHIP_S3TWISTER_P,
  1831. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_S3TWISTER_P},
  1832. {PCI_VENDOR_ID_S3, PCI_CHIP_S3TWISTER_K,
  1833. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_S3TWISTER_K},
  1834. {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_DDR,
  1835. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_DDR},
  1836. {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_DDRK,
  1837. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_DDRK},
  1838. {0, 0, 0, 0, 0, 0, 0}
  1839. };
  1840. MODULE_DEVICE_TABLE(pci, savagefb_devices);
  1841. static struct pci_driver savagefb_driver = {
  1842. .name = "savagefb",
  1843. .id_table = savagefb_devices,
  1844. .probe = savagefb_probe,
  1845. .suspend = savagefb_suspend,
  1846. .resume = savagefb_resume,
  1847. .remove = __devexit_p(savagefb_remove)
  1848. };
  1849. /* **************************** exit-time only **************************** */
  1850. static void __exit savage_done (void)
  1851. {
  1852. DBG("savage_done");
  1853. pci_unregister_driver (&savagefb_driver);
  1854. }
  1855. /* ************************* init in-kernel code ************************** */
  1856. static int __init savagefb_setup(char *options)
  1857. {
  1858. #ifndef MODULE
  1859. char *this_opt;
  1860. if (!options || !*options)
  1861. return 0;
  1862. while ((this_opt = strsep(&options, ",")) != NULL) {
  1863. mode_option = this_opt;
  1864. }
  1865. #endif /* !MODULE */
  1866. return 0;
  1867. }
  1868. static int __init savagefb_init(void)
  1869. {
  1870. char *option;
  1871. DBG("savagefb_init");
  1872. if (fb_get_options("savagefb", &option))
  1873. return -ENODEV;
  1874. savagefb_setup(option);
  1875. return pci_register_driver (&savagefb_driver);
  1876. }
  1877. module_init(savagefb_init);
  1878. module_exit(savage_done);