Commit 170ee4d2 authored by Bartlomiej Zolnierkiewicz's avatar Bartlomiej Zolnierkiewicz Committed by Greg Kroah-Hartman

Staging: rtxxx0: unify RT{USB,MP}FilterCalibration()

RTMP_BBP_IO_{READ,WRITE}8_BY_REG_ID equals RTUSB{Read,Write}BBPRegister
in case of USB chipsets so unify RT30xx and !RT30xx code.
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 37843390
...@@ -1099,145 +1099,6 @@ NDIS_STATUS NICReadRegParameters( ...@@ -1099,145 +1099,6 @@ NDIS_STATUS NICReadRegParameters(
======================================================================== ========================================================================
*/ */
#ifndef RT30xx
VOID RTUSBFilterCalibration(
IN PRTMP_ADAPTER pAd)
{
UCHAR R55x = 0, value, FilterTarget = 0x1E, BBPValue;
UINT loop = 0, count = 0, loopcnt = 0, ReTry = 0;
UCHAR RF_R24_Value = 0;
// Give bbp filter initial value
pAd->Mlme.CaliBW20RfR24 = 0x16;
pAd->Mlme.CaliBW40RfR24 = 0x36; //Bit[5] must be 1 for BW 40
do
{
if (loop == 1) //BandWidth = 40 MHz
{
// Write 0x27 to RF_R24 to program filter
RF_R24_Value = 0x27;
RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
FilterTarget = 0x19;
// when calibrate BW40, BBP mask must set to BW40.
RTUSBReadBBPRegister(pAd, BBP_R4, &BBPValue);
BBPValue&= (~0x18);
BBPValue|= (0x10);
RTUSBWriteBBPRegister(pAd, BBP_R4, BBPValue);
}
else //BandWidth = 20 MHz
{
// Write 0x07 to RF_R24 to program filter
RF_R24_Value = 0x07;
RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
FilterTarget = 0x16;
}
// Write 0x01 to RF_R22 to enable baseband loopback mode
RT30xxReadRFRegister(pAd, RF_R22, &value);
value |= 0x01;
RT30xxWriteRFRegister(pAd, RF_R22, value);
// Write 0x00 to BBP_R24 to set power & frequency of passband test tone
RTUSBWriteBBPRegister(pAd, BBP_R24, 0);
do
{
// Write 0x90 to BBP_R25 to transmit test tone
RTUSBWriteBBPRegister(pAd, BBP_R25, 0x90);
RTMPusecDelay(1000);
// Read BBP_R55[6:0] for received power, set R55x = BBP_R55[6:0]
RTUSBReadBBPRegister(pAd, BBP_R55, &value);
R55x = value & 0xFF;
} while ((ReTry++ < 100) && (R55x == 0));
// Write 0x06 to BBP_R24 to set power & frequency of stopband test tone
RTUSBWriteBBPRegister(pAd, BBP_R24, 0x06);
while(TRUE)
{
// Write 0x90 to BBP_R25 to transmit test tone
RTUSBWriteBBPRegister(pAd, BBP_R25, 0x90);
//We need to wait for calibration
RTMPusecDelay(1000);
RTUSBReadBBPRegister(pAd, BBP_R55, &value);
value &= 0xFF;
if ((R55x - value) < FilterTarget)
{
RF_R24_Value ++;
}
else if ((R55x - value) == FilterTarget)
{
RF_R24_Value ++;
count ++;
}
else
{
break;
}
// prevent infinite loop cause driver hang.
if (loopcnt++ > 100)
{
DBGPRINT(RT_DEBUG_ERROR, ("RTUSBFilterCalibration - can't find a valid value, loopcnt=%d stop calibrating", loopcnt));
break;
}
// Write RF_R24 to program filter
RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
}
if (count > 0)
{
RF_R24_Value = RF_R24_Value - ((count) ? (1) : (0));
}
// Store for future usage
if (loopcnt < 100)
{
if (loop++ == 0)
{
//BandWidth = 20 MHz
pAd->Mlme.CaliBW20RfR24 = (UCHAR)RF_R24_Value;
}
else
{
//BandWidth = 40 MHz
pAd->Mlme.CaliBW40RfR24 = (UCHAR)RF_R24_Value;
break;
}
}
else
break;
RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
// reset count
count = 0;
} while(TRUE);
//
// Set back to initial state
//
RTUSBWriteBBPRegister(pAd, BBP_R24, 0);
RT30xxReadRFRegister(pAd, RF_R22, &value);
value &= ~(0x01);
RT30xxWriteRFRegister(pAd, RF_R22, value);
// set BBP back to BW20
RTUSBReadBBPRegister(pAd, BBP_R4, &BBPValue);
BBPValue&= (~0x18);
RTUSBWriteBBPRegister(pAd, BBP_R4, BBPValue);
DBGPRINT(RT_DEBUG_TRACE, ("RTUSBFilterCalibration - CaliBW20RfR24=0x%x, CaliBW40RfR24=0x%x\n", pAd->Mlme.CaliBW20RfR24, pAd->Mlme.CaliBW40RfR24));
}
#endif /* RT30xx */
#ifdef RT30xx
VOID RTMPFilterCalibration( VOID RTMPFilterCalibration(
IN PRTMP_ADAPTER pAd) IN PRTMP_ADAPTER pAd)
{ {
...@@ -1246,9 +1107,13 @@ VOID RTMPFilterCalibration( ...@@ -1246,9 +1107,13 @@ VOID RTMPFilterCalibration(
UCHAR RF_R24_Value = 0; UCHAR RF_R24_Value = 0;
// Give bbp filter initial value // Give bbp filter initial value
#ifndef RT30xx
pAd->Mlme.CaliBW20RfR24 = 0x16;
pAd->Mlme.CaliBW40RfR24 = 0x36; //Bit[5] must be 1 for BW 40
#else
pAd->Mlme.CaliBW20RfR24 = 0x1F; pAd->Mlme.CaliBW20RfR24 = 0x1F;
pAd->Mlme.CaliBW40RfR24 = 0x2F; //Bit[5] must be 1 for BW 40 pAd->Mlme.CaliBW40RfR24 = 0x2F; //Bit[5] must be 1 for BW 40
#endif
do do
{ {
if (loop == 1) //BandWidth = 40 MHz if (loop == 1) //BandWidth = 40 MHz
...@@ -1266,11 +1131,12 @@ VOID RTMPFilterCalibration( ...@@ -1266,11 +1131,12 @@ VOID RTMPFilterCalibration(
BBPValue&= (~0x18); BBPValue&= (~0x18);
BBPValue|= (0x10); BBPValue|= (0x10);
RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
#ifdef RT30xx
// set to BW40 // set to BW40
RT30xxReadRFRegister(pAd, RF_R31, &value); RT30xxReadRFRegister(pAd, RF_R31, &value);
value |= 0x20; value |= 0x20;
RT30xxWriteRFRegister(pAd, RF_R31, value); RT30xxWriteRFRegister(pAd, RF_R31, value);
#endif
} }
else //BandWidth = 20 MHz else //BandWidth = 20 MHz
{ {
...@@ -1281,11 +1147,12 @@ VOID RTMPFilterCalibration( ...@@ -1281,11 +1147,12 @@ VOID RTMPFilterCalibration(
FilterTarget = 0x13; FilterTarget = 0x13;
else else
FilterTarget = 0x16; FilterTarget = 0x16;
#ifdef RT30xx
// set to BW20 // set to BW20
RT30xxReadRFRegister(pAd, RF_R31, &value); RT30xxReadRFRegister(pAd, RF_R31, &value);
value &= (~0x20); value &= (~0x20);
RT30xxWriteRFRegister(pAd, RF_R31, value); RT30xxWriteRFRegister(pAd, RF_R31, value);
#endif
} }
// Write 0x01 to RF_R22 to enable baseband loopback mode // Write 0x01 to RF_R22 to enable baseband loopback mode
...@@ -1390,7 +1257,6 @@ VOID RTMPFilterCalibration( ...@@ -1390,7 +1257,6 @@ VOID RTMPFilterCalibration(
DBGPRINT(RT_DEBUG_TRACE, ("RTMPFilterCalibration - CaliBW20RfR24=0x%x, CaliBW40RfR24=0x%x\n", pAd->Mlme.CaliBW20RfR24, pAd->Mlme.CaliBW40RfR24)); DBGPRINT(RT_DEBUG_TRACE, ("RTMPFilterCalibration - CaliBW20RfR24=0x%x, CaliBW40RfR24=0x%x\n", pAd->Mlme.CaliBW20RfR24, pAd->Mlme.CaliBW40RfR24));
} }
#endif /* RT30xx */
VOID NICInitRT30xxRFRegisters(IN PRTMP_ADAPTER pAd) VOID NICInitRT30xxRFRegisters(IN PRTMP_ADAPTER pAd)
{ {
...@@ -1417,7 +1283,7 @@ VOID NICInitRT30xxRFRegisters(IN PRTMP_ADAPTER pAd) ...@@ -1417,7 +1283,7 @@ VOID NICInitRT30xxRFRegisters(IN PRTMP_ADAPTER pAd)
} }
//For RF filter Calibration //For RF filter Calibration
RTUSBFilterCalibration(pAd); RTMPFilterCalibration(pAd);
} }
#endif #endif
#ifdef RT30xx #ifdef RT30xx
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment