fbdev.c 20 KB

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