2 * linux/drivers/video/i810_main.c -- Intel 810 frame buffer device
4 * Copyright (C) 2001 Antonino Daplas<adaplas@pol.net>
8 * Michael Vogt <mvogt@acm.org> - added support for Intel 815 chipsets
9 * and enabling the power-on state of
10 * external VGA connectors for
13 * Fredrik Andersson <krueger@shell.linux.se> - alpha testing of
16 * Brad Corrion <bcorrion@web-co.com> - alpha testing of customized
19 * The code framework is a modification of vfb.c by Geert Uytterhoeven.
20 * DotClock and PLL calculations are partly based on i810_driver.c
21 * in xfree86 v4.0.3 by Precision Insight.
22 * Watermark calculation and tables are based on i810_wmark.c
23 * in xfre86 v4.0.3 by Precision Insight. Slight modifications
24 * only to allow for integer operations instead of floating point.
26 * This file is subject to the terms and conditions of the GNU General Public
27 * License. See the file COPYING in the main directory of this archive for
31 #include <linux/module.h>
32 #include <linux/config.h>
33 #include <linux/kernel.h>
34 #include <linux/errno.h>
35 #include <linux/string.h>
37 #include <linux/tty.h>
38 #include <linux/slab.h>
40 #include <linux/init.h>
41 #include <linux/pci.h>
42 #include <linux/pci_ids.h>
43 #include <linux/resource.h>
44 #include <linux/unistd.h>
45 #include <linux/console.h>
48 #include <asm/div64.h>
51 #include "i810_regs.h"
53 #include "i810_main.h"
56 * voffset - framebuffer offset in MiB from aperture start address. In order for
57 * the driver to work with X, we must try to use memory holes left untouched by X. The
58 * following table lists where X's different surfaces start at.
60 * ---------------------------------------------
61 * : : 64 MiB : 32 MiB :
62 * ----------------------------------------------
63 * : FrontBuffer : 0 : 0 :
64 * : DepthBuffer : 48 : 16 :
65 * : BackBuffer : 56 : 24 :
66 * ----------------------------------------------
68 * So for chipsets with 64 MiB Aperture sizes, 32 MiB for v_offset is okay, allowing up to
69 * 15 + 1 MiB of Framebuffer memory. For 32 MiB Aperture sizes, a v_offset of 8 MiB should
70 * work, allowing 7 + 1 MiB of Framebuffer memory.
71 * Note, the size of the hole may change depending on how much memory you allocate to X,
72 * and how the memory is split up between these surfaces.
74 * Note: Anytime the DepthBuffer or FrontBuffer is overlapped, X would still run but with
75 * DRI disabled. But if the Frontbuffer is overlapped, X will fail to load.
77 * Experiment with v_offset to find out which works best for you.
79 static u32 v_offset_default __devinitdata; /* For 32 MiB Aper size, 8 should be the default */
80 static u32 voffset __devinitdata;
82 static int i810fb_cursor(struct fb_info *info, struct fb_cursor *cursor);
83 static int __devinit i810fb_init_pci (struct pci_dev *dev,
84 const struct pci_device_id *entry);
85 static void __exit i810fb_remove_pci(struct pci_dev *dev);
86 static int i810fb_resume(struct pci_dev *dev);
87 static int i810fb_suspend(struct pci_dev *dev, pm_message_t state);
89 /* Chipset Specific Functions */
90 static int i810fb_set_par (struct fb_info *info);
91 static int i810fb_getcolreg (u8 regno, u8 *red, u8 *green, u8 *blue,
92 u8 *transp, struct fb_info *info);
93 static int i810fb_setcolreg (unsigned regno, unsigned red, unsigned green, unsigned blue,
94 unsigned transp, struct fb_info *info);
95 static int i810fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info);
96 static int i810fb_blank (int blank_mode, struct fb_info *info);
99 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
102 static const char *i810_pci_list[] __devinitdata = {
103 "Intel(R) 810 Framebuffer Device" ,
104 "Intel(R) 810-DC100 Framebuffer Device" ,
105 "Intel(R) 810E Framebuffer Device" ,
106 "Intel(R) 815 (Internal Graphics 100Mhz FSB) Framebuffer Device" ,
107 "Intel(R) 815 (Internal Graphics only) Framebuffer Device" ,
108 "Intel(R) 815 (Internal Graphics with AGP) Framebuffer Device"
111 static struct pci_device_id i810fb_pci_tbl[] = {
112 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG1,
113 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
114 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3,
115 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
116 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810E_IG,
117 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
118 /* mvo: added i815 PCI-ID */
119 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_100,
120 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
121 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_NOAGP,
122 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
123 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC,
124 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
128 static struct pci_driver i810fb_driver = {
130 .id_table = i810fb_pci_tbl,
131 .probe = i810fb_init_pci,
132 .remove = __exit_p(i810fb_remove_pci),
133 .suspend = i810fb_suspend,
134 .resume = i810fb_resume,
137 static char *mode_option __devinitdata = NULL;
138 static int vram __devinitdata = 4;
139 static int bpp __devinitdata = 8;
140 static int mtrr __devinitdata;
141 static int accel __devinitdata;
142 static int hsync1 __devinitdata;
143 static int hsync2 __devinitdata;
144 static int vsync1 __devinitdata;
145 static int vsync2 __devinitdata;
146 static int xres __devinitdata;
147 static int yres __devinitdata;
148 static int vyres __devinitdata;
149 static int sync __devinitdata;
150 static int extvga __devinitdata;
151 static int dcolor __devinitdata;
152 static int ddc3 __devinitdata = 2;
154 /*------------------------------------------------------------*/
156 /**************************************************************
157 * Hardware Low Level Routines *
158 **************************************************************/
161 * i810_screen_off - turns off/on display
162 * @mmio: address of register space
166 * Blanks/unblanks the display
168 static void i810_screen_off(u8 __iomem *mmio, u8 mode)
170 u32 count = WAIT_COUNT;
173 i810_writeb(SR_INDEX, mmio, SR01);
174 val = i810_readb(SR_DATA, mmio);
175 val = (mode == OFF) ? val | SCR_OFF :
178 while((i810_readw(DISP_SL, mmio) & 0xFFF) && count--);
179 i810_writeb(SR_INDEX, mmio, SR01);
180 i810_writeb(SR_DATA, mmio, val);
184 * i810_dram_off - turns off/on dram refresh
185 * @mmio: address of register space
189 * Turns off DRAM refresh. Must be off for only 2 vsyncs
190 * before data becomes corrupt
192 static void i810_dram_off(u8 __iomem *mmio, u8 mode)
196 val = i810_readb(DRAMCH, mmio);
198 val = (mode == OFF) ? val : val | DRAM_ON;
199 i810_writeb(DRAMCH, mmio, val);
203 * i810_protect_regs - allows rw/ro mode of certain VGA registers
204 * @mmio: address of register space
205 * @mode: protect/unprotect
208 * The IBM VGA standard allows protection of certain VGA registers.
209 * This will protect or unprotect them.
211 static void i810_protect_regs(u8 __iomem *mmio, int mode)
215 i810_writeb(CR_INDEX_CGA, mmio, CR11);
216 reg = i810_readb(CR_DATA_CGA, mmio);
217 reg = (mode == OFF) ? reg & ~0x80 :
220 i810_writeb(CR_INDEX_CGA, mmio, CR11);
221 i810_writeb(CR_DATA_CGA, mmio, reg);
225 * i810_load_pll - loads values for the hardware PLL clock
226 * @par: pointer to i810fb_par structure
229 * Loads the P, M, and N registers.
231 static void i810_load_pll(struct i810fb_par *par)
234 u8 __iomem *mmio = par->mmio_start_virtual;
236 tmp1 = par->regs.M | par->regs.N << 16;
237 tmp2 = i810_readl(DCLK_2D, mmio);
239 i810_writel(DCLK_2D, mmio, tmp1 | tmp2);
242 tmp2 = i810_readl(DCLK_0DS, mmio);
243 tmp2 &= ~(P_OR << 16);
244 i810_writel(DCLK_0DS, mmio, (tmp1 << 16) | tmp2);
246 i810_writeb(MSR_WRITE, mmio, par->regs.msr | 0xC8 | 1);
251 * i810_load_vga - load standard VGA registers
252 * @par: pointer to i810fb_par structure
255 * Load values to VGA registers
257 static void i810_load_vga(struct i810fb_par *par)
259 u8 __iomem *mmio = par->mmio_start_virtual;
262 i810_writeb(CR_INDEX_CGA, mmio, CR70);
263 i810_writeb(CR_DATA_CGA, mmio, par->interlace);
265 i810_writeb(CR_INDEX_CGA, mmio, CR00);
266 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr00);
267 i810_writeb(CR_INDEX_CGA, mmio, CR01);
268 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr01);
269 i810_writeb(CR_INDEX_CGA, mmio, CR02);
270 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr02);
271 i810_writeb(CR_INDEX_CGA, mmio, CR03);
272 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr03);
273 i810_writeb(CR_INDEX_CGA, mmio, CR04);
274 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr04);
275 i810_writeb(CR_INDEX_CGA, mmio, CR05);
276 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr05);
277 i810_writeb(CR_INDEX_CGA, mmio, CR06);
278 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr06);
279 i810_writeb(CR_INDEX_CGA, mmio, CR09);
280 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr09);
281 i810_writeb(CR_INDEX_CGA, mmio, CR10);
282 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr10);
283 i810_writeb(CR_INDEX_CGA, mmio, CR11);
284 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr11);
285 i810_writeb(CR_INDEX_CGA, mmio, CR12);
286 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr12);
287 i810_writeb(CR_INDEX_CGA, mmio, CR15);
288 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr15);
289 i810_writeb(CR_INDEX_CGA, mmio, CR16);
290 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr16);
294 * i810_load_vgax - load extended VGA registers
295 * @par: pointer to i810fb_par structure
298 * Load values to extended VGA registers
300 static void i810_load_vgax(struct i810fb_par *par)
302 u8 __iomem *mmio = par->mmio_start_virtual;
304 i810_writeb(CR_INDEX_CGA, mmio, CR30);
305 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr30);
306 i810_writeb(CR_INDEX_CGA, mmio, CR31);
307 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr31);
308 i810_writeb(CR_INDEX_CGA, mmio, CR32);
309 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr32);
310 i810_writeb(CR_INDEX_CGA, mmio, CR33);
311 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr33);
312 i810_writeb(CR_INDEX_CGA, mmio, CR35);
313 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr35);
314 i810_writeb(CR_INDEX_CGA, mmio, CR39);
315 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr39);
319 * i810_load_2d - load grahics registers
320 * @par: pointer to i810fb_par structure
323 * Load values to graphics registers
325 static void i810_load_2d(struct i810fb_par *par)
329 u8 __iomem *mmio = par->mmio_start_virtual;
331 i810_writel(FW_BLC, mmio, par->watermark);
332 tmp = i810_readl(PIXCONF, mmio);
334 i810_writel(PIXCONF, mmio, tmp);
336 i810_writel(OVRACT, mmio, par->ovract);
338 i810_writeb(GR_INDEX, mmio, GR10);
339 tmp8 = i810_readb(GR_DATA, mmio);
341 i810_writeb(GR_INDEX, mmio, GR10);
342 i810_writeb(GR_DATA, mmio, tmp8);
346 * i810_hires - enables high resolution mode
347 * @mmio: address of register space
349 static void i810_hires(u8 __iomem *mmio)
353 i810_writeb(CR_INDEX_CGA, mmio, CR80);
354 val = i810_readb(CR_DATA_CGA, mmio);
355 i810_writeb(CR_INDEX_CGA, mmio, CR80);
356 i810_writeb(CR_DATA_CGA, mmio, val | 1);
357 /* Stop LCD displays from flickering */
358 i810_writel(MEM_MODE, mmio, i810_readl(MEM_MODE, mmio) | 4);
362 * i810_load_pitch - loads the characters per line of the display
363 * @par: pointer to i810fb_par structure
366 * Loads the characters per line
368 static void i810_load_pitch(struct i810fb_par *par)
372 u8 __iomem *mmio = par->mmio_start_virtual;
374 pitch = par->pitch >> 3;
375 i810_writeb(SR_INDEX, mmio, SR01);
376 val = i810_readb(SR_DATA, mmio);
379 i810_writeb(SR_INDEX, mmio, SR01);
380 i810_writeb(SR_DATA, mmio, val);
383 i810_writeb(CR_INDEX_CGA, mmio, CR13);
384 i810_writeb(CR_DATA_CGA, mmio, (u8) tmp);
387 i810_writeb(CR_INDEX_CGA, mmio, CR41);
388 val = i810_readb(CR_DATA_CGA, mmio) & ~0x0F;
389 i810_writeb(CR_INDEX_CGA, mmio, CR41);
390 i810_writeb(CR_DATA_CGA, mmio, (u8) tmp | val);
394 * i810_load_color - loads the color depth of the display
395 * @par: pointer to i810fb_par structure
398 * Loads the color depth of the display and the graphics engine
400 static void i810_load_color(struct i810fb_par *par)
402 u8 __iomem *mmio = par->mmio_start_virtual;
406 reg1 = i810_readl(PIXCONF, mmio) & ~(0xF0000 | 1 << 27);
407 reg2 = i810_readw(BLTCNTL, mmio) & ~0x30;
409 reg1 |= 0x8000 | par->pixconf;
410 reg2 |= par->bltcntl;
411 i810_writel(PIXCONF, mmio, reg1);
412 i810_writew(BLTCNTL, mmio, reg2);
416 * i810_load_regs - loads all registers for the mode
417 * @par: pointer to i810fb_par structure
422 static void i810_load_regs(struct i810fb_par *par)
424 u8 __iomem *mmio = par->mmio_start_virtual;
426 i810_screen_off(mmio, OFF);
427 i810_protect_regs(mmio, OFF);
428 i810_dram_off(mmio, OFF);
432 i810_dram_off(mmio, ON);
435 i810_screen_off(mmio, ON);
436 i810_protect_regs(mmio, ON);
437 i810_load_color(par);
438 i810_load_pitch(par);
441 static void i810_write_dac(u8 regno, u8 red, u8 green, u8 blue,
444 i810_writeb(CLUT_INDEX_WRITE, mmio, regno);
445 i810_writeb(CLUT_DATA, mmio, red);
446 i810_writeb(CLUT_DATA, mmio, green);
447 i810_writeb(CLUT_DATA, mmio, blue);
450 static void i810_read_dac(u8 regno, u8 *red, u8 *green, u8 *blue,
453 i810_writeb(CLUT_INDEX_READ, mmio, regno);
454 *red = i810_readb(CLUT_DATA, mmio);
455 *green = i810_readb(CLUT_DATA, mmio);
456 *blue = i810_readb(CLUT_DATA, mmio);
459 /************************************************************
460 * VGA State Restore *
461 ************************************************************/
462 static void i810_restore_pll(struct i810fb_par *par)
465 u8 __iomem *mmio = par->mmio_start_virtual;
467 tmp1 = par->hw_state.dclk_2d;
468 tmp2 = i810_readl(DCLK_2D, mmio);
471 i810_writel(DCLK_2D, mmio, tmp1 | tmp2);
473 tmp1 = par->hw_state.dclk_1d;
474 tmp2 = i810_readl(DCLK_1D, mmio);
477 i810_writel(DCLK_1D, mmio, tmp1 | tmp2);
479 i810_writel(DCLK_0DS, mmio, par->hw_state.dclk_0ds);
482 static void i810_restore_dac(struct i810fb_par *par)
485 u8 __iomem *mmio = par->mmio_start_virtual;
487 tmp1 = par->hw_state.pixconf;
488 tmp2 = i810_readl(PIXCONF, mmio);
491 i810_writel(PIXCONF, mmio, tmp1 | tmp2);
494 static void i810_restore_vgax(struct i810fb_par *par)
497 u8 __iomem *mmio = par->mmio_start_virtual;
499 for (i = 0; i < 4; i++) {
500 i810_writeb(CR_INDEX_CGA, mmio, CR30+i);
501 i810_writeb(CR_DATA_CGA, mmio, *(&(par->hw_state.cr30) + i));
503 i810_writeb(CR_INDEX_CGA, mmio, CR35);
504 i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr35);
505 i810_writeb(CR_INDEX_CGA, mmio, CR39);
506 i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr39);
507 i810_writeb(CR_INDEX_CGA, mmio, CR41);
508 i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr39);
510 /*restore interlace*/
511 i810_writeb(CR_INDEX_CGA, mmio, CR70);
512 i = par->hw_state.cr70;
514 j = i810_readb(CR_DATA_CGA, mmio);
515 i810_writeb(CR_INDEX_CGA, mmio, CR70);
516 i810_writeb(CR_DATA_CGA, mmio, j | i);
518 i810_writeb(CR_INDEX_CGA, mmio, CR80);
519 i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr80);
520 i810_writeb(MSR_WRITE, mmio, par->hw_state.msr);
521 i810_writeb(SR_INDEX, mmio, SR01);
522 i = (par->hw_state.sr01) & ~0xE0 ;
523 j = i810_readb(SR_DATA, mmio) & 0xE0;
524 i810_writeb(SR_INDEX, mmio, SR01);
525 i810_writeb(SR_DATA, mmio, i | j);
528 static void i810_restore_vga(struct i810fb_par *par)
531 u8 __iomem *mmio = par->mmio_start_virtual;
533 for (i = 0; i < 10; i++) {
534 i810_writeb(CR_INDEX_CGA, mmio, CR00 + i);
535 i810_writeb(CR_DATA_CGA, mmio, *((&par->hw_state.cr00) + i));
537 for (i = 0; i < 8; i++) {
538 i810_writeb(CR_INDEX_CGA, mmio, CR10 + i);
539 i810_writeb(CR_DATA_CGA, mmio, *((&par->hw_state.cr10) + i));
543 static void i810_restore_addr_map(struct i810fb_par *par)
546 u8 __iomem *mmio = par->mmio_start_virtual;
548 i810_writeb(GR_INDEX, mmio, GR10);
549 tmp = i810_readb(GR_DATA, mmio);
550 tmp &= ADDR_MAP_MASK;
551 tmp |= par->hw_state.gr10;
552 i810_writeb(GR_INDEX, mmio, GR10);
553 i810_writeb(GR_DATA, mmio, tmp);
556 static void i810_restore_2d(struct i810fb_par *par)
560 u8 __iomem *mmio = par->mmio_start_virtual;
562 tmp_word = i810_readw(BLTCNTL, mmio);
563 tmp_word &= ~(3 << 4);
564 tmp_word |= par->hw_state.bltcntl;
565 i810_writew(BLTCNTL, mmio, tmp_word);
567 i810_dram_off(mmio, OFF);
568 i810_writel(PIXCONF, mmio, par->hw_state.pixconf);
569 i810_dram_off(mmio, ON);
571 tmp_word = i810_readw(HWSTAM, mmio);
573 tmp_word |= par->hw_state.hwstam;
574 i810_writew(HWSTAM, mmio, tmp_word);
576 tmp_long = i810_readl(FW_BLC, mmio);
577 tmp_long &= FW_BLC_MASK;
578 tmp_long |= par->hw_state.fw_blc;
579 i810_writel(FW_BLC, mmio, tmp_long);
581 i810_writel(HWS_PGA, mmio, par->hw_state.hws_pga);
582 i810_writew(IER, mmio, par->hw_state.ier);
583 i810_writew(IMR, mmio, par->hw_state.imr);
584 i810_writel(DPLYSTAS, mmio, par->hw_state.dplystas);
587 static void i810_restore_vga_state(struct i810fb_par *par)
589 u8 __iomem *mmio = par->mmio_start_virtual;
591 i810_screen_off(mmio, OFF);
592 i810_protect_regs(mmio, OFF);
593 i810_dram_off(mmio, OFF);
594 i810_restore_pll(par);
595 i810_restore_dac(par);
596 i810_restore_vga(par);
597 i810_restore_vgax(par);
598 i810_restore_addr_map(par);
599 i810_dram_off(mmio, ON);
600 i810_restore_2d(par);
601 i810_screen_off(mmio, ON);
602 i810_protect_regs(mmio, ON);
605 /***********************************************************************
607 ***********************************************************************/
609 static void i810_save_vgax(struct i810fb_par *par)
612 u8 __iomem *mmio = par->mmio_start_virtual;
614 for (i = 0; i < 4; i++) {
615 i810_writeb(CR_INDEX_CGA, mmio, CR30 + i);
616 *(&(par->hw_state.cr30) + i) = i810_readb(CR_DATA_CGA, mmio);
618 i810_writeb(CR_INDEX_CGA, mmio, CR35);
619 par->hw_state.cr35 = i810_readb(CR_DATA_CGA, mmio);
620 i810_writeb(CR_INDEX_CGA, mmio, CR39);
621 par->hw_state.cr39 = i810_readb(CR_DATA_CGA, mmio);
622 i810_writeb(CR_INDEX_CGA, mmio, CR41);
623 par->hw_state.cr41 = i810_readb(CR_DATA_CGA, mmio);
624 i810_writeb(CR_INDEX_CGA, mmio, CR70);
625 par->hw_state.cr70 = i810_readb(CR_DATA_CGA, mmio);
626 par->hw_state.msr = i810_readb(MSR_READ, mmio);
627 i810_writeb(CR_INDEX_CGA, mmio, CR80);
628 par->hw_state.cr80 = i810_readb(CR_DATA_CGA, mmio);
629 i810_writeb(SR_INDEX, mmio, SR01);
630 par->hw_state.sr01 = i810_readb(SR_DATA, mmio);
633 static void i810_save_vga(struct i810fb_par *par)
636 u8 __iomem *mmio = par->mmio_start_virtual;
638 for (i = 0; i < 10; i++) {
639 i810_writeb(CR_INDEX_CGA, mmio, CR00 + i);
640 *((&par->hw_state.cr00) + i) = i810_readb(CR_DATA_CGA, mmio);
642 for (i = 0; i < 8; i++) {
643 i810_writeb(CR_INDEX_CGA, mmio, CR10 + i);
644 *((&par->hw_state.cr10) + i) = i810_readb(CR_DATA_CGA, mmio);
648 static void i810_save_2d(struct i810fb_par *par)
650 u8 __iomem *mmio = par->mmio_start_virtual;
652 par->hw_state.dclk_2d = i810_readl(DCLK_2D, mmio);
653 par->hw_state.dclk_1d = i810_readl(DCLK_1D, mmio);
654 par->hw_state.dclk_0ds = i810_readl(DCLK_0DS, mmio);
655 par->hw_state.pixconf = i810_readl(PIXCONF, mmio);
656 par->hw_state.fw_blc = i810_readl(FW_BLC, mmio);
657 par->hw_state.bltcntl = i810_readw(BLTCNTL, mmio);
658 par->hw_state.hwstam = i810_readw(HWSTAM, mmio);
659 par->hw_state.hws_pga = i810_readl(HWS_PGA, mmio);
660 par->hw_state.ier = i810_readw(IER, mmio);
661 par->hw_state.imr = i810_readw(IMR, mmio);
662 par->hw_state.dplystas = i810_readl(DPLYSTAS, mmio);
665 static void i810_save_vga_state(struct i810fb_par *par)
672 /************************************************************
674 ************************************************************/
676 * get_line_length - calculates buffer pitch in bytes
677 * @par: pointer to i810fb_par structure
678 * @xres_virtual: virtual resolution of the frame
679 * @bpp: bits per pixel
682 * Calculates buffer pitch in bytes.
684 static u32 get_line_length(struct i810fb_par *par, int xres_virtual, int bpp)
688 length = xres_virtual*bpp;
689 length = (length+31)&-32;
695 * i810_calc_dclk - calculates the P, M, and N values of a pixelclock value
696 * @freq: target pixelclock in picoseconds
697 * @m: where to write M register
698 * @n: where to write N register
699 * @p: where to write P register
702 * Based on the formula Freq_actual = (4*M*Freq_ref)/(N^P)
703 * Repeatedly computes the Freq until the actual Freq is equal to
704 * the target Freq or until the loop count is zero. In the latter
705 * case, the actual frequency nearest the target will be used.
707 static void i810_calc_dclk(u32 freq, u32 *m, u32 *n, u32 *p)
709 u32 m_reg, n_reg, p_divisor, n_target_max;
710 u32 m_target, n_target, p_target, n_best, m_best, mod;
711 u32 f_out, target_freq, diff = 0, mod_min, diff_min;
713 diff_min = mod_min = 0xFFFFFFFF;
714 n_best = m_best = m_target = f_out = 0;
720 * find P such that target freq is 16x reference freq (Hz).
724 while(!((1000000 * p_divisor)/(16 * 24 * target_freq)) &&
730 n_reg = m_reg = n_target = 3;
731 while (diff_min && mod_min && (n_target < n_target_max)) {
732 f_out = (p_divisor * n_reg * 1000000)/(4 * 24 * m_reg);
733 mod = (p_divisor * n_reg * 1000000) % (4 * 24 * m_reg);
736 if (f_out <= target_freq) {
738 diff = target_freq - f_out;
741 diff = f_out - target_freq;
744 if (diff_min > diff) {
750 if (!diff && mod_min > mod) {
756 if (m) *m = (m_best - 2) & 0x3FF;
757 if (n) *n = (n_best - 2) & 0x3FF;
758 if (p) *p = (p_target << 4);
761 /*************************************************************
762 * Hardware Cursor Routines *
763 *************************************************************/
766 * i810_enable_cursor - show or hide the hardware cursor
767 * @mmio: address of register space
768 * @mode: show (1) or hide (0)
771 * Shows or hides the hardware cursor
773 static void i810_enable_cursor(u8 __iomem *mmio, int mode)
777 temp = i810_readl(PIXCONF, mmio);
778 temp = (mode == ON) ? temp | CURSOR_ENABLE_MASK :
779 temp & ~CURSOR_ENABLE_MASK;
781 i810_writel(PIXCONF, mmio, temp);
784 static void i810_reset_cursor_image(struct i810fb_par *par)
786 u8 __iomem *addr = par->cursor_heap.virtual;
789 for (i = 64; i--; ) {
790 for (j = 0; j < 8; j++) {
791 i810_writeb(j, addr, 0xff);
792 i810_writeb(j+8, addr, 0x00);
798 static void i810_load_cursor_image(int width, int height, u8 *data,
799 struct i810fb_par *par)
801 u8 __iomem *addr = par->cursor_heap.virtual;
802 int i, j, w = width/8;
803 int mod = width % 8, t_mask, d_mask;
805 t_mask = 0xff >> mod;
806 d_mask = ~(0xff >> mod);
807 for (i = height; i--; ) {
808 for (j = 0; j < w; j++) {
809 i810_writeb(j+0, addr, 0x00);
810 i810_writeb(j+8, addr, *data++);
813 i810_writeb(j+0, addr, t_mask);
814 i810_writeb(j+8, addr, *data++ & d_mask);
820 static void i810_load_cursor_colors(int fg, int bg, struct fb_info *info)
822 struct i810fb_par *par = info->par;
823 u8 __iomem *mmio = par->mmio_start_virtual;
824 u8 red, green, blue, trans, temp;
826 i810fb_getcolreg(bg, &red, &green, &blue, &trans, info);
828 temp = i810_readb(PIXCONF1, mmio);
829 i810_writeb(PIXCONF1, mmio, temp | EXTENDED_PALETTE);
831 i810_write_dac(4, red, green, blue, mmio);
833 i810_writeb(PIXCONF1, mmio, temp);
835 i810fb_getcolreg(fg, &red, &green, &blue, &trans, info);
836 temp = i810_readb(PIXCONF1, mmio);
837 i810_writeb(PIXCONF1, mmio, temp | EXTENDED_PALETTE);
839 i810_write_dac(5, red, green, blue, mmio);
841 i810_writeb(PIXCONF1, mmio, temp);
845 * i810_init_cursor - initializes the cursor
846 * @par: pointer to i810fb_par structure
849 * Initializes the cursor registers
851 static void i810_init_cursor(struct i810fb_par *par)
853 u8 __iomem *mmio = par->mmio_start_virtual;
855 i810_enable_cursor(mmio, OFF);
856 i810_writel(CURBASE, mmio, par->cursor_heap.physical);
857 i810_writew(CURCNTR, mmio, COORD_ACTIVE | CURSOR_MODE_64_XOR);
860 /*********************************************************************
861 * Framebuffer hook helpers *
862 *********************************************************************/
864 * i810_round_off - Round off values to capability of hardware
865 * @var: pointer to fb_var_screeninfo structure
868 * @var contains user-defined information for the mode to be set.
869 * This will try modify those values to ones nearest the
870 * capability of the hardware
872 static void i810_round_off(struct fb_var_screeninfo *var)
874 u32 xres, yres, vxres, vyres;
877 * Presently supports only these configurations
882 vxres = var->xres_virtual;
883 vyres = var->yres_virtual;
885 var->bits_per_pixel += 7;
886 var->bits_per_pixel &= ~7;
888 if (var->bits_per_pixel < 8)
889 var->bits_per_pixel = 8;
890 if (var->bits_per_pixel > 32)
891 var->bits_per_pixel = 32;
893 round_off_xres(&xres);
898 xres = (xres + 7) & ~7;
903 round_off_yres(&xres, &yres);
912 if (var->bits_per_pixel == 32)
913 var->accel_flags = 0;
915 /* round of horizontal timings to nearest 8 pixels */
916 var->left_margin = (var->left_margin + 4) & ~7;
917 var->right_margin = (var->right_margin + 4) & ~7;
918 var->hsync_len = (var->hsync_len + 4) & ~7;
920 if (var->vmode & FB_VMODE_INTERLACED) {
921 if (!((yres + var->upper_margin + var->vsync_len +
922 var->lower_margin) & 1))
928 var->xres_virtual = vxres;
929 var->yres_virtual = vyres;
933 * set_color_bitfields - sets rgba fields
934 * @var: pointer to fb_var_screeninfo
937 * The length, offset and ordering for each color field
938 * (red, green, blue) will be set as specified
941 static void set_color_bitfields(struct fb_var_screeninfo *var)
943 switch (var->bits_per_pixel) {
947 var->green.offset = 0;
948 var->green.length = 8;
949 var->blue.offset = 0;
950 var->blue.length = 8;
951 var->transp.offset = 0;
952 var->transp.length = 0;
955 var->green.length = (var->green.length == 5) ? 5 : 6;
957 var->blue.length = 5;
958 var->transp.length = 6 - var->green.length;
959 var->blue.offset = 0;
960 var->green.offset = 5;
961 var->red.offset = 5 + var->green.length;
962 var->transp.offset = (5 + var->red.offset) & 15;
964 case 24: /* RGB 888 */
965 case 32: /* RGBA 8888 */
966 var->red.offset = 16;
968 var->green.offset = 8;
969 var->green.length = 8;
970 var->blue.offset = 0;
971 var->blue.length = 8;
972 var->transp.length = var->bits_per_pixel - 24;
973 var->transp.offset = (var->transp.length) ? 24 : 0;
976 var->red.msb_right = 0;
977 var->green.msb_right = 0;
978 var->blue.msb_right = 0;
979 var->transp.msb_right = 0;
983 * i810_check_params - check if contents in var are valid
984 * @var: pointer to fb_var_screeninfo
985 * @info: pointer to fb_info
988 * This will check if the framebuffer size is sufficient
989 * for the current mode and if the user's monitor has the
990 * required specifications to display the current mode.
992 static int i810_check_params(struct fb_var_screeninfo *var,
993 struct fb_info *info)
995 struct i810fb_par *par = info->par;
996 int line_length, vidmem, mode_valid = 0, retval = 0;
997 u32 vyres = var->yres_virtual, vxres = var->xres_virtual;
1001 line_length = get_line_length(par, vxres, var->bits_per_pixel);
1002 vidmem = line_length*vyres;
1004 if (vidmem > par->fb.size) {
1005 vyres = par->fb.size/line_length;
1006 if (vyres < var->yres) {
1008 vxres = par->fb.size/vyres;
1009 vxres /= var->bits_per_pixel >> 3;
1010 line_length = get_line_length(par, vxres,
1011 var->bits_per_pixel);
1012 vidmem = line_length * yres;
1013 if (vxres < var->xres) {
1014 printk("i810fb: required video memory, "
1015 "%d bytes, for %dx%d-%d (virtual) "
1016 "is out of range\n",
1017 vidmem, vxres, vyres,
1018 var->bits_per_pixel);
1024 var->xres_virtual = vxres;
1025 var->yres_virtual = vyres;
1030 switch (var->bits_per_pixel) {
1032 info->monspecs.dclkmax = 234000000;
1035 info->monspecs.dclkmax = 229000000;
1039 info->monspecs.dclkmax = 204000000;
1043 info->monspecs.dclkmin = 15000000;
1045 if (!fb_validate_mode(var, info))
1048 #ifdef CONFIG_FB_I810_I2C
1049 if (!mode_valid && info->monspecs.gtf &&
1050 !fb_get_mode(FB_MAXTIMINGS, 0, var, info))
1053 if (!mode_valid && info->monspecs.modedb_len) {
1054 struct fb_videomode *mode;
1056 mode = fb_find_best_mode(var, &info->modelist);
1058 fb_videomode_to_var(var, mode);
1063 if (!mode_valid && info->monspecs.modedb_len == 0) {
1064 if (fb_get_mode(FB_MAXTIMINGS, 0, var, info)) {
1065 int default_sync = (info->monspecs.hfmin-HFMIN)
1066 |(info->monspecs.hfmax-HFMAX)
1067 |(info->monspecs.vfmin-VFMIN)
1068 |(info->monspecs.vfmax-VFMAX);
1069 printk("i810fb: invalid video mode%s\n",
1070 default_sync ? "" : ". Specifying "
1071 "vsyncN/hsyncN parameters may help");
1080 * encode_fix - fill up fb_fix_screeninfo structure
1081 * @fix: pointer to fb_fix_screeninfo
1082 * @info: pointer to fb_info
1085 * This will set up parameters that are unmodifiable by the user.
1087 static int encode_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
1089 struct i810fb_par *par = info->par;
1091 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
1093 strcpy(fix->id, "I810");
1094 fix->smem_start = par->fb.physical;
1095 fix->smem_len = par->fb.size;
1096 fix->type = FB_TYPE_PACKED_PIXELS;
1101 switch (info->var.bits_per_pixel) {
1103 fix->visual = FB_VISUAL_PSEUDOCOLOR;
1108 if (info->var.nonstd)
1109 fix->visual = FB_VISUAL_DIRECTCOLOR;
1111 fix->visual = FB_VISUAL_TRUECOLOR;
1117 fix->line_length = par->pitch;
1118 fix->mmio_start = par->mmio_start_phys;
1119 fix->mmio_len = MMIO_SIZE;
1120 fix->accel = FB_ACCEL_I810;
1126 * decode_var - modify par according to contents of var
1127 * @var: pointer to fb_var_screeninfo
1128 * @par: pointer to i810fb_par
1131 * Based on the contents of @var, @par will be dynamically filled up.
1132 * @par contains all information necessary to modify the hardware.
1134 static void decode_var(const struct fb_var_screeninfo *var,
1135 struct i810fb_par *par)
1137 u32 xres, yres, vxres, vyres;
1141 vxres = var->xres_virtual;
1142 vyres = var->yres_virtual;
1144 switch (var->bits_per_pixel) {
1146 par->pixconf = PIXCONF8;
1149 par->blit_bpp = BPP8;
1152 if (var->green.length == 5)
1153 par->pixconf = PIXCONF15;
1155 par->pixconf = PIXCONF16;
1158 par->blit_bpp = BPP16;
1161 par->pixconf = PIXCONF24;
1164 par->blit_bpp = BPP24;
1167 par->pixconf = PIXCONF32;
1170 par->blit_bpp = 3 << 24;
1173 if (var->nonstd && var->bits_per_pixel != 8)
1174 par->pixconf |= 1 << 27;
1176 i810_calc_dclk(var->pixclock, &par->regs.M,
1177 &par->regs.N, &par->regs.P);
1178 i810fb_encode_registers(var, par, xres, yres);
1180 par->watermark = i810_get_watermark(var, par);
1181 par->pitch = get_line_length(par, vxres, var->bits_per_pixel);
1185 * i810fb_getcolreg - gets red, green and blue values of the hardware DAC
1190 * @transp: transparency (alpha)
1191 * @info: pointer to fb_info
1194 * Gets the red, green and blue values of the hardware DAC as pointed by @regno
1195 * and writes them to @red, @green and @blue respectively
1197 static int i810fb_getcolreg(u8 regno, u8 *red, u8 *green, u8 *blue,
1198 u8 *transp, struct fb_info *info)
1200 struct i810fb_par *par = info->par;
1201 u8 __iomem *mmio = par->mmio_start_virtual;
1204 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
1205 if ((info->var.green.length == 5 && regno > 31) ||
1206 (info->var.green.length == 6 && regno > 63))
1210 temp = i810_readb(PIXCONF1, mmio);
1211 i810_writeb(PIXCONF1, mmio, temp & ~EXTENDED_PALETTE);
1213 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
1214 info->var.green.length == 5)
1215 i810_read_dac(regno * 8, red, green, blue, mmio);
1217 else if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
1218 info->var.green.length == 6) {
1221 i810_read_dac(regno * 8, red, &tmp, blue, mmio);
1222 i810_read_dac(regno * 4, &tmp, green, &tmp, mmio);
1225 i810_read_dac(regno, red, green, blue, mmio);
1228 i810_writeb(PIXCONF1, mmio, temp);
1233 /******************************************************************
1234 * Framebuffer device-specific hooks *
1235 ******************************************************************/
1237 static int i810fb_open(struct fb_info *info, int user)
1239 struct i810fb_par *par = info->par;
1240 u32 count = atomic_read(&par->use_count);
1243 memset(&par->state, 0, sizeof(struct vgastate));
1244 par->state.flags = VGA_SAVE_CMAP;
1245 par->state.vgabase = par->mmio_start_virtual;
1246 save_vga(&par->state);
1248 i810_save_vga_state(par);
1251 atomic_inc(&par->use_count);
1256 static int i810fb_release(struct fb_info *info, int user)
1258 struct i810fb_par *par = info->par;
1261 count = atomic_read(&par->use_count);
1266 i810_restore_vga_state(par);
1267 restore_vga(&par->state);
1270 atomic_dec(&par->use_count);
1276 static int i810fb_setcolreg(unsigned regno, unsigned red, unsigned green,
1277 unsigned blue, unsigned transp,
1278 struct fb_info *info)
1280 struct i810fb_par *par = info->par;
1281 u8 __iomem *mmio = par->mmio_start_virtual;
1285 if (regno > 255) return 1;
1287 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
1288 if ((info->var.green.length == 5 && regno > 31) ||
1289 (info->var.green.length == 6 && regno > 63))
1293 if (info->var.grayscale)
1294 red = green = blue = (19595 * red + 38470 * green +
1297 temp = i810_readb(PIXCONF1, mmio);
1298 i810_writeb(PIXCONF1, mmio, temp & ~EXTENDED_PALETTE);
1300 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
1301 info->var.green.length == 5) {
1302 for (i = 0; i < 8; i++)
1303 i810_write_dac((u8) (regno * 8) + i, (u8) red,
1304 (u8) green, (u8) blue, mmio);
1305 } else if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
1306 info->var.green.length == 6) {
1310 for (i = 0; i < 8; i++)
1311 i810_write_dac((u8) (regno * 8) + i,
1312 (u8) red, (u8) green,
1315 i810_read_dac((u8) (regno*4), &r, &g, &b, mmio);
1316 for (i = 0; i < 4; i++)
1317 i810_write_dac((u8) (regno*4) + i, r, (u8) green,
1319 } else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
1320 i810_write_dac((u8) regno, (u8) red, (u8) green,
1324 i810_writeb(PIXCONF1, mmio, temp);
1327 switch (info->var.bits_per_pixel) {
1329 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
1330 if (info->var.green.length == 5)
1331 ((u32 *)info->pseudo_palette)[regno] =
1332 (regno << 10) | (regno << 5) |
1335 ((u32 *)info->pseudo_palette)[regno] =
1336 (regno << 11) | (regno << 5) |
1339 if (info->var.green.length == 5) {
1341 ((u32 *)info->pseudo_palette)[regno] =
1342 ((red & 0xf800) >> 1) |
1343 ((green & 0xf800) >> 6) |
1344 ((blue & 0xf800) >> 11);
1347 ((u32 *)info->pseudo_palette)[regno] =
1349 ((green & 0xf800) >> 5) |
1350 ((blue & 0xf800) >> 11);
1354 case 24: /* RGB 888 */
1355 case 32: /* RGBA 8888 */
1356 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR)
1357 ((u32 *)info->pseudo_palette)[regno] =
1358 (regno << 16) | (regno << 8) |
1361 ((u32 *)info->pseudo_palette)[regno] =
1362 ((red & 0xff00) << 8) |
1364 ((blue & 0xff00) >> 8);
1371 static int i810fb_pan_display(struct fb_var_screeninfo *var,
1372 struct fb_info *info)
1374 struct i810fb_par *par = info->par;
1377 total = var->xoffset * par->depth +
1378 var->yoffset * info->fix.line_length;
1379 i810fb_load_front(total, info);
1384 static int i810fb_blank (int blank_mode, struct fb_info *info)
1386 struct i810fb_par *par = info->par;
1387 u8 __iomem *mmio = par->mmio_start_virtual;
1388 int mode = 0, pwr, scr_off = 0;
1390 pwr = i810_readl(PWR_CLKC, mmio);
1392 switch (blank_mode) {
1393 case FB_BLANK_UNBLANK:
1398 case FB_BLANK_NORMAL:
1403 case FB_BLANK_VSYNC_SUSPEND:
1408 case FB_BLANK_HSYNC_SUSPEND:
1413 case FB_BLANK_POWERDOWN:
1422 i810_screen_off(mmio, scr_off);
1423 i810_writel(HVSYNC, mmio, mode);
1424 i810_writel(PWR_CLKC, mmio, pwr);
1429 static int i810fb_set_par(struct fb_info *info)
1431 struct i810fb_par *par = info->par;
1433 decode_var(&info->var, par);
1434 i810_load_regs(par);
1435 i810_init_cursor(par);
1436 encode_fix(&info->fix, info);
1438 if (info->var.accel_flags && !(par->dev_flags & LOCKUP)) {
1439 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
1440 FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
1441 FBINFO_HWACCEL_IMAGEBLIT;
1442 info->pixmap.scan_align = 2;
1444 info->pixmap.scan_align = 1;
1445 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
1450 static int i810fb_check_var(struct fb_var_screeninfo *var,
1451 struct fb_info *info)
1456 var->vmode &= ~FB_VMODE_MASK;
1457 var->vmode |= FB_VMODE_NONINTERLACED;
1459 if (var->vmode & FB_VMODE_DOUBLE) {
1460 var->vmode &= ~FB_VMODE_MASK;
1461 var->vmode |= FB_VMODE_NONINTERLACED;
1464 i810_round_off(var);
1465 if ((err = i810_check_params(var, info)))
1468 i810fb_fill_var_timings(var);
1469 set_color_bitfields(var);
1473 static int i810fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1475 struct i810fb_par *par = info->par;
1476 u8 __iomem *mmio = par->mmio_start_virtual;
1478 if (!par->dev_flags & LOCKUP)
1481 if (cursor->image.width > 64 || cursor->image.height > 64)
1484 if ((i810_readl(CURBASE, mmio) & 0xf) != par->cursor_heap.physical) {
1485 i810_init_cursor(par);
1486 cursor->set |= FB_CUR_SETALL;
1489 i810_enable_cursor(mmio, OFF);
1491 if (cursor->set & FB_CUR_SETPOS) {
1494 tmp = (cursor->image.dx - info->var.xoffset) & 0xffff;
1495 tmp |= (cursor->image.dy - info->var.yoffset) << 16;
1496 i810_writel(CURPOS, mmio, tmp);
1499 if (cursor->set & FB_CUR_SETSIZE)
1500 i810_reset_cursor_image(par);
1502 if (cursor->set & FB_CUR_SETCMAP)
1503 i810_load_cursor_colors(cursor->image.fg_color,
1504 cursor->image.bg_color,
1507 if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
1508 int size = ((cursor->image.width + 7) >> 3) *
1509 cursor->image.height;
1511 u8 *data = kmalloc(64 * 8, GFP_ATOMIC);
1516 switch (cursor->rop) {
1518 for (i = 0; i < size; i++)
1519 data[i] = cursor->image.data[i] ^ cursor->mask[i];
1523 for (i = 0; i < size; i++)
1524 data[i] = cursor->image.data[i] & cursor->mask[i];
1528 i810_load_cursor_image(cursor->image.width,
1529 cursor->image.height, data,
1535 i810_enable_cursor(mmio, ON);
1540 static struct fb_ops i810fb_ops __devinitdata = {
1541 .owner = THIS_MODULE,
1542 .fb_open = i810fb_open,
1543 .fb_release = i810fb_release,
1544 .fb_check_var = i810fb_check_var,
1545 .fb_set_par = i810fb_set_par,
1546 .fb_setcolreg = i810fb_setcolreg,
1547 .fb_blank = i810fb_blank,
1548 .fb_pan_display = i810fb_pan_display,
1549 .fb_fillrect = i810fb_fillrect,
1550 .fb_copyarea = i810fb_copyarea,
1551 .fb_imageblit = i810fb_imageblit,
1552 .fb_cursor = i810fb_cursor,
1553 .fb_sync = i810fb_sync,
1556 /***********************************************************************
1557 * Power Management *
1558 ***********************************************************************/
1559 static int i810fb_suspend(struct pci_dev *dev, pm_message_t state)
1561 struct fb_info *info = pci_get_drvdata(dev);
1562 struct i810fb_par *par = info->par;
1564 par->cur_state = state.event;
1566 if (state.event == PM_EVENT_FREEZE) {
1567 dev->dev.power.power_state = state;
1571 acquire_console_sem();
1572 fb_set_suspend(info, 1);
1574 if (info->fbops->fb_sync)
1575 info->fbops->fb_sync(info);
1577 i810fb_blank(FB_BLANK_POWERDOWN, info);
1578 agp_unbind_memory(par->i810_gtt.i810_fb_memory);
1579 agp_unbind_memory(par->i810_gtt.i810_cursor_memory);
1581 pci_save_state(dev);
1582 pci_disable_device(dev);
1583 pci_set_power_state(dev, pci_choose_state(dev, state));
1584 release_console_sem();
1589 static int i810fb_resume(struct pci_dev *dev)
1591 struct fb_info *info = pci_get_drvdata(dev);
1592 struct i810fb_par *par = info->par;
1593 int cur_state = par->cur_state;
1595 par->cur_state = PM_EVENT_ON;
1597 if (cur_state == PM_EVENT_FREEZE) {
1598 pci_set_power_state(dev, PCI_D0);
1602 acquire_console_sem();
1603 pci_set_power_state(dev, PCI_D0);
1604 pci_restore_state(dev);
1605 pci_enable_device(dev);
1606 pci_set_master(dev);
1607 agp_bind_memory(par->i810_gtt.i810_fb_memory,
1609 agp_bind_memory(par->i810_gtt.i810_cursor_memory,
1610 par->cursor_heap.offset);
1611 i810fb_set_par(info);
1612 fb_set_suspend (info, 0);
1613 info->fbops->fb_blank(VESA_NO_BLANKING, info);
1614 release_console_sem();
1617 /***********************************************************************
1618 * AGP resource allocation *
1619 ***********************************************************************/
1621 static void __devinit i810_fix_pointers(struct i810fb_par *par)
1623 par->fb.physical = par->aperture.physical+(par->fb.offset << 12);
1624 par->fb.virtual = par->aperture.virtual+(par->fb.offset << 12);
1625 par->iring.physical = par->aperture.physical +
1626 (par->iring.offset << 12);
1627 par->iring.virtual = par->aperture.virtual +
1628 (par->iring.offset << 12);
1629 par->cursor_heap.virtual = par->aperture.virtual+
1630 (par->cursor_heap.offset << 12);
1633 static void __devinit i810_fix_offsets(struct i810fb_par *par)
1635 if (vram + 1 > par->aperture.size >> 20)
1636 vram = (par->aperture.size >> 20) - 1;
1637 if (v_offset_default > (par->aperture.size >> 20))
1638 v_offset_default = (par->aperture.size >> 20);
1639 if (vram + v_offset_default + 1 > par->aperture.size >> 20)
1640 v_offset_default = (par->aperture.size >> 20) - (vram + 1);
1642 par->fb.size = vram << 20;
1643 par->fb.offset = v_offset_default << 20;
1644 par->fb.offset >>= 12;
1646 par->iring.offset = par->fb.offset + (par->fb.size >> 12);
1647 par->iring.size = RINGBUFFER_SIZE;
1649 par->cursor_heap.offset = par->iring.offset + (RINGBUFFER_SIZE >> 12);
1650 par->cursor_heap.size = 4096;
1653 static int __devinit i810_alloc_agp_mem(struct fb_info *info)
1655 struct i810fb_par *par = info->par;
1657 struct agp_bridge_data *bridge;
1659 i810_fix_offsets(par);
1660 size = par->fb.size + par->iring.size;
1662 if (!(bridge = agp_backend_acquire(par->dev))) {
1663 printk("i810fb_alloc_fbmem: cannot acquire agpgart\n");
1666 if (!(par->i810_gtt.i810_fb_memory =
1667 agp_allocate_memory(bridge, size >> 12, AGP_NORMAL_MEMORY))) {
1668 printk("i810fb_alloc_fbmem: can't allocate framebuffer "
1670 agp_backend_release(bridge);
1673 if (agp_bind_memory(par->i810_gtt.i810_fb_memory,
1675 printk("i810fb_alloc_fbmem: can't bind framebuffer memory\n");
1676 agp_backend_release(bridge);
1680 if (!(par->i810_gtt.i810_cursor_memory =
1681 agp_allocate_memory(bridge, par->cursor_heap.size >> 12,
1682 AGP_PHYSICAL_MEMORY))) {
1683 printk("i810fb_alloc_cursormem: can't allocate"
1685 agp_backend_release(bridge);
1688 if (agp_bind_memory(par->i810_gtt.i810_cursor_memory,
1689 par->cursor_heap.offset)) {
1690 printk("i810fb_alloc_cursormem: cannot bind cursor memory\n");
1691 agp_backend_release(bridge);
1695 par->cursor_heap.physical = par->i810_gtt.i810_cursor_memory->physical;
1697 i810_fix_pointers(par);
1699 agp_backend_release(bridge);
1704 /***************************************************************
1706 ***************************************************************/
1709 * i810_init_monspecs
1710 * @info: pointer to device specific info structure
1713 * Sets the the user monitor's horizontal and vertical
1716 static void __devinit i810_init_monspecs(struct fb_info *info)
1722 if (!info->monspecs.hfmax)
1723 info->monspecs.hfmax = hsync2;
1724 if (!info->monspecs.hfmin)
1725 info->monspecs.hfmin = hsync1;
1726 if (hsync2 < hsync1)
1727 info->monspecs.hfmin = hsync2;
1733 if (IS_DVT && vsync1 < 60)
1735 if (!info->monspecs.vfmax)
1736 info->monspecs.vfmax = vsync2;
1737 if (!info->monspecs.vfmin)
1738 info->monspecs.vfmin = vsync1;
1739 if (vsync2 < vsync1)
1740 info->monspecs.vfmin = vsync2;
1744 * i810_init_defaults - initializes default values to use
1745 * @par: pointer to i810fb_par structure
1746 * @info: pointer to current fb_info structure
1748 static void __devinit i810_init_defaults(struct i810fb_par *par,
1749 struct fb_info *info)
1752 v_offset_default = voffset;
1753 else if (par->aperture.size > 32 * 1024 * 1024)
1754 v_offset_default = 16;
1756 v_offset_default = 8;
1762 par->dev_flags |= HAS_ACCELERATION;
1765 par->dev_flags |= ALWAYS_SYNC;
1767 par->ddc_num = ddc3;
1772 par->i810fb_ops = i810fb_ops;
1775 info->var.xres = xres;
1777 info->var.xres = 640;
1780 info->var.yres = yres;
1782 info->var.yres = 480;
1785 vyres = (vram << 20)/(info->var.xres*bpp >> 3);
1787 info->var.yres_virtual = vyres;
1788 info->var.bits_per_pixel = bpp;
1791 info->var.nonstd = 1;
1793 if (par->dev_flags & HAS_ACCELERATION)
1794 info->var.accel_flags = 1;
1796 i810_init_monspecs(info);
1800 * i810_init_device - initialize device
1801 * @par: pointer to i810fb_par structure
1803 static void __devinit i810_init_device(struct i810fb_par *par)
1806 u8 __iomem *mmio = par->mmio_start_virtual;
1808 if (mtrr) set_mtrr(par);
1810 i810_init_cursor(par);
1812 /* mvo: enable external vga-connector (for laptops) */
1814 i810_writel(HVSYNC, mmio, 0);
1815 i810_writel(PWR_CLKC, mmio, 3);
1818 pci_read_config_byte(par->dev, 0x50, ®);
1820 par->mem_freq = (reg) ? 133 : 100;
1824 static int __devinit
1825 i810_allocate_pci_resource(struct i810fb_par *par,
1826 const struct pci_device_id *entry)
1830 if ((err = pci_enable_device(par->dev))) {
1831 printk("i810fb_init: cannot enable device\n");
1834 par->res_flags |= PCI_DEVICE_ENABLED;
1836 if (pci_resource_len(par->dev, 0) > 512 * 1024) {
1837 par->aperture.physical = pci_resource_start(par->dev, 0);
1838 par->aperture.size = pci_resource_len(par->dev, 0);
1839 par->mmio_start_phys = pci_resource_start(par->dev, 1);
1841 par->aperture.physical = pci_resource_start(par->dev, 1);
1842 par->aperture.size = pci_resource_len(par->dev, 1);
1843 par->mmio_start_phys = pci_resource_start(par->dev, 0);
1845 if (!par->aperture.size) {
1846 printk("i810fb_init: device is disabled\n");
1850 if (!request_mem_region(par->aperture.physical,
1852 i810_pci_list[entry->driver_data])) {
1853 printk("i810fb_init: cannot request framebuffer region\n");
1856 par->res_flags |= FRAMEBUFFER_REQ;
1858 par->aperture.virtual = ioremap_nocache(par->aperture.physical,
1859 par->aperture.size);
1860 if (!par->aperture.virtual) {
1861 printk("i810fb_init: cannot remap framebuffer region\n");
1865 if (!request_mem_region(par->mmio_start_phys,
1867 i810_pci_list[entry->driver_data])) {
1868 printk("i810fb_init: cannot request mmio region\n");
1871 par->res_flags |= MMIO_REQ;
1873 par->mmio_start_virtual = ioremap_nocache(par->mmio_start_phys,
1875 if (!par->mmio_start_virtual) {
1876 printk("i810fb_init: cannot remap mmio region\n");
1883 static void __devinit i810fb_find_init_mode(struct fb_info *info)
1885 struct fb_videomode mode;
1886 struct fb_var_screeninfo var;
1887 struct fb_monspecs *specs = &info->monspecs;
1889 #ifdef CONFIG_FB_I810_I2C
1892 struct i810fb_par *par = info->par;
1895 INIT_LIST_HEAD(&info->modelist);
1896 memset(&mode, 0, sizeof(struct fb_videomode));
1898 #ifdef CONFIG_FB_I810_I2C
1899 i810_create_i2c_busses(par);
1901 for (i = 0; i < par->ddc_num + 1; i++) {
1902 err = i810_probe_i2c_connector(info, &par->edid, i);
1908 printk("i810fb_init_pci: DDC probe successful\n");
1910 fb_edid_to_monspecs(par->edid, specs);
1912 if (specs->modedb == NULL)
1913 printk("i810fb_init_pci: Unable to get Mode Database\n");
1915 fb_videomode_to_modelist(specs->modedb, specs->modedb_len,
1917 if (specs->modedb != NULL) {
1918 struct fb_videomode *m;
1921 if ((m = fb_find_best_mode(&var, &info->modelist))) {
1928 m = fb_find_best_display(&info->monspecs, &info->modelist);
1933 fb_videomode_to_var(&var, &mode);
1937 fb_find_mode(&var, info, mode_option, specs->modedb,
1938 specs->modedb_len, (found) ? &mode : NULL,
1939 info->var.bits_per_pixel);
1942 fb_destroy_modedb(specs->modedb);
1943 specs->modedb = NULL;
1947 static int __devinit i810fb_setup(char *options)
1949 char *this_opt, *suffix = NULL;
1951 if (!options || !*options)
1954 while ((this_opt = strsep(&options, ",")) != NULL) {
1955 if (!strncmp(this_opt, "mtrr", 4))
1957 else if (!strncmp(this_opt, "accel", 5))
1959 else if (!strncmp(this_opt, "extvga", 6))
1961 else if (!strncmp(this_opt, "sync", 4))
1963 else if (!strncmp(this_opt, "vram:", 5))
1964 vram = (simple_strtoul(this_opt+5, NULL, 0));
1965 else if (!strncmp(this_opt, "voffset:", 8))
1966 voffset = (simple_strtoul(this_opt+8, NULL, 0));
1967 else if (!strncmp(this_opt, "xres:", 5))
1968 xres = simple_strtoul(this_opt+5, NULL, 0);
1969 else if (!strncmp(this_opt, "yres:", 5))
1970 yres = simple_strtoul(this_opt+5, NULL, 0);
1971 else if (!strncmp(this_opt, "vyres:", 6))
1972 vyres = simple_strtoul(this_opt+6, NULL, 0);
1973 else if (!strncmp(this_opt, "bpp:", 4))
1974 bpp = simple_strtoul(this_opt+4, NULL, 0);
1975 else if (!strncmp(this_opt, "hsync1:", 7)) {
1976 hsync1 = simple_strtoul(this_opt+7, &suffix, 0);
1977 if (strncmp(suffix, "H", 1))
1979 } else if (!strncmp(this_opt, "hsync2:", 7)) {
1980 hsync2 = simple_strtoul(this_opt+7, &suffix, 0);
1981 if (strncmp(suffix, "H", 1))
1983 } else if (!strncmp(this_opt, "vsync1:", 7))
1984 vsync1 = simple_strtoul(this_opt+7, NULL, 0);
1985 else if (!strncmp(this_opt, "vsync2:", 7))
1986 vsync2 = simple_strtoul(this_opt+7, NULL, 0);
1987 else if (!strncmp(this_opt, "dcolor", 6))
1989 else if (!strncmp(this_opt, "ddc3", 4))
1992 mode_option = this_opt;
1998 static int __devinit i810fb_init_pci (struct pci_dev *dev,
1999 const struct pci_device_id *entry)
2001 struct fb_info *info;
2002 struct i810fb_par *par = NULL;
2003 struct fb_videomode mode;
2004 int i, err = -1, vfreq, hfreq, pixclock;
2008 info = framebuffer_alloc(sizeof(struct i810fb_par), &dev->dev);
2015 if (!(info->pixmap.addr = kmalloc(8*1024, GFP_KERNEL))) {
2016 i810fb_release_resource(info, par);
2019 memset(info->pixmap.addr, 0, 8*1024);
2020 info->pixmap.size = 8*1024;
2021 info->pixmap.buf_align = 8;
2022 info->pixmap.access_align = 32;
2023 info->pixmap.flags = FB_PIXMAP_SYSTEM;
2025 if ((err = i810_allocate_pci_resource(par, entry))) {
2026 i810fb_release_resource(info, par);
2030 i810_init_defaults(par, info);
2032 if ((err = i810_alloc_agp_mem(info))) {
2033 i810fb_release_resource(info, par);
2037 i810_init_device(par);
2039 info->screen_base = par->fb.virtual;
2040 info->fbops = &par->i810fb_ops;
2041 info->pseudo_palette = par->pseudo_palette;
2042 fb_alloc_cmap(&info->cmap, 256, 0);
2043 i810fb_find_init_mode(info);
2045 if ((err = info->fbops->fb_check_var(&info->var, info))) {
2046 i810fb_release_resource(info, par);
2050 fb_var_to_videomode(&mode, &info->var);
2051 fb_add_videomode(&mode, &info->modelist);
2052 encode_fix(&info->fix, info);
2054 i810fb_init_ringbuffer(info);
2055 err = register_framebuffer(info);
2058 i810fb_release_resource(info, par);
2059 printk("i810fb_init: cannot register framebuffer device\n");
2063 pci_set_drvdata(dev, info);
2064 pixclock = 1000000000/(info->var.pixclock);
2066 hfreq = pixclock/(info->var.xres + info->var.left_margin +
2067 info->var.hsync_len + info->var.right_margin);
2068 vfreq = hfreq/(info->var.yres + info->var.upper_margin +
2069 info->var.vsync_len + info->var.lower_margin);
2071 printk("I810FB: fb%d : %s v%d.%d.%d%s\n"
2072 "I810FB: Video RAM : %dK\n"
2073 "I810FB: Monitor : H: %d-%d KHz V: %d-%d Hz\n"
2074 "I810FB: Mode : %dx%d-%dbpp@%dHz\n",
2076 i810_pci_list[entry->driver_data],
2077 VERSION_MAJOR, VERSION_MINOR, VERSION_TEENIE, BRANCH_VERSION,
2078 (int) par->fb.size>>10, info->monspecs.hfmin/1000,
2079 info->monspecs.hfmax/1000, info->monspecs.vfmin,
2080 info->monspecs.vfmax, info->var.xres,
2081 info->var.yres, info->var.bits_per_pixel, vfreq);
2085 /***************************************************************
2086 * De-initialization *
2087 ***************************************************************/
2089 static void i810fb_release_resource(struct fb_info *info,
2090 struct i810fb_par *par)
2092 struct gtt_data *gtt = &par->i810_gtt;
2095 i810_delete_i2c_busses(par);
2097 if (par->i810_gtt.i810_cursor_memory)
2098 agp_free_memory(gtt->i810_cursor_memory);
2099 if (par->i810_gtt.i810_fb_memory)
2100 agp_free_memory(gtt->i810_fb_memory);
2102 if (par->mmio_start_virtual)
2103 iounmap(par->mmio_start_virtual);
2104 if (par->aperture.virtual)
2105 iounmap(par->aperture.virtual);
2107 if (par->res_flags & FRAMEBUFFER_REQ)
2108 release_mem_region(par->aperture.physical,
2109 par->aperture.size);
2110 if (par->res_flags & MMIO_REQ)
2111 release_mem_region(par->mmio_start_phys, MMIO_SIZE);
2113 framebuffer_release(info);
2117 static void __exit i810fb_remove_pci(struct pci_dev *dev)
2119 struct fb_info *info = pci_get_drvdata(dev);
2120 struct i810fb_par *par = info->par;
2122 unregister_framebuffer(info);
2123 i810fb_release_resource(info, par);
2124 pci_set_drvdata(dev, NULL);
2125 printk("cleanup_module: unloaded i810 framebuffer device\n");
2129 static int __devinit i810fb_init(void)
2131 char *option = NULL;
2133 if (fb_get_options("i810fb", &option))
2135 i810fb_setup(option);
2137 return pci_register_driver(&i810fb_driver);
2141 /*********************************************************************
2143 *********************************************************************/
2147 static int __devinit i810fb_init(void)
2152 return pci_register_driver(&i810fb_driver);
2155 module_param(vram, int, 0);
2156 MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB"
2158 module_param(voffset, int, 0);
2159 MODULE_PARM_DESC(voffset, "at what offset to place start of framebuffer "
2160 "memory (0 to maximum aperture size), in MiB (default = 48)");
2161 module_param(bpp, int, 0);
2162 MODULE_PARM_DESC(bpp, "Color depth for display in bits per pixel"
2164 module_param(xres, int, 0);
2165 MODULE_PARM_DESC(xres, "Horizontal resolution in pixels (default = 640)");
2166 module_param(yres, int, 0);
2167 MODULE_PARM_DESC(yres, "Vertical resolution in scanlines (default = 480)");
2168 module_param(vyres,int, 0);
2169 MODULE_PARM_DESC(vyres, "Virtual vertical resolution in scanlines"
2170 " (default = 480)");
2171 module_param(hsync1, int, 0);
2172 MODULE_PARM_DESC(hsync1, "Minimum horizontal frequency of monitor in KHz"
2174 module_param(hsync2, int, 0);
2175 MODULE_PARM_DESC(hsync2, "Maximum horizontal frequency of monitor in KHz"
2177 module_param(vsync1, int, 0);
2178 MODULE_PARM_DESC(vsync1, "Minimum vertical frequency of monitor in Hz"
2180 module_param(vsync2, int, 0);
2181 MODULE_PARM_DESC(vsync2, "Maximum vertical frequency of monitor in Hz"
2183 module_param(accel, bool, 0);
2184 MODULE_PARM_DESC(accel, "Use Acceleration (BLIT) engine (default = 0)");
2185 module_param(mtrr, bool, 0);
2186 MODULE_PARM_DESC(mtrr, "Use MTRR (default = 0)");
2187 module_param(extvga, bool, 0);
2188 MODULE_PARM_DESC(extvga, "Enable external VGA connector (default = 0)");
2189 module_param(sync, bool, 0);
2190 MODULE_PARM_DESC(sync, "wait for accel engine to finish drawing"
2192 module_param(dcolor, bool, 0);
2193 MODULE_PARM_DESC(dcolor, "use DirectColor visuals"
2194 " (default = 0 = TrueColor)");
2195 module_param(ddc3, bool, 0);
2196 MODULE_PARM_DESC(ddc3, "Probe DDC bus 3 (default = 0 = no)");
2197 module_param(mode_option, charp, 0);
2198 MODULE_PARM_DESC(mode_option, "Specify initial video mode");
2200 MODULE_AUTHOR("Tony A. Daplas");
2201 MODULE_DESCRIPTION("Framebuffer device for the Intel 810/815 and"
2202 " compatible cards");
2203 MODULE_LICENSE("GPL");
2205 static void __exit i810fb_exit(void)
2207 pci_unregister_driver(&i810fb_driver);
2209 module_exit(i810fb_exit);
2213 module_init(i810fb_init);