Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / staging / rtl8723au / 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  ******************************************************************************/
15 #define _RTW_EFUSE_C_
16
17 #include <osdep_service.h>
18 #include <drv_types.h>
19
20 #include <rtw_efuse.h>
21 #include <rtl8723a_hal.h>
22 #include <usb_ops_linux.h>
23
24 /*------------------------Define local variable------------------------------*/
25
26 /*  */
27 #define REG_EFUSE_CTRL          0x0030
28 #define EFUSE_CTRL                      REG_EFUSE_CTRL          /*  E-Fuse Control. */
29 /*  */
30
31 #define VOLTAGE_V25             0x03
32 #define LDOE25_SHIFT            28
33
34 /*-----------------------------------------------------------------------------
35  * Function:    Efuse_PowerSwitch
36  *
37  * Overview:    When we want to enable write operation, we should change to
38  *                              pwr on state. When we stop write, we should switch to 500k mode
39  *                              and disable LDO 2.5V.
40  *
41  * Input:       NONE
42  *
43  * Output:      NONE
44  *
45  * Return:      NONE
46  *
47  * Revised History:
48  * When                 Who             Remark
49  * 11/17/2008   MHC             Create Version 0.
50  *
51  *---------------------------------------------------------------------------*/
52 static void Efuse_PowerSwitch(struct rtw_adapter *padapter,
53                               u8 bWrite, u8 PwrState)
54 {
55         u8 tempval;
56         u16 tmpV16;
57
58         if (PwrState == true) {
59                 rtl8723au_write8(padapter, REG_EFUSE_ACCESS, EFUSE_ACCESS_ON);
60
61                 /*  1.2V Power: From VDDON with Power
62                     Cut(0x0000h[15]), default valid */
63                 tmpV16 = rtl8723au_read16(padapter, REG_SYS_ISO_CTRL);
64                 if (!(tmpV16 & PWC_EV12V)) {
65                         tmpV16 |= PWC_EV12V;
66                         rtl8723au_write16(padapter, REG_SYS_ISO_CTRL, tmpV16);
67                 }
68                 /*  Reset: 0x0000h[28], default valid */
69                 tmpV16 = rtl8723au_read16(padapter, REG_SYS_FUNC_EN);
70                 if (!(tmpV16 & FEN_ELDR)) {
71                         tmpV16 |= FEN_ELDR;
72                         rtl8723au_write16(padapter, REG_SYS_FUNC_EN, tmpV16);
73                 }
74
75                 /*  Clock: Gated(0x0008h[5]) 8M(0x0008h[1]) clock
76                     from ANA, default valid */
77                 tmpV16 = rtl8723au_read16(padapter, REG_SYS_CLKR);
78                 if ((!(tmpV16 & LOADER_CLK_EN)) || (!(tmpV16 & ANA8M))) {
79                         tmpV16 |= (LOADER_CLK_EN | ANA8M);
80                         rtl8723au_write16(padapter, REG_SYS_CLKR, tmpV16);
81                 }
82
83                 if (bWrite == true) {
84                         /*  Enable LDO 2.5V before read/write action */
85                         tempval = rtl8723au_read8(padapter, EFUSE_TEST + 3);
86                         tempval &= 0x0F;
87                         tempval |= (VOLTAGE_V25 << 4);
88                         rtl8723au_write8(padapter, EFUSE_TEST + 3,
89                                          tempval | 0x80);
90                 }
91         } else {
92                 rtl8723au_write8(padapter, REG_EFUSE_ACCESS, EFUSE_ACCESS_OFF);
93
94                 if (bWrite == true) {
95                         /*  Disable LDO 2.5V after read/write action */
96                         tempval = rtl8723au_read8(padapter, EFUSE_TEST + 3);
97                         rtl8723au_write8(padapter, EFUSE_TEST + 3,
98                                          tempval & 0x7F);
99                 }
100         }
101 }
102
103 u16
104 Efuse_GetCurrentSize23a(struct rtw_adapter *pAdapter, u8 efuseType)
105 {
106         u16 ret = 0;
107
108         if (efuseType == EFUSE_WIFI)
109                 ret = rtl8723a_EfuseGetCurrentSize_WiFi(pAdapter);
110         else
111                 ret = rtl8723a_EfuseGetCurrentSize_BT(pAdapter);
112
113         return ret;
114 }
115
116 /*  11/16/2008 MH Add description. Get current efuse area enabled word!!. */
117 u8
118 Efuse_CalculateWordCnts23a(u8 word_en)
119 {
120         return hweight8((~word_en) & 0xf);
121 }
122
123 /*  */
124 /*      Description: */
125 /*              Execute E-Fuse read byte operation. */
126 /*              Referred from SD1 Richard. */
127 /*  */
128 /*      Assumption: */
129 /*              1. Boot from E-Fuse and successfully auto-load. */
130 /*              2. PASSIVE_LEVEL (USB interface) */
131 /*  */
132 /*      Created by Roger, 2008.10.21. */
133 /*  */
134 void
135 ReadEFuseByte23a(struct rtw_adapter *Adapter, u16 _offset, u8 *pbuf)
136 {
137         u32     value32;
138         u8      readbyte;
139         u16     retry;
140
141         /* Write Address */
142         rtl8723au_write8(Adapter, EFUSE_CTRL+1, (_offset & 0xff));
143         readbyte = rtl8723au_read8(Adapter, EFUSE_CTRL+2);
144         rtl8723au_write8(Adapter, EFUSE_CTRL+2,
145                          ((_offset >> 8) & 0x03) | (readbyte & 0xfc));
146
147         /* Write bit 32 0 */
148         readbyte = rtl8723au_read8(Adapter, EFUSE_CTRL+3);
149         rtl8723au_write8(Adapter, EFUSE_CTRL+3, readbyte & 0x7f);
150
151         /* Check bit 32 read-ready */
152         retry = 0;
153         value32 = rtl8723au_read32(Adapter, EFUSE_CTRL);
154         while (!((value32 >> 24) & 0x80) && retry < 10000) {
155                 value32 = rtl8723au_read32(Adapter, EFUSE_CTRL);
156                 retry++;
157         }
158
159         /*  20100205 Joseph: Add delay suggested by SD1 Victor. */
160         /*  This fix the problem that Efuse read error in high temperature condition. */
161         /*  Designer says that there shall be some delay after ready bit is set, or the */
162         /*  result will always stay on last data we read. */
163         udelay(50);
164         value32 = rtl8723au_read32(Adapter, EFUSE_CTRL);
165
166         *pbuf = (u8)(value32 & 0xff);
167 }
168
169 void
170 EFUSE_GetEfuseDefinition23a(struct rtw_adapter *pAdapter, u8 efuseType,
171                             u8 type, void *pOut)
172 {
173         u8 *pu1Tmp;
174         u16 *pu2Tmp;
175         u8 *pMax_section;
176
177         switch (type) {
178         case TYPE_EFUSE_MAX_SECTION:
179                 pMax_section = pOut;
180
181                 if (efuseType == EFUSE_WIFI)
182                         *pMax_section = EFUSE_MAX_SECTION_8723A;
183                 else
184                         *pMax_section = EFUSE_BT_MAX_SECTION;
185                 break;
186
187         case TYPE_EFUSE_REAL_CONTENT_LEN:
188                 pu2Tmp = pOut;
189
190                 if (efuseType == EFUSE_WIFI)
191                         *pu2Tmp = EFUSE_REAL_CONTENT_LEN_8723A;
192                 else
193                         *pu2Tmp = EFUSE_BT_REAL_CONTENT_LEN;
194                 break;
195
196         case TYPE_AVAILABLE_EFUSE_BYTES_BANK:
197                 pu2Tmp = pOut;
198
199                 if (efuseType == EFUSE_WIFI)
200                         *pu2Tmp = (EFUSE_REAL_CONTENT_LEN_8723A -
201                                    EFUSE_OOB_PROTECT_BYTES);
202                 else
203                         *pu2Tmp = (EFUSE_BT_REAL_BANK_CONTENT_LEN -
204                                    EFUSE_PROTECT_BYTES_BANK);
205                 break;
206
207         case TYPE_AVAILABLE_EFUSE_BYTES_TOTAL:
208                 pu2Tmp = pOut;
209
210                 if (efuseType == EFUSE_WIFI)
211                         *pu2Tmp = (EFUSE_REAL_CONTENT_LEN_8723A -
212                                    EFUSE_OOB_PROTECT_BYTES);
213                 else
214                         *pu2Tmp = (EFUSE_BT_REAL_CONTENT_LEN -
215                                    (EFUSE_PROTECT_BYTES_BANK * 3));
216                 break;
217
218         case TYPE_EFUSE_MAP_LEN:
219                 pu2Tmp = pOut;
220
221                 if (efuseType == EFUSE_WIFI)
222                         *pu2Tmp = EFUSE_MAP_LEN_8723A;
223                 else
224                         *pu2Tmp = EFUSE_BT_MAP_LEN;
225                 break;
226
227         case TYPE_EFUSE_PROTECT_BYTES_BANK:
228                 pu1Tmp = pOut;
229
230                 if (efuseType == EFUSE_WIFI)
231                         *pu1Tmp = EFUSE_OOB_PROTECT_BYTES;
232                 else
233                         *pu1Tmp = EFUSE_PROTECT_BYTES_BANK;
234                 break;
235
236         case TYPE_EFUSE_CONTENT_LEN_BANK:
237                 pu2Tmp = pOut;
238
239                 if (efuseType == EFUSE_WIFI)
240                         *pu2Tmp = EFUSE_REAL_CONTENT_LEN_8723A;
241                 else
242                         *pu2Tmp = EFUSE_BT_REAL_BANK_CONTENT_LEN;
243                 break;
244
245         default:
246                 pu1Tmp = pOut;
247                 *pu1Tmp = 0;
248                 break;
249         }
250 }
251
252 /*-----------------------------------------------------------------------------
253  * Function:    EFUSE_Read1Byte23a
254  *
255  * Overview:    Copy from WMAC fot EFUSE read 1 byte.
256  *
257  * Input:       NONE
258  *
259  * Output:      NONE
260  *
261  * Return:      NONE
262  *
263  * Revised History:
264  * When                 Who             Remark
265  * 09/23/2008   MHC             Copy from WMAC.
266  *
267  *---------------------------------------------------------------------------*/
268 u8
269 EFUSE_Read1Byte23a(struct rtw_adapter *Adapter, u16 Address)
270 {
271         u8      data;
272         u8      Bytetemp = {0x00};
273         u8      temp = {0x00};
274         u32     k = 0;
275         u16     contentLen = 0;
276
277         EFUSE_GetEfuseDefinition23a(Adapter, EFUSE_WIFI,
278                                  TYPE_EFUSE_REAL_CONTENT_LEN,
279                                  (void *)&contentLen);
280
281         if (Address < contentLen) { /* E-fuse 512Byte */
282                 /* Write E-fuse Register address bit0~7 */
283                 temp = Address & 0xFF;
284                 rtl8723au_write8(Adapter, EFUSE_CTRL+1, temp);
285                 Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+2);
286                 /* Write E-fuse Register address bit8~9 */
287                 temp = ((Address >> 8) & 0x03) | (Bytetemp & 0xFC);
288                 rtl8723au_write8(Adapter, EFUSE_CTRL+2, temp);
289
290                 /* Write 0x30[31]= 0 */
291                 Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3);
292                 temp = Bytetemp & 0x7F;
293                 rtl8723au_write8(Adapter, EFUSE_CTRL+3, temp);
294
295                 /* Wait Write-ready (0x30[31]= 1) */
296                 Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3);
297                 while (!(Bytetemp & 0x80)) {
298                         Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3);
299                         k++;
300                         if (k == 1000) {
301                                 k = 0;
302                                 break;
303                         }
304                 }
305                 data = rtl8723au_read8(Adapter, EFUSE_CTRL);
306                 return data;
307         } else
308                 return 0xFF;
309 }/* EFUSE_Read1Byte23a */
310
311 /*-----------------------------------------------------------------------------
312  * Function:    EFUSE_Write1Byte
313  *
314  * Overview:    Copy from WMAC fot EFUSE write 1 byte.
315  *
316  * Input:       NONE
317  *
318  * Output:      NONE
319  *
320  * Return:      NONE
321  *
322  * Revised History:
323  * When                 Who             Remark
324  * 09/23/2008   MHC             Copy from WMAC.
325  *
326  *---------------------------------------------------------------------------*/
327
328 void
329 EFUSE_Write1Byte(struct rtw_adapter *Adapter, u16 Address, u8 Value);
330 void
331 EFUSE_Write1Byte(struct rtw_adapter *Adapter, u16 Address, u8 Value)
332 {
333         u8      Bytetemp = {0x00};
334         u8      temp = {0x00};
335         u32     k = 0;
336         u16     contentLen = 0;
337
338         EFUSE_GetEfuseDefinition23a(Adapter, EFUSE_WIFI,
339                                  TYPE_EFUSE_REAL_CONTENT_LEN,
340                                  (void *)&contentLen);
341
342         if (Address < contentLen) { /* E-fuse 512Byte */
343                 rtl8723au_write8(Adapter, EFUSE_CTRL, Value);
344
345                 /* Write E-fuse Register address bit0~7 */
346                 temp = Address & 0xFF;
347                 rtl8723au_write8(Adapter, EFUSE_CTRL+1, temp);
348                 Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+2);
349
350                 /* Write E-fuse Register address bit8~9 */
351                 temp = ((Address >> 8) & 0x03) | (Bytetemp & 0xFC);
352                 rtl8723au_write8(Adapter, EFUSE_CTRL+2, temp);
353
354                 /* Write 0x30[31]= 1 */
355                 Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3);
356                 temp = Bytetemp | 0x80;
357                 rtl8723au_write8(Adapter, EFUSE_CTRL+3, temp);
358
359                 /* Wait Write-ready (0x30[31]= 0) */
360                 Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3);
361                 while (Bytetemp & 0x80) {
362                         Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3);
363                         k++;
364                         if (k == 100) {
365                                 k = 0;
366                                 break;
367                         }
368                 }
369         }
370 }/* EFUSE_Write1Byte */
371
372 /*  11/16/2008 MH Read one byte from real Efuse. */
373 int
374 efuse_OneByteRead23a(struct rtw_adapter *pAdapter, u16 addr, u8 *data)
375 {
376         u8      tmpidx = 0;
377         int     bResult;
378
379         /*  -----------------e-fuse reg ctrl --------------------------------- */
380         /* address */
381         rtl8723au_write8(pAdapter, EFUSE_CTRL+1, (u8)(addr&0xff));
382         rtl8723au_write8(pAdapter, EFUSE_CTRL+2, ((u8)((addr>>8) &0x03)) |
383         (rtl8723au_read8(pAdapter, EFUSE_CTRL+2)&0xFC));
384
385         rtl8723au_write8(pAdapter, EFUSE_CTRL+3,  0x72);/* read cmd */
386
387         while(!(0x80 &rtl8723au_read8(pAdapter, EFUSE_CTRL+3)) && (tmpidx<100))
388                 tmpidx++;
389         if (tmpidx < 100) {
390                 *data = rtl8723au_read8(pAdapter, EFUSE_CTRL);
391                 bResult = _SUCCESS;
392         } else {
393                 *data = 0xff;
394                 bResult = _FAIL;
395         }
396         return bResult;
397 }
398
399 /*  11/16/2008 MH Write one byte to reald Efuse. */
400 int
401 efuse_OneByteWrite23a(struct rtw_adapter *pAdapter, u16 addr, u8 data)
402 {
403         u8      tmpidx = 0;
404         int     bResult;
405
406         /* return       0; */
407
408         /*  -----------------e-fuse reg ctrl --------------------------------- */
409         /* address */
410         rtl8723au_write8(pAdapter, EFUSE_CTRL+1, (u8)(addr&0xff));
411         rtl8723au_write8(pAdapter, EFUSE_CTRL+2,
412         (rtl8723au_read8(pAdapter, EFUSE_CTRL+2)&0xFC)|(u8)((addr>>8)&0x03));
413         rtl8723au_write8(pAdapter, EFUSE_CTRL, data);/* data */
414
415         rtl8723au_write8(pAdapter, EFUSE_CTRL+3, 0xF2);/* write cmd */
416
417         while((0x80 & rtl8723au_read8(pAdapter, EFUSE_CTRL+3)) &&
418               (tmpidx<100)) {
419                 tmpidx++;
420         }
421
422         if (tmpidx < 100)
423                 bResult = _SUCCESS;
424         else
425                 bResult = _FAIL;
426
427         return bResult;
428 }
429
430 /*-----------------------------------------------------------------------------
431  * Function:    efuse_WordEnableDataRead23a
432  *
433  * Overview:    Read allowed word in current efuse section data.
434  *
435  * Input:       NONE
436  *
437  * Output:      NONE
438  *
439  * Return:      NONE
440  *
441  * Revised History:
442  * When                 Who             Remark
443  * 11/16/2008   MHC             Create Version 0.
444  * 11/21/2008   MHC             Fix Write bug when we only enable late word.
445  *
446  *---------------------------------------------------------------------------*/
447 void
448 efuse_WordEnableDataRead23a(u8  word_en,
449                          u8     *sourdata,
450                          u8     *targetdata)
451 {
452         if (!(word_en&BIT(0))) {
453                 targetdata[0] = sourdata[0];
454                 targetdata[1] = sourdata[1];
455         }
456         if (!(word_en&BIT(1))) {
457                 targetdata[2] = sourdata[2];
458                 targetdata[3] = sourdata[3];
459         }
460         if (!(word_en&BIT(2))) {
461                 targetdata[4] = sourdata[4];
462                 targetdata[5] = sourdata[5];
463         }
464         if (!(word_en&BIT(3))) {
465                 targetdata[6] = sourdata[6];
466                 targetdata[7] = sourdata[7];
467         }
468 }
469
470 static int efuse_read8(struct rtw_adapter *padapter, u16 address, u8 *value)
471 {
472         return efuse_OneByteRead23a(padapter, address, value);
473 }
474
475 static int efuse_write8(struct rtw_adapter *padapter, u16 address, u8 *value)
476 {
477         return efuse_OneByteWrite23a(padapter, address, *value);
478 }
479
480 /*
481  * read/write raw efuse data
482  */
483 int rtw_efuse_access23a(struct rtw_adapter *padapter, u8 bWrite, u16 start_addr,
484                         u16 cnts, u8 *data)
485 {
486         int i = 0;
487         u16 real_content_len = 0, max_available_size = 0;
488         int res = _FAIL ;
489         int (*rw8)(struct rtw_adapter *, u16, u8*);
490
491         EFUSE_GetEfuseDefinition23a(padapter, EFUSE_WIFI,
492                                  TYPE_EFUSE_REAL_CONTENT_LEN,
493                                  (void *)&real_content_len);
494         EFUSE_GetEfuseDefinition23a(padapter, EFUSE_WIFI,
495                                  TYPE_AVAILABLE_EFUSE_BYTES_TOTAL,
496                                  (void *)&max_available_size);
497
498         if (start_addr > real_content_len)
499                 return _FAIL;
500
501         if (true == bWrite) {
502                 if ((start_addr + cnts) > max_available_size)
503                         return _FAIL;
504                 rw8 = &efuse_write8;
505         } else
506                 rw8 = &efuse_read8;
507
508         Efuse_PowerSwitch(padapter, bWrite, true);
509
510         /*  e-fuse one byte read / write */
511         for (i = 0; i < cnts; i++) {
512                 if (start_addr >= real_content_len) {
513                         res = _FAIL;
514                         break;
515                 }
516
517                 res = rw8(padapter, start_addr++, data++);
518                 if (res == _FAIL)
519                         break;
520         }
521
522         Efuse_PowerSwitch(padapter, bWrite, false);
523
524         return res;
525 }
526 /*  */
527 u16 efuse_GetMaxSize23a(struct rtw_adapter *padapter)
528 {
529         u16 max_size;
530         EFUSE_GetEfuseDefinition23a(padapter, EFUSE_WIFI,
531                                  TYPE_AVAILABLE_EFUSE_BYTES_TOTAL,
532                                  (void *)&max_size);
533         return max_size;
534 }
535 /*  */
536 int rtw_efuse_map_read23a(struct rtw_adapter *padapter,
537                           u16 addr, u16 cnts, u8 *data)
538 {
539         u16 mapLen = 0;
540
541         EFUSE_GetEfuseDefinition23a(padapter, EFUSE_WIFI,
542                                  TYPE_EFUSE_MAP_LEN, (void *)&mapLen);
543
544         if ((addr + cnts) > mapLen)
545                 return _FAIL;
546
547         Efuse_PowerSwitch(padapter, false, true);
548
549         rtl8723a_readefuse(padapter, EFUSE_WIFI, addr, cnts, data);
550
551         Efuse_PowerSwitch(padapter, false, false);
552
553         return _SUCCESS;
554 }
555
556 int rtw_BT_efuse_map_read23a(struct rtw_adapter *padapter,
557                              u16 addr, u16 cnts, u8 *data)
558 {
559         u16 mapLen = 0;
560
561         EFUSE_GetEfuseDefinition23a(padapter, EFUSE_BT,
562                                  TYPE_EFUSE_MAP_LEN, (void *)&mapLen);
563
564         if ((addr + cnts) > mapLen)
565                 return _FAIL;
566
567         Efuse_PowerSwitch(padapter, false, true);
568
569         rtl8723a_readefuse(padapter, EFUSE_BT, addr, cnts, data);
570
571         Efuse_PowerSwitch(padapter, false, false);
572
573         return _SUCCESS;
574 }
575
576 /*-----------------------------------------------------------------------------
577  * Function:    Efuse_ReadAllMap
578  *
579  * Overview:    Read All Efuse content
580  *
581  * Input:       NONE
582  *
583  * Output:      NONE
584  *
585  * Return:      NONE
586  *
587  * Revised History:
588  * When                 Who             Remark
589  * 11/11/2008   MHC             Create Version 0.
590  *
591  *---------------------------------------------------------------------------*/
592 void
593 Efuse_ReadAllMap(struct rtw_adapter *pAdapter, u8 efuseType, u8 *Efuse);
594 void
595 Efuse_ReadAllMap(struct rtw_adapter *pAdapter, u8 efuseType, u8 *Efuse)
596 {
597         u16     mapLen = 0;
598
599         Efuse_PowerSwitch(pAdapter, false, true);
600
601         EFUSE_GetEfuseDefinition23a(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN,
602                                  (void *)&mapLen);
603
604         rtl8723a_readefuse(pAdapter, efuseType, 0, mapLen, Efuse);
605
606         Efuse_PowerSwitch(pAdapter, false, false);
607 }
608
609 /*-----------------------------------------------------------------------------
610  * Function:    efuse_ShadowRead1Byte
611  *                      efuse_ShadowRead2Byte
612  *                      efuse_ShadowRead4Byte
613  *
614  * Overview:    Read from efuse init map by one/two/four bytes !!!!!
615  *
616  * Input:       NONE
617  *
618  * Output:      NONE
619  *
620  * Return:      NONE
621  *
622  * Revised History:
623  * When                 Who             Remark
624  * 11/12/2008   MHC             Create Version 0.
625  *
626  *---------------------------------------------------------------------------*/
627 static void
628 efuse_ShadowRead1Byte(struct rtw_adapter *pAdapter, u16 Offset, u8 *Value)
629 {
630         struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
631
632         *Value = pEEPROM->efuse_eeprom_data[Offset];
633 }       /*  EFUSE_ShadowRead23a1Byte */
634
635 /* Read Two Bytes */
636 static void
637 efuse_ShadowRead2Byte(struct rtw_adapter *pAdapter, u16 Offset, u16 *Value)
638 {
639         struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
640
641         *Value = pEEPROM->efuse_eeprom_data[Offset];
642         *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
643 }       /*  EFUSE_ShadowRead23a2Byte */
644
645 /* Read Four Bytes */
646 static void
647 efuse_ShadowRead4Byte(struct rtw_adapter *pAdapter, u16 Offset, u32 *Value)
648 {
649         struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
650
651         *Value = pEEPROM->efuse_eeprom_data[Offset];
652         *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
653         *Value |= pEEPROM->efuse_eeprom_data[Offset+2]<<16;
654         *Value |= pEEPROM->efuse_eeprom_data[Offset+3]<<24;
655 }       /*  efuse_ShadowRead4Byte */
656
657 /*-----------------------------------------------------------------------------
658  * Function:    EFUSE_ShadowMapUpdate23a
659  *
660  * Overview:    Transfer current EFUSE content to shadow init and modify map.
661  *
662  * Input:       NONE
663  *
664  * Output:      NONE
665  *
666  * Return:      NONE
667  *
668  * Revised History:
669  * When                 Who             Remark
670  * 11/13/2008   MHC             Create Version 0.
671  *
672  *---------------------------------------------------------------------------*/
673 void EFUSE_ShadowMapUpdate23a(struct rtw_adapter *pAdapter, u8 efuseType)
674 {
675         struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
676         u16     mapLen = 0;
677
678         EFUSE_GetEfuseDefinition23a(pAdapter, efuseType,
679                                  TYPE_EFUSE_MAP_LEN, (void *)&mapLen);
680
681         if (pEEPROM->bautoload_fail_flag == true)
682                 memset(pEEPROM->efuse_eeprom_data, 0xFF, mapLen);
683         else
684                 Efuse_ReadAllMap(pAdapter, efuseType,
685                                  pEEPROM->efuse_eeprom_data);
686
687 }/*  EFUSE_ShadowMapUpdate23a */
688
689 /*-----------------------------------------------------------------------------
690  * Function:    EFUSE_ShadowRead23a
691  *
692  * Overview:    Read from efuse init map !!!!!
693  *
694  * Input:       NONE
695  *
696  * Output:      NONE
697  *
698  * Return:      NONE
699  *
700  * Revised History:
701  * When                 Who             Remark
702  * 11/12/2008   MHC             Create Version 0.
703  *
704  *---------------------------------------------------------------------------*/
705 void
706 EFUSE_ShadowRead23a(struct rtw_adapter *pAdapter,
707                     u8 Type, u16 Offset, u32 *Value)
708 {
709         if (Type == 1)
710                 efuse_ShadowRead1Byte(pAdapter, Offset, (u8 *)Value);
711         else if (Type == 2)
712                 efuse_ShadowRead2Byte(pAdapter, Offset, (u16 *)Value);
713         else if (Type == 4)
714                 efuse_ShadowRead4Byte(pAdapter, Offset, (u32 *)Value);
715 }       /*  EFUSE_ShadowRead23a */