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
)
93 VGA_RD08(par
->PCIO
, par
->IOBase
+ 0x0a);
94 if (par
->paletteEnabled
)
98 VGA_WR08(par
->PCIO
, VGA_ATT_IW
, index
);
99 VGA_WR08(par
->PCIO
, VGA_ATT_W
, value
);
101 u8
NVReadAttr(struct nvidia_par
*par
, u8 index
)
103 VGA_RD08(par
->PCIO
, par
->IOBase
+ 0x0a);
104 if (par
->paletteEnabled
)
108 VGA_WR08(par
->PCIO
, VGA_ATT_IW
, index
);
109 return (VGA_RD08(par
->PCIO
, VGA_ATT_R
));
111 void NVWriteMiscOut(struct nvidia_par
*par
, u8 value
)
113 VGA_WR08(par
->PVIO
, VGA_MIS_W
, value
);
115 u8
NVReadMiscOut(struct nvidia_par
*par
)
117 return (VGA_RD08(par
->PVIO
, VGA_MIS_R
));
119 void NVWriteDacMask(struct nvidia_par
*par
, u8 value
)
121 VGA_WR08(par
->PDIO
, VGA_PEL_MSK
, value
);
123 void NVWriteDacReadAddr(struct nvidia_par
*par
, u8 value
)
125 VGA_WR08(par
->PDIO
, VGA_PEL_IR
, value
);
127 void NVWriteDacWriteAddr(struct nvidia_par
*par
, u8 value
)
129 VGA_WR08(par
->PDIO
, VGA_PEL_IW
, value
);
131 void NVWriteDacData(struct nvidia_par
*par
, u8 value
)
133 VGA_WR08(par
->PDIO
, VGA_PEL_D
, value
);
135 u8
NVReadDacData(struct nvidia_par
*par
)
137 return (VGA_RD08(par
->PDIO
, VGA_PEL_D
));
140 static int NVIsConnected(struct nvidia_par
*par
, int output
)
142 volatile u32 __iomem
*PRAMDAC
= par
->PRAMDAC0
;
143 u32 reg52C
, reg608
, dac0_reg608
= 0;
147 dac0_reg608
= NV_RD32(PRAMDAC
, 0x0608);
151 reg52C
= NV_RD32(PRAMDAC
, 0x052C);
152 reg608
= NV_RD32(PRAMDAC
, 0x0608);
154 NV_WR32(PRAMDAC
, 0x0608, reg608
& ~0x00010000);
156 NV_WR32(PRAMDAC
, 0x052C, reg52C
& 0x0000FEEE);
158 NV_WR32(PRAMDAC
, 0x052C, NV_RD32(PRAMDAC
, 0x052C) | 1);
160 NV_WR32(par
->PRAMDAC0
, 0x0610, 0x94050140);
161 NV_WR32(par
->PRAMDAC0
, 0x0608, NV_RD32(par
->PRAMDAC0
, 0x0608) |
166 present
= (NV_RD32(PRAMDAC
, 0x0608) & (1 << 28)) ? 1 : 0;
169 printk("nvidiafb: CRTC%i analog found\n", output
);
171 printk("nvidiafb: CRTC%i analog not found\n", output
);
174 NV_WR32(par
->PRAMDAC0
, 0x0608, dac0_reg608
);
176 NV_WR32(PRAMDAC
, 0x052C, reg52C
);
177 NV_WR32(PRAMDAC
, 0x0608, reg608
);
182 static void NVSelectHeadRegisters(struct nvidia_par
*par
, int head
)
185 par
->PCIO
= par
->PCIO0
+ 0x2000;
186 par
->PCRTC
= par
->PCRTC0
+ 0x800;
187 par
->PRAMDAC
= par
->PRAMDAC0
+ 0x800;
188 par
->PDIO
= par
->PDIO0
+ 0x2000;
190 par
->PCIO
= par
->PCIO0
;
191 par
->PCRTC
= par
->PCRTC0
;
192 par
->PRAMDAC
= par
->PRAMDAC0
;
193 par
->PDIO
= par
->PDIO0
;
197 static void nv4GetConfig(struct nvidia_par
*par
)
199 if (NV_RD32(par
->PFB
, 0x0000) & 0x00000100) {
200 par
->RamAmountKBytes
=
201 ((NV_RD32(par
->PFB
, 0x0000) >> 12) & 0x0F) * 1024 * 2 +
204 switch (NV_RD32(par
->PFB
, 0x0000) & 0x00000003) {
206 par
->RamAmountKBytes
= 1024 * 32;
209 par
->RamAmountKBytes
= 1024 * 4;
212 par
->RamAmountKBytes
= 1024 * 8;
216 par
->RamAmountKBytes
= 1024 * 16;
220 par
->CrystalFreqKHz
= (NV_RD32(par
->PEXTDEV
, 0x0000) & 0x00000040) ?
222 par
->CURSOR
= &par
->PRAMIN
[0x1E00];
223 par
->MinVClockFreqKHz
= 12000;
224 par
->MaxVClockFreqKHz
= 350000;
227 static void nv10GetConfig(struct nvidia_par
*par
)
230 u32 implementation
= par
->Chipset
& 0x0ff0;
233 /* turn on big endian register access */
234 if (!(NV_RD32(par
->PMC
, 0x0004) & 0x01000001)) {
235 NV_WR32(par
->PMC
, 0x0004, 0x01000001);
240 dev
= pci_get_domain_bus_and_slot(pci_domain_nr(par
->pci_dev
->bus
),
242 if ((par
->Chipset
& 0xffff) == 0x01a0) {
245 pci_read_config_dword(dev
, 0x7c, &amt
);
246 par
->RamAmountKBytes
= (((amt
>> 6) & 31) + 1) * 1024;
247 } else if ((par
->Chipset
& 0xffff) == 0x01f0) {
250 pci_read_config_dword(dev
, 0x84, &amt
);
251 par
->RamAmountKBytes
= (((amt
>> 4) & 127) + 1) * 1024;
253 par
->RamAmountKBytes
=
254 (NV_RD32(par
->PFB
, 0x020C) & 0xFFF00000) >> 10;
258 par
->CrystalFreqKHz
= (NV_RD32(par
->PEXTDEV
, 0x0000) & (1 << 6)) ?
261 if (par
->twoHeads
&& (implementation
!= 0x0110)) {
262 if (NV_RD32(par
->PEXTDEV
, 0x0000) & (1 << 22))
263 par
->CrystalFreqKHz
= 27000;
266 par
->CURSOR
= NULL
; /* can't set this here */
267 par
->MinVClockFreqKHz
= 12000;
268 par
->MaxVClockFreqKHz
= par
->twoStagePLL
? 400000 : 350000;
271 int NVCommonSetup(struct fb_info
*info
)
273 struct nvidia_par
*par
= info
->par
;
274 struct fb_var_screeninfo
*var
;
275 u16 implementation
= par
->Chipset
& 0x0ff0;
276 u8
*edidA
= NULL
, *edidB
= NULL
;
277 struct fb_monspecs
*monitorA
, *monitorB
;
278 struct fb_monspecs
*monA
= NULL
, *monB
= NULL
;
282 int FlatPanel
= -1; /* really means the CRTC is slaved */
286 var
= kzalloc(sizeof(struct fb_var_screeninfo
), GFP_KERNEL
);
287 monitorA
= kzalloc(sizeof(struct fb_monspecs
), GFP_KERNEL
);
288 monitorB
= kzalloc(sizeof(struct fb_monspecs
), GFP_KERNEL
);
290 if (!var
|| !monitorA
|| !monitorB
) {
295 par
->PRAMIN
= par
->REGS
+ (0x00710000 / 4);
296 par
->PCRTC0
= par
->REGS
+ (0x00600000 / 4);
297 par
->PRAMDAC0
= par
->REGS
+ (0x00680000 / 4);
298 par
->PFB
= par
->REGS
+ (0x00100000 / 4);
299 par
->PFIFO
= par
->REGS
+ (0x00002000 / 4);
300 par
->PGRAPH
= par
->REGS
+ (0x00400000 / 4);
301 par
->PEXTDEV
= par
->REGS
+ (0x00101000 / 4);
302 par
->PTIMER
= par
->REGS
+ (0x00009000 / 4);
303 par
->PMC
= par
->REGS
+ (0x00000000 / 4);
304 par
->FIFO
= par
->REGS
+ (0x00800000 / 4);
306 /* 8 bit registers */
307 par
->PCIO0
= (u8 __iomem
*) par
->REGS
+ 0x00601000;
308 par
->PDIO0
= (u8 __iomem
*) par
->REGS
+ 0x00681000;
309 par
->PVIO
= (u8 __iomem
*) par
->REGS
+ 0x000C0000;
311 par
->twoHeads
= (par
->Architecture
>= NV_ARCH_10
) &&
312 (implementation
!= 0x0100) &&
313 (implementation
!= 0x0150) &&
314 (implementation
!= 0x01A0) && (implementation
!= 0x0200);
316 par
->fpScaler
= (par
->FpScale
&& par
->twoHeads
&&
317 (implementation
!= 0x0110));
319 par
->twoStagePLL
= (implementation
== 0x0310) ||
320 (implementation
== 0x0340) || (par
->Architecture
>= NV_ARCH_40
);
322 par
->WaitVSyncPossible
= (par
->Architecture
>= NV_ARCH_10
) &&
323 (implementation
!= 0x0100);
325 par
->BlendingPossible
= ((par
->Chipset
& 0xffff) != 0x0020);
327 /* look for known laptop chips */
328 switch (par
->Chipset
& 0xffff) {
383 if (par
->Architecture
== NV_ARCH_04
)
388 NVSelectHeadRegisters(par
, 0);
390 NVLockUnlock(par
, 0);
392 par
->IOBase
= (NVReadMiscOut(par
) & 0x01) ? 0x3d0 : 0x3b0;
396 nvidia_create_i2c_busses(par
);
397 if (!par
->twoHeads
) {
399 if (nvidia_probe_i2c_connector(info
, 1, &edidA
))
400 nvidia_probe_of_connector(info
, 1, &edidA
);
401 if (edidA
&& !fb_parse_edid(edidA
, var
)) {
402 printk("nvidiafb: EDID found from BUS1\n");
404 fb_edid_to_monspecs(edidA
, monA
);
405 FlatPanel
= (monA
->input
& FB_DISP_DDI
) ? 1 : 0;
407 /* NV4 doesn't support FlatPanels */
408 if ((par
->Chipset
& 0x0fff) <= 0x0020)
411 VGA_WR08(par
->PCIO
, 0x03D4, 0x28);
412 if (VGA_RD08(par
->PCIO
, 0x03D5) & 0x80) {
413 VGA_WR08(par
->PCIO
, 0x03D4, 0x33);
414 if (!(VGA_RD08(par
->PCIO
, 0x03D5) & 0x01))
420 printk("nvidiafb: HW is currently programmed for %s\n",
421 FlatPanel
? (Television
? "TV" : "DFP") :
425 if (par
->FlatPanel
== -1) {
426 par
->FlatPanel
= FlatPanel
;
427 par
->Television
= Television
;
429 printk("nvidiafb: Forcing display type to %s as "
430 "specified\n", par
->FlatPanel
? "DFP" : "CRT");
433 u8 outputAfromCRTC
, outputBfromCRTC
;
435 u8 slaved_on_A
, slaved_on_B
;
436 int analog_on_A
, analog_on_B
;
440 if (implementation
!= 0x0110) {
441 if (NV_RD32(par
->PRAMDAC0
, 0x0000052C) & 0x100)
445 if (NV_RD32(par
->PRAMDAC0
, 0x0000252C) & 0x100)
449 analog_on_A
= NVIsConnected(par
, 0);
450 analog_on_B
= NVIsConnected(par
, 1);
458 VGA_WR08(par
->PCIO
, 0x03D4, 0x44);
459 cr44
= VGA_RD08(par
->PCIO
, 0x03D5);
461 VGA_WR08(par
->PCIO
, 0x03D5, 3);
462 NVSelectHeadRegisters(par
, 1);
463 NVLockUnlock(par
, 0);
465 VGA_WR08(par
->PCIO
, 0x03D4, 0x28);
466 slaved_on_B
= VGA_RD08(par
->PCIO
, 0x03D5) & 0x80;
468 VGA_WR08(par
->PCIO
, 0x03D4, 0x33);
469 tvB
= !(VGA_RD08(par
->PCIO
, 0x03D5) & 0x01);
472 VGA_WR08(par
->PCIO
, 0x03D4, 0x44);
473 VGA_WR08(par
->PCIO
, 0x03D5, 0);
474 NVSelectHeadRegisters(par
, 0);
475 NVLockUnlock(par
, 0);
477 VGA_WR08(par
->PCIO
, 0x03D4, 0x28);
478 slaved_on_A
= VGA_RD08(par
->PCIO
, 0x03D5) & 0x80;
480 VGA_WR08(par
->PCIO
, 0x03D4, 0x33);
481 tvA
= !(VGA_RD08(par
->PCIO
, 0x03D5) & 0x01);
484 oldhead
= NV_RD32(par
->PCRTC0
, 0x00000860);
485 NV_WR32(par
->PCRTC0
, 0x00000860, oldhead
| 0x00000010);
487 if (nvidia_probe_i2c_connector(info
, 1, &edidA
))
488 nvidia_probe_of_connector(info
, 1, &edidA
);
489 if (edidA
&& !fb_parse_edid(edidA
, var
)) {
490 printk("nvidiafb: EDID found from BUS1\n");
492 fb_edid_to_monspecs(edidA
, monA
);
495 if (nvidia_probe_i2c_connector(info
, 2, &edidB
))
496 nvidia_probe_of_connector(info
, 2, &edidB
);
497 if (edidB
&& !fb_parse_edid(edidB
, var
)) {
498 printk("nvidiafb: EDID found from BUS2\n");
500 fb_edid_to_monspecs(edidB
, monB
);
503 if (slaved_on_A
&& !tvA
) {
506 printk("nvidiafb: CRTC 0 is currently programmed for "
508 } else if (slaved_on_B
&& !tvB
) {
511 printk("nvidiafb: CRTC 1 is currently programmed "
513 } else if (analog_on_A
) {
514 CRTCnumber
= outputAfromCRTC
;
516 printk("nvidiafb: CRTC %i appears to have a "
517 "CRT attached\n", CRTCnumber
);
518 } else if (analog_on_B
) {
519 CRTCnumber
= outputBfromCRTC
;
521 printk("nvidiafb: CRTC %i appears to have a "
522 "CRT attached\n", CRTCnumber
);
523 } else if (slaved_on_A
) {
527 printk("nvidiafb: CRTC 0 is currently programmed "
529 } else if (slaved_on_B
) {
533 printk("nvidiafb: CRTC 1 is currently programmed for "
536 FlatPanel
= (monA
->input
& FB_DISP_DDI
) ? 1 : 0;
538 FlatPanel
= (monB
->input
& FB_DISP_DDI
) ? 1 : 0;
541 if (par
->FlatPanel
== -1) {
542 if (FlatPanel
!= -1) {
543 par
->FlatPanel
= FlatPanel
;
544 par
->Television
= Television
;
546 printk("nvidiafb: Unable to detect display "
549 printk("...On a laptop, assuming "
553 printk("...Using default of CRT\n");
558 printk("nvidiafb: Forcing display type to %s as "
559 "specified\n", par
->FlatPanel
? "DFP" : "CRT");
562 if (par
->CRTCnumber
== -1) {
563 if (CRTCnumber
!= -1)
564 par
->CRTCnumber
= CRTCnumber
;
566 printk("nvidiafb: Unable to detect which "
572 printk("...Defaulting to CRTCNumber %i\n",
576 printk("nvidiafb: Forcing CRTCNumber %i as "
577 "specified\n", par
->CRTCnumber
);
581 if (((monA
->input
& FB_DISP_DDI
) &&
583 ((!(monA
->input
& FB_DISP_DDI
)) &&
586 fb_destroy_modedb(monB
->modedb
);
590 fb_destroy_modedb(monA
->modedb
);
596 if (((monB
->input
& FB_DISP_DDI
) &&
598 ((!(monB
->input
& FB_DISP_DDI
)) &&
600 fb_destroy_modedb(monB
->modedb
);
606 if (implementation
== 0x0110)
607 cr44
= par
->CRTCnumber
* 0x3;
609 NV_WR32(par
->PCRTC0
, 0x00000860, oldhead
);
611 VGA_WR08(par
->PCIO
, 0x03D4, 0x44);
612 VGA_WR08(par
->PCIO
, 0x03D5, cr44
);
613 NVSelectHeadRegisters(par
, par
->CRTCnumber
);
616 printk("nvidiafb: Using %s on CRTC %i\n",
617 par
->FlatPanel
? (par
->Television
? "TV" : "DFP") : "CRT",
620 if (par
->FlatPanel
&& !par
->Television
) {
621 par
->fpWidth
= NV_RD32(par
->PRAMDAC
, 0x0820) + 1;
622 par
->fpHeight
= NV_RD32(par
->PRAMDAC
, 0x0800) + 1;
623 par
->fpSyncs
= NV_RD32(par
->PRAMDAC
, 0x0848) & 0x30000033;
625 printk("nvidiafb: Panel size is %i x %i\n", par
->fpWidth
, par
->fpHeight
);
629 info
->monspecs
= *monA
;
631 if (!par
->FlatPanel
|| !par
->twoHeads
)
635 if (par
->FlatPanel
&& par
->twoHeads
) {
636 NV_WR32(par
->PRAMDAC0
, 0x08B0, 0x00010004);
637 if (NV_RD32(par
->PRAMDAC0
, 0x08b4) & 1)
639 printk("nvidiafb: Panel is %s\n", par
->LVDS
? "LVDS" : "TMDS");