wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 ELTEC Elektronik AG |
| 3 | * Frank Gottschling <fgottschling@eltec.de> |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Local network srom writing for first time run |
| 10 | */ |
| 11 | |
| 12 | /* includes */ |
| 13 | #include <common.h> |
| 14 | #include <pci.h> |
| 15 | #include <net.h> |
| 16 | #include "srom.h" |
| 17 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 18 | extern int eepro100_write_eeprom (struct eth_device *dev, |
| 19 | int location, int addr_len, |
| 20 | unsigned short data); |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 21 | |
| 22 | /*----------------------------------------------------------------------------*/ |
| 23 | |
| 24 | unsigned short eepro100_srom_checksum (unsigned short *sromdata) |
| 25 | { |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 26 | unsigned short sum = 0; |
| 27 | unsigned int i; |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 28 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 29 | for (i = 0; i < (EE_SIZE - 1); i++) { |
| 30 | sum += sromdata[i]; |
| 31 | } |
| 32 | return (EE_CHECKSUM - sum); |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | /*----------------------------------------------------------------------------*/ |
| 36 | |
| 37 | int eepro100_srom_store (unsigned short *source) |
| 38 | { |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 39 | int count; |
| 40 | struct eth_device onboard_dev; |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 41 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 42 | /* get onboard network iobase */ |
| 43 | pci_read_config_dword (PCI_BDF (0, 0x10, 0), PCI_BASE_ADDRESS_0, |
| 44 | (unsigned int *) &onboard_dev.iobase); |
| 45 | onboard_dev.iobase &= ~0xf; |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 46 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 47 | source[63] = eepro100_srom_checksum (source); |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 48 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 49 | for (count = 0; count < EE_SIZE; count++) { |
| 50 | if (eepro100_write_eeprom ((struct eth_device *) &onboard_dev, |
| 51 | count, EE_ADDR_BITS, |
| 52 | SROM_SHORT (source)) == -1) { |
| 53 | return -1; |
| 54 | } |
| 55 | source++; |
| 56 | } |
| 57 | return 0; |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /*----------------------------------------------------------------------------*/ |
| 61 | |
| 62 | #ifdef EEPRO100_SROM_CHECK |
| 63 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 64 | extern int read_eeprom (struct eth_device *dev, int location, int addr_len); |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 65 | |
| 66 | void eepro100_srom_load (unsigned short *destination) |
| 67 | { |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 68 | int count; |
| 69 | struct eth_device onboard_dev; |
| 70 | |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 71 | #ifdef DEBUG |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 72 | int lr = 0; |
| 73 | |
| 74 | printf ("eepro100_srom_download:\n"); |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 75 | #endif |
| 76 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 77 | /* get onboard network iobase */ |
| 78 | pci_read_config_dword (PCI_BDF (0, 0x10, 0), PCI_BASE_ADDRESS_0, |
| 79 | &onboard_dev.iobase); |
| 80 | onboard_dev.iobase &= ~0xf; |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 81 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 82 | memset (destination, 0x65, 128); |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 83 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 84 | for (count = 0; count < 0x40; count++) { |
| 85 | *destination++ = read_eeprom ((struct eth_device *) &onboard_dev, |
| 86 | count, EE_ADDR_BITS); |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 87 | #ifdef DEBUG |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 88 | printf ("%04x ", *(destination - 1)); |
| 89 | if (lr++ == 7) { |
| 90 | printf ("\n"); |
| 91 | lr = 0; |
| 92 | } |
| 93 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 94 | } |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 95 | } |
| 96 | #endif /* EEPRO100_SROM_CHECK */ |
| 97 | |
| 98 | /*----------------------------------------------------------------------------*/ |