pm3fb.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590
  1. /*
  2. * linux/drivers/video/pm3fb.c -- 3DLabs Permedia3 frame buffer device
  3. *
  4. * Copyright (C) 2001 Romain Dolbeau <romain@dolbeau.org>.
  5. *
  6. * Ported to 2.6 kernel on 1 May 2007 by Krzysztof Helt <krzysztof.h1@wp.pl>
  7. * based on pm2fb.c
  8. *
  9. * Based on code written by:
  10. * Sven Luther, <luther@dpt-info.u-strasbg.fr>
  11. * Alan Hourihane, <alanh@fairlite.demon.co.uk>
  12. * Russell King, <rmk@arm.linux.org.uk>
  13. * Based on linux/drivers/video/skeletonfb.c:
  14. * Copyright (C) 1997 Geert Uytterhoeven
  15. * Based on linux/driver/video/pm2fb.c:
  16. * Copyright (C) 1998-1999 Ilario Nardinocchi (nardinoc@CS.UniBO.IT)
  17. * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com)
  18. *
  19. * This file is subject to the terms and conditions of the GNU General Public
  20. * License. See the file COPYING in the main directory of this archive for
  21. * more details.
  22. *
  23. */
  24. #include <linux/module.h>
  25. #include <linux/kernel.h>
  26. #include <linux/errno.h>
  27. #include <linux/string.h>
  28. #include <linux/mm.h>
  29. #include <linux/slab.h>
  30. #include <linux/delay.h>
  31. #include <linux/fb.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #ifdef CONFIG_MTRR
  35. #include <asm/mtrr.h>
  36. #endif
  37. #include <video/pm3fb.h>
  38. #if !defined(CONFIG_PCI)
  39. #error "Only generic PCI cards supported."
  40. #endif
  41. #undef PM3FB_MASTER_DEBUG
  42. #ifdef PM3FB_MASTER_DEBUG
  43. #define DPRINTK(a, b...) \
  44. printk(KERN_DEBUG "pm3fb: %s: " a, __func__ , ## b)
  45. #else
  46. #define DPRINTK(a, b...)
  47. #endif
  48. #define PM3_PIXMAP_SIZE (2048 * 4)
  49. /*
  50. * Driver data
  51. */
  52. static int hwcursor = 1;
  53. static char *mode_option __devinitdata;
  54. static int noaccel __devinitdata;
  55. /* mtrr option */
  56. #ifdef CONFIG_MTRR
  57. static int nomtrr __devinitdata;
  58. #endif
  59. /*
  60. * This structure defines the hardware state of the graphics card. Normally
  61. * you place this in a header file in linux/include/video. This file usually
  62. * also includes register information. That allows other driver subsystems
  63. * and userland applications the ability to use the same header file to
  64. * avoid duplicate work and easy porting of software.
  65. */
  66. struct pm3_par {
  67. unsigned char __iomem *v_regs;/* virtual address of p_regs */
  68. u32 video; /* video flags before blanking */
  69. u32 base; /* screen base in 128 bits unit */
  70. u32 palette[16];
  71. int mtrr_handle;
  72. };
  73. /*
  74. * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
  75. * if we don't use modedb. If we do use modedb see pm3fb_init how to use it
  76. * to get a fb_var_screeninfo. Otherwise define a default var as well.
  77. */
  78. static struct fb_fix_screeninfo pm3fb_fix __devinitdata = {
  79. .id = "Permedia3",
  80. .type = FB_TYPE_PACKED_PIXELS,
  81. .visual = FB_VISUAL_PSEUDOCOLOR,
  82. .xpanstep = 1,
  83. .ypanstep = 1,
  84. .ywrapstep = 0,
  85. .accel = FB_ACCEL_3DLABS_PERMEDIA3,
  86. };
  87. /*
  88. * Utility functions
  89. */
  90. static inline u32 PM3_READ_REG(struct pm3_par *par, s32 off)
  91. {
  92. return fb_readl(par->v_regs + off);
  93. }
  94. static inline void PM3_WRITE_REG(struct pm3_par *par, s32 off, u32 v)
  95. {
  96. fb_writel(v, par->v_regs + off);
  97. }
  98. static inline void PM3_WAIT(struct pm3_par *par, u32 n)
  99. {
  100. while (PM3_READ_REG(par, PM3InFIFOSpace) < n)
  101. cpu_relax();
  102. }
  103. static inline void PM3_WRITE_DAC_REG(struct pm3_par *par, unsigned r, u8 v)
  104. {
  105. PM3_WAIT(par, 3);
  106. PM3_WRITE_REG(par, PM3RD_IndexHigh, (r >> 8) & 0xff);
  107. PM3_WRITE_REG(par, PM3RD_IndexLow, r & 0xff);
  108. wmb();
  109. PM3_WRITE_REG(par, PM3RD_IndexedData, v);
  110. wmb();
  111. }
  112. static inline void pm3fb_set_color(struct pm3_par *par, unsigned char regno,
  113. unsigned char r, unsigned char g, unsigned char b)
  114. {
  115. PM3_WAIT(par, 4);
  116. PM3_WRITE_REG(par, PM3RD_PaletteWriteAddress, regno);
  117. wmb();
  118. PM3_WRITE_REG(par, PM3RD_PaletteData, r);
  119. wmb();
  120. PM3_WRITE_REG(par, PM3RD_PaletteData, g);
  121. wmb();
  122. PM3_WRITE_REG(par, PM3RD_PaletteData, b);
  123. wmb();
  124. }
  125. static void pm3fb_clear_colormap(struct pm3_par *par,
  126. unsigned char r, unsigned char g, unsigned char b)
  127. {
  128. int i;
  129. for (i = 0; i < 256 ; i++)
  130. pm3fb_set_color(par, i, r, g, b);
  131. }
  132. /* Calculating various clock parameters */
  133. static void pm3fb_calculate_clock(unsigned long reqclock,
  134. unsigned char *prescale,
  135. unsigned char *feedback,
  136. unsigned char *postscale)
  137. {
  138. int f, pre, post;
  139. unsigned long freq;
  140. long freqerr = 1000;
  141. long currerr;
  142. for (f = 1; f < 256; f++) {
  143. for (pre = 1; pre < 256; pre++) {
  144. for (post = 0; post < 5; post++) {
  145. freq = ((2*PM3_REF_CLOCK * f) >> post) / pre;
  146. currerr = (reqclock > freq)
  147. ? reqclock - freq
  148. : freq - reqclock;
  149. if (currerr < freqerr) {
  150. freqerr = currerr;
  151. *feedback = f;
  152. *prescale = pre;
  153. *postscale = post;
  154. }
  155. }
  156. }
  157. }
  158. }
  159. static inline int pm3fb_depth(const struct fb_var_screeninfo *var)
  160. {
  161. if (var->bits_per_pixel == 16)
  162. return var->red.length + var->green.length
  163. + var->blue.length;
  164. return var->bits_per_pixel;
  165. }
  166. static inline int pm3fb_shift_bpp(unsigned bpp, int v)
  167. {
  168. switch (bpp) {
  169. case 8:
  170. return (v >> 4);
  171. case 16:
  172. return (v >> 3);
  173. case 32:
  174. return (v >> 2);
  175. }
  176. DPRINTK("Unsupported depth %u\n", bpp);
  177. return 0;
  178. }
  179. /* acceleration */
  180. static int pm3fb_sync(struct fb_info *info)
  181. {
  182. struct pm3_par *par = info->par;
  183. PM3_WAIT(par, 2);
  184. PM3_WRITE_REG(par, PM3FilterMode, PM3FilterModeSync);
  185. PM3_WRITE_REG(par, PM3Sync, 0);
  186. mb();
  187. do {
  188. while ((PM3_READ_REG(par, PM3OutFIFOWords)) == 0)
  189. cpu_relax();
  190. } while ((PM3_READ_REG(par, PM3OutputFifo)) != PM3Sync_Tag);
  191. return 0;
  192. }
  193. static void pm3fb_init_engine(struct fb_info *info)
  194. {
  195. struct pm3_par *par = info->par;
  196. const u32 width = (info->var.xres_virtual + 7) & ~7;
  197. PM3_WAIT(par, 50);
  198. PM3_WRITE_REG(par, PM3FilterMode, PM3FilterModeSync);
  199. PM3_WRITE_REG(par, PM3StatisticMode, 0x0);
  200. PM3_WRITE_REG(par, PM3DeltaMode, 0x0);
  201. PM3_WRITE_REG(par, PM3RasterizerMode, 0x0);
  202. PM3_WRITE_REG(par, PM3ScissorMode, 0x0);
  203. PM3_WRITE_REG(par, PM3LineStippleMode, 0x0);
  204. PM3_WRITE_REG(par, PM3AreaStippleMode, 0x0);
  205. PM3_WRITE_REG(par, PM3GIDMode, 0x0);
  206. PM3_WRITE_REG(par, PM3DepthMode, 0x0);
  207. PM3_WRITE_REG(par, PM3StencilMode, 0x0);
  208. PM3_WRITE_REG(par, PM3StencilData, 0x0);
  209. PM3_WRITE_REG(par, PM3ColorDDAMode, 0x0);
  210. PM3_WRITE_REG(par, PM3TextureCoordMode, 0x0);
  211. PM3_WRITE_REG(par, PM3TextureIndexMode0, 0x0);
  212. PM3_WRITE_REG(par, PM3TextureIndexMode1, 0x0);
  213. PM3_WRITE_REG(par, PM3TextureReadMode, 0x0);
  214. PM3_WRITE_REG(par, PM3LUTMode, 0x0);
  215. PM3_WRITE_REG(par, PM3TextureFilterMode, 0x0);
  216. PM3_WRITE_REG(par, PM3TextureCompositeMode, 0x0);
  217. PM3_WRITE_REG(par, PM3TextureApplicationMode, 0x0);
  218. PM3_WRITE_REG(par, PM3TextureCompositeColorMode1, 0x0);
  219. PM3_WRITE_REG(par, PM3TextureCompositeAlphaMode1, 0x0);
  220. PM3_WRITE_REG(par, PM3TextureCompositeColorMode0, 0x0);
  221. PM3_WRITE_REG(par, PM3TextureCompositeAlphaMode0, 0x0);
  222. PM3_WRITE_REG(par, PM3FogMode, 0x0);
  223. PM3_WRITE_REG(par, PM3ChromaTestMode, 0x0);
  224. PM3_WRITE_REG(par, PM3AlphaTestMode, 0x0);
  225. PM3_WRITE_REG(par, PM3AntialiasMode, 0x0);
  226. PM3_WRITE_REG(par, PM3YUVMode, 0x0);
  227. PM3_WRITE_REG(par, PM3AlphaBlendColorMode, 0x0);
  228. PM3_WRITE_REG(par, PM3AlphaBlendAlphaMode, 0x0);
  229. PM3_WRITE_REG(par, PM3DitherMode, 0x0);
  230. PM3_WRITE_REG(par, PM3LogicalOpMode, 0x0);
  231. PM3_WRITE_REG(par, PM3RouterMode, 0x0);
  232. PM3_WRITE_REG(par, PM3Window, 0x0);
  233. PM3_WRITE_REG(par, PM3Config2D, 0x0);
  234. PM3_WRITE_REG(par, PM3SpanColorMask, 0xffffffff);
  235. PM3_WRITE_REG(par, PM3XBias, 0x0);
  236. PM3_WRITE_REG(par, PM3YBias, 0x0);
  237. PM3_WRITE_REG(par, PM3DeltaControl, 0x0);
  238. PM3_WRITE_REG(par, PM3BitMaskPattern, 0xffffffff);
  239. PM3_WRITE_REG(par, PM3FBDestReadEnables,
  240. PM3FBDestReadEnables_E(0xff) |
  241. PM3FBDestReadEnables_R(0xff) |
  242. PM3FBDestReadEnables_ReferenceAlpha(0xff));
  243. PM3_WRITE_REG(par, PM3FBDestReadBufferAddr0, 0x0);
  244. PM3_WRITE_REG(par, PM3FBDestReadBufferOffset0, 0x0);
  245. PM3_WRITE_REG(par, PM3FBDestReadBufferWidth0,
  246. PM3FBDestReadBufferWidth_Width(width));
  247. PM3_WRITE_REG(par, PM3FBDestReadMode,
  248. PM3FBDestReadMode_ReadEnable |
  249. PM3FBDestReadMode_Enable0);
  250. PM3_WRITE_REG(par, PM3FBSourceReadBufferAddr, 0x0);
  251. PM3_WRITE_REG(par, PM3FBSourceReadBufferOffset, 0x0);
  252. PM3_WRITE_REG(par, PM3FBSourceReadBufferWidth,
  253. PM3FBSourceReadBufferWidth_Width(width));
  254. PM3_WRITE_REG(par, PM3FBSourceReadMode,
  255. PM3FBSourceReadMode_Blocking |
  256. PM3FBSourceReadMode_ReadEnable);
  257. PM3_WAIT(par, 2);
  258. {
  259. /* invert bits in bitmask */
  260. unsigned long rm = 1 | (3 << 7);
  261. switch (info->var.bits_per_pixel) {
  262. case 8:
  263. PM3_WRITE_REG(par, PM3PixelSize,
  264. PM3PixelSize_GLOBAL_8BIT);
  265. #ifdef __BIG_ENDIAN
  266. rm |= 3 << 15;
  267. #endif
  268. break;
  269. case 16:
  270. PM3_WRITE_REG(par, PM3PixelSize,
  271. PM3PixelSize_GLOBAL_16BIT);
  272. #ifdef __BIG_ENDIAN
  273. rm |= 2 << 15;
  274. #endif
  275. break;
  276. case 32:
  277. PM3_WRITE_REG(par, PM3PixelSize,
  278. PM3PixelSize_GLOBAL_32BIT);
  279. break;
  280. default:
  281. DPRINTK(1, "Unsupported depth %d\n",
  282. info->var.bits_per_pixel);
  283. break;
  284. }
  285. PM3_WRITE_REG(par, PM3RasterizerMode, rm);
  286. }
  287. PM3_WAIT(par, 20);
  288. PM3_WRITE_REG(par, PM3FBSoftwareWriteMask, 0xffffffff);
  289. PM3_WRITE_REG(par, PM3FBHardwareWriteMask, 0xffffffff);
  290. PM3_WRITE_REG(par, PM3FBWriteMode,
  291. PM3FBWriteMode_WriteEnable |
  292. PM3FBWriteMode_OpaqueSpan |
  293. PM3FBWriteMode_Enable0);
  294. PM3_WRITE_REG(par, PM3FBWriteBufferAddr0, 0x0);
  295. PM3_WRITE_REG(par, PM3FBWriteBufferOffset0, 0x0);
  296. PM3_WRITE_REG(par, PM3FBWriteBufferWidth0,
  297. PM3FBWriteBufferWidth_Width(width));
  298. PM3_WRITE_REG(par, PM3SizeOfFramebuffer, 0x0);
  299. {
  300. /* size in lines of FB */
  301. unsigned long sofb = info->screen_size /
  302. info->fix.line_length;
  303. if (sofb > 4095)
  304. PM3_WRITE_REG(par, PM3SizeOfFramebuffer, 4095);
  305. else
  306. PM3_WRITE_REG(par, PM3SizeOfFramebuffer, sofb);
  307. switch (info->var.bits_per_pixel) {
  308. case 8:
  309. PM3_WRITE_REG(par, PM3DitherMode,
  310. (1 << 10) | (2 << 3));
  311. break;
  312. case 16:
  313. PM3_WRITE_REG(par, PM3DitherMode,
  314. (1 << 10) | (1 << 3));
  315. break;
  316. case 32:
  317. PM3_WRITE_REG(par, PM3DitherMode,
  318. (1 << 10) | (0 << 3));
  319. break;
  320. default:
  321. DPRINTK(1, "Unsupported depth %d\n",
  322. info->current_par->depth);
  323. break;
  324. }
  325. }
  326. PM3_WRITE_REG(par, PM3dXDom, 0x0);
  327. PM3_WRITE_REG(par, PM3dXSub, 0x0);
  328. PM3_WRITE_REG(par, PM3dY, 1 << 16);
  329. PM3_WRITE_REG(par, PM3StartXDom, 0x0);
  330. PM3_WRITE_REG(par, PM3StartXSub, 0x0);
  331. PM3_WRITE_REG(par, PM3StartY, 0x0);
  332. PM3_WRITE_REG(par, PM3Count, 0x0);
  333. /* Disable LocalBuffer. better safe than sorry */
  334. PM3_WRITE_REG(par, PM3LBDestReadMode, 0x0);
  335. PM3_WRITE_REG(par, PM3LBDestReadEnables, 0x0);
  336. PM3_WRITE_REG(par, PM3LBSourceReadMode, 0x0);
  337. PM3_WRITE_REG(par, PM3LBWriteMode, 0x0);
  338. pm3fb_sync(info);
  339. }
  340. static void pm3fb_fillrect(struct fb_info *info,
  341. const struct fb_fillrect *region)
  342. {
  343. struct pm3_par *par = info->par;
  344. struct fb_fillrect modded;
  345. int vxres, vyres;
  346. int rop;
  347. u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ?
  348. ((u32 *)info->pseudo_palette)[region->color] : region->color;
  349. if (info->state != FBINFO_STATE_RUNNING)
  350. return;
  351. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  352. cfb_fillrect(info, region);
  353. return;
  354. }
  355. if (region->rop == ROP_COPY )
  356. rop = PM3Config2D_ForegroundROP(0x3); /* GXcopy */
  357. else
  358. rop = PM3Config2D_ForegroundROP(0x6) | /* GXxor */
  359. PM3Config2D_FBDestReadEnable;
  360. vxres = info->var.xres_virtual;
  361. vyres = info->var.yres_virtual;
  362. memcpy(&modded, region, sizeof(struct fb_fillrect));
  363. if (!modded.width || !modded.height ||
  364. modded.dx >= vxres || modded.dy >= vyres)
  365. return;
  366. if (modded.dx + modded.width > vxres)
  367. modded.width = vxres - modded.dx;
  368. if (modded.dy + modded.height > vyres)
  369. modded.height = vyres - modded.dy;
  370. if (info->var.bits_per_pixel == 8)
  371. color |= color << 8;
  372. if (info->var.bits_per_pixel <= 16)
  373. color |= color << 16;
  374. PM3_WAIT(par, 4);
  375. /* ROP Ox3 is GXcopy */
  376. PM3_WRITE_REG(par, PM3Config2D,
  377. PM3Config2D_UseConstantSource |
  378. PM3Config2D_ForegroundROPEnable |
  379. rop |
  380. PM3Config2D_FBWriteEnable);
  381. PM3_WRITE_REG(par, PM3ForegroundColor, color);
  382. PM3_WRITE_REG(par, PM3RectanglePosition,
  383. PM3RectanglePosition_XOffset(modded.dx) |
  384. PM3RectanglePosition_YOffset(modded.dy));
  385. PM3_WRITE_REG(par, PM3Render2D,
  386. PM3Render2D_XPositive |
  387. PM3Render2D_YPositive |
  388. PM3Render2D_Operation_Normal |
  389. PM3Render2D_SpanOperation |
  390. PM3Render2D_Width(modded.width) |
  391. PM3Render2D_Height(modded.height));
  392. }
  393. static void pm3fb_copyarea(struct fb_info *info,
  394. const struct fb_copyarea *area)
  395. {
  396. struct pm3_par *par = info->par;
  397. struct fb_copyarea modded;
  398. u32 vxres, vyres;
  399. int x_align, o_x, o_y;
  400. if (info->state != FBINFO_STATE_RUNNING)
  401. return;
  402. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  403. cfb_copyarea(info, area);
  404. return;
  405. }
  406. memcpy(&modded, area, sizeof(struct fb_copyarea));
  407. vxres = info->var.xres_virtual;
  408. vyres = info->var.yres_virtual;
  409. if (!modded.width || !modded.height ||
  410. modded.sx >= vxres || modded.sy >= vyres ||
  411. modded.dx >= vxres || modded.dy >= vyres)
  412. return;
  413. if (modded.sx + modded.width > vxres)
  414. modded.width = vxres - modded.sx;
  415. if (modded.dx + modded.width > vxres)
  416. modded.width = vxres - modded.dx;
  417. if (modded.sy + modded.height > vyres)
  418. modded.height = vyres - modded.sy;
  419. if (modded.dy + modded.height > vyres)
  420. modded.height = vyres - modded.dy;
  421. o_x = modded.sx - modded.dx; /*(sx > dx ) ? (sx - dx) : (dx - sx); */
  422. o_y = modded.sy - modded.dy; /*(sy > dy ) ? (sy - dy) : (dy - sy); */
  423. x_align = (modded.sx & 0x1f);
  424. PM3_WAIT(par, 6);
  425. PM3_WRITE_REG(par, PM3Config2D,
  426. PM3Config2D_UserScissorEnable |
  427. PM3Config2D_ForegroundROPEnable |
  428. PM3Config2D_Blocking |
  429. PM3Config2D_ForegroundROP(0x3) | /* Ox3 is GXcopy */
  430. PM3Config2D_FBWriteEnable);
  431. PM3_WRITE_REG(par, PM3ScissorMinXY,
  432. ((modded.dy & 0x0fff) << 16) | (modded.dx & 0x0fff));
  433. PM3_WRITE_REG(par, PM3ScissorMaxXY,
  434. (((modded.dy + modded.height) & 0x0fff) << 16) |
  435. ((modded.dx + modded.width) & 0x0fff));
  436. PM3_WRITE_REG(par, PM3FBSourceReadBufferOffset,
  437. PM3FBSourceReadBufferOffset_XOffset(o_x) |
  438. PM3FBSourceReadBufferOffset_YOffset(o_y));
  439. PM3_WRITE_REG(par, PM3RectanglePosition,
  440. PM3RectanglePosition_XOffset(modded.dx - x_align) |
  441. PM3RectanglePosition_YOffset(modded.dy));
  442. PM3_WRITE_REG(par, PM3Render2D,
  443. ((modded.sx > modded.dx) ? PM3Render2D_XPositive : 0) |
  444. ((modded.sy > modded.dy) ? PM3Render2D_YPositive : 0) |
  445. PM3Render2D_Operation_Normal |
  446. PM3Render2D_SpanOperation |
  447. PM3Render2D_FBSourceReadEnable |
  448. PM3Render2D_Width(modded.width + x_align) |
  449. PM3Render2D_Height(modded.height));
  450. }
  451. static void pm3fb_imageblit(struct fb_info *info, const struct fb_image *image)
  452. {
  453. struct pm3_par *par = info->par;
  454. u32 height = image->height;
  455. u32 fgx, bgx;
  456. const u32 *src = (const u32 *)image->data;
  457. if (info->state != FBINFO_STATE_RUNNING)
  458. return;
  459. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  460. cfb_imageblit(info, image);
  461. return;
  462. }
  463. switch (info->fix.visual) {
  464. case FB_VISUAL_PSEUDOCOLOR:
  465. fgx = image->fg_color;
  466. bgx = image->bg_color;
  467. break;
  468. case FB_VISUAL_TRUECOLOR:
  469. default:
  470. fgx = par->palette[image->fg_color];
  471. bgx = par->palette[image->bg_color];
  472. break;
  473. }
  474. if (image->depth != 1) {
  475. cfb_imageblit(info, image);
  476. return;
  477. }
  478. if (info->var.bits_per_pixel == 8) {
  479. fgx |= fgx << 8;
  480. bgx |= bgx << 8;
  481. }
  482. if (info->var.bits_per_pixel <= 16) {
  483. fgx |= fgx << 16;
  484. bgx |= bgx << 16;
  485. }
  486. PM3_WAIT(par, 7);
  487. PM3_WRITE_REG(par, PM3ForegroundColor, fgx);
  488. PM3_WRITE_REG(par, PM3BackgroundColor, bgx);
  489. /* ROP Ox3 is GXcopy */
  490. PM3_WRITE_REG(par, PM3Config2D,
  491. PM3Config2D_UserScissorEnable |
  492. PM3Config2D_UseConstantSource |
  493. PM3Config2D_ForegroundROPEnable |
  494. PM3Config2D_ForegroundROP(0x3) |
  495. PM3Config2D_OpaqueSpan |
  496. PM3Config2D_FBWriteEnable);
  497. PM3_WRITE_REG(par, PM3ScissorMinXY,
  498. ((image->dy & 0x0fff) << 16) | (image->dx & 0x0fff));
  499. PM3_WRITE_REG(par, PM3ScissorMaxXY,
  500. (((image->dy + image->height) & 0x0fff) << 16) |
  501. ((image->dx + image->width) & 0x0fff));
  502. PM3_WRITE_REG(par, PM3RectanglePosition,
  503. PM3RectanglePosition_XOffset(image->dx) |
  504. PM3RectanglePosition_YOffset(image->dy));
  505. PM3_WRITE_REG(par, PM3Render2D,
  506. PM3Render2D_XPositive |
  507. PM3Render2D_YPositive |
  508. PM3Render2D_Operation_SyncOnBitMask |
  509. PM3Render2D_SpanOperation |
  510. PM3Render2D_Width(image->width) |
  511. PM3Render2D_Height(image->height));
  512. while (height--) {
  513. int width = ((image->width + 7) >> 3)
  514. + info->pixmap.scan_align - 1;
  515. width >>= 2;
  516. while (width >= PM3_FIFO_SIZE) {
  517. int i = PM3_FIFO_SIZE - 1;
  518. PM3_WAIT(par, PM3_FIFO_SIZE);
  519. while (i--) {
  520. PM3_WRITE_REG(par, PM3BitMaskPattern, *src);
  521. src++;
  522. }
  523. width -= PM3_FIFO_SIZE - 1;
  524. }
  525. PM3_WAIT(par, width + 1);
  526. while (width--) {
  527. PM3_WRITE_REG(par, PM3BitMaskPattern, *src);
  528. src++;
  529. }
  530. }
  531. }
  532. /* end of acceleration functions */
  533. /*
  534. * Hardware Cursor support.
  535. */
  536. static const u8 cursor_bits_lookup[16] = {
  537. 0x00, 0x40, 0x10, 0x50, 0x04, 0x44, 0x14, 0x54,
  538. 0x01, 0x41, 0x11, 0x51, 0x05, 0x45, 0x15, 0x55
  539. };
  540. static int pm3fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  541. {
  542. struct pm3_par *par = info->par;
  543. u8 mode;
  544. if (!hwcursor)
  545. return -EINVAL; /* just to force soft_cursor() call */
  546. /* Too large of a cursor or wrong bpp :-( */
  547. if (cursor->image.width > 64 ||
  548. cursor->image.height > 64 ||
  549. cursor->image.depth > 1)
  550. return -EINVAL;
  551. mode = PM3RD_CursorMode_TYPE_X;
  552. if (cursor->enable)
  553. mode |= PM3RD_CursorMode_CURSOR_ENABLE;
  554. PM3_WRITE_DAC_REG(par, PM3RD_CursorMode, mode);
  555. /*
  556. * If the cursor is not be changed this means either we want the
  557. * current cursor state (if enable is set) or we want to query what
  558. * we can do with the cursor (if enable is not set)
  559. */
  560. if (!cursor->set)
  561. return 0;
  562. if (cursor->set & FB_CUR_SETPOS) {
  563. int x = cursor->image.dx - info->var.xoffset;
  564. int y = cursor->image.dy - info->var.yoffset;
  565. PM3_WRITE_DAC_REG(par, PM3RD_CursorXLow, x & 0xff);
  566. PM3_WRITE_DAC_REG(par, PM3RD_CursorXHigh, (x >> 8) & 0xf);
  567. PM3_WRITE_DAC_REG(par, PM3RD_CursorYLow, y & 0xff);
  568. PM3_WRITE_DAC_REG(par, PM3RD_CursorYHigh, (y >> 8) & 0xf);
  569. }
  570. if (cursor->set & FB_CUR_SETHOT) {
  571. PM3_WRITE_DAC_REG(par, PM3RD_CursorHotSpotX,
  572. cursor->hot.x & 0x3f);
  573. PM3_WRITE_DAC_REG(par, PM3RD_CursorHotSpotY,
  574. cursor->hot.y & 0x3f);
  575. }
  576. if (cursor->set & FB_CUR_SETCMAP) {
  577. u32 fg_idx = cursor->image.fg_color;
  578. u32 bg_idx = cursor->image.bg_color;
  579. struct fb_cmap cmap = info->cmap;
  580. /* the X11 driver says one should use these color registers */
  581. PM3_WRITE_DAC_REG(par, PM3RD_CursorPalette(39),
  582. cmap.red[fg_idx] >> 8 );
  583. PM3_WRITE_DAC_REG(par, PM3RD_CursorPalette(40),
  584. cmap.green[fg_idx] >> 8 );
  585. PM3_WRITE_DAC_REG(par, PM3RD_CursorPalette(41),
  586. cmap.blue[fg_idx] >> 8 );
  587. PM3_WRITE_DAC_REG(par, PM3RD_CursorPalette(42),
  588. cmap.red[bg_idx] >> 8 );
  589. PM3_WRITE_DAC_REG(par, PM3RD_CursorPalette(43),
  590. cmap.green[bg_idx] >> 8 );
  591. PM3_WRITE_DAC_REG(par, PM3RD_CursorPalette(44),
  592. cmap.blue[bg_idx] >> 8 );
  593. }
  594. if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
  595. u8 *bitmap = (u8 *)cursor->image.data;
  596. u8 *mask = (u8 *)cursor->mask;
  597. int i;
  598. int pos = PM3RD_CursorPattern(0);
  599. for (i = 0; i < cursor->image.height; i++) {
  600. int j = (cursor->image.width + 7) >> 3;
  601. int k = 8 - j;
  602. for (; j > 0; j--) {
  603. u8 data = *bitmap ^ *mask;
  604. if (cursor->rop == ROP_COPY)
  605. data = *mask & *bitmap;
  606. /* Upper 4 bits of bitmap data */
  607. PM3_WRITE_DAC_REG(par, pos++,
  608. cursor_bits_lookup[data >> 4] |
  609. (cursor_bits_lookup[*mask >> 4] << 1));
  610. /* Lower 4 bits of bitmap */
  611. PM3_WRITE_DAC_REG(par, pos++,
  612. cursor_bits_lookup[data & 0xf] |
  613. (cursor_bits_lookup[*mask & 0xf] << 1));
  614. bitmap++;
  615. mask++;
  616. }
  617. for (; k > 0; k--) {
  618. PM3_WRITE_DAC_REG(par, pos++, 0);
  619. PM3_WRITE_DAC_REG(par, pos++, 0);
  620. }
  621. }
  622. while (pos < PM3RD_CursorPattern(1024))
  623. PM3_WRITE_DAC_REG(par, pos++, 0);
  624. }
  625. return 0;
  626. }
  627. /* write the mode to registers */
  628. static void pm3fb_write_mode(struct fb_info *info)
  629. {
  630. struct pm3_par *par = info->par;
  631. char tempsync = 0x00;
  632. char tempmisc = 0x00;
  633. const u32 hsstart = info->var.right_margin;
  634. const u32 hsend = hsstart + info->var.hsync_len;
  635. const u32 hbend = hsend + info->var.left_margin;
  636. const u32 xres = (info->var.xres + 31) & ~31;
  637. const u32 htotal = xres + hbend;
  638. const u32 vsstart = info->var.lower_margin;
  639. const u32 vsend = vsstart + info->var.vsync_len;
  640. const u32 vbend = vsend + info->var.upper_margin;
  641. const u32 vtotal = info->var.yres + vbend;
  642. const u32 width = (info->var.xres_virtual + 7) & ~7;
  643. const unsigned bpp = info->var.bits_per_pixel;
  644. PM3_WAIT(par, 20);
  645. PM3_WRITE_REG(par, PM3MemBypassWriteMask, 0xffffffff);
  646. PM3_WRITE_REG(par, PM3Aperture0, 0x00000000);
  647. PM3_WRITE_REG(par, PM3Aperture1, 0x00000000);
  648. PM3_WRITE_REG(par, PM3FIFODis, 0x00000007);
  649. PM3_WRITE_REG(par, PM3HTotal,
  650. pm3fb_shift_bpp(bpp, htotal - 1));
  651. PM3_WRITE_REG(par, PM3HsEnd,
  652. pm3fb_shift_bpp(bpp, hsend));
  653. PM3_WRITE_REG(par, PM3HsStart,
  654. pm3fb_shift_bpp(bpp, hsstart));
  655. PM3_WRITE_REG(par, PM3HbEnd,
  656. pm3fb_shift_bpp(bpp, hbend));
  657. PM3_WRITE_REG(par, PM3HgEnd,
  658. pm3fb_shift_bpp(bpp, hbend));
  659. PM3_WRITE_REG(par, PM3ScreenStride,
  660. pm3fb_shift_bpp(bpp, width));
  661. PM3_WRITE_REG(par, PM3VTotal, vtotal - 1);
  662. PM3_WRITE_REG(par, PM3VsEnd, vsend - 1);
  663. PM3_WRITE_REG(par, PM3VsStart, vsstart - 1);
  664. PM3_WRITE_REG(par, PM3VbEnd, vbend);
  665. switch (bpp) {
  666. case 8:
  667. PM3_WRITE_REG(par, PM3ByAperture1Mode,
  668. PM3ByApertureMode_PIXELSIZE_8BIT);
  669. PM3_WRITE_REG(par, PM3ByAperture2Mode,
  670. PM3ByApertureMode_PIXELSIZE_8BIT);
  671. break;
  672. case 16:
  673. #ifndef __BIG_ENDIAN
  674. PM3_WRITE_REG(par, PM3ByAperture1Mode,
  675. PM3ByApertureMode_PIXELSIZE_16BIT);
  676. PM3_WRITE_REG(par, PM3ByAperture2Mode,
  677. PM3ByApertureMode_PIXELSIZE_16BIT);
  678. #else
  679. PM3_WRITE_REG(par, PM3ByAperture1Mode,
  680. PM3ByApertureMode_PIXELSIZE_16BIT |
  681. PM3ByApertureMode_BYTESWAP_BADC);
  682. PM3_WRITE_REG(par, PM3ByAperture2Mode,
  683. PM3ByApertureMode_PIXELSIZE_16BIT |
  684. PM3ByApertureMode_BYTESWAP_BADC);
  685. #endif /* ! __BIG_ENDIAN */
  686. break;
  687. case 32:
  688. #ifndef __BIG_ENDIAN
  689. PM3_WRITE_REG(par, PM3ByAperture1Mode,
  690. PM3ByApertureMode_PIXELSIZE_32BIT);
  691. PM3_WRITE_REG(par, PM3ByAperture2Mode,
  692. PM3ByApertureMode_PIXELSIZE_32BIT);
  693. #else
  694. PM3_WRITE_REG(par, PM3ByAperture1Mode,
  695. PM3ByApertureMode_PIXELSIZE_32BIT |
  696. PM3ByApertureMode_BYTESWAP_DCBA);
  697. PM3_WRITE_REG(par, PM3ByAperture2Mode,
  698. PM3ByApertureMode_PIXELSIZE_32BIT |
  699. PM3ByApertureMode_BYTESWAP_DCBA);
  700. #endif /* ! __BIG_ENDIAN */
  701. break;
  702. default:
  703. DPRINTK("Unsupported depth %d\n", bpp);
  704. break;
  705. }
  706. /*
  707. * Oxygen VX1 - it appears that setting PM3VideoControl and
  708. * then PM3RD_SyncControl to the same SYNC settings undoes
  709. * any net change - they seem to xor together. Only set the
  710. * sync options in PM3RD_SyncControl. --rmk
  711. */
  712. {
  713. unsigned int video = par->video;
  714. video &= ~(PM3VideoControl_HSYNC_MASK |
  715. PM3VideoControl_VSYNC_MASK);
  716. video |= PM3VideoControl_HSYNC_ACTIVE_HIGH |
  717. PM3VideoControl_VSYNC_ACTIVE_HIGH;
  718. PM3_WRITE_REG(par, PM3VideoControl, video);
  719. }
  720. PM3_WRITE_REG(par, PM3VClkCtl,
  721. (PM3_READ_REG(par, PM3VClkCtl) & 0xFFFFFFFC));
  722. PM3_WRITE_REG(par, PM3ScreenBase, par->base);
  723. PM3_WRITE_REG(par, PM3ChipConfig,
  724. (PM3_READ_REG(par, PM3ChipConfig) & 0xFFFFFFFD));
  725. wmb();
  726. {
  727. unsigned char uninitialized_var(m); /* ClkPreScale */
  728. unsigned char uninitialized_var(n); /* ClkFeedBackScale */
  729. unsigned char uninitialized_var(p); /* ClkPostScale */
  730. unsigned long pixclock = PICOS2KHZ(info->var.pixclock);
  731. (void)pm3fb_calculate_clock(pixclock, &m, &n, &p);
  732. DPRINTK("Pixclock: %ld, Pre: %d, Feedback: %d, Post: %d\n",
  733. pixclock, (int) m, (int) n, (int) p);
  734. PM3_WRITE_DAC_REG(par, PM3RD_DClk0PreScale, m);
  735. PM3_WRITE_DAC_REG(par, PM3RD_DClk0FeedbackScale, n);
  736. PM3_WRITE_DAC_REG(par, PM3RD_DClk0PostScale, p);
  737. }
  738. /*
  739. PM3_WRITE_DAC_REG(par, PM3RD_IndexControl, 0x00);
  740. */
  741. /*
  742. PM3_SLOW_WRITE_REG(par, PM3RD_IndexControl, 0x00);
  743. */
  744. if ((par->video & PM3VideoControl_HSYNC_MASK) ==
  745. PM3VideoControl_HSYNC_ACTIVE_HIGH)
  746. tempsync |= PM3RD_SyncControl_HSYNC_ACTIVE_HIGH;
  747. if ((par->video & PM3VideoControl_VSYNC_MASK) ==
  748. PM3VideoControl_VSYNC_ACTIVE_HIGH)
  749. tempsync |= PM3RD_SyncControl_VSYNC_ACTIVE_HIGH;
  750. PM3_WRITE_DAC_REG(par, PM3RD_SyncControl, tempsync);
  751. DPRINTK("PM3RD_SyncControl: %d\n", tempsync);
  752. PM3_WRITE_DAC_REG(par, PM3RD_DACControl, 0x00);
  753. switch (pm3fb_depth(&info->var)) {
  754. case 8:
  755. PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
  756. PM3RD_PixelSize_8_BIT_PIXELS);
  757. PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
  758. PM3RD_ColorFormat_CI8_COLOR |
  759. PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW);
  760. tempmisc |= PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
  761. break;
  762. case 12:
  763. PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
  764. PM3RD_PixelSize_16_BIT_PIXELS);
  765. PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
  766. PM3RD_ColorFormat_4444_COLOR |
  767. PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
  768. PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
  769. tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
  770. PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
  771. break;
  772. case 15:
  773. PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
  774. PM3RD_PixelSize_16_BIT_PIXELS);
  775. PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
  776. PM3RD_ColorFormat_5551_FRONT_COLOR |
  777. PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
  778. PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
  779. tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
  780. PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
  781. break;
  782. case 16:
  783. PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
  784. PM3RD_PixelSize_16_BIT_PIXELS);
  785. PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
  786. PM3RD_ColorFormat_565_FRONT_COLOR |
  787. PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
  788. PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
  789. tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
  790. PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
  791. break;
  792. case 32:
  793. PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
  794. PM3RD_PixelSize_32_BIT_PIXELS);
  795. PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
  796. PM3RD_ColorFormat_8888_COLOR |
  797. PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW);
  798. tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
  799. PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
  800. break;
  801. }
  802. PM3_WRITE_DAC_REG(par, PM3RD_MiscControl, tempmisc);
  803. }
  804. /*
  805. * hardware independent functions
  806. */
  807. static int pm3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  808. {
  809. u32 lpitch;
  810. unsigned bpp = var->red.length + var->green.length
  811. + var->blue.length + var->transp.length;
  812. if (bpp != var->bits_per_pixel) {
  813. /* set predefined mode for bits_per_pixel settings */
  814. switch (var->bits_per_pixel) {
  815. case 8:
  816. var->red.length = 8;
  817. var->green.length = 8;
  818. var->blue.length = 8;
  819. var->red.offset = 0;
  820. var->green.offset = 0;
  821. var->blue.offset = 0;
  822. var->transp.offset = 0;
  823. var->transp.length = 0;
  824. break;
  825. case 16:
  826. var->red.length = 5;
  827. var->blue.length = 5;
  828. var->green.length = 6;
  829. var->transp.length = 0;
  830. break;
  831. case 32:
  832. var->red.length = 8;
  833. var->green.length = 8;
  834. var->blue.length = 8;
  835. var->transp.length = 8;
  836. break;
  837. default:
  838. DPRINTK("depth not supported: %u\n",
  839. var->bits_per_pixel);
  840. return -EINVAL;
  841. }
  842. }
  843. /* it is assumed BGRA order */
  844. if (var->bits_per_pixel > 8 ) {
  845. var->blue.offset = 0;
  846. var->green.offset = var->blue.length;
  847. var->red.offset = var->green.offset + var->green.length;
  848. var->transp.offset = var->red.offset + var->red.length;
  849. }
  850. var->height = -1;
  851. var->width = -1;
  852. if (var->xres != var->xres_virtual) {
  853. DPRINTK("virtual x resolution != "
  854. "physical x resolution not supported\n");
  855. return -EINVAL;
  856. }
  857. if (var->yres > var->yres_virtual) {
  858. DPRINTK("virtual y resolution < "
  859. "physical y resolution not possible\n");
  860. return -EINVAL;
  861. }
  862. if (var->xoffset) {
  863. DPRINTK("xoffset not supported\n");
  864. return -EINVAL;
  865. }
  866. if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
  867. DPRINTK("interlace not supported\n");
  868. return -EINVAL;
  869. }
  870. var->xres = (var->xres + 31) & ~31; /* could sometimes be 8 */
  871. lpitch = var->xres * ((var->bits_per_pixel + 7) >> 3);
  872. if (var->xres < 200 || var->xres > 2048) {
  873. DPRINTK("width not supported: %u\n", var->xres);
  874. return -EINVAL;
  875. }
  876. if (var->yres < 200 || var->yres > 4095) {
  877. DPRINTK("height not supported: %u\n", var->yres);
  878. return -EINVAL;
  879. }
  880. if (lpitch * var->yres_virtual > info->fix.smem_len) {
  881. DPRINTK("no memory for screen (%ux%ux%u)\n",
  882. var->xres, var->yres_virtual, var->bits_per_pixel);
  883. return -EINVAL;
  884. }
  885. if (PICOS2KHZ(var->pixclock) > PM3_MAX_PIXCLOCK) {
  886. DPRINTK("pixclock too high (%ldKHz)\n",
  887. PICOS2KHZ(var->pixclock));
  888. return -EINVAL;
  889. }
  890. var->accel_flags = 0; /* Can't mmap if this is on */
  891. DPRINTK("Checking graphics mode at %dx%d depth %d\n",
  892. var->xres, var->yres, var->bits_per_pixel);
  893. return 0;
  894. }
  895. static int pm3fb_set_par(struct fb_info *info)
  896. {
  897. struct pm3_par *par = info->par;
  898. const u32 xres = (info->var.xres + 31) & ~31;
  899. const unsigned bpp = info->var.bits_per_pixel;
  900. par->base = pm3fb_shift_bpp(bpp, (info->var.yoffset * xres)
  901. + info->var.xoffset);
  902. par->video = 0;
  903. if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
  904. par->video |= PM3VideoControl_HSYNC_ACTIVE_HIGH;
  905. else
  906. par->video |= PM3VideoControl_HSYNC_ACTIVE_LOW;
  907. if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
  908. par->video |= PM3VideoControl_VSYNC_ACTIVE_HIGH;
  909. else
  910. par->video |= PM3VideoControl_VSYNC_ACTIVE_LOW;
  911. if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE)
  912. par->video |= PM3VideoControl_LINE_DOUBLE_ON;
  913. if ((info->var.activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW)
  914. par->video |= PM3VideoControl_ENABLE;
  915. else
  916. DPRINTK("PM3Video disabled\n");
  917. switch (bpp) {
  918. case 8:
  919. par->video |= PM3VideoControl_PIXELSIZE_8BIT;
  920. break;
  921. case 16:
  922. par->video |= PM3VideoControl_PIXELSIZE_16BIT;
  923. break;
  924. case 32:
  925. par->video |= PM3VideoControl_PIXELSIZE_32BIT;
  926. break;
  927. default:
  928. DPRINTK("Unsupported depth\n");
  929. break;
  930. }
  931. info->fix.visual =
  932. (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
  933. info->fix.line_length = ((info->var.xres_virtual + 7) >> 3) * bpp;
  934. /* pm3fb_clear_memory(info, 0);*/
  935. pm3fb_clear_colormap(par, 0, 0, 0);
  936. PM3_WRITE_DAC_REG(par, PM3RD_CursorMode, 0);
  937. pm3fb_init_engine(info);
  938. pm3fb_write_mode(info);
  939. return 0;
  940. }
  941. static int pm3fb_setcolreg(unsigned regno, unsigned red, unsigned green,
  942. unsigned blue, unsigned transp,
  943. struct fb_info *info)
  944. {
  945. struct pm3_par *par = info->par;
  946. if (regno >= 256) /* no. of hw registers */
  947. return -EINVAL;
  948. /* grayscale works only partially under directcolor */
  949. /* grayscale = 0.30*R + 0.59*G + 0.11*B */
  950. if (info->var.grayscale)
  951. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  952. /* Directcolor:
  953. * var->{color}.offset contains start of bitfield
  954. * var->{color}.length contains length of bitfield
  955. * {hardwarespecific} contains width of DAC
  956. * pseudo_palette[X] is programmed to (X << red.offset) |
  957. * (X << green.offset) |
  958. * (X << blue.offset)
  959. * RAMDAC[X] is programmed to (red, green, blue)
  960. * color depth = SUM(var->{color}.length)
  961. *
  962. * Pseudocolor:
  963. * var->{color}.offset is 0
  964. * var->{color}.length contains width of DAC or the number
  965. * of unique colors available (color depth)
  966. * pseudo_palette is not used
  967. * RAMDAC[X] is programmed to (red, green, blue)
  968. * color depth = var->{color}.length
  969. */
  970. /*
  971. * This is the point where the color is converted to something that
  972. * is acceptable by the hardware.
  973. */
  974. #define CNVT_TOHW(val, width) ((((val) << (width)) + 0x7FFF - (val)) >> 16)
  975. red = CNVT_TOHW(red, info->var.red.length);
  976. green = CNVT_TOHW(green, info->var.green.length);
  977. blue = CNVT_TOHW(blue, info->var.blue.length);
  978. transp = CNVT_TOHW(transp, info->var.transp.length);
  979. #undef CNVT_TOHW
  980. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  981. info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  982. u32 v;
  983. if (regno >= 16)
  984. return -EINVAL;
  985. v = (red << info->var.red.offset) |
  986. (green << info->var.green.offset) |
  987. (blue << info->var.blue.offset) |
  988. (transp << info->var.transp.offset);
  989. switch (info->var.bits_per_pixel) {
  990. case 8:
  991. break;
  992. case 16:
  993. case 32:
  994. ((u32 *)(info->pseudo_palette))[regno] = v;
  995. break;
  996. }
  997. return 0;
  998. } else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
  999. pm3fb_set_color(par, regno, red, green, blue);
  1000. return 0;
  1001. }
  1002. static int pm3fb_pan_display(struct fb_var_screeninfo *var,
  1003. struct fb_info *info)
  1004. {
  1005. struct pm3_par *par = info->par;
  1006. const u32 xres = (var->xres + 31) & ~31;
  1007. par->base = pm3fb_shift_bpp(var->bits_per_pixel,
  1008. (var->yoffset * xres)
  1009. + var->xoffset);
  1010. PM3_WAIT(par, 1);
  1011. PM3_WRITE_REG(par, PM3ScreenBase, par->base);
  1012. return 0;
  1013. }
  1014. static int pm3fb_blank(int blank_mode, struct fb_info *info)
  1015. {
  1016. struct pm3_par *par = info->par;
  1017. u32 video = par->video;
  1018. /*
  1019. * Oxygen VX1 - it appears that setting PM3VideoControl and
  1020. * then PM3RD_SyncControl to the same SYNC settings undoes
  1021. * any net change - they seem to xor together. Only set the
  1022. * sync options in PM3RD_SyncControl. --rmk
  1023. */
  1024. video &= ~(PM3VideoControl_HSYNC_MASK |
  1025. PM3VideoControl_VSYNC_MASK);
  1026. video |= PM3VideoControl_HSYNC_ACTIVE_HIGH |
  1027. PM3VideoControl_VSYNC_ACTIVE_HIGH;
  1028. switch (blank_mode) {
  1029. case FB_BLANK_UNBLANK:
  1030. video |= PM3VideoControl_ENABLE;
  1031. break;
  1032. case FB_BLANK_NORMAL:
  1033. video &= ~PM3VideoControl_ENABLE;
  1034. break;
  1035. case FB_BLANK_HSYNC_SUSPEND:
  1036. video &= ~(PM3VideoControl_HSYNC_MASK |
  1037. PM3VideoControl_BLANK_ACTIVE_LOW);
  1038. break;
  1039. case FB_BLANK_VSYNC_SUSPEND:
  1040. video &= ~(PM3VideoControl_VSYNC_MASK |
  1041. PM3VideoControl_BLANK_ACTIVE_LOW);
  1042. break;
  1043. case FB_BLANK_POWERDOWN:
  1044. video &= ~(PM3VideoControl_HSYNC_MASK |
  1045. PM3VideoControl_VSYNC_MASK |
  1046. PM3VideoControl_BLANK_ACTIVE_LOW);
  1047. break;
  1048. default:
  1049. DPRINTK("Unsupported blanking %d\n", blank_mode);
  1050. return 1;
  1051. }
  1052. PM3_WAIT(par, 1);
  1053. PM3_WRITE_REG(par, PM3VideoControl, video);
  1054. return 0;
  1055. }
  1056. /*
  1057. * Frame buffer operations
  1058. */
  1059. static struct fb_ops pm3fb_ops = {
  1060. .owner = THIS_MODULE,
  1061. .fb_check_var = pm3fb_check_var,
  1062. .fb_set_par = pm3fb_set_par,
  1063. .fb_setcolreg = pm3fb_setcolreg,
  1064. .fb_pan_display = pm3fb_pan_display,
  1065. .fb_fillrect = pm3fb_fillrect,
  1066. .fb_copyarea = pm3fb_copyarea,
  1067. .fb_imageblit = pm3fb_imageblit,
  1068. .fb_blank = pm3fb_blank,
  1069. .fb_sync = pm3fb_sync,
  1070. .fb_cursor = pm3fb_cursor,
  1071. };
  1072. /* ------------------------------------------------------------------------- */
  1073. /*
  1074. * Initialization
  1075. */
  1076. /* mmio register are already mapped when this function is called */
  1077. /* the pm3fb_fix.smem_start is also set */
  1078. static unsigned long __devinit pm3fb_size_memory(struct pm3_par *par)
  1079. {
  1080. unsigned long memsize = 0;
  1081. unsigned long tempBypass, i, temp1, temp2;
  1082. unsigned char __iomem *screen_mem;
  1083. pm3fb_fix.smem_len = 64 * 1024l * 1024; /* request full aperture size */
  1084. /* Linear frame buffer - request region and map it. */
  1085. if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len,
  1086. "pm3fb smem")) {
  1087. printk(KERN_WARNING "pm3fb: Can't reserve smem.\n");
  1088. return 0;
  1089. }
  1090. screen_mem =
  1091. ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
  1092. if (!screen_mem) {
  1093. printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n");
  1094. release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
  1095. return 0;
  1096. }
  1097. /* TODO: card-specific stuff, *before* accessing *any* FB memory */
  1098. /* For Appian Jeronimo 2000 board second head */
  1099. tempBypass = PM3_READ_REG(par, PM3MemBypassWriteMask);
  1100. DPRINTK("PM3MemBypassWriteMask was: 0x%08lx\n", tempBypass);
  1101. PM3_WAIT(par, 1);
  1102. PM3_WRITE_REG(par, PM3MemBypassWriteMask, 0xFFFFFFFF);
  1103. /* pm3 split up memory, replicates, and do a lot of
  1104. * nasty stuff IMHO ;-)
  1105. */
  1106. for (i = 0; i < 32; i++) {
  1107. fb_writel(i * 0x00345678,
  1108. (screen_mem + (i * 1048576)));
  1109. mb();
  1110. temp1 = fb_readl((screen_mem + (i * 1048576)));
  1111. /* Let's check for wrapover, write will fail at 16MB boundary */
  1112. if (temp1 == (i * 0x00345678))
  1113. memsize = i;
  1114. else
  1115. break;
  1116. }
  1117. DPRINTK("First detect pass already got %ld MB\n", memsize + 1);
  1118. if (memsize + 1 == i) {
  1119. for (i = 0; i < 32; i++) {
  1120. /* Clear first 32MB ; 0 is 0, no need to byteswap */
  1121. writel(0x0000000, (screen_mem + (i * 1048576)));
  1122. }
  1123. wmb();
  1124. for (i = 32; i < 64; i++) {
  1125. fb_writel(i * 0x00345678,
  1126. (screen_mem + (i * 1048576)));
  1127. mb();
  1128. temp1 =
  1129. fb_readl((screen_mem + (i * 1048576)));
  1130. temp2 =
  1131. fb_readl((screen_mem + ((i - 32) * 1048576)));
  1132. /* different value, different RAM... */
  1133. if ((temp1 == (i * 0x00345678)) && (temp2 == 0))
  1134. memsize = i;
  1135. else
  1136. break;
  1137. }
  1138. }
  1139. DPRINTK("Second detect pass got %ld MB\n", memsize + 1);
  1140. PM3_WAIT(par, 1);
  1141. PM3_WRITE_REG(par, PM3MemBypassWriteMask, tempBypass);
  1142. iounmap(screen_mem);
  1143. release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
  1144. memsize = 1048576 * (memsize + 1);
  1145. DPRINTK("Returning 0x%08lx bytes\n", memsize);
  1146. return memsize;
  1147. }
  1148. static int __devinit pm3fb_probe(struct pci_dev *dev,
  1149. const struct pci_device_id *ent)
  1150. {
  1151. struct fb_info *info;
  1152. struct pm3_par *par;
  1153. struct device *device = &dev->dev; /* for pci drivers */
  1154. int err;
  1155. int retval = -ENXIO;
  1156. err = pci_enable_device(dev);
  1157. if (err) {
  1158. printk(KERN_WARNING "pm3fb: Can't enable PCI dev: %d\n", err);
  1159. return err;
  1160. }
  1161. /*
  1162. * Dynamically allocate info and par
  1163. */
  1164. info = framebuffer_alloc(sizeof(struct pm3_par), device);
  1165. if (!info)
  1166. return -ENOMEM;
  1167. par = info->par;
  1168. /*
  1169. * Here we set the screen_base to the virtual memory address
  1170. * for the framebuffer.
  1171. */
  1172. pm3fb_fix.mmio_start = pci_resource_start(dev, 0);
  1173. pm3fb_fix.mmio_len = PM3_REGS_SIZE;
  1174. #if defined(__BIG_ENDIAN)
  1175. pm3fb_fix.mmio_start += PM3_REGS_SIZE;
  1176. DPRINTK("Adjusting register base for big-endian.\n");
  1177. #endif
  1178. /* Registers - request region and map it. */
  1179. if (!request_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len,
  1180. "pm3fb regbase")) {
  1181. printk(KERN_WARNING "pm3fb: Can't reserve regbase.\n");
  1182. goto err_exit_neither;
  1183. }
  1184. par->v_regs =
  1185. ioremap_nocache(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
  1186. if (!par->v_regs) {
  1187. printk(KERN_WARNING "pm3fb: Can't remap %s register area.\n",
  1188. pm3fb_fix.id);
  1189. release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
  1190. goto err_exit_neither;
  1191. }
  1192. /* Linear frame buffer - request region and map it. */
  1193. pm3fb_fix.smem_start = pci_resource_start(dev, 1);
  1194. pm3fb_fix.smem_len = pm3fb_size_memory(par);
  1195. if (!pm3fb_fix.smem_len) {
  1196. printk(KERN_WARNING "pm3fb: Can't find memory on board.\n");
  1197. goto err_exit_mmio;
  1198. }
  1199. if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len,
  1200. "pm3fb smem")) {
  1201. printk(KERN_WARNING "pm3fb: Can't reserve smem.\n");
  1202. goto err_exit_mmio;
  1203. }
  1204. info->screen_base =
  1205. ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
  1206. if (!info->screen_base) {
  1207. printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n");
  1208. release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
  1209. goto err_exit_mmio;
  1210. }
  1211. info->screen_size = pm3fb_fix.smem_len;
  1212. #ifdef CONFIG_MTRR
  1213. if (!nomtrr)
  1214. par->mtrr_handle = mtrr_add(pm3fb_fix.smem_start,
  1215. pm3fb_fix.smem_len,
  1216. MTRR_TYPE_WRCOMB, 1);
  1217. #endif
  1218. info->fbops = &pm3fb_ops;
  1219. par->video = PM3_READ_REG(par, PM3VideoControl);
  1220. info->fix = pm3fb_fix;
  1221. info->pseudo_palette = par->palette;
  1222. info->flags = FBINFO_DEFAULT |
  1223. FBINFO_HWACCEL_XPAN |
  1224. FBINFO_HWACCEL_YPAN |
  1225. FBINFO_HWACCEL_COPYAREA |
  1226. FBINFO_HWACCEL_IMAGEBLIT |
  1227. FBINFO_HWACCEL_FILLRECT;
  1228. if (noaccel) {
  1229. printk(KERN_DEBUG "disabling acceleration\n");
  1230. info->flags |= FBINFO_HWACCEL_DISABLED;
  1231. }
  1232. info->pixmap.addr = kmalloc(PM3_PIXMAP_SIZE, GFP_KERNEL);
  1233. if (!info->pixmap.addr) {
  1234. retval = -ENOMEM;
  1235. goto err_exit_pixmap;
  1236. }
  1237. info->pixmap.size = PM3_PIXMAP_SIZE;
  1238. info->pixmap.buf_align = 4;
  1239. info->pixmap.scan_align = 4;
  1240. info->pixmap.access_align = 32;
  1241. info->pixmap.flags = FB_PIXMAP_SYSTEM;
  1242. /*
  1243. * This should give a reasonable default video mode. The following is
  1244. * done when we can set a video mode.
  1245. */
  1246. if (!mode_option)
  1247. mode_option = "640x480@60";
  1248. retval = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
  1249. if (!retval || retval == 4) {
  1250. retval = -EINVAL;
  1251. goto err_exit_both;
  1252. }
  1253. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
  1254. retval = -ENOMEM;
  1255. goto err_exit_both;
  1256. }
  1257. /*
  1258. * For drivers that can...
  1259. */
  1260. pm3fb_check_var(&info->var, info);
  1261. if (register_framebuffer(info) < 0) {
  1262. retval = -EINVAL;
  1263. goto err_exit_all;
  1264. }
  1265. printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
  1266. info->fix.id);
  1267. pci_set_drvdata(dev, info);
  1268. return 0;
  1269. err_exit_all:
  1270. fb_dealloc_cmap(&info->cmap);
  1271. err_exit_both:
  1272. kfree(info->pixmap.addr);
  1273. err_exit_pixmap:
  1274. iounmap(info->screen_base);
  1275. release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
  1276. err_exit_mmio:
  1277. iounmap(par->v_regs);
  1278. release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
  1279. err_exit_neither:
  1280. framebuffer_release(info);
  1281. return retval;
  1282. }
  1283. /*
  1284. * Cleanup
  1285. */
  1286. static void __devexit pm3fb_remove(struct pci_dev *dev)
  1287. {
  1288. struct fb_info *info = pci_get_drvdata(dev);
  1289. if (info) {
  1290. struct fb_fix_screeninfo *fix = &info->fix;
  1291. struct pm3_par *par = info->par;
  1292. unregister_framebuffer(info);
  1293. fb_dealloc_cmap(&info->cmap);
  1294. #ifdef CONFIG_MTRR
  1295. if (par->mtrr_handle >= 0)
  1296. mtrr_del(par->mtrr_handle, info->fix.smem_start,
  1297. info->fix.smem_len);
  1298. #endif /* CONFIG_MTRR */
  1299. iounmap(info->screen_base);
  1300. release_mem_region(fix->smem_start, fix->smem_len);
  1301. iounmap(par->v_regs);
  1302. release_mem_region(fix->mmio_start, fix->mmio_len);
  1303. pci_set_drvdata(dev, NULL);
  1304. kfree(info->pixmap.addr);
  1305. framebuffer_release(info);
  1306. }
  1307. }
  1308. static struct pci_device_id pm3fb_id_table[] = {
  1309. { PCI_VENDOR_ID_3DLABS, 0x0a,
  1310. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  1311. { 0, }
  1312. };
  1313. /* For PCI drivers */
  1314. static struct pci_driver pm3fb_driver = {
  1315. .name = "pm3fb",
  1316. .id_table = pm3fb_id_table,
  1317. .probe = pm3fb_probe,
  1318. .remove = __devexit_p(pm3fb_remove),
  1319. };
  1320. MODULE_DEVICE_TABLE(pci, pm3fb_id_table);
  1321. #ifndef MODULE
  1322. /*
  1323. * Setup
  1324. */
  1325. /*
  1326. * Only necessary if your driver takes special options,
  1327. * otherwise we fall back on the generic fb_setup().
  1328. */
  1329. static int __init pm3fb_setup(char *options)
  1330. {
  1331. char *this_opt;
  1332. /* Parse user speficied options (`video=pm3fb:') */
  1333. if (!options || !*options)
  1334. return 0;
  1335. while ((this_opt = strsep(&options, ",")) != NULL) {
  1336. if (!*this_opt)
  1337. continue;
  1338. else if (!strncmp(this_opt, "noaccel", 7))
  1339. noaccel = 1;
  1340. else if (!strncmp(this_opt, "hwcursor=", 9))
  1341. hwcursor = simple_strtoul(this_opt + 9, NULL, 0);
  1342. #ifdef CONFIG_MTRR
  1343. else if (!strncmp(this_opt, "nomtrr", 6))
  1344. nomtrr = 1;
  1345. #endif
  1346. else
  1347. mode_option = this_opt;
  1348. }
  1349. return 0;
  1350. }
  1351. #endif /* MODULE */
  1352. static int __init pm3fb_init(void)
  1353. {
  1354. /*
  1355. * For kernel boot options (in 'video=pm3fb:<options>' format)
  1356. */
  1357. #ifndef MODULE
  1358. char *option = NULL;
  1359. if (fb_get_options("pm3fb", &option))
  1360. return -ENODEV;
  1361. pm3fb_setup(option);
  1362. #endif
  1363. return pci_register_driver(&pm3fb_driver);
  1364. }
  1365. #ifdef MODULE
  1366. static void __exit pm3fb_exit(void)
  1367. {
  1368. pci_unregister_driver(&pm3fb_driver);
  1369. }
  1370. module_exit(pm3fb_exit);
  1371. #endif
  1372. module_init(pm3fb_init);
  1373. module_param(mode_option, charp, 0);
  1374. MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
  1375. module_param(noaccel, bool, 0);
  1376. MODULE_PARM_DESC(noaccel, "Disable acceleration");
  1377. module_param(hwcursor, int, 0644);
  1378. MODULE_PARM_DESC(hwcursor, "Enable hardware cursor "
  1379. "(1=enable, 0=disable, default=1)");
  1380. #ifdef CONFIG_MTRR
  1381. module_param(nomtrr, bool, 0);
  1382. MODULE_PARM_DESC(nomtrr, "Disable MTRR support (0 or 1=disabled) (default=0)");
  1383. #endif
  1384. MODULE_DESCRIPTION("Permedia3 framebuffer device driver");
  1385. MODULE_LICENSE("GPL");