fbdev.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. /*
  2. * linux/drivers/video/kyro/fbdev.c
  3. *
  4. * Copyright (C) 2002 STMicroelectronics
  5. * Copyright (C) 2003, 2004 Paul Mundt
  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
  9. * for more details.
  10. */
  11. #include <linux/config.h>
  12. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/sched.h>
  16. #include <linux/mm.h>
  17. #include <linux/errno.h>
  18. #include <linux/string.h>
  19. #include <linux/tty.h>
  20. #include <linux/delay.h>
  21. #include <linux/fb.h>
  22. #include <linux/ioctl.h>
  23. #include <linux/init.h>
  24. #include <linux/pci.h>
  25. #include <asm/io.h>
  26. #include <asm/uaccess.h>
  27. #ifdef CONFIG_MTRR
  28. #include <asm/mtrr.h>
  29. #endif
  30. #include <video/kyro.h>
  31. #include "STG4000Reg.h"
  32. #include "STG4000Interface.h"
  33. /*
  34. * PCI Definitions
  35. */
  36. #define PCI_VENDOR_ID_ST 0x104a
  37. #define PCI_DEVICE_ID_STG4000 0x0010
  38. #define KHZ2PICOS(a) (1000000000UL/(a))
  39. /****************************************************************************/
  40. static struct fb_fix_screeninfo kyro_fix __devinitdata = {
  41. .id = "ST Kyro",
  42. .type = FB_TYPE_PACKED_PIXELS,
  43. .visual = FB_VISUAL_TRUECOLOR,
  44. .accel = FB_ACCEL_NONE,
  45. };
  46. static struct fb_var_screeninfo kyro_var __devinitdata = {
  47. /* 640x480, 16bpp @ 60 Hz */
  48. .xres = 640,
  49. .yres = 480,
  50. .xres_virtual = 640,
  51. .yres_virtual = 480,
  52. .bits_per_pixel = 16,
  53. .red = { 11, 5, 0 },
  54. .green = { 5, 6, 0 },
  55. .blue = { 0, 5, 0 },
  56. .activate = FB_ACTIVATE_NOW,
  57. .height = -1,
  58. .width = -1,
  59. .pixclock = KHZ2PICOS(25175),
  60. .left_margin = 48,
  61. .right_margin = 16,
  62. .upper_margin = 33,
  63. .lower_margin = 10,
  64. .hsync_len = 96,
  65. .vsync_len = 2,
  66. .vmode = FB_VMODE_NONINTERLACED,
  67. };
  68. typedef struct {
  69. STG4000REG __iomem *pSTGReg; /* Virtual address of PCI register region */
  70. u32 ulNextFreeVidMem; /* Offset from start of vid mem to next free region */
  71. u32 ulOverlayOffset; /* Offset from start of vid mem to overlay */
  72. u32 ulOverlayStride; /* Interleaved YUV and 422 mode Y stride */
  73. u32 ulOverlayUVStride; /* 422 mode U & V stride */
  74. } device_info_t;
  75. /* global graphics card info structure (one per card) */
  76. static device_info_t deviceInfo;
  77. static char *mode_option __devinitdata = NULL;
  78. static int nopan __devinitdata = 0;
  79. static int nowrap __devinitdata = 1;
  80. #ifdef CONFIG_MTRR
  81. static int nomtrr __devinitdata = 0;
  82. #endif
  83. /* PCI driver prototypes */
  84. static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
  85. static void kyrofb_remove(struct pci_dev *pdev);
  86. static struct fb_videomode kyro_modedb[] __devinitdata = {
  87. {
  88. /* 640x350 @ 85Hz */
  89. NULL, 85, 640, 350, KHZ2PICOS(31500),
  90. 96, 32, 60, 32, 64, 3,
  91. FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED
  92. }, {
  93. /* 640x400 @ 85Hz */
  94. NULL, 85, 640, 400, KHZ2PICOS(31500),
  95. 96, 32, 41, 1, 64, 3,
  96. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  97. }, {
  98. /* 720x400 @ 85Hz */
  99. NULL, 85, 720, 400, KHZ2PICOS(35500),
  100. 108, 36, 42, 1, 72, 3,
  101. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  102. }, {
  103. /* 640x480 @ 60Hz */
  104. NULL, 60, 640, 480, KHZ2PICOS(25175),
  105. 48, 16, 33, 10, 96, 2,
  106. 0, FB_VMODE_NONINTERLACED
  107. }, {
  108. /* 640x480 @ 72Hz */
  109. NULL, 72, 640, 480, KHZ2PICOS(31500),
  110. 128, 24, 28, 9, 40, 3,
  111. 0, FB_VMODE_NONINTERLACED
  112. }, {
  113. /* 640x480 @ 75Hz */
  114. NULL, 75, 640, 480, KHZ2PICOS(31500),
  115. 120, 16, 16, 1, 64, 3,
  116. 0, FB_VMODE_NONINTERLACED
  117. }, {
  118. /* 640x480 @ 85Hz */
  119. NULL, 85, 640, 480, KHZ2PICOS(36000),
  120. 80, 56, 25, 1, 56, 3,
  121. 0, FB_VMODE_NONINTERLACED
  122. }, {
  123. /* 800x600 @ 56Hz */
  124. NULL, 56, 800, 600, KHZ2PICOS(36000),
  125. 128, 24, 22, 1, 72, 2,
  126. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  127. }, {
  128. /* 800x600 @ 60Hz */
  129. NULL, 60, 800, 600, KHZ2PICOS(40000),
  130. 88, 40, 23, 1, 128, 4,
  131. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  132. }, {
  133. /* 800x600 @ 72Hz */
  134. NULL, 72, 800, 600, KHZ2PICOS(50000),
  135. 64, 56, 23, 37, 120, 6,
  136. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  137. }, {
  138. /* 800x600 @ 75Hz */
  139. NULL, 75, 800, 600, KHZ2PICOS(49500),
  140. 160, 16, 21, 1, 80, 3,
  141. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  142. }, {
  143. /* 800x600 @ 85Hz */
  144. NULL, 85, 800, 600, KHZ2PICOS(56250),
  145. 152, 32, 27, 1, 64, 3,
  146. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  147. }, {
  148. /* 1024x768 @ 60Hz */
  149. NULL, 60, 1024, 768, KHZ2PICOS(65000),
  150. 160, 24, 29, 3, 136, 6,
  151. 0, FB_VMODE_NONINTERLACED
  152. }, {
  153. /* 1024x768 @ 70Hz */
  154. NULL, 70, 1024, 768, KHZ2PICOS(75000),
  155. 144, 24, 29, 3, 136, 6,
  156. 0, FB_VMODE_NONINTERLACED
  157. }, {
  158. /* 1024x768 @ 75Hz */
  159. NULL, 75, 1024, 768, KHZ2PICOS(78750),
  160. 176, 16, 28, 1, 96, 3,
  161. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  162. }, {
  163. /* 1024x768 @ 85Hz */
  164. NULL, 85, 1024, 768, KHZ2PICOS(94500),
  165. 208, 48, 36, 1, 96, 3,
  166. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  167. }, {
  168. /* 1152x864 @ 75Hz */
  169. NULL, 75, 1152, 864, KHZ2PICOS(108000),
  170. 256, 64, 32, 1, 128, 3,
  171. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  172. }, {
  173. /* 1280x960 @ 60Hz */
  174. NULL, 60, 1280, 960, KHZ2PICOS(108000),
  175. 312, 96, 36, 1, 112, 3,
  176. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  177. }, {
  178. /* 1280x960 @ 85Hz */
  179. NULL, 85, 1280, 960, KHZ2PICOS(148500),
  180. 224, 64, 47, 1, 160, 3,
  181. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  182. }, {
  183. /* 1280x1024 @ 60Hz */
  184. NULL, 60, 1280, 1024, KHZ2PICOS(108000),
  185. 248, 48, 38, 1, 112, 3,
  186. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  187. }, {
  188. /* 1280x1024 @ 75Hz */
  189. NULL, 75, 1280, 1024, KHZ2PICOS(135000),
  190. 248, 16, 38, 1, 144, 3,
  191. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  192. }, {
  193. /* 1280x1024 @ 85Hz */
  194. NULL, 85, 1280, 1024, KHZ2PICOS(157500),
  195. 224, 64, 44, 1, 160, 3,
  196. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  197. }, {
  198. /* 1600x1200 @ 60Hz */
  199. NULL, 60, 1600, 1200, KHZ2PICOS(162000),
  200. 304, 64, 46, 1, 192, 3,
  201. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  202. }, {
  203. /* 1600x1200 @ 65Hz */
  204. NULL, 65, 1600, 1200, KHZ2PICOS(175500),
  205. 304, 64, 46, 1, 192, 3,
  206. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  207. }, {
  208. /* 1600x1200 @ 70Hz */
  209. NULL, 70, 1600, 1200, KHZ2PICOS(189000),
  210. 304, 64, 46, 1, 192, 3,
  211. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  212. }, {
  213. /* 1600x1200 @ 75Hz */
  214. NULL, 75, 1600, 1200, KHZ2PICOS(202500),
  215. 304, 64, 46, 1, 192, 3,
  216. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  217. }, {
  218. /* 1600x1200 @ 85Hz */
  219. NULL, 85, 1600, 1200, KHZ2PICOS(229500),
  220. 304, 64, 46, 1, 192, 3,
  221. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  222. }, {
  223. /* 1792x1344 @ 60Hz */
  224. NULL, 60, 1792, 1344, KHZ2PICOS(204750),
  225. 328, 128, 46, 1, 200, 3,
  226. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  227. }, {
  228. /* 1792x1344 @ 75Hz */
  229. NULL, 75, 1792, 1344, KHZ2PICOS(261000),
  230. 352, 96, 69, 1, 216, 3,
  231. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  232. }, {
  233. /* 1856x1392 @ 60Hz */
  234. NULL, 60, 1856, 1392, KHZ2PICOS(218250),
  235. 352, 96, 43, 1, 224, 3,
  236. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  237. }, {
  238. /* 1856x1392 @ 75Hz */
  239. NULL, 75, 1856, 1392, KHZ2PICOS(288000),
  240. 352, 128, 104, 1, 224, 3,
  241. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  242. }, {
  243. /* 1920x1440 @ 60Hz */
  244. NULL, 60, 1920, 1440, KHZ2PICOS(234000),
  245. 344, 128, 56, 1, 208, 3,
  246. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  247. }, {
  248. /* 1920x1440 @ 75Hz */
  249. NULL, 75, 1920, 1440, KHZ2PICOS(297000),
  250. 352, 144, 56, 1, 224, 3,
  251. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  252. },
  253. };
  254. #define NUM_TOTAL_MODES ARRAY_SIZE(kyro_modedb)
  255. /*
  256. * This needs to be kept ordered corresponding to kyro_modedb.
  257. */
  258. enum {
  259. VMODE_640_350_85,
  260. VMODE_640_400_85,
  261. VMODE_720_400_85,
  262. VMODE_640_480_60,
  263. VMODE_640_480_72,
  264. VMODE_640_480_75,
  265. VMODE_640_480_85,
  266. VMODE_800_600_56,
  267. VMODE_800_600_60,
  268. VMODE_800_600_72,
  269. VMODE_800_600_75,
  270. VMODE_800_600_85,
  271. VMODE_1024_768_60,
  272. VMODE_1024_768_70,
  273. VMODE_1024_768_75,
  274. VMODE_1024_768_85,
  275. VMODE_1152_864_75,
  276. VMODE_1280_960_60,
  277. VMODE_1280_960_85,
  278. VMODE_1280_1024_60,
  279. VMODE_1280_1024_75,
  280. VMODE_1280_1024_85,
  281. VMODE_1600_1200_60,
  282. VMODE_1600_1200_65,
  283. VMODE_1600_1200_70,
  284. VMODE_1600_1200_75,
  285. VMODE_1600_1200_85,
  286. VMODE_1792_1344_60,
  287. VMODE_1792_1344_75,
  288. VMODE_1856_1392_60,
  289. VMODE_1856_1392_75,
  290. VMODE_1920_1440_60,
  291. VMODE_1920_1440_75,
  292. };
  293. /* Accessors */
  294. static int kyro_dev_video_mode_set(struct fb_info *info)
  295. {
  296. struct kyrofb_info *par = info->par;
  297. /* Turn off display */
  298. StopVTG(deviceInfo.pSTGReg);
  299. DisableRamdacOutput(deviceInfo.pSTGReg);
  300. /* Bring us out of VGA and into Hi-Res mode, if not already. */
  301. DisableVGA(deviceInfo.pSTGReg);
  302. if (InitialiseRamdac(deviceInfo.pSTGReg,
  303. info->var.bits_per_pixel,
  304. info->var.xres, info->var.yres,
  305. par->HSP, par->VSP, &par->PIXCLK) < 0)
  306. return -EINVAL;
  307. SetupVTG(deviceInfo.pSTGReg, par);
  308. ResetOverlayRegisters(deviceInfo.pSTGReg);
  309. /* Turn on display in new mode */
  310. EnableRamdacOutput(deviceInfo.pSTGReg);
  311. StartVTG(deviceInfo.pSTGReg);
  312. deviceInfo.ulNextFreeVidMem = info->var.xres * info->var.yres *
  313. info->var.bits_per_pixel;
  314. deviceInfo.ulOverlayOffset = 0;
  315. return 0;
  316. }
  317. static int kyro_dev_overlay_create(u32 ulWidth,
  318. u32 ulHeight, int bLinear)
  319. {
  320. u32 offset;
  321. u32 stride, uvStride;
  322. if (deviceInfo.ulOverlayOffset != 0)
  323. /*
  324. * Can only create one overlay without resetting the card or
  325. * changing display mode
  326. */
  327. return -EINVAL;
  328. ResetOverlayRegisters(deviceInfo.pSTGReg);
  329. /* Overlays are addressed in multiples of 16bytes or 32bytes, so make
  330. * sure the start offset is on an appropriate boundary.
  331. */
  332. offset = deviceInfo.ulNextFreeVidMem;
  333. if ((offset & 0x1f) != 0) {
  334. offset = (offset + 32L) & 0xffffffE0L;
  335. }
  336. if (CreateOverlaySurface(deviceInfo.pSTGReg, ulWidth, ulHeight,
  337. bLinear, offset, &stride, &uvStride) < 0)
  338. return -EINVAL;
  339. deviceInfo.ulOverlayOffset = offset;
  340. deviceInfo.ulOverlayStride = stride;
  341. deviceInfo.ulOverlayUVStride = uvStride;
  342. deviceInfo.ulNextFreeVidMem = offset + (ulHeight * stride) + (ulHeight * 2 * uvStride);
  343. SetOverlayBlendMode(deviceInfo.pSTGReg, GLOBAL_ALPHA, 0xf, 0x0);
  344. return 0;
  345. }
  346. static int kyro_dev_overlay_viewport_set(u32 x, u32 y, u32 ulWidth, u32 ulHeight)
  347. {
  348. if (deviceInfo.ulOverlayOffset == 0)
  349. /* probably haven't called CreateOverlay yet */
  350. return -EINVAL;
  351. /* Stop Ramdac Output */
  352. DisableRamdacOutput(deviceInfo.pSTGReg);
  353. SetOverlayViewPort(deviceInfo.pSTGReg,
  354. x, y, x + ulWidth - 1, y + ulHeight - 1);
  355. EnableOverlayPlane(deviceInfo.pSTGReg);
  356. /* Start Ramdac Output */
  357. EnableRamdacOutput(deviceInfo.pSTGReg);
  358. return 0;
  359. }
  360. static inline unsigned long get_line_length(int x, int bpp)
  361. {
  362. return (unsigned long)((((x*bpp)+31)&~31) >> 3);
  363. }
  364. static int kyrofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  365. {
  366. struct kyrofb_info *par = info->par;
  367. if (var->bits_per_pixel != 16 && var->bits_per_pixel != 32) {
  368. printk(KERN_WARNING "kyrofb: depth not supported: %u\n", var->bits_per_pixel);
  369. return -EINVAL;
  370. }
  371. switch (var->bits_per_pixel) {
  372. case 16:
  373. var->red.offset = 11;
  374. var->red.length = 5;
  375. var->green.offset = 5;
  376. var->green.length = 6;
  377. var->blue.length = 5;
  378. break;
  379. case 32:
  380. var->transp.offset = 24;
  381. var->red.offset = 16;
  382. var->green.offset = 8;
  383. var->blue.offset = 0;
  384. var->red.length = 8;
  385. var->green.length = 8;
  386. var->blue.length = 8;
  387. var->transp.length = 8;
  388. break;
  389. }
  390. /* Height/Width of picture in mm */
  391. var->height = var->width = -1;
  392. /* Timing information. All values are in picoseconds */
  393. /* par->PIXCLK is in 100Hz units. Convert to picoseconds -
  394. * ensuring we do not exceed 32 bit precision
  395. */
  396. /*
  397. * XXX: Enabling this really screws over the pixclock value when we
  398. * read it back with fbset. As such, leaving this commented out appears
  399. * to do the right thing (at least for now) .. bearing in mind that we
  400. * have infact already done the KHZ2PICOS conversion in both the modedb
  401. * and kyro_var. -- PFM.
  402. */
  403. // var->pixclock = 1000000000 / (par->PIXCLK / 10);
  404. /* the header file claims we should use picoseconds
  405. * - nobody else does though, the all use pixels and lines
  406. * of h and v sizes. Both options here.
  407. */
  408. /*
  409. * If we're being called by __fb_try_mode(), then we don't want to
  410. * override any of the var settings that we've already parsed
  411. * from our modedb. -- PFM.
  412. */
  413. if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_TEST)
  414. return 0;
  415. var->left_margin = par->HBP;
  416. var->hsync_len = par->HST;
  417. var->right_margin = par->HFP;
  418. var->upper_margin = par->VBP;
  419. var->vsync_len = par->VST;
  420. var->lower_margin = par->VFP;
  421. if (par->HSP == 1)
  422. var->sync |= FB_SYNC_HOR_HIGH_ACT;
  423. if (par->VSP == 1)
  424. var->sync |= FB_SYNC_VERT_HIGH_ACT;
  425. return 0;
  426. }
  427. static int kyrofb_set_par(struct fb_info *info)
  428. {
  429. struct kyrofb_info *par = info->par;
  430. unsigned long lineclock;
  431. unsigned long frameclock;
  432. /* Actual resolution */
  433. par->XRES = info->var.xres;
  434. par->YRES = info->var.yres;
  435. /* pixel depth */
  436. par->PIXDEPTH = info->var.bits_per_pixel;
  437. /* Refresh rate */
  438. /* time for a line in ns */
  439. lineclock = (info->var.pixclock * (info->var.xres +
  440. info->var.right_margin +
  441. info->var.hsync_len +
  442. info->var.left_margin)) / 1000;
  443. /* time for a frame in ns (precision in 32bpp) */
  444. frameclock = lineclock * (info->var.yres +
  445. info->var.lower_margin +
  446. info->var.vsync_len +
  447. info->var.upper_margin);
  448. /* Calculate refresh rate and horrizontal clocks */
  449. par->VFREQ = (1000000000 + (frameclock / 2)) / frameclock;
  450. par->HCLK = (1000000000 + (lineclock / 2)) / lineclock;
  451. par->PIXCLK = ((1000000000 + (info->var.pixclock / 2))
  452. / info->var.pixclock) * 10;
  453. /* calculate horizontal timings */
  454. par->HFP = info->var.right_margin;
  455. par->HST = info->var.hsync_len;
  456. par->HBP = info->var.left_margin;
  457. par->HTot = par->XRES + par->HBP + par->HST + par->HFP;
  458. /* calculate vertical timings */
  459. par->VFP = info->var.lower_margin;
  460. par->VST = info->var.vsync_len;
  461. par->VBP = info->var.upper_margin;
  462. par->VTot = par->YRES + par->VBP + par->VST + par->VFP;
  463. par->HSP = (info->var.sync & FB_SYNC_HOR_HIGH_ACT) ? 1 : 0;
  464. par->VSP = (info->var.sync & FB_SYNC_VERT_HIGH_ACT) ? 1 : 0;
  465. kyro_dev_video_mode_set(info);
  466. /* length of a line in bytes */
  467. info->fix.line_length = get_line_length(par->XRES, par->PIXDEPTH);
  468. info->fix.visual = FB_VISUAL_TRUECOLOR;
  469. return 0;
  470. }
  471. static int kyrofb_setcolreg(u_int regno, u_int red, u_int green,
  472. u_int blue, u_int transp, struct fb_info *info)
  473. {
  474. struct kyrofb_info *par = info->par;
  475. if (regno > 255)
  476. return 1; /* Invalid register */
  477. if (regno < 16) {
  478. switch (info->var.bits_per_pixel) {
  479. case 16:
  480. par->palette[regno] =
  481. (red & 0xf800) |
  482. ((green & 0xfc00) >> 5) |
  483. ((blue & 0xf800) >> 11);
  484. break;
  485. case 32:
  486. red >>= 8; green >>= 8; blue >>= 8; transp >>= 8;
  487. par->palette[regno] =
  488. (transp << 24) | (red << 16) | (green << 8) | blue;
  489. break;
  490. }
  491. }
  492. return 0;
  493. }
  494. #ifndef MODULE
  495. static int __init kyrofb_setup(char *options)
  496. {
  497. char *this_opt;
  498. if (!options || !*options)
  499. return 0;
  500. while ((this_opt = strsep(&options, ","))) {
  501. if (!*this_opt)
  502. continue;
  503. if (strcmp(this_opt, "nopan") == 0) {
  504. nopan = 1;
  505. } else if (strcmp(this_opt, "nowrap") == 0) {
  506. nowrap = 1;
  507. #ifdef CONFIG_MTRR
  508. } else if (strcmp(this_opt, "nomtrr") == 0) {
  509. nomtrr = 1;
  510. #endif
  511. } else {
  512. mode_option = this_opt;
  513. }
  514. }
  515. return 0;
  516. }
  517. #endif
  518. static int kyrofb_ioctl(struct fb_info *info,
  519. unsigned int cmd, unsigned long arg)
  520. {
  521. overlay_create ol_create;
  522. overlay_viewport_set ol_viewport_set;
  523. void __user *argp = (void __user *)arg;
  524. switch (cmd) {
  525. case KYRO_IOCTL_OVERLAY_CREATE:
  526. if (copy_from_user(&ol_create, argp, sizeof(overlay_create)))
  527. return -EFAULT;
  528. if (kyro_dev_overlay_create(ol_create.ulWidth,
  529. ol_create.ulHeight, 0) < 0) {
  530. printk(KERN_ERR "Kyro FB: failed to create overlay surface.\n");
  531. return -EINVAL;
  532. }
  533. break;
  534. case KYRO_IOCTL_OVERLAY_VIEWPORT_SET:
  535. if (copy_from_user(&ol_viewport_set, argp,
  536. sizeof(overlay_viewport_set)))
  537. return -EFAULT;
  538. if (kyro_dev_overlay_viewport_set(ol_viewport_set.xOrgin,
  539. ol_viewport_set.yOrgin,
  540. ol_viewport_set.xSize,
  541. ol_viewport_set.ySize) != 0)
  542. {
  543. printk(KERN_ERR "Kyro FB: failed to create overlay viewport.\n");
  544. return -EINVAL;
  545. }
  546. break;
  547. case KYRO_IOCTL_SET_VIDEO_MODE:
  548. {
  549. printk(KERN_ERR "Kyro FB: KYRO_IOCTL_SET_VIDEO_MODE is"
  550. "obsolete, use the appropriate fb_ioctl()"
  551. "command instead.\n");
  552. return -EINVAL;
  553. }
  554. break;
  555. case KYRO_IOCTL_UVSTRIDE:
  556. if (copy_to_user(argp, &deviceInfo.ulOverlayUVStride, sizeof(unsigned long)))
  557. return -EFAULT;
  558. break;
  559. case KYRO_IOCTL_STRIDE:
  560. if (copy_to_user(argp, &deviceInfo.ulOverlayStride, sizeof(unsigned long)))
  561. return -EFAULT;
  562. break;
  563. case KYRO_IOCTL_OVERLAY_OFFSET:
  564. if (copy_to_user(argp, &deviceInfo.ulOverlayOffset, sizeof(unsigned long)))
  565. return -EFAULT;
  566. break;
  567. }
  568. return 0;
  569. }
  570. static struct pci_device_id kyrofb_pci_tbl[] = {
  571. { PCI_VENDOR_ID_ST, PCI_DEVICE_ID_STG4000,
  572. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  573. { 0, }
  574. };
  575. MODULE_DEVICE_TABLE(pci, kyrofb_pci_tbl);
  576. static struct pci_driver kyrofb_pci_driver = {
  577. .name = "kyrofb",
  578. .id_table = kyrofb_pci_tbl,
  579. .probe = kyrofb_probe,
  580. .remove = __devexit_p(kyrofb_remove),
  581. };
  582. static struct fb_ops kyrofb_ops = {
  583. .owner = THIS_MODULE,
  584. .fb_check_var = kyrofb_check_var,
  585. .fb_set_par = kyrofb_set_par,
  586. .fb_setcolreg = kyrofb_setcolreg,
  587. .fb_ioctl = kyrofb_ioctl,
  588. .fb_fillrect = cfb_fillrect,
  589. .fb_copyarea = cfb_copyarea,
  590. .fb_imageblit = cfb_imageblit,
  591. };
  592. static int __devinit kyrofb_probe(struct pci_dev *pdev,
  593. const struct pci_device_id *ent)
  594. {
  595. struct fb_info *info;
  596. struct kyrofb_info *currentpar;
  597. unsigned long size;
  598. int err;
  599. if ((err = pci_enable_device(pdev))) {
  600. printk(KERN_WARNING "kyrofb: Can't enable pdev: %d\n", err);
  601. return err;
  602. }
  603. info = framebuffer_alloc(sizeof(struct kyrofb_info), &pdev->dev);
  604. if (!info)
  605. return -ENOMEM;
  606. currentpar = info->par;
  607. kyro_fix.smem_start = pci_resource_start(pdev, 0);
  608. kyro_fix.smem_len = pci_resource_len(pdev, 0);
  609. kyro_fix.mmio_start = pci_resource_start(pdev, 1);
  610. kyro_fix.mmio_len = pci_resource_len(pdev, 1);
  611. currentpar->regbase = deviceInfo.pSTGReg =
  612. ioremap_nocache(kyro_fix.mmio_start, kyro_fix.mmio_len);
  613. info->screen_base = ioremap_nocache(kyro_fix.smem_start,
  614. kyro_fix.smem_len);
  615. #ifdef CONFIG_MTRR
  616. if (!nomtrr)
  617. currentpar->mtrr_handle =
  618. mtrr_add(kyro_fix.smem_start,
  619. kyro_fix.smem_len,
  620. MTRR_TYPE_WRCOMB, 1);
  621. #endif
  622. kyro_fix.ypanstep = nopan ? 0 : 1;
  623. kyro_fix.ywrapstep = nowrap ? 0 : 1;
  624. info->fbops = &kyrofb_ops;
  625. info->fix = kyro_fix;
  626. info->pseudo_palette = currentpar->palette;
  627. info->flags = FBINFO_DEFAULT;
  628. SetCoreClockPLL(deviceInfo.pSTGReg, pdev);
  629. deviceInfo.ulNextFreeVidMem = 0;
  630. deviceInfo.ulOverlayOffset = 0;
  631. /* This should give a reasonable default video mode */
  632. if (!fb_find_mode(&info->var, info, mode_option, kyro_modedb,
  633. NUM_TOTAL_MODES, &kyro_modedb[VMODE_1024_768_75], 32))
  634. info->var = kyro_var;
  635. fb_alloc_cmap(&info->cmap, 256, 0);
  636. kyrofb_set_par(info);
  637. kyrofb_check_var(&info->var, info);
  638. size = get_line_length(info->var.xres_virtual,
  639. info->var.bits_per_pixel);
  640. size *= info->var.yres_virtual;
  641. fb_memset(info->screen_base, 0, size);
  642. if (register_framebuffer(info) < 0)
  643. goto out_unmap;
  644. printk("fb%d: %s frame buffer device, at %dx%d@%d using %ldk/%ldk of VRAM\n",
  645. info->node, info->fix.id, info->var.xres,
  646. info->var.yres, info->var.bits_per_pixel, size >> 10,
  647. (unsigned long)info->fix.smem_len >> 10);
  648. pci_set_drvdata(pdev, info);
  649. return 0;
  650. out_unmap:
  651. iounmap(currentpar->regbase);
  652. iounmap(info->screen_base);
  653. framebuffer_release(info);
  654. return -EINVAL;
  655. }
  656. static void __devexit kyrofb_remove(struct pci_dev *pdev)
  657. {
  658. struct fb_info *info = pci_get_drvdata(pdev);
  659. struct kyrofb_info *par = info->par;
  660. /* Reset the board */
  661. StopVTG(deviceInfo.pSTGReg);
  662. DisableRamdacOutput(deviceInfo.pSTGReg);
  663. /* Sync up the PLL */
  664. SetCoreClockPLL(deviceInfo.pSTGReg, pdev);
  665. deviceInfo.ulNextFreeVidMem = 0;
  666. deviceInfo.ulOverlayOffset = 0;
  667. iounmap(info->screen_base);
  668. iounmap(par->regbase);
  669. #ifdef CONFIG_MTRR
  670. if (par->mtrr_handle)
  671. mtrr_del(par->mtrr_handle,
  672. info->fix.smem_start,
  673. info->fix.smem_len);
  674. #endif
  675. unregister_framebuffer(info);
  676. pci_set_drvdata(pdev, NULL);
  677. framebuffer_release(info);
  678. }
  679. static int __init kyrofb_init(void)
  680. {
  681. #ifndef MODULE
  682. char *option = NULL;
  683. if (fb_get_options("kyrofb", &option))
  684. return -ENODEV;
  685. kyrofb_setup(option);
  686. #endif
  687. return pci_register_driver(&kyrofb_pci_driver);
  688. }
  689. static void __exit kyrofb_exit(void)
  690. {
  691. pci_unregister_driver(&kyrofb_pci_driver);
  692. }
  693. module_init(kyrofb_init);
  694. #ifdef MODULE
  695. module_exit(kyrofb_exit);
  696. #endif
  697. MODULE_AUTHOR("STMicroelectronics; Paul Mundt <lethal@linux-sh.org>");
  698. MODULE_LICENSE("GPL");