pm2fb.c 49 KB

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