1 /***************************************************************************\
3 |* Copyright 2003 NVIDIA, Corporation. All rights reserved. *|
5 |* NOTICE TO USER: The source code is copyrighted under U.S. and *|
6 |* international laws. Users and possessors of this source code are *|
7 |* hereby granted a nonexclusive, royalty-free copyright license to *|
8 |* use this code in individual and commercial software. *|
10 |* Any use of this source code must include, in the user documenta- *|
11 |* tion and internal comments to the code, notices to the end user *|
14 |* Copyright 2003 NVIDIA, Corporation. All rights reserved. *|
16 |* NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY *|
17 |* OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" *|
18 |* WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. NVIDIA, CORPOR- *|
19 |* ATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, *|
20 |* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE- *|
21 |* MENT, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL *|
22 |* NVIDIA, CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT, INCI- *|
23 |* DENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RE- *|
24 |* SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION *|
25 |* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *|
26 |* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
28 |* U.S. Government End Users. This source code is a "commercial *|
29 |* item," as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
30 |* consisting of "commercial computer software" and "commercial *|
31 |* computer software documentation," as such terms are used in *|
32 |* 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Govern- *|
33 |* ment only as a commercial end item. Consistent with 48 C.F.R. *|
34 |* 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
35 |* all U.S. Government End Users acquire the source code with only *|
36 |* those rights set forth herein. *|
38 \***************************************************************************/
41 * GPL Licensing Note - According to Mark Vojkovich, author of the Xorg/
42 * XFree86 'nv' driver, this source code is provided under MIT-style licensing
43 * where the source code is provided "as is" without warranty of any kind.
44 * The only usage restriction is for the copyright notices to be retained
45 * whenever code is used.
47 * Antonino Daplas <adaplas@pol.net> 2005-03-11
50 #include <video/vga.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/slab.h>
58 * Override VGA I/O routines.
60 void NVWriteCrtc(struct nvidia_par
*par
, u8 index
, u8 value
)
62 VGA_WR08(par
->PCIO
, par
->IOBase
+ 0x04, index
);
63 VGA_WR08(par
->PCIO
, par
->IOBase
+ 0x05, value
);
65 u8
NVReadCrtc(struct nvidia_par
*par
, u8 index
)
67 VGA_WR08(par
->PCIO
, par
->IOBase
+ 0x04, index
);
68 return (VGA_RD08(par
->PCIO
, par
->IOBase
+ 0x05));
70 void NVWriteGr(struct nvidia_par
*par
, u8 index
, u8 value
)
72 VGA_WR08(par
->PVIO
, VGA_GFX_I
, index
);
73 VGA_WR08(par
->PVIO
, VGA_GFX_D
, value
);
75 u8
NVReadGr(struct nvidia_par
*par
, u8 index
)
77 VGA_WR08(par
->PVIO
, VGA_GFX_I
, index
);
78 return (VGA_RD08(par
->PVIO
, VGA_GFX_D
));
80 void NVWriteSeq(struct nvidia_par
*par
, u8 index
, u8 value
)
82 VGA_WR08(par
->PVIO
, VGA_SEQ_I
, index
);
83 VGA_WR08(par
->PVIO
, VGA_SEQ_D
, value
);
85 u8
NVReadSeq(struct nvidia_par
*par
, u8 index
)
87 VGA_WR08(par
->PVIO
, VGA_SEQ_I
, index
);
88 return (VGA_RD08(par
->PVIO
, VGA_SEQ_D
));
90 void NVWriteAttr(struct nvidia_par
*par
, u8 index
, u8 value
)
94 tmp
= VGA_RD08(par
->PCIO
, par
->IOBase
+ 0x0a);
95 if (par
->paletteEnabled
)
99 VGA_WR08(par
->PCIO
, VGA_ATT_IW
, index
);
100 VGA_WR08(par
->PCIO
, VGA_ATT_W
, value
);
102 u8
NVReadAttr(struct nvidia_par
*par
, u8 index
)
106 tmp
= VGA_RD08(par
->PCIO
, par
->IOBase
+ 0x0a);
107 if (par
->paletteEnabled
)
111 VGA_WR08(par
->PCIO
, VGA_ATT_IW
, index
);
112 return (VGA_RD08(par
->PCIO
, VGA_ATT_R
));
114 void NVWriteMiscOut(struct nvidia_par
*par
, u8 value
)
116 VGA_WR08(par
->PVIO
, VGA_MIS_W
, value
);
118 u8
NVReadMiscOut(struct nvidia_par
*par
)
120 return (VGA_RD08(par
->PVIO
, VGA_MIS_R
));
122 void NVWriteDacMask(struct nvidia_par
*par
, u8 value
)
124 VGA_WR08(par
->PDIO
, VGA_PEL_MSK
, value
);
126 void NVWriteDacReadAddr(struct nvidia_par
*par
, u8 value
)
128 VGA_WR08(par
->PDIO
, VGA_PEL_IR
, value
);
130 void NVWriteDacWriteAddr(struct nvidia_par
*par
, u8 value
)
132 VGA_WR08(par
->PDIO
, VGA_PEL_IW
, value
);
134 void NVWriteDacData(struct nvidia_par
*par
, u8 value
)
136 VGA_WR08(par
->PDIO
, VGA_PEL_D
, value
);
138 u8
NVReadDacData(struct nvidia_par
*par
)
140 return (VGA_RD08(par
->PDIO
, VGA_PEL_D
));
143 static int NVIsConnected(struct nvidia_par
*par
, int output
)
145 volatile u32 __iomem
*PRAMDAC
= par
->PRAMDAC0
;
146 u32 reg52C
, reg608
, dac0_reg608
= 0;
150 dac0_reg608
= NV_RD32(PRAMDAC
, 0x0608);
154 reg52C
= NV_RD32(PRAMDAC
, 0x052C);
155 reg608
= NV_RD32(PRAMDAC
, 0x0608);
157 NV_WR32(PRAMDAC
, 0x0608, reg608
& ~0x00010000);
159 NV_WR32(PRAMDAC
, 0x052C, reg52C
& 0x0000FEEE);
161 NV_WR32(PRAMDAC
, 0x052C, NV_RD32(PRAMDAC
, 0x052C) | 1);
163 NV_WR32(par
->PRAMDAC0
, 0x0610, 0x94050140);
164 NV_WR32(par
->PRAMDAC0
, 0x0608, NV_RD32(par
->PRAMDAC0
, 0x0608) |
169 present
= (NV_RD32(PRAMDAC
, 0x0608) & (1 << 28)) ? 1 : 0;
172 printk("nvidiafb: CRTC%i analog found\n", output
);
174 printk("nvidiafb: CRTC%i analog not found\n", output
);
177 NV_WR32(par
->PRAMDAC0
, 0x0608, dac0_reg608
);
179 NV_WR32(PRAMDAC
, 0x052C, reg52C
);
180 NV_WR32(PRAMDAC
, 0x0608, reg608
);
185 static void NVSelectHeadRegisters(struct nvidia_par
*par
, int head
)
188 par
->PCIO
= par
->PCIO0
+ 0x2000;
189 par
->PCRTC
= par
->PCRTC0
+ 0x800;
190 par
->PRAMDAC
= par
->PRAMDAC0
+ 0x800;
191 par
->PDIO
= par
->PDIO0
+ 0x2000;
193 par
->PCIO
= par
->PCIO0
;
194 par
->PCRTC
= par
->PCRTC0
;
195 par
->PRAMDAC
= par
->PRAMDAC0
;
196 par
->PDIO
= par
->PDIO0
;
200 static void nv4GetConfig(struct nvidia_par
*par
)
202 if (NV_RD32(par
->PFB
, 0x0000) & 0x00000100) {
203 par
->RamAmountKBytes
=
204 ((NV_RD32(par
->PFB
, 0x0000) >> 12) & 0x0F) * 1024 * 2 +
207 switch (NV_RD32(par
->PFB
, 0x0000) & 0x00000003) {
209 par
->RamAmountKBytes
= 1024 * 32;
212 par
->RamAmountKBytes
= 1024 * 4;
215 par
->RamAmountKBytes
= 1024 * 8;
219 par
->RamAmountKBytes
= 1024 * 16;
223 par
->CrystalFreqKHz
= (NV_RD32(par
->PEXTDEV
, 0x0000) & 0x00000040) ?
225 par
->CURSOR
= &par
->PRAMIN
[0x1E00];
226 par
->MinVClockFreqKHz
= 12000;
227 par
->MaxVClockFreqKHz
= 350000;
230 static void nv10GetConfig(struct nvidia_par
*par
)
233 u32 implementation
= par
->Chipset
& 0x0ff0;
236 /* turn on big endian register access */
237 if (!(NV_RD32(par
->PMC
, 0x0004) & 0x01000001)) {
238 NV_WR32(par
->PMC
, 0x0004, 0x01000001);
243 dev
= pci_get_domain_bus_and_slot(pci_domain_nr(par
->pci_dev
->bus
),
245 if ((par
->Chipset
& 0xffff) == 0x01a0) {
248 pci_read_config_dword(dev
, 0x7c, &amt
);
249 par
->RamAmountKBytes
= (((amt
>> 6) & 31) + 1) * 1024;
250 } else if ((par
->Chipset
& 0xffff) == 0x01f0) {
253 pci_read_config_dword(dev
, 0x84, &amt
);
254 par
->RamAmountKBytes
= (((amt
>> 4) & 127) + 1) * 1024;
256 par
->RamAmountKBytes
=
257 (NV_RD32(par
->PFB
, 0x020C) & 0xFFF00000) >> 10;
261 par
->CrystalFreqKHz
= (NV_RD32(par
->PEXTDEV
, 0x0000) & (1 << 6)) ?
264 if (par
->twoHeads
&& (implementation
!= 0x0110)) {
265 if (NV_RD32(par
->PEXTDEV
, 0x0000) & (1 << 22))
266 par
->CrystalFreqKHz
= 27000;
269 par
->CURSOR
= NULL
; /* can't set this here */
270 par
->MinVClockFreqKHz
= 12000;
271 par
->MaxVClockFreqKHz
= par
->twoStagePLL
? 400000 : 350000;
274 int NVCommonSetup(struct fb_info
*info
)
276 struct nvidia_par
*par
= info
->par
;
277 struct fb_var_screeninfo
*var
;
278 u16 implementation
= par
->Chipset
& 0x0ff0;
279 u8
*edidA
= NULL
, *edidB
= NULL
;
280 struct fb_monspecs
*monitorA
, *monitorB
;
281 struct fb_monspecs
*monA
= NULL
, *monB
= NULL
;
285 int FlatPanel
= -1; /* really means the CRTC is slaved */
289 var
= kzalloc(sizeof(struct fb_var_screeninfo
), GFP_KERNEL
);
290 monitorA
= kzalloc(sizeof(struct fb_monspecs
), GFP_KERNEL
);
291 monitorB
= kzalloc(sizeof(struct fb_monspecs
), GFP_KERNEL
);
293 if (!var
|| !monitorA
|| !monitorB
) {
298 par
->PRAMIN
= par
->REGS
+ (0x00710000 / 4);
299 par
->PCRTC0
= par
->REGS
+ (0x00600000 / 4);
300 par
->PRAMDAC0
= par
->REGS
+ (0x00680000 / 4);
301 par
->PFB
= par
->REGS
+ (0x00100000 / 4);
302 par
->PFIFO
= par
->REGS
+ (0x00002000 / 4);
303 par
->PGRAPH
= par
->REGS
+ (0x00400000 / 4);
304 par
->PEXTDEV
= par
->REGS
+ (0x00101000 / 4);
305 par
->PTIMER
= par
->REGS
+ (0x00009000 / 4);
306 par
->PMC
= par
->REGS
+ (0x00000000 / 4);
307 par
->FIFO
= par
->REGS
+ (0x00800000 / 4);
309 /* 8 bit registers */
310 par
->PCIO0
= (u8 __iomem
*) par
->REGS
+ 0x00601000;
311 par
->PDIO0
= (u8 __iomem
*) par
->REGS
+ 0x00681000;
312 par
->PVIO
= (u8 __iomem
*) par
->REGS
+ 0x000C0000;
314 par
->twoHeads
= (par
->Architecture
>= NV_ARCH_10
) &&
315 (implementation
!= 0x0100) &&
316 (implementation
!= 0x0150) &&
317 (implementation
!= 0x01A0) && (implementation
!= 0x0200);
319 par
->fpScaler
= (par
->FpScale
&& par
->twoHeads
&&
320 (implementation
!= 0x0110));
322 par
->twoStagePLL
= (implementation
== 0x0310) ||
323 (implementation
== 0x0340) || (par
->Architecture
>= NV_ARCH_40
);
325 par
->WaitVSyncPossible
= (par
->Architecture
>= NV_ARCH_10
) &&
326 (implementation
!= 0x0100);
328 par
->BlendingPossible
= ((par
->Chipset
& 0xffff) != 0x0020);
330 /* look for known laptop chips */
331 switch (par
->Chipset
& 0xffff) {
386 if (par
->Architecture
== NV_ARCH_04
)
391 NVSelectHeadRegisters(par
, 0);
393 NVLockUnlock(par
, 0);
395 par
->IOBase
= (NVReadMiscOut(par
) & 0x01) ? 0x3d0 : 0x3b0;
399 nvidia_create_i2c_busses(par
);
400 if (!par
->twoHeads
) {
402 if (nvidia_probe_i2c_connector(info
, 1, &edidA
))
403 nvidia_probe_of_connector(info
, 1, &edidA
);
404 if (edidA
&& !fb_parse_edid(edidA
, var
)) {
405 printk("nvidiafb: EDID found from BUS1\n");
407 fb_edid_to_monspecs(edidA
, monA
);
408 FlatPanel
= (monA
->input
& FB_DISP_DDI
) ? 1 : 0;
410 /* NV4 doesn't support FlatPanels */
411 if ((par
->Chipset
& 0x0fff) <= 0x0020)
414 VGA_WR08(par
->PCIO
, 0x03D4, 0x28);
415 if (VGA_RD08(par
->PCIO
, 0x03D5) & 0x80) {
416 VGA_WR08(par
->PCIO
, 0x03D4, 0x33);
417 if (!(VGA_RD08(par
->PCIO
, 0x03D5) & 0x01))
423 printk("nvidiafb: HW is currently programmed for %s\n",
424 FlatPanel
? (Television
? "TV" : "DFP") :
428 if (par
->FlatPanel
== -1) {
429 par
->FlatPanel
= FlatPanel
;
430 par
->Television
= Television
;
432 printk("nvidiafb: Forcing display type to %s as "
433 "specified\n", par
->FlatPanel
? "DFP" : "CRT");
436 u8 outputAfromCRTC
, outputBfromCRTC
;
438 u8 slaved_on_A
, slaved_on_B
;
439 int analog_on_A
, analog_on_B
;
443 if (implementation
!= 0x0110) {
444 if (NV_RD32(par
->PRAMDAC0
, 0x0000052C) & 0x100)
448 if (NV_RD32(par
->PRAMDAC0
, 0x0000252C) & 0x100)
452 analog_on_A
= NVIsConnected(par
, 0);
453 analog_on_B
= NVIsConnected(par
, 1);
461 VGA_WR08(par
->PCIO
, 0x03D4, 0x44);
462 cr44
= VGA_RD08(par
->PCIO
, 0x03D5);
464 VGA_WR08(par
->PCIO
, 0x03D5, 3);
465 NVSelectHeadRegisters(par
, 1);
466 NVLockUnlock(par
, 0);
468 VGA_WR08(par
->PCIO
, 0x03D4, 0x28);
469 slaved_on_B
= VGA_RD08(par
->PCIO
, 0x03D5) & 0x80;
471 VGA_WR08(par
->PCIO
, 0x03D4, 0x33);
472 tvB
= !(VGA_RD08(par
->PCIO
, 0x03D5) & 0x01);
475 VGA_WR08(par
->PCIO
, 0x03D4, 0x44);
476 VGA_WR08(par
->PCIO
, 0x03D5, 0);
477 NVSelectHeadRegisters(par
, 0);
478 NVLockUnlock(par
, 0);
480 VGA_WR08(par
->PCIO
, 0x03D4, 0x28);
481 slaved_on_A
= VGA_RD08(par
->PCIO
, 0x03D5) & 0x80;
483 VGA_WR08(par
->PCIO
, 0x03D4, 0x33);
484 tvA
= !(VGA_RD08(par
->PCIO
, 0x03D5) & 0x01);
487 oldhead
= NV_RD32(par
->PCRTC0
, 0x00000860);
488 NV_WR32(par
->PCRTC0
, 0x00000860, oldhead
| 0x00000010);
490 if (nvidia_probe_i2c_connector(info
, 1, &edidA
))
491 nvidia_probe_of_connector(info
, 1, &edidA
);
492 if (edidA
&& !fb_parse_edid(edidA
, var
)) {
493 printk("nvidiafb: EDID found from BUS1\n");
495 fb_edid_to_monspecs(edidA
, monA
);
498 if (nvidia_probe_i2c_connector(info
, 2, &edidB
))
499 nvidia_probe_of_connector(info
, 2, &edidB
);
500 if (edidB
&& !fb_parse_edid(edidB
, var
)) {
501 printk("nvidiafb: EDID found from BUS2\n");
503 fb_edid_to_monspecs(edidB
, monB
);
506 if (slaved_on_A
&& !tvA
) {
509 printk("nvidiafb: CRTC 0 is currently programmed for "
511 } else if (slaved_on_B
&& !tvB
) {
514 printk("nvidiafb: CRTC 1 is currently programmed "
516 } else if (analog_on_A
) {
517 CRTCnumber
= outputAfromCRTC
;
519 printk("nvidiafb: CRTC %i appears to have a "
520 "CRT attached\n", CRTCnumber
);
521 } else if (analog_on_B
) {
522 CRTCnumber
= outputBfromCRTC
;
524 printk("nvidiafb: CRTC %i appears to have a "
525 "CRT attached\n", CRTCnumber
);
526 } else if (slaved_on_A
) {
530 printk("nvidiafb: CRTC 0 is currently programmed "
532 } else if (slaved_on_B
) {
536 printk("nvidiafb: CRTC 1 is currently programmed for "
539 FlatPanel
= (monA
->input
& FB_DISP_DDI
) ? 1 : 0;
541 FlatPanel
= (monB
->input
& FB_DISP_DDI
) ? 1 : 0;
544 if (par
->FlatPanel
== -1) {
545 if (FlatPanel
!= -1) {
546 par
->FlatPanel
= FlatPanel
;
547 par
->Television
= Television
;
549 printk("nvidiafb: Unable to detect display "
552 printk("...On a laptop, assuming "
556 printk("...Using default of CRT\n");
561 printk("nvidiafb: Forcing display type to %s as "
562 "specified\n", par
->FlatPanel
? "DFP" : "CRT");
565 if (par
->CRTCnumber
== -1) {
566 if (CRTCnumber
!= -1)
567 par
->CRTCnumber
= CRTCnumber
;
569 printk("nvidiafb: Unable to detect which "
575 printk("...Defaulting to CRTCNumber %i\n",
579 printk("nvidiafb: Forcing CRTCNumber %i as "
580 "specified\n", par
->CRTCnumber
);
584 if (((monA
->input
& FB_DISP_DDI
) &&
586 ((!(monA
->input
& FB_DISP_DDI
)) &&
589 fb_destroy_modedb(monB
->modedb
);
593 fb_destroy_modedb(monA
->modedb
);
599 if (((monB
->input
& FB_DISP_DDI
) &&
601 ((!(monB
->input
& FB_DISP_DDI
)) &&
603 fb_destroy_modedb(monB
->modedb
);
609 if (implementation
== 0x0110)
610 cr44
= par
->CRTCnumber
* 0x3;
612 NV_WR32(par
->PCRTC0
, 0x00000860, oldhead
);
614 VGA_WR08(par
->PCIO
, 0x03D4, 0x44);
615 VGA_WR08(par
->PCIO
, 0x03D5, cr44
);
616 NVSelectHeadRegisters(par
, par
->CRTCnumber
);
619 printk("nvidiafb: Using %s on CRTC %i\n",
620 par
->FlatPanel
? (par
->Television
? "TV" : "DFP") : "CRT",
623 if (par
->FlatPanel
&& !par
->Television
) {
624 par
->fpWidth
= NV_RD32(par
->PRAMDAC
, 0x0820) + 1;
625 par
->fpHeight
= NV_RD32(par
->PRAMDAC
, 0x0800) + 1;
626 par
->fpSyncs
= NV_RD32(par
->PRAMDAC
, 0x0848) & 0x30000033;
628 printk("nvidiafb: Panel size is %i x %i\n", par
->fpWidth
, par
->fpHeight
);
632 info
->monspecs
= *monA
;
634 if (!par
->FlatPanel
|| !par
->twoHeads
)
638 if (par
->FlatPanel
&& par
->twoHeads
) {
639 NV_WR32(par
->PRAMDAC0
, 0x08B0, 0x00010004);
640 if (NV_RD32(par
->PRAMDAC0
, 0x08b4) & 1)
642 printk("nvidiafb: Panel is %s\n", par
->LVDS
? "LVDS" : "TMDS");