fbdev.c 21 KB

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