1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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.
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
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
19 ******************************************************************************/
22 #include <drv_types.h>
26 /*------------------------Define local variable------------------------------*/
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};
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};
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------------------------------*/
44 //------------------------------------------------------------------------------
45 #define REG_EFUSE_CTRL 0x0030
46 #define EFUSE_CTRL REG_EFUSE_CTRL // E-Fuse Control.
47 //------------------------------------------------------------------------------
50 Efuse_Read1ByteFromFakeContent(
55 Efuse_Read1ByteFromFakeContent(
60 if(Offset >= EFUSE_MAX_HW_SIZE)
64 //DbgPrint("Read fake content, offset = %d\n", Offset);
65 if(fakeEfuseBank == 0)
66 *Value = fakeEfuseContent[Offset];
68 *Value = fakeBTEfuseContent[fakeEfuseBank-1][Offset];
73 Efuse_Write1ByteToFakeContent(
78 Efuse_Write1ByteToFakeContent(
83 if(Offset >= EFUSE_MAX_HW_SIZE)
87 if(fakeEfuseBank == 0)
88 fakeEfuseContent[Offset] = Value;
91 fakeBTEfuseContent[fakeEfuseBank-1][Offset] = Value;
96 /*-----------------------------------------------------------------------------
97 * Function: Efuse_PowerSwitch
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.
111 * 11/17/2008 MHC Create Version 0.
113 *---------------------------------------------------------------------------*/
116 IN PADAPTER pAdapter,
120 pAdapter->HalFunc.EfusePowerSwitch(pAdapter, bWrite, PwrState);
125 IN PADAPTER pAdapter,
129 if(pAdapter->HalFunc.BTEfusePowerSwitch)
130 pAdapter->HalFunc.BTEfusePowerSwitch(pAdapter, bWrite, PwrState);
133 /*-----------------------------------------------------------------------------
134 * Function: efuse_GetCurrentSize
136 * Overview: Get current efuse size!!!
146 * 11/16/2008 MHC Create Version 0.
148 *---------------------------------------------------------------------------*/
150 Efuse_GetCurrentSize(
151 IN PADAPTER pAdapter,
153 IN BOOLEAN bPseudoTest)
157 ret = pAdapter->HalFunc.EfuseGetCurrentSize(pAdapter, efuseType, bPseudoTest);
162 /* 11/16/2008 MH Add description. Get current efuse area enabled word!!. */
164 Efuse_CalculateWordCnts(IN u8 word_en)
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++;
176 // Execute E-Fuse read byte operation.
177 // Refered from SD1 Richard.
180 // 1. Boot from E-Fuse and successfully auto-load.
181 // 2. PASSIVE_LEVEL (USB interface)
183 // Created by Roger, 2008.10.21.
190 IN BOOLEAN bPseudoTest)
195 //u32 start=rtw_get_current_time();
199 Efuse_Read1ByteFromFakeContent(Adapter, _offset, pbuf);
202 if (IS_HARDWARE_TYPE_8723B(Adapter))
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);
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));
214 readbyte = rtw_read8(Adapter, EFUSE_CTRL+3);
215 rtw_write8(Adapter, EFUSE_CTRL+3, (readbyte & 0x7f));
217 //Check bit 32 read-ready
219 value32 = rtw_read32(Adapter, EFUSE_CTRL);
220 //while(!(((value32 >> 24) & 0xff) & 0x80) && (retry<10))
221 while(!(((value32 >> 24) & 0xff) & 0x80) && (retry<10000))
223 value32 = rtw_read32(Adapter, EFUSE_CTRL);
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.
232 value32 = rtw_read32(Adapter, EFUSE_CTRL);
234 *pbuf = (u8)(value32 & 0xff);
235 //DBG_871X("ReadEFuseByte _offset:%08u, in %d ms\n",_offset ,rtw_get_passing_time_ms(start));
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.
246 // 1. Boot from E-Fuse and successfully auto-load.
247 // 2. PASSIVE_LEVEL (USB interface)
249 // Created by Roger, 2008.10.21.
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.
264 IN BOOLEAN bPseudoTest
273 IN BOOLEAN bPseudoTest
276 Adapter->HalFunc.ReadEFuse(Adapter, efuseType, _offset, _size_byte, pbuf, bPseudoTest);
280 EFUSE_GetEfuseDefinition(
281 IN PADAPTER pAdapter,
285 IN BOOLEAN bPseudoTest
288 pAdapter->HalFunc.EFUSEGetEfuseDefinition(pAdapter, efuseType, type, pOut, bPseudoTest);
291 /*-----------------------------------------------------------------------------
292 * Function: EFUSE_Read1Byte
294 * Overview: Copy from WMAC fot EFUSE read 1 byte.
304 * 09/23/2008 MHC Copy from WMAC.
306 *---------------------------------------------------------------------------*/
313 u8 Bytetemp = {0x00};
318 EFUSE_GetEfuseDefinition(Adapter, EFUSE_WIFI , TYPE_EFUSE_REAL_CONTENT_LEN, (PVOID)&contentLen, _FALSE);
320 if (Address < contentLen) //E-fuse 512Byte
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);
331 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
332 temp = Bytetemp & 0x7F;
333 rtw_write8(Adapter, EFUSE_CTRL+3, temp);
335 //Wait Write-ready (0x30[31]=1)
336 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
337 while(!(Bytetemp & 0x80))
339 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
347 data=rtw_read8(Adapter, EFUSE_CTRL);
353 }/* EFUSE_Read1Byte */
355 /*-----------------------------------------------------------------------------
356 * Function: EFUSE_Write1Byte
358 * Overview: Copy from WMAC fot EFUSE write 1 byte.
368 * 09/23/2008 MHC Copy from WMAC.
370 *---------------------------------------------------------------------------*/
383 u8 Bytetemp = {0x00};
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);
391 if( Address < contentLen) //E-fuse 512Byte
393 rtw_write8(Adapter, EFUSE_CTRL, Value);
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);
400 //Write E-fuse Register address bit8~9
401 temp = ((Address >> 8) & 0x03) | (Bytetemp & 0xFC);
402 rtw_write8(Adapter, EFUSE_CTRL+2, temp);
405 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
406 temp = Bytetemp | 0x80;
407 rtw_write8(Adapter, EFUSE_CTRL+3, temp);
409 //Wait Write-ready (0x30[31]=0)
410 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
411 while(Bytetemp & 0x80)
413 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
422 }/* EFUSE_Write1Byte */
425 /* 11/16/2008 MH Read one byte from real Efuse. */
428 IN PADAPTER pAdapter,
431 IN BOOLEAN bPseudoTest)
437 //DBG_871X("===> EFUSE_OneByteRead(), addr = %x\n", addr);
438 //DBG_871X("===> EFUSE_OneByteRead() start, 0x34 = 0x%X\n", rtw_read32(pAdapter, EFUSE_TEST));
442 bResult = Efuse_Read1ByteFromFakeContent(pAdapter, addr, data);
446 if( IS_HARDWARE_TYPE_8723B(pAdapter) ||
447 (IS_HARDWARE_TYPE_8192E(pAdapter) && IS_VENDOR_8192E_B_CUT(pAdapter)))
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) );
455 // -----------------e-fuse reg ctrl ---------------------------------
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 ));
461 //rtw_write8(pAdapter, EFUSE_CTRL+3, 0x72);//read cmd
463 readbyte = rtw_read8(pAdapter, EFUSE_CTRL+3);
464 rtw_write8(pAdapter, EFUSE_CTRL+3, (readbyte & 0x7f));
466 while(!(0x80 &rtw_read8(pAdapter, EFUSE_CTRL+3))&&(tmpidx<1000))
473 *data=rtw_read8(pAdapter, EFUSE_CTRL);
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));
487 /* 11/16/2008 MH Write one byte to reald Efuse. */
490 IN PADAPTER pAdapter,
493 IN BOOLEAN bPseudoTest)
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));
504 bResult = Efuse_Write1ByteToFakeContent(pAdapter, addr, data);
509 // -----------------e-fuse reg ctrl ---------------------------------
513 efuseValue = rtw_read32(pAdapter, EFUSE_CTRL);
514 efuseValue |= (BIT21|BIT31);
515 efuseValue &= ~(0x3FFFF);
516 efuseValue |= ((addr<<8 | data) & 0x3FFFF);
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)))
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)) );
530 rtw_write32(pAdapter, EFUSE_CTRL, efuseValue);
533 while((0x80 & rtw_read8(pAdapter, EFUSE_CTRL+3)) && (tmpidx<100) ){
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));
550 // disable Efuse program enable
551 if (IS_HARDWARE_TYPE_8723B(pAdapter))
553 PHY_SetMacReg(pAdapter, EFUSE_TEST, BIT(11), 0);
560 Efuse_PgPacketRead( IN PADAPTER pAdapter,
563 IN BOOLEAN bPseudoTest)
567 ret = pAdapter->HalFunc.Efuse_PgPacketRead(pAdapter, offset, data, bPseudoTest);
573 Efuse_PgPacketWrite(IN PADAPTER pAdapter,
577 IN BOOLEAN bPseudoTest)
581 ret = pAdapter->HalFunc.Efuse_PgPacketWrite(pAdapter, offset, word_en, data, bPseudoTest);
588 Efuse_PgPacketWrite_BT(IN PADAPTER pAdapter,
592 IN BOOLEAN bPseudoTest)
596 ret = pAdapter->HalFunc.Efuse_PgPacketWrite_BT(pAdapter, offset, word_en, data, bPseudoTest);
601 /*-----------------------------------------------------------------------------
602 * Function: efuse_WordEnableDataRead
604 * Overview: Read allowed word in current efuse section data.
614 * 11/16/2008 MHC Create Version 0.
615 * 11/21/2008 MHC Fix Write bug when we only enable late word.
617 *---------------------------------------------------------------------------*/
619 efuse_WordEnableDataRead(IN u8 word_en,
623 if (!(word_en&BIT(0)))
625 targetdata[0] = sourdata[0];
626 targetdata[1] = sourdata[1];
628 if (!(word_en&BIT(1)))
630 targetdata[2] = sourdata[2];
631 targetdata[3] = sourdata[3];
633 if (!(word_en&BIT(2)))
635 targetdata[4] = sourdata[4];
636 targetdata[5] = sourdata[5];
638 if (!(word_en&BIT(3)))
640 targetdata[6] = sourdata[6];
641 targetdata[7] = sourdata[7];
647 Efuse_WordEnableDataWrite( IN PADAPTER pAdapter,
651 IN BOOLEAN bPseudoTest)
655 ret = pAdapter->HalFunc.Efuse_WordEnableDataWrite(pAdapter, efuse_addr, word_en, data, bPseudoTest);
660 static u8 efuse_read8(PADAPTER padapter, u16 address, u8 *value)
662 return efuse_OneByteRead(padapter,address, value, _FALSE);
665 static u8 efuse_write8(PADAPTER padapter, u16 address, u8 *value)
667 return efuse_OneByteWrite(padapter,address, *value, _FALSE);
671 * read/wirte raw efuse data
673 u8 rtw_efuse_access(PADAPTER padapter, u8 bWrite, u16 start_addr, u16 cnts, u8 *data)
676 u16 real_content_len = 0, max_available_size = 0;
678 u8 (*rw8)(PADAPTER, u16, u8*);
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);
683 if (start_addr > real_content_len)
686 if (_TRUE == bWrite) {
687 if ((start_addr + cnts) > max_available_size)
693 Efuse_PowerSwitch(padapter, bWrite, _TRUE);
695 // e-fuse one byte read / write
696 for (i = 0; i < cnts; i++) {
697 if (start_addr >= real_content_len) {
702 res = rw8(padapter, start_addr++, data++);
703 if (_FAIL == res) break;
706 Efuse_PowerSwitch(padapter, bWrite, _FALSE);
710 //------------------------------------------------------------------------------
711 u16 efuse_GetMaxSize(PADAPTER padapter)
714 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI , TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_size, _FALSE);
717 //------------------------------------------------------------------------------
718 u8 efuse_GetCurrentSize(PADAPTER padapter, u16 *size)
720 Efuse_PowerSwitch(padapter, _FALSE, _TRUE);
721 *size = Efuse_GetCurrentSize(padapter, EFUSE_WIFI, _FALSE);
722 Efuse_PowerSwitch(padapter, _FALSE, _FALSE);
726 //------------------------------------------------------------------------------
727 u8 rtw_efuse_map_read(PADAPTER padapter, u16 addr, u16 cnts, u8 *data)
731 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (PVOID)&mapLen, _FALSE);
733 if ((addr + cnts) > mapLen)
736 Efuse_PowerSwitch(padapter, _FALSE, _TRUE);
738 efuse_ReadEFuse(padapter, EFUSE_WIFI, addr, cnts, data, _FALSE);
740 Efuse_PowerSwitch(padapter, _FALSE, _FALSE);
745 u8 rtw_BT_efuse_map_read(PADAPTER padapter, u16 addr, u16 cnts, u8 *data)
749 EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (PVOID)&mapLen, _FALSE);
751 if ((addr + cnts) > mapLen)
754 Efuse_PowerSwitch(padapter, _FALSE, _TRUE);
756 efuse_ReadEFuse(padapter, EFUSE_BT, addr, cnts, data, _FALSE);
758 Efuse_PowerSwitch(padapter, _FALSE, _FALSE);
762 //------------------------------------------------------------------------------
763 u8 rtw_efuse_map_write(PADAPTER padapter, u16 addr, u16 cnts, u8 *data)
765 #define RT_ASSERT_RET(expr) \
767 printk( "Assertion failed! %s at ......\n", #expr); \
768 printk( " ......%s,%s,line=%d\n",__FILE__,__FUNCTION__,__LINE__); \
774 u8 newdata[PGPKT_DATA_SIZE];
778 EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
779 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
781 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (PVOID)&mapLen, _FALSE);
783 if ((addr + cnts) > mapLen)
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
789 map = rtw_zmalloc(mapLen);
794 _rtw_memset(map, 0xFF, mapLen);
796 ret = rtw_efuse_map_read(padapter, 0, mapLen, map);
797 if (ret == _FAIL) goto exit;
799 Efuse_PowerSwitch(padapter, _TRUE, _TRUE);
802 offset = (addr >> 3);
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++)
810 if (data[idx] != map[addr + idx])
812 word_en &= ~BIT(i >> 1);
813 newdata[i] = data[idx];
814 #ifdef CONFIG_RTL8723B
815 if( addr + idx == 0x8)
817 if (IS_C_CUT(pHalData->VersionID) || IS_B_CUT(pHalData->VersionID))
819 if(pEEPROM->adjuseVoltageVal == 6)
821 newdata[i] = map[addr + idx];
822 DBG_8192C(" %s ,\n adjuseVoltageVal = %d ,newdata[%d] = %x \n",__func__,pEEPROM->adjuseVoltageVal,i,newdata[i]);
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);
835 for(i=0;i<PGPKT_DATA_SIZE;i++)
837 DBG_871X("data=%x \t",newdata[i]);
839 if (ret == _FAIL) break;
845 Efuse_PowerSwitch(padapter, _TRUE, _FALSE);
849 rtw_mfree(map, mapLen);
855 //------------------------------------------------------------------------------
856 u8 rtw_BT_efuse_map_write(PADAPTER padapter, u16 addr, u16 cnts, u8 *data)
858 #define RT_ASSERT_RET(expr) \
860 printk( "Assertion failed! %s at ......\n", #expr); \
861 printk( " ......%s,%s,line=%d\n",__FILE__,__FUNCTION__,__LINE__); \
867 u8 newdata[PGPKT_DATA_SIZE];
872 EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (PVOID)&mapLen, _FALSE);
874 if ((addr + cnts) > mapLen)
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
880 map = rtw_zmalloc(mapLen);
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
890 DBG_871X("0x%03x\t", i);
891 for (j=0; j<8; j++) {
892 DBG_871X("%02X ", map[i+j]);
896 DBG_871X("%02X ", map[i+j]);
901 Efuse_PowerSwitch(padapter, _TRUE, _TRUE);
904 offset = (addr >> 3);
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++)
912 if (data[idx] != map[addr + idx])
914 word_en &= ~BIT(i >> 1);
915 newdata[i] = data[idx];
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++)
925 DBG_871X("0x%02X ", newdata[i]);
928 ret = Efuse_PgPacketWrite_BT(padapter, offset, word_en, newdata, _FALSE);
929 if (ret == _FAIL) break;
935 Efuse_PowerSwitch(padapter, _TRUE, _FALSE);
939 rtw_mfree(map, mapLen);
944 /*-----------------------------------------------------------------------------
945 * Function: Efuse_ReadAllMap
947 * Overview: Read All Efuse content
957 * 11/11/2008 MHC Create Version 0.
959 *---------------------------------------------------------------------------*/
962 IN PADAPTER pAdapter,
965 IN BOOLEAN bPseudoTest);
968 IN PADAPTER pAdapter,
971 IN BOOLEAN bPseudoTest)
975 Efuse_PowerSwitch(pAdapter,_FALSE, _TRUE);
977 EFUSE_GetEfuseDefinition(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN, (PVOID)&mapLen, bPseudoTest);
979 efuse_ReadEFuse(pAdapter, efuseType, 0, mapLen, Efuse, bPseudoTest);
981 Efuse_PowerSwitch(pAdapter,_FALSE, _FALSE);
984 /*-----------------------------------------------------------------------------
985 * Function: efuse_ShadowRead1Byte
986 * efuse_ShadowRead2Byte
987 * efuse_ShadowRead4Byte
989 * Overview: Read from efuse init map by one/two/four bytes !!!!!
999 * 11/12/2008 MHC Create Version 0.
1001 *---------------------------------------------------------------------------*/
1003 efuse_ShadowRead1Byte(
1004 IN PADAPTER pAdapter,
1008 EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
1010 *Value = pEEPROM->efuse_eeprom_data[Offset];
1012 } // EFUSE_ShadowRead1Byte
1014 //---------------Read Two Bytes
1016 efuse_ShadowRead2Byte(
1017 IN PADAPTER pAdapter,
1021 EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
1023 *Value = pEEPROM->efuse_eeprom_data[Offset];
1024 *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
1026 } // EFUSE_ShadowRead2Byte
1028 //---------------Read Four Bytes
1030 efuse_ShadowRead4Byte(
1031 IN PADAPTER pAdapter,
1035 EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
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;
1042 } // efuse_ShadowRead4Byte
1045 /*-----------------------------------------------------------------------------
1046 * Function: efuse_ShadowWrite1Byte
1047 * efuse_ShadowWrite2Byte
1048 * efuse_ShadowWrite4Byte
1050 * Overview: Write efuse modify map by one/two/four byte.
1060 * 11/12/2008 MHC Create Version 0.
1062 *---------------------------------------------------------------------------*/
1065 efuse_ShadowWrite1Byte(
1066 IN PADAPTER pAdapter,
1071 efuse_ShadowWrite1Byte(
1072 IN PADAPTER pAdapter,
1076 EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
1078 pEEPROM->efuse_eeprom_data[Offset] = Value;
1080 } // efuse_ShadowWrite1Byte
1082 //---------------Write Two Bytes
1084 efuse_ShadowWrite2Byte(
1085 IN PADAPTER pAdapter,
1089 EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
1091 pEEPROM->efuse_eeprom_data[Offset] = Value&0x00FF;
1092 pEEPROM->efuse_eeprom_data[Offset+1] = Value>>8;
1094 } // efuse_ShadowWrite1Byte
1096 //---------------Write Four Bytes
1098 efuse_ShadowWrite4Byte(
1099 IN PADAPTER pAdapter,
1103 EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
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);
1110 } // efuse_ShadowWrite1Byte
1112 /*-----------------------------------------------------------------------------
1113 * Function: EFUSE_ShadowMapUpdate
1115 * Overview: Transfer current EFUSE content to shadow init and modify map.
1125 * 11/13/2008 MHC Create Version 0.
1127 *---------------------------------------------------------------------------*/
1128 void EFUSE_ShadowMapUpdate(
1129 IN PADAPTER pAdapter,
1131 IN BOOLEAN bPseudoTest)
1133 EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
1136 EFUSE_GetEfuseDefinition(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN, (PVOID)&mapLen, bPseudoTest);
1138 if (pEEPROM->bautoload_fail_flag == _TRUE)
1140 _rtw_memset(pEEPROM->efuse_eeprom_data, 0xFF, mapLen);
1144 #ifdef CONFIG_ADAPTOR_INFO_CACHING_FILE
1145 if(_SUCCESS != retriveAdaptorInfoFile(pAdapter->registrypriv.adaptor_info_caching_file_path, pEEPROM)) {
1148 Efuse_ReadAllMap(pAdapter, efuseType, pEEPROM->efuse_eeprom_data, bPseudoTest);
1150 #ifdef CONFIG_ADAPTOR_INFO_CACHING_FILE
1151 storeAdaptorInfoFile(pAdapter->registrypriv.adaptor_info_caching_file_path, pEEPROM);
1156 //PlatformMoveMemory((PVOID)&pHalData->EfuseMap[EFUSE_MODIFY_MAP][0],
1157 //(PVOID)&pHalData->EfuseMap[EFUSE_INIT_MAP][0], mapLen);
1158 }// EFUSE_ShadowMapUpdate
1161 /*-----------------------------------------------------------------------------
1162 * Function: EFUSE_ShadowRead
1164 * Overview: Read from efuse init map !!!!!
1174 * 11/12/2008 MHC Create Version 0.
1176 *---------------------------------------------------------------------------*/
1179 IN PADAPTER pAdapter,
1185 efuse_ShadowRead1Byte(pAdapter, Offset, (u8 *)Value);
1187 efuse_ShadowRead2Byte(pAdapter, Offset, (u16 *)Value);
1189 efuse_ShadowRead4Byte(pAdapter, Offset, (u32 *)Value);
1191 } // EFUSE_ShadowRead
1193 /*-----------------------------------------------------------------------------
1194 * Function: EFUSE_ShadowWrite
1196 * Overview: Write efuse modify map for later update operation to use!!!!!
1206 * 11/12/2008 MHC Create Version 0.
1208 *---------------------------------------------------------------------------*/
1211 IN PADAPTER pAdapter,
1217 IN PADAPTER pAdapter,
1222 #if (MP_DRIVER == 0)
1225 if ( pAdapter->registrypriv.mp_mode == 0)
1230 efuse_ShadowWrite1Byte(pAdapter, Offset, (u8)Value);
1232 efuse_ShadowWrite2Byte(pAdapter, Offset, (u16)Value);
1234 efuse_ShadowWrite4Byte(pAdapter, Offset, (u32)Value);
1236 } // EFUSE_ShadowWrite
1240 IN PADAPTER pAdapter
1244 IN PADAPTER pAdapter
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);
1253 for(i=0; i<EFUSE_MAX_BT_BANK; i++)
1255 _rtw_memset((PVOID)&BTEfuseContent[i][0], EFUSE_MAX_HW_SIZE, 0xff);
1257 _rtw_memset((PVOID)&BTEfuseInitMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN);
1258 _rtw_memset((PVOID)&BTEfuseModifiedMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN);
1260 for(i=0; i<EFUSE_MAX_BT_BANK; i++)
1262 _rtw_memset((PVOID)&fakeBTEfuseContent[i][0], 0xff, EFUSE_MAX_HW_SIZE);
1264 _rtw_memset((PVOID)&fakeBTEfuseInitMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN);
1265 _rtw_memset((PVOID)&fakeBTEfuseModifiedMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN);
1268 #ifdef PLATFORM_LINUX
1269 #ifdef CONFIG_ADAPTOR_INFO_CACHING_FILE
1270 //#include <rtw_eeprom.h>
1272 int isAdaptorInfoFileValid(void)
1277 int storeAdaptorInfoFile(char *path, struct eeprom_priv * eeprom_priv)
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)
1288 DBG_871X("%s NULL pointer\n",__FUNCTION__);
1294 int retriveAdaptorInfoFile(char *path, struct eeprom_priv * eeprom_priv)
1300 if(path && eeprom_priv) {
1302 ret = rtw_retrive_from_file(path, eeprom_priv->efuse_eeprom_data, EEPROM_MAX_SIZE);
1304 if(ret == EEPROM_MAX_SIZE)
1310 if(isAdaptorInfoFileValid()) {
1318 DBG_871X("%s NULL pointer\n",__FUNCTION__);
1323 #endif //CONFIG_ADAPTOR_INFO_CACHING_FILE
1324 #endif //PLATFORM_LINUX
1326 #ifdef CONFIG_EFUSE_CONFIG_FILE
1328 void Rtw_Hal_ReadMACAddrFromFile(PADAPTER padapter)
1335 u32 curtime = rtw_get_current_time();
1336 EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
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};
1342 _rtw_memset(source_addr, 0, 18);
1343 _rtw_memset(pEEPROM->mac_addr, 0, ETH_ALEN);
1345 fp = filp_open("/data/wifimac.txt", O_RDWR, 0644);
1347 pEEPROM->bloadmac_fail_flag = _TRUE;
1348 DBG_871X("Error, wifi mac address file doesn't exist.\n");
1353 DBG_871X("wifi mac address:\n");
1354 vfs_read(fp, source_addr, 18, &pos);
1355 source_addr[17] = ':';
1357 head = end = source_addr;
1358 for (i=0; i<ETH_ALEN; i++) {
1359 while (end && (*end != ':') )
1362 if (end && (*end == ':') )
1365 pEEPROM->mac_addr[i] = simple_strtoul(head, NULL, 16 );
1371 DBG_871X("%02x \n", pEEPROM->mac_addr[i]);
1375 pEEPROM->bloadmac_fail_flag = _FALSE;
1376 filp_close(fp, NULL);
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) ;
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]);
1396 u32 Rtw_Hal_readPGDataFromConfigFile(PADAPTER padapter)
1403 EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
1404 u8 *PROMContent = pEEPROM->efuse_eeprom_data;
1407 temp[2] = 0; // add end of string '\0'
1409 fp = filp_open("/system/etc/wifi/wifi_efuse.map", O_RDWR, 0644);
1411 pEEPROM->bloadfile_fail_flag = _TRUE;
1412 DBG_871X("Error, Efuse configure file doesn't exist.\n");
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]);
1429 filp_close(fp, NULL);
1431 pEEPROM->bloadfile_fail_flag = _FALSE;
1436 #endif //#CONFIG_EFUSE_CONFIG_FILE