root/drivers/staging/vt6655/srom.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. SROMbyReadEmbedded
  2. SROMvReadAllContents
  3. SROMvReadEtherAddress

   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 
  32 #include "upc.h"
  33 #include "tmacro.h"
  34 #include "mac.h"
  35 #include "srom.h"
  36 
  37 /*---------------------  Static Definitions -------------------------*/
  38 
  39 /*---------------------  Static Classes  ----------------------------*/
  40 
  41 /*---------------------  Static Variables  --------------------------*/
  42 
  43 /*---------------------  Static Functions  --------------------------*/
  44 
  45 /*---------------------  Export Variables  --------------------------*/
  46 
  47 /*---------------------  Export Functions  --------------------------*/
  48 
  49 /*
  50  * Description: Read a byte from EEPROM, by MAC I2C
  51  *
  52  * Parameters:
  53  *  In:
  54  *      iobase          - I/O base address
  55  *      byContntOffset  - address of EEPROM
  56  *  Out:
  57  *      none
  58  *
  59  * Return Value: data read
  60  *
  61  */
  62 unsigned char SROMbyReadEmbedded(void __iomem *iobase,
  63                                  unsigned char byContntOffset)
  64 {
  65         unsigned short wDelay, wNoACK;
  66         unsigned char byWait;
  67         unsigned char byData;
  68         unsigned char byOrg;
  69 
  70         byData = 0xFF;
  71         VNSvInPortB(iobase + MAC_REG_I2MCFG, &byOrg);
  72         /* turn off hardware retry for getting NACK */
  73         VNSvOutPortB(iobase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
  74         for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
  75                 VNSvOutPortB(iobase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
  76                 VNSvOutPortB(iobase + MAC_REG_I2MTGAD, byContntOffset);
  77 
  78                 /* issue read command */
  79                 VNSvOutPortB(iobase + MAC_REG_I2MCSR, I2MCSR_EEMR);
  80                 /* wait DONE be set */
  81                 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
  82                         VNSvInPortB(iobase + MAC_REG_I2MCSR, &byWait);
  83                         if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
  84                                 break;
  85                         PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
  86                 }
  87                 if ((wDelay < W_MAX_TIMEOUT) &&
  88                     (!(byWait & I2MCSR_NACK))) {
  89                         break;
  90                 }
  91         }
  92         VNSvInPortB(iobase + MAC_REG_I2MDIPT, &byData);
  93         VNSvOutPortB(iobase + MAC_REG_I2MCFG, byOrg);
  94         return byData;
  95 }
  96 
  97 /*
  98  * Description: Read all contents of eeprom to buffer
  99  *
 100  * Parameters:
 101  *  In:
 102  *      iobase          - I/O base address
 103  *  Out:
 104  *      pbyEepromRegs   - EEPROM content Buffer
 105  *
 106  * Return Value: none
 107  *
 108  */
 109 void SROMvReadAllContents(void __iomem *iobase, unsigned char *pbyEepromRegs)
 110 {
 111         int     ii;
 112 
 113         /* ii = Rom Address */
 114         for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
 115                 *pbyEepromRegs = SROMbyReadEmbedded(iobase,
 116                                                     (unsigned char)ii);
 117                 pbyEepromRegs++;
 118         }
 119 }
 120 
 121 /*
 122  * Description: Read Ethernet Address from eeprom to buffer
 123  *
 124  * Parameters:
 125  *  In:
 126  *      iobase          - I/O base address
 127  *  Out:
 128  *      pbyEtherAddress - Ethernet Address buffer
 129  *
 130  * Return Value: none
 131  *
 132  */
 133 void SROMvReadEtherAddress(void __iomem *iobase,
 134                            unsigned char *pbyEtherAddress)
 135 {
 136         unsigned char ii;
 137 
 138         /* ii = Rom Address */
 139         for (ii = 0; ii < ETH_ALEN; ii++) {
 140                 *pbyEtherAddress = SROMbyReadEmbedded(iobase, ii);
 141                 pbyEtherAddress++;
 142         }
 143 }

/* [<][>][^][v][top][bottom][index][help] */