1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5  *
6  ******************************************************************************/
7 #ifndef __RTW_EFUSE_H__
8 #define __RTW_EFUSE_H__
9 
10 #define	PGPKT_DATA_SIZE		8
11 
12 #define	EFUSE_WIFI				0
13 #define	EFUSE_BT				1
14 
15 enum {
16 	TYPE_EFUSE_MAX_SECTION				= 0,
17 	TYPE_EFUSE_REAL_CONTENT_LEN			= 1,
18 	TYPE_AVAILABLE_EFUSE_BYTES_BANK		= 2,
19 	TYPE_AVAILABLE_EFUSE_BYTES_TOTAL	= 3,
20 	TYPE_EFUSE_MAP_LEN					= 4,
21 	TYPE_EFUSE_PROTECT_BYTES_BANK		= 5,
22 	TYPE_EFUSE_CONTENT_LEN_BANK			= 6,
23 };
24 
25 #define		EFUSE_MAX_MAP_LEN		512
26 
27 #define		EFUSE_MAX_HW_SIZE		512
28 #define		EFUSE_MAX_SECTION_BASE	16
29 
30 #define EXT_HEADER(header) ((header & 0x1F) == 0x0F)
31 #define ALL_WORDS_DISABLED(wde)	((wde & 0x0F) == 0x0F)
32 #define GET_HDR_OFFSET_2_0(header) ((header & 0xE0) >> 5)
33 
34 #define		EFUSE_REPEAT_THRESHOLD_			3
35 
36 /*  */
37 /* 	The following is for BT Efuse definition */
38 /*  */
39 #define		EFUSE_BT_MAX_MAP_LEN		1024
40 #define		EFUSE_MAX_BANK			4
41 #define		EFUSE_MAX_BT_BANK		(EFUSE_MAX_BANK-1)
42 /*  */
43 /*--------------------------Define Parameters-------------------------------*/
44 #define		EFUSE_MAX_WORD_UNIT			4
45 
46 /*------------------------------Define structure----------------------------*/
47 struct pgpkt_struct {
48 	u8 offset;
49 	u8 word_en;
50 	u8 data[8];
51 	u8 word_cnts;
52 };
53 
54 /*------------------------------Define structure----------------------------*/
55 struct efuse_hal {
56 	u8 fakeEfuseBank;
57 	u32 fakeEfuseUsedBytes;
58 	u8 fakeEfuseContent[EFUSE_MAX_HW_SIZE];
59 	u8 fakeEfuseInitMap[EFUSE_MAX_MAP_LEN];
60 	u8 fakeEfuseModifiedMap[EFUSE_MAX_MAP_LEN];
61 
62 	u16 BTEfuseUsedBytes;
63 	u8 BTEfuseUsedPercentage;
64 	u8 BTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
65 	u8 BTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN];
66 	u8 BTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN];
67 
68 	u16 fakeBTEfuseUsedBytes;
69 	u8 fakeBTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
70 	u8 fakeBTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN];
71 	u8 fakeBTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN];
72 };
73 
74 
75 /*------------------------Export global variable----------------------------*/
76 extern u8 fakeEfuseBank;
77 extern u32 fakeEfuseUsedBytes;
78 extern u8 fakeEfuseContent[];
79 extern u8 fakeEfuseInitMap[];
80 extern u8 fakeEfuseModifiedMap[];
81 
82 extern u32 BTEfuseUsedBytes;
83 extern u8 BTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
84 extern u8 BTEfuseInitMap[];
85 extern u8 BTEfuseModifiedMap[];
86 
87 extern u32 fakeBTEfuseUsedBytes;
88 extern u8 fakeBTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
89 extern u8 fakeBTEfuseInitMap[];
90 extern u8 fakeBTEfuseModifiedMap[];
91 /*------------------------Export global variable----------------------------*/
92 
93 u16 Efuse_GetCurrentSize(struct adapter *padapter, u8 efuseType, bool bPseudoTest);
94 u8 Efuse_CalculateWordCnts(u8 word_en);
95 void EFUSE_GetEfuseDefinition(struct adapter *padapter, u8 efuseType, u8 type, void *pOut, bool bPseudoTest);
96 u8 efuse_OneByteRead(struct adapter *padapter, u16 addr, u8 *data, bool	 bPseudoTest);
97 u8 efuse_OneByteWrite(struct adapter *padapter, u16 addr, u8 data, bool	 bPseudoTest);
98 
99 void Efuse_PowerSwitch(struct adapter *padapter, u8 bWrite, u8  PwrState);
100 int	Efuse_PgPacketRead(struct adapter *padapter, u8 offset, u8 *data, bool bPseudoTest);
101 int	Efuse_PgPacketWrite(struct adapter *padapter, u8 offset, u8 word_en, u8 *data, bool bPseudoTest);
102 void efuse_WordEnableDataRead(u8 word_en, u8 *sourdata, u8 *targetdata);
103 u8 Efuse_WordEnableDataWrite(struct adapter *padapter, u16 efuse_addr, u8 word_en, u8 *data, bool bPseudoTest);
104 
105 u8 EFUSE_Read1Byte(struct adapter *padapter, u16 Address);
106 void EFUSE_ShadowMapUpdate(struct adapter *padapter, u8 efuseType, bool bPseudoTest);
107 void EFUSE_ShadowRead(struct adapter *padapter, u8 Type, u16 Offset, u32 *Value);
108 void Rtw_Hal_ReadMACAddrFromFile(struct adapter *padapter);
109 u32 Rtw_Hal_readPGDataFromConfigFile(struct adapter *padapter);
110 
111 #endif
112