1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * i740fb - framebuffer driver for Intel740 4 * Copyright (c) 2011 Ondrej Zary 5 * 6 * Based on old i740fb driver (c) 2001-2002 Andrey Ulanov <drey@rt.mipt.ru> 7 * which was partially based on: 8 * VGA 16-color framebuffer driver (c) 1999 Ben Pfaff <pfaffben@debian.org> 9 * and Petr Vandrovec <VANDROVE@vc.cvut.cz> 10 * i740 driver from XFree86 (c) 1998-1999 Precision Insight, Inc., Cedar Park, 11 * Texas. 12 * i740fb by Patrick LERDA, v0.9 13 */ 14 15 #include <linux/module.h> 16 #include <linux/kernel.h> 17 #include <linux/errno.h> 18 #include <linux/string.h> 19 #include <linux/mm.h> 20 #include <linux/slab.h> 21 #include <linux/delay.h> 22 #include <linux/fb.h> 23 #include <linux/init.h> 24 #include <linux/pci.h> 25 #include <linux/pci_ids.h> 26 #include <linux/i2c.h> 27 #include <linux/i2c-algo-bit.h> 28 #include <linux/console.h> 29 #include <video/vga.h> 30 31 #include "i740_reg.h" 32 33 static char *mode_option; 34 static int mtrr = 1; 35 36 struct i740fb_par { 37 unsigned char __iomem *regs; 38 bool has_sgram; 39 int wc_cookie; 40 bool ddc_registered; 41 struct i2c_adapter ddc_adapter; 42 struct i2c_algo_bit_data ddc_algo; 43 u32 pseudo_palette[16]; 44 struct mutex open_lock; 45 unsigned int ref_count; 46 47 u8 crtc[VGA_CRT_C]; 48 u8 atc[VGA_ATT_C]; 49 u8 gdc[VGA_GFX_C]; 50 u8 seq[VGA_SEQ_C]; 51 u8 misc; 52 u8 vss; 53 54 /* i740 specific registers */ 55 u8 display_cntl; 56 u8 pixelpipe_cfg0; 57 u8 pixelpipe_cfg1; 58 u8 pixelpipe_cfg2; 59 u8 video_clk2_m; 60 u8 video_clk2_n; 61 u8 video_clk2_mn_msbs; 62 u8 video_clk2_div_sel; 63 u8 pll_cntl; 64 u8 address_mapping; 65 u8 io_cntl; 66 u8 bitblt_cntl; 67 u8 ext_vert_total; 68 u8 ext_vert_disp_end; 69 u8 ext_vert_sync_start; 70 u8 ext_vert_blank_start; 71 u8 ext_horiz_total; 72 u8 ext_horiz_blank; 73 u8 ext_offset; 74 u8 interlace_cntl; 75 u32 lmi_fifo_watermark; 76 u8 ext_start_addr; 77 u8 ext_start_addr_hi; 78 }; 79 80 #define DACSPEED8 203 81 #define DACSPEED16 163 82 #define DACSPEED24_SG 136 83 #define DACSPEED24_SD 128 84 #define DACSPEED32 86 85 86 static const struct fb_fix_screeninfo i740fb_fix = { 87 .id = "i740fb", 88 .type = FB_TYPE_PACKED_PIXELS, 89 .visual = FB_VISUAL_TRUECOLOR, 90 .xpanstep = 8, 91 .ypanstep = 1, 92 .accel = FB_ACCEL_NONE, 93 }; 94 95 static inline void i740outb(struct i740fb_par *par, u16 port, u8 val) 96 { 97 vga_mm_w(par->regs, port, val); 98 } 99 static inline u8 i740inb(struct i740fb_par *par, u16 port) 100 { 101 return vga_mm_r(par->regs, port); 102 } 103 static inline void i740outreg(struct i740fb_par *par, u16 port, u8 reg, u8 val) 104 { 105 vga_mm_w_fast(par->regs, port, reg, val); 106 } 107 static inline u8 i740inreg(struct i740fb_par *par, u16 port, u8 reg) 108 { 109 vga_mm_w(par->regs, port, reg); 110 return vga_mm_r(par->regs, port+1); 111 } 112 static inline void i740outreg_mask(struct i740fb_par *par, u16 port, u8 reg, 113 u8 val, u8 mask) 114 { 115 vga_mm_w_fast(par->regs, port, reg, (val & mask) 116 | (i740inreg(par, port, reg) & ~mask)); 117 } 118 119 #define REG_DDC_DRIVE 0x62 120 #define REG_DDC_STATE 0x63 121 #define DDC_SCL (1 << 3) 122 #define DDC_SDA (1 << 2) 123 124 static void i740fb_ddc_setscl(void *data, int val) 125 { 126 struct i740fb_par *par = data; 127 128 i740outreg_mask(par, XRX, REG_DDC_DRIVE, DDC_SCL, DDC_SCL); 129 i740outreg_mask(par, XRX, REG_DDC_STATE, val ? DDC_SCL : 0, DDC_SCL); 130 } 131 132 static void i740fb_ddc_setsda(void *data, int val) 133 { 134 struct i740fb_par *par = data; 135 136 i740outreg_mask(par, XRX, REG_DDC_DRIVE, DDC_SDA, DDC_SDA); 137 i740outreg_mask(par, XRX, REG_DDC_STATE, val ? DDC_SDA : 0, DDC_SDA); 138 } 139 140 static int i740fb_ddc_getscl(void *data) 141 { 142 struct i740fb_par *par = data; 143 144 i740outreg_mask(par, XRX, REG_DDC_DRIVE, 0, DDC_SCL); 145 146 return !!(i740inreg(par, XRX, REG_DDC_STATE) & DDC_SCL); 147 } 148 149 static int i740fb_ddc_getsda(void *data) 150 { 151 struct i740fb_par *par = data; 152 153 i740outreg_mask(par, XRX, REG_DDC_DRIVE, 0, DDC_SDA); 154 155 return !!(i740inreg(par, XRX, REG_DDC_STATE) & DDC_SDA); 156 } 157 158 static int i740fb_setup_ddc_bus(struct fb_info *info) 159 { 160 struct i740fb_par *par = info->par; 161 162 strlcpy(par->ddc_adapter.name, info->fix.id, 163 sizeof(par->ddc_adapter.name)); 164 par->ddc_adapter.owner = THIS_MODULE; 165 par->ddc_adapter.class = I2C_CLASS_DDC; 166 par->ddc_adapter.algo_data = &par->ddc_algo; 167 par->ddc_adapter.dev.parent = info->device; 168 par->ddc_algo.setsda = i740fb_ddc_setsda; 169 par->ddc_algo.setscl = i740fb_ddc_setscl; 170 par->ddc_algo.getsda = i740fb_ddc_getsda; 171 par->ddc_algo.getscl = i740fb_ddc_getscl; 172 par->ddc_algo.udelay = 10; 173 par->ddc_algo.timeout = 20; 174 par->ddc_algo.data = par; 175 176 i2c_set_adapdata(&par->ddc_adapter, par); 177 178 return i2c_bit_add_bus(&par->ddc_adapter); 179 } 180 181 static int i740fb_open(struct fb_info *info, int user) 182 { 183 struct i740fb_par *par = info->par; 184 185 mutex_lock(&(par->open_lock)); 186 par->ref_count++; 187 mutex_unlock(&(par->open_lock)); 188 189 return 0; 190 } 191 192 static int i740fb_release(struct fb_info *info, int user) 193 { 194 struct i740fb_par *par = info->par; 195 196 mutex_lock(&(par->open_lock)); 197 if (par->ref_count == 0) { 198 fb_err(info, "release called with zero refcount\n"); 199 mutex_unlock(&(par->open_lock)); 200 return -EINVAL; 201 } 202 203 par->ref_count--; 204 mutex_unlock(&(par->open_lock)); 205 206 return 0; 207 } 208 209 static u32 i740_calc_fifo(struct i740fb_par *par, u32 freq, int bpp) 210 { 211 /* 212 * Would like to calculate these values automatically, but a generic 213 * algorithm does not seem possible. Note: These FIFO water mark 214 * values were tested on several cards and seem to eliminate the 215 * all of the snow and vertical banding, but fine adjustments will 216 * probably be required for other cards. 217 */ 218 219 u32 wm; 220 221 switch (bpp) { 222 case 8: 223 if (freq > 200) 224 wm = 0x18120000; 225 else if (freq > 175) 226 wm = 0x16110000; 227 else if (freq > 135) 228 wm = 0x120E0000; 229 else 230 wm = 0x100D0000; 231 break; 232 case 15: 233 case 16: 234 if (par->has_sgram) { 235 if (freq > 140) 236 wm = 0x2C1D0000; 237 else if (freq > 120) 238 wm = 0x2C180000; 239 else if (freq > 100) 240 wm = 0x24160000; 241 else if (freq > 90) 242 wm = 0x18120000; 243 else if (freq > 50) 244 wm = 0x16110000; 245 else if (freq > 32) 246 wm = 0x13100000; 247 else 248 wm = 0x120E0000; 249 } else { 250 if (freq > 160) 251 wm = 0x28200000; 252 else if (freq > 140) 253 wm = 0x2A1E0000; 254 else if (freq > 130) 255 wm = 0x2B1A0000; 256 else if (freq > 120) 257 wm = 0x2C180000; 258 else if (freq > 100) 259 wm = 0x24180000; 260 else if (freq > 90) 261 wm = 0x18120000; 262 else if (freq > 50) 263 wm = 0x16110000; 264 else if (freq > 32) 265 wm = 0x13100000; 266 else 267 wm = 0x120E0000; 268 } 269 break; 270 case 24: 271 if (par->has_sgram) { 272 if (freq > 130) 273 wm = 0x31200000; 274 else if (freq > 120) 275 wm = 0x2E200000; 276 else if (freq > 100) 277 wm = 0x2C1D0000; 278 else if (freq > 80) 279 wm = 0x25180000; 280 else if (freq > 64) 281 wm = 0x24160000; 282 else if (freq > 49) 283 wm = 0x18120000; 284 else if (freq > 32) 285 wm = 0x16110000; 286 else 287 wm = 0x13100000; 288 } else { 289 if (freq > 120) 290 wm = 0x311F0000; 291 else if (freq > 100) 292 wm = 0x2C1D0000; 293 else if (freq > 80) 294 wm = 0x25180000; 295 else if (freq > 64) 296 wm = 0x24160000; 297 else if (freq > 49) 298 wm = 0x18120000; 299 else if (freq > 32) 300 wm = 0x16110000; 301 else 302 wm = 0x13100000; 303 } 304 break; 305 case 32: 306 if (par->has_sgram) { 307 if (freq > 80) 308 wm = 0x2A200000; 309 else if (freq > 60) 310 wm = 0x281A0000; 311 else if (freq > 49) 312 wm = 0x25180000; 313 else if (freq > 32) 314 wm = 0x18120000; 315 else 316 wm = 0x16110000; 317 } else { 318 if (freq > 80) 319 wm = 0x29200000; 320 else if (freq > 60) 321 wm = 0x281A0000; 322 else if (freq > 49) 323 wm = 0x25180000; 324 else if (freq > 32) 325 wm = 0x18120000; 326 else 327 wm = 0x16110000; 328 } 329 break; 330 } 331 332 return wm; 333 } 334 335 /* clock calculation from i740fb by Patrick LERDA */ 336 337 #define I740_RFREQ 1000000 338 #define TARGET_MAX_N 30 339 #define I740_FFIX (1 << 8) 340 #define I740_RFREQ_FIX (I740_RFREQ / I740_FFIX) 341 #define I740_REF_FREQ (6667 * I740_FFIX / 100) /* 66.67 MHz */ 342 #define I740_MAX_VCO_FREQ (450 * I740_FFIX) /* 450 MHz */ 343 344 static void i740_calc_vclk(u32 freq, struct i740fb_par *par) 345 { 346 const u32 err_max = freq / (200 * I740_RFREQ / I740_FFIX); 347 const u32 err_target = freq / (1000 * I740_RFREQ / I740_FFIX); 348 u32 err_best = 512 * I740_FFIX; 349 u32 f_err, f_vco; 350 int m_best = 0, n_best = 0, p_best = 0; 351 int m, n; 352 353 p_best = min(15, ilog2(I740_MAX_VCO_FREQ / (freq / I740_RFREQ_FIX))); 354 f_vco = (freq * (1 << p_best)) / I740_RFREQ_FIX; 355 freq = freq / I740_RFREQ_FIX; 356 357 n = 2; 358 do { 359 n++; 360 m = ((f_vco * n) / I740_REF_FREQ + 2) / 4; 361 362 if (m < 3) 363 m = 3; 364 365 { 366 u32 f_out = (((m * I740_REF_FREQ * 4) 367 / n) + ((1 << p_best) / 2)) / (1 << p_best); 368 369 f_err = (freq - f_out); 370 371 if (abs(f_err) < err_max) { 372 m_best = m; 373 n_best = n; 374 err_best = f_err; 375 } 376 } 377 } while ((abs(f_err) >= err_target) && 378 ((n <= TARGET_MAX_N) || (abs(err_best) > err_max))); 379 380 if (abs(f_err) < err_target) { 381 m_best = m; 382 n_best = n; 383 } 384 385 par->video_clk2_m = (m_best - 2) & 0xFF; 386 par->video_clk2_n = (n_best - 2) & 0xFF; 387 par->video_clk2_mn_msbs = ((((n_best - 2) >> 4) & VCO_N_MSBS) 388 | (((m_best - 2) >> 8) & VCO_M_MSBS)); 389 par->video_clk2_div_sel = ((p_best << 4) | REF_DIV_1); 390 } 391 392 static int i740fb_decode_var(const struct fb_var_screeninfo *var, 393 struct i740fb_par *par, struct fb_info *info) 394 { 395 /* 396 * Get the video params out of 'var'. 397 * If a value doesn't fit, round it up, if it's too big, return -EINVAL. 398 */ 399 400 u32 xres, right, hslen, left, xtotal; 401 u32 yres, lower, vslen, upper, ytotal; 402 u32 vxres, xoffset, vyres, yoffset; 403 u32 bpp, base, dacspeed24, mem, freq; 404 u8 r7; 405 int i; 406 407 dev_dbg(info->device, "decode_var: xres: %i, yres: %i, xres_v: %i, xres_v: %i\n", 408 var->xres, var->yres, var->xres_virtual, var->xres_virtual); 409 dev_dbg(info->device, " xoff: %i, yoff: %i, bpp: %i, graysc: %i\n", 410 var->xoffset, var->yoffset, var->bits_per_pixel, 411 var->grayscale); 412 dev_dbg(info->device, " activate: %i, nonstd: %i, vmode: %i\n", 413 var->activate, var->nonstd, var->vmode); 414 dev_dbg(info->device, " pixclock: %i, hsynclen:%i, vsynclen:%i\n", 415 var->pixclock, var->hsync_len, var->vsync_len); 416 dev_dbg(info->device, " left: %i, right: %i, up:%i, lower:%i\n", 417 var->left_margin, var->right_margin, var->upper_margin, 418 var->lower_margin); 419 420 421 bpp = var->bits_per_pixel; 422 switch (bpp) { 423 case 1 ... 8: 424 bpp = 8; 425 if ((1000000 / var->pixclock) > DACSPEED8) { 426 dev_err(info->device, "requested pixclock %i MHz out of range (max. %i MHz at 8bpp)\n", 427 1000000 / var->pixclock, DACSPEED8); 428 return -EINVAL; 429 } 430 break; 431 case 9 ... 15: 432 bpp = 15; 433 fallthrough; 434 case 16: 435 if ((1000000 / var->pixclock) > DACSPEED16) { 436 dev_err(info->device, "requested pixclock %i MHz out of range (max. %i MHz at 15/16bpp)\n", 437 1000000 / var->pixclock, DACSPEED16); 438 return -EINVAL; 439 } 440 break; 441 case 17 ... 24: 442 bpp = 24; 443 dacspeed24 = par->has_sgram ? DACSPEED24_SG : DACSPEED24_SD; 444 if ((1000000 / var->pixclock) > dacspeed24) { 445 dev_err(info->device, "requested pixclock %i MHz out of range (max. %i MHz at 24bpp)\n", 446 1000000 / var->pixclock, dacspeed24); 447 return -EINVAL; 448 } 449 break; 450 case 25 ... 32: 451 bpp = 32; 452 if ((1000000 / var->pixclock) > DACSPEED32) { 453 dev_err(info->device, "requested pixclock %i MHz out of range (max. %i MHz at 32bpp)\n", 454 1000000 / var->pixclock, DACSPEED32); 455 return -EINVAL; 456 } 457 break; 458 default: 459 return -EINVAL; 460 } 461 462 xres = ALIGN(var->xres, 8); 463 vxres = ALIGN(var->xres_virtual, 16); 464 if (vxres < xres) 465 vxres = xres; 466 467 xoffset = ALIGN(var->xoffset, 8); 468 if (xres + xoffset > vxres) 469 xoffset = vxres - xres; 470 471 left = ALIGN(var->left_margin, 8); 472 right = ALIGN(var->right_margin, 8); 473 hslen = ALIGN(var->hsync_len, 8); 474 475 yres = var->yres; 476 vyres = var->yres_virtual; 477 if (yres > vyres) 478 vyres = yres; 479 480 yoffset = var->yoffset; 481 if (yres + yoffset > vyres) 482 yoffset = vyres - yres; 483 484 lower = var->lower_margin; 485 vslen = var->vsync_len; 486 upper = var->upper_margin; 487 488 mem = vxres * vyres * ((bpp + 1) / 8); 489 if (mem > info->screen_size) { 490 dev_err(info->device, "not enough video memory (%d KB requested, %ld KB available)\n", 491 mem >> 10, info->screen_size >> 10); 492 return -ENOMEM; 493 } 494 495 if (yoffset + yres > vyres) 496 yoffset = vyres - yres; 497 498 xtotal = xres + right + hslen + left; 499 ytotal = yres + lower + vslen + upper; 500 501 par->crtc[VGA_CRTC_H_TOTAL] = (xtotal >> 3) - 5; 502 par->crtc[VGA_CRTC_H_DISP] = (xres >> 3) - 1; 503 par->crtc[VGA_CRTC_H_BLANK_START] = ((xres + right) >> 3) - 1; 504 par->crtc[VGA_CRTC_H_SYNC_START] = (xres + right) >> 3; 505 par->crtc[VGA_CRTC_H_SYNC_END] = (((xres + right + hslen) >> 3) & 0x1F) 506 | ((((xres + right + hslen) >> 3) & 0x20) << 2); 507 par->crtc[VGA_CRTC_H_BLANK_END] = ((xres + right + hslen) >> 3 & 0x1F) 508 | 0x80; 509 510 par->crtc[VGA_CRTC_V_TOTAL] = ytotal - 2; 511 512 r7 = 0x10; /* disable linecompare */ 513 if (ytotal & 0x100) 514 r7 |= 0x01; 515 if (ytotal & 0x200) 516 r7 |= 0x20; 517 518 par->crtc[VGA_CRTC_PRESET_ROW] = 0; 519 par->crtc[VGA_CRTC_MAX_SCAN] = 0x40; /* 1 scanline, no linecmp */ 520 if (var->vmode & FB_VMODE_DOUBLE) 521 par->crtc[VGA_CRTC_MAX_SCAN] |= 0x80; 522 par->crtc[VGA_CRTC_CURSOR_START] = 0x00; 523 par->crtc[VGA_CRTC_CURSOR_END] = 0x00; 524 par->crtc[VGA_CRTC_CURSOR_HI] = 0x00; 525 par->crtc[VGA_CRTC_CURSOR_LO] = 0x00; 526 par->crtc[VGA_CRTC_V_DISP_END] = yres-1; 527 if ((yres-1) & 0x100) 528 r7 |= 0x02; 529 if ((yres-1) & 0x200) 530 r7 |= 0x40; 531 532 par->crtc[VGA_CRTC_V_BLANK_START] = yres + lower - 1; 533 par->crtc[VGA_CRTC_V_SYNC_START] = yres + lower - 1; 534 if ((yres + lower - 1) & 0x100) 535 r7 |= 0x0C; 536 if ((yres + lower - 1) & 0x200) { 537 par->crtc[VGA_CRTC_MAX_SCAN] |= 0x20; 538 r7 |= 0x80; 539 } 540 541 /* disabled IRQ */ 542 par->crtc[VGA_CRTC_V_SYNC_END] = 543 ((yres + lower - 1 + vslen) & 0x0F) & ~0x10; 544 /* 0x7F for VGA, but some SVGA chips require all 8 bits to be set */ 545 par->crtc[VGA_CRTC_V_BLANK_END] = (yres + lower - 1 + vslen) & 0xFF; 546 547 par->crtc[VGA_CRTC_UNDERLINE] = 0x00; 548 par->crtc[VGA_CRTC_MODE] = 0xC3 ; 549 par->crtc[VGA_CRTC_LINE_COMPARE] = 0xFF; 550 par->crtc[VGA_CRTC_OVERFLOW] = r7; 551 552 par->vss = 0x00; /* 3DA */ 553 554 for (i = 0x00; i < 0x10; i++) 555 par->atc[i] = i; 556 par->atc[VGA_ATC_MODE] = 0x81; 557 par->atc[VGA_ATC_OVERSCAN] = 0x00; /* 0 for EGA, 0xFF for VGA */ 558 par->atc[VGA_ATC_PLANE_ENABLE] = 0x0F; 559 par->atc[VGA_ATC_COLOR_PAGE] = 0x00; 560 561 par->misc = 0xC3; 562 if (var->sync & FB_SYNC_HOR_HIGH_ACT) 563 par->misc &= ~0x40; 564 if (var->sync & FB_SYNC_VERT_HIGH_ACT) 565 par->misc &= ~0x80; 566 567 par->seq[VGA_SEQ_CLOCK_MODE] = 0x01; 568 par->seq[VGA_SEQ_PLANE_WRITE] = 0x0F; 569 par->seq[VGA_SEQ_CHARACTER_MAP] = 0x00; 570 par->seq[VGA_SEQ_MEMORY_MODE] = 0x06; 571 572 par->gdc[VGA_GFX_SR_VALUE] = 0x00; 573 par->gdc[VGA_GFX_SR_ENABLE] = 0x00; 574 par->gdc[VGA_GFX_COMPARE_VALUE] = 0x00; 575 par->gdc[VGA_GFX_DATA_ROTATE] = 0x00; 576 par->gdc[VGA_GFX_PLANE_READ] = 0; 577 par->gdc[VGA_GFX_MODE] = 0x02; 578 par->gdc[VGA_GFX_MISC] = 0x05; 579 par->gdc[VGA_GFX_COMPARE_MASK] = 0x0F; 580 par->gdc[VGA_GFX_BIT_MASK] = 0xFF; 581 582 base = (yoffset * vxres + (xoffset & ~7)) >> 2; 583 switch (bpp) { 584 case 8: 585 par->crtc[VGA_CRTC_OFFSET] = vxres >> 3; 586 par->ext_offset = vxres >> 11; 587 par->pixelpipe_cfg1 = DISPLAY_8BPP_MODE; 588 par->bitblt_cntl = COLEXP_8BPP; 589 break; 590 case 15: /* 0rrrrrgg gggbbbbb */ 591 case 16: /* rrrrrggg gggbbbbb */ 592 par->pixelpipe_cfg1 = (var->green.length == 6) ? 593 DISPLAY_16BPP_MODE : DISPLAY_15BPP_MODE; 594 par->crtc[VGA_CRTC_OFFSET] = vxres >> 2; 595 par->ext_offset = vxres >> 10; 596 par->bitblt_cntl = COLEXP_16BPP; 597 base *= 2; 598 break; 599 case 24: 600 par->crtc[VGA_CRTC_OFFSET] = (vxres * 3) >> 3; 601 par->ext_offset = (vxres * 3) >> 11; 602 par->pixelpipe_cfg1 = DISPLAY_24BPP_MODE; 603 par->bitblt_cntl = COLEXP_24BPP; 604 base &= 0xFFFFFFFE; /* ...ignore the last bit. */ 605 base *= 3; 606 break; 607 case 32: 608 par->crtc[VGA_CRTC_OFFSET] = vxres >> 1; 609 par->ext_offset = vxres >> 9; 610 par->pixelpipe_cfg1 = DISPLAY_32BPP_MODE; 611 par->bitblt_cntl = COLEXP_RESERVED; /* Unimplemented on i740 */ 612 base *= 4; 613 break; 614 } 615 616 par->crtc[VGA_CRTC_START_LO] = base & 0x000000FF; 617 par->crtc[VGA_CRTC_START_HI] = (base & 0x0000FF00) >> 8; 618 par->ext_start_addr = 619 ((base & 0x003F0000) >> 16) | EXT_START_ADDR_ENABLE; 620 par->ext_start_addr_hi = (base & 0x3FC00000) >> 22; 621 622 par->pixelpipe_cfg0 = DAC_8_BIT; 623 624 par->pixelpipe_cfg2 = DISPLAY_GAMMA_ENABLE | OVERLAY_GAMMA_ENABLE; 625 par->io_cntl = EXTENDED_CRTC_CNTL; 626 par->address_mapping = LINEAR_MODE_ENABLE | PAGE_MAPPING_ENABLE; 627 par->display_cntl = HIRES_MODE; 628 629 /* Set the MCLK freq */ 630 par->pll_cntl = PLL_MEMCLK_100000KHZ; /* 100 MHz -- use as default */ 631 632 /* Calculate the extended CRTC regs */ 633 par->ext_vert_total = (ytotal - 2) >> 8; 634 par->ext_vert_disp_end = (yres - 1) >> 8; 635 par->ext_vert_sync_start = (yres + lower) >> 8; 636 par->ext_vert_blank_start = (yres + lower) >> 8; 637 par->ext_horiz_total = ((xtotal >> 3) - 5) >> 8; 638 par->ext_horiz_blank = (((xres + right) >> 3) & 0x40) >> 6; 639 640 par->interlace_cntl = INTERLACE_DISABLE; 641 642 /* Set the overscan color to 0. (NOTE: This only affects >8bpp mode) */ 643 par->atc[VGA_ATC_OVERSCAN] = 0; 644 645 /* Calculate VCLK that most closely matches the requested dot clock */ 646 freq = (((u32)1e9) / var->pixclock) * (u32)(1e3); 647 if (freq < I740_RFREQ_FIX) { 648 fb_dbg(info, "invalid pixclock\n"); 649 freq = I740_RFREQ_FIX; 650 } 651 i740_calc_vclk(freq, par); 652 653 /* Since we program the clocks ourselves, always use VCLK2. */ 654 par->misc |= 0x0C; 655 656 /* Calculate the FIFO Watermark and Burst Length. */ 657 par->lmi_fifo_watermark = 658 i740_calc_fifo(par, 1000000 / var->pixclock, bpp); 659 660 return 0; 661 } 662 663 static int i740fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 664 { 665 switch (var->bits_per_pixel) { 666 case 8: 667 var->red.offset = var->green.offset = var->blue.offset = 0; 668 var->red.length = var->green.length = var->blue.length = 8; 669 break; 670 case 16: 671 switch (var->green.length) { 672 default: 673 case 5: 674 var->red.offset = 10; 675 var->green.offset = 5; 676 var->blue.offset = 0; 677 var->red.length = 5; 678 var->green.length = 5; 679 var->blue.length = 5; 680 break; 681 case 6: 682 var->red.offset = 11; 683 var->green.offset = 5; 684 var->blue.offset = 0; 685 var->red.length = var->blue.length = 5; 686 break; 687 } 688 break; 689 case 24: 690 var->red.offset = 16; 691 var->green.offset = 8; 692 var->blue.offset = 0; 693 var->red.length = var->green.length = var->blue.length = 8; 694 break; 695 case 32: 696 var->transp.offset = 24; 697 var->red.offset = 16; 698 var->green.offset = 8; 699 var->blue.offset = 0; 700 var->transp.length = 8; 701 var->red.length = var->green.length = var->blue.length = 8; 702 break; 703 default: 704 return -EINVAL; 705 } 706 707 if (var->xres > var->xres_virtual) 708 var->xres_virtual = var->xres; 709 710 if (var->yres > var->yres_virtual) 711 var->yres_virtual = var->yres; 712 713 if (info->monspecs.hfmax && info->monspecs.vfmax && 714 info->monspecs.dclkmax && fb_validate_mode(var, info) < 0) 715 return -EINVAL; 716 717 return 0; 718 } 719 720 static void vga_protect(struct i740fb_par *par) 721 { 722 /* disable the display */ 723 i740outreg_mask(par, VGA_SEQ_I, VGA_SEQ_CLOCK_MODE, 0x20, 0x20); 724 725 i740inb(par, 0x3DA); 726 i740outb(par, VGA_ATT_W, 0x00); /* enable palette access */ 727 } 728 729 static void vga_unprotect(struct i740fb_par *par) 730 { 731 /* reenable display */ 732 i740outreg_mask(par, VGA_SEQ_I, VGA_SEQ_CLOCK_MODE, 0, 0x20); 733 734 i740inb(par, 0x3DA); 735 i740outb(par, VGA_ATT_W, 0x20); /* disable palette access */ 736 } 737 738 static int i740fb_set_par(struct fb_info *info) 739 { 740 struct i740fb_par *par = info->par; 741 u32 itemp; 742 int i; 743 744 i = i740fb_decode_var(&info->var, par, info); 745 if (i) 746 return i; 747 748 memset(info->screen_base, 0, info->screen_size); 749 750 vga_protect(par); 751 752 i740outreg(par, XRX, DRAM_EXT_CNTL, DRAM_REFRESH_DISABLE); 753 754 mdelay(1); 755 756 i740outreg(par, XRX, VCLK2_VCO_M, par->video_clk2_m); 757 i740outreg(par, XRX, VCLK2_VCO_N, par->video_clk2_n); 758 i740outreg(par, XRX, VCLK2_VCO_MN_MSBS, par->video_clk2_mn_msbs); 759 i740outreg(par, XRX, VCLK2_VCO_DIV_SEL, par->video_clk2_div_sel); 760 761 i740outreg_mask(par, XRX, PIXPIPE_CONFIG_0, 762 par->pixelpipe_cfg0 & DAC_8_BIT, 0x80); 763 764 i740inb(par, 0x3DA); 765 i740outb(par, 0x3C0, 0x00); 766 767 /* update misc output register */ 768 i740outb(par, VGA_MIS_W, par->misc | 0x01); 769 770 /* synchronous reset on */ 771 i740outreg(par, VGA_SEQ_I, VGA_SEQ_RESET, 0x01); 772 /* write sequencer registers */ 773 i740outreg(par, VGA_SEQ_I, VGA_SEQ_CLOCK_MODE, 774 par->seq[VGA_SEQ_CLOCK_MODE] | 0x20); 775 for (i = 2; i < VGA_SEQ_C; i++) 776 i740outreg(par, VGA_SEQ_I, i, par->seq[i]); 777 778 /* synchronous reset off */ 779 i740outreg(par, VGA_SEQ_I, VGA_SEQ_RESET, 0x03); 780 781 /* deprotect CRT registers 0-7 */ 782 i740outreg(par, VGA_CRT_IC, VGA_CRTC_V_SYNC_END, 783 par->crtc[VGA_CRTC_V_SYNC_END]); 784 785 /* write CRT registers */ 786 for (i = 0; i < VGA_CRT_C; i++) 787 i740outreg(par, VGA_CRT_IC, i, par->crtc[i]); 788 789 /* write graphics controller registers */ 790 for (i = 0; i < VGA_GFX_C; i++) 791 i740outreg(par, VGA_GFX_I, i, par->gdc[i]); 792 793 /* write attribute controller registers */ 794 for (i = 0; i < VGA_ATT_C; i++) { 795 i740inb(par, VGA_IS1_RC); /* reset flip-flop */ 796 i740outb(par, VGA_ATT_IW, i); 797 i740outb(par, VGA_ATT_IW, par->atc[i]); 798 } 799 800 i740inb(par, VGA_IS1_RC); 801 i740outb(par, VGA_ATT_IW, 0x20); 802 803 i740outreg(par, VGA_CRT_IC, EXT_VERT_TOTAL, par->ext_vert_total); 804 i740outreg(par, VGA_CRT_IC, EXT_VERT_DISPLAY, par->ext_vert_disp_end); 805 i740outreg(par, VGA_CRT_IC, EXT_VERT_SYNC_START, 806 par->ext_vert_sync_start); 807 i740outreg(par, VGA_CRT_IC, EXT_VERT_BLANK_START, 808 par->ext_vert_blank_start); 809 i740outreg(par, VGA_CRT_IC, EXT_HORIZ_TOTAL, par->ext_horiz_total); 810 i740outreg(par, VGA_CRT_IC, EXT_HORIZ_BLANK, par->ext_horiz_blank); 811 i740outreg(par, VGA_CRT_IC, EXT_OFFSET, par->ext_offset); 812 i740outreg(par, VGA_CRT_IC, EXT_START_ADDR_HI, par->ext_start_addr_hi); 813 i740outreg(par, VGA_CRT_IC, EXT_START_ADDR, par->ext_start_addr); 814 815 i740outreg_mask(par, VGA_CRT_IC, INTERLACE_CNTL, 816 par->interlace_cntl, INTERLACE_ENABLE); 817 i740outreg_mask(par, XRX, ADDRESS_MAPPING, par->address_mapping, 0x1F); 818 i740outreg_mask(par, XRX, BITBLT_CNTL, par->bitblt_cntl, COLEXP_MODE); 819 i740outreg_mask(par, XRX, DISPLAY_CNTL, 820 par->display_cntl, VGA_WRAP_MODE | GUI_MODE); 821 i740outreg_mask(par, XRX, PIXPIPE_CONFIG_0, par->pixelpipe_cfg0, 0x9B); 822 i740outreg_mask(par, XRX, PIXPIPE_CONFIG_2, par->pixelpipe_cfg2, 0x0C); 823 824 i740outreg(par, XRX, PLL_CNTL, par->pll_cntl); 825 826 i740outreg_mask(par, XRX, PIXPIPE_CONFIG_1, 827 par->pixelpipe_cfg1, DISPLAY_COLOR_MODE); 828 829 itemp = readl(par->regs + FWATER_BLC); 830 itemp &= ~(LMI_BURST_LENGTH | LMI_FIFO_WATERMARK); 831 itemp |= par->lmi_fifo_watermark; 832 writel(itemp, par->regs + FWATER_BLC); 833 834 i740outreg(par, XRX, DRAM_EXT_CNTL, DRAM_REFRESH_60HZ); 835 836 i740outreg_mask(par, MRX, COL_KEY_CNTL_1, 0, BLANK_DISP_OVERLAY); 837 i740outreg_mask(par, XRX, IO_CTNL, 838 par->io_cntl, EXTENDED_ATTR_CNTL | EXTENDED_CRTC_CNTL); 839 840 if (par->pixelpipe_cfg1 != DISPLAY_8BPP_MODE) { 841 i740outb(par, VGA_PEL_MSK, 0xFF); 842 i740outb(par, VGA_PEL_IW, 0x00); 843 for (i = 0; i < 256; i++) { 844 itemp = (par->pixelpipe_cfg0 & DAC_8_BIT) ? i : i >> 2; 845 i740outb(par, VGA_PEL_D, itemp); 846 i740outb(par, VGA_PEL_D, itemp); 847 i740outb(par, VGA_PEL_D, itemp); 848 } 849 } 850 851 /* Wait for screen to stabilize. */ 852 mdelay(50); 853 vga_unprotect(par); 854 855 info->fix.line_length = 856 info->var.xres_virtual * info->var.bits_per_pixel / 8; 857 if (info->var.bits_per_pixel == 8) 858 info->fix.visual = FB_VISUAL_PSEUDOCOLOR; 859 else 860 info->fix.visual = FB_VISUAL_TRUECOLOR; 861 862 return 0; 863 } 864 865 static int i740fb_setcolreg(unsigned regno, unsigned red, unsigned green, 866 unsigned blue, unsigned transp, 867 struct fb_info *info) 868 { 869 u32 r, g, b; 870 871 dev_dbg(info->device, "setcolreg: regno: %i, red=%d, green=%d, blue=%d, transp=%d, bpp=%d\n", 872 regno, red, green, blue, transp, info->var.bits_per_pixel); 873 874 switch (info->fix.visual) { 875 case FB_VISUAL_PSEUDOCOLOR: 876 if (regno >= 256) 877 return -EINVAL; 878 i740outb(info->par, VGA_PEL_IW, regno); 879 i740outb(info->par, VGA_PEL_D, red >> 8); 880 i740outb(info->par, VGA_PEL_D, green >> 8); 881 i740outb(info->par, VGA_PEL_D, blue >> 8); 882 break; 883 case FB_VISUAL_TRUECOLOR: 884 if (regno >= 16) 885 return -EINVAL; 886 r = (red >> (16 - info->var.red.length)) 887 << info->var.red.offset; 888 b = (blue >> (16 - info->var.blue.length)) 889 << info->var.blue.offset; 890 g = (green >> (16 - info->var.green.length)) 891 << info->var.green.offset; 892 ((u32 *) info->pseudo_palette)[regno] = r | g | b; 893 break; 894 default: 895 return -EINVAL; 896 } 897 898 return 0; 899 } 900 901 static int i740fb_pan_display(struct fb_var_screeninfo *var, 902 struct fb_info *info) 903 { 904 struct i740fb_par *par = info->par; 905 u32 base = (var->yoffset * info->var.xres_virtual 906 + (var->xoffset & ~7)) >> 2; 907 908 dev_dbg(info->device, "pan_display: xoffset: %i yoffset: %i base: %i\n", 909 var->xoffset, var->yoffset, base); 910 911 switch (info->var.bits_per_pixel) { 912 case 8: 913 break; 914 case 15: 915 case 16: 916 base *= 2; 917 break; 918 case 24: 919 /* 920 * The last bit does not seem to have any effect on the start 921 * address register in 24bpp mode, so... 922 */ 923 base &= 0xFFFFFFFE; /* ...ignore the last bit. */ 924 base *= 3; 925 break; 926 case 32: 927 base *= 4; 928 break; 929 } 930 931 par->crtc[VGA_CRTC_START_LO] = base & 0x000000FF; 932 par->crtc[VGA_CRTC_START_HI] = (base & 0x0000FF00) >> 8; 933 par->ext_start_addr_hi = (base & 0x3FC00000) >> 22; 934 par->ext_start_addr = 935 ((base & 0x003F0000) >> 16) | EXT_START_ADDR_ENABLE; 936 937 i740outreg(par, VGA_CRT_IC, VGA_CRTC_START_LO, base & 0x000000FF); 938 i740outreg(par, VGA_CRT_IC, VGA_CRTC_START_HI, 939 (base & 0x0000FF00) >> 8); 940 i740outreg(par, VGA_CRT_IC, EXT_START_ADDR_HI, 941 (base & 0x3FC00000) >> 22); 942 i740outreg(par, VGA_CRT_IC, EXT_START_ADDR, 943 ((base & 0x003F0000) >> 16) | EXT_START_ADDR_ENABLE); 944 945 return 0; 946 } 947 948 static int i740fb_blank(int blank_mode, struct fb_info *info) 949 { 950 struct i740fb_par *par = info->par; 951 952 unsigned char SEQ01; 953 int DPMSSyncSelect; 954 955 switch (blank_mode) { 956 case FB_BLANK_UNBLANK: 957 case FB_BLANK_NORMAL: 958 SEQ01 = 0x00; 959 DPMSSyncSelect = HSYNC_ON | VSYNC_ON; 960 break; 961 case FB_BLANK_VSYNC_SUSPEND: 962 SEQ01 = 0x20; 963 DPMSSyncSelect = HSYNC_ON | VSYNC_OFF; 964 break; 965 case FB_BLANK_HSYNC_SUSPEND: 966 SEQ01 = 0x20; 967 DPMSSyncSelect = HSYNC_OFF | VSYNC_ON; 968 break; 969 case FB_BLANK_POWERDOWN: 970 SEQ01 = 0x20; 971 DPMSSyncSelect = HSYNC_OFF | VSYNC_OFF; 972 break; 973 default: 974 return -EINVAL; 975 } 976 /* Turn the screen on/off */ 977 i740outb(par, SRX, 0x01); 978 SEQ01 |= i740inb(par, SRX + 1) & ~0x20; 979 i740outb(par, SRX, 0x01); 980 i740outb(par, SRX + 1, SEQ01); 981 982 /* Set the DPMS mode */ 983 i740outreg(par, XRX, DPMS_SYNC_SELECT, DPMSSyncSelect); 984 985 /* Let fbcon do a soft blank for us */ 986 return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0; 987 } 988 989 static const struct fb_ops i740fb_ops = { 990 .owner = THIS_MODULE, 991 .fb_open = i740fb_open, 992 .fb_release = i740fb_release, 993 .fb_check_var = i740fb_check_var, 994 .fb_set_par = i740fb_set_par, 995 .fb_setcolreg = i740fb_setcolreg, 996 .fb_blank = i740fb_blank, 997 .fb_pan_display = i740fb_pan_display, 998 .fb_fillrect = cfb_fillrect, 999 .fb_copyarea = cfb_copyarea, 1000 .fb_imageblit = cfb_imageblit, 1001 }; 1002 1003 /* ------------------------------------------------------------------------- */ 1004 1005 static int i740fb_probe(struct pci_dev *dev, const struct pci_device_id *ent) 1006 { 1007 struct fb_info *info; 1008 struct i740fb_par *par; 1009 int ret, tmp; 1010 bool found = false; 1011 u8 *edid; 1012 1013 info = framebuffer_alloc(sizeof(struct i740fb_par), &(dev->dev)); 1014 if (!info) 1015 return -ENOMEM; 1016 1017 par = info->par; 1018 mutex_init(&par->open_lock); 1019 1020 info->var.activate = FB_ACTIVATE_NOW; 1021 info->var.bits_per_pixel = 8; 1022 info->fbops = &i740fb_ops; 1023 info->pseudo_palette = par->pseudo_palette; 1024 1025 ret = pci_enable_device(dev); 1026 if (ret) { 1027 dev_err(info->device, "cannot enable PCI device\n"); 1028 goto err_enable_device; 1029 } 1030 1031 ret = pci_request_regions(dev, info->fix.id); 1032 if (ret) { 1033 dev_err(info->device, "error requesting regions\n"); 1034 goto err_request_regions; 1035 } 1036 1037 info->screen_base = pci_ioremap_wc_bar(dev, 0); 1038 if (!info->screen_base) { 1039 dev_err(info->device, "error remapping base\n"); 1040 ret = -ENOMEM; 1041 goto err_ioremap_1; 1042 } 1043 1044 par->regs = pci_ioremap_bar(dev, 1); 1045 if (!par->regs) { 1046 dev_err(info->device, "error remapping MMIO\n"); 1047 ret = -ENOMEM; 1048 goto err_ioremap_2; 1049 } 1050 1051 /* detect memory size */ 1052 if ((i740inreg(par, XRX, DRAM_ROW_TYPE) & DRAM_ROW_1) 1053 == DRAM_ROW_1_SDRAM) 1054 i740outb(par, XRX, DRAM_ROW_BNDRY_1); 1055 else 1056 i740outb(par, XRX, DRAM_ROW_BNDRY_0); 1057 info->screen_size = i740inb(par, XRX + 1) * 1024 * 1024; 1058 /* detect memory type */ 1059 tmp = i740inreg(par, XRX, DRAM_ROW_CNTL_LO); 1060 par->has_sgram = !((tmp & DRAM_RAS_TIMING) || 1061 (tmp & DRAM_RAS_PRECHARGE)); 1062 1063 fb_info(info, "Intel740 on %s, %ld KB %s\n", 1064 pci_name(dev), info->screen_size >> 10, 1065 par->has_sgram ? "SGRAM" : "SDRAM"); 1066 1067 info->fix = i740fb_fix; 1068 info->fix.mmio_start = pci_resource_start(dev, 1); 1069 info->fix.mmio_len = pci_resource_len(dev, 1); 1070 info->fix.smem_start = pci_resource_start(dev, 0); 1071 info->fix.smem_len = info->screen_size; 1072 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; 1073 1074 if (i740fb_setup_ddc_bus(info) == 0) { 1075 par->ddc_registered = true; 1076 edid = fb_ddc_read(&par->ddc_adapter); 1077 if (edid) { 1078 fb_edid_to_monspecs(edid, &info->monspecs); 1079 kfree(edid); 1080 if (!info->monspecs.modedb) 1081 dev_err(info->device, 1082 "error getting mode database\n"); 1083 else { 1084 const struct fb_videomode *m; 1085 1086 fb_videomode_to_modelist( 1087 info->monspecs.modedb, 1088 info->monspecs.modedb_len, 1089 &info->modelist); 1090 m = fb_find_best_display(&info->monspecs, 1091 &info->modelist); 1092 if (m) { 1093 fb_videomode_to_var(&info->var, m); 1094 /* fill all other info->var's fields */ 1095 if (!i740fb_check_var(&info->var, info)) 1096 found = true; 1097 } 1098 } 1099 } 1100 } 1101 1102 if (!mode_option && !found) 1103 mode_option = "640x480-8@60"; 1104 1105 if (mode_option) { 1106 ret = fb_find_mode(&info->var, info, mode_option, 1107 info->monspecs.modedb, 1108 info->monspecs.modedb_len, 1109 NULL, info->var.bits_per_pixel); 1110 if (!ret || ret == 4) { 1111 dev_err(info->device, "mode %s not found\n", 1112 mode_option); 1113 ret = -EINVAL; 1114 } 1115 } 1116 1117 fb_destroy_modedb(info->monspecs.modedb); 1118 info->monspecs.modedb = NULL; 1119 1120 /* maximize virtual vertical size for fast scrolling */ 1121 info->var.yres_virtual = info->fix.smem_len * 8 / 1122 (info->var.bits_per_pixel * info->var.xres_virtual); 1123 1124 if (ret == -EINVAL) 1125 goto err_find_mode; 1126 1127 ret = fb_alloc_cmap(&info->cmap, 256, 0); 1128 if (ret) { 1129 dev_err(info->device, "cannot allocate colormap\n"); 1130 goto err_alloc_cmap; 1131 } 1132 1133 ret = register_framebuffer(info); 1134 if (ret) { 1135 dev_err(info->device, "error registering framebuffer\n"); 1136 goto err_reg_framebuffer; 1137 } 1138 1139 fb_info(info, "%s frame buffer device\n", info->fix.id); 1140 pci_set_drvdata(dev, info); 1141 if (mtrr) 1142 par->wc_cookie = arch_phys_wc_add(info->fix.smem_start, 1143 info->fix.smem_len); 1144 return 0; 1145 1146 err_reg_framebuffer: 1147 fb_dealloc_cmap(&info->cmap); 1148 err_alloc_cmap: 1149 err_find_mode: 1150 if (par->ddc_registered) 1151 i2c_del_adapter(&par->ddc_adapter); 1152 pci_iounmap(dev, par->regs); 1153 err_ioremap_2: 1154 pci_iounmap(dev, info->screen_base); 1155 err_ioremap_1: 1156 pci_release_regions(dev); 1157 err_request_regions: 1158 /* pci_disable_device(dev); */ 1159 err_enable_device: 1160 framebuffer_release(info); 1161 return ret; 1162 } 1163 1164 static void i740fb_remove(struct pci_dev *dev) 1165 { 1166 struct fb_info *info = pci_get_drvdata(dev); 1167 1168 if (info) { 1169 struct i740fb_par *par = info->par; 1170 arch_phys_wc_del(par->wc_cookie); 1171 unregister_framebuffer(info); 1172 fb_dealloc_cmap(&info->cmap); 1173 if (par->ddc_registered) 1174 i2c_del_adapter(&par->ddc_adapter); 1175 pci_iounmap(dev, par->regs); 1176 pci_iounmap(dev, info->screen_base); 1177 pci_release_regions(dev); 1178 /* pci_disable_device(dev); */ 1179 framebuffer_release(info); 1180 } 1181 } 1182 1183 static int __maybe_unused i740fb_suspend(struct device *dev) 1184 { 1185 struct fb_info *info = dev_get_drvdata(dev); 1186 struct i740fb_par *par = info->par; 1187 1188 console_lock(); 1189 mutex_lock(&(par->open_lock)); 1190 1191 /* do nothing if framebuffer is not active */ 1192 if (par->ref_count == 0) { 1193 mutex_unlock(&(par->open_lock)); 1194 console_unlock(); 1195 return 0; 1196 } 1197 1198 fb_set_suspend(info, 1); 1199 1200 mutex_unlock(&(par->open_lock)); 1201 console_unlock(); 1202 1203 return 0; 1204 } 1205 1206 static int __maybe_unused i740fb_resume(struct device *dev) 1207 { 1208 struct fb_info *info = dev_get_drvdata(dev); 1209 struct i740fb_par *par = info->par; 1210 1211 console_lock(); 1212 mutex_lock(&(par->open_lock)); 1213 1214 if (par->ref_count == 0) 1215 goto fail; 1216 1217 i740fb_set_par(info); 1218 fb_set_suspend(info, 0); 1219 1220 fail: 1221 mutex_unlock(&(par->open_lock)); 1222 console_unlock(); 1223 return 0; 1224 } 1225 1226 static const struct dev_pm_ops i740fb_pm_ops = { 1227 #ifdef CONFIG_PM_SLEEP 1228 .suspend = i740fb_suspend, 1229 .resume = i740fb_resume, 1230 .freeze = NULL, 1231 .thaw = i740fb_resume, 1232 .poweroff = i740fb_suspend, 1233 .restore = i740fb_resume, 1234 #endif /* CONFIG_PM_SLEEP */ 1235 }; 1236 1237 #define I740_ID_PCI 0x00d1 1238 #define I740_ID_AGP 0x7800 1239 1240 static const struct pci_device_id i740fb_id_table[] = { 1241 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, I740_ID_PCI) }, 1242 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, I740_ID_AGP) }, 1243 { 0 } 1244 }; 1245 MODULE_DEVICE_TABLE(pci, i740fb_id_table); 1246 1247 static struct pci_driver i740fb_driver = { 1248 .name = "i740fb", 1249 .id_table = i740fb_id_table, 1250 .probe = i740fb_probe, 1251 .remove = i740fb_remove, 1252 .driver.pm = &i740fb_pm_ops, 1253 }; 1254 1255 #ifndef MODULE 1256 static int __init i740fb_setup(char *options) 1257 { 1258 char *opt; 1259 1260 if (!options || !*options) 1261 return 0; 1262 1263 while ((opt = strsep(&options, ",")) != NULL) { 1264 if (!*opt) 1265 continue; 1266 else if (!strncmp(opt, "mtrr:", 5)) 1267 mtrr = simple_strtoul(opt + 5, NULL, 0); 1268 else 1269 mode_option = opt; 1270 } 1271 1272 return 0; 1273 } 1274 #endif 1275 1276 static int __init i740fb_init(void) 1277 { 1278 #ifndef MODULE 1279 char *option = NULL; 1280 1281 if (fb_get_options("i740fb", &option)) 1282 return -ENODEV; 1283 i740fb_setup(option); 1284 #endif 1285 1286 return pci_register_driver(&i740fb_driver); 1287 } 1288 1289 static void __exit i740fb_exit(void) 1290 { 1291 pci_unregister_driver(&i740fb_driver); 1292 } 1293 1294 module_init(i740fb_init); 1295 module_exit(i740fb_exit); 1296 1297 MODULE_AUTHOR("(c) 2011 Ondrej Zary <linux@rainbow-software.org>"); 1298 MODULE_LICENSE("GPL"); 1299 MODULE_DESCRIPTION("fbdev driver for Intel740"); 1300 1301 module_param(mode_option, charp, 0444); 1302 MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)"); 1303 1304 module_param(mtrr, int, 0444); 1305 MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)"); 1306