blob: 05ba9c4472d271bc6aac186c6fb6081bcfae5a7d [file] [log] [blame]
wdenk217c9da2002-10-25 20:35:49 +00001/*
2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk217c9da2002-10-25 20:35:49 +00006 */
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 Denkd97cf332008-07-14 20:41:35 +020018extern int eepro100_write_eeprom (struct eth_device *dev,
19 int location, int addr_len,
20 unsigned short data);
wdenk217c9da2002-10-25 20:35:49 +000021
22/*----------------------------------------------------------------------------*/
23
24unsigned short eepro100_srom_checksum (unsigned short *sromdata)
25{
Wolfgang Denkd97cf332008-07-14 20:41:35 +020026 unsigned short sum = 0;
27 unsigned int i;
wdenk217c9da2002-10-25 20:35:49 +000028
Wolfgang Denkd97cf332008-07-14 20:41:35 +020029 for (i = 0; i < (EE_SIZE - 1); i++) {
30 sum += sromdata[i];
31 }
32 return (EE_CHECKSUM - sum);
wdenk217c9da2002-10-25 20:35:49 +000033}
34
35/*----------------------------------------------------------------------------*/
36
37int eepro100_srom_store (unsigned short *source)
38{
Wolfgang Denkd97cf332008-07-14 20:41:35 +020039 int count;
40 struct eth_device onboard_dev;
wdenk217c9da2002-10-25 20:35:49 +000041
Wolfgang Denkd97cf332008-07-14 20:41:35 +020042 /* 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;
wdenk217c9da2002-10-25 20:35:49 +000046
Wolfgang Denkd97cf332008-07-14 20:41:35 +020047 source[63] = eepro100_srom_checksum (source);
wdenk217c9da2002-10-25 20:35:49 +000048
Wolfgang Denkd97cf332008-07-14 20:41:35 +020049 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;
wdenk217c9da2002-10-25 20:35:49 +000058}
59
60/*----------------------------------------------------------------------------*/
61
62#ifdef EEPRO100_SROM_CHECK
63
Wolfgang Denkd97cf332008-07-14 20:41:35 +020064extern int read_eeprom (struct eth_device *dev, int location, int addr_len);
wdenk217c9da2002-10-25 20:35:49 +000065
66void eepro100_srom_load (unsigned short *destination)
67{
Wolfgang Denkd97cf332008-07-14 20:41:35 +020068 int count;
69 struct eth_device onboard_dev;
70
wdenk217c9da2002-10-25 20:35:49 +000071#ifdef DEBUG
Wolfgang Denkd97cf332008-07-14 20:41:35 +020072 int lr = 0;
73
74 printf ("eepro100_srom_download:\n");
wdenk217c9da2002-10-25 20:35:49 +000075#endif
76
Wolfgang Denkd97cf332008-07-14 20:41:35 +020077 /* 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;
wdenk217c9da2002-10-25 20:35:49 +000081
Wolfgang Denkd97cf332008-07-14 20:41:35 +020082 memset (destination, 0x65, 128);
wdenk217c9da2002-10-25 20:35:49 +000083
Wolfgang Denkd97cf332008-07-14 20:41:35 +020084 for (count = 0; count < 0x40; count++) {
85 *destination++ = read_eeprom ((struct eth_device *) &onboard_dev,
86 count, EE_ADDR_BITS);
wdenk217c9da2002-10-25 20:35:49 +000087#ifdef DEBUG
Wolfgang Denkd97cf332008-07-14 20:41:35 +020088 printf ("%04x ", *(destination - 1));
89 if (lr++ == 7) {
90 printf ("\n");
91 lr = 0;
92 }
wdenk217c9da2002-10-25 20:35:49 +000093#endif
Wolfgang Denkd97cf332008-07-14 20:41:35 +020094 }
wdenk217c9da2002-10-25 20:35:49 +000095}
96#endif /* EEPRO100_SROM_CHECK */
97
98/*----------------------------------------------------------------------------*/