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 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * Local network srom writing for first time run |
| 26 | */ |
| 27 | |
| 28 | /* includes */ |
| 29 | #include <common.h> |
| 30 | #include <pci.h> |
| 31 | #include <net.h> |
| 32 | #include "srom.h" |
| 33 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 34 | extern int eepro100_write_eeprom (struct eth_device *dev, |
| 35 | int location, int addr_len, |
| 36 | unsigned short data); |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 37 | |
| 38 | /*----------------------------------------------------------------------------*/ |
| 39 | |
| 40 | unsigned short eepro100_srom_checksum (unsigned short *sromdata) |
| 41 | { |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 42 | unsigned short sum = 0; |
| 43 | unsigned int i; |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 44 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 45 | for (i = 0; i < (EE_SIZE - 1); i++) { |
| 46 | sum += sromdata[i]; |
| 47 | } |
| 48 | return (EE_CHECKSUM - sum); |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /*----------------------------------------------------------------------------*/ |
| 52 | |
| 53 | int eepro100_srom_store (unsigned short *source) |
| 54 | { |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 55 | int count; |
| 56 | struct eth_device onboard_dev; |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 57 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 58 | /* get onboard network iobase */ |
| 59 | pci_read_config_dword (PCI_BDF (0, 0x10, 0), PCI_BASE_ADDRESS_0, |
| 60 | (unsigned int *) &onboard_dev.iobase); |
| 61 | onboard_dev.iobase &= ~0xf; |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 62 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 63 | source[63] = eepro100_srom_checksum (source); |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 64 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 65 | for (count = 0; count < EE_SIZE; count++) { |
| 66 | if (eepro100_write_eeprom ((struct eth_device *) &onboard_dev, |
| 67 | count, EE_ADDR_BITS, |
| 68 | SROM_SHORT (source)) == -1) { |
| 69 | return -1; |
| 70 | } |
| 71 | source++; |
| 72 | } |
| 73 | return 0; |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /*----------------------------------------------------------------------------*/ |
| 77 | |
| 78 | #ifdef EEPRO100_SROM_CHECK |
| 79 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 80 | extern int read_eeprom (struct eth_device *dev, int location, int addr_len); |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 81 | |
| 82 | void eepro100_srom_load (unsigned short *destination) |
| 83 | { |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 84 | int count; |
| 85 | struct eth_device onboard_dev; |
| 86 | |
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 | int lr = 0; |
| 89 | |
| 90 | printf ("eepro100_srom_download:\n"); |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 91 | #endif |
| 92 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 93 | /* get onboard network iobase */ |
| 94 | pci_read_config_dword (PCI_BDF (0, 0x10, 0), PCI_BASE_ADDRESS_0, |
| 95 | &onboard_dev.iobase); |
| 96 | onboard_dev.iobase &= ~0xf; |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 97 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 98 | memset (destination, 0x65, 128); |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 99 | |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 100 | for (count = 0; count < 0x40; count++) { |
| 101 | *destination++ = read_eeprom ((struct eth_device *) &onboard_dev, |
| 102 | count, EE_ADDR_BITS); |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 103 | #ifdef DEBUG |
Wolfgang Denk | e2d45e6 | 2008-07-14 20:41:35 +0200 | [diff] [blame] | 104 | printf ("%04x ", *(destination - 1)); |
| 105 | if (lr++ == 7) { |
| 106 | printf ("\n"); |
| 107 | lr = 0; |
| 108 | } |
| 109 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 110 | } |
wdenk | 217c9da | 2002-10-25 20:35:49 +0000 | [diff] [blame] | 111 | } |
| 112 | #endif /* EEPRO100_SROM_CHECK */ |
| 113 | |
| 114 | /*----------------------------------------------------------------------------*/ |