]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/staging/vt6655/srom.c
Staging: vt665x: remove tbit.h
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / vt6655 / srom.c
CommitLineData
5449c685
FB
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
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.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: srom.c
20 *
21 * Purpose:Implement functions to access eeprom
22 *
23 * Author: Jerry Chen
24 *
25 * Date: Jan 29, 2003
26 *
27 * Functions:
28 * SROMbyReadEmbedded - Embedded read eeprom via MAC
29 * SROMbWriteEmbedded - Embedded write eeprom via MAC
30 * SROMvRegBitsOn - Set Bits On in eeprom
31 * SROMvRegBitsOff - Clear Bits Off in eeprom
32 * SROMbIsRegBitsOn - Test if Bits On in eeprom
33 * SROMbIsRegBitsOff - Test if Bits Off in eeprom
34 * SROMvReadAllContents - Read all contents in eeprom
35 * SROMvWriteAllContents - Write all contents in eeprom
36 * SROMvReadEtherAddress - Read Ethernet Address in eeprom
37 * SROMvWriteEtherAddress - Write Ethernet Address in eeprom
38 * SROMvReadSubSysVenId - Read Sub_VID and Sub_SysId in eeprom
39 * SROMbAutoLoad - Auto Load eeprom to MAC register
40 *
41 * Revision History:
42 *
43 */
44
5449c685 45#include "upc.h"
5449c685 46#include "tmacro.h"
5449c685 47#include "tbit.h"
5449c685 48#include "tether.h"
5449c685 49#include "mac.h"
5449c685 50#include "srom.h"
5449c685
FB
51
52/*--------------------- Static Definitions -------------------------*/
53
54/*--------------------- Static Classes ----------------------------*/
55
56/*--------------------- Static Variables --------------------------*/
57
58/*--------------------- Static Functions --------------------------*/
59
60/*--------------------- Export Variables --------------------------*/
61
62/*--------------------- Export Functions --------------------------*/
63
64
65
66
67/*
68 * Description: Read a byte from EEPROM, by MAC I2C
69 *
70 * Parameters:
71 * In:
72 * dwIoBase - I/O base address
73 * byContntOffset - address of EEPROM
74 * Out:
75 * none
76 *
77 * Return Value: data read
78 *
79 */
80BYTE SROMbyReadEmbedded(DWORD_PTR dwIoBase, BYTE byContntOffset)
81{
82 WORD wDelay, wNoACK;
83 BYTE byWait;
84 BYTE byData;
85 BYTE byOrg;
86
87 byData = 0xFF;
88 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
89 // turn off hardware retry for getting NACK
90 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
91 for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
92 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
93 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
94
95 // issue read command
96 VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMR);
97 // wait DONE be set
98 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
99 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
100 if (BITbIsAnyBitsOn(byWait, (I2MCSR_DONE | I2MCSR_NACK)))
101 break;
102 PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
103 }
104 if ((wDelay < W_MAX_TIMEOUT) &&
105 (BITbIsBitOff(byWait, I2MCSR_NACK))) {
106 break;
107 }
108 }
109 VNSvInPortB(dwIoBase + MAC_REG_I2MDIPT, &byData);
110 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
111 return byData;
112}
113
114
115/*
116 * Description: Write a byte to EEPROM, by MAC I2C
117 *
118 * Parameters:
119 * In:
120 * dwIoBase - I/O base address
121 * byContntOffset - address of EEPROM
122 * wData - data to write
123 * Out:
124 * none
125 *
126 * Return Value: TRUE if succeeded; FALSE if failed.
127 *
128 */
129BOOL SROMbWriteEmbedded (DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byData)
130{
131 WORD wDelay, wNoACK;
132 BYTE byWait;
133
134 BYTE byOrg;
135
136 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
137 // turn off hardware retry for getting NACK
138 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
139 for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
140 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
141 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
142 VNSvOutPortB(dwIoBase + MAC_REG_I2MDOPT, byData);
143
144 // issue write command
145 VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMW);
146 // wait DONE be set
147 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
148 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
149 if (BITbIsAnyBitsOn(byWait, (I2MCSR_DONE | I2MCSR_NACK)))
150 break;
151 PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
152 }
153
154 if ((wDelay < W_MAX_TIMEOUT) &&
155 (BITbIsBitOff(byWait, I2MCSR_NACK))) {
156 break;
157 }
158 }
159 if (wNoACK == W_MAX_I2CRETRY) {
160 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
161 return FALSE;
162 }
163 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
164 return TRUE;
165}
166
167
168/*
169 * Description: Turn bits on in eeprom
170 *
171 * Parameters:
172 * In:
173 * dwIoBase - I/O base address
174 * byContntOffset - address of EEPROM
175 * byBits - bits to turn on
176 * Out:
177 * none
178 *
179 * Return Value: none
180 *
181 */
182void SROMvRegBitsOn (DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byBits)
183{
184 BYTE byOrgData;
185
186 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
187 SROMbWriteEmbedded(dwIoBase, byContntOffset,(BYTE)(byOrgData | byBits));
188}
189
190
191/*
192 * Description: Turn bits off in eeprom
193 *
194 * Parameters:
195 * In:
196 * dwIoBase - I/O base address
197 * byContntOffset - address of EEPROM
198 * byBits - bits to turn off
199 * Out:
200 * none
201 *
202 */
203void SROMvRegBitsOff (DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byBits)
204{
205 BYTE byOrgData;
206
207 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
208 SROMbWriteEmbedded(dwIoBase, byContntOffset,(BYTE)(byOrgData & (~byBits)));
209}
210
211
212/*
213 * Description: Test if bits on in eeprom
214 *
215 * Parameters:
216 * In:
217 * dwIoBase - I/O base address
218 * byContntOffset - address of EEPROM
219 * byTestBits - bits to test
220 * Out:
221 * none
222 *
223 * Return Value: TRUE if all test bits on; otherwise FALSE
224 *
225 */
226BOOL SROMbIsRegBitsOn (DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byTestBits)
227{
228 BYTE byOrgData;
229
230 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
231 return BITbIsAllBitsOn(byOrgData, byTestBits);
232}
233
234
235/*
236 * Description: Test if bits off in eeprom
237 *
238 * Parameters:
239 * In:
240 * dwIoBase - I/O base address
241 * byContntOffset - address of EEPROM
242 * byTestBits - bits to test
243 * Out:
244 * none
245 *
246 * Return Value: TRUE if all test bits off; otherwise FALSE
247 *
248 */
249BOOL SROMbIsRegBitsOff (DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byTestBits)
250{
251 BYTE byOrgData;
252
253 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
254 return BITbIsAllBitsOff(byOrgData, byTestBits);
255}
256
257
258/*
259 * Description: Read all contents of eeprom to buffer
260 *
261 * Parameters:
262 * In:
263 * dwIoBase - I/O base address
264 * Out:
265 * pbyEepromRegs - EEPROM content Buffer
266 *
267 * Return Value: none
268 *
269 */
270void SROMvReadAllContents (DWORD_PTR dwIoBase, PBYTE pbyEepromRegs)
271{
272 int ii;
273
274 // ii = Rom Address
275 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
276 *pbyEepromRegs = SROMbyReadEmbedded(dwIoBase,(BYTE) ii);
277 pbyEepromRegs++;
278 }
279}
280
281
282/*
283 * Description: Write all contents of buffer to eeprom
284 *
285 * Parameters:
286 * In:
287 * dwIoBase - I/O base address
288 * pbyEepromRegs - EEPROM content Buffer
289 * Out:
290 * none
291 *
292 * Return Value: none
293 *
294 */
295void SROMvWriteAllContents (DWORD_PTR dwIoBase, PBYTE pbyEepromRegs)
296{
297 int ii;
298
299 // ii = Rom Address
300 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
301 SROMbWriteEmbedded(dwIoBase,(BYTE) ii, *pbyEepromRegs);
302 pbyEepromRegs++;
303 }
304}
305
306
307/*
308 * Description: Read Ethernet Address from eeprom to buffer
309 *
310 * Parameters:
311 * In:
312 * dwIoBase - I/O base address
313 * Out:
314 * pbyEtherAddress - Ethernet Address buffer
315 *
316 * Return Value: none
317 *
318 */
319void SROMvReadEtherAddress (DWORD_PTR dwIoBase, PBYTE pbyEtherAddress)
320{
321 BYTE ii;
322
323 // ii = Rom Address
324 for (ii = 0; ii < U_ETHER_ADDR_LEN; ii++) {
325 *pbyEtherAddress = SROMbyReadEmbedded(dwIoBase, ii);
326 pbyEtherAddress++;
327 }
328}
329
330
331/*
332 * Description: Write Ethernet Address from buffer to eeprom
333 *
334 * Parameters:
335 * In:
336 * dwIoBase - I/O base address
337 * pbyEtherAddress - Ethernet Address buffer
338 * Out:
339 * none
340 *
341 * Return Value: none
342 *
343 */
344void SROMvWriteEtherAddress (DWORD_PTR dwIoBase, PBYTE pbyEtherAddress)
345{
346 BYTE ii;
347
348 // ii = Rom Address
349 for (ii = 0; ii < U_ETHER_ADDR_LEN; ii++) {
350 SROMbWriteEmbedded(dwIoBase, ii, *pbyEtherAddress);
351 pbyEtherAddress++;
352 }
353}
354
355
356/*
357 * Description: Read Sub_VID and Sub_SysId from eeprom to buffer
358 *
359 * Parameters:
360 * In:
361 * dwIoBase - I/O base address
362 * Out:
363 * pdwSubSysVenId - Sub_VID and Sub_SysId read
364 *
365 * Return Value: none
366 *
367 */
368void SROMvReadSubSysVenId (DWORD_PTR dwIoBase, PDWORD pdwSubSysVenId)
369{
370 PBYTE pbyData;
371
372 pbyData = (PBYTE)pdwSubSysVenId;
373 // sub vendor
374 *pbyData = SROMbyReadEmbedded(dwIoBase, 6);
375 *(pbyData+1) = SROMbyReadEmbedded(dwIoBase, 7);
376 // sub system
377 *(pbyData+2) = SROMbyReadEmbedded(dwIoBase, 8);
378 *(pbyData+3) = SROMbyReadEmbedded(dwIoBase, 9);
379}
380
381/*
382 * Description: Auto Load EEPROM to MAC register
383 *
384 * Parameters:
385 * In:
386 * dwIoBase - I/O base address
387 * Out:
388 * none
389 *
390 * Return Value: TRUE if success; otherwise FALSE
391 *
392 */
393BOOL SROMbAutoLoad (DWORD_PTR dwIoBase)
394{
395 BYTE byWait;
396 int ii;
397
398 BYTE byOrg;
399
400 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
401 // turn on hardware retry
402 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg | I2MCFG_NORETRY));
403
404 MACvRegBitsOn(dwIoBase, MAC_REG_I2MCSR, I2MCSR_AUTOLD);
405
406 // ii = Rom Address
407 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
408 MACvTimer0MicroSDelay(dwIoBase, CB_EEPROM_READBYTE_WAIT);
409 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
410 if (BITbIsBitOff(byWait, I2MCSR_AUTOLD))
411 break;
412 }
413
414 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
415
416 if (ii == EEP_MAX_CONTEXT_SIZE)
417 return FALSE;
418 return TRUE;
419}
420
421