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