fbdev.c 21 KB

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