]> err.no Git - linux-2.6/blobdiff - drivers/net/wireless/rt2x00/rt2x00config.c
rt2x00: Add new D-Link USB ID
[linux-2.6] / drivers / net / wireless / rt2x00 / rt2x00config.c
index 04518b089bdbb1421e111b732203ce6400fe11c2..07adc576db49dc28f92819c6ec46f04e926b4b48 100644 (file)
        Abstract: rt2x00 generic configuration routines.
  */
 
-/*
- * Set enviroment defines for rt2x00.h
- */
-#define DRV_NAME "rt2x00lib"
-
 #include <linux/kernel.h>
 #include <linux/module.h>
 
@@ -94,6 +89,40 @@ void rt2x00lib_config_type(struct rt2x00_dev *rt2x00dev, const int type)
        rt2x00dev->ops->lib->config_type(rt2x00dev, type, tsf_sync);
 }
 
+void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
+                             enum antenna rx, enum antenna tx)
+{
+       struct rt2x00lib_conf libconf;
+
+       libconf.ant.rx = rx;
+       libconf.ant.tx = tx;
+
+       if (rx == rt2x00dev->link.ant.active.rx &&
+           tx == rt2x00dev->link.ant.active.tx)
+               return;
+
+       /*
+        * Antenna setup changes require the RX to be disabled,
+        * else the changes will be ignored by the device.
+        */
+       if (test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
+               rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF_LINK);
+
+       /*
+        * Write new antenna setup to device and reset the link tuner.
+        * The latter is required since we need to recalibrate the
+        * noise-sensitivity ratio for the new setup.
+        */
+       rt2x00dev->ops->lib->config(rt2x00dev, CONFIG_UPDATE_ANTENNA, &libconf);
+       rt2x00lib_reset_link_tuner(rt2x00dev);
+
+       rt2x00dev->link.ant.active.rx = libconf.ant.rx;
+       rt2x00dev->link.ant.active.tx = libconf.ant.tx;
+
+       if (test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
+               rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON_LINK);
+}
+
 void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
                      struct ieee80211_conf *conf, const int force_config)
 {
@@ -101,7 +130,7 @@ void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
        struct ieee80211_hw_mode *mode;
        struct ieee80211_rate *rate;
        struct antenna_setup *default_ant = &rt2x00dev->default_ant;
-       struct antenna_setup *active_ant = &rt2x00dev->link.active_ant;
+       struct antenna_setup *active_ant = &rt2x00dev->link.ant.active;
        int flags = 0;
        int short_slot_time;
 
@@ -146,6 +175,8 @@ void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
        else if (conf->antenna_sel_rx &&
                 conf->antenna_sel_rx != active_ant->rx)
                flags |= CONFIG_UPDATE_ANTENNA;
+       else if (active_ant->rx == ANTENNA_SW_DIVERSITY)
+               flags |= CONFIG_UPDATE_ANTENNA;
 
        if (!conf->antenna_sel_tx &&
            default_ant->tx != ANTENNA_SW_DIVERSITY &&
@@ -154,6 +185,8 @@ void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
        else if (conf->antenna_sel_tx &&
                 conf->antenna_sel_tx != active_ant->tx)
                flags |= CONFIG_UPDATE_ANTENNA;
+       else if (active_ant->tx == ANTENNA_SW_DIVERSITY)
+               flags |= CONFIG_UPDATE_ANTENNA;
 
        /*
         * The following configuration options are never
@@ -242,11 +275,17 @@ config:
        if (flags & (CONFIG_UPDATE_CHANNEL | CONFIG_UPDATE_ANTENNA))
                rt2x00lib_reset_link_tuner(rt2x00dev);
 
-       rt2x00dev->curr_hwmode = libconf.phymode;
-       rt2x00dev->rx_status.phymode = conf->phymode;
+       if (flags & CONFIG_UPDATE_PHYMODE) {
+               rt2x00dev->curr_hwmode = libconf.phymode;
+               rt2x00dev->rx_status.phymode = conf->phymode;
+       }
+
        rt2x00dev->rx_status.freq = conf->freq;
        rt2x00dev->rx_status.channel = conf->channel;
        rt2x00dev->tx_power = conf->power_level;
-       rt2x00dev->link.active_ant.rx = libconf.ant.rx;
-       rt2x00dev->link.active_ant.tx = libconf.ant.tx;
+
+       if (flags & CONFIG_UPDATE_ANTENNA) {
+               rt2x00dev->link.ant.active.rx = libconf.ant.rx;
+               rt2x00dev->link.ant.active.tx = libconf.ant.tx;
+       }
 }