blob: dcb561ff79e88f3de5fee73b5debdb49da807423 [file] [log] [blame]
Simon Glasscece9042015-08-19 09:33:38 -06001#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -06002#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -07003#include <console.h>
Kyle Moffett64b94dd2011-10-18 11:05:29 +00004#include "e1000.h"
Simon Glass9bc15642020-02-03 07:36:16 -07005#include <malloc.h>
Anatolij Gustschin6711ee52011-12-20 02:29:03 +00006#include <linux/compiler.h>
Kyle Moffett64b94dd2011-10-18 11:05:29 +00007
8/*-----------------------------------------------------------------------
9 * SPI transfer
10 *
11 * This writes "bitlen" bits out the SPI MOSI port and simultaneously clocks
12 * "bitlen" bits in the SPI MISO port. That's just the way SPI works.
13 *
14 * The source of the outgoing bits is the "dout" parameter and the
15 * destination of the input bits is the "din" parameter. Note that "dout"
16 * and "din" can point to the same memory location, in which case the
17 * input data overwrites the output data (since both are buffered by
18 * temporary variables, this is OK).
19 *
20 * This may be interrupted with Ctrl-C if "intr" is true, otherwise it will
21 * never return an error.
22 */
23static int e1000_spi_xfer(struct e1000_hw *hw, unsigned int bitlen,
York Sun4a598092013-04-01 11:29:11 -070024 const void *dout_mem, void *din_mem, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +000025{
26 const uint8_t *dout = dout_mem;
27 uint8_t *din = din_mem;
28
29 uint8_t mask = 0;
30 uint32_t eecd;
31 unsigned long i;
32
33 /* Pre-read the control register */
34 eecd = E1000_READ_REG(hw, EECD);
35
36 /* Iterate over each bit */
37 for (i = 0, mask = 0x80; i < bitlen; i++, mask = (mask >> 1)?:0x80) {
38 /* Check for interrupt */
39 if (intr && ctrlc())
40 return -1;
41
42 /* Determine the output bit */
43 if (dout && dout[i >> 3] & mask)
44 eecd |= E1000_EECD_DI;
45 else
46 eecd &= ~E1000_EECD_DI;
47
48 /* Write the output bit and wait 50us */
49 E1000_WRITE_REG(hw, EECD, eecd);
50 E1000_WRITE_FLUSH(hw);
51 udelay(50);
52
53 /* Poke the clock (waits 50us) */
54 e1000_raise_ee_clk(hw, &eecd);
55
56 /* Now read the input bit */
57 eecd = E1000_READ_REG(hw, EECD);
58 if (din) {
59 if (eecd & E1000_EECD_DO)
60 din[i >> 3] |= mask;
61 else
62 din[i >> 3] &= ~mask;
63 }
64
65 /* Poke the clock again (waits 50us) */
66 e1000_lower_ee_clk(hw, &eecd);
67 }
68
69 /* Now clear any remaining bits of the input */
70 if (din && (i & 7))
71 din[i >> 3] &= ~((mask << 1) - 1);
72
73 return 0;
74}
75
76#ifdef CONFIG_E1000_SPI_GENERIC
77static inline struct e1000_hw *e1000_hw_from_spi(struct spi_slave *spi)
78{
79 return container_of(spi, struct e1000_hw, spi);
80}
81
Kyle Moffett64b94dd2011-10-18 11:05:29 +000082struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
83 unsigned int max_hz, unsigned int mode)
84{
85 /* Find the right PCI device */
86 struct e1000_hw *hw = e1000_find_card(bus);
87 if (!hw) {
88 printf("ERROR: No such e1000 device: e1000#%u\n", bus);
89 return NULL;
90 }
91
92 /* Make sure it has an SPI chip */
93 if (hw->eeprom.type != e1000_eeprom_spi) {
Alban Bedelc1255dd2016-08-03 11:31:03 +020094 E1000_ERR(hw, "No attached SPI EEPROM found!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +000095 return NULL;
96 }
97
98 /* Argument sanity checks */
99 if (cs != 0) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200100 E1000_ERR(hw, "No such SPI chip: %u\n", cs);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000101 return NULL;
102 }
103 if (mode != SPI_MODE_0) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200104 E1000_ERR(hw, "Only SPI MODE-0 is supported!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000105 return NULL;
106 }
107
108 /* TODO: Use max_hz somehow */
109 E1000_DBG(hw->nic, "EEPROM SPI access requested\n");
110 return &hw->spi;
111}
112
113void spi_free_slave(struct spi_slave *spi)
114{
Anatolij Gustschin6711ee52011-12-20 02:29:03 +0000115 __maybe_unused struct e1000_hw *hw = e1000_hw_from_spi(spi);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000116 E1000_DBG(hw->nic, "EEPROM SPI access released\n");
117}
118
119int spi_claim_bus(struct spi_slave *spi)
120{
121 struct e1000_hw *hw = e1000_hw_from_spi(spi);
122
123 if (e1000_acquire_eeprom(hw)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200124 E1000_ERR(hw, "EEPROM SPI cannot be acquired!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000125 return -1;
126 }
127
128 return 0;
129}
130
131void spi_release_bus(struct spi_slave *spi)
132{
133 struct e1000_hw *hw = e1000_hw_from_spi(spi);
134 e1000_release_eeprom(hw);
135}
136
137/* Skinny wrapper around e1000_spi_xfer */
138int spi_xfer(struct spi_slave *spi, unsigned int bitlen,
139 const void *dout_mem, void *din_mem, unsigned long flags)
140{
141 struct e1000_hw *hw = e1000_hw_from_spi(spi);
142 int ret;
143
144 if (flags & SPI_XFER_BEGIN)
145 e1000_standby_eeprom(hw);
146
York Sun4a598092013-04-01 11:29:11 -0700147 ret = e1000_spi_xfer(hw, bitlen, dout_mem, din_mem, true);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000148
149 if (flags & SPI_XFER_END)
150 e1000_standby_eeprom(hw);
151
152 return ret;
153}
154
155#endif /* not CONFIG_E1000_SPI_GENERIC */
156
157#ifdef CONFIG_CMD_E1000
158
159/* The EEPROM opcodes */
160#define SPI_EEPROM_ENABLE_WR 0x06
161#define SPI_EEPROM_DISABLE_WR 0x04
162#define SPI_EEPROM_WRITE_STATUS 0x01
163#define SPI_EEPROM_READ_STATUS 0x05
164#define SPI_EEPROM_WRITE_PAGE 0x02
165#define SPI_EEPROM_READ_PAGE 0x03
166
167/* The EEPROM status bits */
168#define SPI_EEPROM_STATUS_BUSY 0x01
169#define SPI_EEPROM_STATUS_WREN 0x02
170
York Sun4a598092013-04-01 11:29:11 -0700171static int e1000_spi_eeprom_enable_wr(struct e1000_hw *hw, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000172{
173 u8 op[] = { SPI_EEPROM_ENABLE_WR };
174 e1000_standby_eeprom(hw);
175 return e1000_spi_xfer(hw, 8*sizeof(op), op, NULL, intr);
176}
177
178/*
179 * These have been tested to perform correctly, but they are not used by any
180 * of the EEPROM commands at this time.
181 */
Bin Mengd0d175f2015-11-16 01:19:18 -0800182static __maybe_unused int e1000_spi_eeprom_disable_wr(struct e1000_hw *hw,
183 bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000184{
185 u8 op[] = { SPI_EEPROM_DISABLE_WR };
186 e1000_standby_eeprom(hw);
187 return e1000_spi_xfer(hw, 8*sizeof(op), op, NULL, intr);
188}
189
Bin Mengd0d175f2015-11-16 01:19:18 -0800190static __maybe_unused int e1000_spi_eeprom_write_status(struct e1000_hw *hw,
191 u8 status, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000192{
193 u8 op[] = { SPI_EEPROM_WRITE_STATUS, status };
194 e1000_standby_eeprom(hw);
195 return e1000_spi_xfer(hw, 8*sizeof(op), op, NULL, intr);
196}
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000197
York Sun4a598092013-04-01 11:29:11 -0700198static int e1000_spi_eeprom_read_status(struct e1000_hw *hw, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000199{
200 u8 op[] = { SPI_EEPROM_READ_STATUS, 0 };
201 e1000_standby_eeprom(hw);
202 if (e1000_spi_xfer(hw, 8*sizeof(op), op, op, intr))
203 return -1;
204 return op[1];
205}
206
207static int e1000_spi_eeprom_write_page(struct e1000_hw *hw,
York Sun4a598092013-04-01 11:29:11 -0700208 const void *data, u16 off, u16 len, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000209{
210 u8 op[] = {
211 SPI_EEPROM_WRITE_PAGE,
212 (off >> (hw->eeprom.address_bits - 8)) & 0xff, off & 0xff
213 };
214
215 e1000_standby_eeprom(hw);
216
217 if (e1000_spi_xfer(hw, 8 + hw->eeprom.address_bits, op, NULL, intr))
218 return -1;
219 if (e1000_spi_xfer(hw, len << 3, data, NULL, intr))
220 return -1;
221
222 return 0;
223}
224
225static int e1000_spi_eeprom_read_page(struct e1000_hw *hw,
York Sun4a598092013-04-01 11:29:11 -0700226 void *data, u16 off, u16 len, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000227{
228 u8 op[] = {
229 SPI_EEPROM_READ_PAGE,
230 (off >> (hw->eeprom.address_bits - 8)) & 0xff, off & 0xff
231 };
232
233 e1000_standby_eeprom(hw);
234
235 if (e1000_spi_xfer(hw, 8 + hw->eeprom.address_bits, op, NULL, intr))
236 return -1;
237 if (e1000_spi_xfer(hw, len << 3, NULL, data, intr))
238 return -1;
239
240 return 0;
241}
242
York Sun4a598092013-04-01 11:29:11 -0700243static int e1000_spi_eeprom_poll_ready(struct e1000_hw *hw, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000244{
245 int status;
246 while ((status = e1000_spi_eeprom_read_status(hw, intr)) >= 0) {
247 if (!(status & SPI_EEPROM_STATUS_BUSY))
248 return 0;
249 }
250 return -1;
251}
252
253static int e1000_spi_eeprom_dump(struct e1000_hw *hw,
York Sun4a598092013-04-01 11:29:11 -0700254 void *data, u16 off, unsigned int len, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000255{
256 /* Interruptibly wait for the EEPROM to be ready */
257 if (e1000_spi_eeprom_poll_ready(hw, intr))
258 return -1;
259
260 /* Dump each page in sequence */
261 while (len) {
262 /* Calculate the data bytes on this page */
263 u16 pg_off = off & (hw->eeprom.page_size - 1);
264 u16 pg_len = hw->eeprom.page_size - pg_off;
265 if (pg_len > len)
266 pg_len = len;
267
268 /* Now dump the page */
269 if (e1000_spi_eeprom_read_page(hw, data, off, pg_len, intr))
270 return -1;
271
272 /* Otherwise go on to the next page */
273 len -= pg_len;
274 off += pg_len;
275 data += pg_len;
276 }
277
278 /* We're done! */
279 return 0;
280}
281
282static int e1000_spi_eeprom_program(struct e1000_hw *hw,
York Sun4a598092013-04-01 11:29:11 -0700283 const void *data, u16 off, u16 len, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000284{
285 /* Program each page in sequence */
286 while (len) {
287 /* Calculate the data bytes on this page */
288 u16 pg_off = off & (hw->eeprom.page_size - 1);
289 u16 pg_len = hw->eeprom.page_size - pg_off;
290 if (pg_len > len)
291 pg_len = len;
292
293 /* Interruptibly wait for the EEPROM to be ready */
294 if (e1000_spi_eeprom_poll_ready(hw, intr))
295 return -1;
296
297 /* Enable write access */
298 if (e1000_spi_eeprom_enable_wr(hw, intr))
299 return -1;
300
301 /* Now program the page */
302 if (e1000_spi_eeprom_write_page(hw, data, off, pg_len, intr))
303 return -1;
304
305 /* Otherwise go on to the next page */
306 len -= pg_len;
307 off += pg_len;
308 data += pg_len;
309 }
310
311 /* Wait for the last write to complete */
312 if (e1000_spi_eeprom_poll_ready(hw, intr))
313 return -1;
314
315 /* We're done! */
316 return 0;
317}
318
Simon Glassed38aef2020-05-10 11:40:03 -0600319static int do_e1000_spi_show(struct cmd_tbl *cmdtp, struct e1000_hw *hw,
320 int argc, char *const argv[])
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000321{
322 unsigned int length = 0;
323 u16 i, offset = 0;
324 u8 *buffer;
325 int err;
326
327 if (argc > 2) {
328 cmd_usage(cmdtp);
329 return 1;
330 }
331
332 /* Parse the offset and length */
333 if (argc >= 1)
334 offset = simple_strtoul(argv[0], NULL, 0);
335 if (argc == 2)
336 length = simple_strtoul(argv[1], NULL, 0);
337 else if (offset < (hw->eeprom.word_size << 1))
338 length = (hw->eeprom.word_size << 1) - offset;
339
340 /* Extra sanity checks */
341 if (!length) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200342 E1000_ERR(hw, "Requested zero-sized dump!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000343 return 1;
344 }
345 if ((0x10000 < length) || (0x10000 - length < offset)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200346 E1000_ERR(hw, "Can't dump past 0xFFFF!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000347 return 1;
348 }
349
350 /* Allocate a buffer to hold stuff */
351 buffer = malloc(length);
352 if (!buffer) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200353 E1000_ERR(hw, "Out of Memory!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000354 return 1;
355 }
356
357 /* Acquire the EEPROM and perform the dump */
358 if (e1000_acquire_eeprom(hw)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200359 E1000_ERR(hw, "EEPROM SPI cannot be acquired!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000360 free(buffer);
361 return 1;
362 }
York Sun4a598092013-04-01 11:29:11 -0700363 err = e1000_spi_eeprom_dump(hw, buffer, offset, length, true);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000364 e1000_release_eeprom(hw);
365 if (err) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200366 E1000_ERR(hw, "Interrupted!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000367 free(buffer);
368 return 1;
369 }
370
371 /* Now hexdump the result */
372 printf("%s: ===== Intel e1000 EEPROM (0x%04hX - 0x%04hX) =====",
Alban Bedelc1255dd2016-08-03 11:31:03 +0200373 hw->name, offset, offset + length - 1);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000374 for (i = 0; i < length; i++) {
375 if ((i & 0xF) == 0)
Alban Bedelc1255dd2016-08-03 11:31:03 +0200376 printf("\n%s: %04hX: ", hw->name, offset + i);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000377 else if ((i & 0xF) == 0x8)
378 printf(" ");
379 printf(" %02hx", buffer[i]);
380 }
381 printf("\n");
382
383 /* Success! */
384 free(buffer);
385 return 0;
386}
387
Simon Glassed38aef2020-05-10 11:40:03 -0600388static int do_e1000_spi_dump(struct cmd_tbl *cmdtp, struct e1000_hw *hw,
389 int argc, char *const argv[])
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000390{
391 unsigned int length;
392 u16 offset;
393 void *dest;
394
395 if (argc != 3) {
396 cmd_usage(cmdtp);
397 return 1;
398 }
399
400 /* Parse the arguments */
401 dest = (void *)simple_strtoul(argv[0], NULL, 16);
402 offset = simple_strtoul(argv[1], NULL, 0);
403 length = simple_strtoul(argv[2], NULL, 0);
404
405 /* Extra sanity checks */
406 if (!length) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200407 E1000_ERR(hw, "Requested zero-sized dump!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000408 return 1;
409 }
410 if ((0x10000 < length) || (0x10000 - length < offset)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200411 E1000_ERR(hw, "Can't dump past 0xFFFF!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000412 return 1;
413 }
414
415 /* Acquire the EEPROM */
416 if (e1000_acquire_eeprom(hw)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200417 E1000_ERR(hw, "EEPROM SPI cannot be acquired!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000418 return 1;
419 }
420
421 /* Perform the programming operation */
York Sun4a598092013-04-01 11:29:11 -0700422 if (e1000_spi_eeprom_dump(hw, dest, offset, length, true) < 0) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200423 E1000_ERR(hw, "Interrupted!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000424 e1000_release_eeprom(hw);
425 return 1;
426 }
427
428 e1000_release_eeprom(hw);
Alban Bedelc1255dd2016-08-03 11:31:03 +0200429 printf("%s: ===== EEPROM DUMP COMPLETE =====\n", hw->name);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000430 return 0;
431}
432
Simon Glassed38aef2020-05-10 11:40:03 -0600433static int do_e1000_spi_program(struct cmd_tbl *cmdtp, struct e1000_hw *hw,
434 int argc, char *const argv[])
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000435{
436 unsigned int length;
437 const void *source;
438 u16 offset;
439
440 if (argc != 3) {
441 cmd_usage(cmdtp);
442 return 1;
443 }
444
445 /* Parse the arguments */
446 source = (const void *)simple_strtoul(argv[0], NULL, 16);
447 offset = simple_strtoul(argv[1], NULL, 0);
448 length = simple_strtoul(argv[2], NULL, 0);
449
450 /* Acquire the EEPROM */
451 if (e1000_acquire_eeprom(hw)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200452 E1000_ERR(hw, "EEPROM SPI cannot be acquired!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000453 return 1;
454 }
455
456 /* Perform the programming operation */
York Sun4a598092013-04-01 11:29:11 -0700457 if (e1000_spi_eeprom_program(hw, source, offset, length, true) < 0) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200458 E1000_ERR(hw, "Interrupted!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000459 e1000_release_eeprom(hw);
460 return 1;
461 }
462
463 e1000_release_eeprom(hw);
Alban Bedelc1255dd2016-08-03 11:31:03 +0200464 printf("%s: ===== EEPROM PROGRAMMED =====\n", hw->name);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000465 return 0;
466}
467
Simon Glassed38aef2020-05-10 11:40:03 -0600468static int do_e1000_spi_checksum(struct cmd_tbl *cmdtp, struct e1000_hw *hw,
469 int argc, char *const argv[])
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000470{
Anatolij Gustschin6711ee52011-12-20 02:29:03 +0000471 uint16_t i, length, checksum = 0, checksum_reg;
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000472 uint16_t *buffer;
York Sun4a598092013-04-01 11:29:11 -0700473 bool upd;
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000474
475 if (argc == 0)
476 upd = 0;
477 else if ((argc == 1) && !strcmp(argv[0], "update"))
478 upd = 1;
479 else {
480 cmd_usage(cmdtp);
481 return 1;
482 }
483
484 /* Allocate a temporary buffer */
485 length = sizeof(uint16_t) * (EEPROM_CHECKSUM_REG + 1);
486 buffer = malloc(length);
487 if (!buffer) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200488 E1000_ERR(hw, "Unable to allocate EEPROM buffer!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000489 return 1;
490 }
491
492 /* Acquire the EEPROM */
493 if (e1000_acquire_eeprom(hw)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200494 E1000_ERR(hw, "EEPROM SPI cannot be acquired!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000495 return 1;
496 }
497
498 /* Read the EEPROM */
York Sun4a598092013-04-01 11:29:11 -0700499 if (e1000_spi_eeprom_dump(hw, buffer, 0, length, true) < 0) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200500 E1000_ERR(hw, "Interrupted!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000501 e1000_release_eeprom(hw);
502 return 1;
503 }
504
505 /* Compute the checksum and read the expected value */
506 for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
507 checksum += le16_to_cpu(buffer[i]);
508 checksum = ((uint16_t)EEPROM_SUM) - checksum;
509 checksum_reg = le16_to_cpu(buffer[i]);
510
511 /* Verify it! */
512 if (checksum_reg == checksum) {
513 printf("%s: INFO: EEPROM checksum is correct! (0x%04hx)\n",
Alban Bedelc1255dd2016-08-03 11:31:03 +0200514 hw->name, checksum);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000515 e1000_release_eeprom(hw);
516 return 0;
517 }
518
519 /* Hrm, verification failed, print an error */
Alban Bedelc1255dd2016-08-03 11:31:03 +0200520 E1000_ERR(hw, "EEPROM checksum is incorrect!\n");
521 E1000_ERR(hw, " ...register was 0x%04hx, calculated 0x%04hx\n",
522 checksum_reg, checksum);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000523
524 /* If they didn't ask us to update it, just return an error */
525 if (!upd) {
526 e1000_release_eeprom(hw);
527 return 1;
528 }
529
530 /* Ok, correct it! */
Alban Bedelc1255dd2016-08-03 11:31:03 +0200531 printf("%s: Reprogramming the EEPROM checksum...\n", hw->name);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000532 buffer[i] = cpu_to_le16(checksum);
533 if (e1000_spi_eeprom_program(hw, &buffer[i], i * sizeof(uint16_t),
York Sun4a598092013-04-01 11:29:11 -0700534 sizeof(uint16_t), true)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200535 E1000_ERR(hw, "Interrupted!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000536 e1000_release_eeprom(hw);
537 return 1;
538 }
539
540 e1000_release_eeprom(hw);
541 return 0;
542}
543
Simon Glassed38aef2020-05-10 11:40:03 -0600544int do_e1000_spi(struct cmd_tbl *cmdtp, struct e1000_hw *hw,
545 int argc, char *const argv[])
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000546{
547 if (argc < 1) {
548 cmd_usage(cmdtp);
549 return 1;
550 }
551
552 /* Make sure it has an SPI chip */
553 if (hw->eeprom.type != e1000_eeprom_spi) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200554 E1000_ERR(hw, "No attached SPI EEPROM found (%d)!\n",
555 hw->eeprom.type);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000556 return 1;
557 }
558
559 /* Check the eeprom sub-sub-command arguments */
560 if (!strcmp(argv[0], "show"))
561 return do_e1000_spi_show(cmdtp, hw, argc - 1, argv + 1);
562
563 if (!strcmp(argv[0], "dump"))
564 return do_e1000_spi_dump(cmdtp, hw, argc - 1, argv + 1);
565
566 if (!strcmp(argv[0], "program"))
567 return do_e1000_spi_program(cmdtp, hw, argc - 1, argv + 1);
568
569 if (!strcmp(argv[0], "checksum"))
570 return do_e1000_spi_checksum(cmdtp, hw, argc - 1, argv + 1);
571
572 cmd_usage(cmdtp);
573 return 1;
574}
575
576#endif /* not CONFIG_CMD_E1000 */