nv_setup.c 18 KB

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