sgivwfb.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. /*
  2. * linux/drivers/video/sgivwfb.c -- SGI DBE frame buffer device
  3. *
  4. * Copyright (C) 1999 Silicon Graphics, Inc.
  5. * Jeffrey Newquist, newquist@engr.sgi.som
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file COPYING in the main directory of this archive for
  9. * more details.
  10. */
  11. #include <linux/config.h>
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/mm.h>
  15. #include <linux/errno.h>
  16. #include <linux/delay.h>
  17. #include <linux/fb.h>
  18. #include <linux/init.h>
  19. #include <linux/ioport.h>
  20. #include <asm/io.h>
  21. #include <asm/mtrr.h>
  22. #define INCLUDE_TIMING_TABLE_DATA
  23. #define DBE_REG_BASE par->regs
  24. #include <video/sgivw.h>
  25. struct sgivw_par {
  26. struct asregs *regs;
  27. u32 cmap_fifo;
  28. u_long timing_num;
  29. };
  30. #define FLATPANEL_SGI_1600SW 5
  31. /*
  32. * RAM we reserve for the frame buffer. This defines the maximum screen
  33. * size
  34. *
  35. * The default can be overridden if the driver is compiled as a module
  36. */
  37. /* set by arch/i386/kernel/setup.c */
  38. extern unsigned long sgivwfb_mem_phys;
  39. extern unsigned long sgivwfb_mem_size;
  40. static int ypan = 0;
  41. static int ywrap = 0;
  42. static int flatpanel_id = -1;
  43. static struct fb_fix_screeninfo sgivwfb_fix __initdata = {
  44. .id = "SGI Vis WS FB",
  45. .type = FB_TYPE_PACKED_PIXELS,
  46. .visual = FB_VISUAL_PSEUDOCOLOR,
  47. .mmio_start = DBE_REG_PHYS,
  48. .mmio_len = DBE_REG_SIZE,
  49. .accel = FB_ACCEL_NONE,
  50. .line_length = 640,
  51. };
  52. static struct fb_var_screeninfo sgivwfb_var __initdata = {
  53. /* 640x480, 8 bpp */
  54. .xres = 640,
  55. .yres = 480,
  56. .xres_virtual = 640,
  57. .yres_virtual = 480,
  58. .bits_per_pixel = 8,
  59. .red = { 0, 8, 0 },
  60. .green = { 0, 8, 0 },
  61. .blue = { 0, 8, 0 },
  62. .height = -1,
  63. .width = -1,
  64. .pixclock = 20000,
  65. .left_margin = 64,
  66. .right_margin = 64,
  67. .upper_margin = 32,
  68. .lower_margin = 32,
  69. .hsync_len = 64,
  70. .vsync_len = 2,
  71. .vmode = FB_VMODE_NONINTERLACED
  72. };
  73. static struct fb_var_screeninfo sgivwfb_var1600sw __initdata = {
  74. /* 1600x1024, 8 bpp */
  75. .xres = 1600,
  76. .yres = 1024,
  77. .xres_virtual = 1600,
  78. .yres_virtual = 1024,
  79. .bits_per_pixel = 8,
  80. .red = { 0, 8, 0 },
  81. .green = { 0, 8, 0 },
  82. .blue = { 0, 8, 0 },
  83. .height = -1,
  84. .width = -1,
  85. .pixclock = 9353,
  86. .left_margin = 20,
  87. .right_margin = 30,
  88. .upper_margin = 37,
  89. .lower_margin = 3,
  90. .hsync_len = 20,
  91. .vsync_len = 3,
  92. .vmode = FB_VMODE_NONINTERLACED
  93. };
  94. /*
  95. * Interface used by the world
  96. */
  97. int sgivwfb_init(void);
  98. static int sgivwfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info);
  99. static int sgivwfb_set_par(struct fb_info *info);
  100. static int sgivwfb_setcolreg(u_int regno, u_int red, u_int green,
  101. u_int blue, u_int transp,
  102. struct fb_info *info);
  103. static int sgivwfb_mmap(struct fb_info *info, struct file *file,
  104. struct vm_area_struct *vma);
  105. static struct fb_ops sgivwfb_ops = {
  106. .owner = THIS_MODULE,
  107. .fb_check_var = sgivwfb_check_var,
  108. .fb_set_par = sgivwfb_set_par,
  109. .fb_setcolreg = sgivwfb_setcolreg,
  110. .fb_fillrect = cfb_fillrect,
  111. .fb_copyarea = cfb_copyarea,
  112. .fb_imageblit = cfb_imageblit,
  113. .fb_cursor = soft_cursor,
  114. .fb_mmap = sgivwfb_mmap,
  115. };
  116. /*
  117. * Internal routines
  118. */
  119. static unsigned long bytes_per_pixel(int bpp)
  120. {
  121. switch (bpp) {
  122. case 8:
  123. return 1;
  124. case 16:
  125. return 2;
  126. case 32:
  127. return 4;
  128. default:
  129. printk(KERN_INFO "sgivwfb: unsupported bpp %d\n", bpp);
  130. return 0;
  131. }
  132. }
  133. static unsigned long get_line_length(int xres_virtual, int bpp)
  134. {
  135. return (xres_virtual * bytes_per_pixel(bpp));
  136. }
  137. /*
  138. * Function: dbe_TurnOffDma
  139. * Parameters: (None)
  140. * Description: This should turn off the monitor and dbe. This is used
  141. * when switching between the serial console and the graphics
  142. * console.
  143. */
  144. static void dbe_TurnOffDma(struct sgivw_par *par)
  145. {
  146. unsigned int readVal;
  147. int i;
  148. // Check to see if things are already turned off:
  149. // 1) Check to see if dbe is not using the internal dotclock.
  150. // 2) Check to see if the xy counter in dbe is already off.
  151. DBE_GETREG(ctrlstat, readVal);
  152. if (GET_DBE_FIELD(CTRLSTAT, PCLKSEL, readVal) < 2)
  153. return;
  154. DBE_GETREG(vt_xy, readVal);
  155. if (GET_DBE_FIELD(VT_XY, VT_FREEZE, readVal) == 1)
  156. return;
  157. // Otherwise, turn off dbe
  158. DBE_GETREG(ovr_control, readVal);
  159. SET_DBE_FIELD(OVR_CONTROL, OVR_DMA_ENABLE, readVal, 0);
  160. DBE_SETREG(ovr_control, readVal);
  161. udelay(1000);
  162. DBE_GETREG(frm_control, readVal);
  163. SET_DBE_FIELD(FRM_CONTROL, FRM_DMA_ENABLE, readVal, 0);
  164. DBE_SETREG(frm_control, readVal);
  165. udelay(1000);
  166. DBE_GETREG(did_control, readVal);
  167. SET_DBE_FIELD(DID_CONTROL, DID_DMA_ENABLE, readVal, 0);
  168. DBE_SETREG(did_control, readVal);
  169. udelay(1000);
  170. // XXX HACK:
  171. //
  172. // This was necessary for GBE--we had to wait through two
  173. // vertical retrace periods before the pixel DMA was
  174. // turned off for sure. I've left this in for now, in
  175. // case dbe needs it.
  176. for (i = 0; i < 10000; i++) {
  177. DBE_GETREG(frm_inhwctrl, readVal);
  178. if (GET_DBE_FIELD(FRM_INHWCTRL, FRM_DMA_ENABLE, readVal) ==
  179. 0)
  180. udelay(10);
  181. else {
  182. DBE_GETREG(ovr_inhwctrl, readVal);
  183. if (GET_DBE_FIELD
  184. (OVR_INHWCTRL, OVR_DMA_ENABLE, readVal) == 0)
  185. udelay(10);
  186. else {
  187. DBE_GETREG(did_inhwctrl, readVal);
  188. if (GET_DBE_FIELD
  189. (DID_INHWCTRL, DID_DMA_ENABLE,
  190. readVal) == 0)
  191. udelay(10);
  192. else
  193. break;
  194. }
  195. }
  196. }
  197. }
  198. /*
  199. * Set the User Defined Part of the Display. Again if par use it to get
  200. * real video mode.
  201. */
  202. static int sgivwfb_check_var(struct fb_var_screeninfo *var,
  203. struct fb_info *info)
  204. {
  205. struct sgivw_par *par = (struct sgivw_par *)info->par;
  206. struct dbe_timing_info *timing;
  207. u_long line_length;
  208. u_long min_mode;
  209. int req_dot;
  210. int test_mode;
  211. /*
  212. * FB_VMODE_CONUPDATE and FB_VMODE_SMOOTH_XPAN are equal!
  213. * as FB_VMODE_SMOOTH_XPAN is only used internally
  214. */
  215. if (var->vmode & FB_VMODE_CONUPDATE) {
  216. var->vmode |= FB_VMODE_YWRAP;
  217. var->xoffset = info->var.xoffset;
  218. var->yoffset = info->var.yoffset;
  219. }
  220. /* XXX FIXME - forcing var's */
  221. var->xoffset = 0;
  222. var->yoffset = 0;
  223. /* Limit bpp to 8, 16, and 32 */
  224. if (var->bits_per_pixel <= 8)
  225. var->bits_per_pixel = 8;
  226. else if (var->bits_per_pixel <= 16)
  227. var->bits_per_pixel = 16;
  228. else if (var->bits_per_pixel <= 32)
  229. var->bits_per_pixel = 32;
  230. else
  231. return -EINVAL;
  232. var->grayscale = 0; /* No grayscale for now */
  233. /* determine valid resolution and timing */
  234. for (min_mode = 0; min_mode < DBE_VT_SIZE; min_mode++) {
  235. if (dbeVTimings[min_mode].width >= var->xres &&
  236. dbeVTimings[min_mode].height >= var->yres)
  237. break;
  238. }
  239. if (min_mode == DBE_VT_SIZE)
  240. return -EINVAL; /* Resolution to high */
  241. /* XXX FIXME - should try to pick best refresh rate */
  242. /* for now, pick closest dot-clock within 3MHz */
  243. req_dot = PICOS2KHZ(var->pixclock);
  244. printk(KERN_INFO "sgivwfb: requested pixclock=%d ps (%d KHz)\n",
  245. var->pixclock, req_dot);
  246. test_mode = min_mode;
  247. while (dbeVTimings[min_mode].width == dbeVTimings[test_mode].width) {
  248. if (dbeVTimings[test_mode].cfreq + 3000 > req_dot)
  249. break;
  250. test_mode++;
  251. }
  252. if (dbeVTimings[min_mode].width != dbeVTimings[test_mode].width)
  253. test_mode--;
  254. min_mode = test_mode;
  255. timing = &dbeVTimings[min_mode];
  256. printk(KERN_INFO "sgivwfb: granted dot-clock=%d KHz\n", timing->cfreq);
  257. /* Adjust virtual resolution, if necessary */
  258. if (var->xres > var->xres_virtual || (!ywrap && !ypan))
  259. var->xres_virtual = var->xres;
  260. if (var->yres > var->yres_virtual || (!ywrap && !ypan))
  261. var->yres_virtual = var->yres;
  262. /*
  263. * Memory limit
  264. */
  265. line_length = get_line_length(var->xres_virtual, var->bits_per_pixel);
  266. if (line_length * var->yres_virtual > sgivwfb_mem_size)
  267. return -ENOMEM; /* Virtual resolution to high */
  268. info->fix.line_length = line_length;
  269. switch (var->bits_per_pixel) {
  270. case 8:
  271. var->red.offset = 0;
  272. var->red.length = 8;
  273. var->green.offset = 0;
  274. var->green.length = 8;
  275. var->blue.offset = 0;
  276. var->blue.length = 8;
  277. var->transp.offset = 0;
  278. var->transp.length = 0;
  279. break;
  280. case 16: /* RGBA 5551 */
  281. var->red.offset = 11;
  282. var->red.length = 5;
  283. var->green.offset = 6;
  284. var->green.length = 5;
  285. var->blue.offset = 1;
  286. var->blue.length = 5;
  287. var->transp.offset = 0;
  288. var->transp.length = 0;
  289. break;
  290. case 32: /* RGB 8888 */
  291. var->red.offset = 0;
  292. var->red.length = 8;
  293. var->green.offset = 8;
  294. var->green.length = 8;
  295. var->blue.offset = 16;
  296. var->blue.length = 8;
  297. var->transp.offset = 24;
  298. var->transp.length = 8;
  299. break;
  300. }
  301. var->red.msb_right = 0;
  302. var->green.msb_right = 0;
  303. var->blue.msb_right = 0;
  304. var->transp.msb_right = 0;
  305. /* set video timing information */
  306. var->pixclock = KHZ2PICOS(timing->cfreq);
  307. var->left_margin = timing->htotal - timing->hsync_end;
  308. var->right_margin = timing->hsync_start - timing->width;
  309. var->upper_margin = timing->vtotal - timing->vsync_end;
  310. var->lower_margin = timing->vsync_start - timing->height;
  311. var->hsync_len = timing->hsync_end - timing->hsync_start;
  312. var->vsync_len = timing->vsync_end - timing->vsync_start;
  313. /* Ouch. This breaks the rules but timing_num is only important if you
  314. * change a video mode */
  315. par->timing_num = min_mode;
  316. printk(KERN_INFO "sgivwfb: new video mode xres=%d yres=%d bpp=%d\n",
  317. var->xres, var->yres, var->bits_per_pixel);
  318. printk(KERN_INFO " vxres=%d vyres=%d\n", var->xres_virtual,
  319. var->yres_virtual);
  320. return 0;
  321. }
  322. /*
  323. * Setup flatpanel related registers.
  324. */
  325. static void sgivwfb_setup_flatpanel(struct sgivw_par *par, struct dbe_timing_info *currentTiming)
  326. {
  327. int fp_wid, fp_hgt, fp_vbs, fp_vbe;
  328. u32 outputVal = 0;
  329. SET_DBE_FIELD(VT_FLAGS, HDRV_INVERT, outputVal,
  330. (currentTiming->flags & FB_SYNC_HOR_HIGH_ACT) ? 0 : 1);
  331. SET_DBE_FIELD(VT_FLAGS, VDRV_INVERT, outputVal,
  332. (currentTiming->flags & FB_SYNC_VERT_HIGH_ACT) ? 0 : 1);
  333. DBE_SETREG(vt_flags, outputVal);
  334. /* Turn on the flat panel */
  335. switch (flatpanel_id) {
  336. case FLATPANEL_SGI_1600SW:
  337. fp_wid = 1600;
  338. fp_hgt = 1024;
  339. fp_vbs = 0;
  340. fp_vbe = 1600;
  341. currentTiming->pll_m = 4;
  342. currentTiming->pll_n = 1;
  343. currentTiming->pll_p = 0;
  344. break;
  345. default:
  346. fp_wid = fp_hgt = fp_vbs = fp_vbe = 0xfff;
  347. }
  348. outputVal = 0;
  349. SET_DBE_FIELD(FP_DE, FP_DE_ON, outputVal, fp_vbs);
  350. SET_DBE_FIELD(FP_DE, FP_DE_OFF, outputVal, fp_vbe);
  351. DBE_SETREG(fp_de, outputVal);
  352. outputVal = 0;
  353. SET_DBE_FIELD(FP_HDRV, FP_HDRV_OFF, outputVal, fp_wid);
  354. DBE_SETREG(fp_hdrv, outputVal);
  355. outputVal = 0;
  356. SET_DBE_FIELD(FP_VDRV, FP_VDRV_ON, outputVal, 1);
  357. SET_DBE_FIELD(FP_VDRV, FP_VDRV_OFF, outputVal, fp_hgt + 1);
  358. DBE_SETREG(fp_vdrv, outputVal);
  359. }
  360. /*
  361. * Set the hardware according to 'par'.
  362. */
  363. static int sgivwfb_set_par(struct fb_info *info)
  364. {
  365. struct sgivw_par *par = info->par;
  366. int i, j, htmp, temp;
  367. u32 readVal, outputVal;
  368. int wholeTilesX, maxPixelsPerTileX;
  369. int frmWrite1, frmWrite2, frmWrite3b;
  370. struct dbe_timing_info *currentTiming; /* Current Video Timing */
  371. int xpmax, ypmax; // Monitor resolution
  372. int bytesPerPixel; // Bytes per pixel
  373. currentTiming = &dbeVTimings[par->timing_num];
  374. bytesPerPixel = bytes_per_pixel(info->var.bits_per_pixel);
  375. xpmax = currentTiming->width;
  376. ypmax = currentTiming->height;
  377. /* dbe_InitGraphicsBase(); */
  378. /* Turn on dotclock PLL */
  379. DBE_SETREG(ctrlstat, 0x20000000);
  380. dbe_TurnOffDma(par);
  381. /* dbe_CalculateScreenParams(); */
  382. maxPixelsPerTileX = 512 / bytesPerPixel;
  383. wholeTilesX = xpmax / maxPixelsPerTileX;
  384. if (wholeTilesX * maxPixelsPerTileX < xpmax)
  385. wholeTilesX++;
  386. printk(KERN_DEBUG "sgivwfb: pixPerTile=%d wholeTilesX=%d\n",
  387. maxPixelsPerTileX, wholeTilesX);
  388. /* dbe_InitGammaMap(); */
  389. udelay(10);
  390. for (i = 0; i < 256; i++) {
  391. DBE_ISETREG(gmap, i, (i << 24) | (i << 16) | (i << 8));
  392. }
  393. /* dbe_TurnOn(); */
  394. DBE_GETREG(vt_xy, readVal);
  395. if (GET_DBE_FIELD(VT_XY, VT_FREEZE, readVal) == 1) {
  396. DBE_SETREG(vt_xy, 0x00000000);
  397. udelay(1);
  398. } else
  399. dbe_TurnOffDma(par);
  400. /* dbe_Initdbe(); */
  401. for (i = 0; i < 256; i++) {
  402. for (j = 0; j < 100; j++) {
  403. DBE_GETREG(cm_fifo, readVal);
  404. if (readVal != 0x00000000)
  405. break;
  406. else
  407. udelay(10);
  408. }
  409. // DBE_ISETREG(cmap, i, 0x00000000);
  410. DBE_ISETREG(cmap, i, (i << 8) | (i << 16) | (i << 24));
  411. }
  412. /* dbe_InitFramebuffer(); */
  413. frmWrite1 = 0;
  414. SET_DBE_FIELD(FRM_SIZE_TILE, FRM_WIDTH_TILE, frmWrite1,
  415. wholeTilesX);
  416. SET_DBE_FIELD(FRM_SIZE_TILE, FRM_RHS, frmWrite1, 0);
  417. switch (bytesPerPixel) {
  418. case 1:
  419. SET_DBE_FIELD(FRM_SIZE_TILE, FRM_DEPTH, frmWrite1,
  420. DBE_FRM_DEPTH_8);
  421. break;
  422. case 2:
  423. SET_DBE_FIELD(FRM_SIZE_TILE, FRM_DEPTH, frmWrite1,
  424. DBE_FRM_DEPTH_16);
  425. break;
  426. case 4:
  427. SET_DBE_FIELD(FRM_SIZE_TILE, FRM_DEPTH, frmWrite1,
  428. DBE_FRM_DEPTH_32);
  429. break;
  430. }
  431. frmWrite2 = 0;
  432. SET_DBE_FIELD(FRM_SIZE_PIXEL, FB_HEIGHT_PIX, frmWrite2, ypmax);
  433. // Tell dbe about the framebuffer location and type
  434. // XXX What format is the FRM_TILE_PTR?? 64K aligned address?
  435. frmWrite3b = 0;
  436. SET_DBE_FIELD(FRM_CONTROL, FRM_TILE_PTR, frmWrite3b,
  437. sgivwfb_mem_phys >> 9);
  438. SET_DBE_FIELD(FRM_CONTROL, FRM_DMA_ENABLE, frmWrite3b, 1);
  439. SET_DBE_FIELD(FRM_CONTROL, FRM_LINEAR, frmWrite3b, 1);
  440. /* Initialize DIDs */
  441. outputVal = 0;
  442. switch (bytesPerPixel) {
  443. case 1:
  444. SET_DBE_FIELD(WID, TYP, outputVal, DBE_CMODE_I8);
  445. break;
  446. case 2:
  447. SET_DBE_FIELD(WID, TYP, outputVal, DBE_CMODE_RGBA5);
  448. break;
  449. case 4:
  450. SET_DBE_FIELD(WID, TYP, outputVal, DBE_CMODE_RGB8);
  451. break;
  452. }
  453. SET_DBE_FIELD(WID, BUF, outputVal, DBE_BMODE_BOTH);
  454. for (i = 0; i < 32; i++) {
  455. DBE_ISETREG(mode_regs, i, outputVal);
  456. }
  457. /* dbe_InitTiming(); */
  458. DBE_SETREG(vt_intr01, 0xffffffff);
  459. DBE_SETREG(vt_intr23, 0xffffffff);
  460. DBE_GETREG(dotclock, readVal);
  461. DBE_SETREG(dotclock, readVal & 0xffff);
  462. DBE_SETREG(vt_xymax, 0x00000000);
  463. outputVal = 0;
  464. SET_DBE_FIELD(VT_VSYNC, VT_VSYNC_ON, outputVal,
  465. currentTiming->vsync_start);
  466. SET_DBE_FIELD(VT_VSYNC, VT_VSYNC_OFF, outputVal,
  467. currentTiming->vsync_end);
  468. DBE_SETREG(vt_vsync, outputVal);
  469. outputVal = 0;
  470. SET_DBE_FIELD(VT_HSYNC, VT_HSYNC_ON, outputVal,
  471. currentTiming->hsync_start);
  472. SET_DBE_FIELD(VT_HSYNC, VT_HSYNC_OFF, outputVal,
  473. currentTiming->hsync_end);
  474. DBE_SETREG(vt_hsync, outputVal);
  475. outputVal = 0;
  476. SET_DBE_FIELD(VT_VBLANK, VT_VBLANK_ON, outputVal,
  477. currentTiming->vblank_start);
  478. SET_DBE_FIELD(VT_VBLANK, VT_VBLANK_OFF, outputVal,
  479. currentTiming->vblank_end);
  480. DBE_SETREG(vt_vblank, outputVal);
  481. outputVal = 0;
  482. SET_DBE_FIELD(VT_HBLANK, VT_HBLANK_ON, outputVal,
  483. currentTiming->hblank_start);
  484. SET_DBE_FIELD(VT_HBLANK, VT_HBLANK_OFF, outputVal,
  485. currentTiming->hblank_end - 3);
  486. DBE_SETREG(vt_hblank, outputVal);
  487. outputVal = 0;
  488. SET_DBE_FIELD(VT_VCMAP, VT_VCMAP_ON, outputVal,
  489. currentTiming->vblank_start);
  490. SET_DBE_FIELD(VT_VCMAP, VT_VCMAP_OFF, outputVal,
  491. currentTiming->vblank_end);
  492. DBE_SETREG(vt_vcmap, outputVal);
  493. outputVal = 0;
  494. SET_DBE_FIELD(VT_HCMAP, VT_HCMAP_ON, outputVal,
  495. currentTiming->hblank_start);
  496. SET_DBE_FIELD(VT_HCMAP, VT_HCMAP_OFF, outputVal,
  497. currentTiming->hblank_end - 3);
  498. DBE_SETREG(vt_hcmap, outputVal);
  499. if (flatpanel_id != -1)
  500. sgivwfb_setup_flatpanel(par, currentTiming);
  501. outputVal = 0;
  502. temp = currentTiming->vblank_start - currentTiming->vblank_end - 1;
  503. if (temp > 0)
  504. temp = -temp;
  505. SET_DBE_FIELD(DID_START_XY, DID_STARTY, outputVal, (u32) temp);
  506. if (currentTiming->hblank_end >= 20)
  507. SET_DBE_FIELD(DID_START_XY, DID_STARTX, outputVal,
  508. currentTiming->hblank_end - 20);
  509. else
  510. SET_DBE_FIELD(DID_START_XY, DID_STARTX, outputVal,
  511. currentTiming->htotal - (20 -
  512. currentTiming->
  513. hblank_end));
  514. DBE_SETREG(did_start_xy, outputVal);
  515. outputVal = 0;
  516. SET_DBE_FIELD(CRS_START_XY, CRS_STARTY, outputVal,
  517. (u32) (temp + 1));
  518. if (currentTiming->hblank_end >= DBE_CRS_MAGIC)
  519. SET_DBE_FIELD(CRS_START_XY, CRS_STARTX, outputVal,
  520. currentTiming->hblank_end - DBE_CRS_MAGIC);
  521. else
  522. SET_DBE_FIELD(CRS_START_XY, CRS_STARTX, outputVal,
  523. currentTiming->htotal - (DBE_CRS_MAGIC -
  524. currentTiming->
  525. hblank_end));
  526. DBE_SETREG(crs_start_xy, outputVal);
  527. outputVal = 0;
  528. SET_DBE_FIELD(VC_START_XY, VC_STARTY, outputVal, (u32) temp);
  529. SET_DBE_FIELD(VC_START_XY, VC_STARTX, outputVal,
  530. currentTiming->hblank_end - 4);
  531. DBE_SETREG(vc_start_xy, outputVal);
  532. DBE_SETREG(frm_size_tile, frmWrite1);
  533. DBE_SETREG(frm_size_pixel, frmWrite2);
  534. outputVal = 0;
  535. SET_DBE_FIELD(DOTCLK, M, outputVal, currentTiming->pll_m - 1);
  536. SET_DBE_FIELD(DOTCLK, N, outputVal, currentTiming->pll_n - 1);
  537. SET_DBE_FIELD(DOTCLK, P, outputVal, currentTiming->pll_p);
  538. SET_DBE_FIELD(DOTCLK, RUN, outputVal, 1);
  539. DBE_SETREG(dotclock, outputVal);
  540. udelay(11 * 1000);
  541. DBE_SETREG(vt_vpixen, 0xffffff);
  542. DBE_SETREG(vt_hpixen, 0xffffff);
  543. outputVal = 0;
  544. SET_DBE_FIELD(VT_XYMAX, VT_MAXX, outputVal, currentTiming->htotal);
  545. SET_DBE_FIELD(VT_XYMAX, VT_MAXY, outputVal, currentTiming->vtotal);
  546. DBE_SETREG(vt_xymax, outputVal);
  547. outputVal = frmWrite1;
  548. SET_DBE_FIELD(FRM_SIZE_TILE, FRM_FIFO_RESET, outputVal, 1);
  549. DBE_SETREG(frm_size_tile, outputVal);
  550. DBE_SETREG(frm_size_tile, frmWrite1);
  551. outputVal = 0;
  552. SET_DBE_FIELD(OVR_WIDTH_TILE, OVR_FIFO_RESET, outputVal, 1);
  553. DBE_SETREG(ovr_width_tile, outputVal);
  554. DBE_SETREG(ovr_width_tile, 0);
  555. DBE_SETREG(frm_control, frmWrite3b);
  556. DBE_SETREG(did_control, 0);
  557. // Wait for dbe to take frame settings
  558. for (i = 0; i < 100000; i++) {
  559. DBE_GETREG(frm_inhwctrl, readVal);
  560. if (GET_DBE_FIELD(FRM_INHWCTRL, FRM_DMA_ENABLE, readVal) !=
  561. 0)
  562. break;
  563. else
  564. udelay(1);
  565. }
  566. if (i == 100000)
  567. printk(KERN_INFO
  568. "sgivwfb: timeout waiting for frame DMA enable.\n");
  569. outputVal = 0;
  570. htmp = currentTiming->hblank_end - 19;
  571. if (htmp < 0)
  572. htmp += currentTiming->htotal; /* allow blank to wrap around */
  573. SET_DBE_FIELD(VT_HPIXEN, VT_HPIXEN_ON, outputVal, htmp);
  574. SET_DBE_FIELD(VT_HPIXEN, VT_HPIXEN_OFF, outputVal,
  575. ((htmp + currentTiming->width -
  576. 2) % currentTiming->htotal));
  577. DBE_SETREG(vt_hpixen, outputVal);
  578. outputVal = 0;
  579. SET_DBE_FIELD(VT_VPIXEN, VT_VPIXEN_OFF, outputVal,
  580. currentTiming->vblank_start);
  581. SET_DBE_FIELD(VT_VPIXEN, VT_VPIXEN_ON, outputVal,
  582. currentTiming->vblank_end);
  583. DBE_SETREG(vt_vpixen, outputVal);
  584. // Turn off mouse cursor
  585. par->regs->crs_ctl = 0;
  586. // XXX What's this section for??
  587. DBE_GETREG(ctrlstat, readVal);
  588. readVal &= 0x02000000;
  589. if (readVal != 0) {
  590. DBE_SETREG(ctrlstat, 0x30000000);
  591. }
  592. return 0;
  593. }
  594. /*
  595. * Set a single color register. The values supplied are already
  596. * rounded down to the hardware's capabilities (according to the
  597. * entries in the var structure). Return != 0 for invalid regno.
  598. */
  599. static int sgivwfb_setcolreg(u_int regno, u_int red, u_int green,
  600. u_int blue, u_int transp,
  601. struct fb_info *info)
  602. {
  603. struct sgivw_par *par = (struct sgivw_par *) info->par;
  604. if (regno > 255)
  605. return 1;
  606. red >>= 8;
  607. green >>= 8;
  608. blue >>= 8;
  609. /* wait for the color map FIFO to have a free entry */
  610. while (par->cmap_fifo == 0)
  611. par->cmap_fifo = par->regs->cm_fifo;
  612. par->regs->cmap[regno] = (red << 24) | (green << 16) | (blue << 8);
  613. par->cmap_fifo--; /* assume FIFO is filling up */
  614. return 0;
  615. }
  616. static int sgivwfb_mmap(struct fb_info *info, struct file *file,
  617. struct vm_area_struct *vma)
  618. {
  619. unsigned long size = vma->vm_end - vma->vm_start;
  620. unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  621. if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
  622. return -EINVAL;
  623. if (offset + size > sgivwfb_mem_size)
  624. return -EINVAL;
  625. offset += sgivwfb_mem_phys;
  626. pgprot_val(vma->vm_page_prot) =
  627. pgprot_val(vma->vm_page_prot) | _PAGE_PCD;
  628. vma->vm_flags |= VM_IO;
  629. if (remap_pfn_range(vma, vma->vm_start, offset >> PAGE_SHIFT,
  630. size, vma->vm_page_prot))
  631. return -EAGAIN;
  632. vma->vm_file = file;
  633. printk(KERN_DEBUG "sgivwfb: mmap framebuffer P(%lx)->V(%lx)\n",
  634. offset, vma->vm_start);
  635. return 0;
  636. }
  637. int __init sgivwfb_setup(char *options)
  638. {
  639. char *this_opt;
  640. if (!options || !*options)
  641. return 0;
  642. while ((this_opt = strsep(&options, ",")) != NULL) {
  643. if (!strncmp(this_opt, "monitor:", 8)) {
  644. if (!strncmp(this_opt + 8, "crt", 3))
  645. flatpanel_id = -1;
  646. else if (!strncmp(this_opt + 8, "1600sw", 6))
  647. flatpanel_id = FLATPANEL_SGI_1600SW;
  648. }
  649. }
  650. return 0;
  651. }
  652. /*
  653. * Initialisation
  654. */
  655. static void sgivwfb_release(struct device *device)
  656. {
  657. }
  658. static int __init sgivwfb_probe(struct device *device)
  659. {
  660. struct platform_device *dev = to_platform_device(device);
  661. struct sgivw_par *par;
  662. struct fb_info *info;
  663. char *monitor;
  664. info = framebuffer_alloc(sizeof(struct sgivw_par) + sizeof(u32) * 256, &dev->dev);
  665. if (!info)
  666. return -ENOMEM;
  667. par = info->par;
  668. if (!request_mem_region(DBE_REG_PHYS, DBE_REG_SIZE, "sgivwfb")) {
  669. printk(KERN_ERR "sgivwfb: couldn't reserve mmio region\n");
  670. framebuffer_release(info);
  671. return -EBUSY;
  672. }
  673. par->regs = (struct asregs *) ioremap_nocache(DBE_REG_PHYS, DBE_REG_SIZE);
  674. if (!par->regs) {
  675. printk(KERN_ERR "sgivwfb: couldn't ioremap registers\n");
  676. goto fail_ioremap_regs;
  677. }
  678. mtrr_add(sgivwfb_mem_phys, sgivwfb_mem_size, MTRR_TYPE_WRCOMB, 1);
  679. sgivwfb_fix.smem_start = sgivwfb_mem_phys;
  680. sgivwfb_fix.smem_len = sgivwfb_mem_size;
  681. sgivwfb_fix.ywrapstep = ywrap;
  682. sgivwfb_fix.ypanstep = ypan;
  683. info->fix = sgivwfb_fix;
  684. switch (flatpanel_id) {
  685. case FLATPANEL_SGI_1600SW:
  686. info->var = sgivwfb_var1600sw;
  687. monitor = "SGI 1600SW flatpanel";
  688. break;
  689. default:
  690. info->var = sgivwfb_var;
  691. monitor = "CRT";
  692. }
  693. printk(KERN_INFO "sgivwfb: %s monitor selected\n", monitor);
  694. info->fbops = &sgivwfb_ops;
  695. info->pseudo_palette = (void *) (par + 1);
  696. info->flags = FBINFO_DEFAULT;
  697. info->screen_base = ioremap_nocache((unsigned long) sgivwfb_mem_phys, sgivwfb_mem_size);
  698. if (!info->screen_base) {
  699. printk(KERN_ERR "sgivwfb: couldn't ioremap screen_base\n");
  700. goto fail_ioremap_fbmem;
  701. }
  702. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
  703. goto fail_color_map;
  704. if (register_framebuffer(info) < 0) {
  705. printk(KERN_ERR "sgivwfb: couldn't register framebuffer\n");
  706. goto fail_register_framebuffer;
  707. }
  708. dev_set_drvdata(&dev->dev, info);
  709. printk(KERN_INFO "fb%d: SGI DBE frame buffer device, using %ldK of video memory at %#lx\n",
  710. info->node, sgivwfb_mem_size >> 10, sgivwfb_mem_phys);
  711. return 0;
  712. fail_register_framebuffer:
  713. fb_dealloc_cmap(&info->cmap);
  714. fail_color_map:
  715. iounmap((char *) info->screen_base);
  716. fail_ioremap_fbmem:
  717. iounmap(par->regs);
  718. fail_ioremap_regs:
  719. release_mem_region(DBE_REG_PHYS, DBE_REG_SIZE);
  720. framebuffer_release(info);
  721. return -ENXIO;
  722. }
  723. static int sgivwfb_remove(struct device *device)
  724. {
  725. struct fb_info *info = dev_get_drvdata(device);
  726. if (info) {
  727. struct sgivw_par *par = info->par;
  728. unregister_framebuffer(info);
  729. dbe_TurnOffDma(par);
  730. iounmap(par->regs);
  731. iounmap(info->screen_base);
  732. release_mem_region(DBE_REG_PHYS, DBE_REG_SIZE);
  733. }
  734. return 0;
  735. }
  736. static struct device_driver sgivwfb_driver = {
  737. .name = "sgivwfb",
  738. .bus = &platform_bus_type,
  739. .probe = sgivwfb_probe,
  740. .remove = sgivwfb_remove,
  741. };
  742. static struct platform_device sgivwfb_device = {
  743. .name = "sgivwfb",
  744. .id = 0,
  745. .dev = {
  746. .release = sgivwfb_release,
  747. }
  748. };
  749. int __init sgivwfb_init(void)
  750. {
  751. int ret;
  752. #ifndef MODULE
  753. char *option = NULL;
  754. if (fb_get_options("sgivwfb", &option))
  755. return -ENODEV;
  756. sgivwfb_setup(option);
  757. #endif
  758. ret = driver_register(&sgivwfb_driver);
  759. if (!ret) {
  760. ret = platform_device_register(&sgivwfb_device);
  761. if (ret)
  762. driver_unregister(&sgivwfb_driver);
  763. }
  764. return ret;
  765. }
  766. module_init(sgivwfb_init);
  767. #ifdef MODULE
  768. MODULE_LICENSE("GPL");
  769. static void __exit sgivwfb_exit(void)
  770. {
  771. platform_device_unregister(&sgivwfb_device);
  772. driver_unregister(&sgivwfb_driver);
  773. }
  774. module_exit(sgivwfb_exit);
  775. #endif /* MODULE */