srom.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * File: srom.c
  20. *
  21. * Purpose:Implement functions to access eeprom
  22. *
  23. * Author: Jerry Chen
  24. *
  25. * Date: Jan 29, 2003
  26. *
  27. * Functions:
  28. * SROMbyReadEmbedded - Embedded read eeprom via MAC
  29. * SROMbWriteEmbedded - Embedded write eeprom via MAC
  30. * SROMvRegBitsOn - Set Bits On in eeprom
  31. * SROMvRegBitsOff - Clear Bits Off in eeprom
  32. * SROMbIsRegBitsOn - Test if Bits On in eeprom
  33. * SROMbIsRegBitsOff - Test if Bits Off in eeprom
  34. * SROMvReadAllContents - Read all contents in eeprom
  35. * SROMvWriteAllContents - Write all contents in eeprom
  36. * SROMvReadEtherAddress - Read Ethernet Address in eeprom
  37. * SROMvWriteEtherAddress - Write Ethernet Address in eeprom
  38. * SROMvReadSubSysVenId - Read Sub_VID and Sub_SysId in eeprom
  39. * SROMbAutoLoad - Auto Load eeprom to MAC register
  40. *
  41. * Revision History:
  42. *
  43. */
  44. #include "upc.h"
  45. #include "tmacro.h"
  46. #include "mac.h"
  47. #include "srom.h"
  48. /*--------------------- Static Definitions -------------------------*/
  49. /*--------------------- Static Classes ----------------------------*/
  50. /*--------------------- Static Variables --------------------------*/
  51. /*--------------------- Static Functions --------------------------*/
  52. /*--------------------- Export Variables --------------------------*/
  53. /*--------------------- Export Functions --------------------------*/
  54. /*
  55. * Description: Read a byte from EEPROM, by MAC I2C
  56. *
  57. * Parameters:
  58. * In:
  59. * dwIoBase - I/O base address
  60. * byContntOffset - address of EEPROM
  61. * Out:
  62. * none
  63. *
  64. * Return Value: data read
  65. *
  66. */
  67. unsigned char SROMbyReadEmbedded(void __iomem *dwIoBase, unsigned char byContntOffset)
  68. {
  69. unsigned short wDelay, wNoACK;
  70. unsigned char byWait;
  71. unsigned char byData;
  72. unsigned char byOrg;
  73. byData = 0xFF;
  74. VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
  75. /* turn off hardware retry for getting NACK */
  76. VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
  77. for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
  78. VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
  79. VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
  80. /* issue read command */
  81. VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMR);
  82. /* wait DONE be set */
  83. for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
  84. VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
  85. if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
  86. break;
  87. PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
  88. }
  89. if ((wDelay < W_MAX_TIMEOUT) &&
  90. (!(byWait & I2MCSR_NACK))) {
  91. break;
  92. }
  93. }
  94. VNSvInPortB(dwIoBase + MAC_REG_I2MDIPT, &byData);
  95. VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
  96. return byData;
  97. }
  98. /*
  99. * Description: Read all contents of eeprom to buffer
  100. *
  101. * Parameters:
  102. * In:
  103. * dwIoBase - I/O base address
  104. * Out:
  105. * pbyEepromRegs - EEPROM content Buffer
  106. *
  107. * Return Value: none
  108. *
  109. */
  110. void SROMvReadAllContents(void __iomem *dwIoBase, unsigned char *pbyEepromRegs)
  111. {
  112. int ii;
  113. /* ii = Rom Address */
  114. for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
  115. *pbyEepromRegs = SROMbyReadEmbedded(dwIoBase, (unsigned char)ii);
  116. pbyEepromRegs++;
  117. }
  118. }
  119. /*
  120. * Description: Read Ethernet Address from eeprom to buffer
  121. *
  122. * Parameters:
  123. * In:
  124. * dwIoBase - I/O base address
  125. * Out:
  126. * pbyEtherAddress - Ethernet Address buffer
  127. *
  128. * Return Value: none
  129. *
  130. */
  131. void SROMvReadEtherAddress(void __iomem *dwIoBase, unsigned char *pbyEtherAddress)
  132. {
  133. unsigned char ii;
  134. /* ii = Rom Address */
  135. for (ii = 0; ii < ETH_ALEN; ii++) {
  136. *pbyEtherAddress = SROMbyReadEmbedded(dwIoBase, ii);
  137. pbyEtherAddress++;
  138. }
  139. }