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/config.h>
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/errno.h>
26 #include <linux/string.h>
28 #include <linux/tty.h>
29 #include <linux/slab.h>
30 #include <linux/delay.h>
32 #include <linux/ioport.h>
33 #include <linux/init.h>
34 #include <linux/pci.h>
35 #include <linux/vmalloc.h>
36 #include <linux/pagemap.h>
41 #include "intelfbhw.h"
44 int min_m
, max_m
, min_m1
, max_m1
;
45 int min_m2
, max_m2
, min_n
, max_n
;
46 int min_p
, max_p
, min_p1
, max_p1
;
47 int min_vco
, max_vco
, p_transition_clk
, ref_clk
;
48 int p_inc_lo
, p_inc_hi
;
55 static struct pll_min_max plls
[PLLS_MAX
] = {
59 930000, 1400000, 165000, 48000,
65 1400000, 2800000, 200000, 96000,
70 intelfbhw_get_chipset(struct pci_dev
*pdev
, struct intelfb_info
*dinfo
)
76 switch (pdev
->device
) {
77 case PCI_DEVICE_ID_INTEL_830M
:
78 dinfo
->name
= "Intel(R) 830M";
79 dinfo
->chipset
= INTEL_830M
;
81 dinfo
->pll_index
= PLLS_I8xx
;
83 case PCI_DEVICE_ID_INTEL_845G
:
84 dinfo
->name
= "Intel(R) 845G";
85 dinfo
->chipset
= INTEL_845G
;
87 dinfo
->pll_index
= PLLS_I8xx
;
89 case PCI_DEVICE_ID_INTEL_85XGM
:
92 dinfo
->pll_index
= PLLS_I8xx
;
93 pci_read_config_dword(pdev
, INTEL_85X_CAPID
, &tmp
);
94 switch ((tmp
>> INTEL_85X_VARIANT_SHIFT
) &
95 INTEL_85X_VARIANT_MASK
) {
96 case INTEL_VAR_855GME
:
97 dinfo
->name
= "Intel(R) 855GME";
98 dinfo
->chipset
= INTEL_855GME
;
100 case INTEL_VAR_855GM
:
101 dinfo
->name
= "Intel(R) 855GM";
102 dinfo
->chipset
= INTEL_855GM
;
104 case INTEL_VAR_852GME
:
105 dinfo
->name
= "Intel(R) 852GME";
106 dinfo
->chipset
= INTEL_852GME
;
108 case INTEL_VAR_852GM
:
109 dinfo
->name
= "Intel(R) 852GM";
110 dinfo
->chipset
= INTEL_852GM
;
113 dinfo
->name
= "Intel(R) 852GM/855GM";
114 dinfo
->chipset
= INTEL_85XGM
;
118 case PCI_DEVICE_ID_INTEL_865G
:
119 dinfo
->name
= "Intel(R) 865G";
120 dinfo
->chipset
= INTEL_865G
;
122 dinfo
->pll_index
= PLLS_I8xx
;
124 case PCI_DEVICE_ID_INTEL_915G
:
125 dinfo
->name
= "Intel(R) 915G";
126 dinfo
->chipset
= INTEL_915G
;
128 dinfo
->pll_index
= PLLS_I9xx
;
130 case PCI_DEVICE_ID_INTEL_915GM
:
131 dinfo
->name
= "Intel(R) 915GM";
132 dinfo
->chipset
= INTEL_915GM
;
134 dinfo
->pll_index
= PLLS_I9xx
;
136 case PCI_DEVICE_ID_INTEL_945G
:
137 dinfo
->name
= "Intel(R) 945G";
138 dinfo
->chipset
= INTEL_945G
;
140 dinfo
->pll_index
= PLLS_I9xx
;
142 case PCI_DEVICE_ID_INTEL_945GM
:
143 dinfo
->name
= "Intel(R) 945GM";
144 dinfo
->chipset
= INTEL_945GM
;
146 dinfo
->pll_index
= PLLS_I9xx
;
154 intelfbhw_get_memory(struct pci_dev
*pdev
, int *aperture_size
,
157 struct pci_dev
*bridge_dev
;
161 if (!pdev
|| !aperture_size
|| !stolen_size
)
164 /* Find the bridge device. It is always 0:0.0 */
165 if (!(bridge_dev
= pci_find_slot(0, PCI_DEVFN(0, 0)))) {
166 ERR_MSG("cannot find bridge device\n");
170 /* Get the fb aperture size and "stolen" memory amount. */
172 pci_read_config_word(bridge_dev
, INTEL_GMCH_CTRL
, &tmp
);
173 switch (pdev
->device
) {
174 case PCI_DEVICE_ID_INTEL_915G
:
175 case PCI_DEVICE_ID_INTEL_915GM
:
176 case PCI_DEVICE_ID_INTEL_945G
:
177 case PCI_DEVICE_ID_INTEL_945GM
:
178 /* 915 and 945 chipsets support a 256MB aperture.
179 Aperture size is determined by inspected the
180 base address of the aperture. */
181 if (pci_resource_start(pdev
, 2) & 0x08000000)
182 *aperture_size
= MB(128);
184 *aperture_size
= MB(256);
187 if ((tmp
& INTEL_GMCH_MEM_MASK
) == INTEL_GMCH_MEM_64M
)
188 *aperture_size
= MB(64);
190 *aperture_size
= MB(128);
194 /* Stolen memory size is reduced by the GTT and the popup.
195 GTT is 1K per MB of aperture size, and popup is 4K. */
196 stolen_overhead
= (*aperture_size
/ MB(1)) + 4;
197 switch(pdev
->device
) {
198 case PCI_DEVICE_ID_INTEL_830M
:
199 case PCI_DEVICE_ID_INTEL_845G
:
200 switch (tmp
& INTEL_830_GMCH_GMS_MASK
) {
201 case INTEL_830_GMCH_GMS_STOLEN_512
:
202 *stolen_size
= KB(512) - KB(stolen_overhead
);
204 case INTEL_830_GMCH_GMS_STOLEN_1024
:
205 *stolen_size
= MB(1) - KB(stolen_overhead
);
207 case INTEL_830_GMCH_GMS_STOLEN_8192
:
208 *stolen_size
= MB(8) - KB(stolen_overhead
);
210 case INTEL_830_GMCH_GMS_LOCAL
:
211 ERR_MSG("only local memory found\n");
213 case INTEL_830_GMCH_GMS_DISABLED
:
214 ERR_MSG("video memory is disabled\n");
217 ERR_MSG("unexpected GMCH_GMS value: 0x%02x\n",
218 tmp
& INTEL_830_GMCH_GMS_MASK
);
223 switch (tmp
& INTEL_855_GMCH_GMS_MASK
) {
224 case INTEL_855_GMCH_GMS_STOLEN_1M
:
225 *stolen_size
= MB(1) - KB(stolen_overhead
);
227 case INTEL_855_GMCH_GMS_STOLEN_4M
:
228 *stolen_size
= MB(4) - KB(stolen_overhead
);
230 case INTEL_855_GMCH_GMS_STOLEN_8M
:
231 *stolen_size
= MB(8) - KB(stolen_overhead
);
233 case INTEL_855_GMCH_GMS_STOLEN_16M
:
234 *stolen_size
= MB(16) - KB(stolen_overhead
);
236 case INTEL_855_GMCH_GMS_STOLEN_32M
:
237 *stolen_size
= MB(32) - KB(stolen_overhead
);
239 case INTEL_915G_GMCH_GMS_STOLEN_48M
:
240 *stolen_size
= MB(48) - KB(stolen_overhead
);
242 case INTEL_915G_GMCH_GMS_STOLEN_64M
:
243 *stolen_size
= MB(64) - KB(stolen_overhead
);
245 case INTEL_855_GMCH_GMS_DISABLED
:
246 ERR_MSG("video memory is disabled\n");
249 ERR_MSG("unexpected GMCH_GMS value: 0x%02x\n",
250 tmp
& INTEL_855_GMCH_GMS_MASK
);
257 intelfbhw_check_non_crt(struct intelfb_info
*dinfo
)
261 if (INREG(LVDS
) & PORT_ENABLE
)
263 if (INREG(DVOA
) & PORT_ENABLE
)
265 if (INREG(DVOB
) & PORT_ENABLE
)
267 if (INREG(DVOC
) & PORT_ENABLE
)
274 intelfbhw_dvo_to_string(int dvo
)
278 else if (dvo
& DVOB_PORT
)
280 else if (dvo
& DVOC_PORT
)
282 else if (dvo
& LVDS_PORT
)
290 intelfbhw_validate_mode(struct intelfb_info
*dinfo
,
291 struct fb_var_screeninfo
*var
)
297 DBG_MSG("intelfbhw_validate_mode\n");
300 bytes_per_pixel
= var
->bits_per_pixel
/ 8;
301 if (bytes_per_pixel
== 3)
304 /* Check if enough video memory. */
305 tmp
= var
->yres_virtual
* var
->xres_virtual
* bytes_per_pixel
;
306 if (tmp
> dinfo
->fb
.size
) {
307 WRN_MSG("Not enough video ram for mode "
308 "(%d KByte vs %d KByte).\n",
309 BtoKB(tmp
), BtoKB(dinfo
->fb
.size
));
313 /* Check if x/y limits are OK. */
314 if (var
->xres
- 1 > HACTIVE_MASK
) {
315 WRN_MSG("X resolution too large (%d vs %d).\n",
316 var
->xres
, HACTIVE_MASK
+ 1);
319 if (var
->yres
- 1 > VACTIVE_MASK
) {
320 WRN_MSG("Y resolution too large (%d vs %d).\n",
321 var
->yres
, VACTIVE_MASK
+ 1);
325 /* Check for interlaced/doublescan modes. */
326 if (var
->vmode
& FB_VMODE_INTERLACED
) {
327 WRN_MSG("Mode is interlaced.\n");
330 if (var
->vmode
& FB_VMODE_DOUBLE
) {
331 WRN_MSG("Mode is double-scan.\n");
335 /* Check if clock is OK. */
336 tmp
= 1000000000 / var
->pixclock
;
337 if (tmp
< MIN_CLOCK
) {
338 WRN_MSG("Pixel clock is too low (%d MHz vs %d MHz).\n",
339 (tmp
+ 500) / 1000, MIN_CLOCK
/ 1000);
342 if (tmp
> MAX_CLOCK
) {
343 WRN_MSG("Pixel clock is too high (%d MHz vs %d MHz).\n",
344 (tmp
+ 500) / 1000, MAX_CLOCK
/ 1000);
352 intelfbhw_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
354 struct intelfb_info
*dinfo
= GET_DINFO(info
);
355 u32 offset
, xoffset
, yoffset
;
358 DBG_MSG("intelfbhw_pan_display\n");
361 xoffset
= ROUND_DOWN_TO(var
->xoffset
, 8);
362 yoffset
= var
->yoffset
;
364 if ((xoffset
+ var
->xres
> var
->xres_virtual
) ||
365 (yoffset
+ var
->yres
> var
->yres_virtual
))
368 offset
= (yoffset
* dinfo
->pitch
) +
369 (xoffset
* var
->bits_per_pixel
) / 8;
371 offset
+= dinfo
->fb
.offset
<< 12;
373 OUTREG(DSPABASE
, offset
);
378 /* Blank the screen. */
380 intelfbhw_do_blank(int blank
, struct fb_info
*info
)
382 struct intelfb_info
*dinfo
= GET_DINFO(info
);
386 DBG_MSG("intelfbhw_do_blank: blank is %d\n", blank
);
389 /* Turn plane A on or off */
390 tmp
= INREG(DSPACNTR
);
392 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
394 tmp
|= DISPPLANE_PLANE_ENABLE
;
395 OUTREG(DSPACNTR
, tmp
);
397 tmp
= INREG(DSPABASE
);
398 OUTREG(DSPABASE
, tmp
);
400 /* Turn off/on the HW cursor */
402 DBG_MSG("cursor_on is %d\n", dinfo
->cursor_on
);
404 if (dinfo
->cursor_on
) {
406 intelfbhw_cursor_hide(dinfo
);
408 intelfbhw_cursor_show(dinfo
);
410 dinfo
->cursor_on
= 1;
412 dinfo
->cursor_blanked
= blank
;
415 tmp
= INREG(ADPA
) & ~ADPA_DPMS_CONTROL_MASK
;
417 case FB_BLANK_UNBLANK
:
418 case FB_BLANK_NORMAL
:
421 case FB_BLANK_VSYNC_SUSPEND
:
424 case FB_BLANK_HSYNC_SUSPEND
:
427 case FB_BLANK_POWERDOWN
:
438 intelfbhw_setcolreg(struct intelfb_info
*dinfo
, unsigned regno
,
439 unsigned red
, unsigned green
, unsigned blue
,
443 DBG_MSG("intelfbhw_setcolreg: %d: (%d, %d, %d)\n",
444 regno
, red
, green
, blue
);
447 u32 palette_reg
= (dinfo
->pipe
== PIPE_A
) ?
448 PALETTE_A
: PALETTE_B
;
450 OUTREG(palette_reg
+ (regno
<< 2),
451 (red
<< PALETTE_8_RED_SHIFT
) |
452 (green
<< PALETTE_8_GREEN_SHIFT
) |
453 (blue
<< PALETTE_8_BLUE_SHIFT
));
458 intelfbhw_read_hw_state(struct intelfb_info
*dinfo
, struct intelfb_hwstate
*hw
,
464 DBG_MSG("intelfbhw_read_hw_state\n");
470 /* Read in as much of the HW state as possible. */
471 hw
->vga0_divisor
= INREG(VGA0_DIVISOR
);
472 hw
->vga1_divisor
= INREG(VGA1_DIVISOR
);
473 hw
->vga_pd
= INREG(VGAPD
);
474 hw
->dpll_a
= INREG(DPLL_A
);
475 hw
->dpll_b
= INREG(DPLL_B
);
476 hw
->fpa0
= INREG(FPA0
);
477 hw
->fpa1
= INREG(FPA1
);
478 hw
->fpb0
= INREG(FPB0
);
479 hw
->fpb1
= INREG(FPB1
);
485 /* This seems to be a problem with the 852GM/855GM */
486 for (i
= 0; i
< PALETTE_8_ENTRIES
; i
++) {
487 hw
->palette_a
[i
] = INREG(PALETTE_A
+ (i
<< 2));
488 hw
->palette_b
[i
] = INREG(PALETTE_B
+ (i
<< 2));
495 hw
->htotal_a
= INREG(HTOTAL_A
);
496 hw
->hblank_a
= INREG(HBLANK_A
);
497 hw
->hsync_a
= INREG(HSYNC_A
);
498 hw
->vtotal_a
= INREG(VTOTAL_A
);
499 hw
->vblank_a
= INREG(VBLANK_A
);
500 hw
->vsync_a
= INREG(VSYNC_A
);
501 hw
->src_size_a
= INREG(SRC_SIZE_A
);
502 hw
->bclrpat_a
= INREG(BCLRPAT_A
);
503 hw
->htotal_b
= INREG(HTOTAL_B
);
504 hw
->hblank_b
= INREG(HBLANK_B
);
505 hw
->hsync_b
= INREG(HSYNC_B
);
506 hw
->vtotal_b
= INREG(VTOTAL_B
);
507 hw
->vblank_b
= INREG(VBLANK_B
);
508 hw
->vsync_b
= INREG(VSYNC_B
);
509 hw
->src_size_b
= INREG(SRC_SIZE_B
);
510 hw
->bclrpat_b
= INREG(BCLRPAT_B
);
515 hw
->adpa
= INREG(ADPA
);
516 hw
->dvoa
= INREG(DVOA
);
517 hw
->dvob
= INREG(DVOB
);
518 hw
->dvoc
= INREG(DVOC
);
519 hw
->dvoa_srcdim
= INREG(DVOA_SRCDIM
);
520 hw
->dvob_srcdim
= INREG(DVOB_SRCDIM
);
521 hw
->dvoc_srcdim
= INREG(DVOC_SRCDIM
);
522 hw
->lvds
= INREG(LVDS
);
527 hw
->pipe_a_conf
= INREG(PIPEACONF
);
528 hw
->pipe_b_conf
= INREG(PIPEBCONF
);
529 hw
->disp_arb
= INREG(DISPARB
);
534 hw
->cursor_a_control
= INREG(CURSOR_A_CONTROL
);
535 hw
->cursor_b_control
= INREG(CURSOR_B_CONTROL
);
536 hw
->cursor_a_base
= INREG(CURSOR_A_BASEADDR
);
537 hw
->cursor_b_base
= INREG(CURSOR_B_BASEADDR
);
542 for (i
= 0; i
< 4; i
++) {
543 hw
->cursor_a_palette
[i
] = INREG(CURSOR_A_PALETTE0
+ (i
<< 2));
544 hw
->cursor_b_palette
[i
] = INREG(CURSOR_B_PALETTE0
+ (i
<< 2));
550 hw
->cursor_size
= INREG(CURSOR_SIZE
);
555 hw
->disp_a_ctrl
= INREG(DSPACNTR
);
556 hw
->disp_b_ctrl
= INREG(DSPBCNTR
);
557 hw
->disp_a_base
= INREG(DSPABASE
);
558 hw
->disp_b_base
= INREG(DSPBBASE
);
559 hw
->disp_a_stride
= INREG(DSPASTRIDE
);
560 hw
->disp_b_stride
= INREG(DSPBSTRIDE
);
565 hw
->vgacntrl
= INREG(VGACNTRL
);
570 hw
->add_id
= INREG(ADD_ID
);
575 for (i
= 0; i
< 7; i
++) {
576 hw
->swf0x
[i
] = INREG(SWF00
+ (i
<< 2));
577 hw
->swf1x
[i
] = INREG(SWF10
+ (i
<< 2));
579 hw
->swf3x
[i
] = INREG(SWF30
+ (i
<< 2));
582 for (i
= 0; i
< 8; i
++)
583 hw
->fence
[i
] = INREG(FENCE
+ (i
<< 2));
585 hw
->instpm
= INREG(INSTPM
);
586 hw
->mem_mode
= INREG(MEM_MODE
);
587 hw
->fw_blc_0
= INREG(FW_BLC_0
);
588 hw
->fw_blc_1
= INREG(FW_BLC_1
);
594 static int calc_vclock3(int index
, int m
, int n
, int p
)
596 if (p
== 0 || n
== 0)
598 return plls
[index
].ref_clk
* m
/ n
/ p
;
601 static int calc_vclock(int index
, int m1
, int m2
, int n
, int p1
, int p2
, int lvds
)
603 struct pll_min_max
*pll
= &plls
[index
];
606 m
= (5 * (m1
+ 2)) + (m2
+ 2);
608 vco
= pll
->ref_clk
* m
/ n
;
610 if (index
== PLLS_I8xx
) {
611 p
= ((p1
+ 2) * (1 << (p2
+ 1)));
613 p
= ((p1
) * (p2
? 5 : 10));
619 intelfbhw_get_p1p2(struct intelfb_info
*dinfo
, int dpll
, int *o_p1
, int *o_p2
)
623 if (IS_I9XX(dinfo
)) {
624 if (dpll
& DPLL_P1_FORCE_DIV2
)
627 p1
= (dpll
>> DPLL_P1_SHIFT
) & 0xff;
631 p2
= (dpll
>> DPLL_I9XX_P2_SHIFT
) & DPLL_P2_MASK
;
633 if (dpll
& DPLL_P1_FORCE_DIV2
)
636 p1
= (dpll
>> DPLL_P1_SHIFT
) & DPLL_P1_MASK
;
637 p2
= (dpll
>> DPLL_P2_SHIFT
) & DPLL_P2_MASK
;
646 intelfbhw_print_hw_state(struct intelfb_info
*dinfo
, struct intelfb_hwstate
*hw
)
649 int i
, m1
, m2
, n
, p1
, p2
;
650 int index
= dinfo
->pll_index
;
651 DBG_MSG("intelfbhw_print_hw_state\n");
655 /* Read in as much of the HW state as possible. */
656 printk("hw state dump start\n");
657 printk(" VGA0_DIVISOR: 0x%08x\n", hw
->vga0_divisor
);
658 printk(" VGA1_DIVISOR: 0x%08x\n", hw
->vga1_divisor
);
659 printk(" VGAPD: 0x%08x\n", hw
->vga_pd
);
660 n
= (hw
->vga0_divisor
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
661 m1
= (hw
->vga0_divisor
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
662 m2
= (hw
->vga0_divisor
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
664 intelfbhw_get_p1p2(dinfo
, hw
->vga_pd
, &p1
, &p2
);
666 printk(" VGA0: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
668 printk(" VGA0: clock is %d\n",
669 calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
671 n
= (hw
->vga1_divisor
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
672 m1
= (hw
->vga1_divisor
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
673 m2
= (hw
->vga1_divisor
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
675 intelfbhw_get_p1p2(dinfo
, hw
->vga_pd
, &p1
, &p2
);
676 printk(" VGA1: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
678 printk(" VGA1: clock is %d\n", calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
680 printk(" DPLL_A: 0x%08x\n", hw
->dpll_a
);
681 printk(" DPLL_B: 0x%08x\n", hw
->dpll_b
);
682 printk(" FPA0: 0x%08x\n", hw
->fpa0
);
683 printk(" FPA1: 0x%08x\n", hw
->fpa1
);
684 printk(" FPB0: 0x%08x\n", hw
->fpb0
);
685 printk(" FPB1: 0x%08x\n", hw
->fpb1
);
687 n
= (hw
->fpa0
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
688 m1
= (hw
->fpa0
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
689 m2
= (hw
->fpa0
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
691 intelfbhw_get_p1p2(dinfo
, hw
->dpll_a
, &p1
, &p2
);
693 printk(" PLLA0: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
695 printk(" PLLA0: clock is %d\n", calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
697 n
= (hw
->fpa1
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
698 m1
= (hw
->fpa1
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
699 m2
= (hw
->fpa1
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
701 intelfbhw_get_p1p2(dinfo
, hw
->dpll_a
, &p1
, &p2
);
703 printk(" PLLA1: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
705 printk(" PLLA1: clock is %d\n", calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
708 printk(" PALETTE_A:\n");
709 for (i
= 0; i
< PALETTE_8_ENTRIES
)
710 printk(" %3d: 0x%08x\n", i
, hw
->palette_a
[i
]);
711 printk(" PALETTE_B:\n");
712 for (i
= 0; i
< PALETTE_8_ENTRIES
)
713 printk(" %3d: 0x%08x\n", i
, hw
->palette_b
[i
]);
716 printk(" HTOTAL_A: 0x%08x\n", hw
->htotal_a
);
717 printk(" HBLANK_A: 0x%08x\n", hw
->hblank_a
);
718 printk(" HSYNC_A: 0x%08x\n", hw
->hsync_a
);
719 printk(" VTOTAL_A: 0x%08x\n", hw
->vtotal_a
);
720 printk(" VBLANK_A: 0x%08x\n", hw
->vblank_a
);
721 printk(" VSYNC_A: 0x%08x\n", hw
->vsync_a
);
722 printk(" SRC_SIZE_A: 0x%08x\n", hw
->src_size_a
);
723 printk(" BCLRPAT_A: 0x%08x\n", hw
->bclrpat_a
);
724 printk(" HTOTAL_B: 0x%08x\n", hw
->htotal_b
);
725 printk(" HBLANK_B: 0x%08x\n", hw
->hblank_b
);
726 printk(" HSYNC_B: 0x%08x\n", hw
->hsync_b
);
727 printk(" VTOTAL_B: 0x%08x\n", hw
->vtotal_b
);
728 printk(" VBLANK_B: 0x%08x\n", hw
->vblank_b
);
729 printk(" VSYNC_B: 0x%08x\n", hw
->vsync_b
);
730 printk(" SRC_SIZE_B: 0x%08x\n", hw
->src_size_b
);
731 printk(" BCLRPAT_B: 0x%08x\n", hw
->bclrpat_b
);
733 printk(" ADPA: 0x%08x\n", hw
->adpa
);
734 printk(" DVOA: 0x%08x\n", hw
->dvoa
);
735 printk(" DVOB: 0x%08x\n", hw
->dvob
);
736 printk(" DVOC: 0x%08x\n", hw
->dvoc
);
737 printk(" DVOA_SRCDIM: 0x%08x\n", hw
->dvoa_srcdim
);
738 printk(" DVOB_SRCDIM: 0x%08x\n", hw
->dvob_srcdim
);
739 printk(" DVOC_SRCDIM: 0x%08x\n", hw
->dvoc_srcdim
);
740 printk(" LVDS: 0x%08x\n", hw
->lvds
);
742 printk(" PIPEACONF: 0x%08x\n", hw
->pipe_a_conf
);
743 printk(" PIPEBCONF: 0x%08x\n", hw
->pipe_b_conf
);
744 printk(" DISPARB: 0x%08x\n", hw
->disp_arb
);
746 printk(" CURSOR_A_CONTROL: 0x%08x\n", hw
->cursor_a_control
);
747 printk(" CURSOR_B_CONTROL: 0x%08x\n", hw
->cursor_b_control
);
748 printk(" CURSOR_A_BASEADDR: 0x%08x\n", hw
->cursor_a_base
);
749 printk(" CURSOR_B_BASEADDR: 0x%08x\n", hw
->cursor_b_base
);
751 printk(" CURSOR_A_PALETTE: ");
752 for (i
= 0; i
< 4; i
++) {
753 printk("0x%08x", hw
->cursor_a_palette
[i
]);
758 printk(" CURSOR_B_PALETTE: ");
759 for (i
= 0; i
< 4; i
++) {
760 printk("0x%08x", hw
->cursor_b_palette
[i
]);
766 printk(" CURSOR_SIZE: 0x%08x\n", hw
->cursor_size
);
768 printk(" DSPACNTR: 0x%08x\n", hw
->disp_a_ctrl
);
769 printk(" DSPBCNTR: 0x%08x\n", hw
->disp_b_ctrl
);
770 printk(" DSPABASE: 0x%08x\n", hw
->disp_a_base
);
771 printk(" DSPBBASE: 0x%08x\n", hw
->disp_b_base
);
772 printk(" DSPASTRIDE: 0x%08x\n", hw
->disp_a_stride
);
773 printk(" DSPBSTRIDE: 0x%08x\n", hw
->disp_b_stride
);
775 printk(" VGACNTRL: 0x%08x\n", hw
->vgacntrl
);
776 printk(" ADD_ID: 0x%08x\n", hw
->add_id
);
778 for (i
= 0; i
< 7; i
++) {
779 printk(" SWF0%d 0x%08x\n", i
,
782 for (i
= 0; i
< 7; i
++) {
783 printk(" SWF1%d 0x%08x\n", i
,
786 for (i
= 0; i
< 3; i
++) {
787 printk(" SWF3%d 0x%08x\n", i
,
790 for (i
= 0; i
< 8; i
++)
791 printk(" FENCE%d 0x%08x\n", i
,
794 printk(" INSTPM 0x%08x\n", hw
->instpm
);
795 printk(" MEM_MODE 0x%08x\n", hw
->mem_mode
);
796 printk(" FW_BLC_0 0x%08x\n", hw
->fw_blc_0
);
797 printk(" FW_BLC_1 0x%08x\n", hw
->fw_blc_1
);
799 printk("hw state dump end\n");
805 /* Split the M parameter into M1 and M2. */
807 splitm(int index
, unsigned int m
, unsigned int *retm1
, unsigned int *retm2
)
811 struct pll_min_max
*pll
= &plls
[index
];
813 /* no point optimising too much - brute force m */
814 for (m1
= pll
->min_m1
; m1
< pll
->max_m1
+ 1; m1
++) {
815 for (m2
= pll
->min_m2
; m2
< pll
->max_m2
+ 1; m2
++) {
816 testm
= (5 * (m1
+ 2)) + (m2
+ 2);
818 *retm1
= (unsigned int)m1
;
819 *retm2
= (unsigned int)m2
;
827 /* Split the P parameter into P1 and P2. */
829 splitp(int index
, unsigned int p
, unsigned int *retp1
, unsigned int *retp2
)
832 struct pll_min_max
*pll
= &plls
[index
];
834 if (index
== PLLS_I9xx
) {
835 p2
= (p
% 10) ? 1 : 0;
837 p1
= p
/ (p2
? 5 : 10);
839 *retp1
= (unsigned int)p1
;
840 *retp2
= (unsigned int)p2
;
848 p1
= (p
/ (1 << (p2
+ 1))) - 2;
849 if (p
% 4 == 0 && p1
< pll
->min_p1
) {
851 p1
= (p
/ (1 << (p2
+ 1))) - 2;
853 if (p1
< pll
->min_p1
|| p1
> pll
->max_p1
||
854 (p1
+ 2) * (1 << (p2
+ 1)) != p
) {
857 *retp1
= (unsigned int)p1
;
858 *retp2
= (unsigned int)p2
;
864 calc_pll_params(int index
, int clock
, u32
*retm1
, u32
*retm2
, u32
*retn
, u32
*retp1
,
865 u32
*retp2
, u32
*retclock
)
867 u32 m1
, m2
, n
, p1
, p2
, n1
, testm
;
868 u32 f_vco
, p
, p_best
= 0, m
, f_out
= 0;
869 u32 err_max
, err_target
, err_best
= 10000000;
870 u32 n_best
= 0, m_best
= 0, f_best
, f_err
;
871 u32 p_min
, p_max
, p_inc
, div_max
;
872 struct pll_min_max
*pll
= &plls
[index
];
874 /* Accept 0.5% difference, but aim for 0.1% */
875 err_max
= 5 * clock
/ 1000;
876 err_target
= clock
/ 1000;
878 DBG_MSG("Clock is %d\n", clock
);
880 div_max
= pll
->max_vco
/ clock
;
882 p_inc
= (clock
<= pll
->p_transition_clk
) ? pll
->p_inc_lo
: pll
->p_inc_hi
;
884 p_max
= ROUND_DOWN_TO(div_max
, p_inc
);
885 if (p_min
< pll
->min_p
)
887 if (p_max
> pll
->max_p
)
890 DBG_MSG("p range is %d-%d (%d)\n", p_min
, p_max
, p_inc
);
894 if (splitp(index
, p
, &p1
, &p2
)) {
895 WRN_MSG("cannot split p = %d\n", p
);
903 m
= ROUND_UP_TO(f_vco
* n
, pll
->ref_clk
) / pll
->ref_clk
;
908 for (testm
= m
- 1; testm
<= m
; testm
++) {
909 f_out
= calc_vclock3(index
, m
, n
, p
);
910 if (splitm(index
, testm
, &m1
, &m2
)) {
911 WRN_MSG("cannot split m = %d\n", m
);
916 f_err
= clock
- f_out
;
917 else/* slightly bias the error for bigger clocks */
918 f_err
= f_out
- clock
+ 1;
920 if (f_err
< err_best
) {
929 } while ((n
<= pll
->max_n
) && (f_out
>= clock
));
931 } while ((p
<= p_max
));
934 WRN_MSG("cannot find parameters for clock %d\n", clock
);
940 splitm(index
, m
, &m1
, &m2
);
941 splitp(index
, p
, &p1
, &p2
);
944 DBG_MSG("m, n, p: %d (%d,%d), %d (%d), %d (%d,%d), "
945 "f: %d (%d), VCO: %d\n",
946 m
, m1
, m2
, n
, n1
, p
, p1
, p2
,
947 calc_vclock3(index
, m
, n
, p
),
948 calc_vclock(index
, m1
, m2
, n1
, p1
, p2
, 0),
949 calc_vclock3(index
, m
, n
, p
) * p
);
955 *retclock
= calc_vclock(index
, m1
, m2
, n1
, p1
, p2
, 0);
960 static __inline__
int
961 check_overflow(u32 value
, u32 limit
, const char *description
)
964 WRN_MSG("%s value %d exceeds limit %d\n",
965 description
, value
, limit
);
971 /* It is assumed that hw is filled in with the initial state information. */
973 intelfbhw_mode_to_hw(struct intelfb_info
*dinfo
, struct intelfb_hwstate
*hw
,
974 struct fb_var_screeninfo
*var
)
977 u32
*dpll
, *fp0
, *fp1
;
978 u32 m1
, m2
, n
, p1
, p2
, clock_target
, clock
;
979 u32 hsync_start
, hsync_end
, hblank_start
, hblank_end
, htotal
, hactive
;
980 u32 vsync_start
, vsync_end
, vblank_start
, vblank_end
, vtotal
, vactive
;
981 u32 vsync_pol
, hsync_pol
;
982 u32
*vs
, *vb
, *vt
, *hs
, *hb
, *ht
, *ss
, *pipe_conf
;
983 u32 stride_alignment
;
985 DBG_MSG("intelfbhw_mode_to_hw\n");
988 hw
->vgacntrl
|= VGA_DISABLE
;
990 /* Check whether pipe A or pipe B is enabled. */
991 if (hw
->pipe_a_conf
& PIPECONF_ENABLE
)
993 else if (hw
->pipe_b_conf
& PIPECONF_ENABLE
)
996 /* Set which pipe's registers will be set. */
997 if (pipe
== PIPE_B
) {
1007 ss
= &hw
->src_size_b
;
1008 pipe_conf
= &hw
->pipe_b_conf
;
1019 ss
= &hw
->src_size_a
;
1020 pipe_conf
= &hw
->pipe_a_conf
;
1023 /* Use ADPA register for sync control. */
1024 hw
->adpa
&= ~ADPA_USE_VGA_HVPOLARITY
;
1027 hsync_pol
= (var
->sync
& FB_SYNC_HOR_HIGH_ACT
) ?
1028 ADPA_SYNC_ACTIVE_HIGH
: ADPA_SYNC_ACTIVE_LOW
;
1029 vsync_pol
= (var
->sync
& FB_SYNC_VERT_HIGH_ACT
) ?
1030 ADPA_SYNC_ACTIVE_HIGH
: ADPA_SYNC_ACTIVE_LOW
;
1031 hw
->adpa
&= ~((ADPA_SYNC_ACTIVE_MASK
<< ADPA_VSYNC_ACTIVE_SHIFT
) |
1032 (ADPA_SYNC_ACTIVE_MASK
<< ADPA_HSYNC_ACTIVE_SHIFT
));
1033 hw
->adpa
|= (hsync_pol
<< ADPA_HSYNC_ACTIVE_SHIFT
) |
1034 (vsync_pol
<< ADPA_VSYNC_ACTIVE_SHIFT
);
1036 /* Connect correct pipe to the analog port DAC */
1037 hw
->adpa
&= ~(PIPE_MASK
<< ADPA_PIPE_SELECT_SHIFT
);
1038 hw
->adpa
|= (pipe
<< ADPA_PIPE_SELECT_SHIFT
);
1040 /* Set DPMS state to D0 (on) */
1041 hw
->adpa
&= ~ADPA_DPMS_CONTROL_MASK
;
1042 hw
->adpa
|= ADPA_DPMS_D0
;
1044 hw
->adpa
|= ADPA_DAC_ENABLE
;
1046 *dpll
|= (DPLL_VCO_ENABLE
| DPLL_VGA_MODE_DISABLE
);
1047 *dpll
&= ~(DPLL_RATE_SELECT_MASK
| DPLL_REFERENCE_SELECT_MASK
);
1048 *dpll
|= (DPLL_REFERENCE_DEFAULT
| DPLL_RATE_SELECT_FP0
);
1050 /* Desired clock in kHz */
1051 clock_target
= 1000000000 / var
->pixclock
;
1053 if (calc_pll_params(dinfo
->pll_index
, clock_target
, &m1
, &m2
,
1054 &n
, &p1
, &p2
, &clock
)) {
1055 WRN_MSG("calc_pll_params failed\n");
1059 /* Check for overflow. */
1060 if (check_overflow(p1
, DPLL_P1_MASK
, "PLL P1 parameter"))
1062 if (check_overflow(p2
, DPLL_P2_MASK
, "PLL P2 parameter"))
1064 if (check_overflow(m1
, FP_DIVISOR_MASK
, "PLL M1 parameter"))
1066 if (check_overflow(m2
, FP_DIVISOR_MASK
, "PLL M2 parameter"))
1068 if (check_overflow(n
, FP_DIVISOR_MASK
, "PLL N parameter"))
1071 *dpll
&= ~DPLL_P1_FORCE_DIV2
;
1072 *dpll
&= ~((DPLL_P2_MASK
<< DPLL_P2_SHIFT
) |
1073 (DPLL_P1_MASK
<< DPLL_P1_SHIFT
));
1075 if (IS_I9XX(dinfo
)) {
1076 *dpll
|= (p2
<< DPLL_I9XX_P2_SHIFT
);
1077 *dpll
|= (1 << (p1
- 1)) << DPLL_P1_SHIFT
;
1079 *dpll
|= (p2
<< DPLL_P2_SHIFT
) | (p1
<< DPLL_P1_SHIFT
);
1082 *fp0
= (n
<< FP_N_DIVISOR_SHIFT
) |
1083 (m1
<< FP_M1_DIVISOR_SHIFT
) |
1084 (m2
<< FP_M2_DIVISOR_SHIFT
);
1087 hw
->dvob
&= ~PORT_ENABLE
;
1088 hw
->dvoc
&= ~PORT_ENABLE
;
1090 /* Use display plane A. */
1091 hw
->disp_a_ctrl
|= DISPPLANE_PLANE_ENABLE
;
1092 hw
->disp_a_ctrl
&= ~DISPPLANE_GAMMA_ENABLE
;
1093 hw
->disp_a_ctrl
&= ~DISPPLANE_PIXFORMAT_MASK
;
1094 switch (intelfb_var_to_depth(var
)) {
1096 hw
->disp_a_ctrl
|= DISPPLANE_8BPP
| DISPPLANE_GAMMA_ENABLE
;
1099 hw
->disp_a_ctrl
|= DISPPLANE_15_16BPP
;
1102 hw
->disp_a_ctrl
|= DISPPLANE_16BPP
;
1105 hw
->disp_a_ctrl
|= DISPPLANE_32BPP_NO_ALPHA
;
1108 hw
->disp_a_ctrl
&= ~(PIPE_MASK
<< DISPPLANE_SEL_PIPE_SHIFT
);
1109 hw
->disp_a_ctrl
|= (pipe
<< DISPPLANE_SEL_PIPE_SHIFT
);
1111 /* Set CRTC registers. */
1112 hactive
= var
->xres
;
1113 hsync_start
= hactive
+ var
->right_margin
;
1114 hsync_end
= hsync_start
+ var
->hsync_len
;
1115 htotal
= hsync_end
+ var
->left_margin
;
1116 hblank_start
= hactive
;
1117 hblank_end
= htotal
;
1119 DBG_MSG("H: act %d, ss %d, se %d, tot %d bs %d, be %d\n",
1120 hactive
, hsync_start
, hsync_end
, htotal
, hblank_start
,
1123 vactive
= var
->yres
;
1124 vsync_start
= vactive
+ var
->lower_margin
;
1125 vsync_end
= vsync_start
+ var
->vsync_len
;
1126 vtotal
= vsync_end
+ var
->upper_margin
;
1127 vblank_start
= vactive
;
1128 vblank_end
= vtotal
;
1129 vblank_end
= vsync_end
+ 1;
1131 DBG_MSG("V: act %d, ss %d, se %d, tot %d bs %d, be %d\n",
1132 vactive
, vsync_start
, vsync_end
, vtotal
, vblank_start
,
1135 /* Adjust for register values, and check for overflow. */
1137 if (check_overflow(hactive
, HACTIVE_MASK
, "CRTC hactive"))
1140 if (check_overflow(hsync_start
, HSYNCSTART_MASK
, "CRTC hsync_start"))
1143 if (check_overflow(hsync_end
, HSYNCEND_MASK
, "CRTC hsync_end"))
1146 if (check_overflow(htotal
, HTOTAL_MASK
, "CRTC htotal"))
1149 if (check_overflow(hblank_start
, HBLANKSTART_MASK
, "CRTC hblank_start"))
1152 if (check_overflow(hblank_end
, HBLANKEND_MASK
, "CRTC hblank_end"))
1156 if (check_overflow(vactive
, VACTIVE_MASK
, "CRTC vactive"))
1159 if (check_overflow(vsync_start
, VSYNCSTART_MASK
, "CRTC vsync_start"))
1162 if (check_overflow(vsync_end
, VSYNCEND_MASK
, "CRTC vsync_end"))
1165 if (check_overflow(vtotal
, VTOTAL_MASK
, "CRTC vtotal"))
1168 if (check_overflow(vblank_start
, VBLANKSTART_MASK
, "CRTC vblank_start"))
1171 if (check_overflow(vblank_end
, VBLANKEND_MASK
, "CRTC vblank_end"))
1174 *ht
= (htotal
<< HTOTAL_SHIFT
) | (hactive
<< HACTIVE_SHIFT
);
1175 *hb
= (hblank_start
<< HBLANKSTART_SHIFT
) |
1176 (hblank_end
<< HSYNCEND_SHIFT
);
1177 *hs
= (hsync_start
<< HSYNCSTART_SHIFT
) | (hsync_end
<< HSYNCEND_SHIFT
);
1179 *vt
= (vtotal
<< VTOTAL_SHIFT
) | (vactive
<< VACTIVE_SHIFT
);
1180 *vb
= (vblank_start
<< VBLANKSTART_SHIFT
) |
1181 (vblank_end
<< VSYNCEND_SHIFT
);
1182 *vs
= (vsync_start
<< VSYNCSTART_SHIFT
) | (vsync_end
<< VSYNCEND_SHIFT
);
1183 *ss
= (hactive
<< SRC_SIZE_HORIZ_SHIFT
) |
1184 (vactive
<< SRC_SIZE_VERT_SHIFT
);
1186 hw
->disp_a_stride
= dinfo
->pitch
;
1187 DBG_MSG("pitch is %d\n", hw
->disp_a_stride
);
1189 hw
->disp_a_base
= hw
->disp_a_stride
* var
->yoffset
+
1190 var
->xoffset
* var
->bits_per_pixel
/ 8;
1192 hw
->disp_a_base
+= dinfo
->fb
.offset
<< 12;
1194 /* Check stride alignment. */
1195 stride_alignment
= IS_I9XX(dinfo
) ? STRIDE_ALIGNMENT_I9XX
:
1197 if (hw
->disp_a_stride
% stride_alignment
!= 0) {
1198 WRN_MSG("display stride %d has bad alignment %d\n",
1199 hw
->disp_a_stride
, stride_alignment
);
1203 /* Set the palette to 8-bit mode. */
1204 *pipe_conf
&= ~PIPECONF_GAMMA
;
1208 /* Program a (non-VGA) video mode. */
1210 intelfbhw_program_mode(struct intelfb_info
*dinfo
,
1211 const struct intelfb_hwstate
*hw
, int blank
)
1215 const u32
*dpll
, *fp0
, *fp1
, *pipe_conf
;
1216 const u32
*hs
, *ht
, *hb
, *vs
, *vt
, *vb
, *ss
;
1217 u32 dpll_reg
, fp0_reg
, fp1_reg
, pipe_conf_reg
;
1218 u32 hsync_reg
, htotal_reg
, hblank_reg
;
1219 u32 vsync_reg
, vtotal_reg
, vblank_reg
;
1221 u32 count
, tmp_val
[3];
1223 /* Assume single pipe, display plane A, analog CRT. */
1226 DBG_MSG("intelfbhw_program_mode\n");
1230 tmp
= INREG(VGACNTRL
);
1232 OUTREG(VGACNTRL
, tmp
);
1234 /* Check whether pipe A or pipe B is enabled. */
1235 if (hw
->pipe_a_conf
& PIPECONF_ENABLE
)
1237 else if (hw
->pipe_b_conf
& PIPECONF_ENABLE
)
1242 if (pipe
== PIPE_B
) {
1246 pipe_conf
= &hw
->pipe_b_conf
;
1253 ss
= &hw
->src_size_b
;
1257 pipe_conf_reg
= PIPEBCONF
;
1258 hsync_reg
= HSYNC_B
;
1259 htotal_reg
= HTOTAL_B
;
1260 hblank_reg
= HBLANK_B
;
1261 vsync_reg
= VSYNC_B
;
1262 vtotal_reg
= VTOTAL_B
;
1263 vblank_reg
= VBLANK_B
;
1264 src_size_reg
= SRC_SIZE_B
;
1269 pipe_conf
= &hw
->pipe_a_conf
;
1276 ss
= &hw
->src_size_a
;
1280 pipe_conf_reg
= PIPEACONF
;
1281 hsync_reg
= HSYNC_A
;
1282 htotal_reg
= HTOTAL_A
;
1283 hblank_reg
= HBLANK_A
;
1284 vsync_reg
= VSYNC_A
;
1285 vtotal_reg
= VTOTAL_A
;
1286 vblank_reg
= VBLANK_A
;
1287 src_size_reg
= SRC_SIZE_A
;
1291 tmp
= INREG(pipe_conf_reg
);
1292 tmp
&= ~PIPECONF_ENABLE
;
1293 OUTREG(pipe_conf_reg
, tmp
);
1297 tmp_val
[count
%3] = INREG(0x70000);
1298 if ((tmp_val
[0] == tmp_val
[1]) && (tmp_val
[1]==tmp_val
[2]))
1302 if (count
% 200 == 0) {
1303 tmp
= INREG(pipe_conf_reg
);
1304 tmp
&= ~PIPECONF_ENABLE
;
1305 OUTREG(pipe_conf_reg
, tmp
);
1307 } while(count
< 2000);
1309 OUTREG(ADPA
, INREG(ADPA
) & ~ADPA_DAC_ENABLE
);
1311 /* Disable planes A and B. */
1312 tmp
= INREG(DSPACNTR
);
1313 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
1314 OUTREG(DSPACNTR
, tmp
);
1315 tmp
= INREG(DSPBCNTR
);
1316 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
1317 OUTREG(DSPBCNTR
, tmp
);
1319 /* Wait for vblank. For now, just wait for a 50Hz cycle (20ms)) */
1322 OUTREG(DVOB
, INREG(DVOB
) & ~PORT_ENABLE
);
1323 OUTREG(DVOC
, INREG(DVOC
) & ~PORT_ENABLE
);
1324 OUTREG(ADPA
, INREG(ADPA
) & ~ADPA_DAC_ENABLE
);
1328 tmp
&= ~ADPA_DPMS_CONTROL_MASK
;
1329 tmp
|= ADPA_DPMS_D3
;
1332 /* do some funky magic - xyzzy */
1333 OUTREG(0x61204, 0xabcd0000);
1336 tmp
= INREG(dpll_reg
);
1337 dpll_reg
&= ~DPLL_VCO_ENABLE
;
1338 OUTREG(dpll_reg
, tmp
);
1340 /* Set PLL parameters */
1341 OUTREG(fp0_reg
, *fp0
);
1342 OUTREG(fp1_reg
, *fp1
);
1345 OUTREG(dpll_reg
, *dpll
);
1348 OUTREG(DVOB
, hw
->dvob
);
1349 OUTREG(DVOC
, hw
->dvoc
);
1351 /* undo funky magic */
1352 OUTREG(0x61204, 0x00000000);
1355 OUTREG(ADPA
, INREG(ADPA
) | ADPA_DAC_ENABLE
);
1356 OUTREG(ADPA
, (hw
->adpa
& ~(ADPA_DPMS_CONTROL_MASK
)) | ADPA_DPMS_D3
);
1358 /* Set pipe parameters */
1359 OUTREG(hsync_reg
, *hs
);
1360 OUTREG(hblank_reg
, *hb
);
1361 OUTREG(htotal_reg
, *ht
);
1362 OUTREG(vsync_reg
, *vs
);
1363 OUTREG(vblank_reg
, *vb
);
1364 OUTREG(vtotal_reg
, *vt
);
1365 OUTREG(src_size_reg
, *ss
);
1368 OUTREG(pipe_conf_reg
, *pipe_conf
| PIPECONF_ENABLE
);
1372 tmp
&= ~ADPA_DPMS_CONTROL_MASK
;
1373 tmp
|= ADPA_DPMS_D0
;
1376 /* setup display plane */
1377 if (dinfo
->pdev
->device
== PCI_DEVICE_ID_INTEL_830M
) {
1379 * i830M errata: the display plane must be enabled
1380 * to allow writes to the other bits in the plane
1383 tmp
= INREG(DSPACNTR
);
1384 if ((tmp
& DISPPLANE_PLANE_ENABLE
) != DISPPLANE_PLANE_ENABLE
) {
1385 tmp
|= DISPPLANE_PLANE_ENABLE
;
1386 OUTREG(DSPACNTR
, tmp
);
1388 hw
->disp_a_ctrl
|DISPPLANE_PLANE_ENABLE
);
1393 OUTREG(DSPACNTR
, hw
->disp_a_ctrl
& ~DISPPLANE_PLANE_ENABLE
);
1394 OUTREG(DSPASTRIDE
, hw
->disp_a_stride
);
1395 OUTREG(DSPABASE
, hw
->disp_a_base
);
1399 tmp
= INREG(DSPACNTR
);
1400 tmp
|= DISPPLANE_PLANE_ENABLE
;
1401 OUTREG(DSPACNTR
, tmp
);
1402 OUTREG(DSPABASE
, hw
->disp_a_base
);
1408 /* forward declarations */
1409 static void refresh_ring(struct intelfb_info
*dinfo
);
1410 static void reset_state(struct intelfb_info
*dinfo
);
1411 static void do_flush(struct intelfb_info
*dinfo
);
1414 wait_ring(struct intelfb_info
*dinfo
, int n
)
1418 u32 last_head
= INREG(PRI_RING_HEAD
) & RING_HEAD_MASK
;
1421 DBG_MSG("wait_ring: %d\n", n
);
1424 end
= jiffies
+ (HZ
* 3);
1425 while (dinfo
->ring_space
< n
) {
1426 dinfo
->ring_head
= (u8 __iomem
*)(INREG(PRI_RING_HEAD
) &
1428 if (dinfo
->ring_tail
+ RING_MIN_FREE
<
1429 (u32 __iomem
) dinfo
->ring_head
)
1430 dinfo
->ring_space
= (u32 __iomem
) dinfo
->ring_head
1431 - (dinfo
->ring_tail
+ RING_MIN_FREE
);
1433 dinfo
->ring_space
= (dinfo
->ring
.size
+
1434 (u32 __iomem
) dinfo
->ring_head
)
1435 - (dinfo
->ring_tail
+ RING_MIN_FREE
);
1436 if ((u32 __iomem
) dinfo
->ring_head
!= last_head
) {
1437 end
= jiffies
+ (HZ
* 3);
1438 last_head
= (u32 __iomem
) dinfo
->ring_head
;
1441 if (time_before(end
, jiffies
)) {
1445 refresh_ring(dinfo
);
1447 end
= jiffies
+ (HZ
* 3);
1450 WRN_MSG("ring buffer : space: %d wanted %d\n",
1451 dinfo
->ring_space
, n
);
1452 WRN_MSG("lockup - turning off hardware "
1454 dinfo
->ring_lockup
= 1;
1464 do_flush(struct intelfb_info
*dinfo
) {
1466 OUT_RING(MI_FLUSH
| MI_WRITE_DIRTY_STATE
| MI_INVALIDATE_MAP_CACHE
);
1472 intelfbhw_do_sync(struct intelfb_info
*dinfo
)
1475 DBG_MSG("intelfbhw_do_sync\n");
1482 * Send a flush, then wait until the ring is empty. This is what
1483 * the XFree86 driver does, and actually it doesn't seem a lot worse
1484 * than the recommended method (both have problems).
1487 wait_ring(dinfo
, dinfo
->ring
.size
- RING_MIN_FREE
);
1488 dinfo
->ring_space
= dinfo
->ring
.size
- RING_MIN_FREE
;
1492 refresh_ring(struct intelfb_info
*dinfo
)
1495 DBG_MSG("refresh_ring\n");
1498 dinfo
->ring_head
= (u8 __iomem
*) (INREG(PRI_RING_HEAD
) &
1500 dinfo
->ring_tail
= INREG(PRI_RING_TAIL
) & RING_TAIL_MASK
;
1501 if (dinfo
->ring_tail
+ RING_MIN_FREE
< (u32 __iomem
)dinfo
->ring_head
)
1502 dinfo
->ring_space
= (u32 __iomem
) dinfo
->ring_head
1503 - (dinfo
->ring_tail
+ RING_MIN_FREE
);
1505 dinfo
->ring_space
= (dinfo
->ring
.size
+
1506 (u32 __iomem
) dinfo
->ring_head
)
1507 - (dinfo
->ring_tail
+ RING_MIN_FREE
);
1511 reset_state(struct intelfb_info
*dinfo
)
1517 DBG_MSG("reset_state\n");
1520 for (i
= 0; i
< FENCE_NUM
; i
++)
1521 OUTREG(FENCE
+ (i
<< 2), 0);
1523 /* Flush the ring buffer if it's enabled. */
1524 tmp
= INREG(PRI_RING_LENGTH
);
1525 if (tmp
& RING_ENABLE
) {
1527 DBG_MSG("reset_state: ring was enabled\n");
1529 refresh_ring(dinfo
);
1530 intelfbhw_do_sync(dinfo
);
1534 OUTREG(PRI_RING_LENGTH
, 0);
1535 OUTREG(PRI_RING_HEAD
, 0);
1536 OUTREG(PRI_RING_TAIL
, 0);
1537 OUTREG(PRI_RING_START
, 0);
1540 /* Stop the 2D engine, and turn off the ring buffer. */
1542 intelfbhw_2d_stop(struct intelfb_info
*dinfo
)
1545 DBG_MSG("intelfbhw_2d_stop: accel: %d, ring_active: %d\n", dinfo
->accel
,
1546 dinfo
->ring_active
);
1552 dinfo
->ring_active
= 0;
1557 * Enable the ring buffer, and initialise the 2D engine.
1558 * It is assumed that the graphics engine has been stopped by previously
1559 * calling intelfb_2d_stop().
1562 intelfbhw_2d_start(struct intelfb_info
*dinfo
)
1565 DBG_MSG("intelfbhw_2d_start: accel: %d, ring_active: %d\n",
1566 dinfo
->accel
, dinfo
->ring_active
);
1572 /* Initialise the primary ring buffer. */
1573 OUTREG(PRI_RING_LENGTH
, 0);
1574 OUTREG(PRI_RING_TAIL
, 0);
1575 OUTREG(PRI_RING_HEAD
, 0);
1577 OUTREG(PRI_RING_START
, dinfo
->ring
.physical
& RING_START_MASK
);
1578 OUTREG(PRI_RING_LENGTH
,
1579 ((dinfo
->ring
.size
- GTT_PAGE_SIZE
) & RING_LENGTH_MASK
) |
1580 RING_NO_REPORT
| RING_ENABLE
);
1581 refresh_ring(dinfo
);
1582 dinfo
->ring_active
= 1;
1585 /* 2D fillrect (solid fill or invert) */
1587 intelfbhw_do_fillrect(struct intelfb_info
*dinfo
, u32 x
, u32 y
, u32 w
, u32 h
,
1588 u32 color
, u32 pitch
, u32 bpp
, u32 rop
)
1590 u32 br00
, br09
, br13
, br14
, br16
;
1593 DBG_MSG("intelfbhw_do_fillrect: (%d,%d) %dx%d, c 0x%06x, p %d bpp %d, "
1594 "rop 0x%02x\n", x
, y
, w
, h
, color
, pitch
, bpp
, rop
);
1597 br00
= COLOR_BLT_CMD
;
1598 br09
= dinfo
->fb_start
+ (y
* pitch
+ x
* (bpp
/ 8));
1599 br13
= (rop
<< ROP_SHIFT
) | pitch
;
1600 br14
= (h
<< HEIGHT_SHIFT
) | ((w
* (bpp
/ 8)) << WIDTH_SHIFT
);
1605 br13
|= COLOR_DEPTH_8
;
1608 br13
|= COLOR_DEPTH_16
;
1611 br13
|= COLOR_DEPTH_32
;
1612 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1626 DBG_MSG("ring = 0x%08x, 0x%08x (%d)\n", dinfo
->ring_head
,
1627 dinfo
->ring_tail
, dinfo
->ring_space
);
1632 intelfbhw_do_bitblt(struct intelfb_info
*dinfo
, u32 curx
, u32 cury
,
1633 u32 dstx
, u32 dsty
, u32 w
, u32 h
, u32 pitch
, u32 bpp
)
1635 u32 br00
, br09
, br11
, br12
, br13
, br22
, br23
, br26
;
1638 DBG_MSG("intelfbhw_do_bitblt: (%d,%d)->(%d,%d) %dx%d, p %d bpp %d\n",
1639 curx
, cury
, dstx
, dsty
, w
, h
, pitch
, bpp
);
1642 br00
= XY_SRC_COPY_BLT_CMD
;
1643 br09
= dinfo
->fb_start
;
1644 br11
= (pitch
<< PITCH_SHIFT
);
1645 br12
= dinfo
->fb_start
;
1646 br13
= (SRC_ROP_GXCOPY
<< ROP_SHIFT
) | (pitch
<< PITCH_SHIFT
);
1647 br22
= (dstx
<< WIDTH_SHIFT
) | (dsty
<< HEIGHT_SHIFT
);
1648 br23
= ((dstx
+ w
) << WIDTH_SHIFT
) |
1649 ((dsty
+ h
) << HEIGHT_SHIFT
);
1650 br26
= (curx
<< WIDTH_SHIFT
) | (cury
<< HEIGHT_SHIFT
);
1654 br13
|= COLOR_DEPTH_8
;
1657 br13
|= COLOR_DEPTH_16
;
1660 br13
|= COLOR_DEPTH_32
;
1661 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1678 intelfbhw_do_drawglyph(struct intelfb_info
*dinfo
, u32 fg
, u32 bg
, u32 w
,
1679 u32 h
, const u8
* cdat
, u32 x
, u32 y
, u32 pitch
, u32 bpp
)
1681 int nbytes
, ndwords
, pad
, tmp
;
1682 u32 br00
, br09
, br13
, br18
, br19
, br22
, br23
;
1683 int dat
, ix
, iy
, iw
;
1687 DBG_MSG("intelfbhw_do_drawglyph: (%d,%d) %dx%d\n", x
, y
, w
, h
);
1690 /* size in bytes of a padded scanline */
1691 nbytes
= ROUND_UP_TO(w
, 16) / 8;
1693 /* Total bytes of padded scanline data to write out. */
1694 nbytes
= nbytes
* h
;
1697 * Check if the glyph data exceeds the immediate mode limit.
1698 * It would take a large font (1K pixels) to hit this limit.
1700 if (nbytes
> MAX_MONO_IMM_SIZE
)
1703 /* Src data is packaged a dword (32-bit) at a time. */
1704 ndwords
= ROUND_UP_TO(nbytes
, 4) / 4;
1707 * Ring has to be padded to a quad word. But because the command starts
1708 with 7 bytes, pad only if there is an even number of ndwords
1710 pad
= !(ndwords
% 2);
1712 tmp
= (XY_MONO_SRC_IMM_BLT_CMD
& DW_LENGTH_MASK
) + ndwords
;
1713 br00
= (XY_MONO_SRC_IMM_BLT_CMD
& ~DW_LENGTH_MASK
) | tmp
;
1714 br09
= dinfo
->fb_start
;
1715 br13
= (SRC_ROP_GXCOPY
<< ROP_SHIFT
) | (pitch
<< PITCH_SHIFT
);
1718 br22
= (x
<< WIDTH_SHIFT
) | (y
<< HEIGHT_SHIFT
);
1719 br23
= ((x
+ w
) << WIDTH_SHIFT
) | ((y
+ h
) << HEIGHT_SHIFT
);
1723 br13
|= COLOR_DEPTH_8
;
1726 br13
|= COLOR_DEPTH_16
;
1729 br13
|= COLOR_DEPTH_32
;
1730 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1734 START_RING(8 + ndwords
);
1743 iw
= ROUND_UP_TO(w
, 8) / 8;
1746 for (j
= 0; j
< 2; ++j
) {
1747 for (i
= 0; i
< 2; ++i
) {
1748 if (ix
!= iw
|| i
== 0)
1749 dat
|= cdat
[iy
*iw
+ ix
++] << (i
+j
*2)*8;
1751 if (ix
== iw
&& iy
!= (h
-1)) {
1765 /* HW cursor functions. */
1767 intelfbhw_cursor_init(struct intelfb_info
*dinfo
)
1772 DBG_MSG("intelfbhw_cursor_init\n");
1775 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1776 if (!dinfo
->cursor
.physical
)
1778 tmp
= INREG(CURSOR_A_CONTROL
);
1779 tmp
&= ~(CURSOR_MODE_MASK
| CURSOR_MOBILE_GAMMA_ENABLE
|
1780 CURSOR_MEM_TYPE_LOCAL
|
1781 (1 << CURSOR_PIPE_SELECT_SHIFT
));
1782 tmp
|= CURSOR_MODE_DISABLE
;
1783 OUTREG(CURSOR_A_CONTROL
, tmp
);
1784 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1786 tmp
= INREG(CURSOR_CONTROL
);
1787 tmp
&= ~(CURSOR_FORMAT_MASK
| CURSOR_GAMMA_ENABLE
|
1788 CURSOR_ENABLE
| CURSOR_STRIDE_MASK
);
1789 tmp
= CURSOR_FORMAT_3C
;
1790 OUTREG(CURSOR_CONTROL
, tmp
);
1791 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.offset
<< 12);
1792 tmp
= (64 << CURSOR_SIZE_H_SHIFT
) |
1793 (64 << CURSOR_SIZE_V_SHIFT
);
1794 OUTREG(CURSOR_SIZE
, tmp
);
1799 intelfbhw_cursor_hide(struct intelfb_info
*dinfo
)
1804 DBG_MSG("intelfbhw_cursor_hide\n");
1807 dinfo
->cursor_on
= 0;
1808 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1809 if (!dinfo
->cursor
.physical
)
1811 tmp
= INREG(CURSOR_A_CONTROL
);
1812 tmp
&= ~CURSOR_MODE_MASK
;
1813 tmp
|= CURSOR_MODE_DISABLE
;
1814 OUTREG(CURSOR_A_CONTROL
, tmp
);
1816 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1818 tmp
= INREG(CURSOR_CONTROL
);
1819 tmp
&= ~CURSOR_ENABLE
;
1820 OUTREG(CURSOR_CONTROL
, tmp
);
1825 intelfbhw_cursor_show(struct intelfb_info
*dinfo
)
1830 DBG_MSG("intelfbhw_cursor_show\n");
1833 dinfo
->cursor_on
= 1;
1835 if (dinfo
->cursor_blanked
)
1838 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1839 if (!dinfo
->cursor
.physical
)
1841 tmp
= INREG(CURSOR_A_CONTROL
);
1842 tmp
&= ~CURSOR_MODE_MASK
;
1843 tmp
|= CURSOR_MODE_64_4C_AX
;
1844 OUTREG(CURSOR_A_CONTROL
, tmp
);
1846 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1848 tmp
= INREG(CURSOR_CONTROL
);
1849 tmp
|= CURSOR_ENABLE
;
1850 OUTREG(CURSOR_CONTROL
, tmp
);
1855 intelfbhw_cursor_setpos(struct intelfb_info
*dinfo
, int x
, int y
)
1860 DBG_MSG("intelfbhw_cursor_setpos: (%d, %d)\n", x
, y
);
1864 * Sets the position. The coordinates are assumed to already
1865 * have any offset adjusted. Assume that the cursor is never
1866 * completely off-screen, and that x, y are always >= 0.
1869 tmp
= ((x
& CURSOR_POS_MASK
) << CURSOR_X_SHIFT
) |
1870 ((y
& CURSOR_POS_MASK
) << CURSOR_Y_SHIFT
);
1871 OUTREG(CURSOR_A_POSITION
, tmp
);
1873 if (IS_I9XX(dinfo
)) {
1874 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1879 intelfbhw_cursor_setcolor(struct intelfb_info
*dinfo
, u32 bg
, u32 fg
)
1882 DBG_MSG("intelfbhw_cursor_setcolor\n");
1885 OUTREG(CURSOR_A_PALETTE0
, bg
& CURSOR_PALETTE_MASK
);
1886 OUTREG(CURSOR_A_PALETTE1
, fg
& CURSOR_PALETTE_MASK
);
1887 OUTREG(CURSOR_A_PALETTE2
, fg
& CURSOR_PALETTE_MASK
);
1888 OUTREG(CURSOR_A_PALETTE3
, bg
& CURSOR_PALETTE_MASK
);
1892 intelfbhw_cursor_load(struct intelfb_info
*dinfo
, int width
, int height
,
1895 u8 __iomem
*addr
= (u8 __iomem
*)dinfo
->cursor
.virtual;
1896 int i
, j
, w
= width
/ 8;
1897 int mod
= width
% 8, t_mask
, d_mask
;
1900 DBG_MSG("intelfbhw_cursor_load\n");
1903 if (!dinfo
->cursor
.virtual)
1906 t_mask
= 0xff >> mod
;
1907 d_mask
= ~(0xff >> mod
);
1908 for (i
= height
; i
--; ) {
1909 for (j
= 0; j
< w
; j
++) {
1910 writeb(0x00, addr
+ j
);
1911 writeb(*(data
++), addr
+ j
+8);
1914 writeb(t_mask
, addr
+ j
);
1915 writeb(*(data
++) & d_mask
, addr
+ j
+8);
1922 intelfbhw_cursor_reset(struct intelfb_info
*dinfo
) {
1923 u8 __iomem
*addr
= (u8 __iomem
*)dinfo
->cursor
.virtual;
1927 DBG_MSG("intelfbhw_cursor_reset\n");
1930 if (!dinfo
->cursor
.virtual)
1933 for (i
= 64; i
--; ) {
1934 for (j
= 0; j
< 8; j
++) {
1935 writeb(0xff, addr
+ j
+0);
1936 writeb(0x00, addr
+ j
+8);