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