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 ******************************************************************************/
17 #include <drv_types.h>
18 #include <rtw_debug.h>
20 #include <linux/jiffies.h>
23 /*------------------------Define local variable------------------------------*/
25 u32 fakeEfuseUsedBytes = 0;
26 u8 fakeEfuseContent[EFUSE_MAX_HW_SIZE]={0};
27 u8 fakeEfuseInitMap[EFUSE_MAX_MAP_LEN]={0};
28 u8 fakeEfuseModifiedMap[EFUSE_MAX_MAP_LEN]={0};
30 u32 BTEfuseUsedBytes = 0;
31 u8 BTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
32 u8 BTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN]={0};
33 u8 BTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN]={0};
35 u32 fakeBTEfuseUsedBytes = 0;
36 u8 fakeBTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
37 u8 fakeBTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN]={0};
38 u8 fakeBTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN]={0};
39 /*------------------------Define local variable------------------------------*/
42 #define REG_EFUSE_CTRL 0x0030
43 #define EFUSE_CTRL REG_EFUSE_CTRL /* E-Fuse Control. */
47 Efuse_Read1ByteFromFakeContent(
48 struct adapter *padapter,
52 Efuse_Read1ByteFromFakeContent(
53 struct adapter *padapter,
57 if (Offset >= EFUSE_MAX_HW_SIZE)
61 /* DbgPrint("Read fake content, offset = %d\n", Offset); */
62 if (fakeEfuseBank == 0)
63 *Value = fakeEfuseContent[Offset];
65 *Value = fakeBTEfuseContent[fakeEfuseBank-1][Offset];
70 Efuse_Write1ByteToFakeContent(
71 struct adapter *padapter,
75 Efuse_Write1ByteToFakeContent(
76 struct adapter *padapter,
80 if (Offset >= EFUSE_MAX_HW_SIZE)
84 if (fakeEfuseBank == 0)
85 fakeEfuseContent[Offset] = Value;
88 fakeBTEfuseContent[fakeEfuseBank-1][Offset] = Value;
93 /*-----------------------------------------------------------------------------
94 * Function: Efuse_PowerSwitch
96 * Overview: When we want to enable write operation, we should change to
97 * pwr on state. When we stop write, we should switch to 500k mode
98 * and disable LDO 2.5V.
108 * 11/17/2008 MHC Create Version 0.
110 *---------------------------------------------------------------------------*/
113 struct adapter *padapter,
117 padapter->HalFunc.EfusePowerSwitch(padapter, bWrite, PwrState);
120 /*-----------------------------------------------------------------------------
121 * Function: Efuse_GetCurrentSize
123 * Overview: Get current efuse size!!!
133 * 11/16/2008 MHC Create Version 0.
135 *---------------------------------------------------------------------------*/
137 Efuse_GetCurrentSize(
138 struct adapter * padapter,
144 ret = padapter->HalFunc.EfuseGetCurrentSize(padapter, efuseType, bPseudoTest);
149 /* 11/16/2008 MH Add description. Get current efuse area enabled word!!. */
151 Efuse_CalculateWordCnts(u8 word_en)
154 if (!(word_en & BIT(0))) word_cnts++; /* 0 : write enable */
155 if (!(word_en & BIT(1))) word_cnts++;
156 if (!(word_en & BIT(2))) word_cnts++;
157 if (!(word_en & BIT(3))) word_cnts++;
163 /* 1. Execute E-Fuse read byte operation according as map offset and */
164 /* save to E-Fuse table. */
165 /* 2. Refered from SD1 Richard. */
168 /* 1. Boot from E-Fuse and successfully auto-load. */
169 /* 2. PASSIVE_LEVEL (USB interface) */
171 /* Created by Roger, 2008.10.21. */
173 /* 2008/12/12 MH 1. Reorganize code flow and reserve bytes. and add description. */
174 /* 2. Add efuse utilization collect. */
175 /* 2008/12/22 MH Read Efuse must check if we write section 1 data again!!! Sec1 */
176 /* write addr must be after sec5. */
181 struct adapter *Adapter,
190 struct adapter *Adapter,
198 Adapter->HalFunc.ReadEFuse(Adapter, efuseType, _offset, _size_byte, pbuf, bPseudoTest);
202 EFUSE_GetEfuseDefinition(
203 struct adapter *padapter,
210 padapter->HalFunc.EFUSEGetEfuseDefinition(padapter, efuseType, type, pOut, bPseudoTest);
213 /*-----------------------------------------------------------------------------
214 * Function: EFUSE_Read1Byte
216 * Overview: Copy from WMAC fot EFUSE read 1 byte.
226 * 09/23/2008 MHC Copy from WMAC.
228 *---------------------------------------------------------------------------*/
231 struct adapter *Adapter,
235 u8 Bytetemp = {0x00};
240 EFUSE_GetEfuseDefinition(Adapter, EFUSE_WIFI , TYPE_EFUSE_REAL_CONTENT_LEN, (void *)&contentLen, false);
242 if (Address < contentLen) /* E-fuse 512Byte */
244 /* Write E-fuse Register address bit0~7 */
245 temp = Address & 0xFF;
246 rtw_write8(Adapter, EFUSE_CTRL+1, temp);
247 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+2);
248 /* Write E-fuse Register address bit8~9 */
249 temp = ((Address >> 8) & 0x03) | (Bytetemp & 0xFC);
250 rtw_write8(Adapter, EFUSE_CTRL+2, temp);
252 /* Write 0x30[31]= 0 */
253 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
254 temp = Bytetemp & 0x7F;
255 rtw_write8(Adapter, EFUSE_CTRL+3, temp);
257 /* Wait Write-ready (0x30[31]= 1) */
258 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
259 while (!(Bytetemp & 0x80))
261 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
269 data =rtw_read8(Adapter, EFUSE_CTRL);
275 }/* EFUSE_Read1Byte */
277 /* 11/16/2008 MH Read one byte from real Efuse. */
280 struct adapter *padapter,
289 /* DBG_871X("===> EFUSE_OneByteRead(), addr = %x\n", addr); */
290 /* DBG_871X("===> EFUSE_OneByteRead() start, 0x34 = 0x%X\n", rtw_read32(padapter, EFUSE_TEST)); */
294 bResult = Efuse_Read1ByteFromFakeContent(padapter, addr, data);
298 /* <20130121, Kordan> For SMIC EFUSE specificatoin. */
299 /* 0x34[11]: SW force PGMEN input of efuse to high. (for the bank selected by 0x34[9:8]) */
300 /* PHY_SetMacReg(padapter, 0x34, BIT11, 0); */
301 rtw_write16(padapter, 0x34, rtw_read16(padapter, 0x34)& (~BIT11));
303 /* -----------------e-fuse reg ctrl --------------------------------- */
305 rtw_write8(padapter, EFUSE_CTRL+1, (u8)(addr&0xff));
306 rtw_write8(padapter, EFUSE_CTRL+2, ((u8)((addr>>8) &0x03)) |
307 (rtw_read8(padapter, EFUSE_CTRL+2)&0xFC));
309 /* rtw_write8(padapter, EFUSE_CTRL+3, 0x72); read cmd */
311 readbyte = rtw_read8(padapter, EFUSE_CTRL+3);
312 rtw_write8(padapter, EFUSE_CTRL+3, (readbyte & 0x7f));
314 while (!(0x80 &rtw_read8(padapter, EFUSE_CTRL+3)) && (tmpidx<1000))
321 *data =rtw_read8(padapter, EFUSE_CTRL);
328 DBG_871X("%s: [ERROR] addr = 0x%x bResult =%d time out 1s !!!\n", __func__, addr, bResult);
329 DBG_871X("%s: [ERROR] EFUSE_CTRL = 0x%08x !!!\n", __func__, rtw_read32(padapter, EFUSE_CTRL));
335 /* 11/16/2008 MH Write one byte to reald Efuse. */
338 struct adapter *padapter,
347 /* DBG_871X("===> EFUSE_OneByteWrite(), addr = %x data =%x\n", addr, data); */
348 /* DBG_871X("===> EFUSE_OneByteWrite() start, 0x34 = 0x%X\n", rtw_read32(padapter, EFUSE_TEST)); */
352 bResult = Efuse_Write1ByteToFakeContent(padapter, addr, data);
357 /* -----------------e-fuse reg ctrl --------------------------------- */
361 efuseValue = rtw_read32(padapter, EFUSE_CTRL);
362 efuseValue |= (BIT21|BIT31);
363 efuseValue &= ~(0x3FFFF);
364 efuseValue |= ((addr<<8 | data) & 0x3FFFF);
367 /* <20130227, Kordan> 8192E MP chip A-cut had better not set 0x34[11] until B-Cut. */
369 /* <20130121, Kordan> For SMIC EFUSE specificatoin. */
370 /* 0x34[11]: SW force PGMEN input of efuse to high. (for the bank selected by 0x34[9:8]) */
371 /* PHY_SetMacReg(padapter, 0x34, BIT11, 1); */
372 rtw_write16(padapter, 0x34, rtw_read16(padapter, 0x34)| (BIT11));
373 rtw_write32(padapter, EFUSE_CTRL, 0x90600000|((addr<<8 | data)));
375 while ((0x80 & rtw_read8(padapter, EFUSE_CTRL+3)) && (tmpidx<100)) {
387 DBG_871X("%s: [ERROR] addr = 0x%x , efuseValue = 0x%x , bResult =%d time out 1s !!!\n",
388 __func__, addr, efuseValue, bResult);
389 DBG_871X("%s: [ERROR] EFUSE_CTRL = 0x%08x !!!\n", __func__, rtw_read32(padapter, EFUSE_CTRL));
392 /* disable Efuse program enable */
393 PHY_SetMacReg(padapter, EFUSE_TEST, BIT(11), 0);
399 Efuse_PgPacketRead(struct adapter *padapter,
406 ret = padapter->HalFunc.Efuse_PgPacketRead(padapter, offset, data, bPseudoTest);
412 Efuse_PgPacketWrite(struct adapter *padapter,
420 ret = padapter->HalFunc.Efuse_PgPacketWrite(padapter, offset, word_en, data, bPseudoTest);
425 /*-----------------------------------------------------------------------------
426 * Function: efuse_WordEnableDataRead
428 * Overview: Read allowed word in current efuse section data.
438 * 11/16/2008 MHC Create Version 0.
439 * 11/21/2008 MHC Fix Write bug when we only enable late word.
441 *---------------------------------------------------------------------------*/
443 efuse_WordEnableDataRead(u8 word_en,
447 if (!(word_en&BIT(0)))
449 targetdata[0] = sourdata[0];
450 targetdata[1] = sourdata[1];
452 if (!(word_en&BIT(1)))
454 targetdata[2] = sourdata[2];
455 targetdata[3] = sourdata[3];
457 if (!(word_en&BIT(2)))
459 targetdata[4] = sourdata[4];
460 targetdata[5] = sourdata[5];
462 if (!(word_en&BIT(3)))
464 targetdata[6] = sourdata[6];
465 targetdata[7] = sourdata[7];
471 Efuse_WordEnableDataWrite(struct adapter *padapter,
479 ret = padapter->HalFunc.Efuse_WordEnableDataWrite(padapter, efuse_addr, word_en, data, bPseudoTest);
484 /*-----------------------------------------------------------------------------
485 * Function: Efuse_ReadAllMap
487 * Overview: Read All Efuse content
497 * 11/11/2008 MHC Create Version 0.
499 *---------------------------------------------------------------------------*/
502 struct adapter *padapter,
508 struct adapter *padapter,
515 Efuse_PowerSwitch(padapter, false, true);
517 EFUSE_GetEfuseDefinition(padapter, efuseType, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, bPseudoTest);
519 efuse_ReadEFuse(padapter, efuseType, 0, mapLen, Efuse, bPseudoTest);
521 Efuse_PowerSwitch(padapter, false, false);
524 /*-----------------------------------------------------------------------------
525 * Function: efuse_ShadowRead1Byte
526 * efuse_ShadowRead2Byte
527 * efuse_ShadowRead4Byte
529 * Overview: Read from efuse init map by one/two/four bytes !!!!!
539 * 11/12/2008 MHC Create Version 0.
541 *---------------------------------------------------------------------------*/
543 efuse_ShadowRead1Byte(
544 struct adapter *padapter,
548 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
550 *Value = pEEPROM->efuse_eeprom_data[Offset];
552 } /* EFUSE_ShadowRead1Byte */
556 efuse_ShadowRead2Byte(
557 struct adapter *padapter,
561 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
563 *Value = pEEPROM->efuse_eeprom_data[Offset];
564 *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
566 } /* EFUSE_ShadowRead2Byte */
568 /* Read Four Bytes */
570 efuse_ShadowRead4Byte(
571 struct adapter *padapter,
575 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
577 *Value = pEEPROM->efuse_eeprom_data[Offset];
578 *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
579 *Value |= pEEPROM->efuse_eeprom_data[Offset+2]<<16;
580 *Value |= pEEPROM->efuse_eeprom_data[Offset+3]<<24;
582 } /* efuse_ShadowRead4Byte */
584 /*-----------------------------------------------------------------------------
585 * Function: EFUSE_ShadowMapUpdate
587 * Overview: Transfer current EFUSE content to shadow init and modify map.
597 * 11/13/2008 MHC Create Version 0.
599 *---------------------------------------------------------------------------*/
600 void EFUSE_ShadowMapUpdate(
601 struct adapter *padapter,
605 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
608 EFUSE_GetEfuseDefinition(padapter, efuseType, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, bPseudoTest);
610 if (pEEPROM->bautoload_fail_flag == true)
612 memset(pEEPROM->efuse_eeprom_data, 0xFF, mapLen);
616 Efuse_ReadAllMap(padapter, efuseType, pEEPROM->efuse_eeprom_data, bPseudoTest);
619 /* PlatformMoveMemory((void *)&pHalData->EfuseMap[EFUSE_MODIFY_MAP][0], */
620 /* void *)&pHalData->EfuseMap[EFUSE_INIT_MAP][0], mapLen); */
621 }/* EFUSE_ShadowMapUpdate */
624 /*-----------------------------------------------------------------------------
625 * Function: EFUSE_ShadowRead
627 * Overview: Read from efuse init map !!!!!
637 * 11/12/2008 MHC Create Version 0.
639 *---------------------------------------------------------------------------*/
642 struct adapter *padapter,
648 efuse_ShadowRead1Byte(padapter, Offset, (u8 *)Value);
650 efuse_ShadowRead2Byte(padapter, Offset, (u16 *)Value);
652 efuse_ShadowRead4Byte(padapter, Offset, (u32 *)Value);
654 } // EFUSE_ShadowRead