radeon_monitor.c 29 KB

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