6 #include <asm/pci-bridge.h>
7 #endif /* CONFIG_PPC_OF */
9 static struct fb_var_screeninfo radeonfb_default_var = {
15 .red = { .length = 8 },
16 .green = { .length = 8 },
17 .blue = { .length = 8 },
18 .activate = FB_ACTIVATE_NOW,
28 .vmode = FB_VMODE_NONINTERLACED
31 static char *radeon_get_mon_name(int type)
62 * Try to find monitor informations & EDID data out of the Open Firmware
63 * device-tree. This also contains some "hacks" to work around a few machine
64 * models with broken OF probing by hard-coding known EDIDs for some Mac
65 * laptops internal LVDS panel. (XXX: not done yet)
67 static int __devinit radeon_parse_montype_prop(struct device_node *dp, u8 **out_EDID, int hdno)
69 static char *propnames[] = { "DFP,EDID", "LCD,EDID", "EDID", "EDID1", "EDID2", NULL };
75 RTRACE("analyzing OF properties...\n");
76 pmt = (u8 *)get_property(dp, "display-type", NULL);
79 RTRACE("display-type: %s\n", pmt);
80 /* OF says "LCD" for DFP as well, we discriminate from the caller of this
83 if (!strcmp(pmt, "LCD") || !strcmp(pmt, "DFP"))
85 else if (!strcmp(pmt, "CRT"))
88 if (strcmp(pmt, "NONE") != 0)
89 printk(KERN_WARNING "radeonfb: Unknown OF display-type: %s\n",
94 for (i = 0; propnames[i] != NULL; ++i) {
95 pedid = (u8 *)get_property(dp, propnames[i], NULL);
99 /* We didn't find the EDID in the leaf node, some cards will actually
100 * put EDID1/EDID2 in the parent, look for these (typically M6 tipb).
101 * single-head cards have hdno == -1 and skip this step
103 if (pedid == NULL && dp->parent && (hdno != -1))
104 pedid = get_property(dp->parent, (hdno == 0) ? "EDID1" : "EDID2", NULL);
105 if (pedid == NULL && dp->parent && (hdno == 0))
106 pedid = get_property(dp->parent, "EDID", NULL);
110 tmp = (u8 *)kmalloc(EDID_LENGTH, GFP_KERNEL);
113 memcpy(tmp, pedid, EDID_LENGTH);
118 static int __devinit radeon_probe_OF_head(struct radeonfb_info *rinfo, int head_no,
121 struct device_node *dp;
123 RTRACE("radeon_probe_OF_head\n");
125 dp = pci_device_to_OF_node(rinfo->pdev);
129 if (rinfo->has_CRTC2) {
137 pname = (char *)get_property(dp, "name", NULL);
141 RTRACE("head: %s (letter: %c, head_no: %d)\n",
142 pname, pname[len-1], head_no);
143 if (pname[len-1] == 'A' && head_no == 0) {
144 int mt = radeon_parse_montype_prop(dp, out_EDID, 0);
145 /* Maybe check for LVDS_GEN_CNTL here ? I need to check out
146 * what OF does when booting with lid closed
148 if (mt == MT_DFP && rinfo->is_mobility)
151 } else if (pname[len-1] == 'B' && head_no == 1)
152 return radeon_parse_montype_prop(dp, out_EDID, 1);
159 return radeon_parse_montype_prop(dp, out_EDID, -1);
163 #endif /* CONFIG_PPC_OF */
166 static int __devinit radeon_get_panel_info_BIOS(struct radeonfb_info *rinfo)
168 unsigned long tmp, tmp0;
172 if (!rinfo->bios_seg)
175 if (!(tmp = BIOS_IN16(rinfo->fp_bios_start + 0x40))) {
176 printk(KERN_ERR "radeonfb: Failed to detect DFP panel info using BIOS\n");
177 rinfo->panel_info.pwr_delay = 200;
182 stmp[i] = BIOS_IN8(tmp+i+1);
184 printk("radeonfb: panel ID string: %s\n", stmp);
185 rinfo->panel_info.xres = BIOS_IN16(tmp + 25);
186 rinfo->panel_info.yres = BIOS_IN16(tmp + 27);
187 printk("radeonfb: detected LVDS panel size from BIOS: %dx%d\n",
188 rinfo->panel_info.xres, rinfo->panel_info.yres);
190 rinfo->panel_info.pwr_delay = BIOS_IN16(tmp + 44);
191 RTRACE("BIOS provided panel power delay: %d\n", rinfo->panel_info.pwr_delay);
192 if (rinfo->panel_info.pwr_delay > 2000 || rinfo->panel_info.pwr_delay <= 0)
193 rinfo->panel_info.pwr_delay = 2000;
196 * Some panels only work properly with some divider combinations
198 rinfo->panel_info.ref_divider = BIOS_IN16(tmp + 46);
199 rinfo->panel_info.post_divider = BIOS_IN8(tmp + 48);
200 rinfo->panel_info.fbk_divider = BIOS_IN16(tmp + 49);
201 if (rinfo->panel_info.ref_divider != 0 &&
202 rinfo->panel_info.fbk_divider > 3) {
203 rinfo->panel_info.use_bios_dividers = 1;
204 printk(KERN_INFO "radeondb: BIOS provided dividers will be used\n");
205 RTRACE("ref_divider = %x\n", rinfo->panel_info.ref_divider);
206 RTRACE("post_divider = %x\n", rinfo->panel_info.post_divider);
207 RTRACE("fbk_divider = %x\n", rinfo->panel_info.fbk_divider);
209 RTRACE("Scanning BIOS table ...\n");
210 for(i=0; i<32; i++) {
211 tmp0 = BIOS_IN16(tmp+64+i*2);
214 RTRACE(" %d x %d\n", BIOS_IN16(tmp0), BIOS_IN16(tmp0+2));
215 if ((BIOS_IN16(tmp0) == rinfo->panel_info.xres) &&
216 (BIOS_IN16(tmp0+2) == rinfo->panel_info.yres)) {
217 rinfo->panel_info.hblank = (BIOS_IN16(tmp0+17) - BIOS_IN16(tmp0+19)) * 8;
218 rinfo->panel_info.hOver_plus = ((BIOS_IN16(tmp0+21) -
219 BIOS_IN16(tmp0+19) -1) * 8) & 0x7fff;
220 rinfo->panel_info.hSync_width = BIOS_IN8(tmp0+23) * 8;
221 rinfo->panel_info.vblank = BIOS_IN16(tmp0+24) - BIOS_IN16(tmp0+26);
222 rinfo->panel_info.vOver_plus = (BIOS_IN16(tmp0+28) & 0x7ff) - BIOS_IN16(tmp0+26);
223 rinfo->panel_info.vSync_width = (BIOS_IN16(tmp0+28) & 0xf800) >> 11;
224 rinfo->panel_info.clock = BIOS_IN16(tmp0+9);
225 /* Assume high active syncs for now until ATI tells me more... maybe we
226 * can probe register values here ?
228 rinfo->panel_info.hAct_high = 1;
229 rinfo->panel_info.vAct_high = 1;
230 /* Mark panel infos valid */
231 rinfo->panel_info.valid = 1;
233 RTRACE("Found panel in BIOS table:\n");
234 RTRACE(" hblank: %d\n", rinfo->panel_info.hblank);
235 RTRACE(" hOver_plus: %d\n", rinfo->panel_info.hOver_plus);
236 RTRACE(" hSync_width: %d\n", rinfo->panel_info.hSync_width);
237 RTRACE(" vblank: %d\n", rinfo->panel_info.vblank);
238 RTRACE(" vOver_plus: %d\n", rinfo->panel_info.vOver_plus);
239 RTRACE(" vSync_width: %d\n", rinfo->panel_info.vSync_width);
240 RTRACE(" clock: %d\n", rinfo->panel_info.clock);
245 RTRACE("Didn't find panel in BIOS table !\n");
250 /* Try to extract the connector informations from the BIOS. This
251 * doesn't quite work yet, but it's output is still useful for
254 static void __devinit radeon_parse_connector_info(struct radeonfb_info *rinfo)
256 int offset, chips, connectors, tmp, i, conn, type;
258 static char* __conn_type_table[16] = {
259 "NONE", "Proprietary", "CRT", "DVI-I", "DVI-D", "Unknown", "Unknown",
260 "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown",
261 "Unknown", "Unknown", "Unknown"
264 if (!rinfo->bios_seg)
267 offset = BIOS_IN16(rinfo->fp_bios_start + 0x50);
269 printk(KERN_WARNING "radeonfb: No connector info table detected\n");
273 /* Don't do much more at this point but displaying the data if
276 chips = BIOS_IN8(offset++) >> 4;
277 RTRACE("%d chips in connector info\n", chips);
278 for (i = 0; i < chips; i++) {
279 tmp = BIOS_IN8(offset++);
280 connectors = tmp & 0x0f;
281 RTRACE(" - chip %d has %d connectors\n", tmp >> 4, connectors);
282 for (conn = 0; ; conn++) {
283 tmp = BIOS_IN16(offset);
287 type = (tmp >> 12) & 0x0f;
288 RTRACE(" * connector %d of type %d (%s) : %04x\n",
289 conn, type, __conn_type_table[type], tmp);
296 * Probe physical connection of a CRT. This code comes from XFree
297 * as well and currently is only implemented for the CRT DAC, the
298 * code for the TVDAC is commented out in XFree as "non working"
300 static int __devinit radeon_crt_is_connected(struct radeonfb_info *rinfo, int is_crt_dac)
304 /* the monitor either wasn't connected or it is a non-DDC CRT.
308 unsigned long ulOrigVCLK_ECP_CNTL;
309 unsigned long ulOrigDAC_CNTL;
310 unsigned long ulOrigDAC_EXT_CNTL;
311 unsigned long ulOrigCRTC_EXT_CNTL;
312 unsigned long ulData;
313 unsigned long ulMask;
315 ulOrigVCLK_ECP_CNTL = INPLL(VCLK_ECP_CNTL);
317 ulData = ulOrigVCLK_ECP_CNTL;
318 ulData &= ~(PIXCLK_ALWAYS_ONb
319 | PIXCLK_DAC_ALWAYS_ONb);
320 ulMask = ~(PIXCLK_ALWAYS_ONb
321 | PIXCLK_DAC_ALWAYS_ONb);
322 OUTPLLP(VCLK_ECP_CNTL, ulData, ulMask);
324 ulOrigCRTC_EXT_CNTL = INREG(CRTC_EXT_CNTL);
325 ulData = ulOrigCRTC_EXT_CNTL;
326 ulData |= CRTC_CRT_ON;
327 OUTREG(CRTC_EXT_CNTL, ulData);
329 ulOrigDAC_EXT_CNTL = INREG(DAC_EXT_CNTL);
330 ulData = ulOrigDAC_EXT_CNTL;
331 ulData &= ~DAC_FORCE_DATA_MASK;
332 ulData |= (DAC_FORCE_BLANK_OFF_EN
334 |DAC_FORCE_DATA_SEL_MASK);
335 if ((rinfo->family == CHIP_FAMILY_RV250) ||
336 (rinfo->family == CHIP_FAMILY_RV280))
337 ulData |= (0x01b6 << DAC_FORCE_DATA_SHIFT);
339 ulData |= (0x01ac << DAC_FORCE_DATA_SHIFT);
341 OUTREG(DAC_EXT_CNTL, ulData);
343 ulOrigDAC_CNTL = INREG(DAC_CNTL);
344 ulData = ulOrigDAC_CNTL;
345 ulData |= DAC_CMP_EN;
346 ulData &= ~(DAC_RANGE_CNTL_MASK
349 OUTREG(DAC_CNTL, ulData);
353 ulData = INREG(DAC_CNTL);
354 connected = (DAC_CMP_OUTPUT & ulData) ? 1 : 0;
356 ulData = ulOrigVCLK_ECP_CNTL;
357 ulMask = 0xFFFFFFFFL;
358 OUTPLLP(VCLK_ECP_CNTL, ulData, ulMask);
360 OUTREG(DAC_CNTL, ulOrigDAC_CNTL );
361 OUTREG(DAC_EXT_CNTL, ulOrigDAC_EXT_CNTL );
362 OUTREG(CRTC_EXT_CNTL, ulOrigCRTC_EXT_CNTL);
365 return connected ? MT_CRT : MT_NONE;
369 * Parse the "monitor_layout" string if any. This code is mostly
370 * copied from XFree's radeon driver
372 static int __devinit radeon_parse_monitor_layout(struct radeonfb_info *rinfo,
373 const char *monitor_layout)
376 int i = 0, second = 0;
409 if (strcmp(s1, "CRT") == 0)
410 rinfo->mon1_type = MT_CRT;
411 else if (strcmp(s1, "TMDS") == 0)
412 rinfo->mon1_type = MT_DFP;
413 else if (strcmp(s1, "LVDS") == 0)
414 rinfo->mon1_type = MT_LCD;
416 if (strcmp(s2, "CRT") == 0)
417 rinfo->mon2_type = MT_CRT;
418 else if (strcmp(s2, "TMDS") == 0)
419 rinfo->mon2_type = MT_DFP;
420 else if (strcmp(s2, "LVDS") == 0)
421 rinfo->mon2_type = MT_LCD;
427 * Probe display on both primary and secondary card's connector (if any)
428 * by various available techniques (i2c, OF device tree, BIOS, ...) and
429 * try to retreive EDID. The algorithm here comes from XFree's radeon
432 void __devinit radeon_probe_screens(struct radeonfb_info *rinfo,
433 const char *monitor_layout, int ignore_edid)
435 #ifdef CONFIG_FB_RADEON_I2C
436 int ddc_crt2_used = 0;
440 radeon_parse_connector_info(rinfo);
442 if (radeon_parse_monitor_layout(rinfo, monitor_layout)) {
445 * If user specified a monitor_layout option, use it instead
446 * of auto-detecting. Maybe we should only use this argument
447 * on the first radeon card probed or provide a way to specify
448 * a layout for each card ?
451 RTRACE("Using specified monitor layout: %s", monitor_layout);
452 #ifdef CONFIG_FB_RADEON_I2C
454 if (rinfo->mon1_type != MT_NONE)
455 if (!radeon_probe_i2c_connector(rinfo, ddc_dvi, &rinfo->mon1_EDID)) {
456 radeon_probe_i2c_connector(rinfo, ddc_crt2, &rinfo->mon1_EDID);
459 if (rinfo->mon2_type != MT_NONE)
460 if (!radeon_probe_i2c_connector(rinfo, ddc_vga, &rinfo->mon2_EDID) &&
462 radeon_probe_i2c_connector(rinfo, ddc_crt2, &rinfo->mon2_EDID);
464 #endif /* CONFIG_FB_RADEON_I2C */
465 if (rinfo->mon1_type == MT_NONE) {
466 if (rinfo->mon2_type != MT_NONE) {
467 rinfo->mon1_type = rinfo->mon2_type;
468 rinfo->mon1_EDID = rinfo->mon2_EDID;
470 rinfo->mon1_type = MT_CRT;
471 printk(KERN_INFO "radeonfb: No valid monitor, assuming CRT on first port\n");
473 rinfo->mon2_type = MT_NONE;
474 rinfo->mon2_EDID = NULL;
478 * Auto-detecting display type (well... trying to ...)
481 RTRACE("Starting monitor auto detection...\n");
483 #if DEBUG && defined(CONFIG_FB_RADEON_I2C)
485 u8 *EDIDs[4] = { NULL, NULL, NULL, NULL };
486 int mon_types[4] = {MT_NONE, MT_NONE, MT_NONE, MT_NONE};
489 for (i = 0; i < 4; i++)
490 mon_types[i] = radeon_probe_i2c_connector(rinfo,
495 * Old single head cards
497 if (!rinfo->has_CRTC2) {
499 if (rinfo->mon1_type == MT_NONE)
500 rinfo->mon1_type = radeon_probe_OF_head(rinfo, 0,
502 #endif /* CONFIG_PPC_OF */
503 #ifdef CONFIG_FB_RADEON_I2C
504 if (rinfo->mon1_type == MT_NONE)
505 rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_dvi,
507 if (rinfo->mon1_type == MT_NONE)
509 radeon_probe_i2c_connector(rinfo, ddc_vga,
511 if (rinfo->mon1_type == MT_NONE)
513 radeon_probe_i2c_connector(rinfo, ddc_crt2,
515 #endif /* CONFIG_FB_RADEON_I2C */
516 if (rinfo->mon1_type == MT_NONE)
517 rinfo->mon1_type = MT_CRT;
522 * Check for cards with reversed DACs or TMDS controllers using BIOS
524 if (rinfo->bios_seg &&
525 (tmp = BIOS_IN16(rinfo->fp_bios_start + 0x50))) {
526 for (i = 1; i < 4; i++) {
529 if (!BIOS_IN8(tmp + i*2) && i > 1)
531 tmp0 = BIOS_IN16(tmp + i*2);
532 if ((!(tmp0 & 0x01)) && (((tmp0 >> 8) & 0x0f) == ddc_dvi)) {
533 rinfo->reversed_DAC = 1;
534 printk(KERN_INFO "radeonfb: Reversed DACs detected\n");
536 if ((((tmp0 >> 8) & 0x0f) == ddc_dvi) && ((tmp0 >> 4) & 0x01)) {
537 rinfo->reversed_TMDS = 1;
538 printk(KERN_INFO "radeonfb: Reversed TMDS detected\n");
544 * Probe primary head (DVI or laptop internal panel)
547 if (rinfo->mon1_type == MT_NONE)
548 rinfo->mon1_type = radeon_probe_OF_head(rinfo, 0, &rinfo->mon1_EDID);
549 #endif /* CONFIG_PPC_OF */
550 #ifdef CONFIG_FB_RADEON_I2C
551 if (rinfo->mon1_type == MT_NONE)
552 rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_dvi,
554 if (rinfo->mon1_type == MT_NONE) {
555 rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_crt2,
557 if (rinfo->mon1_type != MT_NONE)
560 #endif /* CONFIG_FB_RADEON_I2C */
561 if (rinfo->mon1_type == MT_NONE && rinfo->is_mobility &&
562 ((rinfo->bios_seg && (INREG(BIOS_4_SCRATCH) & 4))
563 || (INREG(LVDS_GEN_CNTL) & LVDS_ON))) {
564 rinfo->mon1_type = MT_LCD;
565 printk("Non-DDC laptop panel detected\n");
567 if (rinfo->mon1_type == MT_NONE)
568 rinfo->mon1_type = radeon_crt_is_connected(rinfo, rinfo->reversed_DAC);
571 * Probe secondary head (mostly VGA, can be DVI)
574 if (rinfo->mon2_type == MT_NONE)
575 rinfo->mon2_type = radeon_probe_OF_head(rinfo, 1, &rinfo->mon2_EDID);
576 #endif /* CONFIG_PPC_OF */
577 #ifdef CONFIG_FB_RADEON_I2C
578 if (rinfo->mon2_type == MT_NONE)
579 rinfo->mon2_type = radeon_probe_i2c_connector(rinfo, ddc_vga,
581 if (rinfo->mon2_type == MT_NONE && !ddc_crt2_used)
582 rinfo->mon2_type = radeon_probe_i2c_connector(rinfo, ddc_crt2,
584 #endif /* CONFIG_FB_RADEON_I2C */
585 if (rinfo->mon2_type == MT_NONE)
586 rinfo->mon2_type = radeon_crt_is_connected(rinfo, !rinfo->reversed_DAC);
589 * If we only detected port 2, we swap them, if none detected,
590 * assume CRT (maybe fallback to old BIOS_SCRATCH stuff ? or look
593 if (rinfo->mon1_type == MT_NONE) {
594 if (rinfo->mon2_type != MT_NONE) {
595 rinfo->mon1_type = rinfo->mon2_type;
596 rinfo->mon1_EDID = rinfo->mon2_EDID;
598 rinfo->mon1_type = MT_CRT;
599 rinfo->mon2_type = MT_NONE;
600 rinfo->mon2_EDID = NULL;
604 * Deal with reversed TMDS
606 if (rinfo->reversed_TMDS) {
607 /* Always keep internal TMDS as primary head */
608 if (rinfo->mon1_type == MT_DFP || rinfo->mon2_type == MT_DFP) {
609 int tmp_type = rinfo->mon1_type;
610 u8 *tmp_EDID = rinfo->mon1_EDID;
611 rinfo->mon1_type = rinfo->mon2_type;
612 rinfo->mon1_EDID = rinfo->mon2_EDID;
613 rinfo->mon2_type = tmp_type;
614 rinfo->mon2_EDID = tmp_EDID;
615 if (rinfo->mon1_type == MT_CRT || rinfo->mon2_type == MT_CRT)
616 rinfo->reversed_DAC ^= 1;
621 if (rinfo->mon1_EDID)
622 kfree(rinfo->mon1_EDID);
623 rinfo->mon1_EDID = NULL;
624 if (rinfo->mon2_EDID)
625 kfree(rinfo->mon2_EDID);
626 rinfo->mon2_EDID = NULL;
630 printk(KERN_INFO "radeonfb: Monitor 1 type %s found\n",
631 radeon_get_mon_name(rinfo->mon1_type));
632 if (rinfo->mon1_EDID)
633 printk(KERN_INFO "radeonfb: EDID probed\n");
634 if (!rinfo->has_CRTC2)
636 printk(KERN_INFO "radeonfb: Monitor 2 type %s found\n",
637 radeon_get_mon_name(rinfo->mon2_type));
638 if (rinfo->mon2_EDID)
639 printk(KERN_INFO "radeonfb: EDID probed\n");
644 * This functions applyes any arch/model/machine specific fixups
645 * to the panel info. It may eventually alter EDID block as
646 * well or whatever is specific to a given model and not probed
647 * properly by the default code
649 static void radeon_fixup_panel_info(struct radeonfb_info *rinfo)
653 * LCD Flat panels should use fixed dividers, we enfore that on
654 * PowerMac only for now...
656 if (!rinfo->panel_info.use_bios_dividers && rinfo->mon1_type == MT_LCD
657 && rinfo->is_mobility) {
658 int ppll_div_sel = INREG8(CLOCK_CNTL_INDEX + 1) & 0x3;
659 u32 ppll_divn = INPLL(PPLL_DIV_0 + ppll_div_sel);
660 rinfo->panel_info.ref_divider = rinfo->pll.ref_div;
661 rinfo->panel_info.fbk_divider = ppll_divn & 0x7ff;
662 rinfo->panel_info.post_divider = (ppll_divn >> 16) & 0x7;
663 rinfo->panel_info.use_bios_dividers = 1;
665 printk(KERN_DEBUG "radeonfb: Using Firmware dividers 0x%08x "
667 rinfo->panel_info.fbk_divider |
668 (rinfo->panel_info.post_divider << 16),
671 #endif /* CONFIG_PPC_OF */
676 * Fill up panel infos from a mode definition, either returned by the EDID
677 * or from the default mode when we can't do any better
679 static void radeon_var_to_panel_info(struct radeonfb_info *rinfo, struct fb_var_screeninfo *var)
681 rinfo->panel_info.xres = var->xres;
682 rinfo->panel_info.yres = var->yres;
683 rinfo->panel_info.clock = 100000000 / var->pixclock;
684 rinfo->panel_info.hOver_plus = var->right_margin;
685 rinfo->panel_info.hSync_width = var->hsync_len;
686 rinfo->panel_info.hblank = var->left_margin +
687 (var->right_margin + var->hsync_len);
688 rinfo->panel_info.vOver_plus = var->lower_margin;
689 rinfo->panel_info.vSync_width = var->vsync_len;
690 rinfo->panel_info.vblank = var->upper_margin +
691 (var->lower_margin + var->vsync_len);
692 rinfo->panel_info.hAct_high =
693 (var->sync & FB_SYNC_HOR_HIGH_ACT) != 0;
694 rinfo->panel_info.vAct_high =
695 (var->sync & FB_SYNC_VERT_HIGH_ACT) != 0;
696 rinfo->panel_info.valid = 1;
697 /* We use a default of 200ms for the panel power delay,
698 * I need to have a real schedule() instead of mdelay's in the panel code.
699 * we might be possible to figure out a better power delay either from
700 * MacOS OF tree or from the EDID block (proprietary extensions ?)
702 rinfo->panel_info.pwr_delay = 200;
705 static void radeon_var_to_videomode(struct fb_videomode *mode,
706 const struct fb_var_screeninfo *var)
708 mode->xres = var->xres;
709 mode->yres = var->yres;
710 mode->pixclock = var->pixclock;
711 mode->left_margin = var->left_margin;
712 mode->right_margin = var->right_margin;
713 mode->upper_margin = var->upper_margin;
714 mode->lower_margin = var->lower_margin;
715 mode->hsync_len = var->hsync_len;
716 mode->vsync_len = var->vsync_len;
717 mode->sync = var->sync;
718 mode->vmode = var->vmode;
721 static void radeon_videomode_to_var(struct fb_var_screeninfo *var,
722 const struct fb_videomode *mode)
724 var->xres = mode->xres;
725 var->yres = mode->yres;
726 var->xres_virtual = mode->xres;
727 var->yres_virtual = mode->yres;
730 var->pixclock = mode->pixclock;
731 var->left_margin = mode->left_margin;
732 var->right_margin = mode->right_margin;
733 var->upper_margin = mode->upper_margin;
734 var->lower_margin = mode->lower_margin;
735 var->hsync_len = mode->hsync_len;
736 var->vsync_len = mode->vsync_len;
737 var->sync = mode->sync;
738 var->vmode = mode->vmode;
742 * Build the modedb for head 1 (head 2 will come later), check panel infos
743 * from either BIOS or EDID, and pick up the default mode
745 void __devinit radeon_check_modes(struct radeonfb_info *rinfo, const char *mode_option)
747 int has_default_mode = 0;
750 * Fill default var first
752 rinfo->info->var = radeonfb_default_var;
755 * First check out what BIOS has to say
757 if (rinfo->mon1_type == MT_LCD)
758 radeon_get_panel_info_BIOS(rinfo);
761 * Parse EDID detailed timings and deduce panel infos if any. Right now
762 * we only deal with first entry returned by parse_EDID, we may do better
765 if (!rinfo->panel_info.use_bios_dividers && rinfo->mon1_type != MT_CRT
766 && rinfo->mon1_EDID) {
767 struct fb_var_screeninfo var;
768 RTRACE("Parsing EDID data for panel info\n");
769 if (fb_parse_edid(rinfo->mon1_EDID, &var) == 0) {
770 if (var.xres >= rinfo->panel_info.xres &&
771 var.yres >= rinfo->panel_info.yres)
772 radeon_var_to_panel_info(rinfo, &var);
777 * Do any additional platform/arch fixups to the panel infos
779 radeon_fixup_panel_info(rinfo);
782 * If we have some valid panel infos, we setup the default mode based on
785 if (rinfo->mon1_type != MT_CRT && rinfo->panel_info.valid) {
786 struct fb_var_screeninfo *var = &rinfo->info->var;
788 RTRACE("Setting up default mode based on panel info\n");
789 var->xres = rinfo->panel_info.xres;
790 var->yres = rinfo->panel_info.yres;
791 var->xres_virtual = rinfo->panel_info.xres;
792 var->yres_virtual = rinfo->panel_info.yres;
793 var->xoffset = var->yoffset = 0;
794 var->bits_per_pixel = 8;
795 var->pixclock = 100000000 / rinfo->panel_info.clock;
796 var->left_margin = (rinfo->panel_info.hblank - rinfo->panel_info.hOver_plus
797 - rinfo->panel_info.hSync_width);
798 var->right_margin = rinfo->panel_info.hOver_plus;
799 var->upper_margin = (rinfo->panel_info.vblank - rinfo->panel_info.vOver_plus
800 - rinfo->panel_info.vSync_width);
801 var->lower_margin = rinfo->panel_info.vOver_plus;
802 var->hsync_len = rinfo->panel_info.hSync_width;
803 var->vsync_len = rinfo->panel_info.vSync_width;
805 if (rinfo->panel_info.hAct_high)
806 var->sync |= FB_SYNC_HOR_HIGH_ACT;
807 if (rinfo->panel_info.vAct_high)
808 var->sync |= FB_SYNC_VERT_HIGH_ACT;
810 has_default_mode = 1;
814 * Now build modedb from EDID
816 if (rinfo->mon1_EDID) {
817 rinfo->mon1_modedb = fb_create_modedb(rinfo->mon1_EDID,
818 &rinfo->mon1_dbsize);
819 fb_get_monitor_limits(rinfo->mon1_EDID, &rinfo->info->monspecs);
824 * Finally, if we don't have panel infos we need to figure some (or
825 * we try to read it from card), we try to pick a default mode
826 * and create some panel infos. Whatever...
828 if (rinfo->mon1_type != MT_CRT && !rinfo->panel_info.valid) {
829 struct fb_videomode *modedb;
833 RTRACE("Guessing panel info...\n");
834 if (rinfo->panel_info.xres == 0 || rinfo->panel_info.yres == 0) {
835 u32 tmp = INREG(FP_HORZ_STRETCH) & HORZ_PANEL_SIZE;
836 rinfo->panel_info.xres = ((tmp >> HORZ_PANEL_SHIFT) + 1) * 8;
837 tmp = INREG(FP_VERT_STRETCH) & VERT_PANEL_SIZE;
838 rinfo->panel_info.yres = (tmp >> VERT_PANEL_SHIFT) + 1;
840 if (rinfo->panel_info.xres == 0 || rinfo->panel_info.yres == 0) {
841 printk(KERN_WARNING "radeonfb: Can't find panel size, going back to CRT\n");
842 rinfo->mon1_type = MT_CRT;
845 printk(KERN_WARNING "radeonfb: Assuming panel size %dx%d\n",
846 rinfo->panel_info.xres, rinfo->panel_info.yres);
847 modedb = rinfo->mon1_modedb;
848 dbsize = rinfo->mon1_dbsize;
849 snprintf(modename, 31, "%dx%d", rinfo->panel_info.xres, rinfo->panel_info.yres);
850 if (fb_find_mode(&rinfo->info->var, rinfo->info, modename,
851 modedb, dbsize, NULL, 8) == 0) {
852 printk(KERN_WARNING "radeonfb: Can't find mode for panel size, going back to CRT\n");
853 rinfo->mon1_type = MT_CRT;
856 has_default_mode = 1;
857 radeon_var_to_panel_info(rinfo, &rinfo->info->var);
862 * Pick up a random default mode
864 if (!has_default_mode || mode_option) {
865 struct fb_videomode default_mode;
866 if (has_default_mode)
867 radeon_var_to_videomode(&default_mode, &rinfo->info->var);
869 radeon_var_to_videomode(&default_mode, &radeonfb_default_var);
870 if (fb_find_mode(&rinfo->info->var, rinfo->info, mode_option,
871 rinfo->mon1_modedb, rinfo->mon1_dbsize, &default_mode, 8) == 0)
872 rinfo->info->var = radeonfb_default_var;
878 * The code below is used to pick up a mode in check_var and
879 * set_var. It should be made generic
883 * This is used when looking for modes. We assign a "goodness" value
884 * to a mode in the modedb depending how "close" it is from what we
886 * Currently, we don't compare that much, we could do better but
887 * the current fbcon doesn't quite mind ;)
889 static int radeon_compare_modes(const struct fb_var_screeninfo *var,
890 const struct fb_videomode *mode)
894 if (var->yres == mode->yres)
896 if (var->xres == mode->xres)
902 * This function is called by check_var, it gets the passed in mode parameter, and
903 * outputs a valid mode matching the passed-in one as closely as possible.
904 * We need something better ultimately. Things like fbcon basically pass us out
905 * current mode with xres/yres hacked, while things like XFree will actually
906 * produce a full timing that we should respect as much as possible.
908 * This is why I added the FB_ACTIVATE_FIND that is used by fbcon. Without this,
909 * we do a simple spec match, that's all. With it, we actually look for a mode in
910 * either our monitor modedb or the vesa one if none
913 int radeon_match_mode(struct radeonfb_info *rinfo,
914 struct fb_var_screeninfo *dest,
915 const struct fb_var_screeninfo *src)
917 const struct fb_videomode *db = vesa_modes;
919 int has_rmx, native_db = 0;
921 const struct fb_videomode *candidate = NULL;
923 /* Start with a copy of the requested mode */
924 memcpy(dest, src, sizeof(struct fb_var_screeninfo));
926 /* Check if we have a modedb built from EDID */
927 if (rinfo->mon1_modedb) {
928 db = rinfo->mon1_modedb;
929 dbsize = rinfo->mon1_dbsize;
933 /* Check if we have a scaler allowing any fancy mode */
934 has_rmx = rinfo->mon1_type == MT_LCD || rinfo->mon1_type == MT_DFP;
936 /* If we have a scaler and are passed FB_ACTIVATE_TEST or
937 * FB_ACTIVATE_NOW, just do basic checking and return if the
940 if ((src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_TEST ||
941 (src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
942 /* We don't have an RMX, validate timings. If we don't have
943 * monspecs, we should be paranoid and not let use go above
944 * 640x480-60, but I assume userland knows what it's doing here
945 * (though I may be proven wrong...)
947 if (has_rmx == 0 && rinfo->mon1_modedb)
948 if (fb_validate_mode((struct fb_var_screeninfo *)src, rinfo->info))
953 /* Now look for a mode in the database */
955 for (i = 0; i < dbsize; i++) {
958 if (db[i].yres < src->yres)
960 if (db[i].xres < src->xres)
962 g = radeon_compare_modes(src, &db[i]);
963 /* If the new mode is at least as good as the previous one,
964 * then it's our new candidate
972 /* If we have a scaler, we allow any mode from the database */
973 if (native_db && has_rmx) {
980 /* If we have found a match, return it */
981 if (candidate != NULL) {
982 radeon_videomode_to_var(dest, candidate);
986 /* If we haven't and don't have a scaler, fail */