aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/rtl8723bs/hal/hal_phy.c
blob: ebaefcaf5f2ae603ab0e986780cd84289fe8d588 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// SPDX-License-Identifier: GPL-2.0
/******************************************************************************
 *
 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
 *
 ******************************************************************************/
#define _HAL_PHY_C_

#include <drv_types.h>

/**
* Function:	PHY_CalculateBitShift
*
* OverView:	Get shifted position of the BitMask
*
* Input:
*		u32 	BitMask,
*
* Output:	none
* Return:		u32 	Return the shift bit bit position of the mask
*/
u32 PHY_CalculateBitShift(u32 BitMask)
{
	u32 i;

	for (i = 0; i <= 31; i++) {
		if (((BitMask>>i) &  0x1) == 1)
			break;
	}

	return i;
}


/*  */
/*  ==> RF shadow Operation API Code Section!!! */
/*  */
/*-----------------------------------------------------------------------------
 * Function:	PHY_RFShadowRead
 *			PHY_RFShadowWrite
 *			PHY_RFShadowCompare
 *			PHY_RFShadowRecorver
 *			PHY_RFShadowCompareAll
 *			PHY_RFShadowRecorverAll
 *			PHY_RFShadowCompareFlagSet
 *			PHY_RFShadowRecorverFlagSet
 *
 * Overview:	When we set RF register, we must write shadow at first.
 *		When we are running, we must compare shadow abd locate error addr.
 *		Decide to recorver or not.
 *
 * Input:       NONE
 *
 * Output:      NONE
 *
 * Return:      NONE
 *
 * Revised History:
 * When			Who		Remark
 * 11/20/2008	MHC		Create Version 0.
 *
 *---------------------------------------------------------------------------*/
u32 PHY_RFShadowRead(IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset)
{
	return	RF_Shadow[eRFPath][Offset].Value;

}	/* PHY_RFShadowRead */


void PHY_RFShadowWrite(
	IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset, IN u32 Data
)
{
	RF_Shadow[eRFPath][Offset].Value = (Data & bRFRegOffsetMask);
	RF_Shadow[eRFPath][Offset].Driver_Write = true;

}	/* PHY_RFShadowWrite */


bool PHY_RFShadowCompare(IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset)
{
	u32 reg;
	/*  Check if we need to check the register */
	if (RF_Shadow[eRFPath][Offset].Compare == true) {
		reg = rtw_hal_read_rfreg(Adapter, eRFPath, Offset, bRFRegOffsetMask);
		/*  Compare shadow and real rf register for 20bits!! */
		if (RF_Shadow[eRFPath][Offset].Value != reg) {
			/*  Locate error position. */
			RF_Shadow[eRFPath][Offset].ErrorOrNot = true;
			/* RT_TRACE(COMP_INIT, DBG_LOUD, */
			/* PHY_RFShadowCompare RF-%d Addr%02lx Err = %05lx\n", */
			/* eRFPath, Offset, reg)); */
		}
		return RF_Shadow[eRFPath][Offset].ErrorOrNot;
	}
	return false;
}	/* PHY_RFShadowCompare */


void PHY_RFShadowRecorver(IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset)
{
	/*  Check if the address is error */
	if (RF_Shadow[eRFPath][Offset].ErrorOrNot == true) {
		/*  Check if we need to recorver the register. */
		if (RF_Shadow[eRFPath][Offset].Recorver == true) {
			rtw_hal_write_rfreg(Adapter, eRFPath, Offset, bRFRegOffsetMask,
							RF_Shadow[eRFPath][Offset].Value);
			/* RT_TRACE(COMP_INIT, DBG_LOUD, */
			/* PHY_RFShadowRecorver RF-%d Addr%02lx=%05lx", */
			/* eRFPath, Offset, RF_Shadow[eRFPath][Offset].Value)); */
		}
	}

}	/* PHY_RFShadowRecorver */


void PHY_RFShadowCompareAll(IN PADAPTER Adapter)
{
	u8 eRFPath = 0;
	u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);

	for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
		for (Offset = 0; Offset < maxReg; Offset++) {
			PHY_RFShadowCompare(Adapter, eRFPath, Offset);
		}
	}

}	/* PHY_RFShadowCompareAll */


void PHY_RFShadowRecorverAll(IN PADAPTER Adapter)
{
	u8 eRFPath = 0;
	u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);

	for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
		for (Offset = 0; Offset < maxReg; Offset++) {
			PHY_RFShadowRecorver(Adapter, eRFPath, Offset);
		}
	}

}	/* PHY_RFShadowRecorverAll */


void
PHY_RFShadowCompareFlagSet(
	IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset, IN u8 Type
)
{
	/*  Set True or False!!! */
	RF_Shadow[eRFPath][Offset].Compare = Type;

}	/* PHY_RFShadowCompareFlagSet */


void PHY_RFShadowRecorverFlagSet(
	IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset, IN u8 Type
)
{
	/*  Set True or False!!! */
	RF_Shadow[eRFPath][Offset].Recorver = Type;

}	/* PHY_RFShadowRecorverFlagSet */


void PHY_RFShadowCompareFlagSetAll(IN PADAPTER Adapter)
{
	u8 eRFPath = 0;
	u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);

	for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
		for (Offset = 0; Offset < maxReg; Offset++) {
			/*  2008/11/20 MH For S3S4 test, we only check reg 26/27 now!!!! */
			if (Offset != 0x26 && Offset != 0x27)
				PHY_RFShadowCompareFlagSet(Adapter, eRFPath, Offset, false);
			else
				PHY_RFShadowCompareFlagSet(Adapter, eRFPath, Offset, true);
		}
	}

}	/* PHY_RFShadowCompareFlagSetAll */


void PHY_RFShadowRecorverFlagSetAll(IN PADAPTER Adapter)
{
	u8 eRFPath = 0;
	u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);

	for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
		for (Offset = 0; Offset < maxReg; Offset++) {
			/*  2008/11/20 MH For S3S4 test, we only check reg 26/27 now!!!! */
			if (Offset != 0x26 && Offset != 0x27)
				PHY_RFShadowRecorverFlagSet(Adapter, eRFPath, Offset, false);
			else
				PHY_RFShadowRecorverFlagSet(Adapter, eRFPath, Offset, true);
		}
	}

}	/* PHY_RFShadowCompareFlagSetAll */

void PHY_RFShadowRefresh(IN PADAPTER Adapter)
{
	u8 eRFPath = 0;
	u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);

	for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
		for (Offset = 0; Offset < maxReg; Offset++) {
			RF_Shadow[eRFPath][Offset].Value = 0;
			RF_Shadow[eRFPath][Offset].Compare = false;
			RF_Shadow[eRFPath][Offset].Recorver  = false;
			RF_Shadow[eRFPath][Offset].ErrorOrNot = false;
			RF_Shadow[eRFPath][Offset].Driver_Write = false;
		}
	}

}	/* PHY_RFShadowRead */