107 unsigned int pixclock = var->
pixclock;
111 if (!pixclock) pixclock = 10000;
112 mt->
pixclock = 1000000000 / pixclock;
129 unsigned int*
in,
unsigned int* feed,
unsigned int*
post) {
130 unsigned int bestdiff = ~0;
131 unsigned int bestvco = 0;
152 if (fwant * 2 > fmax)
156 if (fwant < pll->vco_freq_min) fwant = pll->
vco_freq_min;
157 if (fwant > fmax) fwant = fmax;
158 for (; p-- > 0; fwant >>= 1, bestdiff >>= 1) {
161 if (fwant < pll->vco_freq_min)
break;
162 for (m = pll->
in_div_min; m <= pll->in_div_max; m++) {
163 unsigned int diff, fvco;
166 n = (fwant * (m + 1) + (fxtal >> 1)) / fxtal - 1;
169 if (n < pll->feed_div_min)
171 fvco = (fxtal * (n + 1)) / (m + 1);
176 if (diff < bestdiff) {
185 dprintk(
KERN_ERR "clk: %02X %02X %02X %d %d %d\n", *in, *feed, *post, fxtal, bestvco, fwant);
191 unsigned int hd, hs, he, hbe, ht;
192 unsigned int vd, vs, ve, vt,
lc;
194 unsigned int divider;
231 for (i = 0; i < 16; i++)
246 divider = minfo->
curr.final_bppShift;
247 while (divider & 3) {
254 divider = divider / 4;
256 while (divider > 8) {
273 if (((ht & 0x07) == 0x06) || ((ht & 0x0F) == 0x04))
276 wd = minfo->
fbcon.var.xres_virtual * minfo->
curr.final_bppShift / 64;
282 hw->
CRTCEXT[5] = (hs + he - ht) >> 1;
287 hw->
CRTCEXT[0] |= (wd & 0x300) >> 4;
288 hw->
CRTCEXT[1] = (((ht - 4) & 0x100) >> 8) |
289 ((hd & 0x100) >> 7) |
290 ((hs & 0x100) >> 6) |
295 hw->
CRTCEXT[2] = ((vt & 0xC00) >> 10) |
296 ((vd & 0x400) >> 8) |
297 ((vd & 0xC00) >> 7) |
298 ((vs & 0xC00) >> 5) |
300 hw->
CRTCEXT[3] = (divider - 1) | 0x80;
306 hw->
CRTC[3] = (hbe & 0x1F) | 0x80;
308 hw->
CRTC[5] = ((hbe & 0x20) << 2) | (he & 0x1F);
309 hw->
CRTC[6] = vt & 0xFF;
310 hw->
CRTC[7] = ((vt & 0x100) >> 8) |
311 ((vd & 0x100) >> 7) |
312 ((vs & 0x100) >> 6) |
313 ((vd & 0x100) >> 5) |
314 ((lc & 0x100) >> 4) |
315 ((vt & 0x200) >> 4) |
316 ((vd & 0x200) >> 3) |
319 hw->
CRTC[9] = ((vd & 0x200) >> 4) |
323 for (i = 10; i < 16; i++)
326 hw->
CRTC[17] = (ve & 0x0F) | 0x20;
331 hw->
CRTC[22] = (vt + 1) ;
347 for (i = 0; i < 5; i++)
351 for (i = 0; i < 9; i++)
355 for (i = 0; i < 25; i++)
359 for (i = 0; i < 21; i++)
368 for (i = 1; i < 5; i++)
371 for (i = 0; i < 25; i++)
373 for (i = 0; i < 9; i++)
375 for (i = 0; i < 21; i++) {
382 for (i = 0; i < 768; i++)
391 unsigned int b0 =
readb(pins);
393 if (b0 == 0x2E &&
readb(pins+1) == 0x41) {
394 unsigned int pins_len =
readb(pins+2);
399 if (pins_len < 3 || pins_len > 128) {
405 cksum = 0x2E + 0x41 + pins_len;
406 for (i = 3; i < pins_len; i++) {
407 cksum += *dst++ =
readb(pins+i);
413 }
else if (b0 == 0x40 &&
readb(pins+1) == 0x00) {
415 unsigned char* dst = bd->
pins;
419 for (i = 2; i < 0x40; i++) {
420 *dst++ =
readb(pins+i);
427 unsigned int pcir_offset;
429 pcir_offset =
readb(vbios + 24) | (
readb(vbios + 25) << 8);
430 if (pcir_offset >= 26 && pcir_offset < 0xFFE0 &&
431 readb(vbios + pcir_offset ) ==
'P' &&
432 readb(vbios + pcir_offset + 1) ==
'C' &&
433 readb(vbios + pcir_offset + 2) ==
'I' &&
434 readb(vbios + pcir_offset + 3) ==
'R') {
437 h =
readb(vbios + pcir_offset + 0x12);
438 bd->
version.vMaj = (h >> 4) & 0xF;
444 h =
readb(vbios + 5);
445 bd->
version.vMaj = (h >> 4) & 0xF;
454 b =
readb(vbios + 0x7FF1);
466 if (
readb(vbios + 0x1D) !=
'I' ||
467 readb(vbios + 0x1E) !=
'B' ||
468 readb(vbios + 0x1F) !=
'M' ||
469 readb(vbios + 0x20) !=
' ') {
472 for (i = 0x2D; i < 0x2D + 128; i++) {
473 unsigned char b =
readb(vbios + i);
475 if (b ==
'(' &&
readb(vbios + i + 1) ==
'V') {
476 if (
readb(vbios + i + 6) ==
'T' &&
477 readb(vbios + i + 7) ==
'V' &&
478 readb(vbios + i + 8) ==
'O') {
489 unsigned int pins_offset;
491 if (
readb(vbios) != 0x55 ||
readb(vbios + 1) != 0xAA) {
495 get_bios_version(vbios, bd);
496 get_bios_output(vbios, bd);
497 get_bios_tvout(vbios, bd);
498 #if defined(__powerpc__)
507 for ( pins_offset = 0 ; pins_offset <= 0xFF80 ; pins_offset++ ) {
510 header[0] =
readb(vbios + pins_offset);
511 header[1] =
readb(vbios + pins_offset + 1);
512 header[2] =
readb(vbios + pins_offset + 2);
513 if ( (header[0] == 0x2E) && (header[1] == 0x41)
514 && ((header[2] == 0x40) || (header[2] == 0x80)) ) {
517 get_pins(vbios + pins_offset, bd);
522 pins_offset =
readb(vbios + 0x7FFC) | (
readb(vbios + 0x7FFD) << 8);
523 if (pins_offset <= 0xFF80) {
524 get_pins(vbios + pins_offset, bd);
534 switch (bd->
pins[22]) {
535 case 0: maxdac = 175000;
break;
536 case 1: maxdac = 220000;
break;
537 default: maxdac = 240000;
break;
539 if (get_unaligned_le16(bd->
pins + 24)) {
540 maxdac = get_unaligned_le16(bd->
pins + 24) * 10;
542 minfo->
limits.pixel.vcomax = maxdac;
543 minfo->
values.pll.system = get_unaligned_le16(bd->
pins + 28) ?
544 get_unaligned_le16(bd->
pins + 28) * 10 : 50000;
546 minfo->
features.pll.ref_freq = 14318;
547 minfo->
values.reg.mctlwtst = 0x00030101;
554 minfo->
limits.pixel.vcomax = 220000;
555 minfo->
values.pll.system = 50000;
556 minfo->
features.pll.ref_freq = 14318;
557 minfo->
values.reg.mctlwtst = 0x00030101;
563 minfo->
limits.pixel.vcomax =
564 minfo->
limits.system.vcomax = (bd->
pins[41] == 0xFF) ? 230000 : ((bd->
pins[41] + 100) * 1000);
565 minfo->
values.reg.mctlwtst = ((bd->
pins[51] & 0x01) ? 0x00000001 : 0) |
566 ((bd->
pins[51] & 0x02) ? 0x00000100 : 0) |
567 ((bd->
pins[51] & 0x04) ? 0x00010000 : 0) |
568 ((bd->
pins[51] & 0x08) ? 0x00020000 : 0);
569 minfo->
values.pll.system = (bd->
pins[43] == 0xFF) ? 50000 : ((bd->
pins[43] + 100) * 1000);
570 minfo->
features.pll.ref_freq = 14318;
577 minfo->
limits.pixel.vcomax =
578 minfo->
limits.system.vcomax = 230000;
579 minfo->
values.reg.mctlwtst = 0x00030101;
580 minfo->
values.pll.system = 50000;
581 minfo->
features.pll.ref_freq = 14318;
587 minfo->
limits.pixel.vcomax =
588 minfo->
limits.system.vcomax = (bd->
pins[36] == 0xFF) ? 230000 : ((bd->
pins[36] + 100) * 1000);
592 minfo->
values.reg.memrdbk = ((bd->
pins[57] << 21) & 0x1E000000) |
593 ((bd->
pins[57] << 22) & 0x00C00000) |
594 ((bd->
pins[56] << 1) & 0x000001E0) |
595 ( bd->
pins[56] & 0x0000000F);
596 minfo->
values.reg.opt = (bd->
pins[54] & 7) << 10;
598 minfo->
features.pll.ref_freq = (bd->
pins[52] & 0x20) ? 14318 : 27000;
605 minfo->
limits.pixel.vcomax =
606 minfo->
limits.system.vcomax = 230000;
607 minfo->
values.reg.mctlwtst = 0x01250A21;
608 minfo->
values.reg.memrdbk = 0x00000000;
609 minfo->
values.reg.opt = 0x00000C00;
610 minfo->
values.reg.opt2 = 0x00000000;
611 minfo->
features.pll.ref_freq = 27000;
617 minfo->
limits.pixel.vcomax = (bd->
pins[ 39] == 0xFF) ? 230000 : bd->
pins[ 39] * 4000;
618 minfo->
limits.system.vcomax = (bd->
pins[ 38] == 0xFF) ? minfo->
limits.pixel.vcomax : bd->
pins[ 38] * 4000;
620 minfo->
values.reg.memrdbk = ((bd->
pins[87] << 21) & 0x1E000000) |
621 ((bd->
pins[87] << 22) & 0x00C00000) |
622 ((bd->
pins[86] << 1) & 0x000001E0) |
623 ( bd->
pins[86] & 0x0000000F);
624 minfo->
values.reg.opt = ((bd->
pins[53] << 15) & 0x00400000) |
625 ((bd->
pins[53] << 22) & 0x10000000) |
626 ((bd->
pins[53] << 7) & 0x00001C00);
628 minfo->
values.pll.system = (bd->
pins[ 65] == 0xFF) ? 200000 : bd->
pins[ 65] * 4000;
629 minfo->
features.pll.ref_freq = (bd->
pins[ 92] & 0x01) ? 14318 : 27000;
636 minfo->
limits.pixel.vcomax =
637 minfo->
limits.system.vcomax = 252000;
638 minfo->
values.reg.mctlwtst = 0x04A450A1;
639 minfo->
values.reg.memrdbk = 0x000000E7;
640 minfo->
values.reg.opt = 0x10000400;
641 minfo->
values.reg.opt3 = 0x0190A419;
642 minfo->
values.pll.system = 200000;
643 minfo->
features.pll.ref_freq = 27000;
651 mult = bd->
pins[4]?8000:6000;
653 minfo->
limits.pixel.vcomax = (bd->
pins[ 38] == 0xFF) ? 600000 : bd->
pins[ 38] * mult;
655 minfo->
limits.video.vcomax = (bd->
pins[ 37] == 0xFF) ? minfo->
limits.system.vcomax : bd->
pins[ 37] * mult;
657 minfo->
limits.system.vcomin = (bd->
pins[121] == 0xFF) ? minfo->
limits.pixel.vcomin : bd->
pins[121] * mult;
659 minfo->
values.pll.system =
660 minfo->
values.pll.video = (bd->
pins[ 92] == 0xFF) ? 284000 : bd->
pins[ 92] * 4000;
667 minfo->
features.pll.ref_freq = (bd->
pins[110] & 0x01) ? 14318 : 27000;
668 minfo->
values.memory.ddr = (bd->
pins[114] & 0x60) == 0x20;
669 minfo->
values.memory.dll = (bd->
pins[115] & 0x02) != 0;
670 minfo->
values.memory.emrswen = (bd->
pins[115] & 0x01) != 0;
671 minfo->
values.reg.maccess = minfo->
values.memory.emrswen ? 0x00004000 : 0x00000000;
672 if (bd->
pins[115] & 4) {
673 minfo->
values.reg.mctlwtst_core = minfo->
values.reg.mctlwtst;
675 u_int32_t wtst_xlat[] = { 0, 1, 5, 6, 7, 5, 2, 3 };
676 minfo->
values.reg.mctlwtst_core = (minfo->
values.reg.mctlwtst & ~7) |
677 wtst_xlat[minfo->
values.reg.mctlwtst & 7];
686 minfo->
limits.pixel.vcomax =
687 minfo->
limits.system.vcomax =
688 minfo->
limits.video.vcomax = 600000;
689 minfo->
limits.pixel.vcomin =
690 minfo->
limits.system.vcomin =
691 minfo->
limits.video.vcomin = 256000;
692 minfo->
values.pll.system =
693 minfo->
values.pll.video = 284000;
694 minfo->
values.reg.opt = 0x404A1160;
695 minfo->
values.reg.opt2 = 0x0000AC00;
696 minfo->
values.reg.opt3 = 0x0090A409;
697 minfo->
values.reg.mctlwtst_core =
698 minfo->
values.reg.mctlwtst = 0x0C81462B;
699 minfo->
values.reg.memmisc = 0x80000004;
700 minfo->
values.reg.memrdbk = 0x01001103;
701 minfo->
features.pll.ref_freq = 27000;
702 minfo->
values.memory.ddr = 1;
703 minfo->
values.memory.dll = 1;
704 minfo->
values.memory.emrswen = 1;
705 minfo->
values.reg.maccess = 0x00004000;
711 unsigned int pins_version;
712 static const unsigned int pinslen[] = { 64, 64, 64, 128, 128 };
714 switch (minfo->
chip) {
715 case MGA_2064: default_pins1(minfo);
break;
718 case MGA_1164: default_pins2(minfo);
break;
720 case MGA_G200: default_pins3(minfo);
break;
721 case MGA_G400: default_pins4(minfo);
break;
723 case MGA_G550: default_pins5(minfo);
break;
730 printk(
KERN_INFO "matroxfb: BIOS on your Matrox device does not contain powerup info\n");
733 if (bd->
pins[0] == 0x2E && bd->
pins[1] == 0x41) {
734 pins_version = bd->
pins[5];
735 if (pins_version < 2 || pins_version > 5) {
736 printk(
KERN_INFO "matroxfb: Unknown version (%u) of powerup info\n", pins_version);
742 if (bd->
pins_len != pinslen[pins_version - 1]) {
746 switch (pins_version) {
748 return parse_pins1(minfo, bd);
750 return parse_pins2(minfo, bd);
752 return parse_pins3(minfo, bd);
754 return parse_pins4(minfo, bd);
756 return parse_pins5(minfo, bd);
758 printk(
KERN_DEBUG "matroxfb: Powerup info version %u is not yet supported\n", pins_version);
774 pci_read_config_dword(pdev, minfo->
devflags.fbResource, &fbbase);
776 parse_bios(vaddr_va(minfo->
video.vbase), &minfo->
bios);
780 if (!minfo->
bios.bios_valid) {
783 b =
ioremap(0x000C0000, 65536);
787 unsigned int ven =
readb(b+0x64+0) | (
readb(b+0x64+1) << 8);
791 printk(
KERN_INFO "matroxfb: Legacy BIOS is for %04X:%04X, while this device is %04X:%04X\n",
794 parse_bios(b, &minfo->
bios);
800 matroxfb_set_limits(minfo, &minfo->
bios);
802 (minfo->
values.reg.opt & 0x1C00) >> 10);