tdfxfb.c 37 KB

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