diff options
Diffstat (limited to 'drivers/staging/vt6655/srom.c')
-rw-r--r-- | drivers/staging/vt6655/srom.c | 269 |
1 files changed, 127 insertions, 142 deletions
diff --git a/drivers/staging/vt6655/srom.c b/drivers/staging/vt6655/srom.c index 6a0a232..eaddc33 100644 --- a/drivers/staging/vt6655/srom.c +++ b/drivers/staging/vt6655/srom.c @@ -60,9 +60,6 @@ /*--------------------- Export Functions --------------------------*/ - - - /* * Description: Read a byte from EEPROM, by MAC I2C * @@ -78,39 +75,38 @@ */ unsigned char SROMbyReadEmbedded(unsigned long dwIoBase, unsigned char byContntOffset) { - unsigned short wDelay, wNoACK; - unsigned char byWait; - unsigned char byData; - unsigned char byOrg; - - byData = 0xFF; - VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg); - /* turn off hardware retry for getting NACK */ - VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY))); - for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) { - VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID); - VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset); - - /* issue read command */ - VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMR); - /* wait DONE be set */ - for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) { - VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait); - if (byWait & (I2MCSR_DONE | I2MCSR_NACK)) - break; - PCAvDelayByIO(CB_DELAY_LOOP_WAIT); - } - if ((wDelay < W_MAX_TIMEOUT) && - ( !(byWait & I2MCSR_NACK))) { - break; - } - } - VNSvInPortB(dwIoBase + MAC_REG_I2MDIPT, &byData); - VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg); - return byData; + unsigned short wDelay, wNoACK; + unsigned char byWait; + unsigned char byData; + unsigned char byOrg; + + byData = 0xFF; + VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg); + /* turn off hardware retry for getting NACK */ + VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY))); + for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) { + VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID); + VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset); + + /* issue read command */ + VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMR); + /* wait DONE be set */ + for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) { + VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait); + if (byWait & (I2MCSR_DONE | I2MCSR_NACK)) + break; + PCAvDelayByIO(CB_DELAY_LOOP_WAIT); + } + if ((wDelay < W_MAX_TIMEOUT) && + (!(byWait & I2MCSR_NACK))) { + break; + } + } + VNSvInPortB(dwIoBase + MAC_REG_I2MDIPT, &byData); + VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg); + return byData; } - /* * Description: Write a byte to EEPROM, by MAC I2C * @@ -127,43 +123,42 @@ unsigned char SROMbyReadEmbedded(unsigned long dwIoBase, unsigned char byContntO */ bool SROMbWriteEmbedded(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byData) { - unsigned short wDelay, wNoACK; - unsigned char byWait; - - unsigned char byOrg; - - VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg); - /* turn off hardware retry for getting NACK */ - VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY))); - for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) { - VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID); - VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset); - VNSvOutPortB(dwIoBase + MAC_REG_I2MDOPT, byData); - - /* issue write command */ - VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMW); - /* wait DONE be set */ - for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) { - VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait); - if (byWait & (I2MCSR_DONE | I2MCSR_NACK)) - break; - PCAvDelayByIO(CB_DELAY_LOOP_WAIT); - } - - if ((wDelay < W_MAX_TIMEOUT) && - ( !(byWait & I2MCSR_NACK))) { - break; - } - } - if (wNoACK == W_MAX_I2CRETRY) { - VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg); - return false; - } - VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg); - return true; + unsigned short wDelay, wNoACK; + unsigned char byWait; + + unsigned char byOrg; + + VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg); + /* turn off hardware retry for getting NACK */ + VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY))); + for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) { + VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID); + VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset); + VNSvOutPortB(dwIoBase + MAC_REG_I2MDOPT, byData); + + /* issue write command */ + VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMW); + /* wait DONE be set */ + for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) { + VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait); + if (byWait & (I2MCSR_DONE | I2MCSR_NACK)) + break; + PCAvDelayByIO(CB_DELAY_LOOP_WAIT); + } + + if ((wDelay < W_MAX_TIMEOUT) && + (!(byWait & I2MCSR_NACK))) { + break; + } + } + if (wNoACK == W_MAX_I2CRETRY) { + VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg); + return false; + } + VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg); + return true; } - /* * Description: Turn bits on in eeprom * @@ -180,13 +175,12 @@ bool SROMbWriteEmbedded(unsigned long dwIoBase, unsigned char byContntOffset, un */ void SROMvRegBitsOn(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byBits) { - unsigned char byOrgData; + unsigned char byOrgData; - byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset); - SROMbWriteEmbedded(dwIoBase, byContntOffset,(unsigned char)(byOrgData | byBits)); + byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset); + SROMbWriteEmbedded(dwIoBase, byContntOffset, (unsigned char)(byOrgData | byBits)); } - /* * Description: Turn bits off in eeprom * @@ -201,13 +195,12 @@ void SROMvRegBitsOn(unsigned long dwIoBase, unsigned char byContntOffset, unsign */ void SROMvRegBitsOff(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byBits) { - unsigned char byOrgData; + unsigned char byOrgData; - byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset); - SROMbWriteEmbedded(dwIoBase, byContntOffset,(unsigned char)(byOrgData & (~byBits))); + byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset); + SROMbWriteEmbedded(dwIoBase, byContntOffset, (unsigned char)(byOrgData & (~byBits))); } - /* * Description: Test if bits on in eeprom * @@ -224,13 +217,12 @@ void SROMvRegBitsOff(unsigned long dwIoBase, unsigned char byContntOffset, unsig */ bool SROMbIsRegBitsOn(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byTestBits) { - unsigned char byOrgData; + unsigned char byOrgData; - byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset); - return (byOrgData & byTestBits) == byTestBits; + byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset); + return (byOrgData & byTestBits) == byTestBits; } - /* * Description: Test if bits off in eeprom * @@ -247,13 +239,12 @@ bool SROMbIsRegBitsOn(unsigned long dwIoBase, unsigned char byContntOffset, unsi */ bool SROMbIsRegBitsOff(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byTestBits) { - unsigned char byOrgData; + unsigned char byOrgData; - byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset); - return !(byOrgData & byTestBits); + byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset); + return !(byOrgData & byTestBits); } - /* * Description: Read all contents of eeprom to buffer * @@ -268,16 +259,15 @@ bool SROMbIsRegBitsOff(unsigned long dwIoBase, unsigned char byContntOffset, uns */ void SROMvReadAllContents(unsigned long dwIoBase, unsigned char *pbyEepromRegs) { - int ii; + int ii; - /* ii = Rom Address */ - for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) { - *pbyEepromRegs = SROMbyReadEmbedded(dwIoBase,(unsigned char) ii); - pbyEepromRegs++; - } + /* ii = Rom Address */ + for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) { + *pbyEepromRegs = SROMbyReadEmbedded(dwIoBase, (unsigned char)ii); + pbyEepromRegs++; + } } - /* * Description: Write all contents of buffer to eeprom * @@ -293,16 +283,15 @@ void SROMvReadAllContents(unsigned long dwIoBase, unsigned char *pbyEepromRegs) */ void SROMvWriteAllContents(unsigned long dwIoBase, unsigned char *pbyEepromRegs) { - int ii; + int ii; - /* ii = Rom Address */ - for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) { - SROMbWriteEmbedded(dwIoBase,(unsigned char) ii, *pbyEepromRegs); - pbyEepromRegs++; - } + /* ii = Rom Address */ + for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) { + SROMbWriteEmbedded(dwIoBase, (unsigned char)ii, *pbyEepromRegs); + pbyEepromRegs++; + } } - /* * Description: Read Ethernet Address from eeprom to buffer * @@ -317,16 +306,15 @@ void SROMvWriteAllContents(unsigned long dwIoBase, unsigned char *pbyEepromRegs) */ void SROMvReadEtherAddress(unsigned long dwIoBase, unsigned char *pbyEtherAddress) { - unsigned char ii; + unsigned char ii; - /* ii = Rom Address */ - for (ii = 0; ii < ETH_ALEN; ii++) { - *pbyEtherAddress = SROMbyReadEmbedded(dwIoBase, ii); - pbyEtherAddress++; - } + /* ii = Rom Address */ + for (ii = 0; ii < ETH_ALEN; ii++) { + *pbyEtherAddress = SROMbyReadEmbedded(dwIoBase, ii); + pbyEtherAddress++; + } } - /* * Description: Write Ethernet Address from buffer to eeprom * @@ -342,16 +330,15 @@ void SROMvReadEtherAddress(unsigned long dwIoBase, unsigned char *pbyEtherAddres */ void SROMvWriteEtherAddress(unsigned long dwIoBase, unsigned char *pbyEtherAddress) { - unsigned char ii; + unsigned char ii; - /* ii = Rom Address */ - for (ii = 0; ii < ETH_ALEN; ii++) { - SROMbWriteEmbedded(dwIoBase, ii, *pbyEtherAddress); - pbyEtherAddress++; - } + /* ii = Rom Address */ + for (ii = 0; ii < ETH_ALEN; ii++) { + SROMbWriteEmbedded(dwIoBase, ii, *pbyEtherAddress); + pbyEtherAddress++; + } } - /* * Description: Read Sub_VID and Sub_SysId from eeprom to buffer * @@ -366,15 +353,15 @@ void SROMvWriteEtherAddress(unsigned long dwIoBase, unsigned char *pbyEtherAddre */ void SROMvReadSubSysVenId(unsigned long dwIoBase, unsigned long *pdwSubSysVenId) { - unsigned char *pbyData; - - pbyData = (unsigned char *)pdwSubSysVenId; - /* sub vendor */ - *pbyData = SROMbyReadEmbedded(dwIoBase, 6); - *(pbyData+1) = SROMbyReadEmbedded(dwIoBase, 7); - /* sub system */ - *(pbyData+2) = SROMbyReadEmbedded(dwIoBase, 8); - *(pbyData+3) = SROMbyReadEmbedded(dwIoBase, 9); + unsigned char *pbyData; + + pbyData = (unsigned char *)pdwSubSysVenId; + /* sub vendor */ + *pbyData = SROMbyReadEmbedded(dwIoBase, 6); + *(pbyData+1) = SROMbyReadEmbedded(dwIoBase, 7); + /* sub system */ + *(pbyData+2) = SROMbyReadEmbedded(dwIoBase, 8); + *(pbyData+3) = SROMbyReadEmbedded(dwIoBase, 9); } /* @@ -391,30 +378,28 @@ void SROMvReadSubSysVenId(unsigned long dwIoBase, unsigned long *pdwSubSysVenId) */ bool SROMbAutoLoad(unsigned long dwIoBase) { - unsigned char byWait; - int ii; + unsigned char byWait; + int ii; - unsigned char byOrg; + unsigned char byOrg; - VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg); - /* turn on hardware retry */ - VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg | I2MCFG_NORETRY)); + VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg); + /* turn on hardware retry */ + VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg | I2MCFG_NORETRY)); - MACvRegBitsOn(dwIoBase, MAC_REG_I2MCSR, I2MCSR_AUTOLD); + MACvRegBitsOn(dwIoBase, MAC_REG_I2MCSR, I2MCSR_AUTOLD); - /* ii = Rom Address */ - for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) { - MACvTimer0MicroSDelay(dwIoBase, CB_EEPROM_READBYTE_WAIT); - VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait); - if ( !(byWait & I2MCSR_AUTOLD)) - break; - } + /* ii = Rom Address */ + for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) { + MACvTimer0MicroSDelay(dwIoBase, CB_EEPROM_READBYTE_WAIT); + VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait); + if (!(byWait & I2MCSR_AUTOLD)) + break; + } - VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg); + VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg); - if (ii == EEP_MAX_CONTEXT_SIZE) - return false; - return true; + if (ii == EEP_MAX_CONTEXT_SIZE) + return false; + return true; } - - |