This source file includes following definitions.
- radeon_get_mon_name
- radeon_parse_montype_prop
- radeon_probe_OF_head
- radeon_get_panel_info_BIOS
- radeon_parse_connector_info
- radeon_crt_is_connected
- radeon_parse_monitor_layout
- radeon_probe_screens
- radeon_fixup_panel_info
- radeon_var_to_panel_info
- radeon_videomode_to_var
- is_powerblade
- radeon_check_modes
- radeon_compare_modes
- radeon_match_mode
1
2 #include "radeonfb.h"
3
4 #include <linux/slab.h>
5
6 #include "../edid.h"
7
8 static const struct fb_var_screeninfo radeonfb_default_var = {
9 .xres = 640,
10 .yres = 480,
11 .xres_virtual = 640,
12 .yres_virtual = 480,
13 .bits_per_pixel = 8,
14 .red = { .length = 8 },
15 .green = { .length = 8 },
16 .blue = { .length = 8 },
17 .activate = FB_ACTIVATE_NOW,
18 .height = -1,
19 .width = -1,
20 .pixclock = 39721,
21 .left_margin = 40,
22 .right_margin = 24,
23 .upper_margin = 32,
24 .lower_margin = 11,
25 .hsync_len = 96,
26 .vsync_len = 2,
27 .vmode = FB_VMODE_NONINTERLACED
28 };
29
30 static char *radeon_get_mon_name(int type)
31 {
32 char *pret = NULL;
33
34 switch (type) {
35 case MT_NONE:
36 pret = "no";
37 break;
38 case MT_CRT:
39 pret = "CRT";
40 break;
41 case MT_DFP:
42 pret = "DFP";
43 break;
44 case MT_LCD:
45 pret = "LCD";
46 break;
47 case MT_CTV:
48 pret = "CTV";
49 break;
50 case MT_STV:
51 pret = "STV";
52 break;
53 }
54
55 return pret;
56 }
57
58
59 #if defined(CONFIG_PPC) || defined(CONFIG_SPARC)
60
61
62
63
64
65
66 static int radeon_parse_montype_prop(struct device_node *dp, u8 **out_EDID,
67 int hdno)
68 {
69 static char *propnames[] = { "DFP,EDID", "LCD,EDID", "EDID",
70 "EDID1", "EDID2", NULL };
71 const u8 *pedid = NULL;
72 const u8 *pmt = NULL;
73 u8 *tmp;
74 int i, mt = MT_NONE;
75
76 pr_debug("analyzing OF properties...\n");
77 pmt = of_get_property(dp, "display-type", NULL);
78 if (!pmt)
79 return MT_NONE;
80 pr_debug("display-type: %s\n", pmt);
81
82
83
84 if (!strcmp(pmt, "LCD") || !strcmp(pmt, "DFP"))
85 mt = MT_DFP;
86 else if (!strcmp(pmt, "CRT"))
87 mt = MT_CRT;
88 else {
89 if (strcmp(pmt, "NONE") != 0)
90 printk(KERN_WARNING "radeonfb: Unknown OF display-type: %s\n",
91 pmt);
92 return MT_NONE;
93 }
94
95 for (i = 0; propnames[i] != NULL; ++i) {
96 pedid = of_get_property(dp, propnames[i], NULL);
97 if (pedid != NULL)
98 break;
99 }
100
101
102
103
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);
109 if (pedid == NULL)
110 return mt;
111
112 tmp = kmemdup(pedid, EDID_LENGTH, GFP_KERNEL);
113 if (!tmp)
114 return mt;
115 *out_EDID = tmp;
116 return mt;
117 }
118
119 static int radeon_probe_OF_head(struct radeonfb_info *rinfo, int head_no,
120 u8 **out_EDID)
121 {
122 struct device_node *dp;
123
124 pr_debug("radeon_probe_OF_head\n");
125
126 dp = rinfo->of_node;
127 while (dp == NULL)
128 return MT_NONE;
129
130 if (rinfo->has_CRTC2) {
131 const char *pname;
132 int len, second = 0;
133
134 dp = dp->child;
135 do {
136 if (!dp)
137 return MT_NONE;
138 pname = of_get_property(dp, "name", NULL);
139 if (!pname)
140 return MT_NONE;
141 len = strlen(pname);
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
147
148
149 if (mt == MT_DFP && rinfo->is_mobility)
150 mt = MT_LCD;
151 return mt;
152 } else if (pname[len-1] == 'B' && head_no == 1)
153 return radeon_parse_montype_prop(dp, out_EDID, 1);
154 second = 1;
155 dp = dp->sibling;
156 } while(!second);
157 } else {
158 if (head_no > 0)
159 return MT_NONE;
160 return radeon_parse_montype_prop(dp, out_EDID, -1);
161 }
162 return MT_NONE;
163 }
164 #endif
165
166
167 static int radeon_get_panel_info_BIOS(struct radeonfb_info *rinfo)
168 {
169 unsigned long tmp, tmp0;
170 char stmp[30];
171 int i;
172
173 if (!rinfo->bios_seg)
174 return 0;
175
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;
179 return 0;
180 }
181
182 for(i=0; i<24; i++)
183 stmp[i] = BIOS_IN8(tmp+i+1);
184 stmp[24] = 0;
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);
190
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;
195
196
197
198
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);
209 }
210 pr_debug("Scanning BIOS table ...\n");
211 for(i=0; i<32; i++) {
212 tmp0 = BIOS_IN16(tmp+64+i*2);
213 if (tmp0 == 0)
214 break;
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
227
228
229 rinfo->panel_info.hAct_high = 1;
230 rinfo->panel_info.vAct_high = 1;
231
232 rinfo->panel_info.valid = 1;
233
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);
242
243 return 1;
244 }
245 }
246 pr_debug("Didn't find panel in BIOS table !\n");
247
248 return 0;
249 }
250
251
252
253
254
255 static void radeon_parse_connector_info(struct radeonfb_info *rinfo)
256 {
257 int offset, chips, connectors, tmp, i, conn, type;
258
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"
263 };
264
265 if (!rinfo->bios_seg)
266 return;
267
268 offset = BIOS_IN16(rinfo->fp_bios_start + 0x50);
269 if (offset == 0) {
270 printk(KERN_WARNING "radeonfb: No connector info table detected\n");
271 return;
272 }
273
274
275
276
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);
285 if (tmp == 0)
286 break;
287 offset += 2;
288 type = (tmp >> 12) & 0x0f;
289 pr_debug(" * connector %d of type %d (%s) : %04x\n",
290 conn, type, __conn_type_table[type], tmp);
291 }
292 }
293 }
294
295
296
297
298
299
300
301 static int radeon_crt_is_connected(struct radeonfb_info *rinfo, int is_crt_dac)
302 {
303 int connected = 0;
304
305
306
307
308 if (is_crt_dac) {
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;
315
316 ulOrigVCLK_ECP_CNTL = INPLL(VCLK_ECP_CNTL);
317
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);
324
325 ulOrigCRTC_EXT_CNTL = INREG(CRTC_EXT_CNTL);
326 ulData = ulOrigCRTC_EXT_CNTL;
327 ulData |= CRTC_CRT_ON;
328 OUTREG(CRTC_EXT_CNTL, ulData);
329
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
334 |DAC_FORCE_DATA_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);
339 else
340 ulData |= (0x01ac << DAC_FORCE_DATA_SHIFT);
341
342 OUTREG(DAC_EXT_CNTL, ulData);
343
344 ulOrigDAC_CNTL = INREG(DAC_CNTL);
345 ulData = ulOrigDAC_CNTL;
346 ulData |= DAC_CMP_EN;
347 ulData &= ~(DAC_RANGE_CNTL_MASK
348 | DAC_PDWN);
349 ulData |= 0x2;
350 OUTREG(DAC_CNTL, ulData);
351
352 mdelay(1);
353
354 ulData = INREG(DAC_CNTL);
355 connected = (DAC_CMP_OUTPUT & ulData) ? 1 : 0;
356
357 ulData = ulOrigVCLK_ECP_CNTL;
358 ulMask = 0xFFFFFFFFL;
359 OUTPLLP(VCLK_ECP_CNTL, ulData, ulMask);
360
361 OUTREG(DAC_CNTL, ulOrigDAC_CNTL );
362 OUTREG(DAC_EXT_CNTL, ulOrigDAC_EXT_CNTL );
363 OUTREG(CRTC_EXT_CNTL, ulOrigCRTC_EXT_CNTL);
364 }
365
366 return connected ? MT_CRT : MT_NONE;
367 }
368
369
370
371
372
373 static int radeon_parse_monitor_layout(struct radeonfb_info *rinfo,
374 const char *monitor_layout)
375 {
376 char s1[5], s2[5];
377 int i = 0, second = 0;
378 const char *s;
379
380 if (!monitor_layout)
381 return 0;
382
383 s = monitor_layout;
384 do {
385 switch(*s) {
386 case ',':
387 s1[i] = '\0';
388 i = 0;
389 second = 1;
390 break;
391 case ' ':
392 case '\0':
393 break;
394 default:
395 if (i > 4)
396 break;
397 if (second)
398 s2[i] = *s;
399 else
400 s1[i] = *s;
401 i++;
402 }
403
404 if (i > 4)
405 i = 4;
406
407 } while (*s++);
408 if (second)
409 s2[i] = 0;
410 else {
411 s1[i] = 0;
412 s2[0] = 0;
413 }
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;
420
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;
427
428 return 1;
429 }
430
431
432
433
434
435
436
437 void radeon_probe_screens(struct radeonfb_info *rinfo,
438 const char *monitor_layout, int ignore_edid)
439 {
440 #ifdef CONFIG_FB_RADEON_I2C
441 int ddc_crt2_used = 0;
442 #endif
443 int tmp, i;
444
445 radeon_parse_connector_info(rinfo);
446
447 if (radeon_parse_monitor_layout(rinfo, monitor_layout)) {
448
449
450
451
452
453
454
455
456 pr_debug("Using specified monitor layout: %s", monitor_layout);
457 #ifdef CONFIG_FB_RADEON_I2C
458 if (!ignore_edid) {
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);
462 ddc_crt2_used = 1;
463 }
464 if (rinfo->mon2_type != MT_NONE)
465 if (!radeon_probe_i2c_connector(rinfo, ddc_vga, &rinfo->mon2_EDID) &&
466 !ddc_crt2_used)
467 radeon_probe_i2c_connector(rinfo, ddc_crt2, &rinfo->mon2_EDID);
468 }
469 #endif
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;
474 } else {
475 rinfo->mon1_type = MT_CRT;
476 printk(KERN_INFO "radeonfb: No valid monitor, assuming CRT on first port\n");
477 }
478 rinfo->mon2_type = MT_NONE;
479 rinfo->mon2_EDID = NULL;
480 }
481 } else {
482
483
484
485
486 pr_debug("Starting monitor auto detection...\n");
487
488 #if defined(DEBUG) && defined(CONFIG_FB_RADEON_I2C)
489 {
490 u8 *EDIDs[4] = { NULL, NULL, NULL, NULL };
491 int mon_types[4] = {MT_NONE, MT_NONE, MT_NONE, MT_NONE};
492 int i;
493
494 for (i = 0; i < 4; i++)
495 mon_types[i] = radeon_probe_i2c_connector(rinfo,
496 i+1, &EDIDs[i]);
497 }
498 #endif
499
500
501
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,
506 &rinfo->mon1_EDID);
507 #endif
508 #ifdef CONFIG_FB_RADEON_I2C
509 if (rinfo->mon1_type == MT_NONE)
510 rinfo->mon1_type =
511 radeon_probe_i2c_connector(rinfo, ddc_dvi,
512 &rinfo->mon1_EDID);
513 if (rinfo->mon1_type == MT_NONE)
514 rinfo->mon1_type =
515 radeon_probe_i2c_connector(rinfo, ddc_vga,
516 &rinfo->mon1_EDID);
517 if (rinfo->mon1_type == MT_NONE)
518 rinfo->mon1_type =
519 radeon_probe_i2c_connector(rinfo, ddc_crt2,
520 &rinfo->mon1_EDID);
521 #endif
522 if (rinfo->mon1_type == MT_NONE)
523 rinfo->mon1_type = MT_CRT;
524 goto bail;
525 }
526
527
528
529
530 if (rinfo->bios_seg &&
531 (tmp = BIOS_IN16(rinfo->fp_bios_start + 0x50))) {
532 for (i = 1; i < 4; i++) {
533 unsigned int tmp0;
534
535 if (!BIOS_IN8(tmp + i*2) && i > 1)
536 break;
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");
541 }
542 if ((((tmp0 >> 8) & 0x0f) == ddc_dvi) && ((tmp0 >> 4) & 0x01)) {
543 rinfo->reversed_TMDS = 1;
544 printk(KERN_INFO "radeonfb: Reversed TMDS detected\n");
545 }
546 }
547 }
548
549
550
551
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,
555 &rinfo->mon1_EDID);
556 #endif
557 #ifdef CONFIG_FB_RADEON_I2C
558 if (rinfo->mon1_type == MT_NONE)
559 rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_dvi,
560 &rinfo->mon1_EDID);
561 if (rinfo->mon1_type == MT_NONE) {
562 rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_crt2,
563 &rinfo->mon1_EDID);
564 if (rinfo->mon1_type != MT_NONE)
565 ddc_crt2_used = 1;
566 }
567 #endif
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");
573 }
574 if (rinfo->mon1_type == MT_NONE)
575 rinfo->mon1_type = radeon_crt_is_connected(rinfo, rinfo->reversed_DAC);
576
577
578
579
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,
583 &rinfo->mon2_EDID);
584 #endif
585 #ifdef CONFIG_FB_RADEON_I2C
586 if (rinfo->mon2_type == MT_NONE)
587 rinfo->mon2_type = radeon_probe_i2c_connector(rinfo, ddc_vga,
588 &rinfo->mon2_EDID);
589 if (rinfo->mon2_type == MT_NONE && !ddc_crt2_used)
590 rinfo->mon2_type = radeon_probe_i2c_connector(rinfo, ddc_crt2,
591 &rinfo->mon2_EDID);
592 #endif
593 if (rinfo->mon2_type == MT_NONE)
594 rinfo->mon2_type = radeon_crt_is_connected(rinfo, !rinfo->reversed_DAC);
595
596
597
598
599
600
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;
605 } else
606 rinfo->mon1_type = MT_CRT;
607 rinfo->mon2_type = MT_NONE;
608 rinfo->mon2_EDID = NULL;
609 }
610
611
612
613
614 if (rinfo->reversed_TMDS) {
615
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;
625 }
626 }
627 }
628 if (ignore_edid) {
629 kfree(rinfo->mon1_EDID);
630 rinfo->mon1_EDID = NULL;
631 kfree(rinfo->mon2_EDID);
632 rinfo->mon2_EDID = NULL;
633 }
634
635 bail:
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)
641 return;
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");
646 }
647
648
649
650
651
652
653
654
655 static void radeon_fixup_panel_info(struct radeonfb_info *rinfo)
656 {
657 #ifdef CONFIG_PPC
658
659
660
661
662 if (!rinfo->panel_info.use_bios_dividers && rinfo->mon1_type == MT_LCD
663 && rinfo->is_mobility) {
664 int ppll_div_sel;
665 u32 ppll_divn;
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;
673
674 printk(KERN_DEBUG "radeonfb: Using Firmware dividers 0x%08x "
675 "from PPLL %d\n",
676 rinfo->panel_info.fbk_divider |
677 (rinfo->panel_info.post_divider << 16),
678 ppll_div_sel);
679 }
680 #endif
681 }
682
683
684
685
686
687
688 static void radeon_var_to_panel_info(struct radeonfb_info *rinfo, struct fb_var_screeninfo *var)
689 {
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
707
708
709
710
711 rinfo->panel_info.pwr_delay = 200;
712 }
713
714 static void radeon_videomode_to_var(struct fb_var_screeninfo *var,
715 const struct fb_videomode *mode)
716 {
717 var->xres = mode->xres;
718 var->yres = mode->yres;
719 var->xres_virtual = mode->xres;
720 var->yres_virtual = mode->yres;
721 var->xoffset = 0;
722 var->yoffset = 0;
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;
732 }
733
734 #ifdef CONFIG_PPC_PSERIES
735 static int is_powerblade(const char *model)
736 {
737 struct device_node *root;
738 const char* cp;
739 int len, l, rc = 0;
740
741 root = of_find_node_by_path("/");
742 if (root && model) {
743 l = strlen(model);
744 cp = of_get_property(root, "model", &len);
745 if (cp)
746 rc = memcmp(model, cp, min(len, l)) == 0;
747 of_node_put(root);
748 }
749 return rc;
750 }
751 #endif
752
753
754
755
756
757 void radeon_check_modes(struct radeonfb_info *rinfo, const char *mode_option)
758 {
759 struct fb_info * info = rinfo->info;
760 int has_default_mode = 0;
761
762
763
764
765 info->var = radeonfb_default_var;
766 INIT_LIST_HEAD(&info->modelist);
767
768
769
770
771 if (rinfo->mon1_type == MT_LCD)
772 radeon_get_panel_info_BIOS(rinfo);
773
774
775
776
777
778
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);
787 }
788 }
789
790
791
792
793 radeon_fixup_panel_info(rinfo);
794
795
796
797
798
799 if (rinfo->mon1_type != MT_CRT && rinfo->panel_info.valid) {
800 struct fb_var_screeninfo *var = &info->var;
801
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;
818 var->sync = 0;
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;
823 var->vmode = 0;
824 has_default_mode = 1;
825 }
826
827
828
829
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,
834 &info->modelist);
835 rinfo->mon1_modedb = info->monspecs.modedb;
836 rinfo->mon1_dbsize = info->monspecs.modedb_len;
837 }
838
839
840
841
842
843
844
845 if (rinfo->mon1_type != MT_CRT && !rinfo->panel_info.valid) {
846 struct fb_videomode *modedb;
847 int dbsize;
848 char modename[32];
849
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;
856 }
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;
860 goto pickup_default;
861 }
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;
871 goto pickup_default;
872 }
873 has_default_mode = 1;
874 radeon_var_to_panel_info(rinfo, &info->var);
875 }
876
877 pickup_default:
878
879
880
881 if (mode_option) {
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;
886 }
887
888 #ifdef CONFIG_PPC_PSERIES
889 if (!has_default_mode && (
890 is_powerblade("IBM,8842") ||
891 is_powerblade("IBM,8844") ||
892 is_powerblade("IBM,7998") ||
893 is_powerblade("IBM,0792") ||
894 is_powerblade("IBM,0793")
895 )) {
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;
901 }
902 #endif
903
904
905
906
907 if (!has_default_mode && info->monspecs.modedb != NULL) {
908 struct fb_monspecs *specs = &info->monspecs;
909 struct fb_videomode *modedb = NULL;
910
911
912 if (specs->misc & FB_MISC_1ST_DETAIL) {
913 int i;
914
915 for (i = 0; i < specs->modedb_len; i++) {
916 if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
917 modedb = &specs->modedb[i];
918 break;
919 }
920 }
921 } else {
922
923 modedb = &specs->modedb[0];
924 }
925 if (modedb != NULL) {
926 info->var.bits_per_pixel = 8;
927 radeon_videomode_to_var(&info->var, modedb);
928 has_default_mode = 1;
929 }
930 }
931 if (1) {
932 struct fb_videomode mode;
933
934
935
936 fb_var_to_videomode(&mode, &info->var);
937 fb_add_videomode(&mode, &info->modelist);
938 }
939 }
940
941
942
943
944
945
946
947
948
949
950
951
952
953 static int radeon_compare_modes(const struct fb_var_screeninfo *var,
954 const struct fb_videomode *mode)
955 {
956 int distance = 0;
957
958 distance = mode->yres - var->yres;
959 distance += (mode->xres - var->xres)/2;
960 return distance;
961 }
962
963
964
965
966
967
968
969
970
971
972
973
974
975 int radeon_match_mode(struct radeonfb_info *rinfo,
976 struct fb_var_screeninfo *dest,
977 const struct fb_var_screeninfo *src)
978 {
979 const struct fb_videomode *db = vesa_modes;
980 int i, dbsize = 34;
981 int has_rmx, native_db = 0;
982 int distance = INT_MAX;
983 const struct fb_videomode *candidate = NULL;
984
985
986 memcpy(dest, src, sizeof(struct fb_var_screeninfo));
987
988
989 if (rinfo->mon1_modedb) {
990 db = rinfo->mon1_modedb;
991 dbsize = rinfo->mon1_dbsize;
992 native_db = 1;
993 }
994
995
996 has_rmx = rinfo->mon1_type == MT_LCD || rinfo->mon1_type == MT_DFP;
997
998
999
1000
1001
1002 if ((src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_TEST ||
1003 (src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
1004
1005
1006
1007
1008
1009 if (has_rmx == 0 && rinfo->mon1_modedb)
1010 if (fb_validate_mode((struct fb_var_screeninfo *)src, rinfo->info))
1011 return -EINVAL;
1012 return 0;
1013 }
1014
1015
1016 while (db) {
1017 for (i = 0; i < dbsize; i++) {
1018 int d;
1019
1020 if (db[i].yres < src->yres)
1021 continue;
1022 if (db[i].xres < src->xres)
1023 continue;
1024 d = radeon_compare_modes(src, &db[i]);
1025
1026
1027
1028 if (d < distance) {
1029 candidate = &db[i];
1030 distance = d;
1031 }
1032 }
1033 db = NULL;
1034
1035 if (native_db && has_rmx) {
1036 db = vesa_modes;
1037 dbsize = 34;
1038 native_db = 0;
1039 }
1040 }
1041
1042
1043 if (candidate != NULL) {
1044 radeon_videomode_to_var(dest, candidate);
1045 return 0;
1046 }
1047
1048
1049 if (!has_rmx)
1050 return -EINVAL;
1051
1052 return 0;
1053 }