2 * XG20, XG21, XG40, XG42 frame buffer device
3 * for Linux kernels 2.5.x, 2.6.x
4 * Base on TW's sis fbdev code.
7 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9 #include <linux/sizes.h>
10 #include <linux/module.h>
11 #include <linux/pci.h>
16 #include "vb_setmode.h"
18 #define Index_CR_GPIO_Reg1 0x48
19 #define Index_CR_GPIO_Reg3 0x4a
21 #define GPIOG_EN BIT(6)
22 #define GPIOG_READ BIT(1)
24 static char *forcecrt2type
;
27 static unsigned int refresh_rate
;
29 /* -------------------- Macro definitions ---------------------------- */
32 static void dumpVGAReg(struct xgifb_video_info
*xgifb_info
)
36 xgifb_reg_set(XGISR
, 0x05, 0x86);
38 for (i
= 0; i
< 0x4f; i
++) {
39 reg
= xgifb_reg_get(XGISR
, i
);
40 pr_debug("o 3c4 %x\n", i
);
41 pr_debug("i 3c5 => %x\n", reg
);
44 for (i
= 0; i
< 0xF0; i
++) {
45 reg
= xgifb_reg_get(XGICR
, i
);
46 pr_debug("o 3d4 %x\n", i
);
47 pr_debug("i 3d5 => %x\n", reg
);
51 static inline void dumpVGAReg(struct xgifb_video_info
*xgifb_info
)
56 /* --------------- Hardware Access Routines -------------------------- */
58 static int XGIfb_mode_rate_to_dclock(struct vb_device_info
*XGI_Pr
,
59 struct xgi_hw_device_info
*HwDeviceExtension
,
62 unsigned short ModeNo
= modeno
;
63 unsigned short ModeIdIndex
= 0, ClockIndex
= 0;
64 unsigned short RefreshRateTableIndex
= 0;
67 InitTo330Pointer(HwDeviceExtension
->jChipType
, XGI_Pr
);
69 XGI_SearchModeID(ModeNo
, &ModeIdIndex
);
71 RefreshRateTableIndex
= XGI_GetRatePtrCRT2(HwDeviceExtension
, ModeNo
,
74 ClockIndex
= XGI330_RefIndex
[RefreshRateTableIndex
].Ext_CRTVCLK
;
76 Clock
= XGI_VCLKData
[ClockIndex
].CLOCK
* 1000;
81 static int XGIfb_mode_rate_to_ddata(struct vb_device_info
*XGI_Pr
,
82 struct xgi_hw_device_info
*HwDeviceExtension
,
84 u32
*left_margin
, u32
*right_margin
, u32
*upper_margin
,
85 u32
*lower_margin
, u32
*hsync_len
, u32
*vsync_len
, u32
*sync
,
88 unsigned short ModeNo
= modeno
;
89 unsigned short ModeIdIndex
, index
= 0;
90 unsigned short RefreshRateTableIndex
= 0;
92 unsigned short VRE
, VBE
, VRS
, VDE
;
93 unsigned short HRE
, HBE
, HRS
, HDE
;
94 unsigned char sr_data
, cr_data
, cr_data2
;
95 int B
, C
, D
, F
, temp
, j
;
97 InitTo330Pointer(HwDeviceExtension
->jChipType
, XGI_Pr
);
98 if (!XGI_SearchModeID(ModeNo
, &ModeIdIndex
))
100 RefreshRateTableIndex
= XGI_GetRatePtrCRT2(HwDeviceExtension
, ModeNo
,
101 ModeIdIndex
, XGI_Pr
);
102 index
= XGI330_RefIndex
[RefreshRateTableIndex
].Ext_CRT1CRTC
;
104 sr_data
= XGI_CRT1Table
[index
].CR
[5];
106 HDE
= XGI330_RefIndex
[RefreshRateTableIndex
].XRes
>> 3;
108 cr_data
= XGI_CRT1Table
[index
].CR
[3];
110 /* Horizontal retrace (=sync) start */
111 HRS
= (cr_data
& 0xff) | ((unsigned short) (sr_data
& 0xC0) << 2);
114 sr_data
= XGI_CRT1Table
[index
].CR
[6];
116 cr_data
= XGI_CRT1Table
[index
].CR
[2];
118 cr_data2
= XGI_CRT1Table
[index
].CR
[4];
120 /* Horizontal blank end */
121 HBE
= (cr_data
& 0x1f) | ((unsigned short) (cr_data2
& 0x80) >> 2)
122 | ((unsigned short) (sr_data
& 0x03) << 6);
124 /* Horizontal retrace (=sync) end */
125 HRE
= (cr_data2
& 0x1f) | ((sr_data
& 0x04) << 3);
127 temp
= HBE
- ((HDE
- 1) & 255);
128 B
= (temp
> 0) ? temp
: (temp
+ 256);
130 temp
= HRE
- ((HDE
+ F
+ 3) & 63);
131 C
= (temp
> 0) ? temp
: (temp
+ 64);
135 *left_margin
= D
* 8;
136 *right_margin
= F
* 8;
139 sr_data
= XGI_CRT1Table
[index
].CR
[14];
141 cr_data2
= XGI_CRT1Table
[index
].CR
[9];
143 VDE
= XGI330_RefIndex
[RefreshRateTableIndex
].YRes
;
145 cr_data
= XGI_CRT1Table
[index
].CR
[10];
147 /* Vertical retrace (=sync) start */
148 VRS
= (cr_data
& 0xff) | ((unsigned short) (cr_data2
& 0x04) << 6)
149 | ((unsigned short) (cr_data2
& 0x80) << 2)
150 | ((unsigned short) (sr_data
& 0x08) << 7);
153 cr_data
= XGI_CRT1Table
[index
].CR
[13];
155 /* Vertical blank end */
156 VBE
= (cr_data
& 0xff) | ((unsigned short) (sr_data
& 0x10) << 4);
157 temp
= VBE
- ((VDE
- 1) & 511);
158 B
= (temp
> 0) ? temp
: (temp
+ 512);
160 cr_data
= XGI_CRT1Table
[index
].CR
[11];
162 /* Vertical retrace (=sync) end */
163 VRE
= (cr_data
& 0x0f) | ((sr_data
& 0x20) >> 1);
164 temp
= VRE
- ((VDE
+ F
- 1) & 31);
165 C
= (temp
> 0) ? temp
: (temp
+ 32);
173 if (XGI330_RefIndex
[RefreshRateTableIndex
].Ext_InfoFlag
& 0x8000)
174 *sync
&= ~FB_SYNC_VERT_HIGH_ACT
;
176 *sync
|= FB_SYNC_VERT_HIGH_ACT
;
178 if (XGI330_RefIndex
[RefreshRateTableIndex
].Ext_InfoFlag
& 0x4000)
179 *sync
&= ~FB_SYNC_HOR_HIGH_ACT
;
181 *sync
|= FB_SYNC_HOR_HIGH_ACT
;
183 *vmode
= FB_VMODE_NONINTERLACED
;
184 if (XGI330_RefIndex
[RefreshRateTableIndex
].Ext_InfoFlag
& 0x0080)
185 *vmode
= FB_VMODE_INTERLACED
;
188 while (XGI330_EModeIDTable
[j
].Ext_ModeID
!= 0xff) {
189 if (XGI330_EModeIDTable
[j
].Ext_ModeID
==
190 XGI330_RefIndex
[RefreshRateTableIndex
].ModeID
) {
191 if (XGI330_EModeIDTable
[j
].Ext_ModeFlag
&
193 *vmode
= FB_VMODE_DOUBLE
;
204 void XGIRegInit(struct vb_device_info
*XGI_Pr
, unsigned long BaseAddr
)
206 XGI_Pr
->P3c4
= BaseAddr
+ 0x14;
207 XGI_Pr
->P3d4
= BaseAddr
+ 0x24;
208 XGI_Pr
->P3c0
= BaseAddr
+ 0x10;
209 XGI_Pr
->P3ce
= BaseAddr
+ 0x1e;
210 XGI_Pr
->P3c2
= BaseAddr
+ 0x12;
211 XGI_Pr
->P3cc
= BaseAddr
+ 0x1c;
212 XGI_Pr
->P3ca
= BaseAddr
+ 0x1a;
213 XGI_Pr
->P3c6
= BaseAddr
+ 0x16;
214 XGI_Pr
->P3c7
= BaseAddr
+ 0x17;
215 XGI_Pr
->P3c8
= BaseAddr
+ 0x18;
216 XGI_Pr
->P3c9
= BaseAddr
+ 0x19;
217 XGI_Pr
->P3da
= BaseAddr
+ 0x2A;
218 XGI_Pr
->Part0Port
= BaseAddr
+ XGI_CRT2_PORT_00
;
219 /* Digital video interface registers (LCD) */
220 XGI_Pr
->Part1Port
= BaseAddr
+ SIS_CRT2_PORT_04
;
221 /* 301 TV Encoder registers */
222 XGI_Pr
->Part2Port
= BaseAddr
+ SIS_CRT2_PORT_10
;
223 /* 301 Macrovision registers */
224 XGI_Pr
->Part3Port
= BaseAddr
+ SIS_CRT2_PORT_12
;
225 /* 301 VGA2 (and LCD) registers */
226 XGI_Pr
->Part4Port
= BaseAddr
+ SIS_CRT2_PORT_14
;
227 /* 301 palette address port registers */
228 XGI_Pr
->Part5Port
= BaseAddr
+ SIS_CRT2_PORT_14
+ 2;
232 /* ------------------ Internal helper routines ----------------- */
234 static int XGIfb_GetXG21DefaultLVDSModeIdx(struct xgifb_video_info
*xgifb_info
)
238 while ((XGIbios_mode
[i
].mode_no
!= 0)
239 && (XGIbios_mode
[i
].xres
<= xgifb_info
->lvds_data
.LVDSHDE
)) {
240 if ((XGIbios_mode
[i
].xres
== xgifb_info
->lvds_data
.LVDSHDE
)
241 && (XGIbios_mode
[i
].yres
== xgifb_info
->lvds_data
.LVDSVDE
)
242 && (XGIbios_mode
[i
].bpp
== 8)) {
251 static void XGIfb_search_mode(struct xgifb_video_info
*xgifb_info
,
259 if (sscanf(name
, "%ux%ux%u", &xres
, &yres
, &bpp
) != 3)
263 bpp
= 32; /* That's for people who mix up color and fb depth. */
265 for (i
= 0; XGIbios_mode
[i
].mode_no
!= 0; i
++)
266 if (XGIbios_mode
[i
].xres
== xres
&&
267 XGIbios_mode
[i
].yres
== yres
&&
268 XGIbios_mode
[i
].bpp
== bpp
) {
269 xgifb_info
->mode_idx
= i
;
273 pr_info("Invalid mode '%s'\n", name
);
276 static void XGIfb_search_vesamode(struct xgifb_video_info
*xgifb_info
,
277 unsigned int vesamode
)
284 vesamode
&= 0x1dff; /* Clean VESA mode number from other flags */
286 while (XGIbios_mode
[i
].mode_no
!= 0) {
287 if ((XGIbios_mode
[i
].vesa_mode_no_1
== vesamode
) ||
288 (XGIbios_mode
[i
].vesa_mode_no_2
== vesamode
)) {
289 xgifb_info
->mode_idx
= i
;
296 pr_info("Invalid VESA mode 0x%x'\n", vesamode
);
299 static int XGIfb_validate_mode(struct xgifb_video_info
*xgifb_info
, int myindex
)
302 struct xgi_hw_device_info
*hw_info
= &xgifb_info
->hw_info
;
303 unsigned long required_mem
;
305 if (xgifb_info
->chip
== XG21
) {
306 if (xgifb_info
->display2
== XGIFB_DISP_LCD
) {
307 xres
= xgifb_info
->lvds_data
.LVDSHDE
;
308 yres
= xgifb_info
->lvds_data
.LVDSVDE
;
309 if (XGIbios_mode
[myindex
].xres
> xres
)
311 if (XGIbios_mode
[myindex
].yres
> yres
)
313 if ((XGIbios_mode
[myindex
].xres
< xres
) &&
314 (XGIbios_mode
[myindex
].yres
< yres
)) {
315 if (XGIbios_mode
[myindex
].bpp
> 8)
324 /* FIXME: for now, all is valid on XG27 */
325 if (xgifb_info
->chip
== XG27
)
328 if (!(XGIbios_mode
[myindex
].chipset
& MD_XGI315
))
331 switch (xgifb_info
->display2
) {
333 switch (hw_info
->ulCRT2LCDType
) {
379 if (XGIbios_mode
[myindex
].xres
> xres
)
381 if (XGIbios_mode
[myindex
].yres
> yres
)
383 if ((hw_info
->ulExternalChip
== 0x01) || /* LVDS */
384 (hw_info
->ulExternalChip
== 0x05)) { /* LVDS+Chrontel */
385 switch (XGIbios_mode
[myindex
].xres
) {
387 if (XGIbios_mode
[myindex
].yres
!= 512)
389 if (hw_info
->ulCRT2LCDType
== LCD_1024x600
)
393 if ((XGIbios_mode
[myindex
].yres
!= 400)
394 && (XGIbios_mode
[myindex
].yres
399 if (XGIbios_mode
[myindex
].yres
!= 600)
403 if ((XGIbios_mode
[myindex
].yres
!= 600) &&
404 (XGIbios_mode
[myindex
].yres
!= 768))
406 if ((XGIbios_mode
[myindex
].yres
== 600) &&
407 (hw_info
->ulCRT2LCDType
!= LCD_1024x600
))
411 if ((XGIbios_mode
[myindex
].yres
) != 768)
413 if (hw_info
->ulCRT2LCDType
!= LCD_1152x768
)
417 if ((XGIbios_mode
[myindex
].yres
!= 768) &&
418 (XGIbios_mode
[myindex
].yres
!= 1024))
420 if ((XGIbios_mode
[myindex
].yres
== 768) &&
421 (hw_info
->ulCRT2LCDType
!= LCD_1280x768
))
425 if (XGIbios_mode
[myindex
].yres
!= 1050)
429 if (XGIbios_mode
[myindex
].yres
!= 1200)
436 switch (XGIbios_mode
[myindex
].xres
) {
438 if (XGIbios_mode
[myindex
].yres
!= 512)
442 if ((XGIbios_mode
[myindex
].yres
!= 400) &&
443 (XGIbios_mode
[myindex
].yres
!= 480))
447 if (XGIbios_mode
[myindex
].yres
!= 600)
451 if (XGIbios_mode
[myindex
].yres
!= 768)
455 if ((XGIbios_mode
[myindex
].yres
!= 960) &&
456 (XGIbios_mode
[myindex
].yres
!= 1024))
458 if (XGIbios_mode
[myindex
].yres
== 960) {
459 if (hw_info
->ulCRT2LCDType
==
465 if (XGIbios_mode
[myindex
].yres
!= 1050)
469 if (XGIbios_mode
[myindex
].yres
!= 1200)
478 switch (XGIbios_mode
[myindex
].xres
) {
484 if (xgifb_info
->TV_type
== TVMODE_NTSC
) {
485 if (XGIbios_mode
[myindex
].yres
!= 480)
487 } else if (xgifb_info
->TV_type
== TVMODE_PAL
) {
488 if (XGIbios_mode
[myindex
].yres
!= 576)
491 /* LVDS/CHRONTEL does not support 720 */
492 if (xgifb_info
->hasVB
== HASVB_LVDS_CHRONTEL
||
493 xgifb_info
->hasVB
== HASVB_CHRONTEL
) {
498 if (xgifb_info
->TV_type
== TVMODE_NTSC
) {
499 if (XGIbios_mode
[myindex
].bpp
== 32)
508 if (XGIbios_mode
[myindex
].xres
> 1280)
511 case XGIFB_DISP_NONE
:
516 required_mem
= XGIbios_mode
[myindex
].xres
* XGIbios_mode
[myindex
].yres
*
517 XGIbios_mode
[myindex
].bpp
/ 8;
518 if (required_mem
> xgifb_info
->video_size
)
524 static void XGIfb_search_crt2type(const char *name
)
531 while (XGI_crt2type
[i
].type_no
!= -1) {
532 if (!strcmp(name
, XGI_crt2type
[i
].name
)) {
533 XGIfb_crt2type
= XGI_crt2type
[i
].type_no
;
534 XGIfb_tvplug
= XGI_crt2type
[i
].tvplug_no
;
539 if (XGIfb_crt2type
< 0)
540 pr_info("Invalid CRT2 type: %s\n", name
);
543 static u8
XGIfb_search_refresh_rate(struct xgifb_video_info
*xgifb_info
,
549 xres
= XGIbios_mode
[xgifb_info
->mode_idx
].xres
;
550 yres
= XGIbios_mode
[xgifb_info
->mode_idx
].yres
;
552 xgifb_info
->rate_idx
= 0;
553 while ((XGIfb_vrate
[i
].idx
!= 0) && (XGIfb_vrate
[i
].xres
<= xres
)) {
554 if ((XGIfb_vrate
[i
].xres
== xres
) &&
555 (XGIfb_vrate
[i
].yres
== yres
)) {
556 if (XGIfb_vrate
[i
].refresh
== rate
) {
557 xgifb_info
->rate_idx
= XGIfb_vrate
[i
].idx
;
559 } else if (XGIfb_vrate
[i
].refresh
> rate
) {
560 if ((XGIfb_vrate
[i
].refresh
- rate
) <= 3) {
561 pr_debug("Adjusting rate from %d up to %d\n",
562 rate
, XGIfb_vrate
[i
].refresh
);
563 xgifb_info
->rate_idx
=
565 xgifb_info
->refresh_rate
=
566 XGIfb_vrate
[i
].refresh
;
567 } else if (((rate
- XGIfb_vrate
[i
- 1].refresh
)
568 <= 2) && (XGIfb_vrate
[i
].idx
570 pr_debug("Adjusting rate from %d down to %d\n",
572 XGIfb_vrate
[i
-1].refresh
);
573 xgifb_info
->rate_idx
=
574 XGIfb_vrate
[i
- 1].idx
;
575 xgifb_info
->refresh_rate
=
576 XGIfb_vrate
[i
- 1].refresh
;
579 } else if ((rate
- XGIfb_vrate
[i
].refresh
) <= 2) {
580 pr_debug("Adjusting rate from %d down to %d\n",
581 rate
, XGIfb_vrate
[i
].refresh
);
582 xgifb_info
->rate_idx
= XGIfb_vrate
[i
].idx
;
588 if (xgifb_info
->rate_idx
> 0)
589 return xgifb_info
->rate_idx
;
590 pr_info("Unsupported rate %d for %dx%d\n",
595 static void XGIfb_search_tvstd(const char *name
)
602 while (XGI_tvtype
[i
].type_no
!= -1) {
603 if (!strcmp(name
, XGI_tvtype
[i
].name
)) {
604 XGIfb_tvmode
= XGI_tvtype
[i
].type_no
;
611 /* ----------- FBDev related routines for all series ----------- */
613 static void XGIfb_bpp_to_var(struct xgifb_video_info
*xgifb_info
,
614 struct fb_var_screeninfo
*var
)
616 switch (var
->bits_per_pixel
) {
618 var
->red
.offset
= var
->green
.offset
= var
->blue
.offset
= 0;
619 var
->red
.length
= var
->green
.length
= var
->blue
.length
= 6;
620 xgifb_info
->video_cmap_len
= 256;
623 var
->red
.offset
= 11;
625 var
->green
.offset
= 5;
626 var
->green
.length
= 6;
627 var
->blue
.offset
= 0;
628 var
->blue
.length
= 5;
629 var
->transp
.offset
= 0;
630 var
->transp
.length
= 0;
631 xgifb_info
->video_cmap_len
= 16;
634 var
->red
.offset
= 16;
636 var
->green
.offset
= 8;
637 var
->green
.length
= 8;
638 var
->blue
.offset
= 0;
639 var
->blue
.length
= 8;
640 var
->transp
.offset
= 24;
641 var
->transp
.length
= 8;
642 xgifb_info
->video_cmap_len
= 16;
647 /* --------------------- SetMode routines ------------------------- */
649 static void XGIfb_pre_setmode(struct xgifb_video_info
*xgifb_info
)
651 u8 cr30
= 0, cr31
= 0;
653 cr31
= xgifb_reg_get(XGICR
, 0x31);
656 switch (xgifb_info
->display2
) {
658 cr30
= (SIS_VB_OUTPUT_CRT2
| SIS_SIMULTANEOUS_VIEW_ENABLE
);
659 cr31
|= SIS_DRIVER_MODE
;
662 cr30
= (SIS_VB_OUTPUT_LCD
| SIS_SIMULTANEOUS_VIEW_ENABLE
);
663 cr31
|= SIS_DRIVER_MODE
;
666 if (xgifb_info
->TV_type
== TVMODE_HIVISION
)
667 cr30
= (SIS_VB_OUTPUT_HIVISION
668 | SIS_SIMULTANEOUS_VIEW_ENABLE
);
669 else if (xgifb_info
->TV_plug
== TVPLUG_SVIDEO
)
670 cr30
= (SIS_VB_OUTPUT_SVIDEO
671 | SIS_SIMULTANEOUS_VIEW_ENABLE
);
672 else if (xgifb_info
->TV_plug
== TVPLUG_COMPOSITE
)
673 cr30
= (SIS_VB_OUTPUT_COMPOSITE
674 | SIS_SIMULTANEOUS_VIEW_ENABLE
);
675 else if (xgifb_info
->TV_plug
== TVPLUG_SCART
)
676 cr30
= (SIS_VB_OUTPUT_SCART
677 | SIS_SIMULTANEOUS_VIEW_ENABLE
);
678 cr31
|= SIS_DRIVER_MODE
;
680 if (XGIfb_tvmode
== 1 || xgifb_info
->TV_type
== TVMODE_PAL
)
685 default: /* disable CRT2 */
687 cr31
|= (SIS_DRIVER_MODE
| SIS_VB_OUTPUT_DISABLE
);
690 xgifb_reg_set(XGICR
, IND_XGI_SCRATCH_REG_CR30
, cr30
);
691 xgifb_reg_set(XGICR
, IND_XGI_SCRATCH_REG_CR31
, cr31
);
692 xgifb_reg_set(XGICR
, IND_XGI_SCRATCH_REG_CR33
,
693 (xgifb_info
->rate_idx
& 0x0F));
696 static void XGIfb_post_setmode(struct xgifb_video_info
*xgifb_info
)
699 unsigned char doit
= 1;
701 if (xgifb_info
->video_bpp
== 8) {
703 * We can't switch off CRT1 on LVDS/Chrontel
706 if ((xgifb_info
->hasVB
== HASVB_LVDS
) ||
707 (xgifb_info
->hasVB
== HASVB_LVDS_CHRONTEL
)) {
711 * We can't switch off CRT1 on 301B-DH
712 * in 8bpp Modes if using LCD
714 if (xgifb_info
->display2
== XGIFB_DISP_LCD
)
718 /* We can't switch off CRT1 if bridge is in slave mode */
719 if (xgifb_info
->hasVB
!= HASVB_NONE
) {
720 reg
= xgifb_reg_get(XGIPART1
, 0x00);
722 if ((reg
& 0x50) == 0x10)
729 reg
= xgifb_reg_get(XGICR
, 0x17);
730 if ((XGIfb_crt1off
) && (doit
))
734 xgifb_reg_set(XGICR
, 0x17, reg
);
736 xgifb_reg_and(XGISR
, IND_SIS_RAMDAC_CONTROL
, ~0x04);
738 if (xgifb_info
->display2
== XGIFB_DISP_TV
&&
739 xgifb_info
->hasVB
== HASVB_301
) {
741 reg
= xgifb_reg_get(XGIPART4
, 0x01);
743 if (reg
< 0xB0) { /* Set filter for XGI301 */
746 switch (xgifb_info
->video_width
) {
748 filter_tb
= (xgifb_info
->TV_type
==
749 TVMODE_NTSC
) ? 4 : 12;
752 filter_tb
= (xgifb_info
->TV_type
==
753 TVMODE_NTSC
) ? 5 : 13;
756 filter_tb
= (xgifb_info
->TV_type
==
757 TVMODE_NTSC
) ? 6 : 14;
760 filter_tb
= (xgifb_info
->TV_type
==
761 TVMODE_NTSC
) ? 7 : 15;
768 xgifb_reg_or(XGIPART1
,
769 SIS_CRT2_WENABLE_315
,
772 if (xgifb_info
->TV_type
== TVMODE_NTSC
) {
774 xgifb_reg_and(XGIPART2
, 0x3a, 0x1f);
776 if (xgifb_info
->TV_plug
== TVPLUG_SVIDEO
) {
778 xgifb_reg_and(XGIPART2
, 0x30, 0xdf);
780 } else if (xgifb_info
->TV_plug
781 == TVPLUG_COMPOSITE
) {
783 xgifb_reg_or(XGIPART2
, 0x30, 0x20);
785 switch (xgifb_info
->video_width
) {
787 xgifb_reg_set(XGIPART2
,
790 xgifb_reg_set(XGIPART2
,
793 xgifb_reg_set(XGIPART2
,
796 xgifb_reg_set(XGIPART2
,
801 xgifb_reg_set(XGIPART2
,
804 xgifb_reg_set(XGIPART2
,
807 xgifb_reg_set(XGIPART2
,
810 xgifb_reg_set(XGIPART2
,
815 xgifb_reg_set(XGIPART2
,
818 xgifb_reg_set(XGIPART2
,
821 xgifb_reg_set(XGIPART2
,
824 xgifb_reg_set(XGIPART2
,
831 } else if (xgifb_info
->TV_type
== TVMODE_PAL
) {
833 xgifb_reg_and(XGIPART2
, 0x3A, 0x1F);
835 if (xgifb_info
->TV_plug
== TVPLUG_SVIDEO
) {
837 xgifb_reg_and(XGIPART2
, 0x30, 0xDF);
839 } else if (xgifb_info
->TV_plug
840 == TVPLUG_COMPOSITE
) {
842 xgifb_reg_or(XGIPART2
, 0x30, 0x20);
844 switch (xgifb_info
->video_width
) {
846 xgifb_reg_set(XGIPART2
,
849 xgifb_reg_set(XGIPART2
,
852 xgifb_reg_set(XGIPART2
,
855 xgifb_reg_set(XGIPART2
,
860 xgifb_reg_set(XGIPART2
,
863 xgifb_reg_set(XGIPART2
,
866 xgifb_reg_set(XGIPART2
,
869 xgifb_reg_set(XGIPART2
,
874 xgifb_reg_set(XGIPART2
,
877 xgifb_reg_set(XGIPART2
,
880 xgifb_reg_set(XGIPART2
,
883 xgifb_reg_set(XGIPART2
,
891 if ((filter
>= 0) && (filter
<= 7)) {
892 pr_debug("FilterTable[%d]-%d: %*ph\n",
894 4, XGI_TV_filter
[filter_tb
].
899 (XGI_TV_filter
[filter_tb
].
904 (XGI_TV_filter
[filter_tb
].
909 (XGI_TV_filter
[filter_tb
].
914 (XGI_TV_filter
[filter_tb
].
921 static int XGIfb_do_set_var(struct fb_var_screeninfo
*var
, int isactive
,
922 struct fb_info
*info
)
924 struct xgifb_video_info
*xgifb_info
= info
->par
;
925 struct xgi_hw_device_info
*hw_info
= &xgifb_info
->hw_info
;
926 unsigned int htotal
= var
->left_margin
+ var
->xres
+ var
->right_margin
928 unsigned int vtotal
= var
->upper_margin
+ var
->yres
+ var
->lower_margin
930 #if defined(__BIG_ENDIAN)
933 unsigned int drate
= 0, hrate
= 0;
937 info
->var
.xres_virtual
= var
->xres_virtual
;
938 info
->var
.yres_virtual
= var
->yres_virtual
;
939 info
->var
.bits_per_pixel
= var
->bits_per_pixel
;
941 if ((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_NONINTERLACED
)
943 else if ((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_DOUBLE
)
946 if (!htotal
|| !vtotal
) {
947 pr_debug("Invalid 'var' information\n");
949 } pr_debug("var->pixclock=%d, htotal=%d, vtotal=%d\n",
950 var
->pixclock
, htotal
, vtotal
);
953 drate
= 1000000000 / var
->pixclock
;
954 hrate
= (drate
* 1000) / htotal
;
955 xgifb_info
->refresh_rate
= (unsigned int) (hrate
* 2
958 xgifb_info
->refresh_rate
= 60;
961 pr_debug("Change mode to %dx%dx%d-%dHz\n",
965 xgifb_info
->refresh_rate
);
967 old_mode
= xgifb_info
->mode_idx
;
968 xgifb_info
->mode_idx
= 0;
970 while ((XGIbios_mode
[xgifb_info
->mode_idx
].mode_no
!= 0) &&
971 (XGIbios_mode
[xgifb_info
->mode_idx
].xres
<= var
->xres
)) {
972 if ((XGIbios_mode
[xgifb_info
->mode_idx
].xres
== var
->xres
) &&
973 (XGIbios_mode
[xgifb_info
->mode_idx
].yres
== var
->yres
) &&
974 (XGIbios_mode
[xgifb_info
->mode_idx
].bpp
975 == var
->bits_per_pixel
)) {
979 xgifb_info
->mode_idx
++;
983 xgifb_info
->mode_idx
= XGIfb_validate_mode(xgifb_info
,
984 xgifb_info
->mode_idx
);
986 xgifb_info
->mode_idx
= -1;
988 if (xgifb_info
->mode_idx
< 0) {
989 pr_err("Mode %dx%dx%d not supported\n",
990 var
->xres
, var
->yres
, var
->bits_per_pixel
);
991 xgifb_info
->mode_idx
= old_mode
;
995 if (XGIfb_search_refresh_rate(xgifb_info
,
996 xgifb_info
->refresh_rate
) == 0) {
997 xgifb_info
->rate_idx
= 1;
998 xgifb_info
->refresh_rate
= 60;
1003 XGIfb_pre_setmode(xgifb_info
);
1004 if (XGISetModeNew(xgifb_info
, hw_info
,
1005 XGIbios_mode
[xgifb_info
->mode_idx
].mode_no
)
1007 pr_err("Setting mode[0x%x] failed\n",
1008 XGIbios_mode
[xgifb_info
->mode_idx
].mode_no
);
1011 info
->fix
.line_length
= (info
->var
.xres_virtual
1012 * info
->var
.bits_per_pixel
) >> 6;
1014 xgifb_reg_set(XGISR
, IND_SIS_PASSWORD
, SIS_PASSWORD
);
1016 xgifb_reg_set(XGICR
, 0x13, (info
->fix
.line_length
& 0x00ff));
1017 xgifb_reg_set(XGISR
,
1019 (info
->fix
.line_length
& 0xff00) >> 8);
1021 XGIfb_post_setmode(xgifb_info
);
1023 pr_debug("Set new mode: %dx%dx%d-%d\n",
1024 XGIbios_mode
[xgifb_info
->mode_idx
].xres
,
1025 XGIbios_mode
[xgifb_info
->mode_idx
].yres
,
1026 XGIbios_mode
[xgifb_info
->mode_idx
].bpp
,
1027 xgifb_info
->refresh_rate
);
1029 xgifb_info
->video_bpp
= XGIbios_mode
[xgifb_info
->mode_idx
].bpp
;
1030 xgifb_info
->video_vwidth
= info
->var
.xres_virtual
;
1031 xgifb_info
->video_width
=
1032 XGIbios_mode
[xgifb_info
->mode_idx
].xres
;
1033 xgifb_info
->video_vheight
= info
->var
.yres_virtual
;
1034 xgifb_info
->video_height
=
1035 XGIbios_mode
[xgifb_info
->mode_idx
].yres
;
1036 xgifb_info
->org_x
= xgifb_info
->org_y
= 0;
1037 xgifb_info
->video_linelength
= info
->var
.xres_virtual
1038 * (xgifb_info
->video_bpp
>> 3);
1039 switch (xgifb_info
->video_bpp
) {
1041 xgifb_info
->DstColor
= 0x0000;
1042 xgifb_info
->XGI310_AccelDepth
= 0x00000000;
1043 xgifb_info
->video_cmap_len
= 256;
1044 #if defined(__BIG_ENDIAN)
1045 cr_data
= xgifb_reg_get(XGICR
, 0x4D);
1046 xgifb_reg_set(XGICR
, 0x4D, (cr_data
& 0xE0));
1050 xgifb_info
->DstColor
= 0x8000;
1051 xgifb_info
->XGI310_AccelDepth
= 0x00010000;
1052 #if defined(__BIG_ENDIAN)
1053 cr_data
= xgifb_reg_get(XGICR
, 0x4D);
1054 xgifb_reg_set(XGICR
, 0x4D, ((cr_data
& 0xE0) | 0x0B));
1056 xgifb_info
->video_cmap_len
= 16;
1059 xgifb_info
->DstColor
= 0xC000;
1060 xgifb_info
->XGI310_AccelDepth
= 0x00020000;
1061 xgifb_info
->video_cmap_len
= 16;
1062 #if defined(__BIG_ENDIAN)
1063 cr_data
= xgifb_reg_get(XGICR
, 0x4D);
1064 xgifb_reg_set(XGICR
, 0x4D, ((cr_data
& 0xE0) | 0x15));
1068 xgifb_info
->video_cmap_len
= 16;
1069 pr_err("Unsupported depth %d\n",
1070 xgifb_info
->video_bpp
);
1074 XGIfb_bpp_to_var(xgifb_info
, var
); /*update ARGB info*/
1076 dumpVGAReg(xgifb_info
);
1080 static int XGIfb_pan_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
1082 struct xgifb_video_info
*xgifb_info
= info
->par
;
1085 base
= var
->yoffset
* info
->var
.xres_virtual
+ var
->xoffset
;
1087 /* calculate base bpp dep. */
1088 switch (info
->var
.bits_per_pixel
) {
1100 xgifb_reg_set(XGISR
, IND_SIS_PASSWORD
, SIS_PASSWORD
);
1102 xgifb_reg_set(XGICR
, 0x0D, base
& 0xFF);
1103 xgifb_reg_set(XGICR
, 0x0C, (base
>> 8) & 0xFF);
1104 xgifb_reg_set(XGISR
, 0x0D, (base
>> 16) & 0xFF);
1105 xgifb_reg_set(XGISR
, 0x37, (base
>> 24) & 0x03);
1106 xgifb_reg_and_or(XGISR
, 0x37, 0xDF, (base
>> 21) & 0x04);
1108 if (xgifb_info
->display2
!= XGIFB_DISP_NONE
) {
1109 xgifb_reg_or(XGIPART1
, SIS_CRT2_WENABLE_315
, 0x01);
1110 xgifb_reg_set(XGIPART1
, 0x06, (base
& 0xFF));
1111 xgifb_reg_set(XGIPART1
, 0x05, ((base
>> 8) & 0xFF));
1112 xgifb_reg_set(XGIPART1
, 0x04, ((base
>> 16) & 0xFF));
1113 xgifb_reg_and_or(XGIPART1
,
1116 ((base
>> 24) & 0x01) << 7);
1121 static int XGIfb_open(struct fb_info
*info
, int user
)
1126 static int XGIfb_release(struct fb_info
*info
, int user
)
1131 /* similar to sisfb_get_cmap_len */
1132 static int XGIfb_get_cmap_len(const struct fb_var_screeninfo
*var
)
1134 return (var
->bits_per_pixel
== 8) ? 256 : 16;
1137 static int XGIfb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
1138 unsigned blue
, unsigned transp
, struct fb_info
*info
)
1140 struct xgifb_video_info
*xgifb_info
= info
->par
;
1142 if (regno
>= XGIfb_get_cmap_len(&info
->var
))
1145 switch (info
->var
.bits_per_pixel
) {
1147 outb(regno
, XGIDACA
);
1148 outb((red
>> 10), XGIDACD
);
1149 outb((green
>> 10), XGIDACD
);
1150 outb((blue
>> 10), XGIDACD
);
1151 if (xgifb_info
->display2
!= XGIFB_DISP_NONE
) {
1152 outb(regno
, XGIDAC2A
);
1153 outb((red
>> 8), XGIDAC2D
);
1154 outb((green
>> 8), XGIDAC2D
);
1155 outb((blue
>> 8), XGIDAC2D
);
1159 ((u32
*) (info
->pseudo_palette
))[regno
] = ((red
& 0xf800))
1160 | ((green
& 0xfc00) >> 5) | ((blue
& 0xf800)
1167 ((u32
*) (info
->pseudo_palette
))[regno
] = (red
<< 16) | (green
1174 /* ----------- FBDev related routines for all series ---------- */
1176 static int XGIfb_get_fix(struct fb_fix_screeninfo
*fix
, int con
,
1177 struct fb_info
*info
)
1179 struct xgifb_video_info
*xgifb_info
= info
->par
;
1181 memset(fix
, 0, sizeof(struct fb_fix_screeninfo
));
1183 strncpy(fix
->id
, "XGI", sizeof(fix
->id
) - 1);
1185 /* if register_framebuffer has been called, we must lock */
1186 if (atomic_read(&info
->count
))
1187 mutex_lock(&info
->mm_lock
);
1189 fix
->smem_start
= xgifb_info
->video_base
;
1190 fix
->smem_len
= xgifb_info
->video_size
;
1192 /* if register_framebuffer has been called, we can unlock */
1193 if (atomic_read(&info
->count
))
1194 mutex_unlock(&info
->mm_lock
);
1196 fix
->type
= FB_TYPE_PACKED_PIXELS
;
1198 if (xgifb_info
->video_bpp
== 8)
1199 fix
->visual
= FB_VISUAL_PSEUDOCOLOR
;
1201 fix
->visual
= FB_VISUAL_DIRECTCOLOR
;
1206 fix
->line_length
= xgifb_info
->video_linelength
;
1207 fix
->mmio_start
= xgifb_info
->mmio_base
;
1208 fix
->mmio_len
= xgifb_info
->mmio_size
;
1209 fix
->accel
= FB_ACCEL_SIS_XABRE
;
1214 static int XGIfb_set_par(struct fb_info
*info
)
1218 err
= XGIfb_do_set_var(&info
->var
, 1, info
);
1221 XGIfb_get_fix(&info
->fix
, -1, info
);
1225 static int XGIfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
1227 struct xgifb_video_info
*xgifb_info
= info
->par
;
1228 unsigned int htotal
= var
->left_margin
+ var
->xres
+ var
->right_margin
1230 unsigned int vtotal
= 0;
1231 unsigned int drate
= 0, hrate
= 0;
1233 int refresh_rate
, search_idx
;
1235 if ((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_NONINTERLACED
) {
1236 vtotal
= var
->upper_margin
+ var
->yres
+ var
->lower_margin
1239 } else if ((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_DOUBLE
) {
1240 vtotal
= var
->upper_margin
+ var
->yres
+ var
->lower_margin
1243 } else if ((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
) {
1244 vtotal
= var
->upper_margin
+ (var
->yres
/ 2)
1245 + var
->lower_margin
+ var
->vsync_len
;
1247 vtotal
= var
->upper_margin
+ var
->yres
+ var
->lower_margin
1250 if (!(htotal
) || !(vtotal
)) {
1251 pr_debug("No valid timing data\n");
1255 if (var
->pixclock
&& htotal
&& vtotal
) {
1256 drate
= 1000000000 / var
->pixclock
;
1257 hrate
= (drate
* 1000) / htotal
;
1258 xgifb_info
->refresh_rate
=
1259 (unsigned int) (hrate
* 2 / vtotal
);
1261 "%s: pixclock = %d ,htotal=%d, vtotal=%d\n"
1262 "%s: drate=%d, hrate=%d, refresh_rate=%d\n",
1263 __func__
, var
->pixclock
, htotal
, vtotal
,
1264 __func__
, drate
, hrate
, xgifb_info
->refresh_rate
);
1266 xgifb_info
->refresh_rate
= 60;
1269 /* Calculation wrong for 1024x600 - force it to 60Hz */
1270 if ((var
->xres
== 1024) && (var
->yres
== 600))
1274 while ((XGIbios_mode
[search_idx
].mode_no
!= 0) &&
1275 (XGIbios_mode
[search_idx
].xres
<= var
->xres
)) {
1276 if ((XGIbios_mode
[search_idx
].xres
== var
->xres
) &&
1277 (XGIbios_mode
[search_idx
].yres
== var
->yres
) &&
1278 (XGIbios_mode
[search_idx
].bpp
== var
->bits_per_pixel
)) {
1279 if (XGIfb_validate_mode(xgifb_info
, search_idx
) > 0) {
1289 pr_err("%dx%dx%d is no valid mode\n",
1290 var
->xres
, var
->yres
, var
->bits_per_pixel
);
1292 while (XGIbios_mode
[search_idx
].mode_no
!= 0) {
1293 if ((var
->xres
<= XGIbios_mode
[search_idx
].xres
) &&
1294 (var
->yres
<= XGIbios_mode
[search_idx
].yres
) &&
1295 (var
->bits_per_pixel
==
1296 XGIbios_mode
[search_idx
].bpp
)) {
1297 if (XGIfb_validate_mode(xgifb_info
,
1306 var
->xres
= XGIbios_mode
[search_idx
].xres
;
1307 var
->yres
= XGIbios_mode
[search_idx
].yres
;
1308 pr_debug("Adapted to mode %dx%dx%d\n",
1309 var
->xres
, var
->yres
, var
->bits_per_pixel
);
1312 pr_err("Failed to find similar mode to %dx%dx%d\n",
1313 var
->xres
, var
->yres
, var
->bits_per_pixel
);
1318 /* Adapt RGB settings */
1319 XGIfb_bpp_to_var(xgifb_info
, var
);
1322 if (var
->xres
!= var
->xres_virtual
)
1323 var
->xres_virtual
= var
->xres
;
1324 if (var
->yres
!= var
->yres_virtual
)
1325 var
->yres_virtual
= var
->yres
;
1328 /* Truncate offsets to maximum if too high */
1329 if (var
->xoffset
> var
->xres_virtual
- var
->xres
)
1330 var
->xoffset
= var
->xres_virtual
- var
->xres
- 1;
1332 if (var
->yoffset
> var
->yres_virtual
- var
->yres
)
1333 var
->yoffset
= var
->yres_virtual
- var
->yres
- 1;
1335 /* Set everything else to 0 */
1336 var
->red
.msb_right
=
1337 var
->green
.msb_right
=
1338 var
->blue
.msb_right
=
1339 var
->transp
.offset
= var
->transp
.length
= var
->transp
.msb_right
= 0;
1344 static int XGIfb_pan_display(struct fb_var_screeninfo
*var
,
1345 struct fb_info
*info
)
1349 if (var
->xoffset
> (info
->var
.xres_virtual
- info
->var
.xres
))
1351 if (var
->yoffset
> (info
->var
.yres_virtual
- info
->var
.yres
))
1354 if (var
->vmode
& FB_VMODE_YWRAP
) {
1355 if (var
->yoffset
>= info
->var
.yres_virtual
|| var
->xoffset
)
1357 } else if (var
->xoffset
+ info
->var
.xres
> info
->var
.xres_virtual
1358 || var
->yoffset
+ info
->var
.yres
1359 > info
->var
.yres_virtual
) {
1362 err
= XGIfb_pan_var(var
, info
);
1366 info
->var
.xoffset
= var
->xoffset
;
1367 info
->var
.yoffset
= var
->yoffset
;
1368 if (var
->vmode
& FB_VMODE_YWRAP
)
1369 info
->var
.vmode
|= FB_VMODE_YWRAP
;
1371 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1376 static int XGIfb_blank(int blank
, struct fb_info
*info
)
1378 struct xgifb_video_info
*xgifb_info
= info
->par
;
1381 reg
= xgifb_reg_get(XGICR
, 0x17);
1388 xgifb_reg_set(XGICR
, 0x17, reg
);
1389 xgifb_reg_set(XGISR
, 0x00, 0x01); /* Synchronous Reset */
1390 xgifb_reg_set(XGISR
, 0x00, 0x03); /* End Reset */
1394 static struct fb_ops XGIfb_ops
= {
1395 .owner
= THIS_MODULE
,
1396 .fb_open
= XGIfb_open
,
1397 .fb_release
= XGIfb_release
,
1398 .fb_check_var
= XGIfb_check_var
,
1399 .fb_set_par
= XGIfb_set_par
,
1400 .fb_setcolreg
= XGIfb_setcolreg
,
1401 .fb_pan_display
= XGIfb_pan_display
,
1402 .fb_blank
= XGIfb_blank
,
1403 .fb_fillrect
= cfb_fillrect
,
1404 .fb_copyarea
= cfb_copyarea
,
1405 .fb_imageblit
= cfb_imageblit
,
1408 /* ---------------- Chip generation dependent routines ---------------- */
1410 /* for XGI 315/550/650/740/330 */
1412 static int XGIfb_get_dram_size(struct xgifb_video_info
*xgifb_info
)
1418 /* xorg driver sets 32MB * 1 channel */
1419 if (xgifb_info
->chip
== XG27
)
1420 xgifb_reg_set(XGISR
, IND_SIS_DRAM_SIZE
, 0x51);
1422 reg
= xgifb_reg_get(XGISR
, IND_SIS_DRAM_SIZE
);
1426 switch ((reg
& XGI_DRAM_SIZE_MASK
) >> 4) {
1427 case XGI_DRAM_SIZE_1MB
:
1428 xgifb_info
->video_size
= 0x100000;
1430 case XGI_DRAM_SIZE_2MB
:
1431 xgifb_info
->video_size
= 0x200000;
1433 case XGI_DRAM_SIZE_4MB
:
1434 xgifb_info
->video_size
= 0x400000;
1436 case XGI_DRAM_SIZE_8MB
:
1437 xgifb_info
->video_size
= 0x800000;
1439 case XGI_DRAM_SIZE_16MB
:
1440 xgifb_info
->video_size
= 0x1000000;
1442 case XGI_DRAM_SIZE_32MB
:
1443 xgifb_info
->video_size
= 0x2000000;
1445 case XGI_DRAM_SIZE_64MB
:
1446 xgifb_info
->video_size
= 0x4000000;
1448 case XGI_DRAM_SIZE_128MB
:
1449 xgifb_info
->video_size
= 0x8000000;
1451 case XGI_DRAM_SIZE_256MB
:
1452 xgifb_info
->video_size
= 0x10000000;
1458 tmp
= (reg
& 0x0c) >> 2;
1459 switch (xgifb_info
->chip
) {
1484 xgifb_info
->video_size
= xgifb_info
->video_size
* ChannelNum
;
1486 pr_info("SR14=%x DramSzie %x ChannelNum %x\n",
1488 xgifb_info
->video_size
, ChannelNum
);
1493 static void XGIfb_detect_VB(struct xgifb_video_info
*xgifb_info
)
1497 xgifb_info
->TV_plug
= xgifb_info
->TV_type
= 0;
1499 cr32
= xgifb_reg_get(XGICR
, IND_XGI_SCRATCH_REG_CR32
);
1501 if ((cr32
& SIS_CRT1
) && !XGIfb_crt1off
)
1510 if (!xgifb_info
->display2_force
) {
1511 if (cr32
& SIS_VB_TV
)
1512 xgifb_info
->display2
= XGIFB_DISP_TV
;
1513 else if (cr32
& SIS_VB_LCD
)
1514 xgifb_info
->display2
= XGIFB_DISP_LCD
;
1515 else if (cr32
& SIS_VB_CRT2
)
1516 xgifb_info
->display2
= XGIFB_DISP_CRT
;
1518 xgifb_info
->display2
= XGIFB_DISP_NONE
;
1521 if (XGIfb_tvplug
!= -1)
1522 /* Override with option */
1523 xgifb_info
->TV_plug
= XGIfb_tvplug
;
1524 else if (cr32
& SIS_VB_HIVISION
) {
1525 xgifb_info
->TV_type
= TVMODE_HIVISION
;
1526 xgifb_info
->TV_plug
= TVPLUG_SVIDEO
;
1527 } else if (cr32
& SIS_VB_SVIDEO
)
1528 xgifb_info
->TV_plug
= TVPLUG_SVIDEO
;
1529 else if (cr32
& SIS_VB_COMPOSITE
)
1530 xgifb_info
->TV_plug
= TVPLUG_COMPOSITE
;
1531 else if (cr32
& SIS_VB_SCART
)
1532 xgifb_info
->TV_plug
= TVPLUG_SCART
;
1534 if (xgifb_info
->TV_type
== 0) {
1535 temp
= xgifb_reg_get(XGICR
, 0x38);
1537 xgifb_info
->TV_type
= TVMODE_PAL
;
1539 xgifb_info
->TV_type
= TVMODE_NTSC
;
1542 /* Copy forceCRT1 option to CRT1off if option is given */
1543 if (XGIfb_forcecrt1
!= -1) {
1544 if (XGIfb_forcecrt1
)
1551 static int XGIfb_has_VB(struct xgifb_video_info
*xgifb_info
)
1555 vb_chipid
= xgifb_reg_get(XGIPART4
, 0x00);
1556 switch (vb_chipid
) {
1558 xgifb_info
->hasVB
= HASVB_301
;
1561 xgifb_info
->hasVB
= HASVB_302
;
1564 xgifb_info
->hasVB
= HASVB_NONE
;
1570 static void XGIfb_get_VB_type(struct xgifb_video_info
*xgifb_info
)
1574 if (!XGIfb_has_VB(xgifb_info
)) {
1575 reg
= xgifb_reg_get(XGICR
, IND_XGI_SCRATCH_REG_CR37
);
1576 switch ((reg
& SIS_EXTERNAL_CHIP_MASK
) >> 1) {
1577 case SIS_EXTERNAL_CHIP_LVDS
:
1578 xgifb_info
->hasVB
= HASVB_LVDS
;
1580 case SIS_EXTERNAL_CHIP_LVDS_CHRONTEL
:
1581 xgifb_info
->hasVB
= HASVB_LVDS_CHRONTEL
;
1589 static int __init
xgifb_optval(char *fullopt
, int validx
)
1593 if (kstrtoul(fullopt
+ validx
, 0, &lres
) < 0 || lres
> INT_MAX
) {
1594 pr_err("Invalid value for option: %s\n", fullopt
);
1600 static int __init
XGIfb_setup(char *options
)
1604 if (!options
|| !*options
)
1607 pr_info("Options: %s\n", options
);
1609 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
1614 if (!strncmp(this_opt
, "mode:", 5)) {
1615 mode
= this_opt
+ 5;
1616 } else if (!strncmp(this_opt
, "vesa:", 5)) {
1617 vesa
= xgifb_optval(this_opt
, 5);
1618 } else if (!strncmp(this_opt
, "vrate:", 6)) {
1619 refresh_rate
= xgifb_optval(this_opt
, 6);
1620 } else if (!strncmp(this_opt
, "rate:", 5)) {
1621 refresh_rate
= xgifb_optval(this_opt
, 5);
1622 } else if (!strncmp(this_opt
, "crt1off", 7)) {
1624 } else if (!strncmp(this_opt
, "filter:", 7)) {
1625 filter
= xgifb_optval(this_opt
, 7);
1626 } else if (!strncmp(this_opt
, "forcecrt2type:", 14)) {
1627 XGIfb_search_crt2type(this_opt
+ 14);
1628 } else if (!strncmp(this_opt
, "forcecrt1:", 10)) {
1629 XGIfb_forcecrt1
= xgifb_optval(this_opt
, 10);
1630 } else if (!strncmp(this_opt
, "tvmode:", 7)) {
1631 XGIfb_search_tvstd(this_opt
+ 7);
1632 } else if (!strncmp(this_opt
, "tvstandard:", 11)) {
1633 XGIfb_search_tvstd(this_opt
+ 7);
1634 } else if (!strncmp(this_opt
, "dstn", 4)) {
1636 /* DSTN overrules forcecrt2type */
1637 XGIfb_crt2type
= XGIFB_DISP_LCD
;
1638 } else if (!strncmp(this_opt
, "noypan", 6)) {
1647 static int xgifb_probe(struct pci_dev
*pdev
,
1648 const struct pci_device_id
*ent
)
1653 struct fb_info
*fb_info
;
1654 struct xgifb_video_info
*xgifb_info
;
1655 struct xgi_hw_device_info
*hw_info
;
1656 unsigned long video_size_max
;
1658 fb_info
= framebuffer_alloc(sizeof(*xgifb_info
), &pdev
->dev
);
1662 xgifb_info
= fb_info
->par
;
1663 hw_info
= &xgifb_info
->hw_info
;
1664 xgifb_info
->fb_info
= fb_info
;
1665 xgifb_info
->chip_id
= pdev
->device
;
1666 pci_read_config_byte(pdev
,
1668 &xgifb_info
->revision_id
);
1669 hw_info
->jChipRevision
= xgifb_info
->revision_id
;
1671 xgifb_info
->pcibus
= pdev
->bus
->number
;
1672 xgifb_info
->pcislot
= PCI_SLOT(pdev
->devfn
);
1673 xgifb_info
->pcifunc
= PCI_FUNC(pdev
->devfn
);
1674 xgifb_info
->subsysvendor
= pdev
->subsystem_vendor
;
1675 xgifb_info
->subsysdevice
= pdev
->subsystem_device
;
1677 video_size_max
= pci_resource_len(pdev
, 0);
1678 xgifb_info
->video_base
= pci_resource_start(pdev
, 0);
1679 xgifb_info
->mmio_base
= pci_resource_start(pdev
, 1);
1680 xgifb_info
->mmio_size
= pci_resource_len(pdev
, 1);
1681 xgifb_info
->vga_base
= pci_resource_start(pdev
, 2) + 0x30;
1682 dev_info(&pdev
->dev
, "Relocate IO address: %Lx [%08lx]\n",
1683 (u64
) pci_resource_start(pdev
, 2),
1684 xgifb_info
->vga_base
);
1686 if (pci_enable_device(pdev
)) {
1691 if (XGIfb_crt2type
!= -1) {
1692 xgifb_info
->display2
= XGIfb_crt2type
;
1693 xgifb_info
->display2_force
= true;
1696 XGIRegInit(&xgifb_info
->dev_info
, xgifb_info
->vga_base
);
1698 xgifb_reg_set(XGISR
, IND_SIS_PASSWORD
, SIS_PASSWORD
);
1699 reg1
= xgifb_reg_get(XGISR
, IND_SIS_PASSWORD
);
1701 if (reg1
!= 0xa1) { /*I/O error */
1702 dev_err(&pdev
->dev
, "I/O error\n");
1707 switch (xgifb_info
->chip_id
) {
1708 case PCI_DEVICE_ID_XGI_20
:
1709 xgifb_reg_or(XGICR
, Index_CR_GPIO_Reg3
, GPIOG_EN
);
1710 CR48
= xgifb_reg_get(XGICR
, Index_CR_GPIO_Reg1
);
1711 if (CR48
&GPIOG_READ
)
1712 xgifb_info
->chip
= XG21
;
1714 xgifb_info
->chip
= XG20
;
1716 case PCI_DEVICE_ID_XGI_40
:
1717 xgifb_info
->chip
= XG40
;
1719 case PCI_DEVICE_ID_XGI_42
:
1720 xgifb_info
->chip
= XG42
;
1722 case PCI_DEVICE_ID_XGI_27
:
1723 xgifb_info
->chip
= XG27
;
1730 dev_info(&pdev
->dev
, "chipid = %x\n", xgifb_info
->chip
);
1731 hw_info
->jChipType
= xgifb_info
->chip
;
1733 if (XGIfb_get_dram_size(xgifb_info
)) {
1734 xgifb_info
->video_size
= min_t(unsigned long, video_size_max
,
1736 } else if (xgifb_info
->video_size
> video_size_max
) {
1737 xgifb_info
->video_size
= video_size_max
;
1740 /* Enable PCI_LINEAR_ADDRESSING and MMIO_ENABLE */
1742 IND_SIS_PCI_ADDRESS_SET
,
1743 (SIS_PCI_ADDR_ENABLE
| SIS_MEM_MAP_IO_ENABLE
));
1744 /* Enable 2D accelerator engine */
1745 xgifb_reg_or(XGISR
, IND_SIS_MODULE_ENABLE
, SIS_ENABLE_2D
);
1747 hw_info
->ulVideoMemorySize
= xgifb_info
->video_size
;
1749 if (!request_mem_region(xgifb_info
->video_base
,
1750 xgifb_info
->video_size
,
1752 dev_err(&pdev
->dev
, "Unable request memory size %x\n",
1753 xgifb_info
->video_size
);
1755 "Fatal error: Unable to reserve frame buffer memory. Is there another framebuffer driver active?\n");
1760 if (!request_mem_region(xgifb_info
->mmio_base
,
1761 xgifb_info
->mmio_size
,
1764 "Fatal error: Unable to reserve MMIO region\n");
1769 xgifb_info
->video_vbase
= hw_info
->pjVideoMemoryAddress
=
1770 ioremap_wc(xgifb_info
->video_base
, xgifb_info
->video_size
);
1771 xgifb_info
->mmio_vbase
= ioremap(xgifb_info
->mmio_base
,
1772 xgifb_info
->mmio_size
);
1774 dev_info(&pdev
->dev
,
1775 "Framebuffer at 0x%Lx, mapped to 0x%p, size %dk\n",
1776 (u64
) xgifb_info
->video_base
,
1777 xgifb_info
->video_vbase
,
1778 xgifb_info
->video_size
/ 1024);
1780 dev_info(&pdev
->dev
,
1781 "MMIO at 0x%Lx, mapped to 0x%p, size %ldk\n",
1782 (u64
) xgifb_info
->mmio_base
, xgifb_info
->mmio_vbase
,
1783 xgifb_info
->mmio_size
/ 1024);
1785 pci_set_drvdata(pdev
, xgifb_info
);
1786 if (!XGIInitNew(pdev
))
1787 dev_err(&pdev
->dev
, "XGIInitNew() failed!\n");
1789 xgifb_info
->mtrr
= -1;
1791 xgifb_info
->hasVB
= HASVB_NONE
;
1792 if ((xgifb_info
->chip
== XG20
) ||
1793 (xgifb_info
->chip
== XG27
)) {
1794 xgifb_info
->hasVB
= HASVB_NONE
;
1795 } else if (xgifb_info
->chip
== XG21
) {
1796 CR38
= xgifb_reg_get(XGICR
, 0x38);
1797 if ((CR38
&0xE0) == 0xC0)
1798 xgifb_info
->display2
= XGIFB_DISP_LCD
;
1799 else if ((CR38
&0xE0) == 0x60)
1800 xgifb_info
->hasVB
= HASVB_CHRONTEL
;
1802 xgifb_info
->hasVB
= HASVB_NONE
;
1804 XGIfb_get_VB_type(xgifb_info
);
1807 hw_info
->ujVBChipID
= VB_CHIP_UNKNOWN
;
1809 hw_info
->ulExternalChip
= 0;
1811 switch (xgifb_info
->hasVB
) {
1813 reg
= xgifb_reg_get(XGIPART4
, 0x01);
1815 hw_info
->ujVBChipID
= VB_CHIP_302LV
;
1816 dev_info(&pdev
->dev
,
1817 "XGI302LV bridge detected (revision 0x%02x)\n",
1819 } else if (reg
>= 0xD0) {
1820 hw_info
->ujVBChipID
= VB_CHIP_301LV
;
1821 dev_info(&pdev
->dev
,
1822 "XGI301LV bridge detected (revision 0x%02x)\n",
1825 hw_info
->ujVBChipID
= VB_CHIP_301
;
1826 dev_info(&pdev
->dev
, "XGI301 bridge detected\n");
1830 reg
= xgifb_reg_get(XGIPART4
, 0x01);
1832 hw_info
->ujVBChipID
= VB_CHIP_302LV
;
1833 dev_info(&pdev
->dev
,
1834 "XGI302LV bridge detected (revision 0x%02x)\n",
1836 } else if (reg
>= 0xD0) {
1837 hw_info
->ujVBChipID
= VB_CHIP_301LV
;
1838 dev_info(&pdev
->dev
,
1839 "XGI302LV bridge detected (revision 0x%02x)\n",
1841 } else if (reg
>= 0xB0) {
1842 reg1
= xgifb_reg_get(XGIPART4
, 0x23);
1844 hw_info
->ujVBChipID
= VB_CHIP_302B
;
1847 hw_info
->ujVBChipID
= VB_CHIP_302
;
1848 dev_info(&pdev
->dev
, "XGI302 bridge detected\n");
1852 hw_info
->ulExternalChip
= 0x1;
1853 dev_info(&pdev
->dev
, "LVDS transmitter detected\n");
1855 case HASVB_TRUMPION
:
1856 hw_info
->ulExternalChip
= 0x2;
1857 dev_info(&pdev
->dev
, "Trumpion Zurac LVDS scaler detected\n");
1859 case HASVB_CHRONTEL
:
1860 hw_info
->ulExternalChip
= 0x4;
1861 dev_info(&pdev
->dev
, "Chrontel TV encoder detected\n");
1863 case HASVB_LVDS_CHRONTEL
:
1864 hw_info
->ulExternalChip
= 0x5;
1865 dev_info(&pdev
->dev
,
1866 "LVDS transmitter and Chrontel TV encoder detected\n");
1869 dev_info(&pdev
->dev
, "No or unknown bridge type detected\n");
1873 if (xgifb_info
->hasVB
!= HASVB_NONE
)
1874 XGIfb_detect_VB(xgifb_info
);
1875 else if (xgifb_info
->chip
!= XG21
)
1876 xgifb_info
->display2
= XGIFB_DISP_NONE
;
1878 if (xgifb_info
->display2
== XGIFB_DISP_LCD
) {
1880 reg
= xgifb_reg_get(XGICR
, IND_XGI_LCD_PANEL
);
1882 hw_info
->ulCRT2LCDType
= XGI310paneltype
[reg
];
1886 xgifb_info
->mode_idx
= -1;
1889 XGIfb_search_mode(xgifb_info
, mode
);
1890 else if (vesa
!= -1)
1891 XGIfb_search_vesamode(xgifb_info
, vesa
);
1893 if (xgifb_info
->mode_idx
>= 0)
1894 xgifb_info
->mode_idx
=
1895 XGIfb_validate_mode(xgifb_info
, xgifb_info
->mode_idx
);
1897 if (xgifb_info
->mode_idx
< 0) {
1898 if (xgifb_info
->display2
== XGIFB_DISP_LCD
&&
1899 xgifb_info
->chip
== XG21
)
1900 xgifb_info
->mode_idx
=
1901 XGIfb_GetXG21DefaultLVDSModeIdx(xgifb_info
);
1903 xgifb_info
->mode_idx
= DEFAULT_MODE
;
1906 if (xgifb_info
->mode_idx
< 0) {
1907 dev_err(&pdev
->dev
, "No supported video mode found\n");
1912 /* set default refresh rate */
1913 xgifb_info
->refresh_rate
= refresh_rate
;
1914 if (xgifb_info
->refresh_rate
== 0)
1915 xgifb_info
->refresh_rate
= 60;
1916 if (XGIfb_search_refresh_rate(xgifb_info
,
1917 xgifb_info
->refresh_rate
) == 0) {
1918 xgifb_info
->rate_idx
= 1;
1919 xgifb_info
->refresh_rate
= 60;
1922 xgifb_info
->video_bpp
= XGIbios_mode
[xgifb_info
->mode_idx
].bpp
;
1923 xgifb_info
->video_vwidth
=
1924 xgifb_info
->video_width
=
1925 XGIbios_mode
[xgifb_info
->mode_idx
].xres
;
1926 xgifb_info
->video_vheight
=
1927 xgifb_info
->video_height
=
1928 XGIbios_mode
[xgifb_info
->mode_idx
].yres
;
1929 xgifb_info
->org_x
= xgifb_info
->org_y
= 0;
1930 xgifb_info
->video_linelength
=
1931 xgifb_info
->video_width
*
1932 (xgifb_info
->video_bpp
>> 3);
1933 switch (xgifb_info
->video_bpp
) {
1935 xgifb_info
->DstColor
= 0x0000;
1936 xgifb_info
->XGI310_AccelDepth
= 0x00000000;
1937 xgifb_info
->video_cmap_len
= 256;
1940 xgifb_info
->DstColor
= 0x8000;
1941 xgifb_info
->XGI310_AccelDepth
= 0x00010000;
1942 xgifb_info
->video_cmap_len
= 16;
1945 xgifb_info
->DstColor
= 0xC000;
1946 xgifb_info
->XGI310_AccelDepth
= 0x00020000;
1947 xgifb_info
->video_cmap_len
= 16;
1950 xgifb_info
->video_cmap_len
= 16;
1951 pr_info("Unsupported depth %d\n",
1952 xgifb_info
->video_bpp
);
1956 pr_info("Default mode is %dx%dx%d (%dHz)\n",
1957 xgifb_info
->video_width
,
1958 xgifb_info
->video_height
,
1959 xgifb_info
->video_bpp
,
1960 xgifb_info
->refresh_rate
);
1962 fb_info
->var
.red
.length
= 8;
1963 fb_info
->var
.green
.length
= 8;
1964 fb_info
->var
.blue
.length
= 8;
1965 fb_info
->var
.activate
= FB_ACTIVATE_NOW
;
1966 fb_info
->var
.height
= -1;
1967 fb_info
->var
.width
= -1;
1968 fb_info
->var
.vmode
= FB_VMODE_NONINTERLACED
;
1969 fb_info
->var
.xres
= xgifb_info
->video_width
;
1970 fb_info
->var
.xres_virtual
= xgifb_info
->video_width
;
1971 fb_info
->var
.yres
= xgifb_info
->video_height
;
1972 fb_info
->var
.yres_virtual
= xgifb_info
->video_height
;
1973 fb_info
->var
.bits_per_pixel
= xgifb_info
->video_bpp
;
1975 XGIfb_bpp_to_var(xgifb_info
, &fb_info
->var
);
1977 fb_info
->var
.pixclock
= (u32
) (1000000000 /
1978 XGIfb_mode_rate_to_dclock(&xgifb_info
->dev_info
,
1980 XGIbios_mode
[xgifb_info
->mode_idx
].mode_no
));
1982 if (XGIfb_mode_rate_to_ddata(&xgifb_info
->dev_info
, hw_info
,
1983 XGIbios_mode
[xgifb_info
->mode_idx
].mode_no
,
1984 &fb_info
->var
.left_margin
,
1985 &fb_info
->var
.right_margin
,
1986 &fb_info
->var
.upper_margin
,
1987 &fb_info
->var
.lower_margin
,
1988 &fb_info
->var
.hsync_len
,
1989 &fb_info
->var
.vsync_len
,
1991 &fb_info
->var
.vmode
)) {
1993 if ((fb_info
->var
.vmode
& FB_VMODE_MASK
) ==
1994 FB_VMODE_INTERLACED
) {
1995 fb_info
->var
.yres
<<= 1;
1996 fb_info
->var
.yres_virtual
<<= 1;
1997 } else if ((fb_info
->var
.vmode
& FB_VMODE_MASK
) ==
1999 fb_info
->var
.pixclock
>>= 1;
2000 fb_info
->var
.yres
>>= 1;
2001 fb_info
->var
.yres_virtual
>>= 1;
2006 fb_info
->flags
= FBINFO_FLAG_DEFAULT
;
2007 fb_info
->screen_base
= xgifb_info
->video_vbase
;
2008 fb_info
->fbops
= &XGIfb_ops
;
2009 XGIfb_get_fix(&fb_info
->fix
, -1, fb_info
);
2010 fb_info
->pseudo_palette
= xgifb_info
->pseudo_palette
;
2012 fb_alloc_cmap(&fb_info
->cmap
, 256, 0);
2014 xgifb_info
->mtrr
= arch_phys_wc_add(xgifb_info
->video_base
,
2015 xgifb_info
->video_size
);
2017 if (register_framebuffer(fb_info
) < 0) {
2022 dumpVGAReg(xgifb_info
);
2027 arch_phys_wc_del(xgifb_info
->mtrr
);
2029 iounmap(xgifb_info
->mmio_vbase
);
2030 iounmap(xgifb_info
->video_vbase
);
2031 release_mem_region(xgifb_info
->mmio_base
, xgifb_info
->mmio_size
);
2033 release_mem_region(xgifb_info
->video_base
, xgifb_info
->video_size
);
2035 pci_disable_device(pdev
);
2037 framebuffer_release(fb_info
);
2041 /*****************************************************/
2042 /* PCI DEVICE HANDLING */
2043 /*****************************************************/
2045 static void xgifb_remove(struct pci_dev
*pdev
)
2047 struct xgifb_video_info
*xgifb_info
= pci_get_drvdata(pdev
);
2048 struct fb_info
*fb_info
= xgifb_info
->fb_info
;
2050 unregister_framebuffer(fb_info
);
2051 arch_phys_wc_del(xgifb_info
->mtrr
);
2052 iounmap(xgifb_info
->mmio_vbase
);
2053 iounmap(xgifb_info
->video_vbase
);
2054 release_mem_region(xgifb_info
->mmio_base
, xgifb_info
->mmio_size
);
2055 release_mem_region(xgifb_info
->video_base
, xgifb_info
->video_size
);
2056 pci_disable_device(pdev
);
2057 framebuffer_release(fb_info
);
2060 static struct pci_driver xgifb_driver
= {
2062 .id_table
= xgifb_pci_table
,
2063 .probe
= xgifb_probe
,
2064 .remove
= xgifb_remove
2069 /*****************************************************/
2071 /*****************************************************/
2073 module_param(mode
, charp
, 0);
2074 MODULE_PARM_DESC(mode
,
2075 "Selects the desired default display mode in the format XxYxDepth (eg. 1024x768x16).");
2077 module_param(forcecrt2type
, charp
, 0);
2078 MODULE_PARM_DESC(forcecrt2type
,
2079 "Force the second display output type. Possible values are NONE, LCD, TV, VGA, SVIDEO or COMPOSITE.");
2081 module_param(vesa
, int, 0);
2082 MODULE_PARM_DESC(vesa
,
2083 "Selects the desired default display mode by VESA mode number (eg. 0x117).");
2085 module_param(filter
, int, 0);
2086 MODULE_PARM_DESC(filter
,
2087 "Selects TV flicker filter type (only for systems with a SiS301 video bridge). Possible values 0-7. Default: [no filter]).");
2089 static int __init
xgifb_init(void)
2091 char *option
= NULL
;
2093 if (forcecrt2type
!= NULL
)
2094 XGIfb_search_crt2type(forcecrt2type
);
2095 if (fb_get_options("xgifb", &option
))
2097 XGIfb_setup(option
);
2099 return pci_register_driver(&xgifb_driver
);
2102 static void __exit
xgifb_remove_module(void)
2104 pci_unregister_driver(&xgifb_driver
);
2105 pr_debug("Module unloaded\n");
2108 MODULE_DESCRIPTION("Z7 Z9 Z9S Z11 framebuffer device driver");
2109 MODULE_LICENSE("GPL");
2110 MODULE_AUTHOR("XGITECH , Others");
2111 module_init(xgifb_init
);
2112 module_exit(xgifb_remove_module
);