Merge tag 'for-v3.17' of git://git.infradead.org/battery-2.6
[cascardo/linux.git] / 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         u8 word_cnts = 0;
121         if (!(word_en & BIT(0)))        word_cnts++; /*  0 : write enable */
122         if (!(word_en & BIT(1)))        word_cnts++;
123         if (!(word_en & BIT(2)))        word_cnts++;
124         if (!(word_en & BIT(3)))        word_cnts++;
125         return word_cnts;
126 }
127
128 /*  */
129 /*      Description: */
130 /*              Execute E-Fuse read byte operation. */
131 /*              Referred from SD1 Richard. */
132 /*  */
133 /*      Assumption: */
134 /*              1. Boot from E-Fuse and successfully auto-load. */
135 /*              2. PASSIVE_LEVEL (USB interface) */
136 /*  */
137 /*      Created by Roger, 2008.10.21. */
138 /*  */
139 void
140 ReadEFuseByte23a(struct rtw_adapter *Adapter, u16 _offset, u8 *pbuf)
141 {
142         u32     value32;
143         u8      readbyte;
144         u16     retry;
145
146         /* Write Address */
147         rtl8723au_write8(Adapter, EFUSE_CTRL+1, (_offset & 0xff));
148         readbyte = rtl8723au_read8(Adapter, EFUSE_CTRL+2);
149         rtl8723au_write8(Adapter, EFUSE_CTRL+2,
150                          ((_offset >> 8) & 0x03) | (readbyte & 0xfc));
151
152         /* Write bit 32 0 */
153         readbyte = rtl8723au_read8(Adapter, EFUSE_CTRL+3);
154         rtl8723au_write8(Adapter, EFUSE_CTRL+3, readbyte & 0x7f);
155
156         /* Check bit 32 read-ready */
157         retry = 0;
158         value32 = rtl8723au_read32(Adapter, EFUSE_CTRL);
159         /* while(!(((value32 >> 24) & 0xff) & 0x80)  && (retry<10)) */
160         while(!(((value32 >> 24) & 0xff) & 0x80)  && (retry<10000))
161         {
162                 value32 = rtl8723au_read32(Adapter, EFUSE_CTRL);
163                 retry++;
164         }
165
166         /*  20100205 Joseph: Add delay suggested by SD1 Victor. */
167         /*  This fix the problem that Efuse read error in high temperature condition. */
168         /*  Designer says that there shall be some delay after ready bit is set, or the */
169         /*  result will always stay on last data we read. */
170         udelay(50);
171         value32 = rtl8723au_read32(Adapter, EFUSE_CTRL);
172
173         *pbuf = (u8)(value32 & 0xff);
174 }
175
176 void
177 EFUSE_GetEfuseDefinition23a(struct rtw_adapter *pAdapter, u8 efuseType,
178                             u8 type, void *pOut)
179 {
180         u8 *pu1Tmp;
181         u16 *pu2Tmp;
182         u8 *pMax_section;
183
184         switch (type) {
185         case TYPE_EFUSE_MAX_SECTION:
186                 pMax_section = (u8 *) pOut;
187
188                 if (efuseType == EFUSE_WIFI)
189                         *pMax_section = EFUSE_MAX_SECTION_8723A;
190                 else
191                         *pMax_section = EFUSE_BT_MAX_SECTION;
192                 break;
193
194         case TYPE_EFUSE_REAL_CONTENT_LEN:
195                 pu2Tmp = (u16 *) pOut;
196
197                 if (efuseType == EFUSE_WIFI)
198                         *pu2Tmp = EFUSE_REAL_CONTENT_LEN_8723A;
199                 else
200                         *pu2Tmp = EFUSE_BT_REAL_CONTENT_LEN;
201                 break;
202
203         case TYPE_AVAILABLE_EFUSE_BYTES_BANK:
204                 pu2Tmp = (u16 *) pOut;
205
206                 if (efuseType == EFUSE_WIFI)
207                         *pu2Tmp = (EFUSE_REAL_CONTENT_LEN_8723A -
208                                    EFUSE_OOB_PROTECT_BYTES);
209                 else
210                         *pu2Tmp = (EFUSE_BT_REAL_BANK_CONTENT_LEN -
211                                    EFUSE_PROTECT_BYTES_BANK);
212                 break;
213
214         case TYPE_AVAILABLE_EFUSE_BYTES_TOTAL:
215                 pu2Tmp = (u16 *) pOut;
216
217                 if (efuseType == EFUSE_WIFI)
218                         *pu2Tmp = (EFUSE_REAL_CONTENT_LEN_8723A -
219                                    EFUSE_OOB_PROTECT_BYTES);
220                 else
221                         *pu2Tmp = (EFUSE_BT_REAL_CONTENT_LEN -
222                                    (EFUSE_PROTECT_BYTES_BANK * 3));
223                 break;
224
225         case TYPE_EFUSE_MAP_LEN:
226                 pu2Tmp = (u16 *) pOut;
227
228                 if (efuseType == EFUSE_WIFI)
229                         *pu2Tmp = EFUSE_MAP_LEN_8723A;
230                 else
231                         *pu2Tmp = EFUSE_BT_MAP_LEN;
232                 break;
233
234         case TYPE_EFUSE_PROTECT_BYTES_BANK:
235                 pu1Tmp = (u8 *) pOut;
236
237                 if (efuseType == EFUSE_WIFI)
238                         *pu1Tmp = EFUSE_OOB_PROTECT_BYTES;
239                 else
240                         *pu1Tmp = EFUSE_PROTECT_BYTES_BANK;
241                 break;
242
243         case TYPE_EFUSE_CONTENT_LEN_BANK:
244                 pu2Tmp = (u16 *) pOut;
245
246                 if (efuseType == EFUSE_WIFI)
247                         *pu2Tmp = EFUSE_REAL_CONTENT_LEN_8723A;
248                 else
249                         *pu2Tmp = EFUSE_BT_REAL_BANK_CONTENT_LEN;
250                 break;
251
252         default:
253                 pu1Tmp = (u8 *) pOut;
254                 *pu1Tmp = 0;
255                 break;
256         }
257 }
258
259 /*-----------------------------------------------------------------------------
260  * Function:    EFUSE_Read1Byte23a
261  *
262  * Overview:    Copy from WMAC fot EFUSE read 1 byte.
263  *
264  * Input:       NONE
265  *
266  * Output:      NONE
267  *
268  * Return:      NONE
269  *
270  * Revised History:
271  * When                 Who             Remark
272  * 09/23/2008   MHC             Copy from WMAC.
273  *
274  *---------------------------------------------------------------------------*/
275 u8
276 EFUSE_Read1Byte23a(struct rtw_adapter *Adapter, u16 Address)
277 {
278         u8      data;
279         u8      Bytetemp = {0x00};
280         u8      temp = {0x00};
281         u32     k = 0;
282         u16     contentLen = 0;
283
284         EFUSE_GetEfuseDefinition23a(Adapter, EFUSE_WIFI,
285                                  TYPE_EFUSE_REAL_CONTENT_LEN,
286                                  (void *)&contentLen);
287
288         if (Address < contentLen)       /* E-fuse 512Byte */
289         {
290                 /* Write E-fuse Register address bit0~7 */
291                 temp = Address & 0xFF;
292                 rtl8723au_write8(Adapter, EFUSE_CTRL+1, temp);
293                 Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+2);
294                 /* Write E-fuse Register address bit8~9 */
295                 temp = ((Address >> 8) & 0x03) | (Bytetemp & 0xFC);
296                 rtl8723au_write8(Adapter, EFUSE_CTRL+2, temp);
297
298                 /* Write 0x30[31]= 0 */
299                 Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3);
300                 temp = Bytetemp & 0x7F;
301                 rtl8723au_write8(Adapter, EFUSE_CTRL+3, temp);
302
303                 /* Wait Write-ready (0x30[31]= 1) */
304                 Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3);
305                 while(!(Bytetemp & 0x80))
306                 {
307                         Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3);
308                         k++;
309                         if (k == 1000)
310                         {
311                                 k = 0;
312                                 break;
313                         }
314                 }
315                 data = rtl8723au_read8(Adapter, EFUSE_CTRL);
316                 return data;
317         }
318         else
319                 return 0xFF;
320 }/* EFUSE_Read1Byte23a */
321
322 /*-----------------------------------------------------------------------------
323  * Function:    EFUSE_Write1Byte
324  *
325  * Overview:    Copy from WMAC fot EFUSE write 1 byte.
326  *
327  * Input:       NONE
328  *
329  * Output:      NONE
330  *
331  * Return:      NONE
332  *
333  * Revised History:
334  * When                 Who             Remark
335  * 09/23/2008   MHC             Copy from WMAC.
336  *
337  *---------------------------------------------------------------------------*/
338
339 void
340 EFUSE_Write1Byte(
341         struct rtw_adapter *    Adapter,
342         u16             Address,
343         u8              Value);
344 void
345 EFUSE_Write1Byte(
346         struct rtw_adapter *    Adapter,
347         u16             Address,
348         u8              Value)
349 {
350         u8      Bytetemp = {0x00};
351         u8      temp = {0x00};
352         u32     k = 0;
353         u16     contentLen = 0;
354
355         /* RT_TRACE(COMP_EFUSE, DBG_LOUD, ("Addr =%x Data =%x\n", Address, Value)); */
356         EFUSE_GetEfuseDefinition23a(Adapter, EFUSE_WIFI,
357                                  TYPE_EFUSE_REAL_CONTENT_LEN,
358                                  (void *)&contentLen);
359
360         if (Address < contentLen)       /* E-fuse 512Byte */
361         {
362                 rtl8723au_write8(Adapter, EFUSE_CTRL, Value);
363
364                 /* Write E-fuse Register address bit0~7 */
365                 temp = Address & 0xFF;
366                 rtl8723au_write8(Adapter, EFUSE_CTRL+1, temp);
367                 Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+2);
368
369                 /* Write E-fuse Register address bit8~9 */
370                 temp = ((Address >> 8) & 0x03) | (Bytetemp & 0xFC);
371                 rtl8723au_write8(Adapter, EFUSE_CTRL+2, temp);
372
373                 /* Write 0x30[31]= 1 */
374                 Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3);
375                 temp = Bytetemp | 0x80;
376                 rtl8723au_write8(Adapter, EFUSE_CTRL+3, temp);
377
378                 /* Wait Write-ready (0x30[31]= 0) */
379                 Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3);
380                 while(Bytetemp & 0x80)
381                 {
382                         Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3);
383                         k++;
384                         if (k == 100)
385                         {
386                                 k = 0;
387                                 break;
388                         }
389                 }
390         }
391 }/* EFUSE_Write1Byte */
392
393 /*  11/16/2008 MH Read one byte from real Efuse. */
394 int
395 efuse_OneByteRead23a(struct rtw_adapter *pAdapter, u16 addr, u8 *data)
396 {
397         u8      tmpidx = 0;
398         int     bResult;
399
400         /*  -----------------e-fuse reg ctrl --------------------------------- */
401         /* address */
402         rtl8723au_write8(pAdapter, EFUSE_CTRL+1, (u8)(addr&0xff));
403         rtl8723au_write8(pAdapter, EFUSE_CTRL+2, ((u8)((addr>>8) &0x03)) |
404         (rtl8723au_read8(pAdapter, EFUSE_CTRL+2)&0xFC));
405
406         rtl8723au_write8(pAdapter, EFUSE_CTRL+3,  0x72);/* read cmd */
407
408         while(!(0x80 &rtl8723au_read8(pAdapter, EFUSE_CTRL+3)) && (tmpidx<100))
409                 tmpidx++;
410         if (tmpidx < 100) {
411                 *data = rtl8723au_read8(pAdapter, EFUSE_CTRL);
412                 bResult = _SUCCESS;
413         } else {
414                 *data = 0xff;
415                 bResult = _FAIL;
416         }
417         return bResult;
418 }
419
420 /*  11/16/2008 MH Write one byte to reald Efuse. */
421 int
422 efuse_OneByteWrite23a(struct rtw_adapter *pAdapter, u16 addr, u8 data)
423 {
424         u8      tmpidx = 0;
425         int     bResult;
426
427         /* RT_TRACE(COMP_EFUSE, DBG_LOUD, ("Addr = %x Data =%x\n", addr, data)); */
428
429         /* return       0; */
430
431         /*  -----------------e-fuse reg ctrl --------------------------------- */
432         /* address */
433         rtl8723au_write8(pAdapter, EFUSE_CTRL+1, (u8)(addr&0xff));
434         rtl8723au_write8(pAdapter, EFUSE_CTRL+2,
435         (rtl8723au_read8(pAdapter, EFUSE_CTRL+2)&0xFC)|(u8)((addr>>8)&0x03));
436         rtl8723au_write8(pAdapter, EFUSE_CTRL, data);/* data */
437
438         rtl8723au_write8(pAdapter, EFUSE_CTRL+3, 0xF2);/* write cmd */
439
440         while((0x80 & rtl8723au_read8(pAdapter, EFUSE_CTRL+3)) &&
441               (tmpidx<100)) {
442                 tmpidx++;
443         }
444
445         if (tmpidx < 100)
446                 bResult = _SUCCESS;
447         else
448                 bResult = _FAIL;
449
450         return bResult;
451 }
452
453 /*-----------------------------------------------------------------------------
454  * Function:    efuse_WordEnableDataRead23a
455  *
456  * Overview:    Read allowed word in current efuse section data.
457  *
458  * Input:       NONE
459  *
460  * Output:      NONE
461  *
462  * Return:      NONE
463  *
464  * Revised History:
465  * When                 Who             Remark
466  * 11/16/2008   MHC             Create Version 0.
467  * 11/21/2008   MHC             Fix Write bug when we only enable late word.
468  *
469  *---------------------------------------------------------------------------*/
470 void
471 efuse_WordEnableDataRead23a(u8  word_en,
472                          u8     *sourdata,
473                          u8     *targetdata)
474 {
475         if (!(word_en&BIT(0)))
476         {
477                 targetdata[0] = sourdata[0];
478                 targetdata[1] = sourdata[1];
479         }
480         if (!(word_en&BIT(1)))
481         {
482                 targetdata[2] = sourdata[2];
483                 targetdata[3] = sourdata[3];
484         }
485         if (!(word_en&BIT(2)))
486         {
487                 targetdata[4] = sourdata[4];
488                 targetdata[5] = sourdata[5];
489         }
490         if (!(word_en&BIT(3)))
491         {
492                 targetdata[6] = sourdata[6];
493                 targetdata[7] = sourdata[7];
494         }
495 }
496
497 static int efuse_read8(struct rtw_adapter *padapter, u16 address, u8 *value)
498 {
499         return efuse_OneByteRead23a(padapter, address, value);
500 }
501
502 static int efuse_write8(struct rtw_adapter *padapter, u16 address, u8 *value)
503 {
504         return efuse_OneByteWrite23a(padapter, address, *value);
505 }
506
507 /*
508  * read/write raw efuse data
509  */
510 int rtw_efuse_access23a(struct rtw_adapter *padapter, u8 bWrite, u16 start_addr,
511                         u16 cnts, u8 *data)
512 {
513         int i = 0;
514         u16 real_content_len = 0, max_available_size = 0;
515         int res = _FAIL ;
516         int (*rw8)(struct rtw_adapter *, u16, u8*);
517
518         EFUSE_GetEfuseDefinition23a(padapter, EFUSE_WIFI,
519                                  TYPE_EFUSE_REAL_CONTENT_LEN,
520                                  (void *)&real_content_len);
521         EFUSE_GetEfuseDefinition23a(padapter, EFUSE_WIFI,
522                                  TYPE_AVAILABLE_EFUSE_BYTES_TOTAL,
523                                  (void *)&max_available_size);
524
525         if (start_addr > real_content_len)
526                 return _FAIL;
527
528         if (true == bWrite) {
529                 if ((start_addr + cnts) > max_available_size)
530                         return _FAIL;
531                 rw8 = &efuse_write8;
532         } else
533                 rw8 = &efuse_read8;
534
535         Efuse_PowerSwitch(padapter, bWrite, true);
536
537         /*  e-fuse one byte read / write */
538         for (i = 0; i < cnts; i++) {
539                 if (start_addr >= real_content_len) {
540                         res = _FAIL;
541                         break;
542                 }
543
544                 res = rw8(padapter, start_addr++, data++);
545                 if (res == _FAIL)
546                         break;
547         }
548
549         Efuse_PowerSwitch(padapter, bWrite, false);
550
551         return res;
552 }
553 /*  */
554 u16 efuse_GetMaxSize23a(struct rtw_adapter *padapter)
555 {
556         u16 max_size;
557         EFUSE_GetEfuseDefinition23a(padapter, EFUSE_WIFI,
558                                  TYPE_AVAILABLE_EFUSE_BYTES_TOTAL,
559                                  (void *)&max_size);
560         return max_size;
561 }
562 /*  */
563 int rtw_efuse_map_read23a(struct rtw_adapter *padapter,
564                           u16 addr, u16 cnts, u8 *data)
565 {
566         u16 mapLen = 0;
567
568         EFUSE_GetEfuseDefinition23a(padapter, EFUSE_WIFI,
569                                  TYPE_EFUSE_MAP_LEN, (void *)&mapLen);
570
571         if ((addr + cnts) > mapLen)
572                 return _FAIL;
573
574         Efuse_PowerSwitch(padapter, false, true);
575
576         rtl8723a_readefuse(padapter, EFUSE_WIFI, addr, cnts, data);
577
578         Efuse_PowerSwitch(padapter, false, false);
579
580         return _SUCCESS;
581 }
582
583 int rtw_BT_efuse_map_read23a(struct rtw_adapter *padapter,
584                              u16 addr, u16 cnts, u8 *data)
585 {
586         u16 mapLen = 0;
587
588         EFUSE_GetEfuseDefinition23a(padapter, EFUSE_BT,
589                                  TYPE_EFUSE_MAP_LEN, (void *)&mapLen);
590
591         if ((addr + cnts) > mapLen)
592                 return _FAIL;
593
594         Efuse_PowerSwitch(padapter, false, true);
595
596         rtl8723a_readefuse(padapter, EFUSE_BT, addr, cnts, data);
597
598         Efuse_PowerSwitch(padapter, false, false);
599
600         return _SUCCESS;
601 }
602
603 /*-----------------------------------------------------------------------------
604  * Function:    Efuse_ReadAllMap
605  *
606  * Overview:    Read All Efuse content
607  *
608  * Input:       NONE
609  *
610  * Output:      NONE
611  *
612  * Return:      NONE
613  *
614  * Revised History:
615  * When                 Who             Remark
616  * 11/11/2008   MHC             Create Version 0.
617  *
618  *---------------------------------------------------------------------------*/
619 void
620 Efuse_ReadAllMap(struct rtw_adapter *pAdapter, u8 efuseType, u8 *Efuse);
621 void
622 Efuse_ReadAllMap(struct rtw_adapter *pAdapter, u8 efuseType, u8 *Efuse)
623 {
624         u16     mapLen = 0;
625
626         Efuse_PowerSwitch(pAdapter, false, true);
627
628         EFUSE_GetEfuseDefinition23a(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN,
629                                  (void *)&mapLen);
630
631         rtl8723a_readefuse(pAdapter, efuseType, 0, mapLen, Efuse);
632
633         Efuse_PowerSwitch(pAdapter, false, false);
634 }
635
636 /*-----------------------------------------------------------------------------
637  * Function:    efuse_ShadowRead1Byte
638  *                      efuse_ShadowRead2Byte
639  *                      efuse_ShadowRead4Byte
640  *
641  * Overview:    Read from efuse init map by one/two/four bytes !!!!!
642  *
643  * Input:       NONE
644  *
645  * Output:      NONE
646  *
647  * Return:      NONE
648  *
649  * Revised History:
650  * When                 Who             Remark
651  * 11/12/2008   MHC             Create Version 0.
652  *
653  *---------------------------------------------------------------------------*/
654 static void
655 efuse_ShadowRead1Byte(
656         struct rtw_adapter *    pAdapter,
657         u16             Offset,
658         u8              *Value)
659 {
660         struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
661
662         *Value = pEEPROM->efuse_eeprom_data[Offset];
663 }       /*  EFUSE_ShadowRead23a1Byte */
664
665 /* Read Two Bytes */
666 static void
667 efuse_ShadowRead2Byte(
668         struct rtw_adapter *    pAdapter,
669         u16             Offset,
670         u16             *Value)
671 {
672         struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
673
674         *Value = pEEPROM->efuse_eeprom_data[Offset];
675         *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
676 }       /*  EFUSE_ShadowRead23a2Byte */
677
678 /* Read Four Bytes */
679 static void
680 efuse_ShadowRead4Byte(
681         struct rtw_adapter *    pAdapter,
682         u16             Offset,
683         u32             *Value)
684 {
685         struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
686
687         *Value = pEEPROM->efuse_eeprom_data[Offset];
688         *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
689         *Value |= pEEPROM->efuse_eeprom_data[Offset+2]<<16;
690         *Value |= pEEPROM->efuse_eeprom_data[Offset+3]<<24;
691 }       /*  efuse_ShadowRead4Byte */
692
693 /*-----------------------------------------------------------------------------
694  * Function:    EFUSE_ShadowMapUpdate23a
695  *
696  * Overview:    Transfer current EFUSE content to shadow init and modify map.
697  *
698  * Input:       NONE
699  *
700  * Output:      NONE
701  *
702  * Return:      NONE
703  *
704  * Revised History:
705  * When                 Who             Remark
706  * 11/13/2008   MHC             Create Version 0.
707  *
708  *---------------------------------------------------------------------------*/
709 void EFUSE_ShadowMapUpdate23a(struct rtw_adapter *pAdapter, u8 efuseType)
710 {
711         struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
712         u16     mapLen = 0;
713
714         EFUSE_GetEfuseDefinition23a(pAdapter, efuseType,
715                                  TYPE_EFUSE_MAP_LEN, (void *)&mapLen);
716
717         if (pEEPROM->bautoload_fail_flag == true)
718                 memset(pEEPROM->efuse_eeprom_data, 0xFF, mapLen);
719         else
720                 Efuse_ReadAllMap(pAdapter, efuseType,
721                                  pEEPROM->efuse_eeprom_data);
722
723 }/*  EFUSE_ShadowMapUpdate23a */
724
725 /*-----------------------------------------------------------------------------
726  * Function:    EFUSE_ShadowRead23a
727  *
728  * Overview:    Read from efuse init map !!!!!
729  *
730  * Input:       NONE
731  *
732  * Output:      NONE
733  *
734  * Return:      NONE
735  *
736  * Revised History:
737  * When                 Who             Remark
738  * 11/12/2008   MHC             Create Version 0.
739  *
740  *---------------------------------------------------------------------------*/
741 void
742 EFUSE_ShadowRead23a(
743         struct rtw_adapter *    pAdapter,
744         u8              Type,
745         u16             Offset,
746         u32             *Value  )
747 {
748         if (Type == 1)
749                 efuse_ShadowRead1Byte(pAdapter, Offset, (u8 *)Value);
750         else if (Type == 2)
751                 efuse_ShadowRead2Byte(pAdapter, Offset, (u16 *)Value);
752         else if (Type == 4)
753                 efuse_ShadowRead4Byte(pAdapter, Offset, (u32 *)Value);
754 }       /*  EFUSE_ShadowRead23a */