pm2fb.c 43 KB

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