pm2fb.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  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/config.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/tty.h>
  37. #include <linux/slab.h>
  38. #include <linux/delay.h>
  39. #include <linux/fb.h>
  40. #include <linux/init.h>
  41. #include <linux/pci.h>
  42. #include <video/permedia2.h>
  43. #include <video/cvisionppc.h>
  44. #if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
  45. #error "The endianness of the target host has not been defined."
  46. #endif
  47. #if !defined(CONFIG_PCI)
  48. #error "Only generic PCI cards supported."
  49. #endif
  50. #undef PM2FB_MASTER_DEBUG
  51. #ifdef PM2FB_MASTER_DEBUG
  52. #define DPRINTK(a,b...) printk(KERN_DEBUG "pm2fb: %s: " a, __FUNCTION__ , ## b)
  53. #else
  54. #define DPRINTK(a,b...)
  55. #endif
  56. /*
  57. * Driver data
  58. */
  59. static char *mode __devinitdata = NULL;
  60. /*
  61. * The XFree GLINT driver will (I think to implement hardware cursor
  62. * support on TVP4010 and similar where there is no RAMDAC - see
  63. * comment in set_video) always request +ve sync regardless of what
  64. * the mode requires. This screws me because I have a Sun
  65. * fixed-frequency monitor which absolutely has to have -ve sync. So
  66. * these flags allow the user to specify that requests for +ve sync
  67. * should be silently turned in -ve sync.
  68. */
  69. static int lowhsync __devinitdata = 0;
  70. static int lowvsync __devinitdata = 0;
  71. /*
  72. * The hardware state of the graphics card that isn't part of the
  73. * screeninfo.
  74. */
  75. struct pm2fb_par
  76. {
  77. pm2type_t type; /* Board type */
  78. u32 fb_size; /* framebuffer memory size */
  79. unsigned char __iomem *v_fb; /* virtual address of frame buffer */
  80. unsigned char __iomem *v_regs;/* virtual address of p_regs */
  81. u32 memclock; /* memclock */
  82. u32 video; /* video flags before blanking */
  83. u32 mem_config; /* MemConfig reg at probe */
  84. u32 mem_control; /* MemControl reg at probe */
  85. u32 boot_address; /* BootAddress reg at probe */
  86. u32 palette[16];
  87. };
  88. /*
  89. * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
  90. * if we don't use modedb.
  91. */
  92. static struct fb_fix_screeninfo pm2fb_fix __devinitdata = {
  93. .id = "",
  94. .type = FB_TYPE_PACKED_PIXELS,
  95. .visual = FB_VISUAL_PSEUDOCOLOR,
  96. .xpanstep = 1,
  97. .ypanstep = 1,
  98. .ywrapstep = 0,
  99. .accel = FB_ACCEL_NONE,
  100. };
  101. /*
  102. * Default video mode. In case the modedb doesn't work.
  103. */
  104. static struct fb_var_screeninfo pm2fb_var __devinitdata = {
  105. /* "640x480, 8 bpp @ 60 Hz */
  106. .xres = 640,
  107. .yres = 480,
  108. .xres_virtual = 640,
  109. .yres_virtual = 480,
  110. .bits_per_pixel =8,
  111. .red = {0, 8, 0},
  112. .blue = {0, 8, 0},
  113. .green = {0, 8, 0},
  114. .activate = FB_ACTIVATE_NOW,
  115. .height = -1,
  116. .width = -1,
  117. .accel_flags = 0,
  118. .pixclock = 39721,
  119. .left_margin = 40,
  120. .right_margin = 24,
  121. .upper_margin = 32,
  122. .lower_margin = 11,
  123. .hsync_len = 96,
  124. .vsync_len = 2,
  125. .vmode = FB_VMODE_NONINTERLACED
  126. };
  127. /*
  128. * Utility functions
  129. */
  130. static inline u32 RD32(unsigned char __iomem *base, s32 off)
  131. {
  132. return fb_readl(base + off);
  133. }
  134. static inline void WR32(unsigned char __iomem *base, s32 off, u32 v)
  135. {
  136. fb_writel(v, base + off);
  137. }
  138. static inline u32 pm2_RD(struct pm2fb_par* p, s32 off)
  139. {
  140. return RD32(p->v_regs, off);
  141. }
  142. static inline void pm2_WR(struct pm2fb_par* p, s32 off, u32 v)
  143. {
  144. WR32(p->v_regs, off, v);
  145. }
  146. static inline u32 pm2_RDAC_RD(struct pm2fb_par* p, s32 idx)
  147. {
  148. int index = PM2R_RD_INDEXED_DATA;
  149. switch (p->type) {
  150. case PM2_TYPE_PERMEDIA2:
  151. pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, idx);
  152. break;
  153. case PM2_TYPE_PERMEDIA2V:
  154. pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff);
  155. index = PM2VR_RD_INDEXED_DATA;
  156. break;
  157. }
  158. mb();
  159. return pm2_RD(p, index);
  160. }
  161. static inline void pm2_RDAC_WR(struct pm2fb_par* p, s32 idx, u32 v)
  162. {
  163. int index = PM2R_RD_INDEXED_DATA;
  164. switch (p->type) {
  165. case PM2_TYPE_PERMEDIA2:
  166. pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, idx);
  167. break;
  168. case PM2_TYPE_PERMEDIA2V:
  169. pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff);
  170. index = PM2VR_RD_INDEXED_DATA;
  171. break;
  172. }
  173. mb();
  174. pm2_WR(p, index, v);
  175. }
  176. static inline void pm2v_RDAC_WR(struct pm2fb_par* p, s32 idx, u32 v)
  177. {
  178. pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff);
  179. mb();
  180. pm2_WR(p, PM2VR_RD_INDEXED_DATA, v);
  181. }
  182. #ifdef CONFIG_FB_PM2_FIFO_DISCONNECT
  183. #define WAIT_FIFO(p,a)
  184. #else
  185. static inline void WAIT_FIFO(struct pm2fb_par* p, u32 a)
  186. {
  187. while( pm2_RD(p, PM2R_IN_FIFO_SPACE) < a );
  188. mb();
  189. }
  190. #endif
  191. /*
  192. * partial products for the supported horizontal resolutions.
  193. */
  194. #define PACKPP(p0,p1,p2) (((p2) << 6) | ((p1) << 3) | (p0))
  195. static const struct {
  196. u16 width;
  197. u16 pp;
  198. } pp_table[] = {
  199. { 32, PACKPP(1, 0, 0) }, { 64, PACKPP(1, 1, 0) },
  200. { 96, PACKPP(1, 1, 1) }, { 128, PACKPP(2, 1, 1) },
  201. { 160, PACKPP(2, 2, 1) }, { 192, PACKPP(2, 2, 2) },
  202. { 224, PACKPP(3, 2, 1) }, { 256, PACKPP(3, 2, 2) },
  203. { 288, PACKPP(3, 3, 1) }, { 320, PACKPP(3, 3, 2) },
  204. { 384, PACKPP(3, 3, 3) }, { 416, PACKPP(4, 3, 1) },
  205. { 448, PACKPP(4, 3, 2) }, { 512, PACKPP(4, 3, 3) },
  206. { 544, PACKPP(4, 4, 1) }, { 576, PACKPP(4, 4, 2) },
  207. { 640, PACKPP(4, 4, 3) }, { 768, PACKPP(4, 4, 4) },
  208. { 800, PACKPP(5, 4, 1) }, { 832, PACKPP(5, 4, 2) },
  209. { 896, PACKPP(5, 4, 3) }, { 1024, PACKPP(5, 4, 4) },
  210. { 1056, PACKPP(5, 5, 1) }, { 1088, PACKPP(5, 5, 2) },
  211. { 1152, PACKPP(5, 5, 3) }, { 1280, PACKPP(5, 5, 4) },
  212. { 1536, PACKPP(5, 5, 5) }, { 1568, PACKPP(6, 5, 1) },
  213. { 1600, PACKPP(6, 5, 2) }, { 1664, PACKPP(6, 5, 3) },
  214. { 1792, PACKPP(6, 5, 4) }, { 2048, PACKPP(6, 5, 5) },
  215. { 0, 0 } };
  216. static u32 partprod(u32 xres)
  217. {
  218. int i;
  219. for (i = 0; pp_table[i].width && pp_table[i].width != xres; i++)
  220. ;
  221. if ( pp_table[i].width == 0 )
  222. DPRINTK("invalid width %u\n", xres);
  223. return pp_table[i].pp;
  224. }
  225. static u32 to3264(u32 timing, int bpp, int is64)
  226. {
  227. switch (bpp) {
  228. case 8:
  229. timing >>= 2 + is64;
  230. break;
  231. case 16:
  232. timing >>= 1 + is64;
  233. break;
  234. case 24:
  235. timing = (timing * 3) >> (2 + is64);
  236. break;
  237. case 32:
  238. if (is64)
  239. timing >>= 1;
  240. break;
  241. }
  242. return timing;
  243. }
  244. static void pm2_mnp(u32 clk, unsigned char* mm, unsigned char* nn,
  245. unsigned char* pp)
  246. {
  247. unsigned char m;
  248. unsigned char n;
  249. unsigned char p;
  250. u32 f;
  251. s32 curr;
  252. s32 delta = 100000;
  253. *mm = *nn = *pp = 0;
  254. for (n = 2; n < 15; n++) {
  255. for (m = 2; m; m++) {
  256. f = PM2_REFERENCE_CLOCK * m / n;
  257. if (f >= 150000 && f <= 300000) {
  258. for ( p = 0; p < 5; p++, f >>= 1) {
  259. curr = ( clk > f ) ? clk - f : f - clk;
  260. if ( curr < delta ) {
  261. delta=curr;
  262. *mm=m;
  263. *nn=n;
  264. *pp=p;
  265. }
  266. }
  267. }
  268. }
  269. }
  270. }
  271. static void pm2v_mnp(u32 clk, unsigned char* mm, unsigned char* nn,
  272. unsigned char* pp)
  273. {
  274. unsigned char m;
  275. unsigned char n;
  276. unsigned char p;
  277. u32 f;
  278. s32 delta = 1000;
  279. *mm = *nn = *pp = 0;
  280. for (n = 1; n; n++) {
  281. for ( m = 1; m; m++) {
  282. for ( p = 0; p < 2; p++) {
  283. f = PM2_REFERENCE_CLOCK * n / (m * (1 << (p + 1)));
  284. if ( clk > f - delta && clk < f + delta ) {
  285. delta = ( clk > f ) ? clk - f : f - clk;
  286. *mm=m;
  287. *nn=n;
  288. *pp=p;
  289. }
  290. }
  291. }
  292. }
  293. }
  294. static void clear_palette(struct pm2fb_par* p) {
  295. int i=256;
  296. WAIT_FIFO(p, 1);
  297. pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, 0);
  298. wmb();
  299. while (i--) {
  300. WAIT_FIFO(p, 3);
  301. pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
  302. pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
  303. pm2_WR(p, PM2R_RD_PALETTE_DATA, 0);
  304. }
  305. }
  306. static void reset_card(struct pm2fb_par* p)
  307. {
  308. if (p->type == PM2_TYPE_PERMEDIA2V)
  309. pm2_WR(p, PM2VR_RD_INDEX_HIGH, 0);
  310. pm2_WR(p, PM2R_RESET_STATUS, 0);
  311. mb();
  312. while (pm2_RD(p, PM2R_RESET_STATUS) & PM2F_BEING_RESET)
  313. ;
  314. mb();
  315. #ifdef CONFIG_FB_PM2_FIFO_DISCONNECT
  316. DPRINTK("FIFO disconnect enabled\n");
  317. pm2_WR(p, PM2R_FIFO_DISCON, 1);
  318. mb();
  319. #endif
  320. /* Restore stashed memory config information from probe */
  321. WAIT_FIFO(p, 3);
  322. pm2_WR(p, PM2R_MEM_CONTROL, p->mem_control);
  323. pm2_WR(p, PM2R_BOOT_ADDRESS, p->boot_address);
  324. wmb();
  325. pm2_WR(p, PM2R_MEM_CONFIG, p->mem_config);
  326. }
  327. static void reset_config(struct pm2fb_par* p)
  328. {
  329. WAIT_FIFO(p, 52);
  330. pm2_WR(p, PM2R_CHIP_CONFIG, pm2_RD(p, PM2R_CHIP_CONFIG)&
  331. ~(PM2F_VGA_ENABLE|PM2F_VGA_FIXED));
  332. pm2_WR(p, PM2R_BYPASS_WRITE_MASK, ~(0L));
  333. pm2_WR(p, PM2R_FRAMEBUFFER_WRITE_MASK, ~(0L));
  334. pm2_WR(p, PM2R_FIFO_CONTROL, 0);
  335. pm2_WR(p, PM2R_APERTURE_ONE, 0);
  336. pm2_WR(p, PM2R_APERTURE_TWO, 0);
  337. pm2_WR(p, PM2R_RASTERIZER_MODE, 0);
  338. pm2_WR(p, PM2R_DELTA_MODE, PM2F_DELTA_ORDER_RGB);
  339. pm2_WR(p, PM2R_LB_READ_FORMAT, 0);
  340. pm2_WR(p, PM2R_LB_WRITE_FORMAT, 0);
  341. pm2_WR(p, PM2R_LB_READ_MODE, 0);
  342. pm2_WR(p, PM2R_LB_SOURCE_OFFSET, 0);
  343. pm2_WR(p, PM2R_FB_SOURCE_OFFSET, 0);
  344. pm2_WR(p, PM2R_FB_PIXEL_OFFSET, 0);
  345. pm2_WR(p, PM2R_FB_WINDOW_BASE, 0);
  346. pm2_WR(p, PM2R_LB_WINDOW_BASE, 0);
  347. pm2_WR(p, PM2R_FB_SOFT_WRITE_MASK, ~(0L));
  348. pm2_WR(p, PM2R_FB_HARD_WRITE_MASK, ~(0L));
  349. pm2_WR(p, PM2R_FB_READ_PIXEL, 0);
  350. pm2_WR(p, PM2R_DITHER_MODE, 0);
  351. pm2_WR(p, PM2R_AREA_STIPPLE_MODE, 0);
  352. pm2_WR(p, PM2R_DEPTH_MODE, 0);
  353. pm2_WR(p, PM2R_STENCIL_MODE, 0);
  354. pm2_WR(p, PM2R_TEXTURE_ADDRESS_MODE, 0);
  355. pm2_WR(p, PM2R_TEXTURE_READ_MODE, 0);
  356. pm2_WR(p, PM2R_TEXEL_LUT_MODE, 0);
  357. pm2_WR(p, PM2R_YUV_MODE, 0);
  358. pm2_WR(p, PM2R_COLOR_DDA_MODE, 0);
  359. pm2_WR(p, PM2R_TEXTURE_COLOR_MODE, 0);
  360. pm2_WR(p, PM2R_FOG_MODE, 0);
  361. pm2_WR(p, PM2R_ALPHA_BLEND_MODE, 0);
  362. pm2_WR(p, PM2R_LOGICAL_OP_MODE, 0);
  363. pm2_WR(p, PM2R_STATISTICS_MODE, 0);
  364. pm2_WR(p, PM2R_SCISSOR_MODE, 0);
  365. pm2_WR(p, PM2R_FILTER_MODE, PM2F_SYNCHRONIZATION);
  366. switch (p->type) {
  367. case PM2_TYPE_PERMEDIA2:
  368. pm2_RDAC_WR(p, PM2I_RD_MODE_CONTROL, 0); /* no overlay */
  369. pm2_RDAC_WR(p, PM2I_RD_CURSOR_CONTROL, 0);
  370. pm2_RDAC_WR(p, PM2I_RD_MISC_CONTROL, PM2F_RD_PALETTE_WIDTH_8);
  371. break;
  372. case PM2_TYPE_PERMEDIA2V:
  373. pm2v_RDAC_WR(p, PM2VI_RD_MISC_CONTROL, 1); /* 8bit */
  374. break;
  375. }
  376. pm2_RDAC_WR(p, PM2I_RD_COLOR_KEY_CONTROL, 0);
  377. pm2_RDAC_WR(p, PM2I_RD_OVERLAY_KEY, 0);
  378. pm2_RDAC_WR(p, PM2I_RD_RED_KEY, 0);
  379. pm2_RDAC_WR(p, PM2I_RD_GREEN_KEY, 0);
  380. pm2_RDAC_WR(p, PM2I_RD_BLUE_KEY, 0);
  381. }
  382. static void set_aperture(struct pm2fb_par* p, u32 depth)
  383. {
  384. /*
  385. * The hardware is little-endian. When used in big-endian
  386. * hosts, the on-chip aperture settings are used where
  387. * possible to translate from host to card byte order.
  388. */
  389. WAIT_FIFO(p, 4);
  390. #ifdef __LITTLE_ENDIAN
  391. pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_STANDARD);
  392. #else
  393. switch (depth) {
  394. case 24: /* RGB->BGR */
  395. /*
  396. * We can't use the aperture to translate host to
  397. * card byte order here, so we switch to BGR mode
  398. * in pm2fb_set_par().
  399. */
  400. case 8: /* B->B */
  401. pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_STANDARD);
  402. break;
  403. case 16: /* HL->LH */
  404. pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_HALFWORDSWAP);
  405. break;
  406. case 32: /* RGBA->ABGR */
  407. pm2_WR(p, PM2R_APERTURE_ONE, PM2F_APERTURE_BYTESWAP);
  408. break;
  409. }
  410. #endif
  411. // We don't use aperture two, so this may be superflous
  412. pm2_WR(p, PM2R_APERTURE_TWO, PM2F_APERTURE_STANDARD);
  413. }
  414. static void set_color(struct pm2fb_par* p, unsigned char regno,
  415. unsigned char r, unsigned char g, unsigned char b)
  416. {
  417. WAIT_FIFO(p, 4);
  418. pm2_WR(p, PM2R_RD_PALETTE_WRITE_ADDRESS, regno);
  419. wmb();
  420. pm2_WR(p, PM2R_RD_PALETTE_DATA, r);
  421. wmb();
  422. pm2_WR(p, PM2R_RD_PALETTE_DATA, g);
  423. wmb();
  424. pm2_WR(p, PM2R_RD_PALETTE_DATA, b);
  425. }
  426. static void set_memclock(struct pm2fb_par* par, u32 clk)
  427. {
  428. int i;
  429. unsigned char m, n, p;
  430. pm2_mnp(clk, &m, &n, &p);
  431. WAIT_FIFO(par, 10);
  432. pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 6);
  433. wmb();
  434. pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_1, m);
  435. pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_2, n);
  436. wmb();
  437. pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 8|p);
  438. wmb();
  439. pm2_RDAC_RD(par, PM2I_RD_MEMORY_CLOCK_STATUS);
  440. rmb();
  441. for (i = 256;
  442. i && !(pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED);
  443. i--)
  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, 8);
  454. pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A3, 0);
  455. wmb();
  456. pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A1, m);
  457. pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A2, n);
  458. wmb();
  459. pm2_RDAC_WR(par, PM2I_RD_PIXEL_CLOCK_A3, 8|p);
  460. wmb();
  461. pm2_RDAC_RD(par, PM2I_RD_PIXEL_CLOCK_STATUS);
  462. rmb();
  463. for (i = 256;
  464. i && !(pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED);
  465. i--)
  466. ;
  467. break;
  468. case PM2_TYPE_PERMEDIA2V:
  469. pm2v_mnp(clk/2, &m, &n, &p);
  470. WAIT_FIFO(par, 8);
  471. pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_CLK0_PRESCALE >> 8);
  472. pm2v_RDAC_WR(par, PM2VI_RD_CLK0_PRESCALE, m);
  473. pm2v_RDAC_WR(par, PM2VI_RD_CLK0_FEEDBACK, n);
  474. pm2v_RDAC_WR(par, PM2VI_RD_CLK0_POSTSCALE, p);
  475. pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
  476. break;
  477. }
  478. }
  479. static void set_video(struct pm2fb_par* p, u32 video) {
  480. u32 tmp;
  481. u32 vsync;
  482. vsync = video;
  483. DPRINTK("video = 0x%x\n", video);
  484. /*
  485. * The hardware cursor needs +vsync to recognise vert retrace.
  486. * We may not be using the hardware cursor, but the X Glint
  487. * driver may well. So always set +hsync/+vsync and then set
  488. * the RAMDAC to invert the sync if necessary.
  489. */
  490. vsync &= ~(PM2F_HSYNC_MASK|PM2F_VSYNC_MASK);
  491. vsync |= PM2F_HSYNC_ACT_HIGH|PM2F_VSYNC_ACT_HIGH;
  492. WAIT_FIFO(p, 5);
  493. pm2_WR(p, PM2R_VIDEO_CONTROL, vsync);
  494. switch (p->type) {
  495. case PM2_TYPE_PERMEDIA2:
  496. tmp = PM2F_RD_PALETTE_WIDTH_8;
  497. if ((video & PM2F_HSYNC_MASK) == PM2F_HSYNC_ACT_LOW)
  498. tmp |= 4; /* invert hsync */
  499. if ((video & PM2F_VSYNC_MASK) == PM2F_VSYNC_ACT_LOW)
  500. tmp |= 8; /* invert vsync */
  501. pm2_RDAC_WR(p, PM2I_RD_MISC_CONTROL, tmp);
  502. break;
  503. case PM2_TYPE_PERMEDIA2V:
  504. tmp = 0;
  505. if ((video & PM2F_HSYNC_MASK) == PM2F_HSYNC_ACT_LOW)
  506. tmp |= 1; /* invert hsync */
  507. if ((video & PM2F_VSYNC_MASK) == PM2F_VSYNC_ACT_LOW)
  508. tmp |= 4; /* invert vsync */
  509. pm2v_RDAC_WR(p, PM2VI_RD_SYNC_CONTROL, tmp);
  510. pm2v_RDAC_WR(p, PM2VI_RD_MISC_CONTROL, 1);
  511. break;
  512. }
  513. }
  514. /*
  515. *
  516. */
  517. /**
  518. * pm2fb_check_var - Optional function. Validates a var passed in.
  519. * @var: frame buffer variable screen structure
  520. * @info: frame buffer structure that represents a single frame buffer
  521. *
  522. * Checks to see if the hardware supports the state requested by
  523. * var passed in.
  524. *
  525. * Returns negative errno on error, or zero on success.
  526. */
  527. static int pm2fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  528. {
  529. u32 lpitch;
  530. if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 &&
  531. var->bits_per_pixel != 24 && var->bits_per_pixel != 32) {
  532. DPRINTK("depth not supported: %u\n", var->bits_per_pixel);
  533. return -EINVAL;
  534. }
  535. if (var->xres != var->xres_virtual) {
  536. DPRINTK("virtual x resolution != physical x resolution not supported\n");
  537. return -EINVAL;
  538. }
  539. if (var->yres > var->yres_virtual) {
  540. DPRINTK("virtual y resolution < physical y resolution not possible\n");
  541. return -EINVAL;
  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 (PICOS2KHZ(var->pixclock) > PM2_MAX_PIXCLOCK) {
  567. DPRINTK("pixclock too high (%ldKHz)\n", PICOS2KHZ(var->pixclock));
  568. return -EINVAL;
  569. }
  570. switch(var->bits_per_pixel) {
  571. case 8:
  572. var->red.length = var->green.length = var->blue.length = 8;
  573. break;
  574. case 16:
  575. var->red.offset = 11;
  576. var->red.length = 5;
  577. var->green.offset = 5;
  578. var->green.length = 6;
  579. var->blue.offset = 0;
  580. var->blue.length = 5;
  581. break;
  582. case 32:
  583. var->transp.offset = 24;
  584. var->transp.length = 8;
  585. var->red.offset = 16;
  586. var->green.offset = 8;
  587. var->blue.offset = 0;
  588. var->red.length = var->green.length = var->blue.length = 8;
  589. break;
  590. case 24:
  591. #ifdef __BIG_ENDIAN
  592. var->red.offset = 0;
  593. var->blue.offset = 16;
  594. #else
  595. var->red.offset = 16;
  596. var->blue.offset = 0;
  597. #endif
  598. var->green.offset = 8;
  599. var->red.length = var->green.length = var->blue.length = 8;
  600. break;
  601. }
  602. var->height = var->width = -1;
  603. var->accel_flags = 0; /* Can't mmap if this is on */
  604. DPRINTK("Checking graphics mode at %dx%d depth %d\n",
  605. var->xres, var->yres, var->bits_per_pixel);
  606. return 0;
  607. }
  608. /**
  609. * pm2fb_set_par - Alters the hardware state.
  610. * @info: frame buffer structure that represents a single frame buffer
  611. *
  612. * Using the fb_var_screeninfo in fb_info we set the resolution of the
  613. * this particular framebuffer.
  614. */
  615. static int pm2fb_set_par(struct fb_info *info)
  616. {
  617. struct pm2fb_par *par = info->par;
  618. u32 pixclock;
  619. u32 width, height, depth;
  620. u32 hsstart, hsend, hbend, htotal;
  621. u32 vsstart, vsend, vbend, vtotal;
  622. u32 stride;
  623. u32 base;
  624. u32 video = 0;
  625. u32 clrmode = PM2F_RD_COLOR_MODE_RGB | PM2F_RD_GUI_ACTIVE;
  626. u32 txtmap = 0;
  627. u32 pixsize = 0;
  628. u32 clrformat = 0;
  629. u32 xres;
  630. int data64;
  631. reset_card(par);
  632. reset_config(par);
  633. clear_palette(par);
  634. if ( par->memclock )
  635. set_memclock(par, par->memclock);
  636. width = (info->var.xres_virtual + 7) & ~7;
  637. height = info->var.yres_virtual;
  638. depth = (info->var.bits_per_pixel + 7) & ~7;
  639. depth = (depth > 32) ? 32 : depth;
  640. data64 = depth > 8 || par->type == PM2_TYPE_PERMEDIA2V;
  641. xres = (info->var.xres + 31) & ~31;
  642. pixclock = PICOS2KHZ(info->var.pixclock);
  643. if (pixclock > PM2_MAX_PIXCLOCK) {
  644. DPRINTK("pixclock too high (%uKHz)\n", pixclock);
  645. return -EINVAL;
  646. }
  647. hsstart = to3264(info->var.right_margin, depth, data64);
  648. hsend = hsstart + to3264(info->var.hsync_len, depth, data64);
  649. hbend = hsend + to3264(info->var.left_margin, depth, data64);
  650. htotal = to3264(xres, depth, data64) + hbend - 1;
  651. vsstart = (info->var.lower_margin)
  652. ? info->var.lower_margin - 1
  653. : 0; /* FIXME! */
  654. vsend = info->var.lower_margin + info->var.vsync_len - 1;
  655. vbend = info->var.lower_margin + info->var.vsync_len + info->var.upper_margin;
  656. vtotal = info->var.yres + vbend - 1;
  657. stride = to3264(width, depth, 1);
  658. base = to3264(info->var.yoffset * xres + info->var.xoffset, depth, 1);
  659. if (data64)
  660. video |= PM2F_DATA_64_ENABLE;
  661. if (info->var.sync & FB_SYNC_HOR_HIGH_ACT) {
  662. if (lowhsync) {
  663. DPRINTK("ignoring +hsync, using -hsync.\n");
  664. video |= PM2F_HSYNC_ACT_LOW;
  665. } else
  666. video |= PM2F_HSYNC_ACT_HIGH;
  667. }
  668. else
  669. video |= PM2F_HSYNC_ACT_LOW;
  670. if (info->var.sync & FB_SYNC_VERT_HIGH_ACT) {
  671. if (lowvsync) {
  672. DPRINTK("ignoring +vsync, using -vsync.\n");
  673. video |= PM2F_VSYNC_ACT_LOW;
  674. } else
  675. video |= PM2F_VSYNC_ACT_HIGH;
  676. }
  677. else
  678. video |= PM2F_VSYNC_ACT_LOW;
  679. if ((info->var.vmode & FB_VMODE_MASK)==FB_VMODE_INTERLACED) {
  680. DPRINTK("interlaced not supported\n");
  681. return -EINVAL;
  682. }
  683. if ((info->var.vmode & FB_VMODE_MASK)==FB_VMODE_DOUBLE)
  684. video |= PM2F_LINE_DOUBLE;
  685. if ((info->var.activate & FB_ACTIVATE_MASK)==FB_ACTIVATE_NOW)
  686. video |= PM2F_VIDEO_ENABLE;
  687. par->video = video;
  688. info->fix.visual =
  689. (depth == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
  690. info->fix.line_length = info->var.xres * depth / 8;
  691. info->cmap.len = 256;
  692. /*
  693. * Settings calculated. Now write them out.
  694. */
  695. if (par->type == PM2_TYPE_PERMEDIA2V) {
  696. WAIT_FIFO(par, 1);
  697. pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
  698. }
  699. set_aperture(par, depth);
  700. mb();
  701. WAIT_FIFO(par, 19);
  702. pm2_RDAC_WR(par, PM2I_RD_COLOR_KEY_CONTROL,
  703. ( depth == 8 ) ? 0 : PM2F_COLOR_KEY_TEST_OFF);
  704. switch (depth) {
  705. case 8:
  706. pm2_WR(par, PM2R_FB_READ_PIXEL, 0);
  707. clrformat = 0x0e;
  708. break;
  709. case 16:
  710. pm2_WR(par, PM2R_FB_READ_PIXEL, 1);
  711. clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGB565;
  712. txtmap = PM2F_TEXTEL_SIZE_16;
  713. pixsize = 1;
  714. clrformat = 0x70;
  715. break;
  716. case 32:
  717. pm2_WR(par, PM2R_FB_READ_PIXEL, 2);
  718. clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGBA8888;
  719. txtmap = PM2F_TEXTEL_SIZE_32;
  720. pixsize = 2;
  721. clrformat = 0x20;
  722. break;
  723. case 24:
  724. pm2_WR(par, PM2R_FB_READ_PIXEL, 4);
  725. clrmode |= PM2F_RD_TRUECOLOR | PM2F_RD_PIXELFORMAT_RGB888;
  726. txtmap = PM2F_TEXTEL_SIZE_24;
  727. pixsize = 4;
  728. clrformat = 0x20;
  729. break;
  730. }
  731. pm2_WR(par, PM2R_FB_WRITE_MODE, PM2F_FB_WRITE_ENABLE);
  732. pm2_WR(par, PM2R_FB_READ_MODE, partprod(xres));
  733. pm2_WR(par, PM2R_LB_READ_MODE, partprod(xres));
  734. pm2_WR(par, PM2R_TEXTURE_MAP_FORMAT, txtmap | partprod(xres));
  735. pm2_WR(par, PM2R_H_TOTAL, htotal);
  736. pm2_WR(par, PM2R_HS_START, hsstart);
  737. pm2_WR(par, PM2R_HS_END, hsend);
  738. pm2_WR(par, PM2R_HG_END, hbend);
  739. pm2_WR(par, PM2R_HB_END, hbend);
  740. pm2_WR(par, PM2R_V_TOTAL, vtotal);
  741. pm2_WR(par, PM2R_VS_START, vsstart);
  742. pm2_WR(par, PM2R_VS_END, vsend);
  743. pm2_WR(par, PM2R_VB_END, vbend);
  744. pm2_WR(par, PM2R_SCREEN_STRIDE, stride);
  745. wmb();
  746. pm2_WR(par, PM2R_WINDOW_ORIGIN, 0);
  747. pm2_WR(par, PM2R_SCREEN_SIZE, (height << 16) | width);
  748. pm2_WR(par, PM2R_SCISSOR_MODE, PM2F_SCREEN_SCISSOR_ENABLE);
  749. wmb();
  750. pm2_WR(par, PM2R_SCREEN_BASE, base);
  751. wmb();
  752. set_video(par, video);
  753. WAIT_FIFO(par, 4);
  754. switch (par->type) {
  755. case PM2_TYPE_PERMEDIA2:
  756. pm2_RDAC_WR(par, PM2I_RD_COLOR_MODE, clrmode);
  757. break;
  758. case PM2_TYPE_PERMEDIA2V:
  759. pm2v_RDAC_WR(par, PM2VI_RD_PIXEL_SIZE, pixsize);
  760. pm2v_RDAC_WR(par, PM2VI_RD_COLOR_FORMAT, clrformat);
  761. break;
  762. }
  763. set_pixclock(par, pixclock);
  764. DPRINTK("Setting graphics mode at %dx%d depth %d\n",
  765. info->var.xres, info->var.yres, info->var.bits_per_pixel);
  766. return 0;
  767. }
  768. /**
  769. * pm2fb_setcolreg - Sets a color register.
  770. * @regno: boolean, 0 copy local, 1 get_user() function
  771. * @red: frame buffer colormap structure
  772. * @green: The green value which can be up to 16 bits wide
  773. * @blue: The blue value which can be up to 16 bits wide.
  774. * @transp: If supported the alpha value which can be up to 16 bits wide.
  775. * @info: frame buffer info structure
  776. *
  777. * Set a single color register. The values supplied have a 16 bit
  778. * magnitude which needs to be scaled in this function for the hardware.
  779. * Pretty much a direct lift from tdfxfb.c.
  780. *
  781. * Returns negative errno on error, or zero on success.
  782. */
  783. static int pm2fb_setcolreg(unsigned regno, unsigned red, unsigned green,
  784. unsigned blue, unsigned transp,
  785. struct fb_info *info)
  786. {
  787. struct pm2fb_par *par = info->par;
  788. if (regno >= info->cmap.len) /* no. of hw registers */
  789. return 1;
  790. /*
  791. * Program hardware... do anything you want with transp
  792. */
  793. /* grayscale works only partially under directcolor */
  794. if (info->var.grayscale) {
  795. /* grayscale = 0.30*R + 0.59*G + 0.11*B */
  796. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  797. }
  798. /* Directcolor:
  799. * var->{color}.offset contains start of bitfield
  800. * var->{color}.length contains length of bitfield
  801. * {hardwarespecific} contains width of DAC
  802. * cmap[X] is programmed to
  803. * (X << red.offset) | (X << green.offset) | (X << blue.offset)
  804. * RAMDAC[X] is programmed to (red, green, blue)
  805. *
  806. * Pseudocolor:
  807. * uses offset = 0 && length = DAC register width.
  808. * var->{color}.offset is 0
  809. * var->{color}.length contains widht of DAC
  810. * cmap is not used
  811. * DAC[X] is programmed to (red, green, blue)
  812. * Truecolor:
  813. * does not use RAMDAC (usually has 3 of them).
  814. * var->{color}.offset contains start of bitfield
  815. * var->{color}.length contains length of bitfield
  816. * cmap is programmed to
  817. * (red << red.offset) | (green << green.offset) |
  818. * (blue << blue.offset) | (transp << transp.offset)
  819. * RAMDAC does not exist
  820. */
  821. #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
  822. switch (info->fix.visual) {
  823. case FB_VISUAL_TRUECOLOR:
  824. case FB_VISUAL_PSEUDOCOLOR:
  825. red = CNVT_TOHW(red, info->var.red.length);
  826. green = CNVT_TOHW(green, info->var.green.length);
  827. blue = CNVT_TOHW(blue, info->var.blue.length);
  828. transp = CNVT_TOHW(transp, info->var.transp.length);
  829. break;
  830. case FB_VISUAL_DIRECTCOLOR:
  831. /* example here assumes 8 bit DAC. Might be different
  832. * for your hardware */
  833. red = CNVT_TOHW(red, 8);
  834. green = CNVT_TOHW(green, 8);
  835. blue = CNVT_TOHW(blue, 8);
  836. /* hey, there is bug in transp handling... */
  837. transp = CNVT_TOHW(transp, 8);
  838. break;
  839. }
  840. #undef CNVT_TOHW
  841. /* Truecolor has hardware independent palette */
  842. if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
  843. u32 v;
  844. if (regno >= 16)
  845. return 1;
  846. v = (red << info->var.red.offset) |
  847. (green << info->var.green.offset) |
  848. (blue << info->var.blue.offset) |
  849. (transp << info->var.transp.offset);
  850. switch (info->var.bits_per_pixel) {
  851. case 8:
  852. break;
  853. case 16:
  854. case 24:
  855. case 32:
  856. par->palette[regno] = v;
  857. break;
  858. }
  859. return 0;
  860. }
  861. else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
  862. set_color(par, regno, red, green, blue);
  863. return 0;
  864. }
  865. /**
  866. * pm2fb_pan_display - Pans the display.
  867. * @var: frame buffer variable screen structure
  868. * @info: frame buffer structure that represents a single frame buffer
  869. *
  870. * Pan (or wrap, depending on the `vmode' field) the display using the
  871. * `xoffset' and `yoffset' fields of the `var' structure.
  872. * If the values don't fit, return -EINVAL.
  873. *
  874. * Returns negative errno on error, or zero on success.
  875. *
  876. */
  877. static int pm2fb_pan_display(struct fb_var_screeninfo *var,
  878. struct fb_info *info)
  879. {
  880. struct pm2fb_par *p = info->par;
  881. u32 base;
  882. u32 depth;
  883. u32 xres;
  884. xres = (var->xres + 31) & ~31;
  885. depth = (var->bits_per_pixel + 7) & ~7;
  886. depth = (depth > 32) ? 32 : depth;
  887. base = to3264(var->yoffset * xres + var->xoffset, depth, 1);
  888. WAIT_FIFO(p, 1);
  889. pm2_WR(p, PM2R_SCREEN_BASE, base);
  890. return 0;
  891. }
  892. /**
  893. * pm2fb_blank - Blanks the display.
  894. * @blank_mode: the blank mode we want.
  895. * @info: frame buffer structure that represents a single frame buffer
  896. *
  897. * Blank the screen if blank_mode != 0, else unblank. Return 0 if
  898. * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
  899. * video mode which doesn't support it. Implements VESA suspend
  900. * and powerdown modes on hardware that supports disabling hsync/vsync:
  901. * blank_mode == 2: suspend vsync
  902. * blank_mode == 3: suspend hsync
  903. * blank_mode == 4: powerdown
  904. *
  905. * Returns negative errno on error, or zero on success.
  906. *
  907. */
  908. static int pm2fb_blank(int blank_mode, struct fb_info *info)
  909. {
  910. struct pm2fb_par *par = info->par;
  911. u32 video = par->video;
  912. DPRINTK("blank_mode %d\n", blank_mode);
  913. switch (blank_mode) {
  914. case FB_BLANK_UNBLANK:
  915. /* Screen: On */
  916. video |= PM2F_VIDEO_ENABLE;
  917. break;
  918. case FB_BLANK_NORMAL:
  919. /* Screen: Off */
  920. video &= ~PM2F_VIDEO_ENABLE;
  921. break;
  922. case FB_BLANK_VSYNC_SUSPEND:
  923. /* VSync: Off */
  924. video &= ~(PM2F_VSYNC_MASK | PM2F_BLANK_LOW );
  925. break;
  926. case FB_BLANK_HSYNC_SUSPEND:
  927. /* HSync: Off */
  928. video &= ~(PM2F_HSYNC_MASK | PM2F_BLANK_LOW );
  929. break;
  930. case FB_BLANK_POWERDOWN:
  931. /* HSync: Off, VSync: Off */
  932. video &= ~(PM2F_VSYNC_MASK | PM2F_HSYNC_MASK| PM2F_BLANK_LOW);
  933. break;
  934. }
  935. set_video(par, video);
  936. return 0;
  937. }
  938. /* ------------ Hardware Independent Functions ------------ */
  939. /*
  940. * Frame buffer operations
  941. */
  942. static struct fb_ops pm2fb_ops = {
  943. .owner = THIS_MODULE,
  944. .fb_check_var = pm2fb_check_var,
  945. .fb_set_par = pm2fb_set_par,
  946. .fb_setcolreg = pm2fb_setcolreg,
  947. .fb_blank = pm2fb_blank,
  948. .fb_pan_display = pm2fb_pan_display,
  949. .fb_fillrect = cfb_fillrect,
  950. .fb_copyarea = cfb_copyarea,
  951. .fb_imageblit = cfb_imageblit,
  952. };
  953. /*
  954. * PCI stuff
  955. */
  956. /**
  957. * Device initialisation
  958. *
  959. * Initialise and allocate resource for PCI device.
  960. *
  961. * @param pdev PCI device.
  962. * @param id PCI device ID.
  963. */
  964. static int __devinit pm2fb_probe(struct pci_dev *pdev,
  965. const struct pci_device_id *id)
  966. {
  967. struct pm2fb_par *default_par;
  968. struct fb_info *info;
  969. int err, err_retval = -ENXIO;
  970. err = pci_enable_device(pdev);
  971. if ( err ) {
  972. printk(KERN_WARNING "pm2fb: Can't enable pdev: %d\n", err);
  973. return err;
  974. }
  975. info = framebuffer_alloc(sizeof(struct pm2fb_par), &pdev->dev);
  976. if ( !info )
  977. return -ENOMEM;
  978. default_par = info->par;
  979. switch (pdev->device) {
  980. case PCI_DEVICE_ID_TI_TVP4020:
  981. strcpy(pm2fb_fix.id, "TVP4020");
  982. default_par->type = PM2_TYPE_PERMEDIA2;
  983. break;
  984. case PCI_DEVICE_ID_3DLABS_PERMEDIA2:
  985. strcpy(pm2fb_fix.id, "Permedia2");
  986. default_par->type = PM2_TYPE_PERMEDIA2;
  987. break;
  988. case PCI_DEVICE_ID_3DLABS_PERMEDIA2V:
  989. strcpy(pm2fb_fix.id, "Permedia2v");
  990. default_par->type = PM2_TYPE_PERMEDIA2V;
  991. break;
  992. }
  993. pm2fb_fix.mmio_start = pci_resource_start(pdev, 0);
  994. pm2fb_fix.mmio_len = PM2_REGS_SIZE;
  995. #if defined(__BIG_ENDIAN)
  996. /*
  997. * PM2 has a 64k register file, mapped twice in 128k. Lower
  998. * map is little-endian, upper map is big-endian.
  999. */
  1000. pm2fb_fix.mmio_start += PM2_REGS_SIZE;
  1001. DPRINTK("Adjusting register base for big-endian.\n");
  1002. #endif
  1003. DPRINTK("Register base at 0x%lx\n", pm2fb_fix.mmio_start);
  1004. /* Registers - request region and map it. */
  1005. if ( !request_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len,
  1006. "pm2fb regbase") ) {
  1007. printk(KERN_WARNING "pm2fb: Can't reserve regbase.\n");
  1008. goto err_exit_neither;
  1009. }
  1010. default_par->v_regs =
  1011. ioremap_nocache(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
  1012. if ( !default_par->v_regs ) {
  1013. printk(KERN_WARNING "pm2fb: Can't remap %s register area.\n",
  1014. pm2fb_fix.id);
  1015. release_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
  1016. goto err_exit_neither;
  1017. }
  1018. /* Stash away memory register info for use when we reset the board */
  1019. default_par->mem_control = pm2_RD(default_par, PM2R_MEM_CONTROL);
  1020. default_par->boot_address = pm2_RD(default_par, PM2R_BOOT_ADDRESS);
  1021. default_par->mem_config = pm2_RD(default_par, PM2R_MEM_CONFIG);
  1022. DPRINTK("MemControl 0x%x BootAddress 0x%x MemConfig 0x%x\n",
  1023. default_par->mem_control, default_par->boot_address,
  1024. default_par->mem_config);
  1025. if(default_par->mem_control == 0 &&
  1026. default_par->boot_address == 0x31 &&
  1027. default_par->mem_config == 0x259fffff &&
  1028. pdev->subsystem_vendor == 0x1048 &&
  1029. pdev->subsystem_device == 0x0a31) {
  1030. DPRINTK("subsystem_vendor: %04x, subsystem_device: %04x\n",
  1031. pdev->subsystem_vendor, pdev->subsystem_device);
  1032. DPRINTK("We have not been initialized by VGA BIOS "
  1033. "and are running on an Elsa Winner 2000 Office\n");
  1034. DPRINTK("Initializing card timings manually...\n");
  1035. default_par->mem_control=0;
  1036. default_par->boot_address=0x20;
  1037. default_par->mem_config=0xe6002021;
  1038. default_par->memclock=100000;
  1039. }
  1040. /* Now work out how big lfb is going to be. */
  1041. switch(default_par->mem_config & PM2F_MEM_CONFIG_RAM_MASK) {
  1042. case PM2F_MEM_BANKS_1:
  1043. default_par->fb_size=0x200000;
  1044. break;
  1045. case PM2F_MEM_BANKS_2:
  1046. default_par->fb_size=0x400000;
  1047. break;
  1048. case PM2F_MEM_BANKS_3:
  1049. default_par->fb_size=0x600000;
  1050. break;
  1051. case PM2F_MEM_BANKS_4:
  1052. default_par->fb_size=0x800000;
  1053. break;
  1054. }
  1055. default_par->memclock = CVPPC_MEMCLOCK;
  1056. pm2fb_fix.smem_start = pci_resource_start(pdev, 1);
  1057. pm2fb_fix.smem_len = default_par->fb_size;
  1058. /* Linear frame buffer - request region and map it. */
  1059. if ( !request_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len,
  1060. "pm2fb smem") ) {
  1061. printk(KERN_WARNING "pm2fb: Can't reserve smem.\n");
  1062. goto err_exit_mmio;
  1063. }
  1064. info->screen_base = default_par->v_fb =
  1065. ioremap_nocache(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
  1066. if ( !default_par->v_fb ) {
  1067. printk(KERN_WARNING "pm2fb: Can't ioremap smem area.\n");
  1068. release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
  1069. goto err_exit_mmio;
  1070. }
  1071. info->fbops = &pm2fb_ops;
  1072. info->fix = pm2fb_fix;
  1073. info->pseudo_palette = default_par->palette;
  1074. info->flags = FBINFO_DEFAULT |
  1075. FBINFO_HWACCEL_YPAN;
  1076. if (!mode)
  1077. mode = "640x480@60";
  1078. err = fb_find_mode(&info->var, info, mode, NULL, 0, NULL, 8);
  1079. if (!err || err == 4)
  1080. info->var = pm2fb_var;
  1081. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
  1082. goto err_exit_all;
  1083. if (register_framebuffer(info) < 0)
  1084. goto err_exit_both;
  1085. printk(KERN_INFO "fb%d: %s frame buffer device, memory = %dK.\n",
  1086. info->node, info->fix.id, default_par->fb_size / 1024);
  1087. /*
  1088. * Our driver data
  1089. */
  1090. pci_set_drvdata(pdev, info);
  1091. return 0;
  1092. err_exit_all:
  1093. fb_dealloc_cmap(&info->cmap);
  1094. err_exit_both:
  1095. iounmap(info->screen_base);
  1096. release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
  1097. err_exit_mmio:
  1098. iounmap(default_par->v_regs);
  1099. release_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
  1100. err_exit_neither:
  1101. framebuffer_release(info);
  1102. return err_retval;
  1103. }
  1104. /**
  1105. * Device removal.
  1106. *
  1107. * Release all device resources.
  1108. *
  1109. * @param pdev PCI device to clean up.
  1110. */
  1111. static void __devexit pm2fb_remove(struct pci_dev *pdev)
  1112. {
  1113. struct fb_info* info = pci_get_drvdata(pdev);
  1114. struct fb_fix_screeninfo* fix = &info->fix;
  1115. struct pm2fb_par *par = info->par;
  1116. unregister_framebuffer(info);
  1117. iounmap(info->screen_base);
  1118. release_mem_region(fix->smem_start, fix->smem_len);
  1119. iounmap(par->v_regs);
  1120. release_mem_region(fix->mmio_start, fix->mmio_len);
  1121. pci_set_drvdata(pdev, NULL);
  1122. kfree(info);
  1123. }
  1124. static struct pci_device_id pm2fb_id_table[] = {
  1125. { PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TVP4020,
  1126. PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
  1127. 0xff0000, 0 },
  1128. { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2,
  1129. PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
  1130. 0xff0000, 0 },
  1131. { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2V,
  1132. PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
  1133. 0xff0000, 0 },
  1134. { 0, }
  1135. };
  1136. static struct pci_driver pm2fb_driver = {
  1137. .name = "pm2fb",
  1138. .id_table = pm2fb_id_table,
  1139. .probe = pm2fb_probe,
  1140. .remove = __devexit_p(pm2fb_remove),
  1141. };
  1142. MODULE_DEVICE_TABLE(pci, pm2fb_id_table);
  1143. #ifndef MODULE
  1144. /**
  1145. * Parse user speficied options.
  1146. *
  1147. * This is, comma-separated options following `video=pm2fb:'.
  1148. */
  1149. static int __init pm2fb_setup(char *options)
  1150. {
  1151. char* this_opt;
  1152. if (!options || !*options)
  1153. return 0;
  1154. while ((this_opt = strsep(&options, ",")) != NULL) {
  1155. if (!*this_opt)
  1156. continue;
  1157. if(!strcmp(this_opt, "lowhsync")) {
  1158. lowhsync = 1;
  1159. } else if(!strcmp(this_opt, "lowvsync")) {
  1160. lowvsync = 1;
  1161. } else {
  1162. mode = this_opt;
  1163. }
  1164. }
  1165. return 0;
  1166. }
  1167. #endif
  1168. static int __init pm2fb_init(void)
  1169. {
  1170. #ifndef MODULE
  1171. char *option = NULL;
  1172. if (fb_get_options("pm2fb", &option))
  1173. return -ENODEV;
  1174. pm2fb_setup(option);
  1175. #endif
  1176. return pci_register_driver(&pm2fb_driver);
  1177. }
  1178. module_init(pm2fb_init);
  1179. #ifdef MODULE
  1180. /*
  1181. * Cleanup
  1182. */
  1183. static void __exit pm2fb_exit(void)
  1184. {
  1185. pci_unregister_driver(&pm2fb_driver);
  1186. }
  1187. #endif
  1188. #ifdef MODULE
  1189. module_exit(pm2fb_exit);
  1190. module_param(mode, charp, 0);
  1191. MODULE_PARM_DESC(mode, "Preferred video mode e.g. '648x480-8@60'");
  1192. module_param(lowhsync, bool, 0);
  1193. MODULE_PARM_DESC(lowhsync, "Force horizontal sync low regardless of mode");
  1194. module_param(lowvsync, bool, 0);
  1195. MODULE_PARM_DESC(lowvsync, "Force vertical sync low regardless of mode");
  1196. MODULE_AUTHOR("Jim Hague <jim.hague@acm.org>");
  1197. MODULE_DESCRIPTION("Permedia2 framebuffer device driver");
  1198. MODULE_LICENSE("GPL");
  1199. #endif