savagefb_driver.c 60 KB

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