pm2fb.c 36 KB

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