Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Agere Systems Inc. |
| 3 | * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs |
| 4 | * |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 5 | * Copyright © 2005 Agere Systems Inc. |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * http://www.agere.com |
| 8 | * |
| 9 | *------------------------------------------------------------------------------ |
| 10 | * |
| 11 | * et1310_eeprom.c - Code used to access the device's EEPROM |
| 12 | * |
| 13 | *------------------------------------------------------------------------------ |
| 14 | * |
| 15 | * SOFTWARE LICENSE |
| 16 | * |
| 17 | * This software is provided subject to the following terms and conditions, |
| 18 | * which you should read carefully before using the software. Using this |
| 19 | * software indicates your acceptance of these terms and conditions. If you do |
| 20 | * not agree with these terms and conditions, do not use the software. |
| 21 | * |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 22 | * Copyright © 2005 Agere Systems Inc. |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 23 | * All rights reserved. |
| 24 | * |
| 25 | * Redistribution and use in source or binary forms, with or without |
| 26 | * modifications, are permitted provided that the following conditions are met: |
| 27 | * |
| 28 | * . Redistributions of source code must retain the above copyright notice, this |
| 29 | * list of conditions and the following Disclaimer as comments in the code as |
| 30 | * well as in the documentation and/or other materials provided with the |
| 31 | * distribution. |
| 32 | * |
| 33 | * . Redistributions in binary form must reproduce the above copyright notice, |
| 34 | * this list of conditions and the following Disclaimer in the documentation |
| 35 | * and/or other materials provided with the distribution. |
| 36 | * |
| 37 | * . Neither the name of Agere Systems Inc. nor the names of the contributors |
| 38 | * may be used to endorse or promote products derived from this software |
| 39 | * without specific prior written permission. |
| 40 | * |
| 41 | * Disclaimer |
| 42 | * |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 43 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 44 | * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF |
| 45 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY |
| 46 | * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN |
| 47 | * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY |
| 48 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 49 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 50 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 51 | * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT |
| 52 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 53 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 54 | * DAMAGE. |
| 55 | * |
| 56 | */ |
| 57 | |
| 58 | #include "et131x_version.h" |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 59 | #include "et131x_defs.h" |
| 60 | |
| 61 | #include <linux/pci.h> |
| 62 | #include <linux/init.h> |
| 63 | #include <linux/module.h> |
| 64 | #include <linux/types.h> |
| 65 | #include <linux/kernel.h> |
| 66 | |
| 67 | #include <linux/sched.h> |
| 68 | #include <linux/ptrace.h> |
| 69 | #include <linux/slab.h> |
| 70 | #include <linux/ctype.h> |
| 71 | #include <linux/string.h> |
| 72 | #include <linux/timer.h> |
| 73 | #include <linux/interrupt.h> |
| 74 | #include <linux/in.h> |
| 75 | #include <linux/delay.h> |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 76 | #include <linux/bitops.h> |
| 77 | #include <linux/io.h> |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 78 | #include <asm/system.h> |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 79 | |
| 80 | #include <linux/netdevice.h> |
| 81 | #include <linux/etherdevice.h> |
| 82 | #include <linux/skbuff.h> |
| 83 | #include <linux/if_arp.h> |
| 84 | #include <linux/ioport.h> |
| 85 | |
| 86 | #include "et1310_phy.h" |
| 87 | #include "et1310_pm.h" |
| 88 | #include "et1310_jagcore.h" |
| 89 | #include "et1310_eeprom.h" |
| 90 | |
| 91 | #include "et131x_adapter.h" |
| 92 | #include "et131x_initpci.h" |
| 93 | #include "et131x_isr.h" |
| 94 | |
| 95 | #include "et1310_tx.h" |
| 96 | |
| 97 | |
| 98 | /* |
| 99 | * EEPROM Defines |
| 100 | */ |
| 101 | |
| 102 | /* LBCIF Register Groups (addressed via 32-bit offsets) */ |
| 103 | #define LBCIF_DWORD0_GROUP_OFFSET 0xAC |
| 104 | #define LBCIF_DWORD1_GROUP_OFFSET 0xB0 |
| 105 | |
| 106 | /* LBCIF Registers (addressed via 8-bit offsets) */ |
| 107 | #define LBCIF_ADDRESS_REGISTER_OFFSET 0xAC |
| 108 | #define LBCIF_DATA_REGISTER_OFFSET 0xB0 |
| 109 | #define LBCIF_CONTROL_REGISTER_OFFSET 0xB1 |
| 110 | #define LBCIF_STATUS_REGISTER_OFFSET 0xB2 |
| 111 | |
| 112 | /* LBCIF Control Register Bits */ |
| 113 | #define LBCIF_CONTROL_SEQUENTIAL_READ 0x01 |
| 114 | #define LBCIF_CONTROL_PAGE_WRITE 0x02 |
| 115 | #define LBCIF_CONTROL_UNUSED1 0x04 |
| 116 | #define LBCIF_CONTROL_EEPROM_RELOAD 0x08 |
| 117 | #define LBCIF_CONTROL_UNUSED2 0x10 |
| 118 | #define LBCIF_CONTROL_TWO_BYTE_ADDR 0x20 |
| 119 | #define LBCIF_CONTROL_I2C_WRITE 0x40 |
| 120 | #define LBCIF_CONTROL_LBCIF_ENABLE 0x80 |
| 121 | |
| 122 | /* LBCIF Status Register Bits */ |
| 123 | #define LBCIF_STATUS_PHY_QUEUE_AVAIL 0x01 |
| 124 | #define LBCIF_STATUS_I2C_IDLE 0x02 |
| 125 | #define LBCIF_STATUS_ACK_ERROR 0x04 |
| 126 | #define LBCIF_STATUS_GENERAL_ERROR 0x08 |
| 127 | #define LBCIF_STATUS_UNUSED 0x30 |
| 128 | #define LBCIF_STATUS_CHECKSUM_ERROR 0x40 |
| 129 | #define LBCIF_STATUS_EEPROM_PRESENT 0x80 |
| 130 | |
| 131 | /* Miscellaneous Constraints */ |
| 132 | #define MAX_NUM_REGISTER_POLLS 1000 |
| 133 | #define MAX_NUM_WRITE_RETRIES 2 |
| 134 | |
| 135 | /* |
| 136 | * Define macros that allow individual register values to be extracted from a |
| 137 | * DWORD1 register grouping |
| 138 | */ |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 139 | #define EXTRACT_DATA_REGISTER(x) (u8)(x & 0xFF) |
| 140 | #define EXTRACT_STATUS_REGISTER(x) (u8)((x >> 16) & 0xFF) |
| 141 | #define EXTRACT_CONTROL_REG(x) (u8)((x >> 8) & 0xFF) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * EepromWriteByte - Write a byte to the ET1310's EEPROM |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 145 | * @etdev: pointer to our private adapter structure |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 146 | * @addr: the address to write |
| 147 | * @data: the value to write |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 148 | * |
Alan Cox | 53f8aee | 2009-10-06 15:46:24 +0100 | [diff] [blame^] | 149 | * Returns 1 for a successful write. |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 150 | */ |
Alan Cox | 13071fd | 2009-08-27 11:01:04 +0100 | [diff] [blame] | 151 | int EepromWriteByte(struct et131x_adapter *etdev, u32 addr, u8 data) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 152 | { |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 153 | struct pci_dev *pdev = etdev->pdev; |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 154 | int index; |
| 155 | int retries; |
| 156 | int err = 0; |
| 157 | int i2c_wack = 0; |
| 158 | int writeok = 0; |
| 159 | u8 control; |
| 160 | u8 status = 0; |
| 161 | u32 dword1 = 0; |
| 162 | u32 val = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 163 | |
| 164 | /* |
| 165 | * The following excerpt is from "Serial EEPROM HW Design |
| 166 | * Specification" Version 0.92 (9/20/2004): |
| 167 | * |
| 168 | * Single Byte Writes |
| 169 | * |
| 170 | * For an EEPROM, an I2C single byte write is defined as a START |
| 171 | * condition followed by the device address, EEPROM address, one byte |
| 172 | * of data and a STOP condition. The STOP condition will trigger the |
| 173 | * EEPROM's internally timed write cycle to the nonvolatile memory. |
| 174 | * All inputs are disabled during this write cycle and the EEPROM will |
| 175 | * not respond to any access until the internal write is complete. |
| 176 | * The steps to execute a single byte write are as follows: |
| 177 | * |
| 178 | * 1. Check LBCIF Status Register for bits 6 & 3:2 all equal to 0 and |
| 179 | * bits 7,1:0 both equal to 1, at least once after reset. |
| 180 | * Subsequent operations need only to check that bits 1:0 are |
| 181 | * equal to 1 prior to starting a single byte write. |
| 182 | * |
| 183 | * 2. Write to the LBCIF Control Register: bit 7=1, bit 6=1, bit 3=0, |
| 184 | * and bits 1:0 both =0. Bit 5 should be set according to the |
| 185 | * type of EEPROM being accessed (1=two byte addressing, 0=one |
| 186 | * byte addressing). |
| 187 | * |
| 188 | * 3. Write the address to the LBCIF Address Register. |
| 189 | * |
| 190 | * 4. Write the data to the LBCIF Data Register (the I2C write will |
| 191 | * begin). |
| 192 | * |
| 193 | * 5. Monitor bit 1:0 of the LBCIF Status Register. When bits 1:0 are |
| 194 | * both equal to 1, the I2C write has completed and the internal |
| 195 | * write cycle of the EEPROM is about to start. (bits 1:0 = 01 is |
| 196 | * a legal state while waiting from both equal to 1, but bits |
| 197 | * 1:0 = 10 is invalid and implies that something is broken). |
| 198 | * |
| 199 | * 6. Check bit 3 of the LBCIF Status Register. If equal to 1, an |
| 200 | * error has occurred. |
| 201 | * |
| 202 | * 7. Check bit 2 of the LBCIF Status Register. If equal to 1 an ACK |
| 203 | * error has occurred on the address phase of the write. This |
| 204 | * could be due to an actual hardware failure or the EEPROM may |
| 205 | * still be in its internal write cycle from a previous write. |
| 206 | * This write operation was ignored and must be repeated later. |
| 207 | * |
| 208 | * 8. Set bit 6 of the LBCIF Control Register = 0. If another write is |
| 209 | * required, go to step 1. |
| 210 | */ |
| 211 | |
| 212 | /* Step 1: */ |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 213 | for (index = 0; index < MAX_NUM_REGISTER_POLLS; index++) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 214 | /* Read registers grouped in DWORD1 */ |
| 215 | if (pci_read_config_dword(pdev, LBCIF_DWORD1_GROUP_OFFSET, |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 216 | &dword1)) { |
| 217 | err = 1; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 218 | break; |
| 219 | } |
| 220 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 221 | status = EXTRACT_STATUS_REGISTER(dword1); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 222 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 223 | if (status & LBCIF_STATUS_PHY_QUEUE_AVAIL && |
| 224 | status & LBCIF_STATUS_I2C_IDLE) |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 225 | /* bits 1:0 are equal to 1 */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 226 | break; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 229 | if (err || (index >= MAX_NUM_REGISTER_POLLS)) |
Alan Cox | 53f8aee | 2009-10-06 15:46:24 +0100 | [diff] [blame^] | 230 | return 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 231 | |
| 232 | /* Step 2: */ |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 233 | control = 0; |
| 234 | control |= LBCIF_CONTROL_LBCIF_ENABLE | LBCIF_CONTROL_I2C_WRITE; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 235 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 236 | if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER_OFFSET, |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 237 | control)) { |
Alan Cox | 53f8aee | 2009-10-06 15:46:24 +0100 | [diff] [blame^] | 238 | return 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 241 | i2c_wack = 1; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 242 | |
| 243 | /* Prepare EEPROM address for Step 3 */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 244 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 245 | for (retries = 0; retries < MAX_NUM_WRITE_RETRIES; retries++) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 246 | /* Step 3:*/ |
| 247 | if (pci_write_config_dword(pdev, LBCIF_ADDRESS_REGISTER_OFFSET, |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 248 | addr)) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 249 | break; |
| 250 | } |
| 251 | |
| 252 | /* Step 4: */ |
| 253 | if (pci_write_config_byte(pdev, LBCIF_DATA_REGISTER_OFFSET, |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 254 | data)) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 255 | break; |
| 256 | } |
| 257 | |
| 258 | /* Step 5: */ |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 259 | for (index = 0; index < MAX_NUM_REGISTER_POLLS; index++) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 260 | /* Read registers grouped in DWORD1 */ |
| 261 | if (pci_read_config_dword(pdev, |
| 262 | LBCIF_DWORD1_GROUP_OFFSET, |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 263 | &dword1)) { |
| 264 | err = 1; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 265 | break; |
| 266 | } |
| 267 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 268 | status = EXTRACT_STATUS_REGISTER(dword1); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 269 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 270 | if (status & LBCIF_STATUS_PHY_QUEUE_AVAIL && |
| 271 | status & LBCIF_STATUS_I2C_IDLE) { |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 272 | /* I2C write complete */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 273 | break; |
| 274 | } |
| 275 | } |
| 276 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 277 | if (err || (index >= MAX_NUM_REGISTER_POLLS)) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 278 | break; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 279 | |
| 280 | /* |
| 281 | * Step 6: Don't break here if we are revision 1, this is |
| 282 | * so we do a blind write for load bug. |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 283 | */ |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 284 | if (status & LBCIF_STATUS_GENERAL_ERROR |
Alan Cox | 5ec3487 | 2009-08-27 10:59:13 +0100 | [diff] [blame] | 285 | && etdev->pdev->revision == 0) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 286 | break; |
| 287 | } |
| 288 | |
| 289 | /* Step 7 */ |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 290 | if (status & LBCIF_STATUS_ACK_ERROR) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 291 | /* |
| 292 | * This could be due to an actual hardware failure |
| 293 | * or the EEPROM may still be in its internal write |
| 294 | * cycle from a previous write. This write operation |
| 295 | * was ignored and must be repeated later. |
| 296 | */ |
| 297 | udelay(10); |
| 298 | continue; |
| 299 | } |
| 300 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 301 | writeok = 1; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 302 | break; |
| 303 | } |
| 304 | |
| 305 | /* Step 8: */ |
| 306 | udelay(10); |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 307 | index = 0; |
| 308 | while (i2c_wack) { |
| 309 | control &= ~LBCIF_CONTROL_I2C_WRITE; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 310 | |
| 311 | if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER_OFFSET, |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 312 | control)) { |
| 313 | writeok = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | /* Do read until internal ACK_ERROR goes away meaning write |
| 317 | * completed |
| 318 | */ |
| 319 | do { |
| 320 | pci_write_config_dword(pdev, |
| 321 | LBCIF_ADDRESS_REGISTER_OFFSET, |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 322 | addr); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 323 | do { |
| 324 | pci_read_config_dword(pdev, |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 325 | LBCIF_DATA_REGISTER_OFFSET, &val); |
| 326 | } while ((val & 0x00010000) == 0); |
| 327 | } while (val & 0x00040000); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 328 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 329 | control = EXTRACT_CONTROL_REG(val); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 330 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 331 | if (control != 0xC0 || index == 10000) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 332 | break; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 333 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 334 | index++; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Alan Cox | 53f8aee | 2009-10-06 15:46:24 +0100 | [diff] [blame^] | 337 | return writeok; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | /** |
| 341 | * EepromReadByte - Read a byte from the ET1310's EEPROM |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 342 | * @etdev: pointer to our private adapter structure |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 343 | * @addr: the address from which to read |
| 344 | * @pdata: a pointer to a byte in which to store the value of the read |
| 345 | * @eeprom_id: the ID of the EEPROM |
| 346 | * @addrmode: how the EEPROM is to be accessed |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 347 | * |
Alan Cox | 53f8aee | 2009-10-06 15:46:24 +0100 | [diff] [blame^] | 348 | * Returns 1 for a successful read |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 349 | */ |
Alan Cox | 13071fd | 2009-08-27 11:01:04 +0100 | [diff] [blame] | 350 | int EepromReadByte(struct et131x_adapter *etdev, u32 addr, u8 *pdata) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 351 | { |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 352 | struct pci_dev *pdev = etdev->pdev; |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 353 | int index; |
| 354 | int err = 0; |
| 355 | u8 control; |
| 356 | u8 status = 0; |
| 357 | u32 dword1 = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 358 | |
| 359 | /* |
| 360 | * The following excerpt is from "Serial EEPROM HW Design |
| 361 | * Specification" Version 0.92 (9/20/2004): |
| 362 | * |
| 363 | * Single Byte Reads |
| 364 | * |
| 365 | * A single byte read is similar to the single byte write, with the |
| 366 | * exception of the data flow: |
| 367 | * |
| 368 | * 1. Check LBCIF Status Register for bits 6 & 3:2 all equal to 0 and |
| 369 | * bits 7,1:0 both equal to 1, at least once after reset. |
| 370 | * Subsequent operations need only to check that bits 1:0 are equal |
| 371 | * to 1 prior to starting a single byte read. |
| 372 | * |
| 373 | * 2. Write to the LBCIF Control Register: bit 7=1, bit 6=0, bit 3=0, |
| 374 | * and bits 1:0 both =0. Bit 5 should be set according to the type |
| 375 | * of EEPROM being accessed (1=two byte addressing, 0=one byte |
| 376 | * addressing). |
| 377 | * |
| 378 | * 3. Write the address to the LBCIF Address Register (I2C read will |
| 379 | * begin). |
| 380 | * |
| 381 | * 4. Monitor bit 0 of the LBCIF Status Register. When =1, I2C read |
| 382 | * is complete. (if bit 1 =1 and bit 0 stays =0, a hardware failure |
| 383 | * has occurred). |
| 384 | * |
| 385 | * 5. Check bit 2 of the LBCIF Status Register. If =1, then an error |
| 386 | * has occurred. The data that has been returned from the PHY may |
| 387 | * be invalid. |
| 388 | * |
| 389 | * 6. Regardless of error status, read data byte from LBCIF Data |
| 390 | * Register. If another byte is required, go to step 1. |
| 391 | */ |
| 392 | |
| 393 | /* Step 1: */ |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 394 | for (index = 0; index < MAX_NUM_REGISTER_POLLS; index++) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 395 | /* Read registers grouped in DWORD1 */ |
| 396 | if (pci_read_config_dword(pdev, LBCIF_DWORD1_GROUP_OFFSET, |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 397 | &dword1)) { |
| 398 | err = 1; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 399 | break; |
| 400 | } |
| 401 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 402 | status = EXTRACT_STATUS_REGISTER(dword1); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 403 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 404 | if (status & LBCIF_STATUS_PHY_QUEUE_AVAIL && |
| 405 | status & LBCIF_STATUS_I2C_IDLE) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 406 | /* bits 1:0 are equal to 1 */ |
| 407 | break; |
| 408 | } |
| 409 | } |
| 410 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 411 | if (err || (index >= MAX_NUM_REGISTER_POLLS)) |
Alan Cox | 53f8aee | 2009-10-06 15:46:24 +0100 | [diff] [blame^] | 412 | return 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 413 | |
| 414 | /* Step 2: */ |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 415 | control = 0; |
| 416 | control |= LBCIF_CONTROL_LBCIF_ENABLE; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 417 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 418 | if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER_OFFSET, |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 419 | control)) { |
Alan Cox | 53f8aee | 2009-10-06 15:46:24 +0100 | [diff] [blame^] | 420 | return 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* Step 3: */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 424 | |
| 425 | if (pci_write_config_dword(pdev, LBCIF_ADDRESS_REGISTER_OFFSET, |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 426 | addr)) { |
Alan Cox | 53f8aee | 2009-10-06 15:46:24 +0100 | [diff] [blame^] | 427 | return 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | /* Step 4: */ |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 431 | for (index = 0; index < MAX_NUM_REGISTER_POLLS; index++) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 432 | /* Read registers grouped in DWORD1 */ |
| 433 | if (pci_read_config_dword(pdev, LBCIF_DWORD1_GROUP_OFFSET, |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 434 | &dword1)) { |
| 435 | err = 1; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 436 | break; |
| 437 | } |
| 438 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 439 | status = EXTRACT_STATUS_REGISTER(dword1); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 440 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 441 | if (status & LBCIF_STATUS_PHY_QUEUE_AVAIL |
| 442 | && status & LBCIF_STATUS_I2C_IDLE) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 443 | /* I2C read complete */ |
| 444 | break; |
| 445 | } |
| 446 | } |
| 447 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 448 | if (err || (index >= MAX_NUM_REGISTER_POLLS)) |
Alan Cox | 53f8aee | 2009-10-06 15:46:24 +0100 | [diff] [blame^] | 449 | return 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 450 | |
| 451 | /* Step 6: */ |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 452 | *pdata = EXTRACT_DATA_REGISTER(dword1); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 453 | |
Alan Cox | 53f8aee | 2009-10-06 15:46:24 +0100 | [diff] [blame^] | 454 | return (status & LBCIF_STATUS_ACK_ERROR) ? 0 : 1; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 455 | } |