2 Haiku S3 Trio64 driver adapted from the X.org S3 driver.
4 Copyright 2001 Ani Joshi <ajoshi@unixbox.com>
6 Copyright 2008 Haiku, Inc. All rights reserved.
7 Distributed under the terms of the MIT license.
20 WaitQueue(uint32 slots
)
22 // Wait until the requested number of queue slots are available.
24 while (ReadReg16(GP_STAT
) & (0x0100 >> slots
)) {}
31 // Wait until Graphics Processor is idle.
33 while (ReadReg16(GP_STAT
) & GP_BUSY
);
39 Trio64_GetColorSpaceParams(int colorSpace
, uint32
& bitsPerPixel
, uint32
& maxPixelClock
)
41 // Get parameters for a color space which is supported by the Trio64 chips.
42 // Argument maxPixelClock is in KHz.
43 // Return true if the color space is supported; else return false.
48 maxPixelClock
= 110000;
52 maxPixelClock
= 180000;
55 TRACE("Unsupported color space: 0x%X\n", colorSpace
);
64 Trio64_IsModeUsable(const display_mode
* mode
)
66 // Test if the display mode is usable by the current video chip.
67 // Return true if the mode is usable.
69 SharedInfo
& si
= *gInfo
.sharedInfo
;
71 if (si
.chipType
== S3_TRIO64
&& mode
->timing
.h_display
>= 1600)
74 return IsModeUsable(mode
);
81 TRACE("Trio64_Init()\n");
83 SharedInfo
& si
= *gInfo
.sharedInfo
;
85 // Use PIO to enable VGA, enable color instead of monochrome, and
88 WritePIO_8(VGA_ENABLE
, ReadPIO_8(VGA_ENABLE
) | 0x01);
89 WritePIO_8(MISC_OUT_W
, ReadPIO_8(MISC_OUT_R
) | 0x01); // enable color
91 WritePIO_8(CRTC_INDEX
, 0x53);
92 WritePIO_8(CRTC_DATA
, ReadPIO_8(CRTC_DATA
) | 0x8); // enable MMIO
94 WriteCrtcReg(0x38, 0x48); // unlock sys regs
95 WriteCrtcReg(0x39, 0xa5); // unlock sys regs
97 WriteCrtcReg(0x40, 0x01, 0x01);
98 WriteCrtcReg(0x35, 0x00, 0x30);
99 WriteCrtcReg(0x33, 0x20, 0x72);
101 if (si
.chipType
== S3_TRIO64_V2
) {
102 WriteCrtcReg(0x86, 0x80);
103 WriteCrtcReg(0x90, 0x00);
106 // Detect number of megabytes of installed ram.
108 static const uint8 ramSizes
[] = { 4, 0, 3, 8, 2, 6, 1, 0 };
109 int ramSizeMB
= ramSizes
[(ReadCrtcReg(0x36) >> 5) & 0x7];
111 TRACE("memory size: %d MB\n", ramSizeMB
);
116 si
.videoMemSize
= ramSizeMB
* 1024 * 1024;
117 si
.cursorOffset
= si
.videoMemSize
- CURSOR_BYTES
; // put cursor at end of video memory
118 si
.frameBufferOffset
= 0;
119 si
.maxFrameBufferSize
= si
.videoMemSize
- CURSOR_BYTES
;
121 // Detect current mclk.
123 WriteSeqReg(0x08, 0x06); // unlock extended sequencer regs
125 uint8 m
= ReadSeqReg(0x11) & 0x7f;
126 uint8 n
= ReadSeqReg(0x10);
128 uint8 n2
= (n
>> 5) & 0x03;
129 si
.mclk
= ((1431818 * (m
+ 2)) / (n1
+ 2) / (1 << n2
) + 50) / 100;
131 TRACE("MCLK value: %1.3f MHz\n", si
.mclk
/ 1000.0);
133 // Set up the array of color spaces supported by the Trio64 chips.
135 si
.colorSpaces
[0] = B_CMAP8
;
136 si
.colorSpaces
[1] = B_RGB16
;
137 si
.colorSpaceCount
= 2;
139 si
.bDisableHdwCursor
= false; // allow use of hardware cursor
140 si
.bDisableAccelDraw
= false; // allow use of accelerated drawing functions
142 // Setup the mode list.
144 return CreateModeList(Trio64_IsModeUsable
, NULL
);
149 Trio64_SetFunctionPointers(void)
151 // Setting the function pointers must be done prior to first ModeInit call
152 // or any accel activity.
154 gInfo
.WaitQueue
= WaitQueue
;
155 gInfo
.WaitIdleEmpty
= WaitIdle
;
157 gInfo
.DPMSCapabilities
= Trio64_DPMSCapabilities
;
158 gInfo
.GetDPMSMode
= Trio64_GetDPMSMode
;
159 gInfo
.SetDPMSMode
= Trio64_SetDPMSMode
;
161 gInfo
.LoadCursorImage
= Trio64_LoadCursorImage
;
162 gInfo
.SetCursorPosition
= Trio64_SetCursorPosition
;
163 gInfo
.ShowCursor
= Trio64_ShowCursor
;
165 // Note that the 2D accel functions set below do not work with all display
166 // modes; thus, when a mode is set, the function setting the mode will
167 // adjust the pointers according to the mode that is set.
169 gInfo
.FillRectangle
= Trio64_FillRectangle
;
170 gInfo
.FillSpan
= Trio64_FillSpan
;
171 gInfo
.InvertRectangle
= Trio64_InvertRectangle
;
172 gInfo
.ScreenToScreenBlit
= Trio64_ScreenToScreenBlit
;
174 gInfo
.AdjustFrame
= Trio64_AdjustFrame
;
175 gInfo
.ChipInit
= Trio64_Init
;
176 gInfo
.GetColorSpaceParams
= Trio64_GetColorSpaceParams
;
177 gInfo
.SetDisplayMode
= Trio64_SetDisplayMode
;
178 gInfo
.SetIndexedColors
= Trio64_SetIndexedColors
;