4 static struct fb_var_screeninfo radeonfb_default_var = {
10 .red = { .length = 8 },
11 .green = { .length = 8 },
12 .blue = { .length = 8 },
13 .activate = FB_ACTIVATE_NOW,
23 .vmode = FB_VMODE_NONINTERLACED
26 static char *radeon_get_mon_name(int type)
57 * Try to find monitor informations & EDID data out of the Open Firmware
58 * device-tree. This also contains some "hacks" to work around a few machine
59 * models with broken OF probing by hard-coding known EDIDs for some Mac
60 * laptops internal LVDS panel. (XXX: not done yet)
62 static int __devinit radeon_parse_montype_prop(struct device_node *dp, u8 **out_EDID,
65 static char *propnames[] = { "DFP,EDID", "LCD,EDID", "EDID",
66 "EDID1", "EDID2", NULL };
67 const u8 *pedid = NULL;
72 RTRACE("analyzing OF properties...\n");
73 pmt = get_property(dp, "display-type", NULL);
76 RTRACE("display-type: %s\n", pmt);
77 /* OF says "LCD" for DFP as well, we discriminate from the caller of this
80 if (!strcmp(pmt, "LCD") || !strcmp(pmt, "DFP"))
82 else if (!strcmp(pmt, "CRT"))
85 if (strcmp(pmt, "NONE") != 0)
86 printk(KERN_WARNING "radeonfb: Unknown OF display-type: %s\n",
91 for (i = 0; propnames[i] != NULL; ++i) {
92 pedid = get_property(dp, propnames[i], NULL);
96 /* We didn't find the EDID in the leaf node, some cards will actually
97 * put EDID1/EDID2 in the parent, look for these (typically M6 tipb).
98 * single-head cards have hdno == -1 and skip this step
100 if (pedid == NULL && dp->parent && (hdno != -1))
101 pedid = get_property(dp->parent, (hdno == 0) ? "EDID1" : "EDID2", NULL);
102 if (pedid == NULL && dp->parent && (hdno == 0))
103 pedid = get_property(dp->parent, "EDID", NULL);
107 tmp = kmemdup(pedid, EDID_LENGTH, GFP_KERNEL);
114 static int __devinit radeon_probe_OF_head(struct radeonfb_info *rinfo, int head_no,
117 struct device_node *dp;
119 RTRACE("radeon_probe_OF_head\n");
125 if (rinfo->has_CRTC2) {
133 pname = get_property(dp, "name", NULL);
137 RTRACE("head: %s (letter: %c, head_no: %d)\n",
138 pname, pname[len-1], head_no);
139 if (pname[len-1] == 'A' && head_no == 0) {
140 int mt = radeon_parse_montype_prop(dp, out_EDID, 0);
141 /* Maybe check for LVDS_GEN_CNTL here ? I need to check out
142 * what OF does when booting with lid closed
144 if (mt == MT_DFP && rinfo->is_mobility)
147 } else if (pname[len-1] == 'B' && head_no == 1)
148 return radeon_parse_montype_prop(dp, out_EDID, 1);
155 return radeon_parse_montype_prop(dp, out_EDID, -1);
159 #endif /* CONFIG_PPC_OF */
162 static int __devinit radeon_get_panel_info_BIOS(struct radeonfb_info *rinfo)
164 unsigned long tmp, tmp0;
168 if (!rinfo->bios_seg)
171 if (!(tmp = BIOS_IN16(rinfo->fp_bios_start + 0x40))) {
172 printk(KERN_ERR "radeonfb: Failed to detect DFP panel info using BIOS\n");
173 rinfo->panel_info.pwr_delay = 200;
178 stmp[i] = BIOS_IN8(tmp+i+1);
180 printk("radeonfb: panel ID string: %s\n", stmp);
181 rinfo->panel_info.xres = BIOS_IN16(tmp + 25);
182 rinfo->panel_info.yres = BIOS_IN16(tmp + 27);
183 printk("radeonfb: detected LVDS panel size from BIOS: %dx%d\n",
184 rinfo->panel_info.xres, rinfo->panel_info.yres);
186 rinfo->panel_info.pwr_delay = BIOS_IN16(tmp + 44);
187 RTRACE("BIOS provided panel power delay: %d\n", rinfo->panel_info.pwr_delay);
188 if (rinfo->panel_info.pwr_delay > 2000 || rinfo->panel_info.pwr_delay <= 0)
189 rinfo->panel_info.pwr_delay = 2000;
192 * Some panels only work properly with some divider combinations
194 rinfo->panel_info.ref_divider = BIOS_IN16(tmp + 46);
195 rinfo->panel_info.post_divider = BIOS_IN8(tmp + 48);
196 rinfo->panel_info.fbk_divider = BIOS_IN16(tmp + 49);
197 if (rinfo->panel_info.ref_divider != 0 &&
198 rinfo->panel_info.fbk_divider > 3) {
199 rinfo->panel_info.use_bios_dividers = 1;
200 printk(KERN_INFO "radeondb: BIOS provided dividers will be used\n");
201 RTRACE("ref_divider = %x\n", rinfo->panel_info.ref_divider);
202 RTRACE("post_divider = %x\n", rinfo->panel_info.post_divider);
203 RTRACE("fbk_divider = %x\n", rinfo->panel_info.fbk_divider);
205 RTRACE("Scanning BIOS table ...\n");
206 for(i=0; i<32; i++) {
207 tmp0 = BIOS_IN16(tmp+64+i*2);
210 RTRACE(" %d x %d\n", BIOS_IN16(tmp0), BIOS_IN16(tmp0+2));
211 if ((BIOS_IN16(tmp0) == rinfo->panel_info.xres) &&
212 (BIOS_IN16(tmp0+2) == rinfo->panel_info.yres)) {
213 rinfo->panel_info.hblank = (BIOS_IN16(tmp0+17) - BIOS_IN16(tmp0+19)) * 8;
214 rinfo->panel_info.hOver_plus = ((BIOS_IN16(tmp0+21) -
215 BIOS_IN16(tmp0+19) -1) * 8) & 0x7fff;
216 rinfo->panel_info.hSync_width = BIOS_IN8(tmp0+23) * 8;
217 rinfo->panel_info.vblank = BIOS_IN16(tmp0+24) - BIOS_IN16(tmp0+26);
218 rinfo->panel_info.vOver_plus = (BIOS_IN16(tmp0+28) & 0x7ff) - BIOS_IN16(tmp0+26);
219 rinfo->panel_info.vSync_width = (BIOS_IN16(tmp0+28) & 0xf800) >> 11;
220 rinfo->panel_info.clock = BIOS_IN16(tmp0+9);
221 /* Assume high active syncs for now until ATI tells me more... maybe we
222 * can probe register values here ?
224 rinfo->panel_info.hAct_high = 1;
225 rinfo->panel_info.vAct_high = 1;
226 /* Mark panel infos valid */
227 rinfo->panel_info.valid = 1;
229 RTRACE("Found panel in BIOS table:\n");
230 RTRACE(" hblank: %d\n", rinfo->panel_info.hblank);
231 RTRACE(" hOver_plus: %d\n", rinfo->panel_info.hOver_plus);
232 RTRACE(" hSync_width: %d\n", rinfo->panel_info.hSync_width);
233 RTRACE(" vblank: %d\n", rinfo->panel_info.vblank);
234 RTRACE(" vOver_plus: %d\n", rinfo->panel_info.vOver_plus);
235 RTRACE(" vSync_width: %d\n", rinfo->panel_info.vSync_width);
236 RTRACE(" clock: %d\n", rinfo->panel_info.clock);
241 RTRACE("Didn't find panel in BIOS table !\n");
246 /* Try to extract the connector informations from the BIOS. This
247 * doesn't quite work yet, but it's output is still useful for
250 static void __devinit radeon_parse_connector_info(struct radeonfb_info *rinfo)
252 int offset, chips, connectors, tmp, i, conn, type;
254 static char* __conn_type_table[16] = {
255 "NONE", "Proprietary", "CRT", "DVI-I", "DVI-D", "Unknown", "Unknown",
256 "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown",
257 "Unknown", "Unknown", "Unknown"
260 if (!rinfo->bios_seg)
263 offset = BIOS_IN16(rinfo->fp_bios_start + 0x50);
265 printk(KERN_WARNING "radeonfb: No connector info table detected\n");
269 /* Don't do much more at this point but displaying the data if
272 chips = BIOS_IN8(offset++) >> 4;
273 RTRACE("%d chips in connector info\n", chips);
274 for (i = 0; i < chips; i++) {
275 tmp = BIOS_IN8(offset++);
276 connectors = tmp & 0x0f;
277 RTRACE(" - chip %d has %d connectors\n", tmp >> 4, connectors);
278 for (conn = 0; ; conn++) {
279 tmp = BIOS_IN16(offset);
283 type = (tmp >> 12) & 0x0f;
284 RTRACE(" * connector %d of type %d (%s) : %04x\n",
285 conn, type, __conn_type_table[type], tmp);
292 * Probe physical connection of a CRT. This code comes from XFree
293 * as well and currently is only implemented for the CRT DAC, the
294 * code for the TVDAC is commented out in XFree as "non working"
296 static int __devinit radeon_crt_is_connected(struct radeonfb_info *rinfo, int is_crt_dac)
300 /* the monitor either wasn't connected or it is a non-DDC CRT.
304 unsigned long ulOrigVCLK_ECP_CNTL;
305 unsigned long ulOrigDAC_CNTL;
306 unsigned long ulOrigDAC_EXT_CNTL;
307 unsigned long ulOrigCRTC_EXT_CNTL;
308 unsigned long ulData;
309 unsigned long ulMask;
311 ulOrigVCLK_ECP_CNTL = INPLL(VCLK_ECP_CNTL);
313 ulData = ulOrigVCLK_ECP_CNTL;
314 ulData &= ~(PIXCLK_ALWAYS_ONb
315 | PIXCLK_DAC_ALWAYS_ONb);
316 ulMask = ~(PIXCLK_ALWAYS_ONb
317 | PIXCLK_DAC_ALWAYS_ONb);
318 OUTPLLP(VCLK_ECP_CNTL, ulData, ulMask);
320 ulOrigCRTC_EXT_CNTL = INREG(CRTC_EXT_CNTL);
321 ulData = ulOrigCRTC_EXT_CNTL;
322 ulData |= CRTC_CRT_ON;
323 OUTREG(CRTC_EXT_CNTL, ulData);
325 ulOrigDAC_EXT_CNTL = INREG(DAC_EXT_CNTL);
326 ulData = ulOrigDAC_EXT_CNTL;
327 ulData &= ~DAC_FORCE_DATA_MASK;
328 ulData |= (DAC_FORCE_BLANK_OFF_EN
330 |DAC_FORCE_DATA_SEL_MASK);
331 if ((rinfo->family == CHIP_FAMILY_RV250) ||
332 (rinfo->family == CHIP_FAMILY_RV280))
333 ulData |= (0x01b6 << DAC_FORCE_DATA_SHIFT);
335 ulData |= (0x01ac << DAC_FORCE_DATA_SHIFT);
337 OUTREG(DAC_EXT_CNTL, ulData);
339 ulOrigDAC_CNTL = INREG(DAC_CNTL);
340 ulData = ulOrigDAC_CNTL;
341 ulData |= DAC_CMP_EN;
342 ulData &= ~(DAC_RANGE_CNTL_MASK
345 OUTREG(DAC_CNTL, ulData);
349 ulData = INREG(DAC_CNTL);
350 connected = (DAC_CMP_OUTPUT & ulData) ? 1 : 0;
352 ulData = ulOrigVCLK_ECP_CNTL;
353 ulMask = 0xFFFFFFFFL;
354 OUTPLLP(VCLK_ECP_CNTL, ulData, ulMask);
356 OUTREG(DAC_CNTL, ulOrigDAC_CNTL );
357 OUTREG(DAC_EXT_CNTL, ulOrigDAC_EXT_CNTL );
358 OUTREG(CRTC_EXT_CNTL, ulOrigCRTC_EXT_CNTL);
361 return connected ? MT_CRT : MT_NONE;
365 * Parse the "monitor_layout" string if any. This code is mostly
366 * copied from XFree's radeon driver
368 static int __devinit radeon_parse_monitor_layout(struct radeonfb_info *rinfo,
369 const char *monitor_layout)
372 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 retrieve 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)
506 radeon_probe_i2c_connector(rinfo, ddc_dvi,
508 if (rinfo->mon1_type == MT_NONE)
510 radeon_probe_i2c_connector(rinfo, ddc_vga,
512 if (rinfo->mon1_type == MT_NONE)
514 radeon_probe_i2c_connector(rinfo, ddc_crt2,
516 #endif /* CONFIG_FB_RADEON_I2C */
517 if (rinfo->mon1_type == MT_NONE)
518 rinfo->mon1_type = MT_CRT;
523 * Check for cards with reversed DACs or TMDS controllers using BIOS
525 if (rinfo->bios_seg &&
526 (tmp = BIOS_IN16(rinfo->fp_bios_start + 0x50))) {
527 for (i = 1; i < 4; i++) {
530 if (!BIOS_IN8(tmp + i*2) && i > 1)
532 tmp0 = BIOS_IN16(tmp + i*2);
533 if ((!(tmp0 & 0x01)) && (((tmp0 >> 8) & 0x0f) == ddc_dvi)) {
534 rinfo->reversed_DAC = 1;
535 printk(KERN_INFO "radeonfb: Reversed DACs detected\n");
537 if ((((tmp0 >> 8) & 0x0f) == ddc_dvi) && ((tmp0 >> 4) & 0x01)) {
538 rinfo->reversed_TMDS = 1;
539 printk(KERN_INFO "radeonfb: Reversed TMDS detected\n");
545 * Probe primary head (DVI or laptop internal panel)
548 if (rinfo->mon1_type == MT_NONE)
549 rinfo->mon1_type = radeon_probe_OF_head(rinfo, 0,
551 #endif /* CONFIG_PPC_OF */
552 #ifdef CONFIG_FB_RADEON_I2C
553 if (rinfo->mon1_type == MT_NONE)
554 rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_dvi,
556 if (rinfo->mon1_type == MT_NONE) {
557 rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_crt2,
559 if (rinfo->mon1_type != MT_NONE)
562 #endif /* CONFIG_FB_RADEON_I2C */
563 if (rinfo->mon1_type == MT_NONE && rinfo->is_mobility &&
564 ((rinfo->bios_seg && (INREG(BIOS_4_SCRATCH) & 4))
565 || (INREG(LVDS_GEN_CNTL) & LVDS_ON))) {
566 rinfo->mon1_type = MT_LCD;
567 printk("Non-DDC laptop panel detected\n");
569 if (rinfo->mon1_type == MT_NONE)
570 rinfo->mon1_type = radeon_crt_is_connected(rinfo, rinfo->reversed_DAC);
573 * Probe secondary head (mostly VGA, can be DVI)
576 if (rinfo->mon2_type == MT_NONE)
577 rinfo->mon2_type = radeon_probe_OF_head(rinfo, 1,
579 #endif /* CONFIG_PPC_OF */
580 #ifdef CONFIG_FB_RADEON_I2C
581 if (rinfo->mon2_type == MT_NONE)
582 rinfo->mon2_type = radeon_probe_i2c_connector(rinfo, ddc_vga,
584 if (rinfo->mon2_type == MT_NONE && !ddc_crt2_used)
585 rinfo->mon2_type = radeon_probe_i2c_connector(rinfo, ddc_crt2,
587 #endif /* CONFIG_FB_RADEON_I2C */
588 if (rinfo->mon2_type == MT_NONE)
589 rinfo->mon2_type = radeon_crt_is_connected(rinfo, !rinfo->reversed_DAC);
592 * If we only detected port 2, we swap them, if none detected,
593 * assume CRT (maybe fallback to old BIOS_SCRATCH stuff ? or look
596 if (rinfo->mon1_type == MT_NONE) {
597 if (rinfo->mon2_type != MT_NONE) {
598 rinfo->mon1_type = rinfo->mon2_type;
599 rinfo->mon1_EDID = rinfo->mon2_EDID;
601 rinfo->mon1_type = MT_CRT;
602 rinfo->mon2_type = MT_NONE;
603 rinfo->mon2_EDID = NULL;
607 * Deal with reversed TMDS
609 if (rinfo->reversed_TMDS) {
610 /* Always keep internal TMDS as primary head */
611 if (rinfo->mon1_type == MT_DFP || rinfo->mon2_type == MT_DFP) {
612 int tmp_type = rinfo->mon1_type;
613 u8 *tmp_EDID = rinfo->mon1_EDID;
614 rinfo->mon1_type = rinfo->mon2_type;
615 rinfo->mon1_EDID = rinfo->mon2_EDID;
616 rinfo->mon2_type = tmp_type;
617 rinfo->mon2_EDID = tmp_EDID;
618 if (rinfo->mon1_type == MT_CRT || rinfo->mon2_type == MT_CRT)
619 rinfo->reversed_DAC ^= 1;
624 kfree(rinfo->mon1_EDID);
625 rinfo->mon1_EDID = NULL;
626 kfree(rinfo->mon2_EDID);
627 rinfo->mon2_EDID = NULL;
631 printk(KERN_INFO "radeonfb: Monitor 1 type %s found\n",
632 radeon_get_mon_name(rinfo->mon1_type));
633 if (rinfo->mon1_EDID)
634 printk(KERN_INFO "radeonfb: EDID probed\n");
635 if (!rinfo->has_CRTC2)
637 printk(KERN_INFO "radeonfb: Monitor 2 type %s found\n",
638 radeon_get_mon_name(rinfo->mon2_type));
639 if (rinfo->mon2_EDID)
640 printk(KERN_INFO "radeonfb: EDID probed\n");
645 * This functions applyes any arch/model/machine specific fixups
646 * to the panel info. It may eventually alter EDID block as
647 * well or whatever is specific to a given model and not probed
648 * properly by the default code
650 static void radeon_fixup_panel_info(struct radeonfb_info *rinfo)
654 * LCD Flat panels should use fixed dividers, we enfore that on
655 * PPC only for now...
657 if (!rinfo->panel_info.use_bios_dividers && rinfo->mon1_type == MT_LCD
658 && rinfo->is_mobility) {
661 ppll_div_sel = INREG8(CLOCK_CNTL_INDEX + 1) & 0x3;
662 radeon_pll_errata_after_index(rinfo);
663 ppll_divn = INPLL(PPLL_DIV_0 + ppll_div_sel);
664 rinfo->panel_info.ref_divider = rinfo->pll.ref_div;
665 rinfo->panel_info.fbk_divider = ppll_divn & 0x7ff;
666 rinfo->panel_info.post_divider = (ppll_divn >> 16) & 0x7;
667 rinfo->panel_info.use_bios_dividers = 1;
669 printk(KERN_DEBUG "radeonfb: Using Firmware dividers 0x%08x "
671 rinfo->panel_info.fbk_divider |
672 (rinfo->panel_info.post_divider << 16),
675 #endif /* CONFIG_PPC_OF */
680 * Fill up panel infos from a mode definition, either returned by the EDID
681 * or from the default mode when we can't do any better
683 static void radeon_var_to_panel_info(struct radeonfb_info *rinfo, struct fb_var_screeninfo *var)
685 rinfo->panel_info.xres = var->xres;
686 rinfo->panel_info.yres = var->yres;
687 rinfo->panel_info.clock = 100000000 / var->pixclock;
688 rinfo->panel_info.hOver_plus = var->right_margin;
689 rinfo->panel_info.hSync_width = var->hsync_len;
690 rinfo->panel_info.hblank = var->left_margin +
691 (var->right_margin + var->hsync_len);
692 rinfo->panel_info.vOver_plus = var->lower_margin;
693 rinfo->panel_info.vSync_width = var->vsync_len;
694 rinfo->panel_info.vblank = var->upper_margin +
695 (var->lower_margin + var->vsync_len);
696 rinfo->panel_info.hAct_high =
697 (var->sync & FB_SYNC_HOR_HIGH_ACT) != 0;
698 rinfo->panel_info.vAct_high =
699 (var->sync & FB_SYNC_VERT_HIGH_ACT) != 0;
700 rinfo->panel_info.valid = 1;
701 /* We use a default of 200ms for the panel power delay,
702 * I need to have a real schedule() instead of mdelay's in the panel code.
703 * we might be possible to figure out a better power delay either from
704 * MacOS OF tree or from the EDID block (proprietary extensions ?)
706 rinfo->panel_info.pwr_delay = 200;
709 static void radeon_videomode_to_var(struct fb_var_screeninfo *var,
710 const struct fb_videomode *mode)
712 var->xres = mode->xres;
713 var->yres = mode->yres;
714 var->xres_virtual = mode->xres;
715 var->yres_virtual = mode->yres;
718 var->pixclock = mode->pixclock;
719 var->left_margin = mode->left_margin;
720 var->right_margin = mode->right_margin;
721 var->upper_margin = mode->upper_margin;
722 var->lower_margin = mode->lower_margin;
723 var->hsync_len = mode->hsync_len;
724 var->vsync_len = mode->vsync_len;
725 var->sync = mode->sync;
726 var->vmode = mode->vmode;
730 * Build the modedb for head 1 (head 2 will come later), check panel infos
731 * from either BIOS or EDID, and pick up the default mode
733 void __devinit radeon_check_modes(struct radeonfb_info *rinfo, const char *mode_option)
735 struct fb_info * info = rinfo->info;
736 int has_default_mode = 0;
739 * Fill default var first
741 info->var = radeonfb_default_var;
742 INIT_LIST_HEAD(&info->modelist);
745 * First check out what BIOS has to say
747 if (rinfo->mon1_type == MT_LCD)
748 radeon_get_panel_info_BIOS(rinfo);
751 * Parse EDID detailed timings and deduce panel infos if any. Right now
752 * we only deal with first entry returned by parse_EDID, we may do better
755 if (!rinfo->panel_info.use_bios_dividers && rinfo->mon1_type != MT_CRT
756 && rinfo->mon1_EDID) {
757 struct fb_var_screeninfo var;
758 RTRACE("Parsing EDID data for panel info\n");
759 if (fb_parse_edid(rinfo->mon1_EDID, &var) == 0) {
760 if (var.xres >= rinfo->panel_info.xres &&
761 var.yres >= rinfo->panel_info.yres)
762 radeon_var_to_panel_info(rinfo, &var);
767 * Do any additional platform/arch fixups to the panel infos
769 radeon_fixup_panel_info(rinfo);
772 * If we have some valid panel infos, we setup the default mode based on
775 if (rinfo->mon1_type != MT_CRT && rinfo->panel_info.valid) {
776 struct fb_var_screeninfo *var = &info->var;
778 RTRACE("Setting up default mode based on panel info\n");
779 var->xres = rinfo->panel_info.xres;
780 var->yres = rinfo->panel_info.yres;
781 var->xres_virtual = rinfo->panel_info.xres;
782 var->yres_virtual = rinfo->panel_info.yres;
783 var->xoffset = var->yoffset = 0;
784 var->bits_per_pixel = 8;
785 var->pixclock = 100000000 / rinfo->panel_info.clock;
786 var->left_margin = (rinfo->panel_info.hblank - rinfo->panel_info.hOver_plus
787 - rinfo->panel_info.hSync_width);
788 var->right_margin = rinfo->panel_info.hOver_plus;
789 var->upper_margin = (rinfo->panel_info.vblank - rinfo->panel_info.vOver_plus
790 - rinfo->panel_info.vSync_width);
791 var->lower_margin = rinfo->panel_info.vOver_plus;
792 var->hsync_len = rinfo->panel_info.hSync_width;
793 var->vsync_len = rinfo->panel_info.vSync_width;
795 if (rinfo->panel_info.hAct_high)
796 var->sync |= FB_SYNC_HOR_HIGH_ACT;
797 if (rinfo->panel_info.vAct_high)
798 var->sync |= FB_SYNC_VERT_HIGH_ACT;
800 has_default_mode = 1;
804 * Now build modedb from EDID
806 if (rinfo->mon1_EDID) {
807 fb_edid_to_monspecs(rinfo->mon1_EDID, &info->monspecs);
808 fb_videomode_to_modelist(info->monspecs.modedb,
809 info->monspecs.modedb_len,
811 rinfo->mon1_modedb = info->monspecs.modedb;
812 rinfo->mon1_dbsize = info->monspecs.modedb_len;
817 * Finally, if we don't have panel infos we need to figure some (or
818 * we try to read it from card), we try to pick a default mode
819 * and create some panel infos. Whatever...
821 if (rinfo->mon1_type != MT_CRT && !rinfo->panel_info.valid) {
822 struct fb_videomode *modedb;
826 RTRACE("Guessing panel info...\n");
827 if (rinfo->panel_info.xres == 0 || rinfo->panel_info.yres == 0) {
828 u32 tmp = INREG(FP_HORZ_STRETCH) & HORZ_PANEL_SIZE;
829 rinfo->panel_info.xres = ((tmp >> HORZ_PANEL_SHIFT) + 1) * 8;
830 tmp = INREG(FP_VERT_STRETCH) & VERT_PANEL_SIZE;
831 rinfo->panel_info.yres = (tmp >> VERT_PANEL_SHIFT) + 1;
833 if (rinfo->panel_info.xres == 0 || rinfo->panel_info.yres == 0) {
834 printk(KERN_WARNING "radeonfb: Can't find panel size, going back to CRT\n");
835 rinfo->mon1_type = MT_CRT;
838 printk(KERN_WARNING "radeonfb: Assuming panel size %dx%d\n",
839 rinfo->panel_info.xres, rinfo->panel_info.yres);
840 modedb = rinfo->mon1_modedb;
841 dbsize = rinfo->mon1_dbsize;
842 snprintf(modename, 31, "%dx%d", rinfo->panel_info.xres, rinfo->panel_info.yres);
843 if (fb_find_mode(&info->var, info, modename,
844 modedb, dbsize, NULL, 8) == 0) {
845 printk(KERN_WARNING "radeonfb: Can't find mode for panel size, going back to CRT\n");
846 rinfo->mon1_type = MT_CRT;
849 has_default_mode = 1;
850 radeon_var_to_panel_info(rinfo, &info->var);
855 * Apply passed-in mode option if any
858 if (fb_find_mode(&info->var, info, mode_option,
859 info->monspecs.modedb,
860 info->monspecs.modedb_len, NULL, 8) != 0)
861 has_default_mode = 1;
865 * Still no mode, let's pick up a default from the db
867 if (!has_default_mode && info->monspecs.modedb != NULL) {
868 struct fb_monspecs *specs = &info->monspecs;
869 struct fb_videomode *modedb = NULL;
871 /* get preferred timing */
872 if (specs->misc & FB_MISC_1ST_DETAIL) {
875 for (i = 0; i < specs->modedb_len; i++) {
876 if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
877 modedb = &specs->modedb[i];
882 /* otherwise, get first mode in database */
883 modedb = &specs->modedb[0];
885 if (modedb != NULL) {
886 info->var.bits_per_pixel = 8;
887 radeon_videomode_to_var(&info->var, modedb);
888 has_default_mode = 1;
892 struct fb_videomode mode;
893 /* Make sure that whatever mode got selected is actually in the
894 * modelist or the kernel may die
896 fb_var_to_videomode(&mode, &info->var);
897 fb_add_videomode(&mode, &info->modelist);
902 * The code below is used to pick up a mode in check_var and
903 * set_var. It should be made generic
907 * This is used when looking for modes. We assign a "distance" value
908 * to a mode in the modedb depending how "close" it is from what we
910 * Currently, we don't compare that much, we could do better but
911 * the current fbcon doesn't quite mind ;)
913 static int radeon_compare_modes(const struct fb_var_screeninfo *var,
914 const struct fb_videomode *mode)
918 distance = mode->yres - var->yres;
919 distance += (mode->xres - var->xres)/2;
924 * This function is called by check_var, it gets the passed in mode parameter, and
925 * outputs a valid mode matching the passed-in one as closely as possible.
926 * We need something better ultimately. Things like fbcon basically pass us out
927 * current mode with xres/yres hacked, while things like XFree will actually
928 * produce a full timing that we should respect as much as possible.
930 * This is why I added the FB_ACTIVATE_FIND that is used by fbcon. Without this,
931 * we do a simple spec match, that's all. With it, we actually look for a mode in
932 * either our monitor modedb or the vesa one if none
935 int radeon_match_mode(struct radeonfb_info *rinfo,
936 struct fb_var_screeninfo *dest,
937 const struct fb_var_screeninfo *src)
939 const struct fb_videomode *db = vesa_modes;
941 int has_rmx, native_db = 0;
942 int distance = INT_MAX;
943 const struct fb_videomode *candidate = NULL;
945 /* Start with a copy of the requested mode */
946 memcpy(dest, src, sizeof(struct fb_var_screeninfo));
948 /* Check if we have a modedb built from EDID */
949 if (rinfo->mon1_modedb) {
950 db = rinfo->mon1_modedb;
951 dbsize = rinfo->mon1_dbsize;
955 /* Check if we have a scaler allowing any fancy mode */
956 has_rmx = rinfo->mon1_type == MT_LCD || rinfo->mon1_type == MT_DFP;
958 /* If we have a scaler and are passed FB_ACTIVATE_TEST or
959 * FB_ACTIVATE_NOW, just do basic checking and return if the
962 if ((src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_TEST ||
963 (src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
964 /* We don't have an RMX, validate timings. If we don't have
965 * monspecs, we should be paranoid and not let use go above
966 * 640x480-60, but I assume userland knows what it's doing here
967 * (though I may be proven wrong...)
969 if (has_rmx == 0 && rinfo->mon1_modedb)
970 if (fb_validate_mode((struct fb_var_screeninfo *)src, rinfo->info))
975 /* Now look for a mode in the database */
977 for (i = 0; i < dbsize; i++) {
980 if (db[i].yres < src->yres)
982 if (db[i].xres < src->xres)
984 d = radeon_compare_modes(src, &db[i]);
985 /* If the new mode is at least as good as the previous one,
986 * then it's our new candidate
994 /* If we have a scaler, we allow any mode from the database */
995 if (native_db && has_rmx) {
1002 /* If we have found a match, return it */
1003 if (candidate != NULL) {
1004 radeon_videomode_to_var(dest, candidate);
1008 /* If we haven't and don't have a scaler, fail */