tdfxfb.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  1. /*
  2. *
  3. * tdfxfb.c
  4. *
  5. * Author: Hannu Mallat <hmallat@cc.hut.fi>
  6. *
  7. * Copyright © 1999 Hannu Mallat
  8. * All rights reserved
  9. *
  10. * Created : Thu Sep 23 18:17:43 1999, hmallat
  11. * Last modified: Tue Nov 2 21:19:47 1999, hmallat
  12. *
  13. * Lots of the information here comes from the Daryll Strauss' Banshee
  14. * patches to the XF86 server, and the rest comes from the 3dfx
  15. * Banshee specification. I'm very much indebted to Daryll for his
  16. * work on the X server.
  17. *
  18. * Voodoo3 support was contributed Harold Oga. Lots of additions
  19. * (proper acceleration, 24 bpp, hardware cursor) and bug fixes by Attila
  20. * Kesmarki. Thanks guys!
  21. *
  22. * Voodoo1 and Voodoo2 support aren't relevant to this driver as they
  23. * behave very differently from the Voodoo3/4/5. For anyone wanting to
  24. * use frame buffer on the Voodoo1/2, see the sstfb driver (which is
  25. * located at http://www.sourceforge.net/projects/sstfb).
  26. *
  27. * While I _am_ grateful to 3Dfx for releasing the specs for Banshee,
  28. * I do wish the next version is a bit more complete. Without the XF86
  29. * patches I couldn't have gotten even this far... for instance, the
  30. * extensions to the VGA register set go completely unmentioned in the
  31. * spec! Also, lots of references are made to the 'SST core', but no
  32. * spec is publicly available, AFAIK.
  33. *
  34. * The structure of this driver comes pretty much from the Permedia
  35. * driver by Ilario Nardinocchi, which in turn is based on skeletonfb.
  36. *
  37. * TODO:
  38. * - support for 16/32 bpp needs fixing (funky bootup penguin)
  39. * - multihead support (basically need to support an array of fb_infos)
  40. * - support other architectures (PPC, Alpha); does the fact that the VGA
  41. * core can be accessed only thru I/O (not memory mapped) complicate
  42. * things?
  43. *
  44. * Version history:
  45. *
  46. * 0.1.4 (released 2002-05-28) ported over to new fbdev api by James Simmons
  47. *
  48. * 0.1.3 (released 1999-11-02) added Attila's panning support, code
  49. * reorg, hwcursor address page size alignment
  50. * (for mmaping both frame buffer and regs),
  51. * and my changes to get rid of hardcoded
  52. * VGA i/o register locations (uses PCI
  53. * configuration info now)
  54. * 0.1.2 (released 1999-10-19) added Attila Kesmarki's bug fixes and
  55. * improvements
  56. * 0.1.1 (released 1999-10-07) added Voodoo3 support by Harold Oga.
  57. * 0.1.0 (released 1999-10-06) initial version
  58. *
  59. */
  60. #include <linux/config.h>
  61. #include <linux/module.h>
  62. #include <linux/kernel.h>
  63. #include <linux/errno.h>
  64. #include <linux/string.h>
  65. #include <linux/mm.h>
  66. #include <linux/tty.h>
  67. #include <linux/slab.h>
  68. #include <linux/delay.h>
  69. #include <linux/interrupt.h>
  70. #include <linux/fb.h>
  71. #include <linux/init.h>
  72. #include <linux/pci.h>
  73. #include <linux/nvram.h>
  74. #include <asm/io.h>
  75. #include <linux/timer.h>
  76. #include <linux/spinlock.h>
  77. #include <video/tdfx.h>
  78. #undef TDFXFB_DEBUG
  79. #ifdef TDFXFB_DEBUG
  80. #define DPRINTK(a,b...) printk(KERN_DEBUG "fb: %s: " a, __FUNCTION__ , ## b)
  81. #else
  82. #define DPRINTK(a,b...)
  83. #endif
  84. #define BANSHEE_MAX_PIXCLOCK 270000
  85. #define VOODOO3_MAX_PIXCLOCK 300000
  86. #define VOODOO5_MAX_PIXCLOCK 350000
  87. static struct fb_fix_screeninfo tdfx_fix __devinitdata = {
  88. .id = "3Dfx",
  89. .type = FB_TYPE_PACKED_PIXELS,
  90. .visual = FB_VISUAL_PSEUDOCOLOR,
  91. .ypanstep = 1,
  92. .ywrapstep = 1,
  93. .accel = FB_ACCEL_3DFX_BANSHEE
  94. };
  95. static struct fb_var_screeninfo tdfx_var __devinitdata = {
  96. /* "640x480, 8 bpp @ 60 Hz */
  97. .xres = 640,
  98. .yres = 480,
  99. .xres_virtual = 640,
  100. .yres_virtual = 1024,
  101. .bits_per_pixel =8,
  102. .red = {0, 8, 0},
  103. .blue = {0, 8, 0},
  104. .green = {0, 8, 0},
  105. .activate = FB_ACTIVATE_NOW,
  106. .height = -1,
  107. .width = -1,
  108. .accel_flags = FB_ACCELF_TEXT,
  109. .pixclock = 39722,
  110. .left_margin = 40,
  111. .right_margin = 24,
  112. .upper_margin = 32,
  113. .lower_margin = 11,
  114. .hsync_len = 96,
  115. .vsync_len = 2,
  116. .vmode = FB_VMODE_NONINTERLACED
  117. };
  118. /*
  119. * PCI driver prototypes
  120. */
  121. static int __devinit tdfxfb_probe(struct pci_dev *pdev,
  122. const struct pci_device_id *id);
  123. static void __devexit tdfxfb_remove(struct pci_dev *pdev);
  124. static struct pci_device_id tdfxfb_id_table[] = {
  125. { PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_BANSHEE,
  126. PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
  127. 0xff0000, 0 },
  128. { PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO3,
  129. PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
  130. 0xff0000, 0 },
  131. { PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO5,
  132. PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
  133. 0xff0000, 0 },
  134. { 0, }
  135. };
  136. static struct pci_driver tdfxfb_driver = {
  137. .name = "tdfxfb",
  138. .id_table = tdfxfb_id_table,
  139. .probe = tdfxfb_probe,
  140. .remove = __devexit_p(tdfxfb_remove),
  141. };
  142. MODULE_DEVICE_TABLE(pci, tdfxfb_id_table);
  143. /*
  144. * Frame buffer device API
  145. */
  146. static int tdfxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fb);
  147. static int tdfxfb_set_par(struct fb_info *info);
  148. static int tdfxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  149. u_int transp, struct fb_info *info);
  150. static int tdfxfb_blank(int blank, struct fb_info *info);
  151. static int tdfxfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info);
  152. static int banshee_wait_idle(struct fb_info *info);
  153. #ifdef CONFIG_FB_3DFX_ACCEL
  154. static void tdfxfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
  155. static void tdfxfb_copyarea(struct fb_info *info, const struct fb_copyarea *area);
  156. static void tdfxfb_imageblit(struct fb_info *info, const struct fb_image *image);
  157. #endif /* CONFIG_FB_3DFX_ACCEL */
  158. static struct fb_ops tdfxfb_ops = {
  159. .owner = THIS_MODULE,
  160. .fb_check_var = tdfxfb_check_var,
  161. .fb_set_par = tdfxfb_set_par,
  162. .fb_setcolreg = tdfxfb_setcolreg,
  163. .fb_blank = tdfxfb_blank,
  164. .fb_pan_display = tdfxfb_pan_display,
  165. .fb_sync = banshee_wait_idle,
  166. #ifdef CONFIG_FB_3DFX_ACCEL
  167. .fb_fillrect = tdfxfb_fillrect,
  168. .fb_copyarea = tdfxfb_copyarea,
  169. .fb_imageblit = tdfxfb_imageblit,
  170. #else
  171. .fb_fillrect = cfb_fillrect,
  172. .fb_copyarea = cfb_copyarea,
  173. .fb_imageblit = cfb_imageblit,
  174. #endif
  175. .fb_cursor = soft_cursor,
  176. };
  177. /*
  178. * do_xxx: Hardware-specific functions
  179. */
  180. static u32 do_calc_pll(int freq, int *freq_out);
  181. static void do_write_regs(struct fb_info *info, struct banshee_reg *reg);
  182. static unsigned long do_lfb_size(struct tdfx_par *par, unsigned short);
  183. /*
  184. * Driver data
  185. */
  186. static int nopan = 0;
  187. static int nowrap = 1; // not implemented (yet)
  188. static char *mode_option __devinitdata = NULL;
  189. /* -------------------------------------------------------------------------
  190. * Hardware-specific funcions
  191. * ------------------------------------------------------------------------- */
  192. #ifdef VGA_REG_IO
  193. static inline u8 vga_inb(struct tdfx_par *par, u32 reg) { return inb(reg); }
  194. static inline void vga_outb(struct tdfx_par *par, u32 reg, u8 val) { outb(val, reg); }
  195. #else
  196. static inline u8 vga_inb(struct tdfx_par *par, u32 reg) {
  197. return inb(par->iobase + reg - 0x300);
  198. }
  199. static inline void vga_outb(struct tdfx_par *par, u32 reg, u8 val) {
  200. outb(val, par->iobase + reg - 0x300);
  201. }
  202. #endif
  203. static inline void gra_outb(struct tdfx_par *par, u32 idx, u8 val) {
  204. vga_outb(par, GRA_I, idx); vga_outb(par, GRA_D, val);
  205. }
  206. static inline void seq_outb(struct tdfx_par *par, u32 idx, u8 val) {
  207. vga_outb(par, SEQ_I, idx); vga_outb(par, SEQ_D, val);
  208. }
  209. static inline u8 seq_inb(struct tdfx_par *par, u32 idx) {
  210. vga_outb(par, SEQ_I, idx); return vga_inb(par, SEQ_D);
  211. }
  212. static inline void crt_outb(struct tdfx_par *par, u32 idx, u8 val) {
  213. vga_outb(par, CRT_I, idx); vga_outb(par, CRT_D, val);
  214. }
  215. static inline u8 crt_inb(struct tdfx_par *par, u32 idx) {
  216. vga_outb(par, CRT_I, idx); return vga_inb(par, CRT_D);
  217. }
  218. static inline void att_outb(struct tdfx_par *par, u32 idx, u8 val)
  219. {
  220. unsigned char tmp;
  221. tmp = vga_inb(par, IS1_R);
  222. vga_outb(par, ATT_IW, idx);
  223. vga_outb(par, ATT_IW, val);
  224. }
  225. static inline void vga_disable_video(struct tdfx_par *par)
  226. {
  227. unsigned char s;
  228. s = seq_inb(par, 0x01) | 0x20;
  229. seq_outb(par, 0x00, 0x01);
  230. seq_outb(par, 0x01, s);
  231. seq_outb(par, 0x00, 0x03);
  232. }
  233. static inline void vga_enable_video(struct tdfx_par *par)
  234. {
  235. unsigned char s;
  236. s = seq_inb(par, 0x01) & 0xdf;
  237. seq_outb(par, 0x00, 0x01);
  238. seq_outb(par, 0x01, s);
  239. seq_outb(par, 0x00, 0x03);
  240. }
  241. static inline void vga_enable_palette(struct tdfx_par *par)
  242. {
  243. vga_inb(par, IS1_R);
  244. vga_outb(par, ATT_IW, 0x20);
  245. }
  246. static inline u32 tdfx_inl(struct tdfx_par *par, unsigned int reg)
  247. {
  248. return readl(par->regbase_virt + reg);
  249. }
  250. static inline void tdfx_outl(struct tdfx_par *par, unsigned int reg, u32 val)
  251. {
  252. writel(val, par->regbase_virt + reg);
  253. }
  254. static inline void banshee_make_room(struct tdfx_par *par, int size)
  255. {
  256. /* Note: The Voodoo3's onboard FIFO has 32 slots. This loop
  257. * won't quit if you ask for more. */
  258. while((tdfx_inl(par, STATUS) & 0x1f) < size-1);
  259. }
  260. static int banshee_wait_idle(struct fb_info *info)
  261. {
  262. struct tdfx_par *par = (struct tdfx_par *) info->par;
  263. int i = 0;
  264. banshee_make_room(par, 1);
  265. tdfx_outl(par, COMMAND_3D, COMMAND_3D_NOP);
  266. while(1) {
  267. i = (tdfx_inl(par, STATUS) & STATUS_BUSY) ? 0 : i + 1;
  268. if(i == 3) break;
  269. }
  270. return 0;
  271. }
  272. /*
  273. * Set the color of a palette entry in 8bpp mode
  274. */
  275. static inline void do_setpalentry(struct tdfx_par *par, unsigned regno, u32 c)
  276. {
  277. banshee_make_room(par, 2);
  278. tdfx_outl(par, DACADDR, regno);
  279. tdfx_outl(par, DACDATA, c);
  280. }
  281. static u32 do_calc_pll(int freq, int* freq_out)
  282. {
  283. int m, n, k, best_m, best_n, best_k, best_error;
  284. int fref = 14318;
  285. best_error = freq;
  286. best_n = best_m = best_k = 0;
  287. for (k = 3; k >= 0; k--) {
  288. for (m = 63; m >= 0; m--) {
  289. /*
  290. * Estimate value of n that produces target frequency
  291. * with current m and k
  292. */
  293. int n_estimated = (freq * (m + 2) * (1 << k) / fref) - 2;
  294. /* Search neighborhood of estimated n */
  295. for (n = max(0, n_estimated - 1);
  296. n <= min(255, n_estimated + 1); n++) {
  297. /*
  298. * Calculate PLL freqency with current m, k and
  299. * estimated n
  300. */
  301. int f = fref * (n + 2) / (m + 2) / (1 << k);
  302. int error = abs (f - freq);
  303. /*
  304. * If this is the closest we've come to the
  305. * target frequency then remember n, m and k
  306. */
  307. if (error < best_error) {
  308. best_error = error;
  309. best_n = n;
  310. best_m = m;
  311. best_k = k;
  312. }
  313. }
  314. }
  315. }
  316. n = best_n;
  317. m = best_m;
  318. k = best_k;
  319. *freq_out = fref*(n + 2)/(m + 2)/(1 << k);
  320. return (n << 8) | (m << 2) | k;
  321. }
  322. static void do_write_regs(struct fb_info *info, struct banshee_reg* reg)
  323. {
  324. struct tdfx_par *par = (struct tdfx_par *) info->par;
  325. int i;
  326. banshee_wait_idle(info);
  327. tdfx_outl(par, MISCINIT1, tdfx_inl(par, MISCINIT1) | 0x01);
  328. crt_outb(par, 0x11, crt_inb(par, 0x11) & 0x7f); /* CRT unprotect */
  329. banshee_make_room(par, 3);
  330. tdfx_outl(par, VGAINIT1, reg->vgainit1 & 0x001FFFFF);
  331. tdfx_outl(par, VIDPROCCFG, reg->vidcfg & ~0x00000001);
  332. #if 0
  333. tdfx_outl(par, PLLCTRL1, reg->mempll);
  334. tdfx_outl(par, PLLCTRL2, reg->gfxpll);
  335. #endif
  336. tdfx_outl(par, PLLCTRL0, reg->vidpll);
  337. vga_outb(par, MISC_W, reg->misc[0x00] | 0x01);
  338. for (i = 0; i < 5; i++)
  339. seq_outb(par, i, reg->seq[i]);
  340. for (i = 0; i < 25; i++)
  341. crt_outb(par, i, reg->crt[i]);
  342. for (i = 0; i < 9; i++)
  343. gra_outb(par, i, reg->gra[i]);
  344. for (i = 0; i < 21; i++)
  345. att_outb(par, i, reg->att[i]);
  346. crt_outb(par, 0x1a, reg->ext[0]);
  347. crt_outb(par, 0x1b, reg->ext[1]);
  348. vga_enable_palette(par);
  349. vga_enable_video(par);
  350. banshee_make_room(par, 11);
  351. tdfx_outl(par, VGAINIT0, reg->vgainit0);
  352. tdfx_outl(par, DACMODE, reg->dacmode);
  353. tdfx_outl(par, VIDDESKSTRIDE, reg->stride);
  354. tdfx_outl(par, HWCURPATADDR, 0);
  355. tdfx_outl(par, VIDSCREENSIZE,reg->screensize);
  356. tdfx_outl(par, VIDDESKSTART, reg->startaddr);
  357. tdfx_outl(par, VIDPROCCFG, reg->vidcfg);
  358. tdfx_outl(par, VGAINIT1, reg->vgainit1);
  359. tdfx_outl(par, MISCINIT0, reg->miscinit0);
  360. banshee_make_room(par, 8);
  361. tdfx_outl(par, SRCBASE, reg->srcbase);
  362. tdfx_outl(par, DSTBASE, reg->dstbase);
  363. tdfx_outl(par, COMMANDEXTRA_2D, 0);
  364. tdfx_outl(par, CLIP0MIN, 0);
  365. tdfx_outl(par, CLIP0MAX, 0x0fff0fff);
  366. tdfx_outl(par, CLIP1MIN, 0);
  367. tdfx_outl(par, CLIP1MAX, 0x0fff0fff);
  368. tdfx_outl(par, SRCXY, 0);
  369. banshee_wait_idle(info);
  370. }
  371. static unsigned long do_lfb_size(struct tdfx_par *par, unsigned short dev_id)
  372. {
  373. u32 draminit0;
  374. u32 draminit1;
  375. u32 miscinit1;
  376. int num_chips;
  377. int chip_size; /* in MB */
  378. u32 lfbsize;
  379. int has_sgram;
  380. draminit0 = tdfx_inl(par, DRAMINIT0);
  381. draminit1 = tdfx_inl(par, DRAMINIT1);
  382. num_chips = (draminit0 & DRAMINIT0_SGRAM_NUM) ? 8 : 4;
  383. if (dev_id < PCI_DEVICE_ID_3DFX_VOODOO5) {
  384. /* Banshee/Voodoo3 */
  385. has_sgram = draminit1 & DRAMINIT1_MEM_SDRAM;
  386. chip_size = has_sgram ? ((draminit0 & DRAMINIT0_SGRAM_TYPE) ? 2 : 1)
  387. : 2;
  388. } else {
  389. /* Voodoo4/5 */
  390. has_sgram = 0;
  391. chip_size = 1 << ((draminit0 & DRAMINIT0_SGRAM_TYPE_MASK) >> DRAMINIT0_SGRAM_TYPE_SHIFT);
  392. }
  393. lfbsize = num_chips * chip_size * 1024 * 1024;
  394. /* disable block writes for SDRAM */
  395. miscinit1 = tdfx_inl(par, MISCINIT1);
  396. miscinit1 |= has_sgram ? 0 : MISCINIT1_2DBLOCK_DIS;
  397. miscinit1 |= MISCINIT1_CLUT_INV;
  398. banshee_make_room(par, 1);
  399. tdfx_outl(par, MISCINIT1, miscinit1);
  400. return lfbsize;
  401. }
  402. /* ------------------------------------------------------------------------- */
  403. static int tdfxfb_check_var(struct fb_var_screeninfo *var,struct fb_info *info)
  404. {
  405. struct tdfx_par *par = (struct tdfx_par *) info->par;
  406. u32 lpitch;
  407. if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 &&
  408. var->bits_per_pixel != 24 && var->bits_per_pixel != 32) {
  409. DPRINTK("depth not supported: %u\n", var->bits_per_pixel);
  410. return -EINVAL;
  411. }
  412. if (var->xres != var->xres_virtual)
  413. var->xres_virtual = var->xres;
  414. if (var->yres > var->yres_virtual)
  415. var->yres_virtual = var->yres;
  416. if (var->xoffset) {
  417. DPRINTK("xoffset not supported\n");
  418. return -EINVAL;
  419. }
  420. /* Banshee doesn't support interlace, but Voodoo4/5 and probably Voodoo3 do. */
  421. /* no direct information about device id now? use max_pixclock for this... */
  422. if (((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) &&
  423. (par->max_pixclock < VOODOO3_MAX_PIXCLOCK)) {
  424. DPRINTK("interlace not supported\n");
  425. return -EINVAL;
  426. }
  427. var->xres = (var->xres + 15) & ~15; /* could sometimes be 8 */
  428. lpitch = var->xres * ((var->bits_per_pixel + 7)>>3);
  429. if (var->xres < 320 || var->xres > 2048) {
  430. DPRINTK("width not supported: %u\n", var->xres);
  431. return -EINVAL;
  432. }
  433. if (var->yres < 200 || var->yres > 2048) {
  434. DPRINTK("height not supported: %u\n", var->yres);
  435. return -EINVAL;
  436. }
  437. if (lpitch * var->yres_virtual > info->fix.smem_len) {
  438. var->yres_virtual = info->fix.smem_len/lpitch;
  439. if (var->yres_virtual < var->yres) {
  440. DPRINTK("no memory for screen (%ux%ux%u)\n",
  441. var->xres, var->yres_virtual, var->bits_per_pixel);
  442. return -EINVAL;
  443. }
  444. }
  445. if (PICOS2KHZ(var->pixclock) > par->max_pixclock) {
  446. DPRINTK("pixclock too high (%ldKHz)\n",PICOS2KHZ(var->pixclock));
  447. return -EINVAL;
  448. }
  449. switch(var->bits_per_pixel) {
  450. case 8:
  451. var->red.length = var->green.length = var->blue.length = 8;
  452. break;
  453. case 16:
  454. var->red.offset = 11;
  455. var->red.length = 5;
  456. var->green.offset = 5;
  457. var->green.length = 6;
  458. var->blue.offset = 0;
  459. var->blue.length = 5;
  460. break;
  461. case 24:
  462. var->red.offset=16;
  463. var->green.offset=8;
  464. var->blue.offset=0;
  465. var->red.length = var->green.length = var->blue.length = 8;
  466. case 32:
  467. var->red.offset = 16;
  468. var->green.offset = 8;
  469. var->blue.offset = 0;
  470. var->red.length = var->green.length = var->blue.length = 8;
  471. break;
  472. }
  473. var->height = var->width = -1;
  474. var->accel_flags = FB_ACCELF_TEXT;
  475. DPRINTK("Checking graphics mode at %dx%d depth %d\n", var->xres, var->yres, var->bits_per_pixel);
  476. return 0;
  477. }
  478. static int tdfxfb_set_par(struct fb_info *info)
  479. {
  480. struct tdfx_par *par = (struct tdfx_par *) info->par;
  481. u32 hdispend, hsyncsta, hsyncend, htotal;
  482. u32 hd, hs, he, ht, hbs, hbe;
  483. u32 vd, vs, ve, vt, vbs, vbe;
  484. struct banshee_reg reg;
  485. int fout, freq;
  486. u32 wd, cpp;
  487. par->baseline = 0;
  488. memset(&reg, 0, sizeof(reg));
  489. cpp = (info->var.bits_per_pixel + 7)/8;
  490. reg.vidcfg = VIDCFG_VIDPROC_ENABLE | VIDCFG_DESK_ENABLE | VIDCFG_CURS_X11 | ((cpp - 1) << VIDCFG_PIXFMT_SHIFT) | (cpp != 1 ? VIDCFG_CLUT_BYPASS : 0);
  491. /* PLL settings */
  492. freq = PICOS2KHZ(info->var.pixclock);
  493. reg.dacmode = 0;
  494. reg.vidcfg &= ~VIDCFG_2X;
  495. hdispend = info->var.xres;
  496. hsyncsta = hdispend + info->var.right_margin;
  497. hsyncend = hsyncsta + info->var.hsync_len;
  498. htotal = hsyncend + info->var.left_margin;
  499. if (freq > par->max_pixclock/2) {
  500. freq = freq > par->max_pixclock ? par->max_pixclock : freq;
  501. reg.dacmode |= DACMODE_2X;
  502. reg.vidcfg |= VIDCFG_2X;
  503. hdispend >>= 1;
  504. hsyncsta >>= 1;
  505. hsyncend >>= 1;
  506. htotal >>= 1;
  507. }
  508. hd = wd = (hdispend >> 3) - 1;
  509. hs = (hsyncsta >> 3) - 1;
  510. he = (hsyncend >> 3) - 1;
  511. ht = (htotal >> 3) - 1;
  512. hbs = hd;
  513. hbe = ht;
  514. if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
  515. vbs = vd = (info->var.yres << 1) - 1;
  516. vs = vd + (info->var.lower_margin << 1);
  517. ve = vs + (info->var.vsync_len << 1);
  518. vbe = vt = ve + (info->var.upper_margin << 1) - 1;
  519. } else {
  520. vbs = vd = info->var.yres - 1;
  521. vs = vd + info->var.lower_margin;
  522. ve = vs + info->var.vsync_len;
  523. vbe = vt = ve + info->var.upper_margin - 1;
  524. }
  525. /* this is all pretty standard VGA register stuffing */
  526. reg.misc[0x00] = 0x0f |
  527. (info->var.xres < 400 ? 0xa0 :
  528. info->var.xres < 480 ? 0x60 :
  529. info->var.xres < 768 ? 0xe0 : 0x20);
  530. reg.gra[0x00] = 0x00;
  531. reg.gra[0x01] = 0x00;
  532. reg.gra[0x02] = 0x00;
  533. reg.gra[0x03] = 0x00;
  534. reg.gra[0x04] = 0x00;
  535. reg.gra[0x05] = 0x40;
  536. reg.gra[0x06] = 0x05;
  537. reg.gra[0x07] = 0x0f;
  538. reg.gra[0x08] = 0xff;
  539. reg.att[0x00] = 0x00;
  540. reg.att[0x01] = 0x01;
  541. reg.att[0x02] = 0x02;
  542. reg.att[0x03] = 0x03;
  543. reg.att[0x04] = 0x04;
  544. reg.att[0x05] = 0x05;
  545. reg.att[0x06] = 0x06;
  546. reg.att[0x07] = 0x07;
  547. reg.att[0x08] = 0x08;
  548. reg.att[0x09] = 0x09;
  549. reg.att[0x0a] = 0x0a;
  550. reg.att[0x0b] = 0x0b;
  551. reg.att[0x0c] = 0x0c;
  552. reg.att[0x0d] = 0x0d;
  553. reg.att[0x0e] = 0x0e;
  554. reg.att[0x0f] = 0x0f;
  555. reg.att[0x10] = 0x41;
  556. reg.att[0x11] = 0x00;
  557. reg.att[0x12] = 0x0f;
  558. reg.att[0x13] = 0x00;
  559. reg.att[0x14] = 0x00;
  560. reg.seq[0x00] = 0x03;
  561. reg.seq[0x01] = 0x01; /* fixme: clkdiv2? */
  562. reg.seq[0x02] = 0x0f;
  563. reg.seq[0x03] = 0x00;
  564. reg.seq[0x04] = 0x0e;
  565. reg.crt[0x00] = ht - 4;
  566. reg.crt[0x01] = hd;
  567. reg.crt[0x02] = hbs;
  568. reg.crt[0x03] = 0x80 | (hbe & 0x1f);
  569. reg.crt[0x04] = hs;
  570. reg.crt[0x05] = ((hbe & 0x20) << 2) | (he & 0x1f);
  571. reg.crt[0x06] = vt;
  572. reg.crt[0x07] = ((vs & 0x200) >> 2) |
  573. ((vd & 0x200) >> 3) |
  574. ((vt & 0x200) >> 4) | 0x10 |
  575. ((vbs & 0x100) >> 5) |
  576. ((vs & 0x100) >> 6) |
  577. ((vd & 0x100) >> 7) |
  578. ((vt & 0x100) >> 8);
  579. reg.crt[0x08] = 0x00;
  580. reg.crt[0x09] = 0x40 | ((vbs & 0x200) >> 4);
  581. reg.crt[0x0a] = 0x00;
  582. reg.crt[0x0b] = 0x00;
  583. reg.crt[0x0c] = 0x00;
  584. reg.crt[0x0d] = 0x00;
  585. reg.crt[0x0e] = 0x00;
  586. reg.crt[0x0f] = 0x00;
  587. reg.crt[0x10] = vs;
  588. reg.crt[0x11] = (ve & 0x0f) | 0x20;
  589. reg.crt[0x12] = vd;
  590. reg.crt[0x13] = wd;
  591. reg.crt[0x14] = 0x00;
  592. reg.crt[0x15] = vbs;
  593. reg.crt[0x16] = vbe + 1;
  594. reg.crt[0x17] = 0xc3;
  595. reg.crt[0x18] = 0xff;
  596. /* Banshee's nonvga stuff */
  597. reg.ext[0x00] = (((ht & 0x100) >> 8) |
  598. ((hd & 0x100) >> 6) |
  599. ((hbs & 0x100) >> 4) |
  600. ((hbe & 0x40) >> 1) |
  601. ((hs & 0x100) >> 2) |
  602. ((he & 0x20) << 2));
  603. reg.ext[0x01] = (((vt & 0x400) >> 10) |
  604. ((vd & 0x400) >> 8) |
  605. ((vbs & 0x400) >> 6) |
  606. ((vbe & 0x400) >> 4));
  607. reg.vgainit0 = VGAINIT0_8BIT_DAC |
  608. VGAINIT0_EXT_ENABLE |
  609. VGAINIT0_WAKEUP_3C3 |
  610. VGAINIT0_ALT_READBACK |
  611. VGAINIT0_EXTSHIFTOUT;
  612. reg.vgainit1 = tdfx_inl(par, VGAINIT1) & 0x1fffff;
  613. reg.cursloc = 0;
  614. reg.cursc0 = 0;
  615. reg.cursc1 = 0xffffff;
  616. reg.stride = info->var.xres * cpp;
  617. reg.startaddr = par->baseline * reg.stride;
  618. reg.srcbase = reg.startaddr;
  619. reg.dstbase = reg.startaddr;
  620. /* PLL settings */
  621. freq = PICOS2KHZ(info->var.pixclock);
  622. reg.dacmode &= ~DACMODE_2X;
  623. reg.vidcfg &= ~VIDCFG_2X;
  624. if (freq > par->max_pixclock/2) {
  625. freq = freq > par->max_pixclock ? par->max_pixclock : freq;
  626. reg.dacmode |= DACMODE_2X;
  627. reg.vidcfg |= VIDCFG_2X;
  628. }
  629. reg.vidpll = do_calc_pll(freq, &fout);
  630. #if 0
  631. reg.mempll = do_calc_pll(..., &fout);
  632. reg.gfxpll = do_calc_pll(..., &fout);
  633. #endif
  634. if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
  635. reg.screensize = info->var.xres | (info->var.yres << 13);
  636. reg.vidcfg |= VIDCFG_HALF_MODE;
  637. reg.crt[0x09] |= 0x80;
  638. } else {
  639. reg.screensize = info->var.xres | (info->var.yres << 12);
  640. reg.vidcfg &= ~VIDCFG_HALF_MODE;
  641. }
  642. if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED)
  643. reg.vidcfg |= VIDCFG_INTERLACE;
  644. reg.miscinit0 = tdfx_inl(par, MISCINIT0);
  645. #if defined(__BIG_ENDIAN)
  646. switch (info->var.bits_per_pixel) {
  647. case 8:
  648. case 24:
  649. reg.miscinit0 &= ~(1 << 30);
  650. reg.miscinit0 &= ~(1 << 31);
  651. break;
  652. case 16:
  653. reg.miscinit0 |= (1 << 30);
  654. reg.miscinit0 |= (1 << 31);
  655. break;
  656. case 32:
  657. reg.miscinit0 |= (1 << 30);
  658. reg.miscinit0 &= ~(1 << 31);
  659. break;
  660. }
  661. #endif
  662. do_write_regs(info, &reg);
  663. /* Now change fb_fix_screeninfo according to changes in par */
  664. info->fix.line_length = info->var.xres * ((info->var.bits_per_pixel + 7)>>3);
  665. info->fix.visual = (info->var.bits_per_pixel == 8)
  666. ? FB_VISUAL_PSEUDOCOLOR
  667. : FB_VISUAL_TRUECOLOR;
  668. DPRINTK("Graphics mode is now set at %dx%d depth %d\n", info->var.xres, info->var.yres, info->var.bits_per_pixel);
  669. return 0;
  670. }
  671. /* A handy macro shamelessly pinched from matroxfb */
  672. #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
  673. static int tdfxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  674. unsigned blue,unsigned transp,struct fb_info *info)
  675. {
  676. struct tdfx_par *par = (struct tdfx_par *) info->par;
  677. u32 rgbcol;
  678. if (regno >= info->cmap.len || regno > 255) return 1;
  679. switch (info->fix.visual) {
  680. case FB_VISUAL_PSEUDOCOLOR:
  681. rgbcol =(((u32)red & 0xff00) << 8) |
  682. (((u32)green & 0xff00) << 0) |
  683. (((u32)blue & 0xff00) >> 8);
  684. do_setpalentry(par, regno, rgbcol);
  685. break;
  686. /* Truecolor has no hardware color palettes. */
  687. case FB_VISUAL_TRUECOLOR:
  688. rgbcol = (CNVT_TOHW( red, info->var.red.length) << info->var.red.offset) |
  689. (CNVT_TOHW( green, info->var.green.length) << info->var.green.offset) |
  690. (CNVT_TOHW( blue, info->var.blue.length) << info->var.blue.offset) |
  691. (CNVT_TOHW( transp, info->var.transp.length) << info->var.transp.offset);
  692. ((u32*)(info->pseudo_palette))[regno] = rgbcol;
  693. break;
  694. default:
  695. DPRINTK("bad depth %u\n", info->var.bits_per_pixel);
  696. break;
  697. }
  698. return 0;
  699. }
  700. /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
  701. static int tdfxfb_blank(int blank, struct fb_info *info)
  702. {
  703. struct tdfx_par *par = (struct tdfx_par *) info->par;
  704. u32 dacmode, state = 0, vgablank = 0;
  705. dacmode = tdfx_inl(par, DACMODE);
  706. switch (blank) {
  707. case FB_BLANK_UNBLANK: /* Screen: On; HSync: On, VSync: On */
  708. state = 0;
  709. vgablank = 0;
  710. break;
  711. case FB_BLANK_NORMAL: /* Screen: Off; HSync: On, VSync: On */
  712. state = 0;
  713. vgablank = 1;
  714. break;
  715. case FB_BLANK_VSYNC_SUSPEND: /* Screen: Off; HSync: On, VSync: Off */
  716. state = BIT(3);
  717. vgablank = 1;
  718. break;
  719. case FB_BLANK_HSYNC_SUSPEND: /* Screen: Off; HSync: Off, VSync: On */
  720. state = BIT(1);
  721. vgablank = 1;
  722. break;
  723. case FB_BLANK_POWERDOWN: /* Screen: Off; HSync: Off, VSync: Off */
  724. state = BIT(1) | BIT(3);
  725. vgablank = 1;
  726. break;
  727. }
  728. dacmode &= ~(BIT(1) | BIT(3));
  729. dacmode |= state;
  730. banshee_make_room(par, 1);
  731. tdfx_outl(par, DACMODE, dacmode);
  732. if (vgablank)
  733. vga_disable_video(par);
  734. else
  735. vga_enable_video(par);
  736. return 0;
  737. }
  738. /*
  739. * Set the starting position of the visible screen to var->yoffset
  740. */
  741. static int tdfxfb_pan_display(struct fb_var_screeninfo *var,
  742. struct fb_info *info)
  743. {
  744. struct tdfx_par *par = (struct tdfx_par *) info->par;
  745. u32 addr;
  746. if (nopan || var->xoffset || (var->yoffset > var->yres_virtual))
  747. return -EINVAL;
  748. if ((var->yoffset + var->yres > var->yres_virtual && nowrap))
  749. return -EINVAL;
  750. addr = var->yoffset * info->fix.line_length;
  751. banshee_make_room(par, 1);
  752. tdfx_outl(par, VIDDESKSTART, addr);
  753. info->var.xoffset = var->xoffset;
  754. info->var.yoffset = var->yoffset;
  755. return 0;
  756. }
  757. #ifdef CONFIG_FB_3DFX_ACCEL
  758. /*
  759. * FillRect 2D command (solidfill or invert (via ROP_XOR))
  760. */
  761. static void tdfxfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  762. {
  763. struct tdfx_par *par = (struct tdfx_par *) info->par;
  764. u32 bpp = info->var.bits_per_pixel;
  765. u32 stride = info->fix.line_length;
  766. u32 fmt= stride | ((bpp+((bpp==8) ? 0 : 8)) << 13);
  767. int tdfx_rop;
  768. if (rect->rop == ROP_COPY)
  769. tdfx_rop = TDFX_ROP_COPY;
  770. else
  771. tdfx_rop = TDFX_ROP_XOR;
  772. banshee_make_room(par, 5);
  773. tdfx_outl(par, DSTFORMAT, fmt);
  774. if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
  775. tdfx_outl(par, COLORFORE, rect->color);
  776. } else { /* FB_VISUAL_TRUECOLOR */
  777. tdfx_outl(par, COLORFORE, ((u32*)(info->pseudo_palette))[rect->color]);
  778. }
  779. tdfx_outl(par, COMMAND_2D, COMMAND_2D_FILLRECT | (tdfx_rop << 24));
  780. tdfx_outl(par, DSTSIZE, rect->width | (rect->height << 16));
  781. tdfx_outl(par, LAUNCH_2D, rect->dx | (rect->dy << 16));
  782. }
  783. /*
  784. * Screen-to-Screen BitBlt 2D command (for the bmove fb op.)
  785. */
  786. static void tdfxfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  787. {
  788. struct tdfx_par *par = (struct tdfx_par *) info->par;
  789. u32 sx = area->sx, sy = area->sy, dx = area->dx, dy = area->dy;
  790. u32 bpp = info->var.bits_per_pixel;
  791. u32 stride = info->fix.line_length;
  792. u32 blitcmd = COMMAND_2D_S2S_BITBLT | (TDFX_ROP_COPY << 24);
  793. u32 fmt = stride | ((bpp+((bpp==8) ? 0 : 8)) << 13);
  794. if (area->sx <= area->dx) {
  795. //-X
  796. blitcmd |= BIT(14);
  797. sx += area->width - 1;
  798. dx += area->width - 1;
  799. }
  800. if (area->sy <= area->dy) {
  801. //-Y
  802. blitcmd |= BIT(15);
  803. sy += area->height - 1;
  804. dy += area->height - 1;
  805. }
  806. banshee_make_room(par, 6);
  807. tdfx_outl(par, SRCFORMAT, fmt);
  808. tdfx_outl(par, DSTFORMAT, fmt);
  809. tdfx_outl(par, COMMAND_2D, blitcmd);
  810. tdfx_outl(par, DSTSIZE, area->width | (area->height << 16));
  811. tdfx_outl(par, DSTXY, dx | (dy << 16));
  812. tdfx_outl(par, LAUNCH_2D, sx | (sy << 16));
  813. }
  814. static void tdfxfb_imageblit(struct fb_info *info, const struct fb_image *image)
  815. {
  816. struct tdfx_par *par = (struct tdfx_par *) info->par;
  817. int size = image->height * ((image->width * image->depth + 7)>>3);
  818. int fifo_free;
  819. int i, stride = info->fix.line_length;
  820. u32 bpp = info->var.bits_per_pixel;
  821. u32 dstfmt = stride | ((bpp+((bpp==8) ? 0 : 8)) << 13);
  822. u8 *chardata = (u8 *) image->data;
  823. u32 srcfmt;
  824. if (image->depth != 1) {
  825. //banshee_make_room(par, 6 + ((size + 3) >> 2));
  826. //srcfmt = stride | ((bpp+((bpp==8) ? 0 : 8)) << 13) | 0x400000;
  827. cfb_imageblit(info, image);
  828. return;
  829. } else {
  830. banshee_make_room(par, 8);
  831. switch (info->fix.visual) {
  832. case FB_VISUAL_PSEUDOCOLOR:
  833. tdfx_outl(par, COLORFORE, image->fg_color);
  834. tdfx_outl(par, COLORBACK, image->bg_color);
  835. break;
  836. case FB_VISUAL_TRUECOLOR:
  837. default:
  838. tdfx_outl(par, COLORFORE, ((u32*)(info->pseudo_palette))[image->fg_color]);
  839. tdfx_outl(par, COLORBACK, ((u32*)(info->pseudo_palette))[image->bg_color]);
  840. }
  841. #ifdef __BIG_ENDIAN
  842. srcfmt = 0x400000 | BIT(20);
  843. #else
  844. srcfmt = 0x400000;
  845. #endif
  846. }
  847. tdfx_outl(par, SRCXY, 0);
  848. tdfx_outl(par, DSTXY, image->dx | (image->dy << 16));
  849. tdfx_outl(par, COMMAND_2D, COMMAND_2D_H2S_BITBLT | (TDFX_ROP_COPY << 24));
  850. tdfx_outl(par, SRCFORMAT, srcfmt);
  851. tdfx_outl(par, DSTFORMAT, dstfmt);
  852. tdfx_outl(par, DSTSIZE, image->width | (image->height << 16));
  853. /* A count of how many free FIFO entries we've requested.
  854. * When this goes negative, we need to request more. */
  855. fifo_free = 0;
  856. /* Send four bytes at a time of data */
  857. for (i = (size >> 2) ; i > 0; i--) {
  858. if(--fifo_free < 0) {
  859. fifo_free=31;
  860. banshee_make_room(par,fifo_free);
  861. }
  862. tdfx_outl(par, LAUNCH_2D,*(u32*)chardata);
  863. chardata += 4;
  864. }
  865. /* Send the leftovers now */
  866. banshee_make_room(par,3);
  867. i = size%4;
  868. switch (i) {
  869. case 0: break;
  870. case 1: tdfx_outl(par, LAUNCH_2D,*chardata); break;
  871. case 2: tdfx_outl(par, LAUNCH_2D,*(u16*)chardata); break;
  872. case 3: tdfx_outl(par, LAUNCH_2D,*(u16*)chardata | ((chardata[3]) << 24)); break;
  873. }
  874. }
  875. #endif /* CONFIG_FB_3DFX_ACCEL */
  876. #ifdef TDFX_HARDWARE_CURSOR
  877. static int tdfxfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  878. {
  879. struct tdfx_par *par = (struct tdfx_par *) info->par;
  880. unsigned long flags;
  881. /*
  882. * If the cursor is not be changed this means either we want the
  883. * current cursor state (if enable is set) or we want to query what
  884. * we can do with the cursor (if enable is not set)
  885. */
  886. if (!cursor->set) return 0;
  887. /* Too large of a cursor :-( */
  888. if (cursor->image.width > 64 || cursor->image.height > 64)
  889. return -ENXIO;
  890. /*
  891. * If we are going to be changing things we should disable
  892. * the cursor first
  893. */
  894. if (info->cursor.enable) {
  895. spin_lock_irqsave(&par->DAClock, flags);
  896. info->cursor.enable = 0;
  897. del_timer(&(par->hwcursor.timer));
  898. tdfx_outl(par, VIDPROCCFG, par->hwcursor.disable);
  899. spin_unlock_irqrestore(&par->DAClock, flags);
  900. }
  901. /* Disable the Cursor */
  902. if ((cursor->set && FB_CUR_SETCUR) && !cursor->enable)
  903. return 0;
  904. /* fix cursor color - XFree86 forgets to restore it properly */
  905. if (cursor->set && FB_CUR_SETCMAP) {
  906. struct fb_cmap cmap = cursor->image.cmap;
  907. unsigned long bg_color, fg_color;
  908. cmap.len = 2; /* Voodoo 3+ only support 2 color cursors */
  909. fg_color = ((cmap.red[cmap.start] << 16) |
  910. (cmap.green[cmap.start] << 8) |
  911. (cmap.blue[cmap.start]));
  912. bg_color = ((cmap.red[cmap.start+1] << 16) |
  913. (cmap.green[cmap.start+1] << 8) |
  914. (cmap.blue[cmap.start+1]));
  915. fb_copy_cmap(&cmap, &info->cursor.image.cmap);
  916. spin_lock_irqsave(&par->DAClock, flags);
  917. banshee_make_room(par, 2);
  918. tdfx_outl(par, HWCURC0, bg_color);
  919. tdfx_outl(par, HWCURC1, fg_color);
  920. spin_unlock_irqrestore(&par->DAClock, flags);
  921. }
  922. if (cursor->set && FB_CUR_SETPOS) {
  923. int x, y;
  924. x = cursor->image.dx;
  925. y = cursor->image.dy;
  926. y -= info->var.yoffset;
  927. info->cursor.image.dx = x;
  928. info->cursor.image.dy = y;
  929. x += 63;
  930. y += 63;
  931. spin_lock_irqsave(&par->DAClock, flags);
  932. banshee_make_room(par, 1);
  933. tdfx_outl(par, HWCURLOC, (y << 16) + x);
  934. spin_unlock_irqrestore(&par->DAClock, flags);
  935. }
  936. /* Not supported so we fake it */
  937. if (cursor->set && FB_CUR_SETHOT) {
  938. info->cursor.hot.x = cursor->hot.x;
  939. info->cursor.hot.y = cursor->hot.y;
  940. }
  941. if (cursor->set && FB_CUR_SETSHAPE) {
  942. /*
  943. * Voodoo 3 and above cards use 2 monochrome cursor patterns.
  944. * The reason is so the card can fetch 8 words at a time
  945. * and are stored on chip for use for the next 8 scanlines.
  946. * This reduces the number of times for access to draw the
  947. * cursor for each screen refresh.
  948. * Each pattern is a bitmap of 64 bit wide and 64 bit high
  949. * (total of 8192 bits or 1024 Kbytes). The two patterns are
  950. * stored in such a way that pattern 0 always resides in the
  951. * lower half (least significant 64 bits) of a 128 bit word
  952. * and pattern 1 the upper half. If you examine the data of
  953. * the cursor image the graphics card uses then from the
  954. * begining you see line one of pattern 0, line one of
  955. * pattern 1, line two of pattern 0, line two of pattern 1,
  956. * etc etc. The linear stride for the cursor is always 16 bytes
  957. * (128 bits) which is the maximum cursor width times two for
  958. * the two monochrome patterns.
  959. */
  960. u8 *cursorbase = (u8 *) info->cursor.image.data;
  961. char *bitmap = (char *)cursor->image.data;
  962. char *mask = (char *) cursor->mask;
  963. int i, j, k, h = 0;
  964. for (i = 0; i < 64; i++) {
  965. if (i < cursor->image.height) {
  966. j = (cursor->image.width + 7) >> 3;
  967. k = 8 - j;
  968. for (;j > 0; j--) {
  969. /* Pattern 0. Copy the cursor bitmap to it */
  970. fb_writeb(*bitmap, cursorbase + h);
  971. bitmap++;
  972. /* Pattern 1. Copy the cursor mask to it */
  973. fb_writeb(*mask, cursorbase + h + 8);
  974. mask++;
  975. h++;
  976. }
  977. for (;k > 0; k--) {
  978. fb_writeb(0, cursorbase + h);
  979. fb_writeb(~0, cursorbase + h + 8);
  980. h++;
  981. }
  982. } else {
  983. fb_writel(0, cursorbase + h);
  984. fb_writel(0, cursorbase + h + 4);
  985. fb_writel(~0, cursorbase + h + 8);
  986. fb_writel(~0, cursorbase + h + 12);
  987. h += 16;
  988. }
  989. }
  990. }
  991. /* Turn the cursor on */
  992. cursor->enable = 1;
  993. info->cursor = *cursor;
  994. mod_timer(&par->hwcursor.timer, jiffies+HZ/2);
  995. spin_lock_irqsave(&par->DAClock, flags);
  996. banshee_make_room(par, 1);
  997. tdfx_outl(par, VIDPROCCFG, par->hwcursor.enable);
  998. spin_unlock_irqrestore(&par->DAClock, flags);
  999. return 0;
  1000. }
  1001. #endif
  1002. /**
  1003. * tdfxfb_probe - Device Initializiation
  1004. *
  1005. * @pdev: PCI Device to initialize
  1006. * @id: PCI Device ID
  1007. *
  1008. * Initializes and allocates resources for PCI device @pdev.
  1009. *
  1010. */
  1011. static int __devinit tdfxfb_probe(struct pci_dev *pdev,
  1012. const struct pci_device_id *id)
  1013. {
  1014. struct tdfx_par *default_par;
  1015. struct fb_info *info;
  1016. int size, err, lpitch;
  1017. if ((err = pci_enable_device(pdev))) {
  1018. printk(KERN_WARNING "tdfxfb: Can't enable pdev: %d\n", err);
  1019. return err;
  1020. }
  1021. size = sizeof(struct tdfx_par)+256*sizeof(u32);
  1022. info = framebuffer_alloc(size, &pdev->dev);
  1023. if (!info) return -ENOMEM;
  1024. default_par = info->par;
  1025. /* Configure the default fb_fix_screeninfo first */
  1026. switch (pdev->device) {
  1027. case PCI_DEVICE_ID_3DFX_BANSHEE:
  1028. strcat(tdfx_fix.id, " Banshee");
  1029. default_par->max_pixclock = BANSHEE_MAX_PIXCLOCK;
  1030. break;
  1031. case PCI_DEVICE_ID_3DFX_VOODOO3:
  1032. strcat(tdfx_fix.id, " Voodoo3");
  1033. default_par->max_pixclock = VOODOO3_MAX_PIXCLOCK;
  1034. break;
  1035. case PCI_DEVICE_ID_3DFX_VOODOO5:
  1036. strcat(tdfx_fix.id, " Voodoo5");
  1037. default_par->max_pixclock = VOODOO5_MAX_PIXCLOCK;
  1038. break;
  1039. }
  1040. tdfx_fix.mmio_start = pci_resource_start(pdev, 0);
  1041. tdfx_fix.mmio_len = pci_resource_len(pdev, 0);
  1042. default_par->regbase_virt = ioremap_nocache(tdfx_fix.mmio_start, tdfx_fix.mmio_len);
  1043. if (!default_par->regbase_virt) {
  1044. printk("fb: Can't remap %s register area.\n", tdfx_fix.id);
  1045. goto out_err;
  1046. }
  1047. if (!request_mem_region(pci_resource_start(pdev, 0),
  1048. pci_resource_len(pdev, 0), "tdfx regbase")) {
  1049. printk(KERN_WARNING "tdfxfb: Can't reserve regbase\n");
  1050. goto out_err;
  1051. }
  1052. tdfx_fix.smem_start = pci_resource_start(pdev, 1);
  1053. if (!(tdfx_fix.smem_len = do_lfb_size(default_par, pdev->device))) {
  1054. printk("fb: Can't count %s memory.\n", tdfx_fix.id);
  1055. release_mem_region(pci_resource_start(pdev, 0),
  1056. pci_resource_len(pdev, 0));
  1057. goto out_err;
  1058. }
  1059. if (!request_mem_region(pci_resource_start(pdev, 1),
  1060. pci_resource_len(pdev, 1), "tdfx smem")) {
  1061. printk(KERN_WARNING "tdfxfb: Can't reserve smem\n");
  1062. release_mem_region(pci_resource_start(pdev, 0),
  1063. pci_resource_len(pdev, 0));
  1064. goto out_err;
  1065. }
  1066. info->screen_base = ioremap_nocache(tdfx_fix.smem_start,
  1067. tdfx_fix.smem_len);
  1068. if (!info->screen_base) {
  1069. printk("fb: Can't remap %s framebuffer.\n", tdfx_fix.id);
  1070. release_mem_region(pci_resource_start(pdev, 1),
  1071. pci_resource_len(pdev, 1));
  1072. release_mem_region(pci_resource_start(pdev, 0),
  1073. pci_resource_len(pdev, 0));
  1074. goto out_err;
  1075. }
  1076. default_par->iobase = pci_resource_start(pdev, 2);
  1077. if (!request_region(pci_resource_start(pdev, 2),
  1078. pci_resource_len(pdev, 2), "tdfx iobase")) {
  1079. printk(KERN_WARNING "tdfxfb: Can't reserve iobase\n");
  1080. release_mem_region(pci_resource_start(pdev, 1),
  1081. pci_resource_len(pdev, 1));
  1082. release_mem_region(pci_resource_start(pdev, 0),
  1083. pci_resource_len(pdev, 0));
  1084. goto out_err;
  1085. }
  1086. printk("fb: %s memory = %dK\n", tdfx_fix.id, tdfx_fix.smem_len >> 10);
  1087. tdfx_fix.ypanstep = nopan ? 0 : 1;
  1088. tdfx_fix.ywrapstep = nowrap ? 0 : 1;
  1089. info->fbops = &tdfxfb_ops;
  1090. info->fix = tdfx_fix;
  1091. info->pseudo_palette = (void *)(default_par + 1);
  1092. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  1093. #ifdef CONFIG_FB_3DFX_ACCEL
  1094. info->flags |= FBINFO_HWACCEL_FILLRECT |
  1095. FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_IMAGEBLIT;
  1096. #endif
  1097. if (!mode_option)
  1098. mode_option = "640x480@60";
  1099. err = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
  1100. if (!err || err == 4)
  1101. info->var = tdfx_var;
  1102. /* maximize virtual vertical length */
  1103. lpitch = info->var.xres_virtual * ((info->var.bits_per_pixel + 7) >> 3);
  1104. info->var.yres_virtual = info->fix.smem_len/lpitch;
  1105. if (info->var.yres_virtual < info->var.yres)
  1106. goto out_err;
  1107. #ifdef CONFIG_FB_3DFX_ACCEL
  1108. /*
  1109. * FIXME: Limit var->yres_virtual to 4096 because of screen artifacts
  1110. * during scrolling. This is only present if 2D acceleration is
  1111. * enabled.
  1112. */
  1113. if (info->var.yres_virtual > 4096)
  1114. info->var.yres_virtual = 4096;
  1115. #endif /* CONFIG_FB_3DFX_ACCEL */
  1116. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
  1117. printk(KERN_WARNING "tdfxfb: Can't allocate color map\n");
  1118. goto out_err;
  1119. }
  1120. if (register_framebuffer(info) < 0) {
  1121. printk("tdfxfb: can't register framebuffer\n");
  1122. fb_dealloc_cmap(&info->cmap);
  1123. goto out_err;
  1124. }
  1125. /*
  1126. * Our driver data
  1127. */
  1128. pci_set_drvdata(pdev, info);
  1129. return 0;
  1130. out_err:
  1131. /*
  1132. * Cleanup after anything that was remapped/allocated.
  1133. */
  1134. if (default_par->regbase_virt)
  1135. iounmap(default_par->regbase_virt);
  1136. if (info->screen_base)
  1137. iounmap(info->screen_base);
  1138. framebuffer_release(info);
  1139. return -ENXIO;
  1140. }
  1141. #ifndef MODULE
  1142. void tdfxfb_setup(char *options)
  1143. {
  1144. char* this_opt;
  1145. if (!options || !*options)
  1146. return;
  1147. while ((this_opt = strsep(&options, ",")) != NULL) {
  1148. if (!*this_opt)
  1149. continue;
  1150. if(!strcmp(this_opt, "nopan")) {
  1151. nopan = 1;
  1152. } else if(!strcmp(this_opt, "nowrap")) {
  1153. nowrap = 1;
  1154. } else {
  1155. mode_option = this_opt;
  1156. }
  1157. }
  1158. }
  1159. #endif
  1160. /**
  1161. * tdfxfb_remove - Device removal
  1162. *
  1163. * @pdev: PCI Device to cleanup
  1164. *
  1165. * Releases all resources allocated during the course of the driver's
  1166. * lifetime for the PCI device @pdev.
  1167. *
  1168. */
  1169. static void __devexit tdfxfb_remove(struct pci_dev *pdev)
  1170. {
  1171. struct fb_info *info = pci_get_drvdata(pdev);
  1172. struct tdfx_par *par = (struct tdfx_par *) info->par;
  1173. unregister_framebuffer(info);
  1174. iounmap(par->regbase_virt);
  1175. iounmap(info->screen_base);
  1176. /* Clean up after reserved regions */
  1177. release_region(pci_resource_start(pdev, 2),
  1178. pci_resource_len(pdev, 2));
  1179. release_mem_region(pci_resource_start(pdev, 1),
  1180. pci_resource_len(pdev, 1));
  1181. release_mem_region(pci_resource_start(pdev, 0),
  1182. pci_resource_len(pdev, 0));
  1183. pci_set_drvdata(pdev, NULL);
  1184. framebuffer_release(info);
  1185. }
  1186. static int __init tdfxfb_init(void)
  1187. {
  1188. #ifndef MODULE
  1189. char *option = NULL;
  1190. if (fb_get_options("tdfxfb", &option))
  1191. return -ENODEV;
  1192. tdfxfb_setup(option);
  1193. #endif
  1194. return pci_register_driver(&tdfxfb_driver);
  1195. }
  1196. static void __exit tdfxfb_exit(void)
  1197. {
  1198. pci_unregister_driver(&tdfxfb_driver);
  1199. }
  1200. MODULE_AUTHOR("Hannu Mallat <hmallat@cc.hut.fi>");
  1201. MODULE_DESCRIPTION("3Dfx framebuffer device driver");
  1202. MODULE_LICENSE("GPL");
  1203. module_init(tdfxfb_init);
  1204. module_exit(tdfxfb_exit);