xref: /openbmc/linux/drivers/staging/vt6655/srom.c (revision 6a832649)
1d7c43082SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0+
25449c685SForest Bond /*
35449c685SForest Bond  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
45449c685SForest Bond  * All rights reserved.
55449c685SForest Bond  *
65449c685SForest Bond  * Purpose:Implement functions to access eeprom
75449c685SForest Bond  *
85449c685SForest Bond  * Author: Jerry Chen
95449c685SForest Bond  *
105449c685SForest Bond  * Date: Jan 29, 2003
115449c685SForest Bond  *
125449c685SForest Bond  * Functions:
135449c685SForest Bond  *      SROMbyReadEmbedded - Embedded read eeprom via MAC
145449c685SForest Bond  *      SROMbWriteEmbedded - Embedded write eeprom via MAC
155449c685SForest Bond  *      SROMvRegBitsOn - Set Bits On in eeprom
165449c685SForest Bond  *      SROMvRegBitsOff - Clear Bits Off in eeprom
175449c685SForest Bond  *      SROMbIsRegBitsOn - Test if Bits On in eeprom
185449c685SForest Bond  *      SROMbIsRegBitsOff - Test if Bits Off in eeprom
195449c685SForest Bond  *      SROMvReadAllContents - Read all contents in eeprom
205449c685SForest Bond  *      SROMvWriteAllContents - Write all contents in eeprom
215449c685SForest Bond  *      SROMvReadEtherAddress - Read Ethernet Address in eeprom
225449c685SForest Bond  *      SROMvWriteEtherAddress - Write Ethernet Address in eeprom
235449c685SForest Bond  *      SROMvReadSubSysVenId - Read Sub_VID and Sub_SysId in eeprom
245449c685SForest Bond  *      SROMbAutoLoad - Auto Load eeprom to MAC register
255449c685SForest Bond  *
265449c685SForest Bond  * Revision History:
275449c685SForest Bond  *
285449c685SForest Bond  */
295449c685SForest Bond 
30f551dc6eSPhilipp Hortmann #include "device.h"
315449c685SForest Bond #include "mac.h"
325449c685SForest Bond #include "srom.h"
335449c685SForest Bond 
345449c685SForest Bond /*---------------------  Static Definitions -------------------------*/
355449c685SForest Bond 
365449c685SForest Bond /*---------------------  Static Classes  ----------------------------*/
375449c685SForest Bond 
385449c685SForest Bond /*---------------------  Static Variables  --------------------------*/
395449c685SForest Bond 
405449c685SForest Bond /*---------------------  Static Functions  --------------------------*/
415449c685SForest Bond 
425449c685SForest Bond /*---------------------  Export Variables  --------------------------*/
435449c685SForest Bond 
445449c685SForest Bond /*---------------------  Export Functions  --------------------------*/
455449c685SForest Bond 
465449c685SForest Bond /*
475449c685SForest Bond  * Description: Read a byte from EEPROM, by MAC I2C
485449c685SForest Bond  *
495449c685SForest Bond  * Parameters:
505449c685SForest Bond  *  In:
5126f64a6bSVarsha Rao  *      iobase          - I/O base address
52*6a832649SMingzai Sun  *      contnt_offset  - address of EEPROM
535449c685SForest Bond  *  Out:
545449c685SForest Bond  *      none
555449c685SForest Bond  *
565449c685SForest Bond  * Return Value: data read
575449c685SForest Bond  *
585449c685SForest Bond  */
SROMbyReadEmbedded(void __iomem * iobase,unsigned char contnt_offset)5926f64a6bSVarsha Rao unsigned char SROMbyReadEmbedded(void __iomem *iobase,
60*6a832649SMingzai Sun 				 unsigned char contnt_offset)
615449c685SForest Bond {
622986db5fSCharles Clément 	unsigned short wDelay, wNoACK;
633fc9b584SCharles Clément 	unsigned char byWait;
643fc9b584SCharles Clément 	unsigned char byData;
653fc9b584SCharles Clément 	unsigned char byOrg;
665449c685SForest Bond 
675449c685SForest Bond 	byData = 0xFF;
6808bea7daSPhilipp Hortmann 	byOrg = ioread8(iobase + MAC_REG_I2MCFG);
69ec8f002eSSteven Harms 	/* turn off hardware retry for getting NACK */
70404079e7SPhilipp Hortmann 	iowrite8(byOrg & (~I2MCFG_NORETRY), iobase + MAC_REG_I2MCFG);
715449c685SForest Bond 	for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
72404079e7SPhilipp Hortmann 		iowrite8(EEP_I2C_DEV_ID, iobase + MAC_REG_I2MTGID);
73*6a832649SMingzai Sun 		iowrite8(contnt_offset, iobase + MAC_REG_I2MTGAD);
745449c685SForest Bond 
75ec8f002eSSteven Harms 		/* issue read command */
76404079e7SPhilipp Hortmann 		iowrite8(I2MCSR_EEMR, iobase + MAC_REG_I2MCSR);
77ec8f002eSSteven Harms 		/* wait DONE be set */
785449c685SForest Bond 		for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
7908bea7daSPhilipp Hortmann 			byWait = ioread8(iobase + MAC_REG_I2MCSR);
80256a816bSJim Lieb 			if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
815449c685SForest Bond 				break;
8288d33bb8SPhilipp Hortmann 			udelay(CB_DELAY_LOOP_WAIT);
835449c685SForest Bond 		}
845449c685SForest Bond 		if ((wDelay < W_MAX_TIMEOUT) &&
85256a816bSJim Lieb 		    (!(byWait & I2MCSR_NACK))) {
865449c685SForest Bond 			break;
875449c685SForest Bond 		}
885449c685SForest Bond 	}
8908bea7daSPhilipp Hortmann 	byData = ioread8(iobase + MAC_REG_I2MDIPT);
90404079e7SPhilipp Hortmann 	iowrite8(byOrg, iobase + MAC_REG_I2MCFG);
915449c685SForest Bond 	return byData;
925449c685SForest Bond }
935449c685SForest Bond 
945449c685SForest Bond /*
955449c685SForest Bond  * Description: Read all contents of eeprom to buffer
965449c685SForest Bond  *
975449c685SForest Bond  * Parameters:
985449c685SForest Bond  *  In:
9926f64a6bSVarsha Rao  *      iobase          - I/O base address
1005449c685SForest Bond  *  Out:
1015449c685SForest Bond  *      pbyEepromRegs   - EEPROM content Buffer
1025449c685SForest Bond  *
1035449c685SForest Bond  * Return Value: none
1045449c685SForest Bond  *
1055449c685SForest Bond  */
SROMvReadAllContents(void __iomem * iobase,unsigned char * pbyEepromRegs)10626f64a6bSVarsha Rao void SROMvReadAllContents(void __iomem *iobase, unsigned char *pbyEepromRegs)
1075449c685SForest Bond {
1085449c685SForest Bond 	int     ii;
1095449c685SForest Bond 
110ec8f002eSSteven Harms 	/* ii = Rom Address */
1115449c685SForest Bond 	for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
11226f64a6bSVarsha Rao 		*pbyEepromRegs = SROMbyReadEmbedded(iobase,
1135150d01eSKathryn Hampton 						    (unsigned char)ii);
1145449c685SForest Bond 		pbyEepromRegs++;
1155449c685SForest Bond 	}
1165449c685SForest Bond }
1175449c685SForest Bond 
1185449c685SForest Bond /*
1195449c685SForest Bond  * Description: Read Ethernet Address from eeprom to buffer
1205449c685SForest Bond  *
1215449c685SForest Bond  * Parameters:
1225449c685SForest Bond  *  In:
12326f64a6bSVarsha Rao  *      iobase          - I/O base address
1245449c685SForest Bond  *  Out:
1255449c685SForest Bond  *      pbyEtherAddress - Ethernet Address buffer
1265449c685SForest Bond  *
1275449c685SForest Bond  * Return Value: none
1285449c685SForest Bond  *
1295449c685SForest Bond  */
SROMvReadEtherAddress(void __iomem * iobase,unsigned char * pbyEtherAddress)13026f64a6bSVarsha Rao void SROMvReadEtherAddress(void __iomem *iobase,
1315150d01eSKathryn Hampton 			   unsigned char *pbyEtherAddress)
1325449c685SForest Bond {
1333fc9b584SCharles Clément 	unsigned char ii;
1345449c685SForest Bond 
135ec8f002eSSteven Harms 	/* ii = Rom Address */
136078b078fSCharles Clément 	for (ii = 0; ii < ETH_ALEN; ii++) {
13726f64a6bSVarsha Rao 		*pbyEtherAddress = SROMbyReadEmbedded(iobase, ii);
1385449c685SForest Bond 		pbyEtherAddress++;
1395449c685SForest Bond 	}
1405449c685SForest Bond }
141