fbdev.c 21 KB

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