savagefb_driver.c 59 KB

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