ath9k: Use a subroutine to calculate ALT ratio
authorSujith Manoharan <c_manoha@qca.qualcomm.com>
Thu, 1 Aug 2013 06:23:23 +0000 (11:53 +0530)
committerJohn W. Linville <linville@tuxdriver.com>
Thu, 1 Aug 2013 19:52:05 +0000 (15:52 -0400)
Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/ath/ath9k/antenna.c

index 6495fc620b40083491266a588a6388bf4c8ba79d..ea4ee08cddf276c06ecfcd0d1ff0ca138ba23a35 100644 (file)
@@ -125,6 +125,74 @@ static void ath_lnaconf_alt_good_scan(struct ath_ant_comb *antcomb,
        }
 }
 
+static void ath_ant_set_alt_ratio(struct ath_ant_comb *antcomb,
+                                 struct ath_hw_antcomb_conf *conf)
+{
+       /* set alt to the conf with maximun ratio */
+       if (antcomb->first_ratio && antcomb->second_ratio) {
+               if (antcomb->rssi_second > antcomb->rssi_third) {
+                       /* first alt*/
+                       if ((antcomb->first_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1) ||
+                           (antcomb->first_quick_scan_conf == ATH_ANT_DIV_COMB_LNA2))
+                               /* Set alt LNA1 or LNA2*/
+                               if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
+                                       conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
+                               else
+                                       conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
+                       else
+                               /* Set alt to A+B or A-B */
+                               conf->alt_lna_conf =
+                                       antcomb->first_quick_scan_conf;
+               } else if ((antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1) ||
+                          (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA2)) {
+                       /* Set alt LNA1 or LNA2 */
+                       if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
+                               conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
+                       else
+                               conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
+               } else {
+                       /* Set alt to A+B or A-B */
+                       conf->alt_lna_conf = antcomb->second_quick_scan_conf;
+               }
+       } else if (antcomb->first_ratio) {
+               /* first alt */
+               if ((antcomb->first_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1) ||
+                   (antcomb->first_quick_scan_conf == ATH_ANT_DIV_COMB_LNA2))
+                       /* Set alt LNA1 or LNA2 */
+                       if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
+                               conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
+                       else
+                               conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
+               else
+                       /* Set alt to A+B or A-B */
+                       conf->alt_lna_conf = antcomb->first_quick_scan_conf;
+       } else if (antcomb->second_ratio) {
+               /* second alt */
+               if ((antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1) ||
+                   (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA2))
+                       /* Set alt LNA1 or LNA2 */
+                       if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
+                               conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
+                       else
+                               conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
+               else
+                       /* Set alt to A+B or A-B */
+                       conf->alt_lna_conf = antcomb->second_quick_scan_conf;
+       } else {
+               /* main is largest */
+               if ((antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) ||
+                   (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2))
+                       /* Set alt LNA1 or LNA2 */
+                       if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
+                               conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
+                       else
+                               conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
+               else
+                       /* Set alt to A+B or A-B */
+                       conf->alt_lna_conf = antcomb->main_conf;
+       }
+}
+
 static void ath_select_ant_div_from_quick_scan(struct ath_ant_comb *antcomb,
                                       struct ath_hw_antcomb_conf *div_ant_conf,
                                       int main_rssi_avg, int alt_rssi_avg,
@@ -181,17 +249,21 @@ static void ath_select_ant_div_from_quick_scan(struct ath_ant_comb *antcomb,
                antcomb->rssi_first = main_rssi_avg;
                antcomb->rssi_third = alt_rssi_avg;
 
-               if (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1)
+               switch(antcomb->second_quick_scan_conf) {
+               case ATH_ANT_DIV_COMB_LNA1:
                        antcomb->rssi_lna1 = alt_rssi_avg;
-               else if (antcomb->second_quick_scan_conf ==
-                        ATH_ANT_DIV_COMB_LNA2)
+                       break;
+               case ATH_ANT_DIV_COMB_LNA2:
                        antcomb->rssi_lna2 = alt_rssi_avg;
-               else if (antcomb->second_quick_scan_conf ==
-                        ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2) {
+                       break;
+               case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
                        if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2)
                                antcomb->rssi_lna2 = main_rssi_avg;
                        else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1)
                                antcomb->rssi_lna1 = main_rssi_avg;
+                       break;
+               default:
+                       break;
                }
 
                if (antcomb->rssi_lna2 > antcomb->rssi_lna1 +
@@ -229,95 +301,8 @@ static void ath_select_ant_div_from_quick_scan(struct ath_ant_comb *antcomb,
                                antcomb->second_ratio = false;
                }
 
-               /* set alt to the conf with maximun ratio */
-               if (antcomb->first_ratio && antcomb->second_ratio) {
-                       if (antcomb->rssi_second > antcomb->rssi_third) {
-                               /* first alt*/
-                               if ((antcomb->first_quick_scan_conf ==
-                                   ATH_ANT_DIV_COMB_LNA1) ||
-                                   (antcomb->first_quick_scan_conf ==
-                                   ATH_ANT_DIV_COMB_LNA2))
-                                       /* Set alt LNA1 or LNA2*/
-                                       if (div_ant_conf->main_lna_conf ==
-                                           ATH_ANT_DIV_COMB_LNA2)
-                                               div_ant_conf->alt_lna_conf =
-                                                       ATH_ANT_DIV_COMB_LNA1;
-                                       else
-                                               div_ant_conf->alt_lna_conf =
-                                                       ATH_ANT_DIV_COMB_LNA2;
-                               else
-                                       /* Set alt to A+B or A-B */
-                                       div_ant_conf->alt_lna_conf =
-                                               antcomb->first_quick_scan_conf;
-                       } else if ((antcomb->second_quick_scan_conf ==
-                                  ATH_ANT_DIV_COMB_LNA1) ||
-                                  (antcomb->second_quick_scan_conf ==
-                                  ATH_ANT_DIV_COMB_LNA2)) {
-                               /* Set alt LNA1 or LNA2 */
-                               if (div_ant_conf->main_lna_conf ==
-                                   ATH_ANT_DIV_COMB_LNA2)
-                                       div_ant_conf->alt_lna_conf =
-                                               ATH_ANT_DIV_COMB_LNA1;
-                               else
-                                       div_ant_conf->alt_lna_conf =
-                                               ATH_ANT_DIV_COMB_LNA2;
-                       } else {
-                               /* Set alt to A+B or A-B */
-                               div_ant_conf->alt_lna_conf =
-                                       antcomb->second_quick_scan_conf;
-                       }
-               } else if (antcomb->first_ratio) {
-                       /* first alt */
-                       if ((antcomb->first_quick_scan_conf ==
-                           ATH_ANT_DIV_COMB_LNA1) ||
-                           (antcomb->first_quick_scan_conf ==
-                           ATH_ANT_DIV_COMB_LNA2))
-                                       /* Set alt LNA1 or LNA2 */
-                               if (div_ant_conf->main_lna_conf ==
-                                   ATH_ANT_DIV_COMB_LNA2)
-                                       div_ant_conf->alt_lna_conf =
-                                                       ATH_ANT_DIV_COMB_LNA1;
-                               else
-                                       div_ant_conf->alt_lna_conf =
-                                                       ATH_ANT_DIV_COMB_LNA2;
-                       else
-                               /* Set alt to A+B or A-B */
-                               div_ant_conf->alt_lna_conf =
-                                               antcomb->first_quick_scan_conf;
-               } else if (antcomb->second_ratio) {
-                               /* second alt */
-                       if ((antcomb->second_quick_scan_conf ==
-                           ATH_ANT_DIV_COMB_LNA1) ||
-                           (antcomb->second_quick_scan_conf ==
-                           ATH_ANT_DIV_COMB_LNA2))
-                               /* Set alt LNA1 or LNA2 */
-                               if (div_ant_conf->main_lna_conf ==
-                                   ATH_ANT_DIV_COMB_LNA2)
-                                       div_ant_conf->alt_lna_conf =
-                                               ATH_ANT_DIV_COMB_LNA1;
-                               else
-                                       div_ant_conf->alt_lna_conf =
-                                               ATH_ANT_DIV_COMB_LNA2;
-                       else
-                               /* Set alt to A+B or A-B */
-                               div_ant_conf->alt_lna_conf =
-                                               antcomb->second_quick_scan_conf;
-               } else {
-                       /* main is largest */
-                       if ((antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) ||
-                           (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2))
-                               /* Set alt LNA1 or LNA2 */
-                               if (div_ant_conf->main_lna_conf ==
-                                   ATH_ANT_DIV_COMB_LNA2)
-                                       div_ant_conf->alt_lna_conf =
-                                                       ATH_ANT_DIV_COMB_LNA1;
-                               else
-                                       div_ant_conf->alt_lna_conf =
-                                                       ATH_ANT_DIV_COMB_LNA2;
-                       else
-                               /* Set alt to A+B or A-B */
-                               div_ant_conf->alt_lna_conf = antcomb->main_conf;
-               }
+               ath_ant_set_alt_ratio(antcomb, div_ant_conf);
+
                break;
        default:
                break;