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) {
60 /* DbgPrint("Read fake content, offset = %d\n", Offset); */
61 if (fakeEfuseBank == 0)
62 *Value = fakeEfuseContent[Offset];
64 *Value = fakeBTEfuseContent[fakeEfuseBank-1][Offset];
69 Efuse_Write1ByteToFakeContent(
70 struct adapter *padapter,
74 Efuse_Write1ByteToFakeContent(
75 struct adapter *padapter,
79 if (Offset >= EFUSE_MAX_HW_SIZE) {
82 if (fakeEfuseBank == 0)
83 fakeEfuseContent[Offset] = Value;
85 fakeBTEfuseContent[fakeEfuseBank-1][Offset] = Value;
90 /*-----------------------------------------------------------------------------
91 * Function: Efuse_PowerSwitch
93 * Overview: When we want to enable write operation, we should change to
94 * pwr on state. When we stop write, we should switch to 500k mode
95 * and disable LDO 2.5V.
105 * 11/17/2008 MHC Create Version 0.
107 *---------------------------------------------------------------------------*/
110 struct adapter *padapter,
114 padapter->HalFunc.EfusePowerSwitch(padapter, bWrite, PwrState);
117 /*-----------------------------------------------------------------------------
118 * Function: Efuse_GetCurrentSize
120 * Overview: Get current efuse size!!!
130 * 11/16/2008 MHC Create Version 0.
132 *---------------------------------------------------------------------------*/
134 Efuse_GetCurrentSize(
135 struct adapter *padapter,
141 ret = padapter->HalFunc.EfuseGetCurrentSize(padapter, efuseType, bPseudoTest);
146 /* 11/16/2008 MH Add description. Get current efuse area enabled word!!. */
148 Efuse_CalculateWordCnts(u8 word_en)
151 if (!(word_en & BIT(0)))
152 word_cnts++; /* 0 : write enable */
153 if (!(word_en & BIT(1)))
155 if (!(word_en & BIT(2)))
157 if (!(word_en & BIT(3)))
164 /* 1. Execute E-Fuse read byte operation according as map offset and */
165 /* save to E-Fuse table. */
166 /* 2. Refered from SD1 Richard. */
169 /* 1. Boot from E-Fuse and successfully auto-load. */
170 /* 2. PASSIVE_LEVEL (USB interface) */
172 /* Created by Roger, 2008.10.21. */
174 /* 2008/12/12 MH 1. Reorganize code flow and reserve bytes. and add description. */
175 /* 2. Add efuse utilization collect. */
176 /* 2008/12/22 MH Read Efuse must check if we write section 1 data again!!! Sec1 */
177 /* write addr must be after sec5. */
182 struct adapter *Adapter,
191 struct adapter *Adapter,
199 Adapter->HalFunc.ReadEFuse(Adapter, efuseType, _offset, _size_byte, pbuf, bPseudoTest);
203 EFUSE_GetEfuseDefinition(
204 struct adapter *padapter,
211 padapter->HalFunc.EFUSEGetEfuseDefinition(padapter, efuseType, type, pOut, bPseudoTest);
214 /*-----------------------------------------------------------------------------
215 * Function: EFUSE_Read1Byte
217 * Overview: Copy from WMAC fot EFUSE read 1 byte.
227 * 09/23/2008 MHC Copy from WMAC.
229 *---------------------------------------------------------------------------*/
232 struct adapter *Adapter,
236 u8 Bytetemp = {0x00};
241 EFUSE_GetEfuseDefinition(Adapter, EFUSE_WIFI, TYPE_EFUSE_REAL_CONTENT_LEN, (void *)&contentLen, false);
243 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)) {
260 Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
267 data = rtw_read8(Adapter, EFUSE_CTRL);
272 } /* EFUSE_Read1Byte */
274 /* 11/16/2008 MH Read one byte from real Efuse. */
277 struct adapter *padapter,
286 /* DBG_871X("===> EFUSE_OneByteRead(), addr = %x\n", addr); */
287 /* DBG_871X("===> EFUSE_OneByteRead() start, 0x34 = 0x%X\n", rtw_read32(padapter, EFUSE_TEST)); */
290 bResult = Efuse_Read1ByteFromFakeContent(padapter, addr, data);
294 /* <20130121, Kordan> For SMIC EFUSE specificatoin. */
295 /* 0x34[11]: SW force PGMEN input of efuse to high. (for the bank selected by 0x34[9:8]) */
296 /* PHY_SetMacReg(padapter, 0x34, BIT11, 0); */
297 rtw_write16(padapter, 0x34, rtw_read16(padapter, 0x34) & (~BIT11));
299 /* -----------------e-fuse reg ctrl --------------------------------- */
301 rtw_write8(padapter, EFUSE_CTRL+1, (u8)(addr&0xff));
302 rtw_write8(padapter, EFUSE_CTRL+2, ((u8)((addr>>8) & 0x03)) |
303 (rtw_read8(padapter, EFUSE_CTRL+2)&0xFC));
305 /* rtw_write8(padapter, EFUSE_CTRL+3, 0x72); read cmd */
307 readbyte = rtw_read8(padapter, EFUSE_CTRL+3);
308 rtw_write8(padapter, EFUSE_CTRL+3, (readbyte & 0x7f));
310 while (!(0x80 & rtw_read8(padapter, EFUSE_CTRL+3)) && (tmpidx < 1000)) {
315 *data = rtw_read8(padapter, EFUSE_CTRL);
320 DBG_871X("%s: [ERROR] addr = 0x%x bResult =%d time out 1s !!!\n", __func__, addr, bResult);
321 DBG_871X("%s: [ERROR] EFUSE_CTRL = 0x%08x !!!\n", __func__, rtw_read32(padapter, EFUSE_CTRL));
327 /* 11/16/2008 MH Write one byte to reald Efuse. */
330 struct adapter *padapter,
339 /* DBG_871X("===> EFUSE_OneByteWrite(), addr = %x data =%x\n", addr, data); */
340 /* DBG_871X("===> EFUSE_OneByteWrite() start, 0x34 = 0x%X\n", rtw_read32(padapter, EFUSE_TEST)); */
343 bResult = Efuse_Write1ByteToFakeContent(padapter, addr, data);
348 /* -----------------e-fuse reg ctrl --------------------------------- */
352 efuseValue = rtw_read32(padapter, EFUSE_CTRL);
353 efuseValue |= (BIT21|BIT31);
354 efuseValue &= ~(0x3FFFF);
355 efuseValue |= ((addr<<8 | data) & 0x3FFFF);
358 /* <20130227, Kordan> 8192E MP chip A-cut had better not set 0x34[11] until B-Cut. */
360 /* <20130121, Kordan> For SMIC EFUSE specificatoin. */
361 /* 0x34[11]: SW force PGMEN input of efuse to high. (for the bank selected by 0x34[9:8]) */
362 /* PHY_SetMacReg(padapter, 0x34, BIT11, 1); */
363 rtw_write16(padapter, 0x34, rtw_read16(padapter, 0x34) | (BIT11));
364 rtw_write32(padapter, EFUSE_CTRL, 0x90600000|((addr<<8 | data)));
366 while ((0x80 & rtw_read8(padapter, EFUSE_CTRL+3)) && (tmpidx < 100)) {
375 DBG_871X("%s: [ERROR] addr = 0x%x , efuseValue = 0x%x , bResult =%d time out 1s !!!\n",
376 __func__, addr, efuseValue, bResult);
377 DBG_871X("%s: [ERROR] EFUSE_CTRL = 0x%08x !!!\n", __func__, rtw_read32(padapter, EFUSE_CTRL));
380 /* disable Efuse program enable */
381 PHY_SetMacReg(padapter, EFUSE_TEST, BIT(11), 0);
387 Efuse_PgPacketRead(struct adapter *padapter,
394 ret = padapter->HalFunc.Efuse_PgPacketRead(padapter, offset, data, bPseudoTest);
400 Efuse_PgPacketWrite(struct adapter *padapter,
408 ret = padapter->HalFunc.Efuse_PgPacketWrite(padapter, offset, word_en, data, bPseudoTest);
413 /*-----------------------------------------------------------------------------
414 * Function: efuse_WordEnableDataRead
416 * Overview: Read allowed word in current efuse section data.
426 * 11/16/2008 MHC Create Version 0.
427 * 11/21/2008 MHC Fix Write bug when we only enable late word.
429 *---------------------------------------------------------------------------*/
431 efuse_WordEnableDataRead(u8 word_en,
435 if (!(word_en&BIT(0))) {
436 targetdata[0] = sourdata[0];
437 targetdata[1] = sourdata[1];
439 if (!(word_en&BIT(1))) {
440 targetdata[2] = sourdata[2];
441 targetdata[3] = sourdata[3];
443 if (!(word_en&BIT(2))) {
444 targetdata[4] = sourdata[4];
445 targetdata[5] = sourdata[5];
447 if (!(word_en&BIT(3))) {
448 targetdata[6] = sourdata[6];
449 targetdata[7] = sourdata[7];
455 Efuse_WordEnableDataWrite(struct adapter *padapter,
463 ret = padapter->HalFunc.Efuse_WordEnableDataWrite(padapter, efuse_addr, word_en, data, bPseudoTest);
468 /*-----------------------------------------------------------------------------
469 * Function: Efuse_ReadAllMap
471 * Overview: Read All Efuse content
481 * 11/11/2008 MHC Create Version 0.
483 *---------------------------------------------------------------------------*/
486 struct adapter *padapter,
492 struct adapter *padapter,
499 Efuse_PowerSwitch(padapter, false, true);
501 EFUSE_GetEfuseDefinition(padapter, efuseType, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, bPseudoTest);
503 efuse_ReadEFuse(padapter, efuseType, 0, mapLen, Efuse, bPseudoTest);
505 Efuse_PowerSwitch(padapter, false, false);
508 /*-----------------------------------------------------------------------------
509 * Function: efuse_ShadowRead1Byte
510 * efuse_ShadowRead2Byte
511 * efuse_ShadowRead4Byte
513 * Overview: Read from efuse init map by one/two/four bytes !!!!!
523 * 11/12/2008 MHC Create Version 0.
525 *---------------------------------------------------------------------------*/
527 efuse_ShadowRead1Byte(
528 struct adapter *padapter,
532 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
534 *Value = pEEPROM->efuse_eeprom_data[Offset];
536 } /* EFUSE_ShadowRead1Byte */
540 efuse_ShadowRead2Byte(
541 struct adapter *padapter,
545 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
547 *Value = pEEPROM->efuse_eeprom_data[Offset];
548 *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
550 } /* EFUSE_ShadowRead2Byte */
552 /* Read Four Bytes */
554 efuse_ShadowRead4Byte(
555 struct adapter *padapter,
559 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
561 *Value = pEEPROM->efuse_eeprom_data[Offset];
562 *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
563 *Value |= pEEPROM->efuse_eeprom_data[Offset+2]<<16;
564 *Value |= pEEPROM->efuse_eeprom_data[Offset+3]<<24;
566 } /* efuse_ShadowRead4Byte */
568 /*-----------------------------------------------------------------------------
569 * Function: EFUSE_ShadowMapUpdate
571 * Overview: Transfer current EFUSE content to shadow init and modify map.
581 * 11/13/2008 MHC Create Version 0.
583 *---------------------------------------------------------------------------*/
584 void EFUSE_ShadowMapUpdate(
585 struct adapter *padapter,
589 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
592 EFUSE_GetEfuseDefinition(padapter, efuseType, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, bPseudoTest);
594 if (pEEPROM->bautoload_fail_flag == true) {
595 memset(pEEPROM->efuse_eeprom_data, 0xFF, mapLen);
597 Efuse_ReadAllMap(padapter, efuseType, pEEPROM->efuse_eeprom_data, bPseudoTest);
600 /* PlatformMoveMemory((void *)&pHalData->EfuseMap[EFUSE_MODIFY_MAP][0], */
601 /* void *)&pHalData->EfuseMap[EFUSE_INIT_MAP][0], mapLen); */
602 } /* EFUSE_ShadowMapUpdate */
605 /*-----------------------------------------------------------------------------
606 * Function: EFUSE_ShadowRead
608 * Overview: Read from efuse init map !!!!!
618 * 11/12/2008 MHC Create Version 0.
620 *---------------------------------------------------------------------------*/
623 struct adapter *padapter,
629 efuse_ShadowRead1Byte(padapter, Offset, (u8 *)Value);
631 efuse_ShadowRead2Byte(padapter, Offset, (u16 *)Value);
633 efuse_ShadowRead4Byte(padapter, Offset, (u32 *)Value);
635 } /* EFUSE_ShadowRead*/