sgivwfb.c 23 KB

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