tridentfb.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837
  1. /*
  2. * Frame buffer driver for Trident TGUI, Blade and Image series
  3. *
  4. * Copyright 2001, 2002 - Jani Monoses <jani@iv.ro>
  5. * Copyright 2009 Krzysztof Helt <krzysztof.h1@wp.pl>
  6. *
  7. * CREDITS:(in order of appearance)
  8. * skeletonfb.c by Geert Uytterhoeven and other fb code in drivers/video
  9. * Special thanks ;) to Mattia Crivellini <tia@mclink.it>
  10. * much inspired by the XFree86 4.x Trident driver sources
  11. * by Alan Hourihane the FreeVGA project
  12. * Francesco Salvestrini <salvestrini@users.sf.net> XP support,
  13. * code, suggestions
  14. * TODO:
  15. * timing value tweaking so it looks good on every monitor in every mode
  16. */
  17. #include <linux/module.h>
  18. #include <linux/fb.h>
  19. #include <linux/init.h>
  20. #include <linux/pci.h>
  21. #include <linux/slab.h>
  22. #include <linux/delay.h>
  23. #include <video/vga.h>
  24. #include <video/trident.h>
  25. #include <linux/i2c.h>
  26. #include <linux/i2c-algo-bit.h>
  27. struct tridentfb_par {
  28. void __iomem *io_virt; /* iospace virtual memory address */
  29. u32 pseudo_pal[16];
  30. int chip_id;
  31. int flatpanel;
  32. void (*init_accel) (struct tridentfb_par *, int, int);
  33. void (*wait_engine) (struct tridentfb_par *);
  34. void (*fill_rect)
  35. (struct tridentfb_par *par, u32, u32, u32, u32, u32, u32);
  36. void (*copy_rect)
  37. (struct tridentfb_par *par, u32, u32, u32, u32, u32, u32);
  38. void (*image_blit)
  39. (struct tridentfb_par *par, const char*,
  40. u32, u32, u32, u32, u32, u32);
  41. unsigned char eng_oper; /* engine operation... */
  42. bool ddc_registered;
  43. struct i2c_adapter ddc_adapter;
  44. struct i2c_algo_bit_data ddc_algo;
  45. };
  46. static struct fb_fix_screeninfo tridentfb_fix = {
  47. .id = "Trident",
  48. .type = FB_TYPE_PACKED_PIXELS,
  49. .ypanstep = 1,
  50. .visual = FB_VISUAL_PSEUDOCOLOR,
  51. .accel = FB_ACCEL_NONE,
  52. };
  53. /* defaults which are normally overriden by user values */
  54. /* video mode */
  55. static char *mode_option;
  56. static int bpp = 8;
  57. static int noaccel;
  58. static int center;
  59. static int stretch;
  60. static int fp;
  61. static int crt;
  62. static int memsize;
  63. static int memdiff;
  64. static int nativex;
  65. module_param(mode_option, charp, 0);
  66. MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
  67. module_param_named(mode, mode_option, charp, 0);
  68. MODULE_PARM_DESC(mode, "Initial video mode e.g. '648x480-8@60' (deprecated)");
  69. module_param(bpp, int, 0);
  70. module_param(center, int, 0);
  71. module_param(stretch, int, 0);
  72. module_param(noaccel, int, 0);
  73. module_param(memsize, int, 0);
  74. module_param(memdiff, int, 0);
  75. module_param(nativex, int, 0);
  76. module_param(fp, int, 0);
  77. MODULE_PARM_DESC(fp, "Define if flatpanel is connected");
  78. module_param(crt, int, 0);
  79. MODULE_PARM_DESC(crt, "Define if CRT is connected");
  80. static inline int is_oldclock(int id)
  81. {
  82. return (id == TGUI9440) ||
  83. (id == TGUI9660) ||
  84. (id == CYBER9320);
  85. }
  86. static inline int is_oldprotect(int id)
  87. {
  88. return is_oldclock(id) ||
  89. (id == PROVIDIA9685) ||
  90. (id == CYBER9382) ||
  91. (id == CYBER9385);
  92. }
  93. static inline int is_blade(int id)
  94. {
  95. return (id == BLADE3D) ||
  96. (id == CYBERBLADEE4) ||
  97. (id == CYBERBLADEi7) ||
  98. (id == CYBERBLADEi7D) ||
  99. (id == CYBERBLADEi1) ||
  100. (id == CYBERBLADEi1D) ||
  101. (id == CYBERBLADEAi1) ||
  102. (id == CYBERBLADEAi1D);
  103. }
  104. static inline int is_xp(int id)
  105. {
  106. return (id == CYBERBLADEXPAi1) ||
  107. (id == CYBERBLADEXPm8) ||
  108. (id == CYBERBLADEXPm16);
  109. }
  110. static inline int is3Dchip(int id)
  111. {
  112. return is_blade(id) || is_xp(id) ||
  113. (id == CYBER9397) || (id == CYBER9397DVD) ||
  114. (id == CYBER9520) || (id == CYBER9525DVD) ||
  115. (id == IMAGE975) || (id == IMAGE985);
  116. }
  117. static inline int iscyber(int id)
  118. {
  119. switch (id) {
  120. case CYBER9388:
  121. case CYBER9382:
  122. case CYBER9385:
  123. case CYBER9397:
  124. case CYBER9397DVD:
  125. case CYBER9520:
  126. case CYBER9525DVD:
  127. case CYBERBLADEE4:
  128. case CYBERBLADEi7D:
  129. case CYBERBLADEi1:
  130. case CYBERBLADEi1D:
  131. case CYBERBLADEAi1:
  132. case CYBERBLADEAi1D:
  133. case CYBERBLADEXPAi1:
  134. return 1;
  135. case CYBER9320:
  136. case CYBERBLADEi7: /* VIA MPV4 integrated version */
  137. default:
  138. /* case CYBERBLDAEXPm8: Strange */
  139. /* case CYBERBLDAEXPm16: Strange */
  140. return 0;
  141. }
  142. }
  143. static inline void t_outb(struct tridentfb_par *p, u8 val, u16 reg)
  144. {
  145. fb_writeb(val, p->io_virt + reg);
  146. }
  147. static inline u8 t_inb(struct tridentfb_par *p, u16 reg)
  148. {
  149. return fb_readb(p->io_virt + reg);
  150. }
  151. static inline void writemmr(struct tridentfb_par *par, u16 r, u32 v)
  152. {
  153. fb_writel(v, par->io_virt + r);
  154. }
  155. static inline u32 readmmr(struct tridentfb_par *par, u16 r)
  156. {
  157. return fb_readl(par->io_virt + r);
  158. }
  159. #define DDC_SDA_TGUI BIT(0)
  160. #define DDC_SCL_TGUI BIT(1)
  161. #define DDC_SCL_DRIVE_TGUI BIT(2)
  162. #define DDC_SDA_DRIVE_TGUI BIT(3)
  163. #define DDC_MASK_TGUI (DDC_SCL_DRIVE_TGUI | DDC_SDA_DRIVE_TGUI)
  164. static void tridentfb_ddc_setscl_tgui(void *data, int val)
  165. {
  166. struct tridentfb_par *par = data;
  167. u8 reg = vga_mm_rcrt(par->io_virt, I2C) & DDC_MASK_TGUI;
  168. if (val)
  169. reg &= ~DDC_SCL_DRIVE_TGUI; /* disable drive - don't drive hi */
  170. else
  171. reg |= DDC_SCL_DRIVE_TGUI; /* drive low */
  172. vga_mm_wcrt(par->io_virt, I2C, reg);
  173. }
  174. static void tridentfb_ddc_setsda_tgui(void *data, int val)
  175. {
  176. struct tridentfb_par *par = data;
  177. u8 reg = vga_mm_rcrt(par->io_virt, I2C) & DDC_MASK_TGUI;
  178. if (val)
  179. reg &= ~DDC_SDA_DRIVE_TGUI; /* disable drive - don't drive hi */
  180. else
  181. reg |= DDC_SDA_DRIVE_TGUI; /* drive low */
  182. vga_mm_wcrt(par->io_virt, I2C, reg);
  183. }
  184. static int tridentfb_ddc_getsda_tgui(void *data)
  185. {
  186. struct tridentfb_par *par = data;
  187. return !!(vga_mm_rcrt(par->io_virt, I2C) & DDC_SDA_TGUI);
  188. }
  189. #define DDC_SDA_IN BIT(0)
  190. #define DDC_SCL_OUT BIT(1)
  191. #define DDC_SDA_OUT BIT(3)
  192. #define DDC_SCL_IN BIT(6)
  193. #define DDC_MASK (DDC_SCL_OUT | DDC_SDA_OUT)
  194. static void tridentfb_ddc_setscl(void *data, int val)
  195. {
  196. struct tridentfb_par *par = data;
  197. unsigned char reg;
  198. reg = vga_mm_rcrt(par->io_virt, I2C) & DDC_MASK;
  199. if (val)
  200. reg |= DDC_SCL_OUT;
  201. else
  202. reg &= ~DDC_SCL_OUT;
  203. vga_mm_wcrt(par->io_virt, I2C, reg);
  204. }
  205. static void tridentfb_ddc_setsda(void *data, int val)
  206. {
  207. struct tridentfb_par *par = data;
  208. unsigned char reg;
  209. reg = vga_mm_rcrt(par->io_virt, I2C) & DDC_MASK;
  210. if (!val)
  211. reg |= DDC_SDA_OUT;
  212. else
  213. reg &= ~DDC_SDA_OUT;
  214. vga_mm_wcrt(par->io_virt, I2C, reg);
  215. }
  216. static int tridentfb_ddc_getscl(void *data)
  217. {
  218. struct tridentfb_par *par = data;
  219. return !!(vga_mm_rcrt(par->io_virt, I2C) & DDC_SCL_IN);
  220. }
  221. static int tridentfb_ddc_getsda(void *data)
  222. {
  223. struct tridentfb_par *par = data;
  224. return !!(vga_mm_rcrt(par->io_virt, I2C) & DDC_SDA_IN);
  225. }
  226. static int tridentfb_setup_ddc_bus(struct fb_info *info)
  227. {
  228. struct tridentfb_par *par = info->par;
  229. strlcpy(par->ddc_adapter.name, info->fix.id,
  230. sizeof(par->ddc_adapter.name));
  231. par->ddc_adapter.owner = THIS_MODULE;
  232. par->ddc_adapter.class = I2C_CLASS_DDC;
  233. par->ddc_adapter.algo_data = &par->ddc_algo;
  234. par->ddc_adapter.dev.parent = info->device;
  235. if (is_oldclock(par->chip_id)) { /* not sure if this check is OK */
  236. par->ddc_algo.setsda = tridentfb_ddc_setsda_tgui;
  237. par->ddc_algo.setscl = tridentfb_ddc_setscl_tgui;
  238. par->ddc_algo.getsda = tridentfb_ddc_getsda_tgui;
  239. /* no getscl */
  240. } else {
  241. par->ddc_algo.setsda = tridentfb_ddc_setsda;
  242. par->ddc_algo.setscl = tridentfb_ddc_setscl;
  243. par->ddc_algo.getsda = tridentfb_ddc_getsda;
  244. par->ddc_algo.getscl = tridentfb_ddc_getscl;
  245. }
  246. par->ddc_algo.udelay = 10;
  247. par->ddc_algo.timeout = 20;
  248. par->ddc_algo.data = par;
  249. i2c_set_adapdata(&par->ddc_adapter, par);
  250. return i2c_bit_add_bus(&par->ddc_adapter);
  251. }
  252. /*
  253. * Blade specific acceleration.
  254. */
  255. #define point(x, y) ((y) << 16 | (x))
  256. static void blade_init_accel(struct tridentfb_par *par, int pitch, int bpp)
  257. {
  258. int v1 = (pitch >> 3) << 20;
  259. int tmp = bpp == 24 ? 2 : (bpp >> 4);
  260. int v2 = v1 | (tmp << 29);
  261. writemmr(par, 0x21C0, v2);
  262. writemmr(par, 0x21C4, v2);
  263. writemmr(par, 0x21B8, v2);
  264. writemmr(par, 0x21BC, v2);
  265. writemmr(par, 0x21D0, v1);
  266. writemmr(par, 0x21D4, v1);
  267. writemmr(par, 0x21C8, v1);
  268. writemmr(par, 0x21CC, v1);
  269. writemmr(par, 0x216C, 0);
  270. }
  271. static void blade_wait_engine(struct tridentfb_par *par)
  272. {
  273. while (readmmr(par, STATUS) & 0xFA800000)
  274. cpu_relax();
  275. }
  276. static void blade_fill_rect(struct tridentfb_par *par,
  277. u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
  278. {
  279. writemmr(par, COLOR, c);
  280. writemmr(par, ROP, rop ? ROP_X : ROP_S);
  281. writemmr(par, CMD, 0x20000000 | 1 << 19 | 1 << 4 | 2 << 2);
  282. writemmr(par, DST1, point(x, y));
  283. writemmr(par, DST2, point(x + w - 1, y + h - 1));
  284. }
  285. static void blade_image_blit(struct tridentfb_par *par, const char *data,
  286. u32 x, u32 y, u32 w, u32 h, u32 c, u32 b)
  287. {
  288. unsigned size = ((w + 31) >> 5) * h;
  289. writemmr(par, COLOR, c);
  290. writemmr(par, BGCOLOR, b);
  291. writemmr(par, CMD, 0xa0000000 | 3 << 19);
  292. writemmr(par, DST1, point(x, y));
  293. writemmr(par, DST2, point(x + w - 1, y + h - 1));
  294. iowrite32_rep(par->io_virt + 0x10000, data, size);
  295. }
  296. static void blade_copy_rect(struct tridentfb_par *par,
  297. u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
  298. {
  299. int direction = 2;
  300. u32 s1 = point(x1, y1);
  301. u32 s2 = point(x1 + w - 1, y1 + h - 1);
  302. u32 d1 = point(x2, y2);
  303. u32 d2 = point(x2 + w - 1, y2 + h - 1);
  304. if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))
  305. direction = 0;
  306. writemmr(par, ROP, ROP_S);
  307. writemmr(par, CMD, 0xE0000000 | 1 << 19 | 1 << 4 | 1 << 2 | direction);
  308. writemmr(par, SRC1, direction ? s2 : s1);
  309. writemmr(par, SRC2, direction ? s1 : s2);
  310. writemmr(par, DST1, direction ? d2 : d1);
  311. writemmr(par, DST2, direction ? d1 : d2);
  312. }
  313. /*
  314. * BladeXP specific acceleration functions
  315. */
  316. static void xp_init_accel(struct tridentfb_par *par, int pitch, int bpp)
  317. {
  318. unsigned char x = bpp == 24 ? 3 : (bpp >> 4);
  319. int v1 = pitch << (bpp == 24 ? 20 : (18 + x));
  320. switch (pitch << (bpp >> 3)) {
  321. case 8192:
  322. case 512:
  323. x |= 0x00;
  324. break;
  325. case 1024:
  326. x |= 0x04;
  327. break;
  328. case 2048:
  329. x |= 0x08;
  330. break;
  331. case 4096:
  332. x |= 0x0C;
  333. break;
  334. }
  335. t_outb(par, x, 0x2125);
  336. par->eng_oper = x | 0x40;
  337. writemmr(par, 0x2154, v1);
  338. writemmr(par, 0x2150, v1);
  339. t_outb(par, 3, 0x2126);
  340. }
  341. static void xp_wait_engine(struct tridentfb_par *par)
  342. {
  343. int count = 0;
  344. int timeout = 0;
  345. while (t_inb(par, STATUS) & 0x80) {
  346. count++;
  347. if (count == 10000000) {
  348. /* Timeout */
  349. count = 9990000;
  350. timeout++;
  351. if (timeout == 8) {
  352. /* Reset engine */
  353. t_outb(par, 0x00, STATUS);
  354. return;
  355. }
  356. }
  357. cpu_relax();
  358. }
  359. }
  360. static void xp_fill_rect(struct tridentfb_par *par,
  361. u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
  362. {
  363. writemmr(par, 0x2127, ROP_P);
  364. writemmr(par, 0x2158, c);
  365. writemmr(par, DRAWFL, 0x4000);
  366. writemmr(par, OLDDIM, point(h, w));
  367. writemmr(par, OLDDST, point(y, x));
  368. t_outb(par, 0x01, OLDCMD);
  369. t_outb(par, par->eng_oper, 0x2125);
  370. }
  371. static void xp_copy_rect(struct tridentfb_par *par,
  372. u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
  373. {
  374. u32 x1_tmp, x2_tmp, y1_tmp, y2_tmp;
  375. int direction = 0x0004;
  376. if ((x1 < x2) && (y1 == y2)) {
  377. direction |= 0x0200;
  378. x1_tmp = x1 + w - 1;
  379. x2_tmp = x2 + w - 1;
  380. } else {
  381. x1_tmp = x1;
  382. x2_tmp = x2;
  383. }
  384. if (y1 < y2) {
  385. direction |= 0x0100;
  386. y1_tmp = y1 + h - 1;
  387. y2_tmp = y2 + h - 1;
  388. } else {
  389. y1_tmp = y1;
  390. y2_tmp = y2;
  391. }
  392. writemmr(par, DRAWFL, direction);
  393. t_outb(par, ROP_S, 0x2127);
  394. writemmr(par, OLDSRC, point(y1_tmp, x1_tmp));
  395. writemmr(par, OLDDST, point(y2_tmp, x2_tmp));
  396. writemmr(par, OLDDIM, point(h, w));
  397. t_outb(par, 0x01, OLDCMD);
  398. }
  399. /*
  400. * Image specific acceleration functions
  401. */
  402. static void image_init_accel(struct tridentfb_par *par, int pitch, int bpp)
  403. {
  404. int tmp = bpp == 24 ? 2: (bpp >> 4);
  405. writemmr(par, 0x2120, 0xF0000000);
  406. writemmr(par, 0x2120, 0x40000000 | tmp);
  407. writemmr(par, 0x2120, 0x80000000);
  408. writemmr(par, 0x2144, 0x00000000);
  409. writemmr(par, 0x2148, 0x00000000);
  410. writemmr(par, 0x2150, 0x00000000);
  411. writemmr(par, 0x2154, 0x00000000);
  412. writemmr(par, 0x2120, 0x60000000 | (pitch << 16) | pitch);
  413. writemmr(par, 0x216C, 0x00000000);
  414. writemmr(par, 0x2170, 0x00000000);
  415. writemmr(par, 0x217C, 0x00000000);
  416. writemmr(par, 0x2120, 0x10000000);
  417. writemmr(par, 0x2130, (2047 << 16) | 2047);
  418. }
  419. static void image_wait_engine(struct tridentfb_par *par)
  420. {
  421. while (readmmr(par, 0x2164) & 0xF0000000)
  422. cpu_relax();
  423. }
  424. static void image_fill_rect(struct tridentfb_par *par,
  425. u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
  426. {
  427. writemmr(par, 0x2120, 0x80000000);
  428. writemmr(par, 0x2120, 0x90000000 | ROP_S);
  429. writemmr(par, 0x2144, c);
  430. writemmr(par, DST1, point(x, y));
  431. writemmr(par, DST2, point(x + w - 1, y + h - 1));
  432. writemmr(par, 0x2124, 0x80000000 | 3 << 22 | 1 << 10 | 1 << 9);
  433. }
  434. static void image_copy_rect(struct tridentfb_par *par,
  435. u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
  436. {
  437. int direction = 0x4;
  438. u32 s1 = point(x1, y1);
  439. u32 s2 = point(x1 + w - 1, y1 + h - 1);
  440. u32 d1 = point(x2, y2);
  441. u32 d2 = point(x2 + w - 1, y2 + h - 1);
  442. if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))
  443. direction = 0;
  444. writemmr(par, 0x2120, 0x80000000);
  445. writemmr(par, 0x2120, 0x90000000 | ROP_S);
  446. writemmr(par, SRC1, direction ? s2 : s1);
  447. writemmr(par, SRC2, direction ? s1 : s2);
  448. writemmr(par, DST1, direction ? d2 : d1);
  449. writemmr(par, DST2, direction ? d1 : d2);
  450. writemmr(par, 0x2124,
  451. 0x80000000 | 1 << 22 | 1 << 10 | 1 << 7 | direction);
  452. }
  453. /*
  454. * TGUI 9440/96XX acceleration
  455. */
  456. static void tgui_init_accel(struct tridentfb_par *par, int pitch, int bpp)
  457. {
  458. unsigned char x = bpp == 24 ? 3 : (bpp >> 4);
  459. /* disable clipping */
  460. writemmr(par, 0x2148, 0);
  461. writemmr(par, 0x214C, point(4095, 2047));
  462. switch ((pitch * bpp) / 8) {
  463. case 8192:
  464. case 512:
  465. x |= 0x00;
  466. break;
  467. case 1024:
  468. x |= 0x04;
  469. break;
  470. case 2048:
  471. x |= 0x08;
  472. break;
  473. case 4096:
  474. x |= 0x0C;
  475. break;
  476. }
  477. fb_writew(x, par->io_virt + 0x2122);
  478. }
  479. static void tgui_fill_rect(struct tridentfb_par *par,
  480. u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
  481. {
  482. t_outb(par, ROP_P, 0x2127);
  483. writemmr(par, OLDCLR, c);
  484. writemmr(par, DRAWFL, 0x4020);
  485. writemmr(par, OLDDIM, point(w - 1, h - 1));
  486. writemmr(par, OLDDST, point(x, y));
  487. t_outb(par, 1, OLDCMD);
  488. }
  489. static void tgui_copy_rect(struct tridentfb_par *par,
  490. u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
  491. {
  492. int flags = 0;
  493. u16 x1_tmp, x2_tmp, y1_tmp, y2_tmp;
  494. if ((x1 < x2) && (y1 == y2)) {
  495. flags |= 0x0200;
  496. x1_tmp = x1 + w - 1;
  497. x2_tmp = x2 + w - 1;
  498. } else {
  499. x1_tmp = x1;
  500. x2_tmp = x2;
  501. }
  502. if (y1 < y2) {
  503. flags |= 0x0100;
  504. y1_tmp = y1 + h - 1;
  505. y2_tmp = y2 + h - 1;
  506. } else {
  507. y1_tmp = y1;
  508. y2_tmp = y2;
  509. }
  510. writemmr(par, DRAWFL, 0x4 | flags);
  511. t_outb(par, ROP_S, 0x2127);
  512. writemmr(par, OLDSRC, point(x1_tmp, y1_tmp));
  513. writemmr(par, OLDDST, point(x2_tmp, y2_tmp));
  514. writemmr(par, OLDDIM, point(w - 1, h - 1));
  515. t_outb(par, 1, OLDCMD);
  516. }
  517. /*
  518. * Accel functions called by the upper layers
  519. */
  520. static void tridentfb_fillrect(struct fb_info *info,
  521. const struct fb_fillrect *fr)
  522. {
  523. struct tridentfb_par *par = info->par;
  524. int col;
  525. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  526. cfb_fillrect(info, fr);
  527. return;
  528. }
  529. if (info->var.bits_per_pixel == 8) {
  530. col = fr->color;
  531. col |= col << 8;
  532. col |= col << 16;
  533. } else
  534. col = ((u32 *)(info->pseudo_palette))[fr->color];
  535. par->wait_engine(par);
  536. par->fill_rect(par, fr->dx, fr->dy, fr->width,
  537. fr->height, col, fr->rop);
  538. }
  539. static void tridentfb_imageblit(struct fb_info *info,
  540. const struct fb_image *img)
  541. {
  542. struct tridentfb_par *par = info->par;
  543. int col, bgcol;
  544. if ((info->flags & FBINFO_HWACCEL_DISABLED) || img->depth != 1) {
  545. cfb_imageblit(info, img);
  546. return;
  547. }
  548. if (info->var.bits_per_pixel == 8) {
  549. col = img->fg_color;
  550. col |= col << 8;
  551. col |= col << 16;
  552. bgcol = img->bg_color;
  553. bgcol |= bgcol << 8;
  554. bgcol |= bgcol << 16;
  555. } else {
  556. col = ((u32 *)(info->pseudo_palette))[img->fg_color];
  557. bgcol = ((u32 *)(info->pseudo_palette))[img->bg_color];
  558. }
  559. par->wait_engine(par);
  560. if (par->image_blit)
  561. par->image_blit(par, img->data, img->dx, img->dy,
  562. img->width, img->height, col, bgcol);
  563. else
  564. cfb_imageblit(info, img);
  565. }
  566. static void tridentfb_copyarea(struct fb_info *info,
  567. const struct fb_copyarea *ca)
  568. {
  569. struct tridentfb_par *par = info->par;
  570. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  571. cfb_copyarea(info, ca);
  572. return;
  573. }
  574. par->wait_engine(par);
  575. par->copy_rect(par, ca->sx, ca->sy, ca->dx, ca->dy,
  576. ca->width, ca->height);
  577. }
  578. static int tridentfb_sync(struct fb_info *info)
  579. {
  580. struct tridentfb_par *par = info->par;
  581. if (!(info->flags & FBINFO_HWACCEL_DISABLED))
  582. par->wait_engine(par);
  583. return 0;
  584. }
  585. /*
  586. * Hardware access functions
  587. */
  588. static inline unsigned char read3X4(struct tridentfb_par *par, int reg)
  589. {
  590. return vga_mm_rcrt(par->io_virt, reg);
  591. }
  592. static inline void write3X4(struct tridentfb_par *par, int reg,
  593. unsigned char val)
  594. {
  595. vga_mm_wcrt(par->io_virt, reg, val);
  596. }
  597. static inline unsigned char read3CE(struct tridentfb_par *par,
  598. unsigned char reg)
  599. {
  600. return vga_mm_rgfx(par->io_virt, reg);
  601. }
  602. static inline void writeAttr(struct tridentfb_par *par, int reg,
  603. unsigned char val)
  604. {
  605. fb_readb(par->io_virt + VGA_IS1_RC); /* flip-flop to index */
  606. vga_mm_wattr(par->io_virt, reg, val);
  607. }
  608. static inline void write3CE(struct tridentfb_par *par, int reg,
  609. unsigned char val)
  610. {
  611. vga_mm_wgfx(par->io_virt, reg, val);
  612. }
  613. static void enable_mmio(struct tridentfb_par *par)
  614. {
  615. /* Goto New Mode */
  616. vga_io_rseq(0x0B);
  617. /* Unprotect registers */
  618. vga_io_wseq(NewMode1, 0x80);
  619. if (!is_oldprotect(par->chip_id))
  620. vga_io_wseq(Protection, 0x92);
  621. /* Enable MMIO */
  622. outb(PCIReg, 0x3D4);
  623. outb(inb(0x3D5) | 0x01, 0x3D5);
  624. }
  625. static void disable_mmio(struct tridentfb_par *par)
  626. {
  627. /* Goto New Mode */
  628. vga_mm_rseq(par->io_virt, 0x0B);
  629. /* Unprotect registers */
  630. vga_mm_wseq(par->io_virt, NewMode1, 0x80);
  631. if (!is_oldprotect(par->chip_id))
  632. vga_mm_wseq(par->io_virt, Protection, 0x92);
  633. /* Disable MMIO */
  634. t_outb(par, PCIReg, 0x3D4);
  635. t_outb(par, t_inb(par, 0x3D5) & ~0x01, 0x3D5);
  636. }
  637. static inline void crtc_unlock(struct tridentfb_par *par)
  638. {
  639. write3X4(par, VGA_CRTC_V_SYNC_END,
  640. read3X4(par, VGA_CRTC_V_SYNC_END) & 0x7F);
  641. }
  642. /* Return flat panel's maximum x resolution */
  643. static int get_nativex(struct tridentfb_par *par)
  644. {
  645. int x, y, tmp;
  646. if (nativex)
  647. return nativex;
  648. tmp = (read3CE(par, VertStretch) >> 4) & 3;
  649. switch (tmp) {
  650. case 0:
  651. x = 1280; y = 1024;
  652. break;
  653. case 2:
  654. x = 1024; y = 768;
  655. break;
  656. case 3:
  657. x = 800; y = 600;
  658. break;
  659. case 4:
  660. x = 1400; y = 1050;
  661. break;
  662. case 1:
  663. default:
  664. x = 640; y = 480;
  665. break;
  666. }
  667. output("%dx%d flat panel found\n", x, y);
  668. return x;
  669. }
  670. /* Set pitch */
  671. static inline void set_lwidth(struct tridentfb_par *par, int width)
  672. {
  673. write3X4(par, VGA_CRTC_OFFSET, width & 0xFF);
  674. /* chips older than TGUI9660 have only 1 width bit in AddColReg */
  675. /* touching the other one breaks I2C/DDC */
  676. if (par->chip_id == TGUI9440 || par->chip_id == CYBER9320)
  677. write3X4(par, AddColReg,
  678. (read3X4(par, AddColReg) & 0xEF) | ((width & 0x100) >> 4));
  679. else
  680. write3X4(par, AddColReg,
  681. (read3X4(par, AddColReg) & 0xCF) | ((width & 0x300) >> 4));
  682. }
  683. /* For resolutions smaller than FP resolution stretch */
  684. static void screen_stretch(struct tridentfb_par *par)
  685. {
  686. if (par->chip_id != CYBERBLADEXPAi1)
  687. write3CE(par, BiosReg, 0);
  688. else
  689. write3CE(par, BiosReg, 8);
  690. write3CE(par, VertStretch, (read3CE(par, VertStretch) & 0x7C) | 1);
  691. write3CE(par, HorStretch, (read3CE(par, HorStretch) & 0x7C) | 1);
  692. }
  693. /* For resolutions smaller than FP resolution center */
  694. static inline void screen_center(struct tridentfb_par *par)
  695. {
  696. write3CE(par, VertStretch, (read3CE(par, VertStretch) & 0x7C) | 0x80);
  697. write3CE(par, HorStretch, (read3CE(par, HorStretch) & 0x7C) | 0x80);
  698. }
  699. /* Address of first shown pixel in display memory */
  700. static void set_screen_start(struct tridentfb_par *par, int base)
  701. {
  702. u8 tmp;
  703. write3X4(par, VGA_CRTC_START_LO, base & 0xFF);
  704. write3X4(par, VGA_CRTC_START_HI, (base & 0xFF00) >> 8);
  705. tmp = read3X4(par, CRTCModuleTest) & 0xDF;
  706. write3X4(par, CRTCModuleTest, tmp | ((base & 0x10000) >> 11));
  707. tmp = read3X4(par, CRTHiOrd) & 0xF8;
  708. write3X4(par, CRTHiOrd, tmp | ((base & 0xE0000) >> 17));
  709. }
  710. /* Set dotclock frequency */
  711. static void set_vclk(struct tridentfb_par *par, unsigned long freq)
  712. {
  713. int m, n, k;
  714. unsigned long fi, d, di;
  715. unsigned char best_m = 0, best_n = 0, best_k = 0;
  716. unsigned char hi, lo;
  717. unsigned char shift = !is_oldclock(par->chip_id) ? 2 : 1;
  718. d = 20000;
  719. for (k = shift; k >= 0; k--)
  720. for (m = 1; m < 32; m++) {
  721. n = ((m + 2) << shift) - 8;
  722. for (n = (n < 0 ? 0 : n); n < 122; n++) {
  723. fi = ((14318l * (n + 8)) / (m + 2)) >> k;
  724. di = abs(fi - freq);
  725. if (di < d || (di == d && k == best_k)) {
  726. d = di;
  727. best_n = n;
  728. best_m = m;
  729. best_k = k;
  730. }
  731. if (fi > freq)
  732. break;
  733. }
  734. }
  735. if (is_oldclock(par->chip_id)) {
  736. lo = best_n | (best_m << 7);
  737. hi = (best_m >> 1) | (best_k << 4);
  738. } else {
  739. lo = best_n;
  740. hi = best_m | (best_k << 6);
  741. }
  742. if (is3Dchip(par->chip_id)) {
  743. vga_mm_wseq(par->io_virt, ClockHigh, hi);
  744. vga_mm_wseq(par->io_virt, ClockLow, lo);
  745. } else {
  746. t_outb(par, lo, 0x43C8);
  747. t_outb(par, hi, 0x43C9);
  748. }
  749. debug("VCLK = %X %X\n", hi, lo);
  750. }
  751. /* Set number of lines for flat panels*/
  752. static void set_number_of_lines(struct tridentfb_par *par, int lines)
  753. {
  754. int tmp = read3CE(par, CyberEnhance) & 0x8F;
  755. if (lines > 1024)
  756. tmp |= 0x50;
  757. else if (lines > 768)
  758. tmp |= 0x30;
  759. else if (lines > 600)
  760. tmp |= 0x20;
  761. else if (lines > 480)
  762. tmp |= 0x10;
  763. write3CE(par, CyberEnhance, tmp);
  764. }
  765. /*
  766. * If we see that FP is active we assume we have one.
  767. * Otherwise we have a CRT display. User can override.
  768. */
  769. static int is_flatpanel(struct tridentfb_par *par)
  770. {
  771. if (fp)
  772. return 1;
  773. if (crt || !iscyber(par->chip_id))
  774. return 0;
  775. return (read3CE(par, FPConfig) & 0x10) ? 1 : 0;
  776. }
  777. /* Try detecting the video memory size */
  778. static unsigned int get_memsize(struct tridentfb_par *par)
  779. {
  780. unsigned char tmp, tmp2;
  781. unsigned int k;
  782. /* If memory size provided by user */
  783. if (memsize)
  784. k = memsize * Kb;
  785. else
  786. switch (par->chip_id) {
  787. case CYBER9525DVD:
  788. k = 2560 * Kb;
  789. break;
  790. default:
  791. tmp = read3X4(par, SPR) & 0x0F;
  792. switch (tmp) {
  793. case 0x01:
  794. k = 512 * Kb;
  795. break;
  796. case 0x02:
  797. k = 6 * Mb; /* XP */
  798. break;
  799. case 0x03:
  800. k = 1 * Mb;
  801. break;
  802. case 0x04:
  803. k = 8 * Mb;
  804. break;
  805. case 0x06:
  806. k = 10 * Mb; /* XP */
  807. break;
  808. case 0x07:
  809. k = 2 * Mb;
  810. break;
  811. case 0x08:
  812. k = 12 * Mb; /* XP */
  813. break;
  814. case 0x0A:
  815. k = 14 * Mb; /* XP */
  816. break;
  817. case 0x0C:
  818. k = 16 * Mb; /* XP */
  819. break;
  820. case 0x0E: /* XP */
  821. tmp2 = vga_mm_rseq(par->io_virt, 0xC1);
  822. switch (tmp2) {
  823. case 0x00:
  824. k = 20 * Mb;
  825. break;
  826. case 0x01:
  827. k = 24 * Mb;
  828. break;
  829. case 0x10:
  830. k = 28 * Mb;
  831. break;
  832. case 0x11:
  833. k = 32 * Mb;
  834. break;
  835. default:
  836. k = 1 * Mb;
  837. break;
  838. }
  839. break;
  840. case 0x0F:
  841. k = 4 * Mb;
  842. break;
  843. default:
  844. k = 1 * Mb;
  845. break;
  846. }
  847. }
  848. k -= memdiff * Kb;
  849. output("framebuffer size = %d Kb\n", k / Kb);
  850. return k;
  851. }
  852. /* See if we can handle the video mode described in var */
  853. static int tridentfb_check_var(struct fb_var_screeninfo *var,
  854. struct fb_info *info)
  855. {
  856. struct tridentfb_par *par = info->par;
  857. int bpp = var->bits_per_pixel;
  858. int line_length;
  859. int ramdac = 230000; /* 230MHz for most 3D chips */
  860. debug("enter\n");
  861. /* check color depth */
  862. if (bpp == 24)
  863. bpp = var->bits_per_pixel = 32;
  864. if (bpp != 8 && bpp != 16 && bpp != 32)
  865. return -EINVAL;
  866. if (par->chip_id == TGUI9440 && bpp == 32)
  867. return -EINVAL;
  868. /* check whether resolution fits on panel and in memory */
  869. if (par->flatpanel && nativex && var->xres > nativex)
  870. return -EINVAL;
  871. /* various resolution checks */
  872. var->xres = (var->xres + 7) & ~0x7;
  873. if (var->xres > var->xres_virtual)
  874. var->xres_virtual = var->xres;
  875. if (var->yres > var->yres_virtual)
  876. var->yres_virtual = var->yres;
  877. if (var->xres_virtual > 4095 || var->yres > 2048)
  878. return -EINVAL;
  879. /* prevent from position overflow for acceleration */
  880. if (var->yres_virtual > 0xffff)
  881. return -EINVAL;
  882. line_length = var->xres_virtual * bpp / 8;
  883. if (!is3Dchip(par->chip_id) &&
  884. !(info->flags & FBINFO_HWACCEL_DISABLED)) {
  885. /* acceleration requires line length to be power of 2 */
  886. if (line_length <= 512)
  887. var->xres_virtual = 512 * 8 / bpp;
  888. else if (line_length <= 1024)
  889. var->xres_virtual = 1024 * 8 / bpp;
  890. else if (line_length <= 2048)
  891. var->xres_virtual = 2048 * 8 / bpp;
  892. else if (line_length <= 4096)
  893. var->xres_virtual = 4096 * 8 / bpp;
  894. else if (line_length <= 8192)
  895. var->xres_virtual = 8192 * 8 / bpp;
  896. else
  897. return -EINVAL;
  898. line_length = var->xres_virtual * bpp / 8;
  899. }
  900. /* datasheet specifies how to set panning only up to 4 MB */
  901. if (line_length * (var->yres_virtual - var->yres) > (4 << 20))
  902. var->yres_virtual = ((4 << 20) / line_length) + var->yres;
  903. if (line_length * var->yres_virtual > info->fix.smem_len)
  904. return -EINVAL;
  905. switch (bpp) {
  906. case 8:
  907. var->red.offset = 0;
  908. var->red.length = 8;
  909. var->green = var->red;
  910. var->blue = var->red;
  911. break;
  912. case 16:
  913. var->red.offset = 11;
  914. var->green.offset = 5;
  915. var->blue.offset = 0;
  916. var->red.length = 5;
  917. var->green.length = 6;
  918. var->blue.length = 5;
  919. break;
  920. case 32:
  921. var->red.offset = 16;
  922. var->green.offset = 8;
  923. var->blue.offset = 0;
  924. var->red.length = 8;
  925. var->green.length = 8;
  926. var->blue.length = 8;
  927. break;
  928. default:
  929. return -EINVAL;
  930. }
  931. if (is_xp(par->chip_id))
  932. ramdac = 350000;
  933. switch (par->chip_id) {
  934. case TGUI9440:
  935. ramdac = (bpp >= 16) ? 45000 : 90000;
  936. break;
  937. case CYBER9320:
  938. case TGUI9660:
  939. ramdac = 135000;
  940. break;
  941. case PROVIDIA9685:
  942. case CYBER9388:
  943. case CYBER9382:
  944. case CYBER9385:
  945. ramdac = 170000;
  946. break;
  947. }
  948. /* The clock is doubled for 32 bpp */
  949. if (bpp == 32)
  950. ramdac /= 2;
  951. if (PICOS2KHZ(var->pixclock) > ramdac)
  952. return -EINVAL;
  953. debug("exit\n");
  954. return 0;
  955. }
  956. /* Pan the display */
  957. static int tridentfb_pan_display(struct fb_var_screeninfo *var,
  958. struct fb_info *info)
  959. {
  960. struct tridentfb_par *par = info->par;
  961. unsigned int offset;
  962. debug("enter\n");
  963. offset = (var->xoffset + (var->yoffset * info->var.xres_virtual))
  964. * info->var.bits_per_pixel / 32;
  965. set_screen_start(par, offset);
  966. debug("exit\n");
  967. return 0;
  968. }
  969. static inline void shadowmode_on(struct tridentfb_par *par)
  970. {
  971. write3CE(par, CyberControl, read3CE(par, CyberControl) | 0x81);
  972. }
  973. static inline void shadowmode_off(struct tridentfb_par *par)
  974. {
  975. write3CE(par, CyberControl, read3CE(par, CyberControl) & 0x7E);
  976. }
  977. /* Set the hardware to the requested video mode */
  978. static int tridentfb_set_par(struct fb_info *info)
  979. {
  980. struct tridentfb_par *par = info->par;
  981. u32 htotal, hdispend, hsyncstart, hsyncend, hblankstart, hblankend;
  982. u32 vtotal, vdispend, vsyncstart, vsyncend, vblankstart, vblankend;
  983. struct fb_var_screeninfo *var = &info->var;
  984. int bpp = var->bits_per_pixel;
  985. unsigned char tmp;
  986. unsigned long vclk;
  987. debug("enter\n");
  988. hdispend = var->xres / 8 - 1;
  989. hsyncstart = (var->xres + var->right_margin) / 8;
  990. hsyncend = (var->xres + var->right_margin + var->hsync_len) / 8;
  991. htotal = (var->xres + var->left_margin + var->right_margin +
  992. var->hsync_len) / 8 - 5;
  993. hblankstart = hdispend + 1;
  994. hblankend = htotal + 3;
  995. vdispend = var->yres - 1;
  996. vsyncstart = var->yres + var->lower_margin;
  997. vsyncend = vsyncstart + var->vsync_len;
  998. vtotal = var->upper_margin + vsyncend - 2;
  999. vblankstart = vdispend + 1;
  1000. vblankend = vtotal;
  1001. if (info->var.vmode & FB_VMODE_INTERLACED) {
  1002. vtotal /= 2;
  1003. vdispend /= 2;
  1004. vsyncstart /= 2;
  1005. vsyncend /= 2;
  1006. vblankstart /= 2;
  1007. vblankend /= 2;
  1008. }
  1009. enable_mmio(par);
  1010. crtc_unlock(par);
  1011. write3CE(par, CyberControl, 8);
  1012. tmp = 0xEB;
  1013. if (var->sync & FB_SYNC_HOR_HIGH_ACT)
  1014. tmp &= ~0x40;
  1015. if (var->sync & FB_SYNC_VERT_HIGH_ACT)
  1016. tmp &= ~0x80;
  1017. if (par->flatpanel && var->xres < nativex) {
  1018. /*
  1019. * on flat panels with native size larger
  1020. * than requested resolution decide whether
  1021. * we stretch or center
  1022. */
  1023. t_outb(par, tmp | 0xC0, VGA_MIS_W);
  1024. shadowmode_on(par);
  1025. if (center)
  1026. screen_center(par);
  1027. else if (stretch)
  1028. screen_stretch(par);
  1029. } else {
  1030. t_outb(par, tmp, VGA_MIS_W);
  1031. write3CE(par, CyberControl, 8);
  1032. }
  1033. /* vertical timing values */
  1034. write3X4(par, VGA_CRTC_V_TOTAL, vtotal & 0xFF);
  1035. write3X4(par, VGA_CRTC_V_DISP_END, vdispend & 0xFF);
  1036. write3X4(par, VGA_CRTC_V_SYNC_START, vsyncstart & 0xFF);
  1037. write3X4(par, VGA_CRTC_V_SYNC_END, (vsyncend & 0x0F));
  1038. write3X4(par, VGA_CRTC_V_BLANK_START, vblankstart & 0xFF);
  1039. write3X4(par, VGA_CRTC_V_BLANK_END, vblankend & 0xFF);
  1040. /* horizontal timing values */
  1041. write3X4(par, VGA_CRTC_H_TOTAL, htotal & 0xFF);
  1042. write3X4(par, VGA_CRTC_H_DISP, hdispend & 0xFF);
  1043. write3X4(par, VGA_CRTC_H_SYNC_START, hsyncstart & 0xFF);
  1044. write3X4(par, VGA_CRTC_H_SYNC_END,
  1045. (hsyncend & 0x1F) | ((hblankend & 0x20) << 2));
  1046. write3X4(par, VGA_CRTC_H_BLANK_START, hblankstart & 0xFF);
  1047. write3X4(par, VGA_CRTC_H_BLANK_END, hblankend & 0x1F);
  1048. /* higher bits of vertical timing values */
  1049. tmp = 0x10;
  1050. if (vtotal & 0x100) tmp |= 0x01;
  1051. if (vdispend & 0x100) tmp |= 0x02;
  1052. if (vsyncstart & 0x100) tmp |= 0x04;
  1053. if (vblankstart & 0x100) tmp |= 0x08;
  1054. if (vtotal & 0x200) tmp |= 0x20;
  1055. if (vdispend & 0x200) tmp |= 0x40;
  1056. if (vsyncstart & 0x200) tmp |= 0x80;
  1057. write3X4(par, VGA_CRTC_OVERFLOW, tmp);
  1058. tmp = read3X4(par, CRTHiOrd) & 0x07;
  1059. tmp |= 0x08; /* line compare bit 10 */
  1060. if (vtotal & 0x400) tmp |= 0x80;
  1061. if (vblankstart & 0x400) tmp |= 0x40;
  1062. if (vsyncstart & 0x400) tmp |= 0x20;
  1063. if (vdispend & 0x400) tmp |= 0x10;
  1064. write3X4(par, CRTHiOrd, tmp);
  1065. tmp = (htotal >> 8) & 0x01;
  1066. tmp |= (hdispend >> 7) & 0x02;
  1067. tmp |= (hsyncstart >> 5) & 0x08;
  1068. tmp |= (hblankstart >> 4) & 0x10;
  1069. write3X4(par, HorizOverflow, tmp);
  1070. tmp = 0x40;
  1071. if (vblankstart & 0x200) tmp |= 0x20;
  1072. //FIXME if (info->var.vmode & FB_VMODE_DOUBLE) tmp |= 0x80; /* double scan for 200 line modes */
  1073. write3X4(par, VGA_CRTC_MAX_SCAN, tmp);
  1074. write3X4(par, VGA_CRTC_LINE_COMPARE, 0xFF);
  1075. write3X4(par, VGA_CRTC_PRESET_ROW, 0);
  1076. write3X4(par, VGA_CRTC_MODE, 0xC3);
  1077. write3X4(par, LinearAddReg, 0x20); /* enable linear addressing */
  1078. tmp = (info->var.vmode & FB_VMODE_INTERLACED) ? 0x84 : 0x80;
  1079. /* enable access extended memory */
  1080. write3X4(par, CRTCModuleTest, tmp);
  1081. tmp = read3CE(par, MiscIntContReg) & ~0x4;
  1082. if (info->var.vmode & FB_VMODE_INTERLACED)
  1083. tmp |= 0x4;
  1084. write3CE(par, MiscIntContReg, tmp);
  1085. /* enable GE for text acceleration */
  1086. write3X4(par, GraphEngReg, 0x80);
  1087. switch (bpp) {
  1088. case 8:
  1089. tmp = 0x00;
  1090. break;
  1091. case 16:
  1092. tmp = 0x05;
  1093. break;
  1094. case 24:
  1095. tmp = 0x29;
  1096. break;
  1097. case 32:
  1098. tmp = 0x09;
  1099. break;
  1100. }
  1101. write3X4(par, PixelBusReg, tmp);
  1102. tmp = read3X4(par, DRAMControl);
  1103. if (!is_oldprotect(par->chip_id))
  1104. tmp |= 0x10;
  1105. if (iscyber(par->chip_id))
  1106. tmp |= 0x20;
  1107. write3X4(par, DRAMControl, tmp); /* both IO, linear enable */
  1108. write3X4(par, InterfaceSel, read3X4(par, InterfaceSel) | 0x40);
  1109. if (!is_xp(par->chip_id))
  1110. write3X4(par, Performance, read3X4(par, Performance) | 0x10);
  1111. /* MMIO & PCI read and write burst enable */
  1112. if (par->chip_id != TGUI9440 && par->chip_id != IMAGE975)
  1113. write3X4(par, PCIReg, read3X4(par, PCIReg) | 0x06);
  1114. vga_mm_wseq(par->io_virt, 0, 3);
  1115. vga_mm_wseq(par->io_virt, 1, 1); /* set char clock 8 dots wide */
  1116. /* enable 4 maps because needed in chain4 mode */
  1117. vga_mm_wseq(par->io_virt, 2, 0x0F);
  1118. vga_mm_wseq(par->io_virt, 3, 0);
  1119. vga_mm_wseq(par->io_virt, 4, 0x0E); /* memory mode enable bitmaps ?? */
  1120. /* convert from picoseconds to kHz */
  1121. vclk = PICOS2KHZ(info->var.pixclock);
  1122. /* divide clock by 2 if 32bpp chain4 mode display and CPU path */
  1123. tmp = read3CE(par, MiscExtFunc) & 0xF0;
  1124. if (bpp == 32 || (par->chip_id == TGUI9440 && bpp == 16)) {
  1125. tmp |= 8;
  1126. vclk *= 2;
  1127. }
  1128. set_vclk(par, vclk);
  1129. write3CE(par, MiscExtFunc, tmp | 0x12);
  1130. write3CE(par, 0x5, 0x40); /* no CGA compat, allow 256 col */
  1131. write3CE(par, 0x6, 0x05); /* graphics mode */
  1132. write3CE(par, 0x7, 0x0F); /* planes? */
  1133. /* graphics mode and support 256 color modes */
  1134. writeAttr(par, 0x10, 0x41);
  1135. writeAttr(par, 0x12, 0x0F); /* planes */
  1136. writeAttr(par, 0x13, 0); /* horizontal pel panning */
  1137. /* colors */
  1138. for (tmp = 0; tmp < 0x10; tmp++)
  1139. writeAttr(par, tmp, tmp);
  1140. fb_readb(par->io_virt + VGA_IS1_RC); /* flip-flop to index */
  1141. t_outb(par, 0x20, VGA_ATT_W); /* enable attr */
  1142. switch (bpp) {
  1143. case 8:
  1144. tmp = 0;
  1145. break;
  1146. case 16:
  1147. tmp = 0x30;
  1148. break;
  1149. case 24:
  1150. case 32:
  1151. tmp = 0xD0;
  1152. break;
  1153. }
  1154. t_inb(par, VGA_PEL_IW);
  1155. t_inb(par, VGA_PEL_MSK);
  1156. t_inb(par, VGA_PEL_MSK);
  1157. t_inb(par, VGA_PEL_MSK);
  1158. t_inb(par, VGA_PEL_MSK);
  1159. t_outb(par, tmp, VGA_PEL_MSK);
  1160. t_inb(par, VGA_PEL_IW);
  1161. if (par->flatpanel)
  1162. set_number_of_lines(par, info->var.yres);
  1163. info->fix.line_length = info->var.xres_virtual * bpp / 8;
  1164. set_lwidth(par, info->fix.line_length / 8);
  1165. if (!(info->flags & FBINFO_HWACCEL_DISABLED))
  1166. par->init_accel(par, info->var.xres_virtual, bpp);
  1167. info->fix.visual = (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
  1168. info->cmap.len = (bpp == 8) ? 256 : 16;
  1169. debug("exit\n");
  1170. return 0;
  1171. }
  1172. /* Set one color register */
  1173. static int tridentfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  1174. unsigned blue, unsigned transp,
  1175. struct fb_info *info)
  1176. {
  1177. int bpp = info->var.bits_per_pixel;
  1178. struct tridentfb_par *par = info->par;
  1179. if (regno >= info->cmap.len)
  1180. return 1;
  1181. if (bpp == 8) {
  1182. t_outb(par, 0xFF, VGA_PEL_MSK);
  1183. t_outb(par, regno, VGA_PEL_IW);
  1184. t_outb(par, red >> 10, VGA_PEL_D);
  1185. t_outb(par, green >> 10, VGA_PEL_D);
  1186. t_outb(par, blue >> 10, VGA_PEL_D);
  1187. } else if (regno < 16) {
  1188. if (bpp == 16) { /* RGB 565 */
  1189. u32 col;
  1190. col = (red & 0xF800) | ((green & 0xFC00) >> 5) |
  1191. ((blue & 0xF800) >> 11);
  1192. col |= col << 16;
  1193. ((u32 *)(info->pseudo_palette))[regno] = col;
  1194. } else if (bpp == 32) /* ARGB 8888 */
  1195. ((u32 *)info->pseudo_palette)[regno] =
  1196. ((transp & 0xFF00) << 16) |
  1197. ((red & 0xFF00) << 8) |
  1198. ((green & 0xFF00)) |
  1199. ((blue & 0xFF00) >> 8);
  1200. }
  1201. return 0;
  1202. }
  1203. /* Try blanking the screen. For flat panels it does nothing */
  1204. static int tridentfb_blank(int blank_mode, struct fb_info *info)
  1205. {
  1206. unsigned char PMCont, DPMSCont;
  1207. struct tridentfb_par *par = info->par;
  1208. debug("enter\n");
  1209. if (par->flatpanel)
  1210. return 0;
  1211. t_outb(par, 0x04, 0x83C8); /* Read DPMS Control */
  1212. PMCont = t_inb(par, 0x83C6) & 0xFC;
  1213. DPMSCont = read3CE(par, PowerStatus) & 0xFC;
  1214. switch (blank_mode) {
  1215. case FB_BLANK_UNBLANK:
  1216. /* Screen: On, HSync: On, VSync: On */
  1217. case FB_BLANK_NORMAL:
  1218. /* Screen: Off, HSync: On, VSync: On */
  1219. PMCont |= 0x03;
  1220. DPMSCont |= 0x00;
  1221. break;
  1222. case FB_BLANK_HSYNC_SUSPEND:
  1223. /* Screen: Off, HSync: Off, VSync: On */
  1224. PMCont |= 0x02;
  1225. DPMSCont |= 0x01;
  1226. break;
  1227. case FB_BLANK_VSYNC_SUSPEND:
  1228. /* Screen: Off, HSync: On, VSync: Off */
  1229. PMCont |= 0x02;
  1230. DPMSCont |= 0x02;
  1231. break;
  1232. case FB_BLANK_POWERDOWN:
  1233. /* Screen: Off, HSync: Off, VSync: Off */
  1234. PMCont |= 0x00;
  1235. DPMSCont |= 0x03;
  1236. break;
  1237. }
  1238. write3CE(par, PowerStatus, DPMSCont);
  1239. t_outb(par, 4, 0x83C8);
  1240. t_outb(par, PMCont, 0x83C6);
  1241. debug("exit\n");
  1242. /* let fbcon do a softblank for us */
  1243. return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0;
  1244. }
  1245. static struct fb_ops tridentfb_ops = {
  1246. .owner = THIS_MODULE,
  1247. .fb_setcolreg = tridentfb_setcolreg,
  1248. .fb_pan_display = tridentfb_pan_display,
  1249. .fb_blank = tridentfb_blank,
  1250. .fb_check_var = tridentfb_check_var,
  1251. .fb_set_par = tridentfb_set_par,
  1252. .fb_fillrect = tridentfb_fillrect,
  1253. .fb_copyarea = tridentfb_copyarea,
  1254. .fb_imageblit = tridentfb_imageblit,
  1255. .fb_sync = tridentfb_sync,
  1256. };
  1257. static int trident_pci_probe(struct pci_dev *dev,
  1258. const struct pci_device_id *id)
  1259. {
  1260. int err;
  1261. unsigned char revision;
  1262. struct fb_info *info;
  1263. struct tridentfb_par *default_par;
  1264. int chip3D;
  1265. int chip_id;
  1266. bool found = false;
  1267. err = pci_enable_device(dev);
  1268. if (err)
  1269. return err;
  1270. info = framebuffer_alloc(sizeof(struct tridentfb_par), &dev->dev);
  1271. if (!info)
  1272. return -ENOMEM;
  1273. default_par = info->par;
  1274. chip_id = id->device;
  1275. /* If PCI id is 0x9660 then further detect chip type */
  1276. if (chip_id == TGUI9660) {
  1277. revision = vga_io_rseq(RevisionID);
  1278. switch (revision) {
  1279. case 0x21:
  1280. chip_id = PROVIDIA9685;
  1281. break;
  1282. case 0x22:
  1283. case 0x23:
  1284. chip_id = CYBER9397;
  1285. break;
  1286. case 0x2A:
  1287. chip_id = CYBER9397DVD;
  1288. break;
  1289. case 0x30:
  1290. case 0x33:
  1291. case 0x34:
  1292. case 0x35:
  1293. case 0x38:
  1294. case 0x3A:
  1295. case 0xB3:
  1296. chip_id = CYBER9385;
  1297. break;
  1298. case 0x40 ... 0x43:
  1299. chip_id = CYBER9382;
  1300. break;
  1301. case 0x4A:
  1302. chip_id = CYBER9388;
  1303. break;
  1304. default:
  1305. break;
  1306. }
  1307. }
  1308. chip3D = is3Dchip(chip_id);
  1309. if (is_xp(chip_id)) {
  1310. default_par->init_accel = xp_init_accel;
  1311. default_par->wait_engine = xp_wait_engine;
  1312. default_par->fill_rect = xp_fill_rect;
  1313. default_par->copy_rect = xp_copy_rect;
  1314. tridentfb_fix.accel = FB_ACCEL_TRIDENT_BLADEXP;
  1315. } else if (is_blade(chip_id)) {
  1316. default_par->init_accel = blade_init_accel;
  1317. default_par->wait_engine = blade_wait_engine;
  1318. default_par->fill_rect = blade_fill_rect;
  1319. default_par->copy_rect = blade_copy_rect;
  1320. default_par->image_blit = blade_image_blit;
  1321. tridentfb_fix.accel = FB_ACCEL_TRIDENT_BLADE3D;
  1322. } else if (chip3D) { /* 3DImage family left */
  1323. default_par->init_accel = image_init_accel;
  1324. default_par->wait_engine = image_wait_engine;
  1325. default_par->fill_rect = image_fill_rect;
  1326. default_par->copy_rect = image_copy_rect;
  1327. tridentfb_fix.accel = FB_ACCEL_TRIDENT_3DIMAGE;
  1328. } else { /* TGUI 9440/96XX family */
  1329. default_par->init_accel = tgui_init_accel;
  1330. default_par->wait_engine = xp_wait_engine;
  1331. default_par->fill_rect = tgui_fill_rect;
  1332. default_par->copy_rect = tgui_copy_rect;
  1333. tridentfb_fix.accel = FB_ACCEL_TRIDENT_TGUI;
  1334. }
  1335. default_par->chip_id = chip_id;
  1336. /* setup MMIO region */
  1337. tridentfb_fix.mmio_start = pci_resource_start(dev, 1);
  1338. tridentfb_fix.mmio_len = pci_resource_len(dev, 1);
  1339. if (!request_mem_region(tridentfb_fix.mmio_start,
  1340. tridentfb_fix.mmio_len, "tridentfb")) {
  1341. debug("request_region failed!\n");
  1342. framebuffer_release(info);
  1343. return -1;
  1344. }
  1345. default_par->io_virt = ioremap_nocache(tridentfb_fix.mmio_start,
  1346. tridentfb_fix.mmio_len);
  1347. if (!default_par->io_virt) {
  1348. debug("ioremap failed\n");
  1349. err = -1;
  1350. goto out_unmap1;
  1351. }
  1352. enable_mmio(default_par);
  1353. /* setup framebuffer memory */
  1354. tridentfb_fix.smem_start = pci_resource_start(dev, 0);
  1355. tridentfb_fix.smem_len = get_memsize(default_par);
  1356. if (!request_mem_region(tridentfb_fix.smem_start,
  1357. tridentfb_fix.smem_len, "tridentfb")) {
  1358. debug("request_mem_region failed!\n");
  1359. disable_mmio(info->par);
  1360. err = -1;
  1361. goto out_unmap1;
  1362. }
  1363. info->screen_base = ioremap_nocache(tridentfb_fix.smem_start,
  1364. tridentfb_fix.smem_len);
  1365. if (!info->screen_base) {
  1366. debug("ioremap failed\n");
  1367. err = -1;
  1368. goto out_unmap2;
  1369. }
  1370. default_par->flatpanel = is_flatpanel(default_par);
  1371. if (default_par->flatpanel)
  1372. nativex = get_nativex(default_par);
  1373. info->fix = tridentfb_fix;
  1374. info->fbops = &tridentfb_ops;
  1375. info->pseudo_palette = default_par->pseudo_pal;
  1376. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  1377. if (!noaccel && default_par->init_accel) {
  1378. info->flags &= ~FBINFO_HWACCEL_DISABLED;
  1379. info->flags |= FBINFO_HWACCEL_COPYAREA;
  1380. info->flags |= FBINFO_HWACCEL_FILLRECT;
  1381. } else
  1382. info->flags |= FBINFO_HWACCEL_DISABLED;
  1383. if (is_blade(chip_id) && chip_id != BLADE3D)
  1384. info->flags |= FBINFO_READS_FAST;
  1385. info->pixmap.addr = kmalloc(4096, GFP_KERNEL);
  1386. if (!info->pixmap.addr) {
  1387. err = -ENOMEM;
  1388. goto out_unmap2;
  1389. }
  1390. info->pixmap.size = 4096;
  1391. info->pixmap.buf_align = 4;
  1392. info->pixmap.scan_align = 1;
  1393. info->pixmap.access_align = 32;
  1394. info->pixmap.flags = FB_PIXMAP_SYSTEM;
  1395. info->var.bits_per_pixel = 8;
  1396. if (default_par->image_blit) {
  1397. info->flags |= FBINFO_HWACCEL_IMAGEBLIT;
  1398. info->pixmap.scan_align = 4;
  1399. }
  1400. if (noaccel) {
  1401. printk(KERN_DEBUG "disabling acceleration\n");
  1402. info->flags |= FBINFO_HWACCEL_DISABLED;
  1403. info->pixmap.scan_align = 1;
  1404. }
  1405. if (tridentfb_setup_ddc_bus(info) == 0) {
  1406. u8 *edid = fb_ddc_read(&default_par->ddc_adapter);
  1407. default_par->ddc_registered = true;
  1408. if (edid) {
  1409. fb_edid_to_monspecs(edid, &info->monspecs);
  1410. kfree(edid);
  1411. if (!info->monspecs.modedb)
  1412. dev_err(info->device, "error getting mode database\n");
  1413. else {
  1414. const struct fb_videomode *m;
  1415. fb_videomode_to_modelist(info->monspecs.modedb,
  1416. info->monspecs.modedb_len,
  1417. &info->modelist);
  1418. m = fb_find_best_display(&info->monspecs,
  1419. &info->modelist);
  1420. if (m) {
  1421. fb_videomode_to_var(&info->var, m);
  1422. /* fill all other info->var's fields */
  1423. if (tridentfb_check_var(&info->var,
  1424. info) == 0)
  1425. found = true;
  1426. }
  1427. }
  1428. }
  1429. }
  1430. if (!mode_option && !found)
  1431. mode_option = "640x480-8@60";
  1432. /* Prepare startup mode */
  1433. if (mode_option) {
  1434. err = fb_find_mode(&info->var, info, mode_option,
  1435. info->monspecs.modedb,
  1436. info->monspecs.modedb_len,
  1437. NULL, info->var.bits_per_pixel);
  1438. if (!err || err == 4) {
  1439. err = -EINVAL;
  1440. dev_err(info->device, "mode %s not found\n",
  1441. mode_option);
  1442. fb_destroy_modedb(info->monspecs.modedb);
  1443. info->monspecs.modedb = NULL;
  1444. goto out_unmap2;
  1445. }
  1446. }
  1447. fb_destroy_modedb(info->monspecs.modedb);
  1448. info->monspecs.modedb = NULL;
  1449. err = fb_alloc_cmap(&info->cmap, 256, 0);
  1450. if (err < 0)
  1451. goto out_unmap2;
  1452. info->var.activate |= FB_ACTIVATE_NOW;
  1453. info->device = &dev->dev;
  1454. if (register_framebuffer(info) < 0) {
  1455. printk(KERN_ERR "tridentfb: could not register framebuffer\n");
  1456. fb_dealloc_cmap(&info->cmap);
  1457. err = -EINVAL;
  1458. goto out_unmap2;
  1459. }
  1460. output("fb%d: %s frame buffer device %dx%d-%dbpp\n",
  1461. info->node, info->fix.id, info->var.xres,
  1462. info->var.yres, info->var.bits_per_pixel);
  1463. pci_set_drvdata(dev, info);
  1464. return 0;
  1465. out_unmap2:
  1466. if (default_par->ddc_registered)
  1467. i2c_del_adapter(&default_par->ddc_adapter);
  1468. kfree(info->pixmap.addr);
  1469. if (info->screen_base)
  1470. iounmap(info->screen_base);
  1471. release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
  1472. disable_mmio(info->par);
  1473. out_unmap1:
  1474. if (default_par->io_virt)
  1475. iounmap(default_par->io_virt);
  1476. release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
  1477. framebuffer_release(info);
  1478. return err;
  1479. }
  1480. static void trident_pci_remove(struct pci_dev *dev)
  1481. {
  1482. struct fb_info *info = pci_get_drvdata(dev);
  1483. struct tridentfb_par *par = info->par;
  1484. unregister_framebuffer(info);
  1485. if (par->ddc_registered)
  1486. i2c_del_adapter(&par->ddc_adapter);
  1487. iounmap(par->io_virt);
  1488. iounmap(info->screen_base);
  1489. release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
  1490. release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
  1491. kfree(info->pixmap.addr);
  1492. fb_dealloc_cmap(&info->cmap);
  1493. framebuffer_release(info);
  1494. }
  1495. /* List of boards that we are trying to support */
  1496. static struct pci_device_id trident_devices[] = {
  1497. {PCI_VENDOR_ID_TRIDENT, BLADE3D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1498. {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1499. {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi7D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1500. {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1501. {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1502. {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1503. {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1504. {PCI_VENDOR_ID_TRIDENT, CYBERBLADEE4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1505. {PCI_VENDOR_ID_TRIDENT, TGUI9440, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1506. {PCI_VENDOR_ID_TRIDENT, TGUI9660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1507. {PCI_VENDOR_ID_TRIDENT, IMAGE975, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1508. {PCI_VENDOR_ID_TRIDENT, IMAGE985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1509. {PCI_VENDOR_ID_TRIDENT, CYBER9320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1510. {PCI_VENDOR_ID_TRIDENT, CYBER9388, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1511. {PCI_VENDOR_ID_TRIDENT, CYBER9520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1512. {PCI_VENDOR_ID_TRIDENT, CYBER9525DVD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1513. {PCI_VENDOR_ID_TRIDENT, CYBER9397, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1514. {PCI_VENDOR_ID_TRIDENT, CYBER9397DVD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1515. {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1516. {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPm8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1517. {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPm16, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1518. {0,}
  1519. };
  1520. MODULE_DEVICE_TABLE(pci, trident_devices);
  1521. static struct pci_driver tridentfb_pci_driver = {
  1522. .name = "tridentfb",
  1523. .id_table = trident_devices,
  1524. .probe = trident_pci_probe,
  1525. .remove = trident_pci_remove,
  1526. };
  1527. /*
  1528. * Parse user specified options (`video=trident:')
  1529. * example:
  1530. * video=trident:800x600,bpp=16,noaccel
  1531. */
  1532. #ifndef MODULE
  1533. static int __init tridentfb_setup(char *options)
  1534. {
  1535. char *opt;
  1536. if (!options || !*options)
  1537. return 0;
  1538. while ((opt = strsep(&options, ",")) != NULL) {
  1539. if (!*opt)
  1540. continue;
  1541. if (!strncmp(opt, "noaccel", 7))
  1542. noaccel = 1;
  1543. else if (!strncmp(opt, "fp", 2))
  1544. fp = 1;
  1545. else if (!strncmp(opt, "crt", 3))
  1546. fp = 0;
  1547. else if (!strncmp(opt, "bpp=", 4))
  1548. bpp = simple_strtoul(opt + 4, NULL, 0);
  1549. else if (!strncmp(opt, "center", 6))
  1550. center = 1;
  1551. else if (!strncmp(opt, "stretch", 7))
  1552. stretch = 1;
  1553. else if (!strncmp(opt, "memsize=", 8))
  1554. memsize = simple_strtoul(opt + 8, NULL, 0);
  1555. else if (!strncmp(opt, "memdiff=", 8))
  1556. memdiff = simple_strtoul(opt + 8, NULL, 0);
  1557. else if (!strncmp(opt, "nativex=", 8))
  1558. nativex = simple_strtoul(opt + 8, NULL, 0);
  1559. else
  1560. mode_option = opt;
  1561. }
  1562. return 0;
  1563. }
  1564. #endif
  1565. static int __init tridentfb_init(void)
  1566. {
  1567. #ifndef MODULE
  1568. char *option = NULL;
  1569. if (fb_get_options("tridentfb", &option))
  1570. return -ENODEV;
  1571. tridentfb_setup(option);
  1572. #endif
  1573. return pci_register_driver(&tridentfb_pci_driver);
  1574. }
  1575. static void __exit tridentfb_exit(void)
  1576. {
  1577. pci_unregister_driver(&tridentfb_pci_driver);
  1578. }
  1579. module_init(tridentfb_init);
  1580. module_exit(tridentfb_exit);
  1581. MODULE_AUTHOR("Jani Monoses <jani@iv.ro>");
  1582. MODULE_DESCRIPTION("Framebuffer driver for Trident cards");
  1583. MODULE_LICENSE("GPL");
  1584. MODULE_ALIAS("cyblafb");