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 bridge_dev
= pci_get_domain_bus_and_slot(pci_domain_nr(pdev
->bus
), 0,
187 ERR_MSG("cannot find bridge device\n");
191 /* Get the fb aperture size and "stolen" memory amount. */
193 pci_read_config_word(bridge_dev
, INTEL_GMCH_CTRL
, &tmp
);
194 pci_dev_put(bridge_dev
);
196 switch (pdev
->device
) {
197 case PCI_DEVICE_ID_INTEL_915G
:
198 case PCI_DEVICE_ID_INTEL_915GM
:
199 case PCI_DEVICE_ID_INTEL_945G
:
200 case PCI_DEVICE_ID_INTEL_945GM
:
201 case PCI_DEVICE_ID_INTEL_945GME
:
202 case PCI_DEVICE_ID_INTEL_965G
:
203 case PCI_DEVICE_ID_INTEL_965GM
:
204 /* 915, 945 and 965 chipsets support a 256MB aperture.
205 Aperture size is determined by inspected the
206 base address of the aperture. */
207 if (pci_resource_start(pdev
, 2) & 0x08000000)
208 *aperture_size
= MB(128);
210 *aperture_size
= MB(256);
213 if ((tmp
& INTEL_GMCH_MEM_MASK
) == INTEL_GMCH_MEM_64M
)
214 *aperture_size
= MB(64);
216 *aperture_size
= MB(128);
220 /* Stolen memory size is reduced by the GTT and the popup.
221 GTT is 1K per MB of aperture size, and popup is 4K. */
222 stolen_overhead
= (*aperture_size
/ MB(1)) + 4;
223 switch(pdev
->device
) {
224 case PCI_DEVICE_ID_INTEL_830M
:
225 case PCI_DEVICE_ID_INTEL_845G
:
226 switch (tmp
& INTEL_830_GMCH_GMS_MASK
) {
227 case INTEL_830_GMCH_GMS_STOLEN_512
:
228 *stolen_size
= KB(512) - KB(stolen_overhead
);
230 case INTEL_830_GMCH_GMS_STOLEN_1024
:
231 *stolen_size
= MB(1) - KB(stolen_overhead
);
233 case INTEL_830_GMCH_GMS_STOLEN_8192
:
234 *stolen_size
= MB(8) - KB(stolen_overhead
);
236 case INTEL_830_GMCH_GMS_LOCAL
:
237 ERR_MSG("only local memory found\n");
239 case INTEL_830_GMCH_GMS_DISABLED
:
240 ERR_MSG("video memory is disabled\n");
243 ERR_MSG("unexpected GMCH_GMS value: 0x%02x\n",
244 tmp
& INTEL_830_GMCH_GMS_MASK
);
249 switch (tmp
& INTEL_855_GMCH_GMS_MASK
) {
250 case INTEL_855_GMCH_GMS_STOLEN_1M
:
251 *stolen_size
= MB(1) - KB(stolen_overhead
);
253 case INTEL_855_GMCH_GMS_STOLEN_4M
:
254 *stolen_size
= MB(4) - KB(stolen_overhead
);
256 case INTEL_855_GMCH_GMS_STOLEN_8M
:
257 *stolen_size
= MB(8) - KB(stolen_overhead
);
259 case INTEL_855_GMCH_GMS_STOLEN_16M
:
260 *stolen_size
= MB(16) - KB(stolen_overhead
);
262 case INTEL_855_GMCH_GMS_STOLEN_32M
:
263 *stolen_size
= MB(32) - KB(stolen_overhead
);
265 case INTEL_915G_GMCH_GMS_STOLEN_48M
:
266 *stolen_size
= MB(48) - KB(stolen_overhead
);
268 case INTEL_915G_GMCH_GMS_STOLEN_64M
:
269 *stolen_size
= MB(64) - KB(stolen_overhead
);
271 case INTEL_855_GMCH_GMS_DISABLED
:
272 ERR_MSG("video memory is disabled\n");
275 ERR_MSG("unexpected GMCH_GMS value: 0x%02x\n",
276 tmp
& INTEL_855_GMCH_GMS_MASK
);
282 int intelfbhw_check_non_crt(struct intelfb_info
*dinfo
)
286 if (INREG(LVDS
) & PORT_ENABLE
)
288 if (INREG(DVOA
) & PORT_ENABLE
)
290 if (INREG(DVOB
) & PORT_ENABLE
)
292 if (INREG(DVOC
) & PORT_ENABLE
)
298 const char * intelfbhw_dvo_to_string(int dvo
)
302 else if (dvo
& DVOB_PORT
)
304 else if (dvo
& DVOC_PORT
)
306 else if (dvo
& LVDS_PORT
)
313 int intelfbhw_validate_mode(struct intelfb_info
*dinfo
,
314 struct fb_var_screeninfo
*var
)
320 DBG_MSG("intelfbhw_validate_mode\n");
323 bytes_per_pixel
= var
->bits_per_pixel
/ 8;
324 if (bytes_per_pixel
== 3)
327 /* Check if enough video memory. */
328 tmp
= var
->yres_virtual
* var
->xres_virtual
* bytes_per_pixel
;
329 if (tmp
> dinfo
->fb
.size
) {
330 WRN_MSG("Not enough video ram for mode "
331 "(%d KByte vs %d KByte).\n",
332 BtoKB(tmp
), BtoKB(dinfo
->fb
.size
));
336 /* Check if x/y limits are OK. */
337 if (var
->xres
- 1 > HACTIVE_MASK
) {
338 WRN_MSG("X resolution too large (%d vs %d).\n",
339 var
->xres
, HACTIVE_MASK
+ 1);
342 if (var
->yres
- 1 > VACTIVE_MASK
) {
343 WRN_MSG("Y resolution too large (%d vs %d).\n",
344 var
->yres
, VACTIVE_MASK
+ 1);
348 WRN_MSG("X resolution too small (%d vs 4).\n", var
->xres
);
352 WRN_MSG("Y resolution too small (%d vs 4).\n", var
->yres
);
356 /* Check for doublescan modes. */
357 if (var
->vmode
& FB_VMODE_DOUBLE
) {
358 WRN_MSG("Mode is double-scan.\n");
362 if ((var
->vmode
& FB_VMODE_INTERLACED
) && (var
->yres
& 1)) {
363 WRN_MSG("Odd number of lines in interlaced mode\n");
367 /* Check if clock is OK. */
368 tmp
= 1000000000 / var
->pixclock
;
369 if (tmp
< MIN_CLOCK
) {
370 WRN_MSG("Pixel clock is too low (%d MHz vs %d MHz).\n",
371 (tmp
+ 500) / 1000, MIN_CLOCK
/ 1000);
374 if (tmp
> MAX_CLOCK
) {
375 WRN_MSG("Pixel clock is too high (%d MHz vs %d MHz).\n",
376 (tmp
+ 500) / 1000, MAX_CLOCK
/ 1000);
383 int intelfbhw_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
385 struct intelfb_info
*dinfo
= GET_DINFO(info
);
386 u32 offset
, xoffset
, yoffset
;
389 DBG_MSG("intelfbhw_pan_display\n");
392 xoffset
= ROUND_DOWN_TO(var
->xoffset
, 8);
393 yoffset
= var
->yoffset
;
395 if ((xoffset
+ info
->var
.xres
> info
->var
.xres_virtual
) ||
396 (yoffset
+ info
->var
.yres
> info
->var
.yres_virtual
))
399 offset
= (yoffset
* dinfo
->pitch
) +
400 (xoffset
* info
->var
.bits_per_pixel
) / 8;
402 offset
+= dinfo
->fb
.offset
<< 12;
404 dinfo
->vsync
.pan_offset
= offset
;
405 if ((var
->activate
& FB_ACTIVATE_VBL
) &&
406 !intelfbhw_enable_irq(dinfo
))
407 dinfo
->vsync
.pan_display
= 1;
409 dinfo
->vsync
.pan_display
= 0;
410 OUTREG(DSPABASE
, offset
);
416 /* Blank the screen. */
417 void intelfbhw_do_blank(int blank
, struct fb_info
*info
)
419 struct intelfb_info
*dinfo
= GET_DINFO(info
);
423 DBG_MSG("intelfbhw_do_blank: blank is %d\n", blank
);
426 /* Turn plane A on or off */
427 tmp
= INREG(DSPACNTR
);
429 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
431 tmp
|= DISPPLANE_PLANE_ENABLE
;
432 OUTREG(DSPACNTR
, tmp
);
434 tmp
= INREG(DSPABASE
);
435 OUTREG(DSPABASE
, tmp
);
437 /* Turn off/on the HW cursor */
439 DBG_MSG("cursor_on is %d\n", dinfo
->cursor_on
);
441 if (dinfo
->cursor_on
) {
443 intelfbhw_cursor_hide(dinfo
);
445 intelfbhw_cursor_show(dinfo
);
446 dinfo
->cursor_on
= 1;
448 dinfo
->cursor_blanked
= blank
;
451 tmp
= INREG(ADPA
) & ~ADPA_DPMS_CONTROL_MASK
;
453 case FB_BLANK_UNBLANK
:
454 case FB_BLANK_NORMAL
:
457 case FB_BLANK_VSYNC_SUSPEND
:
460 case FB_BLANK_HSYNC_SUSPEND
:
463 case FB_BLANK_POWERDOWN
:
473 /* Check which pipe is connected to an active display plane. */
474 int intelfbhw_active_pipe(const struct intelfb_hwstate
*hw
)
478 /* keep old default behaviour - prefer PIPE_A */
479 if (hw
->disp_b_ctrl
& DISPPLANE_PLANE_ENABLE
) {
480 pipe
= (hw
->disp_b_ctrl
>> DISPPLANE_SEL_PIPE_SHIFT
);
482 if (unlikely(pipe
== PIPE_A
))
485 if (hw
->disp_a_ctrl
& DISPPLANE_PLANE_ENABLE
) {
486 pipe
= (hw
->disp_a_ctrl
>> DISPPLANE_SEL_PIPE_SHIFT
);
488 if (likely(pipe
== PIPE_A
))
491 /* Impossible that no pipe is selected - return PIPE_A */
493 if (unlikely(pipe
== -1))
499 void intelfbhw_setcolreg(struct intelfb_info
*dinfo
, unsigned regno
,
500 unsigned red
, unsigned green
, unsigned blue
,
503 u32 palette_reg
= (dinfo
->pipe
== PIPE_A
) ?
504 PALETTE_A
: PALETTE_B
;
507 DBG_MSG("intelfbhw_setcolreg: %d: (%d, %d, %d)\n",
508 regno
, red
, green
, blue
);
511 OUTREG(palette_reg
+ (regno
<< 2),
512 (red
<< PALETTE_8_RED_SHIFT
) |
513 (green
<< PALETTE_8_GREEN_SHIFT
) |
514 (blue
<< PALETTE_8_BLUE_SHIFT
));
518 int intelfbhw_read_hw_state(struct intelfb_info
*dinfo
,
519 struct intelfb_hwstate
*hw
, int flag
)
524 DBG_MSG("intelfbhw_read_hw_state\n");
530 /* Read in as much of the HW state as possible. */
531 hw
->vga0_divisor
= INREG(VGA0_DIVISOR
);
532 hw
->vga1_divisor
= INREG(VGA1_DIVISOR
);
533 hw
->vga_pd
= INREG(VGAPD
);
534 hw
->dpll_a
= INREG(DPLL_A
);
535 hw
->dpll_b
= INREG(DPLL_B
);
536 hw
->fpa0
= INREG(FPA0
);
537 hw
->fpa1
= INREG(FPA1
);
538 hw
->fpb0
= INREG(FPB0
);
539 hw
->fpb1
= INREG(FPB1
);
545 /* This seems to be a problem with the 852GM/855GM */
546 for (i
= 0; i
< PALETTE_8_ENTRIES
; i
++) {
547 hw
->palette_a
[i
] = INREG(PALETTE_A
+ (i
<< 2));
548 hw
->palette_b
[i
] = INREG(PALETTE_B
+ (i
<< 2));
555 hw
->htotal_a
= INREG(HTOTAL_A
);
556 hw
->hblank_a
= INREG(HBLANK_A
);
557 hw
->hsync_a
= INREG(HSYNC_A
);
558 hw
->vtotal_a
= INREG(VTOTAL_A
);
559 hw
->vblank_a
= INREG(VBLANK_A
);
560 hw
->vsync_a
= INREG(VSYNC_A
);
561 hw
->src_size_a
= INREG(SRC_SIZE_A
);
562 hw
->bclrpat_a
= INREG(BCLRPAT_A
);
563 hw
->htotal_b
= INREG(HTOTAL_B
);
564 hw
->hblank_b
= INREG(HBLANK_B
);
565 hw
->hsync_b
= INREG(HSYNC_B
);
566 hw
->vtotal_b
= INREG(VTOTAL_B
);
567 hw
->vblank_b
= INREG(VBLANK_B
);
568 hw
->vsync_b
= INREG(VSYNC_B
);
569 hw
->src_size_b
= INREG(SRC_SIZE_B
);
570 hw
->bclrpat_b
= INREG(BCLRPAT_B
);
575 hw
->adpa
= INREG(ADPA
);
576 hw
->dvoa
= INREG(DVOA
);
577 hw
->dvob
= INREG(DVOB
);
578 hw
->dvoc
= INREG(DVOC
);
579 hw
->dvoa_srcdim
= INREG(DVOA_SRCDIM
);
580 hw
->dvob_srcdim
= INREG(DVOB_SRCDIM
);
581 hw
->dvoc_srcdim
= INREG(DVOC_SRCDIM
);
582 hw
->lvds
= INREG(LVDS
);
587 hw
->pipe_a_conf
= INREG(PIPEACONF
);
588 hw
->pipe_b_conf
= INREG(PIPEBCONF
);
589 hw
->disp_arb
= INREG(DISPARB
);
594 hw
->cursor_a_control
= INREG(CURSOR_A_CONTROL
);
595 hw
->cursor_b_control
= INREG(CURSOR_B_CONTROL
);
596 hw
->cursor_a_base
= INREG(CURSOR_A_BASEADDR
);
597 hw
->cursor_b_base
= INREG(CURSOR_B_BASEADDR
);
602 for (i
= 0; i
< 4; i
++) {
603 hw
->cursor_a_palette
[i
] = INREG(CURSOR_A_PALETTE0
+ (i
<< 2));
604 hw
->cursor_b_palette
[i
] = INREG(CURSOR_B_PALETTE0
+ (i
<< 2));
610 hw
->cursor_size
= INREG(CURSOR_SIZE
);
615 hw
->disp_a_ctrl
= INREG(DSPACNTR
);
616 hw
->disp_b_ctrl
= INREG(DSPBCNTR
);
617 hw
->disp_a_base
= INREG(DSPABASE
);
618 hw
->disp_b_base
= INREG(DSPBBASE
);
619 hw
->disp_a_stride
= INREG(DSPASTRIDE
);
620 hw
->disp_b_stride
= INREG(DSPBSTRIDE
);
625 hw
->vgacntrl
= INREG(VGACNTRL
);
630 hw
->add_id
= INREG(ADD_ID
);
635 for (i
= 0; i
< 7; i
++) {
636 hw
->swf0x
[i
] = INREG(SWF00
+ (i
<< 2));
637 hw
->swf1x
[i
] = INREG(SWF10
+ (i
<< 2));
639 hw
->swf3x
[i
] = INREG(SWF30
+ (i
<< 2));
642 for (i
= 0; i
< 8; i
++)
643 hw
->fence
[i
] = INREG(FENCE
+ (i
<< 2));
645 hw
->instpm
= INREG(INSTPM
);
646 hw
->mem_mode
= INREG(MEM_MODE
);
647 hw
->fw_blc_0
= INREG(FW_BLC_0
);
648 hw
->fw_blc_1
= INREG(FW_BLC_1
);
650 hw
->hwstam
= INREG16(HWSTAM
);
651 hw
->ier
= INREG16(IER
);
652 hw
->iir
= INREG16(IIR
);
653 hw
->imr
= INREG16(IMR
);
659 static int calc_vclock3(int index
, int m
, int n
, int p
)
661 if (p
== 0 || n
== 0)
663 return plls
[index
].ref_clk
* m
/ n
/ p
;
666 static int calc_vclock(int index
, int m1
, int m2
, int n
, int p1
, int p2
,
669 struct pll_min_max
*pll
= &plls
[index
];
672 m
= (5 * (m1
+ 2)) + (m2
+ 2);
674 vco
= pll
->ref_clk
* m
/ n
;
676 if (index
== PLLS_I8xx
)
677 p
= ((p1
+ 2) * (1 << (p2
+ 1)));
679 p
= ((p1
) * (p2
? 5 : 10));
684 static void intelfbhw_get_p1p2(struct intelfb_info
*dinfo
, int dpll
,
685 int *o_p1
, int *o_p2
)
689 if (IS_I9XX(dinfo
)) {
690 if (dpll
& DPLL_P1_FORCE_DIV2
)
693 p1
= (dpll
>> DPLL_P1_SHIFT
) & 0xff;
697 p2
= (dpll
>> DPLL_I9XX_P2_SHIFT
) & DPLL_P2_MASK
;
699 if (dpll
& DPLL_P1_FORCE_DIV2
)
702 p1
= (dpll
>> DPLL_P1_SHIFT
) & DPLL_P1_MASK
;
703 p2
= (dpll
>> DPLL_P2_SHIFT
) & DPLL_P2_MASK
;
712 void intelfbhw_print_hw_state(struct intelfb_info
*dinfo
,
713 struct intelfb_hwstate
*hw
)
716 int i
, m1
, m2
, n
, p1
, p2
;
717 int index
= dinfo
->pll_index
;
718 DBG_MSG("intelfbhw_print_hw_state\n");
722 /* Read in as much of the HW state as possible. */
723 printk("hw state dump start\n");
724 printk(" VGA0_DIVISOR: 0x%08x\n", hw
->vga0_divisor
);
725 printk(" VGA1_DIVISOR: 0x%08x\n", hw
->vga1_divisor
);
726 printk(" VGAPD: 0x%08x\n", hw
->vga_pd
);
727 n
= (hw
->vga0_divisor
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
728 m1
= (hw
->vga0_divisor
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
729 m2
= (hw
->vga0_divisor
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
731 intelfbhw_get_p1p2(dinfo
, hw
->vga_pd
, &p1
, &p2
);
733 printk(" VGA0: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
735 printk(" VGA0: clock is %d\n",
736 calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
738 n
= (hw
->vga1_divisor
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
739 m1
= (hw
->vga1_divisor
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
740 m2
= (hw
->vga1_divisor
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
742 intelfbhw_get_p1p2(dinfo
, hw
->vga_pd
, &p1
, &p2
);
743 printk(" VGA1: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
745 printk(" VGA1: clock is %d\n",
746 calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
748 printk(" DPLL_A: 0x%08x\n", hw
->dpll_a
);
749 printk(" DPLL_B: 0x%08x\n", hw
->dpll_b
);
750 printk(" FPA0: 0x%08x\n", hw
->fpa0
);
751 printk(" FPA1: 0x%08x\n", hw
->fpa1
);
752 printk(" FPB0: 0x%08x\n", hw
->fpb0
);
753 printk(" FPB1: 0x%08x\n", hw
->fpb1
);
755 n
= (hw
->fpa0
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
756 m1
= (hw
->fpa0
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
757 m2
= (hw
->fpa0
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
759 intelfbhw_get_p1p2(dinfo
, hw
->dpll_a
, &p1
, &p2
);
761 printk(" PLLA0: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
763 printk(" PLLA0: clock is %d\n",
764 calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
766 n
= (hw
->fpa1
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
767 m1
= (hw
->fpa1
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
768 m2
= (hw
->fpa1
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
770 intelfbhw_get_p1p2(dinfo
, hw
->dpll_a
, &p1
, &p2
);
772 printk(" PLLA1: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
774 printk(" PLLA1: clock is %d\n",
775 calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
778 printk(" PALETTE_A:\n");
779 for (i
= 0; i
< PALETTE_8_ENTRIES
)
780 printk(" %3d: 0x%08x\n", i
, hw
->palette_a
[i
]);
781 printk(" PALETTE_B:\n");
782 for (i
= 0; i
< PALETTE_8_ENTRIES
)
783 printk(" %3d: 0x%08x\n", i
, hw
->palette_b
[i
]);
786 printk(" HTOTAL_A: 0x%08x\n", hw
->htotal_a
);
787 printk(" HBLANK_A: 0x%08x\n", hw
->hblank_a
);
788 printk(" HSYNC_A: 0x%08x\n", hw
->hsync_a
);
789 printk(" VTOTAL_A: 0x%08x\n", hw
->vtotal_a
);
790 printk(" VBLANK_A: 0x%08x\n", hw
->vblank_a
);
791 printk(" VSYNC_A: 0x%08x\n", hw
->vsync_a
);
792 printk(" SRC_SIZE_A: 0x%08x\n", hw
->src_size_a
);
793 printk(" BCLRPAT_A: 0x%08x\n", hw
->bclrpat_a
);
794 printk(" HTOTAL_B: 0x%08x\n", hw
->htotal_b
);
795 printk(" HBLANK_B: 0x%08x\n", hw
->hblank_b
);
796 printk(" HSYNC_B: 0x%08x\n", hw
->hsync_b
);
797 printk(" VTOTAL_B: 0x%08x\n", hw
->vtotal_b
);
798 printk(" VBLANK_B: 0x%08x\n", hw
->vblank_b
);
799 printk(" VSYNC_B: 0x%08x\n", hw
->vsync_b
);
800 printk(" SRC_SIZE_B: 0x%08x\n", hw
->src_size_b
);
801 printk(" BCLRPAT_B: 0x%08x\n", hw
->bclrpat_b
);
803 printk(" ADPA: 0x%08x\n", hw
->adpa
);
804 printk(" DVOA: 0x%08x\n", hw
->dvoa
);
805 printk(" DVOB: 0x%08x\n", hw
->dvob
);
806 printk(" DVOC: 0x%08x\n", hw
->dvoc
);
807 printk(" DVOA_SRCDIM: 0x%08x\n", hw
->dvoa_srcdim
);
808 printk(" DVOB_SRCDIM: 0x%08x\n", hw
->dvob_srcdim
);
809 printk(" DVOC_SRCDIM: 0x%08x\n", hw
->dvoc_srcdim
);
810 printk(" LVDS: 0x%08x\n", hw
->lvds
);
812 printk(" PIPEACONF: 0x%08x\n", hw
->pipe_a_conf
);
813 printk(" PIPEBCONF: 0x%08x\n", hw
->pipe_b_conf
);
814 printk(" DISPARB: 0x%08x\n", hw
->disp_arb
);
816 printk(" CURSOR_A_CONTROL: 0x%08x\n", hw
->cursor_a_control
);
817 printk(" CURSOR_B_CONTROL: 0x%08x\n", hw
->cursor_b_control
);
818 printk(" CURSOR_A_BASEADDR: 0x%08x\n", hw
->cursor_a_base
);
819 printk(" CURSOR_B_BASEADDR: 0x%08x\n", hw
->cursor_b_base
);
821 printk(" CURSOR_A_PALETTE: ");
822 for (i
= 0; i
< 4; i
++) {
823 printk("0x%08x", hw
->cursor_a_palette
[i
]);
828 printk(" CURSOR_B_PALETTE: ");
829 for (i
= 0; i
< 4; i
++) {
830 printk("0x%08x", hw
->cursor_b_palette
[i
]);
836 printk(" CURSOR_SIZE: 0x%08x\n", hw
->cursor_size
);
838 printk(" DSPACNTR: 0x%08x\n", hw
->disp_a_ctrl
);
839 printk(" DSPBCNTR: 0x%08x\n", hw
->disp_b_ctrl
);
840 printk(" DSPABASE: 0x%08x\n", hw
->disp_a_base
);
841 printk(" DSPBBASE: 0x%08x\n", hw
->disp_b_base
);
842 printk(" DSPASTRIDE: 0x%08x\n", hw
->disp_a_stride
);
843 printk(" DSPBSTRIDE: 0x%08x\n", hw
->disp_b_stride
);
845 printk(" VGACNTRL: 0x%08x\n", hw
->vgacntrl
);
846 printk(" ADD_ID: 0x%08x\n", hw
->add_id
);
848 for (i
= 0; i
< 7; i
++) {
849 printk(" SWF0%d 0x%08x\n", i
,
852 for (i
= 0; i
< 7; i
++) {
853 printk(" SWF1%d 0x%08x\n", i
,
856 for (i
= 0; i
< 3; i
++) {
857 printk(" SWF3%d 0x%08x\n", i
,
860 for (i
= 0; i
< 8; i
++)
861 printk(" FENCE%d 0x%08x\n", i
,
864 printk(" INSTPM 0x%08x\n", hw
->instpm
);
865 printk(" MEM_MODE 0x%08x\n", hw
->mem_mode
);
866 printk(" FW_BLC_0 0x%08x\n", hw
->fw_blc_0
);
867 printk(" FW_BLC_1 0x%08x\n", hw
->fw_blc_1
);
869 printk(" HWSTAM 0x%04x\n", hw
->hwstam
);
870 printk(" IER 0x%04x\n", hw
->ier
);
871 printk(" IIR 0x%04x\n", hw
->iir
);
872 printk(" IMR 0x%04x\n", hw
->imr
);
873 printk("hw state dump end\n");
879 /* Split the M parameter into M1 and M2. */
880 static int splitm(int index
, unsigned int m
, unsigned int *retm1
,
885 struct pll_min_max
*pll
= &plls
[index
];
887 /* no point optimising too much - brute force m */
888 for (m1
= pll
->min_m1
; m1
< pll
->max_m1
+ 1; m1
++) {
889 for (m2
= pll
->min_m2
; m2
< pll
->max_m2
+ 1; m2
++) {
890 testm
= (5 * (m1
+ 2)) + (m2
+ 2);
892 *retm1
= (unsigned int)m1
;
893 *retm2
= (unsigned int)m2
;
901 /* Split the P parameter into P1 and P2. */
902 static int splitp(int index
, unsigned int p
, unsigned int *retp1
,
906 struct pll_min_max
*pll
= &plls
[index
];
908 if (index
== PLLS_I9xx
) {
909 p2
= (p
% 10) ? 1 : 0;
911 p1
= p
/ (p2
? 5 : 10);
913 *retp1
= (unsigned int)p1
;
914 *retp2
= (unsigned int)p2
;
922 p1
= (p
/ (1 << (p2
+ 1))) - 2;
923 if (p
% 4 == 0 && p1
< pll
->min_p1
) {
925 p1
= (p
/ (1 << (p2
+ 1))) - 2;
927 if (p1
< pll
->min_p1
|| p1
> pll
->max_p1
||
928 (p1
+ 2) * (1 << (p2
+ 1)) != p
) {
931 *retp1
= (unsigned int)p1
;
932 *retp2
= (unsigned int)p2
;
937 static int calc_pll_params(int index
, int clock
, u32
*retm1
, u32
*retm2
,
938 u32
*retn
, u32
*retp1
, u32
*retp2
, u32
*retclock
)
940 u32 m1
, m2
, n
, p1
, p2
, n1
, testm
;
941 u32 f_vco
, p
, p_best
= 0, m
, f_out
= 0;
942 u32 err_best
= 10000000;
943 u32 n_best
= 0, m_best
= 0, f_err
;
944 u32 p_min
, p_max
, p_inc
, div_max
;
945 struct pll_min_max
*pll
= &plls
[index
];
947 DBG_MSG("Clock is %d\n", clock
);
949 div_max
= pll
->max_vco
/ clock
;
951 p_inc
= (clock
<= pll
->p_transition_clk
) ? pll
->p_inc_lo
: pll
->p_inc_hi
;
953 p_max
= ROUND_DOWN_TO(div_max
, p_inc
);
954 if (p_min
< pll
->min_p
)
956 if (p_max
> pll
->max_p
)
959 DBG_MSG("p range is %d-%d (%d)\n", p_min
, p_max
, p_inc
);
963 if (splitp(index
, p
, &p1
, &p2
)) {
964 WRN_MSG("cannot split p = %d\n", p
);
972 m
= ROUND_UP_TO(f_vco
* n
, pll
->ref_clk
) / pll
->ref_clk
;
977 for (testm
= m
- 1; testm
<= m
; testm
++) {
978 f_out
= calc_vclock3(index
, testm
, n
, p
);
979 if (splitm(index
, testm
, &m1
, &m2
)) {
980 WRN_MSG("cannot split m = %d\n",
985 f_err
= clock
- f_out
;
986 else/* slightly bias the error for bigger clocks */
987 f_err
= f_out
- clock
+ 1;
989 if (f_err
< err_best
) {
997 } while ((n
<= pll
->max_n
) && (f_out
>= clock
));
999 } while ((p
<= p_max
));
1002 WRN_MSG("cannot find parameters for clock %d\n", clock
);
1008 splitm(index
, m
, &m1
, &m2
);
1009 splitp(index
, p
, &p1
, &p2
);
1012 DBG_MSG("m, n, p: %d (%d,%d), %d (%d), %d (%d,%d), "
1013 "f: %d (%d), VCO: %d\n",
1014 m
, m1
, m2
, n
, n1
, p
, p1
, p2
,
1015 calc_vclock3(index
, m
, n
, p
),
1016 calc_vclock(index
, m1
, m2
, n1
, p1
, p2
, 0),
1017 calc_vclock3(index
, m
, n
, p
) * p
);
1023 *retclock
= calc_vclock(index
, m1
, m2
, n1
, p1
, p2
, 0);
1028 static __inline__
int check_overflow(u32 value
, u32 limit
,
1029 const char *description
)
1031 if (value
> limit
) {
1032 WRN_MSG("%s value %d exceeds limit %d\n",
1033 description
, value
, limit
);
1039 /* It is assumed that hw is filled in with the initial state information. */
1040 int intelfbhw_mode_to_hw(struct intelfb_info
*dinfo
,
1041 struct intelfb_hwstate
*hw
,
1042 struct fb_var_screeninfo
*var
)
1044 int pipe
= intelfbhw_active_pipe(hw
);
1045 u32
*dpll
, *fp0
, *fp1
;
1046 u32 m1
, m2
, n
, p1
, p2
, clock_target
, clock
;
1047 u32 hsync_start
, hsync_end
, hblank_start
, hblank_end
, htotal
, hactive
;
1048 u32 vsync_start
, vsync_end
, vblank_start
, vblank_end
, vtotal
, vactive
;
1049 u32 vsync_pol
, hsync_pol
;
1050 u32
*vs
, *vb
, *vt
, *hs
, *hb
, *ht
, *ss
, *pipe_conf
;
1051 u32 stride_alignment
;
1053 DBG_MSG("intelfbhw_mode_to_hw\n");
1056 hw
->vgacntrl
|= VGA_DISABLE
;
1058 /* Set which pipe's registers will be set. */
1059 if (pipe
== PIPE_B
) {
1069 ss
= &hw
->src_size_b
;
1070 pipe_conf
= &hw
->pipe_b_conf
;
1081 ss
= &hw
->src_size_a
;
1082 pipe_conf
= &hw
->pipe_a_conf
;
1085 /* Use ADPA register for sync control. */
1086 hw
->adpa
&= ~ADPA_USE_VGA_HVPOLARITY
;
1089 hsync_pol
= (var
->sync
& FB_SYNC_HOR_HIGH_ACT
) ?
1090 ADPA_SYNC_ACTIVE_HIGH
: ADPA_SYNC_ACTIVE_LOW
;
1091 vsync_pol
= (var
->sync
& FB_SYNC_VERT_HIGH_ACT
) ?
1092 ADPA_SYNC_ACTIVE_HIGH
: ADPA_SYNC_ACTIVE_LOW
;
1093 hw
->adpa
&= ~((ADPA_SYNC_ACTIVE_MASK
<< ADPA_VSYNC_ACTIVE_SHIFT
) |
1094 (ADPA_SYNC_ACTIVE_MASK
<< ADPA_HSYNC_ACTIVE_SHIFT
));
1095 hw
->adpa
|= (hsync_pol
<< ADPA_HSYNC_ACTIVE_SHIFT
) |
1096 (vsync_pol
<< ADPA_VSYNC_ACTIVE_SHIFT
);
1098 /* Connect correct pipe to the analog port DAC */
1099 hw
->adpa
&= ~(PIPE_MASK
<< ADPA_PIPE_SELECT_SHIFT
);
1100 hw
->adpa
|= (pipe
<< ADPA_PIPE_SELECT_SHIFT
);
1102 /* Set DPMS state to D0 (on) */
1103 hw
->adpa
&= ~ADPA_DPMS_CONTROL_MASK
;
1104 hw
->adpa
|= ADPA_DPMS_D0
;
1106 hw
->adpa
|= ADPA_DAC_ENABLE
;
1108 *dpll
|= (DPLL_VCO_ENABLE
| DPLL_VGA_MODE_DISABLE
);
1109 *dpll
&= ~(DPLL_RATE_SELECT_MASK
| DPLL_REFERENCE_SELECT_MASK
);
1110 *dpll
|= (DPLL_REFERENCE_DEFAULT
| DPLL_RATE_SELECT_FP0
);
1112 /* Desired clock in kHz */
1113 clock_target
= 1000000000 / var
->pixclock
;
1115 if (calc_pll_params(dinfo
->pll_index
, clock_target
, &m1
, &m2
,
1116 &n
, &p1
, &p2
, &clock
)) {
1117 WRN_MSG("calc_pll_params failed\n");
1121 /* Check for overflow. */
1122 if (check_overflow(p1
, DPLL_P1_MASK
, "PLL P1 parameter"))
1124 if (check_overflow(p2
, DPLL_P2_MASK
, "PLL P2 parameter"))
1126 if (check_overflow(m1
, FP_DIVISOR_MASK
, "PLL M1 parameter"))
1128 if (check_overflow(m2
, FP_DIVISOR_MASK
, "PLL M2 parameter"))
1130 if (check_overflow(n
, FP_DIVISOR_MASK
, "PLL N parameter"))
1133 *dpll
&= ~DPLL_P1_FORCE_DIV2
;
1134 *dpll
&= ~((DPLL_P2_MASK
<< DPLL_P2_SHIFT
) |
1135 (DPLL_P1_MASK
<< DPLL_P1_SHIFT
));
1137 if (IS_I9XX(dinfo
)) {
1138 *dpll
|= (p2
<< DPLL_I9XX_P2_SHIFT
);
1139 *dpll
|= (1 << (p1
- 1)) << DPLL_P1_SHIFT
;
1141 *dpll
|= (p2
<< DPLL_P2_SHIFT
) | (p1
<< DPLL_P1_SHIFT
);
1143 *fp0
= (n
<< FP_N_DIVISOR_SHIFT
) |
1144 (m1
<< FP_M1_DIVISOR_SHIFT
) |
1145 (m2
<< FP_M2_DIVISOR_SHIFT
);
1148 hw
->dvob
&= ~PORT_ENABLE
;
1149 hw
->dvoc
&= ~PORT_ENABLE
;
1151 /* Use display plane A. */
1152 hw
->disp_a_ctrl
|= DISPPLANE_PLANE_ENABLE
;
1153 hw
->disp_a_ctrl
&= ~DISPPLANE_GAMMA_ENABLE
;
1154 hw
->disp_a_ctrl
&= ~DISPPLANE_PIXFORMAT_MASK
;
1155 switch (intelfb_var_to_depth(var
)) {
1157 hw
->disp_a_ctrl
|= DISPPLANE_8BPP
| DISPPLANE_GAMMA_ENABLE
;
1160 hw
->disp_a_ctrl
|= DISPPLANE_15_16BPP
;
1163 hw
->disp_a_ctrl
|= DISPPLANE_16BPP
;
1166 hw
->disp_a_ctrl
|= DISPPLANE_32BPP_NO_ALPHA
;
1169 hw
->disp_a_ctrl
&= ~(PIPE_MASK
<< DISPPLANE_SEL_PIPE_SHIFT
);
1170 hw
->disp_a_ctrl
|= (pipe
<< DISPPLANE_SEL_PIPE_SHIFT
);
1172 /* Set CRTC registers. */
1173 hactive
= var
->xres
;
1174 hsync_start
= hactive
+ var
->right_margin
;
1175 hsync_end
= hsync_start
+ var
->hsync_len
;
1176 htotal
= hsync_end
+ var
->left_margin
;
1177 hblank_start
= hactive
;
1178 hblank_end
= htotal
;
1180 DBG_MSG("H: act %d, ss %d, se %d, tot %d bs %d, be %d\n",
1181 hactive
, hsync_start
, hsync_end
, htotal
, hblank_start
,
1184 vactive
= var
->yres
;
1185 if (var
->vmode
& FB_VMODE_INTERLACED
)
1186 vactive
--; /* the chip adds 2 halflines automatically */
1187 vsync_start
= vactive
+ var
->lower_margin
;
1188 vsync_end
= vsync_start
+ var
->vsync_len
;
1189 vtotal
= vsync_end
+ var
->upper_margin
;
1190 vblank_start
= vactive
;
1191 vblank_end
= vsync_end
+ 1;
1193 DBG_MSG("V: act %d, ss %d, se %d, tot %d bs %d, be %d\n",
1194 vactive
, vsync_start
, vsync_end
, vtotal
, vblank_start
,
1197 /* Adjust for register values, and check for overflow. */
1199 if (check_overflow(hactive
, HACTIVE_MASK
, "CRTC hactive"))
1202 if (check_overflow(hsync_start
, HSYNCSTART_MASK
, "CRTC hsync_start"))
1205 if (check_overflow(hsync_end
, HSYNCEND_MASK
, "CRTC hsync_end"))
1208 if (check_overflow(htotal
, HTOTAL_MASK
, "CRTC htotal"))
1211 if (check_overflow(hblank_start
, HBLANKSTART_MASK
, "CRTC hblank_start"))
1214 if (check_overflow(hblank_end
, HBLANKEND_MASK
, "CRTC hblank_end"))
1218 if (check_overflow(vactive
, VACTIVE_MASK
, "CRTC vactive"))
1221 if (check_overflow(vsync_start
, VSYNCSTART_MASK
, "CRTC vsync_start"))
1224 if (check_overflow(vsync_end
, VSYNCEND_MASK
, "CRTC vsync_end"))
1227 if (check_overflow(vtotal
, VTOTAL_MASK
, "CRTC vtotal"))
1230 if (check_overflow(vblank_start
, VBLANKSTART_MASK
, "CRTC vblank_start"))
1233 if (check_overflow(vblank_end
, VBLANKEND_MASK
, "CRTC vblank_end"))
1236 *ht
= (htotal
<< HTOTAL_SHIFT
) | (hactive
<< HACTIVE_SHIFT
);
1237 *hb
= (hblank_start
<< HBLANKSTART_SHIFT
) |
1238 (hblank_end
<< HSYNCEND_SHIFT
);
1239 *hs
= (hsync_start
<< HSYNCSTART_SHIFT
) | (hsync_end
<< HSYNCEND_SHIFT
);
1241 *vt
= (vtotal
<< VTOTAL_SHIFT
) | (vactive
<< VACTIVE_SHIFT
);
1242 *vb
= (vblank_start
<< VBLANKSTART_SHIFT
) |
1243 (vblank_end
<< VSYNCEND_SHIFT
);
1244 *vs
= (vsync_start
<< VSYNCSTART_SHIFT
) | (vsync_end
<< VSYNCEND_SHIFT
);
1245 *ss
= (hactive
<< SRC_SIZE_HORIZ_SHIFT
) |
1246 (vactive
<< SRC_SIZE_VERT_SHIFT
);
1248 hw
->disp_a_stride
= dinfo
->pitch
;
1249 DBG_MSG("pitch is %d\n", hw
->disp_a_stride
);
1251 hw
->disp_a_base
= hw
->disp_a_stride
* var
->yoffset
+
1252 var
->xoffset
* var
->bits_per_pixel
/ 8;
1254 hw
->disp_a_base
+= dinfo
->fb
.offset
<< 12;
1256 /* Check stride alignment. */
1257 stride_alignment
= IS_I9XX(dinfo
) ? STRIDE_ALIGNMENT_I9XX
:
1259 if (hw
->disp_a_stride
% stride_alignment
!= 0) {
1260 WRN_MSG("display stride %d has bad alignment %d\n",
1261 hw
->disp_a_stride
, stride_alignment
);
1265 /* Set the palette to 8-bit mode. */
1266 *pipe_conf
&= ~PIPECONF_GAMMA
;
1268 if (var
->vmode
& FB_VMODE_INTERLACED
)
1269 *pipe_conf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
1271 *pipe_conf
&= ~PIPECONF_INTERLACE_MASK
;
1276 /* Program a (non-VGA) video mode. */
1277 int intelfbhw_program_mode(struct intelfb_info
*dinfo
,
1278 const struct intelfb_hwstate
*hw
, int blank
)
1281 const u32
*dpll
, *fp0
, *fp1
, *pipe_conf
;
1282 const u32
*hs
, *ht
, *hb
, *vs
, *vt
, *vb
, *ss
;
1283 u32 dpll_reg
, fp0_reg
, fp1_reg
, pipe_conf_reg
, pipe_stat_reg
;
1284 u32 hsync_reg
, htotal_reg
, hblank_reg
;
1285 u32 vsync_reg
, vtotal_reg
, vblank_reg
;
1287 u32 count
, tmp_val
[3];
1289 /* Assume single pipe */
1292 DBG_MSG("intelfbhw_program_mode\n");
1296 tmp
= INREG(VGACNTRL
);
1298 OUTREG(VGACNTRL
, tmp
);
1300 dinfo
->pipe
= intelfbhw_active_pipe(hw
);
1302 if (dinfo
->pipe
== PIPE_B
) {
1306 pipe_conf
= &hw
->pipe_b_conf
;
1313 ss
= &hw
->src_size_b
;
1317 pipe_conf_reg
= PIPEBCONF
;
1318 pipe_stat_reg
= PIPEBSTAT
;
1319 hsync_reg
= HSYNC_B
;
1320 htotal_reg
= HTOTAL_B
;
1321 hblank_reg
= HBLANK_B
;
1322 vsync_reg
= VSYNC_B
;
1323 vtotal_reg
= VTOTAL_B
;
1324 vblank_reg
= VBLANK_B
;
1325 src_size_reg
= SRC_SIZE_B
;
1330 pipe_conf
= &hw
->pipe_a_conf
;
1337 ss
= &hw
->src_size_a
;
1341 pipe_conf_reg
= PIPEACONF
;
1342 pipe_stat_reg
= PIPEASTAT
;
1343 hsync_reg
= HSYNC_A
;
1344 htotal_reg
= HTOTAL_A
;
1345 hblank_reg
= HBLANK_A
;
1346 vsync_reg
= VSYNC_A
;
1347 vtotal_reg
= VTOTAL_A
;
1348 vblank_reg
= VBLANK_A
;
1349 src_size_reg
= SRC_SIZE_A
;
1353 tmp
= INREG(pipe_conf_reg
);
1354 tmp
&= ~PIPECONF_ENABLE
;
1355 OUTREG(pipe_conf_reg
, tmp
);
1359 tmp_val
[count
% 3] = INREG(PIPEA_DSL
);
1360 if ((tmp_val
[0] == tmp_val
[1]) && (tmp_val
[1] == tmp_val
[2]))
1364 if (count
% 200 == 0) {
1365 tmp
= INREG(pipe_conf_reg
);
1366 tmp
&= ~PIPECONF_ENABLE
;
1367 OUTREG(pipe_conf_reg
, tmp
);
1369 } while (count
< 2000);
1371 OUTREG(ADPA
, INREG(ADPA
) & ~ADPA_DAC_ENABLE
);
1373 /* Disable planes A and B. */
1374 tmp
= INREG(DSPACNTR
);
1375 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
1376 OUTREG(DSPACNTR
, tmp
);
1377 tmp
= INREG(DSPBCNTR
);
1378 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
1379 OUTREG(DSPBCNTR
, tmp
);
1381 /* Wait for vblank. For now, just wait for a 50Hz cycle (20ms)) */
1384 OUTREG(DVOB
, INREG(DVOB
) & ~PORT_ENABLE
);
1385 OUTREG(DVOC
, INREG(DVOC
) & ~PORT_ENABLE
);
1386 OUTREG(ADPA
, INREG(ADPA
) & ~ADPA_DAC_ENABLE
);
1390 tmp
&= ~ADPA_DPMS_CONTROL_MASK
;
1391 tmp
|= ADPA_DPMS_D3
;
1394 /* do some funky magic - xyzzy */
1395 OUTREG(0x61204, 0xabcd0000);
1398 tmp
= INREG(dpll_reg
);
1399 tmp
&= ~DPLL_VCO_ENABLE
;
1400 OUTREG(dpll_reg
, tmp
);
1402 /* Set PLL parameters */
1403 OUTREG(fp0_reg
, *fp0
);
1404 OUTREG(fp1_reg
, *fp1
);
1407 OUTREG(dpll_reg
, *dpll
);
1410 OUTREG(DVOB
, hw
->dvob
);
1411 OUTREG(DVOC
, hw
->dvoc
);
1413 /* undo funky magic */
1414 OUTREG(0x61204, 0x00000000);
1417 OUTREG(ADPA
, INREG(ADPA
) | ADPA_DAC_ENABLE
);
1418 OUTREG(ADPA
, (hw
->adpa
& ~(ADPA_DPMS_CONTROL_MASK
)) | ADPA_DPMS_D3
);
1420 /* Set pipe parameters */
1421 OUTREG(hsync_reg
, *hs
);
1422 OUTREG(hblank_reg
, *hb
);
1423 OUTREG(htotal_reg
, *ht
);
1424 OUTREG(vsync_reg
, *vs
);
1425 OUTREG(vblank_reg
, *vb
);
1426 OUTREG(vtotal_reg
, *vt
);
1427 OUTREG(src_size_reg
, *ss
);
1429 switch (dinfo
->info
->var
.vmode
& (FB_VMODE_INTERLACED
|
1430 FB_VMODE_ODD_FLD_FIRST
)) {
1431 case FB_VMODE_INTERLACED
| FB_VMODE_ODD_FLD_FIRST
:
1432 OUTREG(pipe_stat_reg
, 0xFFFF | PIPESTAT_FLD_EVT_ODD_EN
);
1434 case FB_VMODE_INTERLACED
: /* even lines first */
1435 OUTREG(pipe_stat_reg
, 0xFFFF | PIPESTAT_FLD_EVT_EVEN_EN
);
1437 default: /* non-interlaced */
1438 OUTREG(pipe_stat_reg
, 0xFFFF); /* clear all status bits only */
1441 OUTREG(pipe_conf_reg
, *pipe_conf
| PIPECONF_ENABLE
);
1445 tmp
&= ~ADPA_DPMS_CONTROL_MASK
;
1446 tmp
|= ADPA_DPMS_D0
;
1449 /* setup display plane */
1450 if (dinfo
->pdev
->device
== PCI_DEVICE_ID_INTEL_830M
) {
1452 * i830M errata: the display plane must be enabled
1453 * to allow writes to the other bits in the plane
1456 tmp
= INREG(DSPACNTR
);
1457 if ((tmp
& DISPPLANE_PLANE_ENABLE
) != DISPPLANE_PLANE_ENABLE
) {
1458 tmp
|= DISPPLANE_PLANE_ENABLE
;
1459 OUTREG(DSPACNTR
, tmp
);
1461 hw
->disp_a_ctrl
|DISPPLANE_PLANE_ENABLE
);
1466 OUTREG(DSPACNTR
, hw
->disp_a_ctrl
& ~DISPPLANE_PLANE_ENABLE
);
1467 OUTREG(DSPASTRIDE
, hw
->disp_a_stride
);
1468 OUTREG(DSPABASE
, hw
->disp_a_base
);
1472 tmp
= INREG(DSPACNTR
);
1473 tmp
|= DISPPLANE_PLANE_ENABLE
;
1474 OUTREG(DSPACNTR
, tmp
);
1475 OUTREG(DSPABASE
, hw
->disp_a_base
);
1481 /* forward declarations */
1482 static void refresh_ring(struct intelfb_info
*dinfo
);
1483 static void reset_state(struct intelfb_info
*dinfo
);
1484 static void do_flush(struct intelfb_info
*dinfo
);
1486 static u32
get_ring_space(struct intelfb_info
*dinfo
)
1490 if (dinfo
->ring_tail
>= dinfo
->ring_head
)
1491 ring_space
= dinfo
->ring
.size
-
1492 (dinfo
->ring_tail
- dinfo
->ring_head
);
1494 ring_space
= dinfo
->ring_head
- dinfo
->ring_tail
;
1496 if (ring_space
> RING_MIN_FREE
)
1497 ring_space
-= RING_MIN_FREE
;
1504 static int wait_ring(struct intelfb_info
*dinfo
, int n
)
1508 u32 last_head
= INREG(PRI_RING_HEAD
) & RING_HEAD_MASK
;
1511 DBG_MSG("wait_ring: %d\n", n
);
1514 end
= jiffies
+ (HZ
* 3);
1515 while (dinfo
->ring_space
< n
) {
1516 dinfo
->ring_head
= INREG(PRI_RING_HEAD
) & RING_HEAD_MASK
;
1517 dinfo
->ring_space
= get_ring_space(dinfo
);
1519 if (dinfo
->ring_head
!= last_head
) {
1520 end
= jiffies
+ (HZ
* 3);
1521 last_head
= dinfo
->ring_head
;
1524 if (time_before(end
, jiffies
)) {
1528 refresh_ring(dinfo
);
1530 end
= jiffies
+ (HZ
* 3);
1533 WRN_MSG("ring buffer : space: %d wanted %d\n",
1534 dinfo
->ring_space
, n
);
1535 WRN_MSG("lockup - turning off hardware "
1537 dinfo
->ring_lockup
= 1;
1546 static void do_flush(struct intelfb_info
*dinfo
)
1549 OUT_RING(MI_FLUSH
| MI_WRITE_DIRTY_STATE
| MI_INVALIDATE_MAP_CACHE
);
1554 void intelfbhw_do_sync(struct intelfb_info
*dinfo
)
1557 DBG_MSG("intelfbhw_do_sync\n");
1564 * Send a flush, then wait until the ring is empty. This is what
1565 * the XFree86 driver does, and actually it doesn't seem a lot worse
1566 * than the recommended method (both have problems).
1569 wait_ring(dinfo
, dinfo
->ring
.size
- RING_MIN_FREE
);
1570 dinfo
->ring_space
= dinfo
->ring
.size
- RING_MIN_FREE
;
1573 static void refresh_ring(struct intelfb_info
*dinfo
)
1576 DBG_MSG("refresh_ring\n");
1579 dinfo
->ring_head
= INREG(PRI_RING_HEAD
) & RING_HEAD_MASK
;
1580 dinfo
->ring_tail
= INREG(PRI_RING_TAIL
) & RING_TAIL_MASK
;
1581 dinfo
->ring_space
= get_ring_space(dinfo
);
1584 static void reset_state(struct intelfb_info
*dinfo
)
1590 DBG_MSG("reset_state\n");
1593 for (i
= 0; i
< FENCE_NUM
; i
++)
1594 OUTREG(FENCE
+ (i
<< 2), 0);
1596 /* Flush the ring buffer if it's enabled. */
1597 tmp
= INREG(PRI_RING_LENGTH
);
1598 if (tmp
& RING_ENABLE
) {
1600 DBG_MSG("reset_state: ring was enabled\n");
1602 refresh_ring(dinfo
);
1603 intelfbhw_do_sync(dinfo
);
1607 OUTREG(PRI_RING_LENGTH
, 0);
1608 OUTREG(PRI_RING_HEAD
, 0);
1609 OUTREG(PRI_RING_TAIL
, 0);
1610 OUTREG(PRI_RING_START
, 0);
1613 /* Stop the 2D engine, and turn off the ring buffer. */
1614 void intelfbhw_2d_stop(struct intelfb_info
*dinfo
)
1617 DBG_MSG("intelfbhw_2d_stop: accel: %d, ring_active: %d\n",
1618 dinfo
->accel
, dinfo
->ring_active
);
1624 dinfo
->ring_active
= 0;
1629 * Enable the ring buffer, and initialise the 2D engine.
1630 * It is assumed that the graphics engine has been stopped by previously
1631 * calling intelfb_2d_stop().
1633 void intelfbhw_2d_start(struct intelfb_info
*dinfo
)
1636 DBG_MSG("intelfbhw_2d_start: accel: %d, ring_active: %d\n",
1637 dinfo
->accel
, dinfo
->ring_active
);
1643 /* Initialise the primary ring buffer. */
1644 OUTREG(PRI_RING_LENGTH
, 0);
1645 OUTREG(PRI_RING_TAIL
, 0);
1646 OUTREG(PRI_RING_HEAD
, 0);
1648 OUTREG(PRI_RING_START
, dinfo
->ring
.physical
& RING_START_MASK
);
1649 OUTREG(PRI_RING_LENGTH
,
1650 ((dinfo
->ring
.size
- GTT_PAGE_SIZE
) & RING_LENGTH_MASK
) |
1651 RING_NO_REPORT
| RING_ENABLE
);
1652 refresh_ring(dinfo
);
1653 dinfo
->ring_active
= 1;
1656 /* 2D fillrect (solid fill or invert) */
1657 void intelfbhw_do_fillrect(struct intelfb_info
*dinfo
, u32 x
, u32 y
, u32 w
,
1658 u32 h
, u32 color
, u32 pitch
, u32 bpp
, u32 rop
)
1660 u32 br00
, br09
, br13
, br14
, br16
;
1663 DBG_MSG("intelfbhw_do_fillrect: (%d,%d) %dx%d, c 0x%06x, p %d bpp %d, "
1664 "rop 0x%02x\n", x
, y
, w
, h
, color
, pitch
, bpp
, rop
);
1667 br00
= COLOR_BLT_CMD
;
1668 br09
= dinfo
->fb_start
+ (y
* pitch
+ x
* (bpp
/ 8));
1669 br13
= (rop
<< ROP_SHIFT
) | pitch
;
1670 br14
= (h
<< HEIGHT_SHIFT
) | ((w
* (bpp
/ 8)) << WIDTH_SHIFT
);
1675 br13
|= COLOR_DEPTH_8
;
1678 br13
|= COLOR_DEPTH_16
;
1681 br13
|= COLOR_DEPTH_32
;
1682 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1696 DBG_MSG("ring = 0x%08x, 0x%08x (%d)\n", dinfo
->ring_head
,
1697 dinfo
->ring_tail
, dinfo
->ring_space
);
1702 intelfbhw_do_bitblt(struct intelfb_info
*dinfo
, u32 curx
, u32 cury
,
1703 u32 dstx
, u32 dsty
, u32 w
, u32 h
, u32 pitch
, u32 bpp
)
1705 u32 br00
, br09
, br11
, br12
, br13
, br22
, br23
, br26
;
1708 DBG_MSG("intelfbhw_do_bitblt: (%d,%d)->(%d,%d) %dx%d, p %d bpp %d\n",
1709 curx
, cury
, dstx
, dsty
, w
, h
, pitch
, bpp
);
1712 br00
= XY_SRC_COPY_BLT_CMD
;
1713 br09
= dinfo
->fb_start
;
1714 br11
= (pitch
<< PITCH_SHIFT
);
1715 br12
= dinfo
->fb_start
;
1716 br13
= (SRC_ROP_GXCOPY
<< ROP_SHIFT
) | (pitch
<< PITCH_SHIFT
);
1717 br22
= (dstx
<< WIDTH_SHIFT
) | (dsty
<< HEIGHT_SHIFT
);
1718 br23
= ((dstx
+ w
) << WIDTH_SHIFT
) |
1719 ((dsty
+ h
) << HEIGHT_SHIFT
);
1720 br26
= (curx
<< WIDTH_SHIFT
) | (cury
<< HEIGHT_SHIFT
);
1724 br13
|= COLOR_DEPTH_8
;
1727 br13
|= COLOR_DEPTH_16
;
1730 br13
|= COLOR_DEPTH_32
;
1731 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1747 int intelfbhw_do_drawglyph(struct intelfb_info
*dinfo
, u32 fg
, u32 bg
, u32 w
,
1748 u32 h
, const u8
* cdat
, u32 x
, u32 y
, u32 pitch
,
1751 int nbytes
, ndwords
, pad
, tmp
;
1752 u32 br00
, br09
, br13
, br18
, br19
, br22
, br23
;
1753 int dat
, ix
, iy
, iw
;
1757 DBG_MSG("intelfbhw_do_drawglyph: (%d,%d) %dx%d\n", x
, y
, w
, h
);
1760 /* size in bytes of a padded scanline */
1761 nbytes
= ROUND_UP_TO(w
, 16) / 8;
1763 /* Total bytes of padded scanline data to write out. */
1764 nbytes
= nbytes
* h
;
1767 * Check if the glyph data exceeds the immediate mode limit.
1768 * It would take a large font (1K pixels) to hit this limit.
1770 if (nbytes
> MAX_MONO_IMM_SIZE
)
1773 /* Src data is packaged a dword (32-bit) at a time. */
1774 ndwords
= ROUND_UP_TO(nbytes
, 4) / 4;
1777 * Ring has to be padded to a quad word. But because the command starts
1778 with 7 bytes, pad only if there is an even number of ndwords
1780 pad
= !(ndwords
% 2);
1782 tmp
= (XY_MONO_SRC_IMM_BLT_CMD
& DW_LENGTH_MASK
) + ndwords
;
1783 br00
= (XY_MONO_SRC_IMM_BLT_CMD
& ~DW_LENGTH_MASK
) | tmp
;
1784 br09
= dinfo
->fb_start
;
1785 br13
= (SRC_ROP_GXCOPY
<< ROP_SHIFT
) | (pitch
<< PITCH_SHIFT
);
1788 br22
= (x
<< WIDTH_SHIFT
) | (y
<< HEIGHT_SHIFT
);
1789 br23
= ((x
+ w
) << WIDTH_SHIFT
) | ((y
+ h
) << HEIGHT_SHIFT
);
1793 br13
|= COLOR_DEPTH_8
;
1796 br13
|= COLOR_DEPTH_16
;
1799 br13
|= COLOR_DEPTH_32
;
1800 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1804 START_RING(8 + ndwords
);
1813 iw
= ROUND_UP_TO(w
, 8) / 8;
1816 for (j
= 0; j
< 2; ++j
) {
1817 for (i
= 0; i
< 2; ++i
) {
1818 if (ix
!= iw
|| i
== 0)
1819 dat
|= cdat
[iy
*iw
+ ix
++] << (i
+j
*2)*8;
1821 if (ix
== iw
&& iy
!= (h
-1)) {
1835 /* HW cursor functions. */
1836 void intelfbhw_cursor_init(struct intelfb_info
*dinfo
)
1841 DBG_MSG("intelfbhw_cursor_init\n");
1844 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1845 if (!dinfo
->cursor
.physical
)
1847 tmp
= INREG(CURSOR_A_CONTROL
);
1848 tmp
&= ~(CURSOR_MODE_MASK
| CURSOR_MOBILE_GAMMA_ENABLE
|
1849 CURSOR_MEM_TYPE_LOCAL
|
1850 (1 << CURSOR_PIPE_SELECT_SHIFT
));
1851 tmp
|= CURSOR_MODE_DISABLE
;
1852 OUTREG(CURSOR_A_CONTROL
, tmp
);
1853 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1855 tmp
= INREG(CURSOR_CONTROL
);
1856 tmp
&= ~(CURSOR_FORMAT_MASK
| CURSOR_GAMMA_ENABLE
|
1857 CURSOR_ENABLE
| CURSOR_STRIDE_MASK
);
1858 tmp
|= CURSOR_FORMAT_3C
;
1859 OUTREG(CURSOR_CONTROL
, tmp
);
1860 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.offset
<< 12);
1861 tmp
= (64 << CURSOR_SIZE_H_SHIFT
) |
1862 (64 << CURSOR_SIZE_V_SHIFT
);
1863 OUTREG(CURSOR_SIZE
, tmp
);
1867 void intelfbhw_cursor_hide(struct intelfb_info
*dinfo
)
1872 DBG_MSG("intelfbhw_cursor_hide\n");
1875 dinfo
->cursor_on
= 0;
1876 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1877 if (!dinfo
->cursor
.physical
)
1879 tmp
= INREG(CURSOR_A_CONTROL
);
1880 tmp
&= ~CURSOR_MODE_MASK
;
1881 tmp
|= CURSOR_MODE_DISABLE
;
1882 OUTREG(CURSOR_A_CONTROL
, tmp
);
1884 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1886 tmp
= INREG(CURSOR_CONTROL
);
1887 tmp
&= ~CURSOR_ENABLE
;
1888 OUTREG(CURSOR_CONTROL
, tmp
);
1892 void intelfbhw_cursor_show(struct intelfb_info
*dinfo
)
1897 DBG_MSG("intelfbhw_cursor_show\n");
1900 dinfo
->cursor_on
= 1;
1902 if (dinfo
->cursor_blanked
)
1905 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1906 if (!dinfo
->cursor
.physical
)
1908 tmp
= INREG(CURSOR_A_CONTROL
);
1909 tmp
&= ~CURSOR_MODE_MASK
;
1910 tmp
|= CURSOR_MODE_64_4C_AX
;
1911 OUTREG(CURSOR_A_CONTROL
, tmp
);
1913 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1915 tmp
= INREG(CURSOR_CONTROL
);
1916 tmp
|= CURSOR_ENABLE
;
1917 OUTREG(CURSOR_CONTROL
, tmp
);
1921 void intelfbhw_cursor_setpos(struct intelfb_info
*dinfo
, int x
, int y
)
1926 DBG_MSG("intelfbhw_cursor_setpos: (%d, %d)\n", x
, y
);
1930 * Sets the position. The coordinates are assumed to already
1931 * have any offset adjusted. Assume that the cursor is never
1932 * completely off-screen, and that x, y are always >= 0.
1935 tmp
= ((x
& CURSOR_POS_MASK
) << CURSOR_X_SHIFT
) |
1936 ((y
& CURSOR_POS_MASK
) << CURSOR_Y_SHIFT
);
1937 OUTREG(CURSOR_A_POSITION
, tmp
);
1940 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1943 void intelfbhw_cursor_setcolor(struct intelfb_info
*dinfo
, u32 bg
, u32 fg
)
1946 DBG_MSG("intelfbhw_cursor_setcolor\n");
1949 OUTREG(CURSOR_A_PALETTE0
, bg
& CURSOR_PALETTE_MASK
);
1950 OUTREG(CURSOR_A_PALETTE1
, fg
& CURSOR_PALETTE_MASK
);
1951 OUTREG(CURSOR_A_PALETTE2
, fg
& CURSOR_PALETTE_MASK
);
1952 OUTREG(CURSOR_A_PALETTE3
, bg
& CURSOR_PALETTE_MASK
);
1955 void intelfbhw_cursor_load(struct intelfb_info
*dinfo
, int width
, int height
,
1958 u8 __iomem
*addr
= (u8 __iomem
*)dinfo
->cursor
.virtual;
1959 int i
, j
, w
= width
/ 8;
1960 int mod
= width
% 8, t_mask
, d_mask
;
1963 DBG_MSG("intelfbhw_cursor_load\n");
1966 if (!dinfo
->cursor
.virtual)
1969 t_mask
= 0xff >> mod
;
1970 d_mask
= ~(0xff >> mod
);
1971 for (i
= height
; i
--; ) {
1972 for (j
= 0; j
< w
; j
++) {
1973 writeb(0x00, addr
+ j
);
1974 writeb(*(data
++), addr
+ j
+8);
1977 writeb(t_mask
, addr
+ j
);
1978 writeb(*(data
++) & d_mask
, addr
+ j
+8);
1984 void intelfbhw_cursor_reset(struct intelfb_info
*dinfo
)
1986 u8 __iomem
*addr
= (u8 __iomem
*)dinfo
->cursor
.virtual;
1990 DBG_MSG("intelfbhw_cursor_reset\n");
1993 if (!dinfo
->cursor
.virtual)
1996 for (i
= 64; i
--; ) {
1997 for (j
= 0; j
< 8; j
++) {
1998 writeb(0xff, addr
+ j
+0);
1999 writeb(0x00, addr
+ j
+8);
2005 static irqreturn_t
intelfbhw_irq(int irq
, void *dev_id
)
2008 struct intelfb_info
*dinfo
= dev_id
;
2010 spin_lock(&dinfo
->int_lock
);
2013 if (dinfo
->info
->var
.vmode
& FB_VMODE_INTERLACED
)
2014 tmp
&= PIPE_A_EVENT_INTERRUPT
;
2016 tmp
&= VSYNC_PIPE_A_INTERRUPT
; /* non-interlaced */
2019 spin_unlock(&dinfo
->int_lock
);
2020 return IRQ_RETVAL(0); /* not us */
2023 /* clear status bits 0-15 ASAP and don't touch bits 16-31 */
2024 OUTREG(PIPEASTAT
, INREG(PIPEASTAT
));
2027 if (dinfo
->vsync
.pan_display
) {
2028 dinfo
->vsync
.pan_display
= 0;
2029 OUTREG(DSPABASE
, dinfo
->vsync
.pan_offset
);
2032 dinfo
->vsync
.count
++;
2033 wake_up_interruptible(&dinfo
->vsync
.wait
);
2035 spin_unlock(&dinfo
->int_lock
);
2037 return IRQ_RETVAL(1);
2040 int intelfbhw_enable_irq(struct intelfb_info
*dinfo
)
2043 if (!test_and_set_bit(0, &dinfo
->irq_flags
)) {
2044 if (request_irq(dinfo
->pdev
->irq
, intelfbhw_irq
, IRQF_SHARED
,
2045 "intelfb", dinfo
)) {
2046 clear_bit(0, &dinfo
->irq_flags
);
2050 spin_lock_irq(&dinfo
->int_lock
);
2051 OUTREG16(HWSTAM
, 0xfffe); /* i830 DRM uses ffff */
2054 spin_lock_irq(&dinfo
->int_lock
);
2056 if (dinfo
->info
->var
.vmode
& FB_VMODE_INTERLACED
)
2057 tmp
= PIPE_A_EVENT_INTERRUPT
;
2059 tmp
= VSYNC_PIPE_A_INTERRUPT
; /* non-interlaced */
2060 if (tmp
!= INREG16(IER
)) {
2061 DBG_MSG("changing IER to 0x%X\n", tmp
);
2065 spin_unlock_irq(&dinfo
->int_lock
);
2069 void intelfbhw_disable_irq(struct intelfb_info
*dinfo
)
2071 if (test_and_clear_bit(0, &dinfo
->irq_flags
)) {
2072 if (dinfo
->vsync
.pan_display
) {
2073 dinfo
->vsync
.pan_display
= 0;
2074 OUTREG(DSPABASE
, dinfo
->vsync
.pan_offset
);
2076 spin_lock_irq(&dinfo
->int_lock
);
2077 OUTREG16(HWSTAM
, 0xffff);
2078 OUTREG16(IMR
, 0xffff);
2081 OUTREG16(IIR
, INREG16(IIR
)); /* clear IRQ requests */
2082 spin_unlock_irq(&dinfo
->int_lock
);
2084 free_irq(dinfo
->pdev
->irq
, dinfo
);
2088 int intelfbhw_wait_for_vsync(struct intelfb_info
*dinfo
, u32 pipe
)
2090 struct intelfb_vsync
*vsync
;
2096 vsync
= &dinfo
->vsync
;
2102 ret
= intelfbhw_enable_irq(dinfo
);
2106 count
= vsync
->count
;
2107 ret
= wait_event_interruptible_timeout(vsync
->wait
,
2108 count
!= vsync
->count
, HZ
/ 10);
2112 DBG_MSG("wait_for_vsync timed out!\n");