savagefb_driver.c 59 KB

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