1 
2 #ifndef TIMING_H
3 #define TIMING_H
4 
5 /*
6  * Generic mode timing module.
7  */
8 
9 /* This is the type of a basic (monitor-oriented) mode timing. */
10 typedef struct _MMT_S MonitorModeTiming;
11 struct _MMT_S {
12     int pixelClock;		/* Pixel clock in kHz. */
13     int HDisplay;		/* Horizontal Timing. */
14     int HSyncStart;
15     int HSyncEnd;
16     int HTotal;
17     int VDisplay;		/* Vertical Timing. */
18     int VSyncStart;
19     int VSyncEnd;
20     int VTotal;
21     int flags;
22     MonitorModeTiming *next;
23 };
24 
25 /* This is for the hardware (card)-adjusted mode timing. */
26 typedef struct {
27     int pixelClock;		/* Pixel clock in kHz. */
28     int HDisplay;		/* Horizontal Timing. */
29     int HSyncStart;
30     int HSyncEnd;
31     int HTotal;
32     int VDisplay;		/* Vertical Timing. */
33     int VSyncStart;
34     int VSyncEnd;
35     int VTotal;
36     int flags;
37 /* The following field are optionally filled in according to card */
38 /* specific parameters. */
39     int programmedClock;	/* Actual clock to be programmed. */
40     int selectedClockNo;	/* Index number of fixed clock used. */
41     int CrtcHDisplay;		/* Actual programmed horizontal CRTC timing. */
42     int CrtcHSyncStart;
43     int CrtcHSyncEnd;
44     int CrtcHTotal;
45     int CrtcVDisplay;		/* Actual programmed vertical CRTC timing. */
46     int CrtcVSyncStart;
47     int CrtcVSyncEnd;
48     int CrtcVTotal;
49 } ModeTiming;
50 
51 /* Flags in ModeTiming. */
52 #define PHSYNC		0x1	/* Positive hsync polarity. */
53 #define NHSYNC		0x2	/* Negative hsync polarity. */
54 #define PVSYNC		0x4	/* Positive vsync polarity. */
55 #define NVSYNC		0x8	/* Negative vsync polarity. */
56 #define INTERLACED	0x10	/* Mode has interlaced timing. */
57 #define DOUBLESCAN	0x20	/* Mode uses VGA doublescan (see note). */
58 #define HADJUSTED	0x40	/* Horizontal CRTC timing adjusted. */
59 #define VADJUSTED	0x80	/* Vertical CRTC timing adjusted. */
60 #define USEPROGRCLOCK	0x100	/* A programmable clock is used. */
61 
62 /*
63  * Note: Double scan implies that each scanline is displayed twice. The
64  * vertical CRTC timings are programmed to double the effective vertical
65  * resolution (the CRT still displays 400 scanlines for a 200 line
66  * resolution).
67  */
68 
69 /* Cards specifications. */
70 typedef struct {
71     int videoMemory;		/* Video memory in kilobytes. */
72     int maxPixelClock4bpp;	/* Maximum pixel clocks in kHz for each depth. */
73     int maxPixelClock8bpp;
74     int maxPixelClock16bpp;
75     int maxPixelClock24bpp;
76     int maxPixelClock32bpp;
77     int flags;			/* Flags (e.g. programmable clocks). */
78     int nClocks;		/* Number of fixed clocks. */
79     int *clocks;		/* Pointer to array of fixed clock values. */
80     int maxHorizontalCrtc;
81     /*
82      * The following function maps from a pixel clock and depth to
83      * the raw clock frequency required.
84      */
85     int (*mapClock) (int bpp, int pixelclock);
86     /*
87      * The following function maps from a requested clock value
88      * to the closest clock that the programmable clock device
89      * can produce.
90      */
91     int (*matchProgrammableClock) (int desiredclock);
92     /*
93      * The following function maps from a pixel clock, depth and
94      * horizontal CRTC timing parameter to the horizontal timing
95      * that has to be programmed.
96      */
97     int (*mapHorizontalCrtc) (int bpp, int pixelclock, int htiming);
98 } CardSpecs;
99 
100 /* Card flags. */
101 /* The card has programmable clocks (matchProgrammableClock is valid). */
102 #define CLOCK_PROGRAMMABLE		0x1
103 /* For interlaced modes, the vertical timing must be divided by two. */
104 #define INTERLACE_DIVIDE_VERT		0x2
105 /* For modes with vertical timing greater or equal to 1024, vertical */
106 /* timing must be divided by two. */
107 #define GREATER_1024_DIVIDE_VERT	0x4
108 /* The DAC doesn't support 64K colors (5-6-5) at 16bpp, just 5-5-5. */
109 #define NO_RGB16_565			0x8
110 
111 /* Mode info. */
112 typedef struct {
113 /* Basic properties. */
114     short width;		/* Width of the screen in pixels. */
115     short height;		/* Height of the screen in pixels. */
116     char bytesPerPixel;		/* Number of bytes per pixel. */
117     char bitsPerPixel;		/* Number of bits per pixel. */
118     char colorBits;		/* Number of significant bits in pixel. */
119     char __padding1;
120 /* Truecolor pixel specification. */
121     char redWeight;		/* Number of significant red bits. */
122     char greenWeight;		/* Number of significant green bits. */
123     char blueWeight;		/* Number of significant blue bits. */
124     char __padding2;
125     char redOffset;		/* Offset in bits of red value into pixel. */
126     char blueOffset;		/* Offset of green value. */
127     char greenOffset;		/* Offset of blue value. */
128     char __padding3;
129     unsigned redMask;		/* Pixel mask of read value. */
130     unsigned blueMask;		/* Pixel mask of green value. */
131     unsigned greenMask;		/* Pixel mask of blue value. */
132 /* Structural properties of the mode. */
133     int lineWidth;		/* Offset in bytes between scanlines. */
134     short realWidth;		/* Real on-screen resolution. */
135     short realHeight;		/* Real on-screen resolution. */
136     int flags;
137 } ModeInfo;
138 
139 
140 /* Prototypes of functions defined in timing.c. */
141 
142 /*
143  * This function will look up mode timings for a mode matching ModeInfo
144  * that is within monitor spec and matches the capabilities (clocks etc.)
145  * of the card.
146  */
147 
148 int __svgalib_getmodetiming(
149 		     ModeTiming *,	/* Resulting mode timing. */
150 		     ModeInfo *,	/* Structural mode info. */
151 		     CardSpecs *	/* Card specs (dot clocks etc.). */
152 );
153 
154 void __svgalib_addusertiming(
155 		      MonitorModeTiming *
156 );
157 
158 /* GTF constants */
159 #define GTF_lockVF	1		/* Lock to vertical frequency	*/
160 #define GTF_lockHF	2		/* Lock to horizontal frequency	*/
161 #define GTF_lockPF	3		/* Lock to pixel clock frequency*/
162 
163 #endif
164