srom.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  4. * All rights reserved.
  5. *
  6. * File: srom.c
  7. *
  8. * Purpose:Implement functions to access eeprom
  9. *
  10. * Author: Jerry Chen
  11. *
  12. * Date: Jan 29, 2003
  13. *
  14. * Functions:
  15. * SROMbyReadEmbedded - Embedded read eeprom via MAC
  16. * SROMbWriteEmbedded - Embedded write eeprom via MAC
  17. * SROMvRegBitsOn - Set Bits On in eeprom
  18. * SROMvRegBitsOff - Clear Bits Off in eeprom
  19. * SROMbIsRegBitsOn - Test if Bits On in eeprom
  20. * SROMbIsRegBitsOff - Test if Bits Off in eeprom
  21. * SROMvReadAllContents - Read all contents in eeprom
  22. * SROMvWriteAllContents - Write all contents in eeprom
  23. * SROMvReadEtherAddress - Read Ethernet Address in eeprom
  24. * SROMvWriteEtherAddress - Write Ethernet Address in eeprom
  25. * SROMvReadSubSysVenId - Read Sub_VID and Sub_SysId in eeprom
  26. * SROMbAutoLoad - Auto Load eeprom to MAC register
  27. *
  28. * Revision History:
  29. *
  30. */
  31. #include "upc.h"
  32. #include "tmacro.h"
  33. #include "mac.h"
  34. #include "srom.h"
  35. /*--------------------- Static Definitions -------------------------*/
  36. /*--------------------- Static Classes ----------------------------*/
  37. /*--------------------- Static Variables --------------------------*/
  38. /*--------------------- Static Functions --------------------------*/
  39. /*--------------------- Export Variables --------------------------*/
  40. /*--------------------- Export Functions --------------------------*/
  41. /*
  42. * Description: Read a byte from EEPROM, by MAC I2C
  43. *
  44. * Parameters:
  45. * In:
  46. * iobase - I/O base address
  47. * byContntOffset - address of EEPROM
  48. * Out:
  49. * none
  50. *
  51. * Return Value: data read
  52. *
  53. */
  54. unsigned char SROMbyReadEmbedded(void __iomem *iobase,
  55. unsigned char byContntOffset)
  56. {
  57. unsigned short wDelay, wNoACK;
  58. unsigned char byWait;
  59. unsigned char byData;
  60. unsigned char byOrg;
  61. byData = 0xFF;
  62. VNSvInPortB(iobase + MAC_REG_I2MCFG, &byOrg);
  63. /* turn off hardware retry for getting NACK */
  64. VNSvOutPortB(iobase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
  65. for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
  66. VNSvOutPortB(iobase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
  67. VNSvOutPortB(iobase + MAC_REG_I2MTGAD, byContntOffset);
  68. /* issue read command */
  69. VNSvOutPortB(iobase + MAC_REG_I2MCSR, I2MCSR_EEMR);
  70. /* wait DONE be set */
  71. for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
  72. VNSvInPortB(iobase + MAC_REG_I2MCSR, &byWait);
  73. if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
  74. break;
  75. PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
  76. }
  77. if ((wDelay < W_MAX_TIMEOUT) &&
  78. (!(byWait & I2MCSR_NACK))) {
  79. break;
  80. }
  81. }
  82. VNSvInPortB(iobase + MAC_REG_I2MDIPT, &byData);
  83. VNSvOutPortB(iobase + MAC_REG_I2MCFG, byOrg);
  84. return byData;
  85. }
  86. /*
  87. * Description: Read all contents of eeprom to buffer
  88. *
  89. * Parameters:
  90. * In:
  91. * iobase - I/O base address
  92. * Out:
  93. * pbyEepromRegs - EEPROM content Buffer
  94. *
  95. * Return Value: none
  96. *
  97. */
  98. void SROMvReadAllContents(void __iomem *iobase, unsigned char *pbyEepromRegs)
  99. {
  100. int ii;
  101. /* ii = Rom Address */
  102. for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
  103. *pbyEepromRegs = SROMbyReadEmbedded(iobase,
  104. (unsigned char)ii);
  105. pbyEepromRegs++;
  106. }
  107. }
  108. /*
  109. * Description: Read Ethernet Address from eeprom to buffer
  110. *
  111. * Parameters:
  112. * In:
  113. * iobase - I/O base address
  114. * Out:
  115. * pbyEtherAddress - Ethernet Address buffer
  116. *
  117. * Return Value: none
  118. *
  119. */
  120. void SROMvReadEtherAddress(void __iomem *iobase,
  121. unsigned char *pbyEtherAddress)
  122. {
  123. unsigned char ii;
  124. /* ii = Rom Address */
  125. for (ii = 0; ii < ETH_ALEN; ii++) {
  126. *pbyEtherAddress = SROMbyReadEmbedded(iobase, ii);
  127. pbyEtherAddress++;
  128. }
  129. }