eepro100_srom.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. * Local network srom writing for first time run
  25. */
  26. /* includes */
  27. #include <common.h>
  28. #include <pci.h>
  29. #include <net.h>
  30. #include "srom.h"
  31. extern int eepro100_write_eeprom (struct eth_device* dev,
  32. int location, int addr_len, unsigned short data);
  33. /*----------------------------------------------------------------------------*/
  34. unsigned short eepro100_srom_checksum (unsigned short *sromdata)
  35. {
  36. unsigned short sum = 0;
  37. unsigned int i;
  38. for (i = 0; i < (EE_SIZE-1); i++)
  39. {
  40. sum += sromdata[i];
  41. }
  42. return (EE_CHECKSUM - sum);
  43. }
  44. /*----------------------------------------------------------------------------*/
  45. int eepro100_srom_store (unsigned short *source)
  46. {
  47. int count;
  48. struct eth_device onboard_dev;
  49. /* get onboard network iobase */
  50. pci_read_config_dword(PCI_BDF(0,0x10,0), PCI_BASE_ADDRESS_0,
  51. (unsigned int *)&onboard_dev.iobase);
  52. onboard_dev.iobase &= ~0xf;
  53. source[63] = eepro100_srom_checksum (source);
  54. for (count=0; count < EE_SIZE; count++)
  55. {
  56. if ( eepro100_write_eeprom ((struct eth_device*)&onboard_dev,
  57. count, EE_ADDR_BITS, SROM_SHORT(source)) == -1 )
  58. return -1;
  59. source++;
  60. }
  61. return 0;
  62. }
  63. /*----------------------------------------------------------------------------*/
  64. #ifdef EEPRO100_SROM_CHECK
  65. extern int read_eeprom (struct eth_device* dev, int location, int addr_len);
  66. void eepro100_srom_load (unsigned short *destination)
  67. {
  68. int count;
  69. struct eth_device onboard_dev;
  70. #ifdef DEBUG
  71. int lr = 0;
  72. printf ("eepro100_srom_download:\n");
  73. #endif
  74. /* get onboard network iobase */
  75. pci_read_config_dword(PCI_BDF(0,0x10,0), PCI_BASE_ADDRESS_0,
  76. &onboard_dev.iobase);
  77. onboard_dev.iobase &= ~0xf;
  78. memset (destination, 0x65, 128);
  79. for (count=0; count < 0x40; count++)
  80. {
  81. *destination++ = read_eeprom (struct eth_device*)&onboard_dev,
  82. count, EE_ADDR_BITS);
  83. #ifdef DEBUG
  84. printf ("%04x ", *(destination - 1));
  85. if (lr++ == 7)
  86. {
  87. printf("\n");
  88. lr = 0;
  89. }
  90. #endif
  91. }
  92. }
  93. #endif /* EEPRO100_SROM_CHECK */
  94. /*----------------------------------------------------------------------------*/