staging: rtl8188eu: Rename Hal_EFUSEGetEfuseDefinition88E()
[deliverable/linux.git] / drivers / staging / rtl8188eu / core / rtw_efuse.c
1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4 *
5 * This 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 * This 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 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/
20 #define _RTW_EFUSE_C_
21
22 #include <osdep_service.h>
23 #include <drv_types.h>
24 #include <rtw_efuse.h>
25 #include <usb_ops_linux.h>
26
27 /*------------------------Define local variable------------------------------*/
28 u8 fakeEfuseBank;
29 u32 fakeEfuseUsedBytes;
30 u8 fakeEfuseContent[EFUSE_MAX_HW_SIZE] = {0};
31 u8 fakeEfuseInitMap[EFUSE_MAX_MAP_LEN] = {0};
32 u8 fakeEfuseModifiedMap[EFUSE_MAX_MAP_LEN] = {0};
33
34 u32 BTEfuseUsedBytes;
35 u8 BTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
36 u8 BTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN] = {0};
37 u8 BTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN] = {0};
38
39 u32 fakeBTEfuseUsedBytes;
40 u8 fakeBTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
41 u8 fakeBTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN] = {0};
42 u8 fakeBTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN] = {0};
43 /*------------------------Define local variable------------------------------*/
44
45 /* */
46 #define REG_EFUSE_CTRL 0x0030
47 #define EFUSE_CTRL REG_EFUSE_CTRL /* E-Fuse Control. */
48 /* */
49
50 bool
51 Efuse_Read1ByteFromFakeContent(
52 struct adapter *pAdapter,
53 u16 Offset,
54 u8 *Value);
55 bool
56 Efuse_Read1ByteFromFakeContent(
57 struct adapter *pAdapter,
58 u16 Offset,
59 u8 *Value)
60 {
61 if (Offset >= EFUSE_MAX_HW_SIZE)
62 return false;
63 if (fakeEfuseBank == 0)
64 *Value = fakeEfuseContent[Offset];
65 else
66 *Value = fakeBTEfuseContent[fakeEfuseBank-1][Offset];
67 return true;
68 }
69
70 static bool
71 Efuse_Write1ByteToFakeContent(
72 struct adapter *pAdapter,
73 u16 Offset,
74 u8 Value)
75 {
76 if (Offset >= EFUSE_MAX_HW_SIZE)
77 return false;
78 if (fakeEfuseBank == 0)
79 fakeEfuseContent[Offset] = Value;
80 else
81 fakeBTEfuseContent[fakeEfuseBank-1][Offset] = Value;
82 return true;
83 }
84
85 /*-----------------------------------------------------------------------------
86 * Function: Efuse_PowerSwitch
87 *
88 * Overview: When we want to enable write operation, we should change to
89 * pwr on state. When we stop write, we should switch to 500k mode
90 * and disable LDO 2.5V.
91 *
92 * Input: NONE
93 *
94 * Output: NONE
95 *
96 * Return: NONE
97 *
98 * Revised History:
99 * When Who Remark
100 * 11/17/2008 MHC Create Version 0.
101 *
102 *---------------------------------------------------------------------------*/
103 void
104 Efuse_PowerSwitch(
105 struct adapter *pAdapter,
106 u8 write,
107 u8 PwrState)
108 {
109 pAdapter->HalFunc.EfusePowerSwitch(pAdapter, write, PwrState);
110 }
111
112 /*-----------------------------------------------------------------------------
113 * Function: efuse_GetCurrentSize
114 *
115 * Overview: Get current efuse size!!!
116 *
117 * Input: NONE
118 *
119 * Output: NONE
120 *
121 * Return: NONE
122 *
123 * Revised History:
124 * When Who Remark
125 * 11/16/2008 MHC Create Version 0.
126 *
127 *---------------------------------------------------------------------------*/
128 u16
129 Efuse_GetCurrentSize(
130 struct adapter *pAdapter,
131 bool pseudo)
132 {
133 u16 ret = 0;
134
135 ret = pAdapter->HalFunc.EfuseGetCurrentSize(pAdapter, pseudo);
136
137 return ret;
138 }
139
140 /* 11/16/2008 MH Add description. Get current efuse area enabled word!!. */
141 u8
142 Efuse_CalculateWordCnts(u8 word_en)
143 {
144 u8 word_cnts = 0;
145 if (!(word_en & BIT(0)))
146 word_cnts++; /* 0 : write enable */
147 if (!(word_en & BIT(1)))
148 word_cnts++;
149 if (!(word_en & BIT(2)))
150 word_cnts++;
151 if (!(word_en & BIT(3)))
152 word_cnts++;
153 return word_cnts;
154 }
155
156 /*
157 * Description:
158 * Execute E-Fuse read byte operation.
159 * Referred from SD1 Richard.
160 * Assumption:
161 * 1. Boot from E-Fuse and successfully auto-load.
162 * 2. PASSIVE_LEVEL (USB interface)
163 * Created by Roger, 2008.10.21.
164 */
165 void
166 ReadEFuseByte(
167 struct adapter *Adapter,
168 u16 _offset,
169 u8 *pbuf,
170 bool pseudo)
171 {
172 u32 value32;
173 u8 readbyte;
174 u16 retry;
175
176 if (pseudo) {
177 Efuse_Read1ByteFromFakeContent(Adapter, _offset, pbuf);
178 return;
179 }
180
181 /* Write Address */
182 usb_write8(Adapter, EFUSE_CTRL+1, (_offset & 0xff));
183 readbyte = usb_read8(Adapter, EFUSE_CTRL+2);
184 usb_write8(Adapter, EFUSE_CTRL+2, ((_offset >> 8) & 0x03) | (readbyte & 0xfc));
185
186 /* Write bit 32 0 */
187 readbyte = usb_read8(Adapter, EFUSE_CTRL+3);
188 usb_write8(Adapter, EFUSE_CTRL+3, (readbyte & 0x7f));
189
190 /* Check bit 32 read-ready */
191 retry = 0;
192 value32 = usb_read32(Adapter, EFUSE_CTRL);
193 while (!(((value32 >> 24) & 0xff) & 0x80) && (retry < 10000)) {
194 value32 = usb_read32(Adapter, EFUSE_CTRL);
195 retry++;
196 }
197
198 /* 20100205 Joseph: Add delay suggested by SD1 Victor. */
199 /* This fix the problem that Efuse read error in high temperature condition. */
200 /* Designer says that there shall be some delay after ready bit is set, or the */
201 /* result will always stay on last data we read. */
202 udelay(50);
203 value32 = usb_read32(Adapter, EFUSE_CTRL);
204
205 *pbuf = (u8)(value32 & 0xff);
206 }
207
208 /* Description:
209 * 1. Execute E-Fuse read byte operation according as map offset and
210 * save to E-Fuse table.
211 * 2. Referred from SD1 Richard.
212 * Assumption:
213 * 1. Boot from E-Fuse and successfully auto-load.
214 * 2. PASSIVE_LEVEL (USB interface)
215 * Created by Roger, 2008.10.21.
216 * 2008/12/12 MH
217 * 1. Reorganize code flow and reserve bytes. and add description.
218 * 2. Add efuse utilization collect.
219 * 2008/12/22 MH
220 * Read Efuse must check if we write section 1 data again!!!
221 * Sec1 write addr must be after sec5.
222 */
223
224 static void efuse_ReadEFuse(struct adapter *Adapter, u8 efuseType, u16 _offset, u16 _size_byte, u8 *pbuf, bool pseudo)
225 {
226 Adapter->HalFunc.ReadEFuse(Adapter, efuseType, _offset, _size_byte, pbuf, pseudo);
227 }
228
229 void EFUSE_GetEfuseDefinition(struct adapter *pAdapter, u8 efuseType, u8 type, void *pOut, bool pseudo
230 )
231 {
232 pAdapter->HalFunc.EFUSEGetEfuseDefinition(pAdapter, efuseType, type, pOut);
233 }
234
235 /*-----------------------------------------------------------------------------
236 * Function: EFUSE_Read1Byte
237 *
238 * Overview: Copy from WMAC fot EFUSE read 1 byte.
239 *
240 * Input: NONE
241 *
242 * Output: NONE
243 *
244 * Return: NONE
245 *
246 * Revised History:
247 * When Who Remark
248 * 09/23/2008 MHC Copy from WMAC.
249 *
250 *---------------------------------------------------------------------------*/
251 u8 EFUSE_Read1Byte(struct adapter *Adapter, u16 Address)
252 {
253 u8 data;
254 u8 Bytetemp = {0x00};
255 u8 temp = {0x00};
256 u32 k = 0;
257 u16 contentLen = 0;
258
259 EFUSE_GetEfuseDefinition(Adapter, EFUSE_WIFI , TYPE_EFUSE_REAL_CONTENT_LEN, (void *)&contentLen, false);
260
261 if (Address < contentLen) { /* E-fuse 512Byte */
262 /* Write E-fuse Register address bit0~7 */
263 temp = Address & 0xFF;
264 usb_write8(Adapter, EFUSE_CTRL+1, temp);
265 Bytetemp = usb_read8(Adapter, EFUSE_CTRL+2);
266 /* Write E-fuse Register address bit8~9 */
267 temp = ((Address >> 8) & 0x03) | (Bytetemp & 0xFC);
268 usb_write8(Adapter, EFUSE_CTRL+2, temp);
269
270 /* Write 0x30[31]= 0 */
271 Bytetemp = usb_read8(Adapter, EFUSE_CTRL+3);
272 temp = Bytetemp & 0x7F;
273 usb_write8(Adapter, EFUSE_CTRL+3, temp);
274
275 /* Wait Write-ready (0x30[31]= 1) */
276 Bytetemp = usb_read8(Adapter, EFUSE_CTRL+3);
277 while (!(Bytetemp & 0x80)) {
278 Bytetemp = usb_read8(Adapter, EFUSE_CTRL+3);
279 k++;
280 if (k == 1000) {
281 k = 0;
282 break;
283 }
284 }
285 data = usb_read8(Adapter, EFUSE_CTRL);
286 return data;
287 } else {
288 return 0xFF;
289 }
290
291 } /* EFUSE_Read1Byte */
292
293 /* 11/16/2008 MH Read one byte from real Efuse. */
294 u8 efuse_OneByteRead(struct adapter *pAdapter, u16 addr, u8 *data, bool pseudo)
295 {
296 u8 tmpidx = 0;
297 u8 result;
298
299 if (pseudo) {
300 result = Efuse_Read1ByteFromFakeContent(pAdapter, addr, data);
301 return result;
302 }
303 /* -----------------e-fuse reg ctrl --------------------------------- */
304 /* address */
305 usb_write8(pAdapter, EFUSE_CTRL+1, (u8)(addr & 0xff));
306 usb_write8(pAdapter, EFUSE_CTRL+2, ((u8)((addr>>8) & 0x03)) |
307 (usb_read8(pAdapter, EFUSE_CTRL+2) & 0xFC));
308
309 usb_write8(pAdapter, EFUSE_CTRL+3, 0x72);/* read cmd */
310
311 while (!(0x80 & usb_read8(pAdapter, EFUSE_CTRL+3)) && (tmpidx < 100))
312 tmpidx++;
313 if (tmpidx < 100) {
314 *data = usb_read8(pAdapter, EFUSE_CTRL);
315 result = true;
316 } else {
317 *data = 0xff;
318 result = false;
319 }
320 return result;
321 }
322
323 /* 11/16/2008 MH Write one byte to reald Efuse. */
324 u8 efuse_OneByteWrite(struct adapter *pAdapter, u16 addr, u8 data, bool pseudo)
325 {
326 u8 tmpidx = 0;
327 u8 result;
328
329 if (pseudo) {
330 result = Efuse_Write1ByteToFakeContent(pAdapter, addr, data);
331 return result;
332 }
333
334 /* -----------------e-fuse reg ctrl --------------------------------- */
335 /* address */
336 usb_write8(pAdapter, EFUSE_CTRL+1, (u8)(addr&0xff));
337 usb_write8(pAdapter, EFUSE_CTRL+2,
338 (usb_read8(pAdapter, EFUSE_CTRL+2) & 0xFC) |
339 (u8)((addr>>8) & 0x03));
340 usb_write8(pAdapter, EFUSE_CTRL, data);/* data */
341
342 usb_write8(pAdapter, EFUSE_CTRL+3, 0xF2);/* write cmd */
343
344 while ((0x80 & usb_read8(pAdapter, EFUSE_CTRL+3)) && (tmpidx < 100))
345 tmpidx++;
346
347 if (tmpidx < 100)
348 result = true;
349 else
350 result = false;
351
352 return result;
353 }
354
355 int Efuse_PgPacketRead(struct adapter *pAdapter, u8 offset, u8 *data, bool pseudo)
356 {
357 int ret = 0;
358
359 ret = pAdapter->HalFunc.Efuse_PgPacketRead(pAdapter, offset, data, pseudo);
360
361 return ret;
362 }
363
364 int Efuse_PgPacketWrite(struct adapter *pAdapter, u8 offset, u8 word_en, u8 *data, bool pseudo)
365 {
366 int ret;
367
368 ret = pAdapter->HalFunc.Efuse_PgPacketWrite(pAdapter, offset, word_en, data, pseudo);
369
370 return ret;
371 }
372
373
374 static int Efuse_PgPacketWrite_BT(struct adapter *pAdapter, u8 offset, u8 word_en, u8 *data, bool pseudo)
375 {
376 int ret;
377
378 ret = pAdapter->HalFunc.Efuse_PgPacketWrite_BT(pAdapter, offset, word_en, data, pseudo);
379
380 return ret;
381 }
382
383 /*-----------------------------------------------------------------------------
384 * Function: efuse_WordEnableDataRead
385 *
386 * Overview: Read allowed word in current efuse section data.
387 *
388 * Input: NONE
389 *
390 * Output: NONE
391 *
392 * Return: NONE
393 *
394 * Revised History:
395 * When Who Remark
396 * 11/16/2008 MHC Create Version 0.
397 * 11/21/2008 MHC Fix Write bug when we only enable late word.
398 *
399 *---------------------------------------------------------------------------*/
400 void efuse_WordEnableDataRead(u8 word_en, u8 *sourdata, u8 *targetdata)
401 {
402 if (!(word_en&BIT(0))) {
403 targetdata[0] = sourdata[0];
404 targetdata[1] = sourdata[1];
405 }
406 if (!(word_en&BIT(1))) {
407 targetdata[2] = sourdata[2];
408 targetdata[3] = sourdata[3];
409 }
410 if (!(word_en&BIT(2))) {
411 targetdata[4] = sourdata[4];
412 targetdata[5] = sourdata[5];
413 }
414 if (!(word_en&BIT(3))) {
415 targetdata[6] = sourdata[6];
416 targetdata[7] = sourdata[7];
417 }
418 }
419
420 u8 Efuse_WordEnableDataWrite(struct adapter *pAdapter, u16 efuse_addr, u8 word_en, u8 *data, bool pseudo)
421 {
422 u8 ret = 0;
423
424 ret = pAdapter->HalFunc.Efuse_WordEnableDataWrite(pAdapter, efuse_addr, word_en, data, pseudo);
425
426 return ret;
427 }
428
429 static u8 efuse_read8(struct adapter *padapter, u16 address, u8 *value)
430 {
431 return efuse_OneByteRead(padapter, address, value, false);
432 }
433
434 static u8 efuse_write8(struct adapter *padapter, u16 address, u8 *value)
435 {
436 return efuse_OneByteWrite(padapter, address, *value, false);
437 }
438
439 /*
440 * read/wirte raw efuse data
441 */
442 u8 rtw_efuse_access(struct adapter *padapter, u8 write, u16 start_addr, u16 cnts, u8 *data)
443 {
444 int i = 0;
445 u16 real_content_len = 0, max_available_size = 0;
446 u8 res = _FAIL;
447 u8 (*rw8)(struct adapter *, u16, u8*);
448
449 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_REAL_CONTENT_LEN, (void *)&real_content_len, false);
450 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size, false);
451
452 if (start_addr > real_content_len)
453 return _FAIL;
454
455 if (write) {
456 if ((start_addr + cnts) > max_available_size)
457 return _FAIL;
458 rw8 = &efuse_write8;
459 } else {
460 rw8 = &efuse_read8;
461 }
462
463 Efuse_PowerSwitch(padapter, write, true);
464
465 /* e-fuse one byte read / write */
466 for (i = 0; i < cnts; i++) {
467 if (start_addr >= real_content_len) {
468 res = _FAIL;
469 break;
470 }
471
472 res = rw8(padapter, start_addr++, data++);
473 if (_FAIL == res)
474 break;
475 }
476
477 Efuse_PowerSwitch(padapter, write, false);
478
479 return res;
480 }
481 /* */
482 u16 efuse_GetMaxSize(struct adapter *padapter)
483 {
484 u16 max_size;
485 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI , TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_size, false);
486 return max_size;
487 }
488 /* */
489 u8 efuse_GetCurrentSize(struct adapter *padapter, u16 *size)
490 {
491 Efuse_PowerSwitch(padapter, false, true);
492 *size = Efuse_GetCurrentSize(padapter, false);
493 Efuse_PowerSwitch(padapter, false, false);
494
495 return _SUCCESS;
496 }
497 /* */
498 u8 rtw_efuse_map_read(struct adapter *padapter, u16 addr, u16 cnts, u8 *data)
499 {
500 u16 mapLen = 0;
501
502 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, false);
503
504 if ((addr + cnts) > mapLen)
505 return _FAIL;
506
507 Efuse_PowerSwitch(padapter, false, true);
508
509 efuse_ReadEFuse(padapter, EFUSE_WIFI, addr, cnts, data, false);
510
511 Efuse_PowerSwitch(padapter, false, false);
512
513 return _SUCCESS;
514 }
515
516 u8 rtw_BT_efuse_map_read(struct adapter *padapter, u16 addr, u16 cnts, u8 *data)
517 {
518 u16 mapLen = 0;
519
520 EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, false);
521
522 if ((addr + cnts) > mapLen)
523 return _FAIL;
524
525 Efuse_PowerSwitch(padapter, false, true);
526
527 efuse_ReadEFuse(padapter, EFUSE_BT, addr, cnts, data, false);
528
529 Efuse_PowerSwitch(padapter, false, false);
530
531 return _SUCCESS;
532 }
533 /* */
534 u8 rtw_efuse_map_write(struct adapter *padapter, u16 addr, u16 cnts, u8 *data)
535 {
536 u8 offset, word_en;
537 u8 *map;
538 u8 newdata[PGPKT_DATA_SIZE + 1];
539 s32 i, idx;
540 u8 ret = _SUCCESS;
541 u16 mapLen = 0;
542
543 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, false);
544
545 if ((addr + cnts) > mapLen)
546 return _FAIL;
547
548 map = rtw_zmalloc(mapLen);
549 if (map == NULL)
550 return _FAIL;
551
552 ret = rtw_efuse_map_read(padapter, 0, mapLen, map);
553 if (ret == _FAIL)
554 goto exit;
555
556 Efuse_PowerSwitch(padapter, true, true);
557
558 offset = (addr >> 3);
559 word_en = 0xF;
560 _rtw_memset(newdata, 0xFF, PGPKT_DATA_SIZE + 1);
561 i = addr & 0x7; /* index of one package */
562 idx = 0; /* data index */
563
564 if (i & 0x1) {
565 /* odd start */
566 if (data[idx] != map[addr+idx]) {
567 word_en &= ~BIT(i >> 1);
568 newdata[i-1] = map[addr+idx-1];
569 newdata[i] = data[idx];
570 }
571 i++;
572 idx++;
573 }
574 do {
575 for (; i < PGPKT_DATA_SIZE; i += 2) {
576 if (cnts == idx)
577 break;
578 if ((cnts - idx) == 1) {
579 if (data[idx] != map[addr+idx]) {
580 word_en &= ~BIT(i >> 1);
581 newdata[i] = data[idx];
582 newdata[i+1] = map[addr+idx+1];
583 }
584 idx++;
585 break;
586 } else {
587 if ((data[idx] != map[addr+idx]) ||
588 (data[idx+1] != map[addr+idx+1])) {
589 word_en &= ~BIT(i >> 1);
590 newdata[i] = data[idx];
591 newdata[i+1] = data[idx + 1];
592 }
593 idx += 2;
594 }
595 if (idx == cnts)
596 break;
597 }
598
599 if (word_en != 0xF) {
600 ret = Efuse_PgPacketWrite(padapter, offset, word_en, newdata, false);
601 DBG_88E("offset=%x\n", offset);
602 DBG_88E("word_en=%x\n", word_en);
603
604 for (i = 0; i < PGPKT_DATA_SIZE; i++)
605 DBG_88E("data=%x \t", newdata[i]);
606 if (ret == _FAIL)
607 break;
608 }
609
610 if (idx == cnts)
611 break;
612
613 offset++;
614 i = 0;
615 word_en = 0xF;
616 _rtw_memset(newdata, 0xFF, PGPKT_DATA_SIZE);
617 } while (1);
618
619 Efuse_PowerSwitch(padapter, true, false);
620 exit:
621 kfree(map);
622 return ret;
623 }
624
625 /* */
626 u8 rtw_BT_efuse_map_write(struct adapter *padapter, u16 addr, u16 cnts, u8 *data)
627 {
628 u8 offset, word_en;
629 u8 *map;
630 u8 newdata[PGPKT_DATA_SIZE + 1];
631 s32 i, idx;
632 u8 ret = _SUCCESS;
633 u16 mapLen = 0;
634
635 EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, false);
636
637 if ((addr + cnts) > mapLen)
638 return _FAIL;
639
640 map = rtw_zmalloc(mapLen);
641 if (map == NULL)
642 return _FAIL;
643
644 ret = rtw_BT_efuse_map_read(padapter, 0, mapLen, map);
645 if (ret == _FAIL)
646 goto exit;
647
648 Efuse_PowerSwitch(padapter, true, true);
649
650 offset = (addr >> 3);
651 word_en = 0xF;
652 _rtw_memset(newdata, 0xFF, PGPKT_DATA_SIZE + 1);
653 i = addr & 0x7; /* index of one package */
654 idx = 0; /* data index */
655
656 if (i & 0x1) {
657 /* odd start */
658 if (data[idx] != map[addr+idx]) {
659 word_en &= ~BIT(i >> 1);
660 newdata[i-1] = map[addr+idx-1];
661 newdata[i] = data[idx];
662 }
663 i++;
664 idx++;
665 }
666 do {
667 for (; i < PGPKT_DATA_SIZE; i += 2) {
668 if (cnts == idx)
669 break;
670 if ((cnts - idx) == 1) {
671 if (data[idx] != map[addr+idx]) {
672 word_en &= ~BIT(i >> 1);
673 newdata[i] = data[idx];
674 newdata[i+1] = map[addr+idx+1];
675 }
676 idx++;
677 break;
678 } else {
679 if ((data[idx] != map[addr+idx]) ||
680 (data[idx+1] != map[addr+idx+1])) {
681 word_en &= ~BIT(i >> 1);
682 newdata[i] = data[idx];
683 newdata[i+1] = data[idx + 1];
684 }
685 idx += 2;
686 }
687 if (idx == cnts)
688 break;
689 }
690
691 if (word_en != 0xF) {
692 DBG_88E("%s: offset=%#X\n", __func__, offset);
693 DBG_88E("%s: word_en=%#X\n", __func__, word_en);
694 DBG_88E("%s: data=", __func__);
695 for (i = 0; i < PGPKT_DATA_SIZE; i++)
696 DBG_88E("0x%02X ", newdata[i]);
697 DBG_88E("\n");
698
699 ret = Efuse_PgPacketWrite_BT(padapter, offset, word_en, newdata, false);
700 if (ret == _FAIL)
701 break;
702 }
703
704 if (idx == cnts)
705 break;
706
707 offset++;
708 i = 0;
709 word_en = 0xF;
710 _rtw_memset(newdata, 0xFF, PGPKT_DATA_SIZE);
711 } while (1);
712
713 Efuse_PowerSwitch(padapter, true, false);
714
715 exit:
716
717 kfree(map);
718
719 return ret;
720 }
721
722 /*-----------------------------------------------------------------------------
723 * Function: efuse_ShadowRead1Byte
724 * efuse_ShadowRead2Byte
725 * efuse_ShadowRead4Byte
726 *
727 * Overview: Read from efuse init map by one/two/four bytes !!!!!
728 *
729 * Input: NONE
730 *
731 * Output: NONE
732 *
733 * Return: NONE
734 *
735 * Revised History:
736 * When Who Remark
737 * 11/12/2008 MHC Create Version 0.
738 *
739 *---------------------------------------------------------------------------*/
740 static void
741 efuse_ShadowRead1Byte(
742 struct adapter *pAdapter,
743 u16 Offset,
744 u8 *Value)
745 {
746 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
747
748 *Value = pEEPROM->efuse_eeprom_data[Offset];
749
750 } /* EFUSE_ShadowRead1Byte */
751
752 /* Read Two Bytes */
753 static void
754 efuse_ShadowRead2Byte(
755 struct adapter *pAdapter,
756 u16 Offset,
757 u16 *Value)
758 {
759 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
760
761 *Value = pEEPROM->efuse_eeprom_data[Offset];
762 *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
763
764 } /* EFUSE_ShadowRead2Byte */
765
766 /* Read Four Bytes */
767 static void
768 efuse_ShadowRead4Byte(
769 struct adapter *pAdapter,
770 u16 Offset,
771 u32 *Value)
772 {
773 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
774
775 *Value = pEEPROM->efuse_eeprom_data[Offset];
776 *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
777 *Value |= pEEPROM->efuse_eeprom_data[Offset+2]<<16;
778 *Value |= pEEPROM->efuse_eeprom_data[Offset+3]<<24;
779
780 } /* efuse_ShadowRead4Byte */
781
782 /*-----------------------------------------------------------------------------
783 * Function: Efuse_ReadAllMap
784 *
785 * Overview: Read All Efuse content
786 *
787 * Input: NONE
788 *
789 * Output: NONE
790 *
791 * Return: NONE
792 *
793 * Revised History:
794 * When Who Remark
795 * 11/11/2008 MHC Create Version 0.
796 *
797 *---------------------------------------------------------------------------*/
798 static void Efuse_ReadAllMap(struct adapter *pAdapter, u8 efuseType, u8 *Efuse, bool pseudo)
799 {
800 u16 mapLen = 0;
801
802 Efuse_PowerSwitch(pAdapter, false, true);
803
804 EFUSE_GetEfuseDefinition(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, pseudo);
805
806 efuse_ReadEFuse(pAdapter, efuseType, 0, mapLen, Efuse, pseudo);
807
808 Efuse_PowerSwitch(pAdapter, false, false);
809 }
810
811 /*-----------------------------------------------------------------------------
812 * Function: EFUSE_ShadowMapUpdate
813 *
814 * Overview: Transfer current EFUSE content to shadow init and modify map.
815 *
816 * Input: NONE
817 *
818 * Output: NONE
819 *
820 * Return: NONE
821 *
822 * Revised History:
823 * When Who Remark
824 * 11/13/2008 MHC Create Version 0.
825 *
826 *---------------------------------------------------------------------------*/
827 void EFUSE_ShadowMapUpdate(
828 struct adapter *pAdapter,
829 u8 efuseType,
830 bool pseudo)
831 {
832 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
833 u16 mapLen = 0;
834
835 EFUSE_GetEfuseDefinition(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, pseudo);
836
837 if (pEEPROM->bautoload_fail_flag)
838 _rtw_memset(pEEPROM->efuse_eeprom_data, 0xFF, mapLen);
839 else
840 Efuse_ReadAllMap(pAdapter, efuseType, pEEPROM->efuse_eeprom_data, pseudo);
841 } /* EFUSE_ShadowMapUpdate */
842
843 /*-----------------------------------------------------------------------------
844 * Function: EFUSE_ShadowRead
845 *
846 * Overview: Read from efuse init map !!!!!
847 *
848 * Input: NONE
849 *
850 * Output: NONE
851 *
852 * Return: NONE
853 *
854 * Revised History:
855 * When Who Remark
856 * 11/12/2008 MHC Create Version 0.
857 *
858 *---------------------------------------------------------------------------*/
859 void EFUSE_ShadowRead(struct adapter *pAdapter, u8 Type, u16 Offset, u32 *Value)
860 {
861 if (Type == 1)
862 efuse_ShadowRead1Byte(pAdapter, Offset, (u8 *)Value);
863 else if (Type == 2)
864 efuse_ShadowRead2Byte(pAdapter, Offset, (u16 *)Value);
865 else if (Type == 4)
866 efuse_ShadowRead4Byte(pAdapter, Offset, (u32 *)Value);
867
868 } /* EFUSE_ShadowRead */
This page took 0.050325 seconds and 6 git commands to generate.