#include #ifndef __KERNEL__ #include #include void winbond_probe(unsigned short port, unsigned char magic); void main(void) { if (iopl(3)) { fprintf(stderr, "Could not unlock IO ports. Are you superuser?\n"); exit(1); } printf("Looking for a Winbond W83977\n"); winbond_probe(0x3f0, 0x87); winbond_probe(0x370, 0x87); } #else #include #define printf printk #endif unsigned char read_reg(short p, char m, char d, char r) { unsigned char tmp; outb(m, p); outb(m, p); outb(0x07, p); outb(d, p + 1); /* Select this device */ outb(r, p); tmp = inb(p + 1); /* Read value */ outb(0xaa, p); return tmp; } void write_reg(short p, char m, char d, char r, char x) { outb(m, p); outb(m, p); outb(0x07, p); outb(d, p + 1); /* Select this device */ outb(r, p); outb(x, p + 1); /* Write value */ outb(0xaa, p); } void winbond_probe(unsigned short port, unsigned char magic) { unsigned char hk, lk, da, rc, ha, la, pi, pd, pm; char *mode_ref[8] = {"PS2", "EPP(1.9)", "ECP", "ECP+EPP(1.9)", "SPP", "EPP(1.7)", "???", "ECP+EPP(1.7)"}; hk = read_reg(port, magic, 0x00, 0x20); /* High key */ lk = read_reg(port, magic, 0x00, 0x21); /* Low key */ if ((hk == 0xff) && (lk == 0xff)) return; printf("Winbond ID key = %02x%02x\n", hk, lk); da = read_reg(port, magic, 0x01, 0x30); /* Device available */ rc = read_reg(port, magic, 0x01, 0x31); /* Port address range check */ ha = read_reg(port, magic, 0x01, 0x60); /* Port address - high byte */ la = read_reg(port, magic, 0x01, 0x61); /* Port address - low byte */ pi = read_reg(port, magic, 0x01, 0x70); /* Parallel port IRQ */ pd = read_reg(port, magic, 0x01, 0x74); /* Parallel port DMA */ pm = read_reg(port, magic, 0x01, 0xf0); /* Parallel port mode */ printf("Parallel port enabled - %s\n", (da & 0x01) ? "YES" : "NO"); printf(" address - %02x%02x\n", ha, la); printf(" IRQ - %02x\n", pi & 0x07); if (pd > 3) printf(" DMA - none\n"); else printf(" DMA - %02x\n", pd & 0x03); printf(" mode - %s\n", mode_ref[pm & 0x07]); write_reg(port, magic, 0x01, 0xf0, 0x02); }