tdfxfb.c 38 KB

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