1 // SPDX-License-Identifier: GPL-2.0
4 #include <linux/slab.h>
8 static const struct fb_var_screeninfo radeonfb_default_var
= {
14 .red
= { .length
= 8 },
15 .green
= { .length
= 8 },
16 .blue
= { .length
= 8 },
17 .activate
= FB_ACTIVATE_NOW
,
27 .vmode
= FB_VMODE_NONINTERLACED
30 static char *radeon_get_mon_name(int type
)
59 #if defined(CONFIG_PPC) || defined(CONFIG_SPARC)
61 * Try to find monitor informations & EDID data out of the Open Firmware
62 * device-tree. This also contains some "hacks" to work around a few machine
63 * models with broken OF probing by hard-coding known EDIDs for some Mac
64 * laptops internal LVDS panel. (XXX: not done yet)
66 static int radeon_parse_montype_prop(struct device_node
*dp
, u8
**out_EDID
,
69 static char *propnames
[] = { "DFP,EDID", "LCD,EDID", "EDID",
70 "EDID1", "EDID2", NULL
};
71 const u8
*pedid
= NULL
;
76 pr_debug("analyzing OF properties...\n");
77 pmt
= of_get_property(dp
, "display-type", NULL
);
80 pr_debug("display-type: %s\n", pmt
);
81 /* OF says "LCD" for DFP as well, we discriminate from the caller of this
84 if (!strcmp(pmt
, "LCD") || !strcmp(pmt
, "DFP"))
86 else if (!strcmp(pmt
, "CRT"))
89 if (strcmp(pmt
, "NONE") != 0)
90 printk(KERN_WARNING
"radeonfb: Unknown OF display-type: %s\n",
95 for (i
= 0; propnames
[i
] != NULL
; ++i
) {
96 pedid
= of_get_property(dp
, propnames
[i
], NULL
);
100 /* We didn't find the EDID in the leaf node, some cards will actually
101 * put EDID1/EDID2 in the parent, look for these (typically M6 tipb).
102 * single-head cards have hdno == -1 and skip this step
104 if (pedid
== NULL
&& dp
->parent
&& (hdno
!= -1))
105 pedid
= of_get_property(dp
->parent
,
106 (hdno
== 0) ? "EDID1" : "EDID2", NULL
);
107 if (pedid
== NULL
&& dp
->parent
&& (hdno
== 0))
108 pedid
= of_get_property(dp
->parent
, "EDID", NULL
);
112 tmp
= kmemdup(pedid
, EDID_LENGTH
, GFP_KERNEL
);
119 static int radeon_probe_OF_head(struct radeonfb_info
*rinfo
, int head_no
,
122 struct device_node
*dp
;
124 pr_debug("radeon_probe_OF_head\n");
130 if (rinfo
->has_CRTC2
) {
138 pname
= of_get_property(dp
, "name", NULL
);
142 pr_debug("head: %s (letter: %c, head_no: %d)\n",
143 pname
, pname
[len
-1], head_no
);
144 if (pname
[len
-1] == 'A' && head_no
== 0) {
145 int mt
= radeon_parse_montype_prop(dp
, out_EDID
, 0);
146 /* Maybe check for LVDS_GEN_CNTL here ? I need to check out
147 * what OF does when booting with lid closed
149 if (mt
== MT_DFP
&& rinfo
->is_mobility
)
152 } else if (pname
[len
-1] == 'B' && head_no
== 1)
153 return radeon_parse_montype_prop(dp
, out_EDID
, 1);
160 return radeon_parse_montype_prop(dp
, out_EDID
, -1);
164 #endif /* CONFIG_PPC || CONFIG_SPARC */
167 static int radeon_get_panel_info_BIOS(struct radeonfb_info
*rinfo
)
169 unsigned long tmp
, tmp0
;
173 if (!rinfo
->bios_seg
)
176 if (!(tmp
= BIOS_IN16(rinfo
->fp_bios_start
+ 0x40))) {
177 printk(KERN_ERR
"radeonfb: Failed to detect DFP panel info using BIOS\n");
178 rinfo
->panel_info
.pwr_delay
= 200;
183 stmp
[i
] = BIOS_IN8(tmp
+i
+1);
185 printk("radeonfb: panel ID string: %s\n", stmp
);
186 rinfo
->panel_info
.xres
= BIOS_IN16(tmp
+ 25);
187 rinfo
->panel_info
.yres
= BIOS_IN16(tmp
+ 27);
188 printk("radeonfb: detected LVDS panel size from BIOS: %dx%d\n",
189 rinfo
->panel_info
.xres
, rinfo
->panel_info
.yres
);
191 rinfo
->panel_info
.pwr_delay
= BIOS_IN16(tmp
+ 44);
192 pr_debug("BIOS provided panel power delay: %d\n", rinfo
->panel_info
.pwr_delay
);
193 if (rinfo
->panel_info
.pwr_delay
> 2000 || rinfo
->panel_info
.pwr_delay
<= 0)
194 rinfo
->panel_info
.pwr_delay
= 2000;
197 * Some panels only work properly with some divider combinations
199 rinfo
->panel_info
.ref_divider
= BIOS_IN16(tmp
+ 46);
200 rinfo
->panel_info
.post_divider
= BIOS_IN8(tmp
+ 48);
201 rinfo
->panel_info
.fbk_divider
= BIOS_IN16(tmp
+ 49);
202 if (rinfo
->panel_info
.ref_divider
!= 0 &&
203 rinfo
->panel_info
.fbk_divider
> 3) {
204 rinfo
->panel_info
.use_bios_dividers
= 1;
205 printk(KERN_INFO
"radeondb: BIOS provided dividers will be used\n");
206 pr_debug("ref_divider = %x\n", rinfo
->panel_info
.ref_divider
);
207 pr_debug("post_divider = %x\n", rinfo
->panel_info
.post_divider
);
208 pr_debug("fbk_divider = %x\n", rinfo
->panel_info
.fbk_divider
);
210 pr_debug("Scanning BIOS table ...\n");
211 for(i
=0; i
<32; i
++) {
212 tmp0
= BIOS_IN16(tmp
+64+i
*2);
215 pr_debug(" %d x %d\n", BIOS_IN16(tmp0
), BIOS_IN16(tmp0
+2));
216 if ((BIOS_IN16(tmp0
) == rinfo
->panel_info
.xres
) &&
217 (BIOS_IN16(tmp0
+2) == rinfo
->panel_info
.yres
)) {
218 rinfo
->panel_info
.hblank
= (BIOS_IN16(tmp0
+17) - BIOS_IN16(tmp0
+19)) * 8;
219 rinfo
->panel_info
.hOver_plus
= ((BIOS_IN16(tmp0
+21) -
220 BIOS_IN16(tmp0
+19) -1) * 8) & 0x7fff;
221 rinfo
->panel_info
.hSync_width
= BIOS_IN8(tmp0
+23) * 8;
222 rinfo
->panel_info
.vblank
= BIOS_IN16(tmp0
+24) - BIOS_IN16(tmp0
+26);
223 rinfo
->panel_info
.vOver_plus
= (BIOS_IN16(tmp0
+28) & 0x7ff) - BIOS_IN16(tmp0
+26);
224 rinfo
->panel_info
.vSync_width
= (BIOS_IN16(tmp0
+28) & 0xf800) >> 11;
225 rinfo
->panel_info
.clock
= BIOS_IN16(tmp0
+9);
226 /* Assume high active syncs for now until ATI tells me more... maybe we
227 * can probe register values here ?
229 rinfo
->panel_info
.hAct_high
= 1;
230 rinfo
->panel_info
.vAct_high
= 1;
231 /* Mark panel infos valid */
232 rinfo
->panel_info
.valid
= 1;
234 pr_debug("Found panel in BIOS table:\n");
235 pr_debug(" hblank: %d\n", rinfo
->panel_info
.hblank
);
236 pr_debug(" hOver_plus: %d\n", rinfo
->panel_info
.hOver_plus
);
237 pr_debug(" hSync_width: %d\n", rinfo
->panel_info
.hSync_width
);
238 pr_debug(" vblank: %d\n", rinfo
->panel_info
.vblank
);
239 pr_debug(" vOver_plus: %d\n", rinfo
->panel_info
.vOver_plus
);
240 pr_debug(" vSync_width: %d\n", rinfo
->panel_info
.vSync_width
);
241 pr_debug(" clock: %d\n", rinfo
->panel_info
.clock
);
246 pr_debug("Didn't find panel in BIOS table !\n");
251 /* Try to extract the connector informations from the BIOS. This
252 * doesn't quite work yet, but it's output is still useful for
255 static void radeon_parse_connector_info(struct radeonfb_info
*rinfo
)
257 int offset
, chips
, connectors
, tmp
, i
, conn
, type
;
259 static char* __conn_type_table
[16] = {
260 "NONE", "Proprietary", "CRT", "DVI-I", "DVI-D", "Unknown", "Unknown",
261 "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown",
262 "Unknown", "Unknown", "Unknown"
265 if (!rinfo
->bios_seg
)
268 offset
= BIOS_IN16(rinfo
->fp_bios_start
+ 0x50);
270 printk(KERN_WARNING
"radeonfb: No connector info table detected\n");
274 /* Don't do much more at this point but displaying the data if
277 chips
= BIOS_IN8(offset
++) >> 4;
278 pr_debug("%d chips in connector info\n", chips
);
279 for (i
= 0; i
< chips
; i
++) {
280 tmp
= BIOS_IN8(offset
++);
281 connectors
= tmp
& 0x0f;
282 pr_debug(" - chip %d has %d connectors\n", tmp
>> 4, connectors
);
283 for (conn
= 0; ; conn
++) {
284 tmp
= BIOS_IN16(offset
);
288 type
= (tmp
>> 12) & 0x0f;
289 pr_debug(" * connector %d of type %d (%s) : %04x\n",
290 conn
, type
, __conn_type_table
[type
], tmp
);
297 * Probe physical connection of a CRT. This code comes from XFree
298 * as well and currently is only implemented for the CRT DAC, the
299 * code for the TVDAC is commented out in XFree as "non working"
301 static int radeon_crt_is_connected(struct radeonfb_info
*rinfo
, int is_crt_dac
)
305 /* the monitor either wasn't connected or it is a non-DDC CRT.
309 unsigned long ulOrigVCLK_ECP_CNTL
;
310 unsigned long ulOrigDAC_CNTL
;
311 unsigned long ulOrigDAC_EXT_CNTL
;
312 unsigned long ulOrigCRTC_EXT_CNTL
;
313 unsigned long ulData
;
314 unsigned long ulMask
;
316 ulOrigVCLK_ECP_CNTL
= INPLL(VCLK_ECP_CNTL
);
318 ulData
= ulOrigVCLK_ECP_CNTL
;
319 ulData
&= ~(PIXCLK_ALWAYS_ONb
320 | PIXCLK_DAC_ALWAYS_ONb
);
321 ulMask
= ~(PIXCLK_ALWAYS_ONb
322 | PIXCLK_DAC_ALWAYS_ONb
);
323 OUTPLLP(VCLK_ECP_CNTL
, ulData
, ulMask
);
325 ulOrigCRTC_EXT_CNTL
= INREG(CRTC_EXT_CNTL
);
326 ulData
= ulOrigCRTC_EXT_CNTL
;
327 ulData
|= CRTC_CRT_ON
;
328 OUTREG(CRTC_EXT_CNTL
, ulData
);
330 ulOrigDAC_EXT_CNTL
= INREG(DAC_EXT_CNTL
);
331 ulData
= ulOrigDAC_EXT_CNTL
;
332 ulData
&= ~DAC_FORCE_DATA_MASK
;
333 ulData
|= (DAC_FORCE_BLANK_OFF_EN
335 |DAC_FORCE_DATA_SEL_MASK
);
336 if ((rinfo
->family
== CHIP_FAMILY_RV250
) ||
337 (rinfo
->family
== CHIP_FAMILY_RV280
))
338 ulData
|= (0x01b6 << DAC_FORCE_DATA_SHIFT
);
340 ulData
|= (0x01ac << DAC_FORCE_DATA_SHIFT
);
342 OUTREG(DAC_EXT_CNTL
, ulData
);
344 ulOrigDAC_CNTL
= INREG(DAC_CNTL
);
345 ulData
= ulOrigDAC_CNTL
;
346 ulData
|= DAC_CMP_EN
;
347 ulData
&= ~(DAC_RANGE_CNTL_MASK
350 OUTREG(DAC_CNTL
, ulData
);
354 ulData
= INREG(DAC_CNTL
);
355 connected
= (DAC_CMP_OUTPUT
& ulData
) ? 1 : 0;
357 ulData
= ulOrigVCLK_ECP_CNTL
;
358 ulMask
= 0xFFFFFFFFL
;
359 OUTPLLP(VCLK_ECP_CNTL
, ulData
, ulMask
);
361 OUTREG(DAC_CNTL
, ulOrigDAC_CNTL
);
362 OUTREG(DAC_EXT_CNTL
, ulOrigDAC_EXT_CNTL
);
363 OUTREG(CRTC_EXT_CNTL
, ulOrigCRTC_EXT_CNTL
);
366 return connected
? MT_CRT
: MT_NONE
;
370 * Parse the "monitor_layout" string if any. This code is mostly
371 * copied from XFree's radeon driver
373 static int radeon_parse_monitor_layout(struct radeonfb_info
*rinfo
,
374 const char *monitor_layout
)
377 int i
= 0, second
= 0;
414 if (strcmp(s1
, "CRT") == 0)
415 rinfo
->mon1_type
= MT_CRT
;
416 else if (strcmp(s1
, "TMDS") == 0)
417 rinfo
->mon1_type
= MT_DFP
;
418 else if (strcmp(s1
, "LVDS") == 0)
419 rinfo
->mon1_type
= MT_LCD
;
421 if (strcmp(s2
, "CRT") == 0)
422 rinfo
->mon2_type
= MT_CRT
;
423 else if (strcmp(s2
, "TMDS") == 0)
424 rinfo
->mon2_type
= MT_DFP
;
425 else if (strcmp(s2
, "LVDS") == 0)
426 rinfo
->mon2_type
= MT_LCD
;
432 * Probe display on both primary and secondary card's connector (if any)
433 * by various available techniques (i2c, OF device tree, BIOS, ...) and
434 * try to retrieve EDID. The algorithm here comes from XFree's radeon
437 void radeon_probe_screens(struct radeonfb_info
*rinfo
,
438 const char *monitor_layout
, int ignore_edid
)
440 #ifdef CONFIG_FB_RADEON_I2C
441 int ddc_crt2_used
= 0;
445 radeon_parse_connector_info(rinfo
);
447 if (radeon_parse_monitor_layout(rinfo
, monitor_layout
)) {
450 * If user specified a monitor_layout option, use it instead
451 * of auto-detecting. Maybe we should only use this argument
452 * on the first radeon card probed or provide a way to specify
453 * a layout for each card ?
456 pr_debug("Using specified monitor layout: %s", monitor_layout
);
457 #ifdef CONFIG_FB_RADEON_I2C
459 if (rinfo
->mon1_type
!= MT_NONE
)
460 if (!radeon_probe_i2c_connector(rinfo
, ddc_dvi
, &rinfo
->mon1_EDID
)) {
461 radeon_probe_i2c_connector(rinfo
, ddc_crt2
, &rinfo
->mon1_EDID
);
464 if (rinfo
->mon2_type
!= MT_NONE
)
465 if (!radeon_probe_i2c_connector(rinfo
, ddc_vga
, &rinfo
->mon2_EDID
) &&
467 radeon_probe_i2c_connector(rinfo
, ddc_crt2
, &rinfo
->mon2_EDID
);
469 #endif /* CONFIG_FB_RADEON_I2C */
470 if (rinfo
->mon1_type
== MT_NONE
) {
471 if (rinfo
->mon2_type
!= MT_NONE
) {
472 rinfo
->mon1_type
= rinfo
->mon2_type
;
473 rinfo
->mon1_EDID
= rinfo
->mon2_EDID
;
475 rinfo
->mon1_type
= MT_CRT
;
476 printk(KERN_INFO
"radeonfb: No valid monitor, assuming CRT on first port\n");
478 rinfo
->mon2_type
= MT_NONE
;
479 rinfo
->mon2_EDID
= NULL
;
483 * Auto-detecting display type (well... trying to ...)
486 pr_debug("Starting monitor auto detection...\n");
488 #if defined(DEBUG) && defined(CONFIG_FB_RADEON_I2C)
490 u8
*EDIDs
[4] = { NULL
, NULL
, NULL
, NULL
};
491 int mon_types
[4] = {MT_NONE
, MT_NONE
, MT_NONE
, MT_NONE
};
494 for (i
= 0; i
< 4; i
++)
495 mon_types
[i
] = radeon_probe_i2c_connector(rinfo
,
500 * Old single head cards
502 if (!rinfo
->has_CRTC2
) {
503 #if defined(CONFIG_PPC) || defined(CONFIG_SPARC)
504 if (rinfo
->mon1_type
== MT_NONE
)
505 rinfo
->mon1_type
= radeon_probe_OF_head(rinfo
, 0,
507 #endif /* CONFIG_PPC || CONFIG_SPARC */
508 #ifdef CONFIG_FB_RADEON_I2C
509 if (rinfo
->mon1_type
== MT_NONE
)
511 radeon_probe_i2c_connector(rinfo
, ddc_dvi
,
513 if (rinfo
->mon1_type
== MT_NONE
)
515 radeon_probe_i2c_connector(rinfo
, ddc_vga
,
517 if (rinfo
->mon1_type
== MT_NONE
)
519 radeon_probe_i2c_connector(rinfo
, ddc_crt2
,
521 #endif /* CONFIG_FB_RADEON_I2C */
522 if (rinfo
->mon1_type
== MT_NONE
)
523 rinfo
->mon1_type
= MT_CRT
;
528 * Check for cards with reversed DACs or TMDS controllers using BIOS
530 if (rinfo
->bios_seg
&&
531 (tmp
= BIOS_IN16(rinfo
->fp_bios_start
+ 0x50))) {
532 for (i
= 1; i
< 4; i
++) {
535 if (!BIOS_IN8(tmp
+ i
*2) && i
> 1)
537 tmp0
= BIOS_IN16(tmp
+ i
*2);
538 if ((!(tmp0
& 0x01)) && (((tmp0
>> 8) & 0x0f) == ddc_dvi
)) {
539 rinfo
->reversed_DAC
= 1;
540 printk(KERN_INFO
"radeonfb: Reversed DACs detected\n");
542 if ((((tmp0
>> 8) & 0x0f) == ddc_dvi
) && ((tmp0
>> 4) & 0x01)) {
543 rinfo
->reversed_TMDS
= 1;
544 printk(KERN_INFO
"radeonfb: Reversed TMDS detected\n");
550 * Probe primary head (DVI or laptop internal panel)
552 #if defined(CONFIG_PPC) || defined(CONFIG_SPARC)
553 if (rinfo
->mon1_type
== MT_NONE
)
554 rinfo
->mon1_type
= radeon_probe_OF_head(rinfo
, 0,
556 #endif /* CONFIG_PPC || CONFIG_SPARC */
557 #ifdef CONFIG_FB_RADEON_I2C
558 if (rinfo
->mon1_type
== MT_NONE
)
559 rinfo
->mon1_type
= radeon_probe_i2c_connector(rinfo
, ddc_dvi
,
561 if (rinfo
->mon1_type
== MT_NONE
) {
562 rinfo
->mon1_type
= radeon_probe_i2c_connector(rinfo
, ddc_crt2
,
564 if (rinfo
->mon1_type
!= MT_NONE
)
567 #endif /* CONFIG_FB_RADEON_I2C */
568 if (rinfo
->mon1_type
== MT_NONE
&& rinfo
->is_mobility
&&
569 ((rinfo
->bios_seg
&& (INREG(BIOS_4_SCRATCH
) & 4))
570 || (INREG(LVDS_GEN_CNTL
) & LVDS_ON
))) {
571 rinfo
->mon1_type
= MT_LCD
;
572 printk("Non-DDC laptop panel detected\n");
574 if (rinfo
->mon1_type
== MT_NONE
)
575 rinfo
->mon1_type
= radeon_crt_is_connected(rinfo
, rinfo
->reversed_DAC
);
578 * Probe secondary head (mostly VGA, can be DVI)
580 #if defined(CONFIG_PPC) || defined(CONFIG_SPARC)
581 if (rinfo
->mon2_type
== MT_NONE
)
582 rinfo
->mon2_type
= radeon_probe_OF_head(rinfo
, 1,
584 #endif /* CONFIG_PPC || defined(CONFIG_SPARC) */
585 #ifdef CONFIG_FB_RADEON_I2C
586 if (rinfo
->mon2_type
== MT_NONE
)
587 rinfo
->mon2_type
= radeon_probe_i2c_connector(rinfo
, ddc_vga
,
589 if (rinfo
->mon2_type
== MT_NONE
&& !ddc_crt2_used
)
590 rinfo
->mon2_type
= radeon_probe_i2c_connector(rinfo
, ddc_crt2
,
592 #endif /* CONFIG_FB_RADEON_I2C */
593 if (rinfo
->mon2_type
== MT_NONE
)
594 rinfo
->mon2_type
= radeon_crt_is_connected(rinfo
, !rinfo
->reversed_DAC
);
597 * If we only detected port 2, we swap them, if none detected,
598 * assume CRT (maybe fallback to old BIOS_SCRATCH stuff ? or look
601 if (rinfo
->mon1_type
== MT_NONE
) {
602 if (rinfo
->mon2_type
!= MT_NONE
) {
603 rinfo
->mon1_type
= rinfo
->mon2_type
;
604 rinfo
->mon1_EDID
= rinfo
->mon2_EDID
;
606 rinfo
->mon1_type
= MT_CRT
;
607 rinfo
->mon2_type
= MT_NONE
;
608 rinfo
->mon2_EDID
= NULL
;
612 * Deal with reversed TMDS
614 if (rinfo
->reversed_TMDS
) {
615 /* Always keep internal TMDS as primary head */
616 if (rinfo
->mon1_type
== MT_DFP
|| rinfo
->mon2_type
== MT_DFP
) {
617 int tmp_type
= rinfo
->mon1_type
;
618 u8
*tmp_EDID
= rinfo
->mon1_EDID
;
619 rinfo
->mon1_type
= rinfo
->mon2_type
;
620 rinfo
->mon1_EDID
= rinfo
->mon2_EDID
;
621 rinfo
->mon2_type
= tmp_type
;
622 rinfo
->mon2_EDID
= tmp_EDID
;
623 if (rinfo
->mon1_type
== MT_CRT
|| rinfo
->mon2_type
== MT_CRT
)
624 rinfo
->reversed_DAC
^= 1;
629 kfree(rinfo
->mon1_EDID
);
630 rinfo
->mon1_EDID
= NULL
;
631 kfree(rinfo
->mon2_EDID
);
632 rinfo
->mon2_EDID
= NULL
;
636 printk(KERN_INFO
"radeonfb: Monitor 1 type %s found\n",
637 radeon_get_mon_name(rinfo
->mon1_type
));
638 if (rinfo
->mon1_EDID
)
639 printk(KERN_INFO
"radeonfb: EDID probed\n");
640 if (!rinfo
->has_CRTC2
)
642 printk(KERN_INFO
"radeonfb: Monitor 2 type %s found\n",
643 radeon_get_mon_name(rinfo
->mon2_type
));
644 if (rinfo
->mon2_EDID
)
645 printk(KERN_INFO
"radeonfb: EDID probed\n");
650 * This function applies any arch/model/machine specific fixups
651 * to the panel info. It may eventually alter EDID block as
652 * well or whatever is specific to a given model and not probed
653 * properly by the default code
655 static void radeon_fixup_panel_info(struct radeonfb_info
*rinfo
)
659 * LCD Flat panels should use fixed dividers, we enfore that on
660 * PPC only for now...
662 if (!rinfo
->panel_info
.use_bios_dividers
&& rinfo
->mon1_type
== MT_LCD
663 && rinfo
->is_mobility
) {
666 ppll_div_sel
= INREG8(CLOCK_CNTL_INDEX
+ 1) & 0x3;
667 radeon_pll_errata_after_index(rinfo
);
668 ppll_divn
= INPLL(PPLL_DIV_0
+ ppll_div_sel
);
669 rinfo
->panel_info
.ref_divider
= rinfo
->pll
.ref_div
;
670 rinfo
->panel_info
.fbk_divider
= ppll_divn
& 0x7ff;
671 rinfo
->panel_info
.post_divider
= (ppll_divn
>> 16) & 0x7;
672 rinfo
->panel_info
.use_bios_dividers
= 1;
674 printk(KERN_DEBUG
"radeonfb: Using Firmware dividers 0x%08x "
676 rinfo
->panel_info
.fbk_divider
|
677 (rinfo
->panel_info
.post_divider
<< 16),
680 #endif /* CONFIG_PPC */
685 * Fill up panel infos from a mode definition, either returned by the EDID
686 * or from the default mode when we can't do any better
688 static void radeon_var_to_panel_info(struct radeonfb_info
*rinfo
, struct fb_var_screeninfo
*var
)
690 rinfo
->panel_info
.xres
= var
->xres
;
691 rinfo
->panel_info
.yres
= var
->yres
;
692 rinfo
->panel_info
.clock
= 100000000 / var
->pixclock
;
693 rinfo
->panel_info
.hOver_plus
= var
->right_margin
;
694 rinfo
->panel_info
.hSync_width
= var
->hsync_len
;
695 rinfo
->panel_info
.hblank
= var
->left_margin
+
696 (var
->right_margin
+ var
->hsync_len
);
697 rinfo
->panel_info
.vOver_plus
= var
->lower_margin
;
698 rinfo
->panel_info
.vSync_width
= var
->vsync_len
;
699 rinfo
->panel_info
.vblank
= var
->upper_margin
+
700 (var
->lower_margin
+ var
->vsync_len
);
701 rinfo
->panel_info
.hAct_high
=
702 (var
->sync
& FB_SYNC_HOR_HIGH_ACT
) != 0;
703 rinfo
->panel_info
.vAct_high
=
704 (var
->sync
& FB_SYNC_VERT_HIGH_ACT
) != 0;
705 rinfo
->panel_info
.valid
= 1;
706 /* We use a default of 200ms for the panel power delay,
707 * I need to have a real schedule() instead of mdelay's in the panel code.
708 * we might be possible to figure out a better power delay either from
709 * MacOS OF tree or from the EDID block (proprietary extensions ?)
711 rinfo
->panel_info
.pwr_delay
= 200;
714 static void radeon_videomode_to_var(struct fb_var_screeninfo
*var
,
715 const struct fb_videomode
*mode
)
717 var
->xres
= mode
->xres
;
718 var
->yres
= mode
->yres
;
719 var
->xres_virtual
= mode
->xres
;
720 var
->yres_virtual
= mode
->yres
;
723 var
->pixclock
= mode
->pixclock
;
724 var
->left_margin
= mode
->left_margin
;
725 var
->right_margin
= mode
->right_margin
;
726 var
->upper_margin
= mode
->upper_margin
;
727 var
->lower_margin
= mode
->lower_margin
;
728 var
->hsync_len
= mode
->hsync_len
;
729 var
->vsync_len
= mode
->vsync_len
;
730 var
->sync
= mode
->sync
;
731 var
->vmode
= mode
->vmode
;
734 #ifdef CONFIG_PPC_PSERIES
735 static int is_powerblade(const char *model
)
737 struct device_node
*root
;
741 root
= of_find_node_by_path("/");
744 cp
= of_get_property(root
, "model", &len
);
746 rc
= memcmp(model
, cp
, min(len
, l
)) == 0;
754 * Build the modedb for head 1 (head 2 will come later), check panel infos
755 * from either BIOS or EDID, and pick up the default mode
757 void radeon_check_modes(struct radeonfb_info
*rinfo
, const char *mode_option
)
759 struct fb_info
* info
= rinfo
->info
;
760 int has_default_mode
= 0;
763 * Fill default var first
765 info
->var
= radeonfb_default_var
;
766 INIT_LIST_HEAD(&info
->modelist
);
769 * First check out what BIOS has to say
771 if (rinfo
->mon1_type
== MT_LCD
)
772 radeon_get_panel_info_BIOS(rinfo
);
775 * Parse EDID detailed timings and deduce panel infos if any. Right now
776 * we only deal with first entry returned by parse_EDID, we may do better
779 if (!rinfo
->panel_info
.use_bios_dividers
&& rinfo
->mon1_type
!= MT_CRT
780 && rinfo
->mon1_EDID
) {
781 struct fb_var_screeninfo var
;
782 pr_debug("Parsing EDID data for panel info\n");
783 if (fb_parse_edid(rinfo
->mon1_EDID
, &var
) == 0) {
784 if (var
.xres
>= rinfo
->panel_info
.xres
&&
785 var
.yres
>= rinfo
->panel_info
.yres
)
786 radeon_var_to_panel_info(rinfo
, &var
);
791 * Do any additional platform/arch fixups to the panel infos
793 radeon_fixup_panel_info(rinfo
);
796 * If we have some valid panel infos, we setup the default mode based on
799 if (rinfo
->mon1_type
!= MT_CRT
&& rinfo
->panel_info
.valid
) {
800 struct fb_var_screeninfo
*var
= &info
->var
;
802 pr_debug("Setting up default mode based on panel info\n");
803 var
->xres
= rinfo
->panel_info
.xres
;
804 var
->yres
= rinfo
->panel_info
.yres
;
805 var
->xres_virtual
= rinfo
->panel_info
.xres
;
806 var
->yres_virtual
= rinfo
->panel_info
.yres
;
807 var
->xoffset
= var
->yoffset
= 0;
808 var
->bits_per_pixel
= 8;
809 var
->pixclock
= 100000000 / rinfo
->panel_info
.clock
;
810 var
->left_margin
= (rinfo
->panel_info
.hblank
- rinfo
->panel_info
.hOver_plus
811 - rinfo
->panel_info
.hSync_width
);
812 var
->right_margin
= rinfo
->panel_info
.hOver_plus
;
813 var
->upper_margin
= (rinfo
->panel_info
.vblank
- rinfo
->panel_info
.vOver_plus
814 - rinfo
->panel_info
.vSync_width
);
815 var
->lower_margin
= rinfo
->panel_info
.vOver_plus
;
816 var
->hsync_len
= rinfo
->panel_info
.hSync_width
;
817 var
->vsync_len
= rinfo
->panel_info
.vSync_width
;
819 if (rinfo
->panel_info
.hAct_high
)
820 var
->sync
|= FB_SYNC_HOR_HIGH_ACT
;
821 if (rinfo
->panel_info
.vAct_high
)
822 var
->sync
|= FB_SYNC_VERT_HIGH_ACT
;
824 has_default_mode
= 1;
828 * Now build modedb from EDID
830 if (rinfo
->mon1_EDID
) {
831 fb_edid_to_monspecs(rinfo
->mon1_EDID
, &info
->monspecs
);
832 fb_videomode_to_modelist(info
->monspecs
.modedb
,
833 info
->monspecs
.modedb_len
,
835 rinfo
->mon1_modedb
= info
->monspecs
.modedb
;
836 rinfo
->mon1_dbsize
= info
->monspecs
.modedb_len
;
841 * Finally, if we don't have panel infos we need to figure some (or
842 * we try to read it from card), we try to pick a default mode
843 * and create some panel infos. Whatever...
845 if (rinfo
->mon1_type
!= MT_CRT
&& !rinfo
->panel_info
.valid
) {
846 struct fb_videomode
*modedb
;
850 pr_debug("Guessing panel info...\n");
851 if (rinfo
->panel_info
.xres
== 0 || rinfo
->panel_info
.yres
== 0) {
852 u32 tmp
= INREG(FP_HORZ_STRETCH
) & HORZ_PANEL_SIZE
;
853 rinfo
->panel_info
.xres
= ((tmp
>> HORZ_PANEL_SHIFT
) + 1) * 8;
854 tmp
= INREG(FP_VERT_STRETCH
) & VERT_PANEL_SIZE
;
855 rinfo
->panel_info
.yres
= (tmp
>> VERT_PANEL_SHIFT
) + 1;
857 if (rinfo
->panel_info
.xres
== 0 || rinfo
->panel_info
.yres
== 0) {
858 printk(KERN_WARNING
"radeonfb: Can't find panel size, going back to CRT\n");
859 rinfo
->mon1_type
= MT_CRT
;
862 printk(KERN_WARNING
"radeonfb: Assuming panel size %dx%d\n",
863 rinfo
->panel_info
.xres
, rinfo
->panel_info
.yres
);
864 modedb
= rinfo
->mon1_modedb
;
865 dbsize
= rinfo
->mon1_dbsize
;
866 snprintf(modename
, 31, "%dx%d", rinfo
->panel_info
.xres
, rinfo
->panel_info
.yres
);
867 if (fb_find_mode(&info
->var
, info
, modename
,
868 modedb
, dbsize
, NULL
, 8) == 0) {
869 printk(KERN_WARNING
"radeonfb: Can't find mode for panel size, going back to CRT\n");
870 rinfo
->mon1_type
= MT_CRT
;
873 has_default_mode
= 1;
874 radeon_var_to_panel_info(rinfo
, &info
->var
);
879 * Apply passed-in mode option if any
882 if (fb_find_mode(&info
->var
, info
, mode_option
,
883 info
->monspecs
.modedb
,
884 info
->monspecs
.modedb_len
, NULL
, 8) != 0)
885 has_default_mode
= 1;
888 #ifdef CONFIG_PPC_PSERIES
889 if (!has_default_mode
&& (
890 is_powerblade("IBM,8842") || /* JS20 */
891 is_powerblade("IBM,8844") || /* JS21 */
892 is_powerblade("IBM,7998") || /* JS12/JS21/JS22 */
893 is_powerblade("IBM,0792") || /* QS21 */
894 is_powerblade("IBM,0793") /* QS22 */
896 printk("Falling back to 800x600 on JSxx hardware\n");
897 if (fb_find_mode(&info
->var
, info
, "800x600@60",
898 info
->monspecs
.modedb
,
899 info
->monspecs
.modedb_len
, NULL
, 8) != 0)
900 has_default_mode
= 1;
905 * Still no mode, let's pick up a default from the db
907 if (!has_default_mode
&& info
->monspecs
.modedb
!= NULL
) {
908 struct fb_monspecs
*specs
= &info
->monspecs
;
909 struct fb_videomode
*modedb
= NULL
;
911 /* get preferred timing */
912 if (specs
->misc
& FB_MISC_1ST_DETAIL
) {
915 for (i
= 0; i
< specs
->modedb_len
; i
++) {
916 if (specs
->modedb
[i
].flag
& FB_MODE_IS_FIRST
) {
917 modedb
= &specs
->modedb
[i
];
922 /* otherwise, get first mode in database */
923 modedb
= &specs
->modedb
[0];
925 if (modedb
!= NULL
) {
926 info
->var
.bits_per_pixel
= 8;
927 radeon_videomode_to_var(&info
->var
, modedb
);
928 has_default_mode
= 1;
932 struct fb_videomode mode
;
933 /* Make sure that whatever mode got selected is actually in the
934 * modelist or the kernel may die
936 fb_var_to_videomode(&mode
, &info
->var
);
937 fb_add_videomode(&mode
, &info
->modelist
);
942 * The code below is used to pick up a mode in check_var and
943 * set_var. It should be made generic
947 * This is used when looking for modes. We assign a "distance" value
948 * to a mode in the modedb depending how "close" it is from what we
950 * Currently, we don't compare that much, we could do better but
951 * the current fbcon doesn't quite mind ;)
953 static int radeon_compare_modes(const struct fb_var_screeninfo
*var
,
954 const struct fb_videomode
*mode
)
958 distance
= mode
->yres
- var
->yres
;
959 distance
+= (mode
->xres
- var
->xres
)/2;
964 * This function is called by check_var, it gets the passed in mode parameter, and
965 * outputs a valid mode matching the passed-in one as closely as possible.
966 * We need something better ultimately. Things like fbcon basically pass us out
967 * current mode with xres/yres hacked, while things like XFree will actually
968 * produce a full timing that we should respect as much as possible.
970 * This is why I added the FB_ACTIVATE_FIND that is used by fbcon. Without this,
971 * we do a simple spec match, that's all. With it, we actually look for a mode in
972 * either our monitor modedb or the vesa one if none
975 int radeon_match_mode(struct radeonfb_info
*rinfo
,
976 struct fb_var_screeninfo
*dest
,
977 const struct fb_var_screeninfo
*src
)
979 const struct fb_videomode
*db
= vesa_modes
;
981 int has_rmx
, native_db
= 0;
982 int distance
= INT_MAX
;
983 const struct fb_videomode
*candidate
= NULL
;
985 /* Start with a copy of the requested mode */
986 memcpy(dest
, src
, sizeof(struct fb_var_screeninfo
));
988 /* Check if we have a modedb built from EDID */
989 if (rinfo
->mon1_modedb
) {
990 db
= rinfo
->mon1_modedb
;
991 dbsize
= rinfo
->mon1_dbsize
;
995 /* Check if we have a scaler allowing any fancy mode */
996 has_rmx
= rinfo
->mon1_type
== MT_LCD
|| rinfo
->mon1_type
== MT_DFP
;
998 /* If we have a scaler and are passed FB_ACTIVATE_TEST or
999 * FB_ACTIVATE_NOW, just do basic checking and return if the
1002 if ((src
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_TEST
||
1003 (src
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_NOW
) {
1004 /* We don't have an RMX, validate timings. If we don't have
1005 * monspecs, we should be paranoid and not let use go above
1006 * 640x480-60, but I assume userland knows what it's doing here
1007 * (though I may be proven wrong...)
1009 if (has_rmx
== 0 && rinfo
->mon1_modedb
)
1010 if (fb_validate_mode((struct fb_var_screeninfo
*)src
, rinfo
->info
))
1015 /* Now look for a mode in the database */
1017 for (i
= 0; i
< dbsize
; i
++) {
1020 if (db
[i
].yres
< src
->yres
)
1022 if (db
[i
].xres
< src
->xres
)
1024 d
= radeon_compare_modes(src
, &db
[i
]);
1025 /* If the new mode is at least as good as the previous one,
1026 * then it's our new candidate
1034 /* If we have a scaler, we allow any mode from the database */
1035 if (native_db
&& has_rmx
) {
1042 /* If we have found a match, return it */
1043 if (candidate
!= NULL
) {
1044 radeon_videomode_to_var(dest
, candidate
);
1048 /* If we haven't and don't have a scaler, fail */