]> git.ipfire.org Git - people/ms/u-boot.git/blame - board/eltec/elppc/eepro100_srom.c
Add GPL-2.0+ SPDX-License-Identifier to source files
[people/ms/u-boot.git] / board / eltec / elppc / eepro100_srom.c
CommitLineData
217c9dad
WD
1/*
2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
4 *
1a459660 5 * SPDX-License-Identifier: GPL-2.0+
217c9dad
WD
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
e2d45e6f
WD
18extern int eepro100_write_eeprom (struct eth_device *dev,
19 int location, int addr_len,
20 unsigned short data);
217c9dad
WD
21
22/*----------------------------------------------------------------------------*/
23
24unsigned short eepro100_srom_checksum (unsigned short *sromdata)
25{
e2d45e6f
WD
26 unsigned short sum = 0;
27 unsigned int i;
28
29 for (i = 0; i < (EE_SIZE - 1); i++) {
30 sum += sromdata[i];
31 }
32 return (EE_CHECKSUM - sum);
217c9dad
WD
33}
34
35/*----------------------------------------------------------------------------*/
36
37int eepro100_srom_store (unsigned short *source)
38{
e2d45e6f
WD
39 int count;
40 struct eth_device onboard_dev;
41
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;
46
47 source[63] = eepro100_srom_checksum (source);
48
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;
217c9dad
WD
58}
59
60/*----------------------------------------------------------------------------*/
61
62#ifdef EEPRO100_SROM_CHECK
63
e2d45e6f 64extern int read_eeprom (struct eth_device *dev, int location, int addr_len);
217c9dad
WD
65
66void eepro100_srom_load (unsigned short *destination)
67{
e2d45e6f
WD
68 int count;
69 struct eth_device onboard_dev;
70
217c9dad 71#ifdef DEBUG
e2d45e6f
WD
72 int lr = 0;
73
74 printf ("eepro100_srom_download:\n");
217c9dad
WD
75#endif
76
e2d45e6f
WD
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;
217c9dad 81
e2d45e6f 82 memset (destination, 0x65, 128);
217c9dad 83
e2d45e6f
WD
84 for (count = 0; count < 0x40; count++) {
85 *destination++ = read_eeprom ((struct eth_device *) &onboard_dev,
86 count, EE_ADDR_BITS);
217c9dad 87#ifdef DEBUG
e2d45e6f
WD
88 printf ("%04x ", *(destination - 1));
89 if (lr++ == 7) {
90 printf ("\n");
91 lr = 0;
92 }
217c9dad 93#endif
e2d45e6f 94 }
217c9dad
WD
95}
96#endif /* EEPRO100_SROM_CHECK */
97
98/*----------------------------------------------------------------------------*/