radeon_monitor.c 30 KB

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