1 | /*
|
---|
2 | * $ZEL$
|
---|
3 | */
|
---|
4 |
|
---|
5 | #define _GNU_SOURCE
|
---|
6 |
|
---|
7 | #include <stdio.h>
|
---|
8 | #include <errno.h>
|
---|
9 | #include <string.h>
|
---|
10 | #include <sys/types.h>
|
---|
11 | #include <time.h>
|
---|
12 | #include <unistd.h>
|
---|
13 | #include <stdlib.h>
|
---|
14 | #include <fcntl.h>
|
---|
15 | #include <sys/mman.h>
|
---|
16 | #include <sys/ioctl.h>
|
---|
17 |
|
---|
18 | #include "../dev/pci/sis1100_var.h"
|
---|
19 |
|
---|
20 | static int
|
---|
21 | read_eprom(int p)
|
---|
22 | {
|
---|
23 | int res=0, i;
|
---|
24 | u_int16_t data[0x2c];
|
---|
25 | struct sis1100_eeprom_req eeprom_req;
|
---|
26 | u_int32_t val;
|
---|
27 |
|
---|
28 | eeprom_req.num=0x2c;
|
---|
29 | eeprom_req.data=data;
|
---|
30 | eeprom_req.addr=0;
|
---|
31 | res=ioctl(p, SIS1100_READ_EEPROM, &eeprom_req);
|
---|
32 | if (res<0) {
|
---|
33 | printf("ioctl(READ_EEPROM): %s\n", strerror(errno));
|
---|
34 | return -1;
|
---|
35 | }
|
---|
36 | for (i=0; i<0x2c; i+=1) {
|
---|
37 | printf("0x%02x: %04x\n", i*2, data[i]);
|
---|
38 | }
|
---|
39 |
|
---|
40 | val=(data[0x24]<<16)|data[0x25];
|
---|
41 | printf("LAS1RR: 0x%08x\n", val);
|
---|
42 | return 0;
|
---|
43 | }
|
---|
44 |
|
---|
45 | static int
|
---|
46 | write_eprom(int p)
|
---|
47 | {
|
---|
48 | int res=0;
|
---|
49 | u_int16_t data[2];
|
---|
50 | struct sis1100_eeprom_req eeprom_req;
|
---|
51 | u_int32_t val;
|
---|
52 |
|
---|
53 | val=0xfff00000;
|
---|
54 | data[0]=(val>>16)&0xffff;
|
---|
55 | data[1]=(val)&0xffff;
|
---|
56 |
|
---|
57 | eeprom_req.num=2;
|
---|
58 | eeprom_req.data=data;
|
---|
59 | eeprom_req.addr=0x24;
|
---|
60 | res=ioctl(p, SIS1100_WRITE_EEPROM, &eeprom_req);
|
---|
61 | if (res<0) {
|
---|
62 | printf("ioctl(WRITE_EEPROM): %s\n", strerror(errno));
|
---|
63 | return -1;
|
---|
64 | }
|
---|
65 | return 0;
|
---|
66 | }
|
---|
67 |
|
---|
68 | static int
|
---|
69 | patch_eprom(int p)
|
---|
70 | {
|
---|
71 | int res=0;
|
---|
72 | u_int16_t data[0x2c];
|
---|
73 | struct sis1100_eeprom_req eeprom_req;
|
---|
74 | u_int32_t val;
|
---|
75 |
|
---|
76 | eeprom_req.num=0x2c;
|
---|
77 | eeprom_req.data=data;
|
---|
78 | eeprom_req.addr=0;
|
---|
79 | res=ioctl(p, SIS1100_READ_EEPROM, &eeprom_req);
|
---|
80 | if (res<0) {
|
---|
81 | printf("ioctl(READ_EEPROM): %s\n", strerror(errno));
|
---|
82 | return -1;
|
---|
83 | }
|
---|
84 |
|
---|
85 | val=0xfff00000;
|
---|
86 | data[24]=(val>>16)&0xffff;
|
---|
87 | data[25]=(val)&0xffff;
|
---|
88 |
|
---|
89 | eeprom_req.num=0x2c;
|
---|
90 | eeprom_req.data=data;
|
---|
91 | eeprom_req.addr=0;
|
---|
92 | res=ioctl(p, SIS1100_WRITE_EEPROM, &eeprom_req);
|
---|
93 | if (res<0) {
|
---|
94 | printf("ioctl(WRITE_EEPROM): %s\n", strerror(errno));
|
---|
95 | return -1;
|
---|
96 | }
|
---|
97 |
|
---|
98 | return 0;
|
---|
99 | }
|
---|
100 |
|
---|
101 | int main(int argc, char* argv[])
|
---|
102 | {
|
---|
103 | int p;
|
---|
104 | printf("\n==== SIS1100 EEPROM Test; V0.1 ====\n\n");
|
---|
105 |
|
---|
106 | if (argc!=2) {
|
---|
107 | printf("usage: %s pathname\n", argv[0]);
|
---|
108 | return 1;
|
---|
109 | }
|
---|
110 |
|
---|
111 | p=open(argv[1], O_RDWR, 0);
|
---|
112 | if (p<0) {
|
---|
113 | printf("open \"%s\": %s\n", argv[1], strerror(errno));
|
---|
114 | return 1;
|
---|
115 | }
|
---|
116 |
|
---|
117 | if (read_eprom(p)<0) return 2;
|
---|
118 | if (write_eprom(p)<0) return 3;
|
---|
119 | /*
|
---|
120 | if (read_eprom(p)<0) return 4;
|
---|
121 | patch_eprom(p);
|
---|
122 | */
|
---|
123 |
|
---|
124 | close(p);
|
---|
125 | return 0;
|
---|
126 | }
|
---|