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