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