pm2fb.c 49 KB

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