[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <5500d31a407aea3c53f153e4c70fed8f5ca87f0b.1442769012.git.raphael.beamonte@gmail.com>
Date: Sun, 20 Sep 2015 13:14:17 -0400
From: Raphaël Beamonte <raphael.beamonte@...il.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Raphaël Beamonte <raphael.beamonte@...il.com>,
Cristina Opriceana <cristina.opriceana@...il.com>,
devel@...verdev.osuosl.org, linux-kernel@...r.kernel.org
Subject: [PATCHv3 05/15] staging: rtl8192u: r8192U_core: rtl8192_read_eeprom_info: reorganize function
Refactor code to avoid multiple check of same boolean value, and to
make the code clearer. This patches also implements the necessary
changes for the code lines in this function to be under 80 chars.
Signed-off-by: Raphaël Beamonte <raphael.beamonte@...il.com>
---
drivers/staging/rtl8192u/r8192U_core.c | 259 ++++++++++++++++++++-------------
1 file changed, 155 insertions(+), 104 deletions(-)
diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index eb9c07e..7314e2f 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -2447,129 +2447,180 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
priv->rf_type = RTL819X_DEFAULT_RF_TYPE; /* default 1T2R */
priv->rf_chip = RF_8256;
- if (priv->card_8192_version == (u8)VERSION_819xU_A) {
+ /* if version mismatch VERSION_819xU_A, go directly to the led section
+ */
+ if (priv->card_8192_version != (u8)VERSION_819xU_A)
+ goto led;
+
+ if (bLoad_From_EEPOM) {
/* read Tx power gain offset of legacy OFDM to HT rate */
- if (bLoad_From_EEPOM)
- priv->EEPROMTxPowerDiff = (eprom_read(dev, (EEPROM_TxPowerDiff >> 1)) & 0xff00) >> 8;
- else
- priv->EEPROMTxPowerDiff = EEPROM_Default_TxPower;
- RT_TRACE(COMP_EPROM, "TxPowerDiff:%d\n", priv->EEPROMTxPowerDiff);
+ tmpValue = eprom_read(dev, (EEPROM_TxPowerDiff >> 1));
+ priv->EEPROMTxPowerDiff = (tmpValue & 0xff00) >> 8;
+
/* read ThermalMeter from EEPROM */
- if (bLoad_From_EEPOM)
- priv->EEPROMThermalMeter = (u8)(eprom_read(dev, (EEPROM_ThermalMeter >> 1)) & 0x00ff);
- else
- priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
- RT_TRACE(COMP_EPROM, "ThermalMeter:%d\n", priv->EEPROMThermalMeter);
- /* for tx power track */
- priv->TSSI_13dBm = priv->EEPROMThermalMeter * 100;
+ tmpValue = eprom_read(dev, (EEPROM_ThermalMeter >> 1));
+ priv->EEPROMThermalMeter = (u8)(tmpValue & 0x00ff);
+
/* read antenna tx power offset of B/C/D to A from EEPROM */
- if (bLoad_From_EEPOM)
- priv->EEPROMPwDiff = (eprom_read(dev, (EEPROM_PwDiff >> 1)) & 0x0f00) >> 8;
- else
- priv->EEPROMPwDiff = EEPROM_Default_PwDiff;
- RT_TRACE(COMP_EPROM, "TxPwDiff:%d\n", priv->EEPROMPwDiff);
+ tmpValue = eprom_read(dev, (EEPROM_PwDiff >> 1));
+ priv->EEPROMPwDiff = (tmpValue & 0x0f00) >> 8;
+
/* Read CrystalCap from EEPROM */
- if (bLoad_From_EEPOM)
- priv->EEPROMCrystalCap = (eprom_read(dev, (EEPROM_CrystalCap >> 1)) & 0x0f);
- else
- priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap;
- RT_TRACE(COMP_EPROM, "CrystalCap = %d\n", priv->EEPROMCrystalCap);
+ tmpValue = eprom_read(dev, (EEPROM_CrystalCap >> 1));
+ priv->EEPROMCrystalCap = (tmpValue & 0x0f);
+
/* get per-channel Tx power level */
- if (bLoad_From_EEPOM)
- priv->EEPROM_Def_Ver = (eprom_read(dev, (EEPROM_TxPwIndex_Ver >> 1)) & 0xff00) >> 8;
- else
- priv->EEPROM_Def_Ver = 1;
- RT_TRACE(COMP_EPROM, "EEPROM_DEF_VER:%d\n", priv->EEPROM_Def_Ver);
+ tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_Ver >> 1));
+ priv->EEPROM_Def_Ver = (tmpValue & 0xff00) >> 8;
+ } else {
+ /* read Tx power gain offset of legacy OFDM to HT rate */
+ priv->EEPROMTxPowerDiff = EEPROM_Default_TxPower;
+
+ /* read ThermalMeter from EEPROM */
+ priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
+
+ /* read antenna tx power offset of B/C/D to A from EEPROM */
+ priv->EEPROMPwDiff = EEPROM_Default_PwDiff;
+
+ /* Read CrystalCap from EEPROM */
+ priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap;
+
+ /* get per-channel Tx power level */
+ priv->EEPROM_Def_Ver = 1;
+ }
+
+ /* for tx power track */
+ priv->TSSI_13dBm = priv->EEPROMThermalMeter * 100;
+
+ RT_TRACE(COMP_EPROM, "TxPowerDiff:%d\n", priv->EEPROMTxPowerDiff);
+ RT_TRACE(COMP_EPROM, "ThermalMeter:%d\n", priv->EEPROMThermalMeter);
+ RT_TRACE(COMP_EPROM, "TxPwDiff:%d\n", priv->EEPROMPwDiff);
+ RT_TRACE(COMP_EPROM, "CrystalCap = %d\n", priv->EEPROMCrystalCap);
+ RT_TRACE(COMP_EPROM, "EEPROM_DEF_VER:%d\n", priv->EEPROM_Def_Ver);
+
+ if (bLoad_From_EEPOM) {
if (priv->EEPROM_Def_Ver == 0) { /* old eeprom definition */
int i;
- if (bLoad_From_EEPOM)
- priv->EEPROMTxPowerLevelCCK = (eprom_read(dev, (EEPROM_TxPwIndex_CCK >> 1)) & 0xff) >> 8;
- else
- priv->EEPROMTxPowerLevelCCK = 0x10;
- RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n", priv->EEPROMTxPowerLevelCCK);
+ tmpValue = (EEPROM_TxPwIndex_CCK >> 1) & 0xff;
+ tmpValue = eprom_read(dev, tmpValue);
+ priv->EEPROMTxPowerLevelCCK = tmpValue >> 8;
+
+ RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n",
+ priv->EEPROMTxPowerLevelCCK);
+
for (i = 0; i < 3; i++) {
- if (bLoad_From_EEPOM) {
- tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G + i) >> 1);
- if (((EEPROM_TxPwIndex_OFDM_24G + i) % 2) == 0)
- tmpValue = tmpValue & 0x00ff;
- else
- tmpValue = (tmpValue & 0xff00) >> 8;
- } else {
- tmpValue = 0x10;
- }
- priv->EEPROMTxPowerLevelOFDM24G[i] = (u8)tmpValue;
- RT_TRACE(COMP_EPROM, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelCCK);
+ tmpValue = (EEPROM_TxPwIndex_OFDM_24G + i) >> 1;
+ tmpValue = eprom_read(dev, tmpValue);
+ if (((EEPROM_TxPwIndex_OFDM_24G + i) % 2) == 0)
+ tmpValue = tmpValue & 0x00ff;
+ else
+ tmpValue = (tmpValue & 0xff00) >> 8;
+
+ priv->EEPROMTxPowerLevelOFDM24G[i] =
+ (u8)tmpValue;
+
+ RT_TRACE(COMP_EPROM,
+ "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n",
+ i, priv->EEPROMTxPowerLevelCCK);
}
} else if (priv->EEPROM_Def_Ver == 1) {
- if (bLoad_From_EEPOM) {
- tmpValue = eprom_read(dev,
- EEPROM_TxPwIndex_CCK_V1 >> 1);
- tmpValue = (tmpValue & 0xff00) >> 8;
- } else {
- tmpValue = 0x10;
- }
+ tmpValue = EEPROM_TxPwIndex_CCK_V1 >> 1;
+ tmpValue = eprom_read(dev, tmpValue);
+ tmpValue = (tmpValue & 0xff00) >> 8;
priv->EEPROMTxPowerLevelCCK_V1[0] = (u8)tmpValue;
- if (bLoad_From_EEPOM)
- tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1 + 2) >> 1);
- else
- tmpValue = 0x1010;
- *((u16 *)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = tmpValue;
- if (bLoad_From_EEPOM)
- tmpValue = eprom_read(dev,
- EEPROM_TxPwIndex_OFDM_24G_V1 >> 1);
- else
- tmpValue = 0x1010;
- *((u16 *)(&priv->EEPROMTxPowerLevelOFDM24G[0])) = tmpValue;
- if (bLoad_From_EEPOM)
- tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G_V1 + 2) >> 1);
- else
- tmpValue = 0x10;
+ tmpValue = (EEPROM_TxPwIndex_CCK_V1 + 2) >> 1;
+ *((u16 *)(&priv->EEPROMTxPowerLevelCCK_V1[1])) =
+ eprom_read(dev, tmpValue);
+
+ tmpValue = EEPROM_TxPwIndex_OFDM_24G_V1 >> 1;
+ *((u16 *)(&priv->EEPROMTxPowerLevelOFDM24G[0])) =
+ eprom_read(dev, tmpValue);
+
+ tmpValue = (EEPROM_TxPwIndex_OFDM_24G_V1 + 2) >> 1;
+ tmpValue = eprom_read(dev, tmpValue);
priv->EEPROMTxPowerLevelOFDM24G[2] = (u8)tmpValue;
} /* endif EEPROM_Def_Ver == 1 */
+ } else {
+ if (priv->EEPROM_Def_Ver == 0) { /* old eeprom definition */
+ int i;
- /* update HAL variables */
- for (i = 0; i < 14; i++) {
- if (i <= 3)
- priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[0];
- else if (i >= 4 && i <= 9)
- priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[1];
- else
- priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[2];
- }
+ priv->EEPROMTxPowerLevelCCK = 0x10;
- for (i = 0; i < 14; i++) {
- if (priv->EEPROM_Def_Ver == 0) {
- if (i <= 3)
- priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelOFDM24G[0] + (priv->EEPROMTxPowerLevelCCK - priv->EEPROMTxPowerLevelOFDM24G[1]);
- else if (i >= 4 && i <= 9)
- priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK;
- else
- priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelOFDM24G[2] + (priv->EEPROMTxPowerLevelCCK - priv->EEPROMTxPowerLevelOFDM24G[1]);
- } else if (priv->EEPROM_Def_Ver == 1) {
- if (i <= 3)
- priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[0];
- else if (i >= 4 && i <= 9)
- priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[1];
- else
- priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[2];
+ RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n",
+ priv->EEPROMTxPowerLevelCCK);
+
+ for (i = 0; i < 3; i++) {
+ priv->EEPROMTxPowerLevelOFDM24G[i] = (u8)0x10;
+ RT_TRACE(COMP_EPROM,
+ "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n",
+ i, priv->EEPROMTxPowerLevelCCK);
}
- }
- priv->TxPowerDiff = priv->EEPROMPwDiff;
- /* Antenna B gain offset to antenna A, bit0~3 */
- priv->AntennaTxPwDiff[0] = (priv->EEPROMTxPowerDiff & 0xf);
- /* Antenna C gain offset to antenna A, bit4~7 */
- priv->AntennaTxPwDiff[1] =
- (priv->EEPROMTxPowerDiff & 0xf0) >> 4;
- /* CrystalCap, bit12~15 */
- priv->CrystalCap = priv->EEPROMCrystalCap;
- /* ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
- * 92U does not enable TX power tracking.
- */
- priv->ThermalMeter[0] = priv->EEPROMThermalMeter;
- } /* end if VersionID == VERSION_819xU_A */
+ } else if (priv->EEPROM_Def_Ver == 1) {
+ priv->EEPROMTxPowerLevelCCK_V1[0] = (u8)0x10;
+ *((u16 *)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = 0x1010;
+ *((u16 *)(&priv->EEPROMTxPowerLevelOFDM24G[0])) =
+ 0x1010;
+ priv->EEPROMTxPowerLevelOFDM24G[2] = (u8)0x10;
+ } /* endif EEPROM_Def_Ver == 1 */
+ }
+
+ /* update HAL variables */
+ for (i = 0; i < 4; i++) {
+ priv->TxPowerLevelOFDM24G[i] =
+ priv->EEPROMTxPowerLevelOFDM24G[0];
+
+ if (priv->EEPROM_Def_Ver == 0)
+ priv->TxPowerLevelCCK[i] =
+ priv->EEPROMTxPowerLevelOFDM24G[0] +
+ priv->EEPROMTxPowerLevelCCK -
+ priv->EEPROMTxPowerLevelOFDM24G[1];
+ else
+ priv->TxPowerLevelCCK[i] =
+ priv->EEPROMTxPowerLevelCCK_V1[0];
+ }
+
+ for (i = 4; i < 10; i++) {
+ priv->TxPowerLevelOFDM24G[i] =
+ priv->EEPROMTxPowerLevelOFDM24G[1];
+
+ if (priv->EEPROM_Def_Ver == 0)
+ priv->TxPowerLevelCCK[i] =
+ priv->EEPROMTxPowerLevelCCK;
+ else
+ priv->TxPowerLevelCCK[i] =
+ priv->EEPROMTxPowerLevelCCK_V1[1];
+ }
+
+ for (i = 10; i < 14; i++) {
+ priv->TxPowerLevelOFDM24G[i] =
+ priv->EEPROMTxPowerLevelOFDM24G[2];
+
+ if (priv->EEPROM_Def_Ver == 0)
+ priv->TxPowerLevelCCK[i] =
+ priv->EEPROMTxPowerLevelOFDM24G[2] +
+ priv->EEPROMTxPowerLevelCCK -
+ priv->EEPROMTxPowerLevelOFDM24G[1];
+ else
+ priv->TxPowerLevelCCK[i] =
+ priv->EEPROMTxPowerLevelCCK_V1[2];
+ }
+
+ priv->TxPowerDiff = priv->EEPROMPwDiff;
+ /* Antenna B gain offset to antenna A, bit0~3 */
+ priv->AntennaTxPwDiff[0] = (priv->EEPROMTxPowerDiff & 0xf);
+ /* Antenna C gain offset to antenna A, bit4~7 */
+ priv->AntennaTxPwDiff[1] =
+ (priv->EEPROMTxPowerDiff & 0xf0) >> 4;
+ /* CrystalCap, bit12~15 */
+ priv->CrystalCap = priv->EEPROMCrystalCap;
+ /* ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
+ * 92U does not enable TX power tracking.
+ */
+ priv->ThermalMeter[0] = priv->EEPROMThermalMeter;
+led:
/* for dlink led */
switch (priv->eeprom_CustomerID) {
case EEPROM_CID_RUNTOP:
--
2.5.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists