Staging: unisys: Remove RETINT macro
[linux/fpc-iii.git] / drivers / net / wireless / rtlwifi / efuse.c
blob2ffc7298f686ec6002ee54dd210ebc7e8b13b757
1 /******************************************************************************
3 * Copyright(c) 2009-2012 Realtek Corporation.
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.
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.
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
18 * Tme full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
30 #include <linux/export.h>
31 #include "wifi.h"
32 #include "efuse.h"
34 static const u8 MAX_PGPKT_SIZE = 9;
35 static const u8 PGPKT_DATA_SIZE = 8;
36 static const int EFUSE_MAX_SIZE = 512;
38 static const struct efuse_map RTL8712_SDIO_EFUSE_TABLE[] = {
39 {0, 0, 0, 2},
40 {0, 1, 0, 2},
41 {0, 2, 0, 2},
42 {1, 0, 0, 1},
43 {1, 0, 1, 1},
44 {1, 1, 0, 1},
45 {1, 1, 1, 3},
46 {1, 3, 0, 17},
47 {3, 3, 1, 48},
48 {10, 0, 0, 6},
49 {10, 3, 0, 1},
50 {10, 3, 1, 1},
51 {11, 0, 0, 28}
54 static void efuse_shadow_read_1byte(struct ieee80211_hw *hw, u16 offset,
55 u8 *value);
56 static void efuse_shadow_read_2byte(struct ieee80211_hw *hw, u16 offset,
57 u16 *value);
58 static void efuse_shadow_read_4byte(struct ieee80211_hw *hw, u16 offset,
59 u32 *value);
60 static void efuse_shadow_write_1byte(struct ieee80211_hw *hw, u16 offset,
61 u8 value);
62 static void efuse_shadow_write_2byte(struct ieee80211_hw *hw, u16 offset,
63 u16 value);
64 static void efuse_shadow_write_4byte(struct ieee80211_hw *hw, u16 offset,
65 u32 value);
66 static int efuse_one_byte_read(struct ieee80211_hw *hw, u16 addr,
67 u8 *data);
68 static int efuse_one_byte_write(struct ieee80211_hw *hw, u16 addr,
69 u8 data);
70 static void efuse_read_all_map(struct ieee80211_hw *hw, u8 *efuse);
71 static int efuse_pg_packet_read(struct ieee80211_hw *hw, u8 offset,
72 u8 *data);
73 static int efuse_pg_packet_write(struct ieee80211_hw *hw, u8 offset,
74 u8 word_en, u8 *data);
75 static void efuse_word_enable_data_read(u8 word_en, u8 *sourdata,
76 u8 *targetdata);
77 static u8 efuse_word_enable_data_write(struct ieee80211_hw *hw,
78 u16 efuse_addr, u8 word_en, u8 *data);
79 static void efuse_power_switch(struct ieee80211_hw *hw, u8 write,
80 u8 pwrstate);
81 static u16 efuse_get_current_size(struct ieee80211_hw *hw);
82 static u8 efuse_calculate_word_cnts(u8 word_en);
84 void efuse_initialize(struct ieee80211_hw *hw)
86 struct rtl_priv *rtlpriv = rtl_priv(hw);
87 u8 bytetemp;
88 u8 temp;
90 bytetemp = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[SYS_FUNC_EN] + 1);
91 temp = bytetemp | 0x20;
92 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[SYS_FUNC_EN] + 1, temp);
94 bytetemp = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[SYS_ISO_CTRL] + 1);
95 temp = bytetemp & 0xFE;
96 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[SYS_ISO_CTRL] + 1, temp);
98 bytetemp = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_TEST] + 3);
99 temp = bytetemp | 0x80;
100 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_TEST] + 3, temp);
102 rtl_write_byte(rtlpriv, 0x2F8, 0x3);
104 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3, 0x72);
108 u8 efuse_read_1byte(struct ieee80211_hw *hw, u16 address)
110 struct rtl_priv *rtlpriv = rtl_priv(hw);
111 u8 data;
112 u8 bytetemp;
113 u8 temp;
114 u32 k = 0;
115 const u32 efuse_len =
116 rtlpriv->cfg->maps[EFUSE_REAL_CONTENT_SIZE];
118 if (address < efuse_len) {
119 temp = address & 0xFF;
120 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1,
121 temp);
122 bytetemp = rtl_read_byte(rtlpriv,
123 rtlpriv->cfg->maps[EFUSE_CTRL] + 2);
124 temp = ((address >> 8) & 0x03) | (bytetemp & 0xFC);
125 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2,
126 temp);
128 bytetemp = rtl_read_byte(rtlpriv,
129 rtlpriv->cfg->maps[EFUSE_CTRL] + 3);
130 temp = bytetemp & 0x7F;
131 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3,
132 temp);
134 bytetemp = rtl_read_byte(rtlpriv,
135 rtlpriv->cfg->maps[EFUSE_CTRL] + 3);
136 while (!(bytetemp & 0x80)) {
137 bytetemp = rtl_read_byte(rtlpriv,
138 rtlpriv->cfg->
139 maps[EFUSE_CTRL] + 3);
140 k++;
141 if (k == 1000) {
142 k = 0;
143 break;
146 data = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]);
147 return data;
148 } else
149 return 0xFF;
152 EXPORT_SYMBOL(efuse_read_1byte);
154 void efuse_write_1byte(struct ieee80211_hw *hw, u16 address, u8 value)
156 struct rtl_priv *rtlpriv = rtl_priv(hw);
157 u8 bytetemp;
158 u8 temp;
159 u32 k = 0;
160 const u32 efuse_len =
161 rtlpriv->cfg->maps[EFUSE_REAL_CONTENT_SIZE];
163 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, "Addr=%x Data =%x\n",
164 address, value);
166 if (address < efuse_len) {
167 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL], value);
169 temp = address & 0xFF;
170 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1,
171 temp);
172 bytetemp = rtl_read_byte(rtlpriv,
173 rtlpriv->cfg->maps[EFUSE_CTRL] + 2);
175 temp = ((address >> 8) & 0x03) | (bytetemp & 0xFC);
176 rtl_write_byte(rtlpriv,
177 rtlpriv->cfg->maps[EFUSE_CTRL] + 2, temp);
179 bytetemp = rtl_read_byte(rtlpriv,
180 rtlpriv->cfg->maps[EFUSE_CTRL] + 3);
181 temp = bytetemp | 0x80;
182 rtl_write_byte(rtlpriv,
183 rtlpriv->cfg->maps[EFUSE_CTRL] + 3, temp);
185 bytetemp = rtl_read_byte(rtlpriv,
186 rtlpriv->cfg->maps[EFUSE_CTRL] + 3);
188 while (bytetemp & 0x80) {
189 bytetemp = rtl_read_byte(rtlpriv,
190 rtlpriv->cfg->
191 maps[EFUSE_CTRL] + 3);
192 k++;
193 if (k == 100) {
194 k = 0;
195 break;
202 void read_efuse_byte(struct ieee80211_hw *hw, u16 _offset, u8 *pbuf)
204 struct rtl_priv *rtlpriv = rtl_priv(hw);
205 u32 value32;
206 u8 readbyte;
207 u16 retry;
209 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1,
210 (_offset & 0xff));
211 readbyte = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2);
212 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2,
213 ((_offset >> 8) & 0x03) | (readbyte & 0xfc));
215 readbyte = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3);
216 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3,
217 (readbyte & 0x7f));
219 retry = 0;
220 value32 = rtl_read_dword(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]);
221 while (!(((value32 >> 24) & 0xff) & 0x80) && (retry < 10000)) {
222 value32 = rtl_read_dword(rtlpriv,
223 rtlpriv->cfg->maps[EFUSE_CTRL]);
224 retry++;
227 udelay(50);
228 value32 = rtl_read_dword(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]);
230 *pbuf = (u8) (value32 & 0xff);
232 EXPORT_SYMBOL_GPL(read_efuse_byte);
234 void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 _size_byte, u8 *pbuf)
236 struct rtl_priv *rtlpriv = rtl_priv(hw);
237 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
238 u8 *efuse_tbl;
239 u8 rtemp8[1];
240 u16 efuse_addr = 0;
241 u8 offset, wren;
242 u8 u1temp = 0;
243 u16 i;
244 u16 j;
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];
249 u16 **efuse_word;
250 u16 efuse_utilized = 0;
251 u8 efuse_usage;
253 if ((_offset + _size_byte) > rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]) {
254 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD,
255 "read_efuse(): Invalid offset(%#x) with read bytes(%#x)!!\n",
256 _offset, _size_byte);
257 return;
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 = kzalloc(EFUSE_MAX_WORD_UNIT * sizeof(u16 *), GFP_ATOMIC);
266 if (!efuse_word)
267 goto out;
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;
275 for (i = 0; i < efuse_max_section; i++)
276 for (j = 0; j < EFUSE_MAX_WORD_UNIT; j++)
277 efuse_word[j][i] = 0xFFFF;
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++;
287 while ((*rtemp8 != 0xFF) && (efuse_addr < efuse_len)) {
288 /* Check PG header for section num. */
289 if ((*rtemp8 & 0x1F) == 0x0F) {/* extended header */
290 u1temp = ((*rtemp8 & 0xE0) >> 5);
291 read_efuse_byte(hw, efuse_addr, rtemp8);
293 if ((*rtemp8 & 0x0F) == 0x0F) {
294 efuse_addr++;
295 read_efuse_byte(hw, efuse_addr, rtemp8);
297 if (*rtemp8 != 0xFF &&
298 (efuse_addr < efuse_len)) {
299 efuse_addr++;
301 continue;
302 } else {
303 offset = ((*rtemp8 & 0xF0) >> 1) | u1temp;
304 wren = (*rtemp8 & 0x0F);
305 efuse_addr++;
307 } else {
308 offset = ((*rtemp8 >> 4) & 0x0f);
309 wren = (*rtemp8 & 0x0f);
312 if (offset < efuse_max_section) {
313 RTPRINT(rtlpriv, FEEPROM, EFUSE_READ_ALL,
314 "offset-%d Worden=%x\n", offset, wren);
316 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
317 if (!(wren & 0x01)) {
318 RTPRINT(rtlpriv, FEEPROM,
319 EFUSE_READ_ALL,
320 "Addr=%d\n", efuse_addr);
322 read_efuse_byte(hw, efuse_addr, rtemp8);
323 efuse_addr++;
324 efuse_utilized++;
325 efuse_word[i][offset] =
326 (*rtemp8 & 0xff);
328 if (efuse_addr >= efuse_len)
329 break;
331 RTPRINT(rtlpriv, FEEPROM,
332 EFUSE_READ_ALL,
333 "Addr=%d\n", efuse_addr);
335 read_efuse_byte(hw, efuse_addr, rtemp8);
336 efuse_addr++;
337 efuse_utilized++;
338 efuse_word[i][offset] |=
339 (((u16)*rtemp8 << 8) & 0xff00);
341 if (efuse_addr >= efuse_len)
342 break;
345 wren >>= 1;
349 RTPRINT(rtlpriv, FEEPROM, EFUSE_READ_ALL,
350 "Addr=%d\n", efuse_addr);
351 read_efuse_byte(hw, efuse_addr, rtemp8);
352 if (*rtemp8 != 0xFF && (efuse_addr < efuse_len)) {
353 efuse_utilized++;
354 efuse_addr++;
358 for (i = 0; i < efuse_max_section; i++) {
359 for (j = 0; j < EFUSE_MAX_WORD_UNIT; j++) {
360 efuse_tbl[(i * 8) + (j * 2)] =
361 (efuse_word[j][i] & 0xff);
362 efuse_tbl[(i * 8) + ((j * 2) + 1)] =
363 ((efuse_word[j][i] >> 8) & 0xff);
367 for (i = 0; i < _size_byte; i++)
368 pbuf[i] = efuse_tbl[_offset + i];
370 rtlefuse->efuse_usedbytes = efuse_utilized;
371 efuse_usage = (u8) ((efuse_utilized * 100) / efuse_len);
372 rtlefuse->efuse_usedpercentage = efuse_usage;
373 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_EFUSE_BYTES,
374 (u8 *)&efuse_utilized);
375 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_EFUSE_USAGE,
376 &efuse_usage);
377 done:
378 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++)
379 kfree(efuse_word[i]);
380 kfree(efuse_word);
381 out:
382 kfree(efuse_tbl);
385 bool efuse_shadow_update_chk(struct ieee80211_hw *hw)
387 struct rtl_priv *rtlpriv = rtl_priv(hw);
388 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
389 u8 section_idx, i, Base;
390 u16 words_need = 0, hdr_num = 0, totalbytes, efuse_used;
391 bool wordchanged, result = true;
393 for (section_idx = 0; section_idx < 16; section_idx++) {
394 Base = section_idx * 8;
395 wordchanged = false;
397 for (i = 0; i < 8; i = i + 2) {
398 if ((rtlefuse->efuse_map[EFUSE_INIT_MAP][Base + i] !=
399 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][Base + i]) ||
400 (rtlefuse->efuse_map[EFUSE_INIT_MAP][Base + i + 1] !=
401 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][Base + i +
402 1])) {
403 words_need++;
404 wordchanged = true;
408 if (wordchanged)
409 hdr_num++;
412 totalbytes = hdr_num + words_need * 2;
413 efuse_used = rtlefuse->efuse_usedbytes;
415 if ((totalbytes + efuse_used) >=
416 (EFUSE_MAX_SIZE -
417 rtlpriv->cfg->maps[EFUSE_OOB_PROTECT_BYTES_LEN]))
418 result = false;
420 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD,
421 "efuse_shadow_update_chk(): totalbytes(%#x), hdr_num(%#x), words_need(%#x), efuse_used(%d)\n",
422 totalbytes, hdr_num, words_need, efuse_used);
424 return result;
427 void efuse_shadow_read(struct ieee80211_hw *hw, u8 type,
428 u16 offset, u32 *value)
430 if (type == 1)
431 efuse_shadow_read_1byte(hw, offset, (u8 *) value);
432 else if (type == 2)
433 efuse_shadow_read_2byte(hw, offset, (u16 *) value);
434 else if (type == 4)
435 efuse_shadow_read_4byte(hw, offset, value);
439 void efuse_shadow_write(struct ieee80211_hw *hw, u8 type, u16 offset,
440 u32 value)
442 if (type == 1)
443 efuse_shadow_write_1byte(hw, offset, (u8) value);
444 else if (type == 2)
445 efuse_shadow_write_2byte(hw, offset, (u16) value);
446 else if (type == 4)
447 efuse_shadow_write_4byte(hw, offset, value);
451 bool efuse_shadow_update(struct ieee80211_hw *hw)
453 struct rtl_priv *rtlpriv = rtl_priv(hw);
454 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
455 u16 i, offset, base;
456 u8 word_en = 0x0F;
457 u8 first_pg = false;
459 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, "--->\n");
461 if (!efuse_shadow_update_chk(hw)) {
462 efuse_read_all_map(hw, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0]);
463 memcpy(&rtlefuse->efuse_map[EFUSE_MODIFY_MAP][0],
464 &rtlefuse->efuse_map[EFUSE_INIT_MAP][0],
465 rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]);
467 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD,
468 "<---efuse out of capacity!!\n");
469 return false;
471 efuse_power_switch(hw, true, true);
473 for (offset = 0; offset < 16; offset++) {
475 word_en = 0x0F;
476 base = offset * 8;
478 for (i = 0; i < 8; i++) {
479 if (first_pg) {
481 word_en &= ~(BIT(i / 2));
483 rtlefuse->efuse_map[EFUSE_INIT_MAP][base + i] =
484 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][base + i];
485 } else {
487 if (rtlefuse->efuse_map[EFUSE_INIT_MAP][base + i] !=
488 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][base + i]) {
489 word_en &= ~(BIT(i / 2));
491 rtlefuse->efuse_map[EFUSE_INIT_MAP][base + i] =
492 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][base + i];
497 if (word_en != 0x0F) {
498 u8 tmpdata[8];
499 memcpy(tmpdata,
500 &rtlefuse->efuse_map[EFUSE_MODIFY_MAP][base],
502 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_LOUD,
503 "U-efuse", tmpdata, 8);
505 if (!efuse_pg_packet_write(hw, (u8) offset, word_en,
506 tmpdata)) {
507 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
508 "PG section(%#x) fail!!\n", offset);
509 break;
515 efuse_power_switch(hw, true, false);
516 efuse_read_all_map(hw, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0]);
518 memcpy(&rtlefuse->efuse_map[EFUSE_MODIFY_MAP][0],
519 &rtlefuse->efuse_map[EFUSE_INIT_MAP][0],
520 rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]);
522 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, "<---\n");
523 return true;
526 void rtl_efuse_shadow_map_update(struct ieee80211_hw *hw)
528 struct rtl_priv *rtlpriv = rtl_priv(hw);
529 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
531 if (rtlefuse->autoload_failflag)
532 memset(&rtlefuse->efuse_map[EFUSE_INIT_MAP][0], 0xFF,
533 rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]);
534 else
535 efuse_read_all_map(hw, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0]);
537 memcpy(&rtlefuse->efuse_map[EFUSE_MODIFY_MAP][0],
538 &rtlefuse->efuse_map[EFUSE_INIT_MAP][0],
539 rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]);
542 EXPORT_SYMBOL(rtl_efuse_shadow_map_update);
544 void efuse_force_write_vendor_Id(struct ieee80211_hw *hw)
546 u8 tmpdata[8] = { 0xFF, 0xFF, 0xEC, 0x10, 0xFF, 0xFF, 0xFF, 0xFF };
548 efuse_power_switch(hw, true, true);
550 efuse_pg_packet_write(hw, 1, 0xD, tmpdata);
552 efuse_power_switch(hw, true, false);
556 void efuse_re_pg_section(struct ieee80211_hw *hw, u8 section_idx)
560 static void efuse_shadow_read_1byte(struct ieee80211_hw *hw,
561 u16 offset, u8 *value)
563 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
564 *value = rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset];
567 static void efuse_shadow_read_2byte(struct ieee80211_hw *hw,
568 u16 offset, u16 *value)
570 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
572 *value = rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset];
573 *value |= rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 1] << 8;
577 static void efuse_shadow_read_4byte(struct ieee80211_hw *hw,
578 u16 offset, u32 *value)
580 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
582 *value = rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset];
583 *value |= rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 1] << 8;
584 *value |= rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 2] << 16;
585 *value |= rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 3] << 24;
588 static void efuse_shadow_write_1byte(struct ieee80211_hw *hw,
589 u16 offset, u8 value)
591 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
593 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset] = value;
596 static void efuse_shadow_write_2byte(struct ieee80211_hw *hw,
597 u16 offset, u16 value)
599 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
601 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset] = value & 0x00FF;
602 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 1] = value >> 8;
606 static void efuse_shadow_write_4byte(struct ieee80211_hw *hw,
607 u16 offset, u32 value)
609 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
611 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset] =
612 (u8) (value & 0x000000FF);
613 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 1] =
614 (u8) ((value >> 8) & 0x0000FF);
615 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 2] =
616 (u8) ((value >> 16) & 0x00FF);
617 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 3] =
618 (u8) ((value >> 24) & 0xFF);
622 static int efuse_one_byte_read(struct ieee80211_hw *hw, u16 addr, u8 *data)
624 struct rtl_priv *rtlpriv = rtl_priv(hw);
625 u8 tmpidx = 0;
626 int result;
628 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1,
629 (u8) (addr & 0xff));
630 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2,
631 ((u8) ((addr >> 8) & 0x03)) |
632 (rtl_read_byte(rtlpriv,
633 rtlpriv->cfg->maps[EFUSE_CTRL] + 2) &
634 0xFC));
636 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3, 0x72);
638 while (!(0x80 & rtl_read_byte(rtlpriv,
639 rtlpriv->cfg->maps[EFUSE_CTRL] + 3))
640 && (tmpidx < 100)) {
641 tmpidx++;
644 if (tmpidx < 100) {
645 *data = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]);
646 result = true;
647 } else {
648 *data = 0xff;
649 result = false;
651 return result;
654 static int efuse_one_byte_write(struct ieee80211_hw *hw, u16 addr, u8 data)
656 struct rtl_priv *rtlpriv = rtl_priv(hw);
657 u8 tmpidx = 0;
659 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, "Addr = %x Data=%x\n",
660 addr, data);
662 rtl_write_byte(rtlpriv,
663 rtlpriv->cfg->maps[EFUSE_CTRL] + 1, (u8) (addr & 0xff));
664 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2,
665 (rtl_read_byte(rtlpriv,
666 rtlpriv->cfg->maps[EFUSE_CTRL] +
667 2) & 0xFC) | (u8) ((addr >> 8) & 0x03));
669 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL], data);
670 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3, 0xF2);
672 while ((0x80 & rtl_read_byte(rtlpriv,
673 rtlpriv->cfg->maps[EFUSE_CTRL] + 3))
674 && (tmpidx < 100)) {
675 tmpidx++;
678 if (tmpidx < 100)
679 return true;
681 return false;
684 static void efuse_read_all_map(struct ieee80211_hw *hw, u8 * efuse)
686 struct rtl_priv *rtlpriv = rtl_priv(hw);
687 efuse_power_switch(hw, false, true);
688 read_efuse(hw, 0, rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE], efuse);
689 efuse_power_switch(hw, false, false);
692 static void efuse_read_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr,
693 u8 efuse_data, u8 offset, u8 *tmpdata,
694 u8 *readstate)
696 bool dataempty = true;
697 u8 hoffset;
698 u8 tmpidx;
699 u8 hworden;
700 u8 word_cnts;
702 hoffset = (efuse_data >> 4) & 0x0F;
703 hworden = efuse_data & 0x0F;
704 word_cnts = efuse_calculate_word_cnts(hworden);
706 if (hoffset == offset) {
707 for (tmpidx = 0; tmpidx < word_cnts * 2; tmpidx++) {
708 if (efuse_one_byte_read(hw, *efuse_addr + 1 + tmpidx,
709 &efuse_data)) {
710 tmpdata[tmpidx] = efuse_data;
711 if (efuse_data != 0xff)
712 dataempty = true;
716 if (dataempty) {
717 *readstate = PG_STATE_DATA;
718 } else {
719 *efuse_addr = *efuse_addr + (word_cnts * 2) + 1;
720 *readstate = PG_STATE_HEADER;
723 } else {
724 *efuse_addr = *efuse_addr + (word_cnts * 2) + 1;
725 *readstate = PG_STATE_HEADER;
729 static int efuse_pg_packet_read(struct ieee80211_hw *hw, u8 offset, u8 *data)
731 u8 readstate = PG_STATE_HEADER;
732 bool continual = true;
733 u8 efuse_data, word_cnts = 0;
734 u16 efuse_addr = 0;
735 u8 tmpdata[8];
737 if (data == NULL)
738 return false;
739 if (offset > 15)
740 return false;
742 memset(data, 0xff, PGPKT_DATA_SIZE * sizeof(u8));
743 memset(tmpdata, 0xff, PGPKT_DATA_SIZE * sizeof(u8));
745 while (continual && (efuse_addr < EFUSE_MAX_SIZE)) {
746 if (readstate & PG_STATE_HEADER) {
747 if (efuse_one_byte_read(hw, efuse_addr, &efuse_data)
748 && (efuse_data != 0xFF))
749 efuse_read_data_case1(hw, &efuse_addr,
750 efuse_data,
751 offset, tmpdata,
752 &readstate);
753 else
754 continual = false;
755 } else if (readstate & PG_STATE_DATA) {
756 efuse_word_enable_data_read(0, tmpdata, data);
757 efuse_addr = efuse_addr + (word_cnts * 2) + 1;
758 readstate = PG_STATE_HEADER;
763 if ((data[0] == 0xff) && (data[1] == 0xff) &&
764 (data[2] == 0xff) && (data[3] == 0xff) &&
765 (data[4] == 0xff) && (data[5] == 0xff) &&
766 (data[6] == 0xff) && (data[7] == 0xff))
767 return false;
768 else
769 return true;
773 static void efuse_write_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr,
774 u8 efuse_data, u8 offset, int *continual,
775 u8 *write_state, struct pgpkt_struct *target_pkt,
776 int *repeat_times, int *result, u8 word_en)
778 struct rtl_priv *rtlpriv = rtl_priv(hw);
779 struct pgpkt_struct tmp_pkt;
780 bool dataempty = true;
781 u8 originaldata[8 * sizeof(u8)];
782 u8 badworden = 0x0F;
783 u8 match_word_en, tmp_word_en;
784 u8 tmpindex;
785 u8 tmp_header = efuse_data;
786 u8 tmp_word_cnts;
788 tmp_pkt.offset = (tmp_header >> 4) & 0x0F;
789 tmp_pkt.word_en = tmp_header & 0x0F;
790 tmp_word_cnts = efuse_calculate_word_cnts(tmp_pkt.word_en);
792 if (tmp_pkt.offset != target_pkt->offset) {
793 *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) + 1;
794 *write_state = PG_STATE_HEADER;
795 } else {
796 for (tmpindex = 0; tmpindex < (tmp_word_cnts * 2); tmpindex++) {
797 u16 address = *efuse_addr + 1 + tmpindex;
798 if (efuse_one_byte_read(hw, address,
799 &efuse_data) && (efuse_data != 0xFF))
800 dataempty = false;
803 if (!dataempty) {
804 *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) + 1;
805 *write_state = PG_STATE_HEADER;
806 } else {
807 match_word_en = 0x0F;
808 if (!((target_pkt->word_en & BIT(0)) |
809 (tmp_pkt.word_en & BIT(0))))
810 match_word_en &= (~BIT(0));
812 if (!((target_pkt->word_en & BIT(1)) |
813 (tmp_pkt.word_en & BIT(1))))
814 match_word_en &= (~BIT(1));
816 if (!((target_pkt->word_en & BIT(2)) |
817 (tmp_pkt.word_en & BIT(2))))
818 match_word_en &= (~BIT(2));
820 if (!((target_pkt->word_en & BIT(3)) |
821 (tmp_pkt.word_en & BIT(3))))
822 match_word_en &= (~BIT(3));
824 if ((match_word_en & 0x0F) != 0x0F) {
825 badworden = efuse_word_enable_data_write(
826 hw, *efuse_addr + 1,
827 tmp_pkt.word_en,
828 target_pkt->data);
830 if (0x0F != (badworden & 0x0F)) {
831 u8 reorg_offset = offset;
832 u8 reorg_worden = badworden;
833 efuse_pg_packet_write(hw, reorg_offset,
834 reorg_worden,
835 originaldata);
838 tmp_word_en = 0x0F;
839 if ((target_pkt->word_en & BIT(0)) ^
840 (match_word_en & BIT(0)))
841 tmp_word_en &= (~BIT(0));
843 if ((target_pkt->word_en & BIT(1)) ^
844 (match_word_en & BIT(1)))
845 tmp_word_en &= (~BIT(1));
847 if ((target_pkt->word_en & BIT(2)) ^
848 (match_word_en & BIT(2)))
849 tmp_word_en &= (~BIT(2));
851 if ((target_pkt->word_en & BIT(3)) ^
852 (match_word_en & BIT(3)))
853 tmp_word_en &= (~BIT(3));
855 if ((tmp_word_en & 0x0F) != 0x0F) {
856 *efuse_addr = efuse_get_current_size(hw);
857 target_pkt->offset = offset;
858 target_pkt->word_en = tmp_word_en;
859 } else {
860 *continual = false;
862 *write_state = PG_STATE_HEADER;
863 *repeat_times += 1;
864 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) {
865 *continual = false;
866 *result = false;
868 } else {
869 *efuse_addr += (2 * tmp_word_cnts) + 1;
870 target_pkt->offset = offset;
871 target_pkt->word_en = word_en;
872 *write_state = PG_STATE_HEADER;
876 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, "efuse PG_STATE_HEADER-1\n");
879 static void efuse_write_data_case2(struct ieee80211_hw *hw, u16 *efuse_addr,
880 int *continual, u8 *write_state,
881 struct pgpkt_struct target_pkt,
882 int *repeat_times, int *result)
884 struct rtl_priv *rtlpriv = rtl_priv(hw);
885 struct pgpkt_struct tmp_pkt;
886 u8 pg_header;
887 u8 tmp_header;
888 u8 originaldata[8 * sizeof(u8)];
889 u8 tmp_word_cnts;
890 u8 badworden = 0x0F;
892 pg_header = ((target_pkt.offset << 4) & 0xf0) | target_pkt.word_en;
893 efuse_one_byte_write(hw, *efuse_addr, pg_header);
894 efuse_one_byte_read(hw, *efuse_addr, &tmp_header);
896 if (tmp_header == pg_header) {
897 *write_state = PG_STATE_DATA;
898 } else if (tmp_header == 0xFF) {
899 *write_state = PG_STATE_HEADER;
900 *repeat_times += 1;
901 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) {
902 *continual = false;
903 *result = false;
905 } else {
906 tmp_pkt.offset = (tmp_header >> 4) & 0x0F;
907 tmp_pkt.word_en = tmp_header & 0x0F;
909 tmp_word_cnts = efuse_calculate_word_cnts(tmp_pkt.word_en);
911 memset(originaldata, 0xff, 8 * sizeof(u8));
913 if (efuse_pg_packet_read(hw, tmp_pkt.offset, originaldata)) {
914 badworden = efuse_word_enable_data_write(hw,
915 *efuse_addr + 1, tmp_pkt.word_en,
916 originaldata);
918 if (0x0F != (badworden & 0x0F)) {
919 u8 reorg_offset = tmp_pkt.offset;
920 u8 reorg_worden = badworden;
921 efuse_pg_packet_write(hw, reorg_offset,
922 reorg_worden,
923 originaldata);
924 *efuse_addr = efuse_get_current_size(hw);
925 } else {
926 *efuse_addr = *efuse_addr + (tmp_word_cnts * 2)
927 + 1;
929 } else {
930 *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) + 1;
933 *write_state = PG_STATE_HEADER;
934 *repeat_times += 1;
935 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) {
936 *continual = false;
937 *result = false;
940 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG,
941 "efuse PG_STATE_HEADER-2\n");
945 static int efuse_pg_packet_write(struct ieee80211_hw *hw,
946 u8 offset, u8 word_en, u8 *data)
948 struct rtl_priv *rtlpriv = rtl_priv(hw);
949 struct pgpkt_struct target_pkt;
950 u8 write_state = PG_STATE_HEADER;
951 int continual = true, result = true;
952 u16 efuse_addr = 0;
953 u8 efuse_data;
954 u8 target_word_cnts = 0;
955 u8 badworden = 0x0F;
956 static int repeat_times;
958 if (efuse_get_current_size(hw) >= (EFUSE_MAX_SIZE -
959 rtlpriv->cfg->maps[EFUSE_OOB_PROTECT_BYTES_LEN])) {
960 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG,
961 "efuse_pg_packet_write error\n");
962 return false;
965 target_pkt.offset = offset;
966 target_pkt.word_en = word_en;
968 memset(target_pkt.data, 0xFF, 8 * sizeof(u8));
970 efuse_word_enable_data_read(word_en, data, target_pkt.data);
971 target_word_cnts = efuse_calculate_word_cnts(target_pkt.word_en);
973 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, "efuse Power ON\n");
975 while (continual && (efuse_addr < (EFUSE_MAX_SIZE -
976 rtlpriv->cfg->maps[EFUSE_OOB_PROTECT_BYTES_LEN]))) {
978 if (write_state == PG_STATE_HEADER) {
979 badworden = 0x0F;
980 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG,
981 "efuse PG_STATE_HEADER\n");
983 if (efuse_one_byte_read(hw, efuse_addr, &efuse_data) &&
984 (efuse_data != 0xFF))
985 efuse_write_data_case1(hw, &efuse_addr,
986 efuse_data, offset,
987 &continual,
988 &write_state, &target_pkt,
989 &repeat_times, &result,
990 word_en);
991 else
992 efuse_write_data_case2(hw, &efuse_addr,
993 &continual,
994 &write_state,
995 target_pkt,
996 &repeat_times,
997 &result);
999 } else if (write_state == PG_STATE_DATA) {
1000 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG,
1001 "efuse PG_STATE_DATA\n");
1002 badworden =
1003 efuse_word_enable_data_write(hw, efuse_addr + 1,
1004 target_pkt.word_en,
1005 target_pkt.data);
1007 if ((badworden & 0x0F) == 0x0F) {
1008 continual = false;
1009 } else {
1010 efuse_addr += (2 * target_word_cnts) + 1;
1012 target_pkt.offset = offset;
1013 target_pkt.word_en = badworden;
1014 target_word_cnts =
1015 efuse_calculate_word_cnts(target_pkt.
1016 word_en);
1017 write_state = PG_STATE_HEADER;
1018 repeat_times++;
1019 if (repeat_times > EFUSE_REPEAT_THRESHOLD_) {
1020 continual = false;
1021 result = false;
1023 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG,
1024 "efuse PG_STATE_HEADER-3\n");
1029 if (efuse_addr >= (EFUSE_MAX_SIZE -
1030 rtlpriv->cfg->maps[EFUSE_OOB_PROTECT_BYTES_LEN])) {
1031 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD,
1032 "efuse_addr(%#x) Out of size!!\n", efuse_addr);
1035 return true;
1038 static void efuse_word_enable_data_read(u8 word_en,
1039 u8 *sourdata, u8 *targetdata)
1041 if (!(word_en & BIT(0))) {
1042 targetdata[0] = sourdata[0];
1043 targetdata[1] = sourdata[1];
1046 if (!(word_en & BIT(1))) {
1047 targetdata[2] = sourdata[2];
1048 targetdata[3] = sourdata[3];
1051 if (!(word_en & BIT(2))) {
1052 targetdata[4] = sourdata[4];
1053 targetdata[5] = sourdata[5];
1056 if (!(word_en & BIT(3))) {
1057 targetdata[6] = sourdata[6];
1058 targetdata[7] = sourdata[7];
1062 static u8 efuse_word_enable_data_write(struct ieee80211_hw *hw,
1063 u16 efuse_addr, u8 word_en, u8 *data)
1065 struct rtl_priv *rtlpriv = rtl_priv(hw);
1066 u16 tmpaddr;
1067 u16 start_addr = efuse_addr;
1068 u8 badworden = 0x0F;
1069 u8 tmpdata[8];
1071 memset(tmpdata, 0xff, PGPKT_DATA_SIZE);
1072 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, "word_en = %x efuse_addr=%x\n",
1073 word_en, efuse_addr);
1075 if (!(word_en & BIT(0))) {
1076 tmpaddr = start_addr;
1077 efuse_one_byte_write(hw, start_addr++, data[0]);
1078 efuse_one_byte_write(hw, start_addr++, data[1]);
1080 efuse_one_byte_read(hw, tmpaddr, &tmpdata[0]);
1081 efuse_one_byte_read(hw, tmpaddr + 1, &tmpdata[1]);
1082 if ((data[0] != tmpdata[0]) || (data[1] != tmpdata[1]))
1083 badworden &= (~BIT(0));
1086 if (!(word_en & BIT(1))) {
1087 tmpaddr = start_addr;
1088 efuse_one_byte_write(hw, start_addr++, data[2]);
1089 efuse_one_byte_write(hw, start_addr++, data[3]);
1091 efuse_one_byte_read(hw, tmpaddr, &tmpdata[2]);
1092 efuse_one_byte_read(hw, tmpaddr + 1, &tmpdata[3]);
1093 if ((data[2] != tmpdata[2]) || (data[3] != tmpdata[3]))
1094 badworden &= (~BIT(1));
1097 if (!(word_en & BIT(2))) {
1098 tmpaddr = start_addr;
1099 efuse_one_byte_write(hw, start_addr++, data[4]);
1100 efuse_one_byte_write(hw, start_addr++, data[5]);
1102 efuse_one_byte_read(hw, tmpaddr, &tmpdata[4]);
1103 efuse_one_byte_read(hw, tmpaddr + 1, &tmpdata[5]);
1104 if ((data[4] != tmpdata[4]) || (data[5] != tmpdata[5]))
1105 badworden &= (~BIT(2));
1108 if (!(word_en & BIT(3))) {
1109 tmpaddr = start_addr;
1110 efuse_one_byte_write(hw, start_addr++, data[6]);
1111 efuse_one_byte_write(hw, start_addr++, data[7]);
1113 efuse_one_byte_read(hw, tmpaddr, &tmpdata[6]);
1114 efuse_one_byte_read(hw, tmpaddr + 1, &tmpdata[7]);
1115 if ((data[6] != tmpdata[6]) || (data[7] != tmpdata[7]))
1116 badworden &= (~BIT(3));
1119 return badworden;
1122 static void efuse_power_switch(struct ieee80211_hw *hw, u8 write, u8 pwrstate)
1124 struct rtl_priv *rtlpriv = rtl_priv(hw);
1125 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1126 u8 tempval;
1127 u16 tmpV16;
1129 if (pwrstate && (rtlhal->hw_type != HARDWARE_TYPE_RTL8192SE)) {
1130 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8188EE)
1131 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_ACCESS],
1132 0x69);
1134 tmpV16 = rtl_read_word(rtlpriv,
1135 rtlpriv->cfg->maps[SYS_ISO_CTRL]);
1136 if (!(tmpV16 & rtlpriv->cfg->maps[EFUSE_PWC_EV12V])) {
1137 tmpV16 |= rtlpriv->cfg->maps[EFUSE_PWC_EV12V];
1138 rtl_write_word(rtlpriv,
1139 rtlpriv->cfg->maps[SYS_ISO_CTRL],
1140 tmpV16);
1143 tmpV16 = rtl_read_word(rtlpriv,
1144 rtlpriv->cfg->maps[SYS_FUNC_EN]);
1145 if (!(tmpV16 & rtlpriv->cfg->maps[EFUSE_FEN_ELDR])) {
1146 tmpV16 |= rtlpriv->cfg->maps[EFUSE_FEN_ELDR];
1147 rtl_write_word(rtlpriv,
1148 rtlpriv->cfg->maps[SYS_FUNC_EN], tmpV16);
1151 tmpV16 = rtl_read_word(rtlpriv, rtlpriv->cfg->maps[SYS_CLK]);
1152 if ((!(tmpV16 & rtlpriv->cfg->maps[EFUSE_LOADER_CLK_EN])) ||
1153 (!(tmpV16 & rtlpriv->cfg->maps[EFUSE_ANA8M]))) {
1154 tmpV16 |= (rtlpriv->cfg->maps[EFUSE_LOADER_CLK_EN] |
1155 rtlpriv->cfg->maps[EFUSE_ANA8M]);
1156 rtl_write_word(rtlpriv,
1157 rtlpriv->cfg->maps[SYS_CLK], tmpV16);
1161 if (pwrstate) {
1162 if (write) {
1163 tempval = rtl_read_byte(rtlpriv,
1164 rtlpriv->cfg->maps[EFUSE_TEST] +
1167 if (rtlhal->hw_type != HARDWARE_TYPE_RTL8192SE) {
1168 tempval &= 0x0F;
1169 tempval |= (VOLTAGE_V25 << 4);
1172 rtl_write_byte(rtlpriv,
1173 rtlpriv->cfg->maps[EFUSE_TEST] + 3,
1174 (tempval | 0x80));
1177 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) {
1178 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CLK],
1179 0x03);
1182 } else {
1183 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8188EE)
1184 rtl_write_byte(rtlpriv,
1185 rtlpriv->cfg->maps[EFUSE_ACCESS], 0);
1187 if (write) {
1188 tempval = rtl_read_byte(rtlpriv,
1189 rtlpriv->cfg->maps[EFUSE_TEST] +
1191 rtl_write_byte(rtlpriv,
1192 rtlpriv->cfg->maps[EFUSE_TEST] + 3,
1193 (tempval & 0x7F));
1196 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) {
1197 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CLK],
1198 0x02);
1205 static u16 efuse_get_current_size(struct ieee80211_hw *hw)
1207 u16 efuse_addr = 0;
1208 u8 hworden;
1209 u8 efuse_data, word_cnts;
1211 while (efuse_one_byte_read(hw, efuse_addr, &efuse_data) &&
1212 efuse_addr < EFUSE_MAX_SIZE) {
1213 if (efuse_data == 0xFF)
1214 break;
1216 hworden = efuse_data & 0x0F;
1217 word_cnts = efuse_calculate_word_cnts(hworden);
1218 efuse_addr = efuse_addr + (word_cnts * 2) + 1;
1221 return efuse_addr;
1224 static u8 efuse_calculate_word_cnts(u8 word_en)
1226 u8 word_cnts = 0;
1227 if (!(word_en & BIT(0)))
1228 word_cnts++;
1229 if (!(word_en & BIT(1)))
1230 word_cnts++;
1231 if (!(word_en & BIT(2)))
1232 word_cnts++;
1233 if (!(word_en & BIT(3)))
1234 word_cnts++;
1235 return word_cnts;