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
};
72 RTRACE("analyzing OF properties...\n");
73 pmt
= (u8
*)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
= (u8
*)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
= (u8
*)kmalloc(EDID_LENGTH
, GFP_KERNEL
);
110 memcpy(tmp
, pedid
, EDID_LENGTH
);
115 static int __devinit
radeon_probe_OF_head(struct radeonfb_info
*rinfo
, int head_no
,
118 struct device_node
*dp
;
120 RTRACE("radeon_probe_OF_head\n");
126 if (rinfo
->has_CRTC2
) {
134 pname
= (char *)get_property(dp
, "name", NULL
);
138 RTRACE("head: %s (letter: %c, head_no: %d)\n",
139 pname
, pname
[len
-1], head_no
);
140 if (pname
[len
-1] == 'A' && head_no
== 0) {
141 int mt
= radeon_parse_montype_prop(dp
, out_EDID
, 0);
142 /* Maybe check for LVDS_GEN_CNTL here ? I need to check out
143 * what OF does when booting with lid closed
145 if (mt
== MT_DFP
&& rinfo
->is_mobility
)
148 } else if (pname
[len
-1] == 'B' && head_no
== 1)
149 return radeon_parse_montype_prop(dp
, out_EDID
, 1);
156 return radeon_parse_montype_prop(dp
, out_EDID
, -1);
160 #endif /* CONFIG_PPC_OF */
163 static int __devinit
radeon_get_panel_info_BIOS(struct radeonfb_info
*rinfo
)
165 unsigned long tmp
, tmp0
;
169 if (!rinfo
->bios_seg
)
172 if (!(tmp
= BIOS_IN16(rinfo
->fp_bios_start
+ 0x40))) {
173 printk(KERN_ERR
"radeonfb: Failed to detect DFP panel info using BIOS\n");
174 rinfo
->panel_info
.pwr_delay
= 200;
179 stmp
[i
] = BIOS_IN8(tmp
+i
+1);
181 printk("radeonfb: panel ID string: %s\n", stmp
);
182 rinfo
->panel_info
.xres
= BIOS_IN16(tmp
+ 25);
183 rinfo
->panel_info
.yres
= BIOS_IN16(tmp
+ 27);
184 printk("radeonfb: detected LVDS panel size from BIOS: %dx%d\n",
185 rinfo
->panel_info
.xres
, rinfo
->panel_info
.yres
);
187 rinfo
->panel_info
.pwr_delay
= BIOS_IN16(tmp
+ 44);
188 RTRACE("BIOS provided panel power delay: %d\n", rinfo
->panel_info
.pwr_delay
);
189 if (rinfo
->panel_info
.pwr_delay
> 2000 || rinfo
->panel_info
.pwr_delay
<= 0)
190 rinfo
->panel_info
.pwr_delay
= 2000;
193 * Some panels only work properly with some divider combinations
195 rinfo
->panel_info
.ref_divider
= BIOS_IN16(tmp
+ 46);
196 rinfo
->panel_info
.post_divider
= BIOS_IN8(tmp
+ 48);
197 rinfo
->panel_info
.fbk_divider
= BIOS_IN16(tmp
+ 49);
198 if (rinfo
->panel_info
.ref_divider
!= 0 &&
199 rinfo
->panel_info
.fbk_divider
> 3) {
200 rinfo
->panel_info
.use_bios_dividers
= 1;
201 printk(KERN_INFO
"radeondb: BIOS provided dividers will be used\n");
202 RTRACE("ref_divider = %x\n", rinfo
->panel_info
.ref_divider
);
203 RTRACE("post_divider = %x\n", rinfo
->panel_info
.post_divider
);
204 RTRACE("fbk_divider = %x\n", rinfo
->panel_info
.fbk_divider
);
206 RTRACE("Scanning BIOS table ...\n");
207 for(i
=0; i
<32; i
++) {
208 tmp0
= BIOS_IN16(tmp
+64+i
*2);
211 RTRACE(" %d x %d\n", BIOS_IN16(tmp0
), BIOS_IN16(tmp0
+2));
212 if ((BIOS_IN16(tmp0
) == rinfo
->panel_info
.xres
) &&
213 (BIOS_IN16(tmp0
+2) == rinfo
->panel_info
.yres
)) {
214 rinfo
->panel_info
.hblank
= (BIOS_IN16(tmp0
+17) - BIOS_IN16(tmp0
+19)) * 8;
215 rinfo
->panel_info
.hOver_plus
= ((BIOS_IN16(tmp0
+21) -
216 BIOS_IN16(tmp0
+19) -1) * 8) & 0x7fff;
217 rinfo
->panel_info
.hSync_width
= BIOS_IN8(tmp0
+23) * 8;
218 rinfo
->panel_info
.vblank
= BIOS_IN16(tmp0
+24) - BIOS_IN16(tmp0
+26);
219 rinfo
->panel_info
.vOver_plus
= (BIOS_IN16(tmp0
+28) & 0x7ff) - BIOS_IN16(tmp0
+26);
220 rinfo
->panel_info
.vSync_width
= (BIOS_IN16(tmp0
+28) & 0xf800) >> 11;
221 rinfo
->panel_info
.clock
= BIOS_IN16(tmp0
+9);
222 /* Assume high active syncs for now until ATI tells me more... maybe we
223 * can probe register values here ?
225 rinfo
->panel_info
.hAct_high
= 1;
226 rinfo
->panel_info
.vAct_high
= 1;
227 /* Mark panel infos valid */
228 rinfo
->panel_info
.valid
= 1;
230 RTRACE("Found panel in BIOS table:\n");
231 RTRACE(" hblank: %d\n", rinfo
->panel_info
.hblank
);
232 RTRACE(" hOver_plus: %d\n", rinfo
->panel_info
.hOver_plus
);
233 RTRACE(" hSync_width: %d\n", rinfo
->panel_info
.hSync_width
);
234 RTRACE(" vblank: %d\n", rinfo
->panel_info
.vblank
);
235 RTRACE(" vOver_plus: %d\n", rinfo
->panel_info
.vOver_plus
);
236 RTRACE(" vSync_width: %d\n", rinfo
->panel_info
.vSync_width
);
237 RTRACE(" clock: %d\n", rinfo
->panel_info
.clock
);
242 RTRACE("Didn't find panel in BIOS table !\n");
247 /* Try to extract the connector informations from the BIOS. This
248 * doesn't quite work yet, but it's output is still useful for
251 static void __devinit
radeon_parse_connector_info(struct radeonfb_info
*rinfo
)
253 int offset
, chips
, connectors
, tmp
, i
, conn
, type
;
255 static char* __conn_type_table
[16] = {
256 "NONE", "Proprietary", "CRT", "DVI-I", "DVI-D", "Unknown", "Unknown",
257 "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown",
258 "Unknown", "Unknown", "Unknown"
261 if (!rinfo
->bios_seg
)
264 offset
= BIOS_IN16(rinfo
->fp_bios_start
+ 0x50);
266 printk(KERN_WARNING
"radeonfb: No connector info table detected\n");
270 /* Don't do much more at this point but displaying the data if
273 chips
= BIOS_IN8(offset
++) >> 4;
274 RTRACE("%d chips in connector info\n", chips
);
275 for (i
= 0; i
< chips
; i
++) {
276 tmp
= BIOS_IN8(offset
++);
277 connectors
= tmp
& 0x0f;
278 RTRACE(" - chip %d has %d connectors\n", tmp
>> 4, connectors
);
279 for (conn
= 0; ; conn
++) {
280 tmp
= BIOS_IN16(offset
);
284 type
= (tmp
>> 12) & 0x0f;
285 RTRACE(" * connector %d of type %d (%s) : %04x\n",
286 conn
, type
, __conn_type_table
[type
], tmp
);
293 * Probe physical connection of a CRT. This code comes from XFree
294 * as well and currently is only implemented for the CRT DAC, the
295 * code for the TVDAC is commented out in XFree as "non working"
297 static int __devinit
radeon_crt_is_connected(struct radeonfb_info
*rinfo
, int is_crt_dac
)
301 /* the monitor either wasn't connected or it is a non-DDC CRT.
305 unsigned long ulOrigVCLK_ECP_CNTL
;
306 unsigned long ulOrigDAC_CNTL
;
307 unsigned long ulOrigDAC_EXT_CNTL
;
308 unsigned long ulOrigCRTC_EXT_CNTL
;
309 unsigned long ulData
;
310 unsigned long ulMask
;
312 ulOrigVCLK_ECP_CNTL
= INPLL(VCLK_ECP_CNTL
);
314 ulData
= ulOrigVCLK_ECP_CNTL
;
315 ulData
&= ~(PIXCLK_ALWAYS_ONb
316 | PIXCLK_DAC_ALWAYS_ONb
);
317 ulMask
= ~(PIXCLK_ALWAYS_ONb
318 | PIXCLK_DAC_ALWAYS_ONb
);
319 OUTPLLP(VCLK_ECP_CNTL
, ulData
, ulMask
);
321 ulOrigCRTC_EXT_CNTL
= INREG(CRTC_EXT_CNTL
);
322 ulData
= ulOrigCRTC_EXT_CNTL
;
323 ulData
|= CRTC_CRT_ON
;
324 OUTREG(CRTC_EXT_CNTL
, ulData
);
326 ulOrigDAC_EXT_CNTL
= INREG(DAC_EXT_CNTL
);
327 ulData
= ulOrigDAC_EXT_CNTL
;
328 ulData
&= ~DAC_FORCE_DATA_MASK
;
329 ulData
|= (DAC_FORCE_BLANK_OFF_EN
331 |DAC_FORCE_DATA_SEL_MASK
);
332 if ((rinfo
->family
== CHIP_FAMILY_RV250
) ||
333 (rinfo
->family
== CHIP_FAMILY_RV280
))
334 ulData
|= (0x01b6 << DAC_FORCE_DATA_SHIFT
);
336 ulData
|= (0x01ac << DAC_FORCE_DATA_SHIFT
);
338 OUTREG(DAC_EXT_CNTL
, ulData
);
340 ulOrigDAC_CNTL
= INREG(DAC_CNTL
);
341 ulData
= ulOrigDAC_CNTL
;
342 ulData
|= DAC_CMP_EN
;
343 ulData
&= ~(DAC_RANGE_CNTL_MASK
346 OUTREG(DAC_CNTL
, ulData
);
350 ulData
= INREG(DAC_CNTL
);
351 connected
= (DAC_CMP_OUTPUT
& ulData
) ? 1 : 0;
353 ulData
= ulOrigVCLK_ECP_CNTL
;
354 ulMask
= 0xFFFFFFFFL
;
355 OUTPLLP(VCLK_ECP_CNTL
, ulData
, ulMask
);
357 OUTREG(DAC_CNTL
, ulOrigDAC_CNTL
);
358 OUTREG(DAC_EXT_CNTL
, ulOrigDAC_EXT_CNTL
);
359 OUTREG(CRTC_EXT_CNTL
, ulOrigCRTC_EXT_CNTL
);
362 return connected
? MT_CRT
: MT_NONE
;
366 * Parse the "monitor_layout" string if any. This code is mostly
367 * copied from XFree's radeon driver
369 static int __devinit
radeon_parse_monitor_layout(struct radeonfb_info
*rinfo
,
370 const char *monitor_layout
)
373 int i
= 0, second
= 0;
406 if (strcmp(s1
, "CRT") == 0)
407 rinfo
->mon1_type
= MT_CRT
;
408 else if (strcmp(s1
, "TMDS") == 0)
409 rinfo
->mon1_type
= MT_DFP
;
410 else if (strcmp(s1
, "LVDS") == 0)
411 rinfo
->mon1_type
= MT_LCD
;
413 if (strcmp(s2
, "CRT") == 0)
414 rinfo
->mon2_type
= MT_CRT
;
415 else if (strcmp(s2
, "TMDS") == 0)
416 rinfo
->mon2_type
= MT_DFP
;
417 else if (strcmp(s2
, "LVDS") == 0)
418 rinfo
->mon2_type
= MT_LCD
;
424 * Probe display on both primary and secondary card's connector (if any)
425 * by various available techniques (i2c, OF device tree, BIOS, ...) and
426 * try to retreive EDID. The algorithm here comes from XFree's radeon
429 void __devinit
radeon_probe_screens(struct radeonfb_info
*rinfo
,
430 const char *monitor_layout
, int ignore_edid
)
432 #ifdef CONFIG_FB_RADEON_I2C
433 int ddc_crt2_used
= 0;
437 radeon_parse_connector_info(rinfo
);
439 if (radeon_parse_monitor_layout(rinfo
, monitor_layout
)) {
442 * If user specified a monitor_layout option, use it instead
443 * of auto-detecting. Maybe we should only use this argument
444 * on the first radeon card probed or provide a way to specify
445 * a layout for each card ?
448 RTRACE("Using specified monitor layout: %s", monitor_layout
);
449 #ifdef CONFIG_FB_RADEON_I2C
451 if (rinfo
->mon1_type
!= MT_NONE
)
452 if (!radeon_probe_i2c_connector(rinfo
, ddc_dvi
, &rinfo
->mon1_EDID
)) {
453 radeon_probe_i2c_connector(rinfo
, ddc_crt2
, &rinfo
->mon1_EDID
);
456 if (rinfo
->mon2_type
!= MT_NONE
)
457 if (!radeon_probe_i2c_connector(rinfo
, ddc_vga
, &rinfo
->mon2_EDID
) &&
459 radeon_probe_i2c_connector(rinfo
, ddc_crt2
, &rinfo
->mon2_EDID
);
461 #endif /* CONFIG_FB_RADEON_I2C */
462 if (rinfo
->mon1_type
== MT_NONE
) {
463 if (rinfo
->mon2_type
!= MT_NONE
) {
464 rinfo
->mon1_type
= rinfo
->mon2_type
;
465 rinfo
->mon1_EDID
= rinfo
->mon2_EDID
;
467 rinfo
->mon1_type
= MT_CRT
;
468 printk(KERN_INFO
"radeonfb: No valid monitor, assuming CRT on first port\n");
470 rinfo
->mon2_type
= MT_NONE
;
471 rinfo
->mon2_EDID
= NULL
;
475 * Auto-detecting display type (well... trying to ...)
478 RTRACE("Starting monitor auto detection...\n");
480 #if DEBUG && defined(CONFIG_FB_RADEON_I2C)
482 u8
*EDIDs
[4] = { NULL
, NULL
, NULL
, NULL
};
483 int mon_types
[4] = {MT_NONE
, MT_NONE
, MT_NONE
, MT_NONE
};
486 for (i
= 0; i
< 4; i
++)
487 mon_types
[i
] = radeon_probe_i2c_connector(rinfo
,
492 * Old single head cards
494 if (!rinfo
->has_CRTC2
) {
496 if (rinfo
->mon1_type
== MT_NONE
)
497 rinfo
->mon1_type
= radeon_probe_OF_head(rinfo
, 0,
499 #endif /* CONFIG_PPC_OF */
500 #ifdef CONFIG_FB_RADEON_I2C
501 if (rinfo
->mon1_type
== MT_NONE
)
503 radeon_probe_i2c_connector(rinfo
, ddc_dvi
,
505 if (rinfo
->mon1_type
== MT_NONE
)
507 radeon_probe_i2c_connector(rinfo
, ddc_vga
,
509 if (rinfo
->mon1_type
== MT_NONE
)
511 radeon_probe_i2c_connector(rinfo
, ddc_crt2
,
513 #endif /* CONFIG_FB_RADEON_I2C */
514 if (rinfo
->mon1_type
== MT_NONE
)
515 rinfo
->mon1_type
= MT_CRT
;
520 * Check for cards with reversed DACs or TMDS controllers using BIOS
522 if (rinfo
->bios_seg
&&
523 (tmp
= BIOS_IN16(rinfo
->fp_bios_start
+ 0x50))) {
524 for (i
= 1; i
< 4; i
++) {
527 if (!BIOS_IN8(tmp
+ i
*2) && i
> 1)
529 tmp0
= BIOS_IN16(tmp
+ i
*2);
530 if ((!(tmp0
& 0x01)) && (((tmp0
>> 8) & 0x0f) == ddc_dvi
)) {
531 rinfo
->reversed_DAC
= 1;
532 printk(KERN_INFO
"radeonfb: Reversed DACs detected\n");
534 if ((((tmp0
>> 8) & 0x0f) == ddc_dvi
) && ((tmp0
>> 4) & 0x01)) {
535 rinfo
->reversed_TMDS
= 1;
536 printk(KERN_INFO
"radeonfb: Reversed TMDS detected\n");
542 * Probe primary head (DVI or laptop internal panel)
545 if (rinfo
->mon1_type
== MT_NONE
)
546 rinfo
->mon1_type
= radeon_probe_OF_head(rinfo
, 0,
548 #endif /* CONFIG_PPC_OF */
549 #ifdef CONFIG_FB_RADEON_I2C
550 if (rinfo
->mon1_type
== MT_NONE
)
551 rinfo
->mon1_type
= radeon_probe_i2c_connector(rinfo
, ddc_dvi
,
553 if (rinfo
->mon1_type
== MT_NONE
) {
554 rinfo
->mon1_type
= radeon_probe_i2c_connector(rinfo
, ddc_crt2
,
556 if (rinfo
->mon1_type
!= MT_NONE
)
559 #endif /* CONFIG_FB_RADEON_I2C */
560 if (rinfo
->mon1_type
== MT_NONE
&& rinfo
->is_mobility
&&
561 ((rinfo
->bios_seg
&& (INREG(BIOS_4_SCRATCH
) & 4))
562 || (INREG(LVDS_GEN_CNTL
) & LVDS_ON
))) {
563 rinfo
->mon1_type
= MT_LCD
;
564 printk("Non-DDC laptop panel detected\n");
566 if (rinfo
->mon1_type
== MT_NONE
)
567 rinfo
->mon1_type
= radeon_crt_is_connected(rinfo
, rinfo
->reversed_DAC
);
570 * Probe secondary head (mostly VGA, can be DVI)
573 if (rinfo
->mon2_type
== MT_NONE
)
574 rinfo
->mon2_type
= radeon_probe_OF_head(rinfo
, 1,
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 kfree(rinfo
->mon1_EDID
);
622 rinfo
->mon1_EDID
= NULL
;
623 kfree(rinfo
->mon2_EDID
);
624 rinfo
->mon2_EDID
= NULL
;
628 printk(KERN_INFO
"radeonfb: Monitor 1 type %s found\n",
629 radeon_get_mon_name(rinfo
->mon1_type
));
630 if (rinfo
->mon1_EDID
)
631 printk(KERN_INFO
"radeonfb: EDID probed\n");
632 if (!rinfo
->has_CRTC2
)
634 printk(KERN_INFO
"radeonfb: Monitor 2 type %s found\n",
635 radeon_get_mon_name(rinfo
->mon2_type
));
636 if (rinfo
->mon2_EDID
)
637 printk(KERN_INFO
"radeonfb: EDID probed\n");
642 * This functions applyes any arch/model/machine specific fixups
643 * to the panel info. It may eventually alter EDID block as
644 * well or whatever is specific to a given model and not probed
645 * properly by the default code
647 static void radeon_fixup_panel_info(struct radeonfb_info
*rinfo
)
651 * LCD Flat panels should use fixed dividers, we enfore that on
652 * PPC only for now...
654 if (!rinfo
->panel_info
.use_bios_dividers
&& rinfo
->mon1_type
== MT_LCD
655 && rinfo
->is_mobility
) {
658 ppll_div_sel
= INREG8(CLOCK_CNTL_INDEX
+ 1) & 0x3;
659 radeon_pll_errata_after_index(rinfo
);
660 ppll_divn
= INPLL(PPLL_DIV_0
+ ppll_div_sel
);
661 rinfo
->panel_info
.ref_divider
= rinfo
->pll
.ref_div
;
662 rinfo
->panel_info
.fbk_divider
= ppll_divn
& 0x7ff;
663 rinfo
->panel_info
.post_divider
= (ppll_divn
>> 16) & 0x7;
664 rinfo
->panel_info
.use_bios_dividers
= 1;
666 printk(KERN_DEBUG
"radeonfb: Using Firmware dividers 0x%08x "
668 rinfo
->panel_info
.fbk_divider
|
669 (rinfo
->panel_info
.post_divider
<< 16),
672 #endif /* CONFIG_PPC_OF */
677 * Fill up panel infos from a mode definition, either returned by the EDID
678 * or from the default mode when we can't do any better
680 static void radeon_var_to_panel_info(struct radeonfb_info
*rinfo
, struct fb_var_screeninfo
*var
)
682 rinfo
->panel_info
.xres
= var
->xres
;
683 rinfo
->panel_info
.yres
= var
->yres
;
684 rinfo
->panel_info
.clock
= 100000000 / var
->pixclock
;
685 rinfo
->panel_info
.hOver_plus
= var
->right_margin
;
686 rinfo
->panel_info
.hSync_width
= var
->hsync_len
;
687 rinfo
->panel_info
.hblank
= var
->left_margin
+
688 (var
->right_margin
+ var
->hsync_len
);
689 rinfo
->panel_info
.vOver_plus
= var
->lower_margin
;
690 rinfo
->panel_info
.vSync_width
= var
->vsync_len
;
691 rinfo
->panel_info
.vblank
= var
->upper_margin
+
692 (var
->lower_margin
+ var
->vsync_len
);
693 rinfo
->panel_info
.hAct_high
=
694 (var
->sync
& FB_SYNC_HOR_HIGH_ACT
) != 0;
695 rinfo
->panel_info
.vAct_high
=
696 (var
->sync
& FB_SYNC_VERT_HIGH_ACT
) != 0;
697 rinfo
->panel_info
.valid
= 1;
698 /* We use a default of 200ms for the panel power delay,
699 * I need to have a real schedule() instead of mdelay's in the panel code.
700 * we might be possible to figure out a better power delay either from
701 * MacOS OF tree or from the EDID block (proprietary extensions ?)
703 rinfo
->panel_info
.pwr_delay
= 200;
706 static void radeon_videomode_to_var(struct fb_var_screeninfo
*var
,
707 const struct fb_videomode
*mode
)
709 var
->xres
= mode
->xres
;
710 var
->yres
= mode
->yres
;
711 var
->xres_virtual
= mode
->xres
;
712 var
->yres_virtual
= mode
->yres
;
715 var
->pixclock
= mode
->pixclock
;
716 var
->left_margin
= mode
->left_margin
;
717 var
->right_margin
= mode
->right_margin
;
718 var
->upper_margin
= mode
->upper_margin
;
719 var
->lower_margin
= mode
->lower_margin
;
720 var
->hsync_len
= mode
->hsync_len
;
721 var
->vsync_len
= mode
->vsync_len
;
722 var
->sync
= mode
->sync
;
723 var
->vmode
= mode
->vmode
;
727 * Build the modedb for head 1 (head 2 will come later), check panel infos
728 * from either BIOS or EDID, and pick up the default mode
730 void __devinit
radeon_check_modes(struct radeonfb_info
*rinfo
, const char *mode_option
)
732 struct fb_info
* info
= rinfo
->info
;
733 int has_default_mode
= 0;
736 * Fill default var first
738 info
->var
= radeonfb_default_var
;
739 INIT_LIST_HEAD(&info
->modelist
);
742 * First check out what BIOS has to say
744 if (rinfo
->mon1_type
== MT_LCD
)
745 radeon_get_panel_info_BIOS(rinfo
);
748 * Parse EDID detailed timings and deduce panel infos if any. Right now
749 * we only deal with first entry returned by parse_EDID, we may do better
752 if (!rinfo
->panel_info
.use_bios_dividers
&& rinfo
->mon1_type
!= MT_CRT
753 && rinfo
->mon1_EDID
) {
754 struct fb_var_screeninfo var
;
755 RTRACE("Parsing EDID data for panel info\n");
756 if (fb_parse_edid(rinfo
->mon1_EDID
, &var
) == 0) {
757 if (var
.xres
>= rinfo
->panel_info
.xres
&&
758 var
.yres
>= rinfo
->panel_info
.yres
)
759 radeon_var_to_panel_info(rinfo
, &var
);
764 * Do any additional platform/arch fixups to the panel infos
766 radeon_fixup_panel_info(rinfo
);
769 * If we have some valid panel infos, we setup the default mode based on
772 if (rinfo
->mon1_type
!= MT_CRT
&& rinfo
->panel_info
.valid
) {
773 struct fb_var_screeninfo
*var
= &info
->var
;
775 RTRACE("Setting up default mode based on panel info\n");
776 var
->xres
= rinfo
->panel_info
.xres
;
777 var
->yres
= rinfo
->panel_info
.yres
;
778 var
->xres_virtual
= rinfo
->panel_info
.xres
;
779 var
->yres_virtual
= rinfo
->panel_info
.yres
;
780 var
->xoffset
= var
->yoffset
= 0;
781 var
->bits_per_pixel
= 8;
782 var
->pixclock
= 100000000 / rinfo
->panel_info
.clock
;
783 var
->left_margin
= (rinfo
->panel_info
.hblank
- rinfo
->panel_info
.hOver_plus
784 - rinfo
->panel_info
.hSync_width
);
785 var
->right_margin
= rinfo
->panel_info
.hOver_plus
;
786 var
->upper_margin
= (rinfo
->panel_info
.vblank
- rinfo
->panel_info
.vOver_plus
787 - rinfo
->panel_info
.vSync_width
);
788 var
->lower_margin
= rinfo
->panel_info
.vOver_plus
;
789 var
->hsync_len
= rinfo
->panel_info
.hSync_width
;
790 var
->vsync_len
= rinfo
->panel_info
.vSync_width
;
792 if (rinfo
->panel_info
.hAct_high
)
793 var
->sync
|= FB_SYNC_HOR_HIGH_ACT
;
794 if (rinfo
->panel_info
.vAct_high
)
795 var
->sync
|= FB_SYNC_VERT_HIGH_ACT
;
797 has_default_mode
= 1;
801 * Now build modedb from EDID
803 if (rinfo
->mon1_EDID
) {
804 fb_edid_to_monspecs(rinfo
->mon1_EDID
, &info
->monspecs
);
805 fb_videomode_to_modelist(info
->monspecs
.modedb
,
806 info
->monspecs
.modedb_len
,
808 rinfo
->mon1_modedb
= info
->monspecs
.modedb
;
809 rinfo
->mon1_dbsize
= info
->monspecs
.modedb_len
;
814 * Finally, if we don't have panel infos we need to figure some (or
815 * we try to read it from card), we try to pick a default mode
816 * and create some panel infos. Whatever...
818 if (rinfo
->mon1_type
!= MT_CRT
&& !rinfo
->panel_info
.valid
) {
819 struct fb_videomode
*modedb
;
823 RTRACE("Guessing panel info...\n");
824 if (rinfo
->panel_info
.xres
== 0 || rinfo
->panel_info
.yres
== 0) {
825 u32 tmp
= INREG(FP_HORZ_STRETCH
) & HORZ_PANEL_SIZE
;
826 rinfo
->panel_info
.xres
= ((tmp
>> HORZ_PANEL_SHIFT
) + 1) * 8;
827 tmp
= INREG(FP_VERT_STRETCH
) & VERT_PANEL_SIZE
;
828 rinfo
->panel_info
.yres
= (tmp
>> VERT_PANEL_SHIFT
) + 1;
830 if (rinfo
->panel_info
.xres
== 0 || rinfo
->panel_info
.yres
== 0) {
831 printk(KERN_WARNING
"radeonfb: Can't find panel size, going back to CRT\n");
832 rinfo
->mon1_type
= MT_CRT
;
835 printk(KERN_WARNING
"radeonfb: Assuming panel size %dx%d\n",
836 rinfo
->panel_info
.xres
, rinfo
->panel_info
.yres
);
837 modedb
= rinfo
->mon1_modedb
;
838 dbsize
= rinfo
->mon1_dbsize
;
839 snprintf(modename
, 31, "%dx%d", rinfo
->panel_info
.xres
, rinfo
->panel_info
.yres
);
840 if (fb_find_mode(&info
->var
, info
, modename
,
841 modedb
, dbsize
, NULL
, 8) == 0) {
842 printk(KERN_WARNING
"radeonfb: Can't find mode for panel size, going back to CRT\n");
843 rinfo
->mon1_type
= MT_CRT
;
846 has_default_mode
= 1;
847 radeon_var_to_panel_info(rinfo
, &info
->var
);
852 * Apply passed-in mode option if any
855 if (fb_find_mode(&info
->var
, info
, mode_option
,
856 info
->monspecs
.modedb
,
857 info
->monspecs
.modedb_len
, NULL
, 8) != 0)
858 has_default_mode
= 1;
862 * Still no mode, let's pick up a default from the db
864 if (!has_default_mode
&& info
->monspecs
.modedb
!= NULL
) {
865 struct fb_monspecs
*specs
= &info
->monspecs
;
866 struct fb_videomode
*modedb
= NULL
;
868 /* get preferred timing */
869 if (specs
->misc
& FB_MISC_1ST_DETAIL
) {
872 for (i
= 0; i
< specs
->modedb_len
; i
++) {
873 if (specs
->modedb
[i
].flag
& FB_MODE_IS_FIRST
) {
874 modedb
= &specs
->modedb
[i
];
879 /* otherwise, get first mode in database */
880 modedb
= &specs
->modedb
[0];
882 if (modedb
!= NULL
) {
883 info
->var
.bits_per_pixel
= 8;
884 radeon_videomode_to_var(&info
->var
, modedb
);
885 has_default_mode
= 1;
889 struct fb_videomode mode
;
890 /* Make sure that whatever mode got selected is actually in the
891 * modelist or the kernel may die
893 fb_var_to_videomode(&mode
, &info
->var
);
894 fb_add_videomode(&mode
, &info
->modelist
);
899 * The code below is used to pick up a mode in check_var and
900 * set_var. It should be made generic
904 * This is used when looking for modes. We assign a "distance" value
905 * to a mode in the modedb depending how "close" it is from what we
907 * Currently, we don't compare that much, we could do better but
908 * the current fbcon doesn't quite mind ;)
910 static int radeon_compare_modes(const struct fb_var_screeninfo
*var
,
911 const struct fb_videomode
*mode
)
915 distance
= mode
->yres
- var
->yres
;
916 distance
+= (mode
->xres
- var
->xres
)/2;
921 * This function is called by check_var, it gets the passed in mode parameter, and
922 * outputs a valid mode matching the passed-in one as closely as possible.
923 * We need something better ultimately. Things like fbcon basically pass us out
924 * current mode with xres/yres hacked, while things like XFree will actually
925 * produce a full timing that we should respect as much as possible.
927 * This is why I added the FB_ACTIVATE_FIND that is used by fbcon. Without this,
928 * we do a simple spec match, that's all. With it, we actually look for a mode in
929 * either our monitor modedb or the vesa one if none
932 int radeon_match_mode(struct radeonfb_info
*rinfo
,
933 struct fb_var_screeninfo
*dest
,
934 const struct fb_var_screeninfo
*src
)
936 const struct fb_videomode
*db
= vesa_modes
;
938 int has_rmx
, native_db
= 0;
939 int distance
= INT_MAX
;
940 const struct fb_videomode
*candidate
= NULL
;
942 /* Start with a copy of the requested mode */
943 memcpy(dest
, src
, sizeof(struct fb_var_screeninfo
));
945 /* Check if we have a modedb built from EDID */
946 if (rinfo
->mon1_modedb
) {
947 db
= rinfo
->mon1_modedb
;
948 dbsize
= rinfo
->mon1_dbsize
;
952 /* Check if we have a scaler allowing any fancy mode */
953 has_rmx
= rinfo
->mon1_type
== MT_LCD
|| rinfo
->mon1_type
== MT_DFP
;
955 /* If we have a scaler and are passed FB_ACTIVATE_TEST or
956 * FB_ACTIVATE_NOW, just do basic checking and return if the
959 if ((src
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_TEST
||
960 (src
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_NOW
) {
961 /* We don't have an RMX, validate timings. If we don't have
962 * monspecs, we should be paranoid and not let use go above
963 * 640x480-60, but I assume userland knows what it's doing here
964 * (though I may be proven wrong...)
966 if (has_rmx
== 0 && rinfo
->mon1_modedb
)
967 if (fb_validate_mode((struct fb_var_screeninfo
*)src
, rinfo
->info
))
972 /* Now look for a mode in the database */
974 for (i
= 0; i
< dbsize
; i
++) {
977 if (db
[i
].yres
< src
->yres
)
979 if (db
[i
].xres
< src
->xres
)
981 d
= radeon_compare_modes(src
, &db
[i
]);
982 /* If the new mode is at least as good as the previous one,
983 * then it's our new candidate
991 /* If we have a scaler, we allow any mode from the database */
992 if (native_db
&& has_rmx
) {
999 /* If we have found a match, return it */
1000 if (candidate
!= NULL
) {
1001 radeon_videomode_to_var(dest
, candidate
);
1005 /* If we haven't and don't have a scaler, fail */