3 Copyright (C) 2001-2011 Neil Cafferkey
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 #include "eeprom_protos.h"
26 #include "timer_protos.h"
27 #include "realtek8187.h"
30 static ULONG
ReadEEPROMBits(struct DevUnit
*unit
, UBYTE count
,
31 struct DevBase
*base
);
32 static VOID
WriteEEPROMBits(struct DevUnit
*unit
, ULONG value
, UBYTE count
,
33 struct DevBase
*base
);
34 static BOOL
ReadEEPROMBit(struct DevUnit
*unit
, struct DevBase
*base
);
35 static BOOL
WriteEEPROMBit(struct DevUnit
*unit
, BOOL is_one
,
36 struct DevBase
*base
);
39 /****i* realtek8180.device/GetEEPROMAddressSize ****************************
42 * GetEEPROMAddressSize
45 * size = GetEEPROMAddressSize(unit)
47 * UWORD GetEEPROMAddressSize(struct DevUnit *);
50 * unit - A unit of this device.
53 * size - Width of EEPROM addresses.
55 ****************************************************************************
60 static UWORD
GetEEPROMAddressSize(struct DevUnit
*unit
,
65 unit
->ByteOut(unit
->card
, 0x100 + R8180REG_EEPROM
, R8180REG_EEPROMF_SELECT
);
66 WriteEEPROMBits(unit
, 0x6, 3, base
);
67 for(size
= 1; WriteEEPROMBit(unit
, FALSE
, base
); size
++);
68 ReadEEPROMBits(unit
, 16, base
);
69 unit
->ByteOut(unit
->card
, 0x100 + R8180REG_EEPROM
, 0);
70 BusyMicroDelay(1, base
);
78 /****i* realtek8180.device/ReadEEPROM **************************************
81 * ReadEEPROM -- Read an EEPROM location.
84 * value = ReadEEPROM(unit, index)
86 * UWORD ReadEEPROM(struct DevUnit *, UWORD);
89 * unit - A unit of this device.
90 * index - Offset within EEPROM.
93 * value - Contents of specified EEPROM location.
95 ****************************************************************************
99 UWORD
ReadEEPROM(struct DevUnit
*unit
, UWORD index
,
100 struct DevBase
*base
)
104 unit
->ByteOut(unit
->card
, 0x100 + R8180REG_EEPROM
,
105 R8180ECMD_PROGRAM
| R8180REG_EEPROMF_SELECT
);
106 WriteEEPROMBits(unit
, 0x6, 3, base
);
107 WriteEEPROMBits(unit
, index
, unit
->eeprom_addr_size
, base
);
108 value
= ReadEEPROMBits(unit
, 16, base
);
109 unit
->ByteOut(unit
->card
, 0x100 + R8180REG_EEPROM
, R8180ECMD_PROGRAM
);
110 BusyMicroDelay(1, base
);
117 /****i* realtek8180.device/ReadEEPROMBits **********************************
120 * ReadEEPROMBits -- Read a stream of bits from the EEPROM.
123 * value = ReadEEPROMBits(unit, count)
125 * ULONG ReadEEPROMBits(struct DevUnit *, UBYTE);
128 * unit - A unit of this device.
129 * count - Number of bits to be read.
132 * value - The bits read from the EEPROM, right-justified.
134 ****************************************************************************
138 static ULONG
ReadEEPROMBits(struct DevUnit
*unit
, UBYTE count
,
139 struct DevBase
*base
)
144 for(i
= 0; i
< count
; i
++)
147 if(ReadEEPROMBit(unit
, base
))
155 /****i* realtek8180.device/WriteEEPROMBits *********************************
158 * WriteEEPROMBits -- Write a stream of bits to the EEPROM.
161 * WriteEEPROMBits(unit, value, count)
163 * VOID WriteEEPROMBits(struct DevUnit *, ULONG, UBYTE);
166 * unit - A unit of this device.
167 * value - The bits to write to the EEPROM, right-justified.
168 * count - Number of bits to be Write.
173 ****************************************************************************
177 static VOID
WriteEEPROMBits(struct DevUnit
*unit
, ULONG value
, UBYTE count
,
178 struct DevBase
*base
)
182 for(mask
= 1 << (count
- 1); mask
!= 0; mask
>>= 1)
183 WriteEEPROMBit(unit
, (value
& mask
) != 0, base
);
190 /****i* realtek8180.device/ReadEEPROMBit ***********************************
193 * ReadEEPROMBit -- Read a bit from the EEPROM.
196 * value = ReadEEPROMBit(unit)
198 * BOOL ReadEEPROMBit(struct DevUnit *);
201 * unit - A unit of this device.
204 * value - True for one, false for zero.
206 ****************************************************************************
210 static BOOL
ReadEEPROMBit(struct DevUnit
*unit
, struct DevBase
*base
)
214 unit
->ByteOut(unit
->card
, 0x100 + R8180REG_EEPROM
,
215 R8180ECMD_PROGRAM
| R8180REG_EEPROMF_SELECT
| R8180REG_EEPROMF_CLK
);
216 BusyMicroDelay(2, base
);
218 (unit
->ByteIn(unit
->card
, 0x100 + R8180REG_EEPROM
)
219 & R8180REG_EEPROMF_DATAIN
) != 0;
220 unit
->ByteOut(unit
->card
, 0x100 + R8180REG_EEPROM
,
221 R8180ECMD_PROGRAM
| R8180REG_EEPROMF_SELECT
);
222 BusyMicroDelay(2, base
);
229 /****i* realtek8180.device/WriteEEPROMBit **********************************
232 * WriteEEPROMBit -- Write a bit to the EEPROM.
235 * data_in = WriteEEPROMBit(unit, is_one)
237 * BOOL WriteEEPROMBit(struct DevUnit *, BOOL);
240 * unit - A unit of this device.
241 * is_one - True if a set bit should be written.
244 * data_in - True if data-in bit is set.
246 ****************************************************************************
250 static BOOL
WriteEEPROMBit(struct DevUnit
*unit
, BOOL is_one
,
251 struct DevBase
*base
)
256 data_out
= R8180REG_EEPROMF_DATAOUT
;
260 unit
->ByteOut(unit
->card
, 0x100 + R8180REG_EEPROM
,
261 R8180ECMD_PROGRAM
| R8180REG_EEPROMF_SELECT
| data_out
);
262 unit
->ByteOut(unit
->card
, 0x100 + R8180REG_EEPROM
, R8180ECMD_PROGRAM
263 | R8180REG_EEPROMF_SELECT
| R8180REG_EEPROMF_CLK
| data_out
);
264 BusyMicroDelay(2, base
);
265 unit
->ByteOut(unit
->card
, 0x100 + R8180REG_EEPROM
,
266 R8180ECMD_PROGRAM
| R8180REG_EEPROMF_SELECT
| data_out
);
267 BusyMicroDelay(2, base
);
269 return (unit
->ByteIn(unit
->card
, 0x100 + R8180REG_EEPROM
)
270 & R8180REG_EEPROMF_DATAIN
) != 0;