Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2009-2010 Realtek Corporation. |
| 4 | * |
| 5 | * Tmis program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * Tmis program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * tmis program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 17 | * |
| 18 | * Tme full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * wlanfae <wlanfae@realtek.com> |
| 23 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, |
| 24 | * Hsinchu 300, Taiwan. |
| 25 | * |
| 26 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
| 30 | #include "wifi.h" |
| 31 | #include "efuse.h" |
| 32 | |
| 33 | static const u8 MAX_PGPKT_SIZE = 9; |
| 34 | static const u8 PGPKT_DATA_SIZE = 8; |
| 35 | static const int EFUSE_MAX_SIZE = 512; |
| 36 | |
| 37 | static const u8 EFUSE_OOB_PROTECT_BYTES = 15; |
| 38 | |
| 39 | static const struct efuse_map RTL8712_SDIO_EFUSE_TABLE[] = { |
| 40 | {0, 0, 0, 2}, |
| 41 | {0, 1, 0, 2}, |
| 42 | {0, 2, 0, 2}, |
| 43 | {1, 0, 0, 1}, |
| 44 | {1, 0, 1, 1}, |
| 45 | {1, 1, 0, 1}, |
| 46 | {1, 1, 1, 3}, |
| 47 | {1, 3, 0, 17}, |
| 48 | {3, 3, 1, 48}, |
| 49 | {10, 0, 0, 6}, |
| 50 | {10, 3, 0, 1}, |
| 51 | {10, 3, 1, 1}, |
| 52 | {11, 0, 0, 28} |
| 53 | }; |
| 54 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 55 | static void efuse_shadow_read_1byte(struct ieee80211_hw *hw, u16 offset, |
| 56 | u8 *value); |
| 57 | static void efuse_shadow_read_2byte(struct ieee80211_hw *hw, u16 offset, |
| 58 | u16 *value); |
| 59 | static void efuse_shadow_read_4byte(struct ieee80211_hw *hw, u16 offset, |
| 60 | u32 *value); |
| 61 | static void efuse_shadow_write_1byte(struct ieee80211_hw *hw, u16 offset, |
| 62 | u8 value); |
| 63 | static void efuse_shadow_write_2byte(struct ieee80211_hw *hw, u16 offset, |
| 64 | u16 value); |
| 65 | static void efuse_shadow_write_4byte(struct ieee80211_hw *hw, u16 offset, |
| 66 | u32 value); |
| 67 | static int efuse_one_byte_read(struct ieee80211_hw *hw, u16 addr, |
| 68 | u8 *data); |
| 69 | static int efuse_one_byte_write(struct ieee80211_hw *hw, u16 addr, |
| 70 | u8 data); |
| 71 | static void efuse_read_all_map(struct ieee80211_hw *hw, u8 *efuse); |
| 72 | static int efuse_pg_packet_read(struct ieee80211_hw *hw, u8 offset, |
| 73 | u8 *data); |
| 74 | static int efuse_pg_packet_write(struct ieee80211_hw *hw, u8 offset, |
| 75 | u8 word_en, u8 *data); |
| 76 | static void efuse_word_enable_data_read(u8 word_en, u8 *sourdata, |
| 77 | u8 *targetdata); |
| 78 | static u8 efuse_word_enable_data_write(struct ieee80211_hw *hw, |
| 79 | u16 efuse_addr, u8 word_en, u8 *data); |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 80 | static void efuse_power_switch(struct ieee80211_hw *hw, u8 write, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 81 | u8 pwrstate); |
| 82 | static u16 efuse_get_current_size(struct ieee80211_hw *hw); |
| 83 | static u8 efuse_calculate_word_cnts(u8 word_en); |
| 84 | |
| 85 | void efuse_initialize(struct ieee80211_hw *hw) |
| 86 | { |
| 87 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 88 | u8 bytetemp; |
| 89 | u8 temp; |
| 90 | |
| 91 | bytetemp = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[SYS_FUNC_EN] + 1); |
| 92 | temp = bytetemp | 0x20; |
| 93 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[SYS_FUNC_EN] + 1, temp); |
| 94 | |
| 95 | bytetemp = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[SYS_ISO_CTRL] + 1); |
| 96 | temp = bytetemp & 0xFE; |
| 97 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[SYS_ISO_CTRL] + 1, temp); |
| 98 | |
| 99 | bytetemp = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_TEST] + 3); |
| 100 | temp = bytetemp | 0x80; |
| 101 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_TEST] + 3, temp); |
| 102 | |
| 103 | rtl_write_byte(rtlpriv, 0x2F8, 0x3); |
| 104 | |
| 105 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3, 0x72); |
| 106 | |
| 107 | } |
| 108 | |
| 109 | u8 efuse_read_1byte(struct ieee80211_hw *hw, u16 address) |
| 110 | { |
| 111 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 112 | u8 data; |
| 113 | u8 bytetemp; |
| 114 | u8 temp; |
| 115 | u32 k = 0; |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 116 | const u32 efuse_len = |
| 117 | rtlpriv->cfg->maps[EFUSE_REAL_CONTENT_SIZE]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 118 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 119 | if (address < efuse_len) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 120 | temp = address & 0xFF; |
| 121 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1, |
| 122 | temp); |
| 123 | bytetemp = rtl_read_byte(rtlpriv, |
| 124 | rtlpriv->cfg->maps[EFUSE_CTRL] + 2); |
| 125 | temp = ((address >> 8) & 0x03) | (bytetemp & 0xFC); |
| 126 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2, |
| 127 | temp); |
| 128 | |
| 129 | bytetemp = rtl_read_byte(rtlpriv, |
| 130 | rtlpriv->cfg->maps[EFUSE_CTRL] + 3); |
| 131 | temp = bytetemp & 0x7F; |
| 132 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3, |
| 133 | temp); |
| 134 | |
| 135 | bytetemp = rtl_read_byte(rtlpriv, |
| 136 | rtlpriv->cfg->maps[EFUSE_CTRL] + 3); |
| 137 | while (!(bytetemp & 0x80)) { |
| 138 | bytetemp = rtl_read_byte(rtlpriv, |
| 139 | rtlpriv->cfg-> |
| 140 | maps[EFUSE_CTRL] + 3); |
| 141 | k++; |
| 142 | if (k == 1000) { |
| 143 | k = 0; |
| 144 | break; |
| 145 | } |
| 146 | } |
| 147 | data = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]); |
| 148 | return data; |
| 149 | } else |
| 150 | return 0xFF; |
| 151 | |
| 152 | } |
| 153 | EXPORT_SYMBOL(efuse_read_1byte); |
| 154 | |
| 155 | void efuse_write_1byte(struct ieee80211_hw *hw, u16 address, u8 value) |
| 156 | { |
| 157 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 158 | u8 bytetemp; |
| 159 | u8 temp; |
| 160 | u32 k = 0; |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 161 | const u32 efuse_len = |
| 162 | rtlpriv->cfg->maps[EFUSE_REAL_CONTENT_SIZE]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 163 | |
| 164 | RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, |
| 165 | ("Addr=%x Data =%x\n", address, value)); |
| 166 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 167 | if (address < efuse_len) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 168 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL], value); |
| 169 | |
| 170 | temp = address & 0xFF; |
| 171 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1, |
| 172 | temp); |
| 173 | bytetemp = rtl_read_byte(rtlpriv, |
| 174 | rtlpriv->cfg->maps[EFUSE_CTRL] + 2); |
| 175 | |
| 176 | temp = ((address >> 8) & 0x03) | (bytetemp & 0xFC); |
| 177 | rtl_write_byte(rtlpriv, |
| 178 | rtlpriv->cfg->maps[EFUSE_CTRL] + 2, temp); |
| 179 | |
| 180 | bytetemp = rtl_read_byte(rtlpriv, |
| 181 | rtlpriv->cfg->maps[EFUSE_CTRL] + 3); |
| 182 | temp = bytetemp | 0x80; |
| 183 | rtl_write_byte(rtlpriv, |
| 184 | rtlpriv->cfg->maps[EFUSE_CTRL] + 3, temp); |
| 185 | |
| 186 | bytetemp = rtl_read_byte(rtlpriv, |
| 187 | rtlpriv->cfg->maps[EFUSE_CTRL] + 3); |
| 188 | |
| 189 | while (bytetemp & 0x80) { |
| 190 | bytetemp = rtl_read_byte(rtlpriv, |
| 191 | rtlpriv->cfg-> |
| 192 | maps[EFUSE_CTRL] + 3); |
| 193 | k++; |
| 194 | if (k == 100) { |
| 195 | k = 0; |
| 196 | break; |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | } |
| 202 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 203 | void read_efuse_byte(struct ieee80211_hw *hw, u16 _offset, u8 *pbuf) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 204 | { |
| 205 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 206 | u32 value32; |
| 207 | u8 readbyte; |
| 208 | u16 retry; |
| 209 | |
| 210 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1, |
| 211 | (_offset & 0xff)); |
| 212 | readbyte = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2); |
| 213 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2, |
| 214 | ((_offset >> 8) & 0x03) | (readbyte & 0xfc)); |
| 215 | |
| 216 | readbyte = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3); |
| 217 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3, |
| 218 | (readbyte & 0x7f)); |
| 219 | |
| 220 | retry = 0; |
| 221 | value32 = rtl_read_dword(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]); |
| 222 | while (!(((value32 >> 24) & 0xff) & 0x80) && (retry < 10000)) { |
| 223 | value32 = rtl_read_dword(rtlpriv, |
| 224 | rtlpriv->cfg->maps[EFUSE_CTRL]); |
| 225 | retry++; |
| 226 | } |
| 227 | |
| 228 | udelay(50); |
| 229 | value32 = rtl_read_dword(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]); |
| 230 | |
| 231 | *pbuf = (u8) (value32 & 0xff); |
| 232 | } |
| 233 | |
| 234 | void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 _size_byte, u8 *pbuf) |
| 235 | { |
| 236 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 237 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
Larry Finger | c84aa5a | 2011-05-06 13:56:18 -0500 | [diff] [blame] | 238 | u8 *efuse_tbl; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 239 | u8 rtemp8[1]; |
| 240 | u16 efuse_addr = 0; |
| 241 | u8 offset, wren; |
| 242 | u16 i; |
| 243 | u16 j; |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 244 | const u16 efuse_max_section = |
| 245 | rtlpriv->cfg->maps[EFUSE_MAX_SECTION_MAP]; |
| 246 | const u32 efuse_len = |
| 247 | rtlpriv->cfg->maps[EFUSE_REAL_CONTENT_SIZE]; |
Larry Finger | c84aa5a | 2011-05-06 13:56:18 -0500 | [diff] [blame] | 248 | u16 **efuse_word; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 249 | u16 efuse_utilized = 0; |
| 250 | u8 efuse_usage; |
| 251 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 252 | if ((_offset + _size_byte) > rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 253 | RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, |
| 254 | ("read_efuse(): Invalid offset(%#x) with read " |
| 255 | "bytes(%#x)!!\n", _offset, _size_byte)); |
| 256 | return; |
| 257 | } |
| 258 | |
Larry Finger | c84aa5a | 2011-05-06 13:56:18 -0500 | [diff] [blame] | 259 | /* allocate memory for efuse_tbl and efuse_word */ |
| 260 | efuse_tbl = kmalloc(rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE] * |
| 261 | sizeof(u8), GFP_ATOMIC); |
| 262 | if (!efuse_tbl) |
| 263 | return; |
| 264 | efuse_word = kmalloc(EFUSE_MAX_WORD_UNIT * sizeof(u16 *), GFP_ATOMIC); |
| 265 | if (!efuse_word) |
| 266 | goto done; |
| 267 | for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) { |
| 268 | efuse_word[i] = kmalloc(efuse_max_section * sizeof(u16), |
| 269 | GFP_ATOMIC); |
| 270 | if (!efuse_word[i]) |
| 271 | goto done; |
| 272 | } |
| 273 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 274 | for (i = 0; i < efuse_max_section; i++) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 275 | for (j = 0; j < EFUSE_MAX_WORD_UNIT; j++) |
Larry Finger | c84aa5a | 2011-05-06 13:56:18 -0500 | [diff] [blame] | 276 | efuse_word[j][i] = 0xFFFF; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 277 | |
| 278 | read_efuse_byte(hw, efuse_addr, rtemp8); |
| 279 | if (*rtemp8 != 0xFF) { |
| 280 | efuse_utilized++; |
| 281 | RTPRINT(rtlpriv, FEEPROM, EFUSE_READ_ALL, |
| 282 | ("Addr=%d\n", efuse_addr)); |
| 283 | efuse_addr++; |
| 284 | } |
| 285 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 286 | while ((*rtemp8 != 0xFF) && (efuse_addr < efuse_len)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 287 | offset = ((*rtemp8 >> 4) & 0x0f); |
| 288 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 289 | if (offset < efuse_max_section) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 290 | wren = (*rtemp8 & 0x0f); |
| 291 | RTPRINT(rtlpriv, FEEPROM, EFUSE_READ_ALL, |
| 292 | ("offset-%d Worden=%x\n", offset, wren)); |
| 293 | |
| 294 | for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) { |
| 295 | if (!(wren & 0x01)) { |
| 296 | RTPRINT(rtlpriv, FEEPROM, |
| 297 | EFUSE_READ_ALL, ("Addr=%d\n", |
| 298 | efuse_addr)); |
| 299 | |
| 300 | read_efuse_byte(hw, efuse_addr, rtemp8); |
| 301 | efuse_addr++; |
| 302 | efuse_utilized++; |
Larry Finger | c84aa5a | 2011-05-06 13:56:18 -0500 | [diff] [blame] | 303 | efuse_word[i][offset] = |
| 304 | (*rtemp8 & 0xff); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 305 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 306 | if (efuse_addr >= efuse_len) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 307 | break; |
| 308 | |
| 309 | RTPRINT(rtlpriv, FEEPROM, |
| 310 | EFUSE_READ_ALL, ("Addr=%d\n", |
| 311 | efuse_addr)); |
| 312 | |
| 313 | read_efuse_byte(hw, efuse_addr, rtemp8); |
| 314 | efuse_addr++; |
| 315 | efuse_utilized++; |
Larry Finger | c84aa5a | 2011-05-06 13:56:18 -0500 | [diff] [blame] | 316 | efuse_word[i][offset] |= |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 317 | (((u16)*rtemp8 << 8) & 0xff00); |
| 318 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 319 | if (efuse_addr >= efuse_len) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 320 | break; |
| 321 | } |
| 322 | |
| 323 | wren >>= 1; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | RTPRINT(rtlpriv, FEEPROM, EFUSE_READ_ALL, |
| 328 | ("Addr=%d\n", efuse_addr)); |
| 329 | read_efuse_byte(hw, efuse_addr, rtemp8); |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 330 | if (*rtemp8 != 0xFF && (efuse_addr < efuse_len)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 331 | efuse_utilized++; |
| 332 | efuse_addr++; |
| 333 | } |
| 334 | } |
| 335 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 336 | for (i = 0; i < efuse_max_section; i++) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 337 | for (j = 0; j < EFUSE_MAX_WORD_UNIT; j++) { |
| 338 | efuse_tbl[(i * 8) + (j * 2)] = |
Larry Finger | c84aa5a | 2011-05-06 13:56:18 -0500 | [diff] [blame] | 339 | (efuse_word[j][i] & 0xff); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 340 | efuse_tbl[(i * 8) + ((j * 2) + 1)] = |
Larry Finger | c84aa5a | 2011-05-06 13:56:18 -0500 | [diff] [blame] | 341 | ((efuse_word[j][i] >> 8) & 0xff); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
| 345 | for (i = 0; i < _size_byte; i++) |
| 346 | pbuf[i] = efuse_tbl[_offset + i]; |
| 347 | |
| 348 | rtlefuse->efuse_usedbytes = efuse_utilized; |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 349 | efuse_usage = (u8) ((efuse_utilized * 100) / efuse_len); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 350 | rtlefuse->efuse_usedpercentage = efuse_usage; |
| 351 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_EFUSE_BYTES, |
| 352 | (u8 *)&efuse_utilized); |
| 353 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_EFUSE_USAGE, |
| 354 | (u8 *)&efuse_usage); |
Larry Finger | c84aa5a | 2011-05-06 13:56:18 -0500 | [diff] [blame] | 355 | done: |
| 356 | for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) |
| 357 | kfree(efuse_word[i]); |
| 358 | kfree(efuse_word); |
| 359 | kfree(efuse_tbl); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | bool efuse_shadow_update_chk(struct ieee80211_hw *hw) |
| 363 | { |
| 364 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 365 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 366 | u8 section_idx, i, Base; |
| 367 | u16 words_need = 0, hdr_num = 0, totalbytes, efuse_used; |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 368 | bool wordchanged, result = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 369 | |
| 370 | for (section_idx = 0; section_idx < 16; section_idx++) { |
| 371 | Base = section_idx * 8; |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 372 | wordchanged = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 373 | |
| 374 | for (i = 0; i < 8; i = i + 2) { |
| 375 | if ((rtlefuse->efuse_map[EFUSE_INIT_MAP][Base + i] != |
| 376 | rtlefuse->efuse_map[EFUSE_MODIFY_MAP][Base + i]) || |
| 377 | (rtlefuse->efuse_map[EFUSE_INIT_MAP][Base + i + 1] != |
| 378 | rtlefuse->efuse_map[EFUSE_MODIFY_MAP][Base + i + |
| 379 | 1])) { |
| 380 | words_need++; |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 381 | wordchanged = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 385 | if (wordchanged == true) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 386 | hdr_num++; |
| 387 | } |
| 388 | |
| 389 | totalbytes = hdr_num + words_need * 2; |
| 390 | efuse_used = rtlefuse->efuse_usedbytes; |
| 391 | |
| 392 | if ((totalbytes + efuse_used) >= |
| 393 | (EFUSE_MAX_SIZE - EFUSE_OOB_PROTECT_BYTES)) |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 394 | result = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 395 | |
| 396 | RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, |
| 397 | ("efuse_shadow_update_chk(): totalbytes(%#x), " |
| 398 | "hdr_num(%#x), words_need(%#x), efuse_used(%d)\n", |
| 399 | totalbytes, hdr_num, words_need, efuse_used)); |
| 400 | |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 401 | return result; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | void efuse_shadow_read(struct ieee80211_hw *hw, u8 type, |
| 405 | u16 offset, u32 *value) |
| 406 | { |
| 407 | if (type == 1) |
| 408 | efuse_shadow_read_1byte(hw, offset, (u8 *) value); |
| 409 | else if (type == 2) |
| 410 | efuse_shadow_read_2byte(hw, offset, (u16 *) value); |
| 411 | else if (type == 4) |
| 412 | efuse_shadow_read_4byte(hw, offset, (u32 *) value); |
| 413 | |
| 414 | } |
| 415 | |
| 416 | void efuse_shadow_write(struct ieee80211_hw *hw, u8 type, u16 offset, |
| 417 | u32 value) |
| 418 | { |
| 419 | if (type == 1) |
| 420 | efuse_shadow_write_1byte(hw, offset, (u8) value); |
| 421 | else if (type == 2) |
| 422 | efuse_shadow_write_2byte(hw, offset, (u16) value); |
| 423 | else if (type == 4) |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 424 | efuse_shadow_write_4byte(hw, offset, value); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 425 | |
| 426 | } |
| 427 | |
| 428 | bool efuse_shadow_update(struct ieee80211_hw *hw) |
| 429 | { |
| 430 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 431 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 432 | u16 i, offset, base; |
| 433 | u8 word_en = 0x0F; |
| 434 | u8 first_pg = false; |
| 435 | |
| 436 | RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, ("--->\n")); |
| 437 | |
| 438 | if (!efuse_shadow_update_chk(hw)) { |
| 439 | efuse_read_all_map(hw, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0]); |
Ilia Mirkin | 6e9d592 | 2011-03-17 14:08:57 -0400 | [diff] [blame] | 440 | memcpy(&rtlefuse->efuse_map[EFUSE_MODIFY_MAP][0], |
| 441 | &rtlefuse->efuse_map[EFUSE_INIT_MAP][0], |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 442 | rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]); |
| 443 | |
| 444 | RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, |
| 445 | ("<---efuse out of capacity!!\n")); |
| 446 | return false; |
| 447 | } |
| 448 | efuse_power_switch(hw, true, true); |
| 449 | |
| 450 | for (offset = 0; offset < 16; offset++) { |
| 451 | |
| 452 | word_en = 0x0F; |
| 453 | base = offset * 8; |
| 454 | |
| 455 | for (i = 0; i < 8; i++) { |
| 456 | if (first_pg == true) { |
| 457 | |
| 458 | word_en &= ~(BIT(i / 2)); |
| 459 | |
| 460 | rtlefuse->efuse_map[EFUSE_INIT_MAP][base + i] = |
| 461 | rtlefuse->efuse_map[EFUSE_MODIFY_MAP][base + i]; |
| 462 | } else { |
| 463 | |
| 464 | if (rtlefuse->efuse_map[EFUSE_INIT_MAP][base + i] != |
| 465 | rtlefuse->efuse_map[EFUSE_MODIFY_MAP][base + i]) { |
| 466 | word_en &= ~(BIT(i / 2)); |
| 467 | |
| 468 | rtlefuse->efuse_map[EFUSE_INIT_MAP][base + i] = |
| 469 | rtlefuse->efuse_map[EFUSE_MODIFY_MAP][base + i]; |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | if (word_en != 0x0F) { |
| 475 | u8 tmpdata[8]; |
Ilia Mirkin | 6e9d592 | 2011-03-17 14:08:57 -0400 | [diff] [blame] | 476 | memcpy(tmpdata, |
| 477 | &rtlefuse->efuse_map[EFUSE_MODIFY_MAP][base], |
| 478 | 8); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 479 | RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_LOUD, |
| 480 | ("U-efuse\n"), tmpdata, 8); |
| 481 | |
| 482 | if (!efuse_pg_packet_write(hw, (u8) offset, word_en, |
| 483 | tmpdata)) { |
| 484 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
| 485 | ("PG section(%#x) fail!!\n", offset)); |
| 486 | break; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | } |
| 491 | |
| 492 | efuse_power_switch(hw, true, false); |
| 493 | efuse_read_all_map(hw, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0]); |
| 494 | |
Ilia Mirkin | 6e9d592 | 2011-03-17 14:08:57 -0400 | [diff] [blame] | 495 | memcpy(&rtlefuse->efuse_map[EFUSE_MODIFY_MAP][0], |
| 496 | &rtlefuse->efuse_map[EFUSE_INIT_MAP][0], |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 497 | rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]); |
| 498 | |
| 499 | RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, ("<---\n")); |
| 500 | return true; |
| 501 | } |
| 502 | |
| 503 | void rtl_efuse_shadow_map_update(struct ieee80211_hw *hw) |
| 504 | { |
| 505 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 506 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 507 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 508 | if (rtlefuse->autoload_failflag == true) |
| 509 | memset(&rtlefuse->efuse_map[EFUSE_INIT_MAP][0], 0xFF, |
| 510 | rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]); |
| 511 | else |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 512 | efuse_read_all_map(hw, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0]); |
| 513 | |
Ilia Mirkin | 6e9d592 | 2011-03-17 14:08:57 -0400 | [diff] [blame] | 514 | memcpy(&rtlefuse->efuse_map[EFUSE_MODIFY_MAP][0], |
| 515 | &rtlefuse->efuse_map[EFUSE_INIT_MAP][0], |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 516 | rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]); |
| 517 | |
| 518 | } |
| 519 | EXPORT_SYMBOL(rtl_efuse_shadow_map_update); |
| 520 | |
| 521 | void efuse_force_write_vendor_Id(struct ieee80211_hw *hw) |
| 522 | { |
| 523 | u8 tmpdata[8] = { 0xFF, 0xFF, 0xEC, 0x10, 0xFF, 0xFF, 0xFF, 0xFF }; |
| 524 | |
| 525 | efuse_power_switch(hw, true, true); |
| 526 | |
| 527 | efuse_pg_packet_write(hw, 1, 0xD, tmpdata); |
| 528 | |
| 529 | efuse_power_switch(hw, true, false); |
| 530 | |
| 531 | } |
| 532 | |
| 533 | void efuse_re_pg_section(struct ieee80211_hw *hw, u8 section_idx) |
| 534 | { |
| 535 | } |
| 536 | |
| 537 | static void efuse_shadow_read_1byte(struct ieee80211_hw *hw, |
| 538 | u16 offset, u8 *value) |
| 539 | { |
| 540 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 541 | *value = rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset]; |
| 542 | } |
| 543 | |
| 544 | static void efuse_shadow_read_2byte(struct ieee80211_hw *hw, |
| 545 | u16 offset, u16 *value) |
| 546 | { |
| 547 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 548 | |
| 549 | *value = rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset]; |
| 550 | *value |= rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 1] << 8; |
| 551 | |
| 552 | } |
| 553 | |
| 554 | static void efuse_shadow_read_4byte(struct ieee80211_hw *hw, |
| 555 | u16 offset, u32 *value) |
| 556 | { |
| 557 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 558 | |
| 559 | *value = rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset]; |
| 560 | *value |= rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 1] << 8; |
| 561 | *value |= rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 2] << 16; |
| 562 | *value |= rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 3] << 24; |
| 563 | } |
| 564 | |
| 565 | static void efuse_shadow_write_1byte(struct ieee80211_hw *hw, |
| 566 | u16 offset, u8 value) |
| 567 | { |
| 568 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 569 | |
| 570 | rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset] = value; |
| 571 | } |
| 572 | |
| 573 | static void efuse_shadow_write_2byte(struct ieee80211_hw *hw, |
| 574 | u16 offset, u16 value) |
| 575 | { |
| 576 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 577 | |
| 578 | rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset] = value & 0x00FF; |
| 579 | rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 1] = value >> 8; |
| 580 | |
| 581 | } |
| 582 | |
| 583 | static void efuse_shadow_write_4byte(struct ieee80211_hw *hw, |
| 584 | u16 offset, u32 value) |
| 585 | { |
| 586 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 587 | |
| 588 | rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset] = |
| 589 | (u8) (value & 0x000000FF); |
| 590 | rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 1] = |
| 591 | (u8) ((value >> 8) & 0x0000FF); |
| 592 | rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 2] = |
| 593 | (u8) ((value >> 16) & 0x00FF); |
| 594 | rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 3] = |
| 595 | (u8) ((value >> 24) & 0xFF); |
| 596 | |
| 597 | } |
| 598 | |
| 599 | static int efuse_one_byte_read(struct ieee80211_hw *hw, u16 addr, u8 *data) |
| 600 | { |
| 601 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 602 | u8 tmpidx = 0; |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 603 | int result; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 604 | |
| 605 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1, |
| 606 | (u8) (addr & 0xff)); |
| 607 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2, |
| 608 | ((u8) ((addr >> 8) & 0x03)) | |
| 609 | (rtl_read_byte(rtlpriv, |
| 610 | rtlpriv->cfg->maps[EFUSE_CTRL] + 2) & |
| 611 | 0xFC)); |
| 612 | |
| 613 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3, 0x72); |
| 614 | |
| 615 | while (!(0x80 & rtl_read_byte(rtlpriv, |
| 616 | rtlpriv->cfg->maps[EFUSE_CTRL] + 3)) |
| 617 | && (tmpidx < 100)) { |
| 618 | tmpidx++; |
| 619 | } |
| 620 | |
| 621 | if (tmpidx < 100) { |
| 622 | *data = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]); |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 623 | result = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 624 | } else { |
| 625 | *data = 0xff; |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 626 | result = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 627 | } |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 628 | return result; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | static int efuse_one_byte_write(struct ieee80211_hw *hw, u16 addr, u8 data) |
| 632 | { |
| 633 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 634 | u8 tmpidx = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 635 | |
| 636 | RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, |
| 637 | ("Addr = %x Data=%x\n", addr, data)); |
| 638 | |
| 639 | rtl_write_byte(rtlpriv, |
| 640 | rtlpriv->cfg->maps[EFUSE_CTRL] + 1, (u8) (addr & 0xff)); |
| 641 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2, |
| 642 | (rtl_read_byte(rtlpriv, |
| 643 | rtlpriv->cfg->maps[EFUSE_CTRL] + |
| 644 | 2) & 0xFC) | (u8) ((addr >> 8) & 0x03)); |
| 645 | |
| 646 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL], data); |
| 647 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3, 0xF2); |
| 648 | |
| 649 | while ((0x80 & rtl_read_byte(rtlpriv, |
| 650 | rtlpriv->cfg->maps[EFUSE_CTRL] + 3)) |
| 651 | && (tmpidx < 100)) { |
| 652 | tmpidx++; |
| 653 | } |
| 654 | |
| 655 | if (tmpidx < 100) |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 656 | return true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 657 | |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 658 | return false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | static void efuse_read_all_map(struct ieee80211_hw *hw, u8 * efuse) |
| 662 | { |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 663 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 664 | efuse_power_switch(hw, false, true); |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 665 | read_efuse(hw, 0, rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE], efuse); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 666 | efuse_power_switch(hw, false, false); |
| 667 | } |
| 668 | |
| 669 | static void efuse_read_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr, |
| 670 | u8 efuse_data, u8 offset, u8 *tmpdata, |
| 671 | u8 *readstate) |
| 672 | { |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 673 | bool dataempty = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 674 | u8 hoffset; |
| 675 | u8 tmpidx; |
| 676 | u8 hworden; |
| 677 | u8 word_cnts; |
| 678 | |
| 679 | hoffset = (efuse_data >> 4) & 0x0F; |
| 680 | hworden = efuse_data & 0x0F; |
| 681 | word_cnts = efuse_calculate_word_cnts(hworden); |
| 682 | |
| 683 | if (hoffset == offset) { |
| 684 | for (tmpidx = 0; tmpidx < word_cnts * 2; tmpidx++) { |
| 685 | if (efuse_one_byte_read(hw, *efuse_addr + 1 + tmpidx, |
| 686 | &efuse_data)) { |
| 687 | tmpdata[tmpidx] = efuse_data; |
| 688 | if (efuse_data != 0xff) |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 689 | dataempty = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 693 | if (dataempty == true) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 694 | *readstate = PG_STATE_DATA; |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 695 | } else { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 696 | *efuse_addr = *efuse_addr + (word_cnts * 2) + 1; |
| 697 | *readstate = PG_STATE_HEADER; |
| 698 | } |
| 699 | |
| 700 | } else { |
| 701 | *efuse_addr = *efuse_addr + (word_cnts * 2) + 1; |
| 702 | *readstate = PG_STATE_HEADER; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | static int efuse_pg_packet_read(struct ieee80211_hw *hw, u8 offset, u8 *data) |
| 707 | { |
| 708 | u8 readstate = PG_STATE_HEADER; |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 709 | bool continual = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 710 | u8 efuse_data, word_cnts = 0; |
| 711 | u16 efuse_addr = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 712 | u8 tmpdata[8]; |
| 713 | |
| 714 | if (data == NULL) |
| 715 | return false; |
| 716 | if (offset > 15) |
| 717 | return false; |
| 718 | |
Ilia Mirkin | 6e9d592 | 2011-03-17 14:08:57 -0400 | [diff] [blame] | 719 | memset(data, 0xff, PGPKT_DATA_SIZE * sizeof(u8)); |
| 720 | memset(tmpdata, 0xff, PGPKT_DATA_SIZE * sizeof(u8)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 721 | |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 722 | while (continual && (efuse_addr < EFUSE_MAX_SIZE)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 723 | if (readstate & PG_STATE_HEADER) { |
| 724 | if (efuse_one_byte_read(hw, efuse_addr, &efuse_data) |
| 725 | && (efuse_data != 0xFF)) |
| 726 | efuse_read_data_case1(hw, &efuse_addr, |
| 727 | efuse_data, |
| 728 | offset, tmpdata, |
| 729 | &readstate); |
| 730 | else |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 731 | continual = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 732 | } else if (readstate & PG_STATE_DATA) { |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 733 | efuse_word_enable_data_read(0, tmpdata, data); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 734 | efuse_addr = efuse_addr + (word_cnts * 2) + 1; |
| 735 | readstate = PG_STATE_HEADER; |
| 736 | } |
| 737 | |
| 738 | } |
| 739 | |
| 740 | if ((data[0] == 0xff) && (data[1] == 0xff) && |
| 741 | (data[2] == 0xff) && (data[3] == 0xff) && |
| 742 | (data[4] == 0xff) && (data[5] == 0xff) && |
| 743 | (data[6] == 0xff) && (data[7] == 0xff)) |
| 744 | return false; |
| 745 | else |
| 746 | return true; |
| 747 | |
| 748 | } |
| 749 | |
| 750 | static void efuse_write_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr, |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 751 | u8 efuse_data, u8 offset, int *continual, |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 752 | u8 *write_state, struct pgpkt_struct *target_pkt, |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 753 | int *repeat_times, int *result, u8 word_en) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 754 | { |
| 755 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 756 | struct pgpkt_struct tmp_pkt; |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 757 | bool dataempty = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 758 | u8 originaldata[8 * sizeof(u8)]; |
| 759 | u8 badworden = 0x0F; |
| 760 | u8 match_word_en, tmp_word_en; |
| 761 | u8 tmpindex; |
| 762 | u8 tmp_header = efuse_data; |
| 763 | u8 tmp_word_cnts; |
| 764 | |
| 765 | tmp_pkt.offset = (tmp_header >> 4) & 0x0F; |
| 766 | tmp_pkt.word_en = tmp_header & 0x0F; |
| 767 | tmp_word_cnts = efuse_calculate_word_cnts(tmp_pkt.word_en); |
| 768 | |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 769 | if (tmp_pkt.offset != target_pkt->offset) { |
| 770 | *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) + 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 771 | *write_state = PG_STATE_HEADER; |
| 772 | } else { |
| 773 | for (tmpindex = 0; tmpindex < (tmp_word_cnts * 2); tmpindex++) { |
| 774 | u16 address = *efuse_addr + 1 + tmpindex; |
| 775 | if (efuse_one_byte_read(hw, address, |
| 776 | &efuse_data) && (efuse_data != 0xFF)) |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 777 | dataempty = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 778 | } |
| 779 | |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 780 | if (dataempty == false) { |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 781 | *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) + 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 782 | *write_state = PG_STATE_HEADER; |
| 783 | } else { |
| 784 | match_word_en = 0x0F; |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 785 | if (!((target_pkt->word_en & BIT(0)) | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 786 | (tmp_pkt.word_en & BIT(0)))) |
| 787 | match_word_en &= (~BIT(0)); |
| 788 | |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 789 | if (!((target_pkt->word_en & BIT(1)) | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 790 | (tmp_pkt.word_en & BIT(1)))) |
| 791 | match_word_en &= (~BIT(1)); |
| 792 | |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 793 | if (!((target_pkt->word_en & BIT(2)) | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 794 | (tmp_pkt.word_en & BIT(2)))) |
| 795 | match_word_en &= (~BIT(2)); |
| 796 | |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 797 | if (!((target_pkt->word_en & BIT(3)) | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 798 | (tmp_pkt.word_en & BIT(3)))) |
| 799 | match_word_en &= (~BIT(3)); |
| 800 | |
| 801 | if ((match_word_en & 0x0F) != 0x0F) { |
| 802 | badworden = efuse_word_enable_data_write( |
| 803 | hw, *efuse_addr + 1, |
| 804 | tmp_pkt.word_en, |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 805 | target_pkt->data); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 806 | |
| 807 | if (0x0F != (badworden & 0x0F)) { |
| 808 | u8 reorg_offset = offset; |
| 809 | u8 reorg_worden = badworden; |
| 810 | efuse_pg_packet_write(hw, reorg_offset, |
| 811 | reorg_worden, |
| 812 | originaldata); |
| 813 | } |
| 814 | |
| 815 | tmp_word_en = 0x0F; |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 816 | if ((target_pkt->word_en & BIT(0)) ^ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 817 | (match_word_en & BIT(0))) |
| 818 | tmp_word_en &= (~BIT(0)); |
| 819 | |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 820 | if ((target_pkt->word_en & BIT(1)) ^ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 821 | (match_word_en & BIT(1))) |
| 822 | tmp_word_en &= (~BIT(1)); |
| 823 | |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 824 | if ((target_pkt->word_en & BIT(2)) ^ |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 825 | (match_word_en & BIT(2))) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 826 | tmp_word_en &= (~BIT(2)); |
| 827 | |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 828 | if ((target_pkt->word_en & BIT(3)) ^ |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 829 | (match_word_en & BIT(3))) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 830 | tmp_word_en &= (~BIT(3)); |
| 831 | |
| 832 | if ((tmp_word_en & 0x0F) != 0x0F) { |
| 833 | *efuse_addr = efuse_get_current_size(hw); |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 834 | target_pkt->offset = offset; |
| 835 | target_pkt->word_en = tmp_word_en; |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 836 | } else { |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 837 | *continual = false; |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 838 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 839 | *write_state = PG_STATE_HEADER; |
| 840 | *repeat_times += 1; |
| 841 | if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) { |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 842 | *continual = false; |
| 843 | *result = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 844 | } |
| 845 | } else { |
| 846 | *efuse_addr += (2 * tmp_word_cnts) + 1; |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 847 | target_pkt->offset = offset; |
| 848 | target_pkt->word_en = word_en; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 849 | *write_state = PG_STATE_HEADER; |
| 850 | } |
| 851 | } |
| 852 | } |
| 853 | RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, ("efuse PG_STATE_HEADER-1\n")); |
| 854 | } |
| 855 | |
| 856 | static void efuse_write_data_case2(struct ieee80211_hw *hw, u16 *efuse_addr, |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 857 | int *continual, u8 *write_state, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 858 | struct pgpkt_struct target_pkt, |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 859 | int *repeat_times, int *result) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 860 | { |
| 861 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 862 | struct pgpkt_struct tmp_pkt; |
| 863 | u8 pg_header; |
| 864 | u8 tmp_header; |
| 865 | u8 originaldata[8 * sizeof(u8)]; |
| 866 | u8 tmp_word_cnts; |
| 867 | u8 badworden = 0x0F; |
| 868 | |
| 869 | pg_header = ((target_pkt.offset << 4) & 0xf0) | target_pkt.word_en; |
| 870 | efuse_one_byte_write(hw, *efuse_addr, pg_header); |
| 871 | efuse_one_byte_read(hw, *efuse_addr, &tmp_header); |
| 872 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 873 | if (tmp_header == pg_header) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 874 | *write_state = PG_STATE_DATA; |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 875 | } else if (tmp_header == 0xFF) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 876 | *write_state = PG_STATE_HEADER; |
| 877 | *repeat_times += 1; |
| 878 | if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) { |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 879 | *continual = false; |
| 880 | *result = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 881 | } |
| 882 | } else { |
| 883 | tmp_pkt.offset = (tmp_header >> 4) & 0x0F; |
| 884 | tmp_pkt.word_en = tmp_header & 0x0F; |
| 885 | |
| 886 | tmp_word_cnts = efuse_calculate_word_cnts(tmp_pkt.word_en); |
| 887 | |
Ilia Mirkin | 6e9d592 | 2011-03-17 14:08:57 -0400 | [diff] [blame] | 888 | memset(originaldata, 0xff, 8 * sizeof(u8)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 889 | |
| 890 | if (efuse_pg_packet_read(hw, tmp_pkt.offset, originaldata)) { |
| 891 | badworden = efuse_word_enable_data_write(hw, |
| 892 | *efuse_addr + 1, tmp_pkt.word_en, |
| 893 | originaldata); |
| 894 | |
| 895 | if (0x0F != (badworden & 0x0F)) { |
| 896 | u8 reorg_offset = tmp_pkt.offset; |
| 897 | u8 reorg_worden = badworden; |
| 898 | efuse_pg_packet_write(hw, reorg_offset, |
| 899 | reorg_worden, |
| 900 | originaldata); |
| 901 | *efuse_addr = efuse_get_current_size(hw); |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 902 | } else { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 903 | *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) |
| 904 | + 1; |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 905 | } |
| 906 | } else { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 907 | *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) + 1; |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 908 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 909 | |
| 910 | *write_state = PG_STATE_HEADER; |
| 911 | *repeat_times += 1; |
| 912 | if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) { |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 913 | *continual = false; |
| 914 | *result = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, |
| 918 | ("efuse PG_STATE_HEADER-2\n")); |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | static int efuse_pg_packet_write(struct ieee80211_hw *hw, |
| 923 | u8 offset, u8 word_en, u8 *data) |
| 924 | { |
| 925 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 926 | struct pgpkt_struct target_pkt; |
| 927 | u8 write_state = PG_STATE_HEADER; |
Larry Finger | 19086fc | 2011-05-22 20:54:31 -0500 | [diff] [blame^] | 928 | int continual = true, result = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 929 | u16 efuse_addr = 0; |
| 930 | u8 efuse_data; |
| 931 | u8 target_word_cnts = 0; |
| 932 | u8 badworden = 0x0F; |
| 933 | static int repeat_times; |
| 934 | |
| 935 | if (efuse_get_current_size(hw) >= |
| 936 | (EFUSE_MAX_SIZE - EFUSE_OOB_PROTECT_BYTES)) { |
| 937 | RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, |
| 938 | ("efuse_pg_packet_write error\n")); |
| 939 | return false; |
| 940 | } |
| 941 | |
| 942 | target_pkt.offset = offset; |
| 943 | target_pkt.word_en = word_en; |
| 944 | |
Ilia Mirkin | 6e9d592 | 2011-03-17 14:08:57 -0400 | [diff] [blame] | 945 | memset(target_pkt.data, 0xFF, 8 * sizeof(u8)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 946 | |
| 947 | efuse_word_enable_data_read(word_en, data, target_pkt.data); |
| 948 | target_word_cnts = efuse_calculate_word_cnts(target_pkt.word_en); |
| 949 | |
| 950 | RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, ("efuse Power ON\n")); |
| 951 | |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 952 | while (continual && (efuse_addr < |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 953 | (EFUSE_MAX_SIZE - EFUSE_OOB_PROTECT_BYTES))) { |
| 954 | |
| 955 | if (write_state == PG_STATE_HEADER) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 956 | badworden = 0x0F; |
| 957 | RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, |
| 958 | ("efuse PG_STATE_HEADER\n")); |
| 959 | |
| 960 | if (efuse_one_byte_read(hw, efuse_addr, &efuse_data) && |
| 961 | (efuse_data != 0xFF)) |
| 962 | efuse_write_data_case1(hw, &efuse_addr, |
| 963 | efuse_data, offset, |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 964 | &continual, |
Chaoming Li | bc5892c | 2011-01-21 13:57:37 -0600 | [diff] [blame] | 965 | &write_state, &target_pkt, |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 966 | &repeat_times, &result, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 967 | word_en); |
| 968 | else |
| 969 | efuse_write_data_case2(hw, &efuse_addr, |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 970 | &continual, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 971 | &write_state, |
| 972 | target_pkt, |
| 973 | &repeat_times, |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 974 | &result); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 975 | |
| 976 | } else if (write_state == PG_STATE_DATA) { |
| 977 | RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, |
| 978 | ("efuse PG_STATE_DATA\n")); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 979 | badworden = |
| 980 | efuse_word_enable_data_write(hw, efuse_addr + 1, |
| 981 | target_pkt.word_en, |
| 982 | target_pkt.data); |
| 983 | |
| 984 | if ((badworden & 0x0F) == 0x0F) { |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 985 | continual = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 986 | } else { |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 987 | efuse_addr += (2 * target_word_cnts) + 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 988 | |
| 989 | target_pkt.offset = offset; |
| 990 | target_pkt.word_en = badworden; |
| 991 | target_word_cnts = |
| 992 | efuse_calculate_word_cnts(target_pkt. |
| 993 | word_en); |
| 994 | write_state = PG_STATE_HEADER; |
| 995 | repeat_times++; |
| 996 | if (repeat_times > EFUSE_REPEAT_THRESHOLD_) { |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 997 | continual = false; |
| 998 | result = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 999 | } |
| 1000 | RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, |
| 1001 | ("efuse PG_STATE_HEADER-3\n")); |
| 1002 | } |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | if (efuse_addr >= (EFUSE_MAX_SIZE - EFUSE_OOB_PROTECT_BYTES)) { |
| 1007 | RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, |
| 1008 | ("efuse_addr(%#x) Out of size!!\n", efuse_addr)); |
| 1009 | } |
| 1010 | |
| 1011 | return true; |
| 1012 | } |
| 1013 | |
| 1014 | static void efuse_word_enable_data_read(u8 word_en, |
| 1015 | u8 *sourdata, u8 *targetdata) |
| 1016 | { |
| 1017 | if (!(word_en & BIT(0))) { |
| 1018 | targetdata[0] = sourdata[0]; |
| 1019 | targetdata[1] = sourdata[1]; |
| 1020 | } |
| 1021 | |
| 1022 | if (!(word_en & BIT(1))) { |
| 1023 | targetdata[2] = sourdata[2]; |
| 1024 | targetdata[3] = sourdata[3]; |
| 1025 | } |
| 1026 | |
| 1027 | if (!(word_en & BIT(2))) { |
| 1028 | targetdata[4] = sourdata[4]; |
| 1029 | targetdata[5] = sourdata[5]; |
| 1030 | } |
| 1031 | |
| 1032 | if (!(word_en & BIT(3))) { |
| 1033 | targetdata[6] = sourdata[6]; |
| 1034 | targetdata[7] = sourdata[7]; |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | static u8 efuse_word_enable_data_write(struct ieee80211_hw *hw, |
| 1039 | u16 efuse_addr, u8 word_en, u8 *data) |
| 1040 | { |
| 1041 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1042 | u16 tmpaddr; |
| 1043 | u16 start_addr = efuse_addr; |
| 1044 | u8 badworden = 0x0F; |
| 1045 | u8 tmpdata[8]; |
| 1046 | |
Ilia Mirkin | 6e9d592 | 2011-03-17 14:08:57 -0400 | [diff] [blame] | 1047 | memset(tmpdata, 0xff, PGPKT_DATA_SIZE); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1048 | RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, |
| 1049 | ("word_en = %x efuse_addr=%x\n", word_en, efuse_addr)); |
| 1050 | |
| 1051 | if (!(word_en & BIT(0))) { |
| 1052 | tmpaddr = start_addr; |
| 1053 | efuse_one_byte_write(hw, start_addr++, data[0]); |
| 1054 | efuse_one_byte_write(hw, start_addr++, data[1]); |
| 1055 | |
| 1056 | efuse_one_byte_read(hw, tmpaddr, &tmpdata[0]); |
| 1057 | efuse_one_byte_read(hw, tmpaddr + 1, &tmpdata[1]); |
| 1058 | if ((data[0] != tmpdata[0]) || (data[1] != tmpdata[1])) |
| 1059 | badworden &= (~BIT(0)); |
| 1060 | } |
| 1061 | |
| 1062 | if (!(word_en & BIT(1))) { |
| 1063 | tmpaddr = start_addr; |
| 1064 | efuse_one_byte_write(hw, start_addr++, data[2]); |
| 1065 | efuse_one_byte_write(hw, start_addr++, data[3]); |
| 1066 | |
| 1067 | efuse_one_byte_read(hw, tmpaddr, &tmpdata[2]); |
| 1068 | efuse_one_byte_read(hw, tmpaddr + 1, &tmpdata[3]); |
| 1069 | if ((data[2] != tmpdata[2]) || (data[3] != tmpdata[3])) |
| 1070 | badworden &= (~BIT(1)); |
| 1071 | } |
| 1072 | |
| 1073 | if (!(word_en & BIT(2))) { |
| 1074 | tmpaddr = start_addr; |
| 1075 | efuse_one_byte_write(hw, start_addr++, data[4]); |
| 1076 | efuse_one_byte_write(hw, start_addr++, data[5]); |
| 1077 | |
| 1078 | efuse_one_byte_read(hw, tmpaddr, &tmpdata[4]); |
| 1079 | efuse_one_byte_read(hw, tmpaddr + 1, &tmpdata[5]); |
| 1080 | if ((data[4] != tmpdata[4]) || (data[5] != tmpdata[5])) |
| 1081 | badworden &= (~BIT(2)); |
| 1082 | } |
| 1083 | |
| 1084 | if (!(word_en & BIT(3))) { |
| 1085 | tmpaddr = start_addr; |
| 1086 | efuse_one_byte_write(hw, start_addr++, data[6]); |
| 1087 | efuse_one_byte_write(hw, start_addr++, data[7]); |
| 1088 | |
| 1089 | efuse_one_byte_read(hw, tmpaddr, &tmpdata[6]); |
| 1090 | efuse_one_byte_read(hw, tmpaddr + 1, &tmpdata[7]); |
| 1091 | if ((data[6] != tmpdata[6]) || (data[7] != tmpdata[7])) |
| 1092 | badworden &= (~BIT(3)); |
| 1093 | } |
| 1094 | |
| 1095 | return badworden; |
| 1096 | } |
| 1097 | |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 1098 | static void efuse_power_switch(struct ieee80211_hw *hw, u8 write, u8 pwrstate) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1099 | { |
| 1100 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 1101 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1102 | u8 tempval; |
| 1103 | u16 tmpV16; |
| 1104 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 1105 | if (pwrstate && (rtlhal->hw_type != |
| 1106 | HARDWARE_TYPE_RTL8192SE)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1107 | tmpV16 = rtl_read_word(rtlpriv, |
| 1108 | rtlpriv->cfg->maps[SYS_ISO_CTRL]); |
| 1109 | if (!(tmpV16 & rtlpriv->cfg->maps[EFUSE_PWC_EV12V])) { |
| 1110 | tmpV16 |= rtlpriv->cfg->maps[EFUSE_PWC_EV12V]; |
| 1111 | rtl_write_word(rtlpriv, |
| 1112 | rtlpriv->cfg->maps[SYS_ISO_CTRL], |
| 1113 | tmpV16); |
| 1114 | } |
| 1115 | |
| 1116 | tmpV16 = rtl_read_word(rtlpriv, |
| 1117 | rtlpriv->cfg->maps[SYS_FUNC_EN]); |
| 1118 | if (!(tmpV16 & rtlpriv->cfg->maps[EFUSE_FEN_ELDR])) { |
| 1119 | tmpV16 |= rtlpriv->cfg->maps[EFUSE_FEN_ELDR]; |
| 1120 | rtl_write_word(rtlpriv, |
| 1121 | rtlpriv->cfg->maps[SYS_FUNC_EN], tmpV16); |
| 1122 | } |
| 1123 | |
| 1124 | tmpV16 = rtl_read_word(rtlpriv, rtlpriv->cfg->maps[SYS_CLK]); |
| 1125 | if ((!(tmpV16 & rtlpriv->cfg->maps[EFUSE_LOADER_CLK_EN])) || |
| 1126 | (!(tmpV16 & rtlpriv->cfg->maps[EFUSE_ANA8M]))) { |
| 1127 | tmpV16 |= (rtlpriv->cfg->maps[EFUSE_LOADER_CLK_EN] | |
| 1128 | rtlpriv->cfg->maps[EFUSE_ANA8M]); |
| 1129 | rtl_write_word(rtlpriv, |
| 1130 | rtlpriv->cfg->maps[SYS_CLK], tmpV16); |
| 1131 | } |
| 1132 | } |
| 1133 | |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 1134 | if (pwrstate) { |
| 1135 | if (write) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1136 | tempval = rtl_read_byte(rtlpriv, |
| 1137 | rtlpriv->cfg->maps[EFUSE_TEST] + |
| 1138 | 3); |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 1139 | |
| 1140 | if (rtlhal->hw_type != HARDWARE_TYPE_RTL8192SE) { |
| 1141 | tempval &= 0x0F; |
| 1142 | tempval |= (VOLTAGE_V25 << 4); |
| 1143 | } |
| 1144 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1145 | rtl_write_byte(rtlpriv, |
| 1146 | rtlpriv->cfg->maps[EFUSE_TEST] + 3, |
| 1147 | (tempval | 0x80)); |
| 1148 | } |
| 1149 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 1150 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) { |
| 1151 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CLK], |
| 1152 | 0x03); |
| 1153 | } |
| 1154 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1155 | } else { |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 1156 | if (write) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1157 | tempval = rtl_read_byte(rtlpriv, |
| 1158 | rtlpriv->cfg->maps[EFUSE_TEST] + |
| 1159 | 3); |
| 1160 | rtl_write_byte(rtlpriv, |
| 1161 | rtlpriv->cfg->maps[EFUSE_TEST] + 3, |
| 1162 | (tempval & 0x7F)); |
| 1163 | } |
| 1164 | |
Chaoming_Li | e25f51d | 2011-04-25 12:52:44 -0500 | [diff] [blame] | 1165 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) { |
| 1166 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CLK], |
| 1167 | 0x02); |
| 1168 | } |
| 1169 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | } |
| 1173 | |
| 1174 | static u16 efuse_get_current_size(struct ieee80211_hw *hw) |
| 1175 | { |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 1176 | int continual = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1177 | u16 efuse_addr = 0; |
Larry Finger | 19086fc | 2011-05-22 20:54:31 -0500 | [diff] [blame^] | 1178 | u8 hworden; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1179 | u8 efuse_data, word_cnts; |
| 1180 | |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 1181 | while (continual && efuse_one_byte_read(hw, efuse_addr, &efuse_data) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1182 | && (efuse_addr < EFUSE_MAX_SIZE)) { |
| 1183 | if (efuse_data != 0xFF) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1184 | hworden = efuse_data & 0x0F; |
| 1185 | word_cnts = efuse_calculate_word_cnts(hworden); |
| 1186 | efuse_addr = efuse_addr + (word_cnts * 2) + 1; |
| 1187 | } else { |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 1188 | continual = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | return efuse_addr; |
| 1193 | } |
| 1194 | |
| 1195 | static u8 efuse_calculate_word_cnts(u8 word_en) |
| 1196 | { |
| 1197 | u8 word_cnts = 0; |
| 1198 | if (!(word_en & BIT(0))) |
| 1199 | word_cnts++; |
| 1200 | if (!(word_en & BIT(1))) |
| 1201 | word_cnts++; |
| 1202 | if (!(word_en & BIT(2))) |
| 1203 | word_cnts++; |
| 1204 | if (!(word_en & BIT(3))) |
| 1205 | word_cnts++; |
| 1206 | return word_cnts; |
| 1207 | } |
| 1208 | |