radeon_monitor.c 29 KB

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