115fb4814Smrg/*
215fb4814Smrg * Copyright (c) 2005 ASPEED Technology Inc.
315fb4814Smrg *
415fb4814Smrg * Permission to use, copy, modify, distribute, and sell this software and its
515fb4814Smrg * documentation for any purpose is hereby granted without fee, provided that
615fb4814Smrg * the above copyright notice appear in all copies and that both that
715fb4814Smrg * copyright notice and this permission notice appear in supporting
815fb4814Smrg * documentation, and that the name of the authors not be used in
915fb4814Smrg * advertising or publicity pertaining to distribution of the software without
1015fb4814Smrg * specific, written prior permission.  The authors makes no representations
1115fb4814Smrg * about the suitability of this software for any purpose.  It is provided
1215fb4814Smrg * "as is" without express or implied warranty.
1315fb4814Smrg *
1415fb4814Smrg * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1515fb4814Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1615fb4814Smrg * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1715fb4814Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1815fb4814Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1915fb4814Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2015fb4814Smrg * PERFORMANCE OF THIS SOFTWARE.
2115fb4814Smrg */
227fe5393cSmrg
2315fb4814Smrg#ifdef HAVE_CONFIG_H
2415fb4814Smrg#include <config.h>
2515fb4814Smrg#endif
2615fb4814Smrg#include "xf86.h"
2715fb4814Smrg#include "xf86_OSproc.h"
2815fb4814Smrg#include "xf86cmap.h"
2915fb4814Smrg#include "compiler.h"
3015fb4814Smrg#include "vgaHW.h"
3115fb4814Smrg#include "mipointer.h"
3215fb4814Smrg#include "micmap.h"
3315fb4814Smrg
3415fb4814Smrg#include "fb.h"
3515fb4814Smrg#include "regionstr.h"
3615fb4814Smrg#include "xf86xv.h"
3715fb4814Smrg#include <X11/extensions/Xv.h>
3815fb4814Smrg
3915fb4814Smrg#include "xf86Pci.h"
4015fb4814Smrg
4115fb4814Smrg/* framebuffer offscreen manager */
4215fb4814Smrg#include "xf86fbman.h"
4315fb4814Smrg
4415fb4814Smrg/* include xaa includes */
4515fb4814Smrg#include "xaarop.h"
4615fb4814Smrg
4715fb4814Smrg/* H/W cursor support */
4815fb4814Smrg#include "xf86Cursor.h"
4915fb4814Smrg
50b534f209Smrg/* usleep() */
51b534f209Smrg#include <unistd.h>
52b534f209Smrg
5315fb4814Smrg/* Driver specific headers */
5415fb4814Smrg#include "ast.h"
55cf503b78Smrg#include "ast_mode.h"
56cf503b78Smrg#include "ast_vgatool.h"
5715fb4814Smrg
58cf503b78Smrgstatic VBIOS_STDTABLE_STRUCT StdTable[] = {
5915fb4814Smrg    /* MD_2_3_400 */
6015fb4814Smrg    {
617fe5393cSmrg        0x67,
627fe5393cSmrg        {0x00,0x03,0x00,0x02},
637fe5393cSmrg        {0x5f,0x4f,0x50,0x82,0x55,0x81,0xbf,0x1f,
6415fb4814Smrg         0x00,0x4f,0x0d,0x0e,0x00,0x00,0x00,0x00,
6515fb4814Smrg         0x9c,0x8e,0x8f,0x28,0x1f,0x96,0xb9,0xa3,
6615fb4814Smrg         0xff},
677fe5393cSmrg        {0x00,0x01,0x02,0x03,0x04,0x05,0x14,0x07,
6815fb4814Smrg         0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
6915fb4814Smrg         0x0c,0x00,0x0f,0x08},
707fe5393cSmrg        {0x00,0x00,0x00,0x00,0x00,0x10,0x0e,0x00,
7115fb4814Smrg         0xff}
727fe5393cSmrg    },
7315fb4814Smrg    /* Mode12/ExtEGATable */
7415fb4814Smrg    {
757fe5393cSmrg        0xe3,
767fe5393cSmrg        {0x01,0x0f,0x00,0x06},
777fe5393cSmrg        {0x5f,0x4f,0x50,0x82,0x55,0x81,0x0b,0x3e,
787fe5393cSmrg         0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
797fe5393cSmrg         0xe9,0x8b,0xdf,0x28,0x00,0xe7,0x04,0xe3,
807fe5393cSmrg         0xff},
817fe5393cSmrg        {0x00,0x01,0x02,0x03,0x04,0x05,0x14,0x07,
827fe5393cSmrg         0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
837fe5393cSmrg         0x01,0x00,0x0f,0x00},
847fe5393cSmrg        {0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x0f,
857fe5393cSmrg         0xff}
8615fb4814Smrg    },
8715fb4814Smrg    /* ExtVGATable */
8815fb4814Smrg    {
897fe5393cSmrg        0x2f,
907fe5393cSmrg        {0x01,0x0f,0x00,0x0e},
917fe5393cSmrg        {0x5f,0x4f,0x50,0x82,0x54,0x80,0x0b,0x3e,
927fe5393cSmrg         0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
937fe5393cSmrg         0xea,0x8c,0xdf,0x28,0x40,0xe7,0x04,0xa3,
947fe5393cSmrg         0xff},
957fe5393cSmrg        {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
967fe5393cSmrg         0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
977fe5393cSmrg         0x01,0x00,0x00,0x00},
987fe5393cSmrg        {0x00,0x00,0x00,0x00,0x00,0x40,0x05,0x0f,
9915fb4814Smrg         0xff}
10015fb4814Smrg    },
10115fb4814Smrg    /* ExtHiCTable */
10215fb4814Smrg    {
1037fe5393cSmrg        0x2f,
1047fe5393cSmrg        {0x01,0x0f,0x00,0x0e},
1057fe5393cSmrg        {0x5f,0x4f,0x50,0x82,0x54,0x80,0x0b,0x3e,
1067fe5393cSmrg         0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
1077fe5393cSmrg         0xea,0x8c,0xdf,0x28,0x40,0xe7,0x04,0xa3,
1087fe5393cSmrg         0xff},
1097fe5393cSmrg        {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
1107fe5393cSmrg         0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
1117fe5393cSmrg         0x01,0x00,0x00,0x00},
1127fe5393cSmrg        {0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x0f,
11315fb4814Smrg         0xff}
1147fe5393cSmrg    },
11515fb4814Smrg    /* ExtTrueCTable */
11615fb4814Smrg    {
1177fe5393cSmrg        0x2f,
1187fe5393cSmrg        {0x01,0x0f,0x00,0x0e},
1197fe5393cSmrg        {0x5f,0x4f,0x50,0x82,0x54,0x80,0x0b,0x3e,
1207fe5393cSmrg         0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
1217fe5393cSmrg         0xea,0x8c,0xdf,0x28,0x40,0xe7,0x04,0xa3,
1227fe5393cSmrg         0xff},
1237fe5393cSmrg        {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
1247fe5393cSmrg         0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
1257fe5393cSmrg         0x01,0x00,0x00,0x00},
1267fe5393cSmrg        {0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x0f,
12715fb4814Smrg         0xff}
1287fe5393cSmrg    },
12915fb4814Smrg};
13015fb4814Smrg
131cf503b78Smrgstatic VBIOS_ENHTABLE_STRUCT  Res640x480Table[] = {
132de78e416Smrg    { 800, 640, 8, 96, 525, 480, 2, 2, VCLK25_175,	/* 60Hz */
13315fb4814Smrg      (SyncNN | HBorder | VBorder | Charx8Dot), 60, 1, 0x2E },
13415fb4814Smrg    { 832, 640, 16, 40, 520, 480, 1, 3, VCLK31_5,	/* 72Hz */
13515fb4814Smrg      (SyncNN | HBorder | VBorder | Charx8Dot), 72, 2, 0x2E  },
13615fb4814Smrg    { 840, 640, 16, 64, 500, 480, 1, 3, VCLK31_5,	/* 75Hz */
1377fe5393cSmrg      (SyncNN | Charx8Dot) , 75, 3, 0x2E },
13815fb4814Smrg    { 832, 640, 56, 56, 509, 480, 1, 3, VCLK36,		/* 85Hz */
13915fb4814Smrg      (SyncNN | Charx8Dot) , 85, 4, 0x2E },
14015fb4814Smrg    { 832, 640, 56, 56, 509, 480, 1, 3, VCLK36,		/* end */
1417fe5393cSmrg      (SyncNN | Charx8Dot) , 0xFF, 4, 0x2E },
14215fb4814Smrg};
14315fb4814Smrg
14415fb4814Smrg
145cf503b78Smrgstatic VBIOS_ENHTABLE_STRUCT  Res800x600Table[] = {
14615fb4814Smrg    {1024, 800, 24, 72, 625, 600, 1, 2, VCLK36,		/* 56Hz */
1477fe5393cSmrg      (SyncPP | Charx8Dot), 56, 1, 0x30 },
1487fe5393cSmrg    {1056, 800, 40, 128, 628, 600, 1, 4, VCLK40,	/* 60Hz */
14915fb4814Smrg      (SyncPP | Charx8Dot), 60, 2, 0x30 },
1507fe5393cSmrg    {1040, 800, 56, 120, 666, 600, 37, 6, VCLK50,	/* 72Hz */
1517fe5393cSmrg      (SyncPP | Charx8Dot), 72, 3, 0x30 },
1527fe5393cSmrg    {1056, 800, 16, 80, 625, 600, 1, 3, VCLK49_5,	/* 75Hz */
1537fe5393cSmrg      (SyncPP | Charx8Dot), 75, 4, 0x30 },
1547fe5393cSmrg    {1048, 800, 32, 64, 631, 600, 1, 3, VCLK56_25,	/* 85Hz */
1557fe5393cSmrg      (SyncPP | Charx8Dot), 84, 5, 0x30 },
1567fe5393cSmrg    {1048, 800, 32, 64, 631, 600, 1, 3, VCLK56_25,	/* end */
1577fe5393cSmrg      (SyncPP | Charx8Dot), 0xFF, 5, 0x30 },
15815fb4814Smrg};
15915fb4814Smrg
160cf503b78Smrgstatic VBIOS_ENHTABLE_STRUCT  Res1024x768Table[] = {
1617fe5393cSmrg    {1344, 1024, 24, 136, 806, 768, 3, 6, VCLK65,	/* 60Hz */
1627fe5393cSmrg      (SyncNN | Charx8Dot), 60, 1, 0x31 },
1637fe5393cSmrg    {1328, 1024, 24, 136, 806, 768, 3, 6, VCLK75,	/* 70Hz */
16415fb4814Smrg      (SyncNN | Charx8Dot), 70, 2, 0x31 },
1657fe5393cSmrg    {1312, 1024, 16, 96, 800, 768, 1, 3, VCLK78_75,	/* 75Hz */
1667fe5393cSmrg      (SyncPP | Charx8Dot), 75, 3, 0x31 },
1677fe5393cSmrg    {1376, 1024, 48, 96, 808, 768, 1, 3, VCLK94_5,	/* 85Hz */
1687fe5393cSmrg      (SyncPP | Charx8Dot), 84, 4, 0x31 },
1697fe5393cSmrg    {1376, 1024, 48, 96, 808, 768, 1, 3, VCLK94_5,	/* end */
1707fe5393cSmrg      (SyncPP | Charx8Dot), 0xFF, 4, 0x31 },
17115fb4814Smrg};
17215fb4814Smrg
173cf503b78Smrgstatic VBIOS_ENHTABLE_STRUCT  Res1280x1024Table[] = {
1747fe5393cSmrg    {1688, 1280, 48, 112, 1066, 1024, 1, 3, VCLK108,	/* 60Hz */
1757fe5393cSmrg      (SyncPP | Charx8Dot), 60, 1, 0x32 },
1767fe5393cSmrg    {1688, 1280, 16, 144, 1066, 1024, 1, 3, VCLK135,	/* 75Hz */
1777fe5393cSmrg      (SyncPP | Charx8Dot), 75, 2, 0x32 },
1787fe5393cSmrg    {1728, 1280, 64, 160, 1072, 1024, 1, 3, VCLK157_5,	/* 85Hz */
1797fe5393cSmrg      (SyncPP | Charx8Dot), 85, 3, 0x32 },
1807fe5393cSmrg    {1728, 1280, 64, 160, 1072, 1024, 1, 3, VCLK157_5,	/* end */
1817fe5393cSmrg      (SyncPP | Charx8Dot), 0xFF, 3, 0x32 },
18215fb4814Smrg};
18315fb4814Smrg
184cf503b78Smrgstatic VBIOS_ENHTABLE_STRUCT  Res1600x1200Table[] = {
1857fe5393cSmrg    {2160, 1600, 64, 192, 1250, 1200, 1, 3, VCLK162,	/* 60Hz */
1867fe5393cSmrg      (SyncPP | Charx8Dot), 60, 1, 0x33 },
1877fe5393cSmrg    {2160, 1600, 64, 192, 1250, 1200, 1, 3, VCLK162,	/* end */
1887fe5393cSmrg      (SyncPP | Charx8Dot), 0xFF, 1, 0x33 },
189de78e416Smrg};
190de78e416Smrg
1917fe5393cSmrg/* 16:9 */
192cf503b78Smrgstatic VBIOS_ENHTABLE_STRUCT  Res1360x768Table[] = {
1937fe5393cSmrg    {1792, 1360, 64,112, 795,  768, 3, 6, VCLK85_5,	/* 60Hz */
1947fe5393cSmrg      (SyncPP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo), 60, 1, 0x39 },
1957fe5393cSmrg    {1792, 1360, 64,112, 795,  768, 3, 6, VCLK85_5,	/* end */
1967fe5393cSmrg      (SyncPP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo), 0xFF, 1, 0x39 },
1977fe5393cSmrg};
1987fe5393cSmrg
199cf503b78Smrgstatic VBIOS_ENHTABLE_STRUCT  Res1600x900Table[] = {
20058e54220Smrg    {1760, 1600, 48, 32, 926,  900, 3, 5, VCLK97_75,	/* 60Hz CVT RB */
20158e54220Smrg      (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | AST2500PreCatchCRT), 60, 2, 0x3A },
202cf503b78Smrg    {2112, 1600, 88,168, 934,  900, 3, 5, VCLK118_25,	/* 60Hz CVT */
203cf503b78Smrg      (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo), 60, 1, 0x3A },
20458e54220Smrg    {2112, 1600, 88,168, 934,  900, 3, 5, VCLK118_25,	/* end */
20558e54220Smrg      (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo), 0xFF, 1, 0x3A },
2067fe5393cSmrg};
2077fe5393cSmrg
208cf503b78Smrgstatic VBIOS_ENHTABLE_STRUCT  Res1920x1080Table[] = {
2097fe5393cSmrg    {2200, 1920, 88, 44, 1125, 1080, 4, 5, VCLK148_5,	/* HDTV 60Hz */
21058e54220Smrg      (SyncPP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | AST2500PreCatchCRT), 60, 1, 0x38 },
2117fe5393cSmrg    {2200, 1920, 88, 44, 1125, 1080, 4, 5, VCLK148_5,	/* end */
21258e54220Smrg      (SyncPP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | AST2500PreCatchCRT), 0xFF, 1, 0x38 },
21315fb4814Smrg};
21415fb4814Smrg
215b410ddbeSmrg/* 16:10 */
216cf503b78Smrgstatic VBIOS_ENHTABLE_STRUCT  Res1280x800Table[] = {
21758e54220Smrg    {1440, 1280, 48, 32,  823,  800, 3, 6, VCLK71,		/* 60Hz CVT RB */
218f010a93dSmrg      (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | AST2500PreCatchCRT), 60, 2, 0x35 },
219cf503b78Smrg    {1680, 1280, 72,128,  831,  800, 3, 6, VCLK83_5,	/* 60Hz CVT */
220cf503b78Smrg      (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo), 60, 1, 0x35 },
22158e54220Smrg    {1680, 1280, 72,128,  831,  800, 3, 6, VCLK83_5,	/* end */
22258e54220Smrg      (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo), 0xFF, 1, 0x35 },
223b410ddbeSmrg};
224b410ddbeSmrg
225cf503b78Smrgstatic VBIOS_ENHTABLE_STRUCT  Res1440x900Table[] = {
22658e54220Smrg    {1600, 1440, 48, 32,  926,  900, 3, 6, VCLK88_75,	/* 60Hz CVT RB */
22758e54220Smrg      (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | AST2500PreCatchCRT), 60, 2, 0x36 },
228cf503b78Smrg    {1904, 1440, 80,152,  934,  900, 3, 6, VCLK106_5,	/* 60Hz CVT */
229cf503b78Smrg      (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo), 60, 1, 0x36 },
23058e54220Smrg    {1904, 1440, 80,152,  934,  900, 3, 6, VCLK106_5,	/* end */
23158e54220Smrg      (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo), 0xFF, 1, 0x36 },
232b410ddbeSmrg};
233b410ddbeSmrg
234cf503b78Smrgstatic VBIOS_ENHTABLE_STRUCT  Res1680x1050Table[] = {
23558e54220Smrg    {1840, 1680, 48, 32, 1080, 1050, 3, 6, VCLK119,		/* 60Hz CVT RB */
23658e54220Smrg      (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | AST2500PreCatchCRT), 60, 2, 0x37 },
237cf503b78Smrg    {2240, 1680,104,176, 1089, 1050, 3, 6, VCLK146_25,	/* 60Hz CVT */
238cf503b78Smrg      (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo), 60, 1, 0x37 },
23958e54220Smrg    {2240, 1680,104,176, 1089, 1050, 3, 6, VCLK146_25,	/* end */
24058e54220Smrg      (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo), 0xFF, 1, 0x37 },
241b410ddbeSmrg};
242b410ddbeSmrg
243cf503b78Smrgstatic VBIOS_ENHTABLE_STRUCT  Res1920x1200Table[] = {
24458e54220Smrg    {2080, 1920, 48, 32, 1235, 1200, 3, 6, VCLK154,		/* 60Hz CVT RB */
24558e54220Smrg      (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | AST2500PreCatchCRT), 60, 1, 0x34 },
24658e54220Smrg    {2080, 1920, 48, 32, 1235, 1200, 3, 6, VCLK154,		/* end */
2477fe5393cSmrg      (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo), 0xFF, 1, 0x34 },
248b410ddbeSmrg};
249b410ddbeSmrg
250cf503b78Smrgstatic VBIOS_DCLK_INFO DCLKTable [] = {
2517fe5393cSmrg    {0x2C, 0xE7, 0x03},					/* 00: VCLK25_175	*/
2527fe5393cSmrg    {0x95, 0x62, 0x03},					/* 01: VCLK28_322	*/
2537fe5393cSmrg    {0x67, 0x63, 0x01},					/* 02: VCLK31_5     */
2547fe5393cSmrg    {0x76, 0x63, 0x01},					/* 03: VCLK36		*/
2557fe5393cSmrg    {0xEE, 0x67, 0x01},					/* 04: VCLK40		*/
2567fe5393cSmrg    {0x82, 0x62, 0x01},					/* 05: VCLK49_5		*/
2577fe5393cSmrg    {0xC6, 0x64, 0x01},					/* 06: VCLK50		*/
2587fe5393cSmrg    {0x94, 0x62, 0x01},					/* 07: VCLK56_25	*/
2597fe5393cSmrg    {0x80, 0x64, 0x00},					/* 08: VCLK65		*/
2607fe5393cSmrg    {0x7B, 0x63, 0x00},					/* 09: VCLK75		*/
2617fe5393cSmrg    {0x67, 0x62, 0x00},					/* 0A: VCLK78_75	*/
2627fe5393cSmrg    {0x7C, 0x62, 0x00},					/* 0B: VCLK94_5		*/
2637fe5393cSmrg    {0x8E, 0x62, 0x00},					/* 0C: VCLK108		*/
2647fe5393cSmrg    {0x85, 0x24, 0x00},					/* 0D: VCLK135		*/
2657fe5393cSmrg    {0x67, 0x22, 0x00},					/* 0E: VCLK157_5	*/
2667fe5393cSmrg    {0x6A, 0x22, 0x00},					/* 0F: VCLK162		*/
2677fe5393cSmrg    {0x4d, 0x4c, 0x80},				    /* 10: VCLK154      */
2687fe5393cSmrg    {0xa7, 0x78, 0x80},					/* 11: VCLK83.5     */
2697fe5393cSmrg    {0x28, 0x49, 0x80},					/* 12: VCLK106.5    */
2707fe5393cSmrg    {0x37, 0x49, 0x80},					/* 13: VCLK146.25   */
2717fe5393cSmrg    {0x1f, 0x45, 0x80},					/* 14: VCLK148.5    */
2727fe5393cSmrg    {0x47, 0x6c, 0x80},					/* 15: VCLK71       */
2737fe5393cSmrg    {0x25, 0x65, 0x80},					/* 16: VCLK88.75    */
2747fe5393cSmrg    {0x77, 0x58, 0x80},					/* 17: VCLK119      */
2757fe5393cSmrg    {0x32, 0x67, 0x80},				    /* 18: VCLK85_5     */
276cf503b78Smrg    {0x6a, 0x6d, 0x80},					/* 19: VCLK97_75	*/
277cf503b78Smrg    {0x3b, 0x2c, 0x81},					/* 1A: VCLK118_25	*/
27815fb4814Smrg};
27915fb4814Smrg
280cf503b78Smrgstatic VBIOS_DCLK_INFO DCLKTable_AST2100 [] = {
281b534f209Smrg    {0x2C, 0xE7, 0x03},					/* 00: VCLK25_175	*/
282b534f209Smrg    {0x95, 0x62, 0x03},					/* 01: VCLK28_322	*/
2837fe5393cSmrg    {0x67, 0x63, 0x01},					/* 02: VCLK31_5     */
284b534f209Smrg    {0x76, 0x63, 0x01},					/* 03: VCLK36		*/
285b534f209Smrg    {0xEE, 0x67, 0x01},					/* 04: VCLK40		*/
286b534f209Smrg    {0x82, 0x62, 0x01},					/* 05: VCLK49_5		*/
287b534f209Smrg    {0xC6, 0x64, 0x01},					/* 06: VCLK50		*/
288b534f209Smrg    {0x94, 0x62, 0x01},					/* 07: VCLK56_25	*/
289b534f209Smrg    {0x80, 0x64, 0x00},					/* 08: VCLK65		*/
290b534f209Smrg    {0x7B, 0x63, 0x00},					/* 09: VCLK75		*/
291b534f209Smrg    {0x67, 0x62, 0x00},					/* 0A: VCLK78_75	*/
292b534f209Smrg    {0x7C, 0x62, 0x00},					/* 0B: VCLK94_5		*/
293b534f209Smrg    {0x8E, 0x62, 0x00},					/* 0C: VCLK108		*/
294b534f209Smrg    {0x85, 0x24, 0x00},					/* 0D: VCLK135		*/
295b534f209Smrg    {0x67, 0x22, 0x00},					/* 0E: VCLK157_5	*/
296b534f209Smrg    {0x6A, 0x22, 0x00},					/* 0F: VCLK162		*/
2977fe5393cSmrg    {0x4d, 0x4c, 0x80},				    /* 10: VCLK154      */
2987fe5393cSmrg    {0x68, 0x6f, 0x80},					/* 11: VCLK83.5     */
2997fe5393cSmrg    {0x28, 0x49, 0x80},					/* 12: VCLK106.5    */
3007fe5393cSmrg    {0x37, 0x49, 0x80},					/* 13: VCLK146.25   */
3017fe5393cSmrg    {0x1f, 0x45, 0x80},					/* 14: VCLK148.5    */
3027fe5393cSmrg    {0x47, 0x6c, 0x80},					/* 15: VCLK71       */
3037fe5393cSmrg    {0x25, 0x65, 0x80},					/* 16: VCLK88.75    */
3047fe5393cSmrg    {0x77, 0x58, 0x80},					/* 17: VCLK119      */
3057fe5393cSmrg    {0x32, 0x67, 0x80},				    /* 18: VCLK85_5     */
306cf503b78Smrg    {0x6a, 0x6d, 0x80},					/* 19: VCLK97_75	*/
307cf503b78Smrg    {0x3b, 0x2c, 0x81},					/* 1A: VCLK118_25	*/
308b534f209Smrg};
309b534f209Smrg
31058e54220Smrgstatic VBIOS_DCLK_INFO DCLKTable_AST2500 [] = {
31158e54220Smrg    {0x40, 0x38, 0x73},					/* 00: VCLK25_175	*/
31258e54220Smrg    {0x3A, 0x38, 0x43},					/* 01: VCLK28_322	*/
31358e54220Smrg    {0x3E, 0x70, 0x73},					/* 02: VCLK31_5         */
31458e54220Smrg    {0x35, 0x70, 0x43},					/* 03: VCLK36		*/
31558e54220Smrg    {0x31, 0x28, 0x73},					/* 04: VCLK40		*/
31658e54220Smrg    {0x41, 0x68, 0x73},					/* 05: VCLK49_5		*/
31758e54220Smrg    {0x31, 0x68, 0x53},					/* 06: VCLK50		*/
31858e54220Smrg    {0x4A, 0x68, 0x73},					/* 07: VCLK56_25	*/
31958e54220Smrg    {0x40, 0x68, 0x53},					/* 08: VCLK65		*/
32058e54220Smrg    {0x31, 0x60, 0x73},					/* 09: VCLK75		*/
32158e54220Smrg    {0x3A, 0x28, 0x43},					/* 0A: VCLK78_75	*/
32258e54220Smrg    {0x3E, 0x60, 0x73},					/* 0B: VCLK94_5		*/
32358e54220Smrg    {0x35, 0x60, 0x63},					/* 0C: VCLK108		*/
32458e54220Smrg    {0x3D, 0x40, 0x63},					/* 0D: VCLK135		*/
32558e54220Smrg    {0x4E, 0x60, 0x63},					/* 0E: VCLK157_5	*/
32658e54220Smrg    {0x35, 0x60, 0x53},					/* 0F: VCLK162		*/
32758e54220Smrg    {0x4C, 0x60, 0x63},				    /* 10: VCLK154      	*/
32858e54220Smrg    {0x4F, 0x48, 0x53},					/* 11: VCLK83.5         */
32958e54220Smrg    {0x46, 0x60, 0x73},					/* 12: VCLK106.5        */
33058e54220Smrg    {0x3C, 0x20, 0x63},					/* 13: VCLK146.25       */
33158e54220Smrg    {0x3D, 0x20, 0x63},					/* 14: VCLK148.5        */
33258e54220Smrg    {0x46, 0x68, 0x53},					/* 15: VCLK71           */
33358e54220Smrg    {0x49, 0x68, 0x43},					/* 16: VCLK88.75        */
33458e54220Smrg    {0x4e, 0x60, 0x73},					/* 17: VCLK119          */
33558e54220Smrg    {0x38, 0x60, 0x73},				    /* 18: VCLK85_5         */
33658e54220Smrg    {0x38, 0x20, 0x73},					/* 19: VCLK97_75 */
33758e54220Smrg    {0x4e, 0x60, 0x73},					/* 1A: VCLK118_25 */
33858e54220Smrg};
33958e54220Smrg
34058e54220Smrgstatic VBIOS_DCLK_INFO DCLKTable_AST2500A1 [] = {
34158e54220Smrg    {0x2C, 0xE7, 0x03},					/* 00: VCLK25_175	*/
34258e54220Smrg    {0x95, 0x62, 0x03},					/* 01: VCLK28_322	*/
34358e54220Smrg    {0x67, 0x63, 0x01},					/* 02: VCLK31_5         */
34458e54220Smrg    {0x76, 0x63, 0x01},					/* 03: VCLK36		*/
34558e54220Smrg    {0xEE, 0x67, 0x01},					/* 04: VCLK40		*/
34658e54220Smrg    {0x82, 0x62, 0x01},					/* 05: VCLK49_5		*/
34758e54220Smrg    {0xC6, 0x64, 0x01},					/* 06: VCLK50		*/
34858e54220Smrg    {0x94, 0x62, 0x01},					/* 07: VCLK56_25	*/
34958e54220Smrg    {0x80, 0x64, 0x00},					/* 08: VCLK65		*/
35058e54220Smrg    {0x7B, 0x63, 0x00},					/* 09: VCLK75		*/
35158e54220Smrg    {0x67, 0x62, 0x00},					/* 0A: VCLK78_75	*/
35258e54220Smrg    {0x7C, 0x62, 0x00},					/* 0B: VCLK94_5		*/
35358e54220Smrg    {0x8E, 0x62, 0x00},					/* 0C: VCLK108		*/
35458e54220Smrg    {0x85, 0x24, 0x00},					/* 0D: VCLK135		*/
35558e54220Smrg    {0x67, 0x22, 0x00},					/* 0E: VCLK157_5	*/
35658e54220Smrg    {0x6A, 0x22, 0x00},					/* 0F: VCLK162		*/
35758e54220Smrg    {0x4d, 0x4c, 0x80},				        /* 10: VCLK154      	*/
35858e54220Smrg    {0x68, 0x6f, 0x80},					/* 11: VCLK83.5         */
35958e54220Smrg    {0x28, 0x49, 0x80},					/* 12: VCLK106.5        */
36058e54220Smrg    {0x37, 0x49, 0x80},					/* 13: VCLK146.25       */
36158e54220Smrg    {0x1f, 0x45, 0x80},					/* 14: VCLK148.5        */
36258e54220Smrg    {0x47, 0x6c, 0x80},					/* 15: VCLK71           */
36358e54220Smrg    {0x25, 0x65, 0x80},					/* 16: VCLK88.75        */
36458e54220Smrg    {0x58, 0x01, 0x42},					/* 17: VCLK119          */
36558e54220Smrg    {0x32, 0x67, 0x80},				        /* 18: VCLK85_5         */
36658e54220Smrg    {0x6a, 0x6d, 0x80},					/* 19: VCLK97_75 */
36758e54220Smrg    {0x44, 0x20, 0x43},					/* 1A: VCLK118_25 */
36858e54220Smrg};
36958e54220Smrg
370f010a93dSmrg#if 0
371cf503b78Smrgstatic VBIOS_DAC_INFO DAC_TEXT[] = {
3727fe5393cSmrg { 0x00, 0x00, 0x00 },  { 0x00, 0x00, 0x2a },  { 0x00, 0x2a, 0x00 },  { 0x00, 0x2a, 0x2a },
3737fe5393cSmrg { 0x2a, 0x00, 0x00 },  { 0x2a, 0x00, 0x2a },  { 0x2a, 0x2a, 0x00 },  { 0x2a, 0x2a, 0x2a },
3747fe5393cSmrg { 0x00, 0x00, 0x15 },  { 0x00, 0x00, 0x3f },  { 0x00, 0x2a, 0x15 },  { 0x00, 0x2a, 0x3f },
3757fe5393cSmrg { 0x2a, 0x00, 0x15 },  { 0x2a, 0x00, 0x3f },  { 0x2a, 0x2a, 0x15 },  { 0x2a, 0x2a, 0x3f },
3767fe5393cSmrg { 0x00, 0x15, 0x00 },  { 0x00, 0x15, 0x2a },  { 0x00, 0x3f, 0x00 },  { 0x00, 0x3f, 0x2a },
3777fe5393cSmrg { 0x2a, 0x15, 0x00 },  { 0x2a, 0x15, 0x2a },  { 0x2a, 0x3f, 0x00 },  { 0x2a, 0x3f, 0x2a },
3787fe5393cSmrg { 0x00, 0x15, 0x15 },  { 0x00, 0x15, 0x3f },  { 0x00, 0x3f, 0x15 },  { 0x00, 0x3f, 0x3f },
3797fe5393cSmrg { 0x2a, 0x15, 0x15 },  { 0x2a, 0x15, 0x3f },  { 0x2a, 0x3f, 0x15 },  { 0x2a, 0x3f, 0x3f },
3807fe5393cSmrg { 0x15, 0x00, 0x00 },  { 0x15, 0x00, 0x2a },  { 0x15, 0x2a, 0x00 },  { 0x15, 0x2a, 0x2a },
3817fe5393cSmrg { 0x3f, 0x00, 0x00 },  { 0x3f, 0x00, 0x2a },  { 0x3f, 0x2a, 0x00 },  { 0x3f, 0x2a, 0x2a },
3827fe5393cSmrg { 0x15, 0x00, 0x15 },  { 0x15, 0x00, 0x3f },  { 0x15, 0x2a, 0x15 },  { 0x15, 0x2a, 0x3f },
3837fe5393cSmrg { 0x3f, 0x00, 0x15 },  { 0x3f, 0x00, 0x3f },  { 0x3f, 0x2a, 0x15 },  { 0x3f, 0x2a, 0x3f },
3847fe5393cSmrg { 0x15, 0x15, 0x00 },  { 0x15, 0x15, 0x2a },  { 0x15, 0x3f, 0x00 },  { 0x15, 0x3f, 0x2a },
3857fe5393cSmrg { 0x3f, 0x15, 0x00 },  { 0x3f, 0x15, 0x2a },  { 0x3f, 0x3f, 0x00 },  { 0x3f, 0x3f, 0x2a },
3867fe5393cSmrg { 0x15, 0x15, 0x15 },  { 0x15, 0x15, 0x3f },  { 0x15, 0x3f, 0x15 },  { 0x15, 0x3f, 0x3f },
3877fe5393cSmrg { 0x3f, 0x15, 0x15 },  { 0x3f, 0x15, 0x3f },  { 0x3f, 0x3f, 0x15 },  { 0x3f, 0x3f, 0x3f },
38815fb4814Smrg};
38915fb4814Smrg
390cf503b78Smrgstatic VBIOS_DAC_INFO DAC_EGA[] = {
3917fe5393cSmrg { 0x00, 0x00, 0x00 },  { 0x00, 0x00, 0x2a },  { 0x00, 0x2a, 0x00 },  { 0x00, 0x2a, 0x2a },
3927fe5393cSmrg { 0x2a, 0x00, 0x00 },  { 0x2a, 0x00, 0x2a },  { 0x2a, 0x2a, 0x00 },  { 0x2a, 0x2a, 0x2a },
3937fe5393cSmrg { 0x00, 0x00, 0x15 },  { 0x00, 0x00, 0x3f },  { 0x00, 0x2a, 0x15 },  { 0x00, 0x2a, 0x3f },
3947fe5393cSmrg { 0x2a, 0x00, 0x15 },  { 0x2a, 0x00, 0x3f },  { 0x2a, 0x2a, 0x15 },  { 0x2a, 0x2a, 0x3f },
3957fe5393cSmrg { 0x00, 0x15, 0x00 },  { 0x00, 0x15, 0x2a },  { 0x00, 0x3f, 0x00 },  { 0x00, 0x3f, 0x2a },
3967fe5393cSmrg { 0x2a, 0x15, 0x00 },  { 0x2a, 0x15, 0x2a },  { 0x2a, 0x3f, 0x00 },  { 0x2a, 0x3f, 0x2a },
3977fe5393cSmrg { 0x00, 0x15, 0x15 },  { 0x00, 0x15, 0x3f },  { 0x00, 0x3f, 0x15 },  { 0x00, 0x3f, 0x3f },
3987fe5393cSmrg { 0x2a, 0x15, 0x15 },  { 0x2a, 0x15, 0x3f },  { 0x2a, 0x3f, 0x15 },  { 0x2a, 0x3f, 0x3f },
3997fe5393cSmrg { 0x15, 0x00, 0x00 },  { 0x15, 0x00, 0x2a },  { 0x15, 0x2a, 0x00 },  { 0x15, 0x2a, 0x2a },
4007fe5393cSmrg { 0x3f, 0x00, 0x00 },  { 0x3f, 0x00, 0x2a },  { 0x3f, 0x2a, 0x00 },  { 0x3f, 0x2a, 0x2a },
4017fe5393cSmrg { 0x15, 0x00, 0x15 },  { 0x15, 0x00, 0x3f },  { 0x15, 0x2a, 0x15 },  { 0x15, 0x2a, 0x3f },
4027fe5393cSmrg { 0x3f, 0x00, 0x15 },  { 0x3f, 0x00, 0x3f },  { 0x3f, 0x2a, 0x15 },  { 0x3f, 0x2a, 0x3f },
4037fe5393cSmrg { 0x15, 0x15, 0x00 },  { 0x15, 0x15, 0x2a },  { 0x15, 0x3f, 0x00 },  { 0x15, 0x3f, 0x2a },
4047fe5393cSmrg { 0x3f, 0x15, 0x00 },  { 0x3f, 0x15, 0x2a },  { 0x3f, 0x3f, 0x00 },  { 0x3f, 0x3f, 0x2a },
4057fe5393cSmrg { 0x15, 0x15, 0x15 },  { 0x15, 0x15, 0x3f },  { 0x15, 0x3f, 0x15 },  { 0x15, 0x3f, 0x3f },
4067fe5393cSmrg { 0x3f, 0x15, 0x15 },  { 0x3f, 0x15, 0x3f },  { 0x3f, 0x3f, 0x15 },  { 0x3f, 0x3f, 0x3f },
40715fb4814Smrg};
408f010a93dSmrg#endif
40915fb4814Smrg
410cf503b78Smrgstatic VBIOS_DAC_INFO DAC_VGA[] = {
4117fe5393cSmrg { 0x00, 0x00, 0x00 },  { 0x00, 0x00, 0x2a },  { 0x00, 0x2a, 0x00 },  { 0x00, 0x2a, 0x2a },
4127fe5393cSmrg { 0x2a, 0x00, 0x00 },  { 0x2a, 0x00, 0x2a },  { 0x2a, 0x15, 0x00 },  { 0x2a, 0x2a, 0x2a },
4137fe5393cSmrg { 0x15, 0x15, 0x15 },  { 0x15, 0x15, 0x3f },  { 0x15, 0x3f, 0x15 },  { 0x15, 0x3f, 0x3f },
4147fe5393cSmrg { 0x3f, 0x15, 0x15 },  { 0x3f, 0x15, 0x3f },  { 0x3f, 0x3f, 0x15 },  { 0x3f, 0x3f, 0x3f },
4157fe5393cSmrg { 0x00, 0x00, 0x00 },  { 0x05, 0x05, 0x05 },  { 0x08, 0x08, 0x08 },  { 0x0b, 0x0b, 0x0b },
4167fe5393cSmrg { 0x0e, 0x0e, 0x0e },  { 0x11, 0x11, 0x11 },  { 0x14, 0x14, 0x14 },  { 0x18, 0x18, 0x18 },
4177fe5393cSmrg { 0x1c, 0x1c, 0x1c },  { 0x20, 0x20, 0x20 },  { 0x24, 0x24, 0x24 },  { 0x28, 0x28, 0x28 },
4187fe5393cSmrg { 0x2d, 0x2d, 0x2d },  { 0x32, 0x32, 0x32 },  { 0x38, 0x38, 0x38 },  { 0x3f, 0x3f, 0x3f },
4197fe5393cSmrg { 0x00, 0x00, 0x3f },  { 0x10, 0x00, 0x3f },  { 0x1f, 0x00, 0x3f },  { 0x2f, 0x00, 0x3f },
4207fe5393cSmrg { 0x3f, 0x00, 0x3f },  { 0x3f, 0x00, 0x2f },  { 0x3f, 0x00, 0x1f },  { 0x3f, 0x00, 0x10 },
4217fe5393cSmrg { 0x3f, 0x00, 0x00 },  { 0x3f, 0x10, 0x00 },  { 0x3f, 0x1f, 0x00 },  { 0x3f, 0x2f, 0x00 },
4227fe5393cSmrg { 0x3f, 0x3f, 0x00 },  { 0x2f, 0x3f, 0x00 },  { 0x1f, 0x3f, 0x00 },  { 0x10, 0x3f, 0x00 },
4237fe5393cSmrg { 0x00, 0x3f, 0x00 },  { 0x00, 0x3f, 0x10 },  { 0x00, 0x3f, 0x1f },  { 0x00, 0x3f, 0x2f },
4247fe5393cSmrg { 0x00, 0x3f, 0x3f },  { 0x00, 0x2f, 0x3f },  { 0x00, 0x1f, 0x3f },  { 0x00, 0x10, 0x3f },
4257fe5393cSmrg { 0x1f, 0x1f, 0x3f },  { 0x27, 0x1f, 0x3f },  { 0x2f, 0x1f, 0x3f },  { 0x37, 0x1f, 0x3f },
4267fe5393cSmrg { 0x3f, 0x1f, 0x3f },  { 0x3f, 0x1f, 0x37 },  { 0x3f, 0x1f, 0x2f },  { 0x3f, 0x1f, 0x27 },
4277fe5393cSmrg { 0x3f, 0x1f, 0x1f },  { 0x3f, 0x27, 0x1f },  { 0x3f, 0x2f, 0x1f },  { 0x3f, 0x37, 0x1f },
4287fe5393cSmrg { 0x3f, 0x3f, 0x1f },  { 0x37, 0x3f, 0x1f },  { 0x2f, 0x3f, 0x1f },  { 0x27, 0x3f, 0x1f },
4297fe5393cSmrg { 0x1f, 0x3f, 0x1f },  { 0x1f, 0x3f, 0x27 },  { 0x1f, 0x3f, 0x2f },  { 0x1f, 0x3f, 0x37 },
4307fe5393cSmrg { 0x1f, 0x3f, 0x3f },  { 0x1f, 0x37, 0x3f },  { 0x1f, 0x2f, 0x3f },  { 0x1f, 0x27, 0x3f },
4317fe5393cSmrg { 0x2d, 0x2d, 0x3f },  { 0x31, 0x2d, 0x3f },  { 0x36, 0x2d, 0x3f },  { 0x3a, 0x2d, 0x3f },
4327fe5393cSmrg { 0x3f, 0x2d, 0x3f },  { 0x3f, 0x2d, 0x3a },  { 0x3f, 0x2d, 0x36 },  { 0x3f, 0x2d, 0x31 },
4337fe5393cSmrg { 0x3f, 0x2d, 0x2d },  { 0x3f, 0x31, 0x2d },  { 0x3f, 0x36, 0x2d },  { 0x3f, 0x3a, 0x2d },
4347fe5393cSmrg { 0x3f, 0x3f, 0x2d },  { 0x3a, 0x3f, 0x2d },  { 0x36, 0x3f, 0x2d },  { 0x31, 0x3f, 0x2d },
4357fe5393cSmrg { 0x2d, 0x3f, 0x2d },  { 0x2d, 0x3f, 0x31 },  { 0x2d, 0x3f, 0x36 },  { 0x2d, 0x3f, 0x3a },
4367fe5393cSmrg { 0x2d, 0x3f, 0x3f },  { 0x2d, 0x3a, 0x3f },  { 0x2d, 0x36, 0x3f },  { 0x2d, 0x31, 0x3f },
4377fe5393cSmrg { 0x00, 0x00, 0x1c },  { 0x07, 0x00, 0x1c },  { 0x0e, 0x00, 0x1c },  { 0x15, 0x00, 0x1c },
4387fe5393cSmrg { 0x1c, 0x00, 0x1c },  { 0x1c, 0x00, 0x15 },  { 0x1c, 0x00, 0x0e },  { 0x1c, 0x00, 0x07 },
4397fe5393cSmrg { 0x1c, 0x00, 0x00 },  { 0x1c, 0x07, 0x00 },  { 0x1c, 0x0e, 0x00 },  { 0x1c, 0x15, 0x00 },
4407fe5393cSmrg { 0x1c, 0x1c, 0x00 },  { 0x15, 0x1c, 0x00 },  { 0x0e, 0x1c, 0x00 },  { 0x07, 0x1c, 0x00 },
4417fe5393cSmrg { 0x00, 0x1c, 0x00 },  { 0x00, 0x1c, 0x07 },  { 0x00, 0x1c, 0x0e },  { 0x00, 0x1c, 0x15 },
4427fe5393cSmrg { 0x00, 0x1c, 0x1c },  { 0x00, 0x15, 0x1c },  { 0x00, 0x0e, 0x1c },  { 0x00, 0x07, 0x1c },
4437fe5393cSmrg { 0x0e, 0x0e, 0x1c },  { 0x11, 0x0e, 0x1c },  { 0x15, 0x0e, 0x1c },  { 0x18, 0x0e, 0x1c },
4447fe5393cSmrg { 0x1c, 0x0e, 0x1c },  { 0x1c, 0x0e, 0x18 },  { 0x1c, 0x0e, 0x15 },  { 0x1c, 0x0e, 0x11 },
4457fe5393cSmrg { 0x1c, 0x0e, 0x0e },  { 0x1c, 0x11, 0x0e },  { 0x1c, 0x15, 0x0e },  { 0x1c, 0x18, 0x0e },
4467fe5393cSmrg { 0x1c, 0x1c, 0x0e },  { 0x18, 0x1c, 0x0e },  { 0x15, 0x1c, 0x0e },  { 0x11, 0x1c, 0x0e },
4477fe5393cSmrg { 0x0e, 0x1c, 0x0e },  { 0x0e, 0x1c, 0x11 },  { 0x0e, 0x1c, 0x15 },  { 0x0e, 0x1c, 0x18 },
4487fe5393cSmrg { 0x0e, 0x1c, 0x1c },  { 0x0e, 0x18, 0x1c },  { 0x0e, 0x15, 0x1c },  { 0x0e, 0x11, 0x1c },
4497fe5393cSmrg { 0x14, 0x14, 0x1c },  { 0x16, 0x14, 0x1c },  { 0x18, 0x14, 0x1c },  { 0x1a, 0x14, 0x1c },
4507fe5393cSmrg { 0x1c, 0x14, 0x1c },  { 0x1c, 0x14, 0x1a },  { 0x1c, 0x14, 0x18 },  { 0x1c, 0x14, 0x16 },
4517fe5393cSmrg { 0x1c, 0x14, 0x14 },  { 0x1c, 0x16, 0x14 },  { 0x1c, 0x18, 0x14 },  { 0x1c, 0x1a, 0x14 },
4527fe5393cSmrg { 0x1c, 0x1c, 0x14 },  { 0x1a, 0x1c, 0x14 },  { 0x18, 0x1c, 0x14 },  { 0x16, 0x1c, 0x14 },
4537fe5393cSmrg { 0x14, 0x1c, 0x14 },  { 0x14, 0x1c, 0x16 },  { 0x14, 0x1c, 0x18 },  { 0x14, 0x1c, 0x1a },
4547fe5393cSmrg { 0x14, 0x1c, 0x1c },  { 0x14, 0x1a, 0x1c },  { 0x14, 0x18, 0x1c },  { 0x14, 0x16, 0x1c },
4557fe5393cSmrg { 0x00, 0x00, 0x10 },  { 0x04, 0x00, 0x10 },  { 0x08, 0x00, 0x10 },  { 0x0c, 0x00, 0x10 },
4567fe5393cSmrg { 0x10, 0x00, 0x10 },  { 0x10, 0x00, 0x0c },  { 0x10, 0x00, 0x08 },  { 0x10, 0x00, 0x04 },
4577fe5393cSmrg { 0x10, 0x00, 0x00 },  { 0x10, 0x04, 0x00 },  { 0x10, 0x08, 0x00 },  { 0x10, 0x0c, 0x00 },
4587fe5393cSmrg { 0x10, 0x10, 0x00 },  { 0x0c, 0x10, 0x00 },  { 0x08, 0x10, 0x00 },  { 0x04, 0x10, 0x00 },
4597fe5393cSmrg { 0x00, 0x10, 0x00 },  { 0x00, 0x10, 0x04 },  { 0x00, 0x10, 0x08 },  { 0x00, 0x10, 0x0c },
4607fe5393cSmrg { 0x00, 0x10, 0x10 },  { 0x00, 0x0c, 0x10 },  { 0x00, 0x08, 0x10 },  { 0x00, 0x04, 0x10 },
4617fe5393cSmrg { 0x08, 0x08, 0x10 },  { 0x0a, 0x08, 0x10 },  { 0x0c, 0x08, 0x10 },  { 0x0e, 0x08, 0x10 },
4627fe5393cSmrg { 0x10, 0x08, 0x10 },  { 0x10, 0x08, 0x0e },  { 0x10, 0x08, 0x0c },  { 0x10, 0x08, 0x0a },
4637fe5393cSmrg { 0x10, 0x08, 0x08 },  { 0x10, 0x0a, 0x08 },  { 0x10, 0x0c, 0x08 },  { 0x10, 0x0e, 0x08 },
4647fe5393cSmrg { 0x10, 0x10, 0x08 },  { 0x0e, 0x10, 0x08 },  { 0x0c, 0x10, 0x08 },  { 0x0a, 0x10, 0x08 },
4657fe5393cSmrg { 0x08, 0x10, 0x08 },  { 0x08, 0x10, 0x0a },  { 0x08, 0x10, 0x0c },  { 0x08, 0x10, 0x0e },
4667fe5393cSmrg { 0x08, 0x10, 0x10 },  { 0x08, 0x0e, 0x10 },  { 0x08, 0x0c, 0x10 },  { 0x08, 0x0a, 0x10 },
4677fe5393cSmrg { 0x0b, 0x0b, 0x10 },  { 0x0c, 0x0b, 0x10 },  { 0x0d, 0x0b, 0x10 },  { 0x0f, 0x0b, 0x10 },
4687fe5393cSmrg { 0x10, 0x0b, 0x10 },  { 0x10, 0x0b, 0x0f },  { 0x10, 0x0b, 0x0d },  { 0x10, 0x0b, 0x0c },
4697fe5393cSmrg { 0x10, 0x0b, 0x0b },  { 0x10, 0x0c, 0x0b },  { 0x10, 0x0d, 0x0b },  { 0x10, 0x0f, 0x0b },
4707fe5393cSmrg { 0x10, 0x10, 0x0b },  { 0x0f, 0x10, 0x0b },  { 0x0d, 0x10, 0x0b },  { 0x0c, 0x10, 0x0b },
4717fe5393cSmrg { 0x0b, 0x10, 0x0b },  { 0x0b, 0x10, 0x0c },  { 0x0b, 0x10, 0x0d },  { 0x0b, 0x10, 0x0f },
4727fe5393cSmrg { 0x0b, 0x10, 0x10 },  { 0x0b, 0x0f, 0x10 },  { 0x0b, 0x0d, 0x10 },  { 0x0b, 0x0c, 0x10 },
4737fe5393cSmrg { 0x00, 0x00, 0x00 },  { 0x00, 0x00, 0x00 },  { 0x00, 0x00, 0x00 },  { 0x00, 0x00, 0x00 },
4747fe5393cSmrg { 0x00, 0x00, 0x00 },  { 0x00, 0x00, 0x00 },  { 0x00, 0x00, 0x00 },  { 0x00, 0x00, 0x00 },
47515fb4814Smrg};
47615fb4814Smrg
47715fb4814Smrg/* Prototype type declaration*/
478cf503b78Smrgstatic Bool bGetAST1000VGAModeInfo(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo);
479cf503b78Smrgstatic void vSetStdReg(ScrnInfoPtr pScrn,  DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo);
480cf503b78Smrgstatic void vSetCRTCReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo);
481cf503b78Smrgstatic void vSetOffsetReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo);
482cf503b78Smrgstatic void vSetDCLKReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo);
483cf503b78Smrgstatic void vSetExtReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo);
484cf503b78Smrgstatic void vSetSyncReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo);
485cf503b78Smrgstatic Bool bSetDACReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo);
486cf503b78Smrgstatic BOOL bSetAST1180CRTCReg(ScrnInfoPtr pScrn,  DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo);
487cf503b78Smrgstatic BOOL bSetAST1180OffsetReg(ScrnInfoPtr pScrn,  DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo);
488cf503b78Smrgstatic BOOL bSetAST1180DCLKReg(ScrnInfoPtr pScrn,  DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo);
489cf503b78Smrgstatic BOOL bSetAST1180ExtReg(ScrnInfoPtr pScrn,  DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo);
490cf503b78Smrgstatic void vInitChrontelReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo);
49115fb4814Smrg
49215fb4814SmrgBool
49315fb4814SmrgASTSetMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
49415fb4814Smrg{
49515fb4814Smrg    ASTRecPtr pAST;
4967fe5393cSmrg    VBIOS_MODE_INFO vgamodeinfo;
4977fe5393cSmrg
49815fb4814Smrg    pAST = ASTPTR(pScrn);
49915fb4814Smrg
5007fe5393cSmrg    /* pre set mode */
5017fe5393cSmrg    bGetAST1000VGAModeInfo(pScrn, mode, &vgamodeinfo);
5027fe5393cSmrg
50315fb4814Smrg    /* set mode */
504b534f209Smrg    if (pAST->jChipType == AST1180)
505b534f209Smrg    {
506cf503b78Smrg        bASTInitAST1180(pScrn);
5077fe5393cSmrg
508b534f209Smrg        bSetAST1180CRTCReg(pScrn, mode, &vgamodeinfo);
509b534f209Smrg        bSetAST1180OffsetReg(pScrn, mode, &vgamodeinfo);
510b534f209Smrg        bSetAST1180DCLKReg(pScrn, mode, &vgamodeinfo);
511b534f209Smrg        bSetAST1180ExtReg(pScrn, mode, &vgamodeinfo);
5127fe5393cSmrg
513cf503b78Smrg        vInitChrontelReg(pScrn, mode, &vgamodeinfo);
514b534f209Smrg    }
515b534f209Smrg    else
516b534f209Smrg    {
517b534f209Smrg        vASTOpenKey(pScrn);
518b534f209Smrg        bASTRegInit(pScrn);
5197fe5393cSmrg
520cf503b78Smrg        vAST1000DisplayOff(pScrn);
521cf503b78Smrg
5227fe5393cSmrg        vSetStdReg(pScrn, mode, &vgamodeinfo);
523b534f209Smrg        vSetCRTCReg(pScrn, mode, &vgamodeinfo);
5247fe5393cSmrg        vSetOffsetReg(pScrn, mode, &vgamodeinfo);
525b534f209Smrg        vSetDCLKReg(pScrn, mode, &vgamodeinfo);
526b534f209Smrg        vSetExtReg(pScrn, mode, &vgamodeinfo);
527b534f209Smrg        vSetSyncReg(pScrn, mode, &vgamodeinfo);
5287fe5393cSmrg        bSetDACReg(pScrn, mode, &vgamodeinfo);
529cf503b78Smrg
53058e54220Smrg        /* clear video buffer to avoid display noise */
53158e54220Smrg        memset(pAST->FBVirtualAddr, 0x00, pAST->VideoModeInfo.ScreenPitch*pAST->VideoModeInfo.ScreenHeight);
53258e54220Smrg
533cf503b78Smrg        vAST1000DisplayOn(pScrn);
534b534f209Smrg    }
5357fe5393cSmrg
53615fb4814Smrg    /* post set mode */
53715fb4814Smrg#ifdef	Accel_2D
53815fb4814Smrg   if (!pAST->noAccel) {
539cf503b78Smrg       if (!bASTEnable2D(pScrn, pAST)) {
5407fe5393cSmrg           xf86DrvMsg(pScrn->scrnIndex, X_ERROR,"Enable 2D failed\n");
5417fe5393cSmrg           pAST->noAccel = TRUE;
5427fe5393cSmrg       }
54315fb4814Smrg   }
5447fe5393cSmrg#endif
54515fb4814Smrg#ifdef	HWC
54615fb4814Smrg   if (!pAST->noHWC) {
547cf503b78Smrg       if (!bASTInitHWC(pScrn, pAST)) {
5487fe5393cSmrg           xf86DrvMsg(pScrn->scrnIndex, X_ERROR,"Init HWC failed\n");
5497fe5393cSmrg           pAST->noHWC = TRUE;
5507fe5393cSmrg       }
55115fb4814Smrg   }
5527fe5393cSmrg#endif
5537fe5393cSmrg
5547fe5393cSmrg    return (TRUE);
55515fb4814Smrg}
55615fb4814Smrg
55715fb4814Smrg
558cf503b78Smrgstatic Bool bGetAST1000VGAModeInfo(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo)
55915fb4814Smrg{
5607fe5393cSmrg    ASTRecPtr pAST;
56115fb4814Smrg    ULONG ulModeID, ulColorIndex, ulRefreshRate, ulRefreshRateIndex = 0;
56215fb4814Smrg    ULONG ulHBorder, ulVBorder;
56358e54220Smrg    Bool check_sync;
56458e54220Smrg    PVBIOS_ENHTABLE_STRUCT loop, best = NULL;
5657fe5393cSmrg
56615fb4814Smrg    pAST = ASTPTR(pScrn);
5677fe5393cSmrg
56815fb4814Smrg    switch (pScrn->bitsPerPixel)
56915fb4814Smrg    {
57015fb4814Smrg    case 8:
5717fe5393cSmrg         pVGAModeInfo->pStdTableEntry = (PVBIOS_STDTABLE_STRUCT) &StdTable[VGAModeIndex];
5727fe5393cSmrg	 ulColorIndex = VGAModeIndex-1;
5737fe5393cSmrg         break;
57415fb4814Smrg    case 16:
57515fb4814Smrg         pVGAModeInfo->pStdTableEntry = (PVBIOS_STDTABLE_STRUCT) &StdTable[HiCModeIndex];
5767fe5393cSmrg	 ulColorIndex = HiCModeIndex;
57715fb4814Smrg         break;
5787fe5393cSmrg    case 24:
57915fb4814Smrg    case 32:
5807fe5393cSmrg         pVGAModeInfo->pStdTableEntry = (PVBIOS_STDTABLE_STRUCT) &StdTable[TrueCModeIndex];
5817fe5393cSmrg	 ulColorIndex = TrueCModeIndex;
5827fe5393cSmrg	 break;
58315fb4814Smrg    default:
58415fb4814Smrg         return (FALSE);
58515fb4814Smrg    }
58615fb4814Smrg
58715fb4814Smrg    switch (mode->CrtcHDisplay)
58815fb4814Smrg    {
58915fb4814Smrg    case 640:
590b410ddbeSmrg	 pVGAModeInfo->pEnhTableEntry = (PVBIOS_ENHTABLE_STRUCT) &Res640x480Table[ulRefreshRateIndex];
591b410ddbeSmrg	 break;
59215fb4814Smrg    case 800:
593b410ddbeSmrg	 pVGAModeInfo->pEnhTableEntry = (PVBIOS_ENHTABLE_STRUCT) &Res800x600Table[ulRefreshRateIndex];
594b410ddbeSmrg	 break;
59515fb4814Smrg    case 1024:
596b410ddbeSmrg	 pVGAModeInfo->pEnhTableEntry = (PVBIOS_ENHTABLE_STRUCT) &Res1024x768Table[ulRefreshRateIndex];
597b410ddbeSmrg	 break;
59815fb4814Smrg    case 1280:
599b410ddbeSmrg         if (mode->CrtcVDisplay == 800)
6007fe5393cSmrg             pVGAModeInfo->pEnhTableEntry = (PVBIOS_ENHTABLE_STRUCT) &Res1280x800Table[ulRefreshRateIndex];
601b410ddbeSmrg         else
6027fe5393cSmrg             pVGAModeInfo->pEnhTableEntry = (PVBIOS_ENHTABLE_STRUCT) &Res1280x1024Table[ulRefreshRateIndex];
603b410ddbeSmrg	 break;
6047fe5393cSmrg    case 1360:
6057fe5393cSmrg         pVGAModeInfo->pEnhTableEntry = (PVBIOS_ENHTABLE_STRUCT) &Res1360x768Table[ulRefreshRateIndex];
6067fe5393cSmrg         break;
607b410ddbeSmrg    case 1440:
608b410ddbeSmrg         pVGAModeInfo->pEnhTableEntry = (PVBIOS_ENHTABLE_STRUCT) &Res1440x900Table[ulRefreshRateIndex];
6097fe5393cSmrg         break;
61015fb4814Smrg    case 1600:
6117fe5393cSmrg         if (mode->CrtcVDisplay == 900)
6127fe5393cSmrg	     pVGAModeInfo->pEnhTableEntry = (PVBIOS_ENHTABLE_STRUCT) &Res1600x900Table[ulRefreshRateIndex];
6137fe5393cSmrg         else
6147fe5393cSmrg	     pVGAModeInfo->pEnhTableEntry = (PVBIOS_ENHTABLE_STRUCT) &Res1600x1200Table[ulRefreshRateIndex];
615b410ddbeSmrg	 break;
616b410ddbeSmrg    case 1680:
617b410ddbeSmrg         pVGAModeInfo->pEnhTableEntry = (PVBIOS_ENHTABLE_STRUCT) &Res1680x1050Table[ulRefreshRateIndex];
618de78e416Smrg         break;
619de78e416Smrg    case 1920:
620b410ddbeSmrg         if (mode->CrtcVDisplay == 1080)
6217fe5393cSmrg             pVGAModeInfo->pEnhTableEntry = (PVBIOS_ENHTABLE_STRUCT) &Res1920x1080Table[ulRefreshRateIndex];
622b410ddbeSmrg         else
623b410ddbeSmrg             pVGAModeInfo->pEnhTableEntry = (PVBIOS_ENHTABLE_STRUCT) &Res1920x1200Table[ulRefreshRateIndex];
6247fe5393cSmrg         break;
625b410ddbeSmrg    default:
626b410ddbeSmrg	 return (FALSE);
62715fb4814Smrg    }
62815fb4814Smrg
62915fb4814Smrg    /* Get Proper Mode Index */
63058e54220Smrg    ulRefreshRate = (mode->Clock * 1000) / (mode->HTotal * mode->VTotal) + 1;
63158e54220Smrg    loop = pVGAModeInfo->pEnhTableEntry;
63258e54220Smrg    check_sync = loop->Flags & WideScreenMode;
63358e54220Smrg    do {
63458e54220Smrg	while (loop->ulRefreshRate != 0xff) {
63558e54220Smrg		if ((check_sync) &&
63658e54220Smrg		    (((mode->Flags & V_NVSYNC)  &&
63758e54220Smrg		      (loop->Flags & PVSync))  ||
63858e54220Smrg		     ((mode->Flags & V_PVSYNC)  &&
63958e54220Smrg		      (loop->Flags & NVSync))  ||
64058e54220Smrg		     ((mode->Flags & V_NHSYNC)  &&
64158e54220Smrg		      (loop->Flags & PHSync))  ||
64258e54220Smrg		     ((mode->Flags & V_PHSYNC)  &&
64358e54220Smrg		      (loop->Flags & NHSync)))) {
64458e54220Smrg			loop++;
64558e54220Smrg			continue;
64658e54220Smrg		}
64758e54220Smrg	if (loop->ulRefreshRate <= ulRefreshRate
64858e54220Smrg		    && (!best || loop->ulRefreshRate > best->ulRefreshRate))
64958e54220Smrg			best = loop;
65058e54220Smrg			loop++;
65158e54220Smrg	}
65258e54220Smrg	if (best || !check_sync)
65358e54220Smrg		break;
65458e54220Smrg	check_sync = 0;
65558e54220Smrg    } while (1);
65658e54220Smrg    if (best)
65758e54220Smrg	pVGAModeInfo->pEnhTableEntry = best;
658b4d38c65Smrg
65915fb4814Smrg    /* Update mode CRTC info */
6607fe5393cSmrg    ulHBorder = (pVGAModeInfo->pEnhTableEntry->Flags & HBorder) ? 8:0;
6617fe5393cSmrg    ulVBorder = (pVGAModeInfo->pEnhTableEntry->Flags & VBorder) ? 8:0;
6627fe5393cSmrg
66315fb4814Smrg    mode->CrtcHTotal      = (int) pVGAModeInfo->pEnhTableEntry->HT;
66415fb4814Smrg    mode->CrtcHBlankStart = (int) (pVGAModeInfo->pEnhTableEntry->HDE + ulHBorder);
6657fe5393cSmrg    mode->CrtcHBlankEnd   = (int) (pVGAModeInfo->pEnhTableEntry->HT - ulHBorder);
66615fb4814Smrg    mode->CrtcHSyncStart  = (int) (pVGAModeInfo->pEnhTableEntry->HDE + ulHBorder
66715fb4814Smrg                                   + pVGAModeInfo->pEnhTableEntry->HFP);
66815fb4814Smrg    mode->CrtcHSyncEnd    = (int) (pVGAModeInfo->pEnhTableEntry->HDE + ulHBorder
66915fb4814Smrg                                   + pVGAModeInfo->pEnhTableEntry->HFP
67015fb4814Smrg                                   + pVGAModeInfo->pEnhTableEntry->HSYNC);
67115fb4814Smrg
67215fb4814Smrg    mode->CrtcVTotal      = (int) pVGAModeInfo->pEnhTableEntry->VT;
67315fb4814Smrg    mode->CrtcVBlankStart = (int) (pVGAModeInfo->pEnhTableEntry->VDE + ulVBorder);
6747fe5393cSmrg    mode->CrtcVBlankEnd   = (int) (pVGAModeInfo->pEnhTableEntry->VT - ulVBorder);
67515fb4814Smrg    mode->CrtcVSyncStart  = (int) (pVGAModeInfo->pEnhTableEntry->VDE + ulVBorder
67615fb4814Smrg                                   + pVGAModeInfo->pEnhTableEntry->VFP);
67715fb4814Smrg    mode->CrtcVSyncEnd    = (int) (pVGAModeInfo->pEnhTableEntry->VDE + ulVBorder
67815fb4814Smrg                                   + pVGAModeInfo->pEnhTableEntry->VFP
67915fb4814Smrg                                   + pVGAModeInfo->pEnhTableEntry->VSYNC);
6807fe5393cSmrg
68115fb4814Smrg    /* Write mode info to scratch */
68215fb4814Smrg    ulRefreshRateIndex = pVGAModeInfo->pEnhTableEntry->ulRefreshRateIndex;
68315fb4814Smrg    ulModeID = pVGAModeInfo->pEnhTableEntry->ulModeID;
68415fb4814Smrg
685b534f209Smrg    if (pAST->jChipType == AST1180)
686b534f209Smrg    {
6877fe5393cSmrg        /* TODO */
688b534f209Smrg    }
689b534f209Smrg    else
6907fe5393cSmrg    {
691b534f209Smrg        SetIndexReg(CRTC_PORT, 0x8C, (UCHAR) ((ulColorIndex & 0x0F) << 4));
692b534f209Smrg        SetIndexReg(CRTC_PORT, 0x8D, (UCHAR) (ulRefreshRateIndex & 0xFF));
693b534f209Smrg        SetIndexReg(CRTC_PORT, 0x8E, (UCHAR) (ulModeID & 0xFF));
6947fe5393cSmrg
695b534f209Smrg        /* NewModeInfo */
6967fe5393cSmrg        SetIndexReg(CRTC_PORT, 0x91, 0x00);	/* clear signature */
6977fe5393cSmrg        if (pVGAModeInfo->pEnhTableEntry->Flags & NewModeInfo)
6987fe5393cSmrg        {
6997fe5393cSmrg            SetIndexReg(CRTC_PORT, 0x91, 0xA8);	/* signature */
7007fe5393cSmrg            SetIndexReg(CRTC_PORT, 0x92, (UCHAR) (pScrn->bitsPerPixel) );
7017fe5393cSmrg            SetIndexReg(CRTC_PORT, 0x93, (UCHAR) (mode->Clock / 1000) );
7027fe5393cSmrg            SetIndexReg(CRTC_PORT, 0x94, (UCHAR) (mode->CrtcHDisplay) );
7037fe5393cSmrg            SetIndexReg(CRTC_PORT, 0x95, (UCHAR) (mode->CrtcHDisplay >> 8) );	/* color depth */
7047fe5393cSmrg            SetIndexReg(CRTC_PORT, 0x96, (UCHAR) (mode->CrtcVDisplay) );
7057fe5393cSmrg            SetIndexReg(CRTC_PORT, 0x97, (UCHAR) (mode->CrtcVDisplay >> 8) );	/* color depth */
7067fe5393cSmrg        }
7077fe5393cSmrg    }
7087fe5393cSmrg
70915fb4814Smrg    return (TRUE);
71015fb4814Smrg}
7117fe5393cSmrg
712cf503b78Smrgstatic void vSetStdReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo)
71315fb4814Smrg{
7147fe5393cSmrg
71515fb4814Smrg    PVBIOS_STDTABLE_STRUCT pStdModePtr;
7167fe5393cSmrg    ASTRecPtr pAST;
71715fb4814Smrg    ULONG i;
7187fe5393cSmrg    UCHAR jReg;
7197fe5393cSmrg
72015fb4814Smrg    pStdModePtr = pVGAModeInfo->pStdTableEntry;
7217fe5393cSmrg    pAST = ASTPTR(pScrn);
7227fe5393cSmrg
72315fb4814Smrg    /* Set Misc */
72415fb4814Smrg    jReg = pStdModePtr->MISC;
72515fb4814Smrg    SetReg(MISC_PORT_WRITE,jReg);
72615fb4814Smrg
72715fb4814Smrg    /* Set Seq */
72815fb4814Smrg    SetIndexReg(SEQ_PORT,0x00, 0x03);
72915fb4814Smrg    for (i=0; i<4; i++)
73015fb4814Smrg    {
73115fb4814Smrg        jReg = pStdModePtr->SEQ[i];
73215fb4814Smrg    	if (!i) (jReg |= 0x20);			/* display off */
7337fe5393cSmrg        SetIndexReg(SEQ_PORT,(UCHAR) (i+1), jReg);
73415fb4814Smrg    }
7357fe5393cSmrg
73615fb4814Smrg    /* Set CRTC */
73715fb4814Smrg    SetIndexRegMask(CRTC_PORT,0x11, 0x7F, 0x00);
73815fb4814Smrg    for (i=0; i<25; i++)
73915fb4814Smrg    {
74015fb4814Smrg        jReg = pStdModePtr->CRTC[i];
7417fe5393cSmrg        SetIndexReg(CRTC_PORT,(UCHAR) i, jReg);
74215fb4814Smrg    }
74315fb4814Smrg
74415fb4814Smrg    /* Set AR */
74515fb4814Smrg    jReg = GetReg(INPUT_STATUS1_READ);
74615fb4814Smrg    for (i=0; i<20; i++)
74715fb4814Smrg    {
74815fb4814Smrg        jReg = pStdModePtr->AR[i];
7497fe5393cSmrg        SetReg(AR_PORT_WRITE, (UCHAR) i);
7507fe5393cSmrg        SetReg(AR_PORT_WRITE, jReg);
7517fe5393cSmrg    }
7527fe5393cSmrg    SetReg(AR_PORT_WRITE, 0x14);
7537fe5393cSmrg    SetReg(AR_PORT_WRITE, 0x00);
7547fe5393cSmrg
75515fb4814Smrg    jReg = GetReg(INPUT_STATUS1_READ);
75615fb4814Smrg    SetReg (AR_PORT_WRITE, 0x20);		/* set POS */
7577fe5393cSmrg
75815fb4814Smrg    /* Set GR */
75915fb4814Smrg    for (i=0; i<9; i++)
76015fb4814Smrg    {
761de78e416Smrg        jReg = pStdModePtr->GR[i];
7627fe5393cSmrg        SetIndexReg(GR_PORT,(UCHAR) i, jReg);
7637fe5393cSmrg
7647fe5393cSmrg    }
7657fe5393cSmrg
766cf503b78Smrg
76715fb4814Smrg}
76815fb4814Smrg
769cf503b78Smrgstatic void
77015fb4814SmrgvSetCRTCReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo)
77115fb4814Smrg{
7727fe5393cSmrg    ASTRecPtr pAST;
77358e54220Smrg    USHORT usTemp, ulPreCache = 0;
77415fb4814Smrg    UCHAR jReg05, jReg07, jReg09, jRegAC, jRegAD, jRegAE;
77515fb4814Smrg
77615fb4814Smrg    pAST = ASTPTR(pScrn);
77715fb4814Smrg    jReg05 = jReg07 = jReg09 = jRegAC = jRegAD = jRegAE = 0;
7787fe5393cSmrg
77958e54220Smrg    /* init value */
78058e54220Smrg    if ((pAST->jChipType == AST2500) && (pVGAModeInfo->pEnhTableEntry->Flags & AST2500PreCatchCRT))
78158e54220Smrg    	ulPreCache = 40;
78258e54220Smrg
78315fb4814Smrg    /* unlock CRTC */
7847fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0x11, 0x7F, 0x00);
7857fe5393cSmrg
78615fb4814Smrg    /* Horizontal Timing Programming */
78715fb4814Smrg    usTemp = (mode->CrtcHTotal >> 3) - 5;
78815fb4814Smrg    if (usTemp & 0x100) jRegAC |= 0x01;			/* HT D[8] */
78915fb4814Smrg    SetIndexRegMask(CRTC_PORT,0x00, 0x00, (UCHAR) usTemp);
79015fb4814Smrg    usTemp = (mode->CrtcHDisplay >> 3) - 1;
79115fb4814Smrg    if (usTemp & 0x100) jRegAC |= 0x04;			/* HDE D[8] */
7927fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0x01, 0x00, (UCHAR) usTemp);
79315fb4814Smrg    usTemp = (mode->CrtcHBlankStart >> 3) - 1;
79415fb4814Smrg    if (usTemp & 0x100) jRegAC |= 0x10;			/* HBS D[8] */
7957fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0x02, 0x00, (UCHAR) usTemp);
79615fb4814Smrg    usTemp = ((mode->CrtcHBlankEnd >> 3) - 1) & 0x7F;
79715fb4814Smrg    if (usTemp & 0x20) jReg05 |= 0x80;			/* HBE D[5] */
7987fe5393cSmrg    if (usTemp & 0x40) jRegAD |= 0x01;			/* HBE D[6] */
79915fb4814Smrg    SetIndexRegMask(CRTC_PORT,0x03, 0xE0, (UCHAR) (usTemp & 0x1F));
80058e54220Smrg    usTemp = ((mode->CrtcHSyncStart - ulPreCache) >> 3 ) - 1;
8017fe5393cSmrg    if (usTemp & 0x100) jRegAC |= 0x40;			/* HRS D[5] */
8027fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0x04, 0x00, (UCHAR) (usTemp));
80358e54220Smrg    usTemp = (((mode->CrtcHSyncEnd - ulPreCache) >> 3 ) - 1) & 0x3F;
8047fe5393cSmrg    if (usTemp & 0x20) jRegAD |= 0x04;			/* HRE D[5] */
80515fb4814Smrg    SetIndexRegMask(CRTC_PORT,0x05, 0x60, (UCHAR) ((usTemp & 0x1F) | jReg05));
8067fe5393cSmrg
8077fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0xAC, 0x00, (UCHAR) jRegAC);
8087fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0xAD, 0x00, (UCHAR) jRegAD);
8097fe5393cSmrg
81015fb4814Smrg    /* Vetical Timing Programming */
81115fb4814Smrg    usTemp = (mode->CrtcVTotal) - 2;
81215fb4814Smrg    if (usTemp & 0x100) jReg07 |= 0x01;			/* VT D[8] */
8137fe5393cSmrg    if (usTemp & 0x200) jReg07 |= 0x20;
8147fe5393cSmrg    if (usTemp & 0x400) jRegAE |= 0x01;			/* VT D[10] */
8157fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0x06, 0x00, (UCHAR) usTemp);
81615fb4814Smrg    usTemp = (mode->CrtcVSyncStart) - 1;
81715fb4814Smrg    if (usTemp & 0x100) jReg07 |= 0x04;			/* VRS D[8] */
81815fb4814Smrg    if (usTemp & 0x200) jReg07 |= 0x80;			/* VRS D[9] */
8197fe5393cSmrg    if (usTemp & 0x400) jRegAE |= 0x08;			/* VRS D[10] */
8207fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0x10, 0x00, (UCHAR) usTemp);
82115fb4814Smrg    usTemp = ((mode->CrtcVSyncEnd) - 1) & 0x3F;
82215fb4814Smrg    if (usTemp & 0x10) jRegAE |= 0x20;			/* VRE D[4] */
82315fb4814Smrg    if (usTemp & 0x20) jRegAE |= 0x40;			/* VRE D[5] */
8247fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0x11, 0x70, (UCHAR) (usTemp & 0x0F));
82515fb4814Smrg    usTemp = (mode->CrtcVDisplay) - 1;
82615fb4814Smrg    if (usTemp & 0x100) jReg07 |= 0x02;			/* VDE D[8] */
82715fb4814Smrg    if (usTemp & 0x200) jReg07 |= 0x40;			/* VDE D[9] */
8287fe5393cSmrg    if (usTemp & 0x400) jRegAE |= 0x02;			/* VDE D[10] */
8297fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0x12, 0x00, (UCHAR) usTemp);
83015fb4814Smrg    usTemp = (mode->CrtcVBlankStart) - 1;
83115fb4814Smrg    if (usTemp & 0x100) jReg07 |= 0x08;			/* VBS D[8] */
83215fb4814Smrg    if (usTemp & 0x200) jReg09 |= 0x20;			/* VBS D[9] */
8337fe5393cSmrg    if (usTemp & 0x400) jRegAE |= 0x04;			/* VBS D[10] */
8347fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0x15, 0x00, (UCHAR) usTemp);
83515fb4814Smrg    usTemp = (mode->CrtcVBlankEnd) - 1 ;
83615fb4814Smrg    if (usTemp & 0x100) jRegAE |= 0x10;			/* VBE D[8] */
8377fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0x16, 0x00, (UCHAR) usTemp);
83815fb4814Smrg
8397fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0x07, 0x00, (UCHAR) jReg07);
8407fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0x09, 0xDF, (UCHAR) jReg09);
84115fb4814Smrg    SetIndexRegMask(CRTC_PORT,0xAE, 0x00, (UCHAR) (jRegAE | 0x80));	/* disable line compare */
8427fe5393cSmrg
84358e54220Smrg    if ((pAST->jChipType == AST2500) && (pVGAModeInfo->pEnhTableEntry->Flags & AST2500PreCatchCRT))
84458e54220Smrg    {
84558e54220Smrg    	SetIndexRegMask(CRTC_PORT,0xB6, 0x3F, 0x80);
84658e54220Smrg	}
84758e54220Smrg	else
84858e54220Smrg	{
84958e54220Smrg    	SetIndexRegMask(CRTC_PORT,0xB6, 0x3F, 0x00);
85058e54220Smrg	}
85158e54220Smrg
85215fb4814Smrg    /* lock CRTC */
8537fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0x11, 0x7F, 0x80);
8547fe5393cSmrg
85515fb4814Smrg}
85615fb4814Smrg
857cf503b78Smrgstatic void vSetOffsetReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo)
85815fb4814Smrg{
8597fe5393cSmrg    ASTRecPtr pAST;
8607fe5393cSmrg    USHORT usOffset;
86115fb4814Smrg
86215fb4814Smrg    pAST = ASTPTR(pScrn);
86315fb4814Smrg
86415fb4814Smrg    usOffset = 	pAST->VideoModeInfo.ScreenPitch >> 3;		/* Unit: char */
8657fe5393cSmrg
8667fe5393cSmrg    SetIndexReg(CRTC_PORT,0x13, (UCHAR) (usOffset & 0xFF));
8677fe5393cSmrg    SetIndexReg(CRTC_PORT,0xB0, (UCHAR) ((usOffset >> 8) & 0x3F));
8687fe5393cSmrg
86915fb4814Smrg}
87015fb4814Smrg
871cf503b78Smrgstatic void vSetDCLKReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo)
87215fb4814Smrg{
87315fb4814Smrg    PVBIOS_ENHTABLE_STRUCT pEnhModePtr;
87415fb4814Smrg    PVBIOS_DCLK_INFO pDCLKPtr;
8757fe5393cSmrg    ASTRecPtr pAST;
8767fe5393cSmrg
87715fb4814Smrg    pAST = ASTPTR(pScrn);
87815fb4814Smrg
87915fb4814Smrg    pEnhModePtr = pVGAModeInfo->pEnhTableEntry;
88058e54220Smrg    if ((pAST->jChipType == AST2500) && (PCI_DEV_REVISION(pAST->PciInfo) > 0x40))
88158e54220Smrg        pDCLKPtr = &DCLKTable_AST2500A1[pEnhModePtr->DCLKIndex];
88258e54220Smrg    else if ((pAST->jChipType == AST2500) && (PCI_DEV_REVISION(pAST->PciInfo) == 0x40))
88358e54220Smrg        pDCLKPtr = &DCLKTable_AST2500[pEnhModePtr->DCLKIndex];
88458e54220Smrg    else if ((pAST->jChipType == AST2100) || (pAST->jChipType == AST1100) || (pAST->jChipType == AST2200) || (pAST->jChipType == AST2150) || (pAST->jChipType == AST2300) || (pAST->jChipType == AST2400))
8857fe5393cSmrg        pDCLKPtr = &DCLKTable_AST2100[pEnhModePtr->DCLKIndex];
886b534f209Smrg    else
887b534f209Smrg        pDCLKPtr = &DCLKTable[pEnhModePtr->DCLKIndex];
88815fb4814Smrg
8897fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0xC0, 0x00,  pDCLKPtr->Param1);
8907fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0xC1, 0x00,  pDCLKPtr->Param2);
89158e54220Smrg    if ((pAST->jChipType == AST2500) && (PCI_DEV_REVISION(pAST->PciInfo) == 0x40))
89258e54220Smrg    {
89358e54220Smrg        SetIndexRegMask(CRTC_PORT,0xBB, 0x0F, (pDCLKPtr->Param3 & 0xF0));
89458e54220Smrg    }
89558e54220Smrg    else
89658e54220Smrg    {
89758e54220Smrg        SetIndexRegMask(CRTC_PORT,0xBB, 0x0F, (pDCLKPtr->Param3 & 0xC0) | ((pDCLKPtr->Param3 & 0x03) << 4) );
89858e54220Smrg    }
8997fe5393cSmrg
90015fb4814Smrg}
90115fb4814Smrg
90215fb4814Smrg
903cf503b78Smrgstatic void vSetExtReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo)
90415fb4814Smrg{
9057fe5393cSmrg
90615fb4814Smrg    ASTRecPtr pAST;
90715fb4814Smrg    UCHAR jRegA0, jRegA3, jRegA8;
9087fe5393cSmrg
90915fb4814Smrg    pAST = ASTPTR(pScrn);
91015fb4814Smrg
9117fe5393cSmrg    jRegA0=jRegA3=jRegA8=0;
9127fe5393cSmrg    /* Mode Type Setting */
91315fb4814Smrg    switch (pScrn->bitsPerPixel) {
91415fb4814Smrg    case 8:
91515fb4814Smrg        jRegA0 = 0x70;
91615fb4814Smrg        jRegA3 = 0x01;
9177fe5393cSmrg        jRegA8 = 0x00;
91815fb4814Smrg        break;
9197fe5393cSmrg    case 15:
92015fb4814Smrg    case 16:
9217fe5393cSmrg        jRegA0 = 0x70;
92215fb4814Smrg        jRegA3 = 0x04;
9237fe5393cSmrg        jRegA8 = 0x02;
9247fe5393cSmrg        break;
92515fb4814Smrg    case 32:
9267fe5393cSmrg        jRegA0 = 0x70;
92715fb4814Smrg        jRegA3 = 0x08;
9287fe5393cSmrg        jRegA8 = 0x02;
92915fb4814Smrg        break;
9307fe5393cSmrg    }
9317fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0xA0, 0x8F, (UCHAR) jRegA0);
9327fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0xA3, 0xF0, (UCHAR) jRegA3);
9337fe5393cSmrg    SetIndexRegMask(CRTC_PORT,0xA8, 0xFD, (UCHAR) jRegA8);
93415fb4814Smrg
935b4d38c65Smrg#if	defined(__sparc__)
936b4d38c65Smrg    UCHAR jRegA2 = 0x80;
937b4d38c65Smrg    if ((pScrn->bitsPerPixel == 15) || (pScrn->bitsPerPixel == 16) )
938b4d38c65Smrg        jRegA2 |= 0x40;
939b4d38c65Smrg    SetIndexRegMask(CRTC_PORT,0xA2, 0x3F, (UCHAR) jRegA2);
940b4d38c65Smrg#endif
9417fe5393cSmrg
94215fb4814Smrg    /* Set Threshold */
94358e54220Smrg    if ((pAST->jChipType == AST2300) || (pAST->jChipType == AST2400) || (pAST->jChipType == AST2500))
944b410ddbeSmrg    {
945b534f209Smrg        SetIndexReg(CRTC_PORT,0xA7, 0x78);
9467fe5393cSmrg        SetIndexReg(CRTC_PORT,0xA6, 0x60);
9477fe5393cSmrg    }
9487fe5393cSmrg    else if ((pAST->jChipType == AST2100) || (pAST->jChipType == AST1100) || (pAST->jChipType == AST2200) || (pAST->jChipType == AST2150) )
949de78e416Smrg    {
950de78e416Smrg        SetIndexReg(CRTC_PORT,0xA7, 0x3F);
9517fe5393cSmrg        SetIndexReg(CRTC_PORT,0xA6, 0x2F);
952de78e416Smrg    }
953de78e416Smrg    else
9547fe5393cSmrg    {
955de78e416Smrg        SetIndexReg(CRTC_PORT,0xA7, 0x2F);
956de78e416Smrg        SetIndexReg(CRTC_PORT,0xA6, 0x1F);
9577fe5393cSmrg    }
9587fe5393cSmrg
95915fb4814Smrg}
96015fb4814Smrg
961cf503b78Smrgstatic void vSetSyncReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo)
962de78e416Smrg{
963de78e416Smrg    PVBIOS_ENHTABLE_STRUCT pEnhModePtr;
964de78e416Smrg    ASTRecPtr pAST;
9657fe5393cSmrg    UCHAR jReg;
9667fe5393cSmrg
967de78e416Smrg    pAST = ASTPTR(pScrn);
968de78e416Smrg    pEnhModePtr = pVGAModeInfo->pEnhTableEntry;
969de78e416Smrg
970de78e416Smrg    jReg  = GetReg(MISC_PORT_READ);
97158e54220Smrg    jReg &= ~0xC0;
97258e54220Smrg	if (pEnhModePtr->Flags & NVSync) jReg |= 0x80;
97358e54220Smrg	if (pEnhModePtr->Flags & NHSync) jReg |= 0x40;
974de78e416Smrg    SetReg(MISC_PORT_WRITE,jReg);
975de78e416Smrg}
97615fb4814Smrg
977cf503b78Smrgstatic Bool bSetDACReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo)
97815fb4814Smrg{
97915fb4814Smrg    PVBIOS_DAC_INFO pDACPtr;
9807fe5393cSmrg    ASTRecPtr pAST;
98115fb4814Smrg    ULONG i, ulDACNumber;
98215fb4814Smrg    UCHAR DACR, DACG, DACB;
98315fb4814Smrg
9847fe5393cSmrg    pAST = ASTPTR(pScrn);
98515fb4814Smrg
98615fb4814Smrg    switch (pScrn->bitsPerPixel)
98715fb4814Smrg    {
98815fb4814Smrg    case 8:
98915fb4814Smrg         ulDACNumber = DAC_NUM_VGA;
99015fb4814Smrg         pDACPtr = (PVBIOS_DAC_INFO) &DAC_VGA[0];
99115fb4814Smrg         break;
99215fb4814Smrg    default:
99315fb4814Smrg         return (FALSE);
99415fb4814Smrg    }
99515fb4814Smrg
99615fb4814Smrg    for (i=0; i<ulDACNumber; i++)
99715fb4814Smrg    {
99815fb4814Smrg    	DACR = pDACPtr->DACR;
99915fb4814Smrg    	DACG = pDACPtr->DACG;
100015fb4814Smrg    	DACB = pDACPtr->DACB;
100115fb4814Smrg
100215fb4814Smrg        VGA_LOAD_PALETTE_INDEX (i, DACR, DACG, DACB);
10037fe5393cSmrg
100415fb4814Smrg        pDACPtr++;
100515fb4814Smrg    }
100615fb4814Smrg
100715fb4814Smrg    return (TRUE);
100815fb4814Smrg
100915fb4814Smrg}
101015fb4814Smrg
1011cf503b78Smrgstatic ULONG AST1180DCLKTable [] = {
10127fe5393cSmrg    0x0008676b,						/* 00: VCLK25_175	*/
1013b534f209Smrg    0x00086342,				        	/* 01: VCLK28_322	*/
1014b534f209Smrg    0x00086568,				        	/* 02: VCLK31_5         */
1015b534f209Smrg    0x00082118,				        	/* 03: VCLK36         	*/
10167fe5393cSmrg    0x0008232e,				        	/* 04: VCLK40          	*/
1017b534f209Smrg    0x000c256d, 		        		/* 05: VCLK49_5        	*/
1018b534f209Smrg    0x00082016,                        	        	/* 06: VCLK50          	*/
1019b534f209Smrg    0x000c0010,                        	        	/* 07: VCLK56_25       	*/
1020b534f209Smrg    0x000c0332,                        	        	/* 08: VCLK65		*/
1021b534f209Smrg    0x00080010,                        	        	/* 09: VCLK75	        */
1022b534f209Smrg    0x000c033d,				        	/* 0A: VCLK78_75       	*/
1023b534f209Smrg    0x000c0568,                        	        	/* 0B: VCLK94_5        	*/
1024b534f209Smrg    0x00040118,                        	        	/* 0C: VCLK108         	*/
1025b534f209Smrg    0x00040334,                        	        	/* 0D: VCLK135         	*/
1026b534f209Smrg    0x0004033d,                        	        	/* 0E: VCLK157_5       	*/
1027b534f209Smrg    0x00040018,				        	/* 0F: VCLK162         	*/
10287fe5393cSmrg    0x00040123,						/* 10: VCLK154          */
10297fe5393cSmrg    0x000c0669,						/* 11: VCLK83_5         */
10307fe5393cSmrg    0x0004074b,						/* 12: VCLK106_5        */
10317fe5393cSmrg    0x0004022d,						/* 13: VCLK146_25       */
10327fe5393cSmrg    0x00040769,						/* 14: VCLK148_5        */
1033b534f209Smrg};
1034b534f209Smrg
1035cf503b78Smrgstatic BOOL bSetAST1180CRTCReg(ScrnInfoPtr pScrn,  DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo)
1036b534f209Smrg{
10377fe5393cSmrg    ASTRecPtr pAST = ASTPTR(pScrn);
1038b534f209Smrg
10397fe5393cSmrg    ULONG HTIndex, HRIndex, VTIndex, VRIndex;
1040b534f209Smrg    ULONG HT, HDE, HBS, HBE, HRS, HRE;
10417fe5393cSmrg    ULONG VT, VDE, VBS, VBE, VRS, VRE;
1042b534f209Smrg    ULONG HT2, HDE2, HRS2, HRE2;
10437fe5393cSmrg    ULONG VT2, VDE2, VRS2, VRE2;
10447fe5393cSmrg
1045b534f209Smrg    /* Reg. Index Select */
1046b534f209Smrg    {
1047b534f209Smrg        HTIndex =  AST1180_VGA1_HTREG;
1048b534f209Smrg        HRIndex =  AST1180_VGA1_HRREG;
1049b534f209Smrg        VTIndex =  AST1180_VGA1_VTREG;
10507fe5393cSmrg        VRIndex =  AST1180_VGA1_VRREG;
10517fe5393cSmrg    }
10527fe5393cSmrg
1053b534f209Smrg    /* Get CRTC Info */
1054b534f209Smrg    HT = mode->CrtcHTotal;
1055b534f209Smrg    HDE= mode->CrtcHDisplay;
1056b534f209Smrg    HBS= mode->CrtcHBlankStart;
10577fe5393cSmrg    HBE= mode->CrtcHBlankEnd;
1058b534f209Smrg    HRS= mode->CrtcHSyncStart;
1059b534f209Smrg    HRE= mode->CrtcHSyncEnd;
1060b534f209Smrg    VT = mode->CrtcVTotal;
1061b534f209Smrg    VDE= mode->CrtcVDisplay;
1062b534f209Smrg    VBS= mode->CrtcVBlankStart;
10637fe5393cSmrg    VBE= mode->CrtcVBlankEnd;
1064b534f209Smrg    VRS= mode->CrtcVSyncStart;
10657fe5393cSmrg    VRE= mode->CrtcVSyncEnd;
10667fe5393cSmrg
1067b534f209Smrg    /* Calculate CRTC Reg Setting */
1068b534f209Smrg    HT2  = HT - 1;
1069b534f209Smrg    HDE2 = HDE - 1;
1070b534f209Smrg    HRS2 = HRS - 1;
1071b534f209Smrg    HRE2 = HRE - 1;
1072b534f209Smrg    VT2  = VT  - 1;
1073b534f209Smrg    VDE2 = VDE - 1;
10747fe5393cSmrg    VRS2 = VRS - 1;
1075b534f209Smrg    VRE2 = VRE - 1;
10767fe5393cSmrg
1077b534f209Smrg    /* Write Reg */
10787fe5393cSmrg    WriteAST1180SOC(AST1180_GFX_BASE + HTIndex, (ULONG)(HDE2 << 16) | (ULONG) (HT2));
10797fe5393cSmrg    WriteAST1180SOC(AST1180_GFX_BASE + HRIndex, (ULONG)(HRE2 << 16) | (ULONG) (HRS2));
10807fe5393cSmrg    WriteAST1180SOC(AST1180_GFX_BASE + VTIndex, (ULONG)(VDE2 << 16) | (ULONG) (VT2));
10817fe5393cSmrg    WriteAST1180SOC(AST1180_GFX_BASE + VRIndex, (ULONG)(VRE2 << 16) | (ULONG) (VRS2));
10827fe5393cSmrg
1083b534f209Smrg    return (TRUE);
10847fe5393cSmrg
1085b534f209Smrg} /* bSetAST1180CRTCReg */
1086b534f209Smrg
1087cf503b78Smrgstatic BOOL bSetAST1180OffsetReg(ScrnInfoPtr pScrn,  DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo)
1088b534f209Smrg{
10897fe5393cSmrg    ASTRecPtr pAST = ASTPTR(pScrn);
10907fe5393cSmrg    ULONG ulOffset, ulTermalCount;
10917fe5393cSmrg
1092b534f209Smrg    ulOffset      = pAST->VideoModeInfo.ScreenPitch;
1093b534f209Smrg    ulTermalCount = (pAST->VideoModeInfo.ScreenPitch + 7) >> 3;
1094b534f209Smrg
1095b534f209Smrg    /* Write Reg */
10967fe5393cSmrg    WriteAST1180SOC(AST1180_GFX_BASE + AST1180_VGA1_OFFSET, (ULONG) (ulTermalCount << 16) | (ULONG) (ulOffset));
10977fe5393cSmrg
1098b534f209Smrg    return (TRUE);
10997fe5393cSmrg
1100b534f209Smrg} /* bSetAST1180OffsetReg */
1101b534f209Smrg
1102cf503b78Smrgstatic BOOL bSetAST1180DCLKReg(ScrnInfoPtr pScrn,  DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo)
1103b534f209Smrg{
1104b534f209Smrg    PVBIOS_ENHTABLE_STRUCT pEnhModePtr;
11057fe5393cSmrg    ASTRecPtr pAST = ASTPTR(pScrn);
1106b534f209Smrg    ULONG ulDCLK;
11077fe5393cSmrg
1108b534f209Smrg    pEnhModePtr = pVGAModeInfo->pEnhTableEntry;
1109b534f209Smrg    ulDCLK = AST1180DCLKTable[pEnhModePtr->DCLKIndex];
1110b534f209Smrg    if (pEnhModePtr->Flags & HalfDCLK)
1111b534f209Smrg        ulDCLK |= 0x00400000;		/* D[22]: div by 2 */
11127fe5393cSmrg    WriteAST1180SOC(AST1180_GFX_BASE + AST1180_VGA1_PLL, ulDCLK);
1113b534f209Smrg
1114b534f209Smrg    return (TRUE);
1115b534f209Smrg}
1116b534f209Smrg
1117cf503b78Smrgstatic BOOL bSetAST1180ExtReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo)
1118b534f209Smrg{
1119b534f209Smrg    PVBIOS_ENHTABLE_STRUCT pEnhModePtr;
11207fe5393cSmrg    ASTRecPtr pAST = ASTPTR(pScrn);
11217fe5393cSmrg
1122b534f209Smrg    ULONG ulCtlRegIndex, ulCtlReg;			/* enable display */
11237fe5393cSmrg    ULONG ulCtlReg2Index, ulCtlReg2 = 0x80;		/* single edge */
1124b534f209Smrg    ULONG ulThresholdRegIndex ;				/* Threshold */
1125b534f209Smrg    ULONG ulStartAddressIndex;				/* ulStartAddress */
1126b534f209Smrg    ULONG ulStartAddress = pAST->ulVRAMBase;
11277fe5393cSmrg
1128b534f209Smrg    /* Reg. Index Select */
1129b534f209Smrg    {
1130b534f209Smrg        ulCtlRegIndex       = AST1180_VGA1_CTRL;
11317fe5393cSmrg        ulCtlReg2Index      = AST1180_VGA1_CTRL2;
1132b534f209Smrg        ulThresholdRegIndex = AST1180_VGA1_THRESHOLD;
11337fe5393cSmrg        ulStartAddressIndex = AST1180_VGA1_STARTADDR;
1134b534f209Smrg    }
1135b534f209Smrg
1136b534f209Smrg    /* Mode Type Setting */
1137b534f209Smrg    ulCtlReg = 0x30000000;
11387fe5393cSmrg    {
1139b534f209Smrg        switch (pScrn->bitsPerPixel) {
11407fe5393cSmrg        case 15:
1141b534f209Smrg        case 16:
11427fe5393cSmrg            ulCtlReg |= 0x100001;            	/* RGB565, SCREEN OFF, ENABLE */
11437fe5393cSmrg            break;
1144b534f209Smrg        case 32:
11457fe5393cSmrg            ulCtlReg |= 0x100101;            	/* XRGB8888, SCREEN OFF, ENABLE */
1146b534f209Smrg            break;
11477fe5393cSmrg        }
11487fe5393cSmrg    }
1149b534f209Smrg
1150b534f209Smrg    /* Polarity */
1151b534f209Smrg    pEnhModePtr = pVGAModeInfo->pEnhTableEntry;
1152b534f209Smrg    ulCtlReg   |= (ULONG) (pEnhModePtr->Flags & SyncNN) << 10;
11537fe5393cSmrg
1154b534f209Smrg    /* Single/Dual Edge */
1155b534f209Smrg    ulCtlReg2 |= 0x40;				/* dual-edge */
11567fe5393cSmrg
1157b534f209Smrg    /* Write Reg */
11587fe5393cSmrg    WriteAST1180SOC(AST1180_GFX_BASE + ulStartAddressIndex, ulStartAddress);
11597fe5393cSmrg    WriteAST1180SOC(AST1180_GFX_BASE + ulThresholdRegIndex, ((ULONG) CRT_HIGH_THRESHOLD_VALUE << 8) | (ULONG) (CRT_LOW_THRESHOLD_VALUE));
11607fe5393cSmrg    WriteAST1180SOC(AST1180_GFX_BASE + ulCtlReg2Index, ulCtlReg2);
11617fe5393cSmrg    WriteAST1180SOC(AST1180_GFX_BASE + ulCtlRegIndex, ulCtlReg);
11627fe5393cSmrg
1163b534f209Smrg    return (TRUE);
11647fe5393cSmrg
1165b534f209Smrg} /* bSetAST1180ExtReg */
1166b534f209Smrg
1167b534f209Smrg#define I2C_BASE_AST1180	0x80fcb000
1168b534f209Smrg#define I2C_DEVICEADDR_AST1180	0x0EC			/* slave addr */
1169b534f209Smrg
1170cf503b78Smrgstatic void SetChrontelReg(ASTRecPtr pAST, UCHAR jChannel, UCHAR jIndex, UCHAR jData )
1171b534f209Smrg{
11727fe5393cSmrg    ULONG ulData, ulI2CAddr, ulI2CPortBase;
1173b534f209Smrg    ULONG retry;
11747fe5393cSmrg
1175b534f209Smrg    {
11767fe5393cSmrg        ulI2CPortBase = I2C_BASE_AST1180 + 0x40 * jChannel;
11777fe5393cSmrg        ulI2CAddr = I2C_DEVICEADDR_AST1180;
11787fe5393cSmrg    }
1179b534f209Smrg
1180b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x00, 0x00);
1181b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x04, 0x77743355);
1182b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x08, 0x0);
1183b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x10, 0xffffffff);
1184b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x00, 0x1);
1185b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x0C, 0xAF);
1186b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x20, ulI2CAddr);
1187b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x14, 0x03);
1188b534f209Smrg    retry = 0;
1189b534f209Smrg    do {
1190b534f209Smrg        ReadAST1180SOC(ulI2CPortBase + 0x10, ulData);
1191b534f209Smrg        usleep(10);
1192b534f209Smrg        if (retry++ > 1000)
1193b534f209Smrg            goto Exit_SetChrontelReg;
1194b534f209Smrg    } while (!(ulData & 0x01));
1195b534f209Smrg
1196b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x10, 0xffffffff);
1197b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x20, (ULONG) jIndex);
1198b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x14, 0x02);
1199b534f209Smrg    do {
1200b534f209Smrg        ReadAST1180SOC(ulI2CPortBase + 0x10, ulData);
1201b534f209Smrg     } while (!(ulData & 0x01));
1202b534f209Smrg
1203b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x10, 0xffffffff);
1204b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x20, (ULONG) jData);
1205b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x14, 0x02);
1206b534f209Smrg    do {
1207b534f209Smrg        ReadAST1180SOC(ulI2CPortBase + 0x10, ulData);
1208b534f209Smrg     } while (!(ulData & 0x01));
1209b534f209Smrg
1210b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x10, 0xffffffff);
1211b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x0C, 0xBF);
1212b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x14, 0x20);
1213b534f209Smrg    do {
1214b534f209Smrg        ReadAST1180SOC(ulI2CPortBase + 0x10, ulData);
1215b534f209Smrg    } while (!(ulData & 0x10));
1216b534f209Smrg
1217b534f209Smrg    ReadAST1180SOC(ulI2CPortBase + 0x0C, ulData);
1218b534f209Smrg    ulData &= 0xffffffef;
1219b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x0C, ulData);
1220b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x10, 0xffffffff);
1221b534f209Smrg
1222b534f209SmrgExit_SetChrontelReg:
1223b534f209Smrg    ;
1224b534f209Smrg}
1225b534f209Smrg
1226cf503b78Smrgstatic UCHAR GetChrontelReg(ASTRecPtr pAST, UCHAR jChannel, UCHAR jIndex)
1227b534f209Smrg{
12287fe5393cSmrg    ULONG ulData, ulI2CAddr, ulI2CPortBase;
1229b534f209Smrg    UCHAR jData;
1230b534f209Smrg    ULONG retry;
12317fe5393cSmrg
1232b534f209Smrg    {
12337fe5393cSmrg        ulI2CPortBase = I2C_BASE_AST1180 + 0x40 * jChannel;
12347fe5393cSmrg        ulI2CAddr = I2C_DEVICEADDR_AST1180;
12357fe5393cSmrg    }
1236b534f209Smrg
1237b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x00, 0x00);
1238b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x04, 0x77743355);
1239b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x08, 0x0);
1240b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x10, 0xffffffff);
1241b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x00, 0x1);
1242b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x0C, 0xAF);
1243b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x20, ulI2CAddr);
1244b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x14, 0x03);
1245b534f209Smrg    retry = 0;
1246b534f209Smrg    do {
1247b534f209Smrg        ReadAST1180SOC(ulI2CPortBase + 0x10, ulData);
1248b534f209Smrg        usleep(10);
1249b534f209Smrg        if (retry++ > 1000)
1250b534f209Smrg            return 0;
1251b534f209Smrg    } while (!(ulData & 0x01));
1252b534f209Smrg
1253b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x10, 0xffffffff);
1254b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x20, (ULONG) jIndex);
1255b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x14, 0x02);
1256b534f209Smrg    do {
1257b534f209Smrg        ReadAST1180SOC(ulI2CPortBase + 0x10, ulData);
1258b534f209Smrg     } while (!(ulData & 0x01));
1259b534f209Smrg
1260b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x10, 0xffffffff);
1261b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x20, (ULONG) (ulI2CAddr + 1) );
1262b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x14, 0x1B);
1263b534f209Smrg    do {
1264b534f209Smrg        ReadAST1180SOC(ulI2CPortBase + 0x10, ulData);
1265b534f209Smrg     } while (!(ulData & 0x04));
1266b534f209Smrg
1267b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x10, 0xffffffff);
1268b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x0C, 0xBF);
1269b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x14, 0x20);
1270b534f209Smrg    do {
1271b534f209Smrg        ReadAST1180SOC(ulI2CPortBase + 0x10, ulData);
1272b534f209Smrg    } while (!(ulData & 0x10));
1273b534f209Smrg
1274b534f209Smrg    ReadAST1180SOC(ulI2CPortBase + 0x0C, ulData);
1275b534f209Smrg    ulData &= 0xffffffef;
1276b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x0C, ulData);
1277b534f209Smrg    WriteAST1180SOC(ulI2CPortBase + 0x10, 0xffffffff);
12787fe5393cSmrg
1279b534f209Smrg    ReadAST1180SOC(ulI2CPortBase + 0x20, ulData);
1280b534f209Smrg    jData = (UCHAR) ((ulData & 0xFF00) >> 8);
12817fe5393cSmrg
12827fe5393cSmrg    return (jData);
1283b534f209Smrg}
1284b534f209Smrg
1285cf503b78Smrgstatic void vInitChrontelReg(ScrnInfoPtr pScrn, DisplayModePtr mode, PVBIOS_MODE_INFO pVGAModeInfo)
1286b534f209Smrg{
1287b534f209Smrg
12887fe5393cSmrg    PVBIOS_ENHTABLE_STRUCT pEnhModePtr = pVGAModeInfo->pEnhTableEntry;
12897fe5393cSmrg    ASTRecPtr pAST = ASTPTR(pScrn);
1290b534f209Smrg    ULONG ulDCLK = 65;					/* todo */
1291b534f209Smrg    UCHAR jReg;
12927fe5393cSmrg
1293b534f209Smrg    jReg = GetChrontelReg(pAST, 1, 0x4A);		/* get vendor id */
12947fe5393cSmrg    if (jReg == 0x95)
12957fe5393cSmrg    {
12967fe5393cSmrg        jReg = GetChrontelReg(pAST, 1, 0x20);		/* DVI/D-Sub */
1297b534f209Smrg        if (jReg & 0x20)			        /* DVI */
1298b534f209Smrg        {
12997fe5393cSmrg
1300b534f209Smrg            /* DVI PLL Filter */
1301b534f209Smrg            if (ulDCLK > 65)
1302b534f209Smrg            {
1303b534f209Smrg                SetChrontelReg(pAST, 1, 0x33, 0x06);
1304b534f209Smrg                SetChrontelReg(pAST, 1, 0x34, 0x26);
1305b534f209Smrg                SetChrontelReg(pAST, 1, 0x36, 0xA0);
1306b534f209Smrg            }
1307b534f209Smrg            else
1308b534f209Smrg        	{
1309b534f209Smrg                SetChrontelReg(pAST, 1, 0x33, 0x08);
1310b534f209Smrg                SetChrontelReg(pAST, 1, 0x34, 0x16);
1311b534f209Smrg                SetChrontelReg(pAST, 1, 0x36, 0x60);
1312b534f209Smrg            }
13137fe5393cSmrg
13147fe5393cSmrg            SetChrontelReg(pAST, 1, 0x49, 0xc0);
1315b534f209Smrg        }
1316b534f209Smrg        else						/* D-Sub */
1317b534f209Smrg        {
13187fe5393cSmrg
1319b534f209Smrg            SetChrontelReg(pAST, 1, 0x21, 0x09);
1320b534f209Smrg            SetChrontelReg(pAST, 1, 0x49, 0x00);
13217fe5393cSmrg            SetChrontelReg(pAST, 1, 0x56, 0x00);
13227fe5393cSmrg        }
13237fe5393cSmrg    }
13247fe5393cSmrg
1325b534f209Smrg}
132615fb4814Smrg
1327