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