4 * Linux framebuffer driver for Intel(R) 865G integrated graphics chips.
6 * Copyright © 2002, 2003 David Dawes <dawes@xfree86.org>
9 * This driver consists of two parts. The first part (intelfbdrv.c) provides
10 * the basic fbdev interfaces, is derived in part from the radeonfb and
11 * vesafb drivers, and is covered by the GPL. The second part (intelfbhw.c)
12 * provides the code to program the hardware. Most of it is derived from
13 * the i810/i830 XFree86 driver. The HW-specific code is covered here
14 * under a dual license (GPL and MIT/XFree86 license).
20 /* $DHD: intelfb/intelfbhw.c,v 1.9 2003/06/27 15:06:25 dawes Exp $ */
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/errno.h>
25 #include <linux/string.h>
27 #include <linux/delay.h>
29 #include <linux/ioport.h>
30 #include <linux/init.h>
31 #include <linux/pci.h>
32 #include <linux/vmalloc.h>
33 #include <linux/pagemap.h>
34 #include <linux/interrupt.h>
39 #include "intelfbhw.h"
42 int min_m
, max_m
, min_m1
, max_m1
;
43 int min_m2
, max_m2
, min_n
, max_n
;
44 int min_p
, max_p
, min_p1
, max_p1
;
45 int min_vco
, max_vco
, p_transition_clk
, ref_clk
;
46 int p_inc_lo
, p_inc_hi
;
53 static struct pll_min_max plls
[PLLS_MAX
] = {
57 930000, 1400000, 165000, 48000,
63 1400000, 2800000, 200000, 96000,
67 int intelfbhw_get_chipset(struct pci_dev
*pdev
, struct intelfb_info
*dinfo
)
73 switch (pdev
->device
) {
74 case PCI_DEVICE_ID_INTEL_830M
:
75 dinfo
->name
= "Intel(R) 830M";
76 dinfo
->chipset
= INTEL_830M
;
78 dinfo
->pll_index
= PLLS_I8xx
;
80 case PCI_DEVICE_ID_INTEL_845G
:
81 dinfo
->name
= "Intel(R) 845G";
82 dinfo
->chipset
= INTEL_845G
;
84 dinfo
->pll_index
= PLLS_I8xx
;
86 case PCI_DEVICE_ID_INTEL_854
:
88 dinfo
->name
= "Intel(R) 854";
89 dinfo
->chipset
= INTEL_854
;
91 case PCI_DEVICE_ID_INTEL_85XGM
:
94 dinfo
->pll_index
= PLLS_I8xx
;
95 pci_read_config_dword(pdev
, INTEL_85X_CAPID
, &tmp
);
96 switch ((tmp
>> INTEL_85X_VARIANT_SHIFT
) &
97 INTEL_85X_VARIANT_MASK
) {
98 case INTEL_VAR_855GME
:
99 dinfo
->name
= "Intel(R) 855GME";
100 dinfo
->chipset
= INTEL_855GME
;
102 case INTEL_VAR_855GM
:
103 dinfo
->name
= "Intel(R) 855GM";
104 dinfo
->chipset
= INTEL_855GM
;
106 case INTEL_VAR_852GME
:
107 dinfo
->name
= "Intel(R) 852GME";
108 dinfo
->chipset
= INTEL_852GME
;
110 case INTEL_VAR_852GM
:
111 dinfo
->name
= "Intel(R) 852GM";
112 dinfo
->chipset
= INTEL_852GM
;
115 dinfo
->name
= "Intel(R) 852GM/855GM";
116 dinfo
->chipset
= INTEL_85XGM
;
120 case PCI_DEVICE_ID_INTEL_865G
:
121 dinfo
->name
= "Intel(R) 865G";
122 dinfo
->chipset
= INTEL_865G
;
124 dinfo
->pll_index
= PLLS_I8xx
;
126 case PCI_DEVICE_ID_INTEL_915G
:
127 dinfo
->name
= "Intel(R) 915G";
128 dinfo
->chipset
= INTEL_915G
;
130 dinfo
->pll_index
= PLLS_I9xx
;
132 case PCI_DEVICE_ID_INTEL_915GM
:
133 dinfo
->name
= "Intel(R) 915GM";
134 dinfo
->chipset
= INTEL_915GM
;
136 dinfo
->pll_index
= PLLS_I9xx
;
138 case PCI_DEVICE_ID_INTEL_945G
:
139 dinfo
->name
= "Intel(R) 945G";
140 dinfo
->chipset
= INTEL_945G
;
142 dinfo
->pll_index
= PLLS_I9xx
;
144 case PCI_DEVICE_ID_INTEL_945GM
:
145 dinfo
->name
= "Intel(R) 945GM";
146 dinfo
->chipset
= INTEL_945GM
;
148 dinfo
->pll_index
= PLLS_I9xx
;
150 case PCI_DEVICE_ID_INTEL_945GME
:
151 dinfo
->name
= "Intel(R) 945GME";
152 dinfo
->chipset
= INTEL_945GME
;
154 dinfo
->pll_index
= PLLS_I9xx
;
156 case PCI_DEVICE_ID_INTEL_965G
:
157 dinfo
->name
= "Intel(R) 965G";
158 dinfo
->chipset
= INTEL_965G
;
160 dinfo
->pll_index
= PLLS_I9xx
;
162 case PCI_DEVICE_ID_INTEL_965GM
:
163 dinfo
->name
= "Intel(R) 965GM";
164 dinfo
->chipset
= INTEL_965GM
;
166 dinfo
->pll_index
= PLLS_I9xx
;
173 int intelfbhw_get_memory(struct pci_dev
*pdev
, int *aperture_size
,
176 struct pci_dev
*bridge_dev
;
180 if (!pdev
|| !aperture_size
|| !stolen_size
)
183 /* Find the bridge device. It is always 0:0.0 */
184 if (!(bridge_dev
= pci_get_bus_and_slot(0, PCI_DEVFN(0, 0)))) {
185 ERR_MSG("cannot find bridge device\n");
189 /* Get the fb aperture size and "stolen" memory amount. */
191 pci_read_config_word(bridge_dev
, INTEL_GMCH_CTRL
, &tmp
);
192 pci_dev_put(bridge_dev
);
194 switch (pdev
->device
) {
195 case PCI_DEVICE_ID_INTEL_915G
:
196 case PCI_DEVICE_ID_INTEL_915GM
:
197 case PCI_DEVICE_ID_INTEL_945G
:
198 case PCI_DEVICE_ID_INTEL_945GM
:
199 case PCI_DEVICE_ID_INTEL_945GME
:
200 case PCI_DEVICE_ID_INTEL_965G
:
201 case PCI_DEVICE_ID_INTEL_965GM
:
202 /* 915, 945 and 965 chipsets support a 256MB aperture.
203 Aperture size is determined by inspected the
204 base address of the aperture. */
205 if (pci_resource_start(pdev
, 2) & 0x08000000)
206 *aperture_size
= MB(128);
208 *aperture_size
= MB(256);
211 if ((tmp
& INTEL_GMCH_MEM_MASK
) == INTEL_GMCH_MEM_64M
)
212 *aperture_size
= MB(64);
214 *aperture_size
= MB(128);
218 /* Stolen memory size is reduced by the GTT and the popup.
219 GTT is 1K per MB of aperture size, and popup is 4K. */
220 stolen_overhead
= (*aperture_size
/ MB(1)) + 4;
221 switch(pdev
->device
) {
222 case PCI_DEVICE_ID_INTEL_830M
:
223 case PCI_DEVICE_ID_INTEL_845G
:
224 switch (tmp
& INTEL_830_GMCH_GMS_MASK
) {
225 case INTEL_830_GMCH_GMS_STOLEN_512
:
226 *stolen_size
= KB(512) - KB(stolen_overhead
);
228 case INTEL_830_GMCH_GMS_STOLEN_1024
:
229 *stolen_size
= MB(1) - KB(stolen_overhead
);
231 case INTEL_830_GMCH_GMS_STOLEN_8192
:
232 *stolen_size
= MB(8) - KB(stolen_overhead
);
234 case INTEL_830_GMCH_GMS_LOCAL
:
235 ERR_MSG("only local memory found\n");
237 case INTEL_830_GMCH_GMS_DISABLED
:
238 ERR_MSG("video memory is disabled\n");
241 ERR_MSG("unexpected GMCH_GMS value: 0x%02x\n",
242 tmp
& INTEL_830_GMCH_GMS_MASK
);
247 switch (tmp
& INTEL_855_GMCH_GMS_MASK
) {
248 case INTEL_855_GMCH_GMS_STOLEN_1M
:
249 *stolen_size
= MB(1) - KB(stolen_overhead
);
251 case INTEL_855_GMCH_GMS_STOLEN_4M
:
252 *stolen_size
= MB(4) - KB(stolen_overhead
);
254 case INTEL_855_GMCH_GMS_STOLEN_8M
:
255 *stolen_size
= MB(8) - KB(stolen_overhead
);
257 case INTEL_855_GMCH_GMS_STOLEN_16M
:
258 *stolen_size
= MB(16) - KB(stolen_overhead
);
260 case INTEL_855_GMCH_GMS_STOLEN_32M
:
261 *stolen_size
= MB(32) - KB(stolen_overhead
);
263 case INTEL_915G_GMCH_GMS_STOLEN_48M
:
264 *stolen_size
= MB(48) - KB(stolen_overhead
);
266 case INTEL_915G_GMCH_GMS_STOLEN_64M
:
267 *stolen_size
= MB(64) - KB(stolen_overhead
);
269 case INTEL_855_GMCH_GMS_DISABLED
:
270 ERR_MSG("video memory is disabled\n");
273 ERR_MSG("unexpected GMCH_GMS value: 0x%02x\n",
274 tmp
& INTEL_855_GMCH_GMS_MASK
);
280 int intelfbhw_check_non_crt(struct intelfb_info
*dinfo
)
284 if (INREG(LVDS
) & PORT_ENABLE
)
286 if (INREG(DVOA
) & PORT_ENABLE
)
288 if (INREG(DVOB
) & PORT_ENABLE
)
290 if (INREG(DVOC
) & PORT_ENABLE
)
296 const char * intelfbhw_dvo_to_string(int dvo
)
300 else if (dvo
& DVOB_PORT
)
302 else if (dvo
& DVOC_PORT
)
304 else if (dvo
& LVDS_PORT
)
311 int intelfbhw_validate_mode(struct intelfb_info
*dinfo
,
312 struct fb_var_screeninfo
*var
)
318 DBG_MSG("intelfbhw_validate_mode\n");
321 bytes_per_pixel
= var
->bits_per_pixel
/ 8;
322 if (bytes_per_pixel
== 3)
325 /* Check if enough video memory. */
326 tmp
= var
->yres_virtual
* var
->xres_virtual
* bytes_per_pixel
;
327 if (tmp
> dinfo
->fb
.size
) {
328 WRN_MSG("Not enough video ram for mode "
329 "(%d KByte vs %d KByte).\n",
330 BtoKB(tmp
), BtoKB(dinfo
->fb
.size
));
334 /* Check if x/y limits are OK. */
335 if (var
->xres
- 1 > HACTIVE_MASK
) {
336 WRN_MSG("X resolution too large (%d vs %d).\n",
337 var
->xres
, HACTIVE_MASK
+ 1);
340 if (var
->yres
- 1 > VACTIVE_MASK
) {
341 WRN_MSG("Y resolution too large (%d vs %d).\n",
342 var
->yres
, VACTIVE_MASK
+ 1);
346 WRN_MSG("X resolution too small (%d vs 4).\n", var
->xres
);
350 WRN_MSG("Y resolution too small (%d vs 4).\n", var
->yres
);
354 /* Check for doublescan modes. */
355 if (var
->vmode
& FB_VMODE_DOUBLE
) {
356 WRN_MSG("Mode is double-scan.\n");
360 if ((var
->vmode
& FB_VMODE_INTERLACED
) && (var
->yres
& 1)) {
361 WRN_MSG("Odd number of lines in interlaced mode\n");
365 /* Check if clock is OK. */
366 tmp
= 1000000000 / var
->pixclock
;
367 if (tmp
< MIN_CLOCK
) {
368 WRN_MSG("Pixel clock is too low (%d MHz vs %d MHz).\n",
369 (tmp
+ 500) / 1000, MIN_CLOCK
/ 1000);
372 if (tmp
> MAX_CLOCK
) {
373 WRN_MSG("Pixel clock is too high (%d MHz vs %d MHz).\n",
374 (tmp
+ 500) / 1000, MAX_CLOCK
/ 1000);
381 int intelfbhw_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
383 struct intelfb_info
*dinfo
= GET_DINFO(info
);
384 u32 offset
, xoffset
, yoffset
;
387 DBG_MSG("intelfbhw_pan_display\n");
390 xoffset
= ROUND_DOWN_TO(var
->xoffset
, 8);
391 yoffset
= var
->yoffset
;
393 if ((xoffset
+ info
->var
.xres
> info
->var
.xres_virtual
) ||
394 (yoffset
+ info
->var
.yres
> info
->var
.yres_virtual
))
397 offset
= (yoffset
* dinfo
->pitch
) +
398 (xoffset
* info
->var
.bits_per_pixel
) / 8;
400 offset
+= dinfo
->fb
.offset
<< 12;
402 dinfo
->vsync
.pan_offset
= offset
;
403 if ((var
->activate
& FB_ACTIVATE_VBL
) &&
404 !intelfbhw_enable_irq(dinfo
))
405 dinfo
->vsync
.pan_display
= 1;
407 dinfo
->vsync
.pan_display
= 0;
408 OUTREG(DSPABASE
, offset
);
414 /* Blank the screen. */
415 void intelfbhw_do_blank(int blank
, struct fb_info
*info
)
417 struct intelfb_info
*dinfo
= GET_DINFO(info
);
421 DBG_MSG("intelfbhw_do_blank: blank is %d\n", blank
);
424 /* Turn plane A on or off */
425 tmp
= INREG(DSPACNTR
);
427 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
429 tmp
|= DISPPLANE_PLANE_ENABLE
;
430 OUTREG(DSPACNTR
, tmp
);
432 tmp
= INREG(DSPABASE
);
433 OUTREG(DSPABASE
, tmp
);
435 /* Turn off/on the HW cursor */
437 DBG_MSG("cursor_on is %d\n", dinfo
->cursor_on
);
439 if (dinfo
->cursor_on
) {
441 intelfbhw_cursor_hide(dinfo
);
443 intelfbhw_cursor_show(dinfo
);
444 dinfo
->cursor_on
= 1;
446 dinfo
->cursor_blanked
= blank
;
449 tmp
= INREG(ADPA
) & ~ADPA_DPMS_CONTROL_MASK
;
451 case FB_BLANK_UNBLANK
:
452 case FB_BLANK_NORMAL
:
455 case FB_BLANK_VSYNC_SUSPEND
:
458 case FB_BLANK_HSYNC_SUSPEND
:
461 case FB_BLANK_POWERDOWN
:
471 /* Check which pipe is connected to an active display plane. */
472 int intelfbhw_active_pipe(const struct intelfb_hwstate
*hw
)
476 /* keep old default behaviour - prefer PIPE_A */
477 if (hw
->disp_b_ctrl
& DISPPLANE_PLANE_ENABLE
) {
478 pipe
= (hw
->disp_b_ctrl
>> DISPPLANE_SEL_PIPE_SHIFT
);
480 if (unlikely(pipe
== PIPE_A
))
483 if (hw
->disp_a_ctrl
& DISPPLANE_PLANE_ENABLE
) {
484 pipe
= (hw
->disp_a_ctrl
>> DISPPLANE_SEL_PIPE_SHIFT
);
486 if (likely(pipe
== PIPE_A
))
489 /* Impossible that no pipe is selected - return PIPE_A */
491 if (unlikely(pipe
== -1))
497 void intelfbhw_setcolreg(struct intelfb_info
*dinfo
, unsigned regno
,
498 unsigned red
, unsigned green
, unsigned blue
,
501 u32 palette_reg
= (dinfo
->pipe
== PIPE_A
) ?
502 PALETTE_A
: PALETTE_B
;
505 DBG_MSG("intelfbhw_setcolreg: %d: (%d, %d, %d)\n",
506 regno
, red
, green
, blue
);
509 OUTREG(palette_reg
+ (regno
<< 2),
510 (red
<< PALETTE_8_RED_SHIFT
) |
511 (green
<< PALETTE_8_GREEN_SHIFT
) |
512 (blue
<< PALETTE_8_BLUE_SHIFT
));
516 int intelfbhw_read_hw_state(struct intelfb_info
*dinfo
,
517 struct intelfb_hwstate
*hw
, int flag
)
522 DBG_MSG("intelfbhw_read_hw_state\n");
528 /* Read in as much of the HW state as possible. */
529 hw
->vga0_divisor
= INREG(VGA0_DIVISOR
);
530 hw
->vga1_divisor
= INREG(VGA1_DIVISOR
);
531 hw
->vga_pd
= INREG(VGAPD
);
532 hw
->dpll_a
= INREG(DPLL_A
);
533 hw
->dpll_b
= INREG(DPLL_B
);
534 hw
->fpa0
= INREG(FPA0
);
535 hw
->fpa1
= INREG(FPA1
);
536 hw
->fpb0
= INREG(FPB0
);
537 hw
->fpb1
= INREG(FPB1
);
543 /* This seems to be a problem with the 852GM/855GM */
544 for (i
= 0; i
< PALETTE_8_ENTRIES
; i
++) {
545 hw
->palette_a
[i
] = INREG(PALETTE_A
+ (i
<< 2));
546 hw
->palette_b
[i
] = INREG(PALETTE_B
+ (i
<< 2));
553 hw
->htotal_a
= INREG(HTOTAL_A
);
554 hw
->hblank_a
= INREG(HBLANK_A
);
555 hw
->hsync_a
= INREG(HSYNC_A
);
556 hw
->vtotal_a
= INREG(VTOTAL_A
);
557 hw
->vblank_a
= INREG(VBLANK_A
);
558 hw
->vsync_a
= INREG(VSYNC_A
);
559 hw
->src_size_a
= INREG(SRC_SIZE_A
);
560 hw
->bclrpat_a
= INREG(BCLRPAT_A
);
561 hw
->htotal_b
= INREG(HTOTAL_B
);
562 hw
->hblank_b
= INREG(HBLANK_B
);
563 hw
->hsync_b
= INREG(HSYNC_B
);
564 hw
->vtotal_b
= INREG(VTOTAL_B
);
565 hw
->vblank_b
= INREG(VBLANK_B
);
566 hw
->vsync_b
= INREG(VSYNC_B
);
567 hw
->src_size_b
= INREG(SRC_SIZE_B
);
568 hw
->bclrpat_b
= INREG(BCLRPAT_B
);
573 hw
->adpa
= INREG(ADPA
);
574 hw
->dvoa
= INREG(DVOA
);
575 hw
->dvob
= INREG(DVOB
);
576 hw
->dvoc
= INREG(DVOC
);
577 hw
->dvoa_srcdim
= INREG(DVOA_SRCDIM
);
578 hw
->dvob_srcdim
= INREG(DVOB_SRCDIM
);
579 hw
->dvoc_srcdim
= INREG(DVOC_SRCDIM
);
580 hw
->lvds
= INREG(LVDS
);
585 hw
->pipe_a_conf
= INREG(PIPEACONF
);
586 hw
->pipe_b_conf
= INREG(PIPEBCONF
);
587 hw
->disp_arb
= INREG(DISPARB
);
592 hw
->cursor_a_control
= INREG(CURSOR_A_CONTROL
);
593 hw
->cursor_b_control
= INREG(CURSOR_B_CONTROL
);
594 hw
->cursor_a_base
= INREG(CURSOR_A_BASEADDR
);
595 hw
->cursor_b_base
= INREG(CURSOR_B_BASEADDR
);
600 for (i
= 0; i
< 4; i
++) {
601 hw
->cursor_a_palette
[i
] = INREG(CURSOR_A_PALETTE0
+ (i
<< 2));
602 hw
->cursor_b_palette
[i
] = INREG(CURSOR_B_PALETTE0
+ (i
<< 2));
608 hw
->cursor_size
= INREG(CURSOR_SIZE
);
613 hw
->disp_a_ctrl
= INREG(DSPACNTR
);
614 hw
->disp_b_ctrl
= INREG(DSPBCNTR
);
615 hw
->disp_a_base
= INREG(DSPABASE
);
616 hw
->disp_b_base
= INREG(DSPBBASE
);
617 hw
->disp_a_stride
= INREG(DSPASTRIDE
);
618 hw
->disp_b_stride
= INREG(DSPBSTRIDE
);
623 hw
->vgacntrl
= INREG(VGACNTRL
);
628 hw
->add_id
= INREG(ADD_ID
);
633 for (i
= 0; i
< 7; i
++) {
634 hw
->swf0x
[i
] = INREG(SWF00
+ (i
<< 2));
635 hw
->swf1x
[i
] = INREG(SWF10
+ (i
<< 2));
637 hw
->swf3x
[i
] = INREG(SWF30
+ (i
<< 2));
640 for (i
= 0; i
< 8; i
++)
641 hw
->fence
[i
] = INREG(FENCE
+ (i
<< 2));
643 hw
->instpm
= INREG(INSTPM
);
644 hw
->mem_mode
= INREG(MEM_MODE
);
645 hw
->fw_blc_0
= INREG(FW_BLC_0
);
646 hw
->fw_blc_1
= INREG(FW_BLC_1
);
648 hw
->hwstam
= INREG16(HWSTAM
);
649 hw
->ier
= INREG16(IER
);
650 hw
->iir
= INREG16(IIR
);
651 hw
->imr
= INREG16(IMR
);
657 static int calc_vclock3(int index
, int m
, int n
, int p
)
659 if (p
== 0 || n
== 0)
661 return plls
[index
].ref_clk
* m
/ n
/ p
;
664 static int calc_vclock(int index
, int m1
, int m2
, int n
, int p1
, int p2
,
667 struct pll_min_max
*pll
= &plls
[index
];
670 m
= (5 * (m1
+ 2)) + (m2
+ 2);
672 vco
= pll
->ref_clk
* m
/ n
;
674 if (index
== PLLS_I8xx
)
675 p
= ((p1
+ 2) * (1 << (p2
+ 1)));
677 p
= ((p1
) * (p2
? 5 : 10));
682 static void intelfbhw_get_p1p2(struct intelfb_info
*dinfo
, int dpll
,
683 int *o_p1
, int *o_p2
)
687 if (IS_I9XX(dinfo
)) {
688 if (dpll
& DPLL_P1_FORCE_DIV2
)
691 p1
= (dpll
>> DPLL_P1_SHIFT
) & 0xff;
695 p2
= (dpll
>> DPLL_I9XX_P2_SHIFT
) & DPLL_P2_MASK
;
697 if (dpll
& DPLL_P1_FORCE_DIV2
)
700 p1
= (dpll
>> DPLL_P1_SHIFT
) & DPLL_P1_MASK
;
701 p2
= (dpll
>> DPLL_P2_SHIFT
) & DPLL_P2_MASK
;
710 void intelfbhw_print_hw_state(struct intelfb_info
*dinfo
,
711 struct intelfb_hwstate
*hw
)
714 int i
, m1
, m2
, n
, p1
, p2
;
715 int index
= dinfo
->pll_index
;
716 DBG_MSG("intelfbhw_print_hw_state\n");
720 /* Read in as much of the HW state as possible. */
721 printk("hw state dump start\n");
722 printk(" VGA0_DIVISOR: 0x%08x\n", hw
->vga0_divisor
);
723 printk(" VGA1_DIVISOR: 0x%08x\n", hw
->vga1_divisor
);
724 printk(" VGAPD: 0x%08x\n", hw
->vga_pd
);
725 n
= (hw
->vga0_divisor
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
726 m1
= (hw
->vga0_divisor
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
727 m2
= (hw
->vga0_divisor
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
729 intelfbhw_get_p1p2(dinfo
, hw
->vga_pd
, &p1
, &p2
);
731 printk(" VGA0: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
733 printk(" VGA0: clock is %d\n",
734 calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
736 n
= (hw
->vga1_divisor
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
737 m1
= (hw
->vga1_divisor
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
738 m2
= (hw
->vga1_divisor
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
740 intelfbhw_get_p1p2(dinfo
, hw
->vga_pd
, &p1
, &p2
);
741 printk(" VGA1: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
743 printk(" VGA1: clock is %d\n",
744 calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
746 printk(" DPLL_A: 0x%08x\n", hw
->dpll_a
);
747 printk(" DPLL_B: 0x%08x\n", hw
->dpll_b
);
748 printk(" FPA0: 0x%08x\n", hw
->fpa0
);
749 printk(" FPA1: 0x%08x\n", hw
->fpa1
);
750 printk(" FPB0: 0x%08x\n", hw
->fpb0
);
751 printk(" FPB1: 0x%08x\n", hw
->fpb1
);
753 n
= (hw
->fpa0
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
754 m1
= (hw
->fpa0
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
755 m2
= (hw
->fpa0
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
757 intelfbhw_get_p1p2(dinfo
, hw
->dpll_a
, &p1
, &p2
);
759 printk(" PLLA0: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
761 printk(" PLLA0: clock is %d\n",
762 calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
764 n
= (hw
->fpa1
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
765 m1
= (hw
->fpa1
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
766 m2
= (hw
->fpa1
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
768 intelfbhw_get_p1p2(dinfo
, hw
->dpll_a
, &p1
, &p2
);
770 printk(" PLLA1: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
772 printk(" PLLA1: clock is %d\n",
773 calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
776 printk(" PALETTE_A:\n");
777 for (i
= 0; i
< PALETTE_8_ENTRIES
)
778 printk(" %3d: 0x%08x\n", i
, hw
->palette_a
[i
]);
779 printk(" PALETTE_B:\n");
780 for (i
= 0; i
< PALETTE_8_ENTRIES
)
781 printk(" %3d: 0x%08x\n", i
, hw
->palette_b
[i
]);
784 printk(" HTOTAL_A: 0x%08x\n", hw
->htotal_a
);
785 printk(" HBLANK_A: 0x%08x\n", hw
->hblank_a
);
786 printk(" HSYNC_A: 0x%08x\n", hw
->hsync_a
);
787 printk(" VTOTAL_A: 0x%08x\n", hw
->vtotal_a
);
788 printk(" VBLANK_A: 0x%08x\n", hw
->vblank_a
);
789 printk(" VSYNC_A: 0x%08x\n", hw
->vsync_a
);
790 printk(" SRC_SIZE_A: 0x%08x\n", hw
->src_size_a
);
791 printk(" BCLRPAT_A: 0x%08x\n", hw
->bclrpat_a
);
792 printk(" HTOTAL_B: 0x%08x\n", hw
->htotal_b
);
793 printk(" HBLANK_B: 0x%08x\n", hw
->hblank_b
);
794 printk(" HSYNC_B: 0x%08x\n", hw
->hsync_b
);
795 printk(" VTOTAL_B: 0x%08x\n", hw
->vtotal_b
);
796 printk(" VBLANK_B: 0x%08x\n", hw
->vblank_b
);
797 printk(" VSYNC_B: 0x%08x\n", hw
->vsync_b
);
798 printk(" SRC_SIZE_B: 0x%08x\n", hw
->src_size_b
);
799 printk(" BCLRPAT_B: 0x%08x\n", hw
->bclrpat_b
);
801 printk(" ADPA: 0x%08x\n", hw
->adpa
);
802 printk(" DVOA: 0x%08x\n", hw
->dvoa
);
803 printk(" DVOB: 0x%08x\n", hw
->dvob
);
804 printk(" DVOC: 0x%08x\n", hw
->dvoc
);
805 printk(" DVOA_SRCDIM: 0x%08x\n", hw
->dvoa_srcdim
);
806 printk(" DVOB_SRCDIM: 0x%08x\n", hw
->dvob_srcdim
);
807 printk(" DVOC_SRCDIM: 0x%08x\n", hw
->dvoc_srcdim
);
808 printk(" LVDS: 0x%08x\n", hw
->lvds
);
810 printk(" PIPEACONF: 0x%08x\n", hw
->pipe_a_conf
);
811 printk(" PIPEBCONF: 0x%08x\n", hw
->pipe_b_conf
);
812 printk(" DISPARB: 0x%08x\n", hw
->disp_arb
);
814 printk(" CURSOR_A_CONTROL: 0x%08x\n", hw
->cursor_a_control
);
815 printk(" CURSOR_B_CONTROL: 0x%08x\n", hw
->cursor_b_control
);
816 printk(" CURSOR_A_BASEADDR: 0x%08x\n", hw
->cursor_a_base
);
817 printk(" CURSOR_B_BASEADDR: 0x%08x\n", hw
->cursor_b_base
);
819 printk(" CURSOR_A_PALETTE: ");
820 for (i
= 0; i
< 4; i
++) {
821 printk("0x%08x", hw
->cursor_a_palette
[i
]);
826 printk(" CURSOR_B_PALETTE: ");
827 for (i
= 0; i
< 4; i
++) {
828 printk("0x%08x", hw
->cursor_b_palette
[i
]);
834 printk(" CURSOR_SIZE: 0x%08x\n", hw
->cursor_size
);
836 printk(" DSPACNTR: 0x%08x\n", hw
->disp_a_ctrl
);
837 printk(" DSPBCNTR: 0x%08x\n", hw
->disp_b_ctrl
);
838 printk(" DSPABASE: 0x%08x\n", hw
->disp_a_base
);
839 printk(" DSPBBASE: 0x%08x\n", hw
->disp_b_base
);
840 printk(" DSPASTRIDE: 0x%08x\n", hw
->disp_a_stride
);
841 printk(" DSPBSTRIDE: 0x%08x\n", hw
->disp_b_stride
);
843 printk(" VGACNTRL: 0x%08x\n", hw
->vgacntrl
);
844 printk(" ADD_ID: 0x%08x\n", hw
->add_id
);
846 for (i
= 0; i
< 7; i
++) {
847 printk(" SWF0%d 0x%08x\n", i
,
850 for (i
= 0; i
< 7; i
++) {
851 printk(" SWF1%d 0x%08x\n", i
,
854 for (i
= 0; i
< 3; i
++) {
855 printk(" SWF3%d 0x%08x\n", i
,
858 for (i
= 0; i
< 8; i
++)
859 printk(" FENCE%d 0x%08x\n", i
,
862 printk(" INSTPM 0x%08x\n", hw
->instpm
);
863 printk(" MEM_MODE 0x%08x\n", hw
->mem_mode
);
864 printk(" FW_BLC_0 0x%08x\n", hw
->fw_blc_0
);
865 printk(" FW_BLC_1 0x%08x\n", hw
->fw_blc_1
);
867 printk(" HWSTAM 0x%04x\n", hw
->hwstam
);
868 printk(" IER 0x%04x\n", hw
->ier
);
869 printk(" IIR 0x%04x\n", hw
->iir
);
870 printk(" IMR 0x%04x\n", hw
->imr
);
871 printk("hw state dump end\n");
877 /* Split the M parameter into M1 and M2. */
878 static int splitm(int index
, unsigned int m
, unsigned int *retm1
,
883 struct pll_min_max
*pll
= &plls
[index
];
885 /* no point optimising too much - brute force m */
886 for (m1
= pll
->min_m1
; m1
< pll
->max_m1
+ 1; m1
++) {
887 for (m2
= pll
->min_m2
; m2
< pll
->max_m2
+ 1; m2
++) {
888 testm
= (5 * (m1
+ 2)) + (m2
+ 2);
890 *retm1
= (unsigned int)m1
;
891 *retm2
= (unsigned int)m2
;
899 /* Split the P parameter into P1 and P2. */
900 static int splitp(int index
, unsigned int p
, unsigned int *retp1
,
904 struct pll_min_max
*pll
= &plls
[index
];
906 if (index
== PLLS_I9xx
) {
907 p2
= (p
% 10) ? 1 : 0;
909 p1
= p
/ (p2
? 5 : 10);
911 *retp1
= (unsigned int)p1
;
912 *retp2
= (unsigned int)p2
;
920 p1
= (p
/ (1 << (p2
+ 1))) - 2;
921 if (p
% 4 == 0 && p1
< pll
->min_p1
) {
923 p1
= (p
/ (1 << (p2
+ 1))) - 2;
925 if (p1
< pll
->min_p1
|| p1
> pll
->max_p1
||
926 (p1
+ 2) * (1 << (p2
+ 1)) != p
) {
929 *retp1
= (unsigned int)p1
;
930 *retp2
= (unsigned int)p2
;
935 static int calc_pll_params(int index
, int clock
, u32
*retm1
, u32
*retm2
,
936 u32
*retn
, u32
*retp1
, u32
*retp2
, u32
*retclock
)
938 u32 m1
, m2
, n
, p1
, p2
, n1
, testm
;
939 u32 f_vco
, p
, p_best
= 0, m
, f_out
= 0;
940 u32 err_max
, err_target
, err_best
= 10000000;
941 u32 n_best
= 0, m_best
= 0, f_best
, f_err
;
942 u32 p_min
, p_max
, p_inc
, div_max
;
943 struct pll_min_max
*pll
= &plls
[index
];
945 /* Accept 0.5% difference, but aim for 0.1% */
946 err_max
= 5 * clock
/ 1000;
947 err_target
= clock
/ 1000;
949 DBG_MSG("Clock is %d\n", clock
);
951 div_max
= pll
->max_vco
/ clock
;
953 p_inc
= (clock
<= pll
->p_transition_clk
) ? pll
->p_inc_lo
: pll
->p_inc_hi
;
955 p_max
= ROUND_DOWN_TO(div_max
, p_inc
);
956 if (p_min
< pll
->min_p
)
958 if (p_max
> pll
->max_p
)
961 DBG_MSG("p range is %d-%d (%d)\n", p_min
, p_max
, p_inc
);
965 if (splitp(index
, p
, &p1
, &p2
)) {
966 WRN_MSG("cannot split p = %d\n", p
);
974 m
= ROUND_UP_TO(f_vco
* n
, pll
->ref_clk
) / pll
->ref_clk
;
979 for (testm
= m
- 1; testm
<= m
; testm
++) {
980 f_out
= calc_vclock3(index
, testm
, n
, p
);
981 if (splitm(index
, testm
, &m1
, &m2
)) {
982 WRN_MSG("cannot split m = %d\n",
987 f_err
= clock
- f_out
;
988 else/* slightly bias the error for bigger clocks */
989 f_err
= f_out
- clock
+ 1;
991 if (f_err
< err_best
) {
1000 } while ((n
<= pll
->max_n
) && (f_out
>= clock
));
1002 } while ((p
<= p_max
));
1005 WRN_MSG("cannot find parameters for clock %d\n", clock
);
1011 splitm(index
, m
, &m1
, &m2
);
1012 splitp(index
, p
, &p1
, &p2
);
1015 DBG_MSG("m, n, p: %d (%d,%d), %d (%d), %d (%d,%d), "
1016 "f: %d (%d), VCO: %d\n",
1017 m
, m1
, m2
, n
, n1
, p
, p1
, p2
,
1018 calc_vclock3(index
, m
, n
, p
),
1019 calc_vclock(index
, m1
, m2
, n1
, p1
, p2
, 0),
1020 calc_vclock3(index
, m
, n
, p
) * p
);
1026 *retclock
= calc_vclock(index
, m1
, m2
, n1
, p1
, p2
, 0);
1031 static __inline__
int check_overflow(u32 value
, u32 limit
,
1032 const char *description
)
1034 if (value
> limit
) {
1035 WRN_MSG("%s value %d exceeds limit %d\n",
1036 description
, value
, limit
);
1042 /* It is assumed that hw is filled in with the initial state information. */
1043 int intelfbhw_mode_to_hw(struct intelfb_info
*dinfo
,
1044 struct intelfb_hwstate
*hw
,
1045 struct fb_var_screeninfo
*var
)
1047 int pipe
= intelfbhw_active_pipe(hw
);
1048 u32
*dpll
, *fp0
, *fp1
;
1049 u32 m1
, m2
, n
, p1
, p2
, clock_target
, clock
;
1050 u32 hsync_start
, hsync_end
, hblank_start
, hblank_end
, htotal
, hactive
;
1051 u32 vsync_start
, vsync_end
, vblank_start
, vblank_end
, vtotal
, vactive
;
1052 u32 vsync_pol
, hsync_pol
;
1053 u32
*vs
, *vb
, *vt
, *hs
, *hb
, *ht
, *ss
, *pipe_conf
;
1054 u32 stride_alignment
;
1056 DBG_MSG("intelfbhw_mode_to_hw\n");
1059 hw
->vgacntrl
|= VGA_DISABLE
;
1061 /* Set which pipe's registers will be set. */
1062 if (pipe
== PIPE_B
) {
1072 ss
= &hw
->src_size_b
;
1073 pipe_conf
= &hw
->pipe_b_conf
;
1084 ss
= &hw
->src_size_a
;
1085 pipe_conf
= &hw
->pipe_a_conf
;
1088 /* Use ADPA register for sync control. */
1089 hw
->adpa
&= ~ADPA_USE_VGA_HVPOLARITY
;
1092 hsync_pol
= (var
->sync
& FB_SYNC_HOR_HIGH_ACT
) ?
1093 ADPA_SYNC_ACTIVE_HIGH
: ADPA_SYNC_ACTIVE_LOW
;
1094 vsync_pol
= (var
->sync
& FB_SYNC_VERT_HIGH_ACT
) ?
1095 ADPA_SYNC_ACTIVE_HIGH
: ADPA_SYNC_ACTIVE_LOW
;
1096 hw
->adpa
&= ~((ADPA_SYNC_ACTIVE_MASK
<< ADPA_VSYNC_ACTIVE_SHIFT
) |
1097 (ADPA_SYNC_ACTIVE_MASK
<< ADPA_HSYNC_ACTIVE_SHIFT
));
1098 hw
->adpa
|= (hsync_pol
<< ADPA_HSYNC_ACTIVE_SHIFT
) |
1099 (vsync_pol
<< ADPA_VSYNC_ACTIVE_SHIFT
);
1101 /* Connect correct pipe to the analog port DAC */
1102 hw
->adpa
&= ~(PIPE_MASK
<< ADPA_PIPE_SELECT_SHIFT
);
1103 hw
->adpa
|= (pipe
<< ADPA_PIPE_SELECT_SHIFT
);
1105 /* Set DPMS state to D0 (on) */
1106 hw
->adpa
&= ~ADPA_DPMS_CONTROL_MASK
;
1107 hw
->adpa
|= ADPA_DPMS_D0
;
1109 hw
->adpa
|= ADPA_DAC_ENABLE
;
1111 *dpll
|= (DPLL_VCO_ENABLE
| DPLL_VGA_MODE_DISABLE
);
1112 *dpll
&= ~(DPLL_RATE_SELECT_MASK
| DPLL_REFERENCE_SELECT_MASK
);
1113 *dpll
|= (DPLL_REFERENCE_DEFAULT
| DPLL_RATE_SELECT_FP0
);
1115 /* Desired clock in kHz */
1116 clock_target
= 1000000000 / var
->pixclock
;
1118 if (calc_pll_params(dinfo
->pll_index
, clock_target
, &m1
, &m2
,
1119 &n
, &p1
, &p2
, &clock
)) {
1120 WRN_MSG("calc_pll_params failed\n");
1124 /* Check for overflow. */
1125 if (check_overflow(p1
, DPLL_P1_MASK
, "PLL P1 parameter"))
1127 if (check_overflow(p2
, DPLL_P2_MASK
, "PLL P2 parameter"))
1129 if (check_overflow(m1
, FP_DIVISOR_MASK
, "PLL M1 parameter"))
1131 if (check_overflow(m2
, FP_DIVISOR_MASK
, "PLL M2 parameter"))
1133 if (check_overflow(n
, FP_DIVISOR_MASK
, "PLL N parameter"))
1136 *dpll
&= ~DPLL_P1_FORCE_DIV2
;
1137 *dpll
&= ~((DPLL_P2_MASK
<< DPLL_P2_SHIFT
) |
1138 (DPLL_P1_MASK
<< DPLL_P1_SHIFT
));
1140 if (IS_I9XX(dinfo
)) {
1141 *dpll
|= (p2
<< DPLL_I9XX_P2_SHIFT
);
1142 *dpll
|= (1 << (p1
- 1)) << DPLL_P1_SHIFT
;
1144 *dpll
|= (p2
<< DPLL_P2_SHIFT
) | (p1
<< DPLL_P1_SHIFT
);
1146 *fp0
= (n
<< FP_N_DIVISOR_SHIFT
) |
1147 (m1
<< FP_M1_DIVISOR_SHIFT
) |
1148 (m2
<< FP_M2_DIVISOR_SHIFT
);
1151 hw
->dvob
&= ~PORT_ENABLE
;
1152 hw
->dvoc
&= ~PORT_ENABLE
;
1154 /* Use display plane A. */
1155 hw
->disp_a_ctrl
|= DISPPLANE_PLANE_ENABLE
;
1156 hw
->disp_a_ctrl
&= ~DISPPLANE_GAMMA_ENABLE
;
1157 hw
->disp_a_ctrl
&= ~DISPPLANE_PIXFORMAT_MASK
;
1158 switch (intelfb_var_to_depth(var
)) {
1160 hw
->disp_a_ctrl
|= DISPPLANE_8BPP
| DISPPLANE_GAMMA_ENABLE
;
1163 hw
->disp_a_ctrl
|= DISPPLANE_15_16BPP
;
1166 hw
->disp_a_ctrl
|= DISPPLANE_16BPP
;
1169 hw
->disp_a_ctrl
|= DISPPLANE_32BPP_NO_ALPHA
;
1172 hw
->disp_a_ctrl
&= ~(PIPE_MASK
<< DISPPLANE_SEL_PIPE_SHIFT
);
1173 hw
->disp_a_ctrl
|= (pipe
<< DISPPLANE_SEL_PIPE_SHIFT
);
1175 /* Set CRTC registers. */
1176 hactive
= var
->xres
;
1177 hsync_start
= hactive
+ var
->right_margin
;
1178 hsync_end
= hsync_start
+ var
->hsync_len
;
1179 htotal
= hsync_end
+ var
->left_margin
;
1180 hblank_start
= hactive
;
1181 hblank_end
= htotal
;
1183 DBG_MSG("H: act %d, ss %d, se %d, tot %d bs %d, be %d\n",
1184 hactive
, hsync_start
, hsync_end
, htotal
, hblank_start
,
1187 vactive
= var
->yres
;
1188 if (var
->vmode
& FB_VMODE_INTERLACED
)
1189 vactive
--; /* the chip adds 2 halflines automatically */
1190 vsync_start
= vactive
+ var
->lower_margin
;
1191 vsync_end
= vsync_start
+ var
->vsync_len
;
1192 vtotal
= vsync_end
+ var
->upper_margin
;
1193 vblank_start
= vactive
;
1194 vblank_end
= vsync_end
+ 1;
1196 DBG_MSG("V: act %d, ss %d, se %d, tot %d bs %d, be %d\n",
1197 vactive
, vsync_start
, vsync_end
, vtotal
, vblank_start
,
1200 /* Adjust for register values, and check for overflow. */
1202 if (check_overflow(hactive
, HACTIVE_MASK
, "CRTC hactive"))
1205 if (check_overflow(hsync_start
, HSYNCSTART_MASK
, "CRTC hsync_start"))
1208 if (check_overflow(hsync_end
, HSYNCEND_MASK
, "CRTC hsync_end"))
1211 if (check_overflow(htotal
, HTOTAL_MASK
, "CRTC htotal"))
1214 if (check_overflow(hblank_start
, HBLANKSTART_MASK
, "CRTC hblank_start"))
1217 if (check_overflow(hblank_end
, HBLANKEND_MASK
, "CRTC hblank_end"))
1221 if (check_overflow(vactive
, VACTIVE_MASK
, "CRTC vactive"))
1224 if (check_overflow(vsync_start
, VSYNCSTART_MASK
, "CRTC vsync_start"))
1227 if (check_overflow(vsync_end
, VSYNCEND_MASK
, "CRTC vsync_end"))
1230 if (check_overflow(vtotal
, VTOTAL_MASK
, "CRTC vtotal"))
1233 if (check_overflow(vblank_start
, VBLANKSTART_MASK
, "CRTC vblank_start"))
1236 if (check_overflow(vblank_end
, VBLANKEND_MASK
, "CRTC vblank_end"))
1239 *ht
= (htotal
<< HTOTAL_SHIFT
) | (hactive
<< HACTIVE_SHIFT
);
1240 *hb
= (hblank_start
<< HBLANKSTART_SHIFT
) |
1241 (hblank_end
<< HSYNCEND_SHIFT
);
1242 *hs
= (hsync_start
<< HSYNCSTART_SHIFT
) | (hsync_end
<< HSYNCEND_SHIFT
);
1244 *vt
= (vtotal
<< VTOTAL_SHIFT
) | (vactive
<< VACTIVE_SHIFT
);
1245 *vb
= (vblank_start
<< VBLANKSTART_SHIFT
) |
1246 (vblank_end
<< VSYNCEND_SHIFT
);
1247 *vs
= (vsync_start
<< VSYNCSTART_SHIFT
) | (vsync_end
<< VSYNCEND_SHIFT
);
1248 *ss
= (hactive
<< SRC_SIZE_HORIZ_SHIFT
) |
1249 (vactive
<< SRC_SIZE_VERT_SHIFT
);
1251 hw
->disp_a_stride
= dinfo
->pitch
;
1252 DBG_MSG("pitch is %d\n", hw
->disp_a_stride
);
1254 hw
->disp_a_base
= hw
->disp_a_stride
* var
->yoffset
+
1255 var
->xoffset
* var
->bits_per_pixel
/ 8;
1257 hw
->disp_a_base
+= dinfo
->fb
.offset
<< 12;
1259 /* Check stride alignment. */
1260 stride_alignment
= IS_I9XX(dinfo
) ? STRIDE_ALIGNMENT_I9XX
:
1262 if (hw
->disp_a_stride
% stride_alignment
!= 0) {
1263 WRN_MSG("display stride %d has bad alignment %d\n",
1264 hw
->disp_a_stride
, stride_alignment
);
1268 /* Set the palette to 8-bit mode. */
1269 *pipe_conf
&= ~PIPECONF_GAMMA
;
1271 if (var
->vmode
& FB_VMODE_INTERLACED
)
1272 *pipe_conf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
1274 *pipe_conf
&= ~PIPECONF_INTERLACE_MASK
;
1279 /* Program a (non-VGA) video mode. */
1280 int intelfbhw_program_mode(struct intelfb_info
*dinfo
,
1281 const struct intelfb_hwstate
*hw
, int blank
)
1284 const u32
*dpll
, *fp0
, *fp1
, *pipe_conf
;
1285 const u32
*hs
, *ht
, *hb
, *vs
, *vt
, *vb
, *ss
;
1286 u32 dpll_reg
, fp0_reg
, fp1_reg
, pipe_conf_reg
, pipe_stat_reg
;
1287 u32 hsync_reg
, htotal_reg
, hblank_reg
;
1288 u32 vsync_reg
, vtotal_reg
, vblank_reg
;
1290 u32 count
, tmp_val
[3];
1292 /* Assume single pipe */
1295 DBG_MSG("intelfbhw_program_mode\n");
1299 tmp
= INREG(VGACNTRL
);
1301 OUTREG(VGACNTRL
, tmp
);
1303 dinfo
->pipe
= intelfbhw_active_pipe(hw
);
1305 if (dinfo
->pipe
== PIPE_B
) {
1309 pipe_conf
= &hw
->pipe_b_conf
;
1316 ss
= &hw
->src_size_b
;
1320 pipe_conf_reg
= PIPEBCONF
;
1321 pipe_stat_reg
= PIPEBSTAT
;
1322 hsync_reg
= HSYNC_B
;
1323 htotal_reg
= HTOTAL_B
;
1324 hblank_reg
= HBLANK_B
;
1325 vsync_reg
= VSYNC_B
;
1326 vtotal_reg
= VTOTAL_B
;
1327 vblank_reg
= VBLANK_B
;
1328 src_size_reg
= SRC_SIZE_B
;
1333 pipe_conf
= &hw
->pipe_a_conf
;
1340 ss
= &hw
->src_size_a
;
1344 pipe_conf_reg
= PIPEACONF
;
1345 pipe_stat_reg
= PIPEASTAT
;
1346 hsync_reg
= HSYNC_A
;
1347 htotal_reg
= HTOTAL_A
;
1348 hblank_reg
= HBLANK_A
;
1349 vsync_reg
= VSYNC_A
;
1350 vtotal_reg
= VTOTAL_A
;
1351 vblank_reg
= VBLANK_A
;
1352 src_size_reg
= SRC_SIZE_A
;
1356 tmp
= INREG(pipe_conf_reg
);
1357 tmp
&= ~PIPECONF_ENABLE
;
1358 OUTREG(pipe_conf_reg
, tmp
);
1362 tmp_val
[count
% 3] = INREG(PIPEA_DSL
);
1363 if ((tmp_val
[0] == tmp_val
[1]) && (tmp_val
[1] == tmp_val
[2]))
1367 if (count
% 200 == 0) {
1368 tmp
= INREG(pipe_conf_reg
);
1369 tmp
&= ~PIPECONF_ENABLE
;
1370 OUTREG(pipe_conf_reg
, tmp
);
1372 } while (count
< 2000);
1374 OUTREG(ADPA
, INREG(ADPA
) & ~ADPA_DAC_ENABLE
);
1376 /* Disable planes A and B. */
1377 tmp
= INREG(DSPACNTR
);
1378 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
1379 OUTREG(DSPACNTR
, tmp
);
1380 tmp
= INREG(DSPBCNTR
);
1381 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
1382 OUTREG(DSPBCNTR
, tmp
);
1384 /* Wait for vblank. For now, just wait for a 50Hz cycle (20ms)) */
1387 OUTREG(DVOB
, INREG(DVOB
) & ~PORT_ENABLE
);
1388 OUTREG(DVOC
, INREG(DVOC
) & ~PORT_ENABLE
);
1389 OUTREG(ADPA
, INREG(ADPA
) & ~ADPA_DAC_ENABLE
);
1393 tmp
&= ~ADPA_DPMS_CONTROL_MASK
;
1394 tmp
|= ADPA_DPMS_D3
;
1397 /* do some funky magic - xyzzy */
1398 OUTREG(0x61204, 0xabcd0000);
1401 tmp
= INREG(dpll_reg
);
1402 tmp
&= ~DPLL_VCO_ENABLE
;
1403 OUTREG(dpll_reg
, tmp
);
1405 /* Set PLL parameters */
1406 OUTREG(fp0_reg
, *fp0
);
1407 OUTREG(fp1_reg
, *fp1
);
1410 OUTREG(dpll_reg
, *dpll
);
1413 OUTREG(DVOB
, hw
->dvob
);
1414 OUTREG(DVOC
, hw
->dvoc
);
1416 /* undo funky magic */
1417 OUTREG(0x61204, 0x00000000);
1420 OUTREG(ADPA
, INREG(ADPA
) | ADPA_DAC_ENABLE
);
1421 OUTREG(ADPA
, (hw
->adpa
& ~(ADPA_DPMS_CONTROL_MASK
)) | ADPA_DPMS_D3
);
1423 /* Set pipe parameters */
1424 OUTREG(hsync_reg
, *hs
);
1425 OUTREG(hblank_reg
, *hb
);
1426 OUTREG(htotal_reg
, *ht
);
1427 OUTREG(vsync_reg
, *vs
);
1428 OUTREG(vblank_reg
, *vb
);
1429 OUTREG(vtotal_reg
, *vt
);
1430 OUTREG(src_size_reg
, *ss
);
1432 switch (dinfo
->info
->var
.vmode
& (FB_VMODE_INTERLACED
|
1433 FB_VMODE_ODD_FLD_FIRST
)) {
1434 case FB_VMODE_INTERLACED
| FB_VMODE_ODD_FLD_FIRST
:
1435 OUTREG(pipe_stat_reg
, 0xFFFF | PIPESTAT_FLD_EVT_ODD_EN
);
1437 case FB_VMODE_INTERLACED
: /* even lines first */
1438 OUTREG(pipe_stat_reg
, 0xFFFF | PIPESTAT_FLD_EVT_EVEN_EN
);
1440 default: /* non-interlaced */
1441 OUTREG(pipe_stat_reg
, 0xFFFF); /* clear all status bits only */
1444 OUTREG(pipe_conf_reg
, *pipe_conf
| PIPECONF_ENABLE
);
1448 tmp
&= ~ADPA_DPMS_CONTROL_MASK
;
1449 tmp
|= ADPA_DPMS_D0
;
1452 /* setup display plane */
1453 if (dinfo
->pdev
->device
== PCI_DEVICE_ID_INTEL_830M
) {
1455 * i830M errata: the display plane must be enabled
1456 * to allow writes to the other bits in the plane
1459 tmp
= INREG(DSPACNTR
);
1460 if ((tmp
& DISPPLANE_PLANE_ENABLE
) != DISPPLANE_PLANE_ENABLE
) {
1461 tmp
|= DISPPLANE_PLANE_ENABLE
;
1462 OUTREG(DSPACNTR
, tmp
);
1464 hw
->disp_a_ctrl
|DISPPLANE_PLANE_ENABLE
);
1469 OUTREG(DSPACNTR
, hw
->disp_a_ctrl
& ~DISPPLANE_PLANE_ENABLE
);
1470 OUTREG(DSPASTRIDE
, hw
->disp_a_stride
);
1471 OUTREG(DSPABASE
, hw
->disp_a_base
);
1475 tmp
= INREG(DSPACNTR
);
1476 tmp
|= DISPPLANE_PLANE_ENABLE
;
1477 OUTREG(DSPACNTR
, tmp
);
1478 OUTREG(DSPABASE
, hw
->disp_a_base
);
1484 /* forward declarations */
1485 static void refresh_ring(struct intelfb_info
*dinfo
);
1486 static void reset_state(struct intelfb_info
*dinfo
);
1487 static void do_flush(struct intelfb_info
*dinfo
);
1489 static u32
get_ring_space(struct intelfb_info
*dinfo
)
1493 if (dinfo
->ring_tail
>= dinfo
->ring_head
)
1494 ring_space
= dinfo
->ring
.size
-
1495 (dinfo
->ring_tail
- dinfo
->ring_head
);
1497 ring_space
= dinfo
->ring_head
- dinfo
->ring_tail
;
1499 if (ring_space
> RING_MIN_FREE
)
1500 ring_space
-= RING_MIN_FREE
;
1507 static int wait_ring(struct intelfb_info
*dinfo
, int n
)
1511 u32 last_head
= INREG(PRI_RING_HEAD
) & RING_HEAD_MASK
;
1514 DBG_MSG("wait_ring: %d\n", n
);
1517 end
= jiffies
+ (HZ
* 3);
1518 while (dinfo
->ring_space
< n
) {
1519 dinfo
->ring_head
= INREG(PRI_RING_HEAD
) & RING_HEAD_MASK
;
1520 dinfo
->ring_space
= get_ring_space(dinfo
);
1522 if (dinfo
->ring_head
!= last_head
) {
1523 end
= jiffies
+ (HZ
* 3);
1524 last_head
= dinfo
->ring_head
;
1527 if (time_before(end
, jiffies
)) {
1531 refresh_ring(dinfo
);
1533 end
= jiffies
+ (HZ
* 3);
1536 WRN_MSG("ring buffer : space: %d wanted %d\n",
1537 dinfo
->ring_space
, n
);
1538 WRN_MSG("lockup - turning off hardware "
1540 dinfo
->ring_lockup
= 1;
1549 static void do_flush(struct intelfb_info
*dinfo
)
1552 OUT_RING(MI_FLUSH
| MI_WRITE_DIRTY_STATE
| MI_INVALIDATE_MAP_CACHE
);
1557 void intelfbhw_do_sync(struct intelfb_info
*dinfo
)
1560 DBG_MSG("intelfbhw_do_sync\n");
1567 * Send a flush, then wait until the ring is empty. This is what
1568 * the XFree86 driver does, and actually it doesn't seem a lot worse
1569 * than the recommended method (both have problems).
1572 wait_ring(dinfo
, dinfo
->ring
.size
- RING_MIN_FREE
);
1573 dinfo
->ring_space
= dinfo
->ring
.size
- RING_MIN_FREE
;
1576 static void refresh_ring(struct intelfb_info
*dinfo
)
1579 DBG_MSG("refresh_ring\n");
1582 dinfo
->ring_head
= INREG(PRI_RING_HEAD
) & RING_HEAD_MASK
;
1583 dinfo
->ring_tail
= INREG(PRI_RING_TAIL
) & RING_TAIL_MASK
;
1584 dinfo
->ring_space
= get_ring_space(dinfo
);
1587 static void reset_state(struct intelfb_info
*dinfo
)
1593 DBG_MSG("reset_state\n");
1596 for (i
= 0; i
< FENCE_NUM
; i
++)
1597 OUTREG(FENCE
+ (i
<< 2), 0);
1599 /* Flush the ring buffer if it's enabled. */
1600 tmp
= INREG(PRI_RING_LENGTH
);
1601 if (tmp
& RING_ENABLE
) {
1603 DBG_MSG("reset_state: ring was enabled\n");
1605 refresh_ring(dinfo
);
1606 intelfbhw_do_sync(dinfo
);
1610 OUTREG(PRI_RING_LENGTH
, 0);
1611 OUTREG(PRI_RING_HEAD
, 0);
1612 OUTREG(PRI_RING_TAIL
, 0);
1613 OUTREG(PRI_RING_START
, 0);
1616 /* Stop the 2D engine, and turn off the ring buffer. */
1617 void intelfbhw_2d_stop(struct intelfb_info
*dinfo
)
1620 DBG_MSG("intelfbhw_2d_stop: accel: %d, ring_active: %d\n",
1621 dinfo
->accel
, dinfo
->ring_active
);
1627 dinfo
->ring_active
= 0;
1632 * Enable the ring buffer, and initialise the 2D engine.
1633 * It is assumed that the graphics engine has been stopped by previously
1634 * calling intelfb_2d_stop().
1636 void intelfbhw_2d_start(struct intelfb_info
*dinfo
)
1639 DBG_MSG("intelfbhw_2d_start: accel: %d, ring_active: %d\n",
1640 dinfo
->accel
, dinfo
->ring_active
);
1646 /* Initialise the primary ring buffer. */
1647 OUTREG(PRI_RING_LENGTH
, 0);
1648 OUTREG(PRI_RING_TAIL
, 0);
1649 OUTREG(PRI_RING_HEAD
, 0);
1651 OUTREG(PRI_RING_START
, dinfo
->ring
.physical
& RING_START_MASK
);
1652 OUTREG(PRI_RING_LENGTH
,
1653 ((dinfo
->ring
.size
- GTT_PAGE_SIZE
) & RING_LENGTH_MASK
) |
1654 RING_NO_REPORT
| RING_ENABLE
);
1655 refresh_ring(dinfo
);
1656 dinfo
->ring_active
= 1;
1659 /* 2D fillrect (solid fill or invert) */
1660 void intelfbhw_do_fillrect(struct intelfb_info
*dinfo
, u32 x
, u32 y
, u32 w
,
1661 u32 h
, u32 color
, u32 pitch
, u32 bpp
, u32 rop
)
1663 u32 br00
, br09
, br13
, br14
, br16
;
1666 DBG_MSG("intelfbhw_do_fillrect: (%d,%d) %dx%d, c 0x%06x, p %d bpp %d, "
1667 "rop 0x%02x\n", x
, y
, w
, h
, color
, pitch
, bpp
, rop
);
1670 br00
= COLOR_BLT_CMD
;
1671 br09
= dinfo
->fb_start
+ (y
* pitch
+ x
* (bpp
/ 8));
1672 br13
= (rop
<< ROP_SHIFT
) | pitch
;
1673 br14
= (h
<< HEIGHT_SHIFT
) | ((w
* (bpp
/ 8)) << WIDTH_SHIFT
);
1678 br13
|= COLOR_DEPTH_8
;
1681 br13
|= COLOR_DEPTH_16
;
1684 br13
|= COLOR_DEPTH_32
;
1685 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1699 DBG_MSG("ring = 0x%08x, 0x%08x (%d)\n", dinfo
->ring_head
,
1700 dinfo
->ring_tail
, dinfo
->ring_space
);
1705 intelfbhw_do_bitblt(struct intelfb_info
*dinfo
, u32 curx
, u32 cury
,
1706 u32 dstx
, u32 dsty
, u32 w
, u32 h
, u32 pitch
, u32 bpp
)
1708 u32 br00
, br09
, br11
, br12
, br13
, br22
, br23
, br26
;
1711 DBG_MSG("intelfbhw_do_bitblt: (%d,%d)->(%d,%d) %dx%d, p %d bpp %d\n",
1712 curx
, cury
, dstx
, dsty
, w
, h
, pitch
, bpp
);
1715 br00
= XY_SRC_COPY_BLT_CMD
;
1716 br09
= dinfo
->fb_start
;
1717 br11
= (pitch
<< PITCH_SHIFT
);
1718 br12
= dinfo
->fb_start
;
1719 br13
= (SRC_ROP_GXCOPY
<< ROP_SHIFT
) | (pitch
<< PITCH_SHIFT
);
1720 br22
= (dstx
<< WIDTH_SHIFT
) | (dsty
<< HEIGHT_SHIFT
);
1721 br23
= ((dstx
+ w
) << WIDTH_SHIFT
) |
1722 ((dsty
+ h
) << HEIGHT_SHIFT
);
1723 br26
= (curx
<< WIDTH_SHIFT
) | (cury
<< HEIGHT_SHIFT
);
1727 br13
|= COLOR_DEPTH_8
;
1730 br13
|= COLOR_DEPTH_16
;
1733 br13
|= COLOR_DEPTH_32
;
1734 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1750 int intelfbhw_do_drawglyph(struct intelfb_info
*dinfo
, u32 fg
, u32 bg
, u32 w
,
1751 u32 h
, const u8
* cdat
, u32 x
, u32 y
, u32 pitch
,
1754 int nbytes
, ndwords
, pad
, tmp
;
1755 u32 br00
, br09
, br13
, br18
, br19
, br22
, br23
;
1756 int dat
, ix
, iy
, iw
;
1760 DBG_MSG("intelfbhw_do_drawglyph: (%d,%d) %dx%d\n", x
, y
, w
, h
);
1763 /* size in bytes of a padded scanline */
1764 nbytes
= ROUND_UP_TO(w
, 16) / 8;
1766 /* Total bytes of padded scanline data to write out. */
1767 nbytes
= nbytes
* h
;
1770 * Check if the glyph data exceeds the immediate mode limit.
1771 * It would take a large font (1K pixels) to hit this limit.
1773 if (nbytes
> MAX_MONO_IMM_SIZE
)
1776 /* Src data is packaged a dword (32-bit) at a time. */
1777 ndwords
= ROUND_UP_TO(nbytes
, 4) / 4;
1780 * Ring has to be padded to a quad word. But because the command starts
1781 with 7 bytes, pad only if there is an even number of ndwords
1783 pad
= !(ndwords
% 2);
1785 tmp
= (XY_MONO_SRC_IMM_BLT_CMD
& DW_LENGTH_MASK
) + ndwords
;
1786 br00
= (XY_MONO_SRC_IMM_BLT_CMD
& ~DW_LENGTH_MASK
) | tmp
;
1787 br09
= dinfo
->fb_start
;
1788 br13
= (SRC_ROP_GXCOPY
<< ROP_SHIFT
) | (pitch
<< PITCH_SHIFT
);
1791 br22
= (x
<< WIDTH_SHIFT
) | (y
<< HEIGHT_SHIFT
);
1792 br23
= ((x
+ w
) << WIDTH_SHIFT
) | ((y
+ h
) << HEIGHT_SHIFT
);
1796 br13
|= COLOR_DEPTH_8
;
1799 br13
|= COLOR_DEPTH_16
;
1802 br13
|= COLOR_DEPTH_32
;
1803 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1807 START_RING(8 + ndwords
);
1816 iw
= ROUND_UP_TO(w
, 8) / 8;
1819 for (j
= 0; j
< 2; ++j
) {
1820 for (i
= 0; i
< 2; ++i
) {
1821 if (ix
!= iw
|| i
== 0)
1822 dat
|= cdat
[iy
*iw
+ ix
++] << (i
+j
*2)*8;
1824 if (ix
== iw
&& iy
!= (h
-1)) {
1838 /* HW cursor functions. */
1839 void intelfbhw_cursor_init(struct intelfb_info
*dinfo
)
1844 DBG_MSG("intelfbhw_cursor_init\n");
1847 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1848 if (!dinfo
->cursor
.physical
)
1850 tmp
= INREG(CURSOR_A_CONTROL
);
1851 tmp
&= ~(CURSOR_MODE_MASK
| CURSOR_MOBILE_GAMMA_ENABLE
|
1852 CURSOR_MEM_TYPE_LOCAL
|
1853 (1 << CURSOR_PIPE_SELECT_SHIFT
));
1854 tmp
|= CURSOR_MODE_DISABLE
;
1855 OUTREG(CURSOR_A_CONTROL
, tmp
);
1856 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1858 tmp
= INREG(CURSOR_CONTROL
);
1859 tmp
&= ~(CURSOR_FORMAT_MASK
| CURSOR_GAMMA_ENABLE
|
1860 CURSOR_ENABLE
| CURSOR_STRIDE_MASK
);
1861 tmp
|= CURSOR_FORMAT_3C
;
1862 OUTREG(CURSOR_CONTROL
, tmp
);
1863 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.offset
<< 12);
1864 tmp
= (64 << CURSOR_SIZE_H_SHIFT
) |
1865 (64 << CURSOR_SIZE_V_SHIFT
);
1866 OUTREG(CURSOR_SIZE
, tmp
);
1870 void intelfbhw_cursor_hide(struct intelfb_info
*dinfo
)
1875 DBG_MSG("intelfbhw_cursor_hide\n");
1878 dinfo
->cursor_on
= 0;
1879 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1880 if (!dinfo
->cursor
.physical
)
1882 tmp
= INREG(CURSOR_A_CONTROL
);
1883 tmp
&= ~CURSOR_MODE_MASK
;
1884 tmp
|= CURSOR_MODE_DISABLE
;
1885 OUTREG(CURSOR_A_CONTROL
, tmp
);
1887 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1889 tmp
= INREG(CURSOR_CONTROL
);
1890 tmp
&= ~CURSOR_ENABLE
;
1891 OUTREG(CURSOR_CONTROL
, tmp
);
1895 void intelfbhw_cursor_show(struct intelfb_info
*dinfo
)
1900 DBG_MSG("intelfbhw_cursor_show\n");
1903 dinfo
->cursor_on
= 1;
1905 if (dinfo
->cursor_blanked
)
1908 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1909 if (!dinfo
->cursor
.physical
)
1911 tmp
= INREG(CURSOR_A_CONTROL
);
1912 tmp
&= ~CURSOR_MODE_MASK
;
1913 tmp
|= CURSOR_MODE_64_4C_AX
;
1914 OUTREG(CURSOR_A_CONTROL
, tmp
);
1916 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1918 tmp
= INREG(CURSOR_CONTROL
);
1919 tmp
|= CURSOR_ENABLE
;
1920 OUTREG(CURSOR_CONTROL
, tmp
);
1924 void intelfbhw_cursor_setpos(struct intelfb_info
*dinfo
, int x
, int y
)
1929 DBG_MSG("intelfbhw_cursor_setpos: (%d, %d)\n", x
, y
);
1933 * Sets the position. The coordinates are assumed to already
1934 * have any offset adjusted. Assume that the cursor is never
1935 * completely off-screen, and that x, y are always >= 0.
1938 tmp
= ((x
& CURSOR_POS_MASK
) << CURSOR_X_SHIFT
) |
1939 ((y
& CURSOR_POS_MASK
) << CURSOR_Y_SHIFT
);
1940 OUTREG(CURSOR_A_POSITION
, tmp
);
1943 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1946 void intelfbhw_cursor_setcolor(struct intelfb_info
*dinfo
, u32 bg
, u32 fg
)
1949 DBG_MSG("intelfbhw_cursor_setcolor\n");
1952 OUTREG(CURSOR_A_PALETTE0
, bg
& CURSOR_PALETTE_MASK
);
1953 OUTREG(CURSOR_A_PALETTE1
, fg
& CURSOR_PALETTE_MASK
);
1954 OUTREG(CURSOR_A_PALETTE2
, fg
& CURSOR_PALETTE_MASK
);
1955 OUTREG(CURSOR_A_PALETTE3
, bg
& CURSOR_PALETTE_MASK
);
1958 void intelfbhw_cursor_load(struct intelfb_info
*dinfo
, int width
, int height
,
1961 u8 __iomem
*addr
= (u8 __iomem
*)dinfo
->cursor
.virtual;
1962 int i
, j
, w
= width
/ 8;
1963 int mod
= width
% 8, t_mask
, d_mask
;
1966 DBG_MSG("intelfbhw_cursor_load\n");
1969 if (!dinfo
->cursor
.virtual)
1972 t_mask
= 0xff >> mod
;
1973 d_mask
= ~(0xff >> mod
);
1974 for (i
= height
; i
--; ) {
1975 for (j
= 0; j
< w
; j
++) {
1976 writeb(0x00, addr
+ j
);
1977 writeb(*(data
++), addr
+ j
+8);
1980 writeb(t_mask
, addr
+ j
);
1981 writeb(*(data
++) & d_mask
, addr
+ j
+8);
1987 void intelfbhw_cursor_reset(struct intelfb_info
*dinfo
)
1989 u8 __iomem
*addr
= (u8 __iomem
*)dinfo
->cursor
.virtual;
1993 DBG_MSG("intelfbhw_cursor_reset\n");
1996 if (!dinfo
->cursor
.virtual)
1999 for (i
= 64; i
--; ) {
2000 for (j
= 0; j
< 8; j
++) {
2001 writeb(0xff, addr
+ j
+0);
2002 writeb(0x00, addr
+ j
+8);
2008 static irqreturn_t
intelfbhw_irq(int irq
, void *dev_id
)
2011 struct intelfb_info
*dinfo
= dev_id
;
2013 spin_lock(&dinfo
->int_lock
);
2016 if (dinfo
->info
->var
.vmode
& FB_VMODE_INTERLACED
)
2017 tmp
&= PIPE_A_EVENT_INTERRUPT
;
2019 tmp
&= VSYNC_PIPE_A_INTERRUPT
; /* non-interlaced */
2022 spin_unlock(&dinfo
->int_lock
);
2023 return IRQ_RETVAL(0); /* not us */
2026 /* clear status bits 0-15 ASAP and don't touch bits 16-31 */
2027 OUTREG(PIPEASTAT
, INREG(PIPEASTAT
));
2030 if (dinfo
->vsync
.pan_display
) {
2031 dinfo
->vsync
.pan_display
= 0;
2032 OUTREG(DSPABASE
, dinfo
->vsync
.pan_offset
);
2035 dinfo
->vsync
.count
++;
2036 wake_up_interruptible(&dinfo
->vsync
.wait
);
2038 spin_unlock(&dinfo
->int_lock
);
2040 return IRQ_RETVAL(1);
2043 int intelfbhw_enable_irq(struct intelfb_info
*dinfo
)
2046 if (!test_and_set_bit(0, &dinfo
->irq_flags
)) {
2047 if (request_irq(dinfo
->pdev
->irq
, intelfbhw_irq
, IRQF_SHARED
,
2048 "intelfb", dinfo
)) {
2049 clear_bit(0, &dinfo
->irq_flags
);
2053 spin_lock_irq(&dinfo
->int_lock
);
2054 OUTREG16(HWSTAM
, 0xfffe); /* i830 DRM uses ffff */
2057 spin_lock_irq(&dinfo
->int_lock
);
2059 if (dinfo
->info
->var
.vmode
& FB_VMODE_INTERLACED
)
2060 tmp
= PIPE_A_EVENT_INTERRUPT
;
2062 tmp
= VSYNC_PIPE_A_INTERRUPT
; /* non-interlaced */
2063 if (tmp
!= INREG16(IER
)) {
2064 DBG_MSG("changing IER to 0x%X\n", tmp
);
2068 spin_unlock_irq(&dinfo
->int_lock
);
2072 void intelfbhw_disable_irq(struct intelfb_info
*dinfo
)
2074 if (test_and_clear_bit(0, &dinfo
->irq_flags
)) {
2075 if (dinfo
->vsync
.pan_display
) {
2076 dinfo
->vsync
.pan_display
= 0;
2077 OUTREG(DSPABASE
, dinfo
->vsync
.pan_offset
);
2079 spin_lock_irq(&dinfo
->int_lock
);
2080 OUTREG16(HWSTAM
, 0xffff);
2081 OUTREG16(IMR
, 0xffff);
2084 OUTREG16(IIR
, INREG16(IIR
)); /* clear IRQ requests */
2085 spin_unlock_irq(&dinfo
->int_lock
);
2087 free_irq(dinfo
->pdev
->irq
, dinfo
);
2091 int intelfbhw_wait_for_vsync(struct intelfb_info
*dinfo
, u32 pipe
)
2093 struct intelfb_vsync
*vsync
;
2099 vsync
= &dinfo
->vsync
;
2105 ret
= intelfbhw_enable_irq(dinfo
);
2109 count
= vsync
->count
;
2110 ret
= wait_event_interruptible_timeout(vsync
->wait
,
2111 count
!= vsync
->count
, HZ
/ 10);
2115 DBG_MSG("wait_for_vsync timed out!\n");