pm2fb.c 49 KB

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