PageRenderTime 1012ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/video/nvidia/nv_setup.c

https://github.com/Mengqi/linux-2.6
C | 675 lines | 550 code | 71 blank | 54 comment | 113 complexity | 072e9d914908a5636b1dd8e91ee95fa0 MD5 | raw file
  1. /***************************************************************************\
  2. |* *|
  3. |* Copyright 2003 NVIDIA, Corporation. All rights reserved. *|
  4. |* *|
  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. *|
  9. |* *|
  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 *|
  12. |* as follows: *|
  13. |* *|
  14. |* Copyright 2003 NVIDIA, Corporation. All rights reserved. *|
  15. |* *|
  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. *|
  27. |* *|
  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. *|
  37. |* *|
  38. \***************************************************************************/
  39. /*
  40. * GPL Licensing Note - According to Mark Vojkovich, author of the Xorg/
  41. * XFree86 'nv' driver, this source code is provided under MIT-style licensing
  42. * where the source code is provided "as is" without warranty of any kind.
  43. * The only usage restriction is for the copyright notices to be retained
  44. * whenever code is used.
  45. *
  46. * Antonino Daplas <adaplas@pol.net> 2005-03-11
  47. */
  48. #include <video/vga.h>
  49. #include <linux/delay.h>
  50. #include <linux/pci.h>
  51. #include <linux/slab.h>
  52. #include "nv_type.h"
  53. #include "nv_local.h"
  54. #include "nv_proto.h"
  55. /*
  56. * Override VGA I/O routines.
  57. */
  58. void NVWriteCrtc(struct nvidia_par *par, u8 index, u8 value)
  59. {
  60. VGA_WR08(par->PCIO, par->IOBase + 0x04, index);
  61. VGA_WR08(par->PCIO, par->IOBase + 0x05, value);
  62. }
  63. u8 NVReadCrtc(struct nvidia_par *par, u8 index)
  64. {
  65. VGA_WR08(par->PCIO, par->IOBase + 0x04, index);
  66. return (VGA_RD08(par->PCIO, par->IOBase + 0x05));
  67. }
  68. void NVWriteGr(struct nvidia_par *par, u8 index, u8 value)
  69. {
  70. VGA_WR08(par->PVIO, VGA_GFX_I, index);
  71. VGA_WR08(par->PVIO, VGA_GFX_D, value);
  72. }
  73. u8 NVReadGr(struct nvidia_par *par, u8 index)
  74. {
  75. VGA_WR08(par->PVIO, VGA_GFX_I, index);
  76. return (VGA_RD08(par->PVIO, VGA_GFX_D));
  77. }
  78. void NVWriteSeq(struct nvidia_par *par, u8 index, u8 value)
  79. {
  80. VGA_WR08(par->PVIO, VGA_SEQ_I, index);
  81. VGA_WR08(par->PVIO, VGA_SEQ_D, value);
  82. }
  83. u8 NVReadSeq(struct nvidia_par *par, u8 index)
  84. {
  85. VGA_WR08(par->PVIO, VGA_SEQ_I, index);
  86. return (VGA_RD08(par->PVIO, VGA_SEQ_D));
  87. }
  88. void NVWriteAttr(struct nvidia_par *par, u8 index, u8 value)
  89. {
  90. volatile u8 tmp;
  91. tmp = VGA_RD08(par->PCIO, par->IOBase + 0x0a);
  92. if (par->paletteEnabled)
  93. index &= ~0x20;
  94. else
  95. index |= 0x20;
  96. VGA_WR08(par->PCIO, VGA_ATT_IW, index);
  97. VGA_WR08(par->PCIO, VGA_ATT_W, value);
  98. }
  99. u8 NVReadAttr(struct nvidia_par *par, u8 index)
  100. {
  101. volatile u8 tmp;
  102. tmp = VGA_RD08(par->PCIO, par->IOBase + 0x0a);
  103. if (par->paletteEnabled)
  104. index &= ~0x20;
  105. else
  106. index |= 0x20;
  107. VGA_WR08(par->PCIO, VGA_ATT_IW, index);
  108. return (VGA_RD08(par->PCIO, VGA_ATT_R));
  109. }
  110. void NVWriteMiscOut(struct nvidia_par *par, u8 value)
  111. {
  112. VGA_WR08(par->PVIO, VGA_MIS_W, value);
  113. }
  114. u8 NVReadMiscOut(struct nvidia_par *par)
  115. {
  116. return (VGA_RD08(par->PVIO, VGA_MIS_R));
  117. }
  118. #if 0
  119. void NVEnablePalette(struct nvidia_par *par)
  120. {
  121. volatile u8 tmp;
  122. tmp = VGA_RD08(par->PCIO, par->IOBase + 0x0a);
  123. VGA_WR08(par->PCIO, VGA_ATT_IW, 0x00);
  124. par->paletteEnabled = 1;
  125. }
  126. void NVDisablePalette(struct nvidia_par *par)
  127. {
  128. volatile u8 tmp;
  129. tmp = VGA_RD08(par->PCIO, par->IOBase + 0x0a);
  130. VGA_WR08(par->PCIO, VGA_ATT_IW, 0x20);
  131. par->paletteEnabled = 0;
  132. }
  133. #endif /* 0 */
  134. void NVWriteDacMask(struct nvidia_par *par, u8 value)
  135. {
  136. VGA_WR08(par->PDIO, VGA_PEL_MSK, value);
  137. }
  138. #if 0
  139. u8 NVReadDacMask(struct nvidia_par *par)
  140. {
  141. return (VGA_RD08(par->PDIO, VGA_PEL_MSK));
  142. }
  143. #endif /* 0 */
  144. void NVWriteDacReadAddr(struct nvidia_par *par, u8 value)
  145. {
  146. VGA_WR08(par->PDIO, VGA_PEL_IR, value);
  147. }
  148. void NVWriteDacWriteAddr(struct nvidia_par *par, u8 value)
  149. {
  150. VGA_WR08(par->PDIO, VGA_PEL_IW, value);
  151. }
  152. void NVWriteDacData(struct nvidia_par *par, u8 value)
  153. {
  154. VGA_WR08(par->PDIO, VGA_PEL_D, value);
  155. }
  156. u8 NVReadDacData(struct nvidia_par *par)
  157. {
  158. return (VGA_RD08(par->PDIO, VGA_PEL_D));
  159. }
  160. static int NVIsConnected(struct nvidia_par *par, int output)
  161. {
  162. volatile u32 __iomem *PRAMDAC = par->PRAMDAC0;
  163. u32 reg52C, reg608, dac0_reg608 = 0;
  164. int present;
  165. if (output) {
  166. dac0_reg608 = NV_RD32(PRAMDAC, 0x0608);
  167. PRAMDAC += 0x800;
  168. }
  169. reg52C = NV_RD32(PRAMDAC, 0x052C);
  170. reg608 = NV_RD32(PRAMDAC, 0x0608);
  171. NV_WR32(PRAMDAC, 0x0608, reg608 & ~0x00010000);
  172. NV_WR32(PRAMDAC, 0x052C, reg52C & 0x0000FEEE);
  173. msleep(1);
  174. NV_WR32(PRAMDAC, 0x052C, NV_RD32(PRAMDAC, 0x052C) | 1);
  175. NV_WR32(par->PRAMDAC0, 0x0610, 0x94050140);
  176. NV_WR32(par->PRAMDAC0, 0x0608, NV_RD32(par->PRAMDAC0, 0x0608) |
  177. 0x00001000);
  178. msleep(1);
  179. present = (NV_RD32(PRAMDAC, 0x0608) & (1 << 28)) ? 1 : 0;
  180. if (present)
  181. printk("nvidiafb: CRTC%i analog found\n", output);
  182. else
  183. printk("nvidiafb: CRTC%i analog not found\n", output);
  184. if (output)
  185. NV_WR32(par->PRAMDAC0, 0x0608, dac0_reg608);
  186. NV_WR32(PRAMDAC, 0x052C, reg52C);
  187. NV_WR32(PRAMDAC, 0x0608, reg608);
  188. return present;
  189. }
  190. static void NVSelectHeadRegisters(struct nvidia_par *par, int head)
  191. {
  192. if (head) {
  193. par->PCIO = par->PCIO0 + 0x2000;
  194. par->PCRTC = par->PCRTC0 + 0x800;
  195. par->PRAMDAC = par->PRAMDAC0 + 0x800;
  196. par->PDIO = par->PDIO0 + 0x2000;
  197. } else {
  198. par->PCIO = par->PCIO0;
  199. par->PCRTC = par->PCRTC0;
  200. par->PRAMDAC = par->PRAMDAC0;
  201. par->PDIO = par->PDIO0;
  202. }
  203. }
  204. static void nv4GetConfig(struct nvidia_par *par)
  205. {
  206. if (NV_RD32(par->PFB, 0x0000) & 0x00000100) {
  207. par->RamAmountKBytes =
  208. ((NV_RD32(par->PFB, 0x0000) >> 12) & 0x0F) * 1024 * 2 +
  209. 1024 * 2;
  210. } else {
  211. switch (NV_RD32(par->PFB, 0x0000) & 0x00000003) {
  212. case 0:
  213. par->RamAmountKBytes = 1024 * 32;
  214. break;
  215. case 1:
  216. par->RamAmountKBytes = 1024 * 4;
  217. break;
  218. case 2:
  219. par->RamAmountKBytes = 1024 * 8;
  220. break;
  221. case 3:
  222. default:
  223. par->RamAmountKBytes = 1024 * 16;
  224. break;
  225. }
  226. }
  227. par->CrystalFreqKHz = (NV_RD32(par->PEXTDEV, 0x0000) & 0x00000040) ?
  228. 14318 : 13500;
  229. par->CURSOR = &par->PRAMIN[0x1E00];
  230. par->MinVClockFreqKHz = 12000;
  231. par->MaxVClockFreqKHz = 350000;
  232. }
  233. static void nv10GetConfig(struct nvidia_par *par)
  234. {
  235. struct pci_dev *dev;
  236. u32 implementation = par->Chipset & 0x0ff0;
  237. #ifdef __BIG_ENDIAN
  238. /* turn on big endian register access */
  239. if (!(NV_RD32(par->PMC, 0x0004) & 0x01000001)) {
  240. NV_WR32(par->PMC, 0x0004, 0x01000001);
  241. mb();
  242. }
  243. #endif
  244. dev = pci_get_bus_and_slot(0, 1);
  245. if ((par->Chipset & 0xffff) == 0x01a0) {
  246. u32 amt;
  247. pci_read_config_dword(dev, 0x7c, &amt);
  248. par->RamAmountKBytes = (((amt >> 6) & 31) + 1) * 1024;
  249. } else if ((par->Chipset & 0xffff) == 0x01f0) {
  250. u32 amt;
  251. pci_read_config_dword(dev, 0x84, &amt);
  252. par->RamAmountKBytes = (((amt >> 4) & 127) + 1) * 1024;
  253. } else {
  254. par->RamAmountKBytes =
  255. (NV_RD32(par->PFB, 0x020C) & 0xFFF00000) >> 10;
  256. }
  257. pci_dev_put(dev);
  258. par->CrystalFreqKHz = (NV_RD32(par->PEXTDEV, 0x0000) & (1 << 6)) ?
  259. 14318 : 13500;
  260. if (par->twoHeads && (implementation != 0x0110)) {
  261. if (NV_RD32(par->PEXTDEV, 0x0000) & (1 << 22))
  262. par->CrystalFreqKHz = 27000;
  263. }
  264. par->CURSOR = NULL; /* can't set this here */
  265. par->MinVClockFreqKHz = 12000;
  266. par->MaxVClockFreqKHz = par->twoStagePLL ? 400000 : 350000;
  267. }
  268. int NVCommonSetup(struct fb_info *info)
  269. {
  270. struct nvidia_par *par = info->par;
  271. struct fb_var_screeninfo *var;
  272. u16 implementation = par->Chipset & 0x0ff0;
  273. u8 *edidA = NULL, *edidB = NULL;
  274. struct fb_monspecs *monitorA, *monitorB;
  275. struct fb_monspecs *monA = NULL, *monB = NULL;
  276. int mobile = 0;
  277. int tvA = 0;
  278. int tvB = 0;
  279. int FlatPanel = -1; /* really means the CRTC is slaved */
  280. int Television = 0;
  281. int err = 0;
  282. var = kzalloc(sizeof(struct fb_var_screeninfo), GFP_KERNEL);
  283. monitorA = kzalloc(sizeof(struct fb_monspecs), GFP_KERNEL);
  284. monitorB = kzalloc(sizeof(struct fb_monspecs), GFP_KERNEL);
  285. if (!var || !monitorA || !monitorB) {
  286. err = -ENOMEM;
  287. goto done;
  288. }
  289. par->PRAMIN = par->REGS + (0x00710000 / 4);
  290. par->PCRTC0 = par->REGS + (0x00600000 / 4);
  291. par->PRAMDAC0 = par->REGS + (0x00680000 / 4);
  292. par->PFB = par->REGS + (0x00100000 / 4);
  293. par->PFIFO = par->REGS + (0x00002000 / 4);
  294. par->PGRAPH = par->REGS + (0x00400000 / 4);
  295. par->PEXTDEV = par->REGS + (0x00101000 / 4);
  296. par->PTIMER = par->REGS + (0x00009000 / 4);
  297. par->PMC = par->REGS + (0x00000000 / 4);
  298. par->FIFO = par->REGS + (0x00800000 / 4);
  299. /* 8 bit registers */
  300. par->PCIO0 = (u8 __iomem *) par->REGS + 0x00601000;
  301. par->PDIO0 = (u8 __iomem *) par->REGS + 0x00681000;
  302. par->PVIO = (u8 __iomem *) par->REGS + 0x000C0000;
  303. par->twoHeads = (par->Architecture >= NV_ARCH_10) &&
  304. (implementation != 0x0100) &&
  305. (implementation != 0x0150) &&
  306. (implementation != 0x01A0) && (implementation != 0x0200);
  307. par->fpScaler = (par->FpScale && par->twoHeads &&
  308. (implementation != 0x0110));
  309. par->twoStagePLL = (implementation == 0x0310) ||
  310. (implementation == 0x0340) || (par->Architecture >= NV_ARCH_40);
  311. par->WaitVSyncPossible = (par->Architecture >= NV_ARCH_10) &&
  312. (implementation != 0x0100);
  313. par->BlendingPossible = ((par->Chipset & 0xffff) != 0x0020);
  314. /* look for known laptop chips */
  315. switch (par->Chipset & 0xffff) {
  316. case 0x0112:
  317. case 0x0174:
  318. case 0x0175:
  319. case 0x0176:
  320. case 0x0177:
  321. case 0x0179:
  322. case 0x017C:
  323. case 0x017D:
  324. case 0x0186:
  325. case 0x0187:
  326. case 0x018D:
  327. case 0x01D7:
  328. case 0x0228:
  329. case 0x0286:
  330. case 0x028C:
  331. case 0x0316:
  332. case 0x0317:
  333. case 0x031A:
  334. case 0x031B:
  335. case 0x031C:
  336. case 0x031D:
  337. case 0x031E:
  338. case 0x031F:
  339. case 0x0324:
  340. case 0x0325:
  341. case 0x0328:
  342. case 0x0329:
  343. case 0x032C:
  344. case 0x032D:
  345. case 0x0347:
  346. case 0x0348:
  347. case 0x0349:
  348. case 0x034B:
  349. case 0x034C:
  350. case 0x0160:
  351. case 0x0166:
  352. case 0x0169:
  353. case 0x016B:
  354. case 0x016C:
  355. case 0x016D:
  356. case 0x00C8:
  357. case 0x00CC:
  358. case 0x0144:
  359. case 0x0146:
  360. case 0x0147:
  361. case 0x0148:
  362. case 0x0098:
  363. case 0x0099:
  364. mobile = 1;
  365. break;
  366. default:
  367. break;
  368. }
  369. if (par->Architecture == NV_ARCH_04)
  370. nv4GetConfig(par);
  371. else
  372. nv10GetConfig(par);
  373. NVSelectHeadRegisters(par, 0);
  374. NVLockUnlock(par, 0);
  375. par->IOBase = (NVReadMiscOut(par) & 0x01) ? 0x3d0 : 0x3b0;
  376. par->Television = 0;
  377. nvidia_create_i2c_busses(par);
  378. if (!par->twoHeads) {
  379. par->CRTCnumber = 0;
  380. if (nvidia_probe_i2c_connector(info, 1, &edidA))
  381. nvidia_probe_of_connector(info, 1, &edidA);
  382. if (edidA && !fb_parse_edid(edidA, var)) {
  383. printk("nvidiafb: EDID found from BUS1\n");
  384. monA = monitorA;
  385. fb_edid_to_monspecs(edidA, monA);
  386. FlatPanel = (monA->input & FB_DISP_DDI) ? 1 : 0;
  387. /* NV4 doesn't support FlatPanels */
  388. if ((par->Chipset & 0x0fff) <= 0x0020)
  389. FlatPanel = 0;
  390. } else {
  391. VGA_WR08(par->PCIO, 0x03D4, 0x28);
  392. if (VGA_RD08(par->PCIO, 0x03D5) & 0x80) {
  393. VGA_WR08(par->PCIO, 0x03D4, 0x33);
  394. if (!(VGA_RD08(par->PCIO, 0x03D5) & 0x01))
  395. Television = 1;
  396. FlatPanel = 1;
  397. } else {
  398. FlatPanel = 0;
  399. }
  400. printk("nvidiafb: HW is currently programmed for %s\n",
  401. FlatPanel ? (Television ? "TV" : "DFP") :
  402. "CRT");
  403. }
  404. if (par->FlatPanel == -1) {
  405. par->FlatPanel = FlatPanel;
  406. par->Television = Television;
  407. } else {
  408. printk("nvidiafb: Forcing display type to %s as "
  409. "specified\n", par->FlatPanel ? "DFP" : "CRT");
  410. }
  411. } else {
  412. u8 outputAfromCRTC, outputBfromCRTC;
  413. int CRTCnumber = -1;
  414. u8 slaved_on_A, slaved_on_B;
  415. int analog_on_A, analog_on_B;
  416. u32 oldhead;
  417. u8 cr44;
  418. if (implementation != 0x0110) {
  419. if (NV_RD32(par->PRAMDAC0, 0x0000052C) & 0x100)
  420. outputAfromCRTC = 1;
  421. else
  422. outputAfromCRTC = 0;
  423. if (NV_RD32(par->PRAMDAC0, 0x0000252C) & 0x100)
  424. outputBfromCRTC = 1;
  425. else
  426. outputBfromCRTC = 0;
  427. analog_on_A = NVIsConnected(par, 0);
  428. analog_on_B = NVIsConnected(par, 1);
  429. } else {
  430. outputAfromCRTC = 0;
  431. outputBfromCRTC = 1;
  432. analog_on_A = 0;
  433. analog_on_B = 0;
  434. }
  435. VGA_WR08(par->PCIO, 0x03D4, 0x44);
  436. cr44 = VGA_RD08(par->PCIO, 0x03D5);
  437. VGA_WR08(par->PCIO, 0x03D5, 3);
  438. NVSelectHeadRegisters(par, 1);
  439. NVLockUnlock(par, 0);
  440. VGA_WR08(par->PCIO, 0x03D4, 0x28);
  441. slaved_on_B = VGA_RD08(par->PCIO, 0x03D5) & 0x80;
  442. if (slaved_on_B) {
  443. VGA_WR08(par->PCIO, 0x03D4, 0x33);
  444. tvB = !(VGA_RD08(par->PCIO, 0x03D5) & 0x01);
  445. }
  446. VGA_WR08(par->PCIO, 0x03D4, 0x44);
  447. VGA_WR08(par->PCIO, 0x03D5, 0);
  448. NVSelectHeadRegisters(par, 0);
  449. NVLockUnlock(par, 0);
  450. VGA_WR08(par->PCIO, 0x03D4, 0x28);
  451. slaved_on_A = VGA_RD08(par->PCIO, 0x03D5) & 0x80;
  452. if (slaved_on_A) {
  453. VGA_WR08(par->PCIO, 0x03D4, 0x33);
  454. tvA = !(VGA_RD08(par->PCIO, 0x03D5) & 0x01);
  455. }
  456. oldhead = NV_RD32(par->PCRTC0, 0x00000860);
  457. NV_WR32(par->PCRTC0, 0x00000860, oldhead | 0x00000010);
  458. if (nvidia_probe_i2c_connector(info, 1, &edidA))
  459. nvidia_probe_of_connector(info, 1, &edidA);
  460. if (edidA && !fb_parse_edid(edidA, var)) {
  461. printk("nvidiafb: EDID found from BUS1\n");
  462. monA = monitorA;
  463. fb_edid_to_monspecs(edidA, monA);
  464. }
  465. if (nvidia_probe_i2c_connector(info, 2, &edidB))
  466. nvidia_probe_of_connector(info, 2, &edidB);
  467. if (edidB && !fb_parse_edid(edidB, var)) {
  468. printk("nvidiafb: EDID found from BUS2\n");
  469. monB = monitorB;
  470. fb_edid_to_monspecs(edidB, monB);
  471. }
  472. if (slaved_on_A && !tvA) {
  473. CRTCnumber = 0;
  474. FlatPanel = 1;
  475. printk("nvidiafb: CRTC 0 is currently programmed for "
  476. "DFP\n");
  477. } else if (slaved_on_B && !tvB) {
  478. CRTCnumber = 1;
  479. FlatPanel = 1;
  480. printk("nvidiafb: CRTC 1 is currently programmed "
  481. "for DFP\n");
  482. } else if (analog_on_A) {
  483. CRTCnumber = outputAfromCRTC;
  484. FlatPanel = 0;
  485. printk("nvidiafb: CRTC %i appears to have a "
  486. "CRT attached\n", CRTCnumber);
  487. } else if (analog_on_B) {
  488. CRTCnumber = outputBfromCRTC;
  489. FlatPanel = 0;
  490. printk("nvidiafb: CRTC %i appears to have a "
  491. "CRT attached\n", CRTCnumber);
  492. } else if (slaved_on_A) {
  493. CRTCnumber = 0;
  494. FlatPanel = 1;
  495. Television = 1;
  496. printk("nvidiafb: CRTC 0 is currently programmed "
  497. "for TV\n");
  498. } else if (slaved_on_B) {
  499. CRTCnumber = 1;
  500. FlatPanel = 1;
  501. Television = 1;
  502. printk("nvidiafb: CRTC 1 is currently programmed for "
  503. "TV\n");
  504. } else if (monA) {
  505. FlatPanel = (monA->input & FB_DISP_DDI) ? 1 : 0;
  506. } else if (monB) {
  507. FlatPanel = (monB->input & FB_DISP_DDI) ? 1 : 0;
  508. }
  509. if (par->FlatPanel == -1) {
  510. if (FlatPanel != -1) {
  511. par->FlatPanel = FlatPanel;
  512. par->Television = Television;
  513. } else {
  514. printk("nvidiafb: Unable to detect display "
  515. "type...\n");
  516. if (mobile) {
  517. printk("...On a laptop, assuming "
  518. "DFP\n");
  519. par->FlatPanel = 1;
  520. } else {
  521. printk("...Using default of CRT\n");
  522. par->FlatPanel = 0;
  523. }
  524. }
  525. } else {
  526. printk("nvidiafb: Forcing display type to %s as "
  527. "specified\n", par->FlatPanel ? "DFP" : "CRT");
  528. }
  529. if (par->CRTCnumber == -1) {
  530. if (CRTCnumber != -1)
  531. par->CRTCnumber = CRTCnumber;
  532. else {
  533. printk("nvidiafb: Unable to detect which "
  534. "CRTCNumber...\n");
  535. if (par->FlatPanel)
  536. par->CRTCnumber = 1;
  537. else
  538. par->CRTCnumber = 0;
  539. printk("...Defaulting to CRTCNumber %i\n",
  540. par->CRTCnumber);
  541. }
  542. } else {
  543. printk("nvidiafb: Forcing CRTCNumber %i as "
  544. "specified\n", par->CRTCnumber);
  545. }
  546. if (monA) {
  547. if (((monA->input & FB_DISP_DDI) &&
  548. par->FlatPanel) ||
  549. ((!(monA->input & FB_DISP_DDI)) &&
  550. !par->FlatPanel)) {
  551. if (monB) {
  552. fb_destroy_modedb(monB->modedb);
  553. monB = NULL;
  554. }
  555. } else {
  556. fb_destroy_modedb(monA->modedb);
  557. monA = NULL;
  558. }
  559. }
  560. if (monB) {
  561. if (((monB->input & FB_DISP_DDI) &&
  562. !par->FlatPanel) ||
  563. ((!(monB->input & FB_DISP_DDI)) &&
  564. par->FlatPanel)) {
  565. fb_destroy_modedb(monB->modedb);
  566. monB = NULL;
  567. } else
  568. monA = monB;
  569. }
  570. if (implementation == 0x0110)
  571. cr44 = par->CRTCnumber * 0x3;
  572. NV_WR32(par->PCRTC0, 0x00000860, oldhead);
  573. VGA_WR08(par->PCIO, 0x03D4, 0x44);
  574. VGA_WR08(par->PCIO, 0x03D5, cr44);
  575. NVSelectHeadRegisters(par, par->CRTCnumber);
  576. }
  577. printk("nvidiafb: Using %s on CRTC %i\n",
  578. par->FlatPanel ? (par->Television ? "TV" : "DFP") : "CRT",
  579. par->CRTCnumber);
  580. if (par->FlatPanel && !par->Television) {
  581. par->fpWidth = NV_RD32(par->PRAMDAC, 0x0820) + 1;
  582. par->fpHeight = NV_RD32(par->PRAMDAC, 0x0800) + 1;
  583. par->fpSyncs = NV_RD32(par->PRAMDAC, 0x0848) & 0x30000033;
  584. printk("nvidiafb: Panel size is %i x %i\n", par->fpWidth, par->fpHeight);
  585. }
  586. if (monA)
  587. info->monspecs = *monA;
  588. if (!par->FlatPanel || !par->twoHeads)
  589. par->FPDither = 0;
  590. par->LVDS = 0;
  591. if (par->FlatPanel && par->twoHeads) {
  592. NV_WR32(par->PRAMDAC0, 0x08B0, 0x00010004);
  593. if (NV_RD32(par->PRAMDAC0, 0x08b4) & 1)
  594. par->LVDS = 1;
  595. printk("nvidiafb: Panel is %s\n", par->LVDS ? "LVDS" : "TMDS");
  596. }
  597. kfree(edidA);
  598. kfree(edidB);
  599. done:
  600. kfree(var);
  601. kfree(monitorA);
  602. kfree(monitorB);
  603. return err;
  604. }