5d3f80afea294225dd79824e0f3eaa057d514fd2
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bu / core / efuse / 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 <drv_types.h>
23 #include <hal_data.h>
24
25
26 /*------------------------Define local variable------------------------------*/
27 u8      fakeEfuseBank=0;
28 u32     fakeEfuseUsedBytes=0;
29 u8      fakeEfuseContent[EFUSE_MAX_HW_SIZE]={0};
30 u8      fakeEfuseInitMap[EFUSE_MAX_MAP_LEN]={0};
31 u8      fakeEfuseModifiedMap[EFUSE_MAX_MAP_LEN]={0};
32
33 u32     BTEfuseUsedBytes=0;
34 u8      BTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
35 u8      BTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN]={0};
36 u8      BTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN]={0};
37
38 u32     fakeBTEfuseUsedBytes=0;
39 u8      fakeBTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
40 u8      fakeBTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN]={0};
41 u8      fakeBTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN]={0};
42 /*------------------------Define local variable------------------------------*/
43
44 //------------------------------------------------------------------------------
45 #define REG_EFUSE_CTRL          0x0030
46 #define EFUSE_CTRL                      REG_EFUSE_CTRL          // E-Fuse Control.
47 //------------------------------------------------------------------------------
48
49 BOOLEAN
50 Efuse_Read1ByteFromFakeContent(
51         IN              PADAPTER        pAdapter,
52         IN              u16             Offset,
53         IN OUT  u8              *Value  );
54 BOOLEAN
55 Efuse_Read1ByteFromFakeContent(
56         IN              PADAPTER        pAdapter,
57         IN              u16             Offset,
58         IN OUT  u8              *Value  )
59 {
60         if(Offset >= EFUSE_MAX_HW_SIZE)
61         {
62                 return _FALSE;
63         }
64         //DbgPrint("Read fake content, offset = %d\n", Offset);
65         if(fakeEfuseBank == 0)
66                 *Value = fakeEfuseContent[Offset];
67         else
68                 *Value = fakeBTEfuseContent[fakeEfuseBank-1][Offset];
69         return _TRUE;
70 }
71
72 BOOLEAN
73 Efuse_Write1ByteToFakeContent(
74         IN              PADAPTER        pAdapter,
75         IN              u16             Offset,
76         IN              u8              Value   );
77 BOOLEAN
78 Efuse_Write1ByteToFakeContent(
79         IN              PADAPTER        pAdapter,
80         IN              u16             Offset,
81         IN              u8              Value   )
82 {
83         if(Offset >= EFUSE_MAX_HW_SIZE)
84         {
85                 return _FALSE;
86         }
87         if(fakeEfuseBank == 0)
88                 fakeEfuseContent[Offset] = Value;
89         else
90         {
91                 fakeBTEfuseContent[fakeEfuseBank-1][Offset] = Value;
92         }
93         return _TRUE;
94 }
95
96 /*-----------------------------------------------------------------------------
97  * Function:    Efuse_PowerSwitch
98  *
99  * Overview:    When we want to enable write operation, we should change to 
100  *                              pwr on state. When we stop write, we should switch to 500k mode
101  *                              and disable LDO 2.5V.
102  *
103  * Input:       NONE
104  *
105  * Output:      NONE
106  *
107  * Return:      NONE
108  *
109  * Revised History:
110  * When                 Who             Remark
111  * 11/17/2008   MHC             Create Version 0.
112  *
113  *---------------------------------------------------------------------------*/
114 VOID
115 Efuse_PowerSwitch(
116         IN      PADAPTER        pAdapter,
117         IN      u8              bWrite,
118         IN      u8              PwrState)
119 {
120         pAdapter->HalFunc.EfusePowerSwitch(pAdapter, bWrite, PwrState);
121 }
122
123 VOID
124 BTEfuse_PowerSwitch(
125         IN      PADAPTER        pAdapter,
126         IN      u8              bWrite,
127         IN      u8              PwrState)
128 {
129         if(pAdapter->HalFunc.BTEfusePowerSwitch)
130                 pAdapter->HalFunc.BTEfusePowerSwitch(pAdapter, bWrite, PwrState);
131 }
132
133 /*-----------------------------------------------------------------------------
134  * Function:    efuse_GetCurrentSize
135  *
136  * Overview:    Get current efuse size!!!
137  *
138  * Input:       NONE
139  *
140  * Output:      NONE
141  *
142  * Return:      NONE
143  *
144  * Revised History:
145  * When                 Who             Remark
146  * 11/16/2008   MHC             Create Version 0.
147  *
148  *---------------------------------------------------------------------------*/
149 u16
150 Efuse_GetCurrentSize(
151         IN PADAPTER             pAdapter,
152         IN u8                   efuseType,
153         IN BOOLEAN              bPseudoTest)
154 {
155         u16 ret=0;
156
157         ret = pAdapter->HalFunc.EfuseGetCurrentSize(pAdapter, efuseType, bPseudoTest);
158
159         return ret;
160 }
161
162 /*  11/16/2008 MH Add description. Get current efuse area enabled word!!. */
163 u8
164 Efuse_CalculateWordCnts(IN u8   word_en)
165 {
166         u8 word_cnts = 0;
167         if(!(word_en & BIT(0))) word_cnts++; // 0 : write enable
168         if(!(word_en & BIT(1))) word_cnts++;
169         if(!(word_en & BIT(2))) word_cnts++;
170         if(!(word_en & BIT(3))) word_cnts++;
171         return word_cnts;
172 }
173
174 //
175 //      Description:
176 //              Execute E-Fuse read byte operation.
177 //              Refered from SD1 Richard.
178 //
179 //      Assumption:
180 //              1. Boot from E-Fuse and successfully auto-load.
181 //              2. PASSIVE_LEVEL (USB interface)
182 //
183 //      Created by Roger, 2008.10.21.
184 //
185 VOID
186 ReadEFuseByte(
187                 PADAPTER        Adapter,
188                 u16                     _offset, 
189                 u8                      *pbuf, 
190                 IN BOOLEAN      bPseudoTest) 
191 {
192         u32     value32;
193         u8      readbyte;
194         u16     retry;
195         //u32 start=rtw_get_current_time();
196
197         if(bPseudoTest)
198         {
199                 Efuse_Read1ByteFromFakeContent(Adapter, _offset, pbuf);
200                 return;
201         }
202         if (IS_HARDWARE_TYPE_8723B(Adapter))
203         {
204                 // <20130121, Kordan> For SMIC S55 EFUSE specificatoin.
205                 //0x34[11]: SW force PGMEN input of efuse to high. (for the bank selected by 0x34[9:8])
206                 PHY_SetMacReg(Adapter, EFUSE_TEST, BIT11, 0);
207         }
208         //Write Address
209         rtw_write8(Adapter, EFUSE_CTRL+1, (_offset & 0xff));            
210         readbyte = rtw_read8(Adapter, EFUSE_CTRL+2);
211         rtw_write8(Adapter, EFUSE_CTRL+2, ((_offset >> 8) & 0x03) | (readbyte & 0xfc));                 
212
213         //Write bit 32 0
214         readbyte = rtw_read8(Adapter, EFUSE_CTRL+3);            
215         rtw_write8(Adapter, EFUSE_CTRL+3, (readbyte & 0x7f));   
216         
217         //Check bit 32 read-ready
218         retry = 0;
219         value32 = rtw_read32(Adapter, EFUSE_CTRL);
220         //while(!(((value32 >> 24) & 0xff) & 0x80)  && (retry<10))
221         while(!(((value32 >> 24) & 0xff) & 0x80)  && (retry<10000))
222         {
223                 value32 = rtw_read32(Adapter, EFUSE_CTRL);
224                 retry++;
225         }
226
227         // 20100205 Joseph: Add delay suggested by SD1 Victor.
228         // This fix the problem that Efuse read error in high temperature condition.
229         // Designer says that there shall be some delay after ready bit is set, or the
230         // result will always stay on last data we read.
231         rtw_udelay_os(50);
232         value32 = rtw_read32(Adapter, EFUSE_CTRL);
233         
234         *pbuf = (u8)(value32 & 0xff);
235         //DBG_871X("ReadEFuseByte _offset:%08u, in %d ms\n",_offset ,rtw_get_passing_time_ms(start));
236         
237 }
238
239 //
240 //      Description:
241 //              1. Execute E-Fuse read byte operation according as map offset and 
242 //                  save to E-Fuse table.
243 //              2. Refered from SD1 Richard.
244 //
245 //      Assumption:
246 //              1. Boot from E-Fuse and successfully auto-load.
247 //              2. PASSIVE_LEVEL (USB interface)
248 //
249 //      Created by Roger, 2008.10.21.
250 //
251 //      2008/12/12 MH   1. Reorganize code flow and reserve bytes. and add description.
252 //                                      2. Add efuse utilization collect.
253 //      2008/12/22 MH   Read Efuse must check if we write section 1 data again!!! Sec1
254 //                                      write addr must be after sec5.
255 //
256
257 VOID
258 efuse_ReadEFuse(
259         PADAPTER        Adapter,
260         u8              efuseType,
261         u16             _offset,
262         u16             _size_byte,
263         u8              *pbuf,
264         IN      BOOLEAN bPseudoTest
265         );
266 VOID
267 efuse_ReadEFuse(
268         PADAPTER        Adapter,
269         u8              efuseType,
270         u16             _offset,
271         u16             _size_byte,
272         u8              *pbuf,
273         IN      BOOLEAN bPseudoTest
274         )
275 {
276         Adapter->HalFunc.ReadEFuse(Adapter, efuseType, _offset, _size_byte, pbuf, bPseudoTest);
277 }
278
279 VOID
280 EFUSE_GetEfuseDefinition(
281         IN              PADAPTER        pAdapter,
282         IN              u8              efuseType,
283         IN              u8              type,
284         OUT             void            *pOut,
285         IN              BOOLEAN         bPseudoTest
286         )
287 {
288         pAdapter->HalFunc.EFUSEGetEfuseDefinition(pAdapter, efuseType, type, pOut, bPseudoTest);
289 }
290
291 /*-----------------------------------------------------------------------------
292  * Function:    EFUSE_Read1Byte
293  *
294  * Overview:    Copy from WMAC fot EFUSE read 1 byte.
295  *
296  * Input:       NONE
297  *
298  * Output:      NONE
299  *
300  * Return:      NONE
301  *
302  * Revised History:
303  * When                 Who             Remark
304  * 09/23/2008   MHC             Copy from WMAC.
305  *
306  *---------------------------------------------------------------------------*/
307 u8
308 EFUSE_Read1Byte(        
309         IN      PADAPTER        Adapter, 
310         IN      u16             Address)
311 {
312         u8      data;
313         u8      Bytetemp = {0x00};
314         u8      temp = {0x00};
315         u32     k=0;
316         u16     contentLen=0;
317
318         EFUSE_GetEfuseDefinition(Adapter, EFUSE_WIFI , TYPE_EFUSE_REAL_CONTENT_LEN, (PVOID)&contentLen, _FALSE);
319
320         if (Address < contentLen)       //E-fuse 512Byte
321         {
322                 //Write E-fuse Register address bit0~7
323                 temp = Address & 0xFF;  
324                 rtw_write8(Adapter, EFUSE_CTRL+1, temp);        
325                 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+2);    
326                 //Write E-fuse Register address bit8~9
327                 temp = ((Address >> 8) & 0x03) | (Bytetemp & 0xFC);     
328                 rtw_write8(Adapter, EFUSE_CTRL+2, temp);        
329
330                 //Write 0x30[31]=0
331                 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
332                 temp = Bytetemp & 0x7F;
333                 rtw_write8(Adapter, EFUSE_CTRL+3, temp);
334
335                 //Wait Write-ready (0x30[31]=1)
336                 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
337                 while(!(Bytetemp & 0x80))
338                 {                               
339                         Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
340                         k++;
341                         if(k==1000)
342                         {
343                                 k=0;
344                                 break;
345                         }
346                 }
347                 data=rtw_read8(Adapter, EFUSE_CTRL);
348                 return data;
349         }
350         else
351                 return 0xFF;
352         
353 }/* EFUSE_Read1Byte */
354
355 /*-----------------------------------------------------------------------------
356  * Function:    EFUSE_Write1Byte
357  *
358  * Overview:    Copy from WMAC fot EFUSE write 1 byte.
359  *
360  * Input:       NONE
361  *
362  * Output:      NONE
363  *
364  * Return:      NONE
365  *
366  * Revised History:
367  * When                 Who             Remark
368  * 09/23/2008   MHC             Copy from WMAC.
369  *
370  *---------------------------------------------------------------------------*/
371
372 void    
373 EFUSE_Write1Byte(       
374         IN      PADAPTER        Adapter, 
375         IN      u16             Address,
376         IN      u8              Value);
377 void    
378 EFUSE_Write1Byte(       
379         IN      PADAPTER        Adapter, 
380         IN      u16             Address,
381         IN      u8              Value)
382 {
383         u8      Bytetemp = {0x00};
384         u8      temp = {0x00};
385         u32     k=0;
386         u16     contentLen=0;
387
388         //RT_TRACE(COMP_EFUSE, DBG_LOUD, ("Addr=%x Data =%x\n", Address, Value));
389         EFUSE_GetEfuseDefinition(Adapter, EFUSE_WIFI , TYPE_EFUSE_REAL_CONTENT_LEN, (PVOID)&contentLen, _FALSE);
390
391         if( Address < contentLen)       //E-fuse 512Byte
392         {
393                 rtw_write8(Adapter, EFUSE_CTRL, Value);
394
395                 //Write E-fuse Register address bit0~7
396                 temp = Address & 0xFF;  
397                 rtw_write8(Adapter, EFUSE_CTRL+1, temp);        
398                 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+2);    
399                 
400                 //Write E-fuse Register address bit8~9
401                 temp = ((Address >> 8) & 0x03) | (Bytetemp & 0xFC);     
402                 rtw_write8(Adapter, EFUSE_CTRL+2, temp);        
403
404                 //Write 0x30[31]=1
405                 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
406                 temp = Bytetemp | 0x80;
407                 rtw_write8(Adapter, EFUSE_CTRL+3, temp);
408
409                 //Wait Write-ready (0x30[31]=0)
410                 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
411                 while(Bytetemp & 0x80)
412                 {
413                         Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);                    
414                         k++;
415                         if(k==100)
416                         {
417                                 k=0;
418                                 break;
419                         }
420                 }
421         }
422 }/* EFUSE_Write1Byte */
423
424
425 /*  11/16/2008 MH Read one byte from real Efuse. */
426 u8
427 efuse_OneByteRead(
428         IN      PADAPTER        pAdapter, 
429         IN      u16                     addr,
430         IN      u8                      *data,
431         IN      BOOLEAN         bPseudoTest)
432 {
433         u32     tmpidx = 0;
434         u8      bResult;
435         u8      readbyte;
436
437         //DBG_871X("===> EFUSE_OneByteRead(), addr = %x\n", addr);
438         //DBG_871X("===> EFUSE_OneByteRead() start, 0x34 = 0x%X\n", rtw_read32(pAdapter, EFUSE_TEST));
439
440         if(bPseudoTest)
441         {
442                 bResult = Efuse_Read1ByteFromFakeContent(pAdapter, addr, data);
443                 return bResult;
444         }
445
446         if(     IS_HARDWARE_TYPE_8723B(pAdapter) ||
447                 (IS_HARDWARE_TYPE_8192E(pAdapter) && IS_VENDOR_8192E_B_CUT(pAdapter)))
448         {
449                 // <20130121, Kordan> For SMIC EFUSE specificatoin.
450                 //0x34[11]: SW force PGMEN input of efuse to high. (for the bank selected by 0x34[9:8]) 
451                 //PHY_SetMacReg(pAdapter, 0x34, BIT11, 0);
452                 rtw_write16(pAdapter, 0x34, rtw_read16(pAdapter,0x34)& (~BIT11) ); 
453         }
454
455         // -----------------e-fuse reg ctrl ---------------------------------
456         //address                       
457         rtw_write8(pAdapter, EFUSE_CTRL+1, (u8)(addr&0xff));            
458         rtw_write8(pAdapter, EFUSE_CTRL+2, ((u8)((addr>>8) &0x03) ) |
459         (rtw_read8(pAdapter, EFUSE_CTRL+2)&0xFC ));     
460
461         //rtw_write8(pAdapter, EFUSE_CTRL+3,  0x72);//read cmd  
462         //Write bit 32 0
463         readbyte = rtw_read8(pAdapter, EFUSE_CTRL+3);           
464         rtw_write8(pAdapter, EFUSE_CTRL+3, (readbyte & 0x7f));
465
466         while(!(0x80 &rtw_read8(pAdapter, EFUSE_CTRL+3))&&(tmpidx<1000))
467         {
468                 rtw_mdelay_os(1);
469                 tmpidx++;
470         }
471         if(tmpidx<100)
472         {                       
473                 *data=rtw_read8(pAdapter, EFUSE_CTRL);          
474                 bResult = _TRUE;
475         }
476         else
477         {
478                 *data = 0xff;   
479                 bResult = _FALSE;
480                 DBG_871X("%s: [ERROR] addr=0x%x bResult=%d time out 1s !!!\n", __FUNCTION__, addr, bResult);
481                 DBG_871X("%s: [ERROR] EFUSE_CTRL =0x%08x !!!\n", __FUNCTION__, rtw_read32(pAdapter, EFUSE_CTRL));
482         }
483
484         return bResult;
485 }
486                 
487 /*  11/16/2008 MH Write one byte to reald Efuse. */
488 u8
489 efuse_OneByteWrite(
490         IN      PADAPTER        pAdapter,  
491         IN      u16                     addr, 
492         IN      u8                      data,
493         IN      BOOLEAN         bPseudoTest)
494 {
495         u8      tmpidx = 0;
496         u8      bResult=_FALSE;
497         u32 efuseValue = 0;
498
499         //DBG_871X("===> EFUSE_OneByteWrite(), addr = %x data=%x\n", addr, data);
500         //DBG_871X("===> EFUSE_OneByteWrite() start, 0x34 = 0x%X\n", rtw_read32(pAdapter, EFUSE_TEST));
501
502         if(bPseudoTest)
503         {
504                 bResult = Efuse_Write1ByteToFakeContent(pAdapter, addr, data);
505                 return bResult;
506         }
507
508
509         // -----------------e-fuse reg ctrl ---------------------------------   
510         //address                       
511
512         
513         efuseValue = rtw_read32(pAdapter, EFUSE_CTRL);
514         efuseValue |= (BIT21|BIT31);
515         efuseValue &= ~(0x3FFFF);
516         efuseValue |= ((addr<<8 | data) & 0x3FFFF);
517
518
519         // <20130227, Kordan> 8192E MP chip A-cut had better not set 0x34[11] until B-Cut.
520         if (IS_HARDWARE_TYPE_8723B(pAdapter)||(IS_HARDWARE_TYPE_8192E(pAdapter) && IS_VENDOR_8192E_B_CUT(pAdapter)))
521         {
522                 // <20130121, Kordan> For SMIC EFUSE specificatoin.
523                 //0x34[11]: SW force PGMEN input of efuse to high. (for the bank selected by 0x34[9:8])
524                 //PHY_SetMacReg(pAdapter, 0x34, BIT11, 1);
525                 rtw_write16(pAdapter, 0x34, rtw_read16(pAdapter,0x34)| (BIT11) );
526                 rtw_write32(pAdapter, EFUSE_CTRL, 0x90600000|((addr<<8 | data)) );
527         }
528         else
529         {
530                 rtw_write32(pAdapter, EFUSE_CTRL, efuseValue);
531         }
532
533         while((0x80 &  rtw_read8(pAdapter, EFUSE_CTRL+3)) && (tmpidx<100) ){
534                 rtw_mdelay_os(1);
535                 tmpidx++;
536         }
537
538         if(tmpidx<100)
539         {
540                 bResult = _TRUE;
541         }
542         else
543         {
544                 bResult = _FALSE;
545                 DBG_871X("%s: [ERROR] addr=0x%x ,efuseValue=0x%x ,bResult=%d time out 1s !!! \n",
546                                         __FUNCTION__, addr, efuseValue, bResult);
547                 DBG_871X("%s: [ERROR] EFUSE_CTRL =0x%08x !!!\n", __FUNCTION__, rtw_read32(pAdapter, EFUSE_CTRL));
548         }
549
550         // disable Efuse program enable
551         if (IS_HARDWARE_TYPE_8723B(pAdapter))
552         {
553                 PHY_SetMacReg(pAdapter, EFUSE_TEST, BIT(11), 0);
554         }
555
556         return bResult;
557 }
558
559 int
560 Efuse_PgPacketRead(     IN      PADAPTER        pAdapter,
561                                         IN      u8                      offset,
562                                         IN      u8                      *data,
563                                         IN      BOOLEAN         bPseudoTest)
564 {
565         int     ret=0;
566
567         ret =  pAdapter->HalFunc.Efuse_PgPacketRead(pAdapter, offset, data, bPseudoTest);
568
569         return ret;
570 }
571
572 int 
573 Efuse_PgPacketWrite(IN  PADAPTER        pAdapter, 
574                                         IN      u8                      offset,
575                                         IN      u8                      word_en,
576                                         IN      u8                      *data,
577                                         IN      BOOLEAN         bPseudoTest)
578 {
579         int ret;
580
581         ret =  pAdapter->HalFunc.Efuse_PgPacketWrite(pAdapter, offset, word_en, data, bPseudoTest);
582
583         return ret;
584 }
585
586
587 int 
588 Efuse_PgPacketWrite_BT(IN       PADAPTER        pAdapter, 
589                                         IN      u8                      offset,
590                                         IN      u8                      word_en,
591                                         IN      u8                      *data,
592                                         IN      BOOLEAN         bPseudoTest)
593 {
594         int ret;
595
596         ret =  pAdapter->HalFunc.Efuse_PgPacketWrite_BT(pAdapter, offset, word_en, data, bPseudoTest);
597
598         return ret;
599 }
600
601 /*-----------------------------------------------------------------------------
602  * Function:    efuse_WordEnableDataRead
603  *
604  * Overview:    Read allowed word in current efuse section data.
605  *
606  * Input:       NONE
607  *
608  * Output:      NONE
609  *
610  * Return:      NONE
611  *
612  * Revised History:
613  * When                 Who             Remark
614  * 11/16/2008   MHC             Create Version 0.
615  * 11/21/2008   MHC             Fix Write bug when we only enable late word.
616  *
617  *---------------------------------------------------------------------------*/
618 void
619 efuse_WordEnableDataRead(IN     u8      word_en,
620                                                         IN      u8      *sourdata,
621                                                         IN      u8      *targetdata)
622 {       
623         if (!(word_en&BIT(0)))
624         {
625                 targetdata[0] = sourdata[0];
626                 targetdata[1] = sourdata[1];
627         }
628         if (!(word_en&BIT(1)))
629         {
630                 targetdata[2] = sourdata[2];
631                 targetdata[3] = sourdata[3];
632         }
633         if (!(word_en&BIT(2)))
634         {
635                 targetdata[4] = sourdata[4];
636                 targetdata[5] = sourdata[5];
637         }
638         if (!(word_en&BIT(3)))
639         {
640                 targetdata[6] = sourdata[6];
641                 targetdata[7] = sourdata[7];
642         }
643 }
644
645
646 u8
647 Efuse_WordEnableDataWrite(      IN      PADAPTER        pAdapter,
648                                                         IN      u16             efuse_addr,
649                                                         IN      u8              word_en, 
650                                                         IN      u8              *data,
651                                                         IN      BOOLEAN         bPseudoTest)
652 {
653         u8      ret=0;
654
655         ret =  pAdapter->HalFunc.Efuse_WordEnableDataWrite(pAdapter, efuse_addr, word_en, data, bPseudoTest);
656         
657         return ret;
658 }
659
660 static u8 efuse_read8(PADAPTER padapter, u16 address, u8 *value)
661 {
662         return efuse_OneByteRead(padapter,address, value, _FALSE);
663 }
664
665 static u8 efuse_write8(PADAPTER padapter, u16 address, u8 *value)
666 {
667         return efuse_OneByteWrite(padapter,address, *value, _FALSE);
668 }
669
670 /*
671  * read/wirte raw efuse data
672  */
673 u8 rtw_efuse_access(PADAPTER padapter, u8 bWrite, u16 start_addr, u16 cnts, u8 *data)
674 {
675         int i = 0;
676         u16     real_content_len = 0, max_available_size = 0;
677         u8 res = _FAIL ;
678         u8 (*rw8)(PADAPTER, u16, u8*);
679
680         EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_REAL_CONTENT_LEN, (PVOID)&real_content_len, _FALSE);
681         EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE);
682
683         if (start_addr > real_content_len)
684                 return _FAIL;
685
686         if (_TRUE == bWrite) {
687                 if ((start_addr + cnts) > max_available_size)
688                         return _FAIL;
689                 rw8 = &efuse_write8;
690         } else
691                 rw8 = &efuse_read8;
692
693         Efuse_PowerSwitch(padapter, bWrite, _TRUE);
694
695         // e-fuse one byte read / write
696         for (i = 0; i < cnts; i++) {
697                 if (start_addr >= real_content_len) {
698                         res = _FAIL;
699                         break;
700                 }
701
702                 res = rw8(padapter, start_addr++, data++);
703                 if (_FAIL == res) break;
704         }
705
706         Efuse_PowerSwitch(padapter, bWrite, _FALSE);
707
708         return res;
709 }
710 //------------------------------------------------------------------------------
711 u16 efuse_GetMaxSize(PADAPTER padapter)
712 {
713         u16     max_size;
714         EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI , TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_size, _FALSE);
715         return max_size;
716 }
717 //------------------------------------------------------------------------------
718 u8 efuse_GetCurrentSize(PADAPTER padapter, u16 *size)
719 {
720         Efuse_PowerSwitch(padapter, _FALSE, _TRUE);
721         *size = Efuse_GetCurrentSize(padapter, EFUSE_WIFI, _FALSE);
722         Efuse_PowerSwitch(padapter, _FALSE, _FALSE);
723
724         return _SUCCESS;
725 }
726 //------------------------------------------------------------------------------
727 u8 rtw_efuse_map_read(PADAPTER padapter, u16 addr, u16 cnts, u8 *data)
728 {
729         u16     mapLen=0;
730
731         EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (PVOID)&mapLen, _FALSE);
732
733         if ((addr + cnts) > mapLen)
734                 return _FAIL;
735
736         Efuse_PowerSwitch(padapter, _FALSE, _TRUE);
737
738         efuse_ReadEFuse(padapter, EFUSE_WIFI, addr, cnts, data, _FALSE);
739
740         Efuse_PowerSwitch(padapter, _FALSE, _FALSE);
741
742         return _SUCCESS;
743 }
744
745 u8 rtw_BT_efuse_map_read(PADAPTER padapter, u16 addr, u16 cnts, u8 *data)
746 {
747         u16     mapLen=0;
748
749         EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (PVOID)&mapLen, _FALSE);
750
751         if ((addr + cnts) > mapLen)
752                 return _FAIL;
753
754         Efuse_PowerSwitch(padapter, _FALSE, _TRUE);
755
756         efuse_ReadEFuse(padapter, EFUSE_BT, addr, cnts, data, _FALSE);
757
758         Efuse_PowerSwitch(padapter, _FALSE, _FALSE);
759
760         return _SUCCESS;
761 }
762 //------------------------------------------------------------------------------
763 u8 rtw_efuse_map_write(PADAPTER padapter, u16 addr, u16 cnts, u8 *data)
764 {
765 #define RT_ASSERT_RET(expr)                                                                                             \
766         if(!(expr)) {                                                                                                                   \
767                 printk( "Assertion failed! %s at ......\n", #expr);                                                     \
768                 printk( "      ......%s,%s,line=%d\n",__FILE__,__FUNCTION__,__LINE__);  \
769                 return _FAIL;   \
770         }
771
772         u8      offset, word_en;
773         u8      *map;
774         u8      newdata[PGPKT_DATA_SIZE];
775         s32     i, j, idx;
776         u8      ret = _SUCCESS;
777         u16     mapLen=0;
778         EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
779         HAL_DATA_TYPE   *pHalData = GET_HAL_DATA(padapter);
780
781         EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (PVOID)&mapLen, _FALSE);
782
783         if ((addr + cnts) > mapLen)
784                 return _FAIL;
785
786         RT_ASSERT_RET(PGPKT_DATA_SIZE == 8); // have to be 8 byte alignment
787         RT_ASSERT_RET((mapLen & 0x7) == 0); // have to be PGPKT_DATA_SIZE alignment for memcpy
788
789         map = rtw_zmalloc(mapLen);
790         if(map == NULL){
791                 return _FAIL;
792         }
793         
794         _rtw_memset(map, 0xFF, mapLen);
795         
796         ret = rtw_efuse_map_read(padapter, 0, mapLen, map);
797         if (ret == _FAIL) goto exit;
798
799         Efuse_PowerSwitch(padapter, _TRUE, _TRUE);
800
801         idx = 0;
802         offset = (addr >> 3);
803         while (idx < cnts)
804         {
805                 word_en = 0xF;
806                 j = (addr + idx) & 0x7;
807                 _rtw_memcpy(newdata, &map[offset << 3], PGPKT_DATA_SIZE);
808                 for (i = j; i<PGPKT_DATA_SIZE && idx < cnts; i++, idx++)
809                 {
810                         if (data[idx] != map[addr + idx])
811                         {
812                                 word_en &= ~BIT(i >> 1);
813                                 newdata[i] = data[idx];
814 #ifdef CONFIG_RTL8723B                                  
815                                  if( addr + idx == 0x8)
816                                  {      
817                                         if (IS_C_CUT(pHalData->VersionID) || IS_B_CUT(pHalData->VersionID))
818                                         {
819                                                 if(pEEPROM->adjuseVoltageVal == 6)
820                                                 {
821                                                                 newdata[i] = map[addr + idx];
822                                                                 DBG_8192C(" %s ,\n adjuseVoltageVal = %d ,newdata[%d] = %x \n",__func__,pEEPROM->adjuseVoltageVal,i,newdata[i]);         
823                                                 }
824                                         }
825                                   }
826 #endif
827                         }
828                 }
829
830                 if (word_en != 0xF) {
831                         ret = Efuse_PgPacketWrite(padapter, offset, word_en, newdata, _FALSE);
832                         DBG_871X("offset=%x \n",offset);
833                         DBG_871X("word_en=%x \n",word_en);
834
835                         for(i=0;i<PGPKT_DATA_SIZE;i++)
836                         {
837                                 DBG_871X("data=%x \t",newdata[i]);
838                         }
839                         if (ret == _FAIL) break;
840                 }
841
842                 offset++;
843         }
844
845         Efuse_PowerSwitch(padapter, _TRUE, _FALSE);
846
847 exit:
848
849         rtw_mfree(map, mapLen);
850
851         return ret;
852 }
853
854
855 //------------------------------------------------------------------------------
856 u8 rtw_BT_efuse_map_write(PADAPTER padapter, u16 addr, u16 cnts, u8 *data)
857 {
858 #define RT_ASSERT_RET(expr)                                                                                             \
859         if(!(expr)) {                                                                                                                   \
860                 printk( "Assertion failed! %s at ......\n", #expr);                                                     \
861                 printk( "      ......%s,%s,line=%d\n",__FILE__,__FUNCTION__,__LINE__);  \
862                 return _FAIL;   \
863         }
864
865         u8      offset, word_en;
866         u8      *map;
867         u8      newdata[PGPKT_DATA_SIZE];
868         s32     i=0, j=0, idx;
869         u8      ret = _SUCCESS;
870         u16     mapLen=0;
871
872         EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (PVOID)&mapLen, _FALSE);
873
874         if ((addr + cnts) > mapLen)
875                 return _FAIL;
876
877         RT_ASSERT_RET(PGPKT_DATA_SIZE == 8); // have to be 8 byte alignment
878         RT_ASSERT_RET((mapLen & 0x7) == 0); // have to be PGPKT_DATA_SIZE alignment for memcpy
879
880         map = rtw_zmalloc(mapLen);
881         if(map == NULL){
882                 return _FAIL;
883         }
884
885         ret = rtw_BT_efuse_map_read(padapter, 0, mapLen, map);
886         if (ret == _FAIL) goto exit;
887         DBG_871X("OFFSET\tVALUE(hex)\n");
888         for (i=0; i<1024; i+=16) // set 512 because the iwpriv's extra size have limit 0x7FF
889         {
890                         DBG_871X("0x%03x\t", i);
891                         for (j=0; j<8; j++) {
892                                 DBG_871X("%02X ", map[i+j]);
893                         }
894                         DBG_871X("\t");
895                         for (; j<16; j++) {
896                                 DBG_871X("%02X ", map[i+j]);
897                         }
898                         DBG_871X("\n");
899         }
900         DBG_871X("\n");
901         Efuse_PowerSwitch(padapter, _TRUE, _TRUE);
902
903         idx = 0;
904         offset = (addr >> 3);
905         while (idx < cnts)
906         {
907                 word_en = 0xF;
908                 j = (addr + idx) & 0x7;
909                 _rtw_memcpy(newdata, &map[offset << 3], PGPKT_DATA_SIZE);
910                 for (i = j; i<PGPKT_DATA_SIZE && idx < cnts; i++, idx++)
911                 {
912                         if (data[idx] != map[addr + idx])
913                         {
914                                 word_en &= ~BIT(i >> 1);
915                                 newdata[i] = data[idx];
916                         }
917                 }
918
919                 if (word_en != 0xF) {
920                         DBG_871X("offset=%x \n",offset);
921                         DBG_871X("word_en=%x \n",word_en);
922                         DBG_871X("%s: data=", __FUNCTION__);
923                         for(i=0;i<PGPKT_DATA_SIZE;i++)
924                         {
925                                 DBG_871X("0x%02X ", newdata[i]);
926                         }
927                         DBG_871X("\n");
928                         ret = Efuse_PgPacketWrite_BT(padapter, offset, word_en, newdata, _FALSE);
929                         if (ret == _FAIL) break;
930                 }
931
932                 offset++;
933         }
934
935         Efuse_PowerSwitch(padapter, _TRUE, _FALSE);
936
937 exit:
938
939         rtw_mfree(map, mapLen);
940
941         return ret;
942 }
943
944 /*-----------------------------------------------------------------------------
945  * Function:    Efuse_ReadAllMap
946  *
947  * Overview:    Read All Efuse content
948  *
949  * Input:       NONE
950  *
951  * Output:      NONE
952  *
953  * Return:      NONE
954  *
955  * Revised History:
956  * When                 Who             Remark
957  * 11/11/2008   MHC             Create Version 0.
958  *
959  *---------------------------------------------------------------------------*/
960 VOID 
961 Efuse_ReadAllMap(
962         IN              PADAPTER        pAdapter, 
963         IN              u8              efuseType,
964         IN OUT  u8              *Efuse,
965         IN              BOOLEAN         bPseudoTest);
966 VOID 
967 Efuse_ReadAllMap(
968         IN              PADAPTER        pAdapter, 
969         IN              u8              efuseType,
970         IN OUT  u8              *Efuse,
971         IN              BOOLEAN         bPseudoTest)
972 {
973         u16     mapLen=0;
974
975         Efuse_PowerSwitch(pAdapter,_FALSE, _TRUE);
976
977         EFUSE_GetEfuseDefinition(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN, (PVOID)&mapLen, bPseudoTest);
978
979         efuse_ReadEFuse(pAdapter, efuseType, 0, mapLen, Efuse, bPseudoTest);
980
981         Efuse_PowerSwitch(pAdapter,_FALSE, _FALSE);
982 }
983
984 /*-----------------------------------------------------------------------------
985  * Function:    efuse_ShadowRead1Byte
986  *                      efuse_ShadowRead2Byte
987  *                      efuse_ShadowRead4Byte
988  *
989  * Overview:    Read from efuse init map by one/two/four bytes !!!!!
990  *
991  * Input:       NONE
992  *
993  * Output:      NONE
994  *
995  * Return:      NONE
996  *
997  * Revised History:
998  * When                 Who             Remark
999  * 11/12/2008   MHC             Create Version 0.
1000  *
1001  *---------------------------------------------------------------------------*/
1002 static VOID
1003 efuse_ShadowRead1Byte(
1004         IN      PADAPTER        pAdapter,
1005         IN      u16             Offset,
1006         IN OUT  u8              *Value)
1007 {
1008         EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
1009
1010         *Value = pEEPROM->efuse_eeprom_data[Offset];
1011
1012 }       // EFUSE_ShadowRead1Byte
1013
1014 //---------------Read Two Bytes
1015 static VOID
1016 efuse_ShadowRead2Byte(
1017         IN      PADAPTER        pAdapter,
1018         IN      u16             Offset,
1019         IN OUT  u16             *Value)
1020 {
1021         EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
1022
1023         *Value = pEEPROM->efuse_eeprom_data[Offset];
1024         *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
1025
1026 }       // EFUSE_ShadowRead2Byte
1027
1028 //---------------Read Four Bytes
1029 static VOID
1030 efuse_ShadowRead4Byte(
1031         IN      PADAPTER        pAdapter,
1032         IN      u16             Offset,
1033         IN OUT  u32             *Value)
1034 {
1035         EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
1036
1037         *Value = pEEPROM->efuse_eeprom_data[Offset];
1038         *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
1039         *Value |= pEEPROM->efuse_eeprom_data[Offset+2]<<16;
1040         *Value |= pEEPROM->efuse_eeprom_data[Offset+3]<<24;
1041
1042 }       // efuse_ShadowRead4Byte
1043
1044
1045 /*-----------------------------------------------------------------------------
1046  * Function:    efuse_ShadowWrite1Byte
1047  *                      efuse_ShadowWrite2Byte
1048  *                      efuse_ShadowWrite4Byte
1049  *
1050  * Overview:    Write efuse modify map by one/two/four byte.
1051  *
1052  * Input:       NONE
1053  *
1054  * Output:      NONE
1055  *
1056  * Return:      NONE
1057  *
1058  * Revised History:
1059  * When                 Who             Remark
1060  * 11/12/2008   MHC             Create Version 0.
1061  *
1062  *---------------------------------------------------------------------------*/
1063 #ifdef PLATFORM
1064 static VOID
1065 efuse_ShadowWrite1Byte(
1066         IN      PADAPTER        pAdapter,
1067         IN      u16             Offset,
1068         IN      u8              Value);
1069 #endif //PLATFORM
1070 static VOID
1071 efuse_ShadowWrite1Byte(
1072         IN      PADAPTER        pAdapter,
1073         IN      u16             Offset,
1074         IN      u8              Value)
1075 {
1076         EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
1077
1078         pEEPROM->efuse_eeprom_data[Offset] = Value;
1079
1080 }       // efuse_ShadowWrite1Byte
1081
1082 //---------------Write Two Bytes
1083 static VOID
1084 efuse_ShadowWrite2Byte(
1085         IN      PADAPTER        pAdapter,
1086         IN      u16             Offset,
1087         IN      u16             Value)
1088 {
1089         EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
1090
1091         pEEPROM->efuse_eeprom_data[Offset] = Value&0x00FF;
1092         pEEPROM->efuse_eeprom_data[Offset+1] = Value>>8;
1093
1094 }       // efuse_ShadowWrite1Byte
1095
1096 //---------------Write Four Bytes
1097 static VOID
1098 efuse_ShadowWrite4Byte(
1099         IN      PADAPTER        pAdapter,
1100         IN      u16             Offset,
1101         IN      u32             Value)
1102 {
1103         EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
1104
1105         pEEPROM->efuse_eeprom_data[Offset] = (u8)(Value&0x000000FF);
1106         pEEPROM->efuse_eeprom_data[Offset+1] = (u8)((Value>>8)&0x0000FF);
1107         pEEPROM->efuse_eeprom_data[Offset+2] = (u8)((Value>>16)&0x00FF);
1108         pEEPROM->efuse_eeprom_data[Offset+3] = (u8)((Value>>24)&0xFF);
1109
1110 }       // efuse_ShadowWrite1Byte
1111
1112 /*-----------------------------------------------------------------------------
1113  * Function:    EFUSE_ShadowMapUpdate
1114  *
1115  * Overview:    Transfer current EFUSE content to shadow init and modify map.
1116  *
1117  * Input:       NONE
1118  *
1119  * Output:      NONE
1120  *
1121  * Return:      NONE
1122  *
1123  * Revised History:
1124  * When                 Who             Remark
1125  * 11/13/2008   MHC             Create Version 0.
1126  *
1127  *---------------------------------------------------------------------------*/
1128 void EFUSE_ShadowMapUpdate(
1129         IN PADAPTER     pAdapter,
1130         IN u8           efuseType,
1131         IN BOOLEAN      bPseudoTest)
1132 {
1133         EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
1134         u16     mapLen=0;
1135
1136         EFUSE_GetEfuseDefinition(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN, (PVOID)&mapLen, bPseudoTest);
1137
1138         if (pEEPROM->bautoload_fail_flag == _TRUE)
1139         {
1140                 _rtw_memset(pEEPROM->efuse_eeprom_data, 0xFF, mapLen);
1141         }
1142         else
1143         {
1144                 #ifdef CONFIG_ADAPTOR_INFO_CACHING_FILE                 
1145                 if(_SUCCESS != retriveAdaptorInfoFile(pAdapter->registrypriv.adaptor_info_caching_file_path, pEEPROM)) {
1146                 #endif
1147                 
1148                 Efuse_ReadAllMap(pAdapter, efuseType, pEEPROM->efuse_eeprom_data, bPseudoTest);
1149                 
1150                 #ifdef CONFIG_ADAPTOR_INFO_CACHING_FILE
1151                         storeAdaptorInfoFile(pAdapter->registrypriv.adaptor_info_caching_file_path, pEEPROM);
1152                 }
1153                 #endif
1154         }
1155
1156         //PlatformMoveMemory((PVOID)&pHalData->EfuseMap[EFUSE_MODIFY_MAP][0], 
1157         //(PVOID)&pHalData->EfuseMap[EFUSE_INIT_MAP][0], mapLen);
1158 }// EFUSE_ShadowMapUpdate
1159
1160
1161 /*-----------------------------------------------------------------------------
1162  * Function:    EFUSE_ShadowRead
1163  *
1164  * Overview:    Read from efuse init map !!!!!
1165  *
1166  * Input:       NONE
1167  *
1168  * Output:      NONE
1169  *
1170  * Return:      NONE
1171  *
1172  * Revised History:
1173  * When                 Who             Remark
1174  * 11/12/2008   MHC             Create Version 0.
1175  *
1176  *---------------------------------------------------------------------------*/
1177 void
1178 EFUSE_ShadowRead(
1179         IN              PADAPTER        pAdapter,
1180         IN              u8              Type,
1181         IN              u16             Offset,
1182         IN OUT  u32             *Value  )
1183 {
1184         if (Type == 1)
1185                 efuse_ShadowRead1Byte(pAdapter, Offset, (u8 *)Value);
1186         else if (Type == 2)
1187                 efuse_ShadowRead2Byte(pAdapter, Offset, (u16 *)Value);
1188         else if (Type == 4)
1189                 efuse_ShadowRead4Byte(pAdapter, Offset, (u32 *)Value);
1190         
1191 }       // EFUSE_ShadowRead
1192
1193 /*-----------------------------------------------------------------------------
1194  * Function:    EFUSE_ShadowWrite
1195  *
1196  * Overview:    Write efuse modify map for later update operation to use!!!!!
1197  *
1198  * Input:       NONE
1199  *
1200  * Output:      NONE
1201  *
1202  * Return:      NONE
1203  *
1204  * Revised History:
1205  * When                 Who             Remark
1206  * 11/12/2008   MHC             Create Version 0.
1207  *
1208  *---------------------------------------------------------------------------*/
1209 VOID
1210 EFUSE_ShadowWrite(
1211         IN      PADAPTER        pAdapter,
1212         IN      u8              Type,
1213         IN      u16             Offset,
1214         IN OUT  u32             Value);
1215 VOID
1216 EFUSE_ShadowWrite(
1217         IN      PADAPTER        pAdapter,
1218         IN      u8              Type,
1219         IN      u16             Offset,
1220         IN OUT  u32             Value)
1221 {
1222 #if (MP_DRIVER == 0)
1223         return;
1224 #endif
1225         if ( pAdapter->registrypriv.mp_mode == 0)
1226                 return;
1227
1228
1229         if (Type == 1)
1230                 efuse_ShadowWrite1Byte(pAdapter, Offset, (u8)Value);
1231         else if (Type == 2)
1232                 efuse_ShadowWrite2Byte(pAdapter, Offset, (u16)Value);
1233         else if (Type == 4)
1234                 efuse_ShadowWrite4Byte(pAdapter, Offset, (u32)Value);
1235
1236 }       // EFUSE_ShadowWrite
1237
1238 VOID
1239 Efuse_InitSomeVar(
1240         IN              PADAPTER        pAdapter
1241         );
1242 VOID
1243 Efuse_InitSomeVar(
1244         IN              PADAPTER        pAdapter
1245         )
1246 {
1247         u8 i;
1248         
1249         _rtw_memset((PVOID)&fakeEfuseContent[0], 0xff, EFUSE_MAX_HW_SIZE);
1250         _rtw_memset((PVOID)&fakeEfuseInitMap[0], 0xff, EFUSE_MAX_MAP_LEN);
1251         _rtw_memset((PVOID)&fakeEfuseModifiedMap[0], 0xff, EFUSE_MAX_MAP_LEN);
1252
1253         for(i=0; i<EFUSE_MAX_BT_BANK; i++)
1254         {
1255                 _rtw_memset((PVOID)&BTEfuseContent[i][0], EFUSE_MAX_HW_SIZE, 0xff);
1256         }
1257         _rtw_memset((PVOID)&BTEfuseInitMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN);
1258         _rtw_memset((PVOID)&BTEfuseModifiedMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN);
1259
1260         for(i=0; i<EFUSE_MAX_BT_BANK; i++)
1261         {
1262                 _rtw_memset((PVOID)&fakeBTEfuseContent[i][0], 0xff, EFUSE_MAX_HW_SIZE);
1263         }
1264         _rtw_memset((PVOID)&fakeBTEfuseInitMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN);
1265         _rtw_memset((PVOID)&fakeBTEfuseModifiedMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN);
1266 }
1267
1268 #ifdef PLATFORM_LINUX
1269 #ifdef CONFIG_ADAPTOR_INFO_CACHING_FILE
1270 //#include <rtw_eeprom.h>
1271
1272  int isAdaptorInfoFileValid(void)
1273 {
1274         return _TRUE;
1275 }
1276
1277 int storeAdaptorInfoFile(char *path, struct eeprom_priv * eeprom_priv)
1278 {
1279         int ret =_SUCCESS;
1280
1281         if(path && eeprom_priv) {
1282                 ret = rtw_store_to_file(path, eeprom_priv->efuse_eeprom_data, EEPROM_MAX_SIZE_512);
1283                 if(ret == EEPROM_MAX_SIZE)
1284                         ret = _SUCCESS;
1285                 else
1286                         ret = _FAIL;
1287         } else {
1288                 DBG_871X("%s NULL pointer\n",__FUNCTION__);
1289                 ret =  _FAIL;
1290         }
1291         return ret;
1292 }
1293
1294 int retriveAdaptorInfoFile(char *path, struct eeprom_priv * eeprom_priv)
1295 {
1296         int ret = _SUCCESS;
1297         mm_segment_t oldfs;
1298         struct file *fp;
1299         
1300         if(path && eeprom_priv) {
1301
1302                 ret = rtw_retrive_from_file(path, eeprom_priv->efuse_eeprom_data, EEPROM_MAX_SIZE);
1303                 
1304                 if(ret == EEPROM_MAX_SIZE)
1305                         ret = _SUCCESS;
1306                 else
1307                         ret = _FAIL;
1308
1309                 #if 0
1310                 if(isAdaptorInfoFileValid()) {  
1311                         return 0;
1312                 } else {
1313                         return _FAIL;
1314                 }
1315                 #endif
1316                 
1317         } else {
1318                 DBG_871X("%s NULL pointer\n",__FUNCTION__);
1319                 ret = _FAIL;
1320         }
1321         return ret;
1322 }
1323 #endif //CONFIG_ADAPTOR_INFO_CACHING_FILE
1324 #endif //PLATFORM_LINUX
1325
1326 #ifdef CONFIG_EFUSE_CONFIG_FILE
1327
1328 void Rtw_Hal_ReadMACAddrFromFile(PADAPTER padapter)
1329 {
1330         u32 i;
1331         struct file *fp;
1332         mm_segment_t fs;
1333         u8 source_addr[18];
1334         loff_t pos = 0;
1335         u32 curtime = rtw_get_current_time();
1336         EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
1337         u8 *head, *end;
1338
1339         u8 null_mac_addr[ETH_ALEN] = {0, 0, 0,0, 0, 0};
1340         u8 multi_mac_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1341         
1342         _rtw_memset(source_addr, 0, 18);
1343         _rtw_memset(pEEPROM->mac_addr, 0, ETH_ALEN);
1344
1345         fp = filp_open("/data/wifimac.txt", O_RDWR,  0644);
1346         if (IS_ERR(fp)) {
1347                 pEEPROM->bloadmac_fail_flag = _TRUE;
1348                 DBG_871X("Error, wifi mac address file doesn't exist.\n");
1349         } else {
1350                 fs = get_fs();
1351                 set_fs(KERNEL_DS);
1352
1353                 DBG_871X("wifi mac address:\n");
1354                 vfs_read(fp, source_addr, 18, &pos);
1355                 source_addr[17] = ':';
1356
1357                 head = end = source_addr;
1358                 for (i=0; i<ETH_ALEN; i++) {
1359                         while (end && (*end != ':') )
1360                                 end++;
1361
1362                         if (end && (*end == ':') )
1363                                 *end = '\0';
1364
1365                         pEEPROM->mac_addr[i] = simple_strtoul(head, NULL, 16 );
1366
1367                         if (end) {
1368                                 end++;
1369                                 head = end;
1370                         }
1371                         DBG_871X("%02x \n", pEEPROM->mac_addr[i]);
1372                 }
1373                 DBG_871X("\n");
1374                 set_fs(fs);
1375                 pEEPROM->bloadmac_fail_flag = _FALSE;
1376                 filp_close(fp, NULL);
1377         }
1378
1379         if ( (_rtw_memcmp(pEEPROM->mac_addr, null_mac_addr, ETH_ALEN)) ||
1380                 (_rtw_memcmp(pEEPROM->mac_addr, multi_mac_addr, ETH_ALEN)) ) {
1381                 pEEPROM->mac_addr[0] = 0x00;
1382                 pEEPROM->mac_addr[1] = 0xe0;
1383                 pEEPROM->mac_addr[2] = 0x4c;
1384                 pEEPROM->mac_addr[3] = (u8)(curtime & 0xff) ;
1385                 pEEPROM->mac_addr[4] = (u8)((curtime>>8) & 0xff) ;
1386                 pEEPROM->mac_addr[5] = (u8)((curtime>>16) & 0xff) ;
1387         }
1388
1389         DBG_871X("Hal_ReadMACAddrFromFile: Permanent Address = %02x-%02x-%02x-%02x-%02x-%02x !!!\n",
1390                   pEEPROM->mac_addr[0], pEEPROM->mac_addr[1],
1391                   pEEPROM->mac_addr[2], pEEPROM->mac_addr[3],
1392                   pEEPROM->mac_addr[4], pEEPROM->mac_addr[5]);
1393 }
1394
1395
1396 u32 Rtw_Hal_readPGDataFromConfigFile(PADAPTER   padapter)
1397 {
1398         u32 i;
1399         struct file *fp;
1400         mm_segment_t fs;
1401         u8 temp[3];
1402         loff_t pos = 0;
1403         EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
1404         u8      *PROMContent = pEEPROM->efuse_eeprom_data;
1405
1406
1407         temp[2] = 0; // add end of string '\0'
1408
1409         fp = filp_open("/system/etc/wifi/wifi_efuse.map", O_RDWR,  0644);
1410         if (IS_ERR(fp)) {
1411                 pEEPROM->bloadfile_fail_flag = _TRUE;
1412                 DBG_871X("Error, Efuse configure file doesn't exist.\n");
1413                 return _FAIL;
1414         }
1415
1416         fs = get_fs();
1417         set_fs(KERNEL_DS);
1418
1419         DBG_871X("Efuse configure file:\n");
1420         for (i=0; i< EFUSE_MAP_SIZE  ; i++) {
1421                 vfs_read(fp, temp, 2, &pos);
1422                 PROMContent[i] = simple_strtoul(temp, NULL, 16 );
1423                 pos += 1; // Filter the space character
1424                 DBG_871X("%02X \n", PROMContent[i]);
1425         }
1426         DBG_871X("\n");
1427         set_fs(fs);
1428
1429         filp_close(fp, NULL);
1430         
1431         pEEPROM->bloadfile_fail_flag = _FALSE;
1432         
1433         return _SUCCESS;
1434 }
1435
1436 #endif //#CONFIG_EFUSE_CONFIG_FILE