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/tty.h>
28 #include <linux/slab.h>
29 #include <linux/delay.h>
31 #include <linux/ioport.h>
32 #include <linux/init.h>
33 #include <linux/pci.h>
34 #include <linux/vmalloc.h>
35 #include <linux/pagemap.h>
40 #include "intelfbhw.h"
43 int min_m
, max_m
, min_m1
, max_m1
;
44 int min_m2
, max_m2
, min_n
, max_n
;
45 int min_p
, max_p
, min_p1
, max_p1
;
46 int min_vco
, max_vco
, p_transition_clk
, ref_clk
;
47 int p_inc_lo
, p_inc_hi
;
54 static struct pll_min_max plls
[PLLS_MAX
] = {
58 930000, 1400000, 165000, 48000,
64 1400000, 2800000, 200000, 96000,
69 intelfbhw_get_chipset(struct pci_dev
*pdev
, struct intelfb_info
*dinfo
)
75 switch (pdev
->device
) {
76 case PCI_DEVICE_ID_INTEL_830M
:
77 dinfo
->name
= "Intel(R) 830M";
78 dinfo
->chipset
= INTEL_830M
;
80 dinfo
->pll_index
= PLLS_I8xx
;
82 case PCI_DEVICE_ID_INTEL_845G
:
83 dinfo
->name
= "Intel(R) 845G";
84 dinfo
->chipset
= INTEL_845G
;
86 dinfo
->pll_index
= PLLS_I8xx
;
88 case PCI_DEVICE_ID_INTEL_85XGM
:
91 dinfo
->pll_index
= PLLS_I8xx
;
92 pci_read_config_dword(pdev
, INTEL_85X_CAPID
, &tmp
);
93 switch ((tmp
>> INTEL_85X_VARIANT_SHIFT
) &
94 INTEL_85X_VARIANT_MASK
) {
95 case INTEL_VAR_855GME
:
96 dinfo
->name
= "Intel(R) 855GME";
97 dinfo
->chipset
= INTEL_855GME
;
100 dinfo
->name
= "Intel(R) 855GM";
101 dinfo
->chipset
= INTEL_855GM
;
103 case INTEL_VAR_852GME
:
104 dinfo
->name
= "Intel(R) 852GME";
105 dinfo
->chipset
= INTEL_852GME
;
107 case INTEL_VAR_852GM
:
108 dinfo
->name
= "Intel(R) 852GM";
109 dinfo
->chipset
= INTEL_852GM
;
112 dinfo
->name
= "Intel(R) 852GM/855GM";
113 dinfo
->chipset
= INTEL_85XGM
;
117 case PCI_DEVICE_ID_INTEL_865G
:
118 dinfo
->name
= "Intel(R) 865G";
119 dinfo
->chipset
= INTEL_865G
;
121 dinfo
->pll_index
= PLLS_I8xx
;
123 case PCI_DEVICE_ID_INTEL_915G
:
124 dinfo
->name
= "Intel(R) 915G";
125 dinfo
->chipset
= INTEL_915G
;
127 dinfo
->pll_index
= PLLS_I9xx
;
129 case PCI_DEVICE_ID_INTEL_915GM
:
130 dinfo
->name
= "Intel(R) 915GM";
131 dinfo
->chipset
= INTEL_915GM
;
133 dinfo
->pll_index
= PLLS_I9xx
;
135 case PCI_DEVICE_ID_INTEL_945G
:
136 dinfo
->name
= "Intel(R) 945G";
137 dinfo
->chipset
= INTEL_945G
;
139 dinfo
->pll_index
= PLLS_I9xx
;
141 case PCI_DEVICE_ID_INTEL_945GM
:
142 dinfo
->name
= "Intel(R) 945GM";
143 dinfo
->chipset
= INTEL_945GM
;
145 dinfo
->pll_index
= PLLS_I9xx
;
153 intelfbhw_get_memory(struct pci_dev
*pdev
, int *aperture_size
,
156 struct pci_dev
*bridge_dev
;
160 if (!pdev
|| !aperture_size
|| !stolen_size
)
163 /* Find the bridge device. It is always 0:0.0 */
164 if (!(bridge_dev
= pci_find_slot(0, PCI_DEVFN(0, 0)))) {
165 ERR_MSG("cannot find bridge device\n");
169 /* Get the fb aperture size and "stolen" memory amount. */
171 pci_read_config_word(bridge_dev
, INTEL_GMCH_CTRL
, &tmp
);
172 switch (pdev
->device
) {
173 case PCI_DEVICE_ID_INTEL_915G
:
174 case PCI_DEVICE_ID_INTEL_915GM
:
175 case PCI_DEVICE_ID_INTEL_945G
:
176 case PCI_DEVICE_ID_INTEL_945GM
:
177 /* 915 and 945 chipsets support a 256MB aperture.
178 Aperture size is determined by inspected the
179 base address of the aperture. */
180 if (pci_resource_start(pdev
, 2) & 0x08000000)
181 *aperture_size
= MB(128);
183 *aperture_size
= MB(256);
186 if ((tmp
& INTEL_GMCH_MEM_MASK
) == INTEL_GMCH_MEM_64M
)
187 *aperture_size
= MB(64);
189 *aperture_size
= MB(128);
193 /* Stolen memory size is reduced by the GTT and the popup.
194 GTT is 1K per MB of aperture size, and popup is 4K. */
195 stolen_overhead
= (*aperture_size
/ MB(1)) + 4;
196 switch(pdev
->device
) {
197 case PCI_DEVICE_ID_INTEL_830M
:
198 case PCI_DEVICE_ID_INTEL_845G
:
199 switch (tmp
& INTEL_830_GMCH_GMS_MASK
) {
200 case INTEL_830_GMCH_GMS_STOLEN_512
:
201 *stolen_size
= KB(512) - KB(stolen_overhead
);
203 case INTEL_830_GMCH_GMS_STOLEN_1024
:
204 *stolen_size
= MB(1) - KB(stolen_overhead
);
206 case INTEL_830_GMCH_GMS_STOLEN_8192
:
207 *stolen_size
= MB(8) - KB(stolen_overhead
);
209 case INTEL_830_GMCH_GMS_LOCAL
:
210 ERR_MSG("only local memory found\n");
212 case INTEL_830_GMCH_GMS_DISABLED
:
213 ERR_MSG("video memory is disabled\n");
216 ERR_MSG("unexpected GMCH_GMS value: 0x%02x\n",
217 tmp
& INTEL_830_GMCH_GMS_MASK
);
222 switch (tmp
& INTEL_855_GMCH_GMS_MASK
) {
223 case INTEL_855_GMCH_GMS_STOLEN_1M
:
224 *stolen_size
= MB(1) - KB(stolen_overhead
);
226 case INTEL_855_GMCH_GMS_STOLEN_4M
:
227 *stolen_size
= MB(4) - KB(stolen_overhead
);
229 case INTEL_855_GMCH_GMS_STOLEN_8M
:
230 *stolen_size
= MB(8) - KB(stolen_overhead
);
232 case INTEL_855_GMCH_GMS_STOLEN_16M
:
233 *stolen_size
= MB(16) - KB(stolen_overhead
);
235 case INTEL_855_GMCH_GMS_STOLEN_32M
:
236 *stolen_size
= MB(32) - KB(stolen_overhead
);
238 case INTEL_915G_GMCH_GMS_STOLEN_48M
:
239 *stolen_size
= MB(48) - KB(stolen_overhead
);
241 case INTEL_915G_GMCH_GMS_STOLEN_64M
:
242 *stolen_size
= MB(64) - KB(stolen_overhead
);
244 case INTEL_855_GMCH_GMS_DISABLED
:
245 ERR_MSG("video memory is disabled\n");
248 ERR_MSG("unexpected GMCH_GMS value: 0x%02x\n",
249 tmp
& INTEL_855_GMCH_GMS_MASK
);
256 intelfbhw_check_non_crt(struct intelfb_info
*dinfo
)
260 if (INREG(LVDS
) & PORT_ENABLE
)
262 if (INREG(DVOA
) & PORT_ENABLE
)
264 if (INREG(DVOB
) & PORT_ENABLE
)
266 if (INREG(DVOC
) & PORT_ENABLE
)
273 intelfbhw_dvo_to_string(int dvo
)
277 else if (dvo
& DVOB_PORT
)
279 else if (dvo
& DVOC_PORT
)
281 else if (dvo
& LVDS_PORT
)
289 intelfbhw_validate_mode(struct intelfb_info
*dinfo
,
290 struct fb_var_screeninfo
*var
)
296 DBG_MSG("intelfbhw_validate_mode\n");
299 bytes_per_pixel
= var
->bits_per_pixel
/ 8;
300 if (bytes_per_pixel
== 3)
303 /* Check if enough video memory. */
304 tmp
= var
->yres_virtual
* var
->xres_virtual
* bytes_per_pixel
;
305 if (tmp
> dinfo
->fb
.size
) {
306 WRN_MSG("Not enough video ram for mode "
307 "(%d KByte vs %d KByte).\n",
308 BtoKB(tmp
), BtoKB(dinfo
->fb
.size
));
312 /* Check if x/y limits are OK. */
313 if (var
->xres
- 1 > HACTIVE_MASK
) {
314 WRN_MSG("X resolution too large (%d vs %d).\n",
315 var
->xres
, HACTIVE_MASK
+ 1);
318 if (var
->yres
- 1 > VACTIVE_MASK
) {
319 WRN_MSG("Y resolution too large (%d vs %d).\n",
320 var
->yres
, VACTIVE_MASK
+ 1);
324 /* Check for interlaced/doublescan modes. */
325 if (var
->vmode
& FB_VMODE_INTERLACED
) {
326 WRN_MSG("Mode is interlaced.\n");
329 if (var
->vmode
& FB_VMODE_DOUBLE
) {
330 WRN_MSG("Mode is double-scan.\n");
334 /* Check if clock is OK. */
335 tmp
= 1000000000 / var
->pixclock
;
336 if (tmp
< MIN_CLOCK
) {
337 WRN_MSG("Pixel clock is too low (%d MHz vs %d MHz).\n",
338 (tmp
+ 500) / 1000, MIN_CLOCK
/ 1000);
341 if (tmp
> MAX_CLOCK
) {
342 WRN_MSG("Pixel clock is too high (%d MHz vs %d MHz).\n",
343 (tmp
+ 500) / 1000, MAX_CLOCK
/ 1000);
351 intelfbhw_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
353 struct intelfb_info
*dinfo
= GET_DINFO(info
);
354 u32 offset
, xoffset
, yoffset
;
357 DBG_MSG("intelfbhw_pan_display\n");
360 xoffset
= ROUND_DOWN_TO(var
->xoffset
, 8);
361 yoffset
= var
->yoffset
;
363 if ((xoffset
+ var
->xres
> var
->xres_virtual
) ||
364 (yoffset
+ var
->yres
> var
->yres_virtual
))
367 offset
= (yoffset
* dinfo
->pitch
) +
368 (xoffset
* var
->bits_per_pixel
) / 8;
370 offset
+= dinfo
->fb
.offset
<< 12;
372 OUTREG(DSPABASE
, offset
);
377 /* Blank the screen. */
379 intelfbhw_do_blank(int blank
, struct fb_info
*info
)
381 struct intelfb_info
*dinfo
= GET_DINFO(info
);
385 DBG_MSG("intelfbhw_do_blank: blank is %d\n", blank
);
388 /* Turn plane A on or off */
389 tmp
= INREG(DSPACNTR
);
391 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
393 tmp
|= DISPPLANE_PLANE_ENABLE
;
394 OUTREG(DSPACNTR
, tmp
);
396 tmp
= INREG(DSPABASE
);
397 OUTREG(DSPABASE
, tmp
);
399 /* Turn off/on the HW cursor */
401 DBG_MSG("cursor_on is %d\n", dinfo
->cursor_on
);
403 if (dinfo
->cursor_on
) {
405 intelfbhw_cursor_hide(dinfo
);
407 intelfbhw_cursor_show(dinfo
);
409 dinfo
->cursor_on
= 1;
411 dinfo
->cursor_blanked
= blank
;
414 tmp
= INREG(ADPA
) & ~ADPA_DPMS_CONTROL_MASK
;
416 case FB_BLANK_UNBLANK
:
417 case FB_BLANK_NORMAL
:
420 case FB_BLANK_VSYNC_SUSPEND
:
423 case FB_BLANK_HSYNC_SUSPEND
:
426 case FB_BLANK_POWERDOWN
:
437 intelfbhw_setcolreg(struct intelfb_info
*dinfo
, unsigned regno
,
438 unsigned red
, unsigned green
, unsigned blue
,
442 DBG_MSG("intelfbhw_setcolreg: %d: (%d, %d, %d)\n",
443 regno
, red
, green
, blue
);
446 u32 palette_reg
= (dinfo
->pipe
== PIPE_A
) ?
447 PALETTE_A
: PALETTE_B
;
449 OUTREG(palette_reg
+ (regno
<< 2),
450 (red
<< PALETTE_8_RED_SHIFT
) |
451 (green
<< PALETTE_8_GREEN_SHIFT
) |
452 (blue
<< PALETTE_8_BLUE_SHIFT
));
457 intelfbhw_read_hw_state(struct intelfb_info
*dinfo
, struct intelfb_hwstate
*hw
,
463 DBG_MSG("intelfbhw_read_hw_state\n");
469 /* Read in as much of the HW state as possible. */
470 hw
->vga0_divisor
= INREG(VGA0_DIVISOR
);
471 hw
->vga1_divisor
= INREG(VGA1_DIVISOR
);
472 hw
->vga_pd
= INREG(VGAPD
);
473 hw
->dpll_a
= INREG(DPLL_A
);
474 hw
->dpll_b
= INREG(DPLL_B
);
475 hw
->fpa0
= INREG(FPA0
);
476 hw
->fpa1
= INREG(FPA1
);
477 hw
->fpb0
= INREG(FPB0
);
478 hw
->fpb1
= INREG(FPB1
);
484 /* This seems to be a problem with the 852GM/855GM */
485 for (i
= 0; i
< PALETTE_8_ENTRIES
; i
++) {
486 hw
->palette_a
[i
] = INREG(PALETTE_A
+ (i
<< 2));
487 hw
->palette_b
[i
] = INREG(PALETTE_B
+ (i
<< 2));
494 hw
->htotal_a
= INREG(HTOTAL_A
);
495 hw
->hblank_a
= INREG(HBLANK_A
);
496 hw
->hsync_a
= INREG(HSYNC_A
);
497 hw
->vtotal_a
= INREG(VTOTAL_A
);
498 hw
->vblank_a
= INREG(VBLANK_A
);
499 hw
->vsync_a
= INREG(VSYNC_A
);
500 hw
->src_size_a
= INREG(SRC_SIZE_A
);
501 hw
->bclrpat_a
= INREG(BCLRPAT_A
);
502 hw
->htotal_b
= INREG(HTOTAL_B
);
503 hw
->hblank_b
= INREG(HBLANK_B
);
504 hw
->hsync_b
= INREG(HSYNC_B
);
505 hw
->vtotal_b
= INREG(VTOTAL_B
);
506 hw
->vblank_b
= INREG(VBLANK_B
);
507 hw
->vsync_b
= INREG(VSYNC_B
);
508 hw
->src_size_b
= INREG(SRC_SIZE_B
);
509 hw
->bclrpat_b
= INREG(BCLRPAT_B
);
514 hw
->adpa
= INREG(ADPA
);
515 hw
->dvoa
= INREG(DVOA
);
516 hw
->dvob
= INREG(DVOB
);
517 hw
->dvoc
= INREG(DVOC
);
518 hw
->dvoa_srcdim
= INREG(DVOA_SRCDIM
);
519 hw
->dvob_srcdim
= INREG(DVOB_SRCDIM
);
520 hw
->dvoc_srcdim
= INREG(DVOC_SRCDIM
);
521 hw
->lvds
= INREG(LVDS
);
526 hw
->pipe_a_conf
= INREG(PIPEACONF
);
527 hw
->pipe_b_conf
= INREG(PIPEBCONF
);
528 hw
->disp_arb
= INREG(DISPARB
);
533 hw
->cursor_a_control
= INREG(CURSOR_A_CONTROL
);
534 hw
->cursor_b_control
= INREG(CURSOR_B_CONTROL
);
535 hw
->cursor_a_base
= INREG(CURSOR_A_BASEADDR
);
536 hw
->cursor_b_base
= INREG(CURSOR_B_BASEADDR
);
541 for (i
= 0; i
< 4; i
++) {
542 hw
->cursor_a_palette
[i
] = INREG(CURSOR_A_PALETTE0
+ (i
<< 2));
543 hw
->cursor_b_palette
[i
] = INREG(CURSOR_B_PALETTE0
+ (i
<< 2));
549 hw
->cursor_size
= INREG(CURSOR_SIZE
);
554 hw
->disp_a_ctrl
= INREG(DSPACNTR
);
555 hw
->disp_b_ctrl
= INREG(DSPBCNTR
);
556 hw
->disp_a_base
= INREG(DSPABASE
);
557 hw
->disp_b_base
= INREG(DSPBBASE
);
558 hw
->disp_a_stride
= INREG(DSPASTRIDE
);
559 hw
->disp_b_stride
= INREG(DSPBSTRIDE
);
564 hw
->vgacntrl
= INREG(VGACNTRL
);
569 hw
->add_id
= INREG(ADD_ID
);
574 for (i
= 0; i
< 7; i
++) {
575 hw
->swf0x
[i
] = INREG(SWF00
+ (i
<< 2));
576 hw
->swf1x
[i
] = INREG(SWF10
+ (i
<< 2));
578 hw
->swf3x
[i
] = INREG(SWF30
+ (i
<< 2));
581 for (i
= 0; i
< 8; i
++)
582 hw
->fence
[i
] = INREG(FENCE
+ (i
<< 2));
584 hw
->instpm
= INREG(INSTPM
);
585 hw
->mem_mode
= INREG(MEM_MODE
);
586 hw
->fw_blc_0
= INREG(FW_BLC_0
);
587 hw
->fw_blc_1
= INREG(FW_BLC_1
);
593 static int calc_vclock3(int index
, int m
, int n
, int p
)
595 if (p
== 0 || n
== 0)
597 return plls
[index
].ref_clk
* m
/ n
/ p
;
600 static int calc_vclock(int index
, int m1
, int m2
, int n
, int p1
, int p2
, int lvds
)
602 struct pll_min_max
*pll
= &plls
[index
];
605 m
= (5 * (m1
+ 2)) + (m2
+ 2);
607 vco
= pll
->ref_clk
* m
/ n
;
609 if (index
== PLLS_I8xx
) {
610 p
= ((p1
+ 2) * (1 << (p2
+ 1)));
612 p
= ((p1
) * (p2
? 5 : 10));
618 intelfbhw_get_p1p2(struct intelfb_info
*dinfo
, int dpll
, int *o_p1
, int *o_p2
)
622 if (IS_I9XX(dinfo
)) {
623 if (dpll
& DPLL_P1_FORCE_DIV2
)
626 p1
= (dpll
>> DPLL_P1_SHIFT
) & 0xff;
630 p2
= (dpll
>> DPLL_I9XX_P2_SHIFT
) & DPLL_P2_MASK
;
632 if (dpll
& DPLL_P1_FORCE_DIV2
)
635 p1
= (dpll
>> DPLL_P1_SHIFT
) & DPLL_P1_MASK
;
636 p2
= (dpll
>> DPLL_P2_SHIFT
) & DPLL_P2_MASK
;
645 intelfbhw_print_hw_state(struct intelfb_info
*dinfo
, struct intelfb_hwstate
*hw
)
648 int i
, m1
, m2
, n
, p1
, p2
;
649 int index
= dinfo
->pll_index
;
650 DBG_MSG("intelfbhw_print_hw_state\n");
654 /* Read in as much of the HW state as possible. */
655 printk("hw state dump start\n");
656 printk(" VGA0_DIVISOR: 0x%08x\n", hw
->vga0_divisor
);
657 printk(" VGA1_DIVISOR: 0x%08x\n", hw
->vga1_divisor
);
658 printk(" VGAPD: 0x%08x\n", hw
->vga_pd
);
659 n
= (hw
->vga0_divisor
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
660 m1
= (hw
->vga0_divisor
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
661 m2
= (hw
->vga0_divisor
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
663 intelfbhw_get_p1p2(dinfo
, hw
->vga_pd
, &p1
, &p2
);
665 printk(" VGA0: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
667 printk(" VGA0: clock is %d\n",
668 calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
670 n
= (hw
->vga1_divisor
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
671 m1
= (hw
->vga1_divisor
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
672 m2
= (hw
->vga1_divisor
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
674 intelfbhw_get_p1p2(dinfo
, hw
->vga_pd
, &p1
, &p2
);
675 printk(" VGA1: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
677 printk(" VGA1: clock is %d\n", calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
679 printk(" DPLL_A: 0x%08x\n", hw
->dpll_a
);
680 printk(" DPLL_B: 0x%08x\n", hw
->dpll_b
);
681 printk(" FPA0: 0x%08x\n", hw
->fpa0
);
682 printk(" FPA1: 0x%08x\n", hw
->fpa1
);
683 printk(" FPB0: 0x%08x\n", hw
->fpb0
);
684 printk(" FPB1: 0x%08x\n", hw
->fpb1
);
686 n
= (hw
->fpa0
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
687 m1
= (hw
->fpa0
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
688 m2
= (hw
->fpa0
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
690 intelfbhw_get_p1p2(dinfo
, hw
->dpll_a
, &p1
, &p2
);
692 printk(" PLLA0: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
694 printk(" PLLA0: clock is %d\n", calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
696 n
= (hw
->fpa1
>> FP_N_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
697 m1
= (hw
->fpa1
>> FP_M1_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
698 m2
= (hw
->fpa1
>> FP_M2_DIVISOR_SHIFT
) & FP_DIVISOR_MASK
;
700 intelfbhw_get_p1p2(dinfo
, hw
->dpll_a
, &p1
, &p2
);
702 printk(" PLLA1: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
704 printk(" PLLA1: clock is %d\n", calc_vclock(index
, m1
, m2
, n
, p1
, p2
, 0));
707 printk(" PALETTE_A:\n");
708 for (i
= 0; i
< PALETTE_8_ENTRIES
)
709 printk(" %3d: 0x%08x\n", i
, hw
->palette_a
[i
]);
710 printk(" PALETTE_B:\n");
711 for (i
= 0; i
< PALETTE_8_ENTRIES
)
712 printk(" %3d: 0x%08x\n", i
, hw
->palette_b
[i
]);
715 printk(" HTOTAL_A: 0x%08x\n", hw
->htotal_a
);
716 printk(" HBLANK_A: 0x%08x\n", hw
->hblank_a
);
717 printk(" HSYNC_A: 0x%08x\n", hw
->hsync_a
);
718 printk(" VTOTAL_A: 0x%08x\n", hw
->vtotal_a
);
719 printk(" VBLANK_A: 0x%08x\n", hw
->vblank_a
);
720 printk(" VSYNC_A: 0x%08x\n", hw
->vsync_a
);
721 printk(" SRC_SIZE_A: 0x%08x\n", hw
->src_size_a
);
722 printk(" BCLRPAT_A: 0x%08x\n", hw
->bclrpat_a
);
723 printk(" HTOTAL_B: 0x%08x\n", hw
->htotal_b
);
724 printk(" HBLANK_B: 0x%08x\n", hw
->hblank_b
);
725 printk(" HSYNC_B: 0x%08x\n", hw
->hsync_b
);
726 printk(" VTOTAL_B: 0x%08x\n", hw
->vtotal_b
);
727 printk(" VBLANK_B: 0x%08x\n", hw
->vblank_b
);
728 printk(" VSYNC_B: 0x%08x\n", hw
->vsync_b
);
729 printk(" SRC_SIZE_B: 0x%08x\n", hw
->src_size_b
);
730 printk(" BCLRPAT_B: 0x%08x\n", hw
->bclrpat_b
);
732 printk(" ADPA: 0x%08x\n", hw
->adpa
);
733 printk(" DVOA: 0x%08x\n", hw
->dvoa
);
734 printk(" DVOB: 0x%08x\n", hw
->dvob
);
735 printk(" DVOC: 0x%08x\n", hw
->dvoc
);
736 printk(" DVOA_SRCDIM: 0x%08x\n", hw
->dvoa_srcdim
);
737 printk(" DVOB_SRCDIM: 0x%08x\n", hw
->dvob_srcdim
);
738 printk(" DVOC_SRCDIM: 0x%08x\n", hw
->dvoc_srcdim
);
739 printk(" LVDS: 0x%08x\n", hw
->lvds
);
741 printk(" PIPEACONF: 0x%08x\n", hw
->pipe_a_conf
);
742 printk(" PIPEBCONF: 0x%08x\n", hw
->pipe_b_conf
);
743 printk(" DISPARB: 0x%08x\n", hw
->disp_arb
);
745 printk(" CURSOR_A_CONTROL: 0x%08x\n", hw
->cursor_a_control
);
746 printk(" CURSOR_B_CONTROL: 0x%08x\n", hw
->cursor_b_control
);
747 printk(" CURSOR_A_BASEADDR: 0x%08x\n", hw
->cursor_a_base
);
748 printk(" CURSOR_B_BASEADDR: 0x%08x\n", hw
->cursor_b_base
);
750 printk(" CURSOR_A_PALETTE: ");
751 for (i
= 0; i
< 4; i
++) {
752 printk("0x%08x", hw
->cursor_a_palette
[i
]);
757 printk(" CURSOR_B_PALETTE: ");
758 for (i
= 0; i
< 4; i
++) {
759 printk("0x%08x", hw
->cursor_b_palette
[i
]);
765 printk(" CURSOR_SIZE: 0x%08x\n", hw
->cursor_size
);
767 printk(" DSPACNTR: 0x%08x\n", hw
->disp_a_ctrl
);
768 printk(" DSPBCNTR: 0x%08x\n", hw
->disp_b_ctrl
);
769 printk(" DSPABASE: 0x%08x\n", hw
->disp_a_base
);
770 printk(" DSPBBASE: 0x%08x\n", hw
->disp_b_base
);
771 printk(" DSPASTRIDE: 0x%08x\n", hw
->disp_a_stride
);
772 printk(" DSPBSTRIDE: 0x%08x\n", hw
->disp_b_stride
);
774 printk(" VGACNTRL: 0x%08x\n", hw
->vgacntrl
);
775 printk(" ADD_ID: 0x%08x\n", hw
->add_id
);
777 for (i
= 0; i
< 7; i
++) {
778 printk(" SWF0%d 0x%08x\n", i
,
781 for (i
= 0; i
< 7; i
++) {
782 printk(" SWF1%d 0x%08x\n", i
,
785 for (i
= 0; i
< 3; i
++) {
786 printk(" SWF3%d 0x%08x\n", i
,
789 for (i
= 0; i
< 8; i
++)
790 printk(" FENCE%d 0x%08x\n", i
,
793 printk(" INSTPM 0x%08x\n", hw
->instpm
);
794 printk(" MEM_MODE 0x%08x\n", hw
->mem_mode
);
795 printk(" FW_BLC_0 0x%08x\n", hw
->fw_blc_0
);
796 printk(" FW_BLC_1 0x%08x\n", hw
->fw_blc_1
);
798 printk("hw state dump end\n");
804 /* Split the M parameter into M1 and M2. */
806 splitm(int index
, unsigned int m
, unsigned int *retm1
, unsigned int *retm2
)
810 struct pll_min_max
*pll
= &plls
[index
];
812 /* no point optimising too much - brute force m */
813 for (m1
= pll
->min_m1
; m1
< pll
->max_m1
+ 1; m1
++) {
814 for (m2
= pll
->min_m2
; m2
< pll
->max_m2
+ 1; m2
++) {
815 testm
= (5 * (m1
+ 2)) + (m2
+ 2);
817 *retm1
= (unsigned int)m1
;
818 *retm2
= (unsigned int)m2
;
826 /* Split the P parameter into P1 and P2. */
828 splitp(int index
, unsigned int p
, unsigned int *retp1
, unsigned int *retp2
)
831 struct pll_min_max
*pll
= &plls
[index
];
833 if (index
== PLLS_I9xx
) {
834 p2
= (p
% 10) ? 1 : 0;
836 p1
= p
/ (p2
? 5 : 10);
838 *retp1
= (unsigned int)p1
;
839 *retp2
= (unsigned int)p2
;
847 p1
= (p
/ (1 << (p2
+ 1))) - 2;
848 if (p
% 4 == 0 && p1
< pll
->min_p1
) {
850 p1
= (p
/ (1 << (p2
+ 1))) - 2;
852 if (p1
< pll
->min_p1
|| p1
> pll
->max_p1
||
853 (p1
+ 2) * (1 << (p2
+ 1)) != p
) {
856 *retp1
= (unsigned int)p1
;
857 *retp2
= (unsigned int)p2
;
863 calc_pll_params(int index
, int clock
, u32
*retm1
, u32
*retm2
, u32
*retn
, u32
*retp1
,
864 u32
*retp2
, u32
*retclock
)
866 u32 m1
, m2
, n
, p1
, p2
, n1
, testm
;
867 u32 f_vco
, p
, p_best
= 0, m
, f_out
= 0;
868 u32 err_max
, err_target
, err_best
= 10000000;
869 u32 n_best
= 0, m_best
= 0, f_best
, f_err
;
870 u32 p_min
, p_max
, p_inc
, div_max
;
871 struct pll_min_max
*pll
= &plls
[index
];
873 /* Accept 0.5% difference, but aim for 0.1% */
874 err_max
= 5 * clock
/ 1000;
875 err_target
= clock
/ 1000;
877 DBG_MSG("Clock is %d\n", clock
);
879 div_max
= pll
->max_vco
/ clock
;
881 p_inc
= (clock
<= pll
->p_transition_clk
) ? pll
->p_inc_lo
: pll
->p_inc_hi
;
883 p_max
= ROUND_DOWN_TO(div_max
, p_inc
);
884 if (p_min
< pll
->min_p
)
886 if (p_max
> pll
->max_p
)
889 DBG_MSG("p range is %d-%d (%d)\n", p_min
, p_max
, p_inc
);
893 if (splitp(index
, p
, &p1
, &p2
)) {
894 WRN_MSG("cannot split p = %d\n", p
);
902 m
= ROUND_UP_TO(f_vco
* n
, pll
->ref_clk
) / pll
->ref_clk
;
907 for (testm
= m
- 1; testm
<= m
; testm
++) {
908 f_out
= calc_vclock3(index
, m
, n
, p
);
909 if (splitm(index
, testm
, &m1
, &m2
)) {
910 WRN_MSG("cannot split m = %d\n", m
);
915 f_err
= clock
- f_out
;
916 else/* slightly bias the error for bigger clocks */
917 f_err
= f_out
- clock
+ 1;
919 if (f_err
< err_best
) {
928 } while ((n
<= pll
->max_n
) && (f_out
>= clock
));
930 } while ((p
<= p_max
));
933 WRN_MSG("cannot find parameters for clock %d\n", clock
);
939 splitm(index
, m
, &m1
, &m2
);
940 splitp(index
, p
, &p1
, &p2
);
943 DBG_MSG("m, n, p: %d (%d,%d), %d (%d), %d (%d,%d), "
944 "f: %d (%d), VCO: %d\n",
945 m
, m1
, m2
, n
, n1
, p
, p1
, p2
,
946 calc_vclock3(index
, m
, n
, p
),
947 calc_vclock(index
, m1
, m2
, n1
, p1
, p2
, 0),
948 calc_vclock3(index
, m
, n
, p
) * p
);
954 *retclock
= calc_vclock(index
, m1
, m2
, n1
, p1
, p2
, 0);
959 static __inline__
int
960 check_overflow(u32 value
, u32 limit
, const char *description
)
963 WRN_MSG("%s value %d exceeds limit %d\n",
964 description
, value
, limit
);
970 /* It is assumed that hw is filled in with the initial state information. */
972 intelfbhw_mode_to_hw(struct intelfb_info
*dinfo
, struct intelfb_hwstate
*hw
,
973 struct fb_var_screeninfo
*var
)
976 u32
*dpll
, *fp0
, *fp1
;
977 u32 m1
, m2
, n
, p1
, p2
, clock_target
, clock
;
978 u32 hsync_start
, hsync_end
, hblank_start
, hblank_end
, htotal
, hactive
;
979 u32 vsync_start
, vsync_end
, vblank_start
, vblank_end
, vtotal
, vactive
;
980 u32 vsync_pol
, hsync_pol
;
981 u32
*vs
, *vb
, *vt
, *hs
, *hb
, *ht
, *ss
, *pipe_conf
;
982 u32 stride_alignment
;
984 DBG_MSG("intelfbhw_mode_to_hw\n");
987 hw
->vgacntrl
|= VGA_DISABLE
;
989 /* Check whether pipe A or pipe B is enabled. */
990 if (hw
->pipe_a_conf
& PIPECONF_ENABLE
)
992 else if (hw
->pipe_b_conf
& PIPECONF_ENABLE
)
995 /* Set which pipe's registers will be set. */
996 if (pipe
== PIPE_B
) {
1006 ss
= &hw
->src_size_b
;
1007 pipe_conf
= &hw
->pipe_b_conf
;
1018 ss
= &hw
->src_size_a
;
1019 pipe_conf
= &hw
->pipe_a_conf
;
1022 /* Use ADPA register for sync control. */
1023 hw
->adpa
&= ~ADPA_USE_VGA_HVPOLARITY
;
1026 hsync_pol
= (var
->sync
& FB_SYNC_HOR_HIGH_ACT
) ?
1027 ADPA_SYNC_ACTIVE_HIGH
: ADPA_SYNC_ACTIVE_LOW
;
1028 vsync_pol
= (var
->sync
& FB_SYNC_VERT_HIGH_ACT
) ?
1029 ADPA_SYNC_ACTIVE_HIGH
: ADPA_SYNC_ACTIVE_LOW
;
1030 hw
->adpa
&= ~((ADPA_SYNC_ACTIVE_MASK
<< ADPA_VSYNC_ACTIVE_SHIFT
) |
1031 (ADPA_SYNC_ACTIVE_MASK
<< ADPA_HSYNC_ACTIVE_SHIFT
));
1032 hw
->adpa
|= (hsync_pol
<< ADPA_HSYNC_ACTIVE_SHIFT
) |
1033 (vsync_pol
<< ADPA_VSYNC_ACTIVE_SHIFT
);
1035 /* Connect correct pipe to the analog port DAC */
1036 hw
->adpa
&= ~(PIPE_MASK
<< ADPA_PIPE_SELECT_SHIFT
);
1037 hw
->adpa
|= (pipe
<< ADPA_PIPE_SELECT_SHIFT
);
1039 /* Set DPMS state to D0 (on) */
1040 hw
->adpa
&= ~ADPA_DPMS_CONTROL_MASK
;
1041 hw
->adpa
|= ADPA_DPMS_D0
;
1043 hw
->adpa
|= ADPA_DAC_ENABLE
;
1045 *dpll
|= (DPLL_VCO_ENABLE
| DPLL_VGA_MODE_DISABLE
);
1046 *dpll
&= ~(DPLL_RATE_SELECT_MASK
| DPLL_REFERENCE_SELECT_MASK
);
1047 *dpll
|= (DPLL_REFERENCE_DEFAULT
| DPLL_RATE_SELECT_FP0
);
1049 /* Desired clock in kHz */
1050 clock_target
= 1000000000 / var
->pixclock
;
1052 if (calc_pll_params(dinfo
->pll_index
, clock_target
, &m1
, &m2
,
1053 &n
, &p1
, &p2
, &clock
)) {
1054 WRN_MSG("calc_pll_params failed\n");
1058 /* Check for overflow. */
1059 if (check_overflow(p1
, DPLL_P1_MASK
, "PLL P1 parameter"))
1061 if (check_overflow(p2
, DPLL_P2_MASK
, "PLL P2 parameter"))
1063 if (check_overflow(m1
, FP_DIVISOR_MASK
, "PLL M1 parameter"))
1065 if (check_overflow(m2
, FP_DIVISOR_MASK
, "PLL M2 parameter"))
1067 if (check_overflow(n
, FP_DIVISOR_MASK
, "PLL N parameter"))
1070 *dpll
&= ~DPLL_P1_FORCE_DIV2
;
1071 *dpll
&= ~((DPLL_P2_MASK
<< DPLL_P2_SHIFT
) |
1072 (DPLL_P1_MASK
<< DPLL_P1_SHIFT
));
1074 if (IS_I9XX(dinfo
)) {
1075 *dpll
|= (p2
<< DPLL_I9XX_P2_SHIFT
);
1076 *dpll
|= (1 << (p1
- 1)) << DPLL_P1_SHIFT
;
1078 *dpll
|= (p2
<< DPLL_P2_SHIFT
) | (p1
<< DPLL_P1_SHIFT
);
1081 *fp0
= (n
<< FP_N_DIVISOR_SHIFT
) |
1082 (m1
<< FP_M1_DIVISOR_SHIFT
) |
1083 (m2
<< FP_M2_DIVISOR_SHIFT
);
1086 hw
->dvob
&= ~PORT_ENABLE
;
1087 hw
->dvoc
&= ~PORT_ENABLE
;
1089 /* Use display plane A. */
1090 hw
->disp_a_ctrl
|= DISPPLANE_PLANE_ENABLE
;
1091 hw
->disp_a_ctrl
&= ~DISPPLANE_GAMMA_ENABLE
;
1092 hw
->disp_a_ctrl
&= ~DISPPLANE_PIXFORMAT_MASK
;
1093 switch (intelfb_var_to_depth(var
)) {
1095 hw
->disp_a_ctrl
|= DISPPLANE_8BPP
| DISPPLANE_GAMMA_ENABLE
;
1098 hw
->disp_a_ctrl
|= DISPPLANE_15_16BPP
;
1101 hw
->disp_a_ctrl
|= DISPPLANE_16BPP
;
1104 hw
->disp_a_ctrl
|= DISPPLANE_32BPP_NO_ALPHA
;
1107 hw
->disp_a_ctrl
&= ~(PIPE_MASK
<< DISPPLANE_SEL_PIPE_SHIFT
);
1108 hw
->disp_a_ctrl
|= (pipe
<< DISPPLANE_SEL_PIPE_SHIFT
);
1110 /* Set CRTC registers. */
1111 hactive
= var
->xres
;
1112 hsync_start
= hactive
+ var
->right_margin
;
1113 hsync_end
= hsync_start
+ var
->hsync_len
;
1114 htotal
= hsync_end
+ var
->left_margin
;
1115 hblank_start
= hactive
;
1116 hblank_end
= htotal
;
1118 DBG_MSG("H: act %d, ss %d, se %d, tot %d bs %d, be %d\n",
1119 hactive
, hsync_start
, hsync_end
, htotal
, hblank_start
,
1122 vactive
= var
->yres
;
1123 vsync_start
= vactive
+ var
->lower_margin
;
1124 vsync_end
= vsync_start
+ var
->vsync_len
;
1125 vtotal
= vsync_end
+ var
->upper_margin
;
1126 vblank_start
= vactive
;
1127 vblank_end
= vtotal
;
1128 vblank_end
= vsync_end
+ 1;
1130 DBG_MSG("V: act %d, ss %d, se %d, tot %d bs %d, be %d\n",
1131 vactive
, vsync_start
, vsync_end
, vtotal
, vblank_start
,
1134 /* Adjust for register values, and check for overflow. */
1136 if (check_overflow(hactive
, HACTIVE_MASK
, "CRTC hactive"))
1139 if (check_overflow(hsync_start
, HSYNCSTART_MASK
, "CRTC hsync_start"))
1142 if (check_overflow(hsync_end
, HSYNCEND_MASK
, "CRTC hsync_end"))
1145 if (check_overflow(htotal
, HTOTAL_MASK
, "CRTC htotal"))
1148 if (check_overflow(hblank_start
, HBLANKSTART_MASK
, "CRTC hblank_start"))
1151 if (check_overflow(hblank_end
, HBLANKEND_MASK
, "CRTC hblank_end"))
1155 if (check_overflow(vactive
, VACTIVE_MASK
, "CRTC vactive"))
1158 if (check_overflow(vsync_start
, VSYNCSTART_MASK
, "CRTC vsync_start"))
1161 if (check_overflow(vsync_end
, VSYNCEND_MASK
, "CRTC vsync_end"))
1164 if (check_overflow(vtotal
, VTOTAL_MASK
, "CRTC vtotal"))
1167 if (check_overflow(vblank_start
, VBLANKSTART_MASK
, "CRTC vblank_start"))
1170 if (check_overflow(vblank_end
, VBLANKEND_MASK
, "CRTC vblank_end"))
1173 *ht
= (htotal
<< HTOTAL_SHIFT
) | (hactive
<< HACTIVE_SHIFT
);
1174 *hb
= (hblank_start
<< HBLANKSTART_SHIFT
) |
1175 (hblank_end
<< HSYNCEND_SHIFT
);
1176 *hs
= (hsync_start
<< HSYNCSTART_SHIFT
) | (hsync_end
<< HSYNCEND_SHIFT
);
1178 *vt
= (vtotal
<< VTOTAL_SHIFT
) | (vactive
<< VACTIVE_SHIFT
);
1179 *vb
= (vblank_start
<< VBLANKSTART_SHIFT
) |
1180 (vblank_end
<< VSYNCEND_SHIFT
);
1181 *vs
= (vsync_start
<< VSYNCSTART_SHIFT
) | (vsync_end
<< VSYNCEND_SHIFT
);
1182 *ss
= (hactive
<< SRC_SIZE_HORIZ_SHIFT
) |
1183 (vactive
<< SRC_SIZE_VERT_SHIFT
);
1185 hw
->disp_a_stride
= dinfo
->pitch
;
1186 DBG_MSG("pitch is %d\n", hw
->disp_a_stride
);
1188 hw
->disp_a_base
= hw
->disp_a_stride
* var
->yoffset
+
1189 var
->xoffset
* var
->bits_per_pixel
/ 8;
1191 hw
->disp_a_base
+= dinfo
->fb
.offset
<< 12;
1193 /* Check stride alignment. */
1194 stride_alignment
= IS_I9XX(dinfo
) ? STRIDE_ALIGNMENT_I9XX
:
1196 if (hw
->disp_a_stride
% stride_alignment
!= 0) {
1197 WRN_MSG("display stride %d has bad alignment %d\n",
1198 hw
->disp_a_stride
, stride_alignment
);
1202 /* Set the palette to 8-bit mode. */
1203 *pipe_conf
&= ~PIPECONF_GAMMA
;
1207 /* Program a (non-VGA) video mode. */
1209 intelfbhw_program_mode(struct intelfb_info
*dinfo
,
1210 const struct intelfb_hwstate
*hw
, int blank
)
1214 const u32
*dpll
, *fp0
, *fp1
, *pipe_conf
;
1215 const u32
*hs
, *ht
, *hb
, *vs
, *vt
, *vb
, *ss
;
1216 u32 dpll_reg
, fp0_reg
, fp1_reg
, pipe_conf_reg
;
1217 u32 hsync_reg
, htotal_reg
, hblank_reg
;
1218 u32 vsync_reg
, vtotal_reg
, vblank_reg
;
1220 u32 count
, tmp_val
[3];
1222 /* Assume single pipe, display plane A, analog CRT. */
1225 DBG_MSG("intelfbhw_program_mode\n");
1229 tmp
= INREG(VGACNTRL
);
1231 OUTREG(VGACNTRL
, tmp
);
1233 /* Check whether pipe A or pipe B is enabled. */
1234 if (hw
->pipe_a_conf
& PIPECONF_ENABLE
)
1236 else if (hw
->pipe_b_conf
& PIPECONF_ENABLE
)
1241 if (pipe
== PIPE_B
) {
1245 pipe_conf
= &hw
->pipe_b_conf
;
1252 ss
= &hw
->src_size_b
;
1256 pipe_conf_reg
= PIPEBCONF
;
1257 hsync_reg
= HSYNC_B
;
1258 htotal_reg
= HTOTAL_B
;
1259 hblank_reg
= HBLANK_B
;
1260 vsync_reg
= VSYNC_B
;
1261 vtotal_reg
= VTOTAL_B
;
1262 vblank_reg
= VBLANK_B
;
1263 src_size_reg
= SRC_SIZE_B
;
1268 pipe_conf
= &hw
->pipe_a_conf
;
1275 ss
= &hw
->src_size_a
;
1279 pipe_conf_reg
= PIPEACONF
;
1280 hsync_reg
= HSYNC_A
;
1281 htotal_reg
= HTOTAL_A
;
1282 hblank_reg
= HBLANK_A
;
1283 vsync_reg
= VSYNC_A
;
1284 vtotal_reg
= VTOTAL_A
;
1285 vblank_reg
= VBLANK_A
;
1286 src_size_reg
= SRC_SIZE_A
;
1290 tmp
= INREG(pipe_conf_reg
);
1291 tmp
&= ~PIPECONF_ENABLE
;
1292 OUTREG(pipe_conf_reg
, tmp
);
1296 tmp_val
[count
%3] = INREG(0x70000);
1297 if ((tmp_val
[0] == tmp_val
[1]) && (tmp_val
[1]==tmp_val
[2]))
1301 if (count
% 200 == 0) {
1302 tmp
= INREG(pipe_conf_reg
);
1303 tmp
&= ~PIPECONF_ENABLE
;
1304 OUTREG(pipe_conf_reg
, tmp
);
1306 } while(count
< 2000);
1308 OUTREG(ADPA
, INREG(ADPA
) & ~ADPA_DAC_ENABLE
);
1310 /* Disable planes A and B. */
1311 tmp
= INREG(DSPACNTR
);
1312 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
1313 OUTREG(DSPACNTR
, tmp
);
1314 tmp
= INREG(DSPBCNTR
);
1315 tmp
&= ~DISPPLANE_PLANE_ENABLE
;
1316 OUTREG(DSPBCNTR
, tmp
);
1318 /* Wait for vblank. For now, just wait for a 50Hz cycle (20ms)) */
1321 OUTREG(DVOB
, INREG(DVOB
) & ~PORT_ENABLE
);
1322 OUTREG(DVOC
, INREG(DVOC
) & ~PORT_ENABLE
);
1323 OUTREG(ADPA
, INREG(ADPA
) & ~ADPA_DAC_ENABLE
);
1327 tmp
&= ~ADPA_DPMS_CONTROL_MASK
;
1328 tmp
|= ADPA_DPMS_D3
;
1331 /* do some funky magic - xyzzy */
1332 OUTREG(0x61204, 0xabcd0000);
1335 tmp
= INREG(dpll_reg
);
1336 dpll_reg
&= ~DPLL_VCO_ENABLE
;
1337 OUTREG(dpll_reg
, tmp
);
1339 /* Set PLL parameters */
1340 OUTREG(fp0_reg
, *fp0
);
1341 OUTREG(fp1_reg
, *fp1
);
1344 OUTREG(dpll_reg
, *dpll
);
1347 OUTREG(DVOB
, hw
->dvob
);
1348 OUTREG(DVOC
, hw
->dvoc
);
1350 /* undo funky magic */
1351 OUTREG(0x61204, 0x00000000);
1354 OUTREG(ADPA
, INREG(ADPA
) | ADPA_DAC_ENABLE
);
1355 OUTREG(ADPA
, (hw
->adpa
& ~(ADPA_DPMS_CONTROL_MASK
)) | ADPA_DPMS_D3
);
1357 /* Set pipe parameters */
1358 OUTREG(hsync_reg
, *hs
);
1359 OUTREG(hblank_reg
, *hb
);
1360 OUTREG(htotal_reg
, *ht
);
1361 OUTREG(vsync_reg
, *vs
);
1362 OUTREG(vblank_reg
, *vb
);
1363 OUTREG(vtotal_reg
, *vt
);
1364 OUTREG(src_size_reg
, *ss
);
1367 OUTREG(pipe_conf_reg
, *pipe_conf
| PIPECONF_ENABLE
);
1371 tmp
&= ~ADPA_DPMS_CONTROL_MASK
;
1372 tmp
|= ADPA_DPMS_D0
;
1375 /* setup display plane */
1376 if (dinfo
->pdev
->device
== PCI_DEVICE_ID_INTEL_830M
) {
1378 * i830M errata: the display plane must be enabled
1379 * to allow writes to the other bits in the plane
1382 tmp
= INREG(DSPACNTR
);
1383 if ((tmp
& DISPPLANE_PLANE_ENABLE
) != DISPPLANE_PLANE_ENABLE
) {
1384 tmp
|= DISPPLANE_PLANE_ENABLE
;
1385 OUTREG(DSPACNTR
, tmp
);
1387 hw
->disp_a_ctrl
|DISPPLANE_PLANE_ENABLE
);
1392 OUTREG(DSPACNTR
, hw
->disp_a_ctrl
& ~DISPPLANE_PLANE_ENABLE
);
1393 OUTREG(DSPASTRIDE
, hw
->disp_a_stride
);
1394 OUTREG(DSPABASE
, hw
->disp_a_base
);
1398 tmp
= INREG(DSPACNTR
);
1399 tmp
|= DISPPLANE_PLANE_ENABLE
;
1400 OUTREG(DSPACNTR
, tmp
);
1401 OUTREG(DSPABASE
, hw
->disp_a_base
);
1407 /* forward declarations */
1408 static void refresh_ring(struct intelfb_info
*dinfo
);
1409 static void reset_state(struct intelfb_info
*dinfo
);
1410 static void do_flush(struct intelfb_info
*dinfo
);
1413 wait_ring(struct intelfb_info
*dinfo
, int n
)
1417 u32 last_head
= INREG(PRI_RING_HEAD
) & RING_HEAD_MASK
;
1420 DBG_MSG("wait_ring: %d\n", n
);
1423 end
= jiffies
+ (HZ
* 3);
1424 while (dinfo
->ring_space
< n
) {
1425 dinfo
->ring_head
= INREG(PRI_RING_HEAD
) & RING_HEAD_MASK
;
1426 if (dinfo
->ring_tail
+ RING_MIN_FREE
< dinfo
->ring_head
)
1427 dinfo
->ring_space
= dinfo
->ring_head
1428 - (dinfo
->ring_tail
+ RING_MIN_FREE
);
1430 dinfo
->ring_space
= (dinfo
->ring
.size
+
1432 - (dinfo
->ring_tail
+ RING_MIN_FREE
);
1433 if (dinfo
->ring_head
!= last_head
) {
1434 end
= jiffies
+ (HZ
* 3);
1435 last_head
= dinfo
->ring_head
;
1438 if (time_before(end
, jiffies
)) {
1442 refresh_ring(dinfo
);
1444 end
= jiffies
+ (HZ
* 3);
1447 WRN_MSG("ring buffer : space: %d wanted %d\n",
1448 dinfo
->ring_space
, n
);
1449 WRN_MSG("lockup - turning off hardware "
1451 dinfo
->ring_lockup
= 1;
1461 do_flush(struct intelfb_info
*dinfo
) {
1463 OUT_RING(MI_FLUSH
| MI_WRITE_DIRTY_STATE
| MI_INVALIDATE_MAP_CACHE
);
1469 intelfbhw_do_sync(struct intelfb_info
*dinfo
)
1472 DBG_MSG("intelfbhw_do_sync\n");
1479 * Send a flush, then wait until the ring is empty. This is what
1480 * the XFree86 driver does, and actually it doesn't seem a lot worse
1481 * than the recommended method (both have problems).
1484 wait_ring(dinfo
, dinfo
->ring
.size
- RING_MIN_FREE
);
1485 dinfo
->ring_space
= dinfo
->ring
.size
- RING_MIN_FREE
;
1489 refresh_ring(struct intelfb_info
*dinfo
)
1492 DBG_MSG("refresh_ring\n");
1495 dinfo
->ring_head
= INREG(PRI_RING_HEAD
) & RING_HEAD_MASK
;
1496 dinfo
->ring_tail
= INREG(PRI_RING_TAIL
) & RING_TAIL_MASK
;
1497 if (dinfo
->ring_tail
+ RING_MIN_FREE
< dinfo
->ring_head
)
1498 dinfo
->ring_space
= dinfo
->ring_head
1499 - (dinfo
->ring_tail
+ RING_MIN_FREE
);
1501 dinfo
->ring_space
= (dinfo
->ring
.size
+ dinfo
->ring_head
)
1502 - (dinfo
->ring_tail
+ RING_MIN_FREE
);
1506 reset_state(struct intelfb_info
*dinfo
)
1512 DBG_MSG("reset_state\n");
1515 for (i
= 0; i
< FENCE_NUM
; i
++)
1516 OUTREG(FENCE
+ (i
<< 2), 0);
1518 /* Flush the ring buffer if it's enabled. */
1519 tmp
= INREG(PRI_RING_LENGTH
);
1520 if (tmp
& RING_ENABLE
) {
1522 DBG_MSG("reset_state: ring was enabled\n");
1524 refresh_ring(dinfo
);
1525 intelfbhw_do_sync(dinfo
);
1529 OUTREG(PRI_RING_LENGTH
, 0);
1530 OUTREG(PRI_RING_HEAD
, 0);
1531 OUTREG(PRI_RING_TAIL
, 0);
1532 OUTREG(PRI_RING_START
, 0);
1535 /* Stop the 2D engine, and turn off the ring buffer. */
1537 intelfbhw_2d_stop(struct intelfb_info
*dinfo
)
1540 DBG_MSG("intelfbhw_2d_stop: accel: %d, ring_active: %d\n", dinfo
->accel
,
1541 dinfo
->ring_active
);
1547 dinfo
->ring_active
= 0;
1552 * Enable the ring buffer, and initialise the 2D engine.
1553 * It is assumed that the graphics engine has been stopped by previously
1554 * calling intelfb_2d_stop().
1557 intelfbhw_2d_start(struct intelfb_info
*dinfo
)
1560 DBG_MSG("intelfbhw_2d_start: accel: %d, ring_active: %d\n",
1561 dinfo
->accel
, dinfo
->ring_active
);
1567 /* Initialise the primary ring buffer. */
1568 OUTREG(PRI_RING_LENGTH
, 0);
1569 OUTREG(PRI_RING_TAIL
, 0);
1570 OUTREG(PRI_RING_HEAD
, 0);
1572 OUTREG(PRI_RING_START
, dinfo
->ring
.physical
& RING_START_MASK
);
1573 OUTREG(PRI_RING_LENGTH
,
1574 ((dinfo
->ring
.size
- GTT_PAGE_SIZE
) & RING_LENGTH_MASK
) |
1575 RING_NO_REPORT
| RING_ENABLE
);
1576 refresh_ring(dinfo
);
1577 dinfo
->ring_active
= 1;
1580 /* 2D fillrect (solid fill or invert) */
1582 intelfbhw_do_fillrect(struct intelfb_info
*dinfo
, u32 x
, u32 y
, u32 w
, u32 h
,
1583 u32 color
, u32 pitch
, u32 bpp
, u32 rop
)
1585 u32 br00
, br09
, br13
, br14
, br16
;
1588 DBG_MSG("intelfbhw_do_fillrect: (%d,%d) %dx%d, c 0x%06x, p %d bpp %d, "
1589 "rop 0x%02x\n", x
, y
, w
, h
, color
, pitch
, bpp
, rop
);
1592 br00
= COLOR_BLT_CMD
;
1593 br09
= dinfo
->fb_start
+ (y
* pitch
+ x
* (bpp
/ 8));
1594 br13
= (rop
<< ROP_SHIFT
) | pitch
;
1595 br14
= (h
<< HEIGHT_SHIFT
) | ((w
* (bpp
/ 8)) << WIDTH_SHIFT
);
1600 br13
|= COLOR_DEPTH_8
;
1603 br13
|= COLOR_DEPTH_16
;
1606 br13
|= COLOR_DEPTH_32
;
1607 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1621 DBG_MSG("ring = 0x%08x, 0x%08x (%d)\n", dinfo
->ring_head
,
1622 dinfo
->ring_tail
, dinfo
->ring_space
);
1627 intelfbhw_do_bitblt(struct intelfb_info
*dinfo
, u32 curx
, u32 cury
,
1628 u32 dstx
, u32 dsty
, u32 w
, u32 h
, u32 pitch
, u32 bpp
)
1630 u32 br00
, br09
, br11
, br12
, br13
, br22
, br23
, br26
;
1633 DBG_MSG("intelfbhw_do_bitblt: (%d,%d)->(%d,%d) %dx%d, p %d bpp %d\n",
1634 curx
, cury
, dstx
, dsty
, w
, h
, pitch
, bpp
);
1637 br00
= XY_SRC_COPY_BLT_CMD
;
1638 br09
= dinfo
->fb_start
;
1639 br11
= (pitch
<< PITCH_SHIFT
);
1640 br12
= dinfo
->fb_start
;
1641 br13
= (SRC_ROP_GXCOPY
<< ROP_SHIFT
) | (pitch
<< PITCH_SHIFT
);
1642 br22
= (dstx
<< WIDTH_SHIFT
) | (dsty
<< HEIGHT_SHIFT
);
1643 br23
= ((dstx
+ w
) << WIDTH_SHIFT
) |
1644 ((dsty
+ h
) << HEIGHT_SHIFT
);
1645 br26
= (curx
<< WIDTH_SHIFT
) | (cury
<< HEIGHT_SHIFT
);
1649 br13
|= COLOR_DEPTH_8
;
1652 br13
|= COLOR_DEPTH_16
;
1655 br13
|= COLOR_DEPTH_32
;
1656 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1673 intelfbhw_do_drawglyph(struct intelfb_info
*dinfo
, u32 fg
, u32 bg
, u32 w
,
1674 u32 h
, const u8
* cdat
, u32 x
, u32 y
, u32 pitch
, u32 bpp
)
1676 int nbytes
, ndwords
, pad
, tmp
;
1677 u32 br00
, br09
, br13
, br18
, br19
, br22
, br23
;
1678 int dat
, ix
, iy
, iw
;
1682 DBG_MSG("intelfbhw_do_drawglyph: (%d,%d) %dx%d\n", x
, y
, w
, h
);
1685 /* size in bytes of a padded scanline */
1686 nbytes
= ROUND_UP_TO(w
, 16) / 8;
1688 /* Total bytes of padded scanline data to write out. */
1689 nbytes
= nbytes
* h
;
1692 * Check if the glyph data exceeds the immediate mode limit.
1693 * It would take a large font (1K pixels) to hit this limit.
1695 if (nbytes
> MAX_MONO_IMM_SIZE
)
1698 /* Src data is packaged a dword (32-bit) at a time. */
1699 ndwords
= ROUND_UP_TO(nbytes
, 4) / 4;
1702 * Ring has to be padded to a quad word. But because the command starts
1703 with 7 bytes, pad only if there is an even number of ndwords
1705 pad
= !(ndwords
% 2);
1707 tmp
= (XY_MONO_SRC_IMM_BLT_CMD
& DW_LENGTH_MASK
) + ndwords
;
1708 br00
= (XY_MONO_SRC_IMM_BLT_CMD
& ~DW_LENGTH_MASK
) | tmp
;
1709 br09
= dinfo
->fb_start
;
1710 br13
= (SRC_ROP_GXCOPY
<< ROP_SHIFT
) | (pitch
<< PITCH_SHIFT
);
1713 br22
= (x
<< WIDTH_SHIFT
) | (y
<< HEIGHT_SHIFT
);
1714 br23
= ((x
+ w
) << WIDTH_SHIFT
) | ((y
+ h
) << HEIGHT_SHIFT
);
1718 br13
|= COLOR_DEPTH_8
;
1721 br13
|= COLOR_DEPTH_16
;
1724 br13
|= COLOR_DEPTH_32
;
1725 br00
|= WRITE_ALPHA
| WRITE_RGB
;
1729 START_RING(8 + ndwords
);
1738 iw
= ROUND_UP_TO(w
, 8) / 8;
1741 for (j
= 0; j
< 2; ++j
) {
1742 for (i
= 0; i
< 2; ++i
) {
1743 if (ix
!= iw
|| i
== 0)
1744 dat
|= cdat
[iy
*iw
+ ix
++] << (i
+j
*2)*8;
1746 if (ix
== iw
&& iy
!= (h
-1)) {
1760 /* HW cursor functions. */
1762 intelfbhw_cursor_init(struct intelfb_info
*dinfo
)
1767 DBG_MSG("intelfbhw_cursor_init\n");
1770 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1771 if (!dinfo
->cursor
.physical
)
1773 tmp
= INREG(CURSOR_A_CONTROL
);
1774 tmp
&= ~(CURSOR_MODE_MASK
| CURSOR_MOBILE_GAMMA_ENABLE
|
1775 CURSOR_MEM_TYPE_LOCAL
|
1776 (1 << CURSOR_PIPE_SELECT_SHIFT
));
1777 tmp
|= CURSOR_MODE_DISABLE
;
1778 OUTREG(CURSOR_A_CONTROL
, tmp
);
1779 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1781 tmp
= INREG(CURSOR_CONTROL
);
1782 tmp
&= ~(CURSOR_FORMAT_MASK
| CURSOR_GAMMA_ENABLE
|
1783 CURSOR_ENABLE
| CURSOR_STRIDE_MASK
);
1784 tmp
= CURSOR_FORMAT_3C
;
1785 OUTREG(CURSOR_CONTROL
, tmp
);
1786 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.offset
<< 12);
1787 tmp
= (64 << CURSOR_SIZE_H_SHIFT
) |
1788 (64 << CURSOR_SIZE_V_SHIFT
);
1789 OUTREG(CURSOR_SIZE
, tmp
);
1794 intelfbhw_cursor_hide(struct intelfb_info
*dinfo
)
1799 DBG_MSG("intelfbhw_cursor_hide\n");
1802 dinfo
->cursor_on
= 0;
1803 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1804 if (!dinfo
->cursor
.physical
)
1806 tmp
= INREG(CURSOR_A_CONTROL
);
1807 tmp
&= ~CURSOR_MODE_MASK
;
1808 tmp
|= CURSOR_MODE_DISABLE
;
1809 OUTREG(CURSOR_A_CONTROL
, tmp
);
1811 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1813 tmp
= INREG(CURSOR_CONTROL
);
1814 tmp
&= ~CURSOR_ENABLE
;
1815 OUTREG(CURSOR_CONTROL
, tmp
);
1820 intelfbhw_cursor_show(struct intelfb_info
*dinfo
)
1825 DBG_MSG("intelfbhw_cursor_show\n");
1828 dinfo
->cursor_on
= 1;
1830 if (dinfo
->cursor_blanked
)
1833 if (dinfo
->mobile
|| IS_I9XX(dinfo
)) {
1834 if (!dinfo
->cursor
.physical
)
1836 tmp
= INREG(CURSOR_A_CONTROL
);
1837 tmp
&= ~CURSOR_MODE_MASK
;
1838 tmp
|= CURSOR_MODE_64_4C_AX
;
1839 OUTREG(CURSOR_A_CONTROL
, tmp
);
1841 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1843 tmp
= INREG(CURSOR_CONTROL
);
1844 tmp
|= CURSOR_ENABLE
;
1845 OUTREG(CURSOR_CONTROL
, tmp
);
1850 intelfbhw_cursor_setpos(struct intelfb_info
*dinfo
, int x
, int y
)
1855 DBG_MSG("intelfbhw_cursor_setpos: (%d, %d)\n", x
, y
);
1859 * Sets the position. The coordinates are assumed to already
1860 * have any offset adjusted. Assume that the cursor is never
1861 * completely off-screen, and that x, y are always >= 0.
1864 tmp
= ((x
& CURSOR_POS_MASK
) << CURSOR_X_SHIFT
) |
1865 ((y
& CURSOR_POS_MASK
) << CURSOR_Y_SHIFT
);
1866 OUTREG(CURSOR_A_POSITION
, tmp
);
1868 if (IS_I9XX(dinfo
)) {
1869 OUTREG(CURSOR_A_BASEADDR
, dinfo
->cursor
.physical
);
1874 intelfbhw_cursor_setcolor(struct intelfb_info
*dinfo
, u32 bg
, u32 fg
)
1877 DBG_MSG("intelfbhw_cursor_setcolor\n");
1880 OUTREG(CURSOR_A_PALETTE0
, bg
& CURSOR_PALETTE_MASK
);
1881 OUTREG(CURSOR_A_PALETTE1
, fg
& CURSOR_PALETTE_MASK
);
1882 OUTREG(CURSOR_A_PALETTE2
, fg
& CURSOR_PALETTE_MASK
);
1883 OUTREG(CURSOR_A_PALETTE3
, bg
& CURSOR_PALETTE_MASK
);
1887 intelfbhw_cursor_load(struct intelfb_info
*dinfo
, int width
, int height
,
1890 u8 __iomem
*addr
= (u8 __iomem
*)dinfo
->cursor
.virtual;
1891 int i
, j
, w
= width
/ 8;
1892 int mod
= width
% 8, t_mask
, d_mask
;
1895 DBG_MSG("intelfbhw_cursor_load\n");
1898 if (!dinfo
->cursor
.virtual)
1901 t_mask
= 0xff >> mod
;
1902 d_mask
= ~(0xff >> mod
);
1903 for (i
= height
; i
--; ) {
1904 for (j
= 0; j
< w
; j
++) {
1905 writeb(0x00, addr
+ j
);
1906 writeb(*(data
++), addr
+ j
+8);
1909 writeb(t_mask
, addr
+ j
);
1910 writeb(*(data
++) & d_mask
, addr
+ j
+8);
1917 intelfbhw_cursor_reset(struct intelfb_info
*dinfo
) {
1918 u8 __iomem
*addr
= (u8 __iomem
*)dinfo
->cursor
.virtual;
1922 DBG_MSG("intelfbhw_cursor_reset\n");
1925 if (!dinfo
->cursor
.virtual)
1928 for (i
= 64; i
--; ) {
1929 for (j
= 0; j
< 8; j
++) {
1930 writeb(0xff, addr
+ j
+0);
1931 writeb(0x00, addr
+ j
+8);