Mercurial > ~darius > hgwebdir.cgi > hwmon
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c34b37680055 |
---|---|
1 #include <stdio.h> | |
2 #include <errno.h> | |
3 #include <string.h> | |
4 #include <fcntl.h> | |
5 #include <stdlib.h> | |
6 #include <sys/types.h> | |
7 #include <machine/cpufunc.h> | |
8 #include <unistd.h> | |
9 | |
10 void | |
11 usage(char *name) { | |
12 fprintf(stderr, | |
13 "Bad usage\n" | |
14 "\t%s [-b base] adr [data]\n" | |
15 "\n" | |
16 "Read/write registers in Winbond SuperIO parts\n" | |
17 "base is the base address for the chip (default: 0x290)\n" | |
18 "adr is the register to read/write\n" | |
19 "data is the data to write to adr\n", name); | |
20 exit(1); | |
21 } | |
22 | |
23 int | |
24 main(int argc, char **argv) { | |
25 int fd, base, dev, adr, data, ch, type; | |
26 char *progname; | |
27 | |
28 #define WB_ADR 0x5 | |
29 #define WB_DATA 0x6 | |
30 | |
31 base = 0x290; | |
32 | |
33 progname = argv[0]; | |
34 | |
35 while ((ch = getopt(argc, argv, "b:")) != -1) { | |
36 switch (ch) { | |
37 case 'b': | |
38 base = strtol(optarg, NULL, 0) & 0xffff; | |
39 break; | |
40 | |
41 default: | |
42 usage(progname); | |
43 break; | |
44 } | |
45 } | |
46 argc -= optind; | |
47 argv += optind; | |
48 | |
49 if (argc != 1 && argc != 2) | |
50 usage(progname); | |
51 | |
52 if ((fd = open("/dev/io", O_RDWR)) == -1) { | |
53 fprintf(stderr, "Can't open /dev/io: %s\n", strerror(errno)); | |
54 exit(1); | |
55 } | |
56 | |
57 adr = strtol(argv[0], NULL, 0) & 0xff; | |
58 | |
59 /* Register to access */ | |
60 outb(base + WB_ADR, adr); | |
61 | |
62 if (argc == 2) { | |
63 data = strtol(argv[1], NULL, 0) & 0xff; | |
64 printf("Base 0x%02x: 0x%02x <- 0x%02x\n", base, adr, data); | |
65 outb(base + WB_DATA, data); | |
66 } else | |
67 printf("Bank 0x%02x: 0x%02x -> 0x%02x\n", dev, adr, inb(base + WB_DATA)); | |
68 | |
69 exit(0); | |
70 } | |
71 |