brintos

brintos / linux-shallow public Read only

0
0
Text · 3.6 KiB · e805565 Raw
140 lines · c
1// SPDX-License-Identifier: GPL-2.0+2/*3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.4 * All rights reserved.5 *6 * Purpose:Implement functions to access eeprom7 *8 * Author: Jerry Chen9 *10 * Date: Jan 29, 200311 *12 * Functions:13 *      SROMbyReadEmbedded - Embedded read eeprom via MAC14 *      SROMbWriteEmbedded - Embedded write eeprom via MAC15 *      SROMvRegBitsOn - Set Bits On in eeprom16 *      SROMvRegBitsOff - Clear Bits Off in eeprom17 *      SROMbIsRegBitsOn - Test if Bits On in eeprom18 *      SROMbIsRegBitsOff - Test if Bits Off in eeprom19 *      SROMvReadAllContents - Read all contents in eeprom20 *      SROMvWriteAllContents - Write all contents in eeprom21 *      SROMvReadEtherAddress - Read Ethernet Address in eeprom22 *      SROMvWriteEtherAddress - Write Ethernet Address in eeprom23 *      SROMvReadSubSysVenId - Read Sub_VID and Sub_SysId in eeprom24 *      SROMbAutoLoad - Auto Load eeprom to MAC register25 *26 * Revision History:27 *28 */29 30#include "device.h"31#include "mac.h"32#include "srom.h"33 34/*---------------------  Static Definitions -------------------------*/35 36/*---------------------  Static Classes  ----------------------------*/37 38/*---------------------  Static Variables  --------------------------*/39 40/*---------------------  Static Functions  --------------------------*/41 42/*---------------------  Export Variables  --------------------------*/43 44/*---------------------  Export Functions  --------------------------*/45 46/*47 * Description: Read a byte from EEPROM, by MAC I2C48 *49 * Parameters:50 *  In:51 *      iobase          - I/O base address52 *      contnt_offset  - address of EEPROM53 *  Out:54 *      none55 *56 * Return Value: data read57 *58 */59unsigned char SROMbyReadEmbedded(void __iomem *iobase,60				 unsigned char contnt_offset)61{62	unsigned short wDelay, wNoACK;63	unsigned char byWait;64	unsigned char byData;65	unsigned char byOrg;66 67	byOrg = ioread8(iobase + MAC_REG_I2MCFG);68	/* turn off hardware retry for getting NACK */69	iowrite8(byOrg & (~I2MCFG_NORETRY), iobase + MAC_REG_I2MCFG);70	for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {71		iowrite8(EEP_I2C_DEV_ID, iobase + MAC_REG_I2MTGID);72		iowrite8(contnt_offset, iobase + MAC_REG_I2MTGAD);73 74		/* issue read command */75		iowrite8(I2MCSR_EEMR, iobase + MAC_REG_I2MCSR);76		/* wait DONE be set */77		for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {78			byWait = ioread8(iobase + MAC_REG_I2MCSR);79			if (byWait & (I2MCSR_DONE | I2MCSR_NACK))80				break;81			udelay(CB_DELAY_LOOP_WAIT);82		}83		if ((wDelay < W_MAX_TIMEOUT) &&84		    (!(byWait & I2MCSR_NACK))) {85			break;86		}87	}88	byData = ioread8(iobase + MAC_REG_I2MDIPT);89	iowrite8(byOrg, iobase + MAC_REG_I2MCFG);90	return byData;91}92 93/*94 * Description: Read all contents of eeprom to buffer95 *96 * Parameters:97 *  In:98 *      iobase          - I/O base address99 *  Out:100 *      pbyEepromRegs   - EEPROM content Buffer101 *102 * Return Value: none103 *104 */105void SROMvReadAllContents(void __iomem *iobase, unsigned char *pbyEepromRegs)106{107	int     ii;108 109	/* ii = Rom Address */110	for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {111		*pbyEepromRegs = SROMbyReadEmbedded(iobase,112						    (unsigned char)ii);113		pbyEepromRegs++;114	}115}116 117/*118 * Description: Read Ethernet Address from eeprom to buffer119 *120 * Parameters:121 *  In:122 *      iobase          - I/O base address123 *  Out:124 *      pbyEtherAddress - Ethernet Address buffer125 *126 * Return Value: none127 *128 */129void SROMvReadEtherAddress(void __iomem *iobase,130			   unsigned char *pbyEtherAddress)131{132	unsigned char ii;133 134	/* ii = Rom Address */135	for (ii = 0; ii < ETH_ALEN; ii++) {136		*pbyEtherAddress = SROMbyReadEmbedded(iobase, ii);137		pbyEtherAddress++;138	}139}140