radeon_monitor.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  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. #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
  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. pr_debug("analyzing OF properties...\n");
  66. pmt = of_get_property(dp, "display-type", NULL);
  67. if (!pmt)
  68. return MT_NONE;
  69. pr_debug("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 = of_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 = of_get_property(dp->parent,
  94. (hdno == 0) ? "EDID1" : "EDID2", NULL);
  95. if (pedid == NULL && dp->parent && (hdno == 0))
  96. pedid = of_get_property(dp->parent, "EDID", NULL);
  97. if (pedid == NULL)
  98. return mt;
  99. tmp = kmemdup(pedid, EDID_LENGTH, GFP_KERNEL);
  100. if (!tmp)
  101. return mt;
  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. pr_debug("radeon_probe_OF_head\n");
  110. dp = rinfo->of_node;
  111. while (dp == NULL)
  112. return MT_NONE;
  113. if (rinfo->has_CRTC2) {
  114. const char *pname;
  115. int len, second = 0;
  116. dp = dp->child;
  117. do {
  118. if (!dp)
  119. return MT_NONE;
  120. pname = of_get_property(dp, "name", NULL);
  121. if (!pname)
  122. return MT_NONE;
  123. len = strlen(pname);
  124. pr_debug("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 || CONFIG_SPARC */
  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. pr_debug("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. pr_debug("ref_divider = %x\n", rinfo->panel_info.ref_divider);
  182. pr_debug("post_divider = %x\n", rinfo->panel_info.post_divider);
  183. pr_debug("fbk_divider = %x\n", rinfo->panel_info.fbk_divider);
  184. }
  185. pr_debug("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. pr_debug(" %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. pr_debug("Found panel in BIOS table:\n");
  209. pr_debug(" hblank: %d\n", rinfo->panel_info.hblank);
  210. pr_debug(" hOver_plus: %d\n", rinfo->panel_info.hOver_plus);
  211. pr_debug(" hSync_width: %d\n", rinfo->panel_info.hSync_width);
  212. pr_debug(" vblank: %d\n", rinfo->panel_info.vblank);
  213. pr_debug(" vOver_plus: %d\n", rinfo->panel_info.vOver_plus);
  214. pr_debug(" vSync_width: %d\n", rinfo->panel_info.vSync_width);
  215. pr_debug(" clock: %d\n", rinfo->panel_info.clock);
  216. return 1;
  217. }
  218. }
  219. pr_debug("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. pr_debug("%d chips in connector info\n", chips);
  246. for (i = 0; i < chips; i++) {
  247. tmp = BIOS_IN8(offset++);
  248. connectors = tmp & 0x0f;
  249. pr_debug(" - 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. pr_debug(" * 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. if (i > 4)
  354. i = 4;
  355. } while (*s++);
  356. if (second)
  357. s2[i] = 0;
  358. else {
  359. s1[i] = 0;
  360. s2[0] = 0;
  361. }
  362. if (strcmp(s1, "CRT") == 0)
  363. rinfo->mon1_type = MT_CRT;
  364. else if (strcmp(s1, "TMDS") == 0)
  365. rinfo->mon1_type = MT_DFP;
  366. else if (strcmp(s1, "LVDS") == 0)
  367. rinfo->mon1_type = MT_LCD;
  368. if (strcmp(s2, "CRT") == 0)
  369. rinfo->mon2_type = MT_CRT;
  370. else if (strcmp(s2, "TMDS") == 0)
  371. rinfo->mon2_type = MT_DFP;
  372. else if (strcmp(s2, "LVDS") == 0)
  373. rinfo->mon2_type = MT_LCD;
  374. return 1;
  375. }
  376. /*
  377. * Probe display on both primary and secondary card's connector (if any)
  378. * by various available techniques (i2c, OF device tree, BIOS, ...) and
  379. * try to retrieve EDID. The algorithm here comes from XFree's radeon
  380. * driver
  381. */
  382. void __devinit radeon_probe_screens(struct radeonfb_info *rinfo,
  383. const char *monitor_layout, int ignore_edid)
  384. {
  385. #ifdef CONFIG_FB_RADEON_I2C
  386. int ddc_crt2_used = 0;
  387. #endif
  388. int tmp, i;
  389. radeon_parse_connector_info(rinfo);
  390. if (radeon_parse_monitor_layout(rinfo, monitor_layout)) {
  391. /*
  392. * If user specified a monitor_layout option, use it instead
  393. * of auto-detecting. Maybe we should only use this argument
  394. * on the first radeon card probed or provide a way to specify
  395. * a layout for each card ?
  396. */
  397. pr_debug("Using specified monitor layout: %s", monitor_layout);
  398. #ifdef CONFIG_FB_RADEON_I2C
  399. if (!ignore_edid) {
  400. if (rinfo->mon1_type != MT_NONE)
  401. if (!radeon_probe_i2c_connector(rinfo, ddc_dvi, &rinfo->mon1_EDID)) {
  402. radeon_probe_i2c_connector(rinfo, ddc_crt2, &rinfo->mon1_EDID);
  403. ddc_crt2_used = 1;
  404. }
  405. if (rinfo->mon2_type != MT_NONE)
  406. if (!radeon_probe_i2c_connector(rinfo, ddc_vga, &rinfo->mon2_EDID) &&
  407. !ddc_crt2_used)
  408. radeon_probe_i2c_connector(rinfo, ddc_crt2, &rinfo->mon2_EDID);
  409. }
  410. #endif /* CONFIG_FB_RADEON_I2C */
  411. if (rinfo->mon1_type == MT_NONE) {
  412. if (rinfo->mon2_type != MT_NONE) {
  413. rinfo->mon1_type = rinfo->mon2_type;
  414. rinfo->mon1_EDID = rinfo->mon2_EDID;
  415. } else {
  416. rinfo->mon1_type = MT_CRT;
  417. printk(KERN_INFO "radeonfb: No valid monitor, assuming CRT on first port\n");
  418. }
  419. rinfo->mon2_type = MT_NONE;
  420. rinfo->mon2_EDID = NULL;
  421. }
  422. } else {
  423. /*
  424. * Auto-detecting display type (well... trying to ...)
  425. */
  426. pr_debug("Starting monitor auto detection...\n");
  427. #if defined(DEBUG) && defined(CONFIG_FB_RADEON_I2C)
  428. {
  429. u8 *EDIDs[4] = { NULL, NULL, NULL, NULL };
  430. int mon_types[4] = {MT_NONE, MT_NONE, MT_NONE, MT_NONE};
  431. int i;
  432. for (i = 0; i < 4; i++)
  433. mon_types[i] = radeon_probe_i2c_connector(rinfo,
  434. i+1, &EDIDs[i]);
  435. }
  436. #endif /* DEBUG */
  437. /*
  438. * Old single head cards
  439. */
  440. if (!rinfo->has_CRTC2) {
  441. #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
  442. if (rinfo->mon1_type == MT_NONE)
  443. rinfo->mon1_type = radeon_probe_OF_head(rinfo, 0,
  444. &rinfo->mon1_EDID);
  445. #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
  446. #ifdef CONFIG_FB_RADEON_I2C
  447. if (rinfo->mon1_type == MT_NONE)
  448. rinfo->mon1_type =
  449. radeon_probe_i2c_connector(rinfo, ddc_dvi,
  450. &rinfo->mon1_EDID);
  451. if (rinfo->mon1_type == MT_NONE)
  452. rinfo->mon1_type =
  453. radeon_probe_i2c_connector(rinfo, ddc_vga,
  454. &rinfo->mon1_EDID);
  455. if (rinfo->mon1_type == MT_NONE)
  456. rinfo->mon1_type =
  457. radeon_probe_i2c_connector(rinfo, ddc_crt2,
  458. &rinfo->mon1_EDID);
  459. #endif /* CONFIG_FB_RADEON_I2C */
  460. if (rinfo->mon1_type == MT_NONE)
  461. rinfo->mon1_type = MT_CRT;
  462. goto bail;
  463. }
  464. /*
  465. * Check for cards with reversed DACs or TMDS controllers using BIOS
  466. */
  467. if (rinfo->bios_seg &&
  468. (tmp = BIOS_IN16(rinfo->fp_bios_start + 0x50))) {
  469. for (i = 1; i < 4; i++) {
  470. unsigned int tmp0;
  471. if (!BIOS_IN8(tmp + i*2) && i > 1)
  472. break;
  473. tmp0 = BIOS_IN16(tmp + i*2);
  474. if ((!(tmp0 & 0x01)) && (((tmp0 >> 8) & 0x0f) == ddc_dvi)) {
  475. rinfo->reversed_DAC = 1;
  476. printk(KERN_INFO "radeonfb: Reversed DACs detected\n");
  477. }
  478. if ((((tmp0 >> 8) & 0x0f) == ddc_dvi) && ((tmp0 >> 4) & 0x01)) {
  479. rinfo->reversed_TMDS = 1;
  480. printk(KERN_INFO "radeonfb: Reversed TMDS detected\n");
  481. }
  482. }
  483. }
  484. /*
  485. * Probe primary head (DVI or laptop internal panel)
  486. */
  487. #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
  488. if (rinfo->mon1_type == MT_NONE)
  489. rinfo->mon1_type = radeon_probe_OF_head(rinfo, 0,
  490. &rinfo->mon1_EDID);
  491. #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
  492. #ifdef CONFIG_FB_RADEON_I2C
  493. if (rinfo->mon1_type == MT_NONE)
  494. rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_dvi,
  495. &rinfo->mon1_EDID);
  496. if (rinfo->mon1_type == MT_NONE) {
  497. rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_crt2,
  498. &rinfo->mon1_EDID);
  499. if (rinfo->mon1_type != MT_NONE)
  500. ddc_crt2_used = 1;
  501. }
  502. #endif /* CONFIG_FB_RADEON_I2C */
  503. if (rinfo->mon1_type == MT_NONE && rinfo->is_mobility &&
  504. ((rinfo->bios_seg && (INREG(BIOS_4_SCRATCH) & 4))
  505. || (INREG(LVDS_GEN_CNTL) & LVDS_ON))) {
  506. rinfo->mon1_type = MT_LCD;
  507. printk("Non-DDC laptop panel detected\n");
  508. }
  509. if (rinfo->mon1_type == MT_NONE)
  510. rinfo->mon1_type = radeon_crt_is_connected(rinfo, rinfo->reversed_DAC);
  511. /*
  512. * Probe secondary head (mostly VGA, can be DVI)
  513. */
  514. #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
  515. if (rinfo->mon2_type == MT_NONE)
  516. rinfo->mon2_type = radeon_probe_OF_head(rinfo, 1,
  517. &rinfo->mon2_EDID);
  518. #endif /* CONFIG_PPC_OF || defined(CONFIG_SPARC) */
  519. #ifdef CONFIG_FB_RADEON_I2C
  520. if (rinfo->mon2_type == MT_NONE)
  521. rinfo->mon2_type = radeon_probe_i2c_connector(rinfo, ddc_vga,
  522. &rinfo->mon2_EDID);
  523. if (rinfo->mon2_type == MT_NONE && !ddc_crt2_used)
  524. rinfo->mon2_type = radeon_probe_i2c_connector(rinfo, ddc_crt2,
  525. &rinfo->mon2_EDID);
  526. #endif /* CONFIG_FB_RADEON_I2C */
  527. if (rinfo->mon2_type == MT_NONE)
  528. rinfo->mon2_type = radeon_crt_is_connected(rinfo, !rinfo->reversed_DAC);
  529. /*
  530. * If we only detected port 2, we swap them, if none detected,
  531. * assume CRT (maybe fallback to old BIOS_SCRATCH stuff ? or look
  532. * at FP registers ?)
  533. */
  534. if (rinfo->mon1_type == MT_NONE) {
  535. if (rinfo->mon2_type != MT_NONE) {
  536. rinfo->mon1_type = rinfo->mon2_type;
  537. rinfo->mon1_EDID = rinfo->mon2_EDID;
  538. } else
  539. rinfo->mon1_type = MT_CRT;
  540. rinfo->mon2_type = MT_NONE;
  541. rinfo->mon2_EDID = NULL;
  542. }
  543. /*
  544. * Deal with reversed TMDS
  545. */
  546. if (rinfo->reversed_TMDS) {
  547. /* Always keep internal TMDS as primary head */
  548. if (rinfo->mon1_type == MT_DFP || rinfo->mon2_type == MT_DFP) {
  549. int tmp_type = rinfo->mon1_type;
  550. u8 *tmp_EDID = rinfo->mon1_EDID;
  551. rinfo->mon1_type = rinfo->mon2_type;
  552. rinfo->mon1_EDID = rinfo->mon2_EDID;
  553. rinfo->mon2_type = tmp_type;
  554. rinfo->mon2_EDID = tmp_EDID;
  555. if (rinfo->mon1_type == MT_CRT || rinfo->mon2_type == MT_CRT)
  556. rinfo->reversed_DAC ^= 1;
  557. }
  558. }
  559. }
  560. if (ignore_edid) {
  561. kfree(rinfo->mon1_EDID);
  562. rinfo->mon1_EDID = NULL;
  563. kfree(rinfo->mon2_EDID);
  564. rinfo->mon2_EDID = NULL;
  565. }
  566. bail:
  567. printk(KERN_INFO "radeonfb: Monitor 1 type %s found\n",
  568. radeon_get_mon_name(rinfo->mon1_type));
  569. if (rinfo->mon1_EDID)
  570. printk(KERN_INFO "radeonfb: EDID probed\n");
  571. if (!rinfo->has_CRTC2)
  572. return;
  573. printk(KERN_INFO "radeonfb: Monitor 2 type %s found\n",
  574. radeon_get_mon_name(rinfo->mon2_type));
  575. if (rinfo->mon2_EDID)
  576. printk(KERN_INFO "radeonfb: EDID probed\n");
  577. }
  578. /*
  579. * This functions applyes any arch/model/machine specific fixups
  580. * to the panel info. It may eventually alter EDID block as
  581. * well or whatever is specific to a given model and not probed
  582. * properly by the default code
  583. */
  584. static void radeon_fixup_panel_info(struct radeonfb_info *rinfo)
  585. {
  586. #ifdef CONFIG_PPC_OF
  587. /*
  588. * LCD Flat panels should use fixed dividers, we enfore that on
  589. * PPC only for now...
  590. */
  591. if (!rinfo->panel_info.use_bios_dividers && rinfo->mon1_type == MT_LCD
  592. && rinfo->is_mobility) {
  593. int ppll_div_sel;
  594. u32 ppll_divn;
  595. ppll_div_sel = INREG8(CLOCK_CNTL_INDEX + 1) & 0x3;
  596. radeon_pll_errata_after_index(rinfo);
  597. ppll_divn = INPLL(PPLL_DIV_0 + ppll_div_sel);
  598. rinfo->panel_info.ref_divider = rinfo->pll.ref_div;
  599. rinfo->panel_info.fbk_divider = ppll_divn & 0x7ff;
  600. rinfo->panel_info.post_divider = (ppll_divn >> 16) & 0x7;
  601. rinfo->panel_info.use_bios_dividers = 1;
  602. printk(KERN_DEBUG "radeonfb: Using Firmware dividers 0x%08x "
  603. "from PPLL %d\n",
  604. rinfo->panel_info.fbk_divider |
  605. (rinfo->panel_info.post_divider << 16),
  606. ppll_div_sel);
  607. }
  608. #endif /* CONFIG_PPC_OF */
  609. }
  610. /*
  611. * Fill up panel infos from a mode definition, either returned by the EDID
  612. * or from the default mode when we can't do any better
  613. */
  614. static void radeon_var_to_panel_info(struct radeonfb_info *rinfo, struct fb_var_screeninfo *var)
  615. {
  616. rinfo->panel_info.xres = var->xres;
  617. rinfo->panel_info.yres = var->yres;
  618. rinfo->panel_info.clock = 100000000 / var->pixclock;
  619. rinfo->panel_info.hOver_plus = var->right_margin;
  620. rinfo->panel_info.hSync_width = var->hsync_len;
  621. rinfo->panel_info.hblank = var->left_margin +
  622. (var->right_margin + var->hsync_len);
  623. rinfo->panel_info.vOver_plus = var->lower_margin;
  624. rinfo->panel_info.vSync_width = var->vsync_len;
  625. rinfo->panel_info.vblank = var->upper_margin +
  626. (var->lower_margin + var->vsync_len);
  627. rinfo->panel_info.hAct_high =
  628. (var->sync & FB_SYNC_HOR_HIGH_ACT) != 0;
  629. rinfo->panel_info.vAct_high =
  630. (var->sync & FB_SYNC_VERT_HIGH_ACT) != 0;
  631. rinfo->panel_info.valid = 1;
  632. /* We use a default of 200ms for the panel power delay,
  633. * I need to have a real schedule() instead of mdelay's in the panel code.
  634. * we might be possible to figure out a better power delay either from
  635. * MacOS OF tree or from the EDID block (proprietary extensions ?)
  636. */
  637. rinfo->panel_info.pwr_delay = 200;
  638. }
  639. static void radeon_videomode_to_var(struct fb_var_screeninfo *var,
  640. const struct fb_videomode *mode)
  641. {
  642. var->xres = mode->xres;
  643. var->yres = mode->yres;
  644. var->xres_virtual = mode->xres;
  645. var->yres_virtual = mode->yres;
  646. var->xoffset = 0;
  647. var->yoffset = 0;
  648. var->pixclock = mode->pixclock;
  649. var->left_margin = mode->left_margin;
  650. var->right_margin = mode->right_margin;
  651. var->upper_margin = mode->upper_margin;
  652. var->lower_margin = mode->lower_margin;
  653. var->hsync_len = mode->hsync_len;
  654. var->vsync_len = mode->vsync_len;
  655. var->sync = mode->sync;
  656. var->vmode = mode->vmode;
  657. }
  658. /*
  659. * Build the modedb for head 1 (head 2 will come later), check panel infos
  660. * from either BIOS or EDID, and pick up the default mode
  661. */
  662. void __devinit radeon_check_modes(struct radeonfb_info *rinfo, const char *mode_option)
  663. {
  664. struct fb_info * info = rinfo->info;
  665. int has_default_mode = 0;
  666. /*
  667. * Fill default var first
  668. */
  669. info->var = radeonfb_default_var;
  670. INIT_LIST_HEAD(&info->modelist);
  671. /*
  672. * First check out what BIOS has to say
  673. */
  674. if (rinfo->mon1_type == MT_LCD)
  675. radeon_get_panel_info_BIOS(rinfo);
  676. /*
  677. * Parse EDID detailed timings and deduce panel infos if any. Right now
  678. * we only deal with first entry returned by parse_EDID, we may do better
  679. * some day...
  680. */
  681. if (!rinfo->panel_info.use_bios_dividers && rinfo->mon1_type != MT_CRT
  682. && rinfo->mon1_EDID) {
  683. struct fb_var_screeninfo var;
  684. pr_debug("Parsing EDID data for panel info\n");
  685. if (fb_parse_edid(rinfo->mon1_EDID, &var) == 0) {
  686. if (var.xres >= rinfo->panel_info.xres &&
  687. var.yres >= rinfo->panel_info.yres)
  688. radeon_var_to_panel_info(rinfo, &var);
  689. }
  690. }
  691. /*
  692. * Do any additional platform/arch fixups to the panel infos
  693. */
  694. radeon_fixup_panel_info(rinfo);
  695. /*
  696. * If we have some valid panel infos, we setup the default mode based on
  697. * those
  698. */
  699. if (rinfo->mon1_type != MT_CRT && rinfo->panel_info.valid) {
  700. struct fb_var_screeninfo *var = &info->var;
  701. pr_debug("Setting up default mode based on panel info\n");
  702. var->xres = rinfo->panel_info.xres;
  703. var->yres = rinfo->panel_info.yres;
  704. var->xres_virtual = rinfo->panel_info.xres;
  705. var->yres_virtual = rinfo->panel_info.yres;
  706. var->xoffset = var->yoffset = 0;
  707. var->bits_per_pixel = 8;
  708. var->pixclock = 100000000 / rinfo->panel_info.clock;
  709. var->left_margin = (rinfo->panel_info.hblank - rinfo->panel_info.hOver_plus
  710. - rinfo->panel_info.hSync_width);
  711. var->right_margin = rinfo->panel_info.hOver_plus;
  712. var->upper_margin = (rinfo->panel_info.vblank - rinfo->panel_info.vOver_plus
  713. - rinfo->panel_info.vSync_width);
  714. var->lower_margin = rinfo->panel_info.vOver_plus;
  715. var->hsync_len = rinfo->panel_info.hSync_width;
  716. var->vsync_len = rinfo->panel_info.vSync_width;
  717. var->sync = 0;
  718. if (rinfo->panel_info.hAct_high)
  719. var->sync |= FB_SYNC_HOR_HIGH_ACT;
  720. if (rinfo->panel_info.vAct_high)
  721. var->sync |= FB_SYNC_VERT_HIGH_ACT;
  722. var->vmode = 0;
  723. has_default_mode = 1;
  724. }
  725. /*
  726. * Now build modedb from EDID
  727. */
  728. if (rinfo->mon1_EDID) {
  729. fb_edid_to_monspecs(rinfo->mon1_EDID, &info->monspecs);
  730. fb_videomode_to_modelist(info->monspecs.modedb,
  731. info->monspecs.modedb_len,
  732. &info->modelist);
  733. rinfo->mon1_modedb = info->monspecs.modedb;
  734. rinfo->mon1_dbsize = info->monspecs.modedb_len;
  735. }
  736. /*
  737. * Finally, if we don't have panel infos we need to figure some (or
  738. * we try to read it from card), we try to pick a default mode
  739. * and create some panel infos. Whatever...
  740. */
  741. if (rinfo->mon1_type != MT_CRT && !rinfo->panel_info.valid) {
  742. struct fb_videomode *modedb;
  743. int dbsize;
  744. char modename[32];
  745. pr_debug("Guessing panel info...\n");
  746. if (rinfo->panel_info.xres == 0 || rinfo->panel_info.yres == 0) {
  747. u32 tmp = INREG(FP_HORZ_STRETCH) & HORZ_PANEL_SIZE;
  748. rinfo->panel_info.xres = ((tmp >> HORZ_PANEL_SHIFT) + 1) * 8;
  749. tmp = INREG(FP_VERT_STRETCH) & VERT_PANEL_SIZE;
  750. rinfo->panel_info.yres = (tmp >> VERT_PANEL_SHIFT) + 1;
  751. }
  752. if (rinfo->panel_info.xres == 0 || rinfo->panel_info.yres == 0) {
  753. printk(KERN_WARNING "radeonfb: Can't find panel size, going back to CRT\n");
  754. rinfo->mon1_type = MT_CRT;
  755. goto pickup_default;
  756. }
  757. printk(KERN_WARNING "radeonfb: Assuming panel size %dx%d\n",
  758. rinfo->panel_info.xres, rinfo->panel_info.yres);
  759. modedb = rinfo->mon1_modedb;
  760. dbsize = rinfo->mon1_dbsize;
  761. snprintf(modename, 31, "%dx%d", rinfo->panel_info.xres, rinfo->panel_info.yres);
  762. if (fb_find_mode(&info->var, info, modename,
  763. modedb, dbsize, NULL, 8) == 0) {
  764. printk(KERN_WARNING "radeonfb: Can't find mode for panel size, going back to CRT\n");
  765. rinfo->mon1_type = MT_CRT;
  766. goto pickup_default;
  767. }
  768. has_default_mode = 1;
  769. radeon_var_to_panel_info(rinfo, &info->var);
  770. }
  771. pickup_default:
  772. /*
  773. * Apply passed-in mode option if any
  774. */
  775. if (mode_option) {
  776. if (fb_find_mode(&info->var, info, mode_option,
  777. info->monspecs.modedb,
  778. info->monspecs.modedb_len, NULL, 8) != 0)
  779. has_default_mode = 1;
  780. }
  781. /*
  782. * Still no mode, let's pick up a default from the db
  783. */
  784. if (!has_default_mode && info->monspecs.modedb != NULL) {
  785. struct fb_monspecs *specs = &info->monspecs;
  786. struct fb_videomode *modedb = NULL;
  787. /* get preferred timing */
  788. if (specs->misc & FB_MISC_1ST_DETAIL) {
  789. int i;
  790. for (i = 0; i < specs->modedb_len; i++) {
  791. if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
  792. modedb = &specs->modedb[i];
  793. break;
  794. }
  795. }
  796. } else {
  797. /* otherwise, get first mode in database */
  798. modedb = &specs->modedb[0];
  799. }
  800. if (modedb != NULL) {
  801. info->var.bits_per_pixel = 8;
  802. radeon_videomode_to_var(&info->var, modedb);
  803. has_default_mode = 1;
  804. }
  805. }
  806. if (1) {
  807. struct fb_videomode mode;
  808. /* Make sure that whatever mode got selected is actually in the
  809. * modelist or the kernel may die
  810. */
  811. fb_var_to_videomode(&mode, &info->var);
  812. fb_add_videomode(&mode, &info->modelist);
  813. }
  814. }
  815. /*
  816. * The code below is used to pick up a mode in check_var and
  817. * set_var. It should be made generic
  818. */
  819. /*
  820. * This is used when looking for modes. We assign a "distance" value
  821. * to a mode in the modedb depending how "close" it is from what we
  822. * are looking for.
  823. * Currently, we don't compare that much, we could do better but
  824. * the current fbcon doesn't quite mind ;)
  825. */
  826. static int radeon_compare_modes(const struct fb_var_screeninfo *var,
  827. const struct fb_videomode *mode)
  828. {
  829. int distance = 0;
  830. distance = mode->yres - var->yres;
  831. distance += (mode->xres - var->xres)/2;
  832. return distance;
  833. }
  834. /*
  835. * This function is called by check_var, it gets the passed in mode parameter, and
  836. * outputs a valid mode matching the passed-in one as closely as possible.
  837. * We need something better ultimately. Things like fbcon basically pass us out
  838. * current mode with xres/yres hacked, while things like XFree will actually
  839. * produce a full timing that we should respect as much as possible.
  840. *
  841. * This is why I added the FB_ACTIVATE_FIND that is used by fbcon. Without this,
  842. * we do a simple spec match, that's all. With it, we actually look for a mode in
  843. * either our monitor modedb or the vesa one if none
  844. *
  845. */
  846. int radeon_match_mode(struct radeonfb_info *rinfo,
  847. struct fb_var_screeninfo *dest,
  848. const struct fb_var_screeninfo *src)
  849. {
  850. const struct fb_videomode *db = vesa_modes;
  851. int i, dbsize = 34;
  852. int has_rmx, native_db = 0;
  853. int distance = INT_MAX;
  854. const struct fb_videomode *candidate = NULL;
  855. /* Start with a copy of the requested mode */
  856. memcpy(dest, src, sizeof(struct fb_var_screeninfo));
  857. /* Check if we have a modedb built from EDID */
  858. if (rinfo->mon1_modedb) {
  859. db = rinfo->mon1_modedb;
  860. dbsize = rinfo->mon1_dbsize;
  861. native_db = 1;
  862. }
  863. /* Check if we have a scaler allowing any fancy mode */
  864. has_rmx = rinfo->mon1_type == MT_LCD || rinfo->mon1_type == MT_DFP;
  865. /* If we have a scaler and are passed FB_ACTIVATE_TEST or
  866. * FB_ACTIVATE_NOW, just do basic checking and return if the
  867. * mode match
  868. */
  869. if ((src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_TEST ||
  870. (src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
  871. /* We don't have an RMX, validate timings. If we don't have
  872. * monspecs, we should be paranoid and not let use go above
  873. * 640x480-60, but I assume userland knows what it's doing here
  874. * (though I may be proven wrong...)
  875. */
  876. if (has_rmx == 0 && rinfo->mon1_modedb)
  877. if (fb_validate_mode((struct fb_var_screeninfo *)src, rinfo->info))
  878. return -EINVAL;
  879. return 0;
  880. }
  881. /* Now look for a mode in the database */
  882. while (db) {
  883. for (i = 0; i < dbsize; i++) {
  884. int d;
  885. if (db[i].yres < src->yres)
  886. continue;
  887. if (db[i].xres < src->xres)
  888. continue;
  889. d = radeon_compare_modes(src, &db[i]);
  890. /* If the new mode is at least as good as the previous one,
  891. * then it's our new candidate
  892. */
  893. if (d < distance) {
  894. candidate = &db[i];
  895. distance = d;
  896. }
  897. }
  898. db = NULL;
  899. /* If we have a scaler, we allow any mode from the database */
  900. if (native_db && has_rmx) {
  901. db = vesa_modes;
  902. dbsize = 34;
  903. native_db = 0;
  904. }
  905. }
  906. /* If we have found a match, return it */
  907. if (candidate != NULL) {
  908. radeon_videomode_to_var(dest, candidate);
  909. return 0;
  910. }
  911. /* If we haven't and don't have a scaler, fail */
  912. if (!has_rmx)
  913. return -EINVAL;
  914. return 0;
  915. }