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