/* Toshiba Satellite Pro fan control program for FreeBSD.  This was   */
/* written by disassembling Toshiba's FAN.EXE program.  It works okay */
/* on my 405CS, not sure what other models use the same method.       */
/* Must be run as root, and the /dev/io device must exist.            */

/* Written by Orv (dmbrodbe@mtu.edu) with                             */
/*                            help from Max (max@condor.maxie.com)    */

#include <stdio.h>
#include <machine/cpufunc.h>

int main( int argc, char *argv[] ) {
	int off;
	FILE *f;
	unsigned char b;
	
	if ((argc > 1) && ((*argv[ 1 ] == '+') || (*argv[ 1 ] == '-')))
		if (*argv[ 1 ] == '+')
			off = 0;
		else	off = 1;
	else {
		printf( "%s [+|-]\n\n", argv[0] );
		printf( "Toshiba Satellite fan control program.\n" );
		printf( "+ turns it on, - turns it off.\n\n" );
		return( 1 );
	}
	
	f=fopen("/dev/io","r+b");
	
	outb(0xE4,0xBE);
	b=inb(0xE5);

	if (off)
		b=b | 0x01;
	else	b=b & 0xFE;

	outb(0xE5,b);
	fclose(f);
	return( 0 );
}

