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
)
55 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
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
= of_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
= of_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
= of_get_property(dp
->parent
,
102 (hdno
== 0) ? "EDID1" : "EDID2", NULL
);
103 if (pedid
== NULL
&& dp
->parent
&& (hdno
== 0))
104 pedid
= of_get_property(dp
->parent
, "EDID", NULL
);
108 tmp
= kmemdup(pedid
, EDID_LENGTH
, GFP_KERNEL
);
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
= of_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 || CONFIG_SPARC */
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;
410 if (strcmp(s1
, "CRT") == 0)
411 rinfo
->mon1_type
= MT_CRT
;
412 else if (strcmp(s1
, "TMDS") == 0)
413 rinfo
->mon1_type
= MT_DFP
;
414 else if (strcmp(s1
, "LVDS") == 0)
415 rinfo
->mon1_type
= MT_LCD
;
417 if (strcmp(s2
, "CRT") == 0)
418 rinfo
->mon2_type
= MT_CRT
;
419 else if (strcmp(s2
, "TMDS") == 0)
420 rinfo
->mon2_type
= MT_DFP
;
421 else if (strcmp(s2
, "LVDS") == 0)
422 rinfo
->mon2_type
= MT_LCD
;
428 * Probe display on both primary and secondary card's connector (if any)
429 * by various available techniques (i2c, OF device tree, BIOS, ...) and
430 * try to retrieve EDID. The algorithm here comes from XFree's radeon
433 void __devinit
radeon_probe_screens(struct radeonfb_info
*rinfo
,
434 const char *monitor_layout
, int ignore_edid
)
436 #ifdef CONFIG_FB_RADEON_I2C
437 int ddc_crt2_used
= 0;
441 radeon_parse_connector_info(rinfo
);
443 if (radeon_parse_monitor_layout(rinfo
, monitor_layout
)) {
446 * If user specified a monitor_layout option, use it instead
447 * of auto-detecting. Maybe we should only use this argument
448 * on the first radeon card probed or provide a way to specify
449 * a layout for each card ?
452 RTRACE("Using specified monitor layout: %s", monitor_layout
);
453 #ifdef CONFIG_FB_RADEON_I2C
455 if (rinfo
->mon1_type
!= MT_NONE
)
456 if (!radeon_probe_i2c_connector(rinfo
, ddc_dvi
, &rinfo
->mon1_EDID
)) {
457 radeon_probe_i2c_connector(rinfo
, ddc_crt2
, &rinfo
->mon1_EDID
);
460 if (rinfo
->mon2_type
!= MT_NONE
)
461 if (!radeon_probe_i2c_connector(rinfo
, ddc_vga
, &rinfo
->mon2_EDID
) &&
463 radeon_probe_i2c_connector(rinfo
, ddc_crt2
, &rinfo
->mon2_EDID
);
465 #endif /* CONFIG_FB_RADEON_I2C */
466 if (rinfo
->mon1_type
== MT_NONE
) {
467 if (rinfo
->mon2_type
!= MT_NONE
) {
468 rinfo
->mon1_type
= rinfo
->mon2_type
;
469 rinfo
->mon1_EDID
= rinfo
->mon2_EDID
;
471 rinfo
->mon1_type
= MT_CRT
;
472 printk(KERN_INFO
"radeonfb: No valid monitor, assuming CRT on first port\n");
474 rinfo
->mon2_type
= MT_NONE
;
475 rinfo
->mon2_EDID
= NULL
;
479 * Auto-detecting display type (well... trying to ...)
482 RTRACE("Starting monitor auto detection...\n");
484 #if defined(DEBUG) && defined(CONFIG_FB_RADEON_I2C)
486 u8
*EDIDs
[4] = { NULL
, NULL
, NULL
, NULL
};
487 int mon_types
[4] = {MT_NONE
, MT_NONE
, MT_NONE
, MT_NONE
};
490 for (i
= 0; i
< 4; i
++)
491 mon_types
[i
] = radeon_probe_i2c_connector(rinfo
,
496 * Old single head cards
498 if (!rinfo
->has_CRTC2
) {
499 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
500 if (rinfo
->mon1_type
== MT_NONE
)
501 rinfo
->mon1_type
= radeon_probe_OF_head(rinfo
, 0,
503 #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
504 #ifdef CONFIG_FB_RADEON_I2C
505 if (rinfo
->mon1_type
== MT_NONE
)
507 radeon_probe_i2c_connector(rinfo
, ddc_dvi
,
509 if (rinfo
->mon1_type
== MT_NONE
)
511 radeon_probe_i2c_connector(rinfo
, ddc_vga
,
513 if (rinfo
->mon1_type
== MT_NONE
)
515 radeon_probe_i2c_connector(rinfo
, ddc_crt2
,
517 #endif /* CONFIG_FB_RADEON_I2C */
518 if (rinfo
->mon1_type
== MT_NONE
)
519 rinfo
->mon1_type
= MT_CRT
;
524 * Check for cards with reversed DACs or TMDS controllers using BIOS
526 if (rinfo
->bios_seg
&&
527 (tmp
= BIOS_IN16(rinfo
->fp_bios_start
+ 0x50))) {
528 for (i
= 1; i
< 4; i
++) {
531 if (!BIOS_IN8(tmp
+ i
*2) && i
> 1)
533 tmp0
= BIOS_IN16(tmp
+ i
*2);
534 if ((!(tmp0
& 0x01)) && (((tmp0
>> 8) & 0x0f) == ddc_dvi
)) {
535 rinfo
->reversed_DAC
= 1;
536 printk(KERN_INFO
"radeonfb: Reversed DACs detected\n");
538 if ((((tmp0
>> 8) & 0x0f) == ddc_dvi
) && ((tmp0
>> 4) & 0x01)) {
539 rinfo
->reversed_TMDS
= 1;
540 printk(KERN_INFO
"radeonfb: Reversed TMDS detected\n");
546 * Probe primary head (DVI or laptop internal panel)
548 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
549 if (rinfo
->mon1_type
== MT_NONE
)
550 rinfo
->mon1_type
= radeon_probe_OF_head(rinfo
, 0,
552 #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
553 #ifdef CONFIG_FB_RADEON_I2C
554 if (rinfo
->mon1_type
== MT_NONE
)
555 rinfo
->mon1_type
= radeon_probe_i2c_connector(rinfo
, ddc_dvi
,
557 if (rinfo
->mon1_type
== MT_NONE
) {
558 rinfo
->mon1_type
= radeon_probe_i2c_connector(rinfo
, ddc_crt2
,
560 if (rinfo
->mon1_type
!= MT_NONE
)
563 #endif /* CONFIG_FB_RADEON_I2C */
564 if (rinfo
->mon1_type
== MT_NONE
&& rinfo
->is_mobility
&&
565 ((rinfo
->bios_seg
&& (INREG(BIOS_4_SCRATCH
) & 4))
566 || (INREG(LVDS_GEN_CNTL
) & LVDS_ON
))) {
567 rinfo
->mon1_type
= MT_LCD
;
568 printk("Non-DDC laptop panel detected\n");
570 if (rinfo
->mon1_type
== MT_NONE
)
571 rinfo
->mon1_type
= radeon_crt_is_connected(rinfo
, rinfo
->reversed_DAC
);
574 * Probe secondary head (mostly VGA, can be DVI)
576 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
577 if (rinfo
->mon2_type
== MT_NONE
)
578 rinfo
->mon2_type
= radeon_probe_OF_head(rinfo
, 1,
580 #endif /* CONFIG_PPC_OF || defined(CONFIG_SPARC) */
581 #ifdef CONFIG_FB_RADEON_I2C
582 if (rinfo
->mon2_type
== MT_NONE
)
583 rinfo
->mon2_type
= radeon_probe_i2c_connector(rinfo
, ddc_vga
,
585 if (rinfo
->mon2_type
== MT_NONE
&& !ddc_crt2_used
)
586 rinfo
->mon2_type
= radeon_probe_i2c_connector(rinfo
, ddc_crt2
,
588 #endif /* CONFIG_FB_RADEON_I2C */
589 if (rinfo
->mon2_type
== MT_NONE
)
590 rinfo
->mon2_type
= radeon_crt_is_connected(rinfo
, !rinfo
->reversed_DAC
);
593 * If we only detected port 2, we swap them, if none detected,
594 * assume CRT (maybe fallback to old BIOS_SCRATCH stuff ? or look
597 if (rinfo
->mon1_type
== MT_NONE
) {
598 if (rinfo
->mon2_type
!= MT_NONE
) {
599 rinfo
->mon1_type
= rinfo
->mon2_type
;
600 rinfo
->mon1_EDID
= rinfo
->mon2_EDID
;
602 rinfo
->mon1_type
= MT_CRT
;
603 rinfo
->mon2_type
= MT_NONE
;
604 rinfo
->mon2_EDID
= NULL
;
608 * Deal with reversed TMDS
610 if (rinfo
->reversed_TMDS
) {
611 /* Always keep internal TMDS as primary head */
612 if (rinfo
->mon1_type
== MT_DFP
|| rinfo
->mon2_type
== MT_DFP
) {
613 int tmp_type
= rinfo
->mon1_type
;
614 u8
*tmp_EDID
= rinfo
->mon1_EDID
;
615 rinfo
->mon1_type
= rinfo
->mon2_type
;
616 rinfo
->mon1_EDID
= rinfo
->mon2_EDID
;
617 rinfo
->mon2_type
= tmp_type
;
618 rinfo
->mon2_EDID
= tmp_EDID
;
619 if (rinfo
->mon1_type
== MT_CRT
|| rinfo
->mon2_type
== MT_CRT
)
620 rinfo
->reversed_DAC
^= 1;
625 kfree(rinfo
->mon1_EDID
);
626 rinfo
->mon1_EDID
= NULL
;
627 kfree(rinfo
->mon2_EDID
);
628 rinfo
->mon2_EDID
= NULL
;
632 printk(KERN_INFO
"radeonfb: Monitor 1 type %s found\n",
633 radeon_get_mon_name(rinfo
->mon1_type
));
634 if (rinfo
->mon1_EDID
)
635 printk(KERN_INFO
"radeonfb: EDID probed\n");
636 if (!rinfo
->has_CRTC2
)
638 printk(KERN_INFO
"radeonfb: Monitor 2 type %s found\n",
639 radeon_get_mon_name(rinfo
->mon2_type
));
640 if (rinfo
->mon2_EDID
)
641 printk(KERN_INFO
"radeonfb: EDID probed\n");
646 * This functions applyes any arch/model/machine specific fixups
647 * to the panel info. It may eventually alter EDID block as
648 * well or whatever is specific to a given model and not probed
649 * properly by the default code
651 static void radeon_fixup_panel_info(struct radeonfb_info
*rinfo
)
655 * LCD Flat panels should use fixed dividers, we enfore that on
656 * PPC only for now...
658 if (!rinfo
->panel_info
.use_bios_dividers
&& rinfo
->mon1_type
== MT_LCD
659 && rinfo
->is_mobility
) {
662 ppll_div_sel
= INREG8(CLOCK_CNTL_INDEX
+ 1) & 0x3;
663 radeon_pll_errata_after_index(rinfo
);
664 ppll_divn
= INPLL(PPLL_DIV_0
+ ppll_div_sel
);
665 rinfo
->panel_info
.ref_divider
= rinfo
->pll
.ref_div
;
666 rinfo
->panel_info
.fbk_divider
= ppll_divn
& 0x7ff;
667 rinfo
->panel_info
.post_divider
= (ppll_divn
>> 16) & 0x7;
668 rinfo
->panel_info
.use_bios_dividers
= 1;
670 printk(KERN_DEBUG
"radeonfb: Using Firmware dividers 0x%08x "
672 rinfo
->panel_info
.fbk_divider
|
673 (rinfo
->panel_info
.post_divider
<< 16),
676 #endif /* CONFIG_PPC_OF */
681 * Fill up panel infos from a mode definition, either returned by the EDID
682 * or from the default mode when we can't do any better
684 static void radeon_var_to_panel_info(struct radeonfb_info
*rinfo
, struct fb_var_screeninfo
*var
)
686 rinfo
->panel_info
.xres
= var
->xres
;
687 rinfo
->panel_info
.yres
= var
->yres
;
688 rinfo
->panel_info
.clock
= 100000000 / var
->pixclock
;
689 rinfo
->panel_info
.hOver_plus
= var
->right_margin
;
690 rinfo
->panel_info
.hSync_width
= var
->hsync_len
;
691 rinfo
->panel_info
.hblank
= var
->left_margin
+
692 (var
->right_margin
+ var
->hsync_len
);
693 rinfo
->panel_info
.vOver_plus
= var
->lower_margin
;
694 rinfo
->panel_info
.vSync_width
= var
->vsync_len
;
695 rinfo
->panel_info
.vblank
= var
->upper_margin
+
696 (var
->lower_margin
+ var
->vsync_len
);
697 rinfo
->panel_info
.hAct_high
=
698 (var
->sync
& FB_SYNC_HOR_HIGH_ACT
) != 0;
699 rinfo
->panel_info
.vAct_high
=
700 (var
->sync
& FB_SYNC_VERT_HIGH_ACT
) != 0;
701 rinfo
->panel_info
.valid
= 1;
702 /* We use a default of 200ms for the panel power delay,
703 * I need to have a real schedule() instead of mdelay's in the panel code.
704 * we might be possible to figure out a better power delay either from
705 * MacOS OF tree or from the EDID block (proprietary extensions ?)
707 rinfo
->panel_info
.pwr_delay
= 200;
710 static void radeon_videomode_to_var(struct fb_var_screeninfo
*var
,
711 const struct fb_videomode
*mode
)
713 var
->xres
= mode
->xres
;
714 var
->yres
= mode
->yres
;
715 var
->xres_virtual
= mode
->xres
;
716 var
->yres_virtual
= mode
->yres
;
719 var
->pixclock
= mode
->pixclock
;
720 var
->left_margin
= mode
->left_margin
;
721 var
->right_margin
= mode
->right_margin
;
722 var
->upper_margin
= mode
->upper_margin
;
723 var
->lower_margin
= mode
->lower_margin
;
724 var
->hsync_len
= mode
->hsync_len
;
725 var
->vsync_len
= mode
->vsync_len
;
726 var
->sync
= mode
->sync
;
727 var
->vmode
= mode
->vmode
;
731 * Build the modedb for head 1 (head 2 will come later), check panel infos
732 * from either BIOS or EDID, and pick up the default mode
734 void __devinit
radeon_check_modes(struct radeonfb_info
*rinfo
, const char *mode_option
)
736 struct fb_info
* info
= rinfo
->info
;
737 int has_default_mode
= 0;
740 * Fill default var first
742 info
->var
= radeonfb_default_var
;
743 INIT_LIST_HEAD(&info
->modelist
);
746 * First check out what BIOS has to say
748 if (rinfo
->mon1_type
== MT_LCD
)
749 radeon_get_panel_info_BIOS(rinfo
);
752 * Parse EDID detailed timings and deduce panel infos if any. Right now
753 * we only deal with first entry returned by parse_EDID, we may do better
756 if (!rinfo
->panel_info
.use_bios_dividers
&& rinfo
->mon1_type
!= MT_CRT
757 && rinfo
->mon1_EDID
) {
758 struct fb_var_screeninfo var
;
759 RTRACE("Parsing EDID data for panel info\n");
760 if (fb_parse_edid(rinfo
->mon1_EDID
, &var
) == 0) {
761 if (var
.xres
>= rinfo
->panel_info
.xres
&&
762 var
.yres
>= rinfo
->panel_info
.yres
)
763 radeon_var_to_panel_info(rinfo
, &var
);
768 * Do any additional platform/arch fixups to the panel infos
770 radeon_fixup_panel_info(rinfo
);
773 * If we have some valid panel infos, we setup the default mode based on
776 if (rinfo
->mon1_type
!= MT_CRT
&& rinfo
->panel_info
.valid
) {
777 struct fb_var_screeninfo
*var
= &info
->var
;
779 RTRACE("Setting up default mode based on panel info\n");
780 var
->xres
= rinfo
->panel_info
.xres
;
781 var
->yres
= rinfo
->panel_info
.yres
;
782 var
->xres_virtual
= rinfo
->panel_info
.xres
;
783 var
->yres_virtual
= rinfo
->panel_info
.yres
;
784 var
->xoffset
= var
->yoffset
= 0;
785 var
->bits_per_pixel
= 8;
786 var
->pixclock
= 100000000 / rinfo
->panel_info
.clock
;
787 var
->left_margin
= (rinfo
->panel_info
.hblank
- rinfo
->panel_info
.hOver_plus
788 - rinfo
->panel_info
.hSync_width
);
789 var
->right_margin
= rinfo
->panel_info
.hOver_plus
;
790 var
->upper_margin
= (rinfo
->panel_info
.vblank
- rinfo
->panel_info
.vOver_plus
791 - rinfo
->panel_info
.vSync_width
);
792 var
->lower_margin
= rinfo
->panel_info
.vOver_plus
;
793 var
->hsync_len
= rinfo
->panel_info
.hSync_width
;
794 var
->vsync_len
= rinfo
->panel_info
.vSync_width
;
796 if (rinfo
->panel_info
.hAct_high
)
797 var
->sync
|= FB_SYNC_HOR_HIGH_ACT
;
798 if (rinfo
->panel_info
.vAct_high
)
799 var
->sync
|= FB_SYNC_VERT_HIGH_ACT
;
801 has_default_mode
= 1;
805 * Now build modedb from EDID
807 if (rinfo
->mon1_EDID
) {
808 fb_edid_to_monspecs(rinfo
->mon1_EDID
, &info
->monspecs
);
809 fb_videomode_to_modelist(info
->monspecs
.modedb
,
810 info
->monspecs
.modedb_len
,
812 rinfo
->mon1_modedb
= info
->monspecs
.modedb
;
813 rinfo
->mon1_dbsize
= info
->monspecs
.modedb_len
;
818 * Finally, if we don't have panel infos we need to figure some (or
819 * we try to read it from card), we try to pick a default mode
820 * and create some panel infos. Whatever...
822 if (rinfo
->mon1_type
!= MT_CRT
&& !rinfo
->panel_info
.valid
) {
823 struct fb_videomode
*modedb
;
827 RTRACE("Guessing panel info...\n");
828 if (rinfo
->panel_info
.xres
== 0 || rinfo
->panel_info
.yres
== 0) {
829 u32 tmp
= INREG(FP_HORZ_STRETCH
) & HORZ_PANEL_SIZE
;
830 rinfo
->panel_info
.xres
= ((tmp
>> HORZ_PANEL_SHIFT
) + 1) * 8;
831 tmp
= INREG(FP_VERT_STRETCH
) & VERT_PANEL_SIZE
;
832 rinfo
->panel_info
.yres
= (tmp
>> VERT_PANEL_SHIFT
) + 1;
834 if (rinfo
->panel_info
.xres
== 0 || rinfo
->panel_info
.yres
== 0) {
835 printk(KERN_WARNING
"radeonfb: Can't find panel size, going back to CRT\n");
836 rinfo
->mon1_type
= MT_CRT
;
839 printk(KERN_WARNING
"radeonfb: Assuming panel size %dx%d\n",
840 rinfo
->panel_info
.xres
, rinfo
->panel_info
.yres
);
841 modedb
= rinfo
->mon1_modedb
;
842 dbsize
= rinfo
->mon1_dbsize
;
843 snprintf(modename
, 31, "%dx%d", rinfo
->panel_info
.xres
, rinfo
->panel_info
.yres
);
844 if (fb_find_mode(&info
->var
, info
, modename
,
845 modedb
, dbsize
, NULL
, 8) == 0) {
846 printk(KERN_WARNING
"radeonfb: Can't find mode for panel size, going back to CRT\n");
847 rinfo
->mon1_type
= MT_CRT
;
850 has_default_mode
= 1;
851 radeon_var_to_panel_info(rinfo
, &info
->var
);
856 * Apply passed-in mode option if any
859 if (fb_find_mode(&info
->var
, info
, mode_option
,
860 info
->monspecs
.modedb
,
861 info
->monspecs
.modedb_len
, NULL
, 8) != 0)
862 has_default_mode
= 1;
866 * Still no mode, let's pick up a default from the db
868 if (!has_default_mode
&& info
->monspecs
.modedb
!= NULL
) {
869 struct fb_monspecs
*specs
= &info
->monspecs
;
870 struct fb_videomode
*modedb
= NULL
;
872 /* get preferred timing */
873 if (specs
->misc
& FB_MISC_1ST_DETAIL
) {
876 for (i
= 0; i
< specs
->modedb_len
; i
++) {
877 if (specs
->modedb
[i
].flag
& FB_MODE_IS_FIRST
) {
878 modedb
= &specs
->modedb
[i
];
883 /* otherwise, get first mode in database */
884 modedb
= &specs
->modedb
[0];
886 if (modedb
!= NULL
) {
887 info
->var
.bits_per_pixel
= 8;
888 radeon_videomode_to_var(&info
->var
, modedb
);
889 has_default_mode
= 1;
893 struct fb_videomode mode
;
894 /* Make sure that whatever mode got selected is actually in the
895 * modelist or the kernel may die
897 fb_var_to_videomode(&mode
, &info
->var
);
898 fb_add_videomode(&mode
, &info
->modelist
);
903 * The code below is used to pick up a mode in check_var and
904 * set_var. It should be made generic
908 * This is used when looking for modes. We assign a "distance" value
909 * to a mode in the modedb depending how "close" it is from what we
911 * Currently, we don't compare that much, we could do better but
912 * the current fbcon doesn't quite mind ;)
914 static int radeon_compare_modes(const struct fb_var_screeninfo
*var
,
915 const struct fb_videomode
*mode
)
919 distance
= mode
->yres
- var
->yres
;
920 distance
+= (mode
->xres
- var
->xres
)/2;
925 * This function is called by check_var, it gets the passed in mode parameter, and
926 * outputs a valid mode matching the passed-in one as closely as possible.
927 * We need something better ultimately. Things like fbcon basically pass us out
928 * current mode with xres/yres hacked, while things like XFree will actually
929 * produce a full timing that we should respect as much as possible.
931 * This is why I added the FB_ACTIVATE_FIND that is used by fbcon. Without this,
932 * we do a simple spec match, that's all. With it, we actually look for a mode in
933 * either our monitor modedb or the vesa one if none
936 int radeon_match_mode(struct radeonfb_info
*rinfo
,
937 struct fb_var_screeninfo
*dest
,
938 const struct fb_var_screeninfo
*src
)
940 const struct fb_videomode
*db
= vesa_modes
;
942 int has_rmx
, native_db
= 0;
943 int distance
= INT_MAX
;
944 const struct fb_videomode
*candidate
= NULL
;
946 /* Start with a copy of the requested mode */
947 memcpy(dest
, src
, sizeof(struct fb_var_screeninfo
));
949 /* Check if we have a modedb built from EDID */
950 if (rinfo
->mon1_modedb
) {
951 db
= rinfo
->mon1_modedb
;
952 dbsize
= rinfo
->mon1_dbsize
;
956 /* Check if we have a scaler allowing any fancy mode */
957 has_rmx
= rinfo
->mon1_type
== MT_LCD
|| rinfo
->mon1_type
== MT_DFP
;
959 /* If we have a scaler and are passed FB_ACTIVATE_TEST or
960 * FB_ACTIVATE_NOW, just do basic checking and return if the
963 if ((src
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_TEST
||
964 (src
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_NOW
) {
965 /* We don't have an RMX, validate timings. If we don't have
966 * monspecs, we should be paranoid and not let use go above
967 * 640x480-60, but I assume userland knows what it's doing here
968 * (though I may be proven wrong...)
970 if (has_rmx
== 0 && rinfo
->mon1_modedb
)
971 if (fb_validate_mode((struct fb_var_screeninfo
*)src
, rinfo
->info
))
976 /* Now look for a mode in the database */
978 for (i
= 0; i
< dbsize
; i
++) {
981 if (db
[i
].yres
< src
->yres
)
983 if (db
[i
].xres
< src
->xres
)
985 d
= radeon_compare_modes(src
, &db
[i
]);
986 /* If the new mode is at least as good as the previous one,
987 * then it's our new candidate
995 /* If we have a scaler, we allow any mode from the database */
996 if (native_db
&& has_rmx
) {
1003 /* If we have found a match, return it */
1004 if (candidate
!= NULL
) {
1005 radeon_videomode_to_var(dest
, candidate
);
1009 /* If we haven't and don't have a scaler, fail */