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>
56 #include "i810_regs.h"
58 #include "i810_main.h"
61 static const char *i810_pci_list[] __devinitdata = {
62 "Intel(R) 810 Framebuffer Device" ,
63 "Intel(R) 810-DC100 Framebuffer Device" ,
64 "Intel(R) 810E Framebuffer Device" ,
65 "Intel(R) 815 (Internal Graphics 100Mhz FSB) Framebuffer Device" ,
66 "Intel(R) 815 (Internal Graphics only) Framebuffer Device" ,
67 "Intel(R) 815 (Internal Graphics with AGP) Framebuffer Device"
70 static struct pci_device_id i810fb_pci_tbl[] = {
71 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG1,
72 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
73 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3,
74 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
75 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810E_IG,
76 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
77 /* mvo: added i815 PCI-ID */
78 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_100,
79 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
80 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_NOAGP,
81 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
82 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC,
83 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
87 static struct pci_driver i810fb_driver = {
89 .id_table = i810fb_pci_tbl,
90 .probe = i810fb_init_pci,
91 .remove = __exit_p(i810fb_remove_pci),
92 .suspend = i810fb_suspend,
93 .resume = i810fb_resume,
96 static char *mode_option __devinitdata = NULL;
97 static int vram __devinitdata = 4;
98 static int bpp __devinitdata = 8;
99 static int mtrr __devinitdata;
100 static int accel __devinitdata;
101 static int hsync1 __devinitdata;
102 static int hsync2 __devinitdata;
103 static int vsync1 __devinitdata;
104 static int vsync2 __devinitdata;
105 static int xres __devinitdata;
106 static int yres __devinitdata;
107 static int vyres __devinitdata;
108 static int sync __devinitdata;
109 static int extvga __devinitdata;
110 static int dcolor __devinitdata;
112 /*------------------------------------------------------------*/
114 /**************************************************************
115 * Hardware Low Level Routines *
116 **************************************************************/
119 * i810_screen_off - turns off/on display
120 * @mmio: address of register space
124 * Blanks/unblanks the display
126 static void i810_screen_off(u8 __iomem *mmio, u8 mode)
128 u32 count = WAIT_COUNT;
131 i810_writeb(SR_INDEX, mmio, SR01);
132 val = i810_readb(SR_DATA, mmio);
133 val = (mode == OFF) ? val | SCR_OFF :
136 while((i810_readw(DISP_SL, mmio) & 0xFFF) && count--);
137 i810_writeb(SR_INDEX, mmio, SR01);
138 i810_writeb(SR_DATA, mmio, val);
142 * i810_dram_off - turns off/on dram refresh
143 * @mmio: address of register space
147 * Turns off DRAM refresh. Must be off for only 2 vsyncs
148 * before data becomes corrupt
150 static void i810_dram_off(u8 __iomem *mmio, u8 mode)
154 val = i810_readb(DRAMCH, mmio);
156 val = (mode == OFF) ? val : val | DRAM_ON;
157 i810_writeb(DRAMCH, mmio, val);
161 * i810_protect_regs - allows rw/ro mode of certain VGA registers
162 * @mmio: address of register space
163 * @mode: protect/unprotect
166 * The IBM VGA standard allows protection of certain VGA registers.
167 * This will protect or unprotect them.
169 static void i810_protect_regs(u8 __iomem *mmio, int mode)
173 i810_writeb(CR_INDEX_CGA, mmio, CR11);
174 reg = i810_readb(CR_DATA_CGA, mmio);
175 reg = (mode == OFF) ? reg & ~0x80 :
178 i810_writeb(CR_INDEX_CGA, mmio, CR11);
179 i810_writeb(CR_DATA_CGA, mmio, reg);
183 * i810_load_pll - loads values for the hardware PLL clock
184 * @par: pointer to i810fb_par structure
187 * Loads the P, M, and N registers.
189 static void i810_load_pll(struct i810fb_par *par)
192 u8 __iomem *mmio = par->mmio_start_virtual;
194 tmp1 = par->regs.M | par->regs.N << 16;
195 tmp2 = i810_readl(DCLK_2D, mmio);
197 i810_writel(DCLK_2D, mmio, tmp1 | tmp2);
200 tmp2 = i810_readl(DCLK_0DS, mmio);
201 tmp2 &= ~(P_OR << 16);
202 i810_writel(DCLK_0DS, mmio, (tmp1 << 16) | tmp2);
204 i810_writeb(MSR_WRITE, mmio, par->regs.msr | 0xC8 | 1);
209 * i810_load_vga - load standard VGA registers
210 * @par: pointer to i810fb_par structure
213 * Load values to VGA registers
215 static void i810_load_vga(struct i810fb_par *par)
217 u8 __iomem *mmio = par->mmio_start_virtual;
220 i810_writeb(CR_INDEX_CGA, mmio, CR70);
221 i810_writeb(CR_DATA_CGA, mmio, par->interlace);
223 i810_writeb(CR_INDEX_CGA, mmio, CR00);
224 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr00);
225 i810_writeb(CR_INDEX_CGA, mmio, CR01);
226 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr01);
227 i810_writeb(CR_INDEX_CGA, mmio, CR02);
228 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr02);
229 i810_writeb(CR_INDEX_CGA, mmio, CR03);
230 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr03);
231 i810_writeb(CR_INDEX_CGA, mmio, CR04);
232 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr04);
233 i810_writeb(CR_INDEX_CGA, mmio, CR05);
234 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr05);
235 i810_writeb(CR_INDEX_CGA, mmio, CR06);
236 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr06);
237 i810_writeb(CR_INDEX_CGA, mmio, CR09);
238 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr09);
239 i810_writeb(CR_INDEX_CGA, mmio, CR10);
240 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr10);
241 i810_writeb(CR_INDEX_CGA, mmio, CR11);
242 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr11);
243 i810_writeb(CR_INDEX_CGA, mmio, CR12);
244 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr12);
245 i810_writeb(CR_INDEX_CGA, mmio, CR15);
246 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr15);
247 i810_writeb(CR_INDEX_CGA, mmio, CR16);
248 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr16);
252 * i810_load_vgax - load extended VGA registers
253 * @par: pointer to i810fb_par structure
256 * Load values to extended VGA registers
258 static void i810_load_vgax(struct i810fb_par *par)
260 u8 __iomem *mmio = par->mmio_start_virtual;
262 i810_writeb(CR_INDEX_CGA, mmio, CR30);
263 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr30);
264 i810_writeb(CR_INDEX_CGA, mmio, CR31);
265 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr31);
266 i810_writeb(CR_INDEX_CGA, mmio, CR32);
267 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr32);
268 i810_writeb(CR_INDEX_CGA, mmio, CR33);
269 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr33);
270 i810_writeb(CR_INDEX_CGA, mmio, CR35);
271 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr35);
272 i810_writeb(CR_INDEX_CGA, mmio, CR39);
273 i810_writeb(CR_DATA_CGA, mmio, par->regs.cr39);
277 * i810_load_2d - load grahics registers
278 * @par: pointer to i810fb_par structure
281 * Load values to graphics registers
283 static void i810_load_2d(struct i810fb_par *par)
287 u8 __iomem *mmio = par->mmio_start_virtual;
289 i810_writel(FW_BLC, mmio, par->watermark);
290 tmp = i810_readl(PIXCONF, mmio);
292 i810_writel(PIXCONF, mmio, tmp);
294 i810_writel(OVRACT, mmio, par->ovract);
296 i810_writeb(GR_INDEX, mmio, GR10);
297 tmp8 = i810_readb(GR_DATA, mmio);
299 i810_writeb(GR_INDEX, mmio, GR10);
300 i810_writeb(GR_DATA, mmio, tmp8);
304 * i810_hires - enables high resolution mode
305 * @mmio: address of register space
307 static void i810_hires(u8 __iomem *mmio)
311 i810_writeb(CR_INDEX_CGA, mmio, CR80);
312 val = i810_readb(CR_DATA_CGA, mmio);
313 i810_writeb(CR_INDEX_CGA, mmio, CR80);
314 i810_writeb(CR_DATA_CGA, mmio, val | 1);
315 /* Stop LCD displays from flickering */
316 i810_writel(MEM_MODE, mmio, i810_readl(MEM_MODE, mmio) | 4);
320 * i810_load_pitch - loads the characters per line of the display
321 * @par: pointer to i810fb_par structure
324 * Loads the characters per line
326 static void i810_load_pitch(struct i810fb_par *par)
330 u8 __iomem *mmio = par->mmio_start_virtual;
332 pitch = par->pitch >> 3;
333 i810_writeb(SR_INDEX, mmio, SR01);
334 val = i810_readb(SR_DATA, mmio);
337 i810_writeb(SR_INDEX, mmio, SR01);
338 i810_writeb(SR_DATA, mmio, val);
341 i810_writeb(CR_INDEX_CGA, mmio, CR13);
342 i810_writeb(CR_DATA_CGA, mmio, (u8) tmp);
345 i810_writeb(CR_INDEX_CGA, mmio, CR41);
346 val = i810_readb(CR_DATA_CGA, mmio) & ~0x0F;
347 i810_writeb(CR_INDEX_CGA, mmio, CR41);
348 i810_writeb(CR_DATA_CGA, mmio, (u8) tmp | val);
352 * i810_load_color - loads the color depth of the display
353 * @par: pointer to i810fb_par structure
356 * Loads the color depth of the display and the graphics engine
358 static void i810_load_color(struct i810fb_par *par)
360 u8 __iomem *mmio = par->mmio_start_virtual;
364 reg1 = i810_readl(PIXCONF, mmio) & ~(0xF0000 | 1 << 27);
365 reg2 = i810_readw(BLTCNTL, mmio) & ~0x30;
367 reg1 |= 0x8000 | par->pixconf;
368 reg2 |= par->bltcntl;
369 i810_writel(PIXCONF, mmio, reg1);
370 i810_writew(BLTCNTL, mmio, reg2);
374 * i810_load_regs - loads all registers for the mode
375 * @par: pointer to i810fb_par structure
380 static void i810_load_regs(struct i810fb_par *par)
382 u8 __iomem *mmio = par->mmio_start_virtual;
384 i810_screen_off(mmio, OFF);
385 i810_protect_regs(mmio, OFF);
386 i810_dram_off(mmio, OFF);
390 i810_dram_off(mmio, ON);
393 i810_screen_off(mmio, ON);
394 i810_protect_regs(mmio, ON);
395 i810_load_color(par);
396 i810_load_pitch(par);
399 static void i810_write_dac(u8 regno, u8 red, u8 green, u8 blue,
402 i810_writeb(CLUT_INDEX_WRITE, mmio, regno);
403 i810_writeb(CLUT_DATA, mmio, red);
404 i810_writeb(CLUT_DATA, mmio, green);
405 i810_writeb(CLUT_DATA, mmio, blue);
408 static void i810_read_dac(u8 regno, u8 *red, u8 *green, u8 *blue,
411 i810_writeb(CLUT_INDEX_READ, mmio, regno);
412 *red = i810_readb(CLUT_DATA, mmio);
413 *green = i810_readb(CLUT_DATA, mmio);
414 *blue = i810_readb(CLUT_DATA, mmio);
417 /************************************************************
418 * VGA State Restore *
419 ************************************************************/
420 static void i810_restore_pll(struct i810fb_par *par)
423 u8 __iomem *mmio = par->mmio_start_virtual;
425 tmp1 = par->hw_state.dclk_2d;
426 tmp2 = i810_readl(DCLK_2D, mmio);
429 i810_writel(DCLK_2D, mmio, tmp1 | tmp2);
431 tmp1 = par->hw_state.dclk_1d;
432 tmp2 = i810_readl(DCLK_1D, mmio);
435 i810_writel(DCLK_1D, mmio, tmp1 | tmp2);
437 i810_writel(DCLK_0DS, mmio, par->hw_state.dclk_0ds);
440 static void i810_restore_dac(struct i810fb_par *par)
443 u8 __iomem *mmio = par->mmio_start_virtual;
445 tmp1 = par->hw_state.pixconf;
446 tmp2 = i810_readl(PIXCONF, mmio);
449 i810_writel(PIXCONF, mmio, tmp1 | tmp2);
452 static void i810_restore_vgax(struct i810fb_par *par)
455 u8 __iomem *mmio = par->mmio_start_virtual;
457 for (i = 0; i < 4; i++) {
458 i810_writeb(CR_INDEX_CGA, mmio, CR30+i);
459 i810_writeb(CR_DATA_CGA, mmio, *(&(par->hw_state.cr30) + i));
461 i810_writeb(CR_INDEX_CGA, mmio, CR35);
462 i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr35);
463 i810_writeb(CR_INDEX_CGA, mmio, CR39);
464 i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr39);
465 i810_writeb(CR_INDEX_CGA, mmio, CR41);
466 i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr39);
468 /*restore interlace*/
469 i810_writeb(CR_INDEX_CGA, mmio, CR70);
470 i = par->hw_state.cr70;
472 j = i810_readb(CR_DATA_CGA, mmio);
473 i810_writeb(CR_INDEX_CGA, mmio, CR70);
474 i810_writeb(CR_DATA_CGA, mmio, j | i);
476 i810_writeb(CR_INDEX_CGA, mmio, CR80);
477 i810_writeb(CR_DATA_CGA, mmio, par->hw_state.cr80);
478 i810_writeb(MSR_WRITE, mmio, par->hw_state.msr);
479 i810_writeb(SR_INDEX, mmio, SR01);
480 i = (par->hw_state.sr01) & ~0xE0 ;
481 j = i810_readb(SR_DATA, mmio) & 0xE0;
482 i810_writeb(SR_INDEX, mmio, SR01);
483 i810_writeb(SR_DATA, mmio, i | j);
486 static void i810_restore_vga(struct i810fb_par *par)
489 u8 __iomem *mmio = par->mmio_start_virtual;
491 for (i = 0; i < 10; i++) {
492 i810_writeb(CR_INDEX_CGA, mmio, CR00 + i);
493 i810_writeb(CR_DATA_CGA, mmio, *((&par->hw_state.cr00) + i));
495 for (i = 0; i < 8; i++) {
496 i810_writeb(CR_INDEX_CGA, mmio, CR10 + i);
497 i810_writeb(CR_DATA_CGA, mmio, *((&par->hw_state.cr10) + i));
501 static void i810_restore_addr_map(struct i810fb_par *par)
504 u8 __iomem *mmio = par->mmio_start_virtual;
506 i810_writeb(GR_INDEX, mmio, GR10);
507 tmp = i810_readb(GR_DATA, mmio);
508 tmp &= ADDR_MAP_MASK;
509 tmp |= par->hw_state.gr10;
510 i810_writeb(GR_INDEX, mmio, GR10);
511 i810_writeb(GR_DATA, mmio, tmp);
514 static void i810_restore_2d(struct i810fb_par *par)
518 u8 __iomem *mmio = par->mmio_start_virtual;
520 tmp_word = i810_readw(BLTCNTL, mmio);
521 tmp_word &= ~(3 << 4);
522 tmp_word |= par->hw_state.bltcntl;
523 i810_writew(BLTCNTL, mmio, tmp_word);
525 i810_dram_off(mmio, OFF);
526 i810_writel(PIXCONF, mmio, par->hw_state.pixconf);
527 i810_dram_off(mmio, ON);
529 tmp_word = i810_readw(HWSTAM, mmio);
531 tmp_word |= par->hw_state.hwstam;
532 i810_writew(HWSTAM, mmio, tmp_word);
534 tmp_long = i810_readl(FW_BLC, mmio);
535 tmp_long &= FW_BLC_MASK;
536 tmp_long |= par->hw_state.fw_blc;
537 i810_writel(FW_BLC, mmio, tmp_long);
539 i810_writel(HWS_PGA, mmio, par->hw_state.hws_pga);
540 i810_writew(IER, mmio, par->hw_state.ier);
541 i810_writew(IMR, mmio, par->hw_state.imr);
542 i810_writel(DPLYSTAS, mmio, par->hw_state.dplystas);
545 static void i810_restore_vga_state(struct i810fb_par *par)
547 u8 __iomem *mmio = par->mmio_start_virtual;
549 i810_screen_off(mmio, OFF);
550 i810_protect_regs(mmio, OFF);
551 i810_dram_off(mmio, OFF);
552 i810_restore_pll(par);
553 i810_restore_dac(par);
554 i810_restore_vga(par);
555 i810_restore_vgax(par);
556 i810_restore_addr_map(par);
557 i810_dram_off(mmio, ON);
558 i810_restore_2d(par);
559 i810_screen_off(mmio, ON);
560 i810_protect_regs(mmio, ON);
563 /***********************************************************************
565 ***********************************************************************/
567 static void i810_save_vgax(struct i810fb_par *par)
570 u8 __iomem *mmio = par->mmio_start_virtual;
572 for (i = 0; i < 4; i++) {
573 i810_writeb(CR_INDEX_CGA, mmio, CR30 + i);
574 *(&(par->hw_state.cr30) + i) = i810_readb(CR_DATA_CGA, mmio);
576 i810_writeb(CR_INDEX_CGA, mmio, CR35);
577 par->hw_state.cr35 = i810_readb(CR_DATA_CGA, mmio);
578 i810_writeb(CR_INDEX_CGA, mmio, CR39);
579 par->hw_state.cr39 = i810_readb(CR_DATA_CGA, mmio);
580 i810_writeb(CR_INDEX_CGA, mmio, CR41);
581 par->hw_state.cr41 = i810_readb(CR_DATA_CGA, mmio);
582 i810_writeb(CR_INDEX_CGA, mmio, CR70);
583 par->hw_state.cr70 = i810_readb(CR_DATA_CGA, mmio);
584 par->hw_state.msr = i810_readb(MSR_READ, mmio);
585 i810_writeb(CR_INDEX_CGA, mmio, CR80);
586 par->hw_state.cr80 = i810_readb(CR_DATA_CGA, mmio);
587 i810_writeb(SR_INDEX, mmio, SR01);
588 par->hw_state.sr01 = i810_readb(SR_DATA, mmio);
591 static void i810_save_vga(struct i810fb_par *par)
594 u8 __iomem *mmio = par->mmio_start_virtual;
596 for (i = 0; i < 10; i++) {
597 i810_writeb(CR_INDEX_CGA, mmio, CR00 + i);
598 *((&par->hw_state.cr00) + i) = i810_readb(CR_DATA_CGA, mmio);
600 for (i = 0; i < 8; i++) {
601 i810_writeb(CR_INDEX_CGA, mmio, CR10 + i);
602 *((&par->hw_state.cr10) + i) = i810_readb(CR_DATA_CGA, mmio);
606 static void i810_save_2d(struct i810fb_par *par)
608 u8 __iomem *mmio = par->mmio_start_virtual;
610 par->hw_state.dclk_2d = i810_readl(DCLK_2D, mmio);
611 par->hw_state.dclk_1d = i810_readl(DCLK_1D, mmio);
612 par->hw_state.dclk_0ds = i810_readl(DCLK_0DS, mmio);
613 par->hw_state.pixconf = i810_readl(PIXCONF, mmio);
614 par->hw_state.fw_blc = i810_readl(FW_BLC, mmio);
615 par->hw_state.bltcntl = i810_readw(BLTCNTL, mmio);
616 par->hw_state.hwstam = i810_readw(HWSTAM, mmio);
617 par->hw_state.hws_pga = i810_readl(HWS_PGA, mmio);
618 par->hw_state.ier = i810_readw(IER, mmio);
619 par->hw_state.imr = i810_readw(IMR, mmio);
620 par->hw_state.dplystas = i810_readl(DPLYSTAS, mmio);
623 static void i810_save_vga_state(struct i810fb_par *par)
630 /************************************************************
632 ************************************************************/
634 * get_line_length - calculates buffer pitch in bytes
635 * @par: pointer to i810fb_par structure
636 * @xres_virtual: virtual resolution of the frame
637 * @bpp: bits per pixel
640 * Calculates buffer pitch in bytes.
642 static u32 get_line_length(struct i810fb_par *par, int xres_virtual, int bpp)
646 length = xres_virtual*bpp;
647 length = (length+31)&-32;
653 * i810_calc_dclk - calculates the P, M, and N values of a pixelclock value
654 * @freq: target pixelclock in picoseconds
655 * @m: where to write M register
656 * @n: where to write N register
657 * @p: where to write P register
660 * Based on the formula Freq_actual = (4*M*Freq_ref)/(N^P)
661 * Repeatedly computes the Freq until the actual Freq is equal to
662 * the target Freq or until the loop count is zero. In the latter
663 * case, the actual frequency nearest the target will be used.
665 static void i810_calc_dclk(u32 freq, u32 *m, u32 *n, u32 *p)
667 u32 m_reg, n_reg, p_divisor, n_target_max;
668 u32 m_target, n_target, p_target, n_best, m_best, mod;
669 u32 f_out, target_freq, diff = 0, mod_min, diff_min;
671 diff_min = mod_min = 0xFFFFFFFF;
672 n_best = m_best = m_target = f_out = 0;
678 * find P such that target freq is 16x reference freq (Hz).
682 while(!((1000000 * p_divisor)/(16 * 24 * target_freq)) &&
688 n_reg = m_reg = n_target = 3;
689 while (diff_min && mod_min && (n_target < n_target_max)) {
690 f_out = (p_divisor * n_reg * 1000000)/(4 * 24 * m_reg);
691 mod = (p_divisor * n_reg * 1000000) % (4 * 24 * m_reg);
694 if (f_out <= target_freq) {
696 diff = target_freq - f_out;
699 diff = f_out - target_freq;
702 if (diff_min > diff) {
708 if (!diff && mod_min > mod) {
714 if (m) *m = (m_best - 2) & 0x3FF;
715 if (n) *n = (n_best - 2) & 0x3FF;
716 if (p) *p = (p_target << 4);
719 /*************************************************************
720 * Hardware Cursor Routines *
721 *************************************************************/
724 * i810_enable_cursor - show or hide the hardware cursor
725 * @mmio: address of register space
726 * @mode: show (1) or hide (0)
729 * Shows or hides the hardware cursor
731 static void i810_enable_cursor(u8 __iomem *mmio, int mode)
735 temp = i810_readl(PIXCONF, mmio);
736 temp = (mode == ON) ? temp | CURSOR_ENABLE_MASK :
737 temp & ~CURSOR_ENABLE_MASK;
739 i810_writel(PIXCONF, mmio, temp);
742 static void i810_reset_cursor_image(struct i810fb_par *par)
744 u8 __iomem *addr = par->cursor_heap.virtual;
747 for (i = 64; i--; ) {
748 for (j = 0; j < 8; j++) {
749 i810_writeb(j, addr, 0xff);
750 i810_writeb(j+8, addr, 0x00);
756 static void i810_load_cursor_image(int width, int height, u8 *data,
757 struct i810fb_par *par)
759 u8 __iomem *addr = par->cursor_heap.virtual;
760 int i, j, w = width/8;
761 int mod = width % 8, t_mask, d_mask;
763 t_mask = 0xff >> mod;
764 d_mask = ~(0xff >> mod);
765 for (i = height; i--; ) {
766 for (j = 0; j < w; j++) {
767 i810_writeb(j+0, addr, 0x00);
768 i810_writeb(j+8, addr, *data++);
771 i810_writeb(j+0, addr, t_mask);
772 i810_writeb(j+8, addr, *data++ & d_mask);
778 static void i810_load_cursor_colors(int fg, int bg, struct fb_info *info)
780 struct i810fb_par *par = info->par;
781 u8 __iomem *mmio = par->mmio_start_virtual;
782 u8 red, green, blue, trans, temp;
784 i810fb_getcolreg(bg, &red, &green, &blue, &trans, info);
786 temp = i810_readb(PIXCONF1, mmio);
787 i810_writeb(PIXCONF1, mmio, temp | EXTENDED_PALETTE);
789 i810_write_dac(4, red, green, blue, mmio);
791 i810_writeb(PIXCONF1, mmio, temp);
793 i810fb_getcolreg(fg, &red, &green, &blue, &trans, info);
794 temp = i810_readb(PIXCONF1, mmio);
795 i810_writeb(PIXCONF1, mmio, temp | EXTENDED_PALETTE);
797 i810_write_dac(5, red, green, blue, mmio);
799 i810_writeb(PIXCONF1, mmio, temp);
803 * i810_init_cursor - initializes the cursor
804 * @par: pointer to i810fb_par structure
807 * Initializes the cursor registers
809 static void i810_init_cursor(struct i810fb_par *par)
811 u8 __iomem *mmio = par->mmio_start_virtual;
813 i810_enable_cursor(mmio, OFF);
814 i810_writel(CURBASE, mmio, par->cursor_heap.physical);
815 i810_writew(CURCNTR, mmio, COORD_ACTIVE | CURSOR_MODE_64_XOR);
818 /*********************************************************************
819 * Framebuffer hook helpers *
820 *********************************************************************/
822 * i810_round_off - Round off values to capability of hardware
823 * @var: pointer to fb_var_screeninfo structure
826 * @var contains user-defined information for the mode to be set.
827 * This will try modify those values to ones nearest the
828 * capability of the hardware
830 static void i810_round_off(struct fb_var_screeninfo *var)
832 u32 xres, yres, vxres, vyres;
835 * Presently supports only these configurations
840 vxres = var->xres_virtual;
841 vyres = var->yres_virtual;
843 var->bits_per_pixel += 7;
844 var->bits_per_pixel &= ~7;
846 if (var->bits_per_pixel < 8)
847 var->bits_per_pixel = 8;
848 if (var->bits_per_pixel > 32)
849 var->bits_per_pixel = 32;
851 round_off_xres(&xres);
856 xres = (xres + 7) & ~7;
861 round_off_yres(&xres, &yres);
870 if (var->bits_per_pixel == 32)
871 var->accel_flags = 0;
873 /* round of horizontal timings to nearest 8 pixels */
874 var->left_margin = (var->left_margin + 4) & ~7;
875 var->right_margin = (var->right_margin + 4) & ~7;
876 var->hsync_len = (var->hsync_len + 4) & ~7;
878 if (var->vmode & FB_VMODE_INTERLACED) {
879 if (!((yres + var->upper_margin + var->vsync_len +
880 var->lower_margin) & 1))
886 var->xres_virtual = vxres;
887 var->yres_virtual = vyres;
891 * set_color_bitfields - sets rgba fields
892 * @var: pointer to fb_var_screeninfo
895 * The length, offset and ordering for each color field
896 * (red, green, blue) will be set as specified
899 static void set_color_bitfields(struct fb_var_screeninfo *var)
901 switch (var->bits_per_pixel) {
905 var->green.offset = 0;
906 var->green.length = 8;
907 var->blue.offset = 0;
908 var->blue.length = 8;
909 var->transp.offset = 0;
910 var->transp.length = 0;
913 var->green.length = (var->green.length == 5) ? 5 : 6;
915 var->blue.length = 5;
916 var->transp.length = 6 - var->green.length;
917 var->blue.offset = 0;
918 var->green.offset = 5;
919 var->red.offset = 5 + var->green.length;
920 var->transp.offset = (5 + var->red.offset) & 15;
922 case 24: /* RGB 888 */
923 case 32: /* RGBA 8888 */
924 var->red.offset = 16;
926 var->green.offset = 8;
927 var->green.length = 8;
928 var->blue.offset = 0;
929 var->blue.length = 8;
930 var->transp.length = var->bits_per_pixel - 24;
931 var->transp.offset = (var->transp.length) ? 24 : 0;
934 var->red.msb_right = 0;
935 var->green.msb_right = 0;
936 var->blue.msb_right = 0;
937 var->transp.msb_right = 0;
941 * i810_check_params - check if contents in var are valid
942 * @var: pointer to fb_var_screeninfo
943 * @info: pointer to fb_info
946 * This will check if the framebuffer size is sufficient
947 * for the current mode and if the user's monitor has the
948 * required specifications to display the current mode.
950 static int i810_check_params(struct fb_var_screeninfo *var,
951 struct fb_info *info)
953 struct i810fb_par *par = info->par;
954 int line_length, vidmem, mode_valid = 0, retval = 0;
955 u32 vyres = var->yres_virtual, vxres = var->xres_virtual;
959 line_length = get_line_length(par, vxres, var->bits_per_pixel);
960 vidmem = line_length*vyres;
962 if (vidmem > par->fb.size) {
963 vyres = par->fb.size/line_length;
964 if (vyres < var->yres) {
966 vxres = par->fb.size/vyres;
967 vxres /= var->bits_per_pixel >> 3;
968 line_length = get_line_length(par, vxres,
969 var->bits_per_pixel);
970 vidmem = line_length * yres;
971 if (vxres < var->xres) {
972 printk("i810fb: required video memory, "
973 "%d bytes, for %dx%d-%d (virtual) "
975 vidmem, vxres, vyres,
976 var->bits_per_pixel);
982 var->xres_virtual = vxres;
983 var->yres_virtual = vyres;
988 switch (var->bits_per_pixel) {
990 info->monspecs.dclkmax = 234000000;
993 info->monspecs.dclkmax = 229000000;
997 info->monspecs.dclkmax = 204000000;
1001 info->monspecs.dclkmin = 15000000;
1003 if (!fb_validate_mode(var, info))
1006 #ifdef CONFIG_FB_I810_I2C
1007 if (!mode_valid && info->monspecs.gtf &&
1008 !fb_get_mode(FB_MAXTIMINGS, 0, var, info))
1011 if (!mode_valid && info->monspecs.modedb_len) {
1012 struct fb_videomode *mode;
1014 mode = fb_find_best_mode(var, &info->modelist);
1016 fb_videomode_to_var(var, mode);
1021 if (!mode_valid && info->monspecs.modedb_len == 0) {
1022 if (fb_get_mode(FB_MAXTIMINGS, 0, var, info)) {
1023 int default_sync = (info->monspecs.hfmin-HFMIN)
1024 |(info->monspecs.hfmax-HFMAX)
1025 |(info->monspecs.vfmin-VFMIN)
1026 |(info->monspecs.vfmax-VFMAX);
1027 printk("i810fb: invalid video mode%s\n",
1028 default_sync ? "" : ". Specifying "
1029 "vsyncN/hsyncN parameters may help");
1038 * encode_fix - fill up fb_fix_screeninfo structure
1039 * @fix: pointer to fb_fix_screeninfo
1040 * @info: pointer to fb_info
1043 * This will set up parameters that are unmodifiable by the user.
1045 static int encode_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
1047 struct i810fb_par *par = info->par;
1049 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
1051 strcpy(fix->id, "I810");
1052 fix->smem_start = par->fb.physical;
1053 fix->smem_len = par->fb.size;
1054 fix->type = FB_TYPE_PACKED_PIXELS;
1059 switch (info->var.bits_per_pixel) {
1061 fix->visual = FB_VISUAL_PSEUDOCOLOR;
1066 if (info->var.nonstd)
1067 fix->visual = FB_VISUAL_DIRECTCOLOR;
1069 fix->visual = FB_VISUAL_TRUECOLOR;
1075 fix->line_length = par->pitch;
1076 fix->mmio_start = par->mmio_start_phys;
1077 fix->mmio_len = MMIO_SIZE;
1078 fix->accel = FB_ACCEL_I810;
1084 * decode_var - modify par according to contents of var
1085 * @var: pointer to fb_var_screeninfo
1086 * @par: pointer to i810fb_par
1089 * Based on the contents of @var, @par will be dynamically filled up.
1090 * @par contains all information necessary to modify the hardware.
1092 static void decode_var(const struct fb_var_screeninfo *var,
1093 struct i810fb_par *par)
1095 u32 xres, yres, vxres, vyres;
1099 vxres = var->xres_virtual;
1100 vyres = var->yres_virtual;
1102 switch (var->bits_per_pixel) {
1104 par->pixconf = PIXCONF8;
1107 par->blit_bpp = BPP8;
1110 if (var->green.length == 5)
1111 par->pixconf = PIXCONF15;
1113 par->pixconf = PIXCONF16;
1116 par->blit_bpp = BPP16;
1119 par->pixconf = PIXCONF24;
1122 par->blit_bpp = BPP24;
1125 par->pixconf = PIXCONF32;
1128 par->blit_bpp = 3 << 24;
1131 if (var->nonstd && var->bits_per_pixel != 8)
1132 par->pixconf |= 1 << 27;
1134 i810_calc_dclk(var->pixclock, &par->regs.M,
1135 &par->regs.N, &par->regs.P);
1136 i810fb_encode_registers(var, par, xres, yres);
1138 par->watermark = i810_get_watermark(var, par);
1139 par->pitch = get_line_length(par, vxres, var->bits_per_pixel);
1143 * i810fb_getcolreg - gets red, green and blue values of the hardware DAC
1148 * @transp: transparency (alpha)
1149 * @info: pointer to fb_info
1152 * Gets the red, green and blue values of the hardware DAC as pointed by @regno
1153 * and writes them to @red, @green and @blue respectively
1155 static int i810fb_getcolreg(u8 regno, u8 *red, u8 *green, u8 *blue,
1156 u8 *transp, struct fb_info *info)
1158 struct i810fb_par *par = info->par;
1159 u8 __iomem *mmio = par->mmio_start_virtual;
1162 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
1163 if ((info->var.green.length == 5 && regno > 31) ||
1164 (info->var.green.length == 6 && regno > 63))
1168 temp = i810_readb(PIXCONF1, mmio);
1169 i810_writeb(PIXCONF1, mmio, temp & ~EXTENDED_PALETTE);
1171 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
1172 info->var.green.length == 5)
1173 i810_read_dac(regno * 8, red, green, blue, mmio);
1175 else if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
1176 info->var.green.length == 6) {
1179 i810_read_dac(regno * 8, red, &tmp, blue, mmio);
1180 i810_read_dac(regno * 4, &tmp, green, &tmp, mmio);
1183 i810_read_dac(regno, red, green, blue, mmio);
1186 i810_writeb(PIXCONF1, mmio, temp);
1191 /******************************************************************
1192 * Framebuffer device-specific hooks *
1193 ******************************************************************/
1195 static int i810fb_open(struct fb_info *info, int user)
1197 struct i810fb_par *par = info->par;
1198 u32 count = atomic_read(&par->use_count);
1201 memset(&par->state, 0, sizeof(struct vgastate));
1202 par->state.flags = VGA_SAVE_CMAP;
1203 par->state.vgabase = par->mmio_start_virtual;
1204 save_vga(&par->state);
1206 i810_save_vga_state(par);
1209 atomic_inc(&par->use_count);
1214 static int i810fb_release(struct fb_info *info, int user)
1216 struct i810fb_par *par = info->par;
1219 count = atomic_read(&par->use_count);
1224 i810_restore_vga_state(par);
1225 restore_vga(&par->state);
1228 atomic_dec(&par->use_count);
1234 static int i810fb_setcolreg(unsigned regno, unsigned red, unsigned green,
1235 unsigned blue, unsigned transp,
1236 struct fb_info *info)
1238 struct i810fb_par *par = info->par;
1239 u8 __iomem *mmio = par->mmio_start_virtual;
1243 if (regno > 255) return 1;
1245 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
1246 if ((info->var.green.length == 5 && regno > 31) ||
1247 (info->var.green.length == 6 && regno > 63))
1251 if (info->var.grayscale)
1252 red = green = blue = (19595 * red + 38470 * green +
1255 temp = i810_readb(PIXCONF1, mmio);
1256 i810_writeb(PIXCONF1, mmio, temp & ~EXTENDED_PALETTE);
1258 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
1259 info->var.green.length == 5) {
1260 for (i = 0; i < 8; i++)
1261 i810_write_dac((u8) (regno * 8) + i, (u8) red,
1262 (u8) green, (u8) blue, mmio);
1263 } else if (info->fix.visual == FB_VISUAL_DIRECTCOLOR &&
1264 info->var.green.length == 6) {
1268 for (i = 0; i < 8; i++)
1269 i810_write_dac((u8) (regno * 8) + i,
1270 (u8) red, (u8) green,
1273 i810_read_dac((u8) (regno*4), &r, &g, &b, mmio);
1274 for (i = 0; i < 4; i++)
1275 i810_write_dac((u8) (regno*4) + i, r, (u8) green,
1277 } else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
1278 i810_write_dac((u8) regno, (u8) red, (u8) green,
1282 i810_writeb(PIXCONF1, mmio, temp);
1285 switch (info->var.bits_per_pixel) {
1287 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
1288 if (info->var.green.length == 5)
1289 ((u32 *)info->pseudo_palette)[regno] =
1290 (regno << 10) | (regno << 5) |
1293 ((u32 *)info->pseudo_palette)[regno] =
1294 (regno << 11) | (regno << 5) |
1297 if (info->var.green.length == 5) {
1299 ((u32 *)info->pseudo_palette)[regno] =
1300 ((red & 0xf800) >> 1) |
1301 ((green & 0xf800) >> 6) |
1302 ((blue & 0xf800) >> 11);
1305 ((u32 *)info->pseudo_palette)[regno] =
1307 ((green & 0xf800) >> 5) |
1308 ((blue & 0xf800) >> 11);
1312 case 24: /* RGB 888 */
1313 case 32: /* RGBA 8888 */
1314 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR)
1315 ((u32 *)info->pseudo_palette)[regno] =
1316 (regno << 16) | (regno << 8) |
1319 ((u32 *)info->pseudo_palette)[regno] =
1320 ((red & 0xff00) << 8) |
1322 ((blue & 0xff00) >> 8);
1329 static int i810fb_pan_display(struct fb_var_screeninfo *var,
1330 struct fb_info *info)
1332 struct i810fb_par *par = info->par;
1335 total = var->xoffset * par->depth +
1336 var->yoffset * info->fix.line_length;
1337 i810fb_load_front(total, info);
1342 static int i810fb_blank (int blank_mode, struct fb_info *info)
1344 struct i810fb_par *par = info->par;
1345 u8 __iomem *mmio = par->mmio_start_virtual;
1346 int mode = 0, pwr, scr_off = 0;
1348 pwr = i810_readl(PWR_CLKC, mmio);
1350 switch (blank_mode) {
1351 case FB_BLANK_UNBLANK:
1356 case FB_BLANK_NORMAL:
1361 case FB_BLANK_VSYNC_SUSPEND:
1366 case FB_BLANK_HSYNC_SUSPEND:
1371 case FB_BLANK_POWERDOWN:
1380 i810_screen_off(mmio, scr_off);
1381 i810_writel(HVSYNC, mmio, mode);
1382 i810_writel(PWR_CLKC, mmio, pwr);
1387 static int i810fb_set_par(struct fb_info *info)
1389 struct i810fb_par *par = info->par;
1391 decode_var(&info->var, par);
1392 i810_load_regs(par);
1393 i810_init_cursor(par);
1394 encode_fix(&info->fix, info);
1396 if (info->var.accel_flags && !(par->dev_flags & LOCKUP)) {
1397 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
1398 FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
1399 FBINFO_HWACCEL_IMAGEBLIT;
1400 info->pixmap.scan_align = 2;
1402 info->pixmap.scan_align = 1;
1403 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
1408 static int i810fb_check_var(struct fb_var_screeninfo *var,
1409 struct fb_info *info)
1414 var->vmode &= ~FB_VMODE_MASK;
1415 var->vmode |= FB_VMODE_NONINTERLACED;
1417 if (var->vmode & FB_VMODE_DOUBLE) {
1418 var->vmode &= ~FB_VMODE_MASK;
1419 var->vmode |= FB_VMODE_NONINTERLACED;
1422 i810_round_off(var);
1423 if ((err = i810_check_params(var, info)))
1426 i810fb_fill_var_timings(var);
1427 set_color_bitfields(var);
1431 static int i810fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1433 struct i810fb_par *par = info->par;
1434 u8 __iomem *mmio = par->mmio_start_virtual;
1436 if (!par->dev_flags & LOCKUP)
1439 if (cursor->image.width > 64 || cursor->image.height > 64)
1442 if ((i810_readl(CURBASE, mmio) & 0xf) != par->cursor_heap.physical) {
1443 i810_init_cursor(par);
1444 cursor->set |= FB_CUR_SETALL;
1447 i810_enable_cursor(mmio, OFF);
1449 if (cursor->set & FB_CUR_SETPOS) {
1452 tmp = (cursor->image.dx - info->var.xoffset) & 0xffff;
1453 tmp |= (cursor->image.dy - info->var.yoffset) << 16;
1454 i810_writel(CURPOS, mmio, tmp);
1457 if (cursor->set & FB_CUR_SETSIZE)
1458 i810_reset_cursor_image(par);
1460 if (cursor->set & FB_CUR_SETCMAP)
1461 i810_load_cursor_colors(cursor->image.fg_color,
1462 cursor->image.bg_color,
1465 if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
1466 int size = ((cursor->image.width + 7) >> 3) *
1467 cursor->image.height;
1469 u8 *data = kmalloc(64 * 8, GFP_KERNEL);
1474 switch (cursor->rop) {
1476 for (i = 0; i < size; i++)
1477 data[i] = cursor->image.data[i] ^ cursor->mask[i];
1481 for (i = 0; i < size; i++)
1482 data[i] = cursor->image.data[i] & cursor->mask[i];
1486 i810_load_cursor_image(cursor->image.width,
1487 cursor->image.height, data,
1493 i810_enable_cursor(mmio, ON);
1498 static struct fb_ops i810fb_ops __devinitdata = {
1499 .owner = THIS_MODULE,
1500 .fb_open = i810fb_open,
1501 .fb_release = i810fb_release,
1502 .fb_check_var = i810fb_check_var,
1503 .fb_set_par = i810fb_set_par,
1504 .fb_setcolreg = i810fb_setcolreg,
1505 .fb_blank = i810fb_blank,
1506 .fb_pan_display = i810fb_pan_display,
1507 .fb_fillrect = i810fb_fillrect,
1508 .fb_copyarea = i810fb_copyarea,
1509 .fb_imageblit = i810fb_imageblit,
1510 .fb_cursor = i810fb_cursor,
1511 .fb_sync = i810fb_sync,
1514 /***********************************************************************
1515 * Power Management *
1516 ***********************************************************************/
1517 static int i810fb_suspend(struct pci_dev *dev, pm_message_t state)
1519 struct fb_info *info = pci_get_drvdata(dev);
1520 struct i810fb_par *par = info->par;
1522 par->cur_state = state.event;
1524 if (state.event == PM_EVENT_FREEZE) {
1525 dev->dev.power.power_state = state;
1529 acquire_console_sem();
1530 fb_set_suspend(info, 1);
1532 if (info->fbops->fb_sync)
1533 info->fbops->fb_sync(info);
1535 i810fb_blank(FB_BLANK_POWERDOWN, info);
1536 agp_unbind_memory(par->i810_gtt.i810_fb_memory);
1537 agp_unbind_memory(par->i810_gtt.i810_cursor_memory);
1539 pci_save_state(dev);
1540 pci_disable_device(dev);
1541 pci_set_power_state(dev, pci_choose_state(dev, state));
1542 release_console_sem();
1547 static int i810fb_resume(struct pci_dev *dev)
1549 struct fb_info *info = pci_get_drvdata(dev);
1550 struct i810fb_par *par = info->par;
1551 int cur_state = par->cur_state;
1553 par->cur_state = PM_EVENT_ON;
1555 if (cur_state == PM_EVENT_FREEZE) {
1556 pci_set_power_state(dev, PCI_D0);
1560 acquire_console_sem();
1561 pci_set_power_state(dev, PCI_D0);
1562 pci_restore_state(dev);
1563 pci_enable_device(dev);
1564 pci_set_master(dev);
1565 agp_bind_memory(par->i810_gtt.i810_fb_memory,
1567 agp_bind_memory(par->i810_gtt.i810_cursor_memory,
1568 par->cursor_heap.offset);
1569 i810fb_set_par(info);
1570 fb_set_suspend (info, 0);
1571 info->fbops->fb_blank(VESA_NO_BLANKING, info);
1572 release_console_sem();
1575 /***********************************************************************
1576 * AGP resource allocation *
1577 ***********************************************************************/
1579 static void __devinit i810_fix_pointers(struct i810fb_par *par)
1581 par->fb.physical = par->aperture.physical+(par->fb.offset << 12);
1582 par->fb.virtual = par->aperture.virtual+(par->fb.offset << 12);
1583 par->iring.physical = par->aperture.physical +
1584 (par->iring.offset << 12);
1585 par->iring.virtual = par->aperture.virtual +
1586 (par->iring.offset << 12);
1587 par->cursor_heap.virtual = par->aperture.virtual+
1588 (par->cursor_heap.offset << 12);
1591 static void __devinit i810_fix_offsets(struct i810fb_par *par)
1593 if (vram + 1 > par->aperture.size >> 20)
1594 vram = (par->aperture.size >> 20) - 1;
1595 if (v_offset_default > (par->aperture.size >> 20))
1596 v_offset_default = (par->aperture.size >> 20);
1597 if (vram + v_offset_default + 1 > par->aperture.size >> 20)
1598 v_offset_default = (par->aperture.size >> 20) - (vram + 1);
1600 par->fb.size = vram << 20;
1601 par->fb.offset = v_offset_default << 20;
1602 par->fb.offset >>= 12;
1604 par->iring.offset = par->fb.offset + (par->fb.size >> 12);
1605 par->iring.size = RINGBUFFER_SIZE;
1607 par->cursor_heap.offset = par->iring.offset + (RINGBUFFER_SIZE >> 12);
1608 par->cursor_heap.size = 4096;
1611 static int __devinit i810_alloc_agp_mem(struct fb_info *info)
1613 struct i810fb_par *par = info->par;
1615 struct agp_bridge_data *bridge;
1617 i810_fix_offsets(par);
1618 size = par->fb.size + par->iring.size;
1620 if (!(bridge = agp_backend_acquire(par->dev))) {
1621 printk("i810fb_alloc_fbmem: cannot acquire agpgart\n");
1624 if (!(par->i810_gtt.i810_fb_memory =
1625 agp_allocate_memory(bridge, size >> 12, AGP_NORMAL_MEMORY))) {
1626 printk("i810fb_alloc_fbmem: can't allocate framebuffer "
1628 agp_backend_release(bridge);
1631 if (agp_bind_memory(par->i810_gtt.i810_fb_memory,
1633 printk("i810fb_alloc_fbmem: can't bind framebuffer memory\n");
1634 agp_backend_release(bridge);
1638 if (!(par->i810_gtt.i810_cursor_memory =
1639 agp_allocate_memory(bridge, par->cursor_heap.size >> 12,
1640 AGP_PHYSICAL_MEMORY))) {
1641 printk("i810fb_alloc_cursormem: can't allocate"
1643 agp_backend_release(bridge);
1646 if (agp_bind_memory(par->i810_gtt.i810_cursor_memory,
1647 par->cursor_heap.offset)) {
1648 printk("i810fb_alloc_cursormem: cannot bind cursor memory\n");
1649 agp_backend_release(bridge);
1653 par->cursor_heap.physical = par->i810_gtt.i810_cursor_memory->physical;
1655 i810_fix_pointers(par);
1657 agp_backend_release(bridge);
1662 /***************************************************************
1664 ***************************************************************/
1667 * i810_init_monspecs
1668 * @info: pointer to device specific info structure
1671 * Sets the the user monitor's horizontal and vertical
1674 static void __devinit i810_init_monspecs(struct fb_info *info)
1680 if (!info->monspecs.hfmax)
1681 info->monspecs.hfmax = hsync2;
1682 if (!info->monspecs.hfmin)
1683 info->monspecs.hfmin = hsync1;
1684 if (hsync2 < hsync1)
1685 info->monspecs.hfmin = hsync2;
1691 if (IS_DVT && vsync1 < 60)
1693 if (!info->monspecs.vfmax)
1694 info->monspecs.vfmax = vsync2;
1695 if (!info->monspecs.vfmin)
1696 info->monspecs.vfmin = vsync1;
1697 if (vsync2 < vsync1)
1698 info->monspecs.vfmin = vsync2;
1702 * i810_init_defaults - initializes default values to use
1703 * @par: pointer to i810fb_par structure
1704 * @info: pointer to current fb_info structure
1706 static void __devinit i810_init_defaults(struct i810fb_par *par,
1707 struct fb_info *info)
1710 v_offset_default = voffset;
1711 else if (par->aperture.size > 32 * 1024 * 1024)
1712 v_offset_default = 16;
1714 v_offset_default = 8;
1720 par->dev_flags |= HAS_ACCELERATION;
1723 par->dev_flags |= ALWAYS_SYNC;
1728 par->i810fb_ops = i810fb_ops;
1731 info->var.xres = xres;
1733 info->var.xres = 640;
1736 info->var.yres = yres;
1738 info->var.yres = 480;
1741 vyres = (vram << 20)/(info->var.xres*bpp >> 3);
1743 info->var.yres_virtual = vyres;
1744 info->var.bits_per_pixel = bpp;
1747 info->var.nonstd = 1;
1749 if (par->dev_flags & HAS_ACCELERATION)
1750 info->var.accel_flags = 1;
1752 i810_init_monspecs(info);
1756 * i810_init_device - initialize device
1757 * @par: pointer to i810fb_par structure
1759 static void __devinit i810_init_device(struct i810fb_par *par)
1762 u8 __iomem *mmio = par->mmio_start_virtual;
1764 if (mtrr) set_mtrr(par);
1766 i810_init_cursor(par);
1768 /* mvo: enable external vga-connector (for laptops) */
1770 i810_writel(HVSYNC, mmio, 0);
1771 i810_writel(PWR_CLKC, mmio, 3);
1774 pci_read_config_byte(par->dev, 0x50, ®);
1776 par->mem_freq = (reg) ? 133 : 100;
1780 static int __devinit
1781 i810_allocate_pci_resource(struct i810fb_par *par,
1782 const struct pci_device_id *entry)
1786 if ((err = pci_enable_device(par->dev))) {
1787 printk("i810fb_init: cannot enable device\n");
1790 par->res_flags |= PCI_DEVICE_ENABLED;
1792 if (pci_resource_len(par->dev, 0) > 512 * 1024) {
1793 par->aperture.physical = pci_resource_start(par->dev, 0);
1794 par->aperture.size = pci_resource_len(par->dev, 0);
1795 par->mmio_start_phys = pci_resource_start(par->dev, 1);
1797 par->aperture.physical = pci_resource_start(par->dev, 1);
1798 par->aperture.size = pci_resource_len(par->dev, 1);
1799 par->mmio_start_phys = pci_resource_start(par->dev, 0);
1801 if (!par->aperture.size) {
1802 printk("i810fb_init: device is disabled\n");
1806 if (!request_mem_region(par->aperture.physical,
1808 i810_pci_list[entry->driver_data])) {
1809 printk("i810fb_init: cannot request framebuffer region\n");
1812 par->res_flags |= FRAMEBUFFER_REQ;
1814 par->aperture.virtual = ioremap_nocache(par->aperture.physical,
1815 par->aperture.size);
1816 if (!par->aperture.virtual) {
1817 printk("i810fb_init: cannot remap framebuffer region\n");
1821 if (!request_mem_region(par->mmio_start_phys,
1823 i810_pci_list[entry->driver_data])) {
1824 printk("i810fb_init: cannot request mmio region\n");
1827 par->res_flags |= MMIO_REQ;
1829 par->mmio_start_virtual = ioremap_nocache(par->mmio_start_phys,
1831 if (!par->mmio_start_virtual) {
1832 printk("i810fb_init: cannot remap mmio region\n");
1839 static void __devinit i810fb_find_init_mode(struct fb_info *info)
1841 struct fb_videomode mode;
1842 struct fb_var_screeninfo var;
1843 struct fb_monspecs *specs = &info->monspecs;
1845 #ifdef CONFIG_FB_I810_I2C
1848 struct i810fb_par *par = info->par;
1851 INIT_LIST_HEAD(&info->modelist);
1852 memset(&mode, 0, sizeof(struct fb_videomode));
1854 #ifdef CONFIG_FB_I810_I2C
1855 i810_create_i2c_busses(par);
1857 for (i = 0; i < 4; i++) {
1858 err = i810_probe_i2c_connector(info, &par->edid, i+1);
1864 printk("i810fb_init_pci: DDC probe successful\n");
1866 fb_edid_to_monspecs(par->edid, specs);
1868 if (specs->modedb == NULL)
1869 printk("i810fb_init_pci: Unable to get Mode Database\n");
1871 fb_videomode_to_modelist(specs->modedb, specs->modedb_len,
1873 if (specs->modedb != NULL) {
1874 struct fb_videomode *m;
1877 if ((m = fb_find_best_mode(&var, &info->modelist))) {
1884 m = fb_find_best_display(&info->monspecs, &info->modelist);
1889 fb_videomode_to_var(&var, &mode);
1893 fb_find_mode(&var, info, mode_option, specs->modedb,
1894 specs->modedb_len, (found) ? &mode : NULL,
1895 info->var.bits_per_pixel);
1898 fb_destroy_modedb(specs->modedb);
1899 specs->modedb = NULL;
1903 static int __devinit i810fb_setup(char *options)
1905 char *this_opt, *suffix = NULL;
1907 if (!options || !*options)
1910 while ((this_opt = strsep(&options, ",")) != NULL) {
1911 if (!strncmp(this_opt, "mtrr", 4))
1913 else if (!strncmp(this_opt, "accel", 5))
1915 else if (!strncmp(this_opt, "extvga", 6))
1917 else if (!strncmp(this_opt, "sync", 4))
1919 else if (!strncmp(this_opt, "vram:", 5))
1920 vram = (simple_strtoul(this_opt+5, NULL, 0));
1921 else if (!strncmp(this_opt, "voffset:", 8))
1922 voffset = (simple_strtoul(this_opt+8, NULL, 0));
1923 else if (!strncmp(this_opt, "xres:", 5))
1924 xres = simple_strtoul(this_opt+5, NULL, 0);
1925 else if (!strncmp(this_opt, "yres:", 5))
1926 yres = simple_strtoul(this_opt+5, NULL, 0);
1927 else if (!strncmp(this_opt, "vyres:", 6))
1928 vyres = simple_strtoul(this_opt+6, NULL, 0);
1929 else if (!strncmp(this_opt, "bpp:", 4))
1930 bpp = simple_strtoul(this_opt+4, NULL, 0);
1931 else if (!strncmp(this_opt, "hsync1:", 7)) {
1932 hsync1 = simple_strtoul(this_opt+7, &suffix, 0);
1933 if (strncmp(suffix, "H", 1))
1935 } else if (!strncmp(this_opt, "hsync2:", 7)) {
1936 hsync2 = simple_strtoul(this_opt+7, &suffix, 0);
1937 if (strncmp(suffix, "H", 1))
1939 } else if (!strncmp(this_opt, "vsync1:", 7))
1940 vsync1 = simple_strtoul(this_opt+7, NULL, 0);
1941 else if (!strncmp(this_opt, "vsync2:", 7))
1942 vsync2 = simple_strtoul(this_opt+7, NULL, 0);
1943 else if (!strncmp(this_opt, "dcolor", 6))
1946 mode_option = this_opt;
1952 static int __devinit i810fb_init_pci (struct pci_dev *dev,
1953 const struct pci_device_id *entry)
1955 struct fb_info *info;
1956 struct i810fb_par *par = NULL;
1957 struct fb_videomode mode;
1958 int i, err = -1, vfreq, hfreq, pixclock;
1962 info = framebuffer_alloc(sizeof(struct i810fb_par), &dev->dev);
1969 if (!(info->pixmap.addr = kmalloc(8*1024, GFP_KERNEL))) {
1970 i810fb_release_resource(info, par);
1973 memset(info->pixmap.addr, 0, 8*1024);
1974 info->pixmap.size = 8*1024;
1975 info->pixmap.buf_align = 8;
1976 info->pixmap.access_align = 32;
1977 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1979 if ((err = i810_allocate_pci_resource(par, entry))) {
1980 i810fb_release_resource(info, par);
1984 i810_init_defaults(par, info);
1986 if ((err = i810_alloc_agp_mem(info))) {
1987 i810fb_release_resource(info, par);
1991 i810_init_device(par);
1993 info->screen_base = par->fb.virtual;
1994 info->fbops = &par->i810fb_ops;
1995 info->pseudo_palette = par->pseudo_palette;
1996 fb_alloc_cmap(&info->cmap, 256, 0);
1997 i810fb_find_init_mode(info);
1999 if ((err = info->fbops->fb_check_var(&info->var, info))) {
2000 i810fb_release_resource(info, par);
2004 fb_var_to_videomode(&mode, &info->var);
2005 fb_add_videomode(&mode, &info->modelist);
2006 encode_fix(&info->fix, info);
2008 i810fb_init_ringbuffer(info);
2009 err = register_framebuffer(info);
2012 i810fb_release_resource(info, par);
2013 printk("i810fb_init: cannot register framebuffer device\n");
2017 pci_set_drvdata(dev, info);
2018 pixclock = 1000000000/(info->var.pixclock);
2020 hfreq = pixclock/(info->var.xres + info->var.left_margin +
2021 info->var.hsync_len + info->var.right_margin);
2022 vfreq = hfreq/(info->var.yres + info->var.upper_margin +
2023 info->var.vsync_len + info->var.lower_margin);
2025 printk("I810FB: fb%d : %s v%d.%d.%d%s\n"
2026 "I810FB: Video RAM : %dK\n"
2027 "I810FB: Monitor : H: %d-%d KHz V: %d-%d Hz\n"
2028 "I810FB: Mode : %dx%d-%dbpp@%dHz\n",
2030 i810_pci_list[entry->driver_data],
2031 VERSION_MAJOR, VERSION_MINOR, VERSION_TEENIE, BRANCH_VERSION,
2032 (int) par->fb.size>>10, info->monspecs.hfmin/1000,
2033 info->monspecs.hfmax/1000, info->monspecs.vfmin,
2034 info->monspecs.vfmax, info->var.xres,
2035 info->var.yres, info->var.bits_per_pixel, vfreq);
2039 /***************************************************************
2040 * De-initialization *
2041 ***************************************************************/
2043 static void i810fb_release_resource(struct fb_info *info,
2044 struct i810fb_par *par)
2046 struct gtt_data *gtt = &par->i810_gtt;
2049 i810_delete_i2c_busses(par);
2051 if (par->i810_gtt.i810_cursor_memory)
2052 agp_free_memory(gtt->i810_cursor_memory);
2053 if (par->i810_gtt.i810_fb_memory)
2054 agp_free_memory(gtt->i810_fb_memory);
2056 if (par->mmio_start_virtual)
2057 iounmap(par->mmio_start_virtual);
2058 if (par->aperture.virtual)
2059 iounmap(par->aperture.virtual);
2061 if (par->res_flags & FRAMEBUFFER_REQ)
2062 release_mem_region(par->aperture.physical,
2063 par->aperture.size);
2064 if (par->res_flags & MMIO_REQ)
2065 release_mem_region(par->mmio_start_phys, MMIO_SIZE);
2067 if (par->res_flags & PCI_DEVICE_ENABLED)
2068 pci_disable_device(par->dev);
2070 framebuffer_release(info);
2074 static void __exit i810fb_remove_pci(struct pci_dev *dev)
2076 struct fb_info *info = pci_get_drvdata(dev);
2077 struct i810fb_par *par = info->par;
2079 unregister_framebuffer(info);
2080 i810fb_release_resource(info, par);
2081 pci_set_drvdata(dev, NULL);
2082 printk("cleanup_module: unloaded i810 framebuffer device\n");
2086 static int __devinit i810fb_init(void)
2088 char *option = NULL;
2090 if (fb_get_options("i810fb", &option))
2092 i810fb_setup(option);
2094 return pci_register_driver(&i810fb_driver);
2098 /*********************************************************************
2100 *********************************************************************/
2104 static int __devinit i810fb_init(void)
2109 return pci_register_driver(&i810fb_driver);
2112 module_param(vram, int, 0);
2113 MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB"
2115 module_param(voffset, int, 0);
2116 MODULE_PARM_DESC(voffset, "at what offset to place start of framebuffer "
2117 "memory (0 to maximum aperture size), in MiB (default = 48)");
2118 module_param(bpp, int, 0);
2119 MODULE_PARM_DESC(bpp, "Color depth for display in bits per pixel"
2121 module_param(xres, int, 0);
2122 MODULE_PARM_DESC(xres, "Horizontal resolution in pixels (default = 640)");
2123 module_param(yres, int, 0);
2124 MODULE_PARM_DESC(yres, "Vertical resolution in scanlines (default = 480)");
2125 module_param(vyres,int, 0);
2126 MODULE_PARM_DESC(vyres, "Virtual vertical resolution in scanlines"
2127 " (default = 480)");
2128 module_param(hsync1, int, 0);
2129 MODULE_PARM_DESC(hsync1, "Minimum horizontal frequency of monitor in KHz"
2131 module_param(hsync2, int, 0);
2132 MODULE_PARM_DESC(hsync2, "Maximum horizontal frequency of monitor in KHz"
2134 module_param(vsync1, int, 0);
2135 MODULE_PARM_DESC(vsync1, "Minimum vertical frequency of monitor in Hz"
2137 module_param(vsync2, int, 0);
2138 MODULE_PARM_DESC(vsync2, "Maximum vertical frequency of monitor in Hz"
2140 module_param(accel, bool, 0);
2141 MODULE_PARM_DESC(accel, "Use Acceleration (BLIT) engine (default = 0)");
2142 module_param(mtrr, bool, 0);
2143 MODULE_PARM_DESC(mtrr, "Use MTRR (default = 0)");
2144 module_param(extvga, bool, 0);
2145 MODULE_PARM_DESC(extvga, "Enable external VGA connector (default = 0)");
2146 module_param(sync, bool, 0);
2147 MODULE_PARM_DESC(sync, "wait for accel engine to finish drawing"
2149 module_param(dcolor, bool, 0);
2150 MODULE_PARM_DESC(dcolor, "use DirectColor visuals"
2151 " (default = 0 = TrueColor)");
2152 module_param(mode_option, charp, 0);
2153 MODULE_PARM_DESC(mode_option, "Specify initial video mode");
2155 MODULE_AUTHOR("Tony A. Daplas");
2156 MODULE_DESCRIPTION("Framebuffer device for the Intel 810/815 and"
2157 " compatible cards");
2158 MODULE_LICENSE("GPL");
2160 static void __exit i810fb_exit(void)
2162 pci_unregister_driver(&i810fb_driver);
2164 module_exit(i810fb_exit);
2168 module_init(i810fb_init);