3 #include <linux/slab.h>
7 static struct fb_var_screeninfo radeonfb_default_var
= {
13 .red
= { .length
= 8 },
14 .green
= { .length
= 8 },
15 .blue
= { .length
= 8 },
16 .activate
= FB_ACTIVATE_NOW
,
26 .vmode
= FB_VMODE_NONINTERLACED
29 static char *radeon_get_mon_name(int type
)
58 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
60 * Try to find monitor informations & EDID data out of the Open Firmware
61 * device-tree. This also contains some "hacks" to work around a few machine
62 * models with broken OF probing by hard-coding known EDIDs for some Mac
63 * laptops internal LVDS panel. (XXX: not done yet)
65 static int __devinit
radeon_parse_montype_prop(struct device_node
*dp
, u8
**out_EDID
,
68 static char *propnames
[] = { "DFP,EDID", "LCD,EDID", "EDID",
69 "EDID1", "EDID2", NULL
};
70 const u8
*pedid
= NULL
;
75 pr_debug("analyzing OF properties...\n");
76 pmt
= of_get_property(dp
, "display-type", NULL
);
79 pr_debug("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
= of_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
= of_get_property(dp
->parent
,
105 (hdno
== 0) ? "EDID1" : "EDID2", NULL
);
106 if (pedid
== NULL
&& dp
->parent
&& (hdno
== 0))
107 pedid
= of_get_property(dp
->parent
, "EDID", NULL
);
111 tmp
= kmemdup(pedid
, EDID_LENGTH
, GFP_KERNEL
);
118 static int __devinit
radeon_probe_OF_head(struct radeonfb_info
*rinfo
, int head_no
,
121 struct device_node
*dp
;
123 pr_debug("radeon_probe_OF_head\n");
129 if (rinfo
->has_CRTC2
) {
137 pname
= of_get_property(dp
, "name", NULL
);
141 pr_debug("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 || CONFIG_SPARC */
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 pr_debug("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 pr_debug("ref_divider = %x\n", rinfo
->panel_info
.ref_divider
);
206 pr_debug("post_divider = %x\n", rinfo
->panel_info
.post_divider
);
207 pr_debug("fbk_divider = %x\n", rinfo
->panel_info
.fbk_divider
);
209 pr_debug("Scanning BIOS table ...\n");
210 for(i
=0; i
<32; i
++) {
211 tmp0
= BIOS_IN16(tmp
+64+i
*2);
214 pr_debug(" %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 pr_debug("Found panel in BIOS table:\n");
234 pr_debug(" hblank: %d\n", rinfo
->panel_info
.hblank
);
235 pr_debug(" hOver_plus: %d\n", rinfo
->panel_info
.hOver_plus
);
236 pr_debug(" hSync_width: %d\n", rinfo
->panel_info
.hSync_width
);
237 pr_debug(" vblank: %d\n", rinfo
->panel_info
.vblank
);
238 pr_debug(" vOver_plus: %d\n", rinfo
->panel_info
.vOver_plus
);
239 pr_debug(" vSync_width: %d\n", rinfo
->panel_info
.vSync_width
);
240 pr_debug(" clock: %d\n", rinfo
->panel_info
.clock
);
245 pr_debug("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 pr_debug("%d chips in connector info\n", chips
);
278 for (i
= 0; i
< chips
; i
++) {
279 tmp
= BIOS_IN8(offset
++);
280 connectors
= tmp
& 0x0f;
281 pr_debug(" - 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 pr_debug(" * 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;
413 if (strcmp(s1
, "CRT") == 0)
414 rinfo
->mon1_type
= MT_CRT
;
415 else if (strcmp(s1
, "TMDS") == 0)
416 rinfo
->mon1_type
= MT_DFP
;
417 else if (strcmp(s1
, "LVDS") == 0)
418 rinfo
->mon1_type
= MT_LCD
;
420 if (strcmp(s2
, "CRT") == 0)
421 rinfo
->mon2_type
= MT_CRT
;
422 else if (strcmp(s2
, "TMDS") == 0)
423 rinfo
->mon2_type
= MT_DFP
;
424 else if (strcmp(s2
, "LVDS") == 0)
425 rinfo
->mon2_type
= MT_LCD
;
431 * Probe display on both primary and secondary card's connector (if any)
432 * by various available techniques (i2c, OF device tree, BIOS, ...) and
433 * try to retrieve EDID. The algorithm here comes from XFree's radeon
436 void __devinit
radeon_probe_screens(struct radeonfb_info
*rinfo
,
437 const char *monitor_layout
, int ignore_edid
)
439 #ifdef CONFIG_FB_RADEON_I2C
440 int ddc_crt2_used
= 0;
444 radeon_parse_connector_info(rinfo
);
446 if (radeon_parse_monitor_layout(rinfo
, monitor_layout
)) {
449 * If user specified a monitor_layout option, use it instead
450 * of auto-detecting. Maybe we should only use this argument
451 * on the first radeon card probed or provide a way to specify
452 * a layout for each card ?
455 pr_debug("Using specified monitor layout: %s", monitor_layout
);
456 #ifdef CONFIG_FB_RADEON_I2C
458 if (rinfo
->mon1_type
!= MT_NONE
)
459 if (!radeon_probe_i2c_connector(rinfo
, ddc_dvi
, &rinfo
->mon1_EDID
)) {
460 radeon_probe_i2c_connector(rinfo
, ddc_crt2
, &rinfo
->mon1_EDID
);
463 if (rinfo
->mon2_type
!= MT_NONE
)
464 if (!radeon_probe_i2c_connector(rinfo
, ddc_vga
, &rinfo
->mon2_EDID
) &&
466 radeon_probe_i2c_connector(rinfo
, ddc_crt2
, &rinfo
->mon2_EDID
);
468 #endif /* CONFIG_FB_RADEON_I2C */
469 if (rinfo
->mon1_type
== MT_NONE
) {
470 if (rinfo
->mon2_type
!= MT_NONE
) {
471 rinfo
->mon1_type
= rinfo
->mon2_type
;
472 rinfo
->mon1_EDID
= rinfo
->mon2_EDID
;
474 rinfo
->mon1_type
= MT_CRT
;
475 printk(KERN_INFO
"radeonfb: No valid monitor, assuming CRT on first port\n");
477 rinfo
->mon2_type
= MT_NONE
;
478 rinfo
->mon2_EDID
= NULL
;
482 * Auto-detecting display type (well... trying to ...)
485 pr_debug("Starting monitor auto detection...\n");
487 #if defined(DEBUG) && defined(CONFIG_FB_RADEON_I2C)
489 u8
*EDIDs
[4] = { NULL
, NULL
, NULL
, NULL
};
490 int mon_types
[4] = {MT_NONE
, MT_NONE
, MT_NONE
, MT_NONE
};
493 for (i
= 0; i
< 4; i
++)
494 mon_types
[i
] = radeon_probe_i2c_connector(rinfo
,
499 * Old single head cards
501 if (!rinfo
->has_CRTC2
) {
502 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
503 if (rinfo
->mon1_type
== MT_NONE
)
504 rinfo
->mon1_type
= radeon_probe_OF_head(rinfo
, 0,
506 #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
507 #ifdef CONFIG_FB_RADEON_I2C
508 if (rinfo
->mon1_type
== MT_NONE
)
510 radeon_probe_i2c_connector(rinfo
, ddc_dvi
,
512 if (rinfo
->mon1_type
== MT_NONE
)
514 radeon_probe_i2c_connector(rinfo
, ddc_vga
,
516 if (rinfo
->mon1_type
== MT_NONE
)
518 radeon_probe_i2c_connector(rinfo
, ddc_crt2
,
520 #endif /* CONFIG_FB_RADEON_I2C */
521 if (rinfo
->mon1_type
== MT_NONE
)
522 rinfo
->mon1_type
= MT_CRT
;
527 * Check for cards with reversed DACs or TMDS controllers using BIOS
529 if (rinfo
->bios_seg
&&
530 (tmp
= BIOS_IN16(rinfo
->fp_bios_start
+ 0x50))) {
531 for (i
= 1; i
< 4; i
++) {
534 if (!BIOS_IN8(tmp
+ i
*2) && i
> 1)
536 tmp0
= BIOS_IN16(tmp
+ i
*2);
537 if ((!(tmp0
& 0x01)) && (((tmp0
>> 8) & 0x0f) == ddc_dvi
)) {
538 rinfo
->reversed_DAC
= 1;
539 printk(KERN_INFO
"radeonfb: Reversed DACs detected\n");
541 if ((((tmp0
>> 8) & 0x0f) == ddc_dvi
) && ((tmp0
>> 4) & 0x01)) {
542 rinfo
->reversed_TMDS
= 1;
543 printk(KERN_INFO
"radeonfb: Reversed TMDS detected\n");
549 * Probe primary head (DVI or laptop internal panel)
551 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
552 if (rinfo
->mon1_type
== MT_NONE
)
553 rinfo
->mon1_type
= radeon_probe_OF_head(rinfo
, 0,
555 #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
556 #ifdef CONFIG_FB_RADEON_I2C
557 if (rinfo
->mon1_type
== MT_NONE
)
558 rinfo
->mon1_type
= radeon_probe_i2c_connector(rinfo
, ddc_dvi
,
560 if (rinfo
->mon1_type
== MT_NONE
) {
561 rinfo
->mon1_type
= radeon_probe_i2c_connector(rinfo
, ddc_crt2
,
563 if (rinfo
->mon1_type
!= MT_NONE
)
566 #endif /* CONFIG_FB_RADEON_I2C */
567 if (rinfo
->mon1_type
== MT_NONE
&& rinfo
->is_mobility
&&
568 ((rinfo
->bios_seg
&& (INREG(BIOS_4_SCRATCH
) & 4))
569 || (INREG(LVDS_GEN_CNTL
) & LVDS_ON
))) {
570 rinfo
->mon1_type
= MT_LCD
;
571 printk("Non-DDC laptop panel detected\n");
573 if (rinfo
->mon1_type
== MT_NONE
)
574 rinfo
->mon1_type
= radeon_crt_is_connected(rinfo
, rinfo
->reversed_DAC
);
577 * Probe secondary head (mostly VGA, can be DVI)
579 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
580 if (rinfo
->mon2_type
== MT_NONE
)
581 rinfo
->mon2_type
= radeon_probe_OF_head(rinfo
, 1,
583 #endif /* CONFIG_PPC_OF || defined(CONFIG_SPARC) */
584 #ifdef CONFIG_FB_RADEON_I2C
585 if (rinfo
->mon2_type
== MT_NONE
)
586 rinfo
->mon2_type
= radeon_probe_i2c_connector(rinfo
, ddc_vga
,
588 if (rinfo
->mon2_type
== MT_NONE
&& !ddc_crt2_used
)
589 rinfo
->mon2_type
= radeon_probe_i2c_connector(rinfo
, ddc_crt2
,
591 #endif /* CONFIG_FB_RADEON_I2C */
592 if (rinfo
->mon2_type
== MT_NONE
)
593 rinfo
->mon2_type
= radeon_crt_is_connected(rinfo
, !rinfo
->reversed_DAC
);
596 * If we only detected port 2, we swap them, if none detected,
597 * assume CRT (maybe fallback to old BIOS_SCRATCH stuff ? or look
600 if (rinfo
->mon1_type
== MT_NONE
) {
601 if (rinfo
->mon2_type
!= MT_NONE
) {
602 rinfo
->mon1_type
= rinfo
->mon2_type
;
603 rinfo
->mon1_EDID
= rinfo
->mon2_EDID
;
605 rinfo
->mon1_type
= MT_CRT
;
606 rinfo
->mon2_type
= MT_NONE
;
607 rinfo
->mon2_EDID
= NULL
;
611 * Deal with reversed TMDS
613 if (rinfo
->reversed_TMDS
) {
614 /* Always keep internal TMDS as primary head */
615 if (rinfo
->mon1_type
== MT_DFP
|| rinfo
->mon2_type
== MT_DFP
) {
616 int tmp_type
= rinfo
->mon1_type
;
617 u8
*tmp_EDID
= rinfo
->mon1_EDID
;
618 rinfo
->mon1_type
= rinfo
->mon2_type
;
619 rinfo
->mon1_EDID
= rinfo
->mon2_EDID
;
620 rinfo
->mon2_type
= tmp_type
;
621 rinfo
->mon2_EDID
= tmp_EDID
;
622 if (rinfo
->mon1_type
== MT_CRT
|| rinfo
->mon2_type
== MT_CRT
)
623 rinfo
->reversed_DAC
^= 1;
628 kfree(rinfo
->mon1_EDID
);
629 rinfo
->mon1_EDID
= NULL
;
630 kfree(rinfo
->mon2_EDID
);
631 rinfo
->mon2_EDID
= NULL
;
635 printk(KERN_INFO
"radeonfb: Monitor 1 type %s found\n",
636 radeon_get_mon_name(rinfo
->mon1_type
));
637 if (rinfo
->mon1_EDID
)
638 printk(KERN_INFO
"radeonfb: EDID probed\n");
639 if (!rinfo
->has_CRTC2
)
641 printk(KERN_INFO
"radeonfb: Monitor 2 type %s found\n",
642 radeon_get_mon_name(rinfo
->mon2_type
));
643 if (rinfo
->mon2_EDID
)
644 printk(KERN_INFO
"radeonfb: EDID probed\n");
649 * This functions applyes any arch/model/machine specific fixups
650 * to the panel info. It may eventually alter EDID block as
651 * well or whatever is specific to a given model and not probed
652 * properly by the default code
654 static void radeon_fixup_panel_info(struct radeonfb_info
*rinfo
)
658 * LCD Flat panels should use fixed dividers, we enfore that on
659 * PPC only for now...
661 if (!rinfo
->panel_info
.use_bios_dividers
&& rinfo
->mon1_type
== MT_LCD
662 && rinfo
->is_mobility
) {
665 ppll_div_sel
= INREG8(CLOCK_CNTL_INDEX
+ 1) & 0x3;
666 radeon_pll_errata_after_index(rinfo
);
667 ppll_divn
= INPLL(PPLL_DIV_0
+ ppll_div_sel
);
668 rinfo
->panel_info
.ref_divider
= rinfo
->pll
.ref_div
;
669 rinfo
->panel_info
.fbk_divider
= ppll_divn
& 0x7ff;
670 rinfo
->panel_info
.post_divider
= (ppll_divn
>> 16) & 0x7;
671 rinfo
->panel_info
.use_bios_dividers
= 1;
673 printk(KERN_DEBUG
"radeonfb: Using Firmware dividers 0x%08x "
675 rinfo
->panel_info
.fbk_divider
|
676 (rinfo
->panel_info
.post_divider
<< 16),
679 #endif /* CONFIG_PPC_OF */
684 * Fill up panel infos from a mode definition, either returned by the EDID
685 * or from the default mode when we can't do any better
687 static void radeon_var_to_panel_info(struct radeonfb_info
*rinfo
, struct fb_var_screeninfo
*var
)
689 rinfo
->panel_info
.xres
= var
->xres
;
690 rinfo
->panel_info
.yres
= var
->yres
;
691 rinfo
->panel_info
.clock
= 100000000 / var
->pixclock
;
692 rinfo
->panel_info
.hOver_plus
= var
->right_margin
;
693 rinfo
->panel_info
.hSync_width
= var
->hsync_len
;
694 rinfo
->panel_info
.hblank
= var
->left_margin
+
695 (var
->right_margin
+ var
->hsync_len
);
696 rinfo
->panel_info
.vOver_plus
= var
->lower_margin
;
697 rinfo
->panel_info
.vSync_width
= var
->vsync_len
;
698 rinfo
->panel_info
.vblank
= var
->upper_margin
+
699 (var
->lower_margin
+ var
->vsync_len
);
700 rinfo
->panel_info
.hAct_high
=
701 (var
->sync
& FB_SYNC_HOR_HIGH_ACT
) != 0;
702 rinfo
->panel_info
.vAct_high
=
703 (var
->sync
& FB_SYNC_VERT_HIGH_ACT
) != 0;
704 rinfo
->panel_info
.valid
= 1;
705 /* We use a default of 200ms for the panel power delay,
706 * I need to have a real schedule() instead of mdelay's in the panel code.
707 * we might be possible to figure out a better power delay either from
708 * MacOS OF tree or from the EDID block (proprietary extensions ?)
710 rinfo
->panel_info
.pwr_delay
= 200;
713 static void radeon_videomode_to_var(struct fb_var_screeninfo
*var
,
714 const struct fb_videomode
*mode
)
716 var
->xres
= mode
->xres
;
717 var
->yres
= mode
->yres
;
718 var
->xres_virtual
= mode
->xres
;
719 var
->yres_virtual
= mode
->yres
;
722 var
->pixclock
= mode
->pixclock
;
723 var
->left_margin
= mode
->left_margin
;
724 var
->right_margin
= mode
->right_margin
;
725 var
->upper_margin
= mode
->upper_margin
;
726 var
->lower_margin
= mode
->lower_margin
;
727 var
->hsync_len
= mode
->hsync_len
;
728 var
->vsync_len
= mode
->vsync_len
;
729 var
->sync
= mode
->sync
;
730 var
->vmode
= mode
->vmode
;
734 * Build the modedb for head 1 (head 2 will come later), check panel infos
735 * from either BIOS or EDID, and pick up the default mode
737 void __devinit
radeon_check_modes(struct radeonfb_info
*rinfo
, const char *mode_option
)
739 struct fb_info
* info
= rinfo
->info
;
740 int has_default_mode
= 0;
743 * Fill default var first
745 info
->var
= radeonfb_default_var
;
746 INIT_LIST_HEAD(&info
->modelist
);
749 * First check out what BIOS has to say
751 if (rinfo
->mon1_type
== MT_LCD
)
752 radeon_get_panel_info_BIOS(rinfo
);
755 * Parse EDID detailed timings and deduce panel infos if any. Right now
756 * we only deal with first entry returned by parse_EDID, we may do better
759 if (!rinfo
->panel_info
.use_bios_dividers
&& rinfo
->mon1_type
!= MT_CRT
760 && rinfo
->mon1_EDID
) {
761 struct fb_var_screeninfo var
;
762 pr_debug("Parsing EDID data for panel info\n");
763 if (fb_parse_edid(rinfo
->mon1_EDID
, &var
) == 0) {
764 if (var
.xres
>= rinfo
->panel_info
.xres
&&
765 var
.yres
>= rinfo
->panel_info
.yres
)
766 radeon_var_to_panel_info(rinfo
, &var
);
771 * Do any additional platform/arch fixups to the panel infos
773 radeon_fixup_panel_info(rinfo
);
776 * If we have some valid panel infos, we setup the default mode based on
779 if (rinfo
->mon1_type
!= MT_CRT
&& rinfo
->panel_info
.valid
) {
780 struct fb_var_screeninfo
*var
= &info
->var
;
782 pr_debug("Setting up default mode based on panel info\n");
783 var
->xres
= rinfo
->panel_info
.xres
;
784 var
->yres
= rinfo
->panel_info
.yres
;
785 var
->xres_virtual
= rinfo
->panel_info
.xres
;
786 var
->yres_virtual
= rinfo
->panel_info
.yres
;
787 var
->xoffset
= var
->yoffset
= 0;
788 var
->bits_per_pixel
= 8;
789 var
->pixclock
= 100000000 / rinfo
->panel_info
.clock
;
790 var
->left_margin
= (rinfo
->panel_info
.hblank
- rinfo
->panel_info
.hOver_plus
791 - rinfo
->panel_info
.hSync_width
);
792 var
->right_margin
= rinfo
->panel_info
.hOver_plus
;
793 var
->upper_margin
= (rinfo
->panel_info
.vblank
- rinfo
->panel_info
.vOver_plus
794 - rinfo
->panel_info
.vSync_width
);
795 var
->lower_margin
= rinfo
->panel_info
.vOver_plus
;
796 var
->hsync_len
= rinfo
->panel_info
.hSync_width
;
797 var
->vsync_len
= rinfo
->panel_info
.vSync_width
;
799 if (rinfo
->panel_info
.hAct_high
)
800 var
->sync
|= FB_SYNC_HOR_HIGH_ACT
;
801 if (rinfo
->panel_info
.vAct_high
)
802 var
->sync
|= FB_SYNC_VERT_HIGH_ACT
;
804 has_default_mode
= 1;
808 * Now build modedb from EDID
810 if (rinfo
->mon1_EDID
) {
811 fb_edid_to_monspecs(rinfo
->mon1_EDID
, &info
->monspecs
);
812 fb_videomode_to_modelist(info
->monspecs
.modedb
,
813 info
->monspecs
.modedb_len
,
815 rinfo
->mon1_modedb
= info
->monspecs
.modedb
;
816 rinfo
->mon1_dbsize
= info
->monspecs
.modedb_len
;
821 * Finally, if we don't have panel infos we need to figure some (or
822 * we try to read it from card), we try to pick a default mode
823 * and create some panel infos. Whatever...
825 if (rinfo
->mon1_type
!= MT_CRT
&& !rinfo
->panel_info
.valid
) {
826 struct fb_videomode
*modedb
;
830 pr_debug("Guessing panel info...\n");
831 if (rinfo
->panel_info
.xres
== 0 || rinfo
->panel_info
.yres
== 0) {
832 u32 tmp
= INREG(FP_HORZ_STRETCH
) & HORZ_PANEL_SIZE
;
833 rinfo
->panel_info
.xres
= ((tmp
>> HORZ_PANEL_SHIFT
) + 1) * 8;
834 tmp
= INREG(FP_VERT_STRETCH
) & VERT_PANEL_SIZE
;
835 rinfo
->panel_info
.yres
= (tmp
>> VERT_PANEL_SHIFT
) + 1;
837 if (rinfo
->panel_info
.xres
== 0 || rinfo
->panel_info
.yres
== 0) {
838 printk(KERN_WARNING
"radeonfb: Can't find panel size, going back to CRT\n");
839 rinfo
->mon1_type
= MT_CRT
;
842 printk(KERN_WARNING
"radeonfb: Assuming panel size %dx%d\n",
843 rinfo
->panel_info
.xres
, rinfo
->panel_info
.yres
);
844 modedb
= rinfo
->mon1_modedb
;
845 dbsize
= rinfo
->mon1_dbsize
;
846 snprintf(modename
, 31, "%dx%d", rinfo
->panel_info
.xres
, rinfo
->panel_info
.yres
);
847 if (fb_find_mode(&info
->var
, info
, modename
,
848 modedb
, dbsize
, NULL
, 8) == 0) {
849 printk(KERN_WARNING
"radeonfb: Can't find mode for panel size, going back to CRT\n");
850 rinfo
->mon1_type
= MT_CRT
;
853 has_default_mode
= 1;
854 radeon_var_to_panel_info(rinfo
, &info
->var
);
859 * Apply passed-in mode option if any
862 if (fb_find_mode(&info
->var
, info
, mode_option
,
863 info
->monspecs
.modedb
,
864 info
->monspecs
.modedb_len
, NULL
, 8) != 0)
865 has_default_mode
= 1;
869 * Still no mode, let's pick up a default from the db
871 if (!has_default_mode
&& info
->monspecs
.modedb
!= NULL
) {
872 struct fb_monspecs
*specs
= &info
->monspecs
;
873 struct fb_videomode
*modedb
= NULL
;
875 /* get preferred timing */
876 if (specs
->misc
& FB_MISC_1ST_DETAIL
) {
879 for (i
= 0; i
< specs
->modedb_len
; i
++) {
880 if (specs
->modedb
[i
].flag
& FB_MODE_IS_FIRST
) {
881 modedb
= &specs
->modedb
[i
];
886 /* otherwise, get first mode in database */
887 modedb
= &specs
->modedb
[0];
889 if (modedb
!= NULL
) {
890 info
->var
.bits_per_pixel
= 8;
891 radeon_videomode_to_var(&info
->var
, modedb
);
892 has_default_mode
= 1;
896 struct fb_videomode mode
;
897 /* Make sure that whatever mode got selected is actually in the
898 * modelist or the kernel may die
900 fb_var_to_videomode(&mode
, &info
->var
);
901 fb_add_videomode(&mode
, &info
->modelist
);
906 * The code below is used to pick up a mode in check_var and
907 * set_var. It should be made generic
911 * This is used when looking for modes. We assign a "distance" value
912 * to a mode in the modedb depending how "close" it is from what we
914 * Currently, we don't compare that much, we could do better but
915 * the current fbcon doesn't quite mind ;)
917 static int radeon_compare_modes(const struct fb_var_screeninfo
*var
,
918 const struct fb_videomode
*mode
)
922 distance
= mode
->yres
- var
->yres
;
923 distance
+= (mode
->xres
- var
->xres
)/2;
928 * This function is called by check_var, it gets the passed in mode parameter, and
929 * outputs a valid mode matching the passed-in one as closely as possible.
930 * We need something better ultimately. Things like fbcon basically pass us out
931 * current mode with xres/yres hacked, while things like XFree will actually
932 * produce a full timing that we should respect as much as possible.
934 * This is why I added the FB_ACTIVATE_FIND that is used by fbcon. Without this,
935 * we do a simple spec match, that's all. With it, we actually look for a mode in
936 * either our monitor modedb or the vesa one if none
939 int radeon_match_mode(struct radeonfb_info
*rinfo
,
940 struct fb_var_screeninfo
*dest
,
941 const struct fb_var_screeninfo
*src
)
943 const struct fb_videomode
*db
= vesa_modes
;
945 int has_rmx
, native_db
= 0;
946 int distance
= INT_MAX
;
947 const struct fb_videomode
*candidate
= NULL
;
949 /* Start with a copy of the requested mode */
950 memcpy(dest
, src
, sizeof(struct fb_var_screeninfo
));
952 /* Check if we have a modedb built from EDID */
953 if (rinfo
->mon1_modedb
) {
954 db
= rinfo
->mon1_modedb
;
955 dbsize
= rinfo
->mon1_dbsize
;
959 /* Check if we have a scaler allowing any fancy mode */
960 has_rmx
= rinfo
->mon1_type
== MT_LCD
|| rinfo
->mon1_type
== MT_DFP
;
962 /* If we have a scaler and are passed FB_ACTIVATE_TEST or
963 * FB_ACTIVATE_NOW, just do basic checking and return if the
966 if ((src
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_TEST
||
967 (src
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_NOW
) {
968 /* We don't have an RMX, validate timings. If we don't have
969 * monspecs, we should be paranoid and not let use go above
970 * 640x480-60, but I assume userland knows what it's doing here
971 * (though I may be proven wrong...)
973 if (has_rmx
== 0 && rinfo
->mon1_modedb
)
974 if (fb_validate_mode((struct fb_var_screeninfo
*)src
, rinfo
->info
))
979 /* Now look for a mode in the database */
981 for (i
= 0; i
< dbsize
; i
++) {
984 if (db
[i
].yres
< src
->yres
)
986 if (db
[i
].xres
< src
->xres
)
988 d
= radeon_compare_modes(src
, &db
[i
]);
989 /* If the new mode is at least as good as the previous one,
990 * then it's our new candidate
998 /* If we have a scaler, we allow any mode from the database */
999 if (native_db
&& has_rmx
) {
1006 /* If we have found a match, return it */
1007 if (candidate
!= NULL
) {
1008 radeon_videomode_to_var(dest
, candidate
);
1012 /* If we haven't and don't have a scaler, fail */