0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/module.h>
0013 #include <linux/types.h>
0014 #include <linux/kernel.h>
0015 #include <linux/mm.h>
0016 #include <linux/errno.h>
0017 #include <linux/string.h>
0018 #include <linux/delay.h>
0019 #include <linux/fb.h>
0020 #include <linux/ioctl.h>
0021 #include <linux/init.h>
0022 #include <linux/pci.h>
0023 #include <asm/io.h>
0024 #include <linux/uaccess.h>
0025
0026 #include <video/kyro.h>
0027
0028 #include "STG4000Reg.h"
0029 #include "STG4000Interface.h"
0030
0031
0032
0033
0034 #define PCI_VENDOR_ID_ST 0x104a
0035 #define PCI_DEVICE_ID_STG4000 0x0010
0036
0037 #define KHZ2PICOS(a) (1000000000UL/(a))
0038
0039
0040 static struct fb_fix_screeninfo kyro_fix = {
0041 .id = "ST Kyro",
0042 .type = FB_TYPE_PACKED_PIXELS,
0043 .visual = FB_VISUAL_TRUECOLOR,
0044 .accel = FB_ACCEL_NONE,
0045 };
0046
0047 static const struct fb_var_screeninfo kyro_var = {
0048
0049 .xres = 640,
0050 .yres = 480,
0051 .xres_virtual = 640,
0052 .yres_virtual = 480,
0053 .bits_per_pixel = 16,
0054 .red = { 11, 5, 0 },
0055 .green = { 5, 6, 0 },
0056 .blue = { 0, 5, 0 },
0057 .activate = FB_ACTIVATE_NOW,
0058 .height = -1,
0059 .width = -1,
0060 .pixclock = KHZ2PICOS(25175),
0061 .left_margin = 48,
0062 .right_margin = 16,
0063 .upper_margin = 33,
0064 .lower_margin = 10,
0065 .hsync_len = 96,
0066 .vsync_len = 2,
0067 .vmode = FB_VMODE_NONINTERLACED,
0068 };
0069
0070 typedef struct {
0071 STG4000REG __iomem *pSTGReg;
0072 u32 ulNextFreeVidMem;
0073 u32 ulOverlayOffset;
0074 u32 ulOverlayStride;
0075 u32 ulOverlayUVStride;
0076 } device_info_t;
0077
0078
0079 static device_info_t deviceInfo;
0080
0081 static char *mode_option = NULL;
0082 static int nopan = 0;
0083 static int nowrap = 1;
0084 static int nomtrr = 0;
0085
0086
0087 static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
0088 static void kyrofb_remove(struct pci_dev *pdev);
0089
0090 static struct fb_videomode kyro_modedb[] = {
0091 {
0092
0093 NULL, 85, 640, 350, KHZ2PICOS(31500),
0094 96, 32, 60, 32, 64, 3,
0095 FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED
0096 }, {
0097
0098 NULL, 85, 640, 400, KHZ2PICOS(31500),
0099 96, 32, 41, 1, 64, 3,
0100 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0101 }, {
0102
0103 NULL, 85, 720, 400, KHZ2PICOS(35500),
0104 108, 36, 42, 1, 72, 3,
0105 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0106 }, {
0107
0108 NULL, 60, 640, 480, KHZ2PICOS(25175),
0109 48, 16, 33, 10, 96, 2,
0110 0, FB_VMODE_NONINTERLACED
0111 }, {
0112
0113 NULL, 72, 640, 480, KHZ2PICOS(31500),
0114 128, 24, 28, 9, 40, 3,
0115 0, FB_VMODE_NONINTERLACED
0116 }, {
0117
0118 NULL, 75, 640, 480, KHZ2PICOS(31500),
0119 120, 16, 16, 1, 64, 3,
0120 0, FB_VMODE_NONINTERLACED
0121 }, {
0122
0123 NULL, 85, 640, 480, KHZ2PICOS(36000),
0124 80, 56, 25, 1, 56, 3,
0125 0, FB_VMODE_NONINTERLACED
0126 }, {
0127
0128 NULL, 56, 800, 600, KHZ2PICOS(36000),
0129 128, 24, 22, 1, 72, 2,
0130 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0131 }, {
0132
0133 NULL, 60, 800, 600, KHZ2PICOS(40000),
0134 88, 40, 23, 1, 128, 4,
0135 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0136 }, {
0137
0138 NULL, 72, 800, 600, KHZ2PICOS(50000),
0139 64, 56, 23, 37, 120, 6,
0140 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0141 }, {
0142
0143 NULL, 75, 800, 600, KHZ2PICOS(49500),
0144 160, 16, 21, 1, 80, 3,
0145 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0146 }, {
0147
0148 NULL, 85, 800, 600, KHZ2PICOS(56250),
0149 152, 32, 27, 1, 64, 3,
0150 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0151 }, {
0152
0153 NULL, 60, 1024, 768, KHZ2PICOS(65000),
0154 160, 24, 29, 3, 136, 6,
0155 0, FB_VMODE_NONINTERLACED
0156 }, {
0157
0158 NULL, 70, 1024, 768, KHZ2PICOS(75000),
0159 144, 24, 29, 3, 136, 6,
0160 0, FB_VMODE_NONINTERLACED
0161 }, {
0162
0163 NULL, 75, 1024, 768, KHZ2PICOS(78750),
0164 176, 16, 28, 1, 96, 3,
0165 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0166 }, {
0167
0168 NULL, 85, 1024, 768, KHZ2PICOS(94500),
0169 208, 48, 36, 1, 96, 3,
0170 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0171 }, {
0172
0173 NULL, 75, 1152, 864, KHZ2PICOS(108000),
0174 256, 64, 32, 1, 128, 3,
0175 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0176 }, {
0177
0178 NULL, 60, 1280, 960, KHZ2PICOS(108000),
0179 312, 96, 36, 1, 112, 3,
0180 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0181 }, {
0182
0183 NULL, 85, 1280, 960, KHZ2PICOS(148500),
0184 224, 64, 47, 1, 160, 3,
0185 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0186 }, {
0187
0188 NULL, 60, 1280, 1024, KHZ2PICOS(108000),
0189 248, 48, 38, 1, 112, 3,
0190 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0191 }, {
0192
0193 NULL, 75, 1280, 1024, KHZ2PICOS(135000),
0194 248, 16, 38, 1, 144, 3,
0195 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0196 }, {
0197
0198 NULL, 85, 1280, 1024, KHZ2PICOS(157500),
0199 224, 64, 44, 1, 160, 3,
0200 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0201 }, {
0202
0203 NULL, 60, 1600, 1200, KHZ2PICOS(162000),
0204 304, 64, 46, 1, 192, 3,
0205 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0206 }, {
0207
0208 NULL, 65, 1600, 1200, KHZ2PICOS(175500),
0209 304, 64, 46, 1, 192, 3,
0210 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0211 }, {
0212
0213 NULL, 70, 1600, 1200, KHZ2PICOS(189000),
0214 304, 64, 46, 1, 192, 3,
0215 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0216 }, {
0217
0218 NULL, 75, 1600, 1200, KHZ2PICOS(202500),
0219 304, 64, 46, 1, 192, 3,
0220 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0221 }, {
0222
0223 NULL, 85, 1600, 1200, KHZ2PICOS(229500),
0224 304, 64, 46, 1, 192, 3,
0225 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0226 }, {
0227
0228 NULL, 60, 1792, 1344, KHZ2PICOS(204750),
0229 328, 128, 46, 1, 200, 3,
0230 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0231 }, {
0232
0233 NULL, 75, 1792, 1344, KHZ2PICOS(261000),
0234 352, 96, 69, 1, 216, 3,
0235 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0236 }, {
0237
0238 NULL, 60, 1856, 1392, KHZ2PICOS(218250),
0239 352, 96, 43, 1, 224, 3,
0240 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0241 }, {
0242
0243 NULL, 75, 1856, 1392, KHZ2PICOS(288000),
0244 352, 128, 104, 1, 224, 3,
0245 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0246 }, {
0247
0248 NULL, 60, 1920, 1440, KHZ2PICOS(234000),
0249 344, 128, 56, 1, 208, 3,
0250 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0251 }, {
0252
0253 NULL, 75, 1920, 1440, KHZ2PICOS(297000),
0254 352, 144, 56, 1, 224, 3,
0255 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
0256 },
0257 };
0258 #define NUM_TOTAL_MODES ARRAY_SIZE(kyro_modedb)
0259
0260
0261
0262
0263 enum {
0264 VMODE_640_350_85,
0265 VMODE_640_400_85,
0266 VMODE_720_400_85,
0267 VMODE_640_480_60,
0268 VMODE_640_480_72,
0269 VMODE_640_480_75,
0270 VMODE_640_480_85,
0271 VMODE_800_600_56,
0272 VMODE_800_600_60,
0273 VMODE_800_600_72,
0274 VMODE_800_600_75,
0275 VMODE_800_600_85,
0276 VMODE_1024_768_60,
0277 VMODE_1024_768_70,
0278 VMODE_1024_768_75,
0279 VMODE_1024_768_85,
0280 VMODE_1152_864_75,
0281 VMODE_1280_960_60,
0282 VMODE_1280_960_85,
0283 VMODE_1280_1024_60,
0284 VMODE_1280_1024_75,
0285 VMODE_1280_1024_85,
0286 VMODE_1600_1200_60,
0287 VMODE_1600_1200_65,
0288 VMODE_1600_1200_70,
0289 VMODE_1600_1200_75,
0290 VMODE_1600_1200_85,
0291 VMODE_1792_1344_60,
0292 VMODE_1792_1344_75,
0293 VMODE_1856_1392_60,
0294 VMODE_1856_1392_75,
0295 VMODE_1920_1440_60,
0296 VMODE_1920_1440_75,
0297 };
0298
0299
0300 static int kyro_dev_video_mode_set(struct fb_info *info)
0301 {
0302 struct kyrofb_info *par = info->par;
0303
0304
0305 StopVTG(deviceInfo.pSTGReg);
0306 DisableRamdacOutput(deviceInfo.pSTGReg);
0307
0308
0309 DisableVGA(deviceInfo.pSTGReg);
0310
0311 if (InitialiseRamdac(deviceInfo.pSTGReg,
0312 info->var.bits_per_pixel,
0313 info->var.xres, info->var.yres,
0314 par->HSP, par->VSP, &par->PIXCLK) < 0)
0315 return -EINVAL;
0316
0317 SetupVTG(deviceInfo.pSTGReg, par);
0318
0319 ResetOverlayRegisters(deviceInfo.pSTGReg);
0320
0321
0322 EnableRamdacOutput(deviceInfo.pSTGReg);
0323 StartVTG(deviceInfo.pSTGReg);
0324
0325 deviceInfo.ulNextFreeVidMem = info->var.xres * info->var.yres *
0326 info->var.bits_per_pixel;
0327 deviceInfo.ulOverlayOffset = 0;
0328
0329 return 0;
0330 }
0331
0332 static int kyro_dev_overlay_create(u32 ulWidth,
0333 u32 ulHeight, int bLinear)
0334 {
0335 u32 offset;
0336 u32 stride, uvStride;
0337
0338 if (deviceInfo.ulOverlayOffset != 0)
0339
0340
0341
0342
0343 return -EINVAL;
0344
0345 ResetOverlayRegisters(deviceInfo.pSTGReg);
0346
0347
0348
0349
0350 offset = deviceInfo.ulNextFreeVidMem;
0351 if ((offset & 0x1f) != 0) {
0352 offset = (offset + 32L) & 0xffffffE0L;
0353 }
0354
0355 if (CreateOverlaySurface(deviceInfo.pSTGReg, ulWidth, ulHeight,
0356 bLinear, offset, &stride, &uvStride) < 0)
0357 return -EINVAL;
0358
0359 deviceInfo.ulOverlayOffset = offset;
0360 deviceInfo.ulOverlayStride = stride;
0361 deviceInfo.ulOverlayUVStride = uvStride;
0362 deviceInfo.ulNextFreeVidMem = offset + (ulHeight * stride) + (ulHeight * 2 * uvStride);
0363
0364 SetOverlayBlendMode(deviceInfo.pSTGReg, GLOBAL_ALPHA, 0xf, 0x0);
0365
0366 return 0;
0367 }
0368
0369 static int kyro_dev_overlay_viewport_set(u32 x, u32 y, u32 ulWidth, u32 ulHeight)
0370 {
0371 if (deviceInfo.ulOverlayOffset == 0)
0372
0373 return -EINVAL;
0374
0375 if (ulWidth == 0 || ulWidth == 0xffffffff ||
0376 ulHeight == 0 || ulHeight == 0xffffffff ||
0377 (x < 2 && ulWidth + 2 == 0))
0378 return -EINVAL;
0379
0380
0381 DisableRamdacOutput(deviceInfo.pSTGReg);
0382
0383 SetOverlayViewPort(deviceInfo.pSTGReg,
0384 x, y, x + ulWidth - 1, y + ulHeight - 1);
0385
0386 EnableOverlayPlane(deviceInfo.pSTGReg);
0387
0388 EnableRamdacOutput(deviceInfo.pSTGReg);
0389
0390 return 0;
0391 }
0392
0393 static inline unsigned long get_line_length(int x, int bpp)
0394 {
0395 return (unsigned long)((((x*bpp)+31)&~31) >> 3);
0396 }
0397
0398 static int kyrofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
0399 {
0400 struct kyrofb_info *par = info->par;
0401
0402 if (!var->pixclock)
0403 return -EINVAL;
0404
0405 if (var->bits_per_pixel != 16 && var->bits_per_pixel != 32) {
0406 printk(KERN_WARNING "kyrofb: depth not supported: %u\n", var->bits_per_pixel);
0407 return -EINVAL;
0408 }
0409
0410 switch (var->bits_per_pixel) {
0411 case 16:
0412 var->red.offset = 11;
0413 var->red.length = 5;
0414 var->green.offset = 5;
0415 var->green.length = 6;
0416 var->blue.length = 5;
0417 break;
0418 case 32:
0419 var->transp.offset = 24;
0420 var->red.offset = 16;
0421 var->green.offset = 8;
0422 var->blue.offset = 0;
0423
0424 var->red.length = 8;
0425 var->green.length = 8;
0426 var->blue.length = 8;
0427 var->transp.length = 8;
0428 break;
0429 }
0430
0431
0432 var->height = var->width = -1;
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_TEST)
0459 return 0;
0460
0461 var->left_margin = par->HBP;
0462 var->hsync_len = par->HST;
0463 var->right_margin = par->HFP;
0464
0465 var->upper_margin = par->VBP;
0466 var->vsync_len = par->VST;
0467 var->lower_margin = par->VFP;
0468
0469 if (par->HSP == 1)
0470 var->sync |= FB_SYNC_HOR_HIGH_ACT;
0471 if (par->VSP == 1)
0472 var->sync |= FB_SYNC_VERT_HIGH_ACT;
0473
0474 return 0;
0475 }
0476
0477 static int kyrofb_set_par(struct fb_info *info)
0478 {
0479 struct kyrofb_info *par = info->par;
0480 unsigned long lineclock;
0481 unsigned long frameclock;
0482
0483
0484 par->XRES = info->var.xres;
0485 par->YRES = info->var.yres;
0486
0487
0488 par->PIXDEPTH = info->var.bits_per_pixel;
0489
0490
0491
0492 lineclock = (info->var.pixclock * (info->var.xres +
0493 info->var.right_margin +
0494 info->var.hsync_len +
0495 info->var.left_margin)) / 1000;
0496
0497 if (!lineclock)
0498 return -EINVAL;
0499
0500
0501 frameclock = lineclock * (info->var.yres +
0502 info->var.lower_margin +
0503 info->var.vsync_len +
0504 info->var.upper_margin);
0505
0506
0507 par->VFREQ = (1000000000 + (frameclock / 2)) / frameclock;
0508 par->HCLK = (1000000000 + (lineclock / 2)) / lineclock;
0509 par->PIXCLK = ((1000000000 + (info->var.pixclock / 2))
0510 / info->var.pixclock) * 10;
0511
0512
0513 par->HFP = info->var.right_margin;
0514 par->HST = info->var.hsync_len;
0515 par->HBP = info->var.left_margin;
0516 par->HTot = par->XRES + par->HBP + par->HST + par->HFP;
0517
0518
0519 par->VFP = info->var.lower_margin;
0520 par->VST = info->var.vsync_len;
0521 par->VBP = info->var.upper_margin;
0522 par->VTot = par->YRES + par->VBP + par->VST + par->VFP;
0523
0524 par->HSP = (info->var.sync & FB_SYNC_HOR_HIGH_ACT) ? 1 : 0;
0525 par->VSP = (info->var.sync & FB_SYNC_VERT_HIGH_ACT) ? 1 : 0;
0526
0527 kyro_dev_video_mode_set(info);
0528
0529
0530 info->fix.line_length = get_line_length(par->XRES, par->PIXDEPTH);
0531 info->fix.visual = FB_VISUAL_TRUECOLOR;
0532
0533 return 0;
0534 }
0535
0536 static int kyrofb_setcolreg(u_int regno, u_int red, u_int green,
0537 u_int blue, u_int transp, struct fb_info *info)
0538 {
0539 struct kyrofb_info *par = info->par;
0540
0541 if (regno > 255)
0542 return 1;
0543
0544 if (regno < 16) {
0545 switch (info->var.bits_per_pixel) {
0546 case 16:
0547 par->palette[regno] =
0548 (red & 0xf800) |
0549 ((green & 0xfc00) >> 5) |
0550 ((blue & 0xf800) >> 11);
0551 break;
0552 case 32:
0553 red >>= 8; green >>= 8; blue >>= 8; transp >>= 8;
0554 par->palette[regno] =
0555 (transp << 24) | (red << 16) | (green << 8) | blue;
0556 break;
0557 }
0558 }
0559
0560 return 0;
0561 }
0562
0563 #ifndef MODULE
0564 static int __init kyrofb_setup(char *options)
0565 {
0566 char *this_opt;
0567
0568 if (!options || !*options)
0569 return 0;
0570
0571 while ((this_opt = strsep(&options, ","))) {
0572 if (!*this_opt)
0573 continue;
0574 if (strcmp(this_opt, "nopan") == 0) {
0575 nopan = 1;
0576 } else if (strcmp(this_opt, "nowrap") == 0) {
0577 nowrap = 1;
0578 } else if (strcmp(this_opt, "nomtrr") == 0) {
0579 nomtrr = 1;
0580 } else {
0581 mode_option = this_opt;
0582 }
0583 }
0584
0585 return 0;
0586 }
0587 #endif
0588
0589 static int kyrofb_ioctl(struct fb_info *info,
0590 unsigned int cmd, unsigned long arg)
0591 {
0592 overlay_create ol_create;
0593 overlay_viewport_set ol_viewport_set;
0594 void __user *argp = (void __user *)arg;
0595
0596 switch (cmd) {
0597 case KYRO_IOCTL_OVERLAY_CREATE:
0598 if (copy_from_user(&ol_create, argp, sizeof(overlay_create)))
0599 return -EFAULT;
0600
0601 if (kyro_dev_overlay_create(ol_create.ulWidth,
0602 ol_create.ulHeight, 0) < 0) {
0603 printk(KERN_ERR "Kyro FB: failed to create overlay surface.\n");
0604
0605 return -EINVAL;
0606 }
0607 break;
0608 case KYRO_IOCTL_OVERLAY_VIEWPORT_SET:
0609 if (copy_from_user(&ol_viewport_set, argp,
0610 sizeof(overlay_viewport_set)))
0611 return -EFAULT;
0612
0613 if (kyro_dev_overlay_viewport_set(ol_viewport_set.xOrgin,
0614 ol_viewport_set.yOrgin,
0615 ol_viewport_set.xSize,
0616 ol_viewport_set.ySize) != 0)
0617 {
0618 printk(KERN_ERR "Kyro FB: failed to create overlay viewport.\n");
0619 return -EINVAL;
0620 }
0621 break;
0622 case KYRO_IOCTL_SET_VIDEO_MODE:
0623 {
0624 printk(KERN_ERR "Kyro FB: KYRO_IOCTL_SET_VIDEO_MODE is"
0625 "obsolete, use the appropriate fb_ioctl()"
0626 "command instead.\n");
0627 return -EINVAL;
0628 }
0629 case KYRO_IOCTL_UVSTRIDE:
0630 if (copy_to_user(argp, &deviceInfo.ulOverlayUVStride, sizeof(deviceInfo.ulOverlayUVStride)))
0631 return -EFAULT;
0632 break;
0633 case KYRO_IOCTL_STRIDE:
0634 if (copy_to_user(argp, &deviceInfo.ulOverlayStride, sizeof(deviceInfo.ulOverlayStride)))
0635 return -EFAULT;
0636 break;
0637 case KYRO_IOCTL_OVERLAY_OFFSET:
0638 if (copy_to_user(argp, &deviceInfo.ulOverlayOffset, sizeof(deviceInfo.ulOverlayOffset)))
0639 return -EFAULT;
0640 break;
0641 }
0642
0643 return 0;
0644 }
0645
0646 static const struct pci_device_id kyrofb_pci_tbl[] = {
0647 { PCI_VENDOR_ID_ST, PCI_DEVICE_ID_STG4000,
0648 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
0649 { 0, }
0650 };
0651
0652 MODULE_DEVICE_TABLE(pci, kyrofb_pci_tbl);
0653
0654 static struct pci_driver kyrofb_pci_driver = {
0655 .name = "kyrofb",
0656 .id_table = kyrofb_pci_tbl,
0657 .probe = kyrofb_probe,
0658 .remove = kyrofb_remove,
0659 };
0660
0661 static const struct fb_ops kyrofb_ops = {
0662 .owner = THIS_MODULE,
0663 .fb_check_var = kyrofb_check_var,
0664 .fb_set_par = kyrofb_set_par,
0665 .fb_setcolreg = kyrofb_setcolreg,
0666 .fb_ioctl = kyrofb_ioctl,
0667 .fb_fillrect = cfb_fillrect,
0668 .fb_copyarea = cfb_copyarea,
0669 .fb_imageblit = cfb_imageblit,
0670 };
0671
0672 static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
0673 {
0674 struct fb_info *info;
0675 struct kyrofb_info *currentpar;
0676 unsigned long size;
0677 int err;
0678
0679 if ((err = pci_enable_device(pdev))) {
0680 printk(KERN_WARNING "kyrofb: Can't enable pdev: %d\n", err);
0681 return err;
0682 }
0683
0684 info = framebuffer_alloc(sizeof(struct kyrofb_info), &pdev->dev);
0685 if (!info)
0686 return -ENOMEM;
0687
0688 currentpar = info->par;
0689
0690 kyro_fix.smem_start = pci_resource_start(pdev, 0);
0691 kyro_fix.smem_len = pci_resource_len(pdev, 0);
0692 kyro_fix.mmio_start = pci_resource_start(pdev, 1);
0693 kyro_fix.mmio_len = pci_resource_len(pdev, 1);
0694
0695 currentpar->regbase = deviceInfo.pSTGReg =
0696 ioremap(kyro_fix.mmio_start, kyro_fix.mmio_len);
0697 if (!currentpar->regbase)
0698 goto out_free_fb;
0699
0700 info->screen_base = pci_ioremap_wc_bar(pdev, 0);
0701 if (!info->screen_base)
0702 goto out_unmap_regs;
0703
0704 if (!nomtrr)
0705 currentpar->wc_cookie = arch_phys_wc_add(kyro_fix.smem_start,
0706 kyro_fix.smem_len);
0707
0708 kyro_fix.ypanstep = nopan ? 0 : 1;
0709 kyro_fix.ywrapstep = nowrap ? 0 : 1;
0710
0711 info->fbops = &kyrofb_ops;
0712 info->fix = kyro_fix;
0713 info->pseudo_palette = currentpar->palette;
0714 info->flags = FBINFO_DEFAULT;
0715
0716 SetCoreClockPLL(deviceInfo.pSTGReg, pdev);
0717
0718 deviceInfo.ulNextFreeVidMem = 0;
0719 deviceInfo.ulOverlayOffset = 0;
0720
0721
0722 if (!fb_find_mode(&info->var, info, mode_option, kyro_modedb,
0723 NUM_TOTAL_MODES, &kyro_modedb[VMODE_1024_768_75], 32))
0724 info->var = kyro_var;
0725
0726 fb_alloc_cmap(&info->cmap, 256, 0);
0727
0728 kyrofb_set_par(info);
0729 kyrofb_check_var(&info->var, info);
0730
0731 size = get_line_length(info->var.xres_virtual,
0732 info->var.bits_per_pixel);
0733 size *= info->var.yres_virtual;
0734
0735 fb_memset(info->screen_base, 0, size);
0736
0737 if (register_framebuffer(info) < 0)
0738 goto out_unmap;
0739
0740 fb_info(info, "%s frame buffer device, at %dx%d@%d using %ldk/%ldk of VRAM\n",
0741 info->fix.id,
0742 info->var.xres, info->var.yres, info->var.bits_per_pixel,
0743 size >> 10, (unsigned long)info->fix.smem_len >> 10);
0744
0745 pci_set_drvdata(pdev, info);
0746
0747 return 0;
0748
0749 out_unmap:
0750 iounmap(info->screen_base);
0751 out_unmap_regs:
0752 iounmap(currentpar->regbase);
0753 out_free_fb:
0754 framebuffer_release(info);
0755
0756 return -EINVAL;
0757 }
0758
0759 static void kyrofb_remove(struct pci_dev *pdev)
0760 {
0761 struct fb_info *info = pci_get_drvdata(pdev);
0762 struct kyrofb_info *par = info->par;
0763
0764
0765 StopVTG(deviceInfo.pSTGReg);
0766 DisableRamdacOutput(deviceInfo.pSTGReg);
0767
0768
0769 SetCoreClockPLL(deviceInfo.pSTGReg, pdev);
0770
0771 deviceInfo.ulNextFreeVidMem = 0;
0772 deviceInfo.ulOverlayOffset = 0;
0773
0774 iounmap(info->screen_base);
0775 iounmap(par->regbase);
0776
0777 arch_phys_wc_del(par->wc_cookie);
0778
0779 unregister_framebuffer(info);
0780 framebuffer_release(info);
0781 }
0782
0783 static int __init kyrofb_init(void)
0784 {
0785 #ifndef MODULE
0786 char *option = NULL;
0787
0788 if (fb_get_options("kyrofb", &option))
0789 return -ENODEV;
0790 kyrofb_setup(option);
0791 #endif
0792 return pci_register_driver(&kyrofb_pci_driver);
0793 }
0794
0795 static void __exit kyrofb_exit(void)
0796 {
0797 pci_unregister_driver(&kyrofb_pci_driver);
0798 }
0799
0800 module_init(kyrofb_init);
0801
0802 #ifdef MODULE
0803 module_exit(kyrofb_exit);
0804 #endif
0805
0806 MODULE_AUTHOR("STMicroelectronics; Paul Mundt <lethal@linux-sh.org>");
0807 MODULE_LICENSE("GPL");