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