Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 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 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 45 | #include "upc.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 46 | #include "tmacro.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 47 | #include "tether.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 48 | #include "mac.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 49 | #include "srom.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 50 | |
| 51 | /*--------------------- Static Definitions -------------------------*/ |
| 52 | |
| 53 | /*--------------------- Static Classes ----------------------------*/ |
| 54 | |
| 55 | /*--------------------- Static Variables --------------------------*/ |
| 56 | |
| 57 | /*--------------------- Static Functions --------------------------*/ |
| 58 | |
| 59 | /*--------------------- Export Variables --------------------------*/ |
| 60 | |
| 61 | /*--------------------- Export Functions --------------------------*/ |
| 62 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 63 | /* |
| 64 | * Description: Read a byte from EEPROM, by MAC I2C |
| 65 | * |
| 66 | * Parameters: |
| 67 | * In: |
| 68 | * dwIoBase - I/O base address |
| 69 | * byContntOffset - address of EEPROM |
| 70 | * Out: |
| 71 | * none |
| 72 | * |
| 73 | * Return Value: data read |
| 74 | * |
| 75 | */ |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 76 | unsigned char SROMbyReadEmbedded(unsigned long dwIoBase, unsigned char byContntOffset) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 77 | { |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 78 | unsigned short wDelay, wNoACK; |
| 79 | unsigned char byWait; |
| 80 | unsigned char byData; |
| 81 | unsigned char byOrg; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 82 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 83 | byData = 0xFF; |
| 84 | VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg); |
| 85 | /* turn off hardware retry for getting NACK */ |
| 86 | VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY))); |
| 87 | for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) { |
| 88 | VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID); |
| 89 | VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 90 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 91 | /* issue read command */ |
| 92 | VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMR); |
| 93 | /* wait DONE be set */ |
| 94 | for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) { |
| 95 | VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait); |
| 96 | if (byWait & (I2MCSR_DONE | I2MCSR_NACK)) |
| 97 | break; |
| 98 | PCAvDelayByIO(CB_DELAY_LOOP_WAIT); |
| 99 | } |
| 100 | if ((wDelay < W_MAX_TIMEOUT) && |
| 101 | (!(byWait & I2MCSR_NACK))) { |
| 102 | break; |
| 103 | } |
| 104 | } |
| 105 | VNSvInPortB(dwIoBase + MAC_REG_I2MDIPT, &byData); |
| 106 | VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg); |
| 107 | return byData; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 108 | } |
| 109 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 110 | /* |
| 111 | * Description: Write a byte to EEPROM, by MAC I2C |
| 112 | * |
| 113 | * Parameters: |
| 114 | * In: |
| 115 | * dwIoBase - I/O base address |
| 116 | * byContntOffset - address of EEPROM |
| 117 | * wData - data to write |
| 118 | * Out: |
| 119 | * none |
| 120 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 121 | * Return Value: true if succeeded; false if failed. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 122 | * |
| 123 | */ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 124 | bool SROMbWriteEmbedded(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byData) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 125 | { |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 126 | unsigned short wDelay, wNoACK; |
| 127 | unsigned char byWait; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 128 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 129 | unsigned char byOrg; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 130 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 131 | VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg); |
| 132 | /* turn off hardware retry for getting NACK */ |
| 133 | VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY))); |
| 134 | for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) { |
| 135 | VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID); |
| 136 | VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset); |
| 137 | VNSvOutPortB(dwIoBase + MAC_REG_I2MDOPT, byData); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 138 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 139 | /* issue write command */ |
| 140 | VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMW); |
| 141 | /* wait DONE be set */ |
| 142 | for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) { |
| 143 | VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait); |
| 144 | if (byWait & (I2MCSR_DONE | I2MCSR_NACK)) |
| 145 | break; |
| 146 | PCAvDelayByIO(CB_DELAY_LOOP_WAIT); |
| 147 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 148 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 149 | if ((wDelay < W_MAX_TIMEOUT) && |
| 150 | (!(byWait & I2MCSR_NACK))) { |
| 151 | break; |
| 152 | } |
| 153 | } |
| 154 | if (wNoACK == W_MAX_I2CRETRY) { |
| 155 | VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg); |
| 156 | return false; |
| 157 | } |
| 158 | VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg); |
| 159 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 160 | } |
| 161 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 162 | /* |
| 163 | * Description: Turn bits on in eeprom |
| 164 | * |
| 165 | * Parameters: |
| 166 | * In: |
| 167 | * dwIoBase - I/O base address |
| 168 | * byContntOffset - address of EEPROM |
| 169 | * byBits - bits to turn on |
| 170 | * Out: |
| 171 | * none |
| 172 | * |
| 173 | * Return Value: none |
| 174 | * |
| 175 | */ |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 176 | void SROMvRegBitsOn(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byBits) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 177 | { |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 178 | unsigned char byOrgData; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 179 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 180 | byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset); |
| 181 | SROMbWriteEmbedded(dwIoBase, byContntOffset, (unsigned char)(byOrgData | byBits)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 182 | } |
| 183 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 184 | /* |
| 185 | * Description: Turn bits off in eeprom |
| 186 | * |
| 187 | * Parameters: |
| 188 | * In: |
| 189 | * dwIoBase - I/O base address |
| 190 | * byContntOffset - address of EEPROM |
| 191 | * byBits - bits to turn off |
| 192 | * Out: |
| 193 | * none |
| 194 | * |
| 195 | */ |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 196 | void SROMvRegBitsOff(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byBits) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 197 | { |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 198 | unsigned char byOrgData; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 199 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 200 | byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset); |
| 201 | SROMbWriteEmbedded(dwIoBase, byContntOffset, (unsigned char)(byOrgData & (~byBits))); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 202 | } |
| 203 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 204 | /* |
| 205 | * Description: Test if bits on in eeprom |
| 206 | * |
| 207 | * Parameters: |
| 208 | * In: |
| 209 | * dwIoBase - I/O base address |
| 210 | * byContntOffset - address of EEPROM |
| 211 | * byTestBits - bits to test |
| 212 | * Out: |
| 213 | * none |
| 214 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 215 | * Return Value: true if all test bits on; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 216 | * |
| 217 | */ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 218 | bool SROMbIsRegBitsOn(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byTestBits) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 219 | { |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 220 | unsigned char byOrgData; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 221 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 222 | byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset); |
| 223 | return (byOrgData & byTestBits) == byTestBits; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 224 | } |
| 225 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 226 | /* |
| 227 | * Description: Test if bits off in eeprom |
| 228 | * |
| 229 | * Parameters: |
| 230 | * In: |
| 231 | * dwIoBase - I/O base address |
| 232 | * byContntOffset - address of EEPROM |
| 233 | * byTestBits - bits to test |
| 234 | * Out: |
| 235 | * none |
| 236 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 237 | * Return Value: true if all test bits off; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 238 | * |
| 239 | */ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 240 | bool SROMbIsRegBitsOff(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byTestBits) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 241 | { |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 242 | unsigned char byOrgData; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 243 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 244 | byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset); |
| 245 | return !(byOrgData & byTestBits); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 246 | } |
| 247 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 248 | /* |
| 249 | * Description: Read all contents of eeprom to buffer |
| 250 | * |
| 251 | * Parameters: |
| 252 | * In: |
| 253 | * dwIoBase - I/O base address |
| 254 | * Out: |
| 255 | * pbyEepromRegs - EEPROM content Buffer |
| 256 | * |
| 257 | * Return Value: none |
| 258 | * |
| 259 | */ |
Charles Clément | 412b2d0 | 2010-06-22 08:54:42 -0700 | [diff] [blame] | 260 | void SROMvReadAllContents(unsigned long dwIoBase, unsigned char *pbyEepromRegs) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 261 | { |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 262 | int ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 263 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 264 | /* ii = Rom Address */ |
| 265 | for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) { |
| 266 | *pbyEepromRegs = SROMbyReadEmbedded(dwIoBase, (unsigned char)ii); |
| 267 | pbyEepromRegs++; |
| 268 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 269 | } |
| 270 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 271 | /* |
| 272 | * Description: Write all contents of buffer to eeprom |
| 273 | * |
| 274 | * Parameters: |
| 275 | * In: |
| 276 | * dwIoBase - I/O base address |
| 277 | * pbyEepromRegs - EEPROM content Buffer |
| 278 | * Out: |
| 279 | * none |
| 280 | * |
| 281 | * Return Value: none |
| 282 | * |
| 283 | */ |
Charles Clément | 412b2d0 | 2010-06-22 08:54:42 -0700 | [diff] [blame] | 284 | void SROMvWriteAllContents(unsigned long dwIoBase, unsigned char *pbyEepromRegs) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 285 | { |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 286 | int ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 287 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 288 | /* ii = Rom Address */ |
| 289 | for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) { |
| 290 | SROMbWriteEmbedded(dwIoBase, (unsigned char)ii, *pbyEepromRegs); |
| 291 | pbyEepromRegs++; |
| 292 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 293 | } |
| 294 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 295 | /* |
| 296 | * Description: Read Ethernet Address from eeprom to buffer |
| 297 | * |
| 298 | * Parameters: |
| 299 | * In: |
| 300 | * dwIoBase - I/O base address |
| 301 | * Out: |
| 302 | * pbyEtherAddress - Ethernet Address buffer |
| 303 | * |
| 304 | * Return Value: none |
| 305 | * |
| 306 | */ |
Charles Clément | 412b2d0 | 2010-06-22 08:54:42 -0700 | [diff] [blame] | 307 | void SROMvReadEtherAddress(unsigned long dwIoBase, unsigned char *pbyEtherAddress) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 308 | { |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 309 | unsigned char ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 310 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 311 | /* ii = Rom Address */ |
| 312 | for (ii = 0; ii < ETH_ALEN; ii++) { |
| 313 | *pbyEtherAddress = SROMbyReadEmbedded(dwIoBase, ii); |
| 314 | pbyEtherAddress++; |
| 315 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 316 | } |
| 317 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 318 | /* |
| 319 | * Description: Write Ethernet Address from buffer to eeprom |
| 320 | * |
| 321 | * Parameters: |
| 322 | * In: |
| 323 | * dwIoBase - I/O base address |
| 324 | * pbyEtherAddress - Ethernet Address buffer |
| 325 | * Out: |
| 326 | * none |
| 327 | * |
| 328 | * Return Value: none |
| 329 | * |
| 330 | */ |
Charles Clément | 412b2d0 | 2010-06-22 08:54:42 -0700 | [diff] [blame] | 331 | void SROMvWriteEtherAddress(unsigned long dwIoBase, unsigned char *pbyEtherAddress) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 332 | { |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 333 | unsigned char ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 334 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 335 | /* ii = Rom Address */ |
| 336 | for (ii = 0; ii < ETH_ALEN; ii++) { |
| 337 | SROMbWriteEmbedded(dwIoBase, ii, *pbyEtherAddress); |
| 338 | pbyEtherAddress++; |
| 339 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 340 | } |
| 341 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 342 | /* |
| 343 | * Description: Read Sub_VID and Sub_SysId from eeprom to buffer |
| 344 | * |
| 345 | * Parameters: |
| 346 | * In: |
| 347 | * dwIoBase - I/O base address |
| 348 | * Out: |
| 349 | * pdwSubSysVenId - Sub_VID and Sub_SysId read |
| 350 | * |
| 351 | * Return Value: none |
| 352 | * |
| 353 | */ |
Charles Clément | 412b2d0 | 2010-06-22 08:54:42 -0700 | [diff] [blame] | 354 | void SROMvReadSubSysVenId(unsigned long dwIoBase, unsigned long *pdwSubSysVenId) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 355 | { |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 356 | unsigned char *pbyData; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 357 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 358 | pbyData = (unsigned char *)pdwSubSysVenId; |
| 359 | /* sub vendor */ |
| 360 | *pbyData = SROMbyReadEmbedded(dwIoBase, 6); |
| 361 | *(pbyData+1) = SROMbyReadEmbedded(dwIoBase, 7); |
| 362 | /* sub system */ |
| 363 | *(pbyData+2) = SROMbyReadEmbedded(dwIoBase, 8); |
| 364 | *(pbyData+3) = SROMbyReadEmbedded(dwIoBase, 9); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /* |
| 368 | * Description: Auto Load EEPROM to MAC register |
| 369 | * |
| 370 | * Parameters: |
| 371 | * In: |
| 372 | * dwIoBase - I/O base address |
| 373 | * Out: |
| 374 | * none |
| 375 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 376 | * Return Value: true if success; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 377 | * |
| 378 | */ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 379 | bool SROMbAutoLoad(unsigned long dwIoBase) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 380 | { |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 381 | unsigned char byWait; |
| 382 | int ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 383 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 384 | unsigned char byOrg; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 385 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 386 | VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg); |
| 387 | /* turn on hardware retry */ |
| 388 | VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg | I2MCFG_NORETRY)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 389 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 390 | MACvRegBitsOn(dwIoBase, MAC_REG_I2MCSR, I2MCSR_AUTOLD); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 391 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 392 | /* ii = Rom Address */ |
| 393 | for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) { |
| 394 | MACvTimer0MicroSDelay(dwIoBase, CB_EEPROM_READBYTE_WAIT); |
| 395 | VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait); |
| 396 | if (!(byWait & I2MCSR_AUTOLD)) |
| 397 | break; |
| 398 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 399 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 400 | VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 401 | |
Joe Perches | 0c97914 | 2013-03-18 10:45:02 -0700 | [diff] [blame] | 402 | if (ii == EEP_MAX_CONTEXT_SIZE) |
| 403 | return false; |
| 404 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 405 | } |