pm2fb.c 43 KB

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