/* Code to initialize Tyan Tiger MP S2460 motherboard
 * hardware sensing using lm_sensors.
 *
 * See: http://www2.lm-sensors.nu/~lm78/readticket.cgi?ticket=861
 *
 * John Choi 4/11/2002
 *
 * Compiled with: gcc -O2 -fomit-frame-pointer -W -Wall -o init init.c
 * Need to run as root before inserting the lm_sensors/i2c modules. (I think.)
 *
 * WARNING! Run at your own risk! 
 */

#include <stdio.h>
#include <sys/io.h>

#define PORT1 0x2E
#define PORT2 0x0c05

int main(void) {

        if (iopl(3)) {perror("iopl error"); exit(1);}
/*
        if (ioperm(PORT1, 2, 1)) {perror("ioperm open error 1"); exit(1);}
        if (ioperm(PORT2, 2, 1)) {perror("ioperm open error 2"); exit(1);}
*/

/* Open Super I/O Reg for Config mode */
        outb(0x87, PORT1);
        outb(0x87, PORT1);

/* Select Logic Dev 0B (HW Monitor) */
        outb(0x07, PORT1);
        outb(0x0b, PORT1+1);

/* Set I/O port address to C00h */
        outb(0x60, PORT1);
        outb(0x0c, PORT1+1);
        outb(0x61, PORT1);
        outb(0x00, PORT1+1);

/* Activate the Super I/O HW monitoring */
        outb(0x30, PORT1);
        outb(0x01, PORT1+1);

/* Set the Super I/O chip SMBUS slave address */
        outb(0x48, PORT2);
        outb(0x2c, PORT2+1);

/* Set the GP21/22 (Pin 91/92) to SMBUS clock/data */
        outb(0x2b, PORT1);
        outb(0x00, PORT1+1);
        outb(0xaa, PORT1);

        if (iopl(0)) {perror("iopl error"); exit(1);}

/*
        if (ioperm(PORT1, 2, 0)) {perror("ioperm close error 1"); exit(1);}
        if (ioperm(PORT2, 2, 0)) {perror("ioperm close error 2"); exit(1);}
*/
        return 0;
}
