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/slab.h>
28 #include <linux/delay.h>
30 #include <linux/ioport.h>
31 #include <linux/init.h>
32 #include <linux/pci.h>
33 #include <linux/vmalloc.h>
34 #include <linux/pagemap.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,
68 intelfbhw_get_chipset(struct pci_dev
*pdev
, struct intelfb_info
*dinfo
)
74 switch (pdev
->device
) {
75 case PCI_DEVICE_ID_INTEL_830M
:
76 dinfo
->name
= "Intel(R) 830M";
77 dinfo
->chipset
= INTEL_830M
;
79 dinfo
->pll_index
= PLLS_I8xx
;
81 case PCI_DEVICE_ID_INTEL_845G
:
82 dinfo
->name
= "Intel(R) 845G";
83 dinfo
->chipset
= INTEL_845G
;
85 dinfo
->pll_index
= PLLS_I8xx
;
87 case PCI_DEVICE_ID_INTEL_85XGM
:
90 dinfo
->pll_index
= PLLS_I8xx
;
91 pci_read_config_dword(pdev
, INTEL_85X_CAPID
, &tmp
);
92 switch ((tmp
>> INTEL_85X_VARIANT_SHIFT
) &
93 INTEL_85X_VARIANT_MASK
) {
94 case INTEL_VAR_855GME
:
95 dinfo
->name
= "Intel(R) 855GME";
96 dinfo
->chipset
= INTEL_855GME
;
99 dinfo
->name
= "Intel(R) 855GM";
100 dinfo
->chipset
= INTEL_855GM
;
102 case INTEL_VAR_852GME
:
103 dinfo
->name
= "Intel(R) 852GME";
104 dinfo
->chipset
= INTEL_852GME
;
106 case INTEL_VAR_852GM
:
107 dinfo
->name
= "Intel(R) 852GM";
108 dinfo
->chipset
= INTEL_852GM
;
111 dinfo
->name
= "Intel(R) 852GM/855GM";
112 dinfo
->chipset
= INTEL_85XGM
;
116 case PCI_DEVICE_ID_INTEL_865G
:
117 dinfo
->name
= "Intel(R) 865G";
118 dinfo
->chipset
= INTEL_865G
;
120 dinfo
->pll_index
= PLLS_I8xx
;
122 case PCI_DEVICE_ID_INTEL_915G
:
123 dinfo
->name
= "Intel(R) 915G";
124 dinfo
->chipset
= INTEL_915G
;
126 dinfo
->pll_index
= PLLS_I9xx
;
128 case PCI_DEVICE_ID_INTEL_915GM
:
129 dinfo
->name
= "Intel(R) 915GM";
130 dinfo
->chipset
= INTEL_915GM
;
132 dinfo
->pll_index
= PLLS_I9xx
;
134 case PCI_DEVICE_ID_INTEL_945G
:
135 dinfo
->name
= "Intel(R) 945G";
136 dinfo
->chipset
= INTEL_945G
;
138 dinfo
->pll_index
= PLLS_I9xx
;
140 case PCI_DEVICE_ID_INTEL_945GM
:
141 dinfo
->name
= "Intel(R) 945GM";
142 dinfo
->chipset
= INTEL_945GM
;
144 dinfo
->pll_index
= PLLS_I9xx
;
152 intelfbhw_get_memory(struct pci_dev
*pdev
, int *aperture_size
,
155 struct pci_dev
*bridge_dev
;
159 if (!pdev
|| !aperture_size
|| !stolen_size
)
162 /* Find the bridge device. It is always 0:0.0 */
163 if (!(bridge_dev
= pci_find_slot(0, PCI_DEVFN(0, 0)))) {
164 ERR_MSG("cannot find bridge device\n");
168 /* Get the fb aperture size and "stolen" memory amount. */
170 pci_read_config_word(bridge_dev
, INTEL_GMCH_CTRL
, &tmp
);
171 switch (pdev
->device
) {
172 case PCI_DEVICE_ID_INTEL_915G
:
173 case PCI_DEVICE_ID_INTEL_915GM
:
174 case PCI_DEVICE_ID_INTEL_945G
:
175 case PCI_DEVICE_ID_INTEL_945GM
:
176 /* 915 and 945 chipsets support a 256MB aperture.
177 Aperture size is determined by inspected the
178 base address of the aperture. */
179 if (pci_resource_start(pdev
, 2) & 0x08000000)
180 *aperture_size
= MB(128);
182 *aperture_size
= MB(256);
185 if ((tmp
& INTEL_GMCH_MEM_MASK
) == INTEL_GMCH_MEM_64M
)
186 *aperture_size
= MB(64);
188 *aperture_size
= MB(128);
192 /* Stolen memory size is reduced by the GTT and the popup.
193 GTT is 1K per MB of aperture size, and popup is 4K. */
194 stolen_overhead
= (*aperture_size
/ MB(1)) + 4;
195 switch(pdev
->device
) {
196 case PCI_DEVICE_ID_INTEL_830M
:
197 case PCI_DEVICE_ID_INTEL_845G
:
198 switch (tmp
& INTEL_830_GMCH_GMS_MASK
) {
199 case INTEL_830_GMCH_GMS_STOLEN_512
:
200 *stolen_size
= KB(512) - KB(stolen_overhead
);
202 case INTEL_830_GMCH_GMS_STOLEN_1024
:
203 *stolen_size
= MB(1) - KB(stolen_overhead
);
205 case INTEL_830_GMCH_GMS_STOLEN_8192
:
206 *stolen_size
= MB(8) - KB(stolen_overhead
);
208 case INTEL_830_GMCH_GMS_LOCAL
:
209 ERR_MSG("only local memory found\n");
211 case INTEL_830_GMCH_GMS_DISABLED
:
212 ERR_MSG("video memory is disabled\n");
215 ERR_MSG("unexpected GMCH_GMS value: 0x%02x\n",
216 tmp
& INTEL_830_GMCH_GMS_MASK
);
221 switch (tmp
& INTEL_855_GMCH_GMS_MASK
) {
222 case INTEL_855_GMCH_GMS_STOLEN_1M
:
223 *stolen_size
= MB(1) - KB(stolen_overhead
);
225 case INTEL_855_GMCH_GMS_STOLEN_4M
:
226 *stolen_size
= MB(4) - KB(stolen_overhead
);
228 case INTEL_855_GMCH_GMS_STOLEN_8M
:
229 *stolen_size
= MB(8) - KB(stolen_overhead
);
231 case INTEL_855_GMCH_GMS_STOLEN_16M
:
232 *stolen_size
= MB(16) - KB(stolen_overhead
);
234 case INTEL_855_GMCH_GMS_STOLEN_32M
:
235 *stolen_size
= MB(32) - KB(stolen_overhead
);
237 case INTEL_915G_GMCH_GMS_STOLEN_48M
:
238 *stolen_size
= MB(48) - KB(stolen_overhead
);
240 case INTEL_915G_GMCH_GMS_STOLEN_64M
:
241 *stolen_size
= MB(64) - KB(stolen_overhead
);
243 case INTEL_855_GMCH_GMS_DISABLED
:
244 ERR_MSG("video memory is disabled\n");
247 ERR_MSG("unexpected GMCH_GMS value: 0x%02x\n",
248 tmp
& INTEL_855_GMCH_GMS_MASK
);
255 intelfbhw_check_non_crt(struct intelfb_info
*dinfo
)
259 if (INREG(LVDS
) & PORT_ENABLE
)
261 if (INREG(DVOA
) & PORT_ENABLE
)
263 if (INREG(DVOB
) & PORT_ENABLE
)
265 if (INREG(DVOC
) & PORT_ENABLE
)
272 intelfbhw_dvo_to_string(int dvo
)
276 else if (dvo
& DVOB_PORT
)
278 else if (dvo
& DVOC_PORT
)
280 else if (dvo
& LVDS_PORT
)
288 intelfbhw_validate_mode(struct intelfb_info
*dinfo
,
289 struct fb_var_screeninfo
*var
)
295 DBG_MSG("intelfbhw_validate_mode\n");
298 bytes_per_pixel
= var
->bits_per_pixel
/ 8;
299 if (bytes_per_pixel
== 3)
302 /* Check if enough video memory. */
303 tmp
= var
->yres_virtual
* var
->xres_virtual
* bytes_per_pixel
;
304 if (tmp
> dinfo
->fb
.size
) {
305 WRN_MSG("Not enough video ram for mode "
306 "(%d KByte vs %d KByte).\n",
307 BtoKB(tmp
), BtoKB(dinfo
->fb
.size
));
311 /* Check if x/y limits are OK. */
312 if (var
->xres
- 1 > HACTIVE_MASK
) {
313 WRN_MSG("X resolution too large (%d vs %d).\n",
314 var
->xres
, HACTIVE_MASK
+ 1);
317 if (var
->yres
- 1 > VACTIVE_MASK
) {
318 WRN_MSG("Y resolution too large (%d vs %d).\n",
319 var
->yres
, VACTIVE_MASK
+ 1);
323 /* Check for interlaced/doublescan modes. */
324 if (var
->vmode
& FB_VMODE_INTERLACED
) {
325 WRN_MSG("Mode is interlaced.\n");
328 if (var
->vmode
& FB_VMODE_DOUBLE
) {
329 WRN_MSG("Mode is double-scan.\n");
333 /* Check if clock is OK. */
334 tmp
= 1000000000 / var
->pixclock
;
335 if (tmp
< MIN_CLOCK
) {
336 WRN_MSG("Pixel clock is too low (%d MHz vs %d MHz).\n",
337 (tmp
+ 500) / 1000, MIN_CLOCK
/ 1000);
340 if (tmp
> MAX_CLOCK
) {
341 WRN_MSG("Pixel clock is too high (%d MHz vs %d MHz).\n",
342 (tmp
+ 500) / 1000, MAX_CLOCK
/ 1000);
350 intelfbhw_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
352 struct intelfb_info
*dinfo
= GET_DINFO(info
);
353 u32 offset
, xoffset
, yoffset
;
356 DBG_MSG("intelfbhw_pan_display\n");
359 xoffset
= ROUND_DOWN_TO(var
->xoffset
, 8);
360 yoffset
= var
->yoffset
;
362 if ((xoffset
+ var
->xres
> var
->xres_virtual
) ||
363 (yoffset
+ var
->yres
> var
->yres_virtual
))
366 offset
= (yoffset
* dinfo
->pitch
) +
367 (xoffset
* var
->bits_per_pixel
) / 8;
369 offset
+= dinfo
->fb
.offset
<< 12;
371 OUTREG(DSPABASE
, offset
);
376 /* Blank the screen. */
378 intelfbhw_do_blank(int blank
, struct fb_info
*info
)
380 struct intelfb_info
*dinfo
= GET_DINFO(info
);
384 DBG_MSG("intelfbhw_do_blank: blank is %d\n", blank
);
387 /* Turn plane A on or off */
388 tmp
= INREG(DSPACNTR
);
390 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
392 tmp
|= DISPPLANE_PLANE_ENABLE
;
393 OUTREG(DSPACNTR
, tmp
);
395 tmp
= INREG(DSPABASE
);
396 OUTREG(DSPABASE
, tmp
);
398 /* Turn off/on the HW cursor */
400 DBG_MSG("cursor_on is %d\n", dinfo
->cursor_on
);
402 if (dinfo
->cursor_on
) {
404 intelfbhw_cursor_hide(dinfo
);
406 intelfbhw_cursor_show(dinfo
);
408 dinfo
->cursor_on
= 1;
410 dinfo
->cursor_blanked
= blank
;
413 tmp
= INREG(ADPA
) & ~ADPA_DPMS_CONTROL_MASK
;
415 case FB_BLANK_UNBLANK
:
416 case FB_BLANK_NORMAL
:
419 case FB_BLANK_VSYNC_SUSPEND
:
422 case FB_BLANK_HSYNC_SUSPEND
:
425 case FB_BLANK_POWERDOWN
:
436 intelfbhw_setcolreg(struct intelfb_info
*dinfo
, unsigned regno
,
437 unsigned red
, unsigned green
, unsigned blue
,
441 DBG_MSG("intelfbhw_setcolreg: %d: (%d, %d, %d)\n",
442 regno
, red
, green
, blue
);
445 u32 palette_reg
= (dinfo
->pipe
== PIPE_A
) ?
446 PALETTE_A
: PALETTE_B
;
448 OUTREG(palette_reg
+ (regno
<< 2),
449 (red
<< PALETTE_8_RED_SHIFT
) |
450 (green
<< PALETTE_8_GREEN_SHIFT
) |
451 (blue
<< PALETTE_8_BLUE_SHIFT
));
456 intelfbhw_read_hw_state(struct intelfb_info
*dinfo
, struct intelfb_hwstate
*hw
,
462 DBG_MSG("intelfbhw_read_hw_state\n");
468 /* Read in as much of the HW state as possible. */
469 hw
->vga0_divisor
= INREG(VGA0_DIVISOR
);
470 hw
->vga1_divisor
= INREG(VGA1_DIVISOR
);
471 hw
->vga_pd
= INREG(VGAPD
);
472 hw
->dpll_a
= INREG(DPLL_A
);
473 hw
->dpll_b
= INREG(DPLL_B
);
474 hw
->fpa0
= INREG(FPA0
);
475 hw
->fpa1
= INREG(FPA1
);
476 hw
->fpb0
= INREG(FPB0
);
477 hw
->fpb1
= INREG(FPB1
);
483 /* This seems to be a problem with the 852GM/855GM */
484 for (i
= 0; i
< PALETTE_8_ENTRIES
; i
++) {
485 hw
->palette_a
[i
] = INREG(PALETTE_A
+ (i
<< 2));
486 hw
->palette_b
[i
] = INREG(PALETTE_B
+ (i
<< 2));
493 hw
->htotal_a
= INREG(HTOTAL_A
);
494 hw
->hblank_a
= INREG(HBLANK_A
);
495 hw
->hsync_a
= INREG(HSYNC_A
);
496 hw
->vtotal_a
= INREG(VTOTAL_A
);
497 hw
->vblank_a
= INREG(VBLANK_A
);
498 hw
->vsync_a
= INREG(VSYNC_A
);
499 hw
->src_size_a
= INREG(SRC_SIZE_A
);
500 hw
->bclrpat_a
= INREG(BCLRPAT_A
);
501 hw
->htotal_b
= INREG(HTOTAL_B
);
502 hw
->hblank_b
= INREG(HBLANK_B
);
503 hw
->hsync_b
= INREG(HSYNC_B
);
504 hw
->vtotal_b
= INREG(VTOTAL_B
);
505 hw
->vblank_b
= INREG(VBLANK_B
);
506 hw
->vsync_b
= INREG(VSYNC_B
);
507 hw
->src_size_b
= INREG(SRC_SIZE_B
);
508 hw
->bclrpat_b
= INREG(BCLRPAT_B
);
513 hw
->adpa
= INREG(ADPA
);
514 hw
->dvoa
= INREG(DVOA
);
515 hw
->dvob
= INREG(DVOB
);
516 hw
->dvoc
= INREG(DVOC
);
517 hw
->dvoa_srcdim
= INREG(DVOA_SRCDIM
);
518 hw
->dvob_srcdim
= INREG(DVOB_SRCDIM
);
519 hw
->dvoc_srcdim
= INREG(DVOC_SRCDIM
);
520 hw
->lvds
= INREG(LVDS
);
525 hw
->pipe_a_conf
= INREG(PIPEACONF
);
526 hw
->pipe_b_conf
= INREG(PIPEBCONF
);
527 hw
->disp_arb
= INREG(DISPARB
);
532 hw
->cursor_a_control
= INREG(CURSOR_A_CONTROL
);
533 hw
->cursor_b_control
= INREG(CURSOR_B_CONTROL
);
534 hw
->cursor_a_base
= INREG(CURSOR_A_BASEADDR
);
535 hw
->cursor_b_base
= INREG(CURSOR_B_BASEADDR
);
540 for (i
= 0; i
< 4; i
++) {
541 hw
->cursor_a_palette
[i
] = INREG(CURSOR_A_PALETTE0
+ (i
<< 2));
542 hw
->cursor_b_palette
[i
] = INREG(CURSOR_B_PALETTE0
+ (i
<< 2));
548 hw
->cursor_size
= INREG(CURSOR_SIZE
);
553 hw
->disp_a_ctrl
= INREG(DSPACNTR
);
554 hw
->disp_b_ctrl
= INREG(DSPBCNTR
);
555 hw
->disp_a_base
= INREG(DSPABASE
);
556 hw
->disp_b_base
= INREG(DSPBBASE
);
557 hw
->disp_a_stride
= INREG(DSPASTRIDE
);
558 hw
->disp_b_stride
= INREG(DSPBSTRIDE
);
563 hw
->vgacntrl
= INREG(VGACNTRL
);
568 hw
->add_id
= INREG(ADD_ID
);
573 for (i
= 0; i
< 7; i
++) {
574 hw
->swf0x
[i
] = INREG(SWF00
+ (i
<< 2));
575 hw
->swf1x
[i
] = INREG(SWF10
+ (i
<< 2));
577 hw
->swf3x
[i
] = INREG(SWF30
+ (i
<< 2));
580 for (i
= 0; i
< 8; i
++)
581 hw
->fence
[i
] = INREG(FENCE
+ (i
<< 2));
583 hw
->instpm
= INREG(INSTPM
);
584 hw
->mem_mode
= INREG(MEM_MODE
);
585 hw
->fw_blc_0
= INREG(FW_BLC_0
);
586 hw
->fw_blc_1
= INREG(FW_BLC_1
);
592 static int calc_vclock3(int index
, int m
, int n
, int p
)
594 if (p
== 0 || n
== 0)
596 return plls
[index
].ref_clk
* m
/ n
/ p
;
599 static int calc_vclock(int index
, int m1
, int m2
, int n
, int p1
, int p2
, int lvds
)
601 struct pll_min_max
*pll
= &plls
[index
];
604 m
= (5 * (m1
+ 2)) + (m2
+ 2);
606 vco
= pll
->ref_clk
* m
/ n
;
608 if (index
== PLLS_I8xx
) {
609 p
= ((p1
+ 2) * (1 << (p2
+ 1)));
611 p
= ((p1
) * (p2
? 5 : 10));
617 intelfbhw_get_p1p2(struct intelfb_info
*dinfo
, int dpll
, int *o_p1
, int *o_p2
)
621 if (IS_I9XX(dinfo
)) {
622 if (dpll
& DPLL_P1_FORCE_DIV2
)
625 p1
= (dpll
>> DPLL_P1_SHIFT
) & 0xff;
629 p2
= (dpll
>> DPLL_I9XX_P2_SHIFT
) & DPLL_P2_MASK
;
631 if (dpll
& DPLL_P1_FORCE_DIV2
)
634 p1
= (dpll
>> DPLL_P1_SHIFT
) & DPLL_P1_MASK
;
635 p2
= (dpll
>> DPLL_P2_SHIFT
) & DPLL_P2_MASK
;
644 intelfbhw_print_hw_state(struct intelfb_info
*dinfo
, struct intelfb_hwstate
*hw
)
647 int i
, m1
, m2
, n
, p1
, p2
;
648 int index
= dinfo
->pll_index
;
649 DBG_MSG("intelfbhw_print_hw_state\n");
653 /* Read in as much of the HW state as possible. */
654 printk("hw state dump start\n");
655 printk(" VGA0_DIVISOR: 0x%08x\n", hw
->vga0_divisor
);
656 printk(" VGA1_DIVISOR: 0x%08x\n", hw
->vga1_divisor
);
657 printk(" VGAPD: 0x%08x\n", hw
->vga_pd
);
658 n
= (hw
->vga0_divisor
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
659 m1
= (hw
->vga0_divisor
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
660 m2
= (hw
->vga0_divisor
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
662 intelfbhw_get_p1p2(dinfo
, hw
->vga_pd
, &p1
, &p2
);
664 printk(" VGA0: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
666 printk(" VGA0: clock is %d\n",
667 calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
669 n
= (hw
->vga1_divisor
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
670 m1
= (hw
->vga1_divisor
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
671 m2
= (hw
->vga1_divisor
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
673 intelfbhw_get_p1p2(dinfo
, hw
->vga_pd
, &p1
, &p2
);
674 printk(" VGA1: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
676 printk(" VGA1: clock is %d\n", calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
678 printk(" DPLL_A: 0x%08x\n", hw
->dpll_a
);
679 printk(" DPLL_B: 0x%08x\n", hw
->dpll_b
);
680 printk(" FPA0: 0x%08x\n", hw
->fpa0
);
681 printk(" FPA1: 0x%08x\n", hw
->fpa1
);
682 printk(" FPB0: 0x%08x\n", hw
->fpb0
);
683 printk(" FPB1: 0x%08x\n", hw
->fpb1
);
685 n
= (hw
->fpa0
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
686 m1
= (hw
->fpa0
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
687 m2
= (hw
->fpa0
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
689 intelfbhw_get_p1p2(dinfo
, hw
->dpll_a
, &p1
, &p2
);
691 printk(" PLLA0: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
693 printk(" PLLA0: clock is %d\n", calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
695 n
= (hw
->fpa1
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
696 m1
= (hw
->fpa1
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
697 m2
= (hw
->fpa1
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
699 intelfbhw_get_p1p2(dinfo
, hw
->dpll_a
, &p1
, &p2
);
701 printk(" PLLA1: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
703 printk(" PLLA1: clock is %d\n", calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
706 printk(" PALETTE_A:\n");
707 for (i
= 0; i
< PALETTE_8_ENTRIES
)
708 printk(" %3d: 0x%08x\n", i
, hw
->palette_a
[i
]);
709 printk(" PALETTE_B:\n");
710 for (i
= 0; i
< PALETTE_8_ENTRIES
)
711 printk(" %3d: 0x%08x\n", i
, hw
->palette_b
[i
]);
714 printk(" HTOTAL_A: 0x%08x\n", hw
->htotal_a
);
715 printk(" HBLANK_A: 0x%08x\n", hw
->hblank_a
);
716 printk(" HSYNC_A: 0x%08x\n", hw
->hsync_a
);
717 printk(" VTOTAL_A: 0x%08x\n", hw
->vtotal_a
);
718 printk(" VBLANK_A: 0x%08x\n", hw
->vblank_a
);
719 printk(" VSYNC_A: 0x%08x\n", hw
->vsync_a
);
720 printk(" SRC_SIZE_A: 0x%08x\n", hw
->src_size_a
);
721 printk(" BCLRPAT_A: 0x%08x\n", hw
->bclrpat_a
);
722 printk(" HTOTAL_B: 0x%08x\n", hw
->htotal_b
);
723 printk(" HBLANK_B: 0x%08x\n", hw
->hblank_b
);
724 printk(" HSYNC_B: 0x%08x\n", hw
->hsync_b
);
725 printk(" VTOTAL_B: 0x%08x\n", hw
->vtotal_b
);
726 printk(" VBLANK_B: 0x%08x\n", hw
->vblank_b
);
727 printk(" VSYNC_B: 0x%08x\n", hw
->vsync_b
);
728 printk(" SRC_SIZE_B: 0x%08x\n", hw
->src_size_b
);
729 printk(" BCLRPAT_B: 0x%08x\n", hw
->bclrpat_b
);
731 printk(" ADPA: 0x%08x\n", hw
->adpa
);
732 printk(" DVOA: 0x%08x\n", hw
->dvoa
);
733 printk(" DVOB: 0x%08x\n", hw
->dvob
);
734 printk(" DVOC: 0x%08x\n", hw
->dvoc
);
735 printk(" DVOA_SRCDIM: 0x%08x\n", hw
->dvoa_srcdim
);
736 printk(" DVOB_SRCDIM: 0x%08x\n", hw
->dvob_srcdim
);
737 printk(" DVOC_SRCDIM: 0x%08x\n", hw
->dvoc_srcdim
);
738 printk(" LVDS: 0x%08x\n", hw
->lvds
);
740 printk(" PIPEACONF: 0x%08x\n", hw
->pipe_a_conf
);
741 printk(" PIPEBCONF: 0x%08x\n", hw
->pipe_b_conf
);
742 printk(" DISPARB: 0x%08x\n", hw
->disp_arb
);
744 printk(" CURSOR_A_CONTROL: 0x%08x\n", hw
->cursor_a_control
);
745 printk(" CURSOR_B_CONTROL: 0x%08x\n", hw
->cursor_b_control
);
746 printk(" CURSOR_A_BASEADDR: 0x%08x\n", hw
->cursor_a_base
);
747 printk(" CURSOR_B_BASEADDR: 0x%08x\n", hw
->cursor_b_base
);
749 printk(" CURSOR_A_PALETTE: ");
750 for (i
= 0; i
< 4; i
++) {
751 printk("0x%08x", hw
->cursor_a_palette
[i
]);
756 printk(" CURSOR_B_PALETTE: ");
757 for (i
= 0; i
< 4; i
++) {
758 printk("0x%08x", hw
->cursor_b_palette
[i
]);
764 printk(" CURSOR_SIZE: 0x%08x\n", hw
->cursor_size
);
766 printk(" DSPACNTR: 0x%08x\n", hw
->disp_a_ctrl
);
767 printk(" DSPBCNTR: 0x%08x\n", hw
->disp_b_ctrl
);
768 printk(" DSPABASE: 0x%08x\n", hw
->disp_a_base
);
769 printk(" DSPBBASE: 0x%08x\n", hw
->disp_b_base
);
770 printk(" DSPASTRIDE: 0x%08x\n", hw
->disp_a_stride
);
771 printk(" DSPBSTRIDE: 0x%08x\n", hw
->disp_b_stride
);
773 printk(" VGACNTRL: 0x%08x\n", hw
->vgacntrl
);
774 printk(" ADD_ID: 0x%08x\n", hw
->add_id
);
776 for (i
= 0; i
< 7; i
++) {
777 printk(" SWF0%d 0x%08x\n", i
,
780 for (i
= 0; i
< 7; i
++) {
781 printk(" SWF1%d 0x%08x\n", i
,
784 for (i
= 0; i
< 3; i
++) {
785 printk(" SWF3%d 0x%08x\n", i
,
788 for (i
= 0; i
< 8; i
++)
789 printk(" FENCE%d 0x%08x\n", i
,
792 printk(" INSTPM 0x%08x\n", hw
->instpm
);
793 printk(" MEM_MODE 0x%08x\n", hw
->mem_mode
);
794 printk(" FW_BLC_0 0x%08x\n", hw
->fw_blc_0
);
795 printk(" FW_BLC_1 0x%08x\n", hw
->fw_blc_1
);
797 printk("hw state dump end\n");
803 /* Split the M parameter into M1 and M2. */
805 splitm(int index
, unsigned int m
, unsigned int *retm1
, unsigned int *retm2
)
809 struct pll_min_max
*pll
= &plls
[index
];
811 /* no point optimising too much - brute force m */
812 for (m1
= pll
->min_m1
; m1
< pll
->max_m1
+ 1; m1
++) {
813 for (m2
= pll
->min_m2
; m2
< pll
->max_m2
+ 1; m2
++) {
814 testm
= (5 * (m1
+ 2)) + (m2
+ 2);
816 *retm1
= (unsigned int)m1
;
817 *retm2
= (unsigned int)m2
;
825 /* Split the P parameter into P1 and P2. */
827 splitp(int index
, unsigned int p
, unsigned int *retp1
, unsigned int *retp2
)
830 struct pll_min_max
*pll
= &plls
[index
];
832 if (index
== PLLS_I9xx
) {
833 p2
= (p
% 10) ? 1 : 0;
835 p1
= p
/ (p2
? 5 : 10);
837 *retp1
= (unsigned int)p1
;
838 *retp2
= (unsigned int)p2
;
846 p1
= (p
/ (1 << (p2
+ 1))) - 2;
847 if (p
% 4 == 0 && p1
< pll
->min_p1
) {
849 p1
= (p
/ (1 << (p2
+ 1))) - 2;
851 if (p1
< pll
->min_p1
|| p1
> pll
->max_p1
||
852 (p1
+ 2) * (1 << (p2
+ 1)) != p
) {
855 *retp1
= (unsigned int)p1
;
856 *retp2
= (unsigned int)p2
;
862 calc_pll_params(int index
, int clock
, u32
*retm1
, u32
*retm2
, u32
*retn
, u32
*retp1
,
863 u32
*retp2
, u32
*retclock
)
865 u32 m1
, m2
, n
, p1
, p2
, n1
, testm
;
866 u32 f_vco
, p
, p_best
= 0, m
, f_out
= 0;
867 u32 err_max
, err_target
, err_best
= 10000000;
868 u32 n_best
= 0, m_best
= 0, f_best
, f_err
;
869 u32 p_min
, p_max
, p_inc
, div_max
;
870 struct pll_min_max
*pll
= &plls
[index
];
872 /* Accept 0.5% difference, but aim for 0.1% */
873 err_max
= 5 * clock
/ 1000;
874 err_target
= clock
/ 1000;
876 DBG_MSG("Clock is %d\n", clock
);
878 div_max
= pll
->max_vco
/ clock
;
880 p_inc
= (clock
<= pll
->p_transition_clk
) ? pll
->p_inc_lo
: pll
->p_inc_hi
;
882 p_max
= ROUND_DOWN_TO(div_max
, p_inc
);
883 if (p_min
< pll
->min_p
)
885 if (p_max
> pll
->max_p
)
888 DBG_MSG("p range is %d-%d (%d)\n", p_min
, p_max
, p_inc
);
892 if (splitp(index
, p
, &p1
, &p2
)) {
893 WRN_MSG("cannot split p = %d\n", p
);
901 m
= ROUND_UP_TO(f_vco
* n
, pll
->ref_clk
) / pll
->ref_clk
;
906 for (testm
= m
- 1; testm
<= m
; testm
++) {
907 f_out
= calc_vclock3(index
, m
, n
, p
);
908 if (splitm(index
, testm
, &m1
, &m2
)) {
909 WRN_MSG("cannot split m = %d\n", m
);
914 f_err
= clock
- f_out
;
915 else/* slightly bias the error for bigger clocks */
916 f_err
= f_out
- clock
+ 1;
918 if (f_err
< err_best
) {
927 } while ((n
<= pll
->max_n
) && (f_out
>= clock
));
929 } while ((p
<= p_max
));
932 WRN_MSG("cannot find parameters for clock %d\n", clock
);
938 splitm(index
, m
, &m1
, &m2
);
939 splitp(index
, p
, &p1
, &p2
);
942 DBG_MSG("m, n, p: %d (%d,%d), %d (%d), %d (%d,%d), "
943 "f: %d (%d), VCO: %d\n",
944 m
, m1
, m2
, n
, n1
, p
, p1
, p2
,
945 calc_vclock3(index
, m
, n
, p
),
946 calc_vclock(index
, m1
, m2
, n1
, p1
, p2
, 0),
947 calc_vclock3(index
, m
, n
, p
) * p
);
953 *retclock
= calc_vclock(index
, m1
, m2
, n1
, p1
, p2
, 0);
958 static __inline__
int
959 check_overflow(u32 value
, u32 limit
, const char *description
)
962 WRN_MSG("%s value %d exceeds limit %d\n",
963 description
, value
, limit
);
969 /* It is assumed that hw is filled in with the initial state information. */
971 intelfbhw_mode_to_hw(struct intelfb_info
*dinfo
, struct intelfb_hwstate
*hw
,
972 struct fb_var_screeninfo
*var
)
975 u32
*dpll
, *fp0
, *fp1
;
976 u32 m1
, m2
, n
, p1
, p2
, clock_target
, clock
;
977 u32 hsync_start
, hsync_end
, hblank_start
, hblank_end
, htotal
, hactive
;
978 u32 vsync_start
, vsync_end
, vblank_start
, vblank_end
, vtotal
, vactive
;
979 u32 vsync_pol
, hsync_pol
;
980 u32
*vs
, *vb
, *vt
, *hs
, *hb
, *ht
, *ss
, *pipe_conf
;
981 u32 stride_alignment
;
983 DBG_MSG("intelfbhw_mode_to_hw\n");
986 hw
->vgacntrl
|= VGA_DISABLE
;
988 /* Check whether pipe A or pipe B is enabled. */
989 if (hw
->pipe_a_conf
& PIPECONF_ENABLE
)
991 else if (hw
->pipe_b_conf
& PIPECONF_ENABLE
)
994 /* Set which pipe's registers will be set. */
995 if (pipe
== PIPE_B
) {
1005 ss
= &hw
->src_size_b
;
1006 pipe_conf
= &hw
->pipe_b_conf
;
1017 ss
= &hw
->src_size_a
;
1018 pipe_conf
= &hw
->pipe_a_conf
;
1021 /* Use ADPA register for sync control. */
1022 hw
->adpa
&= ~ADPA_USE_VGA_HVPOLARITY
;
1025 hsync_pol
= (var
->sync
& FB_SYNC_HOR_HIGH_ACT
) ?
1026 ADPA_SYNC_ACTIVE_HIGH
: ADPA_SYNC_ACTIVE_LOW
;
1027 vsync_pol
= (var
->sync
& FB_SYNC_VERT_HIGH_ACT
) ?
1028 ADPA_SYNC_ACTIVE_HIGH
: ADPA_SYNC_ACTIVE_LOW
;
1029 hw
->adpa
&= ~((ADPA_SYNC_ACTIVE_MASK
<< ADPA_VSYNC_ACTIVE_SHIFT
) |
1030 (ADPA_SYNC_ACTIVE_MASK
<< ADPA_HSYNC_ACTIVE_SHIFT
));
1031 hw
->adpa
|= (hsync_pol
<< ADPA_HSYNC_ACTIVE_SHIFT
) |
1032 (vsync_pol
<< ADPA_VSYNC_ACTIVE_SHIFT
);
1034 /* Connect correct pipe to the analog port DAC */
1035 hw
->adpa
&= ~(PIPE_MASK
<< ADPA_PIPE_SELECT_SHIFT
);
1036 hw
->adpa
|= (pipe
<< ADPA_PIPE_SELECT_SHIFT
);
1038 /* Set DPMS state to D0 (on) */
1039 hw
->adpa
&= ~ADPA_DPMS_CONTROL_MASK
;
1040 hw
->adpa
|= ADPA_DPMS_D0
;
1042 hw
->adpa
|= ADPA_DAC_ENABLE
;
1044 *dpll
|= (DPLL_VCO_ENABLE
| DPLL_VGA_MODE_DISABLE
);
1045 *dpll
&= ~(DPLL_RATE_SELECT_MASK
| DPLL_REFERENCE_SELECT_MASK
);
1046 *dpll
|= (DPLL_REFERENCE_DEFAULT
| DPLL_RATE_SELECT_FP0
);
1048 /* Desired clock in kHz */
1049 clock_target
= 1000000000 / var
->pixclock
;
1051 if (calc_pll_params(dinfo
->pll_index
, clock_target
, &m1
, &m2
,
1052 &n
, &p1
, &p2
, &clock
)) {
1053 WRN_MSG("calc_pll_params failed\n");
1057 /* Check for overflow. */
1058 if (check_overflow(p1
, DPLL_P1_MASK
, "PLL P1 parameter"))
1060 if (check_overflow(p2
, DPLL_P2_MASK
, "PLL P2 parameter"))
1062 if (check_overflow(m1
, FP_DIVISOR_MASK
, "PLL M1 parameter"))
1064 if (check_overflow(m2
, FP_DIVISOR_MASK
, "PLL M2 parameter"))
1066 if (check_overflow(n
, FP_DIVISOR_MASK
, "PLL N parameter"))
1069 *dpll
&= ~DPLL_P1_FORCE_DIV2
;
1070 *dpll
&= ~((DPLL_P2_MASK
<< DPLL_P2_SHIFT
) |
1071 (DPLL_P1_MASK
<< DPLL_P1_SHIFT
));
1073 if (IS_I9XX(dinfo
)) {
1074 *dpll
|= (p2
<< DPLL_I9XX_P2_SHIFT
);
1075 *dpll
|= (1 << (p1
- 1)) << DPLL_P1_SHIFT
;
1077 *dpll
|= (p2
<< DPLL_P2_SHIFT
) | (p1
<< DPLL_P1_SHIFT
);
1080 *fp0
= (n
<< FP_N_DIVISOR_SHIFT
) |
1081 (m1
<< FP_M1_DIVISOR_SHIFT
) |
1082 (m2
<< FP_M2_DIVISOR_SHIFT
);
1085 hw
->dvob
&= ~PORT_ENABLE
;
1086 hw
->dvoc
&= ~PORT_ENABLE
;
1088 /* Use display plane A. */
1089 hw
->disp_a_ctrl
|= DISPPLANE_PLANE_ENABLE
;
1090 hw
->disp_a_ctrl
&= ~DISPPLANE_GAMMA_ENABLE
;
1091 hw
->disp_a_ctrl
&= ~DISPPLANE_PIXFORMAT_MASK
;
1092 switch (intelfb_var_to_depth(var
)) {
1094 hw
->disp_a_ctrl
|= DISPPLANE_8BPP
| DISPPLANE_GAMMA_ENABLE
;
1097 hw
->disp_a_ctrl
|= DISPPLANE_15_16BPP
;
1100 hw
->disp_a_ctrl
|= DISPPLANE_16BPP
;
1103 hw
->disp_a_ctrl
|= DISPPLANE_32BPP_NO_ALPHA
;
1106 hw
->disp_a_ctrl
&= ~(PIPE_MASK
<< DISPPLANE_SEL_PIPE_SHIFT
);
1107 hw
->disp_a_ctrl
|= (pipe
<< DISPPLANE_SEL_PIPE_SHIFT
);
1109 /* Set CRTC registers. */
1110 hactive
= var
->xres
;
1111 hsync_start
= hactive
+ var
->right_margin
;
1112 hsync_end
= hsync_start
+ var
->hsync_len
;
1113 htotal
= hsync_end
+ var
->left_margin
;
1114 hblank_start
= hactive
;
1115 hblank_end
= htotal
;
1117 DBG_MSG("H: act %d, ss %d, se %d, tot %d bs %d, be %d\n",
1118 hactive
, hsync_start
, hsync_end
, htotal
, hblank_start
,
1121 vactive
= var
->yres
;
1122 vsync_start
= vactive
+ var
->lower_margin
;
1123 vsync_end
= vsync_start
+ var
->vsync_len
;
1124 vtotal
= vsync_end
+ var
->upper_margin
;
1125 vblank_start
= vactive
;
1126 vblank_end
= vtotal
;
1127 vblank_end
= vsync_end
+ 1;
1129 DBG_MSG("V: act %d, ss %d, se %d, tot %d bs %d, be %d\n",
1130 vactive
, vsync_start
, vsync_end
, vtotal
, vblank_start
,
1133 /* Adjust for register values, and check for overflow. */
1135 if (check_overflow(hactive
, HACTIVE_MASK
, "CRTC hactive"))
1138 if (check_overflow(hsync_start
, HSYNCSTART_MASK
, "CRTC hsync_start"))
1141 if (check_overflow(hsync_end
, HSYNCEND_MASK
, "CRTC hsync_end"))
1144 if (check_overflow(htotal
, HTOTAL_MASK
, "CRTC htotal"))
1147 if (check_overflow(hblank_start
, HBLANKSTART_MASK
, "CRTC hblank_start"))
1150 if (check_overflow(hblank_end
, HBLANKEND_MASK
, "CRTC hblank_end"))
1154 if (check_overflow(vactive
, VACTIVE_MASK
, "CRTC vactive"))
1157 if (check_overflow(vsync_start
, VSYNCSTART_MASK
, "CRTC vsync_start"))
1160 if (check_overflow(vsync_end
, VSYNCEND_MASK
, "CRTC vsync_end"))
1163 if (check_overflow(vtotal
, VTOTAL_MASK
, "CRTC vtotal"))
1166 if (check_overflow(vblank_start
, VBLANKSTART_MASK
, "CRTC vblank_start"))
1169 if (check_overflow(vblank_end
, VBLANKEND_MASK
, "CRTC vblank_end"))
1172 *ht
= (htotal
<< HTOTAL_SHIFT
) | (hactive
<< HACTIVE_SHIFT
);
1173 *hb
= (hblank_start
<< HBLANKSTART_SHIFT
) |
1174 (hblank_end
<< HSYNCEND_SHIFT
);
1175 *hs
= (hsync_start
<< HSYNCSTART_SHIFT
) | (hsync_end
<< HSYNCEND_SHIFT
);
1177 *vt
= (vtotal
<< VTOTAL_SHIFT
) | (vactive
<< VACTIVE_SHIFT
);
1178 *vb
= (vblank_start
<< VBLANKSTART_SHIFT
) |
1179 (vblank_end
<< VSYNCEND_SHIFT
);
1180 *vs
= (vsync_start
<< VSYNCSTART_SHIFT
) | (vsync_end
<< VSYNCEND_SHIFT
);
1181 *ss
= (hactive
<< SRC_SIZE_HORIZ_SHIFT
) |
1182 (vactive
<< SRC_SIZE_VERT_SHIFT
);
1184 hw
->disp_a_stride
= dinfo
->pitch
;
1185 DBG_MSG("pitch is %d\n", hw
->disp_a_stride
);
1187 hw
->disp_a_base
= hw
->disp_a_stride
* var
->yoffset
+
1188 var
->xoffset
* var
->bits_per_pixel
/ 8;
1190 hw
->disp_a_base
+= dinfo
->fb
.offset
<< 12;
1192 /* Check stride alignment. */
1193 stride_alignment
= IS_I9XX(dinfo
) ? STRIDE_ALIGNMENT_I9XX
:
1195 if (hw
->disp_a_stride
% stride_alignment
!= 0) {
1196 WRN_MSG("display stride %d has bad alignment %d\n",
1197 hw
->disp_a_stride
, stride_alignment
);
1201 /* Set the palette to 8-bit mode. */
1202 *pipe_conf
&= ~PIPECONF_GAMMA
;
1206 /* Program a (non-VGA) video mode. */
1208 intelfbhw_program_mode(struct intelfb_info
*dinfo
,
1209 const struct intelfb_hwstate
*hw
, int blank
)
1213 const u32
*dpll
, *fp0
, *fp1
, *pipe_conf
;
1214 const u32
*hs
, *ht
, *hb
, *vs
, *vt
, *vb
, *ss
;
1215 u32 dpll_reg
, fp0_reg
, fp1_reg
, pipe_conf_reg
;
1216 u32 hsync_reg
, htotal_reg
, hblank_reg
;
1217 u32 vsync_reg
, vtotal_reg
, vblank_reg
;
1219 u32 count
, tmp_val
[3];
1221 /* Assume single pipe, display plane A, analog CRT. */
1224 DBG_MSG("intelfbhw_program_mode\n");
1228 tmp
= INREG(VGACNTRL
);
1230 OUTREG(VGACNTRL
, tmp
);
1232 /* Check whether pipe A or pipe B is enabled. */
1233 if (hw
->pipe_a_conf
& PIPECONF_ENABLE
)
1235 else if (hw
->pipe_b_conf
& PIPECONF_ENABLE
)
1240 if (pipe
== PIPE_B
) {
1244 pipe_conf
= &hw
->pipe_b_conf
;
1251 ss
= &hw
->src_size_b
;
1255 pipe_conf_reg
= PIPEBCONF
;
1256 hsync_reg
= HSYNC_B
;
1257 htotal_reg
= HTOTAL_B
;
1258 hblank_reg
= HBLANK_B
;
1259 vsync_reg
= VSYNC_B
;
1260 vtotal_reg
= VTOTAL_B
;
1261 vblank_reg
= VBLANK_B
;
1262 src_size_reg
= SRC_SIZE_B
;
1267 pipe_conf
= &hw
->pipe_a_conf
;
1274 ss
= &hw
->src_size_a
;
1278 pipe_conf_reg
= PIPEACONF
;
1279 hsync_reg
= HSYNC_A
;
1280 htotal_reg
= HTOTAL_A
;
1281 hblank_reg
= HBLANK_A
;
1282 vsync_reg
= VSYNC_A
;
1283 vtotal_reg
= VTOTAL_A
;
1284 vblank_reg
= VBLANK_A
;
1285 src_size_reg
= SRC_SIZE_A
;
1289 tmp
= INREG(pipe_conf_reg
);
1290 tmp
&= ~PIPECONF_ENABLE
;
1291 OUTREG(pipe_conf_reg
, tmp
);
1295 tmp_val
[count
%3] = INREG(0x70000);
1296 if ((tmp_val
[0] == tmp_val
[1]) && (tmp_val
[1]==tmp_val
[2]))
1300 if (count
% 200 == 0) {
1301 tmp
= INREG(pipe_conf_reg
);
1302 tmp
&= ~PIPECONF_ENABLE
;
1303 OUTREG(pipe_conf_reg
, tmp
);
1305 } while(count
< 2000);
1307 OUTREG(ADPA
, INREG(ADPA
) & ~ADPA_DAC_ENABLE
);
1309 /* Disable planes A and B. */
1310 tmp
= INREG(DSPACNTR
);
1311 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
1312 OUTREG(DSPACNTR
, tmp
);
1313 tmp
= INREG(DSPBCNTR
);
1314 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
1315 OUTREG(DSPBCNTR
, tmp
);
1317 /* Wait for vblank. For now, just wait for a 50Hz cycle (20ms)) */
1320 OUTREG(DVOB
, INREG(DVOB
) & ~PORT_ENABLE
);
1321 OUTREG(DVOC
, INREG(DVOC
) & ~PORT_ENABLE
);
1322 OUTREG(ADPA
, INREG(ADPA
) & ~ADPA_DAC_ENABLE
);
1326 tmp
&= ~ADPA_DPMS_CONTROL_MASK
;
1327 tmp
|= ADPA_DPMS_D3
;
1330 /* do some funky magic - xyzzy */
1331 OUTREG(0x61204, 0xabcd0000);
1334 tmp
= INREG(dpll_reg
);
1335 dpll_reg
&= ~DPLL_VCO_ENABLE
;
1336 OUTREG(dpll_reg
, tmp
);
1338 /* Set PLL parameters */
1339 OUTREG(fp0_reg
, *fp0
);
1340 OUTREG(fp1_reg
, *fp1
);
1343 OUTREG(dpll_reg
, *dpll
);
1346 OUTREG(DVOB
, hw
->dvob
);
1347 OUTREG(DVOC
, hw
->dvoc
);
1349 /* undo funky magic */
1350 OUTREG(0x61204, 0x00000000);
1353 OUTREG(ADPA
, INREG(ADPA
) | ADPA_DAC_ENABLE
);
1354 OUTREG(ADPA
, (hw
->adpa
& ~(ADPA_DPMS_CONTROL_MASK
)) | ADPA_DPMS_D3
);
1356 /* Set pipe parameters */
1357 OUTREG(hsync_reg
, *hs
);
1358 OUTREG(hblank_reg
, *hb
);
1359 OUTREG(htotal_reg
, *ht
);
1360 OUTREG(vsync_reg
, *vs
);
1361 OUTREG(vblank_reg
, *vb
);
1362 OUTREG(vtotal_reg
, *vt
);
1363 OUTREG(src_size_reg
, *ss
);
1366 OUTREG(pipe_conf_reg
, *pipe_conf
| PIPECONF_ENABLE
);
1370 tmp
&= ~ADPA_DPMS_CONTROL_MASK
;
1371 tmp
|= ADPA_DPMS_D0
;
1374 /* setup display plane */
1375 if (dinfo
->pdev
->device
== PCI_DEVICE_ID_INTEL_830M
) {
1377 * i830M errata: the display plane must be enabled
1378 * to allow writes to the other bits in the plane
1381 tmp
= INREG(DSPACNTR
);
1382 if ((tmp
& DISPPLANE_PLANE_ENABLE
) != DISPPLANE_PLANE_ENABLE
) {
1383 tmp
|= DISPPLANE_PLANE_ENABLE
;
1384 OUTREG(DSPACNTR
, tmp
);
1386 hw
->disp_a_ctrl
|DISPPLANE_PLANE_ENABLE
);
1391 OUTREG(DSPACNTR
, hw
->disp_a_ctrl
& ~DISPPLANE_PLANE_ENABLE
);
1392 OUTREG(DSPASTRIDE
, hw
->disp_a_stride
);
1393 OUTREG(DSPABASE
, hw
->disp_a_base
);
1397 tmp
= INREG(DSPACNTR
);
1398 tmp
|= DISPPLANE_PLANE_ENABLE
;
1399 OUTREG(DSPACNTR
, tmp
);
1400 OUTREG(DSPABASE
, hw
->disp_a_base
);
1406 /* forward declarations */
1407 static void refresh_ring(struct intelfb_info
*dinfo
);
1408 static void reset_state(struct intelfb_info
*dinfo
);
1409 static void do_flush(struct intelfb_info
*dinfo
);
1412 wait_ring(struct intelfb_info
*dinfo
, int n
)
1416 u32 last_head
= INREG(PRI_RING_HEAD
) & RING_HEAD_MASK
;
1419 DBG_MSG("wait_ring: %d\n", n
);
1422 end
= jiffies
+ (HZ
* 3);
1423 while (dinfo
->ring_space
< n
) {
1424 dinfo
->ring_head
= INREG(PRI_RING_HEAD
) & RING_HEAD_MASK
;
1425 if (dinfo
->ring_tail
+ RING_MIN_FREE
< dinfo
->ring_head
)
1426 dinfo
->ring_space
= dinfo
->ring_head
1427 - (dinfo
->ring_tail
+ RING_MIN_FREE
);
1429 dinfo
->ring_space
= (dinfo
->ring
.size
+
1431 - (dinfo
->ring_tail
+ RING_MIN_FREE
);
1432 if (dinfo
->ring_head
!= last_head
) {
1433 end
= jiffies
+ (HZ
* 3);
1434 last_head
= dinfo
->ring_head
;
1437 if (time_before(end
, jiffies
)) {
1441 refresh_ring(dinfo
);
1443 end
= jiffies
+ (HZ
* 3);
1446 WRN_MSG("ring buffer : space: %d wanted %d\n",
1447 dinfo
->ring_space
, n
);
1448 WRN_MSG("lockup - turning off hardware "
1450 dinfo
->ring_lockup
= 1;
1460 do_flush(struct intelfb_info
*dinfo
) {
1462 OUT_RING(MI_FLUSH
| MI_WRITE_DIRTY_STATE
| MI_INVALIDATE_MAP_CACHE
);
1468 intelfbhw_do_sync(struct intelfb_info
*dinfo
)
1471 DBG_MSG("intelfbhw_do_sync\n");
1478 * Send a flush, then wait until the ring is empty. This is what
1479 * the XFree86 driver does, and actually it doesn't seem a lot worse
1480 * than the recommended method (both have problems).
1483 wait_ring(dinfo
, dinfo
->ring
.size
- RING_MIN_FREE
);
1484 dinfo
->ring_space
= dinfo
->ring
.size
- RING_MIN_FREE
;
1488 refresh_ring(struct intelfb_info
*dinfo
)
1491 DBG_MSG("refresh_ring\n");
1494 dinfo
->ring_head
= INREG(PRI_RING_HEAD
) & RING_HEAD_MASK
;
1495 dinfo
->ring_tail
= INREG(PRI_RING_TAIL
) & RING_TAIL_MASK
;
1496 if (dinfo
->ring_tail
+ RING_MIN_FREE
< dinfo
->ring_head
)
1497 dinfo
->ring_space
= dinfo
->ring_head
1498 - (dinfo
->ring_tail
+ RING_MIN_FREE
);
1500 dinfo
->ring_space
= (dinfo
->ring
.size
+ dinfo
->ring_head
)
1501 - (dinfo
->ring_tail
+ RING_MIN_FREE
);
1505 reset_state(struct intelfb_info
*dinfo
)
1511 DBG_MSG("reset_state\n");
1514 for (i
= 0; i
< FENCE_NUM
; i
++)
1515 OUTREG(FENCE
+ (i
<< 2), 0);
1517 /* Flush the ring buffer if it's enabled. */
1518 tmp
= INREG(PRI_RING_LENGTH
);
1519 if (tmp
& RING_ENABLE
) {
1521 DBG_MSG("reset_state: ring was enabled\n");
1523 refresh_ring(dinfo
);
1524 intelfbhw_do_sync(dinfo
);
1528 OUTREG(PRI_RING_LENGTH
, 0);
1529 OUTREG(PRI_RING_HEAD
, 0);
1530 OUTREG(PRI_RING_TAIL
, 0);
1531 OUTREG(PRI_RING_START
, 0);
1534 /* Stop the 2D engine, and turn off the ring buffer. */
1536 intelfbhw_2d_stop(struct intelfb_info
*dinfo
)
1539 DBG_MSG("intelfbhw_2d_stop: accel: %d, ring_active: %d\n", dinfo
->accel
,
1540 dinfo
->ring_active
);
1546 dinfo
->ring_active
= 0;
1551 * Enable the ring buffer, and initialise the 2D engine.
1552 * It is assumed that the graphics engine has been stopped by previously
1553 * calling intelfb_2d_stop().
1556 intelfbhw_2d_start(struct intelfb_info
*dinfo
)
1559 DBG_MSG("intelfbhw_2d_start: accel: %d, ring_active: %d\n",
1560 dinfo
->accel
, dinfo
->ring_active
);
1566 /* Initialise the primary ring buffer. */
1567 OUTREG(PRI_RING_LENGTH
, 0);
1568 OUTREG(PRI_RING_TAIL
, 0);
1569 OUTREG(PRI_RING_HEAD
, 0);
1571 OUTREG(PRI_RING_START
, dinfo
->ring
.physical
& RING_START_MASK
);
1572 OUTREG(PRI_RING_LENGTH
,
1573 ((dinfo
->ring
.size
- GTT_PAGE_SIZE
) & RING_LENGTH_MASK
) |
1574 RING_NO_REPORT
| RING_ENABLE
);
1575 refresh_ring(dinfo
);
1576 dinfo
->ring_active
= 1;
1579 /* 2D fillrect (solid fill or invert) */
1581 intelfbhw_do_fillrect(struct intelfb_info
*dinfo
, u32 x
, u32 y
, u32 w
, u32 h
,
1582 u32 color
, u32 pitch
, u32 bpp
, u32 rop
)
1584 u32 br00
, br09
, br13
, br14
, br16
;
1587 DBG_MSG("intelfbhw_do_fillrect: (%d,%d) %dx%d, c 0x%06x, p %d bpp %d, "
1588 "rop 0x%02x\n", x
, y
, w
, h
, color
, pitch
, bpp
, rop
);
1591 br00
= COLOR_BLT_CMD
;
1592 br09
= dinfo
->fb_start
+ (y
* pitch
+ x
* (bpp
/ 8));
1593 br13
= (rop
<< ROP_SHIFT
) | pitch
;
1594 br14
= (h
<< HEIGHT_SHIFT
) | ((w
* (bpp
/ 8)) << WIDTH_SHIFT
);
1599 br13
|= COLOR_DEPTH_8
;
1602 br13
|= COLOR_DEPTH_16
;
1605 br13
|= COLOR_DEPTH_32
;
1606 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1620 DBG_MSG("ring = 0x%08x, 0x%08x (%d)\n", dinfo
->ring_head
,
1621 dinfo
->ring_tail
, dinfo
->ring_space
);
1626 intelfbhw_do_bitblt(struct intelfb_info
*dinfo
, u32 curx
, u32 cury
,
1627 u32 dstx
, u32 dsty
, u32 w
, u32 h
, u32 pitch
, u32 bpp
)
1629 u32 br00
, br09
, br11
, br12
, br13
, br22
, br23
, br26
;
1632 DBG_MSG("intelfbhw_do_bitblt: (%d,%d)->(%d,%d) %dx%d, p %d bpp %d\n",
1633 curx
, cury
, dstx
, dsty
, w
, h
, pitch
, bpp
);
1636 br00
= XY_SRC_COPY_BLT_CMD
;
1637 br09
= dinfo
->fb_start
;
1638 br11
= (pitch
<< PITCH_SHIFT
);
1639 br12
= dinfo
->fb_start
;
1640 br13
= (SRC_ROP_GXCOPY
<< ROP_SHIFT
) | (pitch
<< PITCH_SHIFT
);
1641 br22
= (dstx
<< WIDTH_SHIFT
) | (dsty
<< HEIGHT_SHIFT
);
1642 br23
= ((dstx
+ w
) << WIDTH_SHIFT
) |
1643 ((dsty
+ h
) << HEIGHT_SHIFT
);
1644 br26
= (curx
<< WIDTH_SHIFT
) | (cury
<< HEIGHT_SHIFT
);
1648 br13
|= COLOR_DEPTH_8
;
1651 br13
|= COLOR_DEPTH_16
;
1654 br13
|= COLOR_DEPTH_32
;
1655 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1672 intelfbhw_do_drawglyph(struct intelfb_info
*dinfo
, u32 fg
, u32 bg
, u32 w
,
1673 u32 h
, const u8
* cdat
, u32 x
, u32 y
, u32 pitch
, u32 bpp
)
1675 int nbytes
, ndwords
, pad
, tmp
;
1676 u32 br00
, br09
, br13
, br18
, br19
, br22
, br23
;
1677 int dat
, ix
, iy
, iw
;
1681 DBG_MSG("intelfbhw_do_drawglyph: (%d,%d) %dx%d\n", x
, y
, w
, h
);
1684 /* size in bytes of a padded scanline */
1685 nbytes
= ROUND_UP_TO(w
, 16) / 8;
1687 /* Total bytes of padded scanline data to write out. */
1688 nbytes
= nbytes
* h
;
1691 * Check if the glyph data exceeds the immediate mode limit.
1692 * It would take a large font (1K pixels) to hit this limit.
1694 if (nbytes
> MAX_MONO_IMM_SIZE
)
1697 /* Src data is packaged a dword (32-bit) at a time. */
1698 ndwords
= ROUND_UP_TO(nbytes
, 4) / 4;
1701 * Ring has to be padded to a quad word. But because the command starts
1702 with 7 bytes, pad only if there is an even number of ndwords
1704 pad
= !(ndwords
% 2);
1706 tmp
= (XY_MONO_SRC_IMM_BLT_CMD
& DW_LENGTH_MASK
) + ndwords
;
1707 br00
= (XY_MONO_SRC_IMM_BLT_CMD
& ~DW_LENGTH_MASK
) | tmp
;
1708 br09
= dinfo
->fb_start
;
1709 br13
= (SRC_ROP_GXCOPY
<< ROP_SHIFT
) | (pitch
<< PITCH_SHIFT
);
1712 br22
= (x
<< WIDTH_SHIFT
) | (y
<< HEIGHT_SHIFT
);
1713 br23
= ((x
+ w
) << WIDTH_SHIFT
) | ((y
+ h
) << HEIGHT_SHIFT
);
1717 br13
|= COLOR_DEPTH_8
;
1720 br13
|= COLOR_DEPTH_16
;
1723 br13
|= COLOR_DEPTH_32
;
1724 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1728 START_RING(8 + ndwords
);
1737 iw
= ROUND_UP_TO(w
, 8) / 8;
1740 for (j
= 0; j
< 2; ++j
) {
1741 for (i
= 0; i
< 2; ++i
) {
1742 if (ix
!= iw
|| i
== 0)
1743 dat
|= cdat
[iy
*iw
+ ix
++] << (i
+j
*2)*8;
1745 if (ix
== iw
&& iy
!= (h
-1)) {
1759 /* HW cursor functions. */
1761 intelfbhw_cursor_init(struct intelfb_info
*dinfo
)
1766 DBG_MSG("intelfbhw_cursor_init\n");
1769 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1770 if (!dinfo
->cursor
.physical
)
1772 tmp
= INREG(CURSOR_A_CONTROL
);
1773 tmp
&= ~(CURSOR_MODE_MASK
| CURSOR_MOBILE_GAMMA_ENABLE
|
1774 CURSOR_MEM_TYPE_LOCAL
|
1775 (1 << CURSOR_PIPE_SELECT_SHIFT
));
1776 tmp
|= CURSOR_MODE_DISABLE
;
1777 OUTREG(CURSOR_A_CONTROL
, tmp
);
1778 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1780 tmp
= INREG(CURSOR_CONTROL
);
1781 tmp
&= ~(CURSOR_FORMAT_MASK
| CURSOR_GAMMA_ENABLE
|
1782 CURSOR_ENABLE
| CURSOR_STRIDE_MASK
);
1783 tmp
= CURSOR_FORMAT_3C
;
1784 OUTREG(CURSOR_CONTROL
, tmp
);
1785 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.offset
<< 12);
1786 tmp
= (64 << CURSOR_SIZE_H_SHIFT
) |
1787 (64 << CURSOR_SIZE_V_SHIFT
);
1788 OUTREG(CURSOR_SIZE
, tmp
);
1793 intelfbhw_cursor_hide(struct intelfb_info
*dinfo
)
1798 DBG_MSG("intelfbhw_cursor_hide\n");
1801 dinfo
->cursor_on
= 0;
1802 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1803 if (!dinfo
->cursor
.physical
)
1805 tmp
= INREG(CURSOR_A_CONTROL
);
1806 tmp
&= ~CURSOR_MODE_MASK
;
1807 tmp
|= CURSOR_MODE_DISABLE
;
1808 OUTREG(CURSOR_A_CONTROL
, tmp
);
1810 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1812 tmp
= INREG(CURSOR_CONTROL
);
1813 tmp
&= ~CURSOR_ENABLE
;
1814 OUTREG(CURSOR_CONTROL
, tmp
);
1819 intelfbhw_cursor_show(struct intelfb_info
*dinfo
)
1824 DBG_MSG("intelfbhw_cursor_show\n");
1827 dinfo
->cursor_on
= 1;
1829 if (dinfo
->cursor_blanked
)
1832 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1833 if (!dinfo
->cursor
.physical
)
1835 tmp
= INREG(CURSOR_A_CONTROL
);
1836 tmp
&= ~CURSOR_MODE_MASK
;
1837 tmp
|= CURSOR_MODE_64_4C_AX
;
1838 OUTREG(CURSOR_A_CONTROL
, tmp
);
1840 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1842 tmp
= INREG(CURSOR_CONTROL
);
1843 tmp
|= CURSOR_ENABLE
;
1844 OUTREG(CURSOR_CONTROL
, tmp
);
1849 intelfbhw_cursor_setpos(struct intelfb_info
*dinfo
, int x
, int y
)
1854 DBG_MSG("intelfbhw_cursor_setpos: (%d, %d)\n", x
, y
);
1858 * Sets the position. The coordinates are assumed to already
1859 * have any offset adjusted. Assume that the cursor is never
1860 * completely off-screen, and that x, y are always >= 0.
1863 tmp
= ((x
& CURSOR_POS_MASK
) << CURSOR_X_SHIFT
) |
1864 ((y
& CURSOR_POS_MASK
) << CURSOR_Y_SHIFT
);
1865 OUTREG(CURSOR_A_POSITION
, tmp
);
1867 if (IS_I9XX(dinfo
)) {
1868 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1873 intelfbhw_cursor_setcolor(struct intelfb_info
*dinfo
, u32 bg
, u32 fg
)
1876 DBG_MSG("intelfbhw_cursor_setcolor\n");
1879 OUTREG(CURSOR_A_PALETTE0
, bg
& CURSOR_PALETTE_MASK
);
1880 OUTREG(CURSOR_A_PALETTE1
, fg
& CURSOR_PALETTE_MASK
);
1881 OUTREG(CURSOR_A_PALETTE2
, fg
& CURSOR_PALETTE_MASK
);
1882 OUTREG(CURSOR_A_PALETTE3
, bg
& CURSOR_PALETTE_MASK
);
1886 intelfbhw_cursor_load(struct intelfb_info
*dinfo
, int width
, int height
,
1889 u8 __iomem
*addr
= (u8 __iomem
*)dinfo
->cursor
.virtual;
1890 int i
, j
, w
= width
/ 8;
1891 int mod
= width
% 8, t_mask
, d_mask
;
1894 DBG_MSG("intelfbhw_cursor_load\n");
1897 if (!dinfo
->cursor
.virtual)
1900 t_mask
= 0xff >> mod
;
1901 d_mask
= ~(0xff >> mod
);
1902 for (i
= height
; i
--; ) {
1903 for (j
= 0; j
< w
; j
++) {
1904 writeb(0x00, addr
+ j
);
1905 writeb(*(data
++), addr
+ j
+8);
1908 writeb(t_mask
, addr
+ j
);
1909 writeb(*(data
++) & d_mask
, addr
+ j
+8);
1916 intelfbhw_cursor_reset(struct intelfb_info
*dinfo
) {
1917 u8 __iomem
*addr
= (u8 __iomem
*)dinfo
->cursor
.virtual;
1921 DBG_MSG("intelfbhw_cursor_reset\n");
1924 if (!dinfo
->cursor
.virtual)
1927 for (i
= 64; i
--; ) {
1928 for (j
= 0; j
< 8; j
++) {
1929 writeb(0xff, addr
+ j
+0);
1930 writeb(0x00, addr
+ j
+8);