📄 nv_setup.c
字号:
/***************************************************************************\|* *||* Copyright 2003 NVIDIA, Corporation. All rights reserved. *||* *||* NOTICE TO USER: The source code is copyrighted under U.S. and *||* international laws. Users and possessors of this source code are *||* hereby granted a nonexclusive, royalty-free copyright license to *||* use this code in individual and commercial software. *||* *||* Any use of this source code must include, in the user documenta- *||* tion and internal comments to the code, notices to the end user *||* as follows: *||* *||* Copyright 2003 NVIDIA, Corporation. All rights reserved. *||* *||* NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY *||* OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" *||* WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. NVIDIA, CORPOR- *||* ATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, *||* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE- *||* MENT, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL *||* NVIDIA, CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT, INCI- *||* DENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RE- *||* SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION *||* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *||* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *||* *||* U.S. Government End Users. This source code is a "commercial *||* item," as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *||* consisting of "commercial computer software" and "commercial *||* computer software documentation," as such terms are used in *||* 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Govern- *||* ment only as a commercial end item. Consistent with 48 C.F.R. *||* 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *||* all U.S. Government End Users acquire the source code with only *||* those rights set forth herein. *||* *| \***************************************************************************//* * GPL Licensing Note - According to Mark Vojkovich, author of the Xorg/ * XFree86 'nv' driver, this source code is provided under MIT-style licensing * where the source code is provided "as is" without warranty of any kind. * The only usage restriction is for the copyright notices to be retained * whenever code is used. * * Antonino Daplas <adaplas@pol.net> 2005-03-11 */#include <video/vga.h>#include <linux/delay.h>#include <linux/pci.h>#include "nv_type.h"#include "nv_local.h"#include "nv_proto.h"/* * Override VGA I/O routines. */void NVWriteCrtc(struct nvidia_par *par, u8 index, u8 value){ VGA_WR08(par->PCIO, par->IOBase + 0x04, index); VGA_WR08(par->PCIO, par->IOBase + 0x05, value);}u8 NVReadCrtc(struct nvidia_par *par, u8 index){ VGA_WR08(par->PCIO, par->IOBase + 0x04, index); return (VGA_RD08(par->PCIO, par->IOBase + 0x05));}void NVWriteGr(struct nvidia_par *par, u8 index, u8 value){ VGA_WR08(par->PVIO, VGA_GFX_I, index); VGA_WR08(par->PVIO, VGA_GFX_D, value);}u8 NVReadGr(struct nvidia_par *par, u8 index){ VGA_WR08(par->PVIO, VGA_GFX_I, index); return (VGA_RD08(par->PVIO, VGA_GFX_D));}void NVWriteSeq(struct nvidia_par *par, u8 index, u8 value){ VGA_WR08(par->PVIO, VGA_SEQ_I, index); VGA_WR08(par->PVIO, VGA_SEQ_D, value);}u8 NVReadSeq(struct nvidia_par *par, u8 index){ VGA_WR08(par->PVIO, VGA_SEQ_I, index); return (VGA_RD08(par->PVIO, VGA_SEQ_D));}void NVWriteAttr(struct nvidia_par *par, u8 index, u8 value){ volatile u8 tmp; tmp = VGA_RD08(par->PCIO, par->IOBase + 0x0a); if (par->paletteEnabled) index &= ~0x20; else index |= 0x20; VGA_WR08(par->PCIO, VGA_ATT_IW, index); VGA_WR08(par->PCIO, VGA_ATT_W, value);}u8 NVReadAttr(struct nvidia_par *par, u8 index){ volatile u8 tmp; tmp = VGA_RD08(par->PCIO, par->IOBase + 0x0a); if (par->paletteEnabled) index &= ~0x20; else index |= 0x20; VGA_WR08(par->PCIO, VGA_ATT_IW, index); return (VGA_RD08(par->PCIO, VGA_ATT_R));}void NVWriteMiscOut(struct nvidia_par *par, u8 value){ VGA_WR08(par->PVIO, VGA_MIS_W, value);}u8 NVReadMiscOut(struct nvidia_par *par){ return (VGA_RD08(par->PVIO, VGA_MIS_R));}#if 0void NVEnablePalette(struct nvidia_par *par){ volatile u8 tmp; tmp = VGA_RD08(par->PCIO, par->IOBase + 0x0a); VGA_WR08(par->PCIO, VGA_ATT_IW, 0x00); par->paletteEnabled = 1;}void NVDisablePalette(struct nvidia_par *par){ volatile u8 tmp; tmp = VGA_RD08(par->PCIO, par->IOBase + 0x0a); VGA_WR08(par->PCIO, VGA_ATT_IW, 0x20); par->paletteEnabled = 0;}#endif /* 0 */void NVWriteDacMask(struct nvidia_par *par, u8 value){ VGA_WR08(par->PDIO, VGA_PEL_MSK, value);}#if 0u8 NVReadDacMask(struct nvidia_par *par){ return (VGA_RD08(par->PDIO, VGA_PEL_MSK));}#endif /* 0 */void NVWriteDacReadAddr(struct nvidia_par *par, u8 value){ VGA_WR08(par->PDIO, VGA_PEL_IR, value);}void NVWriteDacWriteAddr(struct nvidia_par *par, u8 value){ VGA_WR08(par->PDIO, VGA_PEL_IW, value);}void NVWriteDacData(struct nvidia_par *par, u8 value){ VGA_WR08(par->PDIO, VGA_PEL_D, value);}u8 NVReadDacData(struct nvidia_par *par){ return (VGA_RD08(par->PDIO, VGA_PEL_D));}static int NVIsConnected(struct nvidia_par *par, int output){ volatile u32 __iomem *PRAMDAC = par->PRAMDAC0; u32 reg52C, reg608; int present; if (output) PRAMDAC += 0x800; reg52C = NV_RD32(PRAMDAC, 0x052C); reg608 = NV_RD32(PRAMDAC, 0x0608); NV_WR32(PRAMDAC, 0x0608, reg608 & ~0x00010000); NV_WR32(PRAMDAC, 0x052C, reg52C & 0x0000FEEE); msleep(1); NV_WR32(PRAMDAC, 0x052C, NV_RD32(PRAMDAC, 0x052C) | 1); NV_WR32(par->PRAMDAC0, 0x0610, 0x94050140); NV_WR32(par->PRAMDAC0, 0x0608, NV_RD32(par->PRAMDAC0, 0x0608) | 0x00001000); msleep(1); present = (NV_RD32(PRAMDAC, 0x0608) & (1 << 28)) ? 1 : 0; if (present) printk("nvidiafb: CRTC%i analog found\n", output); else printk("nvidiafb: CRTC%i analog not found\n", output); NV_WR32(par->PRAMDAC0, 0x0608, NV_RD32(par->PRAMDAC0, 0x0608) & 0x0000EFFF); NV_WR32(PRAMDAC, 0x052C, reg52C); NV_WR32(PRAMDAC, 0x0608, reg608); return present;}static void NVSelectHeadRegisters(struct nvidia_par *par, int head){ if (head) { par->PCIO = par->PCIO0 + 0x2000; par->PCRTC = par->PCRTC0 + 0x800; par->PRAMDAC = par->PRAMDAC0 + 0x800; par->PDIO = par->PDIO0 + 0x2000; } else { par->PCIO = par->PCIO0; par->PCRTC = par->PCRTC0; par->PRAMDAC = par->PRAMDAC0; par->PDIO = par->PDIO0; }}static void nv4GetConfig(struct nvidia_par *par){ if (NV_RD32(par->PFB, 0x0000) & 0x00000100) { par->RamAmountKBytes = ((NV_RD32(par->PFB, 0x0000) >> 12) & 0x0F) * 1024 * 2 + 1024 * 2; } else { switch (NV_RD32(par->PFB, 0x0000) & 0x00000003) { case 0: par->RamAmountKBytes = 1024 * 32; break; case 1: par->RamAmountKBytes = 1024 * 4; break; case 2: par->RamAmountKBytes = 1024 * 8; break; case 3: default: par->RamAmountKBytes = 1024 * 16; break; } } par->CrystalFreqKHz = (NV_RD32(par->PEXTDEV, 0x0000) & 0x00000040) ? 14318 : 13500; par->CURSOR = &par->PRAMIN[0x1E00]; par->MinVClockFreqKHz = 12000; par->MaxVClockFreqKHz = 350000;}static void nv10GetConfig(struct nvidia_par *par){ struct pci_dev *dev; u32 implementation = par->Chipset & 0x0ff0;#ifdef __BIG_ENDIAN /* turn on big endian register access */ if (!(NV_RD32(par->PMC, 0x0004) & 0x01000001)) { NV_WR32(par->PMC, 0x0004, 0x01000001); mb(); }#endif dev = pci_find_slot(0, 1); if ((par->Chipset && 0xffff) == 0x01a0) { int amt = 0; pci_read_config_dword(dev, 0x7c, &amt); par->RamAmountKBytes = (((amt >> 6) & 31) + 1) * 1024; } else if ((par->Chipset & 0xffff) == 0x01f0) { int amt = 0; pci_read_config_dword(dev, 0x84, &amt); par->RamAmountKBytes = (((amt >> 4) & 127) + 1) * 1024; } else { par->RamAmountKBytes = (NV_RD32(par->PFB, 0x020C) & 0xFFF00000) >> 10; } par->CrystalFreqKHz = (NV_RD32(par->PEXTDEV, 0x0000) & (1 << 6)) ? 14318 : 13500; if (par->twoHeads && (implementation != 0x0110)) { if (NV_RD32(par->PEXTDEV, 0x0000) & (1 << 22)) par->CrystalFreqKHz = 27000; } par->CursorStart = (par->RamAmountKBytes - 96) * 1024; par->CURSOR = NULL; /* can't set this here */ par->MinVClockFreqKHz = 12000; par->MaxVClockFreqKHz = par->twoStagePLL ? 400000 : 350000;}void NVCommonSetup(struct fb_info *info){ struct nvidia_par *par = info->par; struct fb_var_screeninfo var; u16 implementation = par->Chipset & 0x0ff0; u8 *edidA = NULL, *edidB = NULL; struct fb_monspecs monitorA, monitorB; struct fb_monspecs *monA = NULL, *monB = NULL; int mobile = 0; int tvA = 0; int tvB = 0; int FlatPanel = -1; /* really means the CRTC is slaved */ int Television = 0; memset(&monitorA, 0, sizeof(struct fb_monspecs)); memset(&monitorB, 0, sizeof(struct fb_monspecs)); par->PRAMIN = par->REGS + (0x00710000 / 4); par->PCRTC0 = par->REGS + (0x00600000 / 4); par->PRAMDAC0 = par->REGS + (0x00680000 / 4); par->PFB = par->REGS + (0x00100000 / 4); par->PFIFO = par->REGS + (0x00002000 / 4); par->PGRAPH = par->REGS + (0x00400000 / 4); par->PEXTDEV = par->REGS + (0x00101000 / 4); par->PTIMER = par->REGS + (0x00009000 / 4); par->PMC = par->REGS + (0x00000000 / 4); par->FIFO = par->REGS + (0x00800000 / 4); /* 8 bit registers */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -