2 * Copyright 1996-1997 David J. McKay
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * DAVID J. MCKAY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 /* Hacked together from mga driver and 3.3.4 NVIDIA driver by Jarno Paananen
26 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/riva_setup.c $ */
28 #include "riva_include.h"
31 * Override VGA I/O routines.
33 static void RivaWriteCrtc(vgaHWPtr pVga, CARD8 index, CARD8 value)
35 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
36 VGA_WR08(pRiva->riva.PCIO, pVga->IOBase + VGA_CRTC_INDEX_OFFSET, index);
37 VGA_WR08(pRiva->riva.PCIO, pVga->IOBase + VGA_CRTC_DATA_OFFSET, value);
39 static CARD8 RivaReadCrtc(vgaHWPtr pVga, CARD8 index)
41 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
42 VGA_WR08(pRiva->riva.PCIO, pVga->IOBase + VGA_CRTC_INDEX_OFFSET, index);
43 return (VGA_RD08(pRiva->riva.PCIO, pVga->IOBase + VGA_CRTC_DATA_OFFSET));
45 static void RivaWriteGr(vgaHWPtr pVga, CARD8 index, CARD8 value)
47 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
48 VGA_WR08(pRiva->riva.PVIO, VGA_GRAPH_INDEX, index);
49 VGA_WR08(pRiva->riva.PVIO, VGA_GRAPH_DATA, value);
51 static CARD8 RivaReadGr(vgaHWPtr pVga, CARD8 index)
53 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
54 VGA_WR08(pRiva->riva.PVIO, VGA_GRAPH_INDEX, index);
55 return (VGA_RD08(pRiva->riva.PVIO, VGA_GRAPH_DATA));
57 static void RivaWriteSeq(vgaHWPtr pVga, CARD8 index, CARD8 value)
59 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
60 VGA_WR08(pRiva->riva.PVIO, VGA_SEQ_INDEX, index);
61 VGA_WR08(pRiva->riva.PVIO, VGA_SEQ_DATA, value);
63 static CARD8 RivaReadSeq(vgaHWPtr pVga, CARD8 index)
65 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
66 VGA_WR08(pRiva->riva.PVIO, VGA_SEQ_INDEX, index);
67 return (VGA_RD08(pRiva->riva.PVIO, VGA_SEQ_DATA));
69 static void RivaWriteAttr(vgaHWPtr pVga, CARD8 index, CARD8 value)
71 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
74 tmp = VGA_RD08(pRiva->riva.PCIO, pVga->IOBase + VGA_IN_STAT_1_OFFSET);
75 if (pVga->paletteEnabled)
79 VGA_WR08(pRiva->riva.PCIO, VGA_ATTR_INDEX, index);
80 VGA_WR08(pRiva->riva.PCIO, VGA_ATTR_DATA_W, value);
82 static CARD8 RivaReadAttr(vgaHWPtr pVga, CARD8 index)
84 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
87 tmp = VGA_RD08(pRiva->riva.PCIO, pVga->IOBase + VGA_IN_STAT_1_OFFSET);
88 if (pVga->paletteEnabled)
92 VGA_WR08(pRiva->riva.PCIO, VGA_ATTR_INDEX, index);
93 return (VGA_RD08(pRiva->riva.PCIO, VGA_ATTR_DATA_R));
95 static void RivaWriteMiscOut(vgaHWPtr pVga, CARD8 value)
97 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
98 VGA_WR08(pRiva->riva.PVIO, VGA_MISC_OUT_W, value);
100 static CARD8 RivaReadMiscOut(vgaHWPtr pVga)
102 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
103 return (VGA_RD08(pRiva->riva.PVIO, VGA_MISC_OUT_R));
105 static void RivaEnablePalette(vgaHWPtr pVga)
107 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
110 tmp = VGA_RD08(pRiva->riva.PCIO, pVga->IOBase + VGA_IN_STAT_1_OFFSET);
111 VGA_WR08(pRiva->riva.PCIO, VGA_ATTR_INDEX, 0x00);
112 pVga->paletteEnabled = TRUE;
114 static void RivaDisablePalette(vgaHWPtr pVga)
116 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
119 tmp = VGA_RD08(pRiva->riva.PCIO, pVga->IOBase + VGA_IN_STAT_1_OFFSET);
120 VGA_WR08(pRiva->riva.PCIO, VGA_ATTR_INDEX, 0x20);
121 pVga->paletteEnabled = FALSE;
123 static void RivaWriteDacMask(vgaHWPtr pVga, CARD8 value)
125 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
126 VGA_WR08(pRiva->riva.PDIO, VGA_DAC_MASK, value);
128 static CARD8 RivaReadDacMask(vgaHWPtr pVga)
130 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
131 return (VGA_RD08(pRiva->riva.PDIO, VGA_DAC_MASK));
133 static void RivaWriteDacReadAddr(vgaHWPtr pVga, CARD8 value)
135 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
136 VGA_WR08(pRiva->riva.PDIO, VGA_DAC_READ_ADDR, value);
138 static void RivaWriteDacWriteAddr(vgaHWPtr pVga, CARD8 value)
140 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
141 VGA_WR08(pRiva->riva.PDIO, VGA_DAC_WRITE_ADDR, value);
143 static void RivaWriteDacData(vgaHWPtr pVga, CARD8 value)
145 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
146 VGA_WR08(pRiva->riva.PDIO, VGA_DAC_DATA, value);
148 static CARD8 RivaReadDacData(vgaHWPtr pVga)
150 RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
151 return (VGA_RD08(pRiva->riva.PDIO, VGA_DAC_DATA));
157 RivaProbeDDC (ScrnInfoPtr pScrn)
159 RivaPtr pRiva = RivaPTR(pScrn);
160 xf86MonPtr MonInfo = NULL;
162 if(!pRiva->I2C) return NULL;
164 pRiva->DDCBase = 0x3e;
166 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Probing for EDID...\n");
168 if ((MonInfo = xf86DoEDID_DDC2(pScrn->scrnIndex, pRiva->I2C))) {
169 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
171 xf86PrintEDID( MonInfo );
173 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
174 " ... none found\n");
181 Riva3Setup(ScrnInfoPtr pScrn)
183 RivaPtr pRiva = RivaPTR(pScrn);
184 vgaHWPtr pVga = VGAHWPTR(pScrn);
185 CARD32 regBase = pRiva->IOAddress;
186 CARD32 frameBase = pRiva->FbAddress;
190 pRiva->Save = RivaDACSave;
191 pRiva->Restore = RivaDACRestore;
192 pRiva->ModeInit = RivaDACInit;
194 pRiva->Dac.LoadPalette = RivaDACLoadPalette;
197 * Override VGA I/O routines.
199 pVga->writeCrtc = RivaWriteCrtc;
200 pVga->readCrtc = RivaReadCrtc;
201 pVga->writeGr = RivaWriteGr;
202 pVga->readGr = RivaReadGr;
203 pVga->writeAttr = RivaWriteAttr;
204 pVga->readAttr = RivaReadAttr;
205 pVga->writeSeq = RivaWriteSeq;
206 pVga->readSeq = RivaReadSeq;
207 pVga->writeMiscOut = RivaWriteMiscOut;
208 pVga->readMiscOut = RivaReadMiscOut;
209 pVga->enablePalette = RivaEnablePalette;
210 pVga->disablePalette = RivaDisablePalette;
211 pVga->writeDacMask = RivaWriteDacMask;
212 pVga->readDacMask = RivaReadDacMask;
213 pVga->writeDacWriteAddr = RivaWriteDacWriteAddr;
214 pVga->writeDacReadAddr = RivaWriteDacReadAddr;
215 pVga->writeDacData = RivaWriteDacData;
216 pVga->readDacData = RivaReadDacData;
218 * Note: There are different pointers to the CRTC/AR and GR/SEQ registers.
219 * Bastardize the intended uses of these to make it work.
221 pVga->MMIOBase = (CARD8 *)pRiva;
222 pVga->MMIOOffset = 0;
227 pRiva->riva.EnableIRQ = 0;
228 pRiva->riva.IO = VGA_IOBASE_COLOR;
230 mmioFlags = VIDMEM_MMIO | VIDMEM_READSIDEEFFECT;
232 pRiva->riva.PRAMDAC = xf86MapPciMem(pScrn->scrnIndex, mmioFlags, pRiva->PciTag,
233 regBase+0x00680000, 0x00003000);
234 pRiva->riva.PFB = xf86MapPciMem(pScrn->scrnIndex, mmioFlags, pRiva->PciTag,
235 regBase+0x00100000, 0x00001000);
236 pRiva->riva.PFIFO = xf86MapPciMem(pScrn->scrnIndex, mmioFlags, pRiva->PciTag,
237 regBase+0x00002000, 0x00002000);
238 pRiva->riva.PGRAPH = xf86MapPciMem(pScrn->scrnIndex, mmioFlags, pRiva->PciTag,
239 regBase+0x00400000, 0x00002000);
240 pRiva->riva.PEXTDEV = xf86MapPciMem(pScrn->scrnIndex, mmioFlags, pRiva->PciTag,
241 regBase+0x00101000, 0x00001000);
242 pRiva->riva.PTIMER = xf86MapPciMem(pScrn->scrnIndex, mmioFlags, pRiva->PciTag,
243 regBase+0x00009000, 0x00001000);
244 pRiva->riva.PMC = xf86MapPciMem(pScrn->scrnIndex, mmioFlags, pRiva->PciTag,
245 regBase+0x00000000, 0x00009000);
246 pRiva->riva.FIFO = xf86MapPciMem(pScrn->scrnIndex, mmioFlags, pRiva->PciTag,
247 regBase+0x00800000, 0x00010000);
248 pRiva->riva.PRAMIN = xf86MapPciMem(pScrn->scrnIndex, mmioFlags, pRiva->PciTag,
249 frameBase+0x00C00000, 0x00008000);
252 * These registers are read/write as 8 bit values. Probably have to map
255 pRiva->riva.PCIO = (U008 *)xf86MapPciMem(pScrn->scrnIndex, mmioFlags,
256 pRiva->PciTag, regBase+0x00601000,
258 pRiva->riva.PDIO = (U008 *)xf86MapPciMem(pScrn->scrnIndex, mmioFlags,
259 pRiva->PciTag, regBase+0x00681000,
261 pRiva->riva.PVIO = (U008 *)xf86MapPciMem(pScrn->scrnIndex, mmioFlags,
262 pRiva->PciTag, regBase+0x000C0000,
265 pRiva->riva.PCRTC = pRiva->riva.PGRAPH;
267 RivaGetConfig(pRiva);
269 pRiva->riva.LockUnlock(&pRiva->riva, 0);
273 monitor = RivaProbeDDC(pScrn);
276 xf86SetDDCproperties(pScrn, monitor);
278 pRiva->Dac.maxPixelClock = pRiva->riva.MaxVClockFreqKHz;