ath9k: Add a debugfs file to adjust antenna diversity
authorSujith Manoharan <c_manoha@qualcomm.com>
Wed, 26 Sep 2012 02:25:18 +0000 (07:55 +0530)
committerJohn W. Linville <linville@tuxdriver.com>
Fri, 28 Sep 2012 17:54:03 +0000 (13:54 -0400)
Location: /<debugfs>/ieee80211/phy#/ath9k/diversity

Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/ath/ath9k/ar9003_phy.c
drivers/net/wireless/ath/ath9k/debug.c

index fc67844a14305898bfece85e7c9273b5f5780c6c..759f5f5a715469bb43c054b45d4d8ed5f6917302 100644 (file)
@@ -1360,7 +1360,7 @@ static void ar9003_hw_antctrl_shared_chain_lnadiv(struct ath_hw *ah,
        if (enable) {
                REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL,
                            (1 << AR_PHY_ANT_SW_RX_PROT_S));
-               if (IS_CHAN_2GHZ(ah->curchan))
+               if (ah->curchan && IS_CHAN_2GHZ(ah->curchan))
                        REG_SET_BIT(ah, AR_PHY_RESTART,
                                    AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
                REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV,
index ab3bc85a1f8aa13b7e960d05de18391c372ea884..ed38216c3ca39ec45831a1d4df72a29e8ec50771 100644 (file)
@@ -222,6 +222,57 @@ static const struct file_operations fops_disable_ani = {
        .llseek = default_llseek,
 };
 
+static ssize_t read_file_ant_diversity(struct file *file, char __user *user_buf,
+                                      size_t count, loff_t *ppos)
+{
+       struct ath_softc *sc = file->private_data;
+       struct ath_common *common = ath9k_hw_common(sc->sc_ah);
+       char buf[32];
+       unsigned int len;
+
+       len = sprintf(buf, "%d\n", common->antenna_diversity);
+       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+}
+
+static ssize_t write_file_ant_diversity(struct file *file,
+                                       const char __user *user_buf,
+                                       size_t count, loff_t *ppos)
+{
+       struct ath_softc *sc = file->private_data;
+       struct ath_common *common = ath9k_hw_common(sc->sc_ah);
+       unsigned long antenna_diversity;
+       char buf[32];
+       ssize_t len;
+
+       len = min(count, sizeof(buf) - 1);
+       if (copy_from_user(buf, user_buf, len))
+               return -EFAULT;
+
+       if (!AR_SREV_9565(sc->sc_ah))
+               goto exit;
+
+       buf[len] = '\0';
+       if (strict_strtoul(buf, 0, &antenna_diversity))
+               return -EINVAL;
+
+       common->antenna_diversity = !!antenna_diversity;
+       ath9k_ps_wakeup(sc);
+       ath_ant_comb_update(sc);
+       ath_dbg(common, CONFIG, "Antenna diversity: %d\n",
+               common->antenna_diversity);
+       ath9k_ps_restore(sc);
+exit:
+       return count;
+}
+
+static const struct file_operations fops_ant_diversity = {
+       .read = read_file_ant_diversity,
+       .write = write_file_ant_diversity,
+       .open = simple_open,
+       .owner = THIS_MODULE,
+       .llseek = default_llseek,
+};
+
 static ssize_t read_file_dma(struct file *file, char __user *user_buf,
                             size_t count, loff_t *ppos)
 {
@@ -1599,12 +1650,12 @@ int ath9k_init_debug(struct ath_hw *ah)
        debugfs_create_file("samples", S_IRUSR, sc->debug.debugfs_phy, sc,
                            &fops_samps);
 #endif
-
        debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
                           sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
-
        debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
                           sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
+       debugfs_create_file("diversity", S_IRUSR | S_IWUSR,
+                           sc->debug.debugfs_phy, sc, &fops_ant_diversity);
 
        return 0;
 }