radeon_monitor.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. #include "radeonfb.h"
  2. #include <linux/slab.h>
  3. #include "../edid.h"
  4. static struct fb_var_screeninfo radeonfb_default_var = {
  5. .xres = 640,
  6. .yres = 480,
  7. .xres_virtual = 640,
  8. .yres_virtual = 480,
  9. .bits_per_pixel = 8,
  10. .red = { .length = 8 },
  11. .green = { .length = 8 },
  12. .blue = { .length = 8 },
  13. .activate = FB_ACTIVATE_NOW,
  14. .height = -1,
  15. .width = -1,
  16. .pixclock = 39721,
  17. .left_margin = 40,
  18. .right_margin = 24,
  19. .upper_margin = 32,
  20. .lower_margin = 11,
  21. .hsync_len = 96,
  22. .vsync_len = 2,
  23. .vmode = FB_VMODE_NONINTERLACED
  24. };
  25. static char *radeon_get_mon_name(int type)
  26. {
  27. char *pret = NULL;
  28. switch (type) {
  29. case MT_NONE:
  30. pret = "no";
  31. break;
  32. case MT_CRT:
  33. pret = "CRT";
  34. break;
  35. case MT_DFP:
  36. pret = "DFP";
  37. break;
  38. case MT_LCD:
  39. pret = "LCD";
  40. break;
  41. case MT_CTV:
  42. pret = "CTV";
  43. break;
  44. case MT_STV:
  45. pret = "STV";
  46. break;
  47. }
  48. return pret;
  49. }
  50. #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
  51. /*
  52. * Try to find monitor informations & EDID data out of the Open Firmware
  53. * device-tree. This also contains some "hacks" to work around a few machine
  54. * models with broken OF probing by hard-coding known EDIDs for some Mac
  55. * laptops internal LVDS panel. (XXX: not done yet)
  56. */
  57. static int __devinit radeon_parse_montype_prop(struct device_node *dp, u8 **out_EDID,
  58. int hdno)
  59. {
  60. static char *propnames[] = { "DFP,EDID", "LCD,EDID", "EDID",
  61. "EDID1", "EDID2", NULL };
  62. const u8 *pedid = NULL;
  63. const u8 *pmt = NULL;
  64. u8 *tmp;
  65. int i, mt = MT_NONE;
  66. pr_debug("analyzing OF properties...\n");
  67. pmt = of_get_property(dp, "display-type", NULL);
  68. if (!pmt)
  69. return MT_NONE;
  70. pr_debug("display-type: %s\n", pmt);
  71. /* OF says "LCD" for DFP as well, we discriminate from the caller of this
  72. * function
  73. */
  74. if (!strcmp(pmt, "LCD") || !strcmp(pmt, "DFP"))
  75. mt = MT_DFP;
  76. else if (!strcmp(pmt, "CRT"))
  77. mt = MT_CRT;
  78. else {
  79. if (strcmp(pmt, "NONE") != 0)
  80. printk(KERN_WARNING "radeonfb: Unknown OF display-type: %s\n",
  81. pmt);
  82. return MT_NONE;
  83. }
  84. for (i = 0; propnames[i] != NULL; ++i) {
  85. pedid = of_get_property(dp, propnames[i], NULL);
  86. if (pedid != NULL)
  87. break;
  88. }
  89. /* We didn't find the EDID in the leaf node, some cards will actually
  90. * put EDID1/EDID2 in the parent, look for these (typically M6 tipb).
  91. * single-head cards have hdno == -1 and skip this step
  92. */
  93. if (pedid == NULL && dp->parent && (hdno != -1))
  94. pedid = of_get_property(dp->parent,
  95. (hdno == 0) ? "EDID1" : "EDID2", NULL);
  96. if (pedid == NULL && dp->parent && (hdno == 0))
  97. pedid = of_get_property(dp->parent, "EDID", NULL);
  98. if (pedid == NULL)
  99. return mt;
  100. tmp = kmemdup(pedid, EDID_LENGTH, GFP_KERNEL);
  101. if (!tmp)
  102. return mt;
  103. *out_EDID = tmp;
  104. return mt;
  105. }
  106. static int __devinit radeon_probe_OF_head(struct radeonfb_info *rinfo, int head_no,
  107. u8 **out_EDID)
  108. {
  109. struct device_node *dp;
  110. pr_debug("radeon_probe_OF_head\n");
  111. dp = rinfo->of_node;
  112. while (dp == NULL)
  113. return MT_NONE;
  114. if (rinfo->has_CRTC2) {
  115. const char *pname;
  116. int len, second = 0;
  117. dp = dp->child;
  118. do {
  119. if (!dp)
  120. return MT_NONE;
  121. pname = of_get_property(dp, "name", NULL);
  122. if (!pname)
  123. return MT_NONE;
  124. len = strlen(pname);
  125. pr_debug("head: %s (letter: %c, head_no: %d)\n",
  126. pname, pname[len-1], head_no);
  127. if (pname[len-1] == 'A' && head_no == 0) {
  128. int mt = radeon_parse_montype_prop(dp, out_EDID, 0);
  129. /* Maybe check for LVDS_GEN_CNTL here ? I need to check out
  130. * what OF does when booting with lid closed
  131. */
  132. if (mt == MT_DFP && rinfo->is_mobility)
  133. mt = MT_LCD;
  134. return mt;
  135. } else if (pname[len-1] == 'B' && head_no == 1)
  136. return radeon_parse_montype_prop(dp, out_EDID, 1);
  137. second = 1;
  138. dp = dp->sibling;
  139. } while(!second);
  140. } else {
  141. if (head_no > 0)
  142. return MT_NONE;
  143. return radeon_parse_montype_prop(dp, out_EDID, -1);
  144. }
  145. return MT_NONE;
  146. }
  147. #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
  148. static int __devinit radeon_get_panel_info_BIOS(struct radeonfb_info *rinfo)
  149. {
  150. unsigned long tmp, tmp0;
  151. char stmp[30];
  152. int i;
  153. if (!rinfo->bios_seg)
  154. return 0;
  155. if (!(tmp = BIOS_IN16(rinfo->fp_bios_start + 0x40))) {
  156. printk(KERN_ERR "radeonfb: Failed to detect DFP panel info using BIOS\n");
  157. rinfo->panel_info.pwr_delay = 200;
  158. return 0;
  159. }
  160. for(i=0; i<24; i++)
  161. stmp[i] = BIOS_IN8(tmp+i+1);
  162. stmp[24] = 0;
  163. printk("radeonfb: panel ID string: %s\n", stmp);
  164. rinfo->panel_info.xres = BIOS_IN16(tmp + 25);
  165. rinfo->panel_info.yres = BIOS_IN16(tmp + 27);
  166. printk("radeonfb: detected LVDS panel size from BIOS: %dx%d\n",
  167. rinfo->panel_info.xres, rinfo->panel_info.yres);
  168. rinfo->panel_info.pwr_delay = BIOS_IN16(tmp + 44);
  169. pr_debug("BIOS provided panel power delay: %d\n", rinfo->panel_info.pwr_delay);
  170. if (rinfo->panel_info.pwr_delay > 2000 || rinfo->panel_info.pwr_delay <= 0)
  171. rinfo->panel_info.pwr_delay = 2000;
  172. /*
  173. * Some panels only work properly with some divider combinations
  174. */
  175. rinfo->panel_info.ref_divider = BIOS_IN16(tmp + 46);
  176. rinfo->panel_info.post_divider = BIOS_IN8(tmp + 48);
  177. rinfo->panel_info.fbk_divider = BIOS_IN16(tmp + 49);
  178. if (rinfo->panel_info.ref_divider != 0 &&
  179. rinfo->panel_info.fbk_divider > 3) {
  180. rinfo->panel_info.use_bios_dividers = 1;
  181. printk(KERN_INFO "radeondb: BIOS provided dividers will be used\n");
  182. pr_debug("ref_divider = %x\n", rinfo->panel_info.ref_divider);
  183. pr_debug("post_divider = %x\n", rinfo->panel_info.post_divider);
  184. pr_debug("fbk_divider = %x\n", rinfo->panel_info.fbk_divider);
  185. }
  186. pr_debug("Scanning BIOS table ...\n");
  187. for(i=0; i<32; i++) {
  188. tmp0 = BIOS_IN16(tmp+64+i*2);
  189. if (tmp0 == 0)
  190. break;
  191. pr_debug(" %d x %d\n", BIOS_IN16(tmp0), BIOS_IN16(tmp0+2));
  192. if ((BIOS_IN16(tmp0) == rinfo->panel_info.xres) &&
  193. (BIOS_IN16(tmp0+2) == rinfo->panel_info.yres)) {
  194. rinfo->panel_info.hblank = (BIOS_IN16(tmp0+17) - BIOS_IN16(tmp0+19)) * 8;
  195. rinfo->panel_info.hOver_plus = ((BIOS_IN16(tmp0+21) -
  196. BIOS_IN16(tmp0+19) -1) * 8) & 0x7fff;
  197. rinfo->panel_info.hSync_width = BIOS_IN8(tmp0+23) * 8;
  198. rinfo->panel_info.vblank = BIOS_IN16(tmp0+24) - BIOS_IN16(tmp0+26);
  199. rinfo->panel_info.vOver_plus = (BIOS_IN16(tmp0+28) & 0x7ff) - BIOS_IN16(tmp0+26);
  200. rinfo->panel_info.vSync_width = (BIOS_IN16(tmp0+28) & 0xf800) >> 11;
  201. rinfo->panel_info.clock = BIOS_IN16(tmp0+9);
  202. /* Assume high active syncs for now until ATI tells me more... maybe we
  203. * can probe register values here ?
  204. */
  205. rinfo->panel_info.hAct_high = 1;
  206. rinfo->panel_info.vAct_high = 1;
  207. /* Mark panel infos valid */
  208. rinfo->panel_info.valid = 1;
  209. pr_debug("Found panel in BIOS table:\n");
  210. pr_debug(" hblank: %d\n", rinfo->panel_info.hblank);
  211. pr_debug(" hOver_plus: %d\n", rinfo->panel_info.hOver_plus);
  212. pr_debug(" hSync_width: %d\n", rinfo->panel_info.hSync_width);
  213. pr_debug(" vblank: %d\n", rinfo->panel_info.vblank);
  214. pr_debug(" vOver_plus: %d\n", rinfo->panel_info.vOver_plus);
  215. pr_debug(" vSync_width: %d\n", rinfo->panel_info.vSync_width);
  216. pr_debug(" clock: %d\n", rinfo->panel_info.clock);
  217. return 1;
  218. }
  219. }
  220. pr_debug("Didn't find panel in BIOS table !\n");
  221. return 0;
  222. }
  223. /* Try to extract the connector informations from the BIOS. This
  224. * doesn't quite work yet, but it's output is still useful for
  225. * debugging
  226. */
  227. static void __devinit radeon_parse_connector_info(struct radeonfb_info *rinfo)
  228. {
  229. int offset, chips, connectors, tmp, i, conn, type;
  230. static char* __conn_type_table[16] = {
  231. "NONE", "Proprietary", "CRT", "DVI-I", "DVI-D", "Unknown", "Unknown",
  232. "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown",
  233. "Unknown", "Unknown", "Unknown"
  234. };
  235. if (!rinfo->bios_seg)
  236. return;
  237. offset = BIOS_IN16(rinfo->fp_bios_start + 0x50);
  238. if (offset == 0) {
  239. printk(KERN_WARNING "radeonfb: No connector info table detected\n");
  240. return;
  241. }
  242. /* Don't do much more at this point but displaying the data if
  243. * DEBUG is enabled
  244. */
  245. chips = BIOS_IN8(offset++) >> 4;
  246. pr_debug("%d chips in connector info\n", chips);
  247. for (i = 0; i < chips; i++) {
  248. tmp = BIOS_IN8(offset++);
  249. connectors = tmp & 0x0f;
  250. pr_debug(" - chip %d has %d connectors\n", tmp >> 4, connectors);
  251. for (conn = 0; ; conn++) {
  252. tmp = BIOS_IN16(offset);
  253. if (tmp == 0)
  254. break;
  255. offset += 2;
  256. type = (tmp >> 12) & 0x0f;
  257. pr_debug(" * connector %d of type %d (%s) : %04x\n",
  258. conn, type, __conn_type_table[type], tmp);
  259. }
  260. }
  261. }
  262. /*
  263. * Probe physical connection of a CRT. This code comes from XFree
  264. * as well and currently is only implemented for the CRT DAC, the
  265. * code for the TVDAC is commented out in XFree as "non working"
  266. */
  267. static int __devinit radeon_crt_is_connected(struct radeonfb_info *rinfo, int is_crt_dac)
  268. {
  269. int connected = 0;
  270. /* the monitor either wasn't connected or it is a non-DDC CRT.
  271. * try to probe it
  272. */
  273. if (is_crt_dac) {
  274. unsigned long ulOrigVCLK_ECP_CNTL;
  275. unsigned long ulOrigDAC_CNTL;
  276. unsigned long ulOrigDAC_EXT_CNTL;
  277. unsigned long ulOrigCRTC_EXT_CNTL;
  278. unsigned long ulData;
  279. unsigned long ulMask;
  280. ulOrigVCLK_ECP_CNTL = INPLL(VCLK_ECP_CNTL);
  281. ulData = ulOrigVCLK_ECP_CNTL;
  282. ulData &= ~(PIXCLK_ALWAYS_ONb
  283. | PIXCLK_DAC_ALWAYS_ONb);
  284. ulMask = ~(PIXCLK_ALWAYS_ONb
  285. | PIXCLK_DAC_ALWAYS_ONb);
  286. OUTPLLP(VCLK_ECP_CNTL, ulData, ulMask);
  287. ulOrigCRTC_EXT_CNTL = INREG(CRTC_EXT_CNTL);
  288. ulData = ulOrigCRTC_EXT_CNTL;
  289. ulData |= CRTC_CRT_ON;
  290. OUTREG(CRTC_EXT_CNTL, ulData);
  291. ulOrigDAC_EXT_CNTL = INREG(DAC_EXT_CNTL);
  292. ulData = ulOrigDAC_EXT_CNTL;
  293. ulData &= ~DAC_FORCE_DATA_MASK;
  294. ulData |= (DAC_FORCE_BLANK_OFF_EN
  295. |DAC_FORCE_DATA_EN
  296. |DAC_FORCE_DATA_SEL_MASK);
  297. if ((rinfo->family == CHIP_FAMILY_RV250) ||
  298. (rinfo->family == CHIP_FAMILY_RV280))
  299. ulData |= (0x01b6 << DAC_FORCE_DATA_SHIFT);
  300. else
  301. ulData |= (0x01ac << DAC_FORCE_DATA_SHIFT);
  302. OUTREG(DAC_EXT_CNTL, ulData);
  303. ulOrigDAC_CNTL = INREG(DAC_CNTL);
  304. ulData = ulOrigDAC_CNTL;
  305. ulData |= DAC_CMP_EN;
  306. ulData &= ~(DAC_RANGE_CNTL_MASK
  307. | DAC_PDWN);
  308. ulData |= 0x2;
  309. OUTREG(DAC_CNTL, ulData);
  310. mdelay(1);
  311. ulData = INREG(DAC_CNTL);
  312. connected = (DAC_CMP_OUTPUT & ulData) ? 1 : 0;
  313. ulData = ulOrigVCLK_ECP_CNTL;
  314. ulMask = 0xFFFFFFFFL;
  315. OUTPLLP(VCLK_ECP_CNTL, ulData, ulMask);
  316. OUTREG(DAC_CNTL, ulOrigDAC_CNTL );
  317. OUTREG(DAC_EXT_CNTL, ulOrigDAC_EXT_CNTL );
  318. OUTREG(CRTC_EXT_CNTL, ulOrigCRTC_EXT_CNTL);
  319. }
  320. return connected ? MT_CRT : MT_NONE;
  321. }
  322. /*
  323. * Parse the "monitor_layout" string if any. This code is mostly
  324. * copied from XFree's radeon driver
  325. */
  326. static int __devinit radeon_parse_monitor_layout(struct radeonfb_info *rinfo,
  327. const char *monitor_layout)
  328. {
  329. char s1[5], s2[5];
  330. int i = 0, second = 0;
  331. const char *s;
  332. if (!monitor_layout)
  333. return 0;
  334. s = monitor_layout;
  335. do {
  336. switch(*s) {
  337. case ',':
  338. s1[i] = '\0';
  339. i = 0;
  340. second = 1;
  341. break;
  342. case ' ':
  343. case '\0':
  344. break;
  345. default:
  346. if (i > 4)
  347. break;
  348. if (second)
  349. s2[i] = *s;
  350. else
  351. s1[i] = *s;
  352. i++;
  353. }
  354. if (i > 4)
  355. i = 4;
  356. } while (*s++);
  357. if (second)
  358. s2[i] = 0;
  359. else {
  360. s1[i] = 0;
  361. s2[0] = 0;
  362. }
  363. if (strcmp(s1, "CRT") == 0)
  364. rinfo->mon1_type = MT_CRT;
  365. else if (strcmp(s1, "TMDS") == 0)
  366. rinfo->mon1_type = MT_DFP;
  367. else if (strcmp(s1, "LVDS") == 0)
  368. rinfo->mon1_type = MT_LCD;
  369. if (strcmp(s2, "CRT") == 0)
  370. rinfo->mon2_type = MT_CRT;
  371. else if (strcmp(s2, "TMDS") == 0)
  372. rinfo->mon2_type = MT_DFP;
  373. else if (strcmp(s2, "LVDS") == 0)
  374. rinfo->mon2_type = MT_LCD;
  375. return 1;
  376. }
  377. /*
  378. * Probe display on both primary and secondary card's connector (if any)
  379. * by various available techniques (i2c, OF device tree, BIOS, ...) and
  380. * try to retrieve EDID. The algorithm here comes from XFree's radeon
  381. * driver
  382. */
  383. void __devinit radeon_probe_screens(struct radeonfb_info *rinfo,
  384. const char *monitor_layout, int ignore_edid)
  385. {
  386. #ifdef CONFIG_FB_RADEON_I2C
  387. int ddc_crt2_used = 0;
  388. #endif
  389. int tmp, i;
  390. radeon_parse_connector_info(rinfo);
  391. if (radeon_parse_monitor_layout(rinfo, monitor_layout)) {
  392. /*
  393. * If user specified a monitor_layout option, use it instead
  394. * of auto-detecting. Maybe we should only use this argument
  395. * on the first radeon card probed or provide a way to specify
  396. * a layout for each card ?
  397. */
  398. pr_debug("Using specified monitor layout: %s", monitor_layout);
  399. #ifdef CONFIG_FB_RADEON_I2C
  400. if (!ignore_edid) {
  401. if (rinfo->mon1_type != MT_NONE)
  402. if (!radeon_probe_i2c_connector(rinfo, ddc_dvi, &rinfo->mon1_EDID)) {
  403. radeon_probe_i2c_connector(rinfo, ddc_crt2, &rinfo->mon1_EDID);
  404. ddc_crt2_used = 1;
  405. }
  406. if (rinfo->mon2_type != MT_NONE)
  407. if (!radeon_probe_i2c_connector(rinfo, ddc_vga, &rinfo->mon2_EDID) &&
  408. !ddc_crt2_used)
  409. radeon_probe_i2c_connector(rinfo, ddc_crt2, &rinfo->mon2_EDID);
  410. }
  411. #endif /* CONFIG_FB_RADEON_I2C */
  412. if (rinfo->mon1_type == MT_NONE) {
  413. if (rinfo->mon2_type != MT_NONE) {
  414. rinfo->mon1_type = rinfo->mon2_type;
  415. rinfo->mon1_EDID = rinfo->mon2_EDID;
  416. } else {
  417. rinfo->mon1_type = MT_CRT;
  418. printk(KERN_INFO "radeonfb: No valid monitor, assuming CRT on first port\n");
  419. }
  420. rinfo->mon2_type = MT_NONE;
  421. rinfo->mon2_EDID = NULL;
  422. }
  423. } else {
  424. /*
  425. * Auto-detecting display type (well... trying to ...)
  426. */
  427. pr_debug("Starting monitor auto detection...\n");
  428. #if defined(DEBUG) && defined(CONFIG_FB_RADEON_I2C)
  429. {
  430. u8 *EDIDs[4] = { NULL, NULL, NULL, NULL };
  431. int mon_types[4] = {MT_NONE, MT_NONE, MT_NONE, MT_NONE};
  432. int i;
  433. for (i = 0; i < 4; i++)
  434. mon_types[i] = radeon_probe_i2c_connector(rinfo,
  435. i+1, &EDIDs[i]);
  436. }
  437. #endif /* DEBUG */
  438. /*
  439. * Old single head cards
  440. */
  441. if (!rinfo->has_CRTC2) {
  442. #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
  443. if (rinfo->mon1_type == MT_NONE)
  444. rinfo->mon1_type = radeon_probe_OF_head(rinfo, 0,
  445. &rinfo->mon1_EDID);
  446. #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
  447. #ifdef CONFIG_FB_RADEON_I2C
  448. if (rinfo->mon1_type == MT_NONE)
  449. rinfo->mon1_type =
  450. radeon_probe_i2c_connector(rinfo, ddc_dvi,
  451. &rinfo->mon1_EDID);
  452. if (rinfo->mon1_type == MT_NONE)
  453. rinfo->mon1_type =
  454. radeon_probe_i2c_connector(rinfo, ddc_vga,
  455. &rinfo->mon1_EDID);
  456. if (rinfo->mon1_type == MT_NONE)
  457. rinfo->mon1_type =
  458. radeon_probe_i2c_connector(rinfo, ddc_crt2,
  459. &rinfo->mon1_EDID);
  460. #endif /* CONFIG_FB_RADEON_I2C */
  461. if (rinfo->mon1_type == MT_NONE)
  462. rinfo->mon1_type = MT_CRT;
  463. goto bail;
  464. }
  465. /*
  466. * Check for cards with reversed DACs or TMDS controllers using BIOS
  467. */
  468. if (rinfo->bios_seg &&
  469. (tmp = BIOS_IN16(rinfo->fp_bios_start + 0x50))) {
  470. for (i = 1; i < 4; i++) {
  471. unsigned int tmp0;
  472. if (!BIOS_IN8(tmp + i*2) && i > 1)
  473. break;
  474. tmp0 = BIOS_IN16(tmp + i*2);
  475. if ((!(tmp0 & 0x01)) && (((tmp0 >> 8) & 0x0f) == ddc_dvi)) {
  476. rinfo->reversed_DAC = 1;
  477. printk(KERN_INFO "radeonfb: Reversed DACs detected\n");
  478. }
  479. if ((((tmp0 >> 8) & 0x0f) == ddc_dvi) && ((tmp0 >> 4) & 0x01)) {
  480. rinfo->reversed_TMDS = 1;
  481. printk(KERN_INFO "radeonfb: Reversed TMDS detected\n");
  482. }
  483. }
  484. }
  485. /*
  486. * Probe primary head (DVI or laptop internal panel)
  487. */
  488. #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
  489. if (rinfo->mon1_type == MT_NONE)
  490. rinfo->mon1_type = radeon_probe_OF_head(rinfo, 0,
  491. &rinfo->mon1_EDID);
  492. #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
  493. #ifdef CONFIG_FB_RADEON_I2C
  494. if (rinfo->mon1_type == MT_NONE)
  495. rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_dvi,
  496. &rinfo->mon1_EDID);
  497. if (rinfo->mon1_type == MT_NONE) {
  498. rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_crt2,
  499. &rinfo->mon1_EDID);
  500. if (rinfo->mon1_type != MT_NONE)
  501. ddc_crt2_used = 1;
  502. }
  503. #endif /* CONFIG_FB_RADEON_I2C */
  504. if (rinfo->mon1_type == MT_NONE && rinfo->is_mobility &&
  505. ((rinfo->bios_seg && (INREG(BIOS_4_SCRATCH) & 4))
  506. || (INREG(LVDS_GEN_CNTL) & LVDS_ON))) {
  507. rinfo->mon1_type = MT_LCD;
  508. printk("Non-DDC laptop panel detected\n");
  509. }
  510. if (rinfo->mon1_type == MT_NONE)
  511. rinfo->mon1_type = radeon_crt_is_connected(rinfo, rinfo->reversed_DAC);
  512. /*
  513. * Probe secondary head (mostly VGA, can be DVI)
  514. */
  515. #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
  516. if (rinfo->mon2_type == MT_NONE)
  517. rinfo->mon2_type = radeon_probe_OF_head(rinfo, 1,
  518. &rinfo->mon2_EDID);
  519. #endif /* CONFIG_PPC_OF || defined(CONFIG_SPARC) */
  520. #ifdef CONFIG_FB_RADEON_I2C
  521. if (rinfo->mon2_type == MT_NONE)
  522. rinfo->mon2_type = radeon_probe_i2c_connector(rinfo, ddc_vga,
  523. &rinfo->mon2_EDID);
  524. if (rinfo->mon2_type == MT_NONE && !ddc_crt2_used)
  525. rinfo->mon2_type = radeon_probe_i2c_connector(rinfo, ddc_crt2,
  526. &rinfo->mon2_EDID);
  527. #endif /* CONFIG_FB_RADEON_I2C */
  528. if (rinfo->mon2_type == MT_NONE)
  529. rinfo->mon2_type = radeon_crt_is_connected(rinfo, !rinfo->reversed_DAC);
  530. /*
  531. * If we only detected port 2, we swap them, if none detected,
  532. * assume CRT (maybe fallback to old BIOS_SCRATCH stuff ? or look
  533. * at FP registers ?)
  534. */
  535. if (rinfo->mon1_type == MT_NONE) {
  536. if (rinfo->mon2_type != MT_NONE) {
  537. rinfo->mon1_type = rinfo->mon2_type;
  538. rinfo->mon1_EDID = rinfo->mon2_EDID;
  539. } else
  540. rinfo->mon1_type = MT_CRT;
  541. rinfo->mon2_type = MT_NONE;
  542. rinfo->mon2_EDID = NULL;
  543. }
  544. /*
  545. * Deal with reversed TMDS
  546. */
  547. if (rinfo->reversed_TMDS) {
  548. /* Always keep internal TMDS as primary head */
  549. if (rinfo->mon1_type == MT_DFP || rinfo->mon2_type == MT_DFP) {
  550. int tmp_type = rinfo->mon1_type;
  551. u8 *tmp_EDID = rinfo->mon1_EDID;
  552. rinfo->mon1_type = rinfo->mon2_type;
  553. rinfo->mon1_EDID = rinfo->mon2_EDID;
  554. rinfo->mon2_type = tmp_type;
  555. rinfo->mon2_EDID = tmp_EDID;
  556. if (rinfo->mon1_type == MT_CRT || rinfo->mon2_type == MT_CRT)
  557. rinfo->reversed_DAC ^= 1;
  558. }
  559. }
  560. }
  561. if (ignore_edid) {
  562. kfree(rinfo->mon1_EDID);
  563. rinfo->mon1_EDID = NULL;
  564. kfree(rinfo->mon2_EDID);
  565. rinfo->mon2_EDID = NULL;
  566. }
  567. bail:
  568. printk(KERN_INFO "radeonfb: Monitor 1 type %s found\n",
  569. radeon_get_mon_name(rinfo->mon1_type));
  570. if (rinfo->mon1_EDID)
  571. printk(KERN_INFO "radeonfb: EDID probed\n");
  572. if (!rinfo->has_CRTC2)
  573. return;
  574. printk(KERN_INFO "radeonfb: Monitor 2 type %s found\n",
  575. radeon_get_mon_name(rinfo->mon2_type));
  576. if (rinfo->mon2_EDID)
  577. printk(KERN_INFO "radeonfb: EDID probed\n");
  578. }
  579. /*
  580. * This functions applyes any arch/model/machine specific fixups
  581. * to the panel info. It may eventually alter EDID block as
  582. * well or whatever is specific to a given model and not probed
  583. * properly by the default code
  584. */
  585. static void radeon_fixup_panel_info(struct radeonfb_info *rinfo)
  586. {
  587. #ifdef CONFIG_PPC_OF
  588. /*
  589. * LCD Flat panels should use fixed dividers, we enfore that on
  590. * PPC only for now...
  591. */
  592. if (!rinfo->panel_info.use_bios_dividers && rinfo->mon1_type == MT_LCD
  593. && rinfo->is_mobility) {
  594. int ppll_div_sel;
  595. u32 ppll_divn;
  596. ppll_div_sel = INREG8(CLOCK_CNTL_INDEX + 1) & 0x3;
  597. radeon_pll_errata_after_index(rinfo);
  598. ppll_divn = INPLL(PPLL_DIV_0 + ppll_div_sel);
  599. rinfo->panel_info.ref_divider = rinfo->pll.ref_div;
  600. rinfo->panel_info.fbk_divider = ppll_divn & 0x7ff;
  601. rinfo->panel_info.post_divider = (ppll_divn >> 16) & 0x7;
  602. rinfo->panel_info.use_bios_dividers = 1;
  603. printk(KERN_DEBUG "radeonfb: Using Firmware dividers 0x%08x "
  604. "from PPLL %d\n",
  605. rinfo->panel_info.fbk_divider |
  606. (rinfo->panel_info.post_divider << 16),
  607. ppll_div_sel);
  608. }
  609. #endif /* CONFIG_PPC_OF */
  610. }
  611. /*
  612. * Fill up panel infos from a mode definition, either returned by the EDID
  613. * or from the default mode when we can't do any better
  614. */
  615. static void radeon_var_to_panel_info(struct radeonfb_info *rinfo, struct fb_var_screeninfo *var)
  616. {
  617. rinfo->panel_info.xres = var->xres;
  618. rinfo->panel_info.yres = var->yres;
  619. rinfo->panel_info.clock = 100000000 / var->pixclock;
  620. rinfo->panel_info.hOver_plus = var->right_margin;
  621. rinfo->panel_info.hSync_width = var->hsync_len;
  622. rinfo->panel_info.hblank = var->left_margin +
  623. (var->right_margin + var->hsync_len);
  624. rinfo->panel_info.vOver_plus = var->lower_margin;
  625. rinfo->panel_info.vSync_width = var->vsync_len;
  626. rinfo->panel_info.vblank = var->upper_margin +
  627. (var->lower_margin + var->vsync_len);
  628. rinfo->panel_info.hAct_high =
  629. (var->sync & FB_SYNC_HOR_HIGH_ACT) != 0;
  630. rinfo->panel_info.vAct_high =
  631. (var->sync & FB_SYNC_VERT_HIGH_ACT) != 0;
  632. rinfo->panel_info.valid = 1;
  633. /* We use a default of 200ms for the panel power delay,
  634. * I need to have a real schedule() instead of mdelay's in the panel code.
  635. * we might be possible to figure out a better power delay either from
  636. * MacOS OF tree or from the EDID block (proprietary extensions ?)
  637. */
  638. rinfo->panel_info.pwr_delay = 200;
  639. }
  640. static void radeon_videomode_to_var(struct fb_var_screeninfo *var,
  641. const struct fb_videomode *mode)
  642. {
  643. var->xres = mode->xres;
  644. var->yres = mode->yres;
  645. var->xres_virtual = mode->xres;
  646. var->yres_virtual = mode->yres;
  647. var->xoffset = 0;
  648. var->yoffset = 0;
  649. var->pixclock = mode->pixclock;
  650. var->left_margin = mode->left_margin;
  651. var->right_margin = mode->right_margin;
  652. var->upper_margin = mode->upper_margin;
  653. var->lower_margin = mode->lower_margin;
  654. var->hsync_len = mode->hsync_len;
  655. var->vsync_len = mode->vsync_len;
  656. var->sync = mode->sync;
  657. var->vmode = mode->vmode;
  658. }
  659. /*
  660. * Build the modedb for head 1 (head 2 will come later), check panel infos
  661. * from either BIOS or EDID, and pick up the default mode
  662. */
  663. void __devinit radeon_check_modes(struct radeonfb_info *rinfo, const char *mode_option)
  664. {
  665. struct fb_info * info = rinfo->info;
  666. int has_default_mode = 0;
  667. /*
  668. * Fill default var first
  669. */
  670. info->var = radeonfb_default_var;
  671. INIT_LIST_HEAD(&info->modelist);
  672. /*
  673. * First check out what BIOS has to say
  674. */
  675. if (rinfo->mon1_type == MT_LCD)
  676. radeon_get_panel_info_BIOS(rinfo);
  677. /*
  678. * Parse EDID detailed timings and deduce panel infos if any. Right now
  679. * we only deal with first entry returned by parse_EDID, we may do better
  680. * some day...
  681. */
  682. if (!rinfo->panel_info.use_bios_dividers && rinfo->mon1_type != MT_CRT
  683. && rinfo->mon1_EDID) {
  684. struct fb_var_screeninfo var;
  685. pr_debug("Parsing EDID data for panel info\n");
  686. if (fb_parse_edid(rinfo->mon1_EDID, &var) == 0) {
  687. if (var.xres >= rinfo->panel_info.xres &&
  688. var.yres >= rinfo->panel_info.yres)
  689. radeon_var_to_panel_info(rinfo, &var);
  690. }
  691. }
  692. /*
  693. * Do any additional platform/arch fixups to the panel infos
  694. */
  695. radeon_fixup_panel_info(rinfo);
  696. /*
  697. * If we have some valid panel infos, we setup the default mode based on
  698. * those
  699. */
  700. if (rinfo->mon1_type != MT_CRT && rinfo->panel_info.valid) {
  701. struct fb_var_screeninfo *var = &info->var;
  702. pr_debug("Setting up default mode based on panel info\n");
  703. var->xres = rinfo->panel_info.xres;
  704. var->yres = rinfo->panel_info.yres;
  705. var->xres_virtual = rinfo->panel_info.xres;
  706. var->yres_virtual = rinfo->panel_info.yres;
  707. var->xoffset = var->yoffset = 0;
  708. var->bits_per_pixel = 8;
  709. var->pixclock = 100000000 / rinfo->panel_info.clock;
  710. var->left_margin = (rinfo->panel_info.hblank - rinfo->panel_info.hOver_plus
  711. - rinfo->panel_info.hSync_width);
  712. var->right_margin = rinfo->panel_info.hOver_plus;
  713. var->upper_margin = (rinfo->panel_info.vblank - rinfo->panel_info.vOver_plus
  714. - rinfo->panel_info.vSync_width);
  715. var->lower_margin = rinfo->panel_info.vOver_plus;
  716. var->hsync_len = rinfo->panel_info.hSync_width;
  717. var->vsync_len = rinfo->panel_info.vSync_width;
  718. var->sync = 0;
  719. if (rinfo->panel_info.hAct_high)
  720. var->sync |= FB_SYNC_HOR_HIGH_ACT;
  721. if (rinfo->panel_info.vAct_high)
  722. var->sync |= FB_SYNC_VERT_HIGH_ACT;
  723. var->vmode = 0;
  724. has_default_mode = 1;
  725. }
  726. /*
  727. * Now build modedb from EDID
  728. */
  729. if (rinfo->mon1_EDID) {
  730. fb_edid_to_monspecs(rinfo->mon1_EDID, &info->monspecs);
  731. fb_videomode_to_modelist(info->monspecs.modedb,
  732. info->monspecs.modedb_len,
  733. &info->modelist);
  734. rinfo->mon1_modedb = info->monspecs.modedb;
  735. rinfo->mon1_dbsize = info->monspecs.modedb_len;
  736. }
  737. /*
  738. * Finally, if we don't have panel infos we need to figure some (or
  739. * we try to read it from card), we try to pick a default mode
  740. * and create some panel infos. Whatever...
  741. */
  742. if (rinfo->mon1_type != MT_CRT && !rinfo->panel_info.valid) {
  743. struct fb_videomode *modedb;
  744. int dbsize;
  745. char modename[32];
  746. pr_debug("Guessing panel info...\n");
  747. if (rinfo->panel_info.xres == 0 || rinfo->panel_info.yres == 0) {
  748. u32 tmp = INREG(FP_HORZ_STRETCH) & HORZ_PANEL_SIZE;
  749. rinfo->panel_info.xres = ((tmp >> HORZ_PANEL_SHIFT) + 1) * 8;
  750. tmp = INREG(FP_VERT_STRETCH) & VERT_PANEL_SIZE;
  751. rinfo->panel_info.yres = (tmp >> VERT_PANEL_SHIFT) + 1;
  752. }
  753. if (rinfo->panel_info.xres == 0 || rinfo->panel_info.yres == 0) {
  754. printk(KERN_WARNING "radeonfb: Can't find panel size, going back to CRT\n");
  755. rinfo->mon1_type = MT_CRT;
  756. goto pickup_default;
  757. }
  758. printk(KERN_WARNING "radeonfb: Assuming panel size %dx%d\n",
  759. rinfo->panel_info.xres, rinfo->panel_info.yres);
  760. modedb = rinfo->mon1_modedb;
  761. dbsize = rinfo->mon1_dbsize;
  762. snprintf(modename, 31, "%dx%d", rinfo->panel_info.xres, rinfo->panel_info.yres);
  763. if (fb_find_mode(&info->var, info, modename,
  764. modedb, dbsize, NULL, 8) == 0) {
  765. printk(KERN_WARNING "radeonfb: Can't find mode for panel size, going back to CRT\n");
  766. rinfo->mon1_type = MT_CRT;
  767. goto pickup_default;
  768. }
  769. has_default_mode = 1;
  770. radeon_var_to_panel_info(rinfo, &info->var);
  771. }
  772. pickup_default:
  773. /*
  774. * Apply passed-in mode option if any
  775. */
  776. if (mode_option) {
  777. if (fb_find_mode(&info->var, info, mode_option,
  778. info->monspecs.modedb,
  779. info->monspecs.modedb_len, NULL, 8) != 0)
  780. has_default_mode = 1;
  781. }
  782. /*
  783. * Still no mode, let's pick up a default from the db
  784. */
  785. if (!has_default_mode && info->monspecs.modedb != NULL) {
  786. struct fb_monspecs *specs = &info->monspecs;
  787. struct fb_videomode *modedb = NULL;
  788. /* get preferred timing */
  789. if (specs->misc & FB_MISC_1ST_DETAIL) {
  790. int i;
  791. for (i = 0; i < specs->modedb_len; i++) {
  792. if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
  793. modedb = &specs->modedb[i];
  794. break;
  795. }
  796. }
  797. } else {
  798. /* otherwise, get first mode in database */
  799. modedb = &specs->modedb[0];
  800. }
  801. if (modedb != NULL) {
  802. info->var.bits_per_pixel = 8;
  803. radeon_videomode_to_var(&info->var, modedb);
  804. has_default_mode = 1;
  805. }
  806. }
  807. if (1) {
  808. struct fb_videomode mode;
  809. /* Make sure that whatever mode got selected is actually in the
  810. * modelist or the kernel may die
  811. */
  812. fb_var_to_videomode(&mode, &info->var);
  813. fb_add_videomode(&mode, &info->modelist);
  814. }
  815. }
  816. /*
  817. * The code below is used to pick up a mode in check_var and
  818. * set_var. It should be made generic
  819. */
  820. /*
  821. * This is used when looking for modes. We assign a "distance" value
  822. * to a mode in the modedb depending how "close" it is from what we
  823. * are looking for.
  824. * Currently, we don't compare that much, we could do better but
  825. * the current fbcon doesn't quite mind ;)
  826. */
  827. static int radeon_compare_modes(const struct fb_var_screeninfo *var,
  828. const struct fb_videomode *mode)
  829. {
  830. int distance = 0;
  831. distance = mode->yres - var->yres;
  832. distance += (mode->xres - var->xres)/2;
  833. return distance;
  834. }
  835. /*
  836. * This function is called by check_var, it gets the passed in mode parameter, and
  837. * outputs a valid mode matching the passed-in one as closely as possible.
  838. * We need something better ultimately. Things like fbcon basically pass us out
  839. * current mode with xres/yres hacked, while things like XFree will actually
  840. * produce a full timing that we should respect as much as possible.
  841. *
  842. * This is why I added the FB_ACTIVATE_FIND that is used by fbcon. Without this,
  843. * we do a simple spec match, that's all. With it, we actually look for a mode in
  844. * either our monitor modedb or the vesa one if none
  845. *
  846. */
  847. int radeon_match_mode(struct radeonfb_info *rinfo,
  848. struct fb_var_screeninfo *dest,
  849. const struct fb_var_screeninfo *src)
  850. {
  851. const struct fb_videomode *db = vesa_modes;
  852. int i, dbsize = 34;
  853. int has_rmx, native_db = 0;
  854. int distance = INT_MAX;
  855. const struct fb_videomode *candidate = NULL;
  856. /* Start with a copy of the requested mode */
  857. memcpy(dest, src, sizeof(struct fb_var_screeninfo));
  858. /* Check if we have a modedb built from EDID */
  859. if (rinfo->mon1_modedb) {
  860. db = rinfo->mon1_modedb;
  861. dbsize = rinfo->mon1_dbsize;
  862. native_db = 1;
  863. }
  864. /* Check if we have a scaler allowing any fancy mode */
  865. has_rmx = rinfo->mon1_type == MT_LCD || rinfo->mon1_type == MT_DFP;
  866. /* If we have a scaler and are passed FB_ACTIVATE_TEST or
  867. * FB_ACTIVATE_NOW, just do basic checking and return if the
  868. * mode match
  869. */
  870. if ((src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_TEST ||
  871. (src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
  872. /* We don't have an RMX, validate timings. If we don't have
  873. * monspecs, we should be paranoid and not let use go above
  874. * 640x480-60, but I assume userland knows what it's doing here
  875. * (though I may be proven wrong...)
  876. */
  877. if (has_rmx == 0 && rinfo->mon1_modedb)
  878. if (fb_validate_mode((struct fb_var_screeninfo *)src, rinfo->info))
  879. return -EINVAL;
  880. return 0;
  881. }
  882. /* Now look for a mode in the database */
  883. while (db) {
  884. for (i = 0; i < dbsize; i++) {
  885. int d;
  886. if (db[i].yres < src->yres)
  887. continue;
  888. if (db[i].xres < src->xres)
  889. continue;
  890. d = radeon_compare_modes(src, &db[i]);
  891. /* If the new mode is at least as good as the previous one,
  892. * then it's our new candidate
  893. */
  894. if (d < distance) {
  895. candidate = &db[i];
  896. distance = d;
  897. }
  898. }
  899. db = NULL;
  900. /* If we have a scaler, we allow any mode from the database */
  901. if (native_db && has_rmx) {
  902. db = vesa_modes;
  903. dbsize = 34;
  904. native_db = 0;
  905. }
  906. }
  907. /* If we have found a match, return it */
  908. if (candidate != NULL) {
  909. radeon_videomode_to_var(dest, candidate);
  910. return 0;
  911. }
  912. /* If we haven't and don't have a scaler, fail */
  913. if (!has_rmx)
  914. return -EINVAL;
  915. return 0;
  916. }