12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/string.h>
22 #include <linux/pci.h>
37 #define PCI_VENDOR_ID_ST 0x104a
38 #define PCI_DEVICE_ID_STG4000 0x0010
40 #define KHZ2PICOS(a) (1000000000UL/(a))
84 static char *mode_option __devinitdata =
NULL;
85 static int nopan __devinitdata = 0;
86 static int nowrap __devinitdata = 1;
88 static int nomtrr __devinitdata = 0;
93 static void kyrofb_remove(
struct pci_dev *pdev);
95 static struct fb_videomode kyro_modedb[] __devinitdata = {
99 96, 32, 60, 32, 64, 3,
104 96, 32, 41, 1, 64, 3,
109 108, 36, 42, 1, 72, 3,
114 48, 16, 33, 10, 96, 2,
119 128, 24, 28, 9, 40, 3,
124 120, 16, 16, 1, 64, 3,
129 80, 56, 25, 1, 56, 3,
134 128, 24, 22, 1, 72, 2,
139 88, 40, 23, 1, 128, 4,
144 64, 56, 23, 37, 120, 6,
149 160, 16, 21, 1, 80, 3,
154 152, 32, 27, 1, 64, 3,
159 160, 24, 29, 3, 136, 6,
164 144, 24, 29, 3, 136, 6,
169 176, 16, 28, 1, 96, 3,
174 208, 48, 36, 1, 96, 3,
179 256, 64, 32, 1, 128, 3,
184 312, 96, 36, 1, 112, 3,
189 224, 64, 47, 1, 160, 3,
194 248, 48, 38, 1, 112, 3,
199 248, 16, 38, 1, 144, 3,
204 224, 64, 44, 1, 160, 3,
209 304, 64, 46, 1, 192, 3,
214 304, 64, 46, 1, 192, 3,
219 304, 64, 46, 1, 192, 3,
224 304, 64, 46, 1, 192, 3,
229 304, 64, 46, 1, 192, 3,
234 328, 128, 46, 1, 200, 3,
239 352, 96, 69, 1, 216, 3,
244 352, 96, 43, 1, 224, 3,
249 352, 128, 104, 1, 224, 3,
254 344, 128, 56, 1, 208, 3,
259 352, 144, 56, 1, 224, 3,
263 #define NUM_TOTAL_MODES ARRAY_SIZE(kyro_modedb)
305 static int kyro_dev_video_mode_set(
struct fb_info *
info)
317 info->
var.bits_per_pixel,
318 info->
var.xres, info->
var.yres,
331 info->
var.bits_per_pixel;
337 static int kyro_dev_overlay_create(
u32 ulWidth,
338 u32 ulHeight,
int bLinear)
341 u32 stride, uvStride;
356 if ((offset & 0x1f) != 0) {
357 offset = (offset + 32
L) & 0xffffffE0L;
361 bLinear, offset, &stride, &uvStride) < 0)
367 deviceInfo.
ulNextFreeVidMem = offset + (ulHeight * stride) + (ulHeight * 2 * uvStride);
374 static int kyro_dev_overlay_viewport_set(
u32 x,
u32 y,
u32 ulWidth,
u32 ulHeight)
384 x, y, x + ulWidth - 1, y + ulHeight - 1);
393 static inline unsigned long get_line_length(
int x,
int bpp)
395 return (
unsigned long)((((x*
bpp)+31)&~31) >> 3);
409 var->
red.offset = 11;
411 var->
green.offset = 5;
412 var->
green.length = 6;
413 var->
blue.length = 5;
417 var->
red.offset = 16;
418 var->
green.offset = 8;
419 var->
blue.offset = 0;
422 var->
green.length = 8;
423 var->
blue.length = 8;
474 static int kyrofb_set_par(
struct fb_info *info)
477 unsigned long lineclock;
478 unsigned long frameclock;
489 lineclock = (info->
var.pixclock * (info->
var.xres +
490 info->
var.right_margin +
491 info->
var.hsync_len +
492 info->
var.left_margin)) / 1000;
496 frameclock = lineclock * (info->
var.yres +
497 info->
var.lower_margin +
498 info->
var.vsync_len +
499 info->
var.upper_margin);
502 par->
VFREQ = (1000000000 + (frameclock / 2)) / frameclock;
503 par->
HCLK = (1000000000 + (lineclock / 2)) / lineclock;
504 par->
PIXCLK = ((1000000000 + (info->
var.pixclock / 2))
505 / info->
var.pixclock) * 10;
508 par->
HFP = info->
var.right_margin;
509 par->
HST = info->
var.hsync_len;
510 par->
HBP = info->
var.left_margin;
514 par->
VFP = info->
var.lower_margin;
515 par->
VST = info->
var.vsync_len;
516 par->
VBP = info->
var.upper_margin;
522 kyro_dev_video_mode_set(info);
540 switch (info->
var.bits_per_pixel) {
544 ((green & 0xfc00) >> 5) |
545 ((blue & 0xf800) >> 11);
548 red >>= 8; green >>= 8; blue >>= 8; transp >>= 8;
550 (transp << 24) | (red << 16) | (green << 8) | blue;
563 if (!options || !*options)
566 while ((this_opt =
strsep(&options,
","))) {
569 if (
strcmp(this_opt,
"nopan") == 0) {
571 }
else if (
strcmp(this_opt,
"nowrap") == 0) {
574 }
else if (
strcmp(this_opt,
"nomtrr") == 0) {
578 mode_option = this_opt;
586 static int kyrofb_ioctl(
struct fb_info *info,
587 unsigned int cmd,
unsigned long arg)
598 if (kyro_dev_overlay_create(ol_create.
ulWidth,
610 if (kyro_dev_overlay_viewport_set(ol_viewport_set.
xOrgin,
612 ol_viewport_set.
xSize,
613 ol_viewport_set.
ySize) != 0)
622 "obsolete, use the appropriate fb_ioctl()"
623 "command instead.\n");
652 static struct pci_driver kyrofb_pci_driver = {
654 .id_table = kyrofb_pci_tbl,
655 .probe = kyrofb_probe,
659 static struct fb_ops kyrofb_ops = {
661 .fb_check_var = kyrofb_check_var,
662 .fb_set_par = kyrofb_set_par,
663 .fb_setcolreg = kyrofb_setcolreg,
664 .fb_ioctl = kyrofb_ioctl,
687 currentpar = info->
par;
702 currentpar->mtrr_handle =
708 kyro_fix.ypanstep = nopan ? 0 : 1;
709 kyro_fix.ywrapstep = nowrap ? 0 : 1;
711 info->
fbops = &kyrofb_ops;
712 info->
fix = kyro_fix;
724 info->
var = kyro_var;
728 kyrofb_set_par(info);
729 kyrofb_check_var(&info->
var, info);
731 size = get_line_length(info->
var.xres_virtual,
732 info->
var.bits_per_pixel);
733 size *= info->
var.yres_virtual;
740 printk(
"fb%d: %s frame buffer device, at %dx%d@%d using %ldk/%ldk of VRAM\n",
742 info->
var.yres, info->
var.bits_per_pixel, size >> 10,
743 (
unsigned long)info->
fix.smem_len >> 10);
745 pci_set_drvdata(pdev, info);
759 struct fb_info *info = pci_get_drvdata(pdev);
776 if (par->mtrr_handle)
778 info->
fix.smem_start,
783 pci_set_drvdata(pdev,
NULL);
787 static int __init kyrofb_init(
void)
794 kyrofb_setup(option);
796 return pci_register_driver(&kyrofb_pci_driver);
799 static void __exit kyrofb_exit(
void)