This source file includes following definitions.
- send_seeprom_cmd
- reset_seeprom
- ahc_read_seeprom
- ahc_write_seeprom
- ahc_verify_cksum
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 #include "aic7xxx_osm.h"
68 #include "aic7xxx_inline.h"
69 #include "aic7xxx_93cx6.h"
70
71
72
73
74
75 struct seeprom_cmd {
76 uint8_t len;
77 uint8_t bits[11];
78 };
79
80
81 static const struct seeprom_cmd seeprom_ewen = {9, {1, 0, 0, 1, 1, 0, 0, 0, 0}};
82 static const struct seeprom_cmd seeprom_ewds = {9, {1, 0, 0, 0, 0, 0, 0, 0, 0}};
83
84
85 static const struct seeprom_cmd seeprom_long_ewen = {11, {1, 0, 0, 1, 1, 0, 0, 0, 0}};
86 static const struct seeprom_cmd seeprom_long_ewds = {11, {1, 0, 0, 0, 0, 0, 0, 0, 0}};
87
88
89 static const struct seeprom_cmd seeprom_write = {3, {1, 0, 1}};
90 static const struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
91
92
93
94
95 #define CLOCK_PULSE(sd, rdy) \
96 while ((SEEPROM_STATUS_INB(sd) & rdy) == 0) { \
97 ; \
98 } \
99 (void)SEEPROM_INB(sd);
100
101
102
103
104 static void
105 send_seeprom_cmd(struct seeprom_descriptor *sd, const struct seeprom_cmd *cmd)
106 {
107 uint8_t temp;
108 int i = 0;
109
110
111 temp = sd->sd_MS ^ sd->sd_CS;
112 SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
113 CLOCK_PULSE(sd, sd->sd_RDY);
114
115 for (i = 0; i < cmd->len; i++) {
116 if (cmd->bits[i] != 0)
117 temp ^= sd->sd_DO;
118 SEEPROM_OUTB(sd, temp);
119 CLOCK_PULSE(sd, sd->sd_RDY);
120 SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
121 CLOCK_PULSE(sd, sd->sd_RDY);
122 if (cmd->bits[i] != 0)
123 temp ^= sd->sd_DO;
124 }
125 }
126
127
128
129
130 static void
131 reset_seeprom(struct seeprom_descriptor *sd)
132 {
133 uint8_t temp;
134
135 temp = sd->sd_MS;
136 SEEPROM_OUTB(sd, temp);
137 CLOCK_PULSE(sd, sd->sd_RDY);
138 SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
139 CLOCK_PULSE(sd, sd->sd_RDY);
140 SEEPROM_OUTB(sd, temp);
141 CLOCK_PULSE(sd, sd->sd_RDY);
142 }
143
144
145
146
147
148 int
149 ahc_read_seeprom(struct seeprom_descriptor *sd, uint16_t *buf,
150 u_int start_addr, u_int count)
151 {
152 int i = 0;
153 u_int k = 0;
154 uint16_t v;
155 uint8_t temp;
156
157
158
159
160
161 for (k = start_addr; k < count + start_addr; k++) {
162
163
164
165
166 send_seeprom_cmd(sd, &seeprom_read);
167
168
169 temp = sd->sd_MS ^ sd->sd_CS;
170 for (i = (sd->sd_chip - 1); i >= 0; i--) {
171 if ((k & (1 << i)) != 0)
172 temp ^= sd->sd_DO;
173 SEEPROM_OUTB(sd, temp);
174 CLOCK_PULSE(sd, sd->sd_RDY);
175 SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
176 CLOCK_PULSE(sd, sd->sd_RDY);
177 if ((k & (1 << i)) != 0)
178 temp ^= sd->sd_DO;
179 }
180
181
182
183
184
185
186
187 v = 0;
188 for (i = 16; i >= 0; i--) {
189 SEEPROM_OUTB(sd, temp);
190 CLOCK_PULSE(sd, sd->sd_RDY);
191 v <<= 1;
192 if (SEEPROM_DATA_INB(sd) & sd->sd_DI)
193 v |= 1;
194 SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
195 CLOCK_PULSE(sd, sd->sd_RDY);
196 }
197
198 buf[k - start_addr] = v;
199
200
201 reset_seeprom(sd);
202 }
203 #ifdef AHC_DUMP_EEPROM
204 printk("\nSerial EEPROM:\n\t");
205 for (k = 0; k < count; k = k + 1) {
206 if (((k % 8) == 0) && (k != 0)) {
207 printk(KERN_CONT "\n\t");
208 }
209 printk(KERN_CONT " 0x%x", buf[k]);
210 }
211 printk(KERN_CONT "\n");
212 #endif
213 return (1);
214 }
215
216
217
218
219
220 int
221 ahc_write_seeprom(struct seeprom_descriptor *sd, uint16_t *buf,
222 u_int start_addr, u_int count)
223 {
224 const struct seeprom_cmd *ewen, *ewds;
225 uint16_t v;
226 uint8_t temp;
227 int i, k;
228
229
230 if (sd->sd_chip == C46) {
231 ewen = &seeprom_ewen;
232 ewds = &seeprom_ewds;
233 } else if (sd->sd_chip == C56_66) {
234 ewen = &seeprom_long_ewen;
235 ewds = &seeprom_long_ewds;
236 } else {
237 printk("ahc_write_seeprom: unsupported seeprom type %d\n",
238 sd->sd_chip);
239 return (0);
240 }
241
242 send_seeprom_cmd(sd, ewen);
243 reset_seeprom(sd);
244
245
246 temp = sd->sd_MS ^ sd->sd_CS;
247 for (k = start_addr; k < count + start_addr; k++) {
248
249 send_seeprom_cmd(sd, &seeprom_write);
250
251
252 for (i = (sd->sd_chip - 1); i >= 0; i--) {
253 if ((k & (1 << i)) != 0)
254 temp ^= sd->sd_DO;
255 SEEPROM_OUTB(sd, temp);
256 CLOCK_PULSE(sd, sd->sd_RDY);
257 SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
258 CLOCK_PULSE(sd, sd->sd_RDY);
259 if ((k & (1 << i)) != 0)
260 temp ^= sd->sd_DO;
261 }
262
263
264 v = buf[k - start_addr];
265 for (i = 15; i >= 0; i--) {
266 if ((v & (1 << i)) != 0)
267 temp ^= sd->sd_DO;
268 SEEPROM_OUTB(sd, temp);
269 CLOCK_PULSE(sd, sd->sd_RDY);
270 SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
271 CLOCK_PULSE(sd, sd->sd_RDY);
272 if ((v & (1 << i)) != 0)
273 temp ^= sd->sd_DO;
274 }
275
276
277 temp = sd->sd_MS;
278 SEEPROM_OUTB(sd, temp);
279 CLOCK_PULSE(sd, sd->sd_RDY);
280 temp = sd->sd_MS ^ sd->sd_CS;
281 do {
282 SEEPROM_OUTB(sd, temp);
283 CLOCK_PULSE(sd, sd->sd_RDY);
284 SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
285 CLOCK_PULSE(sd, sd->sd_RDY);
286 } while ((SEEPROM_DATA_INB(sd) & sd->sd_DI) == 0);
287
288 reset_seeprom(sd);
289 }
290
291
292 send_seeprom_cmd(sd, ewds);
293 reset_seeprom(sd);
294
295 return (1);
296 }
297
298 int
299 ahc_verify_cksum(struct seeprom_config *sc)
300 {
301 int i;
302 int maxaddr;
303 uint32_t checksum;
304 uint16_t *scarray;
305
306 maxaddr = (sizeof(*sc)/2) - 1;
307 checksum = 0;
308 scarray = (uint16_t *)sc;
309
310 for (i = 0; i < maxaddr; i++)
311 checksum = checksum + scarray[i];
312 if (checksum == 0
313 || (checksum & 0xFFFF) != sc->checksum) {
314 return (0);
315 } else {
316 return(1);
317 }
318 }