pm2fb.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612
  1. /*
  2. * Permedia2 framebuffer driver.
  3. *
  4. * 2.5/2.6 driver:
  5. * Copyright (c) 2003 Jim Hague (jim.hague@acm.org)
  6. *
  7. * based on 2.4 driver:
  8. * Copyright (c) 1998-2000 Ilario Nardinocchi (nardinoc@CS.UniBO.IT)
  9. * Copyright (c) 1999 Jakub Jelinek (jakub@redhat.com)
  10. *
  11. * and additional input from James Simmon's port of Hannu Mallat's tdfx
  12. * driver.
  13. *
  14. * I have a Creative Graphics Blaster Exxtreme card - pm2fb on x86. I
  15. * have no access to other pm2fb implementations. Sparc (and thus
  16. * hopefully other big-endian) devices now work, thanks to a lot of
  17. * testing work by Ron Murray. I have no access to CVision hardware,
  18. * and therefore for now I am omitting the CVision code.
  19. *
  20. * Multiple boards support has been on the TODO list for ages.
  21. * Don't expect this to change.
  22. *
  23. * This file is subject to the terms and conditions of the GNU General Public
  24. * License. See the file COPYING in the main directory of this archive for
  25. * more details.
  26. *
  27. *
  28. */
  29. #include <linux/module.h>
  30. #include <linux/moduleparam.h>
  31. #include <linux/kernel.h>
  32. #include <linux/errno.h>
  33. #include <linux/string.h>
  34. #include <linux/mm.h>
  35. #include <linux/slab.h>
  36. #include <linux/delay.h>
  37. #include <linux/fb.h>
  38. #include <linux/init.h>
  39. #include <linux/pci.h>
  40. #ifdef CONFIG_MTRR
  41. #include <asm/mtrr.h>
  42. #endif
  43. #include <video/permedia2.h>
  44. #include <video/cvisionppc.h>
  45. #if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
  46. #error "The endianness of the target host has not been defined."
  47. #endif
  48. #if !defined(CONFIG_PCI)
  49. #error "Only generic PCI cards supported."
  50. #endif
  51. #undef PM2FB_MASTER_DEBUG
  52. #ifdef PM2FB_MASTER_DEBUG
  53. #define DPRINTK(a, b...) \
  54. printk(KERN_DEBUG "pm2fb: %s: " a, __FUNCTION__ , ## b)
  55. #else
  56. #define DPRINTK(a, b...)
  57. #endif
  58. #define PM2_PIXMAP_SIZE (1600 * 4)
  59. /*
  60. * Driver data
  61. */
  62. static char *mode __devinitdata;
  63. /*
  64. * The XFree GLINT driver will (I think to implement hardware cursor
  65. * support on TVP4010 and similar where there is no RAMDAC - see
  66. * comment in set_video) always request +ve sync regardless of what
  67. * the mode requires. This screws me because I have a Sun
  68. * fixed-frequency monitor which absolutely has to have -ve sync. So
  69. * these flags allow the user to specify that requests for +ve sync
  70. * should be silently turned in -ve sync.
  71. */
  72. static int lowhsync;
  73. static int lowvsync;
  74. static int noaccel __devinitdata;
  75. /* mtrr option */
  76. #ifdef CONFIG_MTRR
  77. static int nomtrr __devinitdata;
  78. #endif
  79. /*
  80. * The hardware state of the graphics card that isn't part of the
  81. * screeninfo.
  82. */
  83. struct pm2fb_par
  84. {
  85. pm2type_t type; /* Board type */
  86. unsigned char __iomem *v_regs;/* virtual address of p_regs */
  87. u32 memclock; /* memclock */
  88. u32 video; /* video flags before blanking */
  89. u32 mem_config; /* MemConfig reg at probe */
  90. u32 mem_control; /* MemControl reg at probe */
  91. u32 boot_address; /* BootAddress reg at probe */
  92. u32 palette[16];
  93. int mtrr_handle;
  94. };
  95. /*
  96. * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
  97. * if we don't use modedb.
  98. */
  99. static struct fb_fix_screeninfo pm2fb_fix __devinitdata = {
  100. .id = "",
  101. .type = FB_TYPE_PACKED_PIXELS,
  102. .visual = FB_VISUAL_PSEUDOCOLOR,
  103. .xpanstep = 1,
  104. .ypanstep = 1,
  105. .ywrapstep = 0,
  106. .accel = FB_ACCEL_3DLABS_PERMEDIA2,
  107. };
  108. /*
  109. * Default video mode. In case the modedb doesn't work.
  110. */
  111. static struct fb_var_screeninfo pm2fb_var __devinitdata = {
  112. /* "640x480, 8 bpp @ 60 Hz */
  113. .xres = 640,
  114. .yres = 480,
  115. .xres_virtual = 640,
  116. .yres_virtual = 480,
  117. .bits_per_pixel = 8,
  118. .red = {0, 8, 0},
  119. .blue = {0, 8, 0},
  120. .green = {0, 8, 0},
  121. .activate = FB_ACTIVATE_NOW,
  122. .height = -1,
  123. .width = -1,
  124. .accel_flags = 0,
  125. .pixclock = 39721,
  126. .left_margin = 40,
  127. .right_margin = 24,
  128. .upper_margin = 32,
  129. .lower_margin = 11,
  130. .hsync_len = 96,
  131. .vsync_len = 2,
  132. .vmode = FB_VMODE_NONINTERLACED
  133. };
  134. /*
  135. * Utility functions
  136. */
  137. static inline u32 pm2_RD(struct pm2fb_par *p, s32 off)
  138. {
  139. return fb_readl(p->v_regs + off);
  140. }
  141. static inline void pm2_WR(struct pm2fb_par *p, s32 off, u32 v)
  142. {
  143. fb_writel(v, p->v_regs + off);
  144. }
  145. static inline u32 pm2_RDAC_RD(struct pm2fb_par *p, s32 idx)
  146. {
  147. pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, idx);
  148. mb();
  149. return pm2_RD(p, PM2R_RD_INDEXED_DATA);
  150. }
  151. static inline u32 pm2v_RDAC_RD(struct pm2fb_par *p, s32 idx)
  152. {
  153. pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff);
  154. mb();
  155. return pm2_RD(p, PM2VR_RD_INDEXED_DATA);
  156. }
  157. static inline void pm2_RDAC_WR(struct pm2fb_par *p, s32 idx, u32 v)
  158. {
  159. pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, idx);
  160. wmb();
  161. pm2_WR(p, PM2R_RD_INDEXED_DATA, v);
  162. wmb();
  163. }
  164. static inline void pm2v_RDAC_WR(struct pm2fb_par *p, s32 idx, u32 v)
  165. {
  166. pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff);
  167. wmb();
  168. pm2_WR(p, PM2VR_RD_INDEXED_DATA, v);
  169. wmb();
  170. }
  171. #ifdef CONFIG_FB_PM2_FIFO_DISCONNECT
  172. #define WAIT_FIFO(p, a)
  173. #else
  174. static inline void WAIT_FIFO(struct pm2fb_par *p, u32 a)
  175. {
  176. while (pm2_RD(p, PM2R_IN_FIFO_SPACE) < a);
  177. mb();
  178. }
  179. #endif
  180. /*
  181. * partial products for the supported horizontal resolutions.
  182. */
  183. #define PACKPP(p0, p1, p2) (((p2) << 6) | ((p1) << 3) | (p0))
  184. static const struct {
  185. u16 width;
  186. u16 pp;
  187. } pp_table[] = {
  188. { 32, PACKPP(1, 0, 0) }, { 64, PACKPP(1, 1, 0) },
  189. { 96, PACKPP(1, 1, 1) }, { 128, PACKPP(2, 1, 1) },
  190. { 160, PACKPP(2, 2, 1) }, { 192, PACKPP(2, 2, 2) },
  191. { 224, PACKPP(3, 2, 1) }, { 256, PACKPP(3, 2, 2) },
  192. { 288, PACKPP(3, 3, 1) }, { 320, PACKPP(3, 3, 2) },
  193. { 384, PACKPP(3, 3, 3) }, { 416, PACKPP(4, 3, 1) },
  194. { 448, PACKPP(4, 3, 2) }, { 512, PACKPP(4, 3, 3) },
  195. { 544, PACKPP(4, 4, 1) }, { 576, PACKPP(4, 4, 2) },
  196. { 640, PACKPP(4, 4, 3) }, { 768, PACKPP(4, 4, 4) },
  197. { 800, PACKPP(5, 4, 1) }, { 832, PACKPP(5, 4, 2) },
  198. { 896, PACKPP(5, 4, 3) }, { 1024, PACKPP(5, 4, 4) },
  199. { 1056, PACKPP(5, 5, 1) }, { 1088, PACKPP(5, 5, 2) },
  200. { 1152, PACKPP(5, 5, 3) }, { 1280, PACKPP(5, 5, 4) },
  201. { 1536, PACKPP(5, 5, 5) }, { 1568, PACKPP(6, 5, 1) },
  202. { 1600, PACKPP(6, 5, 2) }, { 1664, PACKPP(6, 5, 3) },
  203. { 1792, PACKPP(6, 5, 4) }, { 2048, PACKPP(6, 5, 5) },
  204. { 0, 0 } };
  205. static u32 partprod(u32 xres)
  206. {
  207. int i;
  208. for (i = 0; pp_table[i].width && pp_table[i].width != xres; i++)
  209. ;
  210. if (pp_table[i].width == 0)
  211. DPRINTK("invalid width %u\n", xres);
  212. return pp_table[i].pp;
  213. }
  214. static u32 to3264(u32 timing, int bpp, int is64)
  215. {
  216. switch (bpp) {
  217. case 24:
  218. timing *= 3;
  219. case 8:
  220. timing >>= 1;
  221. case 16:
  222. timing >>= 1;
  223. case 32:
  224. break;
  225. }
  226. if (is64)
  227. timing >>= 1;
  228. return timing;
  229. }
  230. static void pm2_mnp(u32 clk, unsigned char *mm, unsigned char *nn,
  231. unsigned char *pp)
  232. {
  233. unsigned char m;
  234. unsigned char n;
  235. unsigned char p;
  236. u32 f;
  237. s32 curr;
  238. s32 delta = 100000;
  239. *mm = *nn = *pp = 0;
  240. for (n = 2; n < 15; n++) {
  241. for (m = 2; m; m++) {
  242. f = PM2_REFERENCE_CLOCK * m / n;
  243. if (f >= 150000 && f <= 300000) {
  244. for (p = 0; p < 5; p++, f >>= 1) {
  245. curr = (clk > f) ? clk - f : f - clk;
  246. if (curr < delta) {
  247. delta = curr;
  248. *mm = m;
  249. *nn = n;
  250. *pp = p;
  251. }
  252. }
  253. }
  254. }
  255. }
  256. }
  257. static void pm2v_mnp(u32 clk, unsigned char *mm, unsigned char *nn,
  258. unsigned char *pp)
  259. {
  260. unsigned char m;
  261. unsigned char n;
  262. unsigned char p;
  263. u32 f;
  264. s32 delta = 1000;
  265. *mm = *nn = *pp = 0;
  266. for (m = 1; m < 128; m++) {
  267. for (n = 2 * m + 1; n; n++) {
  268. for (p = 0; p < 2; p++) {
  269. f = (PM2_REFERENCE_CLOCK >> (p + 1)) * n / m;
  270. if (clk > f - delta && clk < f + delta) {
  271. delta = (clk > f) ? clk - f : f - clk;
  272. *mm = m;
  273. *nn = n;
  274. *pp = p;
  275. }
  276. }
  277. }
  278. }
  279. }
  280. static void clear_palette(struct pm2fb_par *p)
  281. {
  282. int i = 256;
  283. WAIT_FIFO(p, 1);
  284. pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, 0);
  285. wmb();
  286. while (i--) {
  287. WAIT_FIFO(p, 3);
  288. pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
  289. pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
  290. pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
  291. }
  292. }
  293. static void reset_card(struct pm2fb_par *p)
  294. {
  295. if (p->type == PM2_TYPE_PERMEDIA2V)
  296. pm2_WR(p, PM2VR_RD_INDEX_HIGH, 0);
  297. pm2_WR(p, PM2R_RESET_STATUS, 0);
  298. mb();
  299. while (pm2_RD(p, PM2R_RESET_STATUS) & PM2F_BEING_RESET)
  300. ;
  301. mb();
  302. #ifdef CONFIG_FB_PM2_FIFO_DISCONNECT
  303. DPRINTK("FIFO disconnect enabled\n");
  304. pm2_WR(p, PM2R_FIFO_DISCON, 1);
  305. mb();
  306. #endif
  307. /* Restore stashed memory config information from probe */
  308. WAIT_FIFO(p, 3);
  309. pm2_WR(p, PM2R_MEM_CONTROL, p->mem_control);
  310. pm2_WR(p, PM2R_BOOT_ADDRESS, p->boot_address);
  311. wmb();
  312. pm2_WR(p, PM2R_MEM_CONFIG, p->mem_config);
  313. }
  314. static void reset_config(struct pm2fb_par *p)
  315. {
  316. WAIT_FIFO(p, 53);
  317. pm2_WR(p, PM2R_CHIP_CONFIG, pm2_RD(p, PM2R_CHIP_CONFIG) &
  318. ~(PM2F_VGA_ENABLE | PM2F_VGA_FIXED));
  319. pm2_WR(p, PM2R_BYPASS_WRITE_MASK, ~(0L));
  320. pm2_WR(p, PM2R_FRAMEBUFFER_WRITE_MASK, ~(0L));
  321. pm2_WR(p, PM2R_FIFO_CONTROL, 0);
  322. pm2_WR(p, PM2R_APERTURE_ONE, 0);
  323. pm2_WR(p, PM2R_APERTURE_TWO, 0);
  324. pm2_WR(p, PM2R_RASTERIZER_MODE, 0);
  325. pm2_WR(p, PM2R_DELTA_MODE, PM2F_DELTA_ORDER_RGB);
  326. pm2_WR(p, PM2R_LB_READ_FORMAT, 0);
  327. pm2_WR(p, PM2R_LB_WRITE_FORMAT, 0);
  328. pm2_WR(p, PM2R_LB_READ_MODE, 0);
  329. pm2_WR(p, PM2R_LB_SOURCE_OFFSET, 0);
  330. pm2_WR(p, PM2R_FB_SOURCE_OFFSET, 0);
  331. pm2_WR(p, PM2R_FB_PIXEL_OFFSET, 0);
  332. pm2_WR(p, PM2R_FB_WINDOW_BASE, 0);
  333. pm2_WR(p, PM2R_LB_WINDOW_BASE, 0);
  334. pm2_WR(p, PM2R_FB_SOFT_WRITE_MASK, ~(0L));
  335. pm2_WR(p, PM2R_FB_HARD_WRITE_MASK, ~(0L));
  336. pm2_WR(p, PM2R_FB_READ_PIXEL, 0);
  337. pm2_WR(p, PM2R_DITHER_MODE, 0);
  338. pm2_WR(p, PM2R_AREA_STIPPLE_MODE, 0);
  339. pm2_WR(p, PM2R_DEPTH_MODE, 0);
  340. pm2_WR(p, PM2R_STENCIL_MODE, 0);
  341. pm2_WR(p, PM2R_TEXTURE_ADDRESS_MODE, 0);
  342. pm2_WR(p, PM2R_TEXTURE_READ_MODE, 0);
  343. pm2_WR(p, PM2R_TEXEL_LUT_MODE, 0);
  344. pm2_WR(p, PM2R_YUV_MODE, 0);
  345. pm2_WR(p, PM2R_COLOR_DDA_MODE, 0);
  346. pm2_WR(p, PM2R_TEXTURE_COLOR_MODE, 0);
  347. pm2_WR(p, PM2R_FOG_MODE, 0);
  348. pm2_WR(p, PM2R_ALPHA_BLEND_MODE, 0);
  349. pm2_WR(p, PM2R_LOGICAL_OP_MODE, 0);
  350. pm2_WR(p, PM2R_STATISTICS_MODE, 0);
  351. pm2_WR(p, PM2R_SCISSOR_MODE, 0);
  352. pm2_WR(p, PM2R_FILTER_MODE, PM2F_SYNCHRONIZATION);
  353. pm2_WR(p, PM2R_RD_PIXEL_MASK, 0xff);
  354. switch (p->type) {
  355. case PM2_TYPE_PERMEDIA2:
  356. pm2_RDAC_WR(p, PM2I_RD_MODE_CONTROL, 0); /* no overlay */
  357. pm2_RDAC_WR(p, PM2I_RD_CURSOR_CONTROL, 0);
  358. pm2_RDAC_WR(p, PM2I_RD_MISC_CONTROL, PM2F_RD_PALETTE_WIDTH_8);
  359. pm2_RDAC_WR(p, PM2I_RD_COLOR_KEY_CONTROL, 0);
  360. pm2_RDAC_WR(p, PM2I_RD_OVERLAY_KEY, 0);
  361. pm2_RDAC_WR(p, PM2I_RD_RED_KEY, 0);
  362. pm2_RDAC_WR(p, PM2I_RD_GREEN_KEY, 0);
  363. pm2_RDAC_WR(p, PM2I_RD_BLUE_KEY, 0);
  364. break;
  365. case PM2_TYPE_PERMEDIA2V:
  366. pm2v_RDAC_WR(p, PM2VI_RD_MISC_CONTROL, 1); /* 8bit */
  367. break;
  368. }
  369. }
  370. static void set_aperture(struct pm2fb_par *p, u32 depth)
  371. {
  372. /*
  373. * The hardware is little-endian. When used in big-endian
  374. * hosts, the on-chip aperture settings are used where
  375. * possible to translate from host to card byte order.
  376. */
  377. WAIT_FIFO(p, 2);
  378. #ifdef __LITTLE_ENDIAN
  379. pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_STANDARD);
  380. #else
  381. switch (depth) {
  382. case 24: /* RGB->BGR */
  383. /*
  384. * We can't use the aperture to translate host to
  385. * card byte order here, so we switch to BGR mode
  386. * in pm2fb_set_par().
  387. */
  388. case 8: /* B->B */
  389. pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_STANDARD);
  390. break;
  391. case 16: /* HL->LH */
  392. pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_HALFWORDSWAP);
  393. break;
  394. case 32: /* RGBA->ABGR */
  395. pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_BYTESWAP);
  396. break;
  397. }
  398. #endif
  399. /* We don't use aperture two, so this may be superflous */
  400. pm2_WR(p, PM2R_APERTURE_TWO, PM2F_APERTURE_STANDARD);
  401. }
  402. static void set_color(struct pm2fb_par *p, unsigned char regno,
  403. unsigned char r, unsigned char g, unsigned char b)
  404. {
  405. WAIT_FIFO(p, 4);
  406. pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, regno);
  407. wmb();
  408. pm2_WR(p, PM2R_RD_PALETTE_DATA, r);
  409. wmb();
  410. pm2_WR(p, PM2R_RD_PALETTE_DATA, g);
  411. wmb();
  412. pm2_WR(p, PM2R_RD_PALETTE_DATA, b);
  413. }
  414. static void set_memclock(struct pm2fb_par *par, u32 clk)
  415. {
  416. int i;
  417. unsigned char m, n, p;
  418. switch (par->type) {
  419. case PM2_TYPE_PERMEDIA2V:
  420. pm2v_mnp(clk/2, &m, &n, &p);
  421. WAIT_FIFO(par, 12);
  422. pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_MCLK_CONTROL >> 8);
  423. pm2v_RDAC_WR(par, PM2VI_RD_MCLK_CONTROL, 0);
  424. pm2v_RDAC_WR(par, PM2VI_RD_MCLK_PRESCALE, m);
  425. pm2v_RDAC_WR(par, PM2VI_RD_MCLK_FEEDBACK, n);
  426. pm2v_RDAC_WR(par, PM2VI_RD_MCLK_POSTSCALE, p);
  427. pm2v_RDAC_WR(par, PM2VI_RD_MCLK_CONTROL, 1);
  428. rmb();
  429. for (i = 256; i; i--)
  430. if (pm2v_RDAC_RD(par, PM2VI_RD_MCLK_CONTROL) & 2)
  431. break;
  432. pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
  433. break;
  434. case PM2_TYPE_PERMEDIA2:
  435. pm2_mnp(clk, &m, &n, &p);
  436. WAIT_FIFO(par, 10);
  437. pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 6);
  438. pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_1, m);
  439. pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_2, n);
  440. pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 8|p);
  441. pm2_RDAC_RD(par, PM2I_RD_MEMORY_CLOCK_STATUS);
  442. rmb();
  443. for (i = 256; i; i--)
  444. if (pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED)
  445. break;
  446. break;
  447. }
  448. }
  449. static void set_pixclock(struct pm2fb_par *par, u32 clk)
  450. {
  451. int i;
  452. unsigned char m, n, p;
  453. switch (par->type) {
  454. case PM2_TYPE_PERMEDIA2:
  455. pm2_mnp(clk, &m, &n, &p);
  456. WAIT_FIFO(par, 10);
  457. pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A3, 0);
  458. pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A1, m);
  459. pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A2, n);
  460. pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A3, 8|p);
  461. pm2_RDAC_RD(par, PM2I_RD_PIXEL_CLOCK_STATUS);
  462. rmb();
  463. for (i = 256; i; i--)
  464. if (pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED)
  465. break;
  466. break;
  467. case PM2_TYPE_PERMEDIA2V:
  468. pm2v_mnp(clk/2, &m, &n, &p);
  469. WAIT_FIFO(par, 8);
  470. pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_CLK0_PRESCALE >> 8);
  471. pm2v_RDAC_WR(par, PM2VI_RD_CLK0_PRESCALE, m);
  472. pm2v_RDAC_WR(par, PM2VI_RD_CLK0_FEEDBACK, n);
  473. pm2v_RDAC_WR(par, PM2VI_RD_CLK0_POSTSCALE, p);
  474. pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
  475. break;
  476. }
  477. }
  478. static void set_video(struct pm2fb_par *p, u32 video)
  479. {
  480. u32 tmp;
  481. u32 vsync = video;
  482. DPRINTK("video = 0x%x\n", video);
  483. /*
  484. * The hardware cursor needs +vsync to recognise vert retrace.
  485. * We may not be using the hardware cursor, but the X Glint
  486. * driver may well. So always set +hsync/+vsync and then set
  487. * the RAMDAC to invert the sync if necessary.
  488. */
  489. vsync &= ~(PM2F_HSYNC_MASK | PM2F_VSYNC_MASK);
  490. vsync |= PM2F_HSYNC_ACT_HIGH | PM2F_VSYNC_ACT_HIGH;
  491. WAIT_FIFO(p, 3);
  492. pm2_WR(p, PM2R_VIDEO_CONTROL, vsync);
  493. switch (p->type) {
  494. case PM2_TYPE_PERMEDIA2:
  495. tmp = PM2F_RD_PALETTE_WIDTH_8;
  496. if ((video & PM2F_HSYNC_MASK) == PM2F_HSYNC_ACT_LOW)
  497. tmp |= 4; /* invert hsync */
  498. if ((video & PM2F_VSYNC_MASK) == PM2F_VSYNC_ACT_LOW)
  499. tmp |= 8; /* invert vsync */
  500. pm2_RDAC_WR(p, PM2I_RD_MISC_CONTROL, tmp);
  501. break;
  502. case PM2_TYPE_PERMEDIA2V:
  503. tmp = 0;
  504. if ((video & PM2F_HSYNC_MASK) == PM2F_HSYNC_ACT_LOW)
  505. tmp |= 1; /* invert hsync */
  506. if ((video & PM2F_VSYNC_MASK) == PM2F_VSYNC_ACT_LOW)
  507. tmp |= 4; /* invert vsync */
  508. pm2v_RDAC_WR(p, PM2VI_RD_SYNC_CONTROL, tmp);
  509. break;
  510. }
  511. }
  512. /*
  513. * pm2fb_check_var - Optional function. Validates a var passed in.
  514. * @var: frame buffer variable screen structure
  515. * @info: frame buffer structure that represents a single frame buffer
  516. *
  517. * Checks to see if the hardware supports the state requested by
  518. * var passed in.
  519. *
  520. * Returns negative errno on error, or zero on success.
  521. */
  522. static int pm2fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  523. {
  524. u32 lpitch;
  525. if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 &&
  526. var->bits_per_pixel != 24 && var->bits_per_pixel != 32) {
  527. DPRINTK("depth not supported: %u\n", var->bits_per_pixel);
  528. return -EINVAL;
  529. }
  530. if (var->xres != var->xres_virtual) {
  531. DPRINTK("virtual x resolution != "
  532. "physical x resolution not supported\n");
  533. return -EINVAL;
  534. }
  535. if (var->yres > var->yres_virtual) {
  536. DPRINTK("virtual y resolution < "
  537. "physical y resolution not possible\n");
  538. return -EINVAL;
  539. }
  540. if (var->xoffset) {
  541. DPRINTK("xoffset not supported\n");
  542. return -EINVAL;
  543. }
  544. if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
  545. DPRINTK("interlace not supported\n");
  546. return -EINVAL;
  547. }
  548. var->xres = (var->xres + 15) & ~15; /* could sometimes be 8 */
  549. lpitch = var->xres * ((var->bits_per_pixel + 7) >> 3);
  550. if (var->xres < 320 || var->xres > 1600) {
  551. DPRINTK("width not supported: %u\n", var->xres);
  552. return -EINVAL;
  553. }
  554. if (var->yres < 200 || var->yres > 1200) {
  555. DPRINTK("height not supported: %u\n", var->yres);
  556. return -EINVAL;
  557. }
  558. if (lpitch * var->yres_virtual > info->fix.smem_len) {
  559. DPRINTK("no memory for screen (%ux%ux%u)\n",
  560. var->xres, var->yres_virtual, var->bits_per_pixel);
  561. return -EINVAL;
  562. }
  563. if (PICOS2KHZ(var->pixclock) > PM2_MAX_PIXCLOCK) {
  564. DPRINTK("pixclock too high (%ldKHz)\n",
  565. PICOS2KHZ(var->pixclock));
  566. return -EINVAL;
  567. }
  568. var->transp.offset = 0;
  569. var->transp.length = 0;
  570. switch (var->bits_per_pixel) {
  571. case 8:
  572. var->red.length = 8;
  573. var->green.length = 8;
  574. var->blue.length = 8;
  575. break;
  576. case 16:
  577. var->red.offset = 11;
  578. var->red.length = 5;
  579. var->green.offset = 5;
  580. var->green.length = 6;
  581. var->blue.offset = 0;
  582. var->blue.length = 5;
  583. break;
  584. case 32:
  585. var->transp.offset = 24;
  586. var->transp.length = 8;
  587. var->red.offset = 16;
  588. var->green.offset = 8;
  589. var->blue.offset = 0;
  590. var->red.length = 8;
  591. var->green.length = 8;
  592. var->blue.length = 8;
  593. break;
  594. case 24:
  595. #ifdef __BIG_ENDIAN
  596. var->red.offset = 0;
  597. var->blue.offset = 16;
  598. #else
  599. var->red.offset = 16;
  600. var->blue.offset = 0;
  601. #endif
  602. var->green.offset = 8;
  603. var->red.length = 8;
  604. var->green.length = 8;
  605. var->blue.length = 8;
  606. break;
  607. }
  608. var->height = -1;
  609. var->width = -1;
  610. var->accel_flags = 0; /* Can't mmap if this is on */
  611. DPRINTK("Checking graphics mode at %dx%d depth %d\n",
  612. var->xres, var->yres, var->bits_per_pixel);
  613. return 0;
  614. }
  615. /**
  616. * pm2fb_set_par - Alters the hardware state.
  617. * @info: frame buffer structure that represents a single frame buffer
  618. *
  619. * Using the fb_var_screeninfo in fb_info we set the resolution of the
  620. * this particular framebuffer.
  621. */
  622. static int pm2fb_set_par(struct fb_info *info)
  623. {
  624. struct pm2fb_par *par = info->par;
  625. u32 pixclock;
  626. u32 width = (info->var.xres_virtual + 7) & ~7;
  627. u32 height = info->var.yres_virtual;
  628. u32 depth = (info->var.bits_per_pixel + 7) & ~7;
  629. u32 hsstart, hsend, hbend, htotal;
  630. u32 vsstart, vsend, vbend, vtotal;
  631. u32 stride;
  632. u32 base;
  633. u32 video = 0;
  634. u32 clrmode = PM2F_RD_COLOR_MODE_RGB | PM2F_RD_GUI_ACTIVE;
  635. u32 txtmap = 0;
  636. u32 pixsize = 0;
  637. u32 clrformat = 0;
  638. u32 misc = 1; /* 8-bit DAC */
  639. u32 xres = (info->var.xres + 31) & ~31;
  640. int data64;
  641. reset_card(par);
  642. reset_config(par);
  643. clear_palette(par);
  644. if (par->memclock)
  645. set_memclock(par, par->memclock);
  646. depth = (depth > 32) ? 32 : depth;
  647. data64 = depth > 8 || par->type == PM2_TYPE_PERMEDIA2V;
  648. pixclock = PICOS2KHZ(info->var.pixclock);
  649. if (pixclock > PM2_MAX_PIXCLOCK) {
  650. DPRINTK("pixclock too high (%uKHz)\n", pixclock);
  651. return -EINVAL;
  652. }
  653. hsstart = to3264(info->var.right_margin, depth, data64);
  654. hsend = hsstart + to3264(info->var.hsync_len, depth, data64);
  655. hbend = hsend + to3264(info->var.left_margin, depth, data64);
  656. htotal = to3264(xres, depth, data64) + hbend - 1;
  657. vsstart = (info->var.lower_margin)
  658. ? info->var.lower_margin - 1
  659. : 0; /* FIXME! */
  660. vsend = info->var.lower_margin + info->var.vsync_len - 1;
  661. vbend = info->var.lower_margin + info->var.vsync_len +
  662. info->var.upper_margin;
  663. vtotal = info->var.yres + vbend - 1;
  664. stride = to3264(width, depth, 1);
  665. base = to3264(info->var.yoffset * xres + info->var.xoffset, depth, 1);
  666. if (data64)
  667. video |= PM2F_DATA_64_ENABLE;
  668. if (info->var.sync & FB_SYNC_HOR_HIGH_ACT) {
  669. if (lowhsync) {
  670. DPRINTK("ignoring +hsync, using -hsync.\n");
  671. video |= PM2F_HSYNC_ACT_LOW;
  672. } else
  673. video |= PM2F_HSYNC_ACT_HIGH;
  674. } else
  675. video |= PM2F_HSYNC_ACT_LOW;
  676. if (info->var.sync & FB_SYNC_VERT_HIGH_ACT) {
  677. if (lowvsync) {
  678. DPRINTK("ignoring +vsync, using -vsync.\n");
  679. video |= PM2F_VSYNC_ACT_LOW;
  680. } else
  681. video |= PM2F_VSYNC_ACT_HIGH;
  682. } else
  683. video |= PM2F_VSYNC_ACT_LOW;
  684. if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
  685. DPRINTK("interlaced not supported\n");
  686. return -EINVAL;
  687. }
  688. if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE)
  689. video |= PM2F_LINE_DOUBLE;
  690. if ((info->var.activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW)
  691. video |= PM2F_VIDEO_ENABLE;
  692. par->video = video;
  693. info->fix.visual =
  694. (depth == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
  695. info->fix.line_length = info->var.xres * depth / 8;
  696. info->cmap.len = 256;
  697. /*
  698. * Settings calculated. Now write them out.
  699. */
  700. if (par->type == PM2_TYPE_PERMEDIA2V) {
  701. WAIT_FIFO(par, 1);
  702. pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
  703. }
  704. set_aperture(par, depth);
  705. mb();
  706. WAIT_FIFO(par, 19);
  707. switch (depth) {
  708. case 8:
  709. pm2_WR(par, PM2R_FB_READ_PIXEL, 0);
  710. clrformat = 0x2e;
  711. break;
  712. case 16:
  713. pm2_WR(par, PM2R_FB_READ_PIXEL, 1);
  714. clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGB565;
  715. txtmap = PM2F_TEXTEL_SIZE_16;
  716. pixsize = 1;
  717. clrformat = 0x70;
  718. misc |= 8;
  719. break;
  720. case 32:
  721. pm2_WR(par, PM2R_FB_READ_PIXEL, 2);
  722. clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGBA8888;
  723. txtmap = PM2F_TEXTEL_SIZE_32;
  724. pixsize = 2;
  725. clrformat = 0x20;
  726. misc |= 8;
  727. break;
  728. case 24:
  729. pm2_WR(par, PM2R_FB_READ_PIXEL, 4);
  730. clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGB888;
  731. txtmap = PM2F_TEXTEL_SIZE_24;
  732. pixsize = 4;
  733. clrformat = 0x20;
  734. misc |= 8;
  735. break;
  736. }
  737. pm2_WR(par, PM2R_FB_WRITE_MODE, PM2F_FB_WRITE_ENABLE);
  738. pm2_WR(par, PM2R_FB_READ_MODE, partprod(xres));
  739. pm2_WR(par, PM2R_LB_READ_MODE, partprod(xres));
  740. pm2_WR(par, PM2R_TEXTURE_MAP_FORMAT, txtmap | partprod(xres));
  741. pm2_WR(par, PM2R_H_TOTAL, htotal);
  742. pm2_WR(par, PM2R_HS_START, hsstart);
  743. pm2_WR(par, PM2R_HS_END, hsend);
  744. pm2_WR(par, PM2R_HG_END, hbend);
  745. pm2_WR(par, PM2R_HB_END, hbend);
  746. pm2_WR(par, PM2R_V_TOTAL, vtotal);
  747. pm2_WR(par, PM2R_VS_START, vsstart);
  748. pm2_WR(par, PM2R_VS_END, vsend);
  749. pm2_WR(par, PM2R_VB_END, vbend);
  750. pm2_WR(par, PM2R_SCREEN_STRIDE, stride);
  751. wmb();
  752. pm2_WR(par, PM2R_WINDOW_ORIGIN, 0);
  753. pm2_WR(par, PM2R_SCREEN_SIZE, (height << 16) | width);
  754. pm2_WR(par, PM2R_SCISSOR_MODE, PM2F_SCREEN_SCISSOR_ENABLE);
  755. wmb();
  756. pm2_WR(par, PM2R_SCREEN_BASE, base);
  757. wmb();
  758. set_video(par, video);
  759. WAIT_FIFO(par, 10);
  760. switch (par->type) {
  761. case PM2_TYPE_PERMEDIA2:
  762. pm2_RDAC_WR(par, PM2I_RD_COLOR_MODE, clrmode);
  763. pm2_RDAC_WR(par, PM2I_RD_COLOR_KEY_CONTROL,
  764. (depth == 8) ? 0 : PM2F_COLOR_KEY_TEST_OFF);
  765. break;
  766. case PM2_TYPE_PERMEDIA2V:
  767. pm2v_RDAC_WR(par, PM2VI_RD_DAC_CONTROL, 0);
  768. pm2v_RDAC_WR(par, PM2VI_RD_PIXEL_SIZE, pixsize);
  769. pm2v_RDAC_WR(par, PM2VI_RD_COLOR_FORMAT, clrformat);
  770. pm2v_RDAC_WR(par, PM2VI_RD_MISC_CONTROL, misc);
  771. pm2v_RDAC_WR(par, PM2VI_RD_OVERLAY_KEY, 0);
  772. break;
  773. }
  774. set_pixclock(par, pixclock);
  775. DPRINTK("Setting graphics mode at %dx%d depth %d\n",
  776. info->var.xres, info->var.yres, info->var.bits_per_pixel);
  777. return 0;
  778. }
  779. /**
  780. * pm2fb_setcolreg - Sets a color register.
  781. * @regno: boolean, 0 copy local, 1 get_user() function
  782. * @red: frame buffer colormap structure
  783. * @green: The green value which can be up to 16 bits wide
  784. * @blue: The blue value which can be up to 16 bits wide.
  785. * @transp: If supported the alpha value which can be up to 16 bits wide.
  786. * @info: frame buffer info structure
  787. *
  788. * Set a single color register. The values supplied have a 16 bit
  789. * magnitude which needs to be scaled in this function for the hardware.
  790. * Pretty much a direct lift from tdfxfb.c.
  791. *
  792. * Returns negative errno on error, or zero on success.
  793. */
  794. static int pm2fb_setcolreg(unsigned regno, unsigned red, unsigned green,
  795. unsigned blue, unsigned transp,
  796. struct fb_info *info)
  797. {
  798. struct pm2fb_par *par = info->par;
  799. if (regno >= info->cmap.len) /* no. of hw registers */
  800. return -EINVAL;
  801. /*
  802. * Program hardware... do anything you want with transp
  803. */
  804. /* grayscale works only partially under directcolor */
  805. /* grayscale = 0.30*R + 0.59*G + 0.11*B */
  806. if (info->var.grayscale)
  807. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  808. /* Directcolor:
  809. * var->{color}.offset contains start of bitfield
  810. * var->{color}.length contains length of bitfield
  811. * {hardwarespecific} contains width of DAC
  812. * cmap[X] is programmed to
  813. * (X << red.offset) | (X << green.offset) | (X << blue.offset)
  814. * RAMDAC[X] is programmed to (red, green, blue)
  815. *
  816. * Pseudocolor:
  817. * uses offset = 0 && length = DAC register width.
  818. * var->{color}.offset is 0
  819. * var->{color}.length contains widht of DAC
  820. * cmap is not used
  821. * DAC[X] is programmed to (red, green, blue)
  822. * Truecolor:
  823. * does not use RAMDAC (usually has 3 of them).
  824. * var->{color}.offset contains start of bitfield
  825. * var->{color}.length contains length of bitfield
  826. * cmap is programmed to
  827. * (red << red.offset) | (green << green.offset) |
  828. * (blue << blue.offset) | (transp << transp.offset)
  829. * RAMDAC does not exist
  830. */
  831. #define CNVT_TOHW(val, width) ((((val) << (width)) + 0x7FFF -(val)) >> 16)
  832. switch (info->fix.visual) {
  833. case FB_VISUAL_TRUECOLOR:
  834. case FB_VISUAL_PSEUDOCOLOR:
  835. red = CNVT_TOHW(red, info->var.red.length);
  836. green = CNVT_TOHW(green, info->var.green.length);
  837. blue = CNVT_TOHW(blue, info->var.blue.length);
  838. transp = CNVT_TOHW(transp, info->var.transp.length);
  839. break;
  840. case FB_VISUAL_DIRECTCOLOR:
  841. /* example here assumes 8 bit DAC. Might be different
  842. * for your hardware */
  843. red = CNVT_TOHW(red, 8);
  844. green = CNVT_TOHW(green, 8);
  845. blue = CNVT_TOHW(blue, 8);
  846. /* hey, there is bug in transp handling... */
  847. transp = CNVT_TOHW(transp, 8);
  848. break;
  849. }
  850. #undef CNVT_TOHW
  851. /* Truecolor has hardware independent palette */
  852. if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
  853. u32 v;
  854. if (regno >= 16)
  855. return -EINVAL;
  856. v = (red << info->var.red.offset) |
  857. (green << info->var.green.offset) |
  858. (blue << info->var.blue.offset) |
  859. (transp << info->var.transp.offset);
  860. switch (info->var.bits_per_pixel) {
  861. case 8:
  862. break;
  863. case 16:
  864. case 24:
  865. case 32:
  866. par->palette[regno] = v;
  867. break;
  868. }
  869. return 0;
  870. } else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
  871. set_color(par, regno, red, green, blue);
  872. return 0;
  873. }
  874. /**
  875. * pm2fb_pan_display - Pans the display.
  876. * @var: frame buffer variable screen structure
  877. * @info: frame buffer structure that represents a single frame buffer
  878. *
  879. * Pan (or wrap, depending on the `vmode' field) the display using the
  880. * `xoffset' and `yoffset' fields of the `var' structure.
  881. * If the values don't fit, return -EINVAL.
  882. *
  883. * Returns negative errno on error, or zero on success.
  884. *
  885. */
  886. static int pm2fb_pan_display(struct fb_var_screeninfo *var,
  887. struct fb_info *info)
  888. {
  889. struct pm2fb_par *p = info->par;
  890. u32 base;
  891. u32 depth = (var->bits_per_pixel + 7) & ~7;
  892. u32 xres = (var->xres + 31) & ~31;
  893. depth = (depth > 32) ? 32 : depth;
  894. base = to3264(var->yoffset * xres + var->xoffset, depth, 1);
  895. WAIT_FIFO(p, 1);
  896. pm2_WR(p, PM2R_SCREEN_BASE, base);
  897. return 0;
  898. }
  899. /**
  900. * pm2fb_blank - Blanks the display.
  901. * @blank_mode: the blank mode we want.
  902. * @info: frame buffer structure that represents a single frame buffer
  903. *
  904. * Blank the screen if blank_mode != 0, else unblank. Return 0 if
  905. * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
  906. * video mode which doesn't support it. Implements VESA suspend
  907. * and powerdown modes on hardware that supports disabling hsync/vsync:
  908. * blank_mode == 2: suspend vsync
  909. * blank_mode == 3: suspend hsync
  910. * blank_mode == 4: powerdown
  911. *
  912. * Returns negative errno on error, or zero on success.
  913. *
  914. */
  915. static int pm2fb_blank(int blank_mode, struct fb_info *info)
  916. {
  917. struct pm2fb_par *par = info->par;
  918. u32 video = par->video;
  919. DPRINTK("blank_mode %d\n", blank_mode);
  920. switch (blank_mode) {
  921. case FB_BLANK_UNBLANK:
  922. /* Screen: On */
  923. video |= PM2F_VIDEO_ENABLE;
  924. break;
  925. case FB_BLANK_NORMAL:
  926. /* Screen: Off */
  927. video &= ~PM2F_VIDEO_ENABLE;
  928. break;
  929. case FB_BLANK_VSYNC_SUSPEND:
  930. /* VSync: Off */
  931. video &= ~(PM2F_VSYNC_MASK | PM2F_BLANK_LOW);
  932. break;
  933. case FB_BLANK_HSYNC_SUSPEND:
  934. /* HSync: Off */
  935. video &= ~(PM2F_HSYNC_MASK | PM2F_BLANK_LOW);
  936. break;
  937. case FB_BLANK_POWERDOWN:
  938. /* HSync: Off, VSync: Off */
  939. video &= ~(PM2F_VSYNC_MASK | PM2F_HSYNC_MASK | PM2F_BLANK_LOW);
  940. break;
  941. }
  942. set_video(par, video);
  943. return 0;
  944. }
  945. static int pm2fb_sync(struct fb_info *info)
  946. {
  947. struct pm2fb_par *par = info->par;
  948. WAIT_FIFO(par, 1);
  949. pm2_WR(par, PM2R_SYNC, 0);
  950. mb();
  951. do {
  952. while (pm2_RD(par, PM2R_OUT_FIFO_WORDS) == 0)
  953. udelay(10);
  954. rmb();
  955. } while (pm2_RD(par, PM2R_OUT_FIFO) != PM2TAG(PM2R_SYNC));
  956. return 0;
  957. }
  958. static void pm2fb_fillrect(struct fb_info *info,
  959. const struct fb_fillrect *region)
  960. {
  961. struct pm2fb_par *par = info->par;
  962. struct fb_fillrect modded;
  963. int vxres, vyres;
  964. u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ?
  965. ((u32 *)info->pseudo_palette)[region->color] : region->color;
  966. if (info->state != FBINFO_STATE_RUNNING)
  967. return;
  968. if ((info->flags & FBINFO_HWACCEL_DISABLED) ||
  969. region->rop != ROP_COPY ) {
  970. cfb_fillrect(info, region);
  971. return;
  972. }
  973. vxres = info->var.xres_virtual;
  974. vyres = info->var.yres_virtual;
  975. memcpy(&modded, region, sizeof(struct fb_fillrect));
  976. if (!modded.width || !modded.height ||
  977. modded.dx >= vxres || modded.dy >= vyres)
  978. return;
  979. if (modded.dx + modded.width > vxres)
  980. modded.width = vxres - modded.dx;
  981. if (modded.dy + modded.height > vyres)
  982. modded.height = vyres - modded.dy;
  983. if (info->var.bits_per_pixel == 8)
  984. color |= color << 8;
  985. if (info->var.bits_per_pixel <= 16)
  986. color |= color << 16;
  987. WAIT_FIFO(par, 3);
  988. pm2_WR(par, PM2R_CONFIG, PM2F_CONFIG_FB_WRITE_ENABLE);
  989. pm2_WR(par, PM2R_RECTANGLE_ORIGIN, (modded.dy << 16) | modded.dx);
  990. pm2_WR(par, PM2R_RECTANGLE_SIZE, (modded.height << 16) | modded.width);
  991. if (info->var.bits_per_pixel != 24) {
  992. WAIT_FIFO(par, 2);
  993. pm2_WR(par, PM2R_FB_BLOCK_COLOR, color);
  994. wmb();
  995. pm2_WR(par, PM2R_RENDER,
  996. PM2F_RENDER_RECTANGLE | PM2F_RENDER_FASTFILL);
  997. } else {
  998. WAIT_FIFO(par, 4);
  999. pm2_WR(par, PM2R_COLOR_DDA_MODE, 1);
  1000. pm2_WR(par, PM2R_CONSTANT_COLOR, color);
  1001. wmb();
  1002. pm2_WR(par, PM2R_RENDER,
  1003. PM2F_RENDER_RECTANGLE |
  1004. PM2F_INCREASE_X | PM2F_INCREASE_Y );
  1005. pm2_WR(par, PM2R_COLOR_DDA_MODE, 0);
  1006. }
  1007. }
  1008. static void pm2fb_copyarea(struct fb_info *info,
  1009. const struct fb_copyarea *area)
  1010. {
  1011. struct pm2fb_par *par = info->par;
  1012. struct fb_copyarea modded;
  1013. u32 vxres, vyres;
  1014. if (info->state != FBINFO_STATE_RUNNING)
  1015. return;
  1016. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  1017. cfb_copyarea(info, area);
  1018. return;
  1019. }
  1020. memcpy(&modded, area, sizeof(struct fb_copyarea));
  1021. vxres = info->var.xres_virtual;
  1022. vyres = info->var.yres_virtual;
  1023. if (!modded.width || !modded.height ||
  1024. modded.sx >= vxres || modded.sy >= vyres ||
  1025. modded.dx >= vxres || modded.dy >= vyres)
  1026. return;
  1027. if (modded.sx + modded.width > vxres)
  1028. modded.width = vxres - modded.sx;
  1029. if (modded.dx + modded.width > vxres)
  1030. modded.width = vxres - modded.dx;
  1031. if (modded.sy + modded.height > vyres)
  1032. modded.height = vyres - modded.sy;
  1033. if (modded.dy + modded.height > vyres)
  1034. modded.height = vyres - modded.dy;
  1035. WAIT_FIFO(par, 5);
  1036. pm2_WR(par, PM2R_CONFIG, PM2F_CONFIG_FB_WRITE_ENABLE |
  1037. PM2F_CONFIG_FB_READ_SOURCE_ENABLE);
  1038. pm2_WR(par, PM2R_FB_SOURCE_DELTA,
  1039. ((modded.sy - modded.dy) & 0xfff) << 16 |
  1040. ((modded.sx - modded.dx) & 0xfff));
  1041. pm2_WR(par, PM2R_RECTANGLE_ORIGIN, (modded.dy << 16) | modded.dx);
  1042. pm2_WR(par, PM2R_RECTANGLE_SIZE, (modded.height << 16) | modded.width);
  1043. wmb();
  1044. pm2_WR(par, PM2R_RENDER, PM2F_RENDER_RECTANGLE |
  1045. (modded.dx < modded.sx ? PM2F_INCREASE_X : 0) |
  1046. (modded.dy < modded.sy ? PM2F_INCREASE_Y : 0));
  1047. }
  1048. static void pm2fb_imageblit(struct fb_info *info, const struct fb_image *image)
  1049. {
  1050. struct pm2fb_par *par = info->par;
  1051. u32 height = image->height;
  1052. u32 fgx, bgx;
  1053. const u32 *src = (const u32 *)image->data;
  1054. u32 xres = (info->var.xres + 31) & ~31;
  1055. if (info->state != FBINFO_STATE_RUNNING)
  1056. return;
  1057. if (info->flags & FBINFO_HWACCEL_DISABLED || image->depth != 1) {
  1058. cfb_imageblit(info, image);
  1059. return;
  1060. }
  1061. switch (info->fix.visual) {
  1062. case FB_VISUAL_PSEUDOCOLOR:
  1063. fgx = image->fg_color;
  1064. bgx = image->bg_color;
  1065. break;
  1066. case FB_VISUAL_TRUECOLOR:
  1067. default:
  1068. fgx = par->palette[image->fg_color];
  1069. bgx = par->palette[image->bg_color];
  1070. break;
  1071. }
  1072. if (info->var.bits_per_pixel == 8) {
  1073. fgx |= fgx << 8;
  1074. bgx |= bgx << 8;
  1075. }
  1076. if (info->var.bits_per_pixel <= 16) {
  1077. fgx |= fgx << 16;
  1078. bgx |= bgx << 16;
  1079. }
  1080. WAIT_FIFO(par, 13);
  1081. pm2_WR(par, PM2R_FB_READ_MODE, partprod(xres));
  1082. pm2_WR(par, PM2R_SCISSOR_MIN_XY,
  1083. ((image->dy & 0xfff) << 16) | (image->dx & 0x0fff));
  1084. pm2_WR(par, PM2R_SCISSOR_MAX_XY,
  1085. (((image->dy + image->height) & 0x0fff) << 16) |
  1086. ((image->dx + image->width) & 0x0fff));
  1087. pm2_WR(par, PM2R_SCISSOR_MODE, 1);
  1088. /* GXcopy & UNIT_ENABLE */
  1089. pm2_WR(par, PM2R_LOGICAL_OP_MODE, (0x3 << 1) | 1);
  1090. pm2_WR(par, PM2R_RECTANGLE_ORIGIN,
  1091. ((image->dy & 0xfff) << 16) | (image->dx & 0x0fff));
  1092. pm2_WR(par, PM2R_RECTANGLE_SIZE,
  1093. ((image->height & 0x0fff) << 16) |
  1094. ((image->width) & 0x0fff));
  1095. if (info->var.bits_per_pixel == 24) {
  1096. pm2_WR(par, PM2R_COLOR_DDA_MODE, 1);
  1097. /* clear area */
  1098. pm2_WR(par, PM2R_CONSTANT_COLOR, bgx);
  1099. pm2_WR(par, PM2R_RENDER,
  1100. PM2F_RENDER_RECTANGLE |
  1101. PM2F_INCREASE_X | PM2F_INCREASE_Y);
  1102. /* BitMapPackEachScanline & invert bits and byte order*/
  1103. /* force background */
  1104. pm2_WR(par, PM2R_RASTERIZER_MODE, (1 << 9) | 1 | (3 << 7));
  1105. pm2_WR(par, PM2R_CONSTANT_COLOR, fgx);
  1106. pm2_WR(par, PM2R_RENDER,
  1107. PM2F_RENDER_RECTANGLE |
  1108. PM2F_INCREASE_X | PM2F_INCREASE_Y |
  1109. PM2F_RENDER_SYNC_ON_BIT_MASK);
  1110. } else {
  1111. pm2_WR(par, PM2R_COLOR_DDA_MODE, 0);
  1112. /* clear area */
  1113. pm2_WR(par, PM2R_FB_BLOCK_COLOR, bgx);
  1114. pm2_WR(par, PM2R_RENDER,
  1115. PM2F_RENDER_RECTANGLE |
  1116. PM2F_RENDER_FASTFILL |
  1117. PM2F_INCREASE_X | PM2F_INCREASE_Y);
  1118. /* invert bits and byte order*/
  1119. pm2_WR(par, PM2R_RASTERIZER_MODE, 1 | (3 << 7));
  1120. pm2_WR(par, PM2R_FB_BLOCK_COLOR, fgx);
  1121. pm2_WR(par, PM2R_RENDER,
  1122. PM2F_RENDER_RECTANGLE |
  1123. PM2F_INCREASE_X | PM2F_INCREASE_Y |
  1124. PM2F_RENDER_FASTFILL |
  1125. PM2F_RENDER_SYNC_ON_BIT_MASK);
  1126. }
  1127. while (height--) {
  1128. int width = ((image->width + 7) >> 3)
  1129. + info->pixmap.scan_align - 1;
  1130. width >>= 2;
  1131. WAIT_FIFO(par, width);
  1132. while (width--) {
  1133. pm2_WR(par, PM2R_BIT_MASK_PATTERN, *src);
  1134. src++;
  1135. }
  1136. }
  1137. WAIT_FIFO(par, 3);
  1138. pm2_WR(par, PM2R_RASTERIZER_MODE, 0);
  1139. pm2_WR(par, PM2R_COLOR_DDA_MODE, 0);
  1140. pm2_WR(par, PM2R_SCISSOR_MODE, 0);
  1141. }
  1142. /* ------------ Hardware Independent Functions ------------ */
  1143. /*
  1144. * Frame buffer operations
  1145. */
  1146. static struct fb_ops pm2fb_ops = {
  1147. .owner = THIS_MODULE,
  1148. .fb_check_var = pm2fb_check_var,
  1149. .fb_set_par = pm2fb_set_par,
  1150. .fb_setcolreg = pm2fb_setcolreg,
  1151. .fb_blank = pm2fb_blank,
  1152. .fb_pan_display = pm2fb_pan_display,
  1153. .fb_fillrect = pm2fb_fillrect,
  1154. .fb_copyarea = pm2fb_copyarea,
  1155. .fb_imageblit = pm2fb_imageblit,
  1156. .fb_sync = pm2fb_sync,
  1157. };
  1158. /*
  1159. * PCI stuff
  1160. */
  1161. /**
  1162. * Device initialisation
  1163. *
  1164. * Initialise and allocate resource for PCI device.
  1165. *
  1166. * @param pdev PCI device.
  1167. * @param id PCI device ID.
  1168. */
  1169. static int __devinit pm2fb_probe(struct pci_dev *pdev,
  1170. const struct pci_device_id *id)
  1171. {
  1172. struct pm2fb_par *default_par;
  1173. struct fb_info *info;
  1174. int err;
  1175. int retval = -ENXIO;
  1176. err = pci_enable_device(pdev);
  1177. if (err) {
  1178. printk(KERN_WARNING "pm2fb: Can't enable pdev: %d\n", err);
  1179. return err;
  1180. }
  1181. info = framebuffer_alloc(sizeof(struct pm2fb_par), &pdev->dev);
  1182. if (!info)
  1183. return -ENOMEM;
  1184. default_par = info->par;
  1185. switch (pdev->device) {
  1186. case PCI_DEVICE_ID_TI_TVP4020:
  1187. strcpy(pm2fb_fix.id, "TVP4020");
  1188. default_par->type = PM2_TYPE_PERMEDIA2;
  1189. break;
  1190. case PCI_DEVICE_ID_3DLABS_PERMEDIA2:
  1191. strcpy(pm2fb_fix.id, "Permedia2");
  1192. default_par->type = PM2_TYPE_PERMEDIA2;
  1193. break;
  1194. case PCI_DEVICE_ID_3DLABS_PERMEDIA2V:
  1195. strcpy(pm2fb_fix.id, "Permedia2v");
  1196. default_par->type = PM2_TYPE_PERMEDIA2V;
  1197. break;
  1198. }
  1199. pm2fb_fix.mmio_start = pci_resource_start(pdev, 0);
  1200. pm2fb_fix.mmio_len = PM2_REGS_SIZE;
  1201. #if defined(__BIG_ENDIAN)
  1202. /*
  1203. * PM2 has a 64k register file, mapped twice in 128k. Lower
  1204. * map is little-endian, upper map is big-endian.
  1205. */
  1206. pm2fb_fix.mmio_start += PM2_REGS_SIZE;
  1207. DPRINTK("Adjusting register base for big-endian.\n");
  1208. #endif
  1209. DPRINTK("Register base at 0x%lx\n", pm2fb_fix.mmio_start);
  1210. /* Registers - request region and map it. */
  1211. if (!request_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len,
  1212. "pm2fb regbase")) {
  1213. printk(KERN_WARNING "pm2fb: Can't reserve regbase.\n");
  1214. goto err_exit_neither;
  1215. }
  1216. default_par->v_regs =
  1217. ioremap_nocache(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
  1218. if (!default_par->v_regs) {
  1219. printk(KERN_WARNING "pm2fb: Can't remap %s register area.\n",
  1220. pm2fb_fix.id);
  1221. release_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
  1222. goto err_exit_neither;
  1223. }
  1224. /* Stash away memory register info for use when we reset the board */
  1225. default_par->mem_control = pm2_RD(default_par, PM2R_MEM_CONTROL);
  1226. default_par->boot_address = pm2_RD(default_par, PM2R_BOOT_ADDRESS);
  1227. default_par->mem_config = pm2_RD(default_par, PM2R_MEM_CONFIG);
  1228. DPRINTK("MemControl 0x%x BootAddress 0x%x MemConfig 0x%x\n",
  1229. default_par->mem_control, default_par->boot_address,
  1230. default_par->mem_config);
  1231. if (default_par->mem_control == 0 &&
  1232. default_par->boot_address == 0x31 &&
  1233. default_par->mem_config == 0x259fffff) {
  1234. default_par->memclock = CVPPC_MEMCLOCK;
  1235. default_par->mem_control = 0;
  1236. default_par->boot_address = 0x20;
  1237. default_par->mem_config = 0xe6002021;
  1238. if (pdev->subsystem_vendor == 0x1048 &&
  1239. pdev->subsystem_device == 0x0a31) {
  1240. DPRINTK("subsystem_vendor: %04x, "
  1241. "subsystem_device: %04x\n",
  1242. pdev->subsystem_vendor, pdev->subsystem_device);
  1243. DPRINTK("We have not been initialized by VGA BIOS and "
  1244. "are running on an Elsa Winner 2000 Office\n");
  1245. DPRINTK("Initializing card timings manually...\n");
  1246. default_par->memclock = 100000;
  1247. }
  1248. if (pdev->subsystem_vendor == 0x3d3d &&
  1249. pdev->subsystem_device == 0x0100) {
  1250. DPRINTK("subsystem_vendor: %04x, "
  1251. "subsystem_device: %04x\n",
  1252. pdev->subsystem_vendor, pdev->subsystem_device);
  1253. DPRINTK("We have not been initialized by VGA BIOS and "
  1254. "are running on an 3dlabs reference board\n");
  1255. DPRINTK("Initializing card timings manually...\n");
  1256. default_par->memclock = 74894;
  1257. }
  1258. }
  1259. /* Now work out how big lfb is going to be. */
  1260. switch (default_par->mem_config & PM2F_MEM_CONFIG_RAM_MASK) {
  1261. case PM2F_MEM_BANKS_1:
  1262. pm2fb_fix.smem_len = 0x200000;
  1263. break;
  1264. case PM2F_MEM_BANKS_2:
  1265. pm2fb_fix.smem_len = 0x400000;
  1266. break;
  1267. case PM2F_MEM_BANKS_3:
  1268. pm2fb_fix.smem_len = 0x600000;
  1269. break;
  1270. case PM2F_MEM_BANKS_4:
  1271. pm2fb_fix.smem_len = 0x800000;
  1272. break;
  1273. }
  1274. pm2fb_fix.smem_start = pci_resource_start(pdev, 1);
  1275. /* Linear frame buffer - request region and map it. */
  1276. if (!request_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len,
  1277. "pm2fb smem")) {
  1278. printk(KERN_WARNING "pm2fb: Can't reserve smem.\n");
  1279. goto err_exit_mmio;
  1280. }
  1281. info->screen_base =
  1282. ioremap_nocache(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
  1283. if (!info->screen_base) {
  1284. printk(KERN_WARNING "pm2fb: Can't ioremap smem area.\n");
  1285. release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
  1286. goto err_exit_mmio;
  1287. }
  1288. #ifdef CONFIG_MTRR
  1289. default_par->mtrr_handle = -1;
  1290. if (!nomtrr)
  1291. default_par->mtrr_handle =
  1292. mtrr_add(pm2fb_fix.smem_start,
  1293. pm2fb_fix.smem_len,
  1294. MTRR_TYPE_WRCOMB, 1);
  1295. #endif
  1296. info->fbops = &pm2fb_ops;
  1297. info->fix = pm2fb_fix;
  1298. info->pseudo_palette = default_par->palette;
  1299. info->flags = FBINFO_DEFAULT |
  1300. FBINFO_HWACCEL_YPAN |
  1301. FBINFO_HWACCEL_COPYAREA |
  1302. FBINFO_HWACCEL_IMAGEBLIT |
  1303. FBINFO_HWACCEL_FILLRECT;
  1304. info->pixmap.addr = kmalloc(PM2_PIXMAP_SIZE, GFP_KERNEL);
  1305. if (!info->pixmap.addr) {
  1306. retval = -ENOMEM;
  1307. goto err_exit_pixmap;
  1308. }
  1309. info->pixmap.size = PM2_PIXMAP_SIZE;
  1310. info->pixmap.buf_align = 4;
  1311. info->pixmap.scan_align = 4;
  1312. info->pixmap.access_align = 32;
  1313. info->pixmap.flags = FB_PIXMAP_SYSTEM;
  1314. if (noaccel) {
  1315. printk(KERN_DEBUG "disabling acceleration\n");
  1316. info->flags |= FBINFO_HWACCEL_DISABLED;
  1317. info->pixmap.scan_align = 1;
  1318. }
  1319. if (!mode)
  1320. mode = "640x480@60";
  1321. err = fb_find_mode(&info->var, info, mode, NULL, 0, NULL, 8);
  1322. if (!err || err == 4)
  1323. info->var = pm2fb_var;
  1324. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
  1325. goto err_exit_both;
  1326. if (register_framebuffer(info) < 0)
  1327. goto err_exit_all;
  1328. printk(KERN_INFO "fb%d: %s frame buffer device, memory = %dK.\n",
  1329. info->node, info->fix.id, pm2fb_fix.smem_len / 1024);
  1330. /*
  1331. * Our driver data
  1332. */
  1333. pci_set_drvdata(pdev, info);
  1334. return 0;
  1335. err_exit_all:
  1336. fb_dealloc_cmap(&info->cmap);
  1337. err_exit_both:
  1338. kfree(info->pixmap.addr);
  1339. err_exit_pixmap:
  1340. iounmap(info->screen_base);
  1341. release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
  1342. err_exit_mmio:
  1343. iounmap(default_par->v_regs);
  1344. release_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
  1345. err_exit_neither:
  1346. framebuffer_release(info);
  1347. return retval;
  1348. }
  1349. /**
  1350. * Device removal.
  1351. *
  1352. * Release all device resources.
  1353. *
  1354. * @param pdev PCI device to clean up.
  1355. */
  1356. static void __devexit pm2fb_remove(struct pci_dev *pdev)
  1357. {
  1358. struct fb_info *info = pci_get_drvdata(pdev);
  1359. struct fb_fix_screeninfo *fix = &info->fix;
  1360. struct pm2fb_par *par = info->par;
  1361. unregister_framebuffer(info);
  1362. #ifdef CONFIG_MTRR
  1363. if (par->mtrr_handle >= 0)
  1364. mtrr_del(par->mtrr_handle, info->fix.smem_start,
  1365. info->fix.smem_len);
  1366. #endif /* CONFIG_MTRR */
  1367. iounmap(info->screen_base);
  1368. release_mem_region(fix->smem_start, fix->smem_len);
  1369. iounmap(par->v_regs);
  1370. release_mem_region(fix->mmio_start, fix->mmio_len);
  1371. pci_set_drvdata(pdev, NULL);
  1372. kfree(info->pixmap.addr);
  1373. kfree(info);
  1374. }
  1375. static struct pci_device_id pm2fb_id_table[] = {
  1376. { PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TVP4020,
  1377. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  1378. { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2,
  1379. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  1380. { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2V,
  1381. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  1382. { 0, }
  1383. };
  1384. static struct pci_driver pm2fb_driver = {
  1385. .name = "pm2fb",
  1386. .id_table = pm2fb_id_table,
  1387. .probe = pm2fb_probe,
  1388. .remove = __devexit_p(pm2fb_remove),
  1389. };
  1390. MODULE_DEVICE_TABLE(pci, pm2fb_id_table);
  1391. #ifndef MODULE
  1392. /**
  1393. * Parse user speficied options.
  1394. *
  1395. * This is, comma-separated options following `video=pm2fb:'.
  1396. */
  1397. static int __init pm2fb_setup(char *options)
  1398. {
  1399. char *this_opt;
  1400. if (!options || !*options)
  1401. return 0;
  1402. while ((this_opt = strsep(&options, ",")) != NULL) {
  1403. if (!*this_opt)
  1404. continue;
  1405. if (!strcmp(this_opt, "lowhsync"))
  1406. lowhsync = 1;
  1407. else if (!strcmp(this_opt, "lowvsync"))
  1408. lowvsync = 1;
  1409. #ifdef CONFIG_MTRR
  1410. else if (!strncmp(this_opt, "nomtrr", 6))
  1411. nomtrr = 1;
  1412. #endif
  1413. else if (!strncmp(this_opt, "noaccel", 7))
  1414. noaccel = 1;
  1415. else
  1416. mode = this_opt;
  1417. }
  1418. return 0;
  1419. }
  1420. #endif
  1421. static int __init pm2fb_init(void)
  1422. {
  1423. #ifndef MODULE
  1424. char *option = NULL;
  1425. if (fb_get_options("pm2fb", &option))
  1426. return -ENODEV;
  1427. pm2fb_setup(option);
  1428. #endif
  1429. return pci_register_driver(&pm2fb_driver);
  1430. }
  1431. module_init(pm2fb_init);
  1432. #ifdef MODULE
  1433. /*
  1434. * Cleanup
  1435. */
  1436. static void __exit pm2fb_exit(void)
  1437. {
  1438. pci_unregister_driver(&pm2fb_driver);
  1439. }
  1440. #endif
  1441. #ifdef MODULE
  1442. module_exit(pm2fb_exit);
  1443. module_param(mode, charp, 0);
  1444. MODULE_PARM_DESC(mode, "Preferred video mode e.g. '648x480-8@60'");
  1445. module_param(lowhsync, bool, 0);
  1446. MODULE_PARM_DESC(lowhsync, "Force horizontal sync low regardless of mode");
  1447. module_param(lowvsync, bool, 0);
  1448. MODULE_PARM_DESC(lowvsync, "Force vertical sync low regardless of mode");
  1449. module_param(noaccel, bool, 0);
  1450. MODULE_PARM_DESC(noaccel, "Disable acceleration");
  1451. #ifdef CONFIG_MTRR
  1452. module_param(nomtrr, bool, 0);
  1453. MODULE_PARM_DESC(nomtrr, "Disable MTRR support (0 or 1=disabled) (default=0)");
  1454. #endif
  1455. MODULE_AUTHOR("Jim Hague <jim.hague@acm.org>");
  1456. MODULE_DESCRIPTION("Permedia2 framebuffer device driver");
  1457. MODULE_LICENSE("GPL");
  1458. #endif