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