nv_setup.c 18 KB

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