tdfxfb.c 38 KB

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