powerpc/eeh: Fix PE#0 check in eeh_add_to_parent_pe()
[linux/fpc-iii.git] / drivers / net / wireless / rtlwifi / efuse.c
blob0b4082c9272a12e36063b3b5e951e48d49944952
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 * Tme full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
25 #include "wifi.h"
26 #include "efuse.h"
27 #include <linux/export.h>
29 static const u8 MAX_PGPKT_SIZE = 9;
30 static const u8 PGPKT_DATA_SIZE = 8;
31 static const int EFUSE_MAX_SIZE = 512;
33 static const struct efuse_map RTL8712_SDIO_EFUSE_TABLE[] = {
34 {0, 0, 0, 2},
35 {0, 1, 0, 2},
36 {0, 2, 0, 2},
37 {1, 0, 0, 1},
38 {1, 0, 1, 1},
39 {1, 1, 0, 1},
40 {1, 1, 1, 3},
41 {1, 3, 0, 17},
42 {3, 3, 1, 48},
43 {10, 0, 0, 6},
44 {10, 3, 0, 1},
45 {10, 3, 1, 1},
46 {11, 0, 0, 28}
49 static void efuse_shadow_read_1byte(struct ieee80211_hw *hw, u16 offset,
50 u8 *value);
51 static void efuse_shadow_read_2byte(struct ieee80211_hw *hw, u16 offset,
52 u16 *value);
53 static void efuse_shadow_read_4byte(struct ieee80211_hw *hw, u16 offset,
54 u32 *value);
55 static void efuse_shadow_write_1byte(struct ieee80211_hw *hw, u16 offset,
56 u8 value);
57 static void efuse_shadow_write_2byte(struct ieee80211_hw *hw, u16 offset,
58 u16 value);
59 static void efuse_shadow_write_4byte(struct ieee80211_hw *hw, u16 offset,
60 u32 value);
61 static int efuse_one_byte_write(struct ieee80211_hw *hw, u16 addr,
62 u8 data);
63 static void efuse_read_all_map(struct ieee80211_hw *hw, u8 *efuse);
64 static int efuse_pg_packet_read(struct ieee80211_hw *hw, u8 offset,
65 u8 *data);
66 static int efuse_pg_packet_write(struct ieee80211_hw *hw, u8 offset,
67 u8 word_en, u8 *data);
68 static void efuse_word_enable_data_read(u8 word_en, u8 *sourdata,
69 u8 *targetdata);
70 static u8 enable_efuse_data_write(struct ieee80211_hw *hw,
71 u16 efuse_addr, u8 word_en, u8 *data);
72 static void efuse_power_switch(struct ieee80211_hw *hw, u8 write,
73 u8 pwrstate);
74 static u16 efuse_get_current_size(struct ieee80211_hw *hw);
75 static u8 efuse_calculate_word_cnts(u8 word_en);
77 void efuse_initialize(struct ieee80211_hw *hw)
79 struct rtl_priv *rtlpriv = rtl_priv(hw);
80 u8 bytetemp;
81 u8 temp;
83 bytetemp = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[SYS_FUNC_EN] + 1);
84 temp = bytetemp | 0x20;
85 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[SYS_FUNC_EN] + 1, temp);
87 bytetemp = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[SYS_ISO_CTRL] + 1);
88 temp = bytetemp & 0xFE;
89 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[SYS_ISO_CTRL] + 1, temp);
91 bytetemp = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_TEST] + 3);
92 temp = bytetemp | 0x80;
93 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_TEST] + 3, temp);
95 rtl_write_byte(rtlpriv, 0x2F8, 0x3);
97 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3, 0x72);
101 u8 efuse_read_1byte(struct ieee80211_hw *hw, u16 address)
103 struct rtl_priv *rtlpriv = rtl_priv(hw);
104 u8 data;
105 u8 bytetemp;
106 u8 temp;
107 u32 k = 0;
108 const u32 efuse_len =
109 rtlpriv->cfg->maps[EFUSE_REAL_CONTENT_SIZE];
111 if (address < efuse_len) {
112 temp = address & 0xFF;
113 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1,
114 temp);
115 bytetemp = rtl_read_byte(rtlpriv,
116 rtlpriv->cfg->maps[EFUSE_CTRL] + 2);
117 temp = ((address >> 8) & 0x03) | (bytetemp & 0xFC);
118 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2,
119 temp);
121 bytetemp = rtl_read_byte(rtlpriv,
122 rtlpriv->cfg->maps[EFUSE_CTRL] + 3);
123 temp = bytetemp & 0x7F;
124 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3,
125 temp);
127 bytetemp = rtl_read_byte(rtlpriv,
128 rtlpriv->cfg->maps[EFUSE_CTRL] + 3);
129 while (!(bytetemp & 0x80)) {
130 bytetemp = rtl_read_byte(rtlpriv,
131 rtlpriv->cfg->
132 maps[EFUSE_CTRL] + 3);
133 k++;
134 if (k == 1000) {
135 k = 0;
136 break;
139 data = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]);
140 return data;
141 } else
142 return 0xFF;
145 EXPORT_SYMBOL(efuse_read_1byte);
147 void efuse_write_1byte(struct ieee80211_hw *hw, u16 address, u8 value)
149 struct rtl_priv *rtlpriv = rtl_priv(hw);
150 u8 bytetemp;
151 u8 temp;
152 u32 k = 0;
153 const u32 efuse_len =
154 rtlpriv->cfg->maps[EFUSE_REAL_CONTENT_SIZE];
156 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, "Addr=%x Data =%x\n",
157 address, value);
159 if (address < efuse_len) {
160 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL], value);
162 temp = address & 0xFF;
163 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1,
164 temp);
165 bytetemp = rtl_read_byte(rtlpriv,
166 rtlpriv->cfg->maps[EFUSE_CTRL] + 2);
168 temp = ((address >> 8) & 0x03) | (bytetemp & 0xFC);
169 rtl_write_byte(rtlpriv,
170 rtlpriv->cfg->maps[EFUSE_CTRL] + 2, temp);
172 bytetemp = rtl_read_byte(rtlpriv,
173 rtlpriv->cfg->maps[EFUSE_CTRL] + 3);
174 temp = bytetemp | 0x80;
175 rtl_write_byte(rtlpriv,
176 rtlpriv->cfg->maps[EFUSE_CTRL] + 3, temp);
178 bytetemp = rtl_read_byte(rtlpriv,
179 rtlpriv->cfg->maps[EFUSE_CTRL] + 3);
181 while (bytetemp & 0x80) {
182 bytetemp = rtl_read_byte(rtlpriv,
183 rtlpriv->cfg->
184 maps[EFUSE_CTRL] + 3);
185 k++;
186 if (k == 100) {
187 k = 0;
188 break;
195 void read_efuse_byte(struct ieee80211_hw *hw, u16 _offset, u8 *pbuf)
197 struct rtl_priv *rtlpriv = rtl_priv(hw);
198 u32 value32;
199 u8 readbyte;
200 u16 retry;
202 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1,
203 (_offset & 0xff));
204 readbyte = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2);
205 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2,
206 ((_offset >> 8) & 0x03) | (readbyte & 0xfc));
208 readbyte = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3);
209 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3,
210 (readbyte & 0x7f));
212 retry = 0;
213 value32 = rtl_read_dword(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]);
214 while (!(((value32 >> 24) & 0xff) & 0x80) && (retry < 10000)) {
215 value32 = rtl_read_dword(rtlpriv,
216 rtlpriv->cfg->maps[EFUSE_CTRL]);
217 retry++;
220 udelay(50);
221 value32 = rtl_read_dword(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]);
223 *pbuf = (u8) (value32 & 0xff);
225 EXPORT_SYMBOL_GPL(read_efuse_byte);
227 void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 _size_byte, u8 *pbuf)
229 struct rtl_priv *rtlpriv = rtl_priv(hw);
230 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
231 u8 *efuse_tbl;
232 u8 rtemp8[1];
233 u16 efuse_addr = 0;
234 u8 offset, wren;
235 u8 u1temp = 0;
236 u16 i;
237 u16 j;
238 const u16 efuse_max_section =
239 rtlpriv->cfg->maps[EFUSE_MAX_SECTION_MAP];
240 const u32 efuse_len =
241 rtlpriv->cfg->maps[EFUSE_REAL_CONTENT_SIZE];
242 u16 **efuse_word;
243 u16 efuse_utilized = 0;
244 u8 efuse_usage;
246 if ((_offset + _size_byte) > rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]) {
247 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD,
248 "read_efuse(): Invalid offset(%#x) with read bytes(%#x)!!\n",
249 _offset, _size_byte);
250 return;
253 /* allocate memory for efuse_tbl and efuse_word */
254 efuse_tbl = kzalloc(rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE] *
255 sizeof(u8), GFP_ATOMIC);
256 if (!efuse_tbl)
257 return;
258 efuse_word = kzalloc(EFUSE_MAX_WORD_UNIT * sizeof(u16 *), GFP_ATOMIC);
259 if (!efuse_word)
260 goto out;
261 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
262 efuse_word[i] = kzalloc(efuse_max_section * sizeof(u16),
263 GFP_ATOMIC);
264 if (!efuse_word[i])
265 goto done;
268 for (i = 0; i < efuse_max_section; i++)
269 for (j = 0; j < EFUSE_MAX_WORD_UNIT; j++)
270 efuse_word[j][i] = 0xFFFF;
272 read_efuse_byte(hw, efuse_addr, rtemp8);
273 if (*rtemp8 != 0xFF) {
274 efuse_utilized++;
275 RTPRINT(rtlpriv, FEEPROM, EFUSE_READ_ALL,
276 "Addr=%d\n", efuse_addr);
277 efuse_addr++;
280 while ((*rtemp8 != 0xFF) && (efuse_addr < efuse_len)) {
281 /* Check PG header for section num. */
282 if ((*rtemp8 & 0x1F) == 0x0F) {/* extended header */
283 u1temp = ((*rtemp8 & 0xE0) >> 5);
284 read_efuse_byte(hw, efuse_addr, rtemp8);
286 if ((*rtemp8 & 0x0F) == 0x0F) {
287 efuse_addr++;
288 read_efuse_byte(hw, efuse_addr, rtemp8);
290 if (*rtemp8 != 0xFF &&
291 (efuse_addr < efuse_len)) {
292 efuse_addr++;
294 continue;
295 } else {
296 offset = ((*rtemp8 & 0xF0) >> 1) | u1temp;
297 wren = (*rtemp8 & 0x0F);
298 efuse_addr++;
300 } else {
301 offset = ((*rtemp8 >> 4) & 0x0f);
302 wren = (*rtemp8 & 0x0f);
305 if (offset < efuse_max_section) {
306 RTPRINT(rtlpriv, FEEPROM, EFUSE_READ_ALL,
307 "offset-%d Worden=%x\n", offset, wren);
309 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
310 if (!(wren & 0x01)) {
311 RTPRINT(rtlpriv, FEEPROM,
312 EFUSE_READ_ALL,
313 "Addr=%d\n", efuse_addr);
315 read_efuse_byte(hw, efuse_addr, rtemp8);
316 efuse_addr++;
317 efuse_utilized++;
318 efuse_word[i][offset] =
319 (*rtemp8 & 0xff);
321 if (efuse_addr >= efuse_len)
322 break;
324 RTPRINT(rtlpriv, FEEPROM,
325 EFUSE_READ_ALL,
326 "Addr=%d\n", efuse_addr);
328 read_efuse_byte(hw, efuse_addr, rtemp8);
329 efuse_addr++;
330 efuse_utilized++;
331 efuse_word[i][offset] |=
332 (((u16)*rtemp8 << 8) & 0xff00);
334 if (efuse_addr >= efuse_len)
335 break;
338 wren >>= 1;
342 RTPRINT(rtlpriv, FEEPROM, EFUSE_READ_ALL,
343 "Addr=%d\n", efuse_addr);
344 read_efuse_byte(hw, efuse_addr, rtemp8);
345 if (*rtemp8 != 0xFF && (efuse_addr < efuse_len)) {
346 efuse_utilized++;
347 efuse_addr++;
351 for (i = 0; i < efuse_max_section; i++) {
352 for (j = 0; j < EFUSE_MAX_WORD_UNIT; j++) {
353 efuse_tbl[(i * 8) + (j * 2)] =
354 (efuse_word[j][i] & 0xff);
355 efuse_tbl[(i * 8) + ((j * 2) + 1)] =
356 ((efuse_word[j][i] >> 8) & 0xff);
360 for (i = 0; i < _size_byte; i++)
361 pbuf[i] = efuse_tbl[_offset + i];
363 rtlefuse->efuse_usedbytes = efuse_utilized;
364 efuse_usage = (u8) ((efuse_utilized * 100) / efuse_len);
365 rtlefuse->efuse_usedpercentage = efuse_usage;
366 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_EFUSE_BYTES,
367 (u8 *)&efuse_utilized);
368 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_EFUSE_USAGE,
369 &efuse_usage);
370 done:
371 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++)
372 kfree(efuse_word[i]);
373 kfree(efuse_word);
374 out:
375 kfree(efuse_tbl);
378 bool efuse_shadow_update_chk(struct ieee80211_hw *hw)
380 struct rtl_priv *rtlpriv = rtl_priv(hw);
381 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
382 u8 section_idx, i, Base;
383 u16 words_need = 0, hdr_num = 0, totalbytes, efuse_used;
384 bool wordchanged, result = true;
386 for (section_idx = 0; section_idx < 16; section_idx++) {
387 Base = section_idx * 8;
388 wordchanged = false;
390 for (i = 0; i < 8; i = i + 2) {
391 if ((rtlefuse->efuse_map[EFUSE_INIT_MAP][Base + i] !=
392 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][Base + i]) ||
393 (rtlefuse->efuse_map[EFUSE_INIT_MAP][Base + i + 1] !=
394 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][Base + i +
395 1])) {
396 words_need++;
397 wordchanged = true;
401 if (wordchanged)
402 hdr_num++;
405 totalbytes = hdr_num + words_need * 2;
406 efuse_used = rtlefuse->efuse_usedbytes;
408 if ((totalbytes + efuse_used) >=
409 (EFUSE_MAX_SIZE - rtlpriv->cfg->maps[EFUSE_OOB_PROTECT_BYTES_LEN]))
410 result = false;
412 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD,
413 "efuse_shadow_update_chk(): totalbytes(%#x), hdr_num(%#x), words_need(%#x), efuse_used(%d)\n",
414 totalbytes, hdr_num, words_need, efuse_used);
416 return result;
419 void efuse_shadow_read(struct ieee80211_hw *hw, u8 type,
420 u16 offset, u32 *value)
422 if (type == 1)
423 efuse_shadow_read_1byte(hw, offset, (u8 *)value);
424 else if (type == 2)
425 efuse_shadow_read_2byte(hw, offset, (u16 *)value);
426 else if (type == 4)
427 efuse_shadow_read_4byte(hw, offset, value);
430 EXPORT_SYMBOL(efuse_shadow_read);
432 void efuse_shadow_write(struct ieee80211_hw *hw, u8 type, u16 offset,
433 u32 value)
435 if (type == 1)
436 efuse_shadow_write_1byte(hw, offset, (u8) value);
437 else if (type == 2)
438 efuse_shadow_write_2byte(hw, offset, (u16) value);
439 else if (type == 4)
440 efuse_shadow_write_4byte(hw, offset, value);
444 bool efuse_shadow_update(struct ieee80211_hw *hw)
446 struct rtl_priv *rtlpriv = rtl_priv(hw);
447 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
448 u16 i, offset, base;
449 u8 word_en = 0x0F;
450 u8 first_pg = false;
452 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, "\n");
454 if (!efuse_shadow_update_chk(hw)) {
455 efuse_read_all_map(hw, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0]);
456 memcpy(&rtlefuse->efuse_map[EFUSE_MODIFY_MAP][0],
457 &rtlefuse->efuse_map[EFUSE_INIT_MAP][0],
458 rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]);
460 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD,
461 "efuse out of capacity!!\n");
462 return false;
464 efuse_power_switch(hw, true, true);
466 for (offset = 0; offset < 16; offset++) {
468 word_en = 0x0F;
469 base = offset * 8;
471 for (i = 0; i < 8; i++) {
472 if (first_pg) {
473 word_en &= ~(BIT(i / 2));
475 rtlefuse->efuse_map[EFUSE_INIT_MAP][base + i] =
476 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][base + i];
477 } else {
479 if (rtlefuse->efuse_map[EFUSE_INIT_MAP][base + i] !=
480 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][base + i]) {
481 word_en &= ~(BIT(i / 2));
483 rtlefuse->efuse_map[EFUSE_INIT_MAP][base + i] =
484 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][base + i];
489 if (word_en != 0x0F) {
490 u8 tmpdata[8];
491 memcpy(tmpdata,
492 &rtlefuse->efuse_map[EFUSE_MODIFY_MAP][base],
494 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_LOUD,
495 "U-efuse\n", tmpdata, 8);
497 if (!efuse_pg_packet_write(hw, (u8) offset, word_en,
498 tmpdata)) {
499 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
500 "PG section(%#x) fail!!\n", offset);
501 break;
507 efuse_power_switch(hw, true, false);
508 efuse_read_all_map(hw, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0]);
510 memcpy(&rtlefuse->efuse_map[EFUSE_MODIFY_MAP][0],
511 &rtlefuse->efuse_map[EFUSE_INIT_MAP][0],
512 rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]);
514 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, "\n");
515 return true;
518 void rtl_efuse_shadow_map_update(struct ieee80211_hw *hw)
520 struct rtl_priv *rtlpriv = rtl_priv(hw);
521 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
523 if (rtlefuse->autoload_failflag)
524 memset((&rtlefuse->efuse_map[EFUSE_INIT_MAP][0]),
525 0xFF, rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]);
526 else
527 efuse_read_all_map(hw, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0]);
529 memcpy(&rtlefuse->efuse_map[EFUSE_MODIFY_MAP][0],
530 &rtlefuse->efuse_map[EFUSE_INIT_MAP][0],
531 rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]);
534 EXPORT_SYMBOL(rtl_efuse_shadow_map_update);
536 void efuse_force_write_vendor_Id(struct ieee80211_hw *hw)
538 u8 tmpdata[8] = { 0xFF, 0xFF, 0xEC, 0x10, 0xFF, 0xFF, 0xFF, 0xFF };
540 efuse_power_switch(hw, true, true);
542 efuse_pg_packet_write(hw, 1, 0xD, tmpdata);
544 efuse_power_switch(hw, true, false);
548 void efuse_re_pg_section(struct ieee80211_hw *hw, u8 section_idx)
552 static void efuse_shadow_read_1byte(struct ieee80211_hw *hw,
553 u16 offset, u8 *value)
555 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
556 *value = rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset];
559 static void efuse_shadow_read_2byte(struct ieee80211_hw *hw,
560 u16 offset, u16 *value)
562 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
564 *value = rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset];
565 *value |= rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 1] << 8;
569 static void efuse_shadow_read_4byte(struct ieee80211_hw *hw,
570 u16 offset, u32 *value)
572 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
574 *value = rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset];
575 *value |= rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 1] << 8;
576 *value |= rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 2] << 16;
577 *value |= rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 3] << 24;
580 static void efuse_shadow_write_1byte(struct ieee80211_hw *hw,
581 u16 offset, u8 value)
583 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
585 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset] = value;
588 static void efuse_shadow_write_2byte(struct ieee80211_hw *hw,
589 u16 offset, u16 value)
591 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
593 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset] = value & 0x00FF;
594 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 1] = value >> 8;
598 static void efuse_shadow_write_4byte(struct ieee80211_hw *hw,
599 u16 offset, u32 value)
601 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
603 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset] =
604 (u8) (value & 0x000000FF);
605 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 1] =
606 (u8) ((value >> 8) & 0x0000FF);
607 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 2] =
608 (u8) ((value >> 16) & 0x00FF);
609 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][offset + 3] =
610 (u8) ((value >> 24) & 0xFF);
614 int efuse_one_byte_read(struct ieee80211_hw *hw, u16 addr, u8 *data)
616 struct rtl_priv *rtlpriv = rtl_priv(hw);
617 u8 tmpidx = 0;
618 int result;
620 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1,
621 (u8) (addr & 0xff));
622 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2,
623 ((u8) ((addr >> 8) & 0x03)) |
624 (rtl_read_byte(rtlpriv,
625 rtlpriv->cfg->maps[EFUSE_CTRL] + 2) &
626 0xFC));
628 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3, 0x72);
630 while (!(0x80 & rtl_read_byte(rtlpriv,
631 rtlpriv->cfg->maps[EFUSE_CTRL] + 3))
632 && (tmpidx < 100)) {
633 tmpidx++;
636 if (tmpidx < 100) {
637 *data = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]);
638 result = true;
639 } else {
640 *data = 0xff;
641 result = false;
643 return result;
645 EXPORT_SYMBOL(efuse_one_byte_read);
647 static int efuse_one_byte_write(struct ieee80211_hw *hw, u16 addr, u8 data)
649 struct rtl_priv *rtlpriv = rtl_priv(hw);
650 u8 tmpidx = 0;
652 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD,
653 "Addr = %x Data=%x\n", addr, data);
655 rtl_write_byte(rtlpriv,
656 rtlpriv->cfg->maps[EFUSE_CTRL] + 1, (u8) (addr & 0xff));
657 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2,
658 (rtl_read_byte(rtlpriv,
659 rtlpriv->cfg->maps[EFUSE_CTRL] +
660 2) & 0xFC) | (u8) ((addr >> 8) & 0x03));
662 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL], data);
663 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3, 0xF2);
665 while ((0x80 & rtl_read_byte(rtlpriv,
666 rtlpriv->cfg->maps[EFUSE_CTRL] + 3))
667 && (tmpidx < 100)) {
668 tmpidx++;
671 if (tmpidx < 100)
672 return true;
673 return false;
676 static void efuse_read_all_map(struct ieee80211_hw *hw, u8 *efuse)
678 struct rtl_priv *rtlpriv = rtl_priv(hw);
679 efuse_power_switch(hw, false, true);
680 read_efuse(hw, 0, rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE], efuse);
681 efuse_power_switch(hw, false, false);
684 static void efuse_read_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr,
685 u8 efuse_data, u8 offset, u8 *tmpdata,
686 u8 *readstate)
688 bool dataempty = true;
689 u8 hoffset;
690 u8 tmpidx;
691 u8 hworden;
692 u8 word_cnts;
694 hoffset = (efuse_data >> 4) & 0x0F;
695 hworden = efuse_data & 0x0F;
696 word_cnts = efuse_calculate_word_cnts(hworden);
698 if (hoffset == offset) {
699 for (tmpidx = 0; tmpidx < word_cnts * 2; tmpidx++) {
700 if (efuse_one_byte_read(hw, *efuse_addr + 1 + tmpidx,
701 &efuse_data)) {
702 tmpdata[tmpidx] = efuse_data;
703 if (efuse_data != 0xff)
704 dataempty = false;
708 if (!dataempty) {
709 *readstate = PG_STATE_DATA;
710 } else {
711 *efuse_addr = *efuse_addr + (word_cnts * 2) + 1;
712 *readstate = PG_STATE_HEADER;
715 } else {
716 *efuse_addr = *efuse_addr + (word_cnts * 2) + 1;
717 *readstate = PG_STATE_HEADER;
721 static int efuse_pg_packet_read(struct ieee80211_hw *hw, u8 offset, u8 *data)
723 u8 readstate = PG_STATE_HEADER;
725 bool continual = true;
727 u8 efuse_data, word_cnts = 0;
728 u16 efuse_addr = 0;
729 u8 tmpdata[8];
731 if (data == NULL)
732 return false;
733 if (offset > 15)
734 return false;
736 memset(data, 0xff, PGPKT_DATA_SIZE * sizeof(u8));
737 memset(tmpdata, 0xff, PGPKT_DATA_SIZE * sizeof(u8));
739 while (continual && (efuse_addr < EFUSE_MAX_SIZE)) {
740 if (readstate & PG_STATE_HEADER) {
741 if (efuse_one_byte_read(hw, efuse_addr, &efuse_data)
742 && (efuse_data != 0xFF))
743 efuse_read_data_case1(hw, &efuse_addr,
744 efuse_data, offset,
745 tmpdata, &readstate);
746 else
747 continual = false;
748 } else if (readstate & PG_STATE_DATA) {
749 efuse_word_enable_data_read(0, tmpdata, data);
750 efuse_addr = efuse_addr + (word_cnts * 2) + 1;
751 readstate = PG_STATE_HEADER;
756 if ((data[0] == 0xff) && (data[1] == 0xff) &&
757 (data[2] == 0xff) && (data[3] == 0xff) &&
758 (data[4] == 0xff) && (data[5] == 0xff) &&
759 (data[6] == 0xff) && (data[7] == 0xff))
760 return false;
761 else
762 return true;
766 static void efuse_write_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr,
767 u8 efuse_data, u8 offset,
768 int *continual, u8 *write_state,
769 struct pgpkt_struct *target_pkt,
770 int *repeat_times, int *result, u8 word_en)
772 struct rtl_priv *rtlpriv = rtl_priv(hw);
773 struct pgpkt_struct tmp_pkt;
774 int dataempty = true;
775 u8 originaldata[8 * sizeof(u8)];
776 u8 badworden = 0x0F;
777 u8 match_word_en, tmp_word_en;
778 u8 tmpindex;
779 u8 tmp_header = efuse_data;
780 u8 tmp_word_cnts;
782 tmp_pkt.offset = (tmp_header >> 4) & 0x0F;
783 tmp_pkt.word_en = tmp_header & 0x0F;
784 tmp_word_cnts = efuse_calculate_word_cnts(tmp_pkt.word_en);
786 if (tmp_pkt.offset != target_pkt->offset) {
787 *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) + 1;
788 *write_state = PG_STATE_HEADER;
789 } else {
790 for (tmpindex = 0; tmpindex < (tmp_word_cnts * 2); tmpindex++) {
791 if (efuse_one_byte_read(hw,
792 (*efuse_addr + 1 + tmpindex),
793 &efuse_data) &&
794 (efuse_data != 0xFF))
795 dataempty = false;
798 if (!dataempty) {
799 *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) + 1;
800 *write_state = PG_STATE_HEADER;
801 } else {
802 match_word_en = 0x0F;
803 if (!((target_pkt->word_en & BIT(0)) |
804 (tmp_pkt.word_en & BIT(0))))
805 match_word_en &= (~BIT(0));
807 if (!((target_pkt->word_en & BIT(1)) |
808 (tmp_pkt.word_en & BIT(1))))
809 match_word_en &= (~BIT(1));
811 if (!((target_pkt->word_en & BIT(2)) |
812 (tmp_pkt.word_en & BIT(2))))
813 match_word_en &= (~BIT(2));
815 if (!((target_pkt->word_en & BIT(3)) |
816 (tmp_pkt.word_en & BIT(3))))
817 match_word_en &= (~BIT(3));
819 if ((match_word_en & 0x0F) != 0x0F) {
820 badworden =
821 enable_efuse_data_write(hw,
822 *efuse_addr + 1,
823 tmp_pkt.word_en,
824 target_pkt->data);
826 if (0x0F != (badworden & 0x0F)) {
827 u8 reorg_offset = offset;
828 u8 reorg_worden = badworden;
829 efuse_pg_packet_write(hw, reorg_offset,
830 reorg_worden,
831 originaldata);
834 tmp_word_en = 0x0F;
835 if ((target_pkt->word_en & BIT(0)) ^
836 (match_word_en & BIT(0)))
837 tmp_word_en &= (~BIT(0));
839 if ((target_pkt->word_en & BIT(1)) ^
840 (match_word_en & BIT(1)))
841 tmp_word_en &= (~BIT(1));
843 if ((target_pkt->word_en & BIT(2)) ^
844 (match_word_en & BIT(2)))
845 tmp_word_en &= (~BIT(2));
847 if ((target_pkt->word_en & BIT(3)) ^
848 (match_word_en & BIT(3)))
849 tmp_word_en &= (~BIT(3));
851 if ((tmp_word_en & 0x0F) != 0x0F) {
852 *efuse_addr = efuse_get_current_size(hw);
853 target_pkt->offset = offset;
854 target_pkt->word_en = tmp_word_en;
855 } else {
856 *continual = false;
858 *write_state = PG_STATE_HEADER;
859 *repeat_times += 1;
860 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) {
861 *continual = false;
862 *result = false;
864 } else {
865 *efuse_addr += (2 * tmp_word_cnts) + 1;
866 target_pkt->offset = offset;
867 target_pkt->word_en = word_en;
868 *write_state = PG_STATE_HEADER;
872 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, "efuse PG_STATE_HEADER-1\n");
875 static void efuse_write_data_case2(struct ieee80211_hw *hw, u16 *efuse_addr,
876 int *continual, u8 *write_state,
877 struct pgpkt_struct target_pkt,
878 int *repeat_times, int *result)
880 struct rtl_priv *rtlpriv = rtl_priv(hw);
881 struct pgpkt_struct tmp_pkt;
882 u8 pg_header;
883 u8 tmp_header;
884 u8 originaldata[8 * sizeof(u8)];
885 u8 tmp_word_cnts;
886 u8 badworden = 0x0F;
888 pg_header = ((target_pkt.offset << 4) & 0xf0) | target_pkt.word_en;
889 efuse_one_byte_write(hw, *efuse_addr, pg_header);
890 efuse_one_byte_read(hw, *efuse_addr, &tmp_header);
892 if (tmp_header == pg_header) {
893 *write_state = PG_STATE_DATA;
894 } else if (tmp_header == 0xFF) {
895 *write_state = PG_STATE_HEADER;
896 *repeat_times += 1;
897 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) {
898 *continual = false;
899 *result = false;
901 } else {
902 tmp_pkt.offset = (tmp_header >> 4) & 0x0F;
903 tmp_pkt.word_en = tmp_header & 0x0F;
905 tmp_word_cnts = efuse_calculate_word_cnts(tmp_pkt.word_en);
907 memset(originaldata, 0xff, 8 * sizeof(u8));
909 if (efuse_pg_packet_read(hw, tmp_pkt.offset, originaldata)) {
910 badworden = enable_efuse_data_write(hw,
911 *efuse_addr + 1,
912 tmp_pkt.word_en,
913 originaldata);
915 if (0x0F != (badworden & 0x0F)) {
916 u8 reorg_offset = tmp_pkt.offset;
917 u8 reorg_worden = badworden;
918 efuse_pg_packet_write(hw, reorg_offset,
919 reorg_worden,
920 originaldata);
921 *efuse_addr = efuse_get_current_size(hw);
922 } else {
923 *efuse_addr = *efuse_addr +
924 (tmp_word_cnts * 2) + 1;
926 } else {
927 *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) + 1;
930 *write_state = PG_STATE_HEADER;
931 *repeat_times += 1;
932 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) {
933 *continual = false;
934 *result = false;
937 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG,
938 "efuse PG_STATE_HEADER-2\n");
942 static int efuse_pg_packet_write(struct ieee80211_hw *hw,
943 u8 offset, u8 word_en, u8 *data)
945 struct rtl_priv *rtlpriv = rtl_priv(hw);
946 struct pgpkt_struct target_pkt;
947 u8 write_state = PG_STATE_HEADER;
948 int continual = true, dataempty = true, result = true;
949 u16 efuse_addr = 0;
950 u8 efuse_data;
951 u8 target_word_cnts = 0;
952 u8 badworden = 0x0F;
953 static int repeat_times;
955 if (efuse_get_current_size(hw) >= (EFUSE_MAX_SIZE -
956 rtlpriv->cfg->maps[EFUSE_OOB_PROTECT_BYTES_LEN])) {
957 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG,
958 "efuse_pg_packet_write error\n");
959 return false;
962 target_pkt.offset = offset;
963 target_pkt.word_en = word_en;
965 memset(target_pkt.data, 0xFF, 8 * sizeof(u8));
967 efuse_word_enable_data_read(word_en, data, target_pkt.data);
968 target_word_cnts = efuse_calculate_word_cnts(target_pkt.word_en);
970 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, "efuse Power ON\n");
972 while (continual && (efuse_addr < (EFUSE_MAX_SIZE -
973 rtlpriv->cfg->maps[EFUSE_OOB_PROTECT_BYTES_LEN]))) {
975 if (write_state == PG_STATE_HEADER) {
976 dataempty = true;
977 badworden = 0x0F;
978 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG,
979 "efuse PG_STATE_HEADER\n");
981 if (efuse_one_byte_read(hw, efuse_addr, &efuse_data) &&
982 (efuse_data != 0xFF))
983 efuse_write_data_case1(hw, &efuse_addr,
984 efuse_data, offset,
985 &continual,
986 &write_state,
987 &target_pkt,
988 &repeat_times, &result,
989 word_en);
990 else
991 efuse_write_data_case2(hw, &efuse_addr,
992 &continual,
993 &write_state,
994 target_pkt,
995 &repeat_times,
996 &result);
998 } else if (write_state == PG_STATE_DATA) {
999 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG,
1000 "efuse PG_STATE_DATA\n");
1001 badworden = 0x0f;
1002 badworden =
1003 enable_efuse_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 =
1011 efuse_addr + (2 * target_word_cnts) + 1;
1013 target_pkt.offset = offset;
1014 target_pkt.word_en = badworden;
1015 target_word_cnts =
1016 efuse_calculate_word_cnts(target_pkt.
1017 word_en);
1018 write_state = PG_STATE_HEADER;
1019 repeat_times++;
1020 if (repeat_times > EFUSE_REPEAT_THRESHOLD_) {
1021 continual = false;
1022 result = false;
1024 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG,
1025 "efuse PG_STATE_HEADER-3\n");
1030 if (efuse_addr >= (EFUSE_MAX_SIZE -
1031 rtlpriv->cfg->maps[EFUSE_OOB_PROTECT_BYTES_LEN])) {
1032 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD,
1033 "efuse_addr(%#x) Out of size!!\n", efuse_addr);
1036 return true;
1039 static void efuse_word_enable_data_read(u8 word_en, u8 *sourdata,
1040 u8 *targetdata)
1042 if (!(word_en & BIT(0))) {
1043 targetdata[0] = sourdata[0];
1044 targetdata[1] = sourdata[1];
1047 if (!(word_en & BIT(1))) {
1048 targetdata[2] = sourdata[2];
1049 targetdata[3] = sourdata[3];
1052 if (!(word_en & BIT(2))) {
1053 targetdata[4] = sourdata[4];
1054 targetdata[5] = sourdata[5];
1057 if (!(word_en & BIT(3))) {
1058 targetdata[6] = sourdata[6];
1059 targetdata[7] = sourdata[7];
1063 static u8 enable_efuse_data_write(struct ieee80211_hw *hw,
1064 u16 efuse_addr, u8 word_en, u8 *data)
1066 struct rtl_priv *rtlpriv = rtl_priv(hw);
1067 u16 tmpaddr;
1068 u16 start_addr = efuse_addr;
1069 u8 badworden = 0x0F;
1070 u8 tmpdata[8];
1072 memset(tmpdata, 0xff, PGPKT_DATA_SIZE);
1073 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD,
1074 "word_en = %x efuse_addr=%x\n", word_en, efuse_addr);
1076 if (!(word_en & BIT(0))) {
1077 tmpaddr = start_addr;
1078 efuse_one_byte_write(hw, start_addr++, data[0]);
1079 efuse_one_byte_write(hw, start_addr++, data[1]);
1081 efuse_one_byte_read(hw, tmpaddr, &tmpdata[0]);
1082 efuse_one_byte_read(hw, tmpaddr + 1, &tmpdata[1]);
1083 if ((data[0] != tmpdata[0]) || (data[1] != tmpdata[1]))
1084 badworden &= (~BIT(0));
1087 if (!(word_en & BIT(1))) {
1088 tmpaddr = start_addr;
1089 efuse_one_byte_write(hw, start_addr++, data[2]);
1090 efuse_one_byte_write(hw, start_addr++, data[3]);
1092 efuse_one_byte_read(hw, tmpaddr, &tmpdata[2]);
1093 efuse_one_byte_read(hw, tmpaddr + 1, &tmpdata[3]);
1094 if ((data[2] != tmpdata[2]) || (data[3] != tmpdata[3]))
1095 badworden &= (~BIT(1));
1098 if (!(word_en & BIT(2))) {
1099 tmpaddr = start_addr;
1100 efuse_one_byte_write(hw, start_addr++, data[4]);
1101 efuse_one_byte_write(hw, start_addr++, data[5]);
1103 efuse_one_byte_read(hw, tmpaddr, &tmpdata[4]);
1104 efuse_one_byte_read(hw, tmpaddr + 1, &tmpdata[5]);
1105 if ((data[4] != tmpdata[4]) || (data[5] != tmpdata[5]))
1106 badworden &= (~BIT(2));
1109 if (!(word_en & BIT(3))) {
1110 tmpaddr = start_addr;
1111 efuse_one_byte_write(hw, start_addr++, data[6]);
1112 efuse_one_byte_write(hw, start_addr++, data[7]);
1114 efuse_one_byte_read(hw, tmpaddr, &tmpdata[6]);
1115 efuse_one_byte_read(hw, tmpaddr + 1, &tmpdata[7]);
1116 if ((data[6] != tmpdata[6]) || (data[7] != tmpdata[7]))
1117 badworden &= (~BIT(3));
1120 return badworden;
1123 static void efuse_power_switch(struct ieee80211_hw *hw, u8 write, u8 pwrstate)
1125 struct rtl_priv *rtlpriv = rtl_priv(hw);
1126 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1127 u8 tempval;
1128 u16 tmpV16;
1130 if (pwrstate && (rtlhal->hw_type != HARDWARE_TYPE_RTL8192SE)) {
1132 if (rtlhal->hw_type != HARDWARE_TYPE_RTL8192CE &&
1133 rtlhal->hw_type != HARDWARE_TYPE_RTL8192DE) {
1134 rtl_write_byte(rtlpriv,
1135 rtlpriv->cfg->maps[EFUSE_ACCESS], 0x69);
1136 } else {
1137 tmpV16 =
1138 rtl_read_word(rtlpriv,
1139 rtlpriv->cfg->maps[SYS_ISO_CTRL]);
1140 if (!(tmpV16 & rtlpriv->cfg->maps[EFUSE_PWC_EV12V])) {
1141 tmpV16 |= rtlpriv->cfg->maps[EFUSE_PWC_EV12V];
1142 rtl_write_word(rtlpriv,
1143 rtlpriv->cfg->maps[SYS_ISO_CTRL],
1144 tmpV16);
1147 tmpV16 = rtl_read_word(rtlpriv,
1148 rtlpriv->cfg->maps[SYS_FUNC_EN]);
1149 if (!(tmpV16 & rtlpriv->cfg->maps[EFUSE_FEN_ELDR])) {
1150 tmpV16 |= rtlpriv->cfg->maps[EFUSE_FEN_ELDR];
1151 rtl_write_word(rtlpriv,
1152 rtlpriv->cfg->maps[SYS_FUNC_EN], tmpV16);
1155 tmpV16 = rtl_read_word(rtlpriv, rtlpriv->cfg->maps[SYS_CLK]);
1156 if ((!(tmpV16 & rtlpriv->cfg->maps[EFUSE_LOADER_CLK_EN])) ||
1157 (!(tmpV16 & rtlpriv->cfg->maps[EFUSE_ANA8M]))) {
1158 tmpV16 |= (rtlpriv->cfg->maps[EFUSE_LOADER_CLK_EN] |
1159 rtlpriv->cfg->maps[EFUSE_ANA8M]);
1160 rtl_write_word(rtlpriv,
1161 rtlpriv->cfg->maps[SYS_CLK], tmpV16);
1165 if (pwrstate) {
1166 if (write) {
1167 tempval = rtl_read_byte(rtlpriv,
1168 rtlpriv->cfg->maps[EFUSE_TEST] +
1171 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
1172 tempval &= ~(BIT(3) | BIT(4) | BIT(5) | BIT(6));
1173 tempval |= (VOLTAGE_V25 << 3);
1174 } else if (rtlhal->hw_type != HARDWARE_TYPE_RTL8192SE) {
1175 tempval &= 0x0F;
1176 tempval |= (VOLTAGE_V25 << 4);
1179 rtl_write_byte(rtlpriv,
1180 rtlpriv->cfg->maps[EFUSE_TEST] + 3,
1181 (tempval | 0x80));
1184 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) {
1185 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CLK],
1186 0x03);
1188 } else {
1189 if (rtlhal->hw_type != HARDWARE_TYPE_RTL8192CE &&
1190 rtlhal->hw_type != HARDWARE_TYPE_RTL8192DE)
1191 rtl_write_byte(rtlpriv,
1192 rtlpriv->cfg->maps[EFUSE_ACCESS], 0);
1194 if (write) {
1195 tempval = rtl_read_byte(rtlpriv,
1196 rtlpriv->cfg->maps[EFUSE_TEST] +
1198 rtl_write_byte(rtlpriv,
1199 rtlpriv->cfg->maps[EFUSE_TEST] + 3,
1200 (tempval & 0x7F));
1203 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) {
1204 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CLK],
1205 0x02);
1210 static u16 efuse_get_current_size(struct ieee80211_hw *hw)
1212 int continual = true;
1213 u16 efuse_addr = 0;
1214 u8 hoffset, hworden;
1215 u8 efuse_data, word_cnts;
1217 while (continual && efuse_one_byte_read(hw, efuse_addr, &efuse_data) &&
1218 (efuse_addr < EFUSE_MAX_SIZE)) {
1219 if (efuse_data != 0xFF) {
1220 hoffset = (efuse_data >> 4) & 0x0F;
1221 hworden = efuse_data & 0x0F;
1222 word_cnts = efuse_calculate_word_cnts(hworden);
1223 efuse_addr = efuse_addr + (word_cnts * 2) + 1;
1224 } else {
1225 continual = false;
1229 return efuse_addr;
1232 static u8 efuse_calculate_word_cnts(u8 word_en)
1234 u8 word_cnts = 0;
1235 if (!(word_en & BIT(0)))
1236 word_cnts++;
1237 if (!(word_en & BIT(1)))
1238 word_cnts++;
1239 if (!(word_en & BIT(2)))
1240 word_cnts++;
1241 if (!(word_en & BIT(3)))
1242 word_cnts++;
1243 return word_cnts;