pm2fb.c 46 KB

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