]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/rtl8188eu/core/rtw_efuse.c
f2d374d5a764b10d3f89f901c7e661c6527663ad
[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 /* Description:
148  *      1. Execute E-Fuse read byte operation according as map offset and
149  *      save to E-Fuse table.
150  *      2. Referred from SD1 Richard.
151  * Assumption:
152  *      1. Boot from E-Fuse and successfully auto-load.
153  *      2. PASSIVE_LEVEL (USB interface)
154  *      Created by Roger, 2008.10.21.
155  * 2008/12/12 MH
156  *      1. Reorganize code flow and reserve bytes. and add description.
157  *      2. Add efuse utilization collect.
158  * 2008/12/22 MH
159  *      Read Efuse must check if we write section 1 data again!!!
160  *      Sec1 write addr must be after sec5.
161  */
162
163 static void efuse_ReadEFuse(struct adapter *Adapter, u8 efuseType, u16 _offset, u16 _size_byte, u8 *pbuf, bool pseudo)
164 {
165         Adapter->HalFunc.ReadEFuse(Adapter, efuseType, _offset, _size_byte, pbuf, pseudo);
166 }
167
168 /*-----------------------------------------------------------------------------
169  * Function:    EFUSE_Read1Byte
170  *
171  * Overview:    Copy from WMAC fot EFUSE read 1 byte.
172  *
173  * Input:       NONE
174  *
175  * Output:      NONE
176  *
177  * Return:      NONE
178  *
179  * Revised History:
180  * When                 Who             Remark
181  * 09/23/2008   MHC             Copy from WMAC.
182  *
183  *---------------------------------------------------------------------------*/
184 u8 EFUSE_Read1Byte(struct adapter *Adapter, u16 Address)
185 {
186         u8 data;
187         u8 Bytetemp = {0x00};
188         u8 temp = {0x00};
189         u32 k = 0;
190         u16 contentLen = 0;
191
192         EFUSE_GetEfuseDefinition(Adapter, EFUSE_WIFI , TYPE_EFUSE_REAL_CONTENT_LEN, (void *)&contentLen);
193
194         if (Address < contentLen) {     /* E-fuse 512Byte */
195                 /* Write E-fuse Register address bit0~7 */
196                 temp = Address & 0xFF;
197                 usb_write8(Adapter, EFUSE_CTRL+1, temp);
198                 Bytetemp = usb_read8(Adapter, EFUSE_CTRL+2);
199                 /* Write E-fuse Register address bit8~9 */
200                 temp = ((Address >> 8) & 0x03) | (Bytetemp & 0xFC);
201                 usb_write8(Adapter, EFUSE_CTRL+2, temp);
202
203                 /* Write 0x30[31]= 0 */
204                 Bytetemp = usb_read8(Adapter, EFUSE_CTRL+3);
205                 temp = Bytetemp & 0x7F;
206                 usb_write8(Adapter, EFUSE_CTRL+3, temp);
207
208                 /* Wait Write-ready (0x30[31]= 1) */
209                 Bytetemp = usb_read8(Adapter, EFUSE_CTRL+3);
210                 while (!(Bytetemp & 0x80)) {
211                         Bytetemp = usb_read8(Adapter, EFUSE_CTRL+3);
212                         k++;
213                         if (k == 1000) {
214                                 k = 0;
215                                 break;
216                         }
217                 }
218                 data = usb_read8(Adapter, EFUSE_CTRL);
219                 return data;
220         } else {
221                 return 0xFF;
222         }
223
224 } /* EFUSE_Read1Byte */
225
226 /*  11/16/2008 MH Read one byte from real Efuse. */
227 u8 efuse_OneByteRead(struct adapter *pAdapter, u16 addr, u8 *data, bool pseudo)
228 {
229         u8 tmpidx = 0;
230         u8 result;
231
232         if (pseudo) {
233                 result = Efuse_Read1ByteFromFakeContent(pAdapter, addr, data);
234                 return result;
235         }
236         /*  -----------------e-fuse reg ctrl --------------------------------- */
237         /* address */
238         usb_write8(pAdapter, EFUSE_CTRL+1, (u8)(addr & 0xff));
239         usb_write8(pAdapter, EFUSE_CTRL+2, ((u8)((addr>>8) & 0x03)) |
240                    (usb_read8(pAdapter, EFUSE_CTRL+2) & 0xFC));
241
242         usb_write8(pAdapter, EFUSE_CTRL+3,  0x72);/* read cmd */
243
244         while (!(0x80 & usb_read8(pAdapter, EFUSE_CTRL+3)) && (tmpidx < 100))
245                 tmpidx++;
246         if (tmpidx < 100) {
247                 *data = usb_read8(pAdapter, EFUSE_CTRL);
248                 result = true;
249         } else {
250                 *data = 0xff;
251                 result = false;
252         }
253         return result;
254 }
255
256 /*  11/16/2008 MH Write one byte to reald Efuse. */
257 u8 efuse_OneByteWrite(struct adapter *pAdapter, u16 addr, u8 data, bool pseudo)
258 {
259         u8 tmpidx = 0;
260         u8 result;
261
262         if (pseudo) {
263                 result = Efuse_Write1ByteToFakeContent(pAdapter, addr, data);
264                 return result;
265         }
266
267         /*  -----------------e-fuse reg ctrl --------------------------------- */
268         /* address */
269         usb_write8(pAdapter, EFUSE_CTRL+1, (u8)(addr&0xff));
270         usb_write8(pAdapter, EFUSE_CTRL+2,
271                    (usb_read8(pAdapter, EFUSE_CTRL+2) & 0xFC) |
272                    (u8)((addr>>8) & 0x03));
273         usb_write8(pAdapter, EFUSE_CTRL, data);/* data */
274
275         usb_write8(pAdapter, EFUSE_CTRL+3, 0xF2);/* write cmd */
276
277         while ((0x80 &  usb_read8(pAdapter, EFUSE_CTRL+3)) && (tmpidx < 100))
278                 tmpidx++;
279
280         if (tmpidx < 100)
281                 result = true;
282         else
283                 result = false;
284
285         return result;
286 }
287
288 int Efuse_PgPacketRead(struct adapter *pAdapter, u8 offset, u8 *data, bool pseudo)
289 {
290         int     ret = 0;
291
292         ret =  pAdapter->HalFunc.Efuse_PgPacketRead(pAdapter, offset, data, pseudo);
293
294         return ret;
295 }
296
297 int Efuse_PgPacketWrite(struct adapter *pAdapter, u8 offset, u8 word_en, u8 *data, bool pseudo)
298 {
299         int ret;
300
301         ret =  pAdapter->HalFunc.Efuse_PgPacketWrite(pAdapter, offset, word_en, data, pseudo);
302
303         return ret;
304 }
305
306
307 static int Efuse_PgPacketWrite_BT(struct adapter *pAdapter, u8 offset, u8 word_en, u8 *data, bool pseudo)
308 {
309         int ret;
310
311         ret =  pAdapter->HalFunc.Efuse_PgPacketWrite_BT(pAdapter, offset, word_en, data, pseudo);
312
313         return ret;
314 }
315
316 /*-----------------------------------------------------------------------------
317  * Function:    efuse_WordEnableDataRead
318  *
319  * Overview:    Read allowed word in current efuse section data.
320  *
321  * Input:       NONE
322  *
323  * Output:      NONE
324  *
325  * Return:      NONE
326  *
327  * Revised History:
328  * When                 Who             Remark
329  * 11/16/2008   MHC             Create Version 0.
330  * 11/21/2008   MHC             Fix Write bug when we only enable late word.
331  *
332  *---------------------------------------------------------------------------*/
333 void efuse_WordEnableDataRead(u8 word_en, u8 *sourdata, u8 *targetdata)
334 {
335         if (!(word_en&BIT(0))) {
336                 targetdata[0] = sourdata[0];
337                 targetdata[1] = sourdata[1];
338         }
339         if (!(word_en&BIT(1))) {
340                 targetdata[2] = sourdata[2];
341                 targetdata[3] = sourdata[3];
342         }
343         if (!(word_en&BIT(2))) {
344                 targetdata[4] = sourdata[4];
345                 targetdata[5] = sourdata[5];
346         }
347         if (!(word_en&BIT(3))) {
348                 targetdata[6] = sourdata[6];
349                 targetdata[7] = sourdata[7];
350         }
351 }
352
353 static u8 efuse_read8(struct adapter *padapter, u16 address, u8 *value)
354 {
355         return efuse_OneByteRead(padapter, address, value, false);
356 }
357
358 static u8 efuse_write8(struct adapter *padapter, u16 address, u8 *value)
359 {
360         return efuse_OneByteWrite(padapter, address, *value, false);
361 }
362
363 /*
364  * read/wirte raw efuse data
365  */
366 u8 rtw_efuse_access(struct adapter *padapter, u8 write, u16 start_addr, u16 cnts, u8 *data)
367 {
368         int i = 0;
369         u16 real_content_len = 0, max_available_size = 0;
370         u8 res = _FAIL;
371         u8 (*rw8)(struct adapter *, u16, u8*);
372
373         EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_REAL_CONTENT_LEN, (void *)&real_content_len);
374         EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size);
375
376         if (start_addr > real_content_len)
377                 return _FAIL;
378
379         if (write) {
380                 if ((start_addr + cnts) > max_available_size)
381                         return _FAIL;
382                 rw8 = &efuse_write8;
383         } else {
384                 rw8 = &efuse_read8;
385         }
386
387         Efuse_PowerSwitch(padapter, write, true);
388
389         /*  e-fuse one byte read / write */
390         for (i = 0; i < cnts; i++) {
391                 if (start_addr >= real_content_len) {
392                         res = _FAIL;
393                         break;
394                 }
395
396                 res = rw8(padapter, start_addr++, data++);
397                 if (_FAIL == res)
398                         break;
399         }
400
401         Efuse_PowerSwitch(padapter, write, false);
402
403         return res;
404 }
405 /*  */
406 u16 efuse_GetMaxSize(struct adapter *padapter)
407 {
408         u16 max_size;
409         EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI , TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_size);
410         return max_size;
411 }
412 /*  */
413 u8 efuse_GetCurrentSize(struct adapter *padapter, u16 *size)
414 {
415         Efuse_PowerSwitch(padapter, false, true);
416         *size = Efuse_GetCurrentSize(padapter, false);
417         Efuse_PowerSwitch(padapter, false, false);
418
419         return _SUCCESS;
420 }
421 /*  */
422 u8 rtw_efuse_map_read(struct adapter *padapter, u16 addr, u16 cnts, u8 *data)
423 {
424         u16 mapLen = 0;
425
426         EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&mapLen);
427
428         if ((addr + cnts) > mapLen)
429                 return _FAIL;
430
431         Efuse_PowerSwitch(padapter, false, true);
432
433         efuse_ReadEFuse(padapter, EFUSE_WIFI, addr, cnts, data, false);
434
435         Efuse_PowerSwitch(padapter, false, false);
436
437         return _SUCCESS;
438 }
439
440 u8 rtw_BT_efuse_map_read(struct adapter *padapter, u16 addr, u16 cnts, u8 *data)
441 {
442         u16 mapLen = 0;
443
444         EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (void *)&mapLen);
445
446         if ((addr + cnts) > mapLen)
447                 return _FAIL;
448
449         Efuse_PowerSwitch(padapter, false, true);
450
451         efuse_ReadEFuse(padapter, EFUSE_BT, addr, cnts, data, false);
452
453         Efuse_PowerSwitch(padapter, false, false);
454
455         return _SUCCESS;
456 }
457 /*  */
458 u8 rtw_efuse_map_write(struct adapter *padapter, u16 addr, u16 cnts, u8 *data)
459 {
460         u8 offset, word_en;
461         u8 *map;
462         u8 newdata[PGPKT_DATA_SIZE + 1];
463         s32     i, idx;
464         u8 ret = _SUCCESS;
465         u16 mapLen = 0;
466
467         EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&mapLen);
468
469         if ((addr + cnts) > mapLen)
470                 return _FAIL;
471
472         map = rtw_zmalloc(mapLen);
473         if (map == NULL)
474                 return _FAIL;
475
476         ret = rtw_efuse_map_read(padapter, 0, mapLen, map);
477         if (ret == _FAIL)
478                 goto exit;
479
480         Efuse_PowerSwitch(padapter, true, true);
481
482         offset = (addr >> 3);
483         word_en = 0xF;
484         _rtw_memset(newdata, 0xFF, PGPKT_DATA_SIZE + 1);
485         i = addr & 0x7; /*  index of one package */
486         idx = 0;        /*  data index */
487
488         if (i & 0x1) {
489                 /*  odd start */
490                 if (data[idx] != map[addr+idx]) {
491                         word_en &= ~BIT(i >> 1);
492                         newdata[i-1] = map[addr+idx-1];
493                         newdata[i] = data[idx];
494                 }
495                 i++;
496                 idx++;
497         }
498         do {
499                 for (; i < PGPKT_DATA_SIZE; i += 2) {
500                         if (cnts == idx)
501                                 break;
502                         if ((cnts - idx) == 1) {
503                                 if (data[idx] != map[addr+idx]) {
504                                         word_en &= ~BIT(i >> 1);
505                                         newdata[i] = data[idx];
506                                         newdata[i+1] = map[addr+idx+1];
507                                 }
508                                 idx++;
509                                 break;
510                         } else {
511                                 if ((data[idx] != map[addr+idx]) ||
512                                     (data[idx+1] != map[addr+idx+1])) {
513                                         word_en &= ~BIT(i >> 1);
514                                         newdata[i] = data[idx];
515                                         newdata[i+1] = data[idx + 1];
516                                 }
517                                 idx += 2;
518                         }
519                         if (idx == cnts)
520                                 break;
521                 }
522
523                 if (word_en != 0xF) {
524                         ret = Efuse_PgPacketWrite(padapter, offset, word_en, newdata, false);
525                         DBG_88E("offset=%x\n", offset);
526                         DBG_88E("word_en=%x\n", word_en);
527
528                         for (i = 0; i < PGPKT_DATA_SIZE; i++)
529                                 DBG_88E("data=%x \t", newdata[i]);
530                         if (ret == _FAIL)
531                                 break;
532                 }
533
534                 if (idx == cnts)
535                         break;
536
537                 offset++;
538                 i = 0;
539                 word_en = 0xF;
540                 _rtw_memset(newdata, 0xFF, PGPKT_DATA_SIZE);
541         } while (1);
542
543         Efuse_PowerSwitch(padapter, true, false);
544 exit:
545         kfree(map);
546         return ret;
547 }
548
549 /*  */
550 u8 rtw_BT_efuse_map_write(struct adapter *padapter, u16 addr, u16 cnts, u8 *data)
551 {
552         u8 offset, word_en;
553         u8 *map;
554         u8 newdata[PGPKT_DATA_SIZE + 1];
555         s32     i, idx;
556         u8 ret = _SUCCESS;
557         u16 mapLen = 0;
558
559         EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (void *)&mapLen);
560
561         if ((addr + cnts) > mapLen)
562                 return _FAIL;
563
564         map = rtw_zmalloc(mapLen);
565         if (map == NULL)
566                 return _FAIL;
567
568         ret = rtw_BT_efuse_map_read(padapter, 0, mapLen, map);
569         if (ret == _FAIL)
570                 goto exit;
571
572         Efuse_PowerSwitch(padapter, true, true);
573
574         offset = (addr >> 3);
575         word_en = 0xF;
576         _rtw_memset(newdata, 0xFF, PGPKT_DATA_SIZE + 1);
577         i = addr & 0x7; /*  index of one package */
578         idx = 0;        /*  data index */
579
580         if (i & 0x1) {
581                 /*  odd start */
582                 if (data[idx] != map[addr+idx]) {
583                         word_en &= ~BIT(i >> 1);
584                         newdata[i-1] = map[addr+idx-1];
585                         newdata[i] = data[idx];
586                 }
587                 i++;
588                 idx++;
589         }
590         do {
591                 for (; i < PGPKT_DATA_SIZE; i += 2) {
592                         if (cnts == idx)
593                                 break;
594                         if ((cnts - idx) == 1) {
595                                 if (data[idx] != map[addr+idx]) {
596                                         word_en &= ~BIT(i >> 1);
597                                         newdata[i] = data[idx];
598                                         newdata[i+1] = map[addr+idx+1];
599                                 }
600                                 idx++;
601                                 break;
602                         } else {
603                                 if ((data[idx] != map[addr+idx]) ||
604                                     (data[idx+1] != map[addr+idx+1])) {
605                                         word_en &= ~BIT(i >> 1);
606                                         newdata[i] = data[idx];
607                                         newdata[i+1] = data[idx + 1];
608                                 }
609                                 idx += 2;
610                         }
611                         if (idx == cnts)
612                                 break;
613                 }
614
615                 if (word_en != 0xF) {
616                         DBG_88E("%s: offset=%#X\n", __func__, offset);
617                         DBG_88E("%s: word_en=%#X\n", __func__, word_en);
618                         DBG_88E("%s: data=", __func__);
619                         for (i = 0; i < PGPKT_DATA_SIZE; i++)
620                                 DBG_88E("0x%02X ", newdata[i]);
621                         DBG_88E("\n");
622
623                         ret = Efuse_PgPacketWrite_BT(padapter, offset, word_en, newdata, false);
624                         if (ret == _FAIL)
625                                 break;
626                 }
627
628                 if (idx == cnts)
629                         break;
630
631                 offset++;
632                 i = 0;
633                 word_en = 0xF;
634                 _rtw_memset(newdata, 0xFF, PGPKT_DATA_SIZE);
635         } while (1);
636
637         Efuse_PowerSwitch(padapter, true, false);
638
639 exit:
640
641         kfree(map);
642
643         return ret;
644 }
645
646 /*-----------------------------------------------------------------------------
647  * Function:    efuse_ShadowRead1Byte
648  *                      efuse_ShadowRead2Byte
649  *                      efuse_ShadowRead4Byte
650  *
651  * Overview:    Read from efuse init map by one/two/four bytes !!!!!
652  *
653  * Input:       NONE
654  *
655  * Output:      NONE
656  *
657  * Return:      NONE
658  *
659  * Revised History:
660  * When                 Who             Remark
661  * 11/12/2008   MHC             Create Version 0.
662  *
663  *---------------------------------------------------------------------------*/
664 static void
665 efuse_ShadowRead1Byte(
666                 struct adapter *pAdapter,
667                 u16 Offset,
668                 u8 *Value)
669 {
670         struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
671
672         *Value = pEEPROM->efuse_eeprom_data[Offset];
673
674 }       /*  EFUSE_ShadowRead1Byte */
675
676 /* Read Two Bytes */
677 static void
678 efuse_ShadowRead2Byte(
679                 struct adapter *pAdapter,
680                 u16 Offset,
681                 u16 *Value)
682 {
683         struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
684
685         *Value = pEEPROM->efuse_eeprom_data[Offset];
686         *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
687
688 }       /*  EFUSE_ShadowRead2Byte */
689
690 /* Read Four Bytes */
691 static void
692 efuse_ShadowRead4Byte(
693                 struct adapter *pAdapter,
694                 u16 Offset,
695                 u32 *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         *Value |= pEEPROM->efuse_eeprom_data[Offset+2]<<16;
702         *Value |= pEEPROM->efuse_eeprom_data[Offset+3]<<24;
703
704 }       /*  efuse_ShadowRead4Byte */
705
706 /*-----------------------------------------------------------------------------
707  * Function:    Efuse_ReadAllMap
708  *
709  * Overview:    Read All Efuse content
710  *
711  * Input:       NONE
712  *
713  * Output:      NONE
714  *
715  * Return:      NONE
716  *
717  * Revised History:
718  * When                 Who             Remark
719  * 11/11/2008   MHC             Create Version 0.
720  *
721  *---------------------------------------------------------------------------*/
722 static void Efuse_ReadAllMap(struct adapter *pAdapter, u8 efuseType, u8 *Efuse, bool pseudo)
723 {
724         u16 mapLen = 0;
725
726         Efuse_PowerSwitch(pAdapter, false, true);
727
728         EFUSE_GetEfuseDefinition(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN, (void *)&mapLen);
729
730         efuse_ReadEFuse(pAdapter, efuseType, 0, mapLen, Efuse, pseudo);
731
732         Efuse_PowerSwitch(pAdapter, false, false);
733 }
734
735 /*-----------------------------------------------------------------------------
736  * Function:    EFUSE_ShadowMapUpdate
737  *
738  * Overview:    Transfer current EFUSE content to shadow init and modify map.
739  *
740  * Input:       NONE
741  *
742  * Output:      NONE
743  *
744  * Return:      NONE
745  *
746  * Revised History:
747  * When                 Who             Remark
748  * 11/13/2008   MHC             Create Version 0.
749  *
750  *---------------------------------------------------------------------------*/
751 void EFUSE_ShadowMapUpdate(
752         struct adapter *pAdapter,
753         u8 efuseType,
754         bool pseudo)
755 {
756         struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
757         u16 mapLen = 0;
758
759         EFUSE_GetEfuseDefinition(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN, (void *)&mapLen);
760
761         if (pEEPROM->bautoload_fail_flag)
762                 _rtw_memset(pEEPROM->efuse_eeprom_data, 0xFF, mapLen);
763         else
764                 Efuse_ReadAllMap(pAdapter, efuseType, pEEPROM->efuse_eeprom_data, pseudo);
765 } /*  EFUSE_ShadowMapUpdate */
766
767 /*-----------------------------------------------------------------------------
768  * Function:    EFUSE_ShadowRead
769  *
770  * Overview:    Read from efuse init map !!!!!
771  *
772  * Input:       NONE
773  *
774  * Output:      NONE
775  *
776  * Return:      NONE
777  *
778  * Revised History:
779  * When                 Who             Remark
780  * 11/12/2008   MHC             Create Version 0.
781  *
782  *---------------------------------------------------------------------------*/
783 void EFUSE_ShadowRead(struct adapter *pAdapter, u8 Type, u16 Offset, u32 *Value)
784 {
785         if (Type == 1)
786                 efuse_ShadowRead1Byte(pAdapter, Offset, (u8 *)Value);
787         else if (Type == 2)
788                 efuse_ShadowRead2Byte(pAdapter, Offset, (u16 *)Value);
789         else if (Type == 4)
790                 efuse_ShadowRead4Byte(pAdapter, Offset, (u32 *)Value);
791
792 }       /*  EFUSE_ShadowRead */