hal_phy.c 6.22 KB
Newer Older
Tony Feng committed
1 2
/******************************************************************************
 *
3 4
 * Copyright(c) 2007 - 2017 Realtek Corporation.
 *
Tony Feng committed
5 6 7 8 9 10 11 12 13
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
14
 *****************************************************************************/
Tony Feng committed
15 16 17 18
#define _HAL_PHY_C_

#include <drv_types.h>

19 20 21 22
/* ********************************************************************************
 *	Constant.
 * ********************************************************************************
 * 2008/11/20 MH For Debug only, RF */
Tony Feng committed
23 24 25 26 27 28 29 30
static RF_SHADOW_T RF_Shadow[RF6052_MAX_PATH][RF6052_MAX_REG];

/**
* Function:	PHY_CalculateBitShift
*
* OverView:	Get shifted position of the BitMask
*
* Input:
31
*			u4Byte		BitMask,
Tony Feng committed
32 33 34 35 36 37 38
*
* Output:	none
* Return:		u4Byte		Return the shift bit bit position of the mask
*/
u32
PHY_CalculateBitShift(
	u32 BitMask
39
)
Tony Feng committed
40 41 42
{
	u32 i;

43 44
	for (i = 0; i <= 31; i++) {
		if (((BitMask >> i) &  0x1) == 1)
Tony Feng committed
45 46 47
			break;
	}

48
	return i;
Tony Feng committed
49 50 51
}


52 53 54 55
/*
 * ==> RF shadow Operation API Code Section!!!
 *
 *-----------------------------------------------------------------------------
Tony Feng committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
 * 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
77
 * 11/20/2008	MHC		Create Version 0.
Tony Feng committed
78 79 80 81 82
 *
 *---------------------------------------------------------------------------*/
u32
PHY_RFShadowRead(
	IN	PADAPTER		Adapter,
83
	IN	enum rf_path		eRFPath,
Tony Feng committed
84 85 86 87 88 89 90 91 92 93
	IN	u32				Offset)
{
	return	RF_Shadow[eRFPath][Offset].Value;

}	/* PHY_RFShadowRead */


VOID
PHY_RFShadowWrite(
	IN	PADAPTER		Adapter,
94
	IN	enum rf_path		eRFPath,
Tony Feng committed
95 96 97 98 99 100 101 102 103 104 105 106
	IN	u32				Offset,
	IN	u32				Data)
{
	RF_Shadow[eRFPath][Offset].Value = (Data & bRFRegOffsetMask);
	RF_Shadow[eRFPath][Offset].Driver_Write = _TRUE;

}	/* PHY_RFShadowWrite */


BOOLEAN
PHY_RFShadowCompare(
	IN	PADAPTER		Adapter,
107
	IN	enum rf_path		eRFPath,
Tony Feng committed
108 109 110
	IN	u32				Offset)
{
	u32	reg;
111 112
	/* Check if we need to check the register */
	if (RF_Shadow[eRFPath][Offset].Compare == _TRUE) {
Tony Feng committed
113
		reg = rtw_hal_read_rfreg(Adapter, eRFPath, Offset, bRFRegOffsetMask);
114 115 116
		/* Compare shadow and real rf register for 20bits!! */
		if (RF_Shadow[eRFPath][Offset].Value != reg) {
			/* Locate error position. */
Tony Feng committed
117 118 119 120 121 122 123 124 125 126 127
			RF_Shadow[eRFPath][Offset].ErrorOrNot = _TRUE;
		}
		return RF_Shadow[eRFPath][Offset].ErrorOrNot ;
	}
	return _FALSE;
}	/* PHY_RFShadowCompare */


VOID
PHY_RFShadowRecorver(
	IN	PADAPTER		Adapter,
128
	IN	enum rf_path		eRFPath,
Tony Feng committed
129 130
	IN	u32				Offset)
{
131 132 133 134
	/* 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) {
Tony Feng committed
135
			rtw_hal_write_rfreg(Adapter, eRFPath, Offset, bRFRegOffsetMask,
136
					    RF_Shadow[eRFPath][Offset].Value);
Tony Feng committed
137 138 139 140 141 142 143 144 145 146
		}
	}

}	/* PHY_RFShadowRecorver */


VOID
PHY_RFShadowCompareAll(
	IN	PADAPTER			Adapter)
{
147 148
	enum rf_path	eRFPath = RF_PATH_A;
	u32		Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
Tony Feng committed
149

150
	for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
Tony Feng committed
151 152 153 154 155 156 157 158 159 160 161
		for (Offset = 0; Offset < maxReg; Offset++)
			PHY_RFShadowCompare(Adapter, eRFPath, Offset);
	}

}	/* PHY_RFShadowCompareAll */


VOID
PHY_RFShadowRecorverAll(
	IN	PADAPTER			Adapter)
{
162 163
	enum rf_path		eRFPath = RF_PATH_A;
	u32		Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
Tony Feng committed
164

165
	for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
Tony Feng committed
166 167 168 169 170 171 172 173 174 175
		for (Offset = 0; Offset < maxReg; Offset++)
			PHY_RFShadowRecorver(Adapter, eRFPath, Offset);
	}

}	/* PHY_RFShadowRecorverAll */


VOID
PHY_RFShadowCompareFlagSet(
	IN	PADAPTER		Adapter,
176
	IN	enum rf_path		eRFPath,
Tony Feng committed
177 178 179
	IN	u32				Offset,
	IN	u8				Type)
{
180
	/* Set True or False!!! */
Tony Feng committed
181 182 183 184 185 186 187 188
	RF_Shadow[eRFPath][Offset].Compare = Type;

}	/* PHY_RFShadowCompareFlagSet */


VOID
PHY_RFShadowRecorverFlagSet(
	IN	PADAPTER		Adapter,
189
	IN	enum rf_path		eRFPath,
Tony Feng committed
190 191 192
	IN	u32				Offset,
	IN	u8				Type)
{
193 194
	/* Set True or False!!! */
	RF_Shadow[eRFPath][Offset].Recorver = Type;
Tony Feng committed
195 196 197 198 199 200 201 202

}	/* PHY_RFShadowRecorverFlagSet */


VOID
PHY_RFShadowCompareFlagSetAll(
	IN	PADAPTER			Adapter)
{
203 204
	enum rf_path	eRFPath = RF_PATH_A;
	u32		Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
Tony Feng committed
205

206 207 208
	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!!!! */
Tony Feng committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222
			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)
{
223 224
	enum rf_path		eRFPath = RF_PATH_A;
	u32		Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
Tony Feng committed
225

226 227 228
	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!!!! */
Tony Feng committed
229 230 231 232 233 234 235 236 237 238 239 240 241
			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)
{
242 243
	enum rf_path		eRFPath = RF_PATH_A;
	u32		Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
Tony Feng committed
244

245 246
	for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
		for (Offset = 0; Offset < maxReg; Offset++) {
Tony Feng committed
247 248 249 250 251 252 253 254 255
			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 */