Mercurial > ~darius > hgwebdir.cgi > hwmon
view wbio/wbio.c @ 0:c34b37680055 default tip
Inital commit of random SuperIO code.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Thu, 20 Oct 2011 16:48:24 +1030 |
parents | |
children |
line wrap: on
line source
#include <stdio.h> #include <errno.h> #include <string.h> #include <fcntl.h> #include <stdlib.h> #include <sys/types.h> #include <machine/cpufunc.h> #include <unistd.h> void usage(char *name) { fprintf(stderr, "Bad usage\n" "\t%s [-b base] adr [data]\n" "\n" "Read/write registers in Winbond SuperIO parts\n" "base is the base address for the chip (default: 0x290)\n" "adr is the register to read/write\n" "data is the data to write to adr\n", name); exit(1); } int main(int argc, char **argv) { int fd, base, dev, adr, data, ch, type; char *progname; #define WB_ADR 0x5 #define WB_DATA 0x6 base = 0x290; progname = argv[0]; while ((ch = getopt(argc, argv, "b:")) != -1) { switch (ch) { case 'b': base = strtol(optarg, NULL, 0) & 0xffff; break; default: usage(progname); break; } } argc -= optind; argv += optind; if (argc != 1 && argc != 2) usage(progname); if ((fd = open("/dev/io", O_RDWR)) == -1) { fprintf(stderr, "Can't open /dev/io: %s\n", strerror(errno)); exit(1); } adr = strtol(argv[0], NULL, 0) & 0xff; /* Register to access */ outb(base + WB_ADR, adr); if (argc == 2) { data = strtol(argv[1], NULL, 0) & 0xff; printf("Base 0x%02x: 0x%02x <- 0x%02x\n", base, adr, data); outb(base + WB_DATA, data); } else printf("Bank 0x%02x: 0x%02x -> 0x%02x\n", dev, adr, inb(base + WB_DATA)); exit(0); }