blob: 52b3c79794aebd5f4d7aafd4f03a4376960da287 [file] [log] [blame]
Simon Glasscece9042015-08-19 09:33:38 -06001#include <common.h>
Simon Glassa73bda42015-11-08 23:47:45 -07002#include <console.h>
Kyle Moffett64b94dd2011-10-18 11:05:29 +00003#include "e1000.h"
Simon Glass9bc15642020-02-03 07:36:16 -07004#include <malloc.h>
Anatolij Gustschin6711ee52011-12-20 02:29:03 +00005#include <linux/compiler.h>
Kyle Moffett64b94dd2011-10-18 11:05:29 +00006
7/*-----------------------------------------------------------------------
8 * SPI transfer
9 *
10 * This writes "bitlen" bits out the SPI MOSI port and simultaneously clocks
11 * "bitlen" bits in the SPI MISO port. That's just the way SPI works.
12 *
13 * The source of the outgoing bits is the "dout" parameter and the
14 * destination of the input bits is the "din" parameter. Note that "dout"
15 * and "din" can point to the same memory location, in which case the
16 * input data overwrites the output data (since both are buffered by
17 * temporary variables, this is OK).
18 *
19 * This may be interrupted with Ctrl-C if "intr" is true, otherwise it will
20 * never return an error.
21 */
22static int e1000_spi_xfer(struct e1000_hw *hw, unsigned int bitlen,
York Sun4a598092013-04-01 11:29:11 -070023 const void *dout_mem, void *din_mem, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +000024{
25 const uint8_t *dout = dout_mem;
26 uint8_t *din = din_mem;
27
28 uint8_t mask = 0;
29 uint32_t eecd;
30 unsigned long i;
31
32 /* Pre-read the control register */
33 eecd = E1000_READ_REG(hw, EECD);
34
35 /* Iterate over each bit */
36 for (i = 0, mask = 0x80; i < bitlen; i++, mask = (mask >> 1)?:0x80) {
37 /* Check for interrupt */
38 if (intr && ctrlc())
39 return -1;
40
41 /* Determine the output bit */
42 if (dout && dout[i >> 3] & mask)
43 eecd |= E1000_EECD_DI;
44 else
45 eecd &= ~E1000_EECD_DI;
46
47 /* Write the output bit and wait 50us */
48 E1000_WRITE_REG(hw, EECD, eecd);
49 E1000_WRITE_FLUSH(hw);
50 udelay(50);
51
52 /* Poke the clock (waits 50us) */
53 e1000_raise_ee_clk(hw, &eecd);
54
55 /* Now read the input bit */
56 eecd = E1000_READ_REG(hw, EECD);
57 if (din) {
58 if (eecd & E1000_EECD_DO)
59 din[i >> 3] |= mask;
60 else
61 din[i >> 3] &= ~mask;
62 }
63
64 /* Poke the clock again (waits 50us) */
65 e1000_lower_ee_clk(hw, &eecd);
66 }
67
68 /* Now clear any remaining bits of the input */
69 if (din && (i & 7))
70 din[i >> 3] &= ~((mask << 1) - 1);
71
72 return 0;
73}
74
75#ifdef CONFIG_E1000_SPI_GENERIC
76static inline struct e1000_hw *e1000_hw_from_spi(struct spi_slave *spi)
77{
78 return container_of(spi, struct e1000_hw, spi);
79}
80
Kyle Moffett64b94dd2011-10-18 11:05:29 +000081struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
82 unsigned int max_hz, unsigned int mode)
83{
84 /* Find the right PCI device */
85 struct e1000_hw *hw = e1000_find_card(bus);
86 if (!hw) {
87 printf("ERROR: No such e1000 device: e1000#%u\n", bus);
88 return NULL;
89 }
90
91 /* Make sure it has an SPI chip */
92 if (hw->eeprom.type != e1000_eeprom_spi) {
Alban Bedelc1255dd2016-08-03 11:31:03 +020093 E1000_ERR(hw, "No attached SPI EEPROM found!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +000094 return NULL;
95 }
96
97 /* Argument sanity checks */
98 if (cs != 0) {
Alban Bedelc1255dd2016-08-03 11:31:03 +020099 E1000_ERR(hw, "No such SPI chip: %u\n", cs);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000100 return NULL;
101 }
102 if (mode != SPI_MODE_0) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200103 E1000_ERR(hw, "Only SPI MODE-0 is supported!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000104 return NULL;
105 }
106
107 /* TODO: Use max_hz somehow */
108 E1000_DBG(hw->nic, "EEPROM SPI access requested\n");
109 return &hw->spi;
110}
111
112void spi_free_slave(struct spi_slave *spi)
113{
Anatolij Gustschin6711ee52011-12-20 02:29:03 +0000114 __maybe_unused struct e1000_hw *hw = e1000_hw_from_spi(spi);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000115 E1000_DBG(hw->nic, "EEPROM SPI access released\n");
116}
117
118int spi_claim_bus(struct spi_slave *spi)
119{
120 struct e1000_hw *hw = e1000_hw_from_spi(spi);
121
122 if (e1000_acquire_eeprom(hw)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200123 E1000_ERR(hw, "EEPROM SPI cannot be acquired!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000124 return -1;
125 }
126
127 return 0;
128}
129
130void spi_release_bus(struct spi_slave *spi)
131{
132 struct e1000_hw *hw = e1000_hw_from_spi(spi);
133 e1000_release_eeprom(hw);
134}
135
136/* Skinny wrapper around e1000_spi_xfer */
137int spi_xfer(struct spi_slave *spi, unsigned int bitlen,
138 const void *dout_mem, void *din_mem, unsigned long flags)
139{
140 struct e1000_hw *hw = e1000_hw_from_spi(spi);
141 int ret;
142
143 if (flags & SPI_XFER_BEGIN)
144 e1000_standby_eeprom(hw);
145
York Sun4a598092013-04-01 11:29:11 -0700146 ret = e1000_spi_xfer(hw, bitlen, dout_mem, din_mem, true);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000147
148 if (flags & SPI_XFER_END)
149 e1000_standby_eeprom(hw);
150
151 return ret;
152}
153
154#endif /* not CONFIG_E1000_SPI_GENERIC */
155
156#ifdef CONFIG_CMD_E1000
157
158/* The EEPROM opcodes */
159#define SPI_EEPROM_ENABLE_WR 0x06
160#define SPI_EEPROM_DISABLE_WR 0x04
161#define SPI_EEPROM_WRITE_STATUS 0x01
162#define SPI_EEPROM_READ_STATUS 0x05
163#define SPI_EEPROM_WRITE_PAGE 0x02
164#define SPI_EEPROM_READ_PAGE 0x03
165
166/* The EEPROM status bits */
167#define SPI_EEPROM_STATUS_BUSY 0x01
168#define SPI_EEPROM_STATUS_WREN 0x02
169
York Sun4a598092013-04-01 11:29:11 -0700170static int e1000_spi_eeprom_enable_wr(struct e1000_hw *hw, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000171{
172 u8 op[] = { SPI_EEPROM_ENABLE_WR };
173 e1000_standby_eeprom(hw);
174 return e1000_spi_xfer(hw, 8*sizeof(op), op, NULL, intr);
175}
176
177/*
178 * These have been tested to perform correctly, but they are not used by any
179 * of the EEPROM commands at this time.
180 */
Bin Mengd0d175f2015-11-16 01:19:18 -0800181static __maybe_unused int e1000_spi_eeprom_disable_wr(struct e1000_hw *hw,
182 bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000183{
184 u8 op[] = { SPI_EEPROM_DISABLE_WR };
185 e1000_standby_eeprom(hw);
186 return e1000_spi_xfer(hw, 8*sizeof(op), op, NULL, intr);
187}
188
Bin Mengd0d175f2015-11-16 01:19:18 -0800189static __maybe_unused int e1000_spi_eeprom_write_status(struct e1000_hw *hw,
190 u8 status, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000191{
192 u8 op[] = { SPI_EEPROM_WRITE_STATUS, status };
193 e1000_standby_eeprom(hw);
194 return e1000_spi_xfer(hw, 8*sizeof(op), op, NULL, intr);
195}
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000196
York Sun4a598092013-04-01 11:29:11 -0700197static int e1000_spi_eeprom_read_status(struct e1000_hw *hw, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000198{
199 u8 op[] = { SPI_EEPROM_READ_STATUS, 0 };
200 e1000_standby_eeprom(hw);
201 if (e1000_spi_xfer(hw, 8*sizeof(op), op, op, intr))
202 return -1;
203 return op[1];
204}
205
206static int e1000_spi_eeprom_write_page(struct e1000_hw *hw,
York Sun4a598092013-04-01 11:29:11 -0700207 const void *data, u16 off, u16 len, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000208{
209 u8 op[] = {
210 SPI_EEPROM_WRITE_PAGE,
211 (off >> (hw->eeprom.address_bits - 8)) & 0xff, off & 0xff
212 };
213
214 e1000_standby_eeprom(hw);
215
216 if (e1000_spi_xfer(hw, 8 + hw->eeprom.address_bits, op, NULL, intr))
217 return -1;
218 if (e1000_spi_xfer(hw, len << 3, data, NULL, intr))
219 return -1;
220
221 return 0;
222}
223
224static int e1000_spi_eeprom_read_page(struct e1000_hw *hw,
York Sun4a598092013-04-01 11:29:11 -0700225 void *data, u16 off, u16 len, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000226{
227 u8 op[] = {
228 SPI_EEPROM_READ_PAGE,
229 (off >> (hw->eeprom.address_bits - 8)) & 0xff, off & 0xff
230 };
231
232 e1000_standby_eeprom(hw);
233
234 if (e1000_spi_xfer(hw, 8 + hw->eeprom.address_bits, op, NULL, intr))
235 return -1;
236 if (e1000_spi_xfer(hw, len << 3, NULL, data, intr))
237 return -1;
238
239 return 0;
240}
241
York Sun4a598092013-04-01 11:29:11 -0700242static int e1000_spi_eeprom_poll_ready(struct e1000_hw *hw, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000243{
244 int status;
245 while ((status = e1000_spi_eeprom_read_status(hw, intr)) >= 0) {
246 if (!(status & SPI_EEPROM_STATUS_BUSY))
247 return 0;
248 }
249 return -1;
250}
251
252static int e1000_spi_eeprom_dump(struct e1000_hw *hw,
York Sun4a598092013-04-01 11:29:11 -0700253 void *data, u16 off, unsigned int len, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000254{
255 /* Interruptibly wait for the EEPROM to be ready */
256 if (e1000_spi_eeprom_poll_ready(hw, intr))
257 return -1;
258
259 /* Dump each page in sequence */
260 while (len) {
261 /* Calculate the data bytes on this page */
262 u16 pg_off = off & (hw->eeprom.page_size - 1);
263 u16 pg_len = hw->eeprom.page_size - pg_off;
264 if (pg_len > len)
265 pg_len = len;
266
267 /* Now dump the page */
268 if (e1000_spi_eeprom_read_page(hw, data, off, pg_len, intr))
269 return -1;
270
271 /* Otherwise go on to the next page */
272 len -= pg_len;
273 off += pg_len;
274 data += pg_len;
275 }
276
277 /* We're done! */
278 return 0;
279}
280
281static int e1000_spi_eeprom_program(struct e1000_hw *hw,
York Sun4a598092013-04-01 11:29:11 -0700282 const void *data, u16 off, u16 len, bool intr)
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000283{
284 /* Program each page in sequence */
285 while (len) {
286 /* Calculate the data bytes on this page */
287 u16 pg_off = off & (hw->eeprom.page_size - 1);
288 u16 pg_len = hw->eeprom.page_size - pg_off;
289 if (pg_len > len)
290 pg_len = len;
291
292 /* Interruptibly wait for the EEPROM to be ready */
293 if (e1000_spi_eeprom_poll_ready(hw, intr))
294 return -1;
295
296 /* Enable write access */
297 if (e1000_spi_eeprom_enable_wr(hw, intr))
298 return -1;
299
300 /* Now program the page */
301 if (e1000_spi_eeprom_write_page(hw, data, off, pg_len, intr))
302 return -1;
303
304 /* Otherwise go on to the next page */
305 len -= pg_len;
306 off += pg_len;
307 data += pg_len;
308 }
309
310 /* Wait for the last write to complete */
311 if (e1000_spi_eeprom_poll_ready(hw, intr))
312 return -1;
313
314 /* We're done! */
315 return 0;
316}
317
318static int do_e1000_spi_show(cmd_tbl_t *cmdtp, struct e1000_hw *hw,
319 int argc, char * const argv[])
320{
321 unsigned int length = 0;
322 u16 i, offset = 0;
323 u8 *buffer;
324 int err;
325
326 if (argc > 2) {
327 cmd_usage(cmdtp);
328 return 1;
329 }
330
331 /* Parse the offset and length */
332 if (argc >= 1)
333 offset = simple_strtoul(argv[0], NULL, 0);
334 if (argc == 2)
335 length = simple_strtoul(argv[1], NULL, 0);
336 else if (offset < (hw->eeprom.word_size << 1))
337 length = (hw->eeprom.word_size << 1) - offset;
338
339 /* Extra sanity checks */
340 if (!length) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200341 E1000_ERR(hw, "Requested zero-sized dump!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000342 return 1;
343 }
344 if ((0x10000 < length) || (0x10000 - length < offset)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200345 E1000_ERR(hw, "Can't dump past 0xFFFF!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000346 return 1;
347 }
348
349 /* Allocate a buffer to hold stuff */
350 buffer = malloc(length);
351 if (!buffer) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200352 E1000_ERR(hw, "Out of Memory!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000353 return 1;
354 }
355
356 /* Acquire the EEPROM and perform the dump */
357 if (e1000_acquire_eeprom(hw)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200358 E1000_ERR(hw, "EEPROM SPI cannot be acquired!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000359 free(buffer);
360 return 1;
361 }
York Sun4a598092013-04-01 11:29:11 -0700362 err = e1000_spi_eeprom_dump(hw, buffer, offset, length, true);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000363 e1000_release_eeprom(hw);
364 if (err) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200365 E1000_ERR(hw, "Interrupted!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000366 free(buffer);
367 return 1;
368 }
369
370 /* Now hexdump the result */
371 printf("%s: ===== Intel e1000 EEPROM (0x%04hX - 0x%04hX) =====",
Alban Bedelc1255dd2016-08-03 11:31:03 +0200372 hw->name, offset, offset + length - 1);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000373 for (i = 0; i < length; i++) {
374 if ((i & 0xF) == 0)
Alban Bedelc1255dd2016-08-03 11:31:03 +0200375 printf("\n%s: %04hX: ", hw->name, offset + i);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000376 else if ((i & 0xF) == 0x8)
377 printf(" ");
378 printf(" %02hx", buffer[i]);
379 }
380 printf("\n");
381
382 /* Success! */
383 free(buffer);
384 return 0;
385}
386
387static int do_e1000_spi_dump(cmd_tbl_t *cmdtp, struct e1000_hw *hw,
388 int argc, char * const argv[])
389{
390 unsigned int length;
391 u16 offset;
392 void *dest;
393
394 if (argc != 3) {
395 cmd_usage(cmdtp);
396 return 1;
397 }
398
399 /* Parse the arguments */
400 dest = (void *)simple_strtoul(argv[0], NULL, 16);
401 offset = simple_strtoul(argv[1], NULL, 0);
402 length = simple_strtoul(argv[2], NULL, 0);
403
404 /* Extra sanity checks */
405 if (!length) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200406 E1000_ERR(hw, "Requested zero-sized dump!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000407 return 1;
408 }
409 if ((0x10000 < length) || (0x10000 - length < offset)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200410 E1000_ERR(hw, "Can't dump past 0xFFFF!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000411 return 1;
412 }
413
414 /* Acquire the EEPROM */
415 if (e1000_acquire_eeprom(hw)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200416 E1000_ERR(hw, "EEPROM SPI cannot be acquired!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000417 return 1;
418 }
419
420 /* Perform the programming operation */
York Sun4a598092013-04-01 11:29:11 -0700421 if (e1000_spi_eeprom_dump(hw, dest, offset, length, true) < 0) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200422 E1000_ERR(hw, "Interrupted!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000423 e1000_release_eeprom(hw);
424 return 1;
425 }
426
427 e1000_release_eeprom(hw);
Alban Bedelc1255dd2016-08-03 11:31:03 +0200428 printf("%s: ===== EEPROM DUMP COMPLETE =====\n", hw->name);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000429 return 0;
430}
431
432static int do_e1000_spi_program(cmd_tbl_t *cmdtp, struct e1000_hw *hw,
433 int argc, char * const argv[])
434{
435 unsigned int length;
436 const void *source;
437 u16 offset;
438
439 if (argc != 3) {
440 cmd_usage(cmdtp);
441 return 1;
442 }
443
444 /* Parse the arguments */
445 source = (const void *)simple_strtoul(argv[0], NULL, 16);
446 offset = simple_strtoul(argv[1], NULL, 0);
447 length = simple_strtoul(argv[2], NULL, 0);
448
449 /* Acquire the EEPROM */
450 if (e1000_acquire_eeprom(hw)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200451 E1000_ERR(hw, "EEPROM SPI cannot be acquired!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000452 return 1;
453 }
454
455 /* Perform the programming operation */
York Sun4a598092013-04-01 11:29:11 -0700456 if (e1000_spi_eeprom_program(hw, source, offset, length, true) < 0) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200457 E1000_ERR(hw, "Interrupted!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000458 e1000_release_eeprom(hw);
459 return 1;
460 }
461
462 e1000_release_eeprom(hw);
Alban Bedelc1255dd2016-08-03 11:31:03 +0200463 printf("%s: ===== EEPROM PROGRAMMED =====\n", hw->name);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000464 return 0;
465}
466
467static int do_e1000_spi_checksum(cmd_tbl_t *cmdtp, struct e1000_hw *hw,
468 int argc, char * const argv[])
469{
Anatolij Gustschin6711ee52011-12-20 02:29:03 +0000470 uint16_t i, length, checksum = 0, checksum_reg;
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000471 uint16_t *buffer;
York Sun4a598092013-04-01 11:29:11 -0700472 bool upd;
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000473
474 if (argc == 0)
475 upd = 0;
476 else if ((argc == 1) && !strcmp(argv[0], "update"))
477 upd = 1;
478 else {
479 cmd_usage(cmdtp);
480 return 1;
481 }
482
483 /* Allocate a temporary buffer */
484 length = sizeof(uint16_t) * (EEPROM_CHECKSUM_REG + 1);
485 buffer = malloc(length);
486 if (!buffer) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200487 E1000_ERR(hw, "Unable to allocate EEPROM buffer!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000488 return 1;
489 }
490
491 /* Acquire the EEPROM */
492 if (e1000_acquire_eeprom(hw)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200493 E1000_ERR(hw, "EEPROM SPI cannot be acquired!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000494 return 1;
495 }
496
497 /* Read the EEPROM */
York Sun4a598092013-04-01 11:29:11 -0700498 if (e1000_spi_eeprom_dump(hw, buffer, 0, length, true) < 0) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200499 E1000_ERR(hw, "Interrupted!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000500 e1000_release_eeprom(hw);
501 return 1;
502 }
503
504 /* Compute the checksum and read the expected value */
505 for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
506 checksum += le16_to_cpu(buffer[i]);
507 checksum = ((uint16_t)EEPROM_SUM) - checksum;
508 checksum_reg = le16_to_cpu(buffer[i]);
509
510 /* Verify it! */
511 if (checksum_reg == checksum) {
512 printf("%s: INFO: EEPROM checksum is correct! (0x%04hx)\n",
Alban Bedelc1255dd2016-08-03 11:31:03 +0200513 hw->name, checksum);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000514 e1000_release_eeprom(hw);
515 return 0;
516 }
517
518 /* Hrm, verification failed, print an error */
Alban Bedelc1255dd2016-08-03 11:31:03 +0200519 E1000_ERR(hw, "EEPROM checksum is incorrect!\n");
520 E1000_ERR(hw, " ...register was 0x%04hx, calculated 0x%04hx\n",
521 checksum_reg, checksum);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000522
523 /* If they didn't ask us to update it, just return an error */
524 if (!upd) {
525 e1000_release_eeprom(hw);
526 return 1;
527 }
528
529 /* Ok, correct it! */
Alban Bedelc1255dd2016-08-03 11:31:03 +0200530 printf("%s: Reprogramming the EEPROM checksum...\n", hw->name);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000531 buffer[i] = cpu_to_le16(checksum);
532 if (e1000_spi_eeprom_program(hw, &buffer[i], i * sizeof(uint16_t),
York Sun4a598092013-04-01 11:29:11 -0700533 sizeof(uint16_t), true)) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200534 E1000_ERR(hw, "Interrupted!\n");
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000535 e1000_release_eeprom(hw);
536 return 1;
537 }
538
539 e1000_release_eeprom(hw);
540 return 0;
541}
542
543int do_e1000_spi(cmd_tbl_t *cmdtp, struct e1000_hw *hw,
544 int argc, char * const argv[])
545{
546 if (argc < 1) {
547 cmd_usage(cmdtp);
548 return 1;
549 }
550
551 /* Make sure it has an SPI chip */
552 if (hw->eeprom.type != e1000_eeprom_spi) {
Alban Bedelc1255dd2016-08-03 11:31:03 +0200553 E1000_ERR(hw, "No attached SPI EEPROM found (%d)!\n",
554 hw->eeprom.type);
Kyle Moffett64b94dd2011-10-18 11:05:29 +0000555 return 1;
556 }
557
558 /* Check the eeprom sub-sub-command arguments */
559 if (!strcmp(argv[0], "show"))
560 return do_e1000_spi_show(cmdtp, hw, argc - 1, argv + 1);
561
562 if (!strcmp(argv[0], "dump"))
563 return do_e1000_spi_dump(cmdtp, hw, argc - 1, argv + 1);
564
565 if (!strcmp(argv[0], "program"))
566 return do_e1000_spi_program(cmdtp, hw, argc - 1, argv + 1);
567
568 if (!strcmp(argv[0], "checksum"))
569 return do_e1000_spi_checksum(cmdtp, hw, argc - 1, argv + 1);
570
571 cmd_usage(cmdtp);
572 return 1;
573}
574
575#endif /* not CONFIG_CMD_E1000 */