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>
44 #define PFX "rivafb: "
46 static inline unsigned char MISCin(struct riva_par
*par
)
48 return (VGA_RD08(par
->riva
.PVIO
, 0x3cc));
52 riva_is_connected(struct riva_par
*par
, Bool second
)
54 volatile U032 __iomem
*PRAMDAC
= par
->riva
.PRAMDAC0
;
58 if(second
) PRAMDAC
+= 0x800;
60 reg52C
= NV_RD32(PRAMDAC
, 0x052C);
61 reg608
= NV_RD32(PRAMDAC
, 0x0608);
63 NV_WR32(PRAMDAC
, 0x0608, reg608
& ~0x00010000);
65 NV_WR32(PRAMDAC
, 0x052C, reg52C
& 0x0000FEEE);
67 NV_WR32(PRAMDAC
, 0x052C, NV_RD32(PRAMDAC
, 0x052C) | 1);
69 NV_WR32(par
->riva
.PRAMDAC0
, 0x0610, 0x94050140);
70 NV_WR32(par
->riva
.PRAMDAC0
, 0x0608, 0x00001000);
74 present
= (NV_RD32(PRAMDAC
, 0x0608) & (1 << 28)) ? TRUE
: FALSE
;
76 NV_WR32(par
->riva
.PRAMDAC0
, 0x0608,
77 NV_RD32(par
->riva
.PRAMDAC0
, 0x0608) & 0x0000EFFF);
79 NV_WR32(PRAMDAC
, 0x052C, reg52C
);
80 NV_WR32(PRAMDAC
, 0x0608, reg608
);
86 riva_override_CRTC(struct riva_par
*par
)
89 "Detected CRTC controller %i being used\n",
90 par
->SecondCRTC
? 1 : 0);
92 if(par
->forceCRTC
!= -1) {
94 "Forcing usage of CRTC %i\n", par
->forceCRTC
);
95 par
->SecondCRTC
= par
->forceCRTC
;
100 riva_is_second(struct riva_par
*par
)
102 if (par
->FlatPanel
== 1) {
103 switch(par
->Chipset
& 0xffff) {
113 /* this might not be a good default for the chips below */
130 par
->SecondCRTC
= TRUE
;
133 par
->SecondCRTC
= FALSE
;
137 if(riva_is_connected(par
, 0)) {
139 if (NV_RD32(par
->riva
.PRAMDAC0
, 0x0000052C) & 0x100)
140 par
->SecondCRTC
= TRUE
;
142 par
->SecondCRTC
= FALSE
;
144 if (riva_is_connected(par
, 1)) {
145 if(NV_RD32(par
->riva
.PRAMDAC0
, 0x0000252C) & 0x100)
146 par
->SecondCRTC
= TRUE
;
148 par
->SecondCRTC
= FALSE
;
150 par
->SecondCRTC
= FALSE
;
152 riva_override_CRTC(par
);
155 unsigned long riva_get_memlen(struct riva_par
*par
)
157 RIVA_HW_INST
*chip
= &par
->riva
;
158 unsigned long memlen
= 0;
159 unsigned int chipset
= par
->Chipset
;
162 int domain
= pci_domain_nr(par
->pdev
->bus
);
164 switch (chip
->Architecture
) {
166 if (NV_RD32(chip
->PFB
, 0x00000000) & 0x00000020) {
167 if (((NV_RD32(chip
->PMC
, 0x00000000) & 0xF0) == 0x20)
168 && ((NV_RD32(chip
->PMC
, 0x00000000)&0x0F)>=0x02)) {
172 switch (NV_RD32(chip
->PFB
,0x00000000) & 0x03) {
190 switch (NV_RD32(chip
->PFB
, 0x00000000) & 0x00000003) {
204 if (NV_RD32(chip
->PFB
, 0x00000000) & 0x00000100) {
205 memlen
= ((NV_RD32(chip
->PFB
, 0x00000000)>>12)&0x0F) *
208 switch (NV_RD32(chip
->PFB
, 0x00000000) & 0x00000003) {
228 if(chipset
== NV_CHIP_IGEFORCE2
) {
230 dev
= pci_get_domain_bus_and_slot(domain
, 0, 1);
231 pci_read_config_dword(dev
, 0x7C, &amt
);
233 memlen
= (((amt
>> 6) & 31) + 1) * 1024;
234 } else if (chipset
== NV_CHIP_0x01F0
) {
235 dev
= pci_get_domain_bus_and_slot(domain
, 0, 1);
236 pci_read_config_dword(dev
, 0x84, &amt
);
238 memlen
= (((amt
>> 4) & 127) + 1) * 1024;
240 switch ((NV_RD32(chip
->PFB
, 0x0000020C) >> 20) &
273 unsigned long riva_get_maxdclk(struct riva_par
*par
)
275 RIVA_HW_INST
*chip
= &par
->riva
;
276 unsigned long dclk
= 0;
278 switch (chip
->Architecture
) {
280 if (NV_RD32(chip
->PFB
, 0x00000000) & 0x00000020) {
281 if (((NV_RD32(chip
->PMC
, 0x00000000) & 0xF0) == 0x20)
282 && ((NV_RD32(chip
->PMC
,0x00000000)&0x0F) >= 0x02)) {
301 switch ((NV_RD32(chip
->PFB
, 0x00000000) >> 3) & 0x00000003) {
315 riva_common_setup(struct riva_par
*par
)
317 par
->riva
.EnableIRQ
= 0;
319 (volatile U032 __iomem
*)(par
->ctrl_base
+ 0x00680000);
321 (volatile U032 __iomem
*)(par
->ctrl_base
+ 0x00100000);
323 (volatile U032 __iomem
*)(par
->ctrl_base
+ 0x00002000);
325 (volatile U032 __iomem
*)(par
->ctrl_base
+ 0x00400000);
327 (volatile U032 __iomem
*)(par
->ctrl_base
+ 0x00101000);
329 (volatile U032 __iomem
*)(par
->ctrl_base
+ 0x00009000);
331 (volatile U032 __iomem
*)(par
->ctrl_base
+ 0x00000000);
333 (volatile U032 __iomem
*)(par
->ctrl_base
+ 0x00800000);
334 par
->riva
.PCIO0
= par
->ctrl_base
+ 0x00601000;
335 par
->riva
.PDIO0
= par
->ctrl_base
+ 0x00681000;
336 par
->riva
.PVIO
= par
->ctrl_base
+ 0x000C0000;
338 par
->riva
.IO
= (MISCin(par
) & 0x01) ? 0x3D0 : 0x3B0;
340 if (par
->FlatPanel
== -1) {
341 switch (par
->Chipset
& 0xffff) {
342 case 0x0112: /* known laptop chips */
369 "On a laptop. Assuming Digital Flat Panel\n");
377 switch (par
->Chipset
& 0x0ff0) {
379 if (par
->Chipset
== NV_CHIP_GEFORCE2_GO
)
380 par
->SecondCRTC
= TRUE
;
381 #if defined(__powerpc__)
382 if (par
->FlatPanel
== 1)
383 par
->SecondCRTC
= TRUE
;
385 riva_override_CRTC(par
);
403 if (par
->SecondCRTC
) {
404 par
->riva
.PCIO
= par
->riva
.PCIO0
+ 0x2000;
405 par
->riva
.PCRTC
= par
->riva
.PCRTC0
+ 0x800;
406 par
->riva
.PRAMDAC
= par
->riva
.PRAMDAC0
+ 0x800;
407 par
->riva
.PDIO
= par
->riva
.PDIO0
+ 0x2000;
409 par
->riva
.PCIO
= par
->riva
.PCIO0
;
410 par
->riva
.PCRTC
= par
->riva
.PCRTC0
;
411 par
->riva
.PRAMDAC
= par
->riva
.PRAMDAC0
;
412 par
->riva
.PDIO
= par
->riva
.PDIO0
;
415 if (par
->FlatPanel
== -1) {
416 /* Fix me, need x86 DDC code */
419 par
->riva
.flatPanel
= (par
->FlatPanel
> 0) ? TRUE
: FALSE
;
421 RivaGetConfig(&par
->riva
, par
->pdev
, par
->Chipset
);