1 /* $XConsortium: nv_driver.c /main/3 1996/10/28 05:13:37 kaleb $ */
3 * Copyright 1996-1997 David J. McKay
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * DAVID J. MCKAY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
20 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * GPL licensing note -- nVidia is allowing a liberal interpretation of
26 * the documentation restriction above, to merely say that this nVidia's
27 * copyright and disclaimer should be included with all code derived
28 * from this source. -- Jeff Garzik <jgarzik@pobox.com>, 01/Nov/99
31 /* Hacked together from mga driver and 3.3.4 NVIDIA driver by Jarno Paananen
34 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/nv_setup.c,v 1.18 2002/08/0
35 5 20:47:06 mvojkovi Exp $ */
37 #include <linux/delay.h>
38 #include <linux/pci.h>
39 #include <linux/pci_ids.h>
45 #ifndef CONFIG_PCI /* sanity check */
46 #error This driver requires PCI support.
49 #define PFX "rivafb: "
51 static inline unsigned char MISCin(struct riva_par *par)
53 return (VGA_RD08(par->riva.PVIO, 0x3cc));
57 riva_is_connected(struct riva_par *par, Bool second)
59 volatile U032 __iomem *PRAMDAC = par->riva.PRAMDAC0;
63 if(second) PRAMDAC += 0x800;
65 reg52C = NV_RD32(PRAMDAC, 0x052C);
66 reg608 = NV_RD32(PRAMDAC, 0x0608);
68 NV_WR32(PRAMDAC, 0x0608, reg608 & ~0x00010000);
70 NV_WR32(PRAMDAC, 0x052C, reg52C & 0x0000FEEE);
72 NV_WR32(PRAMDAC, 0x052C, NV_RD32(PRAMDAC, 0x052C) | 1);
74 NV_WR32(par->riva.PRAMDAC0, 0x0610, 0x94050140);
75 NV_WR32(par->riva.PRAMDAC0, 0x0608, 0x00001000);
79 present = (NV_RD32(PRAMDAC, 0x0608) & (1 << 28)) ? TRUE : FALSE;
81 NV_WR32(par->riva.PRAMDAC0, 0x0608,
82 NV_RD32(par->riva.PRAMDAC0, 0x0608) & 0x0000EFFF);
84 NV_WR32(PRAMDAC, 0x052C, reg52C);
85 NV_WR32(PRAMDAC, 0x0608, reg608);
91 riva_override_CRTC(struct riva_par *par)
94 "Detected CRTC controller %i being used\n",
95 par->SecondCRTC ? 1 : 0);
97 if(par->forceCRTC != -1) {
99 "Forcing usage of CRTC %i\n", par->forceCRTC);
100 par->SecondCRTC = par->forceCRTC;
105 riva_is_second(struct riva_par *par)
107 if (par->FlatPanel == 1) {
108 switch(par->Chipset & 0xffff) {
118 /* this might not be a good default for the chips below */
135 par->SecondCRTC = TRUE;
138 par->SecondCRTC = FALSE;
142 if(riva_is_connected(par, 0)) {
144 if (NV_RD32(par->riva.PRAMDAC0, 0x0000052C) & 0x100)
145 par->SecondCRTC = TRUE;
147 par->SecondCRTC = FALSE;
149 if (riva_is_connected(par, 1)) {
150 if(NV_RD32(par->riva.PRAMDAC0, 0x0000252C) & 0x100)
151 par->SecondCRTC = TRUE;
153 par->SecondCRTC = FALSE;
155 par->SecondCRTC = FALSE;
157 riva_override_CRTC(par);
160 unsigned long riva_get_memlen(struct riva_par *par)
162 RIVA_HW_INST *chip = &par->riva;
163 unsigned long memlen = 0;
164 unsigned int chipset = par->Chipset;
168 switch (chip->Architecture) {
170 if (NV_RD32(chip->PFB, 0x00000000) & 0x00000020) {
171 if (((NV_RD32(chip->PMC, 0x00000000) & 0xF0) == 0x20)
172 && ((NV_RD32(chip->PMC, 0x00000000)&0x0F)>=0x02)) {
176 switch (NV_RD32(chip->PFB,0x00000000) & 0x03) {
194 switch (NV_RD32(chip->PFB, 0x00000000) & 0x00000003) {
208 if (NV_RD32(chip->PFB, 0x00000000) & 0x00000100) {
209 memlen = ((NV_RD32(chip->PFB, 0x00000000)>>12)&0x0F) *
212 switch (NV_RD32(chip->PFB, 0x00000000) & 0x00000003) {
232 if(chipset == NV_CHIP_IGEFORCE2) {
234 dev = pci_find_slot(0, 1);
235 pci_read_config_dword(dev, 0x7C, &amt);
236 memlen = (((amt >> 6) & 31) + 1) * 1024;
237 } else if (chipset == NV_CHIP_0x01F0) {
238 dev = pci_find_slot(0, 1);
239 pci_read_config_dword(dev, 0x84, &amt);
240 memlen = (((amt >> 4) & 127) + 1) * 1024;
242 switch ((NV_RD32(chip->PFB, 0x0000020C) >> 20) &
275 unsigned long riva_get_maxdclk(struct riva_par *par)
277 RIVA_HW_INST *chip = &par->riva;
278 unsigned long dclk = 0;
280 switch (chip->Architecture) {
282 if (NV_RD32(chip->PFB, 0x00000000) & 0x00000020) {
283 if (((NV_RD32(chip->PMC, 0x00000000) & 0xF0) == 0x20)
284 && ((NV_RD32(chip->PMC,0x00000000)&0x0F) >= 0x02)) {
303 switch ((NV_RD32(chip->PFB, 0x00000000) >> 3) & 0x00000003) {
317 riva_common_setup(struct riva_par *par)
319 par->riva.EnableIRQ = 0;
321 (volatile U032 __iomem *)(par->ctrl_base + 0x00680000);
323 (volatile U032 __iomem *)(par->ctrl_base + 0x00100000);
325 (volatile U032 __iomem *)(par->ctrl_base + 0x00002000);
327 (volatile U032 __iomem *)(par->ctrl_base + 0x00400000);
329 (volatile U032 __iomem *)(par->ctrl_base + 0x00101000);
331 (volatile U032 __iomem *)(par->ctrl_base + 0x00009000);
333 (volatile U032 __iomem *)(par->ctrl_base + 0x00000000);
335 (volatile U032 __iomem *)(par->ctrl_base + 0x00800000);
336 par->riva.PCIO0 = par->ctrl_base + 0x00601000;
337 par->riva.PDIO0 = par->ctrl_base + 0x00681000;
338 par->riva.PVIO = par->ctrl_base + 0x000C0000;
340 par->riva.IO = (MISCin(par) & 0x01) ? 0x3D0 : 0x3B0;
342 if (par->FlatPanel == -1) {
343 switch (par->Chipset & 0xffff) {
344 case 0x0112: /* known laptop chips */
371 "On a laptop. Assuming Digital Flat Panel\n");
379 switch (par->Chipset & 0x0ff0) {
381 if (par->Chipset == NV_CHIP_GEFORCE2_GO)
382 par->SecondCRTC = TRUE;
383 #if defined(__powerpc__)
384 if (par->FlatPanel == 1)
385 par->SecondCRTC = TRUE;
387 riva_override_CRTC(par);
405 if (par->SecondCRTC) {
406 par->riva.PCIO = par->riva.PCIO0 + 0x2000;
407 par->riva.PCRTC = par->riva.PCRTC0 + 0x800;
408 par->riva.PRAMDAC = par->riva.PRAMDAC0 + 0x800;
409 par->riva.PDIO = par->riva.PDIO0 + 0x2000;
411 par->riva.PCIO = par->riva.PCIO0;
412 par->riva.PCRTC = par->riva.PCRTC0;
413 par->riva.PRAMDAC = par->riva.PRAMDAC0;
414 par->riva.PDIO = par->riva.PDIO0;
417 if (par->FlatPanel == -1) {
418 /* Fix me, need x86 DDC code */
421 par->riva.flatPanel = (par->FlatPanel > 0) ? TRUE : FALSE;
423 RivaGetConfig(&par->riva, par->Chipset);